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