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: 0 67 0.0 %
Date: 2026-11-16 02:06:09 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14