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