LCOV - code coverage report
Current view: top level - bgp - bgp_show_neighbor.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 0 90 0.0 %
Date: 2026-09-28 02:13:17 Functions: 0 9 0.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.h"
       9             : #include "bgp/bgp_peer_internal_types.h"
      10             : #include "bgp/bgp_server.h"
      11             : #include "bgp/routing-instance/peer_manager.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             : // Build the list of BgpPeers in one shot for now.
      22             : //
      23           0 : static bool FillBgpNeighborInfoList(const BgpSandeshContext *bsc,
      24             :     bool summary, uint32_t page_limit, uint32_t iter_limit,
      25             :     const string &start_neighbor, const string &search_string,
      26             :     vector<BgpNeighborResp> *show_list, string *next_instance) {
      27           0 :     regex search_expr(search_string);
      28             : 
      29           0 :     for (const BgpPeer *peer = bsc->bgp_server->FindNextPeer(); peer != NULL;
      30           0 :          peer = bsc->bgp_server->FindNextPeer(peer->peer_name())) {
      31           0 :         if ((!regex_search(peer->peer_basename(), search_expr)) &&
      32           0 :             (!regex_search(peer->peer_address_string(), search_expr)) &&
      33           0 :             (search_string != "deleted" || !peer->IsDeleted())) {
      34           0 :             continue;
      35             :         }
      36             : 
      37           0 :         BgpNeighborResp bnr;
      38           0 :         peer->FillNeighborInfo(bsc, &bnr, summary);
      39           0 :         show_list->push_back(bnr);
      40           0 :     }
      41           0 :     return true;
      42           0 : }
      43             : 
      44             : //
      45             : // Specialization of BgpShowHandler<>::CallbackCommon for regular introspect.
      46             : //
      47             : // Note that we don't both paginating bgp neighbors since the list should be
      48             : // pretty small. We always add at least one xmpp neighbor to the list and then
      49             : // paginate the xmpp neighbors as needed.
      50             : //
      51             : template <>
      52           0 : bool BgpShowHandler<BgpNeighborReq, BgpNeighborReqIterate,
      53             :     BgpNeighborListResp, BgpNeighborResp>::CallbackCommon(
      54             :     const BgpSandeshContext *bsc, Data *data) {
      55           0 :     uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
      56           0 :     uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
      57             : 
      58             :     // Build the list of BgpPeers in one shot for now.
      59           0 :     if (data->next_entry.empty()) {
      60           0 :         FillBgpNeighborInfoList(bsc, false, page_limit, iter_limit, string(),
      61           0 :             data->search_string, &data->show_list, NULL);
      62             :     }
      63             : 
      64             :     // Add xmpp neighbors.
      65           0 :     string next_neighbor;
      66           0 :     bool done = bsc->ShowNeighborExtension(bsc, false, page_limit, iter_limit,
      67           0 :         data->next_entry, data->search_string, &data->show_list,
      68             :         &next_neighbor);
      69           0 :     if (!next_neighbor.empty())
      70           0 :         SaveContextToData(next_neighbor, done, data);
      71           0 :     return done;
      72           0 : }
      73             : 
      74             : //
      75             : // Specialization of BgpShowHandler<>::FillShowList for regular introspect.
      76             : //
      77             : template <>
      78           0 : void BgpShowHandler<BgpNeighborReq, BgpNeighborReqIterate,
      79             :     BgpNeighborListResp, BgpNeighborResp>::FillShowList(
      80             :     BgpNeighborListResp *resp, const vector<BgpNeighborResp> &show_list) {
      81           0 :     resp->set_neighbors(show_list);
      82           0 : }
      83             : 
      84             : //
      85             : // Specialization of BgpShowHandler<>::CallbackCommon for summary introspect.
      86             : //
      87             : // Note that we don't both paginating bgp neighbors since the list should be
      88             : // pretty small. We always add at least one xmpp neighbor to the list and then
      89             : // paginate the xmpp neighbors as needed.
      90             : //
      91             : template <>
      92           0 : bool BgpShowHandler<ShowBgpNeighborSummaryReq, ShowBgpNeighborSummaryReqIterate,
      93             :     ShowBgpNeighborSummaryResp, BgpNeighborResp>::CallbackCommon(
      94             :     const BgpSandeshContext *bsc, Data *data) {
      95           0 :     uint32_t page_limit = bsc->page_limit() ? bsc->page_limit() : kPageLimit;
      96           0 :     uint32_t iter_limit = bsc->iter_limit() ? bsc->iter_limit() : kIterLimit;
      97             : 
      98             :     // Build the list of BgpPeers in one shot for now.
      99           0 :     if (data->next_entry.empty()) {
     100           0 :         FillBgpNeighborInfoList(bsc, true, page_limit, iter_limit, string(),
     101           0 :             data->search_string, &data->show_list, NULL);
     102             :     }
     103             : 
     104             :     // Add xmpp neighbors.
     105           0 :     string next_neighbor;
     106           0 :     bool done = bsc->ShowNeighborExtension(bsc, true, page_limit, iter_limit,
     107           0 :         data->next_entry, data->search_string, &data->show_list,
     108             :         &next_neighbor);
     109           0 :     if (!next_neighbor.empty())
     110           0 :         SaveContextToData(next_neighbor, done, data);
     111           0 :     return done;
     112           0 : }
     113             : 
     114             : //
     115             : // Specialization of BgpShowHandler<>::FillShowList for summary introspect.
     116             : //
     117             : template <>
     118           0 : void BgpShowHandler<ShowBgpNeighborSummaryReq, ShowBgpNeighborSummaryReqIterate,
     119             :     ShowBgpNeighborSummaryResp, BgpNeighborResp>::FillShowList(
     120             :     ShowBgpNeighborSummaryResp *resp,
     121             :     const vector<BgpNeighborResp> &show_list) {
     122           0 :     resp->set_neighbors(show_list);
     123           0 : }
     124             : 
     125             : //
     126             : // Handler for BgpNeighborReq.
     127             : //
     128           0 : void BgpNeighborReq::HandleRequest() const {
     129           0 :     RequestPipeline::PipeSpec ps(this);
     130           0 :     RequestPipeline::StageSpec s1;
     131           0 :     TaskScheduler *scheduler = TaskScheduler::GetInstance();
     132             : 
     133           0 :     s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
     134             :     s1.cbFn_ = boost::bind(&BgpShowHandler<
     135             :         BgpNeighborReq,
     136             :         BgpNeighborReqIterate,
     137             :         BgpNeighborListResp,
     138           0 :         BgpNeighborResp>::Callback, _1, _2, _3, _4, _5);
     139             :     s1.allocFn_ = BgpShowHandler<
     140             :         BgpNeighborReq,
     141             :         BgpNeighborReqIterate,
     142             :         BgpNeighborListResp,
     143           0 :         BgpNeighborResp>::CreateData;
     144           0 :     s1.instances_.push_back(0);
     145           0 :     ps.stages_.push_back(s1);
     146           0 :     RequestPipeline rp(ps);
     147           0 : }
     148             : 
     149             : //
     150             : // Handler for BgpNeighborReqIterate.
     151             : //
     152           0 : void BgpNeighborReqIterate::HandleRequest() const {
     153           0 :     RequestPipeline::PipeSpec ps(this);
     154           0 :     RequestPipeline::StageSpec s1;
     155           0 :     TaskScheduler *scheduler = TaskScheduler::GetInstance();
     156             : 
     157           0 :     s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
     158             :     s1.cbFn_ = boost::bind(&BgpShowHandler<
     159             :         BgpNeighborReq,
     160             :         BgpNeighborReqIterate,
     161             :         BgpNeighborListResp,
     162           0 :         BgpNeighborResp>::CallbackIterate, _1, _2, _3, _4, _5);
     163             :     s1.allocFn_ = BgpShowHandler<
     164             :         BgpNeighborReq,
     165             :         BgpNeighborReqIterate,
     166             :         BgpNeighborListResp,
     167           0 :         BgpNeighborResp>::CreateData;
     168           0 :     s1.instances_.push_back(0);
     169           0 :     ps.stages_.push_back(s1);
     170           0 :     RequestPipeline rp(ps);
     171           0 : }
     172             : 
     173             : //
     174             : // Handler for ShowBgpNeighborSummaryReq.
     175             : //
     176           0 : void ShowBgpNeighborSummaryReq::HandleRequest() const {
     177           0 :     RequestPipeline::PipeSpec ps(this);
     178           0 :     RequestPipeline::StageSpec s1;
     179           0 :     TaskScheduler *scheduler = TaskScheduler::GetInstance();
     180             : 
     181           0 :     s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
     182             :     s1.cbFn_ = boost::bind(&BgpShowHandler<
     183             :         ShowBgpNeighborSummaryReq,
     184             :         ShowBgpNeighborSummaryReqIterate,
     185             :         ShowBgpNeighborSummaryResp,
     186           0 :         BgpNeighborResp>::Callback, _1, _2, _3, _4, _5);
     187             :     s1.allocFn_ = BgpShowHandler<
     188             :         ShowBgpNeighborSummaryReq,
     189             :         ShowBgpNeighborSummaryReqIterate,
     190             :         ShowBgpNeighborSummaryResp,
     191           0 :         BgpNeighborResp>::CreateData;
     192           0 :     s1.instances_.push_back(0);
     193           0 :     ps.stages_.push_back(s1);
     194           0 :     RequestPipeline rp(ps);
     195           0 : }
     196             : 
     197             : //
     198             : // Handler for ShowBgpNeighborSummaryReqIterate.
     199             : //
     200           0 : void ShowBgpNeighborSummaryReqIterate::HandleRequest() const {
     201           0 :     RequestPipeline::PipeSpec ps(this);
     202           0 :     RequestPipeline::StageSpec s1;
     203           0 :     TaskScheduler *scheduler = TaskScheduler::GetInstance();
     204             : 
     205           0 :     s1.taskId_ = scheduler->GetTaskId("bgp::ShowCommand");
     206             :     s1.cbFn_ = boost::bind(&BgpShowHandler<
     207             :         ShowBgpNeighborSummaryReq,
     208             :         ShowBgpNeighborSummaryReqIterate,
     209             :         ShowBgpNeighborSummaryResp,
     210           0 :         BgpNeighborResp>::CallbackIterate, _1, _2, _3, _4, _5);
     211             :     s1.allocFn_ = BgpShowHandler<
     212             :         ShowBgpNeighborSummaryReq,
     213             :         ShowBgpNeighborSummaryReqIterate,
     214             :         ShowBgpNeighborSummaryResp,
     215           0 :         BgpNeighborResp>::CreateData;
     216           0 :     s1.instances_.push_back(0);
     217           0 :     ps.stages_.push_back(s1);
     218           0 :     RequestPipeline rp(ps);
     219           0 : }

Generated by: LCOV version 1.14