LCOV - code coverage report
Current view: top level - bgp - bgp_multicast.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 63 582 10.8 %
Date: 2026-11-16 02:06:09 Functions: 18 80 22.5 %
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_multicast.h"
       7             : 
       8             : #include <boost/bind/bind.hpp>
       9             : #include <boost/foreach.hpp>
      10             : 
      11             : #include "base/string_util.h"
      12             : #include "base/task_annotations.h"
      13             : #include "bgp/bgp_log.h"
      14             : #include "bgp/bgp_mvpn.h"
      15             : #include "bgp/bgp_server.h"
      16             : #include "bgp/bgp_update.h"
      17             : #include "bgp/ermvpn/ermvpn_table.h"
      18             : #include "bgp/mvpn/mvpn_route.h"
      19             : #include "bgp/routing-instance/routing_instance.h"
      20             : #include "bgp/routing-instance/routing_instance_analytics_types.h"
      21             : #include "bgp/routing-instance/routing_instance_log.h"
      22             : #include "bgp/tunnel_encap/tunnel_encap.h"
      23             : 
      24             : using std::string;
      25             : using std::vector;
      26             : using namespace boost::placeholders;
      27             : 
      28             : class McastTreeManager::DeleteActor : public LifetimeActor {
      29             : public:
      30          80 :     explicit DeleteActor(McastTreeManager *tree_manager)
      31          80 :         : LifetimeActor(tree_manager->table_->routing_instance()->server()->
      32             :                 lifetime_manager()),
      33          80 :           tree_manager_(tree_manager) {
      34          80 :     }
      35         160 :     virtual ~DeleteActor() {
      36         160 :     }
      37             : 
      38          80 :     virtual bool MayDelete() const {
      39          80 :         return tree_manager_->MayDelete();
      40             :     }
      41             : 
      42          80 :     virtual void Shutdown() {
      43          80 :         tree_manager_->Shutdown();
      44          80 :     }
      45             : 
      46          80 :     virtual void Destroy() {
      47          80 :         tree_manager_->table_->DestroyTreeManager();
      48          80 :     }
      49             : 
      50             : private:
      51             :     McastTreeManager *tree_manager_;
      52             : };
      53             : 
      54             : //
      55             : // Constructor for McastForwarder.  The level is determined by the route type.
      56             : // We get the address of the forwarder and the label_block from the attributes
      57             : // of the active path.  The LabelBLockPtr needs to be copied so that we can
      58             : // release the label when processing a delete notification - we won't have the
      59             : // path at that point.
      60             : //
      61             : // The RD will be zero for BGP learnt routes and the RouterId will be zero for
      62             : // XMPP learnt routes.
      63             : //
      64           0 : McastForwarder::McastForwarder(McastSGEntry *sg_entry, ErmVpnRoute *route)
      65           0 :     : sg_entry_(sg_entry),
      66           0 :       route_(route),
      67           0 :       global_tree_route_(NULL),
      68           0 :       label_(0),
      69           0 :       address_(0),
      70           0 :       rd_(route->GetPrefix().route_distinguisher()),
      71           0 :       router_id_(route->GetPrefix().router_id()) {
      72           0 :     const BgpPath *path = route->BestPath();
      73           0 :     const BgpAttr *attr = path->GetAttr();
      74             : 
      75           0 :     if (route_->GetPrefix().type() == ErmVpnPrefix::NativeRoute) {
      76           0 :         level_ = McastTreeManager::LevelNative;
      77           0 :         address_ = attr->nexthop().to_v4();
      78           0 :         label_block_ = attr->label_block();
      79             :     } else {
      80           0 :         level_ = McastTreeManager::LevelLocal;
      81           0 :         const EdgeDiscovery::Edge *edge = attr->edge_discovery()->edge_list[0];
      82           0 :         address_ = edge->address;
      83           0 :         label_block_ = edge->label_block;
      84             :     }
      85             : 
      86           0 :     if (path->GetAttr()->ext_community())
      87           0 :         encap_ = path->GetAttr()->ext_community()->GetTunnelEncap();
      88           0 : }
      89             : 
      90             : //
      91             : // Destructor for McastForwarder. Flushes forward and reverse links to and
      92             : // from other McastForwarders.
      93             : //
      94           0 : McastForwarder::~McastForwarder() {
      95           0 :     DeleteGlobalTreeRoute();
      96           0 :     FlushLinks();
      97           0 :     ReleaseLabel();
      98           0 : }
      99             : 
     100             : //
     101             : // Update the McastForwarder based on information in the ErmVpnRoute.
     102             : // Return true if something changed.
     103             : //
     104           0 : bool McastForwarder::Update(ErmVpnRoute *route) {
     105           0 :     McastForwarder forwarder(sg_entry_, route);
     106             : 
     107           0 :     bool changed = false;
     108           0 :     if (label_block_ != forwarder.label_block_) {
     109           0 :         ReleaseLabel();
     110           0 :         label_block_ = forwarder.label_block_;
     111           0 :         changed = true;
     112             :     }
     113           0 :     if (address_ != forwarder.address_) {
     114           0 :         address_ = forwarder.address_;
     115           0 :         changed = true;
     116             :     }
     117           0 :     if (encap_ != forwarder.encap_) {
     118           0 :         encap_ = forwarder.encap_;
     119           0 :         changed = true;
     120             :     }
     121             : 
     122           0 :     return changed;
     123           0 : }
     124             : 
     125             : //
     126             : // Printable string for McastForwarder.
     127             : //
     128           0 : std::string McastForwarder::ToString() const {
     129           0 :     if (level_ == McastTreeManager::LevelNative) {
     130           0 :         return rd_.ToString() + " -> " + integerToString(label_);
     131             :     } else {
     132           0 :         return router_id_.to_string() + " -> " + integerToString(label_);
     133             :     }
     134             : }
     135             : 
     136             : //
     137             : // Find a link to the given McastForwarder.
     138             : //
     139           0 : McastForwarder *McastForwarder::FindLink(McastForwarder *forwarder) {
     140           0 :     for (McastForwarderList::iterator it = tree_links_.begin();
     141           0 :          it != tree_links_.end(); ++it) {
     142           0 :         if (*it == forwarder) return forwarder;
     143             :     }
     144           0 :     return NULL;
     145             : }
     146             : 
     147             : //
     148             : // Add a link to the given McastForwarder.
     149             : //
     150           0 : void McastForwarder::AddLink(McastForwarder *forwarder) {
     151           0 :     assert(!FindLink(forwarder));
     152           0 :     tree_links_.push_back(forwarder);
     153           0 : }
     154             : 
     155             : //
     156             : // Remove a link to the given McastForwarder.
     157             : //
     158           0 : void McastForwarder::RemoveLink(McastForwarder *forwarder) {
     159           0 :     for (McastForwarderList::iterator it = tree_links_.begin();
     160           0 :          it != tree_links_.end(); ++it) {
     161           0 :         if (*it == forwarder) {
     162           0 :             tree_links_.erase(it);
     163           0 :             return;
     164             :         }
     165             :     }
     166             : }
     167             : 
     168             : //
     169             : // Flush all links from this McastForwarder.  Takes care of removing the
     170             : // reverse links as well.
     171             : //
     172           0 : void McastForwarder::FlushLinks() {
     173           0 :     for (McastForwarderList::iterator it = tree_links_.begin();
     174           0 :          it != tree_links_.end(); ++it) {
     175           0 :         (*it)->RemoveLink(this);
     176             :     }
     177           0 :     tree_links_.clear();
     178           0 : }
     179             : 
     180             : //
     181             : // Allocate a label for this McastForwarder.  The label gets allocated from
     182             : // the LabelBlock corresponding to the label range advertised by the peer.
     183             : // This is used when updating the distribution tree for the McastSGEntry to
     184             : // this McastForwarder belongs.
     185             : //
     186           0 : void McastForwarder::AllocateLabel() {
     187           0 :     label_ = label_block_->AllocateLabel();
     188           0 : }
     189             : 
     190             : //
     191             : // Release the label, if any, for this McastForwarder. This is required when
     192             : // updating the distribution tree for the McastSGEntry to which we belong.
     193             : //
     194           0 : void McastForwarder::ReleaseLabel() {
     195           0 :     if (label_ != 0) {
     196           0 :         label_block_->ReleaseLabel(label_);
     197           0 :         label_ = 0;
     198             :     }
     199           0 : }
     200             : 
     201             : //
     202             : // Add the GlobalTreeRoute for this McastForwarder. The GlobalTreeRoute is
     203             : // used by the tree builder to tell the associated control-node about the
     204             : // forwarding edges for Native McastForwarders attached it.
     205             : //
     206           0 : void McastForwarder::AddGlobalTreeRoute() {
     207           0 :     assert(level_ == McastTreeManager::LevelLocal);
     208           0 :     assert(!global_tree_route_);
     209             : 
     210             :     // Bail if there's no label allocated.
     211           0 :     if (label_ == 0)
     212           0 :         return;
     213             : 
     214             :     // Bail if we can't build a source RD.
     215           0 :     if (sg_entry_->GetSourceRd().IsZero())
     216           0 :         return;
     217             : 
     218             :     // Construct the prefix and route key.
     219           0 :     BgpTable *table = static_cast<BgpTable *>(route_->get_table());
     220             :     ErmVpnPrefix prefix(ErmVpnPrefix::GlobalTreeRoute,
     221           0 :         RouteDistinguisher::kZeroRd, router_id_,
     222           0 :         sg_entry_->group(), sg_entry_->source());
     223           0 :     ErmVpnRoute rt_key(prefix);
     224             : 
     225             :     // Find or create the route.
     226           0 :     McastManagerPartition *partition = sg_entry_->partition();
     227             :     DBTablePartition *tbl_partition =
     228           0 :         static_cast<DBTablePartition *>(partition->GetTablePartition());
     229             :     ErmVpnRoute *route =
     230           0 :         static_cast<ErmVpnRoute *>(tbl_partition->Find(&rt_key));
     231           0 :     if (!route) {
     232           0 :         route = new ErmVpnRoute(prefix);
     233           0 :         tbl_partition->Add(route);
     234             :     } else {
     235           0 :         route->ClearDelete();
     236             :     }
     237             : 
     238             :     // Build the attributes.  Need to go through the tree links to build the
     239             :     // EdgeForwardingSpec.
     240           0 :     BgpServer *server = table->routing_instance()->server();
     241           0 :     BgpAttrSpec attr_spec;
     242           0 :     BgpAttrNextHop nexthop(server->bgp_identifier());
     243           0 :     attr_spec.push_back(&nexthop);
     244           0 :     BgpAttrSourceRd source_rd(sg_entry_->GetSourceRd());
     245           0 :     attr_spec.push_back(&source_rd);
     246           0 :     EdgeForwardingSpec efspec;
     247           0 :     for (McastForwarderList::const_iterator it = tree_links_.begin();
     248           0 :          it != tree_links_.end(); ++it) {
     249           0 :         EdgeForwardingSpec::Edge *edge = new EdgeForwardingSpec::Edge;
     250           0 :         edge->SetInboundIp4Address(address_);
     251           0 :         edge->inbound_label = label_;
     252           0 :         edge->SetOutboundIp4Address((*it)->address());
     253           0 :         edge->outbound_label = (*it)->label();
     254           0 :         efspec.edge_list.push_back(edge);
     255             :     }
     256           0 :     attr_spec.push_back(&efspec);
     257             :     // Add tunnel encaps for remote nodes
     258           0 :     ExtCommunitySpec ext;
     259           0 :     ext.AddTunnelEncaps(encap_);
     260           0 :     if (!ext.communities.empty())
     261           0 :         attr_spec.push_back(&ext);
     262           0 :     BgpAttrPtr attr = server->attr_db()->Locate(attr_spec);
     263             : 
     264             :     // Add a path with source BgpPath::Local.
     265           0 :     BgpPath *path = new BgpPath(0, BgpPath::Local, attr);
     266           0 :     route->InsertPath(path);
     267           0 :     tbl_partition->Notify(route);
     268           0 :     global_tree_route_ = route;
     269           0 : }
     270             : 
     271             : //
     272             : // Delete the GlobalTreeRoute for this McastForwarder.
     273             : //
     274           0 : void McastForwarder::DeleteGlobalTreeRoute() {
     275           0 :     if (!global_tree_route_)
     276           0 :         return;
     277             : 
     278           0 :     McastManagerPartition *partition = sg_entry_->partition();
     279             :     DBTablePartition *tbl_partition =
     280           0 :         static_cast<DBTablePartition *>(partition->GetTablePartition());
     281           0 :     global_tree_route_->RemovePath(BgpPath::Local);
     282             : 
     283           0 :     if (!global_tree_route_->HasPaths()) {
     284           0 :         tbl_partition->Delete(global_tree_route_);
     285             :     } else {
     286           0 :         tbl_partition->Notify(global_tree_route_);
     287             :     }
     288           0 :     global_tree_route_ = NULL;
     289             : }
     290             : 
     291             : //
     292             : // Append list of BgpOListElems from the Local tree to the BgpOListSpec. The
     293             : // list is built based on the tree links in this McastForwarder.
     294             : //
     295           0 : void McastForwarder::AddLocalOListElems(BgpOListSpec *olist_spec) {
     296           0 :     assert(level_ == McastTreeManager::LevelNative);
     297             : 
     298           0 :     for (McastForwarderList::const_iterator it = tree_links_.begin();
     299           0 :          it != tree_links_.end(); ++it) {
     300           0 :         BgpOListElem elem((*it)->address(), (*it)->label(), (*it)->encap());
     301           0 :         olist_spec->elements.push_back(elem);
     302           0 :     }
     303           0 : }
     304             : 
     305             : //
     306             : // Append list of BgpOListElems from the Global tree to the BgpOListSpec. The
     307             : // list is built based on EdgeForwarding attribute in the GlobalTreeRoute.
     308             : //
     309           0 : void McastForwarder::AddGlobalOListElems(BgpOListSpec *olist_spec) {
     310           0 :     assert(level_ == McastTreeManager::LevelNative);
     311             : 
     312             :     // Bail if this is not the forest node for the Local tree.
     313           0 :     if (!sg_entry_->IsForestNode(this))
     314           0 :         return;
     315             : 
     316           0 :     const ErmVpnRoute *route = sg_entry_->tree_result_route();
     317           0 :     if (!route)
     318           0 :         return;
     319             : 
     320           0 :     const BgpPath *path = route->BestPath();
     321           0 :     if (!path)
     322           0 :         return;
     323           0 :     const BgpAttr *attr = path->GetAttr();
     324           0 :     vector<string> encaps;
     325           0 :     if (attr && attr->ext_community())
     326           0 :         encaps = attr->ext_community()->GetTunnelEncap();
     327             : 
     328             :     // Go through each forwarding edge and add it to the list.
     329           0 :     const EdgeForwarding *eforwarding = path->GetAttr()->edge_forwarding();
     330           0 :     for (EdgeForwarding::EdgeList::const_iterator it =
     331           0 :          eforwarding->edge_list.begin(); it != eforwarding->edge_list.end();
     332           0 :          ++it) {
     333           0 :         const EdgeForwarding::Edge *edge = *it;
     334           0 :         if (edge->inbound_address == address_) {
     335           0 :             BgpOListElem elem(edge->outbound_address, edge->outbound_label,
     336           0 :                               encaps);
     337           0 :             olist_spec->elements.push_back(elem);
     338           0 :         }
     339             :     }
     340           0 : }
     341             : 
     342             : //
     343             : // Construct an UpdateInfo with the RibOutAttr that needs to be advertised to
     344             : // the IPeer for the ErmVpnRoute associated with this McastForwarder. This is
     345             : // used as Export method of the ErmVpnTable.  It is expected that the caller
     346             : // fills in the target RibPeerSet in the UpdateInfo.
     347             : //
     348             : // The main functionality here is to transform the McastForwarderList for the
     349             : // distribution tree and the EdgeForwarding attribute from the GlobalTreeRoute
     350             : // into a BgpOList.
     351             : //
     352           0 : UpdateInfo *McastForwarder::GetUpdateInfo(ErmVpnTable *table) {
     353           0 :     CHECK_CONCURRENCY("db::DBTable");
     354             : 
     355           0 :     assert(level_ == McastTreeManager::LevelNative);
     356             : 
     357           0 :     BgpOListSpec olist_spec(BgpAttribute::OList);
     358           0 :     AddLocalOListElems(&olist_spec);
     359           0 :     AddGlobalOListElems(&olist_spec);
     360             : 
     361             :     // Bail if there is no label allocated.
     362           0 :     if (label_ == 0)
     363           0 :         return NULL;
     364             : 
     365           0 :     BgpAttrSpec attr_spec;
     366           0 :     attr_spec.push_back(&olist_spec);
     367           0 :     BgpAttrPtr attr = table->server()->attr_db()->Locate(attr_spec);
     368             : 
     369           0 :     UpdateInfo *uinfo = new UpdateInfo;
     370           0 :     uinfo->roattr = RibOutAttr(table, route_, attr.get(), label_, true, true);
     371           0 :     if (route_ && sg_entry_->IsForestNode(this) &&
     372           0 :             sg_entry_->IsTreeBuilder(McastTreeManager::LevelLocal)) {
     373           0 :         table->GetMvpnSourceAddress(route_, uinfo->roattr.source_address());
     374             :     }
     375           0 :     return uinfo;
     376           0 : }
     377             : 
     378             : //
     379             : // Constructor for McastSGEntry.
     380             : //
     381           0 : McastSGEntry::McastSGEntry(McastManagerPartition *partition,
     382           0 :         Ip4Address group, Ip4Address source)
     383           0 :     : partition_(partition),
     384           0 :       group_(group),
     385           0 :       source_(source),
     386           0 :       forest_node_(NULL),
     387           0 :       local_tree_route_(NULL),
     388           0 :       tree_result_route_(NULL),
     389           0 :       on_work_queue_(false) {
     390           0 :     for (int level = McastTreeManager::LevelFirst;
     391           0 :          level < McastTreeManager::LevelCount; ++level) {
     392           0 :         ForwarderSet *forwarders = new ForwarderSet;
     393           0 :         forwarder_sets_.push_back(forwarders);
     394           0 :         update_needed_.push_back(false);
     395             :     }
     396           0 : }
     397             : 
     398             : //
     399             : // Destructor for McastSGEntry.
     400             : //
     401           0 : McastSGEntry::~McastSGEntry() {
     402           0 :     STLDeleteValues(&forwarder_sets_);
     403           0 : }
     404             : 
     405             : //
     406             : // Printable string for McastSGEntry.
     407             : //
     408           0 : std::string McastSGEntry::ToString() const {
     409           0 :     return group_.to_string() + "," + source_.to_string();
     410             : }
     411             : 
     412             : //
     413             : // Add the given McastForwarder under this McastSGEntry and trigger update
     414             : // of the distribution tree.
     415             : //
     416           0 : void McastSGEntry::AddForwarder(McastForwarder *forwarder) {
     417           0 :     uint8_t level = forwarder->level();
     418           0 :     forwarder_sets_[level]->insert(forwarder);
     419           0 :     update_needed_[level] = true;
     420           0 :     partition_->EnqueueSGEntry(this);
     421           0 : }
     422             : 
     423             : //
     424             : // Handle change for the given McastForwarder under this McastSGEntry. Trigger
     425             : // update of the distribution tree.
     426             : //
     427             : // Note that this method only handles the change = the caller determines that
     428             : // there has been a change.
     429             : //
     430           0 : void McastSGEntry::ChangeForwarder(McastForwarder *forwarder) {
     431           0 :     uint8_t level = forwarder->level();
     432           0 :     update_needed_[level] = true;
     433           0 :     partition_->EnqueueSGEntry(this);
     434           0 : }
     435             : 
     436             : //
     437             : // Delete the given McastForwarder from this McastSGEntry and trigger update
     438             : // of the distribution tree.
     439             : //
     440           0 : void McastSGEntry::DeleteForwarder(McastForwarder *forwarder) {
     441           0 :     if (forwarder == forest_node_)
     442           0 :         forest_node_ = NULL;
     443           0 :     uint8_t level = forwarder->level();
     444           0 :     forwarder_sets_[level]->erase(forwarder);
     445           0 :     update_needed_[level] = true;
     446           0 :     partition_->EnqueueSGEntry(this);
     447           0 : }
     448             : 
     449             : //
     450             : // Get the SourceRD to be used when adding [Local|Global]TreeRoutes.  This
     451             : // SourceRD gets used as the RD when the ErmVpnRoute is replicated from the
     452             : // VRF table to the VPN table.
     453             : //
     454             : // We simply use the RD for the forest node.
     455             : //
     456           0 : const RouteDistinguisher &McastSGEntry::GetSourceRd() const {
     457           0 :     if (!forest_node_)
     458           0 :         return RouteDistinguisher::kZeroRd;
     459           0 :     return forest_node_->route()->GetPrefix().route_distinguisher();
     460             : }
     461             : 
     462             : //
     463             : // Add the LocalTreeRoute for this McastSGEntry.  This route advertises a set
     464             : // of candidate edges from McastForwarders attached to this control-node that
     465             : // can be used by the tree builder to build the higher level tree.  We simply
     466             : // advertise edges McastTreeManager::kDegree - 1 edges from the forest node.
     467             : //
     468             : // We advertise kDegree-1 candidate edges via the EdgeDiscovery attribute. All
     469             : // the edges are for the forest node for the tree of native McastForwarders.
     470             : // The label block for each edge in the EdgeDiscovery attribute is of size 1 -
     471             : // this is label that has been allocated for the forest node.  Using a single
     472             : // label is acceptable because the tree builder algorithm does not change the
     473             : // relative order of nodes in the tree.
     474             : //
     475           0 : void McastSGEntry::AddLocalTreeRoute() {
     476           0 :     assert(!forest_node_);
     477           0 :     assert(!local_tree_route_);
     478             : 
     479             :     // Select last usable leaf in the distribution tree as the forest node.
     480             :     // A leaf is considered usable if it has a valid label i.e. it has not
     481             :     // run out of labels.
     482           0 :     uint8_t level = McastTreeManager::LevelNative;
     483           0 :     ForwarderSet *forwarders = forwarder_sets_[level];
     484           0 :     for (ForwarderSet::reverse_iterator rit = forwarders->rbegin();
     485           0 :          rit != forwarders->rend(); ++rit) {
     486           0 :         McastForwarder *forwarder = *rit;
     487           0 :         if (forwarder->label()) {
     488           0 :             forest_node_ = forwarder;
     489           0 :             break;
     490             :         }
     491             :     }
     492             : 
     493             :     // Bail if we couldn't designate a forest node.
     494           0 :     if (!forest_node_)
     495           0 :         return;
     496             : 
     497             :     // Construct the prefix and route key.
     498           0 :     BgpServer *server = partition_->server();
     499           0 :     Ip4Address router_id(server->bgp_identifier());
     500             :     ErmVpnPrefix prefix(ErmVpnPrefix::LocalTreeRoute,
     501           0 :         RouteDistinguisher::kZeroRd, router_id, group_, source_);
     502           0 :     ErmVpnRoute rt_key(prefix);
     503             : 
     504             :     // Find or create the route.
     505             :     DBTablePartition *tbl_partition =
     506           0 :         static_cast<DBTablePartition *>(partition_->GetTablePartition());
     507             :     ErmVpnRoute *route =
     508           0 :         static_cast<ErmVpnRoute *>(tbl_partition->Find(&rt_key));
     509           0 :     if (!route) {
     510           0 :         route = new ErmVpnRoute(prefix);
     511           0 :         tbl_partition->Add(route);
     512             :     } else {
     513           0 :         route->ClearDelete();
     514             :     }
     515             : 
     516             :     // Build the attributes.
     517           0 :     BgpAttrSpec attr_spec;
     518           0 :     BgpAttrNextHop nexthop(server->bgp_identifier());
     519           0 :     attr_spec.push_back(&nexthop);
     520           0 :     BgpAttrSourceRd source_rd(GetSourceRd());
     521           0 :     attr_spec.push_back(&source_rd);
     522           0 :     EdgeDiscoverySpec edspec;
     523           0 :     for (int idx = 1; idx <= McastTreeManager::kDegree - 1; ++idx) {
     524           0 :         EdgeDiscoverySpec::Edge *edge = new EdgeDiscoverySpec::Edge;
     525           0 :         edge->SetIp4Address(forest_node_->address());
     526           0 :         edge->SetLabels(forest_node_->label(), forest_node_->label());
     527           0 :         edspec.edge_list.push_back(edge);
     528             :     }
     529           0 :     attr_spec.push_back(&edspec);
     530             :     // Add tunnel encaps for remote nodes
     531           0 :     ExtCommunitySpec ext;
     532           0 :     ext.AddTunnelEncaps(forest_node_->encap());
     533           0 :     if (!ext.communities.empty())
     534           0 :         attr_spec.push_back(&ext);
     535           0 :     BgpAttrPtr attr = server->attr_db()->Locate(attr_spec);
     536             : 
     537             :     // Add a path with source BgpPath::Local.
     538           0 :     BgpPath *path = new BgpPath(0, BgpPath::Local, attr);
     539           0 :     route->InsertPath(path);
     540           0 :     tbl_partition->Notify(route);
     541           0 :     local_tree_route_ = route;
     542           0 : }
     543             : 
     544             : //
     545             : // Delete the LocalTreeRoute for this McastSGEntry.
     546             : //
     547           0 : void McastSGEntry::DeleteLocalTreeRoute() {
     548           0 :     if (!local_tree_route_)
     549           0 :         return;
     550             : 
     551           0 :     forest_node_ = NULL;
     552             :     DBTablePartition *tbl_partition =
     553           0 :         static_cast<DBTablePartition *>(partition_->GetTablePartition());
     554           0 :     local_tree_route_->RemovePath(BgpPath::Local);
     555           0 :     if (!local_tree_route_->HasPaths()) {
     556           0 :         tbl_partition->Delete(local_tree_route_);
     557             :     } else {
     558           0 :         tbl_partition->Notify(local_tree_route_);
     559             :     }
     560           0 :     local_tree_route_ = NULL;
     561             : }
     562             : 
     563             : //
     564             : // Update the LocalTreeRoute for this McastSGEntry if RouterId has changed.
     565             : //
     566           0 : void McastSGEntry::UpdateLocalTreeRoute() {
     567           0 :     if (!local_tree_route_)
     568           0 :         return;
     569             : 
     570             :     // Bail if the RouterId hasn't changed.
     571           0 :     const BgpServer *server = partition_->server();
     572           0 :     Ip4Address router_id = local_tree_route_->GetPrefix().router_id();
     573           0 :     if (router_id.to_ulong() == server->bgp_identifier())
     574           0 :         return;
     575             : 
     576             :     // Add and delete the route.
     577           0 :     DeleteLocalTreeRoute();
     578           0 :     AddLocalTreeRoute();
     579             : }
     580             : 
     581             : //
     582             : // Update relevant [Local|Global]TreeRoutes for the McastSGEntry.
     583             : //
     584           0 : void McastSGEntry::UpdateRoutes(uint8_t level) {
     585           0 :     if (level == McastTreeManager::LevelNative) {
     586           0 :         DeleteLocalTreeRoute();
     587           0 :         AddLocalTreeRoute();
     588             :     } else {
     589           0 :         ForwarderSet *forwarders = forwarder_sets_[level];
     590           0 :         for (ForwarderSet::iterator it = forwarders->begin();
     591           0 :              it != forwarders->end(); ++it) {
     592           0 :             (*it)->DeleteGlobalTreeRoute();
     593           0 :             (*it)->AddGlobalTreeRoute();
     594             :         }
     595             :     }
     596           0 : }
     597             : 
     598           0 : ErmVpnRoute *McastSGEntry::GetGlobalTreeRootRoute() const {
     599           0 :     if (!IsTreeBuilder(McastTreeManager::LevelLocal))
     600           0 :         return NULL;
     601           0 :     ForwarderSet *forwarders = forwarder_sets_[McastTreeManager::LevelLocal];
     602           0 :     assert(!forwarders->empty());
     603           0 :     ForwarderSet::const_iterator it = forwarders->begin();
     604           0 :     return (*it)->global_tree_route();
     605             : }
     606             : 
     607             : //
     608             : // Implement tree builder election.
     609             : //
     610           0 : bool McastSGEntry::IsTreeBuilder(uint8_t level) const {
     611           0 :     if (level == McastTreeManager::LevelNative)
     612           0 :         return true;
     613             : 
     614           0 :     const ForwarderSet *forwarders = forwarder_sets_[level];
     615           0 :     ForwarderSet::const_iterator it = forwarders->begin();
     616           0 :     if (it == forwarders->end())
     617           0 :         return false;
     618             : 
     619           0 :     Ip4Address router_id(partition_->server()->bgp_identifier());
     620           0 :     if ((*it)->router_id() != router_id)
     621           0 :         return false;
     622             : 
     623           0 :     return true;
     624             : }
     625             : 
     626             : //
     627             : //
     628             : // Update specified distribution tree for the McastSGEntry.  We traverse all
     629             : // McastForwarders in sorted order and arrange them in breadth first fashion
     630             : // in a k-ary tree.  Building the tree in this manner guarantees that we get
     631             : // the same tree for a given set of forwarders, independent of the order in
     632             : // in which they joined. This predictability is deemed to be more important
     633             : // than other criteria such as minimizing disruption of traffic, minimizing
     634             : // the cost/weight of the tree etc.
     635             : //
     636           0 : void McastSGEntry::UpdateTree(uint8_t level) {
     637           0 :     CHECK_CONCURRENCY("db::DBTable");
     638             : 
     639           0 :     if (!update_needed_[level])
     640           0 :         return;
     641           0 :     update_needed_[level] = false;
     642             : 
     643             :     int degree;
     644           0 :     if (level == McastTreeManager::LevelNative) {
     645           0 :         degree = McastTreeManager::kDegree;
     646             :     } else {
     647           0 :         degree = McastTreeManager::kDegree - 1;
     648             :     }
     649             : 
     650             :     // First get rid of the previous distribution tree and enqueue all the
     651             :     // associated ErmVpnRoutes for notification. Note that DBListeners will
     652             :     // not get invoked until after this routine is done.
     653           0 :     ForwarderSet *forwarders = forwarder_sets_[level];
     654           0 :     for (ForwarderSet::iterator it = forwarders->begin();
     655           0 :          it != forwarders->end(); ++it) {
     656           0 :        (*it)->FlushLinks();
     657           0 :        (*it)->ReleaseLabel();
     658           0 :        partition_->GetTablePartition()->Notify((*it)->route());
     659             :     }
     660             : 
     661             :     // Bail if we're not the tree builder.
     662           0 :     if (!IsTreeBuilder(level)) {
     663           0 :         UpdateRoutes(level);
     664           0 :         return;
     665             :     }
     666             : 
     667             :     // Create a vector of pointers to the McastForwarders in sorted order.
     668             :     // We do this because std::set doesn't support random access iterators.
     669             :     // Skip if we can't allocate a label for the McastForwarder.
     670           0 :     McastForwarderList vec;
     671           0 :     vec.reserve(forwarders->size());
     672           0 :     for (ForwarderSet::iterator it = forwarders->begin();
     673           0 :          it != forwarders->end(); ++it) {
     674           0 :         McastForwarder *forwarder = *it;
     675           0 :         forwarder->AllocateLabel();
     676           0 :         if (!forwarder->label())
     677           0 :             continue;
     678           0 :         vec.push_back(forwarder);
     679             :     }
     680             : 
     681             :     // Go through each McastForwarder in the vector and link it to it's parent
     682             :     // McastForwarder in the k-ary tree. We also add a link from the parent to
     683             :     // the entry in question.
     684           0 :     for (McastForwarderList::iterator it = vec.begin(); it != vec.end(); ++it) {
     685           0 :         int idx = it - vec.begin();
     686           0 :         if (idx == 0)
     687           0 :             continue;
     688             : 
     689           0 :         int parent_idx = (idx - 1) / degree;
     690           0 :         McastForwarderList::iterator parent_it = vec.begin() + parent_idx;
     691           0 :         assert(parent_it != vec.end());
     692           0 :         McastForwarder *forwarder = *it;
     693           0 :         McastForwarder *parent_forwarder = *parent_it;
     694           0 :         forwarder->AddLink(parent_forwarder);
     695           0 :         parent_forwarder->AddLink(forwarder);
     696             :     }
     697             : 
     698             :     // Update [Local|Global]TreeRoutes.
     699           0 :     UpdateRoutes(level);
     700           0 : }
     701             : 
     702             : //
     703             : // Update distribution trees for both levels.
     704             : //
     705           0 : void McastSGEntry::UpdateTree() {
     706           0 :     for (uint8_t level = McastTreeManager::LevelFirst;
     707           0 :          level < McastTreeManager::LevelCount; ++level) {
     708           0 :         UpdateTree(level);
     709             :     }
     710           0 : }
     711             : 
     712             : //
     713             : // Trigger notification of the ErmVpnRoute associated with the McastForwarder
     714             : // that is the forest node. This is used to trigger a rebuild of the BgpOlist
     715             : // when the GlobalTreeRoute is updated.
     716             : //
     717           0 : void McastSGEntry::NotifyForestNode() {
     718           0 :     if (!forest_node_)
     719           0 :         return;
     720           0 :     partition_->GetTablePartition()->Notify(forest_node_->route());
     721             : }
     722             : 
     723           0 : bool McastSGEntry::GetForestNodePMSI(uint32_t *label, Ip4Address *address,
     724             :         vector<string> *tunnel_encap) const {
     725           0 :     if (!forest_node_)
     726           0 :         return false;
     727           0 :     *label = forest_node_->label();
     728           0 :     *address = forest_node_->address();
     729           0 :     *tunnel_encap = forest_node_->encap();
     730           0 :     return true;
     731             : }
     732             : 
     733           0 : bool McastSGEntry::IsForestNode(McastForwarder *forwarder) {
     734           0 :     return (forwarder == forest_node_);
     735             : }
     736             : 
     737           0 : bool McastSGEntry::empty() const {
     738           0 :     if (local_tree_route_ || tree_result_route_)
     739           0 :         return false;
     740           0 :     if (!forwarder_sets_[McastTreeManager::LevelNative]->empty())
     741           0 :         return false;
     742           0 :     if (!forwarder_sets_[McastTreeManager::LevelLocal]->empty())
     743           0 :         return false;
     744           0 :     return true;
     745             : }
     746             : 
     747             : //
     748             : // Constructor for McastManagerPartition.
     749             : //
     750          80 : McastManagerPartition::McastManagerPartition(McastTreeManager *tree_manager,
     751          80 :         size_t part_id)
     752          80 :     : tree_manager_(tree_manager),
     753          80 :       part_id_(part_id),
     754          80 :       update_count_(0),
     755         160 :       work_queue_(TaskScheduler::GetInstance()->GetTaskId("db::DBTable"),
     756          80 :               part_id_,
     757          80 :               boost::bind(&McastManagerPartition::ProcessSGEntry, this, _1)) {
     758          80 : }
     759             : 
     760             : //
     761             : // Destructor for McastManagerPartition.
     762             : //
     763          80 : McastManagerPartition::~McastManagerPartition() {
     764          80 :     work_queue_.Shutdown();
     765          80 : }
     766             : 
     767             : // Find the McastSGEntry for the given group and source.
     768           0 : McastSGEntry *McastManagerPartition::FindSGEntry(
     769             :         const Ip4Address &group, const Ip4Address &source) {
     770             :     return const_cast<McastSGEntry *>(
     771           0 :         static_cast<const McastManagerPartition *>(this)->FindSGEntry(group,
     772           0 :                                                                       source));
     773             : }
     774             : 
     775             : //
     776             : // Find the McastSGEntry for the given group and source.
     777             : //
     778           0 : const McastSGEntry *McastManagerPartition::FindSGEntry(
     779             :         const Ip4Address &group, const Ip4Address &source) const {
     780             :     McastSGEntry temp_sg_entry(const_cast<McastManagerPartition *>(this),
     781           0 :                                group, source);
     782           0 :     SGList::const_iterator it = sg_list_.find(&temp_sg_entry);
     783           0 :     return (it != sg_list_.end() ? *it : NULL);
     784           0 : }
     785             : 
     786             : //
     787             : // Find or create the McastSGEntry for the given group and source.
     788             : //
     789           0 : McastSGEntry *McastManagerPartition::LocateSGEntry(
     790             :         Ip4Address group, Ip4Address source) {
     791           0 :     McastSGEntry *sg_entry = FindSGEntry(group, source);
     792           0 :     if (!sg_entry) {
     793           0 :         sg_entry = new McastSGEntry(this, group, source);
     794           0 :         sg_list_.insert(sg_entry);
     795             :     }
     796           0 :     return sg_entry;
     797             : }
     798             : 
     799           0 : ErmVpnRoute *McastManagerPartition::GetGlobalTreeRootRoute(
     800             :         const Ip4Address &source, const Ip4Address &group) const {
     801           0 :     const McastSGEntry *sg = FindSGEntry(group, source);
     802           0 :     return sg ? sg->GetGlobalTreeRootRoute() : NULL;
     803             : }
     804             : 
     805           0 : void McastManagerPartition::NotifyForestNode(
     806             :         const Ip4Address &source, const Ip4Address &group) {
     807           0 :     McastSGEntry *sg = FindSGEntry(group, source);
     808           0 :     if (sg)
     809           0 :         sg->NotifyForestNode();
     810           0 : }
     811             : 
     812           0 : bool McastManagerPartition::GetForestNodePMSI(ErmVpnRoute *rt, uint32_t *label,
     813             :         Ip4Address *address, vector<string> *encap) const {
     814           0 :     const McastSGEntry *sg = FindSGEntry(rt->GetPrefix().group(),
     815           0 :                                          rt->GetPrefix().source());
     816           0 :     return sg ? sg->GetForestNodePMSI(label, address, encap) : false;
     817             : }
     818             : 
     819             : //
     820             : // Enqueue the given McastSGEntry on the WorkQueue if it's not already on it.
     821             : //
     822           0 : void McastManagerPartition::EnqueueSGEntry(McastSGEntry *sg_entry) {
     823           0 :     if (sg_entry->on_work_queue())
     824           0 :         return;
     825           0 :     work_queue_.Enqueue(sg_entry);
     826           0 :     sg_entry->set_on_work_queue();
     827             : }
     828             : 
     829             : //
     830             : // Callback for the WorkQueue. Updates distribution trees for the McastSGEntry.
     831             : // Also gets rid of the McastSGEntry if it is eligible to be deleted.
     832             : //
     833           0 : bool McastManagerPartition::ProcessSGEntry(McastSGEntry *sg_entry) {
     834           0 :     CHECK_CONCURRENCY("db::DBTable");
     835             : 
     836           0 :     sg_entry->clear_on_work_queue();
     837           0 :     sg_entry->UpdateTree();
     838           0 :     update_count_++;
     839             : 
     840           0 :     if (sg_entry->empty()) {
     841           0 :         sg_list_.erase(sg_entry);
     842           0 :         delete sg_entry;
     843             :     }
     844             : 
     845           0 :     if (sg_list_.empty())
     846           0 :         tree_manager_->RetryDelete();
     847             : 
     848           0 :     return true;
     849             : }
     850             : 
     851             : //
     852             : // Get the DBTablePartBase for the ErmVpnTable for our partition id.
     853             : //
     854           0 : DBTablePartBase *McastManagerPartition::GetTablePartition() {
     855           0 :     return tree_manager_->GetTablePartition(part_id_);
     856             : }
     857             : 
     858           0 : const RoutingInstance *McastManagerPartition::routing_instance() const {
     859           0 :     return tree_manager_->table()->routing_instance();
     860             : }
     861             : 
     862           0 : BgpServer *McastManagerPartition::server() {
     863           0 :     return tree_manager_->table()->server();
     864             : }
     865             : 
     866           0 : const BgpServer *McastManagerPartition::server() const {
     867           0 :     return tree_manager_->table()->server();
     868             : }
     869             : 
     870             : //
     871             : // Constructor for McastTreeManager.
     872             : //
     873          80 : McastTreeManager::McastTreeManager(ErmVpnTable *table)
     874          80 :     : table_(table),
     875          80 :       listener_id_(DBTable::kInvalidId),
     876          80 :       table_delete_ref_(this, table->deleter()) {
     877          80 :     deleter_.reset(new DeleteActor(this));
     878          80 : }
     879             : 
     880             : //
     881             : // Destructor for McastTreeManager.
     882             : //
     883         160 : McastTreeManager::~McastTreeManager() {
     884         160 : }
     885             : 
     886             : //
     887             : // Initialize the McastTreeManager. We allocate the McastManagerPartitions
     888             : // and register a DBListener for the ErmVpnTable.
     889             : //
     890          80 : void McastTreeManager::Initialize() {
     891          80 :     AllocPartitions();
     892          80 :     listener_id_ = table_->Register(
     893             :         boost::bind(&McastTreeManager::RouteListener, this, _1, _2),
     894             :         "McastTreeManager");
     895          80 : }
     896             : 
     897             : //
     898             : // Terminate the McastTreeManager. We free the McastManagerPartitions
     899             : // and unregister from the ErmVpnTable.
     900             : //
     901          80 : void McastTreeManager::Terminate() {
     902          80 :     table_->Unregister(listener_id_);
     903          80 :     FreePartitions();
     904          80 : }
     905             : 
     906             : //
     907             : // Allocate the McastManagerPartitions.
     908             : //
     909          80 : void McastTreeManager::AllocPartitions() {
     910         160 :     for (int part_id = 0; part_id < table_->PartitionCount(); part_id++) {
     911          80 :         partitions_.push_back(new McastManagerPartition(this, part_id));
     912             :     }
     913          80 : }
     914             : 
     915             : //
     916             : // Free the McastManagerPartitions.
     917             : //
     918          80 : void McastTreeManager::FreePartitions() {
     919         160 :     for (size_t part_id = 0; part_id < partitions_.size(); part_id++) {
     920          80 :         delete partitions_[part_id];
     921             :     }
     922          80 :     partitions_.clear();
     923          80 : }
     924             : 
     925           0 : McastManagerPartition *McastTreeManager::GetPartition(int part_id) {
     926           0 :     return partitions_[part_id];
     927             : }
     928             : 
     929           0 : const McastManagerPartition *McastTreeManager::GetPartition(int part_id) const {
     930           0 :     return partitions_[part_id];
     931             : }
     932             : 
     933             : //
     934             : // Get the DBTablePartBase for the ErmVpnTable for given partition id.
     935             : //
     936           0 : DBTablePartBase *McastTreeManager::GetTablePartition(size_t part_id) {
     937           0 :     return table_->GetTablePartition(part_id);
     938             : }
     939             : 
     940             : //
     941             : // Construct export state for the given ErmVpnRoute. Note that the route
     942             : // only needs to be exported to the IPeer from which it was learnt.
     943             : //
     944           0 : UpdateInfo *McastTreeManager::GetUpdateInfo(ErmVpnRoute *route) {
     945           0 :     CHECK_CONCURRENCY("db::DBTable");
     946             : 
     947           0 :     DBState *dbstate = route->GetState(table_, listener_id_);
     948           0 :     McastForwarder *forwarder = dynamic_cast<McastForwarder *>(dbstate);
     949             : 
     950           0 :     if (!forwarder)
     951           0 :         return NULL;
     952             : 
     953           0 :     return forwarder->GetUpdateInfo(table_);
     954             : }
     955             : 
     956             : //
     957             : // DBListener callback handler for Native and Local routes in the ErmVpnTable.
     958             : // It creates, updates or deletes the associated McastForwarder as appropriate.
     959             : //
     960             : // Creates a McastSGEntry if one doesn't already exist. However, McastSGEntrys
     961             : // don't get deleted from here.  They only get deleted from WorkQueue callback
     962             : // routine i.e. McastManagerPartition::ProcessSGEntry.
     963             : //
     964           0 : void McastTreeManager::TreeNodeListener(McastManagerPartition *partition,
     965             :         ErmVpnRoute *route) {
     966           0 :     CHECK_CONCURRENCY("db::DBTable");
     967             : 
     968           0 :     DBState *dbstate = route->GetState(table_, listener_id_);
     969           0 :     if (!dbstate) {
     970             :         // We have no previous DBState for this route.
     971             :         // Bail if the route is not valid.
     972           0 :         if (!route->IsValid())
     973           0 :             return;
     974             : 
     975             :         // Create a new McastForwarder and associate it with the route.
     976           0 :         McastSGEntry *sg_entry = partition->LocateSGEntry(
     977           0 :             route->GetPrefix().group(), route->GetPrefix().source());
     978           0 :         McastForwarder *forwarder = new McastForwarder(sg_entry, route);
     979           0 :         sg_entry->AddForwarder(forwarder);
     980           0 :         route->SetState(table_, listener_id_, forwarder);
     981             : 
     982             :         // Update local tree route if our RouterId has changed. Ideally,
     983             :         // we should trigger an update of all local trees routes when we
     984             :         // detect a change in RouterId. Instead, we currently check and
     985             :         // update the local route when we detect a new local route from
     986             :         // another node.
     987           0 :         if (route->GetPrefix().type() == ErmVpnPrefix::LocalTreeRoute)
     988           0 :             sg_entry->UpdateLocalTreeRoute();
     989             :     } else {
     990           0 :         McastSGEntry *sg_entry = partition->FindSGEntry(
     991           0 :             route->GetPrefix().group(), route->GetPrefix().source());
     992           0 :         assert(sg_entry);
     993           0 :         McastForwarder *forwarder = dynamic_cast<McastForwarder *>(dbstate);
     994           0 :         assert(forwarder);
     995             : 
     996           0 :         if (!route->IsValid()) {
     997             :             // Delete the McastForwarder associated with the route.
     998           0 :             route->ClearState(table_, listener_id_);
     999           0 :             sg_entry->DeleteForwarder(forwarder);
    1000           0 :             delete forwarder;
    1001           0 :         } else if (forwarder->Update(route)) {
    1002             :             // Trigger update of the distribution tree.
    1003           0 :             sg_entry->ChangeForwarder(forwarder);
    1004             :         }
    1005             :     }
    1006             : }
    1007             : 
    1008             : //
    1009             : // DBListener callback handler for GlobalTreeRoutes in the ErmVpnTable. It
    1010             : // updates the tree_result_route_ and triggers re-evaluation of the forest
    1011             : // node McastForwarder's BgpOlist.
    1012             : //
    1013           0 : void McastTreeManager::TreeResultListener(McastManagerPartition *partition,
    1014             :         ErmVpnRoute *route) {
    1015           0 :     CHECK_CONCURRENCY("db::DBTable");
    1016             : 
    1017           0 :     DBState *dbstate = route->GetState(table_, listener_id_);
    1018           0 :     if (!dbstate) {
    1019             :         // We have no previous DBState for this route.
    1020             :         // Bail if the route is not valid.
    1021           0 :         if (!route->IsValid())
    1022           0 :             return;
    1023             : 
    1024             :         // Ignore GlobalTreeRoute if it's not applicable to this control-node.
    1025           0 :         BgpServer *server = table_->routing_instance()->server();
    1026           0 :         if (route->GetPrefix().router_id().to_ulong() !=
    1027           0 :             server->bgp_identifier())
    1028           0 :             return;
    1029             : 
    1030           0 :         McastSGEntry *sg_entry = partition->LocateSGEntry(
    1031           0 :             route->GetPrefix().group(), route->GetPrefix().source());
    1032           0 :         route->SetState(table_, listener_id_, sg_entry);
    1033           0 :         sg_entry->set_tree_result_route(route);
    1034           0 :         sg_entry->NotifyForestNode();
    1035             :     } else {
    1036           0 :         McastSGEntry *sg_entry = dynamic_cast<McastSGEntry *>(dbstate);
    1037           0 :         assert(sg_entry);
    1038             : 
    1039           0 :         if (!route->IsValid()) {
    1040           0 :             sg_entry->clear_tree_result_route();
    1041           0 :             route->ClearState(table_, listener_id_);
    1042           0 :             partition->EnqueueSGEntry(sg_entry);
    1043             :         }
    1044           0 :         sg_entry->NotifyForestNode();
    1045             :     }
    1046             : }
    1047             : 
    1048             : //
    1049             : // DBListener callback handler for the ErmVpnTable. GlobalTreeRoutes provide
    1050             : // result information and hence are handled differently than Native and Local
    1051             : // routes, which result in update of a McastForwarder.
    1052             : //
    1053           0 : void McastTreeManager::RouteListener(
    1054             :         DBTablePartBase *tpart, DBEntryBase *db_entry) {
    1055           0 :     CHECK_CONCURRENCY("db::DBTable");
    1056             : 
    1057           0 :     McastManagerPartition *partition = partitions_[tpart->index()];
    1058           0 :     ErmVpnRoute *route = dynamic_cast<ErmVpnRoute *>(db_entry);
    1059           0 :     if (route->GetPrefix().type() == ErmVpnPrefix::GlobalTreeRoute) {
    1060           0 :         TreeResultListener(partition, route);
    1061             :     } else {
    1062           0 :         TreeNodeListener(partition, route);
    1063             :     }
    1064           0 : }
    1065             : 
    1066             : 
    1067             : //
    1068             : // Check if the McastTreeManager can be deleted. This can happen only if all
    1069             : // the McastManagerPartitions are empty.
    1070             : //
    1071          80 : bool McastTreeManager::MayDelete() const {
    1072          80 :     CHECK_CONCURRENCY("bgp::Config");
    1073             : 
    1074          80 :     for (PartitionList::const_iterator it = partitions_.begin();
    1075         160 :          it != partitions_.end(); ++it) {
    1076          80 :         if (!(*it)->empty())
    1077           0 :             return false;
    1078             :     }
    1079             : 
    1080          80 :     return true;
    1081             : }
    1082             : 
    1083             : //
    1084             : // Initiate shutdown for the McastTreeManager.
    1085             : //
    1086          80 : void McastTreeManager::Shutdown() {
    1087          80 :     CHECK_CONCURRENCY("bgp::Config");
    1088          80 : }
    1089             : 
    1090             : //
    1091             : // Trigger deletion of the McastTreeManager and propagate the delete to any
    1092             : // dependents.
    1093             : //
    1094          80 : void McastTreeManager::ManagedDelete() {
    1095          80 :     deleter_->Delete();
    1096          80 : }
    1097             : 
    1098             : //
    1099             : // Attempt to enqueue a delete for the McastTreeManager.
    1100             : //
    1101           0 : void McastTreeManager::RetryDelete() {
    1102           0 :     if (!deleter()->IsDeleted())
    1103           0 :         return;
    1104           0 :     deleter()->RetryDelete();
    1105             : }
    1106             : 
    1107             : //
    1108             : // Return the LifetimeActor for the McastTreeManager.
    1109             : //
    1110           0 : LifetimeActor *McastTreeManager::deleter() {
    1111           0 :     return deleter_.get();
    1112             : }
    1113             : 
    1114             : //
    1115             : // Return the LifetimeActor for the McastTreeManager.
    1116             : // Const version.
    1117             : //
    1118           0 : const LifetimeActor *McastTreeManager::deleter() const {
    1119           0 :     return deleter_.get();
    1120             : }
    1121             : 
    1122             : //
    1123             : // Return true if the McastTreeManager is deleted.
    1124             : //
    1125           0 : bool McastTreeManager::deleted() const {
    1126           0 :     return deleter_->IsDeleted();
    1127             : }
    1128             : 
    1129           0 : ErmVpnRoute *McastTreeManager::GetGlobalTreeRootRoute(
    1130             :     const Ip4Address &source, const Ip4Address &group) const {
    1131           0 :     const McastManagerPartition *partition = GetPartition(table_->Hash(group));
    1132           0 :     return partition->GetGlobalTreeRootRoute(source, group);
    1133             : }
    1134             : 
    1135           0 : void McastTreeManager::NotifyForestNode(int part_id, const Ip4Address &source,
    1136             :                                         const Ip4Address &group) {
    1137           0 :     McastManagerPartition *partition = GetPartition(part_id);
    1138           0 :     partition->NotifyForestNode(source, group);
    1139           0 : }
    1140             : 
    1141           0 : bool McastTreeManager::GetForestNodePMSI(ErmVpnRoute *rt, uint32_t *label,
    1142             :         Ip4Address *address, vector<string> *encap) const {
    1143           0 :     if (!rt || !rt->IsUsable())
    1144           0 :         return false;
    1145             :     const McastManagerPartition *partition =
    1146           0 :         GetPartition(rt->get_table_partition()->index());
    1147           0 :     return partition->GetForestNodePMSI(rt, label, address, encap);
    1148             : }

Generated by: LCOV version 1.14