OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bgp_route.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "bgp/bgp_config_ifmap.h"
6 #include "bgp/bgp_route.h"
7 
8 #include "bgp/bgp_peer.h"
9 #include "bgp/bgp_server.h"
10 #include "bgp/bgp_table.h"
30 
31 using std::string;
32 using std::vector;
33 using std::ostringstream;
34 
36 }
37 
39  assert(GetPathList().empty());
40 }
41 
42 //
43 // Return the best path for this route.
44 // Skip aliased paths.
45 //
46 const BgpPath *BgpRoute::BestPath() const {
47  for (Route::PathList::const_iterator it = GetPathList().begin();
48  it != GetPathList().end(); ++it) {
49  const BgpPath *path = static_cast<const BgpPath *>(it.operator->());
50  if (path->GetFlags() & BgpPath::AliasedPath)
51  continue;
52  return path;
53  }
54  return NULL;
55 }
56 
57 //
58 // Insert given path and redo path selection.
59 //
61  assert(!IsDeleted());
62  const Path *prev_front = front();
63 
64  BgpTable *table = static_cast<BgpTable *>(get_table());
65  // 'table' is not expected to be null, suspect it is checked here because of
66  // unit tests.
67  if (table) {
68  // Default Tunnel Encapsulation processing is done if configured for
69  // the address family on the peer.
70  // If routing policy is supported on the table(family)it is handled in
71  // ProcessRoutingPolicy where other changes may be made to the
72  // attributes. Also, when there are routing policy configuration changes
73  // the attributes needs to be re-evaluated using the original attributes
74  // and Default Tunnel Encapsulation also needs to be re-applied, this
75  // will be handled seamlessly since ProcessRoutingPolicy will be called
76  // in that case.
77  // Note that currently routing policies are not supported on VPN address
78  // families, however this is ensuring that it will be handed correctly
79  // in future. Additionally, for labeled inet routes, routing policies
80  // are supported so the Default Tunnel Encapsulation needs to be handled
81  // in ProcessRoutingPolicy.
82  // If the table(family) does not support routing policies the Default
83  // Tunnel Encapsulation processing is handled here. The original and
84  // modified attributes are saved and are not expected to be modified
85  // further. Note that the configuration is not applied if the path
86  // already has tunnel encapsulation specified.
87 
88  if (table->IsRoutingPolicySupported()) {
89  if (!path->IsReplicated()) {
90  // Add sub-cluster extended community to all routes
91  // originated within a sub-cluster
92  uint32_t subcluster_id = SubClusterId();
93  if (subcluster_id) {
94  path->AddExtCommunitySubCluster(subcluster_id);
95  }
96  }
97  RoutingInstance *rtinstance = table->routing_instance();
98  rtinstance->ProcessRoutingPolicy(this, path);
99  } else {
100  IPeer *peer = path->GetPeer();
101  if (peer) {
102  // Take snapshot of original attribute
103  BgpAttr *out_attr = new BgpAttr(*(path->GetOriginalAttr()));
104  peer->ProcessPathTunnelEncapsulation(path, out_attr,
105  table->server()->extcomm_db(), table);
106  BgpAttrPtr modified_attr =
107  table->server()->attr_db()->Locate(out_attr);
108  // Update the path with new set of attributes
109  path->SetAttr(modified_attr, path->GetOriginalAttr());
110  }
111  }
112  }
113  insert(path);
114 
115  Sort(&BgpTable::PathSelection, prev_front);
116 
117  // Update counters.
118  if (table)
119  table->UpdatePathCount(path, +1);
120  path->UpdatePeerRefCount(+1, table ? table->family() : Address::UNSPEC);
121 }
122 
123 //
124 // Delete given path and redo path selection.
125 //
127  const Path *prev_front = front();
128 
129  remove(path);
130  Sort(&BgpTable::PathSelection, prev_front);
131 
132  // Update counters.
133  BgpTable *table = static_cast<BgpTable *>(get_table());
134  if (table)
135  table->UpdatePathCount(path, -1);
136  path->UpdatePeerRefCount(-1, table ? table->family() : Address::UNSPEC);
137 
138  delete path;
139 }
140 
141 //
142 // Find first path with given path source.
143 // Skips secondary, aliased and resolved paths.
144 //
146  for (Route::PathList::const_iterator it = GetPathList().begin();
147  it != GetPathList().end(); ++it) {
148  // Skip secondary paths.
149  if (dynamic_cast<const BgpSecondaryPath *>(it.operator->())) {
150  continue;
151  }
152 
153  const BgpPath *path = static_cast<const BgpPath *>(it.operator->());
154  if (path->GetFlags() & BgpPath::AliasedPath) {
155  continue;
156  }
157  if (path->GetFlags() & BgpPath::ResolvedPath) {
158  continue;
159  }
160  if (path->GetSource() == src) {
161  return path;
162  }
163  }
164  return NULL;
165 }
166 
167 //
168 // Find path added by BGP_XMPP peer.
169 // Skips non BGP_XMPP, secondary, aliased and resolved paths.
170 //
171 BgpPath *BgpRoute::FindPath(const IPeer *peer, bool include_secondary) {
172  for (Route::PathList::iterator it = GetPathList().begin();
173  it != GetPathList().end(); ++it) {
174  BgpPath *path = static_cast<BgpPath *>(it.operator->());
175  if (path->GetSource() != BgpPath::BGP_XMPP) {
176  continue;
177  }
178  if (path->GetFlags() & BgpPath::AliasedPath) {
179  continue;
180  }
181  if (path->GetFlags() & BgpPath::ResolvedPath) {
182  continue;
183  }
184  if (!include_secondary &&
185  dynamic_cast<BgpSecondaryPath *>(it.operator->())) {
186  continue;
187  }
188  if (path->GetPeer() == peer) {
189  return path;
190  }
191  }
192  return NULL;
193 }
194 
195 const BgpPath *BgpRoute::FindPath(const IPeer *peer,
196  bool include_secondary) const {
197  return const_cast<BgpRoute *>(this)->FindPath(peer, include_secondary);
198 }
199 
200 //
201 // Find path with given nexthop address.
202 // Skips non BGP_XMPP, aliased and resolved paths.
203 //
205  for (Route::PathList::iterator it = GetPathList().begin();
206  it != GetPathList().end(); ++it) {
207  BgpPath *path = static_cast<BgpPath *>(it.operator->());
208  if (path->GetSource() != BgpPath::BGP_XMPP) {
209  continue;
210  }
211  if (path->IsResolved() || path->IsAliased()) {
212  continue;
213  }
214  if (path->GetAttr()->nexthop() == nexthop) {
215  return path;
216  }
217  }
218  return NULL;
219 }
220 
221 //
222 // Find path added by peer with given path id and path source.
223 // Skips secondary, aliased and resolved paths.
224 //
226  uint32_t path_id) {
227  for (Route::PathList::iterator it = GetPathList().begin();
228  it != GetPathList().end(); ++it) {
229  // Skip secondary paths.
230  if (dynamic_cast<BgpSecondaryPath *>(it.operator->())) {
231  continue;
232  }
233 
234  BgpPath *path = static_cast<BgpPath *>(it.operator->());
235  if (path->GetFlags() & BgpPath::AliasedPath) {
236  continue;
237  }
238  if (path->GetFlags() & BgpPath::ResolvedPath) {
239  continue;
240  }
241  if (path->GetPeer() == peer && path->GetPathId() == path_id &&
242  path->GetSource() == src) {
243  return path;
244  }
245  }
246  return NULL;
247 }
248 
249 //
250 // Find path added given source and path id - peer must be NULL.
251 // Skips secondary paths and resolved paths.
252 //
254  return FindPath(src, NULL, path_id);
255 }
256 
257 //
258 // Remove path added by peer with given path id and source.
259 // Skips secondary paths.
260 // Return true if the path is found and removed, false otherwise.
261 //
263  uint32_t path_id) {
264  for (Route::PathList::iterator it = GetPathList().begin();
265  it != GetPathList().end(); it++) {
266  BgpPath *path = static_cast<BgpPath *>(it.operator->());
267 
268  //
269  // Skip secondary paths.
270  //
271  if (dynamic_cast<BgpSecondaryPath *>(it.operator->())) {
272  continue;
273  }
274 
275  if (path->GetPeer() == peer && path->GetPathId() == path_id &&
276  path->GetSource() == src) {
277  DeletePath(path);
278  return true;
279  }
280  }
281  return false;
282 }
283 
284 //
285 // Remove path added given source and path id - peer must be NULL.
286 // Skips secondary paths.
287 // Return true if the path is found and removed, false otherwise.
288 //
289 bool BgpRoute::RemovePath(BgpPath::PathSource src, uint32_t path_id) {
290  return RemovePath(src, NULL, path_id);
291 }
292 
293 //
294 // Remove path added by peer with given path id and source.
295 // Skips secondary paths.
296 // Return true if the path is found and removed, false otherwise.
297 //
298 bool BgpRoute::RemovePath(const IPeer *peer) {
299  bool ret = false;
300 
301  for (Route::PathList::iterator it = GetPathList().begin(), next = it;
302  it != GetPathList().end(); it = next) {
303  next++;
304  BgpPath *path = static_cast<BgpPath *>(it.operator->());
305 
306  //
307  // Skip secondary paths.
308  //
309  if (dynamic_cast<BgpSecondaryPath *>(it.operator->())) {
310  continue;
311  }
312 
313  if (path->GetPeer() == peer) {
314  DeletePath(path);
315  ret = true;
316  }
317  }
318  return ret;
319 }
320 
321 //
322 // Check if the route is usable.
323 //
324 bool BgpRoute::IsUsable() const {
325  if (IsDeleted())
326  return false;
327 
328  const BgpPath *path = BestPath();
329  if (!path || !path->IsFeasible())
330  return false;
331 
332  return true;
333 }
334 
335 //
336 // Check if the route is valid.
337 //
338 bool BgpRoute::IsValid() const {
339  return IsUsable();
340 }
341 
342 //
343 // Check if there's a better path with the same forwarding information.
344 //
345 // Return true if we find such a path, false otherwise.
346 //
347 // The forwarding information we look at is just the next hop. We don't
348 // consider the label since there's could be transient cases where we
349 // have 2 paths with the same next hop and different labels. We don't
350 // want to treat these as unique paths.
351 //
352 bool BgpRoute::DuplicateForwardingPath(const BgpPath *in_path) const {
353  for (Route::PathList::const_iterator it = GetPathList().begin();
354  it != GetPathList().end(); ++it) {
355  const BgpPath *path = static_cast<const BgpPath *>(it.operator->());
356 
357  // Bail if we reached the input path since the paths are sorted.
358  if (path == in_path)
359  return false;
360 
361  // Check the forwarding information.
362  if (path->GetAttr()->nexthop() == in_path->GetAttr()->nexthop())
363  return true;
364  }
365 
366  return false;
367 }
368 
369 //
370 // Find the secondary path matching secondary replicated info.
371 //
373  BgpPath::PathSource src, const IPeer *peer, uint32_t path_id) {
374  for (Route::PathList::iterator it = GetPathList().begin();
375  it != GetPathList().end(); ++it) {
376  BgpSecondaryPath *path = dynamic_cast<BgpSecondaryPath *>(
377  it.operator->());
378  // Skip resolved paths. They'll be taken care of by the path
379  // resolver infrastructure.
380  if (path && (src_rt->table()->IsVpnTable()) &&
381  (path->GetFlags() & BgpPath::ResolvedPath)) {
382  continue;
383  }
384  if (path && path->src_rt() == src_rt &&
385  path->GetPeer() == peer && path->GetPathId() == path_id &&
386  path->GetSource() == src) {
387  return path;
388  }
389  }
390  return NULL;
391 }
392 
393 //
394 // Remove the secondary path matching secondary replicated info.
395 // Return true if the path is found and removed, false otherwise.
396 //
398  BgpPath::PathSource src, const IPeer *peer, uint32_t path_id) {
399  for (Route::PathList::iterator it = GetPathList().begin();
400  it != GetPathList().end(); it++) {
401  BgpSecondaryPath *path =
402  dynamic_cast<BgpSecondaryPath *>(it.operator->());
403  // Skip resolved paths. They'll be taken care of by the path
404  // resolver infrastructure.
405  if (path && (src_rt->table()->IsVpnTable()) &&
406  (path->GetFlags() & BgpPath::ResolvedPath)) {
407  continue;
408  }
409  if (path && path->src_rt() == src_rt &&
410  path->GetPeer() == peer && path->GetPathId() == path_id &&
411  path->GetSource() == src) {
412  DeletePath(path);
413  return true;
414  }
415  }
416 
417  return false;
418 }
419 
420 size_t BgpRoute::count() const {
421  return GetPathList().size();
422 }
423 
425  return dynamic_cast<BgpTable *>(get_table_partition()->parent());
426 }
427 
428 const BgpTable *BgpRoute::table() const {
429  return dynamic_cast<BgpTable *>(get_table_partition()->parent());
430 }
431 
433  ShowRouteBrief *show_route) const {
434  show_route->set_prefix(ToString());
435  vector<ShowRoutePathBrief> show_route_paths;
436  for (Route::PathList::const_iterator it = GetPathList().begin();
437  it != GetPathList().end(); ++it) {
438  const BgpPath *path = static_cast<const BgpPath *>(it.operator->());
439  ShowRoutePathBrief srp;
440  const IPeer *peer = path->GetPeer();
441  if (peer) {
442  srp.set_source(peer->ToString());
443  }
444 
445  srp.set_protocol(path->GetSourceString());
446 
447  const BgpAttr *attr = path->GetAttr();
448  srp.set_local_preference(attr->local_pref());
449  srp.set_med(attr->med());
450  srp.set_next_hop(attr->nexthop().to_string());
451  srp.set_label(path->GetLabel());
452  show_route_paths.push_back(srp);
453  }
454  show_route->set_paths(show_route_paths);
455 }
456 
457 static void FillRoutePathClusterListInfo(const ClusterList *clist,
458  ShowRoutePath *show_path) {
459  const vector<uint32_t> &list = clist->cluster_list().cluster_list;
460  vector<string> cluster_list = vector<string>();
461  for (vector<uint32_t>::const_iterator it = list.begin(); it != list.end();
462  ++it) {
463  cluster_list.push_back(Ip4Address(*it).to_string());
464  }
465  show_path->set_cluster_list(cluster_list);
466 }
467 
468 static void FillRoutePathCommunityInfo(const Community *comm,
469  ShowRoutePath *show_path, vector<string> *communities) {
470  comm->BuildStringList(communities);
471 }
472 
473 static void FillRoutePathExtCommunityInfo(const BgpTable *table,
474  const ExtCommunity *extcomm,
475  ShowRoutePath *show_path, vector<string> *communities) {
476  const RoutingInstance *ri = table->routing_instance();
477  const RoutingInstanceMgr *ri_mgr = ri->manager();
478  vector<string> tunnel_encap = vector<string>();
479 
480  const ExtCommunity::ExtCommunityList &v = extcomm->communities();
481  for (ExtCommunity::ExtCommunityList::const_iterator it = v.begin();
482  it != v.end(); ++it) {
484  RouteTarget rt(*it);
485  communities->push_back(rt.ToString());
486  } else if (ExtCommunity::is_default_gateway(*it)) {
487  DefaultGateway dgw(*it);
488  communities->push_back(dgw.ToString());
489  } else if (ExtCommunity::is_es_import(*it)) {
490  EsImport es_import(*it);
491  communities->push_back(es_import.ToString());
492  } else if (ExtCommunity::is_esi_label(*it)) {
493  EsiLabel esi_label(*it);
494  communities->push_back(esi_label.ToString());
495  } else if (ExtCommunity::is_mac_mobility(*it)) {
496  MacMobility mm(*it);
497  communities->push_back(mm.ToString());
498  show_path->set_sequence_no(integerToString(mm.sequence_number()));
499  } else if (ExtCommunity::is_local_sequence_number(*it)) {
500  LocalSequenceNumber lsn(*it);
501  communities->push_back(lsn.ToString());
502  } else if (ExtCommunity::is_etree(*it)) {
503  ETree etree(*it);
504  communities->push_back(etree.ToString());
505  } else if (ExtCommunity::is_router_mac(*it)) {
506  RouterMac router_mac(*it);
507  communities->push_back(router_mac.ToString());
508  } else if (ExtCommunity::is_origin_vn(*it)) {
509  OriginVn origin_vn(*it);
510  communities->push_back(origin_vn.ToString());
511  int vn_index = origin_vn.vn_index();
512  show_path->set_origin_vn(
513  ri_mgr->GetVirtualNetworkByVnIndex(vn_index));
514  } else if (ExtCommunity::is_security_group(*it)) {
515  SecurityGroup sg(*it);
516  communities->push_back(sg.ToString());
517  } else if (ExtCommunity::is_security_group4(*it)) {
518  SecurityGroup4ByteAs sg(*it);
519  communities->push_back(sg.ToString());
520  } else if (ExtCommunity::is_site_of_origin(*it)) {
521  SiteOfOrigin soo(*it);
522  communities->push_back(soo.ToString());
523  } else if (ExtCommunity::is_tunnel_encap(*it)) {
524  TunnelEncap encap(*it);
525  communities->push_back(encap.ToString());
527  tunnel_encap.push_back(TunnelEncapType::TunnelEncapToString(id));
528  } else if (ExtCommunity::is_load_balance(*it)) {
529  LoadBalance load_balance(*it);
530  communities->push_back(load_balance.ToString());
531 
532  ShowLoadBalance show_load_balance;
533  load_balance.ShowAttribute(&show_load_balance);
534  show_path->set_load_balance(show_load_balance);
535  } else if (ExtCommunity::is_tag(*it)) {
536  Tag tag(*it);
537  communities->push_back(tag.ToString());
538  } else if (ExtCommunity::is_tag4(*it)) {
539  Tag4ByteAs tag(*it);
540  communities->push_back(tag.ToString());
541  } else if (ExtCommunity::is_source_as(*it)) {
542  SourceAs sas(*it);
543  communities->push_back(sas.ToString());
544  } else if (ExtCommunity::is_sub_cluster(*it)) {
545  SubCluster sc(*it);
546  communities->push_back(sc.ToString());
547  } else if (ExtCommunity::is_vrf_route_import(*it)) {
548  VrfRouteImport rt_import(*it);
549  communities->push_back(rt_import.ToString());
550  } else if (ExtCommunity::is_multicast_flags(*it)) {
551  MulticastFlags mf(*it);
552  communities->push_back(mf.ToString());
553  } else {
554  char temp[50];
555  int len = snprintf(temp, sizeof(temp), "ext community: ");
556  for (size_t i = 0; i < it->size(); i++) {
557  len += snprintf(temp+len, sizeof(temp) - len, "%02x", (*it)[i]);
558  }
559  communities->push_back(string(temp));
560  }
561  }
562  show_path->set_tunnel_encap(tunnel_encap);
563 }
564 
565 static void FillEdgeForwardingInfo(const EdgeForwarding *edge_forwarding,
566  ShowRoutePath *show_path) {
567  vector<ShowEdgeForwarding> show_ef_list;
568  vector<EdgeForwardingSpec::Edge *> edge_list =
569  edge_forwarding->edge_forwarding().edge_list;
570  for (vector<EdgeForwardingSpec::Edge *>::const_iterator it =
571  edge_list.begin(); it != edge_list.end(); ++it) {
572  const EdgeForwardingSpec::Edge *edge = *it;
573  ShowEdgeForwarding show_ef;
574  ostringstream oss;
575  oss << edge->GetInboundIp4Address() << ":" << edge->inbound_label;
576  show_ef.set_in_address_label(oss.str());
577  oss.str("");
578  oss.clear();
579  oss << edge->GetOutboundIp4Address() << ":" << edge->outbound_label;
580  show_ef.set_out_address_label(oss.str());
581  show_ef_list.push_back(show_ef);
582  }
583  show_path->set_edge_forwarding(show_ef_list);
584 }
585 
586 static void FillEdgeDiscoveryInfo(const EdgeDiscovery *edge_discovery,
587  ShowRoutePath *show_path) {
588  vector<ShowEdgeDiscovery> show_ed_list;
589  vector<EdgeDiscoverySpec::Edge *> edge_list =
590  edge_discovery->edge_discovery().edge_list;
591  int idx = 0;
592  for (vector<EdgeDiscoverySpec::Edge *>::const_iterator it =
593  edge_list.begin();
594  it != edge_list.end(); ++it, ++idx) {
595  const EdgeDiscoverySpec::Edge *edge = *it;
596  ShowEdgeDiscovery show_ed;
597  ostringstream oss;
598  uint32_t first_label, last_label;
599  oss << edge->GetIp4Address();
600  show_ed.set_address(oss.str());
601  oss.str("");
602  oss.clear();
603  edge->GetLabels(&first_label, &last_label);
604  oss << first_label << "-" << last_label;
605  show_ed.set_labels(oss.str());
606  show_ed_list.push_back(show_ed);
607  }
608  show_path->set_edge_discovery(show_ed_list);
609 }
610 
611 static void FillOriginVnPathInfo(const OriginVnPath *ovnpath,
612  ShowRoutePath *show_path) {
613  const OriginVnPath::OriginVnList &v = ovnpath->origin_vns();
614  vector<string> origin_vn_path = vector<string>();
615  for (OriginVnPath::OriginVnList::const_iterator it = v.begin();
616  it != v.end(); ++it) {
617  OriginVn origin_vn(*it);
618  origin_vn_path.push_back(origin_vn.ToString());
619  }
620  show_path->set_origin_vn_path(origin_vn_path);
621 }
622 
623 static void FillPmsiTunnelInfo(const PmsiTunnel *pmsi_tunnel,
624  const ExtCommunity *ext, ShowRoutePath *show_path) {
625  ShowPmsiTunnel spt;
626  spt.set_type(pmsi_tunnel->pmsi_tunnel().GetTunnelTypeString());
627  spt.set_ar_type(pmsi_tunnel->pmsi_tunnel().GetTunnelArTypeString());
628  spt.set_identifier(pmsi_tunnel->identifier().to_string());
629  spt.set_label(pmsi_tunnel->GetLabel(ext));
630  spt.set_flags(pmsi_tunnel->pmsi_tunnel().GetTunnelFlagsStrings());
631  show_path->set_pmsi_tunnel(spt);
632 }
633 
634 void BgpRoute::FillRouteInfo(const BgpTable *table,
635  ShowRoute *show_route, const string &source, const string &protocol) const {
636  const RoutingInstance *ri = table->routing_instance();
637 
638  show_route->set_prefix(ToString());
639  show_route->set_last_modified(
641 
642  vector<ShowRoutePath> show_route_paths;
643  for (Route::PathList::const_iterator it = GetPathList().begin();
644  it != GetPathList().end(); ++it) {
645  const BgpPath *path = static_cast<const BgpPath *>(it.operator->());
646  ShowRoutePath srp;
647  const IPeer *peer = path->GetPeer();
648 
649  // Filter against peer source, if specified.
650  if (!source.empty() && (!peer || source != peer->ToString()))
651  continue;
652 
653  // Filter against path protocol, if specified.
654  if (!protocol.empty() && protocol != path->GetSourceString())
655  continue;
656 
657  if (peer) {
658  srp.set_source(peer->ToString());
659  }
660 
661  const BgpPeer *bgp_peer = dynamic_cast<const BgpPeer *>(peer);
662  if (bgp_peer) {
663  srp.set_local_as(bgp_peer->local_as());
664  srp.set_peer_as(bgp_peer->peer_as());
665  srp.set_peer_router_id(bgp_peer->bgp_identifier_string());
666  }
667 
668  const BgpAttr *attr = path->GetAttr();
669  if (attr->edge_forwarding()) {
671  }
672  if (attr->edge_discovery()) {
673  FillEdgeDiscoveryInfo(attr->edge_discovery(), &srp);
674  }
675  if (attr->sub_protocol().empty()) {
676  srp.set_protocol(path->GetSourceString());
677  } else {
678  const string sbp = attr->sub_protocol();
679  srp.set_protocol(path->GetSourceString() + " (" + sbp + ")");
680  }
681  srp.set_origin(attr->origin_string());
682  if (attr->as_path() != NULL)
683  srp.set_as_path(attr->as_path()->path().ToString());
684  else if (attr->aspath_4byte() != NULL)
685  srp.set_as_path(attr->aspath_4byte()->path().ToString());
686  if (attr->as4_path() != NULL)
687  srp.set_as4_path(attr->as4_path()->path().ToString());
688  srp.set_local_preference(attr->local_pref());
689  srp.set_med(attr->med());
690  srp.set_next_hop(attr->nexthop().to_string());
691  srp.set_label(path->GetLabel());
692  srp.set_flags(path->GetFlagsStringList());
693  srp.set_last_modified(
695  if (path->IsReplicated()) {
696  const BgpSecondaryPath *replicated;
697  replicated = static_cast<const BgpSecondaryPath *>(path);
698  srp.set_replicated(true);
699  srp.set_primary_table(replicated->src_table()->name());
700  } else {
701  srp.set_replicated(false);
702  Address::Family vpn_family =
704  const RoutePathReplicator *replicator =
705  table->server()->replicator(vpn_family);
706  if (replicator) {
707  srp.set_secondary_tables(
708  replicator->GetReplicatedTableNameList(table, this, path));
709  }
710  }
711  if (attr->cluster_list()) {
713  }
714  vector<string> communities;
715  if (attr->community()) {
716  FillRoutePathCommunityInfo(attr->community(), &srp, &communities);
717  }
718  if (attr->ext_community()) {
719  FillRoutePathExtCommunityInfo(table, attr->ext_community(), &srp,
720  &communities);
721  }
722  if (!communities.empty()){
723  srp.set_communities(communities);
724  }
725  if (srp.get_origin_vn().empty() &&
726  !table->IsVpnTable() && path->IsVrfOriginated()) {
727  srp.set_origin_vn(ri->GetVirtualNetworkName());
728  }
729  if (attr->origin_vn_path()) {
730  FillOriginVnPathInfo(attr->origin_vn_path(), &srp);
731  }
732  if (attr->pmsi_tunnel()) {
733  const ExtCommunity *extcomm = attr->ext_community();
734  if (extcomm) {
735  FillPmsiTunnelInfo(attr->pmsi_tunnel(), extcomm, &srp);
736  }
737  }
738  if (attr->originator_id().to_ulong()) {
739  srp.set_originator_id(attr->originator_id().to_string());
740  }
741 
742  show_route_paths.push_back(srp);
743  }
744  show_route->set_paths(show_route_paths);
745 }
746 
748  if (!front()) {
749  Delete();
750  } else {
751  Notify();
752  }
753 }
754 
755 uint32_t BgpRoute::SubClusterId() const {
756  BgpTable *table = static_cast<BgpTable *>(get_table());
757  const BgpConfigManager *config_manager_ = table->server()->config_manager();
758  if (!config_manager_) {
759  return 0;
760  }
761  const BgpProtocolConfig *proto =
763  if (!proto) {
764  return 0;
765  }
766  return proto->subcluster_id();
767 }
void UpdatePathCount(const BgpPath *path, int count)
Definition: bgp_table.cc:1116
void FillRouteInfo(const BgpTable *table, ShowRouteBrief *show_route) const
Definition: bgp_route.cc:432
void ShowAttribute(ShowLoadBalance *show_load_balance) const
const Community * community() const
Definition: bgp_attr.h:914
const Ip4Address identifier() const
Definition: bgp_attr.h:384
static void FillRoutePathCommunityInfo(const Community *comm, ShowRoutePath *show_path, vector< string > *communities)
Definition: bgp_route.cc:468
Ip4Address GetInboundIp4Address() const
Definition: bgp_attr.cc:594
std::vector< OriginVnValue > OriginVnList
static Family VpnFamilyFromFamily(Family family)
Definition: address.cc:71
const ClusterListSpec & cluster_list() const
Definition: bgp_attr.h:229
void Sort(Compare compare, const Path *prev_front)
Definition: route.cc:40
uint32_t local_pref() const
Definition: bgp_attr.h:889
const IpAddress & nexthop() const
Definition: bgp_attr.h:886
Definition: etree.h:16
const BgpPath * BestPath() const
Definition: bgp_route.cc:46
TypePtr Locate(Type *attr)
void NotifyOrDelete()
Definition: bgp_route.cc:747
const AsPathSpec & path() const
Definition: bgp_aspath.h:127
void GetLabels(uint32_t *first_label, uint32_t *last_label) const
Definition: bgp_attr.cc:456
std::string ToString()
Definition: tunnel_encap.cc:51
std::vector< std::string > GetTunnelFlagsStrings() const
Definition: bgp_attr.cc:386
DBTableBase * get_table() const
Definition: db_entry.cc:119
bool RemoveSecondaryPath(const BgpRoute *src_rt, BgpPath::PathSource src, const IPeer *peer, uint32_t path_id)
Definition: bgp_route.cc:397
static bool is_security_group(const ExtCommunityValue &val)
Definition: community.h:304
BgpRoute()
Definition: bgp_route.cc:35
std::string ToString() const
std::string ToString() const
const EdgeForwardingSpec & edge_forwarding() const
Definition: bgp_attr.h:577
std::string ToString()
virtual bool IsVpnTable() const
Definition: bgp_table.h:110
static const std::string & TunnelEncapToString(TunnelEncapType::Encap encap)
RoutingInstance * routing_instance()
Definition: bgp_table.h:148
Family
Definition: address.h:24
static const char * kMasterInstance
Definition: bgp_config.h:764
bool IsDeleted() const
Definition: db_entry.h:49
boost::asio::ip::address IpAddress
Definition: address.h:13
EdgeList edge_list
Definition: bgp_attr.h:459
static bool is_source_as(const ExtCommunityValue &val)
Definition: community.h:335
const uint32_t GetPathId() const
Definition: bgp_path.h:78
DBTableBase * parent()
const OriginVnPath * origin_vn_path() const
Definition: bgp_attr.h:916
virtual std::string ToString() const
Definition: bgp_aspath.cc:73
std::string ToString() const
const BgpPath * FindPath(BgpPath::PathSource src) const
Definition: bgp_route.cc:145
const Ip4Address & originator_id() const
Definition: bgp_attr.h:895
RoutePathReplicator * replicator(Address::Family family)
Definition: bgp_server.h:146
static void FillOriginVnPathInfo(const OriginVnPath *ovnpath, ShowRoutePath *show_path)
Definition: bgp_route.cc:611
static bool is_site_of_origin(const ExtCommunityValue &val)
Definition: community.h:322
static void FillEdgeDiscoveryInfo(const EdgeDiscovery *edge_discovery, ShowRoutePath *show_path)
Definition: bgp_route.cc:586
std::string ToString() const
virtual Address::Family family() const =0
uint32_t GetFlags() const
Definition: bgp_path.h:100
Definition: ipeer.h:186
std::string origin_string() const
Definition: bgp_attr.cc:1120
std::vector< uint32_t > cluster_list
Definition: bgp_attr.h:217
std::string ToString()
static bool is_esi_label(const ExtCommunityValue &val)
Definition: community.h:219
std::string ToString() const
Definition: source_as.cc:50
bool IsUsable() const
Definition: bgp_route.cc:324
static bool is_security_group4(const ExtCommunityValue &val)
Definition: community.h:313
std::string GetSourceString(bool combine_bgp_and_xmpp=false) const
Definition: bgp_path.cc:270
Ip4Address GetIp4Address() const
Definition: bgp_attr.cc:446
const uint64_t last_change_at() const
Definition: db_entry.h:68
boost::intrusive_ptr< const BgpAttr > BgpAttrPtr
Definition: bgp_attr.h:991
std::string ToString()
Definition: mac_mobility.cc:43
const std::string & sub_protocol() const
Definition: bgp_attr.h:927
PathSource
Definition: bgp_path.h:37
std::string ToString()
Ip4Address GetOutboundIp4Address() const
Definition: bgp_attr.cc:598
bool IsFeasible() const
Definition: bgp_path.h:92
static void FillRoutePathExtCommunityInfo(const BgpTable *table, const ExtCommunity *extcomm, ShowRoutePath *show_path, vector< string > *communities)
Definition: bgp_route.cc:473
PathSource GetSource() const
Definition: bgp_path.h:103
static const std::string integerToString(const NumberType &num)
Definition: string_util.h:19
const AsPath4Byte * aspath_4byte() const
Definition: bgp_attr.h:902
virtual bool IsRoutingPolicySupported() const
Definition: bgp_table.h:111
const ClusterList * cluster_list() const
Definition: bgp_attr.h:907
const ExtCommunityList & communities() const
Definition: community.h:180
Definition: path.h:10
ExtCommunityDB * extcomm_db()
Definition: bgp_server.h:187
std::string ToString() const
static bool is_router_mac(const ExtCommunityValue &val)
Definition: community.h:257
BgpConfigManager * config_manager()
Definition: bgp_server.h:100
std::string GetTunnelArTypeString() const
Definition: bgp_attr.cc:372
static bool is_multicast_flags(const ExtCommunityValue &val)
Definition: community.h:248
virtual const std::string & ToString() const =0
static void FillPmsiTunnelInfo(const PmsiTunnel *pmsi_tunnel, const ExtCommunity *ext, ShowRoutePath *show_path)
Definition: bgp_route.cc:623
TunnelEncapType::Encap tunnel_encap() const
Definition: tunnel_encap.cc:40
static boost::posix_time::ptime UTCUsecToPTime(uint64_t tusec)
Definition: time_util.h:38
as_t local_as() const
Definition: bgp_peer.h:183
virtual std::string ToString() const =0
std::string ToString() const
Definition: es_import.cc:28
static bool is_tag4(const ExtCommunityValue &val)
Definition: community.h:384
IPeer * GetPeer()
Definition: bgp_path.h:76
void UpdatePeerRefCount(int count, Address::Family family) const
Definition: bgp_path.cc:168
bool IsVrfOriginated() const
Definition: bgp_path.h:68
const std::string & name() const
Definition: db_table.h:110
const EdgeDiscoverySpec & edge_discovery() const
Definition: bgp_attr.h:470
const As4Path * as4_path() const
Definition: bgp_attr.h:911
uint32_t GetLabel() const
Definition: bgp_path.h:89
static void FillRoutePathClusterListInfo(const ClusterList *clist, ShowRoutePath *show_path)
Definition: bgp_route.cc:457
virtual std::string ToString() const
Definition: bgp_aspath.cc:335
bool IsResolved() const
Definition: bgp_path.h:99
bool ProcessRoutingPolicy(const BgpRoute *route, BgpPath *path) const
uint32_t sequence_number() const
Definition: mac_mobility.cc:32
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
uint32_t subcluster_id() const
Definition: bgp_config.h:561
const AsPath * as_path() const
Definition: bgp_attr.h:899
static bool is_es_import(const ExtCommunityValue &val)
Definition: community.h:211
uint32_t SubClusterId() const
Definition: bgp_route.cc:755
void InsertPath(BgpPath *path)
Definition: bgp_route.cc:60
void Delete()
Definition: db_entry.cc:131
const BgpAttr * GetOriginalAttr() const
Definition: bgp_path.h:88
static bool is_local_sequence_number(const ExtCommunityValue &val)
Definition: community.h:235
bool DuplicateForwardingPath(const BgpPath *in_path) const
Definition: bgp_route.cc:352
BgpServer * server()
Definition: bgp_table.cc:88
bool RemovePath(BgpPath::PathSource src, const IPeer *peer=NULL, uint32_t path_id=0)
Definition: bgp_route.cc:262
const RoutingInstanceMgr * manager() const
static bool is_sub_cluster(const ExtCommunityValue &val)
Definition: community.h:346
const Path * front() const
Definition: route.cc:16
BgpPath * FindSecondaryPath(BgpRoute *src_rt, BgpPath::PathSource src, const IPeer *peer, uint32_t path_id)
Definition: bgp_route.cc:372
static bool is_default_gateway(const ExtCommunityValue &val)
Definition: community.h:203
const ExtCommunity * ext_community() const
Definition: bgp_attr.h:915
int vn_index() const
Definition: origin_vn.cc:122
const BgpRoute * src_rt() const
Definition: bgp_path.h:186
const OriginVnList & origin_vns() const
const AsPath4ByteSpec & path() const
Definition: bgp_aspath.h:285
BgpAttrDB * attr_db()
Definition: bgp_server.h:181
void AddExtCommunitySubCluster(uint32_t subcluster_id)
Definition: bgp_path.cc:304
static bool PathSelection(const Path &path1, const Path &path2)
Definition: bgp_table.cc:821
std::vector< ExtCommunityValue > ExtCommunityList
Definition: community.h:153
std::string ToString()
Definition: router_mac.cc:33
static bool is_tag(const ExtCommunityValue &val)
Definition: community.h:378
std::string GetVirtualNetworkByVnIndex(int vn_index) const
BgpTable * table()
Definition: bgp_route.cc:424
static bool is_route_target(const ExtCommunityValue &val)
Definition: community.h:265
const BgpAttr * GetAttr() const
Definition: bgp_path.h:87
std::vector< std::string > GetFlagsStringList() const
Definition: bgp_path.cc:191
static bool is_tunnel_encap(const ExtCommunityValue &val)
Definition: community.h:366
std::string ToString() const
Definition: sub_cluster.cc:59
size_t count() const
Definition: bgp_route.cc:420
const std::string GetVirtualNetworkName() const
void set_med(uint32_t med)
Definition: bgp_attr.h:838
bool IsAliased() const
Definition: bgp_path.h:98
std::string ToString() const
const PmsiTunnelSpec & pmsi_tunnel() const
Definition: bgp_attr.h:373
as_t peer_as() const
Definition: bgp_peer.h:184
std::string GetTunnelTypeString() const
Definition: bgp_attr.cc:346
const uint64_t time_stamp_usecs() const
Definition: path.h:17
void DeletePath(BgpPath *path)
Definition: bgp_route.cc:126
~BgpRoute()
Definition: bgp_route.cc:38
EdgeList edge_list
Definition: bgp_attr.h:566
const EdgeForwarding * edge_forwarding() const
Definition: bgp_attr.h:921
const As4PathSpec & path() const
Definition: bgp_aspath.h:443
static bool is_etree(const ExtCommunityValue &val)
Definition: community.h:240
void Notify()
Definition: db_entry.cc:127
std::string ToString() const
Definition: esi_label.cc:44
DBTablePartBase * get_table_partition() const
Definition: db_entry.cc:115
const BgpTable * src_table() const
Definition: bgp_path.h:182
const EdgeDiscovery * edge_discovery() const
Definition: bgp_attr.h:918
static void FillEdgeForwardingInfo(const EdgeForwarding *edge_forwarding, ShowRoutePath *show_path)
Definition: bgp_route.cc:565
std::string ToString()
Definition: origin_vn.cc:138
uint32_t med() const
Definition: bgp_attr.h:888
std::string ToString() const
std::string bgp_identifier_string() const
Definition: bgp_peer.cc:1227
virtual std::string ToString() const
Definition: bgp_aspath.cc:561
static bool is_vrf_route_import(const ExtCommunityValue &val)
Definition: community.h:357
const PmsiTunnel * pmsi_tunnel() const
Definition: bgp_attr.h:917
virtual const BgpProtocolConfig * GetProtocolConfig(const std::string &instance_name) const =0
void BuildStringList(std::vector< std::string > *list) const
Definition: community.cc:121
virtual void ProcessPathTunnelEncapsulation(const BgpPath *path, BgpAttr *attr, ExtCommunityDB *extcomm_db, const BgpTable *table) const =0
virtual bool IsReplicated() const
Definition: bgp_path.h:91
std::string ToString()
Definition: etree.cc:44
void insert(const Path *path)
Definition: route.cc:24
virtual bool IsValid() const
Definition: bgp_route.cc:338
void SetAttr(const BgpAttrPtr attr, const BgpAttrPtr original_attr)
Definition: bgp_path.h:82
uint32_t GetLabel(const ExtCommunity *ext) const
Definition: bgp_attr.cc:415
static bool is_mac_mobility(const ExtCommunityValue &val)
Definition: community.h:227
const PathList & GetPathList() const
Definition: route.h:46
static bool is_load_balance(const ExtCommunityValue &val)
Definition: community.h:372
static bool is_origin_vn(const ExtCommunityValue &val)
Definition: community.h:193