LCOV - code coverage report
Current view: top level - bgp - bgp_show_ribout_statistics.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 33 50 66.0 %
Date: 2026-06-11 01:56:02 Functions: 3 4 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016 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_server.h"
      10             : #include "bgp/bgp_table.h"
      11             : #include "bgp/routing-instance/routing_instance.h"
      12             : 
      13             : using contrail::regex;
      14             : using contrail::regex_match;
      15             : using contrail::regex_search;
      16             : using std::string;
      17             : using std::vector;
      18             : 
      19             : //
      20             : // Specialization of BgpShowHandler<>::CallbackCommon.
      21             : //
      22             : // Note that we check the page and iteration limits only after examining all
      23             : // ribouts in all tables for a given routing instance. This simplifies things
      24             : // and requires to only keep track of the next instance rather than the next
      25             : // instance and next table.
      26             : //
      27             : template <>
      28           2 : bool BgpShowHandler<ShowRibOutStatisticsReq, ShowRibOutStatisticsReqIterate,
      29             :     ShowRibOutStatisticsResp, ShowRibOutStatistics>::CallbackCommon(
      30             :     const BgpSandeshContext *bsc, Data *data) {
      31           2 :     uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
      32           2 :     uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
      33           2 :     RoutingInstanceMgr *rim = bsc->bgp_server->routing_instance_mgr();
      34             : 
      35           2 :     regex search_expr(data->search_string);
      36             :     RoutingInstanceMgr::const_name_iterator it1 =
      37           2 :         rim->name_clower_bound(data->next_entry);
      38           4 :     for (uint32_t iter_count = 0; it1 != rim->name_cend(); ++it1) {
      39           2 :         const RoutingInstance *rtinstance = it1->second;
      40           2 :         for (RoutingInstance::RouteTableList::const_iterator it2 =
      41           2 :              rtinstance->GetTables().begin();
      42          20 :              it2 != rtinstance->GetTables().end(); ++it2, ++iter_count) {
      43          18 :             const BgpTable *table = it2->second;
      44          18 :             if (!regex_search(table->name(), search_expr))
      45           0 :                 continue;
      46          18 :             table->FillRibOutStatisticsInfo(&data->show_list);
      47             :         }
      48           2 :         if (data->show_list.size() >= page_limit)
      49           0 :             break;
      50           2 :         if (iter_count >= iter_limit)
      51           0 :             break;
      52             :     }
      53             : 
      54             :     // All done if we've looked at all instances.
      55           2 :     if (it1 == rim->name_cend() || ++it1 == rim->name_end())
      56           2 :         return true;
      57             : 
      58             :     // Return true if we've reached the page limit, false if we've reached the
      59             :     // iteration limit.
      60           0 :     bool done = data->show_list.size() >= page_limit;
      61           0 :     SaveContextToData(it1->second->name(), done, data);
      62           0 :     return done;
      63           2 : }
      64             : 
      65             : //
      66             : // Specialization of BgpShowHandler<>::FillShowList.
      67             : //
      68             : template <>
      69           2 : void BgpShowHandler<ShowRibOutStatisticsReq, ShowRibOutStatisticsReqIterate,
      70             :     ShowRibOutStatisticsResp, ShowRibOutStatistics>::FillShowList(
      71             :     ShowRibOutStatisticsResp *resp,
      72             :     const vector<ShowRibOutStatistics> &show_list) {
      73           2 :     resp->set_ribouts(show_list);
      74           2 : }
      75             : 
      76             : //
      77             : // Handler for ShowRibOutStatisticsReq.
      78             : //
      79           2 : void ShowRibOutStatisticsReq::HandleRequest() const {
      80           2 :     RequestPipeline::PipeSpec ps(this);
      81           2 :     RequestPipeline::StageSpec s1;
      82           2 :     TaskScheduler *scheduler = TaskScheduler::GetInstance();
      83             : 
      84           2 :     s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
      85             :     s1.cbFn_ = boost::bind(&BgpShowHandler<
      86             :         ShowRibOutStatisticsReq,
      87             :         ShowRibOutStatisticsReqIterate,
      88             :         ShowRibOutStatisticsResp,
      89           2 :         ShowRibOutStatistics>::Callback, _1, _2, _3, _4, _5);
      90             :     s1.allocFn_ = BgpShowHandler<
      91             :         ShowRibOutStatisticsReq,
      92             :         ShowRibOutStatisticsReqIterate,
      93             :         ShowRibOutStatisticsResp,
      94           2 :         ShowRibOutStatistics>::CreateData;
      95           2 :     s1.instances_.push_back(0);
      96           2 :     ps.stages_.push_back(s1);
      97           2 :     RequestPipeline rp(ps);
      98           2 : }
      99             : 
     100             : //
     101             : // Handler for ShowRibOutStatisticsReqIterate.
     102             : //
     103           0 : void ShowRibOutStatisticsReqIterate::HandleRequest() const {
     104           0 :     RequestPipeline::PipeSpec ps(this);
     105           0 :     RequestPipeline::StageSpec s1;
     106           0 :     TaskScheduler *scheduler = TaskScheduler::GetInstance();
     107             : 
     108           0 :     s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
     109             :     s1.cbFn_ = boost::bind(&BgpShowHandler<
     110             :         ShowRibOutStatisticsReq,
     111             :         ShowRibOutStatisticsReqIterate,
     112             :         ShowRibOutStatisticsResp,
     113           0 :         ShowRibOutStatistics>::CallbackIterate, _1, _2, _3, _4, _5);
     114             :     s1.allocFn_ = BgpShowHandler<
     115             :         ShowRibOutStatisticsReq,
     116             :         ShowRibOutStatisticsReqIterate,
     117             :         ShowRibOutStatisticsResp,
     118           0 :         ShowRibOutStatistics>::CreateData;
     119           0 :     s1.instances_.push_back(0);
     120           0 :     ps.stages_.push_back(s1);
     121           0 :     RequestPipeline rp(ps);
     122           0 : }

Generated by: LCOV version 1.14