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

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

Generated by: LCOV version 1.14