OpenSDN source code
routepath_replicator.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
7 
8 #include <boost/foreach.hpp>
9 
10 #include <utility>
11 
12 #include "base/set_util.h"
13 #include "base/task_annotations.h"
14 #include "base/task_trigger.h"
15 #include "bgp/bgp_config.h"
16 #include "bgp/bgp_log.h"
17 #include "bgp/bgp_route.h"
18 #include "bgp/bgp_server.h"
23 #include "bgp/routing-instance/routing_instance_analytics_types.h"
24 
25 using std::ostringstream;
26 using std::make_pair;
27 using std::pair;
28 using std::string;
29 using std::vector;
30 
31 //
32 // RoutePathReplication trace macro. Optionally logs the server name as well for
33 // easier debugging in multi server unit tests
34 //
35 #define RPR_TRACE(obj, ...) \
36 do { \
37  if (LoggingDisabled()) break; \
38  bgp_log_test::LogServerName(server()); \
39  Rpr##obj##Log::Send("RoutingInstance", \
40  SandeshLevel::SYS_DEBUG, __FILE__, __LINE__, __VA_ARGS__); \
41  Rpr##obj::TraceMsg(trace_buf_, __FILE__, __LINE__, __VA_ARGS__); \
42 } while (false)
43 
44 #define RPR_TRACE_ONLY(obj, ...) \
45 do { \
46  if (LoggingDisabled()) break; \
47  bgp_log_test::LogServerName(server()); \
48  Rpr##obj::TraceMsg(trace_buf_, __FILE__, __LINE__, __VA_ARGS__); \
49 } while (false)
50 
52 public:
53  explicit DeleteActor(TableState *ts)
54  : LifetimeActor(ts->replicator()->server()->lifetime_manager()),
55  ts_(ts) {
56  }
57 
58  virtual bool MayDelete() const {
59  return ts_->MayDelete();
60  }
61 
62  virtual void Shutdown() {
63  }
64 
65  virtual void Destroy() {
67  }
68 
69 private:
71 };
72 
74  : replicator_(replicator),
75  table_(table),
76  listener_id_(DBTableBase::kInvalidId),
77  deleter_(new DeleteActor(this)),
78  table_delete_ref_(this, table->deleter()),
79  export_target_gen_(0) {
80  assert(table->deleter() != NULL);
81 }
82 
84  if (walk_ref() != NULL) {
86  }
87 }
88 
90  deleter()->Delete();
91 }
92 
93 bool TableState::deleted() const {
94  return deleter()->IsDeleted();
95 }
96 
98  return deleter_.get();
99 }
100 
102  return deleter_.get();
103 }
104 
105 bool TableState::MayDelete() const {
106  if (list_.empty() && !route_count() &&
107  ((walk_ref() == NULL) || !walk_ref()->walk_is_active()))
108  return true;
109  return false;
110 }
111 
113  if (!deleter()->IsDeleted())
114  return;
115  deleter()->RetryDelete();
116 }
117 
119  list_.insert(group);
120 }
121 
123  list_.erase(group);
124 }
125 
126 const RtGroup *TableState::FindGroup(RtGroup *group) const {
127  GroupList::const_iterator it = list_.find(group);
128  return (it != list_.end() ? *it : NULL);
129 }
130 
131 uint32_t TableState::route_count() const {
133 }
134 
136  : replicator_(replicator),
137  export_target_gen_(0) {
138 }
139 
141  ReplicatedRtPathList::const_iterator it) {
142  pair<ReplicatedRtPathList::iterator, bool> result;
143  result = replicate_list_.insert(*it);
144  assert(result.second);
145 }
146 
148  ReplicatedRtPathList::const_iterator it) {
149  replicator_->DeleteSecondaryPath(table, rt, *it);
150  replicate_list_.erase(it);
151 }
152 
153 //
154 // Return the list of secondary table names for the given primary path.
155 // We go through all SecondaryRouteInfos and skip the ones that don't
156 // match the primary path.
157 //
158 vector<string> RtReplicated::GetTableNameList(const BgpPath *path) const {
159  vector<string> table_list;
160  BOOST_FOREACH(const SecondaryRouteInfo &rinfo, replicate_list_) {
161  if (rinfo.peer_ != path->GetPeer())
162  continue;
163  if (rinfo.path_id_ != path->GetPathId())
164  continue;
165  if (rinfo.src_ != path->GetSource())
166  continue;
167  table_list.push_back(rinfo.table_->name());
168  }
169  return table_list;
170 }
171 
173  Address::Family family)
174  : server_(server),
175  family_(family),
176  vpn_table_(NULL),
177  trace_buf_(SandeshTraceBufferCreate("RoutePathReplicator", 500)) {
178 }
179 
181  assert(table_state_list_.empty());
182 }
183 
185  assert(!vpn_table_);
187  assert(mgr);
189  assert(master);
190  vpn_table_ = master->GetTable(family_);
191  assert(vpn_table_);
192  assert(AddTableState(vpn_table_));
193 }
194 
196  RtGroup *group) {
197  assert(table->IsVpnTable() || group);
198 
199  TableStateList::iterator loc = table_state_list_.find(table);
200  if (loc == table_state_list_.end()) {
201  TableState *ts = new TableState(this, table);
202  DBTableBase::ListenerId id = table->Register(
203  boost::bind(&RoutePathReplicator::RouteListener, this, ts, _1, _2),
204  "RoutePathReplicator");
205  ts->set_listener_id(id);
206  if (group)
207  ts->AddGroup(group);
208  table_state_list_.insert(make_pair(table, ts));
209  RPR_TRACE(RegTable, table->name());
210  return ts;
211  } else {
212  assert(group);
213  TableState *ts = loc->second;
214  ts->AddGroup(group);
215  return ts;
216  }
217 }
218 
220  TableState *ts = FindTableState(table);
221  assert(ts);
222  ts->RemoveGroup(group);
223 }
224 
226  TableState *ts = FindTableState(table);
227  assert(ts);
228  RPR_TRACE(UnregTable, table->name());
229  table->Unregister(ts->listener_id());
230  table_state_list_.erase(table);
231  delete ts;
232 }
233 
235  TableStateList::iterator loc = table_state_list_.find(table);
236  return (loc != table_state_list_.end() ? loc->second : NULL);
237 }
238 
240  const BgpTable *table) const {
241  TableStateList::const_iterator loc =
242  table_state_list_.find(const_cast<BgpTable *>(table));
243  return (loc != table_state_list_.end() ? loc->second : NULL);
244 }
245 
246 void
248  CHECK_CONCURRENCY("bgp::Config", "bgp::ConfigHelper");
249  TableState *ts = FindTableState(table);
250  assert(ts);
251  if (!ts->walk_ref()) {
252  DBTable::DBTableWalkRef walk_ref = table->AllocWalker(
253  boost::bind(&RoutePathReplicator::RouteListener, this, ts, _1, _2),
254  boost::bind(&RoutePathReplicator::BulkReplicationDone, this, _2));
255  table->WalkTable(walk_ref);
256  ts->set_walk_ref(walk_ref);
257  } else {
258  table->WalkAgain(ts->walk_ref());
259  }
260 }
261 
262 void
264  CHECK_CONCURRENCY("db::Walker");
265  BgpTable *table = static_cast<BgpTable *>(dbtable);
266  RPR_TRACE(WalkDone, table->name());
267  TableState *ts = FindTableState(table);
268  ts->RetryDelete();
269 }
270 
272  CHECK_CONCURRENCY("bgp::Config", "bgp::ConfigHelper");
274  if (!vpn_ts || vpn_ts->FindGroup(group))
275  return;
276  RPR_TRACE(TableJoin, vpn_table_->name(), group->rt().ToString(), true);
277  group->AddImportTable(family(), vpn_table_);
278  RPR_TRACE(TableJoin, vpn_table_->name(), group->rt().ToString(), false);
279  group->AddExportTable(family(), vpn_table_);
280  AddTableState(vpn_table_, group);
281 }
282 
284  CHECK_CONCURRENCY("bgp::Config", "bgp::ConfigHelper");
286  if (!vpn_ts)
287  return;
288  RPR_TRACE(TableLeave, vpn_table_->name(), group->rt().ToString(), true);
290  RPR_TRACE(TableLeave, vpn_table_->name(), group->rt().ToString(), false);
293 }
294 
295 //
296 // Add a given BgpTable to RtGroup of given RouteTarget.
297 // It will create a new RtGroup if none exists.
298 // In case of export RouteTarget, create TableState if it doesn't exist.
299 //
301  bool import) {
302  CHECK_CONCURRENCY("bgp::Config", "bgp::ConfigHelper");
303 
304  std::scoped_lock lock(mutex_);
305  RPR_TRACE(TableJoin, table->name(), rt.ToString(), import);
306 
307  bool first = false;
308  RtGroup *group = server()->rtarget_group_mgr()->LocateRtGroup(rt);
309  if (import) {
310  first = group->AddImportTable(family(), table);
311  if (group->HasDepRoutes())
313  if (family_ == Address::INETVPN)
315  BOOST_FOREACH(BgpTable *sec_table, group->GetExportTables(family())) {
316  if (sec_table->IsVpnTable() || sec_table->empty())
317  continue;
318  RequestWalk(sec_table);
319  }
320  } else {
321  first = group->AddExportTable(family(), table);
322  TableState *ts = AddTableState(table, group);
323  // Export targets changed, so the attributes of the paths replicated
324  // earlier are stale. Bump before the walk, so that RouteListener does
325  // not take the optimized path for them.
327  if (!table->empty()) {
328  RequestWalk(table);
329  }
330  }
331 
332  // Join the vpn table when group is created.
333  if (first)
334  JoinVpnTable(group);
335 }
336 
337 //
338 // Remove a BgpTable from RtGroup of given RouteTarget.
339 // If the last group is going away, the RtGroup will be removed
340 // In case of export RouteTarget, trigger remove of TableState appropriate.
341 //
343  bool import) {
344  CHECK_CONCURRENCY("bgp::Config", "bgp::ConfigHelper");
345 
346  std::scoped_lock lock(mutex_);
347  RtGroup *group = server()->rtarget_group_mgr()->GetRtGroup(rt);
348  assert(group);
349  RPR_TRACE(TableLeave, table->name(), rt.ToString(), import);
350 
351  if (import) {
352  group->RemoveImportTable(family(), table);
353  if (group->HasDepRoutes())
355  if (family_ == Address::INETVPN)
357  BOOST_FOREACH(BgpTable *sec_table, group->GetExportTables(family())) {
358  if (sec_table->IsVpnTable() || sec_table->empty())
359  continue;
360  RequestWalk(sec_table);
361  }
362  } else {
363  group->RemoveExportTable(family(), table);
364  RemoveTableState(table, group);
365  // The paths replicated earlier still carry the target being removed.
367  if (!table->empty()) {
368  RequestWalk(table);
369  }
370  }
371 
372  // Leave the vpn table when the last VRF has left the group.
373  if (!group->HasVrfTables(family())) {
374  LeaveVpnTable(group);
376  }
377 }
378 
380  BgpRoute *rt, RtReplicated *dbstate,
381  const RtReplicated::ReplicatedRtPathList *future) {
382  set_synchronize(dbstate->GetMutableList(), future,
383  boost::bind(&RtReplicated::AddRouteInfo, dbstate, table, rt, _1),
384  boost::bind(&RtReplicated::DeleteRouteInfo, dbstate, table, rt, _1));
385 
386  if (dbstate->GetList().empty()) {
387  rt->ClearState(table, ts->listener_id());
388  delete dbstate;
389  if (table->GetDBStateCount(ts->listener_id()) == 0)
390  ts->RetryDelete();
391  }
392 }
393 
395  const ExtCommunity *ext_community,
396  int vn_index) {
397  as_t asn = server->autonomous_system();
398  ExtCommunityPtr extcomm_ptr;
399  if (vn_index) {
400  if (asn > AS2_MAX && vn_index > 0xffff) {
401  OriginVn origin_vn(asn, AS_TRANS);
402  extcomm_ptr = server->extcomm_db()->ReplaceOriginVnAndLocate(
403  ext_community, origin_vn.GetExtCommunity());
404  OriginVn origin_vn2(AS_TRANS, vn_index);
405  extcomm_ptr = server->extcomm_db()->AppendAndLocate(
406  extcomm_ptr.get(), origin_vn2.GetExtCommunity());
407  } else {
408  OriginVn origin_vn(asn, vn_index);
409  extcomm_ptr = server->extcomm_db()->ReplaceOriginVnAndLocate(
410  ext_community, origin_vn.GetExtCommunity());
411  return extcomm_ptr;
412  }
413  }
414  extcomm_ptr = server->extcomm_db()->RemoveOriginVnAndLocate(ext_community);
415  return extcomm_ptr;
416 }
417 
418 //
419 // Update the ExtCommunity with the RouteTargets from the export list
420 // and the OriginVn. The OriginVn is derived from the RouteTargets in
421 // vpn routes.
422 //
424  const RoutingInstance *rtinstance, const ExtCommunity *ext_community,
425  const ExtCommunity::ExtCommunityList &export_list) {
426  // Add RouteTargets exported by the instance for a non-master instance.
427  ExtCommunityPtr extcomm_ptr;
428  if (!rtinstance->IsMasterRoutingInstance()) {
429  extcomm_ptr =
430  server->extcomm_db()->AppendAndLocate(ext_community, export_list);
431  return extcomm_ptr;
432  }
433 
434  // Bail if we have a vpn route without extended communities.
435  if (!ext_community)
436  return ExtCommunityPtr(NULL);
437 
438  // Nothing to do if we already have the OriginVn community with our AS
439  // or with a vn index from the global range.
440  BOOST_FOREACH(const ExtCommunity::ExtCommunityValue &comm,
441  ext_community->communities()) {
442  if (!ExtCommunity::is_origin_vn(comm))
443  continue;
444  OriginVn origin_vn(comm);
445  if (!origin_vn.IsGlobal() &&
446  origin_vn.as_number() != server->autonomous_system()) {
447  continue;
448  }
449  return ExtCommunityPtr(ext_community);
450  }
451 
452  // Add the OriginVn if we have a valid vn index.
453  int vn_index =
454  server->routing_instance_mgr()->GetVnIndexByExtCommunity(ext_community);
455  return UpdateOriginVn(server, ext_community, vn_index);
456 }
457 
458 //
459 // Concurrency: Called in the context of the DB partition task.
460 //
461 // This function handles
462 // 1. Table Notification for path replication
463 // 2. Table walk for import/export of new targets
464 //
465 // Replicate a path (clone the BgpPath) to secondary BgpTables based on the
466 // export targets of the primary BgpTable.
467 // If primary table is a VRF table attach it's export targets to replicated
468 // path in the VPN table.
469 //
471  DBTablePartBase *root, DBEntryBase *entry) {
472  CHECK_CONCURRENCY("db::DBTable");
473 
474  BgpTable *table = static_cast<BgpTable *>(root->parent());
475  BgpRoute *rt = static_cast<BgpRoute *>(entry);
476  const RoutingInstance *rtinstance = table->routing_instance();
477 
479  assert(id != DBTableBase::kInvalidId);
480 
481  // Get the DBState.
482  RtReplicated *dbstate =
483  static_cast<RtReplicated *>(rt->GetState(table, id));
484  RtReplicated::ReplicatedRtPathList replicated_path_list;
485 
486  //Flag to track if any change happenned to route in last 30 minutes
487  bool route_unchanged = false;
488  //List of tables that needs replication of route
489  RtGroup::RtGroupMemberList addedTables;
490  //List of tables that doesn't need replication of route
491  RtGroup::RtGroupMemberList deletedTables;
492  //List of tables having the latest changes in route
493  RtGroup::RtGroupMemberList previousTables;
494  //Threshold used for optimised replication
495  uint64_t optimizationThresholdTime = 30ULL * 60 * 1000000;
496  uint64_t start = UTCTimestampUsec();
497  //Read once: a change racing with this walk must not be recorded as
498  //applied. The walk it requests runs after this one and sees the mismatch.
499  uint64_t export_target_gen = ts->export_target_gen();
500 
501  //Optimize only if last route change occurred 30 mins before and the
502  //export targets of the primary table are unchanged since the route was
503  //last replicated - the optimized path skips every destination table that
504  //is in both the old and the new set, which for a route in a VRF always
505  //includes the VPN table, leaving it with the previous export targets.
506  //We update the route_unchanged flag to true
507  if ( (start - rt->last_update_at() > optimizationThresholdTime) &&
508  dbstate != NULL &&
509  dbstate->export_target_gen() == export_target_gen)
510  {
511  RPR_TRACE(RouteListener, "Route change occurred before threshold \
512  time, optimising replication");
513  route_unchanged = true;
514  }
515 
516  //
517  // Cleanup if the route is not usable.
518  // If route aggregation is enabled, contributing route/more specific route
519  // for a aggregate route will NOT be replicated to destination table
520  //
521  if (!rt->IsUsable() || (table->IsRouteAggregationSupported() &&
522  !rtinstance->deleted() &&
523  table->IsContributingRoute(rt))) {
524  if (!dbstate) {
525  return true;
526  }
527  DBStateSync(table, ts, rt, dbstate, &replicated_path_list);
528  return true;
529  }
530 
531  // Create and set new DBState on the route. This will get cleaned up via
532  // via the call to DBStateSync if we don't need to replicate the route to
533  // any tables.
534  if (dbstate == NULL) {
535  dbstate = new RtReplicated(this);
536  rt->SetState(table, id, dbstate);
537  }
538 
539  // Get the export route target list from the routing instance.
540  ExtCommunity::ExtCommunityList export_list;
541  if (!rtinstance->IsMasterRoutingInstance()) {
542  BOOST_FOREACH(RouteTarget rtarget, rtinstance->GetExportList()) {
543  export_list.push_back(rtarget.GetExtCommunity());
544  }
545  }
546 
547  // Updating previousTables with the list of tables having the information
548  // about the route.
549  if (route_unchanged){
550  replicated_path_list = dbstate->GetList();
551  BOOST_FOREACH (RtReplicated::SecondaryRouteInfo path,
552  replicated_path_list){
553  previousTables.insert(path.table_);
554  }
555  }
556 
557  // Replicate all feasible and non-replicated paths.
558  for (Route::PathList::iterator it = rt->GetPathList().begin();
559  it != rt->GetPathList().end(); ++it) {
560  BgpPath *path = static_cast<BgpPath *>(it.operator->());
561 
562  // Skip if the source peer is down.
563  if (!path->IsStale() && !path->IsLlgrStale() && path->GetPeer() &&
564  !path->GetPeer()->IsReady())
565  continue;
566 
567  // No need to replicate aliased or replicated paths.
568  if (path->IsReplicated() || path->IsAliased())
569  continue;
570 
571  // Do not replicate non-ecmp paths.
572  if (rt->BestPath()->PathCompare(*path, true))
573  break;
574 
575  // Do not replicate if nexthop is not hitched by ermvpn tree.
576  if (path->CheckErmVpn())
577  break;
578 
579  const BgpAttr *attr = path->GetAttr();
580  const ExtCommunity *ext_community = attr->ext_community();
581 
582  ExtCommunityPtr extcomm_ptr =
583  UpdateExtCommunity(server(), rtinstance, ext_community, export_list);
584  ext_community = extcomm_ptr.get();
585  if (!ext_community)
586  continue;
587 
588  // Go through all extended communities.
589  //
590  // Get the vn_index from the OriginVn extended community.
591  // For each RouteTarget extended community, get the list of tables
592  // to which we need to replicate the path.
593  int vn_index = 0;
594  RtGroup::RtGroupMemberList secondary_tables;
595  BOOST_FOREACH(const ExtCommunity::ExtCommunityValue &comm,
596  ext_community->communities()) {
597  if (ExtCommunity::is_origin_vn(comm)) {
598  OriginVn origin_vn(comm);
599  vn_index = origin_vn.vn_index();
600  } else if (ExtCommunity::is_route_target(comm)) {
601  RtGroup *group =
602  server()->rtarget_group_mgr()->GetRtGroup(comm);
603  if (!group)
604  continue;
605  RtGroup::RtGroupMemberList import_list =
606  group->GetImportTables(family());
607  if (import_list.empty())
608  continue;
609  secondary_tables.insert(import_list.begin(), import_list.end());
610  }
611  }
612 
613  // Update with family specific secondary tables.
614  table->UpdateSecondaryTablesForReplication(rt, &secondary_tables);
615 
616  // Skip if we don't need to replicate the path to any tables.
617  if (secondary_tables.empty())
618  continue;
619 
620  // Add OriginVn when replicating self-originated routes from a VRF.
621  if (!vn_index && !rtinstance->IsMasterRoutingInstance() &&
622  path->IsVrfOriginated() && rtinstance->virtual_network_index()) {
623  vn_index = rtinstance->virtual_network_index();
624  extcomm_ptr = UpdateOriginVn(server_, extcomm_ptr.get(), vn_index);
625  }
626 
627  if (route_unchanged){
628  addedTables = RtGroup::RtGroupMemberList();
629  // Finding the difference between sets, secondary_tables and
630  // previousTables
631  std::set_difference(secondary_tables.begin(), secondary_tables.end(),
632  previousTables.begin(), previousTables.end(),
633  std::inserter(addedTables, addedTables.end()));
634  std::set_difference(previousTables.begin(), previousTables.end(),
635  secondary_tables.begin(), secondary_tables.end(),
636  std::inserter(deletedTables, deletedTables.end()));
637  BOOST_FOREACH (RtReplicated::SecondaryRouteInfo path,
638  dbstate->GetList()){
639  if (deletedTables.find(path.table_)!=deletedTables.end()) {
640  replicated_path_list.erase(path);
641  }
642  }
643  //Updating the secondary tables with the difference.
644  secondary_tables = addedTables;
645 
646  }
647 
648 
649  // Replicate path to all destination tables.
650  BOOST_FOREACH(BgpTable *dest, secondary_tables) {
651  // Skip if destination is same as source table.
652  if (dest == table)
653  continue;
654 
655  const RoutingInstance *dest_rtinstance = dest->routing_instance();
656  ExtCommunityPtr new_extcomm_ptr = extcomm_ptr;
657 
658  // If the origin vn is unresolved, see if route has a RouteTarget
659  // that's in the set of export RouteTargets for the dest instance.
660  // If so, we set the origin vn for the replicated route to be the
661  // vn for the dest instance.
662  if (!vn_index && dest_rtinstance->virtual_network_index() &&
663  dest_rtinstance->HasExportTarget(ext_community)) {
664  int dest_vn_index = dest_rtinstance->virtual_network_index();
665  new_extcomm_ptr = UpdateOriginVn(server_, extcomm_ptr.get(),
666  dest_vn_index);
667  }
668 
669  // Replicate the route to the destination table. The destination
670  // table may decide to not replicate based on it's own policy e.g.
671  // multicast routes are never leaked across routing-instances.
672  BgpRoute *replicated_rt = dest->RouteReplicate(
673  server_, table, rt, path, new_extcomm_ptr);
674  if (!replicated_rt)
675  continue;
676 
677  // Add information about the secondary path to the replicated path
678  // list.
679  RtReplicated::SecondaryRouteInfo rtinfo(dest, path->GetPeer(),
680  path->GetPathId(), path->GetSource(), replicated_rt);
681  pair<RtReplicated::ReplicatedRtPathList::iterator, bool> result;
682  result = replicated_path_list.insert(rtinfo);
683  // Assert if the insertion to replication path list fails
684  if (!route_unchanged)
685  assert(result.second);
686  RPR_TRACE_ONLY(Replicate, table->name(), rt->ToString(),
687  path->ToString(),
689  dest->name(), replicated_rt->ToString());
690  }
691  }
692 
693  // Record what this replication was done with, for the next walk.
694  dbstate->set_export_target_gen(export_target_gen);
695 
696  // Update the DBState to reflect the new list of secondary paths. The
697  // DBState will get cleared if the list is empty.
698  DBStateSync(table, ts, rt, dbstate, &replicated_path_list);
699  return true;
700 }
702  BgpTable *table, BgpRoute *rt) const {
703  const TableState *ts = FindTableState(table);
704  if (!ts)
705  return NULL;
706  RtReplicated *dbstate =
707  static_cast<RtReplicated *>(rt->GetState(table, ts->listener_id()));
708  return dbstate;
709 }
710 
711 //
712 // Return the list of secondary table names for the given primary path.
713 //
715  const BgpTable *table, const BgpRoute *rt, const BgpPath *path) const {
716  const TableState *ts = FindTableState(table);
717  if (!ts)
718  return vector<string>();
719  const RtReplicated *dbstate = static_cast<const RtReplicated *>(
720  rt->GetState(table, ts->listener_id()));
721  if (!dbstate)
722  return vector<string>();
723  return dbstate->GetTableNameList(path);
724 }
725 
727  const RtReplicated::SecondaryRouteInfo &rtinfo) {
728  BgpRoute *rt_secondary = rtinfo.rt_;
729  BgpTable *secondary_table = rtinfo.table_;
730  const IPeer *peer = rtinfo.peer_;
731  uint32_t path_id = rtinfo.path_id_;
732  BgpPath::PathSource src = rtinfo.src_;
733 
734  DBTablePartBase *partition =
735  secondary_table->GetTablePartition(rt_secondary);
736  BgpPath *secondary_path = rt_secondary->FindSecondaryPath(rt, src,
737  peer, path_id);
738  if (secondary_path && secondary_path->NeedsResolution()) {
739  secondary_table->path_resolver()->StopPathResolution(partition->index(),
740  secondary_path);
741  }
742  assert(rt_secondary->RemoveSecondaryPath(rt, src, peer, path_id));
743  if (rt_secondary->count() == 0) {
744  RPR_TRACE_ONLY(Flush, secondary_table->name(), rt_secondary->ToString(),
745  peer ? peer->ToString() : "Nil",
746  BgpPath::PathIdString(path_id), table->name(),
747  rt->ToString(), "Delete");
748  partition->Delete(rt_secondary);
749  } else {
750  partition->Notify(rt_secondary);
751  RPR_TRACE_ONLY(Flush, secondary_table->name(), rt_secondary->ToString(),
752  peer ? peer->ToString() : "Nil",
753  BgpPath::PathIdString(path_id), table->name(),
754  rt->ToString(), "Path update");
755  }
756 }
757 
759  ostringstream out;
760  out << table_->name() << "(" << table_ << ")" << ":" <<
761  peer_->ToString() << "(" << peer_ << ")" << ":" <<
762  rt_->ToString() << "(" << rt_ << ")";
763  return out.str();
764 }
#define AS_TRANS
Definition: bgp_common.h:24
#define AS2_MAX
Definition: bgp_common.h:25
uint32_t as_t
Definition: bgp_common.h:22
Family
Definition: address.h:25
@ INETVPN
Definition: address.h:29
const ExtCommunity * ext_community() const
Definition: bgp_attr.h:918
bool IsVrfOriginated() const
Definition: bgp_path.h:69
virtual std::string ToString() const
Definition: bgp_path.cc:178
bool IsAliased() const
Definition: bgp_path.h:99
IPeer * GetPeer()
Definition: bgp_path.h:77
const uint32_t GetPathId() const
Definition: bgp_path.h:79
static std::string PathIdString(uint32_t path_id)
Definition: bgp_path.cc:19
bool NeedsResolution() const
Definition: bgp_path.h:136
bool IsStale() const
Definition: bgp_path.h:108
virtual bool IsReplicated() const
Definition: bgp_path.h:92
PathSource
Definition: bgp_path.h:38
const BgpAttr * GetAttr() const
Definition: bgp_path.h:88
PathSource GetSource() const
Definition: bgp_path.h:104
int PathCompare(const BgpPath &rhs, bool allow_ecmp) const
Definition: bgp_path.cc:59
bool IsLlgrStale() const
Definition: bgp_path.h:111
bool CheckErmVpn() const
Definition: bgp_path.h:137
const BgpPath * BestPath() const
Definition: bgp_route.cc:48
bool RemoveSecondaryPath(const BgpRoute *src_rt, BgpPath::PathSource src, const IPeer *peer, uint32_t path_id)
Definition: bgp_route.cc:399
bool IsUsable() const
Definition: bgp_route.cc:326
size_t count() const
Definition: bgp_route.cc:422
BgpPath * FindSecondaryPath(BgpRoute *src_rt, BgpPath::PathSource src, const IPeer *peer, uint32_t path_id)
Definition: bgp_route.cc:374
RTargetGroupMgr * rtarget_group_mgr()
Definition: bgp_server.h:115
ExtCommunityDB * extcomm_db()
Definition: bgp_server.h:194
RoutingInstanceMgr * routing_instance_mgr()
Definition: bgp_server.h:107
as_t autonomous_system() const
Definition: bgp_server.h:213
void NotifyAllStaticRoutes()
Definition: bgp_server.cc:1013
bool IsContributingRoute(const BgpRoute *route) const
Definition: bgp_table.cc:1152
virtual bool IsVpnTable() const
Definition: bgp_table.h:110
virtual BgpRoute * RouteReplicate(BgpServer *server, BgpTable *table, BgpRoute *src, const BgpPath *path, ExtCommunityPtr community)=0
RoutingInstance * routing_instance()
Definition: bgp_table.h:148
virtual bool IsRouteAggregationSupported() const
Definition: bgp_table.h:112
PathResolver * path_resolver()
Definition: bgp_table.h:153
virtual void UpdateSecondaryTablesForReplication(BgpRoute *rt, TableSet *secondary_tables)
Definition: bgp_table.h:135
LifetimeActor * deleter()
Definition: bgp_table.cc:1118
virtual std::string ToString() const =0
DBState * GetState(DBTableBase *tbl_base, ListenerId listener) const
Definition: db_entry.cc:38
const uint64_t last_update_at() const
Definition: db_entry.h:72
void ClearState(DBTableBase *tbl_base, ListenerId listener)
Definition: db_entry.cc:74
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
uint64_t GetDBStateCount(ListenerId listener)
Definition: db_table.cc:243
bool empty() const
Definition: db_table.h:102
static const int kInvalidId
Definition: db_table.h:65
void Unregister(ListenerId listener)
Definition: db_table.cc:213
int ListenerId
Definition: db_table.h:63
const std::string & name() const
Definition: db_table.h:111
DBTableBase * parent()
void Notify(DBEntryBase *entry)
void Delete(DBEntryBase *)
void WalkAgain(DBTableWalkRef walk)
Definition: db_table.cc:658
DBTableWalkRef AllocWalker(WalkFn walk_fn, WalkCompleteFn walk_complete)
Definition: db_table.cc:640
void WalkTable(DBTableWalkRef walk)
Definition: db_table.cc:652
void ReleaseWalker(DBTableWalkRef &walk)
Definition: db_table.cc:646
virtual DBTablePartBase * GetTablePartition(const DBRequestKey *key)
Definition: db_table.cc:463
boost::intrusive_ptr< DBTableWalk > DBTableWalkRef
Definition: db_table.h:170
ExtCommunityPtr AppendAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityList &list)
Definition: community.cc:766
ExtCommunityPtr ReplaceOriginVnAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityValue &origin_vn)
Definition: community.cc:954
ExtCommunityPtr RemoveOriginVnAndLocate(const ExtCommunity *src)
Definition: community.cc:941
static bool is_route_target(const ExtCommunityValue &val)
Definition: community.h:268
std::vector< ExtCommunityValue > ExtCommunityList
Definition: community.h:156
boost::array< uint8_t, 8 > ExtCommunityValue
Definition: community.h:155
const ExtCommunityList & communities() const
Definition: community.h:183
static bool is_origin_vn(const ExtCommunityValue &val)
Definition: community.h:196
Definition: ipeer.h:187
virtual const std::string & ToString() const =0
virtual bool IsReady() const =0
virtual void Delete()
Definition: lifetime.cc:41
bool IsDeleted() const
Definition: lifetime.h:132
void RetryDelete()
Definition: lifetime.cc:74
bool IsGlobal() const
Definition: origin_vn.cc:135
as_t as_number() const
Definition: origin_vn.cc:111
int vn_index() const
Definition: origin_vn.cc:123
const bytes_type & GetExtCommunity() const
Definition: origin_vn.h:34
void StopPathResolution(int part_id, const BgpPath *path)
void RemoveRtGroup(const RouteTarget &rt)
RtGroup * LocateRtGroup(const RouteTarget &rt)
void NotifyRtGroup(const RouteTarget &rt)
RtGroup * GetRtGroup(const RouteTarget &rt)
void DeleteSecondaryPath(BgpTable *table, BgpRoute *rt, const RtReplicated::SecondaryRouteInfo &rtinfo)
void DeleteTableState(BgpTable *table)
void LeaveVpnTable(RtGroup *group)
RoutePathReplicator(BgpServer *server, Address::Family family)
void RemoveTableState(BgpTable *table, RtGroup *group)
void DBStateSync(BgpTable *table, TableState *ts, BgpRoute *rt, RtReplicated *dbstate, const RtReplicated::ReplicatedRtPathList *future)
TableStateList table_state_list_
TableState * AddTableState(BgpTable *table, RtGroup *group=NULL)
Address::Family family() const
const RtReplicated * GetReplicationState(BgpTable *table, BgpRoute *rt) const
void BulkReplicationDone(DBTableBase *dbtable)
TableState * FindTableState(BgpTable *table)
void JoinVpnTable(RtGroup *group)
void Join(BgpTable *table, const RouteTarget &rt, bool import)
std::vector< std::string > GetReplicatedTableNameList(const BgpTable *table, const BgpRoute *route, const BgpPath *path) const
void RequestWalk(BgpTable *table)
bool RouteListener(TableState *ts, DBTablePartBase *root, DBEntryBase *entry)
void Leave(BgpTable *table, const RouteTarget &rt, bool import)
std::string ToString() const
const bytes_type & GetExtCommunity() const
const PathList & GetPathList() const
Definition: route.h:47
int GetVnIndexByExtCommunity(const ExtCommunity *community) const
RoutingInstance * GetDefaultRoutingInstance()
bool deleted() const
bool HasExportTarget(const ExtCommunity *extcomm) const
int virtual_network_index() const
const RouteTargetList & GetExportList() const
BgpTable * GetTable(Address::Family fmly)
bool IsMasterRoutingInstance() const
const RtGroupMemberList & GetImportTables(Address::Family family) const
bool AddExportTable(Address::Family family, BgpTable *tbl)
bool AddImportTable(Address::Family family, BgpTable *tbl)
const RouteTarget & rt()
bool RemoveExportTable(Address::Family family, BgpTable *tbl)
bool HasDepRoutes() const
bool RemoveImportTable(Address::Family family, BgpTable *tbl)
bool HasVrfTables(Address::Family family) const
std::set< BgpTable * > RtGroupMemberList
Definition: rtarget_group.h:64
const RtGroupMemberList & GetExportTables(Address::Family family) const
void DeleteRouteInfo(BgpTable *table, BgpRoute *rt, ReplicatedRtPathList::const_iterator it)
void AddRouteInfo(BgpTable *table, BgpRoute *rt, ReplicatedRtPathList::const_iterator it)
ReplicatedRtPathList replicate_list_
RtReplicated(RoutePathReplicator *replicator)
RoutePathReplicator * replicator_
ReplicatedRtPathList * GetMutableList()
void set_export_target_gen(uint64_t gen)
const ReplicatedRtPathList & GetList() const
std::set< SecondaryRouteInfo > ReplicatedRtPathList
uint64_t export_target_gen() const
std::vector< std::string > GetTableNameList(const BgpPath *path) const
virtual bool MayDelete() const
void RemoveGroup(RtGroup *group)
const DBTable::DBTableWalkRef & walk_ref() const
boost::scoped_ptr< DeleteActor > deleter_
void AddGroup(RtGroup *group)
bool MayDelete() const
TableState(RoutePathReplicator *replicator, BgpTable *table)
bool deleted() const
BgpTable * table() const
void bump_export_target_gen()
void set_listener_id(DBTableBase::ListenerId listener_id)
const RtGroup * FindGroup(RtGroup *group) const
LifetimeActor * deleter()
uint64_t export_target_gen() const
DBTableBase::ListenerId listener_id() const
uint32_t route_count() const
RoutePathReplicator * replicator()
void set_walk_ref(DBTable::DBTableWalkRef walk_ref)
boost::intrusive_ptr< const ExtCommunity > ExtCommunityPtr
Definition: community.h:451
#define RPR_TRACE(obj,...)
#define RPR_TRACE_ONLY(obj,...)
static ExtCommunityPtr UpdateOriginVn(BgpServer *server, const ExtCommunity *ext_community, int vn_index)
static ExtCommunityPtr UpdateExtCommunity(BgpServer *server, const RoutingInstance *rtinstance, const ExtCommunity *ext_community, const ExtCommunity::ExtCommunityList &export_list)
SandeshTraceBufferPtr SandeshTraceBufferCreate(const std::string &buf_name, size_t buf_size, bool trace_enable=true)
Definition: sandesh_trace.h:47
bool set_synchronize(const SetType *set1, const SetType *set2, AddFunctor add_fn, DelFunctor del_fn)
Definition: set_util.h:22
#define CHECK_CONCURRENCY(...)
static uint64_t UTCTimestampUsec()
Definition: time_util.h:14