OpenSDN source code
bgp_evpn.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include "bgp/bgp_evpn.h"
7 
8 #include <boost/foreach.hpp>
9 
10 #include <algorithm>
11 #include <string>
12 
13 #include "base/set_util.h"
14 #include "base/task_annotations.h"
15 #include "bgp/bgp_log.h"
16 #include "bgp/bgp_multicast.h"
17 #include "bgp/bgp_peer_types.h"
18 #include "bgp/bgp_server.h"
19 #include "bgp/bgp_update.h"
22 #include "bgp/evpn/evpn_table.h"
25 #include "bgp/routing-instance/routing_instance_analytics_types.h"
27 
28 using std::pair;
29 using std::set;
30 using std::sort;
31 using std::string;
32 using std::vector;
33 
34 // A global MVPN state for a given <S.G> within a EvpnProjectManager.
35 EvpnState::EvpnState(const SG &sg, StatesMap *states, EvpnManager *manager) :
36  sg_(sg), global_ermvpn_tree_rt_(NULL), states_(states),
37  manager_(manager) {
38  refcount_ = 0;
39 }
40 
42  assert(!global_ermvpn_tree_rt_);
43  EVPN_TRACE(EvpnStateCreate, sg_.source.to_string(), sg_.group.to_string());
44 }
45 
46 const ErmVpnTable *EvpnState::table() const {
47  return manager_ ? manager_->ermvpn_table() : NULL;
48 }
49 
51 public:
52  explicit DeleteActor(EvpnManager *evpn_manager)
53  : LifetimeActor(evpn_manager->server()->lifetime_manager()),
54  evpn_manager_(evpn_manager) {
55  }
56  virtual ~DeleteActor() {
57  }
58 
59  virtual bool MayDelete() const {
60  CHECK_CONCURRENCY("bgp::Config");
61  return evpn_manager_->MayDelete();
62  }
63 
64  virtual void Shutdown() {
66  }
67 
68  virtual void Destroy() {
70  }
71 
72 private:
74 };
75 
76 //
77 // Constructor for EvpnMcastNode. The type indicates whether this is a local
78 // or remote EvpnMcastNode.
79 //
81  EvpnRoute *route, uint8_t type)
82  : partition_(partition),
83  state_(NULL),
84  route_(route),
85  type_(type),
86  label_(0),
87  edge_replication_not_supported_(false),
88  assisted_replication_supported_(false),
89  assisted_replication_leaf_(false) {
91 }
92 
94  EvpnRoute *route, uint8_t type, EvpnStatePtr state)
95  : partition_(partition),
96  state_(state),
97  route_(route),
98  type_(type),
99  label_(0),
100  edge_replication_not_supported_(false),
101  assisted_replication_supported_(false),
102  assisted_replication_leaf_(false) {
103  if (route)
105 }
106 
107 //
108 // Destructor for EvpnMcastNode.
109 //
111  set_state(NULL);
112 }
113 
114 //
115 // Update the label and attributes for a EvpnMcastNode.
116 // Return true if either of them changed.
117 //
119  bool changed = false;
120  const BgpPath *path = route->BestPath();
121  if (path->GetLabel() != label_) {
122  label_ = path->GetLabel();
123  changed = true;
124  }
125  if (path->GetAttr() != attr_) {
126  attr_ = path->GetAttr();
127  changed = true;
128  }
129 
130  const PmsiTunnel *pmsi_tunnel = attr_->pmsi_tunnel();
131  uint8_t ar_type = 0;
132  bool edge_replication_not_supported = false;
133  if (pmsi_tunnel) {
134  ar_type = pmsi_tunnel->tunnel_flags() &
136  if ((pmsi_tunnel->tunnel_flags() &
139  }
140  if (replicator_address_ != pmsi_tunnel->identifier()) {
141  replicator_address_ = pmsi_tunnel->identifier();
142  changed = true;
143  }
144  }
145 
148  changed = true;
149  }
150 
151  bool assisted_replication_supported = false;
152  if (ar_type == PmsiTunnelSpec::ARReplicator)
156  changed = true;
157  }
158 
159  bool assisted_replication_leaf = false;
160  if (ar_type == PmsiTunnelSpec::ARLeaf)
164  changed = true;
165  }
166 
167  if (address_ != path->GetAttr()->nexthop().to_v4()) {
168  address_ = path->GetAttr()->nexthop().to_v4();
169  changed = true;
170  }
171 
172  return changed;
173 }
174 
175 //
176 // Constructor for EvpnLocalMcastNode.
177 //
178 // Add an Inclusive Multicast route corresponding to Broadcast MAC route.
179 //
180 // Need to Notify the Broadcast MAC route so that the table Export method
181 // can run and build the OList. OList is not built till EvpnLocalMcastNode
182 // has been created.
183 //
185  EvpnRoute *route)
186  : EvpnMcastNode(partition, route, EvpnMcastNode::LocalNode),
187  inclusive_mcast_route_(NULL) {
189  DBTablePartition *tbl_partition = partition_->GetTablePartition();
190  tbl_partition->Notify(route_);
191 }
192 
194  EvpnRoute *route, EvpnStatePtr state)
195  : EvpnMcastNode(partition, route, EvpnMcastNode::LocalNode, state),
196  inclusive_mcast_route_(NULL) {
197  if (!route)
198  return;
200  DBTablePartition *tbl_partition = partition_->GetTablePartition();
201  tbl_partition->Notify(route_);
202 }
203 
204 //
205 // Destructor for EvpnLocalMcastNode.
206 //
209 }
210 
211 //
212 // Add Inclusive Multicast route for this EvpnLocalMcastNode.
213 // The attributes are based on the Broadcast MAC route.
214 //
216  // No need to create IMET route if group is specified
217  if (!route_->GetPrefix().group().is_unspecified())
218  return;
219  assert(!inclusive_mcast_route_);
220  if (label_ == 0)
221  return;
222 
223  // Construct the prefix and route key.
224  // Build the RD using the TOR IP address, not the TOR agent IP address.
225  // This ensures that the MAC broadcast route from the primary and backup
226  // TOR Agents results in the same Inclusive Multicast prefix.
227  const EvpnPrefix &mac_prefix = route_->GetPrefix();
229  address_.to_ulong(), mac_prefix.route_distinguisher().GetVrfId());
230  EvpnPrefix prefix(rd, mac_prefix.tag(), address_);
231  EvpnRoute rt_key(prefix);
232 
233  // Find or create the route.
234  DBTablePartition *tbl_partition = partition_->GetTablePartition();
235  EvpnRoute *route = static_cast<EvpnRoute *>(tbl_partition->Find(&rt_key));
236  if (!route) {
237  route = new EvpnRoute(prefix);
238  tbl_partition->Add(route);
239  } else {
240  route->ClearDelete();
241  }
242  // Add MulticastFlags community to specify that it supports SMET route
244  mcastFlags.push_back(MulticastFlags().GetExtCommunity());
245  ExtCommunityPtr ext_community = partition_->server()->extcomm_db()->
246  ReplaceMFlagsAndLocate(attr_->ext_community(), mcastFlags);
248  attr_.get(), ext_community);
249 
250  // Add a path with source BgpPath::Local and the peer address as path_id.
251  uint32_t path_id = mac_prefix.route_distinguisher().GetAddress();
252  BgpPath *path = new BgpPath(path_id, BgpPath::Local, attr_, 0, label_);
253  route->InsertPath(path);
255  tbl_partition->Notify(inclusive_mcast_route_);
256  BGP_LOG_ROUTE(partition_->table(), static_cast<IPeer *>(NULL),
257  route, "Insert new Local path");
258 }
259 
260 //
261 // Delete Inclusive Multicast route for this EvpnLocalMcastNode.
262 //
265  return;
266 
267  const EvpnPrefix &mac_prefix = route_->GetPrefix();
268  uint32_t path_id = mac_prefix.route_distinguisher().GetAddress();
269  DBTablePartition *tbl_partition = partition_->GetTablePartition();
271  BGP_LOG_ROUTE(partition_->table(), static_cast<IPeer *>(NULL),
272  inclusive_mcast_route_, "Delete Local path");
273 
275  tbl_partition->Delete(inclusive_mcast_route_);
276  } else {
277  tbl_partition->Notify(inclusive_mcast_route_);
278  }
279  inclusive_mcast_route_ = NULL;
280 }
281 
282 //
283 // Handle update of EvpnLocalMcastNode.
284 //
285 // We delete and add the Inclusive Multicast route to ensure that all the
286 // attributes are updated. An in-place update is not always possible since
287 // the vRouter address is part of the key for the Inclusive Multicast route.
288 //
292 }
293 
294 //
295 // Construct an UpdateInfo with the RibOutAttr that needs to be advertised to
296 // the IPeer for the EvpnRoute associated with this EvpnLocalMcastNode. This
297 // is used the Export method of the EvpnTable. It is expected that the caller
298 // fills in the target RibPeerSet in the UpdateInfo.
299 //
300 // The main functionality here is to build a per-IPeer BgpOList from the list
301 // of EvpnRemoteMcastNodes.
302 //
304  CHECK_CONCURRENCY("db::DBTable");
305 
306  // Nothing to send for a leaf as it already knows the replicator-address.
308  return NULL;
309 
311  bool pbb_evpn_enable = rti->virtual_network_pbb_evpn_enable();
312  uint32_t local_ethernet_tag = route_->GetPrefix().tag();
313 
315  route->GetPrefix().group());
316  // Go through list of EvpnRemoteMcastNodes and build the BgpOList.
317  BgpOListSpec olist_spec(BgpAttribute::OList);
318  if (partition_->remote_mcast_node_list()->count(sg)) {
319  set<EvpnMcastNode*> nodes = (*partition_->remote_mcast_node_list())[sg];
320  BOOST_FOREACH(EvpnMcastNode *node, nodes) {
321  if (node->address() == address_)
322  continue;
323  if (node->assisted_replication_leaf())
324  continue;
327  continue;
328  uint32_t remote_ethernet_tag = node->route()->GetPrefix().tag();
329 
330  if (pbb_evpn_enable && remote_ethernet_tag &&
331  (local_ethernet_tag != remote_ethernet_tag))
332  continue;
333 
334  const ExtCommunity *extcomm = node->attr()->ext_community();
335  BgpOListElem elem(node->address(), node->label(),
336  extcomm ? extcomm->GetTunnelEncap() : vector<string>());
337  olist_spec.elements.push_back(elem);
338  }
339  }
340 
341  // Go through list of leaf EvpnMcastNodes and build the leaf BgpOList.
342  BgpOListSpec leaf_olist_spec(BgpAttribute::LeafOList);
344  if (partition_->leaf_node_list()->count(sg)) {
345  set<EvpnMcastNode*> nodes = (*partition_->leaf_node_list())[sg];
346  BOOST_FOREACH(EvpnMcastNode *node, nodes) {
347  if (node->replicator_address() != address_)
348  continue;
349 
350  const ExtCommunity *extcomm = node->attr()->ext_community();
351  BgpOListElem elem(node->address(), node->label(),
352  extcomm ? extcomm->GetTunnelEncap() : vector<string>());
353  leaf_olist_spec.elements.push_back(elem);
354  }
355  }
356  }
357 
358  // Bail if both BgpOLists are empty.
359  if (olist_spec.elements.empty() && leaf_olist_spec.elements.empty())
360  return NULL;
361 
362  // Add BgpOList and leaf BgpOList to RibOutAttr for broadcast MAC route.
363  BgpAttrDB *attr_db = partition_->server()->attr_db();
364  BgpAttrPtr attr = attr_db->ReplaceOListAndLocate(attr_.get(), &olist_spec);
365  attr = attr_db->ReplaceLeafOListAndLocate(attr.get(), &leaf_olist_spec);
366 
367  UpdateInfo *uinfo = new UpdateInfo;
368  uinfo->roattr =
369  RibOutAttr(partition_->table(), route_, attr.get(), 0, false, true);
370  return uinfo;
371 }
372 
373 //
374 // Constructor for EvpnRemoteMcastNode.
375 //
377  EvpnRoute *route)
378  : EvpnMcastNode(partition, route, EvpnMcastNode::RemoteNode) {
379 }
380 
382  EvpnRoute *route, EvpnStatePtr state)
383  : EvpnMcastNode(partition, route, EvpnMcastNode::RemoteNode, state) {
384 }
385 
386 //
387 // Destructor for EvpnRemoteMcastNode.
388 //
390 }
391 
392 //
393 // Handle update of EvpnRemoteMcastNode.
394 //
396 }
397 
398 //
399 // Constructor for EvpnSegment.
400 //
402  : evpn_manager_(manager),
403  esi_(esi),
404  esi_ad_route_(NULL),
405  single_active_(true),
406  route_lists_(DB::PartitionCount()) {
407 }
408 
409 //
410 // Destructor for EvpnSegment.
411 //
413  assert(!esi_ad_route_);
414  assert(pe_list_.empty());
415 }
416 
417 //
418 // Add the given MAC route as a dependent of this EvpnSegment.
419 //
420 void EvpnSegment::AddMacRoute(size_t part_id, EvpnRoute *route) {
421  pair<RouteList::iterator, bool> ret = route_lists_[part_id].insert(route);
422  assert(ret.second);
423 }
424 
425 //
426 // Delete the given MAC route as a dependent of this EvpnSegment.
427 // Trigger deletion of the EvpnSegment if there are no dependent
428 // routes in the partition.
429 //
430 void EvpnSegment::DeleteMacRoute(size_t part_id, EvpnRoute *route) {
431  size_t count = route_lists_[part_id].erase(route);
432  assert(count == 1);
433  if (route_lists_[part_id].empty())
435 }
436 
437 //
438 // Trigger an update of all dependent MAC routes for this EvpnSegment.
439 // Note that the bgp::EvpnSegment task is mutually exclusive with the
440 // db::DBTable task.
441 //
443  CHECK_CONCURRENCY("bgp::EvpnSegment");
444 
445  for (size_t part_id = 0; part_id < route_lists_.size(); ++part_id) {
446  EvpnManagerPartition *partition = evpn_manager_->GetPartition(part_id);
447  BOOST_FOREACH(EvpnRoute *route, route_lists_[part_id]) {
448  partition->TriggerMacRouteUpdate(route);
449  }
450  }
451 }
452 
453 //
454 // Update the PE list for this EvpnSegment. This should be called when
455 // the AutoDisocvery route is updated.
456 // Return true if there's a change in the PE list i.e. if an entry is
457 // added, deleted or updated.
458 //
460  CHECK_CONCURRENCY("bgp::EvpnSegment");
461 
462  // Mark all entries as invalid.
463  for (RemotePeList::iterator it = pe_list_.begin();
464  it != pe_list_.end(); ++it) {
465  it->esi_valid = false;
466  }
467 
468  // Go through all paths for the route and refresh/update existing entries
469  // or add new ones as necessary. Remember that there was a change in the
470  // list if any element changed or is added/deleted.
471  bool changed = false;
472  for (Route::PathList::const_iterator path_it =
473  esi_ad_route_->GetPathList().begin();
474  path_it != esi_ad_route_->GetPathList().end(); ++path_it) {
475  const BgpPath *path =
476  static_cast<const BgpPath *>(path_it.operator->());
477  const BgpAttr *attr = path->GetAttr();
478 
479  // Skip non-VXLAN paths for now.
480  const ExtCommunity *extcomm = attr->ext_community();
481  if (!extcomm || !extcomm->ContainsTunnelEncapVxlan())
482  continue;
483 
484  // Go through existing pe list and try to find the RemotePe.
485  bool found = false;
486  RemotePe remote_pe(path);
487  for (RemotePeList::iterator it = pe_list_.begin();
488  it != pe_list_.end(); ++it) {
489  // Skip if the nexthop doesn't match.
490  if (it->attr->nexthop() != remote_pe.attr->nexthop())
491  continue;
492 
493  // We're done if there are multiple paths for the same remote PE
494  // e.g. when a pair of route reflectors is being used.
495  if (it->esi_valid) {
496  found = true;
497  break;
498  }
499 
500  // Check if we have a match.
501  if (*it == remote_pe) {
502  it->esi_valid = true;
503  found = true;
504  break;
505  }
506  }
507 
508  // Add a new entry to the pe list if we didn't find the RemotePe.
509  if (!found) {
510  pe_list_.push_back(remote_pe);
511  changed = true;
512  }
513  }
514 
515  // Erase invalid entries from the list.
516  for (RemotePeList::iterator it = pe_list_.begin(), next = it;
517  it != pe_list_.end(); it = next) {
518  ++next;
519  if (!it->esi_valid) {
520  pe_list_.erase(it);
521  changed = true;
522  }
523  }
524 
525  // Update the single active status of the EvpnSegment itself.
526  single_active_ = false;
527  for (RemotePeList::iterator it = pe_list_.begin();
528  it != pe_list_.end(); ++it) {
529  if (it->single_active) {
530  single_active_ = true;
531  break;
532  }
533  }
534 
535  return changed;
536 }
537 
538 //
539 // Return true if it's safe to delete this EvpnSegment.
540 //
542  CHECK_CONCURRENCY("bgp::EvpnSegment");
543 
544  // Bail if we have state set on the per-ESI AD route.
545  if (esi_ad_route_)
546  return false;
547 
548  // Bail if the dependent route list for any partition is not empty.
549  for (size_t part_id = 0; part_id < route_lists_.size(); ++part_id) {
550  if (!route_lists_[part_id].empty())
551  return false;
552  }
553 
554  return true;
555 }
556 
557 //
558 // Constructor for EvpnSegment::RemotePe.
559 //
561  : esi_valid(true),
562  single_active(path->GetAttr()->evpn_single_active()),
563  peer(path->GetPeer()),
564  attr(path->GetAttr()),
565  flags(path->GetFlags()),
566  src(path->GetSource()) {
567 }
568 
569 //
570 // Equality operator for EvpnSegment::RemotePe.
571 // Do not compare esi_valid and single_active fields since they are
572 // derived.
573 //
575  if (peer != rhs.peer)
576  return false;
577  if (attr != rhs.attr)
578  return false;
579  if (flags != rhs.flags)
580  return false;
581  if (src != rhs.src)
582  return false;
583  return true;
584 }
585 
586 //
587 // Constructor for EvpnMacState.
588 //
590  : evpn_manager_(evpn_manager), route_(route), segment_(NULL) {
591 }
592 
593 //
594 // Destructor for EvpnMacState.
595 //
597  assert(segment_ == NULL);
598  assert(aliased_path_list_.empty());
599 }
600 
601 //
602 // Add the BgpPath specified by the iterator to the aliased path list.
603 // Also inserts the BgpPath to the BgpRoute.
604 //
605 void EvpnMacState::AddAliasedPath(AliasedPathList::const_iterator it) {
606  BgpPath *path = *it;
607  const IPeer *peer = path->GetPeer();
608  aliased_path_list_.insert(path);
609  route_->InsertPath(path);
610  BGP_LOG_STR(BgpMessage, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_TRACE,
611  "Added aliased path " << route_->ToString() <<
612  " peer " << (peer ? peer->ToString() : "None") <<
613  " nexthop " << path->GetAttr()->nexthop().to_string() <<
614  " label " << path->GetLabel() <<
615  " in table " << evpn_manager_->table()->name());
616 }
617 
618 //
619 // Delete the BgpPath specified by the iterator from the aliased path list.
620 // Also deletes the BgpPath from the BgpRoute.
621 //
622 void EvpnMacState::DeleteAliasedPath(AliasedPathList::const_iterator it) {
623  BgpPath *path = *it;
624  const IPeer *peer = path->GetPeer();
625  BGP_LOG_STR(BgpMessage, SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_TRACE,
626  "Deleted aliased path " << route_->ToString() <<
627  " peer " << (peer ? peer->ToString() : "None") <<
628  " nexthop " << path->GetAttr()->nexthop().to_string() <<
629  " label " << path->GetLabel() <<
630  " in table " << evpn_manager_->table()->name());
631  route_->DeletePath(path);
632  aliased_path_list_.erase(it);
633 }
634 
635 //
636 // Find or create the matching aliased BgpPath.
637 //
639  const EvpnSegment::RemotePe *remote_pe, uint32_t label) {
640  const IPeer *peer = remote_pe->peer;
641  const BgpAttr *attr = remote_pe->attr.get();
642  uint32_t flags = remote_pe->flags | BgpPath::AliasedPath;
643  BgpPath::PathSource src = remote_pe->src;
644  for (AliasedPathList::iterator it = aliased_path_list_.begin();
645  it != aliased_path_list_.end(); ++it) {
646  BgpPath *path = *it;
647  if (path->GetPeer() == peer &&
648  path->GetAttr() == attr &&
649  path->GetFlags() == flags &&
650  path->GetLabel() == label) {
651  return path;
652  }
653  }
654 
655  return (new BgpPath(peer, src, attr, flags, label));
656 }
657 
658 //
659 // Update aliased BgpPaths for the EvpnRoute based on the remote PEs
660 // for the EvpnSegment.
661 // Return true if the list of aliased paths is modified.
662 //
664  CHECK_CONCURRENCY("db::DBTable");
665 
666  const BgpPath *path = route_->BestPath();
667 
668  // Find the remote PE entry that corresponds to the primary path.
669  bool found_primary_pe = false;
671  if (path && segment_ && !segment_->single_active())
672  it = segment_->begin();
673  for (; path && segment_ && !segment_->single_active() &&
674  it != segment_->end(); ++it) {
675  if (path->GetAttr()->nexthop() != it->attr->nexthop())
676  continue;
677  found_primary_pe = true;
678  break;
679  }
680 
681  // Go through the remote PE list for the EvpnSegment and build the
682  // list of future aliased paths.
683  AliasedPathList future_aliased_path_list;
684  if (found_primary_pe && path && segment_ && !segment_->single_active())
685  it = segment_->begin();
686  for (; found_primary_pe && path && segment_ &&
687  !segment_->single_active() && it != segment_->end(); ++it) {
688  // Skip if there's a BGP_XMPP path with the remote PE as nexthop.
689  if (route_->FindPath(it->attr->nexthop()))
690  continue;
691 
692  // Locate the aliased path using attributes for the remote PE and
693  // label from the primary path.
694  BgpPath *aliased_path =
695  LocateAliasedPath(it.operator->(), path->GetLabel());
696  future_aliased_path_list.insert(aliased_path);
697  }
698 
699  // Reconcile the current and future aliased paths and notify/delete the
700  // route as appropriate.
701  bool modified = set_synchronize(&aliased_path_list_,
702  &future_aliased_path_list,
703  boost::bind(&EvpnMacState::AddAliasedPath, this, _1),
704  boost::bind(&EvpnMacState::DeleteAliasedPath, this, _1));
705  return modified;
706 }
707 
708 //
709 // Constructor for EvpnManagerPartition.
710 //
712  size_t part_id)
713  : evpn_manager_(evpn_manager),
714  part_id_(part_id),
715  mac_update_trigger_(new TaskTrigger(
716  boost::bind(&EvpnManagerPartition::ProcessMacUpdateList, this),
717  TaskScheduler::GetInstance()->GetTaskId("db::DBTable"),
718  part_id)) {
720 }
721 
722 //
723 // Destructor for EvpnManagerPartition.
724 //
726  assert(local_mcast_node_list_.empty());
727  assert(remote_mcast_node_list_.empty());
728  assert(mac_update_list_.empty());
729 }
730 
731 //
732 // Get the DBTablePartition for the EvpnTable for our partition id.
733 //
736 }
737 
738 //
739 // Notify the Broadcast MAC route for the given EvpnMcastNode.
740 //
742  DBTablePartition *tbl_partition = GetTablePartition();
743  tbl_partition->Notify(node->route());
744 }
745 
746 //
747 // Go through all replicator EvpnMcastNodes and notify associated Broadcast
748 // MAC route.
749 //
751  DBTablePartition *tbl_partition = GetTablePartition();
752  EvpnMcastNodeList::const_iterator it = replicator_node_list_.begin();
753  for (; it != replicator_node_list_.end(); it++) {
754  BOOST_FOREACH(EvpnMcastNode *node, it->second)
755  tbl_partition->Notify(node->route());
756  }
757 }
758 
759 //
760 // Go through all ingress replication client EvpnMcastNodes and notify the
761 // associated Broadcast MAC route.
762 //
764  bool exclude_edge_replication_supported) {
765  DBTablePartition *tbl_partition = GetTablePartition();
766  EvpnMcastNodeList::const_iterator it = ir_client_node_list_.begin();
767  for (; it != ir_client_node_list_.end(); it++) {
768  BOOST_FOREACH(EvpnMcastNode *node, it->second) {
769  if (exclude_edge_replication_supported &&
771  continue;
772  }
773  tbl_partition->Notify(node->route());
774  }
775  }
776 }
777 
778 //
779 // Add an EvpnMcastNode to the EvpnManagerPartition.
780 //
783  rt->GetPrefix().group());
784  if (node->type() == EvpnMcastNode::LocalNode) {
785  local_mcast_node_list_[sg].insert(node);
786  if (node->assisted_replication_supported())
787  replicator_node_list_[sg].insert(node);
788  if (!node->assisted_replication_leaf())
789  ir_client_node_list_[sg].insert(node);
790  NotifyNodeRoute(node);
791  } else {
792  remote_mcast_node_list_[sg].insert(node);
793  if (node->assisted_replication_leaf()) {
794  leaf_node_list_[sg].insert(node);
796  } else if (node->edge_replication_not_supported()) {
797  regular_node_list_[sg].insert(node);
799  } else if (!node->assisted_replication_leaf()) {
801  }
802  }
803 }
804 
805 //
806 // Delete an EvpnMcastNode from the EvpnManagerPartition.
807 //
809  EvpnMcastNode *node,
810  EvpnMcastNodeList *list) {
811  size_t deleted = 0;
812  if (list->count(sg)) {
813  deleted = (*list)[sg].erase(node);
814  if ((*list)[sg].size() == 0)
815  list->erase(sg);
816  }
817  return (deleted > 0);
818 }
819 
820 //
821 // Delete an EvpnMcastNode from the EvpnManagerPartition.
822 //
824  EvpnRoute * rt) {
826  rt->GetPrefix().group());
827  if (node->type() == EvpnMcastNode::LocalNode) {
831  } else {
833  if (RemoveMcastNodeFromList(sg, node, &leaf_node_list_)) {
835  } else {
837  }
840  }
841  }
842  if (empty())
844 }
845 
846 //
847 // Update an EvpnMcastNode in the EvpnManagerPartition.
848 // Need to remove/add EvpnMcastNode from the replicator, leaf and ir client
849 // lists as appropriate.
850 //
852  node->TriggerUpdate();
854  rt->GetPrefix().group());
855  if (node->type() == EvpnMcastNode::LocalNode) {
857  if (node->assisted_replication_supported())
858  replicator_node_list_[sg].insert(node);
860  if (!node->assisted_replication_leaf())
861  ir_client_node_list_[sg].insert(node);
862  NotifyNodeRoute(node);
863  } else {
864  bool was_leaf = RemoveMcastNodeFromList(sg, node, &leaf_node_list_);
865  if (node->assisted_replication_leaf())
866  leaf_node_list_[sg].insert(node);
867  if (was_leaf || node->assisted_replication_leaf())
869  if (!was_leaf || !node->assisted_replication_leaf())
871  bool was_regular = RemoveMcastNodeFromList(
872  sg, node, &regular_node_list_);
873  if (node->edge_replication_not_supported())
874  regular_node_list_[sg].insert(node);
875  if (was_regular || node->edge_replication_not_supported())
877  }
878 }
879 
880 //
881 // Add the given MAC route to the update list.
882 // This method gets called either when the MAC route itself changes or when
883 // the remote PE list for the EvpnSegment of the MAC route gets updated.
884 //
886  CHECK_CONCURRENCY("db::DBTable", "bgp::EvpnSegment");
887 
888  mac_update_list_.insert(route);
889  mac_update_trigger_->Set();
890 }
891 
892 //
893 // Process the MAC route update list for this EvpnManagerPartition.
894 //
896  CHECK_CONCURRENCY("db::DBTable");
897 
899  int listener_id = evpn_manager_->listener_id();
900 
901  BOOST_FOREACH(EvpnRoute *route, mac_update_list_) {
902  // Skip if the route is on the change list. We will get another
903  // chance to process it after the MacAdvertisement listener sees
904  // it and changes the EvpnMacState to point to the updated value
905  // of EvpnSegment.
906  if (route->is_onlist())
907  continue;
908 
909  EvpnMacState *mac_state =
910  dynamic_cast<EvpnMacState *>(route->GetState(table, listener_id));
911  assert(mac_state);
912  bool modified = mac_state->ProcessMacRouteAliasing();
913  if (route->HasPaths()) {
914  if (!mac_state->segment()) {
915  route->ClearState(table, listener_id);
916  delete mac_state;
917  }
918  if (modified) {
919  table_partition_->Notify(route);
920  }
921  } else {
922  route->ClearState(table, listener_id);
923  table_partition_->Delete(route);
924  delete mac_state;
925  }
926  }
927 
928  mac_update_list_.clear();
930  return true;
931 }
932 
934  Ip4Address *address) const {
936  return false;
937  uint32_t label;
938  vector<string> te;
940  rt, &label, address, &te);
941 }
942 
944  EvpnState::StatesMap::const_iterator iter = states_.find(sg);
945  return iter != states_.end() ? iter->second : NULL;
946 }
947 
949  EvpnState::StatesMap::iterator iter = states_.find(sg);
950  return iter != states_.end() ? iter->second : NULL;
951 }
952 
955  rt->GetPrefix().group());
956  return GetState(sg);
957 }
958 
960  EvpnStatePtr state(new EvpnState(sg, &states_, evpn_manager_));
961  assert(states_.insert(make_pair(sg, state.get())).second);
962  EVPN_TRACE(EvpnStateCreate, sg.source.to_string(), sg.group.to_string());
963  return state;
964 }
965 
967  EvpnStatePtr evpn_state = GetState(sg);
968  if (evpn_state)
969  return evpn_state;
970  evpn_state = CreateState(sg);
971  assert(evpn_state);
972  return evpn_state;
973 }
974 
977  rt->GetPrefix().group());
978  return LocateState(sg);
979 }
980 
981 //
982 // Disable processing of the update list.
983 // For testing only.
984 //
986  mac_update_trigger_->set_disable();
987 }
988 
989 //
990 // Enable processing of the update list.
991 // For testing only.
992 //
994  mac_update_trigger_->set_enable();
995 }
996 
997 //
998 // Return true if the EvpnManagerPartition is empty i.e. it has no local
999 // or remote EvpnMcastNodes and no MAC routes that need to be updated.
1000 //
1002  if (!local_mcast_node_list_.empty())
1003  return false;
1004  if (!remote_mcast_node_list_.empty())
1005  return false;
1006  if (!mac_update_list_.empty())
1007  return false;
1008  assert(leaf_node_list_.empty());
1009  assert(replicator_node_list_.empty());
1010  assert(regular_node_list_.empty());
1011  assert(ir_client_node_list_.empty());
1012  return true;
1013 }
1014 
1015 //
1016 // Return the BgpServer for the EvpnManagerPartition.
1017 //
1019  return evpn_manager_->server();
1020 }
1021 
1022 //
1023 // Return the EvpnTable for the EvpnManagerPartition.
1024 //
1026  return evpn_manager_->table();
1027 }
1028 
1029 //
1030 // Constructor for EvpnManager.
1031 //
1033  : table_(table),
1034  listener_id_(DBTable::kInvalidId),
1035  segment_delete_trigger_(new TaskTrigger(
1036  boost::bind(&EvpnManager::ProcessSegmentDeleteSet, this),
1037  TaskScheduler::GetInstance()->GetTaskId("bgp::EvpnSegment"), 0)),
1038  segment_update_trigger_(new TaskTrigger(
1039  boost::bind(&EvpnManager::ProcessSegmentUpdateSet, this),
1040  TaskScheduler::GetInstance()->GetTaskId("bgp::EvpnSegment"), 0)),
1041  table_delete_ref_(this, table->deleter()) {
1042  deleter_.reset(new DeleteActor(this));
1043  db_states_count_ = 0;
1044 }
1045 
1046 //
1047 // Destructor for EvpnManager.
1048 //
1050  assert(segment_map_.empty());
1051  assert(segment_delete_set_.empty());
1052  assert(segment_update_set_.empty());
1053 }
1054 
1055 //
1056 // Initialize the EvpnManager. We allocate the EvpnManagerPartitions
1057 // and register a DBListener for the EvpnTable.
1058 //
1060  AllocPartitions();
1062  boost::bind(&EvpnManager::RouteListener, this, _1, _2),
1063  "EvpnManager");
1064  ermvpn_table_ = dynamic_cast<ErmVpnTable *>(
1066  if (ermvpn_table_)
1068  boost::bind(&EvpnManager::ErmVpnRouteListener, this, _1, _2),
1069  "EvpnManager");
1070 }
1071 
1072 //
1073 // Terminate the EvpnManager. We free the EvpnManagerPartitions
1074 // and unregister from the EvpnTable.
1075 //
1077  CHECK_CONCURRENCY("bgp::Config");
1083  }
1084  FreePartitions();
1085 }
1086 
1087 //
1088 // Allocate the EvpnManagerPartitions.
1089 //
1091  for (int part_id = 0; part_id < DB::PartitionCount(); part_id++) {
1092  partitions_.push_back(new EvpnManagerPartition(this, part_id));
1093  }
1094 }
1095 
1096 //
1097 // Free the EvpnManagerPartitions.
1098 //
1101 }
1102 
1103 //
1104 // Disable processing of the update lists in all partitions.
1105 // For testing only.
1106 //
1108  for (int part_id = 0; part_id < DB::PartitionCount(); part_id++) {
1109  partitions_[part_id]->DisableMacUpdateProcessing();
1110  }
1111 }
1112 
1113 //
1114 // Enable processing of the update lists in all partitions.
1115 // For testing only.
1116 //
1118  for (int part_id = 0; part_id < DB::PartitionCount(); part_id++) {
1119  partitions_[part_id]->EnableMacUpdateProcessing();
1120  }
1121 }
1122 
1123 //
1124 // Get the EvpnManagerPartition for the given partition id.
1125 //
1127  return partitions_[part_id];
1128 }
1129 
1130 //
1131 // Get the DBTablePartition for the EvpnTable for given partition id.
1132 //
1134  return static_cast<DBTablePartition *>(table_->GetTablePartition(part_id));
1135 }
1136 
1137 //
1138 // Construct export state for the given EvpnRoute. Note that the route
1139 // only needs to be exported to the IPeer from which it was learnt.
1140 //
1142  CHECK_CONCURRENCY("db::DBTable");
1143 
1144  DBState *dbstate = route->GetState(table_, listener_id_);
1145  EvpnLocalMcastNode *local_node =
1146  dynamic_cast<EvpnLocalMcastNode *>(dbstate);
1147 
1148  if (!local_node)
1149  return NULL;
1150 
1151  return local_node->GetUpdateInfo(route);
1152 }
1153 
1155  return table_->server();
1156 }
1157 
1158 //
1159 // Find or create the EvpnSegment for the given EthernetSegmentId.
1160 //
1162  assert(!esi.IsZero());
1163  tbb::spin_rw_mutex::scoped_lock write_lock(segment_rw_mutex_, true);
1164  SegmentMap::iterator loc = segment_map_.find(esi);
1165  EvpnSegment *segment = (loc != segment_map_.end()) ? loc->second : NULL;
1166  if (!segment) {
1167  segment = new EvpnSegment(this, esi);
1168  segment_map_.insert(esi, segment);
1169  }
1170  return segment;
1171 }
1172 
1173 //
1174 // Find the EvpnSegment for the given EthernetSegmentId.
1175 //
1177  assert(!esi.IsZero());
1178  tbb::spin_rw_mutex::scoped_lock read_lock(segment_rw_mutex_, false);
1179  SegmentMap::iterator loc = segment_map_.find(esi);
1180  return (loc != segment_map_.end()) ? loc->second : NULL;
1181 }
1182 
1183 //
1184 // Trigger deletion of the given EvpnSegment.
1185 // The EvpnSegment is added to a set of EvpnSegments that can potentially
1186 // be deleted. This method can be invoked from multiple db::DBTable tasks
1187 // in parallel when a MAC routes are removed from the dependency list in an
1188 // EvpnSegment. Hence we ensure exclusive access using a write lock.
1189 //
1190 // The list is processed from the context of bgp::EvpnSegment task which is
1191 // mutually exclusive with db::DBTable task.
1192 //
1194  CHECK_CONCURRENCY("db::DBTable", "bgp::EvpnSegment");
1195 
1196  tbb::spin_rw_mutex::scoped_lock write_lock(segment_rw_mutex_, true);
1197  segment_delete_set_.insert(segment);
1198  segment_delete_trigger_->Set();
1199 }
1200 
1201 //
1202 // Process the set of EvpnSegments that can potentially be deleted.
1203 // Remove the EvpnSegment from the map and destroy if it's fine to
1204 // to delete the EvpnSegment.
1205 //
1207  CHECK_CONCURRENCY("bgp::EvpnSegment");
1208 
1209  BOOST_FOREACH(EvpnSegment *segment, segment_delete_set_) {
1210  if (segment->MayDelete()) {
1211  segment_update_set_.erase(segment);
1212  EthernetSegmentId esi = segment->esi();
1213  segment_map_.erase(esi);
1214  }
1215  }
1216  segment_delete_set_.clear();
1217  RetryDelete();
1218  return true;
1219 }
1220 
1221 //
1222 // Disable processing of the delete list.
1223 // For testing only.
1224 //
1226  segment_delete_trigger_->set_disable();
1227 }
1228 
1229 //
1230 // Enable processing of the delete list.
1231 // For testing only.
1232 //
1234  segment_delete_trigger_->set_enable();
1235 }
1236 
1237 //
1238 // Trigger update of the given EvpnSegment.
1239 // The EvpnSegment is added to a set of EvpnSegments for which updates
1240 // need triggered. This method is called in the context of db::DBTable
1241 // task and a task instance of 0 since all AutoDisocvery routes always
1242 // get sharded to partition 0.
1243 //
1244 // The set is processed in the context of bgp::EvpnSegment task, which
1245 // is mutually exclusive with db::DBTable task.
1246 //
1248  CHECK_CONCURRENCY("db::DBTable");
1249 
1250  segment_update_set_.insert(segment);
1251  segment_update_trigger_->Set();
1252 }
1253 
1254 //
1255 // Process the set of EvpnSegments that need to be updated.
1256 //
1257 // Go through each EvpnSegment and update it's PE list. Trigger updates
1258 // of all it's dependent MAC routes if there's a change in the PE list.
1259 //
1261  CHECK_CONCURRENCY("bgp::EvpnSegment");
1262 
1263  BOOST_FOREACH(EvpnSegment *segment, segment_update_set_) {
1264  EvpnRoute *esi_ad_route = segment->esi_ad_route();
1265  bool changed = segment->UpdatePeList();
1266  if (changed)
1267  segment->TriggerMacRouteUpdate();
1268  if (!esi_ad_route->IsValid()) {
1269  segment->clear_esi_ad_route();
1270  esi_ad_route->ClearState(table_, listener_id_);
1271  TriggerSegmentDelete(segment);
1272  }
1273  }
1274  segment_update_set_.clear();
1275  RetryDelete();
1276  return true;
1277 }
1278 
1279 //
1280 // Disable processing of the update list.
1281 // For testing only.
1282 //
1284  segment_update_trigger_->set_disable();
1285 }
1286 
1287 //
1288 // Enable processing of the update list.
1289 // For testing only.
1290 //
1292  segment_update_trigger_->set_enable();
1293 }
1294 
1295 //
1296 // DBListener callback handler for AutoDisocvery routes in the EvpnTable.
1297 //
1299  CHECK_CONCURRENCY("db::DBTable");
1300 
1301  DBState *dbstate = route->GetState(table_, listener_id_);
1302  if (!dbstate) {
1303  // We have no previous DBState for this route.
1304  // Bail if the route is not valid.
1305  if (!route->IsValid())
1306  return;
1307 
1308  // Locate the EvpnSegment and associate it with the route.
1309  // Trigger an update of EvpnSegment so that it's PE list
1310  // gets updated.
1311  EvpnSegment *segment = LocateSegment(route->GetPrefix().esi());
1312  segment->set_esi_ad_route(route);
1313  route->SetState(table_, listener_id_, segment);
1314  TriggerSegmentUpdate(segment);
1315  } else {
1316  // Trigger an update of EvpnSegment so that it's PE list
1317  // gets updated.
1318  EvpnSegment *segment = dynamic_cast<EvpnSegment *>(dbstate);
1319  assert(segment);
1320  TriggerSegmentUpdate(segment);
1321  }
1322 }
1323 
1324 //
1325 // DBListener callback handler for MacAdvertisement routes in the EvpnTable.
1326 //
1328  EvpnManagerPartition *partition, EvpnRoute *route) {
1329  CHECK_CONCURRENCY("db::DBTable");
1330 
1331  DBState *dbstate = route->GetState(table_, listener_id_);
1332  if (!dbstate) {
1333  // We have no previous DBState for this route.
1334  // Bail if the route is not valid or if it doesn't have an ESI.
1335  if (!route->IsValid())
1336  return;
1337  const BgpPath *path = route->BestPath();
1338  if (path->GetAttr()->esi().IsZero())
1339  return;
1340 
1341  // Create a new EvpnMacState and associate it with the route.
1342  EvpnMacState *mac_state = new EvpnMacState(this, route);
1343  route->SetState(table_, listener_id_, mac_state);
1344 
1345  // Locate the EvpnSegment and add the MAC route as a dependent
1346  // of the EvpnSegment.
1347  EvpnSegment *segment = LocateSegment(path->GetAttr()->esi());
1348  mac_state->set_segment(segment);
1349  segment->AddMacRoute(partition->part_id(), route);
1350  partition->TriggerMacRouteUpdate(route);
1351  } else {
1352  EvpnMacState *mac_state = dynamic_cast<EvpnMacState *>(dbstate);
1353  assert(mac_state);
1354  EvpnSegment *segment = mac_state->segment();
1355 
1356  // Handle change in the ESI and update the dependency on the
1357  // EvpnSegment as appropriate.
1358  // Note that the DBState on the EvpnRoute doesn't get cleared
1359  // here. That only happens when aliasing for the route is being
1360  // processed.
1361  const BgpPath *path = route->BestPath();
1362  if (!route->IsValid() || (path && path->GetAttr()->esi().IsZero())) {
1363  if (segment) {
1364  segment->DeleteMacRoute(partition->part_id(), route);
1365  mac_state->clear_segment();
1366  }
1367  } else if (!segment && !path->GetAttr()->esi().IsZero()) {
1368  segment = LocateSegment(path->GetAttr()->esi());
1369  mac_state->set_segment(segment);
1370  segment->AddMacRoute(partition->part_id(), route);
1371  } else if (segment && segment->esi() != path->GetAttr()->esi()) {
1372  segment->DeleteMacRoute(partition->part_id(), route);
1373  mac_state->clear_segment();
1374  segment = LocateSegment(path->GetAttr()->esi());
1375  mac_state->set_segment(segment);
1376  segment->AddMacRoute(partition->part_id(), route);
1377  }
1378  partition->TriggerMacRouteUpdate(route);
1379  }
1380 }
1381 
1382 //
1383 // DBListener callback handler for InclusiveMulticast routes in the EvpnTable.
1384 //
1386  EvpnManagerPartition *partition, EvpnRoute *route) {
1387  CHECK_CONCURRENCY("db::DBTable");
1388 
1389  DBState *dbstate = route->GetState(table_, listener_id_);
1390  if (!dbstate) {
1391  // We have no previous DBState for this route.
1392  // Bail if the route is not valid.
1393  if (!route->IsValid())
1394  return;
1395 
1396  // Create a new EvpnMcastNode and associate it with the route.
1397  EvpnMcastNode *node;
1398  if (route->GetPrefix().type() == EvpnPrefix::MacAdvertisementRoute) {
1399  node = new EvpnLocalMcastNode(partition, route);
1400  } else {
1401  node = new EvpnRemoteMcastNode(partition, route);
1402  }
1403  partition->AddMcastNode(node, route);
1404  route->SetState(table_, listener_id_, node);
1405  } else {
1406  EvpnMcastNode *node = dynamic_cast<EvpnMcastNode *>(dbstate);
1407  assert(node);
1408 
1409  if (!route->IsValid()) {
1410  // Delete the EvpnMcastNode associated with the route.
1411  route->ClearState(table_, listener_id_);
1412  partition->DeleteMcastNode(node, route);
1413  delete node;
1414  } else if (node->UpdateAttributes(route)) {
1415  // Update the EvpnMcastNode associated with the route.
1416  partition->UpdateMcastNode(node, route);
1417  }
1418  }
1419 }
1420 
1421 //
1422 // DBListener callback handler for SelectiveMulticast routes in the EvpnTable.
1423 //
1425  EvpnManagerPartition *partition, EvpnRoute *route) {
1426 
1427  CHECK_CONCURRENCY("db::DBTable");
1428  EvpnMcastNode *dbstate = dynamic_cast<EvpnMcastNode *>(
1429  route->GetState(table_, listener_id_));
1430  bool is_usable = route->IsUsable();
1431  bool is_deleted = route->IsDeleted();
1432  bool checkErmvpnRoute = false;
1433  if (route->BestPath()) {
1434  checkErmvpnRoute = route->BestPath()->GetFlags() &
1436  }
1437  if ((!is_usable && !checkErmvpnRoute) || is_deleted) {
1438  if (!dbstate)
1439  return;
1440 
1441  EvpnStatePtr evpn_state = partition->GetState(route);
1442  if (evpn_state)
1443  evpn_state->smet_routes().erase(route);
1444  EVPN_RT_LOG(route, "Processed Smet route deletion");
1445  ClearDBState(route);
1446  partition->NotifyForestNode(route, ermvpn_table());
1447  partition->DeleteMcastNode(dbstate, route);
1448  delete dbstate;
1449  return;
1450  }
1451 
1452  EvpnStatePtr evpn_state = partition->LocateState(route);
1453  assert(evpn_state);
1454  evpn_state->smet_routes().insert(route);
1455  BgpPath *path = const_cast<BgpPath *>(route->BestPath());
1456  if (path && path->CheckErmVpn()) {
1457  ErmVpnRoute *global_rt = evpn_state->global_ermvpn_tree_rt();
1458  Ip4Address address;
1459  bool nh_found = partition->GetForestNodeAddress(global_rt, &address);
1460  if (nh_found) {
1461  BgpAttrPtr attr = path->GetAttr();
1462  BgpAttrPtr new_attr = partition->server()->attr_db()->
1463  ReplaceNexthopAndLocate(attr.get(), address);
1464  path->SetAttr(new_attr, attr);
1465  path->ResetCheckErmVpn();
1466  partition->NotifyForestNode(route, ermvpn_table());
1467  }
1468  }
1469 
1470  if (!dbstate) {
1471  // Create a new DBState and associate it with the route.
1472  EvpnMcastNode *node;
1473  if (route->GetPrefix().ip_address() ==
1475  node = new EvpnLocalMcastNode(partition, route, evpn_state);
1476  } else {
1477  node = new EvpnRemoteMcastNode(partition, route, evpn_state);
1478  }
1479  SetDBState(route, node);
1480  partition->AddMcastNode(node, route);
1481  EVPN_RT_LOG(route, "Processed Smet route creation");
1482  }
1483 }
1484 
1486  ErmVpnTable *table) {
1487  const Ip4Address &source = route->GetPrefix().source().to_v4();
1488  const Ip4Address &group = route->GetPrefix().group().to_v4();
1489  if (table->tree_manager())
1490  table->tree_manager()->NotifyForestNode(part_id_, source, group);
1491 }
1492 
1493 // Set DB State and update count.
1495  route->SetState(table_, listener_id_, dbstate);
1496  db_states_count_++;
1497 }
1498 
1499 // Create DB State and update count. If there is no DB State associated in the
1500 // table, resume table deletion if the deletion was pending.
1502  route->ClearState(table_, listener_id_);
1503  assert(db_states_count_);
1504  db_states_count_--;
1505 
1506  // Retry deletion now as there is no more attached db state in the table.
1507  if (!db_states_count_ && deleter_->IsDeleted())
1508  deleter_->RetryDelete();
1509 }
1510 
1511 // Check whether an ErmVpnRoute is locally originated GlobalTreeRoute.
1513  ErmVpnRoute *ermvpn_route) const {
1514  if (!ermvpn_route || !ermvpn_route->IsUsable())
1515  return false;
1516  if (!ermvpn_table()->tree_manager())
1517  return false;
1518  if (ermvpn_table()->tree_manager()->begin() ==
1519  ermvpn_table()->tree_manager()->end())
1520  return false;
1521  ErmVpnRoute *global_rt = ermvpn_table()->tree_manager()->
1522  GetGlobalTreeRootRoute(
1523  ermvpn_route->GetPrefix().source(),
1524  ermvpn_route->GetPrefix().group());
1525  return (global_rt && global_rt == ermvpn_route);
1526 }
1527 
1528 // ErmVpnTable route listener callback function.
1529 //
1530 // Process changes (create/update/delete) to GlobalErmVpnRoute in vrf.ermvpn.0
1532  DBEntryBase *db_entry) {
1533  CHECK_CONCURRENCY("db::DBTable");
1534 
1535  ErmVpnRoute *ermvpn_route = dynamic_cast<ErmVpnRoute *>(db_entry);
1536  assert(ermvpn_route);
1537 
1538  // We only care about global tree routes for evpn stitching.
1539  if (ermvpn_route->GetPrefix().type() != ErmVpnPrefix::GlobalTreeRoute) {
1540  return;
1541  }
1542 
1543  EvpnMcastNode *dbstate = dynamic_cast<EvpnMcastNode *>(
1544  ermvpn_route->GetState(ermvpn_table(), ermvpn_listener_id()));
1545 
1546  // Handle GlobalTreeRoute route deletion.
1547  if (!IsUsableGlobalTreeRootRoute(ermvpn_route)) {
1548  // Ignore if there is no DB State associated with route.
1549  if (!dbstate)
1550  return;
1551  EvpnStatePtr evpn_state = dbstate->state();
1552  evpn_state->set_global_ermvpn_tree_rt(NULL);
1553 
1554  // Notify all received smet routes for PMSI re-computation.
1555  // Since usable global ermvpn is no longer available, any advertised
1556  // smet routes must now be withdrawn.
1557  BOOST_FOREACH(EvpnRoute *route, evpn_state->smet_routes()) {
1558  BgpPath *path = const_cast<BgpPath *>(route->BestPath());
1559  if (path && (path->GetPathId() == 0)) {
1560  path->SetCheckErmVpn();
1561  }
1562  route->Notify();
1563  }
1564  ermvpn_route->ClearState(ermvpn_table(), ermvpn_listener_id());
1565  EVPN_ERMVPN_RT_LOG(ermvpn_route,
1566  "Processed EVPN GlobalErmVpnRoute deletion");
1567  delete dbstate;
1568  return;
1569  }
1570 
1571  // Set DB State in the route if not already done so before.
1572  EvpnManagerPartition *partition = GetPartition(tpart->index());
1573  EvpnStatePtr evpn_state;
1574  if (!dbstate) {
1575  EvpnState::SG sg(ermvpn_route);
1576  evpn_state = partition->LocateState(sg);
1577  dbstate = new EvpnLocalMcastNode(partition, NULL, evpn_state);
1578  ermvpn_route->SetState(ermvpn_table(), ermvpn_listener_id(), dbstate);
1579  } else {
1580  evpn_state = dbstate->state();
1581  }
1582 
1583  // Note down current usable ermvpn route for stitching to evpn.
1584  dbstate->state()->set_global_ermvpn_tree_rt(ermvpn_route);
1585 
1586  // Notify all originated Type6 routes.
1587  BOOST_FOREACH(EvpnRoute *route, evpn_state->smet_routes()) {
1588  route->Notify();
1589  }
1590  EVPN_ERMVPN_RT_LOG(ermvpn_route,
1591  "Processed EVPN GlobalErmVpnRoute creation");
1592 }
1593 
1594 //
1595 // DBListener callback handler for the EvpnTable.
1596 //
1598  CHECK_CONCURRENCY("db::DBTable");
1599 
1600  EvpnManagerPartition *partition = GetPartition(tpart->index());
1601  EvpnRoute *route = dynamic_cast<EvpnRoute *>(db_entry);
1602  assert(route);
1603 
1604  switch (route->GetPrefix().type()) {
1607  break;
1609  if (route->GetPrefix().mac_addr().IsBroadcast()) {
1610  InclusiveMulticastRouteListener(partition, route);
1611  } else {
1612  MacAdvertisementRouteListener(partition, route);
1613  }
1614  break;
1616  InclusiveMulticastRouteListener(partition, route);
1617  break;
1619  SelectiveMulticastRouteListener(partition, route);
1620  break;
1621  default:
1622  break;
1623  }
1624 }
1625 
1626 //
1627 // Fill information for introspect command.
1628 // Note that all IM routes are always in partition 0.
1629 //
1630 void EvpnManager::FillShowInfo(ShowEvpnTable *sevt) const {
1631  CHECK_CONCURRENCY("db::DBTable");
1632 
1633  vector<string> regular_nves;
1634  vector<string> ar_replicators;
1635  vector<ShowEvpnMcastLeaf> ar_leafs;
1636  EvpnManagerPartition::EvpnMcastNodeList::const_iterator it =
1637  partitions_[0]->remote_mcast_node_list()->begin();
1638  for (; it != partitions_[0]->remote_mcast_node_list()->end(); it++) {
1639  BOOST_FOREACH(const EvpnMcastNode *node, it->second) {
1640  if (node->assisted_replication_leaf()) {
1641  ShowEvpnMcastLeaf leaf;
1642  leaf.set_address(node->address().to_string());
1643  leaf.set_replicator(node->replicator_address().to_string());
1644  ar_leafs.push_back(leaf);
1645  } else if (node->assisted_replication_supported()) {
1646  ar_replicators.push_back(node->address().to_string());
1647  } else if (node->edge_replication_not_supported()) {
1648  regular_nves.push_back(node->address().to_string());
1649  }
1650  }
1651  }
1652 
1653  sort(regular_nves.begin(), regular_nves.end());
1654  sort(ar_replicators.begin(), ar_replicators.end());
1655  sort(ar_leafs.begin(), ar_leafs.end());
1656  sevt->set_regular_nves(regular_nves);
1657  sevt->set_ar_replicators(ar_replicators);
1658  sevt->set_ar_leafs(ar_leafs);
1659 }
1660 
1661 //
1662 // Check if the EvpnManager can be deleted. This can happen only if all the
1663 // EvpnManagerPartitions are empty.
1664 //
1666  CHECK_CONCURRENCY("bgp::Config");
1667 
1668  if (!segment_map_.empty())
1669  return false;
1670 
1671  if (!segment_update_set_.empty())
1672  return false;
1673  if (segment_update_trigger_->IsSet())
1674  return false;
1675 
1676  if (!segment_delete_set_.empty())
1677  return false;
1678  if (segment_delete_trigger_->IsSet())
1679  return false;
1680 
1681  BOOST_FOREACH(const EvpnManagerPartition *partition, partitions_) {
1682  if (!partition->empty())
1683  return false;
1684  if (!partition->states().empty())
1685  return false;
1686  }
1687  if (db_states_count_)
1688  return false;
1689  return true;
1690 }
1691 
1692 //
1693 // Initiate shutdown for the EvpnManager.
1694 //
1696  CHECK_CONCURRENCY("bgp::Config");
1697 }
1698 
1699 //
1700 // Trigger deletion of the EvpnManager and propagate the delete to any
1701 // dependents.
1702 //
1704  deleter_->Delete();
1705 }
1706 
1707 //
1708 // Attempt to enqueue a delete for the EvpnManager.
1709 //
1711  if (!deleter()->IsDeleted())
1712  return;
1713  deleter()->RetryDelete();
1714 }
1715 
1716 //
1717 // Return the LifetimeActor for the EvpnManager.
1718 //
1720  return deleter_.get();
1721 }
1722 
1723 EvpnState::SG::SG(const Ip4Address &source, const Ip4Address &group) :
1724  source(IpAddress(source)), group(IpAddress(group)) {
1725 }
1726 
1728  source(route->GetPrefix().source()),
1729  group(route->GetPrefix().group()) {
1730 }
1731 
1733  source(route->GetPrefix().source()), group(route->GetPrefix().group()) {
1734 }
1735 
1736 EvpnState::SG::SG(const IpAddress &source, const IpAddress &group) :
1737  source(source), group(group) {
1738 }
1739 
1740 bool EvpnState::SG::operator<(const SG &other) const {
1741  if (source < other.source)
1742  return true;
1743  if (source > other.source)
1744  return false;
1745  if (group < other.group)
1746  return true;
1747  if (group > other.group)
1748  return false;
1749  return false;
1750 }
1751 
1753  return sg_;
1754 }
1755 
1758 }
1759 
1761  return global_ermvpn_tree_rt_;
1762 }
1763 
1765  return global_ermvpn_tree_rt_;
1766 }
boost::asio::ip::address IpAddress
Definition: address.h:14
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
boost::intrusive_ptr< const BgpAttr > BgpAttrPtr
Definition: bgp_attr.h:999
#define EVPN_RT_LOG(rt,...)
Definition: bgp_evpn.h:789
#define EVPN_ERMVPN_RT_LOG(rt,...)
Definition: bgp_evpn.h:797
boost::intrusive_ptr< EvpnState > EvpnStatePtr
Definition: bgp_evpn.h:36
#define EVPN_TRACE(type,...)
Definition: bgp_evpn.h:805
#define BGP_LOG_FLAG_TRACE
Definition: bgp_log.h:44
#define BGP_LOG_ROUTE(table, peer, route, arg)
Definition: bgp_log.h:248
#define BGP_LOG_STR(obj, level, flags, arg)
Definition: bgp_log.h:90
@ ERMVPN
Definition: address.h:33
BgpAttrPtr ReplaceOListAndLocate(const BgpAttr *attr, const BgpOListSpec *olist_spec)
Definition: bgp_attr.cc:1423
BgpAttrPtr ReplaceLeafOListAndLocate(const BgpAttr *attr, const BgpOListSpec *leaf_olist_spec)
Definition: bgp_attr.cc:1432
BgpAttrPtr ReplaceExtCommunityAndLocate(const BgpAttr *attr, ExtCommunityPtr extcomm)
Definition: bgp_attr.cc:1367
const IpAddress & nexthop() const
Definition: bgp_attr.h:889
const ExtCommunity * ext_community() const
Definition: bgp_attr.h:918
const EthernetSegmentId & esi() const
Definition: bgp_attr.h:900
uint32_t GetLabel() const
Definition: bgp_path.h:90
void SetAttr(const BgpAttrPtr attr, const BgpAttrPtr original_attr)
Definition: bgp_path.h:83
void ResetCheckErmVpn()
Definition: bgp_path.h:140
uint32_t GetFlags() const
Definition: bgp_path.h:101
IPeer * GetPeer()
Definition: bgp_path.h:77
const uint32_t GetPathId() const
Definition: bgp_path.h:79
PathSource
Definition: bgp_path.h:38
@ Local
Definition: bgp_path.h:44
const BgpAttr * GetAttr() const
Definition: bgp_path.h:88
void SetCheckErmVpn()
Definition: bgp_path.h:141
bool CheckErmVpn() const
Definition: bgp_path.h:137
@ CheckGlobalErmVpnRoute
Definition: bgp_path.h:34
@ AliasedPath
Definition: bgp_path.h:33
const BgpPath * FindPath(BgpPath::PathSource src) const
Definition: bgp_route.cc:147
bool RemovePath(BgpPath::PathSource src, const IPeer *peer=NULL, uint32_t path_id=0)
Definition: bgp_route.cc:264
const BgpPath * BestPath() const
Definition: bgp_route.cc:48
void DeletePath(BgpPath *path)
Definition: bgp_route.cc:128
bool IsUsable() const
Definition: bgp_route.cc:326
void InsertPath(BgpPath *path)
Definition: bgp_route.cc:62
bool HasPaths() const
Definition: bgp_route.h:29
ExtCommunityDB * extcomm_db()
Definition: bgp_server.h:194
uint32_t bgp_identifier() const
Definition: bgp_server.h:216
BgpAttrDB * attr_db()
Definition: bgp_server.h:188
BgpServer * server()
Definition: bgp_table.cc:88
RoutingInstance * routing_instance()
Definition: bgp_table.h:148
DBState * GetState(DBTableBase *tbl_base, ListenerId listener) const
Definition: db_entry.cc:38
void Notify()
Definition: db_entry.cc:128
void ClearState(DBTableBase *tbl_base, ListenerId listener)
Definition: db_entry.cc:74
void ClearDelete()
Definition: db_entry.h:48
bool IsDeleted() const
Definition: db_entry.h:49
bool is_onlist()
Definition: db_entry.h:53
void SetState(DBTableBase *tbl_base, ListenerId listener, DBState *state)
Definition: db_entry.cc:23
ListenerId Register(ChangeCallback callback, const std::string &name="unspecified")
Definition: db_table.cc:208
static const int kInvalidId
Definition: db_table.h:65
void Unregister(ListenerId listener)
Definition: db_table.cc:213
const std::string & name() const
Definition: db_table.h:111
void Notify(DBEntryBase *entry)
void Delete(DBEntryBase *)
virtual void Add(DBEntry *entry)
DBEntry * Find(const DBEntry *entry)
virtual DBTablePartBase * GetTablePartition(const DBRequestKey *key)
Definition: db_table.cc:463
Definition: db.h:25
static int PartitionCount()
Definition: db.cc:32
Ip4Address source() const
Definition: ermvpn_route.h:61
uint8_t type() const
Definition: ermvpn_route.h:57
Ip4Address group() const
Definition: ermvpn_route.h:60
const ErmVpnPrefix & GetPrefix() const
Definition: ermvpn_route.h:82
const McastTreeManager * tree_manager() const
Definition: ermvpn_table.h:65
bool IsZero() const
Definition: esi.h:44
This class represents (in the context of an EVPN instance) a local vRouter that's connected to a cont...
Definition: bgp_evpn.h:126
virtual ~EvpnLocalMcastNode()
Definition: bgp_evpn.cc:207
EvpnRoute * inclusive_mcast_route_
Definition: bgp_evpn.h:159
EvpnLocalMcastNode(EvpnManagerPartition *partition, EvpnRoute *route)
Constructor for EvpnLocalMcastNode.
Definition: bgp_evpn.cc:184
UpdateInfo * GetUpdateInfo(EvpnRoute *route)
Definition: bgp_evpn.cc:303
virtual void TriggerUpdate()
Handle update of EvpnLocalMcastNode.
Definition: bgp_evpn.cc:289
void DeleteInclusiveMulticastRoute()
Delete Inclusive Multicast route for this EvpnLocalMcastNode.
Definition: bgp_evpn.cc:263
void AddInclusiveMulticastRoute()
Add Inclusive Multicast route for this EvpnLocalMcastNode. The attributes are based on the Broadcast ...
Definition: bgp_evpn.cc:215
This class represents the EvpnManager state associated with a MAC route.
Definition: bgp_evpn.h:289
BgpPath * LocateAliasedPath(const EvpnSegment::RemotePe *remote_pe, uint32_t label)
Find or create the matching aliased BgpPath.
Definition: bgp_evpn.cc:638
EvpnRoute * route_
Definition: bgp_evpn.h:320
void clear_segment()
Definition: bgp_evpn.h:302
std::set< BgpPath * > AliasedPathList
Definition: bgp_evpn.h:305
void set_segment(EvpnSegment *segment)
Definition: bgp_evpn.h:301
void DeleteAliasedPath(AliasedPathList::const_iterator it)
Delete the BgpPath specified by the iterator from the aliased path list. Also deletes the BgpPath fro...
Definition: bgp_evpn.cc:622
bool ProcessMacRouteAliasing()
Update aliased BgpPaths for the EvpnRoute based on the remote PEs for the EvpnSegment....
Definition: bgp_evpn.cc:663
EvpnSegment * segment_
Definition: bgp_evpn.h:321
void AddAliasedPath(AliasedPathList::const_iterator it)
Add the BgpPath specified by the iterator to the aliased path list. Also inserts the BgpPath to the B...
Definition: bgp_evpn.cc:605
EvpnMacState(EvpnManager *evpn_manager, EvpnRoute *route)
Definition: bgp_evpn.cc:589
EvpnManager * evpn_manager_
Definition: bgp_evpn.h:319
AliasedPathList aliased_path_list_
Definition: bgp_evpn.h:322
EvpnSegment * segment()
Definition: bgp_evpn.h:299
This class represents a partition in the EvpnManager.
Definition: bgp_evpn.h:420
size_t part_id() const
Definition: bgp_evpn.h:491
void NotifyIrClientNodeRoutes(bool exclude_edge_replication_supported)
Go through all ingress replication client EvpnMcastNodes and notify the associated Broadcast MAC rout...
Definition: bgp_evpn.cc:763
const EvpnMcastNodeList & leaf_node_list() const
Definition: bgp_evpn.h:472
std::map< SG, std::set< EvpnMcastNode * > > EvpnMcastNodeList
Definition: bgp_evpn.h:423
void NotifyReplicatorNodeRoutes()
Go through all replicator EvpnMcastNodes and notify associated Broadcast MAC route.
Definition: bgp_evpn.cc:750
void TriggerMacRouteUpdate(EvpnRoute *route)
Add the given MAC route to the update list. This method gets called either when the MAC route itself ...
Definition: bgp_evpn.cc:885
EvpnManagerPartition(EvpnManager *evpn_manager, size_t part_id)
Definition: bgp_evpn.cc:711
EvpnMcastNodeList leaf_node_list_
Definition: bgp_evpn.h:528
EvpnMcastNodeList local_mcast_node_list_
Definition: bgp_evpn.h:525
bool RemoveMcastNodeFromList(EvpnState::SG &sg, EvpnMcastNode *node, EvpnMcastNodeList *list)
Delete an EvpnMcastNode from the EvpnManagerPartition.
Definition: bgp_evpn.cc:808
bool ProcessMacUpdateList()
Process the MAC route update list for this EvpnManagerPartition.
Definition: bgp_evpn.cc:895
void UpdateMcastNode(EvpnMcastNode *node, EvpnRoute *route)
Update an EvpnMcastNode in the EvpnManagerPartition. Need to remove/add EvpnMcastNode from the replic...
Definition: bgp_evpn.cc:851
EvpnManager * evpn_manager_
Definition: bgp_evpn.h:521
EvpnState::StatesMap states_
Definition: bgp_evpn.h:523
void AddMcastNode(EvpnMcastNode *node, EvpnRoute *route)
Add an EvpnMcastNode to the EvpnManagerPartition.
Definition: bgp_evpn.cc:781
EvpnRouteList mac_update_list_
Definition: bgp_evpn.h:531
void NotifyNodeRoute(EvpnMcastNode *node)
Notify the Broadcast MAC route for the given EvpnMcastNode.
Definition: bgp_evpn.cc:741
EvpnMcastNodeList replicator_node_list_
Definition: bgp_evpn.h:527
void EnableMacUpdateProcessing()
Enable processing of the update list. For testing only.
Definition: bgp_evpn.cc:993
EvpnMcastNodeList regular_node_list_
Definition: bgp_evpn.h:529
boost::scoped_ptr< TaskTrigger > mac_update_trigger_
Definition: bgp_evpn.h:532
EvpnStatePtr GetState(const SG &sg)
Definition: bgp_evpn.cc:948
void DisableMacUpdateProcessing()
Disable processing of the update list. For testing only.
Definition: bgp_evpn.cc:985
void NotifyForestNode(EvpnRoute *route, ErmVpnTable *table)
Definition: bgp_evpn.cc:1485
EvpnMcastNodeList ir_client_node_list_
Definition: bgp_evpn.h:530
bool GetForestNodeAddress(ErmVpnRoute *rt, Ip4Address *address) const
Definition: bgp_evpn.cc:933
EvpnStatePtr CreateState(const SG &sg)
Definition: bgp_evpn.cc:959
DBTablePartition * GetTablePartition()
Get the DBTablePartition for the EvpnTable for our partition id.
Definition: bgp_evpn.cc:734
DBTablePartition * table_partition_
Definition: bgp_evpn.h:523
void DeleteMcastNode(EvpnMcastNode *node, EvpnRoute *route)
Delete an EvpnMcastNode from the EvpnManagerPartition.
Definition: bgp_evpn.cc:823
const EvpnState::StatesMap & states() const
Definition: bgp_evpn.h:516
const EvpnMcastNodeList & remote_mcast_node_list() const
Definition: bgp_evpn.h:466
bool empty() const
Return true if the EvpnManagerPartition is empty i.e. it has no local or remote EvpnMcastNodes and no...
Definition: bgp_evpn.cc:1001
BgpServer * server()
Return the BgpServer for the EvpnManagerPartition.
Definition: bgp_evpn.cc:1018
EvpnMcastNodeList remote_mcast_node_list_
Definition: bgp_evpn.h:526
EvpnStatePtr LocateState(EvpnRoute *route)
Definition: bgp_evpn.cc:975
const EvpnTable * table() const
Return the EvpnTable for the EvpnManagerPartition.
Definition: bgp_evpn.cc:1025
DeleteActor(EvpnManager *evpn_manager)
Definition: bgp_evpn.cc:52
virtual bool MayDelete() const
Definition: bgp_evpn.cc:59
virtual void Shutdown()
Definition: bgp_evpn.cc:64
virtual void Destroy()
Definition: bgp_evpn.cc:68
EvpnManager * evpn_manager_
Definition: bgp_evpn.cc:73
This class represents the EVPN manager for an EvpnTable in a VRF.
Definition: bgp_evpn.h:580
void ErmVpnRouteListener(DBTablePartBase *tpart, DBEntryBase *db_entry)
ErmVpnTable route listener callback function.
Definition: bgp_evpn.cc:1531
void RouteListener(DBTablePartBase *tpart, DBEntryBase *db_entry)
DBListener callback handler for the EvpnTable.
Definition: bgp_evpn.cc:1597
bool ProcessSegmentUpdateSet()
Process the set of EvpnSegments that need to be updated.
Definition: bgp_evpn.cc:1260
LifetimeActor * deleter()
Return the LifetimeActor for the EvpnManager.
Definition: bgp_evpn.cc:1719
ErmVpnTable * ermvpn_table_
Definition: bgp_evpn.h:742
void Shutdown()
Initiate shutdown for the EvpnManager.
Definition: bgp_evpn.cc:1695
SegmentMap segment_map_
Definition: bgp_evpn.h:748
void DisableMacUpdateProcessing()
Disable processing of the update lists in all partitions. For testing only.
Definition: bgp_evpn.cc:1107
SegmentSet segment_delete_set_
Definition: bgp_evpn.h:749
EvpnManager(EvpnTable *table)
Definition: bgp_evpn.cc:1032
void AllocPartitions()
Allocate the EvpnManagerPartitions.
Definition: bgp_evpn.cc:1090
virtual UpdateInfo * GetUpdateInfo(EvpnRoute *route)
Construct export state for the given EvpnRoute. Note that the route only needs to be exported to the ...
Definition: bgp_evpn.cc:1141
int ermvpn_listener_id() const
Definition: bgp_evpn.h:613
int listener_id_
Definition: bgp_evpn.h:743
void RetryDelete()
Attempt to enqueue a delete for the EvpnManager.
Definition: bgp_evpn.cc:1710
boost::scoped_ptr< TaskTrigger > segment_delete_trigger_
Definition: bgp_evpn.h:751
EvpnTable * table_
Definition: bgp_evpn.h:741
EvpnSegment * FindSegment(const EthernetSegmentId &esi)
Find the EvpnSegment for the given EthernetSegmentId.
Definition: bgp_evpn.cc:1176
void DisableSegmentUpdateProcessing()
Disable processing of the update list. For testing only.
Definition: bgp_evpn.cc:1283
virtual void Initialize()
Initialize the EvpnManager. We allocate the EvpnManagerPartitions and register a DBListener for the E...
Definition: bgp_evpn.cc:1059
bool MayDelete() const
Trigger deletion of the EvpnManager and propagate the delete to any dependents.
Definition: bgp_evpn.cc:1665
void TriggerSegmentDelete(EvpnSegment *segment)
Trigger deletion of the given EvpnSegment. The EvpnSegment is added to a set of EvpnSegments that can...
Definition: bgp_evpn.cc:1193
EvpnManagerPartition * GetPartition(size_t part_id)
Get the EvpnManagerPartition for the given partition id.
Definition: bgp_evpn.cc:1126
ErmVpnTable * ermvpn_table()
Definition: bgp_evpn.h:610
void MacAdvertisementRouteListener(EvpnManagerPartition *partition, EvpnRoute *route)
DBListener callback handler for MacAdvertisement routes in the EvpnTable.
Definition: bgp_evpn.cc:1327
boost::scoped_ptr< DeleteActor > deleter_
Definition: bgp_evpn.h:754
SegmentSet segment_update_set_
Definition: bgp_evpn.h:750
EvpnSegment * LocateSegment(const EthernetSegmentId &esi)
Find or create the EvpnSegment for the given EthernetSegmentId.
Definition: bgp_evpn.cc:1161
PartitionList partitions_
Definition: bgp_evpn.h:746
void FillShowInfo(ShowEvpnTable *sevt) const
Fill information for introspect command. Note that all IM routes are always in partition 0.
Definition: bgp_evpn.cc:1630
void FreePartitions()
Free the EvpnManagerPartitions.
Definition: bgp_evpn.cc:1099
void InclusiveMulticastRouteListener(EvpnManagerPartition *partition, EvpnRoute *route)
DBListener callback handler for InclusiveMulticast routes in the EvpnTable.
Definition: bgp_evpn.cc:1385
bool ProcessSegmentDeleteSet()
Process the set of EvpnSegments that can potentially be deleted. Remove the EvpnSegment from the map ...
Definition: bgp_evpn.cc:1206
void AutoDiscoveryRouteListener(EvpnRoute *route)
DBListener callback handler for AutoDisocvery routes in the EvpnTable.
Definition: bgp_evpn.cc:1298
void EnableMacUpdateProcessing()
Enable processing of the update lists in all partitions. For testing only.
Definition: bgp_evpn.cc:1117
virtual void Terminate()
Terminate the EvpnManager. We free the EvpnManagerPartitions and unregister from the EvpnTable.
Definition: bgp_evpn.cc:1076
boost::scoped_ptr< TaskTrigger > segment_update_trigger_
Definition: bgp_evpn.h:752
void SelectiveMulticastRouteListener(EvpnManagerPartition *partition, EvpnRoute *route)
DBListener callback handler for SelectiveMulticast routes in the EvpnTable.
Definition: bgp_evpn.cc:1424
void SetDBState(EvpnRoute *route, EvpnMcastNode *dbstate)
Set DB State and update count.
Definition: bgp_evpn.cc:1494
void ClearDBState(EvpnRoute *route)
Create DB State and update count. If there is no DB State associated in the table,...
Definition: bgp_evpn.cc:1501
void TriggerSegmentUpdate(EvpnSegment *segment)
Trigger update of the given EvpnSegment. The EvpnSegment is added to a set of EvpnSegments for which ...
Definition: bgp_evpn.cc:1247
BgpServer * server()
Definition: bgp_evpn.cc:1154
void EnableSegmentUpdateProcessing()
Enable processing of the update list. For testing only.
Definition: bgp_evpn.cc:1291
DBTablePartition * GetTablePartition(size_t part_id)
Get the DBTablePartition for the EvpnTable for given partition id.
Definition: bgp_evpn.cc:1133
int listener_id() const
Definition: bgp_evpn.h:612
int ermvpn_listener_id_
Definition: bgp_evpn.h:744
void DisableSegmentDeleteProcessing()
Disable processing of the delete list. For testing only.
Definition: bgp_evpn.cc:1225
std::atomic< int > db_states_count_
Definition: bgp_evpn.h:745
bool IsUsableGlobalTreeRootRoute(ErmVpnRoute *ermvpn_route) const
Check whether an ErmVpnRoute is locally originated GlobalTreeRoute.
Definition: bgp_evpn.cc:1512
void ManagedDelete()
Trigger deletion of the EvpnManager and propagate the delete to any dependents.
Definition: bgp_evpn.cc:1703
tbb::spin_rw_mutex segment_rw_mutex_
Definition: bgp_evpn.h:747
virtual ~EvpnManager()
Definition: bgp_evpn.cc:1049
EvpnTable * table()
Definition: bgp_evpn.h:608
void EnableSegmentDeleteProcessing()
Enable processing of the delete list. For testing only.
Definition: bgp_evpn.cc:1233
This is the base class for a multicast node in an EVPN instance. The node could either represent a lo...
Definition: bgp_evpn.h:48
uint32_t label() const
Definition: bgp_evpn.h:78
bool edge_replication_not_supported_
Definition: bgp_evpn.h:100
EvpnStatePtr state()
Definition: bgp_evpn.h:73
uint8_t type() const
Definition: bgp_evpn.h:76
bool assisted_replication_leaf() const
Definition: bgp_evpn.h:87
bool assisted_replication_supported() const
Definition: bgp_evpn.h:84
Ip4Address replicator_address_
Definition: bgp_evpn.h:99
EvpnMcastNode(EvpnManagerPartition *partition, EvpnRoute *route, uint8_t type)
Constructor for EvpnMcastNode. The type indicates whether this is a local or remote EvpnMcastNode.
Definition: bgp_evpn.cc:80
bool assisted_replication_supported_
Definition: bgp_evpn.h:101
BgpAttrPtr attr_
Definition: bgp_evpn.h:96
uint32_t label_
Definition: bgp_evpn.h:97
EvpnManagerPartition * partition_
Definition: bgp_evpn.h:92
Ip4Address address_
Definition: bgp_evpn.h:98
void set_state(EvpnStatePtr state)
Definition: bgp_evpn.h:74
Ip4Address address() const
Definition: bgp_evpn.h:79
bool edge_replication_not_supported() const
Definition: bgp_evpn.h:81
bool assisted_replication_leaf_
Definition: bgp_evpn.h:102
virtual void TriggerUpdate()=0
Handle update of EvpnLocalMcastNode.
EvpnRoute * route_
Definition: bgp_evpn.h:94
EvpnRoute * route()
Definition: bgp_evpn.h:75
bool UpdateAttributes(EvpnRoute *route)
Update the label and attributes for a EvpnMcastNode. Return true if either of them changed.
Definition: bgp_evpn.cc:118
const BgpAttr * attr() const
Definition: bgp_evpn.h:77
Ip4Address replicator_address() const
Definition: bgp_evpn.h:80
uint32_t tag() const
uint8_t type() const
IpAddress ip_address() const
const EthernetSegmentId & esi() const
const RouteDistinguisher & route_distinguisher() const
const MacAddress & mac_addr() const
IpAddress source() const
IpAddress group() const
This class represents (in the context of an EVPN instance) a remote vRouter or PE discovered via BGP....
Definition: bgp_evpn.h:172
EvpnRemoteMcastNode(EvpnManagerPartition *partition, EvpnRoute *route)
Definition: bgp_evpn.cc:376
virtual ~EvpnRemoteMcastNode()
Definition: bgp_evpn.cc:389
virtual void TriggerUpdate()
Handle update of EvpnRemoteMcastNode.
Definition: bgp_evpn.cc:395
const EvpnPrefix & GetPrefix() const
virtual bool IsValid() const
virtual std::string ToString() const
bool operator==(const RemotePe &rhs) const
Equality operator for EvpnSegment::RemotePe. Do not compare esi_valid and single_active fields since ...
Definition: bgp_evpn.cc:574
const IPeer * peer
Definition: bgp_evpn.h:220
BgpPath::PathSource src
Definition: bgp_evpn.h:223
RemotePe(const BgpPath *path)
Definition: bgp_evpn.cc:560
This class represents a remote EVPN segment that has 2 or more PEs that are multi-homed to it....
Definition: bgp_evpn.h:204
EvpnRoute * esi_ad_route()
Definition: bgp_evpn.h:255
EvpnRoute * esi_ad_route_
Definition: bgp_evpn.h:268
void DeleteMacRoute(size_t part_id, EvpnRoute *route)
Delete the given MAC route as a dependent of this EvpnSegment. Trigger deletion of the EvpnSegment if...
Definition: bgp_evpn.cc:430
const_iterator begin() const
Definition: bgp_evpn.h:229
void AddMacRoute(size_t part_id, EvpnRoute *route)
Add the given MAC route as a dependent of this EvpnSegment.
Definition: bgp_evpn.cc:420
void set_esi_ad_route(EvpnRoute *esi_ad_route)
Definition: bgp_evpn.h:256
RouteListVector route_lists_
Definition: bgp_evpn.h:270
EvpnManager * evpn_manager_
Definition: bgp_evpn.h:266
EvpnSegment(EvpnManager *evpn_manager, const EthernetSegmentId &esi)
Definition: bgp_evpn.cc:401
const EthernetSegmentId & esi() const
Definition: bgp_evpn.h:254
bool MayDelete() const
Return true if it's safe to delete this EvpnSegment.
Definition: bgp_evpn.cc:541
bool single_active() const
Definition: bgp_evpn.h:260
bool single_active_
Definition: bgp_evpn.h:269
bool UpdatePeList()
Update the PE list for this EvpnSegment. This should be called when the AutoDisocvery route is update...
Definition: bgp_evpn.cc:459
void TriggerMacRouteUpdate()
Trigger an update of all dependent MAC routes for this EvpnSegment. Note that the bgp::EvpnSegment ta...
Definition: bgp_evpn.cc:442
const_iterator end() const
Definition: bgp_evpn.h:230
RemotePeList::const_iterator const_iterator
Definition: bgp_evpn.h:227
void clear_esi_ad_route()
Definition: bgp_evpn.h:259
RemotePeList pe_list_
Definition: bgp_evpn.h:271
This class holds Evpn state for a particular <S,G> at any given time.
Definition: bgp_evpn.h:349
const SG & sg() const
Definition: bgp_evpn.cc:1752
const ErmVpnTable * table() const
Definition: bgp_evpn.cc:46
void set_global_ermvpn_tree_rt(ErmVpnRoute *global_ermvpn_tree_rt)
Definition: bgp_evpn.cc:1756
EvpnState(const SG &sg, StatesMap *states, EvpnManager *manager)
A global MVPN state for a given <S.G> within a EvpnProjectManager.
Definition: bgp_evpn.cc:35
ErmVpnRoute * global_ermvpn_tree_rt_
Definition: bgp_evpn.h:401
EvpnManager * manager_
Definition: bgp_evpn.h:404
ErmVpnRoute * global_ermvpn_tree_rt()
Definition: bgp_evpn.cc:1760
virtual ~EvpnState()
Definition: bgp_evpn.cc:41
std::atomic< int > refcount_
Definition: bgp_evpn.h:405
std::map< SG, EvpnState * > StatesMap
Definition: bgp_evpn.h:367
void DestroyEvpnManager()
Definition: evpn_table.cc:367
std::vector< ExtCommunityValue > ExtCommunityList
Definition: community.h:156
std::vector< std::string > GetTunnelEncap() const
Definition: community.cc:665
bool ContainsTunnelEncapVxlan() const
Definition: community.cc:725
Definition: ipeer.h:187
virtual const std::string & ToString() const =0
void RetryDelete()
Definition: lifetime.cc:74
bool IsBroadcast() const
Definition: mac_address.cc:34
virtual bool GetForestNodePMSI(ErmVpnRoute *rt, uint32_t *label, Ip4Address *address, std::vector< std::string > *encap) const
const uint8_t tunnel_flags() const
Definition: bgp_attr.h:383
const Ip4Address identifier() const
Definition: bgp_attr.h:385
uint16_t GetVrfId() const
Definition: rd.cc:53
uint32_t GetAddress() const
Definition: rd.cc:49
const PathList & GetPathList() const
Definition: route.h:47
bool virtual_network_pbb_evpn_enable() const
BgpTable * GetTable(Address::Family fmly)
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:307
boost::intrusive_ptr< const ExtCommunity > ExtCommunityPtr
Definition: community.h:451
uint8_t type
Definition: load_balance.h:2
bool set_synchronize(const SetType *set1, const SetType *set2, AddFunctor add_fn, DelFunctor del_fn)
Definition: set_util.h:22
Elements elements
Definition: bgp_attr.h:695
Simple structure to hold <S,G>. Source as "0.0.0.0" can be used to encode <*,G> as well.
Definition: bgp_evpn.h:356
IpAddress group
Definition: bgp_evpn.h:364
bool operator<(const SG &other) const
Definition: bgp_evpn.cc:1740
IpAddress source
Definition: bgp_evpn.h:363
SG(const Ip4Address &source, const Ip4Address &group)
Definition: bgp_evpn.cc:1723
@ AssistedReplicationType
Definition: bgp_attr.h:318
@ EdgeReplicationSupported
Definition: bgp_attr.h:319
RibOutAttr roattr
Definition: bgp_update.h:101
#define CHECK_CONCURRENCY(...)
void STLDeleteValues(Container *container)
Definition: util.h:102