LCOV - code coverage report
Current view: top level - bgp/routing-instance - show_static_route.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 43 60 71.7 %
Date: 2026-06-11 01:56:02 Functions: 4 5 80.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 "base/regex.h"
       6             : #include "bgp/bgp_config.h"
       7             : #include "bgp/bgp_server.h"
       8             : #include "bgp/bgp_show_handler.h"
       9             : #include "bgp/bgp_table.h"
      10             : #include "bgp/routing-instance/routing_instance.h"
      11             : #include "bgp/routing-instance/static_route.h"
      12             : #include "bgp/routing-instance/static_route_types.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         224 : static bool FillStaticRouteInfo(Address::Family family,
      21             :                                 const string &search_string,
      22             :                                 const regex &search_expr,
      23             :                                 StaticRouteEntriesInfo &info,
      24             :                                 RoutingInstance *rtinstance) {
      25             :     const BgpTable *table =
      26         224 :         static_cast<const BgpTable *>(rtinstance->GetTable(family));
      27         224 :     if (!table)
      28           0 :         return false;
      29         372 :     if ((!regex_search(table->name(), search_expr)) &&
      30         148 :         (search_string != "deleted" || !table->IsDeleted())) {
      31         148 :         return false;
      32             :     }
      33             : 
      34          76 :     IStaticRouteMgr *imanager = rtinstance->static_route_mgr(family);
      35          76 :     if (!imanager)
      36          38 :         return false;
      37          38 :     return imanager->FillStaticRouteInfo(rtinstance, &info);
      38             : }
      39             : 
      40             : // Specialization of BgpShowHandler<>::CallbackCommon.
      41             : template <>
      42          38 : bool BgpShowHandler<ShowStaticRouteReq, ShowStaticRouteReqIterate,
      43             :     ShowStaticRouteResp, StaticRouteEntriesInfo>::CallbackCommon(
      44             :     const BgpSandeshContext *bsc, Data *data) {
      45          38 :     uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
      46          38 :     uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
      47          38 :     RoutingInstanceMgr *rim = bsc->bgp_server->routing_instance_mgr();
      48             : 
      49          38 :     regex search_expr(data->search_string);
      50             :     RoutingInstanceMgr::const_name_iterator it =
      51          38 :         rim->name_clower_bound(data->next_entry);
      52         150 :     for (uint32_t iter_count = 0; it != rim->name_cend(); ++it, ++iter_count) {
      53         112 :         RoutingInstance *rinstance = it->second;
      54         112 :         StaticRouteEntriesInfo info;
      55         112 :         if (FillStaticRouteInfo(Address::INET, data->search_string,
      56             :                                 search_expr, info, rinstance)) {
      57          19 :             data->show_list.push_back(info);
      58             :         }
      59         112 :         if (FillStaticRouteInfo(Address::INET6, data->search_string,
      60             :                                 search_expr, info, rinstance)) {
      61          19 :             data->show_list.push_back(info);
      62             :         }
      63             : 
      64         112 :         if (data->show_list.size() >= page_limit)
      65           0 :             break;
      66         112 :         if (iter_count >= iter_limit)
      67           0 :             break;
      68         112 :     }
      69             : 
      70             :     // All done if we've looked at all instances.
      71          38 :     if (it == rim->name_cend() || ++it == rim->name_cend())
      72          38 :         return true;
      73             : 
      74             :     // Return true if we've reached the page limit, false if we've reached the
      75             :     // iteration limit.
      76           0 :     bool done = data->show_list.size() >= page_limit;
      77           0 :     SaveContextToData(it->second->name(), done, data);
      78           0 :     return done;
      79          38 : }
      80             : 
      81             : // Specialization of BgpShowHandler<>::FillShowList.
      82             : template <>
      83          38 : void BgpShowHandler<ShowStaticRouteReq, ShowStaticRouteReqIterate,
      84             :     ShowStaticRouteResp, StaticRouteEntriesInfo>::FillShowList(
      85             :         ShowStaticRouteResp *resp,
      86             :         const vector<StaticRouteEntriesInfo> &show_list) {
      87          38 :     resp->set_static_route_entries(show_list);
      88          38 : }
      89             : 
      90             : // Handler for ShowStaticRouteReq.
      91          38 : void ShowStaticRouteReq::HandleRequest() const {
      92          38 :     RequestPipeline::PipeSpec ps(this);
      93          38 :     RequestPipeline::StageSpec s1;
      94          38 :     TaskScheduler *scheduler = TaskScheduler::GetInstance();
      95             : 
      96          38 :     s1.taskId_ = scheduler->GetTaskId("bgp::StaticRoute");
      97             :     s1.cbFn_ = boost::bind(&BgpShowHandler<
      98             :         ShowStaticRouteReq,
      99             :         ShowStaticRouteReqIterate,
     100             :         ShowStaticRouteResp,
     101          38 :         StaticRouteEntriesInfo>::Callback, _1, _2, _3, _4, _5);
     102             :     s1.allocFn_ = BgpShowHandler<
     103             :         ShowStaticRouteReq,
     104             :         ShowStaticRouteReqIterate,
     105             :         ShowStaticRouteResp,
     106          38 :         StaticRouteEntriesInfo>::CreateData;
     107          38 :     s1.instances_.push_back(0);
     108          38 :     ps.stages_.push_back(s1);
     109          38 :     RequestPipeline rp(ps);
     110          38 : }
     111             : 
     112             : //
     113             : // Handler for ShowStaticRouteReqIterate.
     114             : //
     115           0 : void ShowStaticRouteReqIterate::HandleRequest() const {
     116           0 :     RequestPipeline::PipeSpec ps(this);
     117           0 :     RequestPipeline::StageSpec s1;
     118           0 :     TaskScheduler *scheduler = TaskScheduler::GetInstance();
     119             : 
     120           0 :     s1.taskId_ = scheduler->GetTaskId("bgp::StaticRoute");
     121             :     s1.cbFn_ = boost::bind(&BgpShowHandler<
     122             :         ShowStaticRouteReq,
     123             :         ShowStaticRouteReqIterate,
     124             :         ShowStaticRouteResp,
     125           0 :         StaticRouteEntriesInfo>::CallbackIterate, _1, _2, _3, _4, _5);
     126             :     s1.allocFn_ = BgpShowHandler<
     127             :         ShowStaticRouteReq,
     128             :         ShowStaticRouteReqIterate,
     129             :         ShowStaticRouteResp,
     130           0 :         StaticRouteEntriesInfo>::CreateData;
     131           0 :     s1.instances_.push_back(0);
     132           0 :     ps.stages_.push_back(s1);
     133           0 :     RequestPipeline rp(ps);
     134           0 : }

Generated by: LCOV version 1.14