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

Generated by: LCOV version 1.14