OpenSDN source code
bgp_mvpn.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include "bgp/bgp_mvpn.h"
7 
8 #include <utility>
9 
10 #include <boost/foreach.hpp>
11 
12 #include "base/task_annotations.h"
16 #include "bgp/bgp_log.h"
17 #include "bgp/bgp_multicast.h"
18 #include "bgp/bgp_server.h"
19 #include "bgp/bgp_update.h"
20 #include "bgp/mvpn/mvpn_table.h"
23 #include "bgp/routing-instance/routing_instance_analytics_types.h"
27 
28 using std::make_pair;
29 using std::ostringstream;
30 using std::pair;
31 using std::string;
32 using std::vector;
33 
34 // A global MVPN state for a given <S.G> within a MvpnProjectManager.
36  sg_(sg), global_ermvpn_tree_rt_(NULL), spmsi_rt_(NULL),
37  source_active_rt_(NULL), states_(states), project_manager_(pm) {
38  refcount_ = 0;
39 }
40 
42  assert(!global_ermvpn_tree_rt_);
43  assert(!spmsi_rt_);
44  assert(!source_active_rt_);
45  assert(spmsi_routes_received_.empty());
46  assert(leafad_routes_attr_received_.empty());
47  MVPN_TRACE(MvpnStateCreate, sg_.source.to_string(), sg_.group.to_string());
48 }
49 
50 const ErmVpnTable *MvpnState::table() const {
51  return project_manager_ ? project_manager_->table() : NULL;
52 }
53 
54 // MvpnProjectManager is deleted when parent ErmVpnTable is deleted.
56 public:
57  explicit DeleteActor(MvpnProjectManager *manager)
58  : LifetimeActor(manager->table_->routing_instance()->server()->
59  lifetime_manager()), manager_(manager) {
60  }
61 
62  virtual ~DeleteActor() {
63  }
64 
65  virtual bool MayDelete() const {
66  CHECK_CONCURRENCY("bgp::Config");
67  return manager_->MayDelete();
68  }
69 
70  virtual void Shutdown() {
71  }
72 
73  virtual void Destroy() {
75  }
76 
77 private:
79 };
80 
81 // Create MvpnProjectManager object and take a lifetime reference to the
82 // parent ErmVpnTable object.
84  : table_(table),
85  listener_id_(DBTable::kInvalidId),
86  table_delete_ref_(this, table->deleter()) {
87  deleter_.reset(new DeleteActor(this));
88 }
89 
91 }
92 
93 // MvpnProjectManager can be deleted only after all <S,G> MvpnState objects
94 // are deleted from the map.
96  BOOST_FOREACH(const MvpnProjectManagerPartition *partition, partitions_) {
97  if (!partition->states().empty()) {
98  MVPN_LOG(MvpnProjectManagerDelete,
99  "MvpnProjectManager::MayDelete() paused due to pending " +
100  integerToString(partition->states().size()) + " MvpnStates");
101  return false;
102  }
103  }
104  return true;
105 }
106 
108  return deleter_.get();
109 }
110 
112  return deleter_.get();
113 }
114 
115 // Create MvpnProjectManagerPartitions and register with the ErmVpnTable to
116 // get route change notifications.
118  if (!table_->server()->mvpn_ipv4_enable())
119  return;
120 
121  AllocPartitions();
122 
124  boost::bind(&MvpnProjectManager::RouteListener, this, _1, _2),
125  "MvpnProjectManager");
126  MVPN_LOG(MvpnProjectManagerCreate, "Initialized MvpnProjectManager");
127 }
128 
130  CHECK_CONCURRENCY("bgp::Config");
133  FreePartitions();
134  MVPN_LOG(MvpnProjectManagerDelete, "Terminated MvpnProjectManager");
135 }
136 
138  for (int part_id = 0; part_id < table_->PartitionCount(); part_id++)
139  partitions_.push_back(new MvpnProjectManagerPartition(this, part_id));
140 }
141 
143  for (size_t part_id = 0; part_id < partitions_.size(); part_id++) {
144  delete partitions_[part_id];
145  }
146  partitions_.clear();
147 }
148 
150  return partitions_[part_id];
151 }
152 
154  int part_id) const {
155  return partitions_[part_id];
156 }
157 
159  deleter_->Delete();
160 }
161 
163  return deleter_->IsDeleted();
164 }
165 
167  MvpnState::SG sg(route->GetPrefix().source(), route->GetPrefix().group());
168  return GetPartition(route->get_table_partition()->index())->GetState(sg);
169 }
170 
172  return static_cast<const MvpnProjectManager *>(this)->GetState(route);
173 }
174 
176  MvpnState::SG sg(route->GetPrefix().source(), route->GetPrefix().group());
177  return GetPartition(route->get_table_partition()->index())->GetState(sg);
178 }
179 
181  MvpnProjectManager *manager, int part_id)
182  : manager_(manager), part_id_(part_id) {
183 }
184 
186  assert(states_.empty());
187 }
188 
190  MvpnStatePtr state(new MvpnState(sg, &states_, manager_));
191  assert(states_.insert(make_pair(sg, state.get())).second);
192  MVPN_TRACE(MvpnStateCreate, sg.source.to_string(), sg.group.to_string());
193  return state;
194 }
195 
197  MvpnStatePtr mvpn_state = GetState(sg);
198  if (mvpn_state)
199  return mvpn_state;
200  mvpn_state = CreateState(sg);
201  assert(mvpn_state);
202  return mvpn_state;
203 }
204 
206  MvpnState::StatesMap::const_iterator iter = states_.find(sg);
207  return iter != states_.end() ? iter->second : NULL;
208 }
209 
211  MvpnState::StatesMap::iterator iter = states_.find(sg);
212  return iter != states_.end() ? iter->second : NULL;
213 }
214 
215 MvpnNeighbor::MvpnNeighbor() : source_as_(0) {
216 }
217 
219  const IpAddress &originator) :
220  rd_(rd), originator_(originator), source_as_(0) {
221 }
222 
224  return rd_;
225 }
226 
227 uint32_t MvpnNeighbor::source_as() const {
228  return source_as_;
229 }
230 
232  return originator_;
233 }
234 
235 bool MvpnNeighbor::operator==(const MvpnNeighbor &rhs) const {
236  return rd_ == rhs.rd_ && originator_ == rhs.originator_ &&
237  source_as_ == rhs.source_as_;
238 }
239 
241  MvpnNeighbor *nbr) const {
242  std::shared_lock<std::shared_mutex> lock(neighbors_mutex_);
243  NeighborMap::const_iterator iter = neighbors_.find(rd);
244  if (iter != neighbors_.end()) {
245  *nbr = iter->second;
246  return true;
247  }
248  return false;
249 }
250 
252  // Assert that lock cannot be taken now as it must have been taken already.
253  // assert(!neighbors_mutex_.try_lock_read());
254  return neighbors_;
255 }
256 
258  std::shared_lock<std::shared_mutex> lock(neighbors_mutex_);
259  return neighbors_.size();
260 }
261 
262 MvpnState::SG::SG(const Ip4Address &source, const Ip4Address &group) :
263  source(IpAddress(source)), group(IpAddress(group)) {
264 }
265 
267  source(route->GetPrefix().source()),
268  group(route->GetPrefix().group()) {
269 }
270 
272  source(route->GetPrefix().source()), group(route->GetPrefix().group()) {
273 }
274 
275 MvpnState::SG::SG(const IpAddress &source, const IpAddress &group) :
276  source(source), group(group) {
277 }
278 
279 bool MvpnState::SG::operator<(const SG &other) const {
280  if (source < other.source)
281  return true;
282  if (source > other.source)
283  return false;
284  if (group < other.group)
285  return true;
286  if (group > other.group)
287  return false;
288  return false;
289 }
290 
291 const MvpnState::SG &MvpnState::sg() const {
292  return sg_;
293 }
294 
296  return global_ermvpn_tree_rt_;
297 }
298 
300  return global_ermvpn_tree_rt_;
301 }
302 
304  return spmsi_rt_;
305 }
306 
308  return spmsi_rt_;
309 }
310 
312  return spmsi_routes_received_;
313 }
314 
316  return spmsi_routes_received_;
317 }
318 
321 }
322 
325 }
326 
329 }
330 
333 }
334 
336  return source_active_rt_;
337 }
338 
340  return source_active_rt_;
341 }
342 
345 }
346 
347 MvpnDBState::MvpnDBState(MvpnStatePtr state) : state_(state) , route_(NULL) {
348 }
349 
351  set_state(NULL);
352 }
353 
355  return state_;
356 }
357 
359  return route_;
360 }
361 
363  route_ = route;
364 }
365 
367  state_ = state;
368 }
369 
371 public:
372  explicit DeleteActor(MvpnManager *manager)
373  : LifetimeActor(manager->table_->routing_instance()->server()->
374  lifetime_manager()), manager_(manager) {
375  }
376  virtual ~DeleteActor() {
377  }
378 
379  virtual bool MayDelete() const {
380  CHECK_CONCURRENCY("bgp::Config");
381  return manager_->MayDelete();
382  }
383 
384  virtual void Shutdown() {
385  if (manager_->table()->IsDeleted())
386  return;
388  }
389 
390  virtual void Destroy() {
392  }
393 
394 private:
396 };
397 
399  : table_(table),
400  ermvpn_table_(ermvpn_table),
401  listener_id_(DBTable::kInvalidId),
402  identifier_listener_id_(-1),
403  table_delete_ref_(this, table->deleter()),
404  ermvpn_table_delete_ref_(this, ermvpn_table->deleter()) {
405  deleter_.reset(new DeleteActor(this));
406  db_states_count_ = 0;
407 }
408 
410 }
411 
413  return table_;
414 }
415 
417  return table_;
418 }
419 
421  return listener_id_;
422 }
423 
424 bool MvpnManager::deleted() const {
425  return deleter_->IsDeleted();
426 }
427 
429  return deleter_.get();
430 }
431 
433  CHECK_CONCURRENCY("bgp::Config");
434 
435  // Delete locally originated type-1 route.
436  MvpnRoute *type1_route = table_->FindType1ADRoute();
437  if (type1_route) {
438  BgpPath *path = type1_route->FindPath(BgpPath::Local, 0);
439  if (path)
440  type1_route->DeletePath(path);
441  type1_route->NotifyOrDelete();
442  }
443 
444  if (identifier_listener_id_ != -1) {
448  }
451  FreePartitions();
452  MVPN_LOG(MvpnManagerDelete, "Terminated MvpnManager");
453 }
454 
456  deleter_->Delete();
457 }
458 
460  for (int part_id = 0; part_id < table_->PartitionCount(); part_id++)
461  partitions_.push_back(new MvpnManagerPartition(this, part_id));
462 }
463 
465  for (size_t part_id = 0; part_id < partitions_.size(); part_id++) {
466  delete partitions_[part_id];
467  }
468  partitions_.clear();
469 }
470 
471 // MvpnManager can be deleted only after all associated DB States are cleared.
473  if (!db_states_count_)
474  return true;
475  MVPN_LOG(MvpnManagerDelete,
476  "MvpnManager::MayDelete() paused due to pending " +
477  integerToString(db_states_count_) + " MvpnDBStates");
478  return false;
479 }
480 
481 // Set DB State and update count.
482 void MvpnManager::SetDBState(MvpnRoute *route, MvpnDBState *mvpn_dbstate) {
483  route->SetState(table_, listener_id_, mvpn_dbstate);
485 }
486 
487 // Create DB State and update count. If there is no DB State associated in the
488 // table, resume table deletion if the deletion was pending.
490  route->ClearState(table_, listener_id_);
491  assert(db_states_count_);
493 
494  // Retry deletion now as there is no more attached db state in the table.
495  if (!db_states_count_ && deleter_->IsDeleted())
496  deleter_->RetryDelete();
497 }
498 
500  return manager_->table();
501 }
502 
504  return manager_->listener_id();
505 }
506 
508  : manager_(manager), part_id_(part_id) {
509 }
510 
512 }
513 
516  MvpnProjectManager *project_manager = manager_->GetProjectManager();
517  return project_manager ? project_manager->GetPartition(part_id_) : NULL;
518 }
519 
522  MvpnProjectManager *project_manager = manager_->GetProjectManager();
523  return project_manager ? project_manager->GetPartition(part_id_) : NULL;
524 }
525 
527  return table_->GetProjectManager();
528 }
529 
531  return listener_id_;
532 }
533 
535  return manager_->listener_id();
536 }
537 
539  MvpnProjectManagerPartition *project_manager_partition =
541  assert(project_manager_partition);
543  rt->GetPrefix().groupIpAddress());
544  return project_manager_partition->LocateState(sg);
545 }
546 
548  const MvpnProjectManagerPartition *project_manager_partition =
550  if (!project_manager_partition)
551  return NULL;
553  rt->GetPrefix().groupIpAddress());
554  return project_manager_partition->GetState(sg);
555 }
556 
558  return static_cast<const MvpnManagerPartition *>(this)->GetState(rt);
559 }
560 
562  return table_;
563 }
564 
566  return table_;
567 }
568 
570  return manager_->table();
571 }
572 
574  return manager_->table();
575 }
576 
578  const Ip4Address &source, const Ip4Address &group) {
579  if (table()->tree_manager())
580  table()->tree_manager()->NotifyForestNode(part_id_, source, group);
581 }
582 
584  const Ip4Address &source, const Ip4Address &group) {
586  if (pm)
587  pm->NotifyForestNode(source, group);
588 }
589 
591  uint32_t *label, Ip4Address *address, vector<string> *enc) const {
592  if (!table()->tree_manager())
593  return false;
594  return table()->tree_manager()->GetForestNodePMSI(rt, label, address, enc);
595 }
596 
598  Ip4Address *address, vector<string> *encap) const {
600  return pm ? pm->GetForestNodePMSI(rt, label, address, encap) : false;
601 }
602 
604 
605 // Initialize MvpnManager by allcating one MvpnManagerPartition for each DB
606 // partition, and register a route listener for the MvpnTable.
608  if (!table_->server()->mvpn_ipv4_enable())
609  return;
610 
611  assert(!table_->IsMaster());
612  AllocPartitions();
613 
615  boost::bind(&MvpnManager::RouteListener, this, _1, _2),
616  "MvpnManager");
617 
622 
623  MVPN_LOG(MvpnManagerCreate, "Initialized MvpnManager");
624 }
625 
626 void MvpnManager::ReOriginateType1Route(const Ip4Address &old_identifier) {
627  // Check if a path is already origianted. If so, delete it.
628  MvpnRoute *route = table_->FindType1ADRoute(old_identifier);
629  if (route) {
630  BgpPath *path = route->FindPath(BgpPath::Local, 0);
631  if (path) {
632  route->DeletePath(path);
633  route->NotifyOrDelete();
634  }
635  }
637 }
638 
640  // Originate Type1 Intra AS Auto-Discovery path.
641  BgpServer *server = table_->server();
642 
643  // Check for the presence of valid identifier.
644  if (!table_->server()->bgp_identifier())
645  return;
646  MvpnRoute *route = table_->LocateType1ADRoute();
647  BgpAttrSpec attr_spec;
648  BgpAttrNextHop nexthop(server->bgp_identifier());
649  attr_spec.push_back(&nexthop);
650  BgpAttrPtr attr = server->attr_db()->Locate(attr_spec);
651  BgpPath *path = new BgpPath(NULL, 0, BgpPath::Local, attr, 0, 0, 0);
652  route->InsertPath(path);
653  route->Notify();
654 
655  // TODO(Ananth) Originate Type2 Inter AS Auto-Discovery Route.
656 }
657 
658 // MvpnTable route listener callback function.
659 //
660 // Process changes (create/update/delete) to all different types of MvpnRoute.
662  CHECK_CONCURRENCY("db::DBTable");
663 
664  MvpnRoute *route = dynamic_cast<MvpnRoute *>(db_entry);
665  assert(route);
666 
667  MvpnManagerPartition *partition = partitions_[tpart->index()];
668 
669  // Process Type1 Intra-AS AD route.
670  if (route->GetPrefix().type() == MvpnPrefix::IntraASPMSIADRoute) {
671  ProcessType1ADRoute(route);
672  return;
673  }
674 
675  // TODO(Ananth) Inter-AS Multiast Site AD.
676 
677  // Process Type3 S-PMSI route.
678  if (route->GetPrefix().type() == MvpnPrefix::SPMSIADRoute) {
679  partition->ProcessType3SPMSIRoute(route);
680  return;
681  }
682 
683  // Process Type7 C-Join route.
684  if (route->GetPrefix().type() == MvpnPrefix::SourceTreeJoinRoute) {
685  partition->ProcessType7SourceTreeJoinRoute(route);
686  return;
687  }
688 
689  // Process Type5 Source Active route.
690  if (route->GetPrefix().type() == MvpnPrefix::SourceActiveADRoute) {
691  partition->ProcessType5SourceActiveRoute(route);
692  return;
693  }
694 
695  // Process Type4 LeafAD route.
696  if (route->GetPrefix().type() == MvpnPrefix::LeafADRoute) {
697  partition->ProcessType4LeafADRoute(route);
698  return;
699  }
700 }
701 
702 // Update MVPN neighbor list with create/delete/update of auto-discovery routes.
703 //
704 // Protect access to neighbors_ map with a mutex as the same be 'read' off other
705 // DB tasks in parallel. (Type-1 and Type-2 do not carrry any <S,G> information)
708 
709  // Check if an entry is already present.
710  MvpnNeighbor old_neighbor;
711  bool found = FindNeighbor(rd, &old_neighbor);
712 
713  if (!route->IsUsable()) {
714  if (!found)
715  return;
716  std::unique_lock<std::shared_mutex> lock(neighbors_mutex_);
717  MVPN_LOG(MvpnNeighborDelete, old_neighbor.rd().ToString(),
718  old_neighbor.originator().to_string(),
719  old_neighbor.source_as());
720  neighbors_.erase(rd);
721  return;
722  }
723 
724  // Ignore primary paths.
725  if (!route->BestPath()->IsReplicated())
726  return;
727 
728  MvpnNeighbor neighbor(route->GetPrefix().route_distinguisher(),
729  route->GetPrefix().originator());
730 
731  // Ignore if there is no change.
732  if (found && old_neighbor == neighbor)
733  return;
734 
735  std::unique_lock<std::shared_mutex> lock(neighbors_mutex_);
736  if (found)
737  neighbors_.erase(rd);
738  neighbors_.insert(make_pair(rd, neighbor));
739  MVPN_LOG(MvpnNeighborCreate, neighbor.rd().ToString(),
740  neighbor.originator().to_string(), neighbor.source_as());
741 }
742 
743 // Check whether an ErmVpnRoute is locally originated GlobalTreeRoute.
745  ErmVpnRoute *ermvpn_route) const {
746  if (!ermvpn_route || !ermvpn_route->IsUsable())
747  return NULL;
748  if (!table()->tree_manager())
749  return false;
751  ermvpn_route->GetPrefix().source(), ermvpn_route->GetPrefix().group());
752  return (global_rt && global_rt == ermvpn_route);
753 }
754 
755 // ErmVpnTable route listener callback function.
756 //
757 // Process changes (create/update/delete) to GlobalErmVpnRoute in vrf.ermvpn.0
759  DBEntryBase *db_entry) {
760  CHECK_CONCURRENCY("db::DBTable");
761  MvpnProjectManagerPartition *partition = GetPartition(tpart->index());
762  partition->RouteListener(db_entry);
763 }
764 
765 // Process changes to ErmVpnRoutes. We only care about changes to routes of
766 // type GlobalTreeRoute.
768  ErmVpnRoute *ermvpn_route = dynamic_cast<ErmVpnRoute *>(db_entry);
769  assert(ermvpn_route);
770 
771  // We only care about global tree routes for mvpn stitching.
772  if (ermvpn_route->GetPrefix().type() != ErmVpnPrefix::GlobalTreeRoute)
773  return;
774 
775  MvpnDBState *mvpn_dbstate = dynamic_cast<MvpnDBState *>(
776  ermvpn_route->GetState(table(), listener_id()));
777 
778  // Handle GlobalTreeRoute route deletion.
779  if (!IsUsableGlobalTreeRootRoute(ermvpn_route)) {
780  // Ignore if there is no DB State associated with route.
781  if (!mvpn_dbstate)
782  return;
783  MvpnStatePtr mvpn_state = mvpn_dbstate->state();
784  mvpn_state->set_global_ermvpn_tree_rt(NULL);
785 
786  // Notify all received Type3 spmsi routes for PMSI re-computation.
787  // Since usable global ermvpn is no longer available, any advertised
788  // type-4 lead-ad routes must now be withdrawn.
789  BOOST_FOREACH(MvpnRoute *route, mvpn_state->spmsi_routes_received()) {
790  route->Notify();
791  }
792  ermvpn_route->ClearState(table(), listener_id());
793  MVPN_ERMVPN_RT_LOG(ermvpn_route,
794  "Processed MVPN GlobalErmVpnRoute deletion");
795  delete mvpn_dbstate;
796  return;
797  }
798 
799  // Set DB State in the route if not already done so before.
800  MvpnStatePtr mvpn_state;
801  if (!mvpn_dbstate) {
802  MvpnState::SG sg(ermvpn_route);
803  mvpn_state = LocateState(sg);
804  mvpn_dbstate = new MvpnDBState(mvpn_state);
805  ermvpn_route->SetState(table(), listener_id(), mvpn_dbstate);
806  } else {
807  mvpn_state = mvpn_dbstate->state();
808  }
809 
810  // Note down current usable ermvpn route for stitching to mvpn.
811  mvpn_dbstate->state()->set_global_ermvpn_tree_rt(ermvpn_route);
812 
813  // Notify all originated Type3 spmsi routes for PMSI re-computation.
814  BOOST_FOREACH(MvpnRoute *route, mvpn_state->spmsi_routes_received()) {
815  route->Notify();
816  }
817 
818  MVPN_ERMVPN_RT_LOG(ermvpn_route,
819  "Processed MVPN GlobalErmVpnRoute creation");
820 }
821 
822 // Process change to MVPN Type-5 SourceActive route.
824  MvpnDBState *mvpn_dbstate = dynamic_cast<MvpnDBState *>(rt->GetState(
825  table(), listener_id()));
826 
827  // Process route change as delete if ProjectManager is not set.
828  bool is_usable = rt->IsUsable() && table()->IsProjectManagerUsable();
829  if (!is_usable) {
830  if (!mvpn_dbstate)
831  return;
832 
833  // Delete any associated type-3 s-pmsi route.
834  MvpnRoute *spmsi_rt =
835  mvpn_dbstate->state() ? mvpn_dbstate->state()->spmsi_rt() : NULL;
836  if (spmsi_rt && spmsi_rt->IsUsable()) {
837  BgpPath *path = spmsi_rt->FindPath(BgpPath::Local, 0);
838  if (path)
839  spmsi_rt->DeletePath(path);
840  }
841 
842  mvpn_dbstate->set_route(NULL);
843  mvpn_dbstate->state()->set_source_active_rt(NULL);
844  mvpn_dbstate->state()->set_spmsi_rt(NULL);
845  if (spmsi_rt)
846  spmsi_rt->NotifyOrDelete();
847  manager_->ClearDBState(rt);
848  MVPN_RT_LOG(rt, "Processed MVPN Source Active route deletion");
849  delete mvpn_dbstate;
850  return;
851  }
852 
853  const BgpPath *path = rt->BestPath();
854  // Here in the sender side, we only care about changes to the primary path.
855  if (path->IsReplicated())
856  return;
857 
858  MvpnStatePtr state = LocateState(rt);
859  state->set_source_active_rt(rt);
860 
861  // Set DB State if not already done so.
862  if (!mvpn_dbstate) {
863  mvpn_dbstate = new MvpnDBState(state);
864  manager_->SetDBState(rt, mvpn_dbstate);
865  }
866 
867  // Check if there is any receiver interested. If not, do not originate
868  // type-3 spmsi route. Also, we originate Type3 S-PMSI route only if there
869  // is an imported secondary path for the join route (i.e when the join
870  // route reached the sender)
871  const MvpnRoute *join_rt = table()->FindType7SourceTreeJoinRoute(rt);
872  if (!join_rt || !join_rt->IsUsable() ||
873  !join_rt->BestPath()->IsReplicated()) {
874  // Remove any type-3 spmsi path originated before.
875  MvpnRoute *spmsi_rt = mvpn_dbstate->route();
876  if (spmsi_rt) {
877  assert(!state->spmsi_rt() || spmsi_rt == state->spmsi_rt());
878  state->set_spmsi_rt(NULL);
879  mvpn_dbstate->set_route(NULL);
880  BgpPath *path = spmsi_rt->FindPath(BgpPath::Local, 0);
881  if (path) {
882  MVPN_RT_LOG(spmsi_rt, "Deleted already originated SPMSI path");
883  spmsi_rt->DeletePath(path);
884  spmsi_rt->NotifyOrDelete();
885  }
886  }
887  return;
888  }
889 
890  // Originate Type-3 S-PMSI route to send towards the receivers.
891  MvpnRoute *spmsi_rt = table()->LocateType3SPMSIRoute(join_rt);
892  assert(spmsi_rt);
893  state->set_spmsi_rt(spmsi_rt);
894  if (!mvpn_dbstate->route()) {
895  mvpn_dbstate->set_route(spmsi_rt);
896  } else {
897  assert(spmsi_rt == mvpn_dbstate->route());
898  BgpPath *path = spmsi_rt->FindPath(BgpPath::Local, 0);
899  assert(path);
900 
901  // Ignore if there is no change in the attributes.
902  if (path->GetAttr() == rt->BestPath()->GetAttr())
903  return;
904  spmsi_rt->DeletePath(path);
905  }
906 
907  PmsiTunnelSpec pmsi_spec;
909  BgpAttrDB *attr_db = table()->server()->attr_db();
910  BgpAttrPtr new_attrp = attr_db->ReplacePmsiTunnelAndLocate(
911  rt->BestPath()->GetAttr(), &pmsi_spec);
912 
913  // Insert new path and notify.
914  BgpPath *new_path = new BgpPath(NULL, 0, BgpPath::Local,
915  new_attrp, 0, 0, 0);
916  spmsi_rt->InsertPath(new_path);
917  spmsi_rt->Notify();
918  MVPN_RT_LOG(rt, "Processed MVPN Source Active route creation");
919 }
920 
922  MvpnDBState *mvpn_dbstate = dynamic_cast<MvpnDBState *>(
923  join_rt->GetState(table(), listener_id()));
924 
925  // Process route change as delete if ProjectManager is not set.
926  bool is_usable = join_rt->IsUsable() && table()->IsProjectManagerUsable();
927  if (!is_usable) {
928  if (!mvpn_dbstate)
929  return;
930 
931  // Notify associatd source-active route so that any s-pmsi route if
932  // originated before can be withdrawn as there is no more active join
933  // route (receiver) for this <S,G>.
934  if (mvpn_dbstate->state()->source_active_rt())
935  mvpn_dbstate->state()->source_active_rt()->Notify();
936  manager_->ClearDBState(join_rt);
937  MVPN_RT_LOG(join_rt, "Processed Type 7 Join route deletion");
938  delete mvpn_dbstate;
939  return;
940  }
941 
942  // We care only for imported secondary type-7 joins (at the sender).
943  if (!join_rt->BestPath()->IsReplicated())
944  return;
945 
946  MvpnStatePtr state = LocateState(join_rt);
947  if (!mvpn_dbstate) {
948  mvpn_dbstate = new MvpnDBState(state);
949  manager_->SetDBState(join_rt, mvpn_dbstate);
950  }
951 
952  // A join has been received or updated at the sender. Re-evaluate the
953  // type5 source active, if one such route is present.
954  if (state->source_active_rt()) {
955  state->source_active_rt()->Notify();
956  MVPN_RT_LOG(join_rt, "Processed Type 7 Join route creation and "
957  "notified Source Active route");
958  } else {
959  MVPN_RT_LOG(join_rt, "Processed Type 7 Join route creation");
960  }
961 }
962 
964  MvpnDBState *mvpn_dbstate = dynamic_cast<MvpnDBState *>(
965  leaf_ad->GetState(table(), listener_id()));
966  // Process route change as delete if ProjectManager is not set.
967  bool is_usable = leaf_ad->IsUsable() && table()->IsProjectManagerUsable();
968  if (!is_usable) {
969  if (!mvpn_dbstate)
970  return;
971  assert(mvpn_dbstate->state()->leafad_routes_attr_received().
972  erase(leaf_ad));
973  MvpnRoute *sa_active_rt = mvpn_dbstate->state()->source_active_rt();
974 
975  // Re-evaluate type5 route as secondary type4 leafad route is deleted.
976  // olist needs to be updated and sent to the sender route agent.
977  if (sa_active_rt && sa_active_rt->IsUsable()) {
978  sa_active_rt->Notify();
979  MVPN_RT_LOG(leaf_ad, "Processed Type 4 LeafAD route deletion"
980  " and notified type5 source active route");
981  } else {
982  MVPN_RT_LOG(leaf_ad, "Processed Type 4 LeafAD route deletion");
983  }
984  manager_->ClearDBState(leaf_ad);
985  delete mvpn_dbstate;
986  return;
987  }
988 
989  const BgpPath *path = leaf_ad->BestPath();
990  if (!path->IsReplicated())
991  return;
992 
993  // Secondary leaft-ad path has been imported.
994  MvpnStatePtr state = LocateState(leaf_ad);
995  if (!mvpn_dbstate) {
996  mvpn_dbstate = new MvpnDBState(state);
997  manager_->SetDBState(leaf_ad, mvpn_dbstate);
998  }
999 
1000  pair<MvpnState::RoutesMap::iterator, bool> result =
1001  state->leafad_routes_attr_received().insert(make_pair(leaf_ad,
1002  leaf_ad->BestPath()->GetAttr()));
1003 
1004  // Overwrite the entry with new best path attributes if one already exists.
1005  if (!result.second) {
1006  // Ignore if there is no change in the best path's attributes.
1007  if (result.first->second.get() == leaf_ad->BestPath()->GetAttr())
1008  return;
1009  result.first->second = leaf_ad->BestPath()->GetAttr();
1010  }
1011 
1012  // Update the sender source-active route to update the olist.
1013  MvpnRoute *sa_active_rt = mvpn_dbstate->state()->source_active_rt();
1014  if (sa_active_rt && sa_active_rt->IsUsable()) {
1015  sa_active_rt->Notify();
1016  MVPN_RT_LOG(sa_active_rt, "Processed Type 4 Leaf AD route creation"
1017  " and Type-5 source active route was notified");
1018  } else {
1019  MVPN_RT_LOG(sa_active_rt, "Processed Type 4 Leaf AD route creation");
1020  }
1021 }
1022 
1023 // Process changes to Type3 S-PMSI routes by originating or deleting Type4 Leaf
1024 // AD paths as appropriate.
1026  // Retrieve any state associcated with this S-PMSI route.
1027  MvpnDBState *mvpn_dbstate = dynamic_cast<MvpnDBState *>(
1028  spmsi_rt->GetState(table(), listener_id()));
1029 
1030  MvpnRoute *leaf_ad_route = NULL;
1031  // Process route change as delete if ProjectManager is not set.
1032  bool is_usable = spmsi_rt->IsUsable() && table()->IsProjectManagerUsable();
1033  if (!is_usable) {
1034  if (!mvpn_dbstate)
1035  return;
1036  MvpnStatePtr mvpn_state = GetState(spmsi_rt);
1037  assert(mvpn_dbstate->state() == mvpn_state);
1038 
1039  // Check if a Type4 LeafAD path was already originated before for this
1040  // S-PMSI path. If so, delete it as the S-PMSI path is no nonger usable.
1041  leaf_ad_route = mvpn_dbstate->route();
1042  if (leaf_ad_route) {
1043  BgpPath *path = leaf_ad_route->FindPath(BgpPath::Local, 0);
1044  if (path)
1045  leaf_ad_route->DeletePath(path);
1046  mvpn_dbstate->set_route(NULL);
1047  }
1048 
1049  assert(mvpn_state->spmsi_routes_received().erase(spmsi_rt));
1050  manager_->ClearDBState(spmsi_rt);
1051  delete mvpn_dbstate;
1052  if (leaf_ad_route) {
1053  leaf_ad_route->NotifyOrDelete();
1054 
1055  // Forest node route needs to be updated to delete the source
1056  // address if advertised before.
1057  NotifyForestNode(spmsi_rt->GetPrefix().source(),
1058  spmsi_rt->GetPrefix().group());
1059  MVPN_RT_LOG(spmsi_rt, "Processed Type 3 S-PMSI route deletion"
1060  " and notified local ForestNode");
1061  } else {
1062  MVPN_RT_LOG(spmsi_rt, "Processed Type 3 S-PMSI route deletion");
1063  }
1064  return;
1065  }
1066 
1067  // Ignore notifications of primary S-PMSI paths.
1068  if (!spmsi_rt->BestPath()->IsReplicated())
1069  return;
1070 
1071  // Don't send Type 4 route if there is no receiver in this vrf
1072  const MvpnRoute *join_rt = table()->FindType7SourceTreeJoinRoute(spmsi_rt);
1073  if (!join_rt || !join_rt->IsUsable())
1074  return;
1075 
1076  // A valid S-PMSI path has been imported to a table. Originate a new
1077  // LeafAD path, if GlobalErmVpnTreeRoute is available to stitch.
1078  // TODO(Ananth) If LeafInfoRequired bit is not set in the S-PMSI route,
1079  // then we do not need to originate a leaf ad route for this s-pmsi rt.
1080  MvpnStatePtr mvpn_state = LocateState(spmsi_rt);
1081  assert(mvpn_state);
1082  if (!mvpn_dbstate) {
1083  mvpn_dbstate = new MvpnDBState(mvpn_state);
1084  manager_->SetDBState(spmsi_rt, mvpn_dbstate);
1085  assert(mvpn_state->spmsi_routes_received().insert(spmsi_rt).second);
1086  } else {
1087  leaf_ad_route = mvpn_dbstate->route();
1088  }
1089 
1090  // If LeafInfoRequired bit is not set, no need to process further
1091  if (!spmsi_rt->BestPath()->GetAttr()->pmsi_tunnel() ||
1092  (!(spmsi_rt->BestPath()->GetAttr()->pmsi_tunnel()->tunnel_flags() &
1094  MVPN_RT_LOG(spmsi_rt, "No need to process Type 3 S-PMSI route as"
1095  " LeafInfoRequired bit is not set");
1096  return;
1097  }
1098 
1099  ErmVpnRoute *global_rt = mvpn_state->global_ermvpn_tree_rt();
1100  uint32_t label;
1101  Ip4Address address;
1102  vector<string> tunnel_encaps;
1103  bool pmsi_found =
1104  GetForestNodePMSI(global_rt, &label, &address, &tunnel_encaps);
1105 
1106  if (!pmsi_found) {
1107  // There is no ermvpn route available to stitch at this time. Remove any
1108  // originated Type4 LeafAD route. DB State shall remain on the route as
1109  // SPMSI route itself is still a usable route.
1110  if (leaf_ad_route) {
1111  BgpPath *path = leaf_ad_route->FindPath(BgpPath::Local, 0);
1112  if (path)
1113  leaf_ad_route->DeletePath(path);
1114  mvpn_dbstate->set_route(NULL);
1115  leaf_ad_route->NotifyOrDelete();
1116  NotifyForestNode(spmsi_rt->GetPrefix().source(),
1117  spmsi_rt->GetPrefix().group());
1118  MVPN_RT_LOG(spmsi_rt, "Processed Type 3 S-PMSI route as deletion"
1119  " and notified local ForestNode due to missing PMSI");
1120  }
1121  return;
1122  }
1123 
1124  if (!leaf_ad_route) {
1125  leaf_ad_route = table()->LocateType4LeafADRoute(spmsi_rt);
1126  mvpn_dbstate->set_route(leaf_ad_route);
1127  }
1128  BgpPath *old_path = leaf_ad_route->FindPath(BgpPath::Local, 0);
1129 
1130  // For LeafAD routes, rtarget is always <sender-router-id>:0.
1131  BgpAttrPtr attrp = BgpAttrPtr(spmsi_rt->BestPath()->GetAttr());
1133  rtarget.push_back(RouteTarget(spmsi_rt->GetPrefix().originator(), 0).
1134  GetExtCommunity());
1135  ExtCommunityPtr ext_community = table()->server()->extcomm_db()->
1136  ReplaceRTargetAndLocate(attrp->ext_community(), rtarget);
1137 
1138  ExtCommunity::ExtCommunityList tunnel_encaps_list;
1139  BOOST_FOREACH(string encap, tunnel_encaps) {
1140  tunnel_encaps_list.push_back(TunnelEncap(encap).GetExtCommunity());
1141  }
1142 
1143  ext_community = table()->server()->extcomm_db()->
1144  ReplaceTunnelEncapsulationAndLocate(ext_community.get(),
1145  tunnel_encaps_list);
1146 
1148  attrp.get(), ext_community);
1149 
1150  // Retrieve PMSI tunnel attribute from the GlobalErmVpnTreeRoute.
1151  PmsiTunnelSpec pmsi_spec;
1152  pmsi_spec.tunnel_flags = 0;
1154  pmsi_spec.SetLabel(label, ext_community.get());
1155  pmsi_spec.SetIdentifier(address);
1156 
1157  // Replicate the LeafAD path with appropriate PMSI tunnel info as part of
1158  // the path attributes. Community should be route-target with root ingress
1159  // PE router-id + 0 (Page 254).
1160  BgpAttrPtr new_attrp =
1161  table()->server()->attr_db()->ReplacePmsiTunnelAndLocate(attrp.get(),
1162  &pmsi_spec);
1163 
1164  // Ignore if there is no change in the path attributes of already originated
1165  // leaf ad path.
1166  if (old_path && old_path->GetAttr() == new_attrp.get())
1167  return;
1168 
1169  BgpPath *path = new BgpPath(NULL, 0, BgpPath::Local, new_attrp, 0, 0, 0);
1170  if (old_path)
1171  leaf_ad_route->DeletePath(old_path);
1172  leaf_ad_route->InsertPath(path);
1173  leaf_ad_route->NotifyOrDelete();
1174  NotifyForestNode(spmsi_rt->GetPrefix().source(),
1175  spmsi_rt->GetPrefix().group());
1176  MVPN_RT_LOG(spmsi_rt, "Processed Type 3 S-PMSI route creation");
1177 }
1178 
1180  BgpTable::TableSet *secondary_tables) const {
1181  // Find the right MvpnProjectManagerPartition based on the rt's partition.
1182  const MvpnProjectManagerPartition *partition =
1183  table()->GetProjectManagerPartition(mvpn_rt);
1184  if (!partition)
1185  return;
1186 
1187  // Retrieve MVPN state. Ignore if there is no state or if there is no usable
1188  // Type3 SPMSI route 0associated with it (perhaps it was deleted already).
1189  MvpnState::SG sg(mvpn_rt);
1190  MvpnStatePtr state = partition->GetState(sg);
1191  if (!state || !state->spmsi_rt() || !state->spmsi_rt()->IsUsable())
1192  return;
1193 
1194  // Matching Type-3 S-PMSI route was found. Return its table.
1195  BgpTable *table = dynamic_cast<BgpTable *>(
1196  state->spmsi_rt()->get_table_partition()->parent());
1197  assert(table);
1198 
1199  // Update table list to let replicator invoke RouteReplicate() for this
1200  // LeafAD route for this table which has the corresponding Type3 SPMSI
1201  // route. This was originated as the 'Sender' since receiver joined to
1202  // the <C-S,G> group.
1203  secondary_tables->insert(table);
1204  MVPN_RT_LOG(mvpn_rt, "Updated tables for replication with table " +
1205  table->name());
1206 }
1207 
1208 // Return source_address of the type-3 s-pmsi route used for rpf check in the
1209 // forest node.
1211  Ip4Address *addrp) const {
1212  // Bail if project manager is deleted.
1213  if (deleter_->IsDeleted())
1214  return;
1215 
1216  // Bail if there is no state for this <S,G>.
1217  MvpnStatePtr state = GetState(ermvpn_route);
1218  if (!state)
1219  return;
1220 
1221  // Bail if there is no usable global_ermvpn_tree_rt.
1222  if (!state->global_ermvpn_tree_rt() ||
1223  !state->global_ermvpn_tree_rt()->IsUsable()) {
1224  return;
1225  }
1226 
1227  // Bail if there is no s-pmsi route received (no active sender)
1228  if (state->spmsi_routes_received().empty())
1229  return;
1230 
1231  // Use mvpn type3 spmsi route originator address as the source address.
1232  *addrp = (*(state->spmsi_routes_received().begin()))->
1233  GetPrefix().originator();
1234  MVPN_ERMVPN_RT_LOG(ermvpn_route, "Found Source Address for RPF Check " +
1235  addrp->to_string());
1236 }
1237 
1239  BgpAttrPtr attr = route->BestPath()->GetAttr();
1240  UpdateInfo *uinfo = new UpdateInfo;
1241  uinfo->roattr = RibOutAttr(table(), route, attr.get(), 0, false, true);
1242  return uinfo;
1243 }
1244 
1246  assert((route->GetPrefix().type() == MvpnPrefix::SourceActiveADRoute) ||
1248 
1250  return GetType7UpdateInfo(route);
1251  MvpnStatePtr state = GetState(route);
1252 
1253  // If there is no imported leaf-ad route, then essentially there is no
1254  // olist that can be formed. Route can be withdrawn if already advertised.
1255  if (!state || state->leafad_routes_attr_received().empty())
1256  return NULL;
1257 
1258  // Retrieve olist element from each of the imported type-4 leaf-ad route.
1259  BgpOListSpec olist_spec(BgpAttribute::OList);
1260  BOOST_FOREACH(MvpnState::RoutesMap::value_type &iter,
1261  state->leafad_routes_attr_received()) {
1262  BgpAttrPtr attr = iter.second;
1263  const PmsiTunnel *pmsi = attr->pmsi_tunnel();
1264  if (!pmsi)
1265  continue;
1267  continue;
1268  const ExtCommunity *extcomm = attr->ext_community();
1269  uint32_t label = attr->pmsi_tunnel()->GetLabel(extcomm);
1270  if (!label)
1271  continue;
1272  BgpOListElem elem(pmsi->identifier(), label,
1273  extcomm ? extcomm->GetTunnelEncap() : vector<string>());
1274  olist_spec.elements.push_back(elem);
1275  MVPN_RT_LOG(route, "Encoded olist " + pmsi->pmsi_tunnel().ToString());
1276  }
1277 
1278  if (olist_spec.elements.empty())
1279  return NULL;
1280 
1281  BgpAttrDB *attr_db = table()->server()->attr_db();
1282  BgpAttrPtr attr = attr_db->ReplaceOListAndLocate(
1283  route->BestPath()->GetAttr(), &olist_spec);
1284  UpdateInfo *uinfo = new UpdateInfo;
1285  uinfo->roattr = RibOutAttr(table(), route, attr.get(), 0, false, true);
1286  return uinfo;
1287 }
boost::asio::ip::address IpAddress
Definition: address.h:14
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
std::vector< BgpAttribute * > BgpAttrSpec
Definition: bgp_attr.h:823
boost::intrusive_ptr< const BgpAttr > BgpAttrPtr
Definition: bgp_attr.h:999
#define MVPN_TRACE(type,...)
Definition: bgp_mvpn.h:512
#define MVPN_ERMVPN_RT_LOG(rt,...)
Definition: bgp_mvpn.h:500
#define MVPN_LOG(type,...)
Definition: bgp_mvpn.h:508
#define MVPN_RT_LOG(rt,...)
Definition: bgp_mvpn.h:492
boost::intrusive_ptr< MvpnState > MvpnStatePtr
Definition: bgp_mvpn.h:41
BgpAttrPtr ReplaceOListAndLocate(const BgpAttr *attr, const BgpOListSpec *olist_spec)
Definition: bgp_attr.cc:1423
BgpAttrPtr ReplacePmsiTunnelAndLocate(const BgpAttr *attr, const PmsiTunnelSpec *pmsi_spec)
Definition: bgp_attr.cc:1450
BgpAttrPtr ReplaceExtCommunityAndLocate(const BgpAttr *attr, ExtCommunityPtr extcomm)
Definition: bgp_attr.cc:1367
const PmsiTunnel * pmsi_tunnel() const
Definition: bgp_attr.h:923
TypePtr Locate(Type *attr)
virtual bool IsReplicated() const
Definition: bgp_path.h:92
@ Local
Definition: bgp_path.h:44
const BgpAttr * GetAttr() const
Definition: bgp_path.h:88
const BgpPath * FindPath(BgpPath::PathSource src) const
Definition: bgp_route.cc:147
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
void NotifyOrDelete()
Definition: bgp_route.cc:773
ExtCommunityDB * extcomm_db()
Definition: bgp_server.h:194
int RegisterIdentifierUpdateCallback(IdentifierUpdateCb callback)
Definition: bgp_server.cc:956
uint32_t bgp_identifier() const
Definition: bgp_server.h:216
bool mvpn_ipv4_enable() const
Definition: bgp_server.h:311
void UnregisterIdentifierUpdateCallback(int listener)
Definition: bgp_server.cc:972
BgpAttrDB * attr_db()
Definition: bgp_server.h:188
BgpServer * server()
Definition: bgp_table.cc:88
std::set< BgpTable * > TableSet
Definition: bgp_table.h:38
bool IsDeleted() const
Definition: bgp_table.h:143
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
DBTablePartBase * get_table_partition() const
Definition: db_entry.cc:116
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 NotifyAllEntries()
Definition: db_table.cc:623
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
void DestroyMvpnProjectManager()
virtual int PartitionCount() const
Definition: ermvpn_table.h:45
std::vector< ExtCommunityValue > ExtCommunityList
Definition: community.h:156
std::vector< std::string > GetTunnelEncap() const
Definition: community.cc:665
void NotifyForestNode(int part_id, const Ip4Address &source, const Ip4Address &group)
virtual bool GetForestNodePMSI(ErmVpnRoute *rt, uint32_t *label, Ip4Address *address, std::vector< std::string > *encap) const
virtual ErmVpnRoute * GetGlobalTreeRootRoute(const Ip4Address &source, const Ip4Address &group) const
bool GetForestNodePMSI(ErmVpnRoute *rt, uint32_t *label, Ip4Address *address, std::vector< std::string > *encap) const
Definition: bgp_mvpn.cc:597
int listener_id() const
Definition: bgp_mvpn.cc:503
void ProcessType7SourceTreeJoinRoute(MvpnRoute *join_rt)
Definition: bgp_mvpn.cc:921
void ProcessType4LeafADRoute(MvpnRoute *leaf_ad)
Definition: bgp_mvpn.cc:963
MvpnManagerPartition(MvpnManager *manager, int part_id)
Definition: bgp_mvpn.cc:507
MvpnStatePtr GetState(MvpnRoute *route)
Definition: bgp_mvpn.cc:557
void ProcessType3SPMSIRoute(MvpnRoute *spmsi_rt)
Definition: bgp_mvpn.cc:1025
MvpnStatePtr LocateState(MvpnRoute *route)
Definition: bgp_mvpn.cc:538
virtual ~MvpnManagerPartition()
Definition: bgp_mvpn.cc:511
void NotifyForestNode(const Ip4Address &source, const Ip4Address &group)
Definition: bgp_mvpn.cc:583
void ProcessType5SourceActiveRoute(MvpnRoute *join_rt)
Definition: bgp_mvpn.cc:823
MvpnManager * manager_
Definition: bgp_mvpn.h:132
MvpnProjectManagerPartition * GetProjectManagerPartition()
Definition: bgp_mvpn.cc:515
MvpnTable * table()
Definition: bgp_mvpn.cc:499
MvpnManager * manager_
Definition: bgp_mvpn.cc:395
virtual bool MayDelete() const
Definition: bgp_mvpn.cc:379
DeleteActor(MvpnManager *manager)
Definition: bgp_mvpn.cc:372
virtual void Destroy()
Definition: bgp_mvpn.cc:390
virtual void Shutdown()
Definition: bgp_mvpn.cc:384
bool deleted() const
Definition: bgp_mvpn.cc:424
boost::scoped_ptr< DeleteActor > deleter_
Definition: bgp_mvpn.h:213
virtual void Terminate()
Definition: bgp_mvpn.cc:432
int listener_id() const
Definition: bgp_mvpn.cc:420
void SetDBState(MvpnRoute *route, MvpnDBState *mvpn_dbstate)
Definition: bgp_mvpn.cc:482
virtual void Initialize()
Definition: bgp_mvpn.cc:607
MvpnTable * table()
Definition: bgp_mvpn.cc:412
NeighborMap neighbors_
Definition: bgp_mvpn.h:210
void RouteListener(DBTablePartBase *tpart, DBEntryBase *db_entry)
Definition: bgp_mvpn.cc:661
int listener_id_
Definition: bgp_mvpn.h:205
MvpnProjectManager * GetProjectManager()
Definition: bgp_mvpn.cc:526
void ReOriginateType1Route(const Ip4Address &old_identifier)
Definition: bgp_mvpn.cc:626
void ProcessType1ADRoute(MvpnRoute *route)
Definition: bgp_mvpn.cc:706
virtual ~MvpnManager()
Definition: bgp_mvpn.cc:409
MvpnManager(MvpnTable *table, ErmVpnTable *ermvpn_table)
Definition: bgp_mvpn.cc:398
void AllocPartitions()
Definition: bgp_mvpn.cc:459
PartitionList partitions_
Definition: bgp_mvpn.h:208
std::map< RouteDistinguisher, MvpnNeighbor > NeighborMap
Definition: bgp_mvpn.h:163
void ClearDBState(MvpnRoute *route)
Definition: bgp_mvpn.cc:489
std::atomic< int > db_states_count_
Definition: bgp_mvpn.h:207
std::shared_mutex neighbors_mutex_
Definition: bgp_mvpn.h:211
void FreePartitions()
Definition: bgp_mvpn.cc:464
const NeighborMap & neighbors() const
Definition: bgp_mvpn.cc:251
void OriginateType1Route()
Definition: bgp_mvpn.cc:639
bool FindNeighbor(const RouteDistinguisher &rd, MvpnNeighbor *nbr) const
Definition: bgp_mvpn.cc:240
const LifetimeActor * deleter() const
Definition: bgp_mvpn.cc:428
MvpnTable * table_
Definition: bgp_mvpn.h:203
void ManagedDelete()
Definition: bgp_mvpn.cc:455
bool MayDelete() const
Definition: bgp_mvpn.cc:472
int identifier_listener_id_
Definition: bgp_mvpn.h:206
size_t neighbors_count() const
Definition: bgp_mvpn.cc:257
virtual void UpdateSecondaryTablesForReplication(MvpnRoute *rt, BgpTable::TableSet *secondary_tables) const
Definition: bgp_mvpn.cc:1179
Ip4Address source() const
Definition: mvpn_route.h:76
uint8_t type() const
Definition: mvpn_route.h:73
IpAddress sourceIpAddress() const
Definition: mvpn_route.h:79
@ SourceTreeJoinRoute
Definition: mvpn_route.h:47
@ IntraASPMSIADRoute
Definition: mvpn_route.h:41
@ SPMSIADRoute
Definition: mvpn_route.h:43
@ SourceActiveADRoute
Definition: mvpn_route.h:45
Ip4Address originator() const
Definition: mvpn_route.h:77
const RouteDistinguisher & route_distinguisher() const
Definition: mvpn_route.h:74
IpAddress groupIpAddress() const
Definition: mvpn_route.h:78
Ip4Address group() const
Definition: mvpn_route.h:75
ErmVpnTable * table()
Definition: bgp_mvpn.cc:569
MvpnProjectManagerPartition(MvpnProjectManager *manager, int part_id)
Definition: bgp_mvpn.cc:180
void RouteListener(DBEntryBase *db_entry)
Definition: bgp_mvpn.cc:767
MvpnState::StatesMap states_
Definition: bgp_mvpn.h:401
MvpnStatePtr GetState(const SG &sg)
Definition: bgp_mvpn.cc:210
bool GetForestNodePMSI(ErmVpnRoute *rt, uint32_t *label, Ip4Address *address, std::vector< std::string > *encap) const
Definition: bgp_mvpn.cc:590
const MvpnState::StatesMap & states() const
Definition: bgp_mvpn.h:379
virtual ~MvpnProjectManagerPartition()
Definition: bgp_mvpn.cc:185
MvpnStatePtr CreateState(const SG &sg)
Definition: bgp_mvpn.cc:189
bool IsUsableGlobalTreeRootRoute(ErmVpnRoute *ermvpn_route) const
Definition: bgp_mvpn.cc:744
void NotifyForestNode(const Ip4Address &source, const Ip4Address &group)
Definition: bgp_mvpn.cc:577
MvpnStatePtr LocateState(const SG &sg)
Definition: bgp_mvpn.cc:196
MvpnProjectManager * manager_
Definition: bgp_mvpn.h:397
DeleteActor(MvpnProjectManager *manager)
Definition: bgp_mvpn.cc:57
virtual bool MayDelete() const
Definition: bgp_mvpn.cc:65
MvpnProjectManager * manager_
Definition: bgp_mvpn.cc:78
const LifetimeActor * deleter() const
Definition: bgp_mvpn.cc:111
MvpnProjectManagerPartition * GetPartition(int part_id)
Definition: bgp_mvpn.cc:149
boost::scoped_ptr< DeleteActor > deleter_
Definition: bgp_mvpn.h:457
UpdateInfo * GetUpdateInfo(MvpnRoute *route)
Definition: bgp_mvpn.cc:1245
MvpnStatePtr GetState(MvpnRoute *route) const
Definition: bgp_mvpn.cc:166
PartitionList partitions_
Definition: bgp_mvpn.h:455
void AllocPartitions()
Definition: bgp_mvpn.cc:137
bool MayDelete() const
Definition: bgp_mvpn.cc:95
ErmVpnTable * table()
Definition: bgp_mvpn.cc:561
void GetMvpnSourceAddress(ErmVpnRoute *ermvpn_route, Ip4Address *address) const
Definition: bgp_mvpn.cc:1210
virtual void Terminate()
Definition: bgp_mvpn.cc:129
MvpnProjectManager(ErmVpnTable *table)
Definition: bgp_mvpn.cc:83
UpdateInfo * GetType7UpdateInfo(MvpnRoute *route)
Definition: bgp_mvpn.cc:1238
void RouteListener(DBTablePartBase *tpart, DBEntryBase *db_entry)
Definition: bgp_mvpn.cc:758
void FreePartitions()
Definition: bgp_mvpn.cc:142
virtual void Initialize()
Definition: bgp_mvpn.cc:117
bool deleted() const
Definition: bgp_mvpn.cc:162
virtual ~MvpnProjectManager()
Definition: bgp_mvpn.cc:90
ErmVpnTable * table_
Definition: bgp_mvpn.h:453
void ManagedDelete()
Definition: bgp_mvpn.cc:158
int listener_id() const
Definition: bgp_mvpn.cc:530
const MvpnPrefix & GetPrefix() const
Definition: mvpn_route.h:140
RoutesSet spmsi_routes_received_
Definition: bgp_mvpn.h:320
RoutesMap & leafad_routes_attr_received()
Definition: bgp_mvpn.cc:319
std::set< MvpnRoute * > RoutesSet
Definition: bgp_mvpn.h:265
const ErmVpnTable * table() const
Definition: bgp_mvpn.cc:50
MvpnState(const SG &sg, StatesMap *states, MvpnProjectManager *pm)
Definition: bgp_mvpn.cc:35
ErmVpnRoute * global_ermvpn_tree_rt()
Definition: bgp_mvpn.cc:295
void set_source_active_rt(MvpnRoute *source_active_rt)
Definition: bgp_mvpn.cc:343
std::atomic< int > refcount_
Definition: bgp_mvpn.h:324
const SG & sg() const
Definition: bgp_mvpn.cc:291
std::map< MvpnRoute *, BgpAttrPtr > RoutesMap
Definition: bgp_mvpn.h:266
ErmVpnRoute * global_ermvpn_tree_rt_
Definition: bgp_mvpn.h:317
std::map< SG, MvpnState * > StatesMap
Definition: bgp_mvpn.h:281
MvpnRoute * spmsi_rt()
Definition: bgp_mvpn.cc:303
MvpnRoute * source_active_rt_
Definition: bgp_mvpn.h:319
RoutesSet & spmsi_routes_received()
Definition: bgp_mvpn.cc:311
RoutesMap leafad_routes_attr_received_
Definition: bgp_mvpn.h:321
MvpnRoute * spmsi_rt_
Definition: bgp_mvpn.h:318
MvpnRoute * source_active_rt()
Definition: bgp_mvpn.cc:335
void set_spmsi_rt(MvpnRoute *spmsi_rt)
Definition: bgp_mvpn.cc:331
MvpnProjectManager * project_manager_
Definition: bgp_mvpn.h:323
void set_global_ermvpn_tree_rt(ErmVpnRoute *global_ermvpn_tree_rt)
Definition: bgp_mvpn.cc:327
virtual ~MvpnState()
Definition: bgp_mvpn.cc:41
bool IsProjectManagerUsable() const
Definition: mvpn_table.cc:201
void DestroyManager()
Definition: mvpn_table.cc:114
const MvpnProjectManager * GetProjectManager() const
Definition: mvpn_table.cc:186
MvpnRoute * LocateType4LeafADRoute(const MvpnRoute *type3_spmsi_rt)
Definition: mvpn_table.cc:304
MvpnRoute * LocateType3SPMSIRoute(const MvpnRoute *type7_join_rt)
Definition: mvpn_table.cc:343
MvpnRoute * LocateType1ADRoute()
Definition: mvpn_table.cc:367
virtual int PartitionCount() const
Definition: mvpn_table.h:50
const MvpnRoute * FindType7SourceTreeJoinRoute(MvpnRoute *rt) const
Definition: mvpn_table.cc:382
bool IsMaster() const
Definition: mvpn_table.cc:665
const MvpnProjectManagerPartition * GetProjectManagerPartition(BgpRoute *route) const
Definition: mvpn_table.cc:223
MvpnRoute * FindType1ADRoute(const Ip4Address &originator_ip)
Definition: mvpn_table.cc:372
const uint8_t tunnel_flags() const
Definition: bgp_attr.h:383
const PmsiTunnelSpec & pmsi_tunnel() const
Definition: bgp_attr.h:374
const uint8_t tunnel_type() const
Definition: bgp_attr.h:384
const Ip4Address identifier() const
Definition: bgp_attr.h:385
std::string ToString() const
Definition: rd.cc:57
boost::intrusive_ptr< const ExtCommunity > ExtCommunityPtr
Definition: community.h:451
static const std::string integerToString(const NumberType &num)
Definition: string_util.h:20
Elements elements
Definition: bgp_attr.h:695
MvpnDBState(MvpnStatePtr state)
Definition: bgp_mvpn.cc:347
MvpnStatePtr state()
Definition: bgp_mvpn.cc:354
MvpnStatePtr state_
Definition: bgp_mvpn.h:345
MvpnRoute * route_
Definition: bgp_mvpn.h:346
void set_state(MvpnStatePtr state)
Definition: bgp_mvpn.cc:366
void set_route(MvpnRoute *route)
Definition: bgp_mvpn.cc:362
MvpnRoute * route()
Definition: bgp_mvpn.cc:358
const IpAddress & originator() const
Definition: bgp_mvpn.cc:231
uint32_t source_as_
Definition: bgp_mvpn.h:72
uint32_t source_as() const
Definition: bgp_mvpn.cc:227
IpAddress originator_
Definition: bgp_mvpn.h:71
bool operator==(const MvpnNeighbor &rhs) const
Definition: bgp_mvpn.cc:235
RouteDistinguisher rd_
Definition: bgp_mvpn.h:70
const RouteDistinguisher & rd() const
Definition: bgp_mvpn.cc:223
bool operator<(const SG &other) const
Definition: bgp_mvpn.cc:279
SG(const Ip4Address &source, const Ip4Address &group)
Definition: bgp_mvpn.cc:262
IpAddress source
Definition: bgp_mvpn.h:277
IpAddress group
Definition: bgp_mvpn.h:278
uint8_t tunnel_flags
Definition: bgp_attr.h:359
virtual std::string ToString() const
Definition: bgp_attr.cc:310
@ IngressReplication
Definition: bgp_attr.h:335
uint8_t tunnel_type
Definition: bgp_attr.h:360
void SetIdentifier(Ip4Address identifier)
Definition: bgp_attr.cc:341
void SetLabel(uint32_t label, const ExtCommunity *ext)
Definition: bgp_attr.cc:329
RibOutAttr roattr
Definition: bgp_update.h:101
#define CHECK_CONCURRENCY(...)