LCOV - code coverage report
Current view: top level - bgp - bgp_show_multicast_manager.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 67 67 100.0 %
Date: 2026-11-09 02:10:49 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #include "bgp/bgp_show_handler.h"
       7             : 
       8             : #include "base/regex.h"
       9             : #include "bgp/bgp_peer_internal_types.h"
      10             : #include "bgp/bgp_multicast.h"
      11             : #include "bgp/bgp_server.h"
      12             : #include "bgp/ermvpn/ermvpn_table.h"
      13             : #include "bgp/routing-instance/routing_instance.h"
      14             : 
      15             : using contrail::regex;
      16             : using contrail::regex_match;
      17             : using contrail::regex_search;
      18             : using std::string;
      19             : using std::vector;
      20             : 
      21             : //
      22             : // Fill in information for an ermvpn table.
      23             : //
      24         210 : static void FillMulticastManagerInfo(ShowMulticastManager *smm,
      25             :     const BgpSandeshContext *bsc, const ErmVpnTable *table) {
      26         210 :     smm->set_name(table->name());
      27         210 :     const McastTreeManager *manager = table->GetTreeManager();
      28         210 :     if (!manager)
      29          20 :         return;
      30             : 
      31         190 :     smm->set_deleted(manager->deleted());
      32         190 :     smm->set_deleted_at(
      33         380 :         UTCUsecToString(manager->deleter()->delete_time_stamp_usecs()));
      34             : 
      35         190 :     uint32_t total_trees = 0;
      36         190 :     for (McastTreeManager::const_iterator it = manager->begin();
      37         380 :          it != manager->end(); ++it) {
      38         190 :         const McastManagerPartition *partition = *it;
      39         190 :         total_trees += partition->size();
      40             :     }
      41         190 :     smm->set_total_trees(total_trees);
      42             : }
      43             : 
      44             : //
      45             : // Specialization of BgpShowHandler<>::CallbackCommon.
      46             : //
      47             : template <>
      48          41 : bool BgpShowHandler<ShowMulticastManagerReq, ShowMulticastManagerReqIterate,
      49             :     ShowMulticastManagerResp, ShowMulticastManager>::CallbackCommon(
      50             :     const BgpSandeshContext *bsc, Data *data) {
      51          41 :     uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
      52          41 :     uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
      53          41 :     RoutingInstanceMgr *rim = bsc->bgp_server->routing_instance_mgr();
      54             : 
      55          41 :     regex search_expr(data->search_string);
      56             :     RoutingInstanceMgr::const_name_iterator it =
      57          41 :         rim->name_clower_bound(data->next_entry);
      58         306 :     for (uint32_t iter_count = 0; it != rim->name_cend(); ++it, ++iter_count) {
      59         290 :         const RoutingInstance *rtinstance = it->second;
      60             :         const ErmVpnTable *table = static_cast<const ErmVpnTable *>(
      61         290 :             rtinstance->GetTable(Address::ERMVPN));
      62         290 :         if (!table)
      63          80 :             continue;
      64         412 :         if ((!regex_search(table->name(), search_expr)) &&
      65         122 :             (data->search_string != "deleted" || !table->IsDeleted())) {
      66          80 :             continue;
      67             :         }
      68         210 :         ShowMulticastManager smm;
      69         210 :         FillMulticastManagerInfo(&smm, bsc, table);
      70         210 :         data->show_list.push_back(smm);
      71         210 :         if (data->show_list.size() >= page_limit)
      72          13 :             break;
      73         197 :         if (iter_count >= iter_limit)
      74          12 :             break;
      75         210 :     }
      76             : 
      77             :     // All done if we've looked at all instances.
      78          41 :     if (it == rim->name_cend() || ++it == rim->name_cend())
      79          19 :         return true;
      80             : 
      81             :     // Return true if we've reached the page limit, false if we've reached the
      82             :     // iteration limit.
      83          22 :     bool done = data->show_list.size() >= page_limit;
      84          22 :     SaveContextToData(it->second->name(), done, data);
      85          22 :     return done;
      86          41 : }
      87             : 
      88             : //
      89             : // Specialization of BgpShowHandler<>::FillShowList.
      90             : //
      91             : template <>
      92          24 : void BgpShowHandler<ShowMulticastManagerReq, ShowMulticastManagerReqIterate,
      93             :     ShowMulticastManagerResp, ShowMulticastManager>::FillShowList(
      94             :     ShowMulticastManagerResp *resp,
      95             :     const vector<ShowMulticastManager> &show_list) {
      96          24 :     resp->set_managers(show_list);
      97          24 : }
      98             : 
      99             : //
     100             : // Handler for ShowMulticastManagerReq.
     101             : //
     102          16 : void ShowMulticastManagerReq::HandleRequest() const {
     103          16 :     RequestPipeline::PipeSpec ps(this);
     104          16 :     RequestPipeline::StageSpec s1;
     105          16 :     TaskScheduler *scheduler = TaskScheduler::GetInstance();
     106             : 
     107          16 :     s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
     108             :     s1.cbFn_ = boost::bind(&BgpShowHandler<
     109             :         ShowMulticastManagerReq,
     110             :         ShowMulticastManagerReqIterate,
     111             :         ShowMulticastManagerResp,
     112          16 :         ShowMulticastManager>::Callback, _1, _2, _3, _4, _5);
     113             :     s1.allocFn_ = BgpShowHandler<
     114             :         ShowMulticastManagerReq,
     115             :         ShowMulticastManagerReqIterate,
     116             :         ShowMulticastManagerResp,
     117          16 :         ShowMulticastManager>::CreateData;
     118          16 :     s1.instances_.push_back(0);
     119          16 :     ps.stages_.push_back(s1);
     120          16 :     RequestPipeline rp(ps);
     121          16 : }
     122             : 
     123             : //
     124             : // Handler for ShowMulticastManagerReqIterate.
     125             : //
     126          16 : void ShowMulticastManagerReqIterate::HandleRequest() const {
     127          16 :     RequestPipeline::PipeSpec ps(this);
     128          16 :     RequestPipeline::StageSpec s1;
     129          16 :     TaskScheduler *scheduler = TaskScheduler::GetInstance();
     130             : 
     131          16 :     s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
     132             :     s1.cbFn_ = boost::bind(&BgpShowHandler<
     133             :         ShowMulticastManagerReq,
     134             :         ShowMulticastManagerReqIterate,
     135             :         ShowMulticastManagerResp,
     136          16 :         ShowMulticastManager>::CallbackIterate, _1, _2, _3, _4, _5);
     137             :     s1.allocFn_ = BgpShowHandler<
     138             :         ShowMulticastManagerReq,
     139             :         ShowMulticastManagerReqIterate,
     140             :         ShowMulticastManagerResp,
     141          16 :         ShowMulticastManager>::CreateData;
     142          16 :     s1.instances_.push_back(0);
     143          16 :     ps.stages_.push_back(s1);
     144          16 :     RequestPipeline rp(ps);
     145          16 : }

Generated by: LCOV version 1.14