LCOV - code coverage report
Current view: top level - bgp - bgp_ribout.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 197 322 61.2 %
Date: 2026-11-23 02:04:52 Functions: 23 33 69.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #include "bgp/bgp_ribout.h"
       7             : 
       8             : #include <boost/bind/bind.hpp>
       9             : 
      10             : #include <algorithm>
      11             : 
      12             : #include "sandesh/sandesh_trace.h"
      13             : #include "base/string_util.h"
      14             : #include "bgp/bgp_peer_types.h"
      15             : #include "bgp/bgp_ribout_updates.h"
      16             : #include "bgp/bgp_export.h"
      17             : #include "bgp/bgp_factory.h"
      18             : #include "bgp/bgp_route.h"
      19             : #include "bgp/bgp_server.h"
      20             : #include "bgp/bgp_table.h"
      21             : #include "bgp/bgp_update.h"
      22             : #include "bgp/bgp_update_sender.h"
      23             : #include "bgp/ipeer.h"
      24             : #include "bgp/routing-instance/routing_instance.h"
      25             : #include "db/db.h"
      26             : 
      27             : using std::find;
      28             : using namespace boost::placeholders;
      29             : 
      30        2849 : RibOutAttr::NextHop::NextHop(const BgpTable *table, IpAddress address,
      31             :     const MacAddress &mac, uint32_t label, uint32_t l3_label,
      32             :     const ExtCommunity *ext_community, const LargeCommunity *large_community,
      33        2849 :     bool vrf_originated)
      34        2849 :     : address_(address),
      35        2849 :       mac_(mac),
      36        2849 :       label_(label),
      37        2849 :       l3_label_(l3_label),
      38        2849 :       origin_vn_index_(-1) {
      39        2849 :       as_t asn = table ? table->server()->autonomous_system() : 0;
      40        5698 :       bool all = table ?
      41        2849 :           table->server()->global_config()->all_tags_are_global() : false;
      42        2849 :     if (large_community != nullptr) {
      43         320 :         tag_list_ = large_community->GetTagList(all ? 0 : asn);
      44             :     }
      45        2849 :     if (ext_community != nullptr) {
      46        2849 :         encap_ = ext_community->GetTunnelEncap();
      47        2851 :         origin_vn_index_ = ext_community->GetOriginVnIndex();
      48             :     }
      49             : 
      50        2851 :     if (origin_vn_index_ < 0 && vrf_originated) {
      51        2851 :         origin_vn_index_ =
      52        2851 :             table ? table->routing_instance()->virtual_network_index() : 0;
      53             :     }
      54        2851 : }
      55             : 
      56       10702 : int RibOutAttr::NextHop::CompareTo(const NextHop &rhs) const {
      57       10702 :     KEY_COMPARE(address_, rhs.address_);
      58       10446 :     KEY_COMPARE(mac_, rhs.mac_) ;
      59       10445 :     KEY_COMPARE(label_, rhs.label_);
      60       10445 :     KEY_COMPARE(l3_label_, rhs.l3_label_);
      61       10445 :     KEY_COMPARE(source_address_, rhs.source_address_);
      62       10446 :     KEY_COMPARE(origin_vn_index_, rhs.origin_vn_index_);
      63       10446 :     KEY_COMPARE(encap_.size(), rhs.encap_.size());
      64       20886 :     for (size_t idx = 0; idx < encap_.size(); ++idx) {
      65       10445 :         KEY_COMPARE(encap_[idx], rhs.encap_[idx]);
      66             :     }
      67       10441 :     KEY_COMPARE(tag_list_.size(), rhs.tag_list_.size());
      68       10441 :     for (size_t idx = 0; idx < tag_list_.size(); ++idx) {
      69           0 :         KEY_COMPARE(tag_list_[idx], rhs.tag_list_[idx]);
      70             :     }
      71       10441 :     return 0;
      72             : }
      73             : 
      74         256 : bool RibOutAttr::NextHop::operator==(const NextHop &rhs) const {
      75         256 :     return CompareTo(rhs) == 0;
      76             : }
      77             : 
      78           0 : bool RibOutAttr::NextHop::operator!=(const NextHop &rhs) const {
      79           0 :     return CompareTo(rhs) != 0;
      80             : }
      81             : 
      82       10446 : bool RibOutAttr::NextHop::operator<(const NextHop &rhs) const {
      83       10446 :     return CompareTo(rhs) < 0;
      84             : }
      85             : 
      86        9230 : RibOutAttr::RibOutAttr()
      87        9227 :     : label_(0),
      88        9227 :       l3_label_(0),
      89        9228 :       is_xmpp_(false),
      90        9230 :       vrf_originated_(false) {
      91        9228 : }
      92             : 
      93             : //
      94             : // Copy constructor.
      95             : // Do not copy the string representation;
      96             : //
      97        5786 : RibOutAttr::RibOutAttr(const RibOutAttr &rhs) {
      98        5786 :     attr_out_ = rhs.attr_out_;
      99        5791 :     nexthop_list_ = rhs.nexthop_list_;
     100        5787 :     label_ = rhs.label_;
     101        5787 :     l3_label_ = rhs.l3_label_;
     102        5787 :     source_address_ = rhs.source_address_;
     103        5787 :     is_xmpp_ = rhs.is_xmpp_;
     104        5787 :     vrf_originated_ = rhs.vrf_originated_;
     105        5787 : }
     106             : 
     107           0 : RibOutAttr::RibOutAttr(const BgpTable *table, const BgpAttr *attr,
     108           0 :     uint32_t label, uint32_t l3_label, bool is_xmpp)
     109           0 :     : attr_out_(attr),
     110           0 :       label_(label),
     111           0 :       l3_label_(l3_label),
     112           0 :       is_xmpp_(is_xmpp),
     113           0 :       vrf_originated_(false) {
     114           0 :     if (attr && is_xmpp) {
     115           0 :         nexthop_list_.push_back(NextHop(table, attr->nexthop(),
     116           0 :             attr->mac_address(), label, l3_label, attr->ext_community(),
     117             :             attr->large_community(), false));
     118             :     }
     119           0 : }
     120             : 
     121           0 : RibOutAttr::RibOutAttr(const BgpTable *table, const BgpRoute *route,
     122           0 :     const BgpAttr *attr, uint32_t label, bool include_nh, bool is_xmpp)
     123           0 :     : attr_out_(attr),
     124           0 :       label_(0),
     125           0 :       l3_label_(0),
     126           0 :       is_xmpp_(is_xmpp),
     127           0 :       vrf_originated_(route->BestPath()->IsVrfOriginated()) {
     128           0 :     if (attr && include_nh) {
     129           0 :         if (is_xmpp) {
     130           0 :             nexthop_list_.push_back(NextHop(table, attr->nexthop(),
     131           0 :                 attr->mac_address(), label, 0, attr->ext_community(),
     132           0 :                 attr->large_community(), vrf_originated_));
     133             :         } else {
     134           0 :             label_ = label;
     135           0 :             l3_label_ = 0;
     136             :         }
     137             :     }
     138           0 : }
     139             : 
     140        6998 : RibOutAttr::RibOutAttr(const BgpRoute *route, const BgpAttr *attr,
     141        6998 :                        bool is_xmpp) :
     142        6998 :         label_(0), l3_label_(0), is_xmpp_(is_xmpp), vrf_originated_(false) {
     143             :     // Attribute should not be set already
     144        6998 :     assert(!attr_out_);
     145             : 
     146        6998 :     const BgpTable *table = static_cast<const BgpTable *>(route->get_table());
     147             : 
     148             :     // Always encode best path's attributes (including it's nexthop) and label.
     149        6997 :     if (!is_xmpp) {
     150        4402 :         set_attr(table, attr, route->BestPath()->GetLabel(),
     151             :             route->BestPath()->GetL3Label(), false, is_xmpp);
     152        4404 :         return;
     153             :     }
     154             : 
     155             :     // Encode ECMP nexthops only for XMPP peers.
     156             :     // Vrf Origination matters only for XMPP peers.
     157        2596 :     set_attr(table, attr, route->BestPath()->GetLabel(),
     158        2595 :         route->BestPath()->GetL3Label(), route->BestPath()->IsVrfOriginated(),
     159             :         is_xmpp);
     160             : 
     161        2596 :     for (Route::PathList::const_iterator it = route->GetPathList().begin();
     162       10894 :         it != route->GetPathList().end(); ++it) {
     163        4935 :         const BgpPath *path = static_cast<const BgpPath *>(it.operator->());
     164             : 
     165             :         // Skip the best path.
     166        4935 :         if (path == route->BestPath())
     167        2596 :             continue;
     168             : 
     169             :         // Check if the path is ECMP eligible. If not, bail out, as the paths
     170             :         // are sorted in cost order anyways.
     171        2340 :         if (route->BestPath()->PathCompare(*path, true))
     172        2084 :             break;
     173             : 
     174             :         // We have an eligible ECMP path.
     175             :         // Remember if the path was originated in the VRF.  This is used to
     176             :         // determine if VRF's VN name can be used as the origin VN for the
     177             :         // nexthop.
     178         256 :         NextHop nexthop(table, path->GetAttr()->nexthop(),
     179         256 :             path->GetAttr()->mac_address(), path->GetLabel(),
     180             :             path->GetL3Label(), path->GetAttr()->ext_community(),
     181         512 :             path->GetAttr()->large_community(), path->IsVrfOriginated());
     182             : 
     183             :         // Skip if we have already encoded this next-hop
     184         256 :         if (find(nexthop_list_.begin(), nexthop_list_.end(), nexthop) !=
     185         512 :                 nexthop_list_.end()) {
     186           0 :             continue;
     187             :         }
     188         256 :         nexthop_list_.push_back(nexthop);
     189         256 :     }
     190           0 : }
     191             : 
     192             : //
     193             : // Assignment operator.
     194             : // Do not copy the string representation;
     195             : //
     196        6999 : RibOutAttr &RibOutAttr::operator=(const RibOutAttr &rhs) {
     197        6999 :     attr_out_ = rhs.attr_out_;
     198        7000 :     nexthop_list_ = rhs.nexthop_list_;
     199        6999 :     label_ = rhs.label_;
     200        6999 :     l3_label_ = rhs.l3_label_;
     201        6999 :     source_address_ = rhs.source_address_;
     202        6999 :     is_xmpp_ = rhs.is_xmpp_;
     203        6999 :     vrf_originated_ = rhs.vrf_originated_;
     204        6999 :     return *this;
     205             : }
     206             : 
     207             : //
     208             : // Comparator for RibOutAttr.
     209             : // First compare the BgpAttr and then the nexthops.
     210             : //
     211       13053 : int RibOutAttr::CompareTo(const RibOutAttr &rhs) const {
     212       13053 :     KEY_COMPARE(attr_out_.get(), rhs.attr_out_.get());
     213        6259 :     KEY_COMPARE(nexthop_list_.size(), rhs.nexthop_list_.size());
     214       11271 :     for (size_t idx = 0; idx < nexthop_list_.size(); ++idx) {
     215        5225 :         KEY_COMPARE(nexthop_list_[idx], rhs.nexthop_list_[idx]);
     216             :     }
     217        6046 :     KEY_COMPARE(label_, rhs.label());
     218        1208 :     KEY_COMPARE(l3_label_, rhs.l3_label());
     219        1208 :     KEY_COMPARE(source_address_, rhs.source_address());
     220        1208 :     KEY_COMPARE(is_xmpp_, rhs.is_xmpp());
     221        1208 :     KEY_COMPARE(vrf_originated_, rhs.vrf_originated());
     222        1208 :     return 0;
     223             : }
     224             : 
     225        9001 : void RibOutAttr::set_attr(const BgpTable *table, const BgpAttrPtr &attrp,
     226             :     uint32_t label, uint32_t l3_label, bool vrf_originated, bool is_xmpp) {
     227        9001 :     if (!attr_out_) {
     228        6999 :         attr_out_ = attrp;
     229        6999 :         assert(nexthop_list_.empty());
     230        6997 :         if (is_xmpp) {
     231        2594 :             NextHop nexthop(table, attrp->nexthop(), attrp->mac_address(),
     232             :                 label, l3_label, attrp->ext_community(),
     233        5188 :                 attrp->large_community(), vrf_originated);
     234        2595 :             nexthop_list_.push_back(nexthop);
     235        2595 :         } else {
     236        4402 :             label_ = label;
     237        4402 :             l3_label_ = l3_label;
     238             :         }
     239        6997 :         return;
     240             :     }
     241             : 
     242        2003 :     if (!attrp) {
     243           0 :         clear();
     244           0 :         return;
     245             :     }
     246             : 
     247        2002 :     assert(attr_out_->nexthop() == attrp->nexthop());
     248        2002 :     attr_out_ = attrp;
     249             : }
     250             : 
     251        5789 : RouteState::RouteState() {
     252        5790 : }
     253             : 
     254             : //
     255             : // Move history from RouteState to RouteUpdate.
     256             : //
     257        4694 : void RouteState::MoveHistory(RouteUpdate *rt_update) {
     258        4694 :     AdvertiseSList adv_slist;
     259        4694 :     SwapHistory(adv_slist);
     260        4694 :     rt_update->SwapHistory(adv_slist);
     261        4694 : }
     262             : 
     263             : //
     264             : // Find the AdvertiseInfo element with matching RibOutAttr.
     265             : //
     266        3670 : const AdvertiseInfo *RouteState::FindHistory(
     267             :         const RibOutAttr &roattr) const {
     268        6132 :     for (AdvertiseSList::List::const_iterator iter = advertised_->begin();
     269       12264 :          iter != advertised_->end(); iter++) {
     270        4878 :         if (iter->roattr == roattr) return iter.operator->();
     271             :     }
     272        2462 :     return NULL;
     273             : }
     274             : 
     275             : //
     276             : // Compare AdevrtiseInfos in this RouteState with the UpdateInfo elements
     277             : // in the given list.
     278             : //
     279             : // Uses brute force since the UpdateInfo and AdvertiseInfo lists typically
     280             : // contain just a single element.
     281             : //
     282             : // Return true if the information in the RouteState is same as that in the
     283             : // UpdateInfoSList.
     284             : //
     285        5903 : bool RouteState::CompareUpdateInfo(const UpdateInfoSList &uinfo_slist) const {
     286             :     // Both lists must have the same number of elements.
     287        5903 :     if (uinfo_slist->size() != advertised_->size())
     288        2231 :         return false;
     289             : 
     290             :     // Compare the peerset for each UpdateInfo in the UpdateInfoSList to
     291             :     // the peerset for the corresponding AdvertiseInfo in the advertised
     292             :     // list.
     293        3672 :     for (UpdateInfoSList::List::const_iterator iter = uinfo_slist->begin();
     294        9757 :          iter != uinfo_slist->end(); ++iter) {
     295        3670 :         const AdvertiseInfo *ainfo = FindHistory(iter->roattr);
     296        4878 :         if (!ainfo || iter->target != ainfo->bitset)
     297        2462 :             return false;
     298             :     }
     299             : 
     300        1208 :     return true;
     301             : }
     302             : 
     303             : //
     304             : // Create a new RibOut based on the BgpTable and RibExportPolicy.
     305             : //
     306         862 : RibOut::RibOut(BgpTable *table, BgpUpdateSender *sender,
     307         862 :                const RibExportPolicy &policy)
     308         862 :     : table_(table),
     309         862 :       sender_(sender),
     310         862 :       policy_(policy),
     311         862 :       listener_id_(DBTableBase::kInvalidId),
     312         862 :       bgp_export_(BgpStaticObjectFactory::Create<BgpExport>(this)) {
     313         862 :     name_ = "RibOut";
     314         862 :     if (policy_.type == BgpProto::XMPP) {
     315         170 :         name_ += " Type: XMPP";
     316         692 :     } else if (policy_.type == BgpProto::IBGP) {
     317         500 :         name_ += " Type: IBGP";
     318             :     } else {
     319         192 :         name_ += " Type: EBGP";
     320         192 :         name_ += " (AS " + integerToString(policy_.as_number);
     321         192 :         if (!policy_.nexthop.is_unspecified())
     322          96 :             name_ += " Nexthop " + policy_.nexthop.to_string();
     323         192 :         if (policy_.as_override)
     324           0 :             name_ += " ASOverride";
     325         192 :         name_ += ")";
     326             :     }
     327        4310 :     for (int idx = 0; idx < DB::PartitionCount(); ++idx) {
     328        3448 :         updates_.push_back(BgpStaticObjectFactory::Create<RibOutUpdates>(this, idx));
     329             :     }
     330         862 : }
     331             : 
     332             : //
     333             : // Destructor for RibOut.  Takes care of unregistering the RibOut from
     334             : // the DBTableBase.
     335             : //
     336         862 : RibOut::~RibOut() {
     337         862 :     if (listener_id_ != DBTableBase::kInvalidId) {
     338         862 :         table_->Unregister(listener_id_);
     339         862 :         listener_id_ = DBTableBase::kInvalidId;
     340             :     }
     341         862 :     STLDeleteValues(&updates_);
     342         862 : }
     343             : 
     344             : //
     345             : // Register the RibOut as a listener with the underlying DBTableBase. This
     346             : // is separated out from the constructor to let the unit testing code work
     347             : // using the bare bones RibOut functionality.
     348             : //
     349             : // Note that the corresponding unregister from the DBTableBase will happen
     350             : // implicitly from the destructor.
     351             : //
     352         862 : void RibOut::RegisterListener() {
     353         862 :     if (listener_id_ != DBTableBase::kInvalidId)
     354           0 :         return;
     355         862 :     listener_id_ = table_->Register(
     356             :         boost::bind(&BgpExport::Export, bgp_export_.get(), _1, _2),
     357             :         ToString());
     358             : }
     359             : 
     360             : //
     361             : // Register a new peer to the RibOut. If the peer is not present in the
     362             : // PeerStateMap, create a new PeerState and add it to the map.
     363             : // Join the IPeerUpdate to the UPDATE and BULK queues for all RibOutUpdates
     364             : // associated with the RibOut.
     365             : //
     366         862 : void RibOut::Register(IPeerUpdate *peer) {
     367         862 :     PeerState *ps = state_map_.Locate(peer);
     368         862 :     assert(ps != NULL);
     369         862 :     active_peerset_.set(ps->index);
     370         862 :     sender_->Join(this, peer);
     371        4310 :     for (int idx = 0; idx < DB::PartitionCount(); ++idx) {
     372        3448 :         if (updates_[idx]->QueueJoin(RibOutUpdates::QUPDATE, ps->index))
     373           0 :             sender_->RibOutActive(idx, this, RibOutUpdates::QUPDATE);
     374        3448 :         if (updates_[idx]->QueueJoin(RibOutUpdates::QBULK, ps->index))
     375           0 :             sender_->RibOutActive(idx, this, RibOutUpdates::QBULK);
     376             :     }
     377         862 : }
     378             : 
     379             : //
     380             : // Unregister a IPeerUpdate from the RibOut.
     381             : // Leave the IPeerUpdate from the UPDATE and BULK queues for all RibOutUpdates
     382             : // associated with the RibOut.
     383             : // Removes the IPeerUpdate from the PeerStateMap.
     384             : // If this was the last IPeerUpdate in the RibOut, remove the RibOut from the
     385             : // BgpTable.  That will cause this RibOut itself to get destroyed.
     386             : //
     387         862 : void RibOut::Unregister(IPeerUpdate *peer) {
     388         862 :     PeerState *ps = state_map_.Find(peer);
     389         862 :     assert(ps != NULL);
     390         862 :     assert(!active_peerset_.test(ps->index));
     391             : 
     392        4310 :     for (int idx = 0; idx < DB::PartitionCount(); ++idx) {
     393        3448 :         updates_[idx]->QueueLeave(RibOutUpdates::QUPDATE, ps->index);
     394        3448 :         updates_[idx]->QueueLeave(RibOutUpdates::QBULK, ps->index);
     395             :     }
     396         862 :     sender_->Leave(this, peer);
     397         862 :     state_map_.Remove(peer, ps->index);
     398             : 
     399         862 :     if (state_map_.empty()) {
     400         862 :         table_->RibOutDelete(policy_);
     401             :     }
     402         862 : }
     403             : 
     404             : //
     405             : // Return true if the IPeerUpdate is registered to this RibOut.
     406             : //
     407           0 : bool RibOut::IsRegistered(IPeerUpdate *peer) {
     408           0 :     PeerState *ps = state_map_.Find(peer);
     409           0 :     return (ps != NULL);
     410             : }
     411             : 
     412             : //
     413             : // Deactivate a IPeerUpdate from the RibOut. Removes it from the RibPeerSet of
     414             : // active peers without removing it from the PeerStateMap.
     415             : //
     416             : // This must be called when the peer starts the process of leaving the RibOut
     417             : // in order to prevent any new or existing routes from getting exported while
     418             : // the route table walk for the leave processing is in progress.
     419             : //
     420         862 : void RibOut::Deactivate(IPeerUpdate *peer) {
     421         862 :     PeerState *ps = state_map_.Find(peer);
     422         862 :     assert(ps != NULL);
     423         862 :     assert(active_peerset_.test(ps->index));
     424         862 :     active_peerset_.reset(ps->index);
     425         862 : }
     426             : 
     427           0 : bool RibOut::IsActive(IPeerUpdate *peer) const {
     428           0 :     int index = GetPeerIndex(peer);
     429           0 :     return (index < 0 ? false : active_peerset_.test(index));
     430             : }
     431             : 
     432             : //
     433             : // Build the subset of given RibPeerSet in this RibOut that are send ready.
     434             : //
     435           0 : void RibOut::BuildSendReadyBitSet(const RibPeerSet &peerset,
     436             :     RibPeerSet *mready) const {
     437           0 :     for (size_t bit = peerset.find_first(); bit != RibPeerSet::npos;
     438           0 :          bit = peerset.find_next(bit)) {
     439           0 :         IPeerUpdate *peer = GetPeer(bit);
     440           0 :         if (peer->send_ready()) {
     441           0 :             mready->set(bit);
     442             :         }
     443             :     }
     444           0 : }
     445             : 
     446             : //
     447             : // Return the number of peers this route has been advertised to.
     448             : //
     449           0 : int RibOut::RouteAdvertiseCount(const BgpRoute *rt) const {
     450           0 :     const DBState *dbstate = rt->GetState(table_, listener_id_);
     451           0 :     if (dbstate == NULL) {
     452           0 :         return 0;
     453             :     }
     454             : 
     455           0 :     const RouteState *rstate = dynamic_cast<const RouteState *>(dbstate);
     456           0 :     if (rstate != NULL) {
     457           0 :         int count = 0;
     458           0 :         for (AdvertiseSList::List::const_iterator iter =
     459           0 :              rstate->Advertised()->begin();
     460           0 :              iter != rstate->Advertised()->end(); ++iter) {
     461           0 :             count += iter->bitset.count();
     462             :         }
     463           0 :         return count;
     464             :     }
     465             : 
     466           0 :     const RouteUpdate *rt_update = dynamic_cast<const RouteUpdate *>(dbstate);
     467           0 :     if (rt_update != NULL) {
     468           0 :         int count = 0;
     469           0 :         for (AdvertiseSList::List::const_iterator iter =
     470           0 :              rt_update->History()->begin();
     471           0 :              iter != rt_update->History()->end(); ++iter) {
     472           0 :             count += iter->bitset.count();
     473             :         }
     474           0 :         return count;
     475             :     }
     476             : 
     477           0 :     const UpdateList *uplist = dynamic_cast<const UpdateList *>(dbstate);
     478           0 :     if (uplist != NULL) {
     479           0 :         int count = 0;
     480           0 :         for (AdvertiseSList::List::const_iterator iter =
     481           0 :              uplist->History()->begin();
     482           0 :              iter != uplist->History()->end(); ++iter) {
     483           0 :             count += iter->bitset.count();
     484             :         }
     485           0 :         return count;
     486             :     }
     487             : 
     488           0 :     return 0;
     489             : }
     490             : 
     491             : //
     492             : // Return the total queue size across all RibOutUpdates and UpdateQueues.
     493             : //
     494           0 : uint32_t RibOut::GetQueueSize() const {
     495           0 :     uint32_t queue_size = 0;
     496           0 :     for (int idx = 0; idx < DB::PartitionCount(); ++idx) {
     497           0 :         const RibOutUpdates *updates = updates_[idx];
     498           0 :         for (int qid = RibOutUpdates::QFIRST; qid < RibOutUpdates::QCOUNT;
     499             :              ++qid) {
     500           0 :             queue_size += updates->queue_size(qid);
     501             :         }
     502             :     }
     503           0 :     return queue_size;
     504             : }
     505             : 
     506             : //
     507             : // Return the active RibPeerSet for this RibOut.  We keep track of the active
     508             : // peers via the calls to Register and Deactivate.
     509             : //
     510             : // The active RibPeerSet is always a subset of the registered RibPeerSet that
     511             : // is in the PeerStateMap.
     512             : //
     513       21875 : const RibPeerSet &RibOut::PeerSet() const {
     514       21875 :     return active_peerset_;
     515             : }
     516             : 
     517             : //
     518             : // Clear the bit index corresponding to the specified peer.
     519             : // Used to implement split horizon within an EBGP Ribout.
     520             : //
     521           0 : void RibOut::GetSubsetPeerSet(RibPeerSet *peerset,
     522             :     const IPeerUpdate *cpeer) const {
     523           0 :     assert(policy_.type == BgpProto::EBGP);
     524           0 :     IPeerUpdate *peer = const_cast<IPeerUpdate *>(cpeer);
     525           0 :     int index = GetPeerIndex(peer);
     526           0 :     if (index < 0)
     527           0 :         return;
     528           0 :     peerset->reset(index);
     529             : }
     530             : 
     531             : //
     532             : // Return the peer corresponding to the specified bit index.
     533             : //
     534       13744 : IPeerUpdate *RibOut::GetPeer(int index) const {
     535       13744 :     PeerState *ps = state_map_.At(index);
     536       13744 :     if (ps != NULL) {
     537       13745 :         return ps->peer;
     538             :     }
     539           0 :     return NULL;
     540             : }
     541             : 
     542             : //
     543             : // Return the bit index corresponding to the specified peer.
     544             : //
     545        8450 : int RibOut::GetPeerIndex(IPeerUpdate *peer) const {
     546        8450 :     PeerState *ps = state_map_.Find(peer);
     547        8451 :     return (ps ? ps->index : -1);
     548             : }
     549             : 
     550             : //
     551             : // Fill introspect information.
     552             : // Accumulate counters from all RibOutUpdates.
     553             : //
     554           0 : void RibOut::FillStatisticsInfo(vector<ShowRibOutStatistics> *sros_list) const {
     555           0 :     for (int qid = RibOutUpdates::QFIRST; qid < RibOutUpdates::QCOUNT; ++qid) {
     556             :         RibOutUpdates::Stats stats;
     557           0 :         memset(&stats, 0, sizeof(stats));
     558           0 :         size_t queue_size = 0;
     559           0 :         size_t queue_marker_count = 0;
     560           0 :         for (int idx = 0; idx < DB::PartitionCount(); ++idx) {
     561           0 :             const RibOutUpdates *updates = updates_[idx];
     562           0 :             updates->AddStatisticsInfo(qid, &stats);
     563           0 :             queue_size += updates->queue_size(qid);
     564           0 :             queue_marker_count += updates->queue_marker_count(qid);
     565             :         }
     566             : 
     567           0 :         ShowRibOutStatistics sros;
     568           0 :         sros.set_table(table_->name());
     569           0 :         sros.set_encoding(EncodingString());
     570           0 :         sros.set_peer_type(BgpProto::BgpPeerTypeString(peer_type()));
     571           0 :         sros.set_peer_as(peer_as());
     572           0 :         sros.set_peers(state_map_.size());
     573           0 :         sros.set_queue(qid == RibOutUpdates::QBULK ? "BULK" : "UPDATE");
     574           0 :         sros.set_pending_updates(queue_size);
     575           0 :         sros.set_markers(queue_marker_count);
     576           0 :         sros.set_messages_built(stats.messages_built_count_);
     577           0 :         sros.set_messages_sent(stats.messages_sent_count_);
     578           0 :         sros.set_reach(stats.reach_count_);
     579           0 :         sros.set_unreach(stats.unreach_count_);
     580           0 :         sros.set_tail_dequeues(stats.tail_dequeue_count_);
     581           0 :         sros.set_peer_dequeues(stats.peer_dequeue_count_);
     582           0 :         sros.set_marker_splits(stats.marker_split_count_);
     583           0 :         sros.set_marker_merges(stats.marker_merge_count_);
     584           0 :         sros.set_marker_moves(stats.marker_move_count_);
     585           0 :         sros_list->push_back(sros);
     586           0 :     }
     587           0 : }

Generated by: LCOV version 1.14