OpenSDN source code
bgp_attr.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_attr.h"
7 
8 #include <algorithm>
9 #include <string>
10 
11 #include "bgp/bgp_server.h"
16 #include "net/bgp_af.h"
17 
18 using std::sort;
19 using std::vector;
20 using std::string;
21 
22 int BgpAttrOrigin::CompareTo(const BgpAttribute &rhs_attr) const {
23  int ret = BgpAttribute::CompareTo(rhs_attr);
24  if (ret != 0) return ret;
25  KEY_COMPARE(origin, static_cast<const BgpAttrOrigin &>(rhs_attr).origin);
26  return 0;
27 }
28 
30  attr->set_origin(static_cast<BgpAttrOrigin::OriginType>(origin));
31 }
32 
33 string BgpAttrOrigin::ToString() const {
34  char repr[80];
35  snprintf(repr, sizeof(repr), "ORIGIN <code: %d, flags: %02x> : %02x",
36  code, flags, origin);
37  return string(repr);
38 }
39 
40 int BgpAttrNextHop::CompareTo(const BgpAttribute &rhs_attr) const {
41  int ret = BgpAttribute::CompareTo(rhs_attr);
42  if (ret != 0) return ret;
44  static_cast<const BgpAttrNextHop &>(rhs_attr).nexthop);
45  return 0;
46 }
47 
49  if (v6_nexthop.is_unspecified()) {
51  } else {
52  attr->set_nexthop(v6_nexthop);
53  }
54 }
55 
56 string BgpAttrNextHop::ToString() const {
57  char repr[80];
58  snprintf(repr, sizeof(repr), "NEXTHOP <code: %d, flags: %02x> : %04x",
59  code, flags, nexthop);
60  return string(repr);
61 }
62 
63 int BgpAttrMultiExitDisc::CompareTo(const BgpAttribute &rhs_attr) const {
64  int ret = BgpAttribute::CompareTo(rhs_attr);
65  if (ret != 0) return ret;
66  KEY_COMPARE(med, static_cast<const BgpAttrMultiExitDisc &>(rhs_attr).med);
67  return 0;
68 }
70  attr->set_med(med);
71 }
72 
74  char repr[80];
75  snprintf(repr, sizeof(repr), "MED <code: %d, flags: %02x> : %d",
76  code, flags, med);
77  return string(repr);
78 }
79 
80 int BgpAttrLocalPref::CompareTo(const BgpAttribute &rhs_attr) const {
81  int ret = BgpAttribute::CompareTo(rhs_attr);
82  if (ret != 0) return ret;
84  static_cast<const BgpAttrLocalPref &>(rhs_attr).local_pref);
85  return 0;
86 }
89 }
90 
92  char repr[80];
93  snprintf(repr, sizeof(repr), "LOCAL_PREF <code: %d, flags: %02x> : %d",
95  return string(repr);
96 }
97 
99  attr->set_atomic_aggregate(true);
100 }
101 
103  char repr[80];
104  snprintf(repr, sizeof(repr), "ATOMIC_AGGR <code: %d, flags: %02x>",
105  code, flags);
106  return string(repr);
107 }
108 
110  int ret = BgpAttribute::CompareTo(rhs_attr);
111  if (ret != 0) return ret;
113  static_cast<const BgpAttr4ByteAggregator &>(rhs_attr).as_num);
115  static_cast<const BgpAttr4ByteAggregator &>(rhs_attr).address);
116  return 0;
117 }
120 }
121 
123  char repr[80];
124  snprintf(repr, sizeof(repr),
125  "Aggregator <code: %d, flags: %02x> : %d:%08x",
126  code, flags, as_num, address);
127  return string(repr);
128 }
129 
130 int BgpAttrAggregator::CompareTo(const BgpAttribute &rhs_attr) const {
131  int ret = BgpAttribute::CompareTo(rhs_attr);
132  if (ret != 0) return ret;
134  static_cast<const BgpAttrAggregator &>(rhs_attr).as_num);
136  static_cast<const BgpAttrAggregator &>(rhs_attr).address);
137  return 0;
138 }
141 }
142 
144  char repr[80];
145  snprintf(repr, sizeof(repr),
146  "Aggregator <code: %d, flags: %02x> : %d:%08x",
147  code, flags, as_num, address);
148  return string(repr);
149 }
150 
151 int BgpAttrAs4Aggregator::CompareTo(const BgpAttribute &rhs_attr) const {
152  int ret = BgpAttribute::CompareTo(rhs_attr);
153  if (ret != 0) return ret;
155  static_cast<const BgpAttrAs4Aggregator &>(rhs_attr).as_num);
157  static_cast<const BgpAttrAs4Aggregator &>(rhs_attr).address);
158  return 0;
159 }
162 }
163 
165  char repr[80];
166  snprintf(repr, sizeof(repr),
167  "Aggregator <code: %d, flags: %02x> : %d:%08x",
168  code, flags, as_num, address);
169  return string(repr);
170 }
171 
172 int BgpAttrOriginatorId::CompareTo(const BgpAttribute &rhs_attr) const {
173  int ret = BgpAttribute::CompareTo(rhs_attr);
174  if (ret != 0) return ret;
176  static_cast<const BgpAttrOriginatorId &>(rhs_attr).originator_id);
177  return 0;
178 }
179 
182 }
183 
185  char repr[80];
186  snprintf(repr, sizeof(repr), "OriginatorId <code: %d, flags: 0x%02x> : %s",
187  code, flags, Ip4Address(originator_id).to_string().c_str());
188  return string(repr);
189 }
190 
192  const ClusterListSpec *rhs)
194  cluster_list.push_back(cluster_id);
195  if (rhs) {
196  cluster_list.insert(cluster_list.end(), rhs->cluster_list.begin(),
197  rhs->cluster_list.end());
198  }
199 }
200 
201 int ClusterListSpec::CompareTo(const BgpAttribute &rhs_attr) const {
202  int ret = BgpAttribute::CompareTo(rhs_attr);
203  if (ret != 0) return ret;
205  static_cast<const ClusterListSpec &>(rhs_attr).cluster_list);
206  return 0;
207 }
208 
210  attr->set_cluster_list(this);
211 }
212 
214  std::stringstream repr;
215  repr << "CLUSTER_LIST <code: " << int(code);
216  repr << ", flags: 0x" << std::hex << int(flags) << "> :";
217  for (vector<uint32_t>::const_iterator iter = cluster_list.begin();
218  iter != cluster_list.end(); ++iter) {
219  repr << " " << Ip4Address(*iter).to_string();
220  }
221  return repr.str();
222 }
223 
224 bool ClusterListSpec::ClusterListLoop(uint32_t cluster_id) const {
225  for (vector<uint32_t>::const_iterator iter = cluster_list.begin();
226  iter != cluster_list.end(); ++iter) {
227  if (*iter == cluster_id)
228  return true;
229  }
230  return false;
231 }
232 
234  const ClusterListSpec &spec)
235  : cluster_list_db_(cluster_list_db),
236  spec_(spec) {
237  refcount_ = 0;
238 }
239 
241  cluster_list_db_->Delete(this);
242 }
243 
245 }
246 
247 int BgpMpNlri::CompareTo(const BgpAttribute &rhs_attr) const {
248  int ret = BgpAttribute::CompareTo(rhs_attr);
249  if (ret != 0) return ret;
250  const BgpMpNlri &rhs = static_cast<const BgpMpNlri &>(rhs_attr);
251  KEY_COMPARE(afi, rhs.afi);
252  KEY_COMPARE(safi, rhs.safi);
254  KEY_COMPARE(nlri.size(), rhs.nlri.size());
255 
256  for (size_t i = 0; i < nlri.size(); i++) {
257  KEY_COMPARE(nlri[i]->type, rhs.nlri[i]->type);
258  KEY_COMPARE(nlri[i]->prefixlen, rhs.nlri[i]->prefixlen);
259  KEY_COMPARE(nlri[i]->prefix, rhs.nlri[i]->prefix);
260  }
261  return 0;
262 }
263 
265 }
266 
267 size_t BgpMpNlri::EncodeLength() const {
268  size_t sz = 2 /* safi */ + 1 /* afi */ +
269  1 /* NlriNextHopLength */ +
270  1 /* Reserved */;
271  sz += nexthop.size();
272  for (vector<BgpProtoPrefix*>::const_iterator iter = nlri.begin();
273  iter != nlri.end(); ++iter) {
274  size_t bytes = 0;
275  if (afi == BgpAf::L2Vpn &&
276  (safi == BgpAf::EVpn || safi == BgpAf::ErmVpn)) {
277  bytes = (*iter)->prefixlen;
278  } else {
279  bytes = ((*iter)->prefixlen + 7) / 8;
280  }
281  sz += 1 + bytes;
282  }
283  return sz;
284 }
285 
287  : BgpAttribute(PmsiTunnel, kFlags),
288  tunnel_flags(0), tunnel_type(0), label(0) {
289 }
290 
292  : BgpAttribute(rhs), tunnel_flags(0), tunnel_type(0), label(0) {
293 }
294 
295 int PmsiTunnelSpec::CompareTo(const BgpAttribute &rhs_attr) const {
296  int ret = BgpAttribute::CompareTo(rhs_attr);
297  if (ret != 0) return ret;
298  const PmsiTunnelSpec &rhs = static_cast<const PmsiTunnelSpec &>(rhs_attr);
301  KEY_COMPARE(label, rhs.label);
303  return 0;
304 }
305 
307  attr->set_pmsi_tunnel(this);
308 }
309 
310 string PmsiTunnelSpec::ToString() const {
311  std::ostringstream oss;
312  oss << "PmsiTunnel <code: " << int(code);
313  oss << ", flags: 0x" << std::hex << int(flags) << std::dec << ">";
314  oss << " Tunnel Flags: 0x" << std::hex << int(tunnel_flags) << std::dec;
315  oss << " Tunnel Type: " << int(tunnel_type);
316  oss << " Label: 0x" << std::hex << int(label) << std::dec;
317  oss << " (" << int(label) << ")";
318  oss << " Identifier: " << GetIdentifier().to_string();
319 
320  return oss.str();
321 }
322 
323 uint32_t PmsiTunnelSpec::GetLabel(const ExtCommunity *ext) const {
324  assert(ext);
325  bool is_vni = ext->ContainsTunnelEncapVxlan();
326  return (is_vni ? label : (label >> 4));
327 }
328 
329 void PmsiTunnelSpec::SetLabel(uint32_t in_label, const ExtCommunity *ext) {
330  assert(ext);
331  bool is_vni = ext->ContainsTunnelEncapVxlan();
332  label = (is_vni ? in_label : (in_label << 4 | 0x01));
333 }
334 
336  if (identifier.size() < 4)
337  return Ip4Address();
338  return Ip4Address(get_value(&identifier[0], 4));
339 }
340 
342  identifier.resize(4, 0);
343  const Ip4Address::bytes_type &bytes = in_identifier.to_bytes();
344  std::copy(bytes.begin(), bytes.begin() + 4, identifier.begin());
345 }
346 
348  switch (tunnel_type) {
349  case RsvpP2mpLsp:
350  return "RsvpP2mpLsp";
351  case LdpP2mpLsp:
352  return "LdpP2mpLsp";
353  case PimSsmTree:
354  return "PimSsmTree";
355  case PimSmTree:
356  return "PimSmTree";
357  case BidirPimTree:
358  return "BidirPimTree";
359  case IngressReplication:
360  return "IngressReplication";
361  case MldpMp2mpLsp:
362  return "MldpMp2mpLsp";
364  return "AssistedReplication";
365  default:
366  break;
367  }
368  std::ostringstream oss;
369  oss << "Unknown(" << int(tunnel_type) << ")";
370  return oss.str();
371 }
372 
375  case RegularNVE:
376  return "RegularNVE";
377  case ARReplicator:
378  return "ARReplicator";
379  case ARLeaf:
380  return "ARLeaf";
381  default:
382  break;
383  }
384  return "Unknown";
385 }
386 
388  vector<string> flags;
390  flags.push_back("LeafInfoRequired");
391  }
393  flags.push_back("EdgeReplicationSupported");
394  }
395  if (flags.empty()) {
396  flags.push_back("None");
397  }
398  return flags;
399 }
400 
402  const PmsiTunnelSpec &pmsi_spec)
403  : pmsi_tunnel_db_(pmsi_tunnel_db),
404  pmsi_spec_(pmsi_spec) {
405  refcount_ = 0;
410 }
411 
413  pmsi_tunnel_db_->Delete(this);
414 }
415 
416 uint32_t PmsiTunnel::GetLabel(const ExtCommunity *ext) const {
417  bool is_vni = false;
418  if (ext)
419  is_vni = ext->ContainsTunnelEncapVxlan();
420  return (is_vni ? label_ : label_ >> 4);
421 }
422 
424 }
425 
427  : BgpAttribute(McastEdgeDiscovery, kFlags) {
428 }
429 
431  : BgpAttribute(rhs) {
432 }
433 
435  : BgpAttribute(BgpAttribute::McastEdgeDiscovery, kFlags) {
436  for (size_t i = 0; i < rhs.edge_list.size(); i++) {
437  Edge *edge = new Edge;
438  *edge = *rhs.edge_list[i];
439  edge_list.push_back(edge);
440  }
441 }
442 
445 }
446 
448  return Ip4Address(get_value(&address[0], 4));
449 }
450 
452  address.resize(4, 0);
453  const Ip4Address::bytes_type &addr_bytes = addr.to_bytes();
454  std::copy(addr_bytes.begin(), addr_bytes.begin() + 4, address.begin());
455 }
456 
458  uint32_t *first_label, uint32_t *last_label) const {
459  *first_label = labels[0];
460  *last_label = labels[1];
461 }
462 
464  uint32_t first_label, uint32_t last_label) {
465  labels.push_back(first_label);
466  labels.push_back(last_label);
467 }
468 
471  const EdgeDiscoverySpec::Edge *rhs) const {
472  KEY_COMPARE(lhs->address, rhs->address);
473  KEY_COMPARE(lhs->labels, rhs->labels);
474  return 0;
475  }
476 };
477 
478 int EdgeDiscoverySpec::CompareTo(const BgpAttribute &rhs_attr) const {
479  int ret = BgpAttribute::CompareTo(rhs_attr);
480  if (ret != 0) return ret;
481  const EdgeDiscoverySpec &rhs =
482  static_cast<const EdgeDiscoverySpec &>(rhs_attr);
483  ret = STLSortedCompare(edge_list.begin(), edge_list.end(),
484  rhs.edge_list.begin(), rhs.edge_list.end(),
486  return ret;
487 }
488 
490  attr->set_edge_discovery(this);
491 }
492 
494  std::ostringstream oss;
495  oss << "EdgeDiscovery <code: " << int(code);
496  oss << ", flags: 0x" << std::hex << int(flags) << std::dec << ">";
497  int idx = 0;
498  for (EdgeList::const_iterator it = edge_list.begin();
499  it != edge_list.end(); ++it, ++idx) {
500  const Edge *edge = *it;
501  uint32_t first_label, last_label;
502  edge->GetLabels(&first_label, &last_label);
503  oss << " Edge[" << idx << "] = (" << edge->GetIp4Address() << ", ";
504  oss << first_label << "-" << last_label << ")";
505  }
506 
507  return oss.str();
508 }
509 
511  size_t sz = 0;
512  for (EdgeList::const_iterator iter = edge_list.begin();
513  iter != edge_list.end(); ++iter) {
514  sz += 2; /* AddressLen + LabelLen */
515  sz += (*iter)->address.size();
516  sz += (*iter)->labels.size() * sizeof(uint32_t);
517  }
518  return sz;
519 }
520 
522  address = spec_edge->GetIp4Address();
523  uint32_t first_label, last_label;
524  spec_edge->GetLabels(&first_label, &last_label);
525  label_block = new LabelBlock(first_label, last_label);
526 }
527 
528 bool EdgeDiscovery::Edge::operator<(const Edge &rhs) const {
529  BOOL_KEY_COMPARE(address, rhs.address);
530  BOOL_KEY_COMPARE(label_block->first(), rhs.label_block->first());
531  BOOL_KEY_COMPARE(label_block->last(), rhs.label_block->last());
532  return false;
533 }
534 
536  const EdgeDiscoverySpec &edspec)
537  : edge_discovery_db_(edge_discovery_db),
538  edspec_(edspec) {
539  refcount_ = 0;
540  for (EdgeDiscoverySpec::EdgeList::const_iterator it =
541  edspec_.edge_list.begin(); it != edspec_.edge_list.end(); ++it) {
542  Edge *edge = new Edge(*it);
543  edge_list.push_back(edge);
544  }
545  sort(edge_list.begin(), edge_list.end(), EdgeDiscovery::EdgeCompare());
546 }
547 
550 }
551 
554  const EdgeDiscovery::Edge *rhs) const {
555  KEY_COMPARE(*lhs, *rhs);
556  return 0;
557  }
558 };
559 
561  int result = STLSortedCompare(edge_list.begin(), edge_list.end(),
562  rhs.edge_list.begin(), rhs.edge_list.end(),
564  return result;
565 }
566 
568  edge_discovery_db_->Delete(this);
569 }
570 
572 }
573 
575  : BgpAttribute(McastEdgeForwarding, kFlags) {
576 }
577 
579  : BgpAttribute(rhs) {
580 }
581 
583  : BgpAttribute(BgpAttribute::McastEdgeForwarding, kFlags) {
584  for (size_t i = 0; i < rhs.edge_list.size(); i++) {
585  Edge *edge = new Edge;
586  *edge = *rhs.edge_list[i];
587  edge_list.push_back(edge);
588  }
589 }
590 
593 }
594 
596  return Ip4Address(get_value(&inbound_address[0], 4));
597 }
598 
600  return Ip4Address(get_value(&outbound_address[0], 4));
601 }
602 
604  inbound_address.resize(4, 0);
605  const Ip4Address::bytes_type &addr_bytes = addr.to_bytes();
606  std::copy(addr_bytes.begin(), addr_bytes.begin() + 4,
607  inbound_address.begin());
608 }
609 
611  outbound_address.resize(4, 0);
612  const Ip4Address::bytes_type &addr_bytes = addr.to_bytes();
613  std::copy(addr_bytes.begin(), addr_bytes.begin() + 4,
614  outbound_address.begin());
615 }
616 
619  const EdgeForwardingSpec::Edge *rhs) const {
624  return 0;
625  }
626 };
627 
628 int EdgeForwardingSpec::CompareTo(const BgpAttribute &rhs_attr) const {
629  int ret = BgpAttribute::CompareTo(rhs_attr);
630  if (ret != 0) return ret;
631  const EdgeForwardingSpec &rhs =
632  static_cast<const EdgeForwardingSpec &>(rhs_attr);
633  ret = STLSortedCompare(edge_list.begin(), edge_list.end(),
634  rhs.edge_list.begin(), rhs.edge_list.end(),
636  return ret;
637 }
638 
640  attr->set_edge_forwarding(this);
641 }
642 
644  std::ostringstream oss;
645  oss << "EdgeForwarding <code: " << int(code);
646  oss << ", flags: 0x" << std::hex << int(flags) << std::dec << ">";
647  int idx = 0;
648  for (EdgeList::const_iterator it = edge_list.begin();
649  it != edge_list.end(); ++it, ++idx) {
650  const Edge *edge = *it;
651  oss << " Edge[" << idx << "] = (";
652  oss << "InAddress=" << edge->GetInboundIp4Address() << ", ";
653  oss << "InLabel=" << edge->inbound_label << ", ";
654  oss << "OutAddress=" << edge->GetOutboundIp4Address() << ", ";
655  oss << "OutLabel=" << edge->outbound_label << ")";
656  }
657 
658  return oss.str();
659 }
660 
662  size_t sz = 0;
663  for (EdgeList::const_iterator iter = edge_list.begin();
664  iter != edge_list.end(); ++iter) {
665  sz += 1 /* address len */ + 8 /* 2 labels */;
666  sz += (*iter)->inbound_address.size();
667  sz += (*iter)->outbound_address.size();
668  }
669 
670  return sz;
671 }
672 
674  inbound_address = spec_edge->GetInboundIp4Address();
675  outbound_address = spec_edge->GetOutboundIp4Address();
676  inbound_label = spec_edge->inbound_label;
677  outbound_label = spec_edge->outbound_label;
678 }
679 
680 bool EdgeForwarding::Edge::operator<(const Edge &rhs) const {
681  BOOL_KEY_COMPARE(inbound_address, rhs.inbound_address);
682  BOOL_KEY_COMPARE(outbound_address, rhs.outbound_address);
683  BOOL_KEY_COMPARE(inbound_label, rhs.inbound_label);
684  BOOL_KEY_COMPARE(outbound_label, rhs.outbound_label);
685  return false;
686 }
687 
689  const EdgeForwardingSpec &efspec)
690  : edge_forwarding_db_(edge_forwarding_db),
691  efspec_(efspec) {
692  refcount_ = 0;
693  for (EdgeForwardingSpec::EdgeList::const_iterator it =
694  efspec_.edge_list.begin(); it != efspec_.edge_list.end(); ++it) {
695  Edge *edge = new Edge(*it);
696  edge_list.push_back(edge);
697  }
698  sort(edge_list.begin(), edge_list.end(), EdgeForwarding::EdgeCompare());
699 }
700 
703 }
704 
707  const EdgeForwarding::Edge *rhs) const {
708  KEY_COMPARE(*lhs, *rhs);
709  return 0;
710  }
711 };
712 
714  int result = STLSortedCompare(edge_list.begin(), edge_list.end(),
715  rhs.edge_list.begin(), rhs.edge_list.end(),
717  return result;
718 }
719 
722 }
723 
725 }
726 
727 bool BgpOListElem::operator<(const BgpOListElem &rhs) const {
731  return false;
732 }
733 
734 int BgpOListSpec::CompareTo(const BgpAttribute &rhs_attr) const {
735  int ret = BgpAttribute::CompareTo(rhs_attr);
736  if (ret != 0) return ret;
737  return 0;
738 }
739 
741  if (subcode == BgpAttribute::OList) {
742  attr->set_olist(this);
743  } else if (subcode == BgpAttribute::LeafOList) {
744  attr->set_leaf_olist(this);
745  } else {
746  assert(false);
747  }
748 }
749 
750 string BgpOListSpec::ToString() const {
751  std::ostringstream oss;
752  oss << "OList <subcode: " << int(subcode) << ">";
753  int idx = 0;
754  for (Elements::const_iterator it = elements.begin();
755  it != elements.end(); ++it, ++idx) {
756  BgpOListElem elem(*it);
757  oss << "OList[" << idx << "] = (";
758  oss << "address: " << elem.address << ", ";
759  oss << "label: " << elem.label << ", ";
760  oss << "encap-list:";
761  int eid = 0;
762  for (vector<string>::const_iterator e_it = elem.encap.begin();
763  e_it != elem.encap.end(); ++e_it, ++eid) {
764  oss << " " << *e_it;
765  }
766  oss << ")";
767  }
768  return (oss.str());
769 }
770 
771 BgpOList::BgpOList(BgpOListDB *olist_db, const BgpOListSpec &olist_spec)
772  : olist_db_(olist_db),
773  olist_spec_(olist_spec) {
774  refcount_ = 0;
775  for (BgpOListSpec::Elements::const_iterator it =
776  olist_spec_.elements.begin(); it != olist_spec_.elements.end(); ++it) {
777  BgpOListElem *elem = new BgpOListElem(*it);
778  sort(elem->encap.begin(), elem->encap.end());
779  elements_.push_back(elem);
780  }
781  sort(elements_.begin(), elements_.end(), BgpOListElemCompare());
782 }
783 
786 }
787 
789  int operator()(const BgpOListElem *lhs, const BgpOListElem *rhs) const {
790  KEY_COMPARE(*lhs, *rhs);
791  return 0;
792  }
793 };
794 
795 int BgpOList::CompareTo(const BgpOList &rhs) const {
796  KEY_COMPARE(olist().subcode, rhs.olist().subcode);
797  int result = STLSortedCompare(elements().begin(), elements().end(),
798  rhs.elements().begin(), rhs.elements().end(),
800  return result;
801 }
802 
804  olist_db_->Delete(this);
805 }
806 
808 }
809 
810 int BgpAttrLabelBlock::CompareTo(const BgpAttribute &rhs_attr) const {
811  int ret = BgpAttribute::CompareTo(rhs_attr);
812  if (ret != 0) return ret;
813  KEY_COMPARE(label_block.get(),
814  static_cast<const BgpAttrLabelBlock &>(rhs_attr).label_block.get());
815  return 0;
816 }
817 
820 }
821 
823  char repr[80];
824  snprintf(repr, sizeof(repr), "LabelBlock <subcode: %d> : %d-%d",
825  subcode, label_block->first(), label_block->last());
826  return string(repr);
827 }
828 
829 int BgpAttrSourceRd::CompareTo(const BgpAttribute &rhs_attr) const {
830  int ret = BgpAttribute::CompareTo(rhs_attr);
831  if (ret != 0) return ret;
833  static_cast<const BgpAttrSourceRd &>(rhs_attr).source_rd);
834  return 0;
835 }
836 
838  attr->set_source_rd(source_rd);
839 }
840 
842  char repr[80];
843  snprintf(repr, sizeof(repr), "SourceRd <subcode: %d> : %s",
844  subcode, source_rd.ToString().c_str());
845  return string(repr);
846 }
847 
848 int BgpAttrEsi::CompareTo(const BgpAttribute &rhs_attr) const {
849  int ret = BgpAttribute::CompareTo(rhs_attr);
850  if (ret != 0) return ret;
851  KEY_COMPARE(esi, static_cast<const BgpAttrEsi &>(rhs_attr).esi);
852  return 0;
853 }
854 
856  attr->set_esi(esi);
857 }
858 
859 string BgpAttrEsi::ToString() const {
860  char repr[80];
861  snprintf(repr, sizeof(repr), "Esi <subcode: %d> : %s",
862  subcode, esi.ToString().c_str());
863  return string(repr);
864 }
865 
866 int BgpAttrParams::CompareTo(const BgpAttribute &rhs_attr) const {
867  int ret = BgpAttribute::CompareTo(rhs_attr);
868  if (ret != 0) return ret;
869  KEY_COMPARE(params, static_cast<const BgpAttrParams &>(rhs_attr).params);
870  return 0;
871 }
872 
874  attr->set_params(params);
875 }
876 
877 string BgpAttrParams::ToString() const {
878  char repr[80];
879  snprintf(repr, sizeof(repr), "Params <subcode: %d> : 0x%016jx",
880  subcode, params);
881  return string(repr);
882 }
883 
884 int BgpAttrSubProtocol::CompareTo(const BgpAttribute &rhs_attr) const {
885  int ret = BgpAttribute::CompareTo(rhs_attr);
886  if (ret != 0) return ret;
887  KEY_COMPARE(sbp, static_cast<const BgpAttrSubProtocol &>(rhs_attr).sbp);
888  return 0;
889 }
890 
892  attr->set_sub_protocol(sbp);
893 }
894 
896  char repr[80];
897  snprintf(repr, sizeof(repr), "SubProtocol <subcode: %d> : %s",
898  subcode, sbp.c_str());
899  return string(repr);
900 }
901 
903  : attr_db_(NULL), origin_(BgpAttrOrigin::INCOMPLETE), nexthop_(),
904  med_(0), local_pref_(0), atomic_aggregate_(false),
905  aggregator_as_num_(0), aggregator_as4_num_(0), params_(0) {
906  refcount_ = 0;
907 }
908 
910  : attr_db_(attr_db), origin_(BgpAttrOrigin::INCOMPLETE),
911  nexthop_(), med_(0), local_pref_(0), atomic_aggregate_(false),
912  aggregator_as_num_(0), aggregator_as4_num_(0), params_(0) {
913  refcount_ = 0;
914 }
915 
916 BgpAttr::BgpAttr(BgpAttrDB *attr_db, const BgpAttrSpec &spec)
917  : attr_db_(attr_db), origin_(BgpAttrOrigin::INCOMPLETE),
918  nexthop_(), med_(0),
919  local_pref_(BgpAttrLocalPref::kDefault),
920  atomic_aggregate_(false),
921  aggregator_as_num_(0), aggregator_as4_num_(0),
922  aggregator_address_(), params_(0) {
923  refcount_ = 0;
924  for (vector<BgpAttribute *>::const_iterator it = spec.begin();
925  it < spec.end(); it++) {
926  (*it)->ToCanonical(this);
927  }
928 }
929 
931  : attr_db_(rhs.attr_db_), origin_(rhs.origin_), nexthop_(rhs.nexthop_),
932  med_(rhs.med_), local_pref_(rhs.local_pref_),
933  atomic_aggregate_(rhs.atomic_aggregate_),
934  aggregator_as_num_(rhs.aggregator_as_num_),
935  aggregator_as4_num_(rhs.aggregator_as4_num_),
936  aggregator_address_(rhs.aggregator_address_),
937  originator_id_(rhs.originator_id_),
938  source_rd_(rhs.source_rd_), esi_(rhs.esi_), params_(rhs.params_),
939  as_path_(rhs.as_path_),
940  aspath_4byte_(rhs.aspath_4byte_),
941  as4_path_(rhs.as4_path_),
942  cluster_list_(rhs.cluster_list_),
943  community_(rhs.community_),
944  ext_community_(rhs.ext_community_),
945  large_community_(rhs.large_community_),
946  deferred_large_spec_(nullptr),
947  origin_vn_path_(rhs.origin_vn_path_),
948  pmsi_tunnel_(rhs.pmsi_tunnel_),
949  edge_discovery_(rhs.edge_discovery_),
950  edge_forwarding_(rhs.edge_forwarding_),
951  label_block_(rhs.label_block_),
952  olist_(rhs.olist_),
953  leaf_olist_(rhs.leaf_olist_),
954  sub_protocol_(rhs.sub_protocol_) {
955  refcount_ = 0;
956 }
957 
959  as_path_ = aspath;
960 }
961 
962 void BgpAttr::set_as_path(const AsPathSpec *spec) {
963  if (spec) {
964  as_path_ = attr_db_->server()->aspath_db()->Locate(*spec);
965  } else {
966  as_path_ = NULL;
967  }
968 }
969 
971  as4_path_ = aspath;
972 }
973 
975  if (spec) {
976  as4_path_ = attr_db_->server()->as4path_db()->Locate(*spec);
977  } else {
978  as4_path_ = NULL;
979  }
980 }
981 
983  aspath_4byte_ = aspath;
984 }
985 
987  if (spec) {
989  } else {
990  aspath_4byte_ = NULL;
991  }
992 }
993 
995  if (spec) {
997  } else {
998  cluster_list_ = NULL;
999  }
1000 }
1001 
1003  community_ = comm;
1004 }
1005 
1007  if (comm) {
1008  community_ = attr_db_->server()->comm_db()->Locate(*comm);
1009  } else {
1010  community_ = NULL;
1011  }
1012 }
1013 
1015  ext_community_ = extcomm;
1016 }
1017 
1019  if (extcomm) {
1020  LargeCommunitySpec large_spec = LargeCommunitySpec::FromTag(*extcomm);
1021  set_large_community(&large_spec);
1022 
1023  if (large_spec.communities.size()) {
1024  ExtCommunitySpec new_comms =
1026  ext_community_ =
1027  attr_db_->server()->extcomm_db()->Locate(new_comms);
1028  return;
1029  }
1030  ext_community_ = attr_db_->server()->extcomm_db()->Locate(*extcomm);
1031  } else {
1032  ext_community_ = NULL;
1033  }
1034 }
1035 
1037  large_community_ = largecomm;
1038 }
1039 
1041  if (largecomm) {
1042  if (!bool(deferred_large_spec_)) {
1044  deferred_large_spec_->communities = largecomm->communities;
1045  } else {
1046  deferred_large_spec_->communities.insert(
1047  deferred_large_spec_->communities.end(),
1048  largecomm->communities.begin(),
1049  largecomm->communities.end());
1050  }
1053  } else {
1054  large_community_ = NULL;
1055  }
1056 }
1057 
1059  origin_vn_path_ = ovnpath;
1060 }
1061 
1063  if (spec) {
1065  } else {
1066  origin_vn_path_ = NULL;
1067  }
1068 }
1069 
1071  if (pmsi_spec) {
1072  pmsi_tunnel_ = attr_db_->server()->pmsi_tunnel_db()->Locate(*pmsi_spec);
1073  } else {
1074  pmsi_tunnel_ = NULL;
1075  }
1076 }
1077 
1079  if (edspec) {
1080  edge_discovery_ =
1081  attr_db_->server()->edge_discovery_db()->Locate(*edspec);
1082  } else {
1083  edge_discovery_ = NULL;
1084  }
1085 }
1086 
1088  if (efspec) {
1090  attr_db_->server()->edge_forwarding_db()->Locate(*efspec);
1091  } else {
1092  edge_forwarding_ = NULL;
1093  }
1094 }
1095 
1098 }
1099 
1100 void BgpAttr::set_olist(const BgpOListSpec *olist_spec) {
1101  if (olist_spec) {
1102  olist_ = attr_db_->server()->olist_db()->Locate(*olist_spec);
1103  } else {
1104  olist_ = NULL;
1105  }
1106 }
1107 
1108 void BgpAttr::set_leaf_olist(const BgpOListSpec *leaf_olist_spec) {
1109  if (leaf_olist_spec) {
1110  leaf_olist_ = attr_db_->server()->olist_db()->Locate(*leaf_olist_spec);
1111  } else {
1112  leaf_olist_ = NULL;
1113  }
1114 }
1115 
1117  int as_count = as_path_count();
1118  int as4_count = aspath_4byte_count();
1119  return as_count > as4_count ? as_count : as4_count;
1120 }
1121 
1123  if (as_path_ && !as_path_->empty())
1124  return false;
1125  if (aspath_4byte_ && !aspath_4byte_->empty())
1126  return false;
1127  return true;
1128 }
1129 
1131  switch (origin) {
1132  case BgpAttrOrigin::IGP:
1133  return "igp";
1134  break;
1135  case BgpAttrOrigin::EGP:
1136  return "egp";
1137  break;
1139  return "incomplete";
1140  break;
1141  }
1142  return "unknown";
1143 }
1144 
1146  const string &bgp_origin_type) {
1147  if(bgp_origin_type == "IGP"){
1148  return BgpAttrOrigin::IGP;
1149  } else if( bgp_origin_type == "EGP") {
1150  return BgpAttrOrigin::EGP;
1151  }
1153 }
1154 
1155 string BgpAttr::origin_string() const {
1156  return OriginToString(origin());
1157 }
1158 
1160  if (nexthop_.is_v6()) {
1161  return Address::INET6;
1162  } else {
1163  return Address::INET;
1164  }
1165 }
1166 
1168  if (as_path_.get())
1169  return as_path_->neighbor_as();
1170  if (aspath_4byte_.get())
1171  return aspath_4byte_->neighbor_as();
1172  return 0;
1173 }
1174 
1175 uint32_t BgpAttr::sequence_number() const {
1176  if (!ext_community_)
1177  return 0;
1178  for (ExtCommunity::ExtCommunityList::const_iterator it =
1179  ext_community_->communities().begin();
1180  it != ext_community_->communities().end(); ++it) {
1181  if (ExtCommunity::is_mac_mobility(*it)) {
1182  MacMobility mm(*it);
1183  return mm.sequence_number();
1184  }
1185  }
1186  return 0;
1187 }
1188 
1190  if (!ext_community_)
1191  return 0;
1192  for (ExtCommunity::ExtCommunityList::const_iterator it =
1193  ext_community_->communities().begin();
1194  it != ext_community_->communities().end(); ++it) {
1195  if (ExtCommunity::is_mac_mobility(*it)) {
1196  MacMobility mm(*it);
1197  return mm.sticky();
1198  }
1199  }
1200  return 0;
1201 }
1202 
1203 bool BgpAttr::etree_leaf() const {
1204  if (!ext_community_)
1205  return 0;
1206  for (ExtCommunity::ExtCommunityList::const_iterator it =
1207  ext_community_->communities().begin();
1208  it != ext_community_->communities().end(); ++it) {
1209  if (ExtCommunity::is_etree(*it)) {
1210  ETree etree(*it);
1211  return etree.leaf();
1212  }
1213  }
1214  return 0;
1215 }
1216 
1218  if (!ext_community_)
1219  return false;
1220  for (ExtCommunity::ExtCommunityList::const_iterator it =
1221  ext_community_->communities().begin();
1222  it != ext_community_->communities().end(); ++it) {
1223  if (ExtCommunity::is_esi_label(*it)) {
1224  EsiLabel esi_label(*it);
1225  return esi_label.single_active();
1226  }
1227  }
1228  return true;
1229 }
1230 
1232  if (!ext_community_)
1233  return MacAddress::kZeroMac;
1234  for (ExtCommunity::ExtCommunityList::const_iterator it =
1235  ext_community_->communities().begin();
1236  it != ext_community_->communities().end(); ++it) {
1237  if (ExtCommunity::is_router_mac(*it)) {
1238  RouterMac router_mac(*it);
1239  return router_mac.mac_address();
1240  }
1241  }
1242  return MacAddress::kZeroMac;
1243 }
1244 
1246  attr_db_->Delete(this);
1247 }
1248 
1249 int BgpAttr::IsAsPathLoop(as_t asn, uint8_t max_loop_count) const {
1250  if (as_path() && as_path()->path().AsPathLoop(asn, max_loop_count)) {
1251  return true;
1252  }
1253  if (aspath_4byte() &&
1254  aspath_4byte()->path().AsPathLoop(asn, max_loop_count)) {
1255  return true;
1256  }
1257  if (asn > AS2_MAX && as4_path() &&
1258  as4_path()->path().AsPathLoop(asn, max_loop_count)) {
1259  return true;
1260  }
1261  return false;
1262 }
1263 
1264 int BgpAttr::CompareTo(const BgpAttr &rhs) const {
1265  KEY_COMPARE(origin_, rhs.origin_);
1267  KEY_COMPARE(med_, rhs.med_);
1274  KEY_COMPARE(pmsi_tunnel_.get(), rhs.pmsi_tunnel_.get());
1275  KEY_COMPARE(edge_discovery_.get(), rhs.edge_discovery_.get());
1276  KEY_COMPARE(edge_forwarding_.get(), rhs.edge_forwarding_.get());
1277  KEY_COMPARE(esi_, rhs.esi_);
1278  KEY_COMPARE(params_, rhs.params_);
1280  KEY_COMPARE(label_block_.get(), rhs.label_block_.get());
1281  KEY_COMPARE(olist_.get(), rhs.olist_.get());
1282  KEY_COMPARE(leaf_olist_.get(), rhs.leaf_olist_.get());
1283  KEY_COMPARE(as_path_.get(), rhs.as_path_.get());
1284  KEY_COMPARE(aspath_4byte_.get(), rhs.aspath_4byte_.get());
1285  KEY_COMPARE(as4_path_.get(), rhs.as4_path_.get());
1286  KEY_COMPARE(cluster_list_.get(), rhs.cluster_list_.get());
1287  KEY_COMPARE(community_.get(), rhs.community_.get());
1288  KEY_COMPARE(ext_community_.get(), rhs.ext_community_.get());
1289  KEY_COMPARE(large_community_.get(), rhs.large_community_.get());
1290  KEY_COMPARE(origin_vn_path_.get(), rhs.origin_vn_path_.get());
1292  return 0;
1293 }
1294 
1295 std::size_t hash_value(BgpAttr const &attr) {
1296  size_t hash = 0;
1297 
1298  boost::hash_combine(hash, attr.origin_);
1299  boost::hash_combine(hash, attr.nexthop_.to_string());
1300  boost::hash_combine(hash, attr.med_);
1301  boost::hash_combine(hash, attr.local_pref_);
1302  boost::hash_combine(hash, attr.atomic_aggregate_);
1303  boost::hash_combine(hash, attr.aggregator_as_num_);
1304  boost::hash_combine(hash, attr.aggregator_as4_num_);
1305  boost::hash_combine(hash, attr.aggregator_address_.to_string());
1306  boost::hash_combine(hash, attr.originator_id_.to_string());
1307  boost::hash_combine(hash, attr.params_);
1308  boost::hash_combine(hash, attr.source_rd_.ToString());
1309  boost::hash_combine(hash, attr.esi_.ToString());
1310 
1311  if (attr.label_block_) {
1312  boost::hash_combine(hash, attr.label_block_->first());
1313  boost::hash_combine(hash, attr.label_block_->last());
1314  }
1315 
1316  if (attr.olist_) {
1317  boost::hash_range(hash, attr.olist_->elements().begin(),
1318  attr.olist_->elements().end());
1319  }
1320  if (attr.leaf_olist_) {
1321  boost::hash_range(hash, attr.leaf_olist_->elements().begin(),
1322  attr.leaf_olist_->elements().end());
1323  }
1324 
1325  if (attr.as_path_) boost::hash_combine(hash, *attr.as_path_);
1326  if (attr.aspath_4byte_) boost::hash_combine(hash, *attr.aspath_4byte_);
1327  if (attr.as4_path_) boost::hash_combine(hash, *attr.as4_path_);
1328  if (attr.community_) boost::hash_combine(hash, *attr.community_);
1329  if (attr.ext_community_) boost::hash_combine(hash, *attr.ext_community_);
1330  if (attr.large_community_) boost::hash_combine(hash, *attr.large_community_);
1331  if (attr.origin_vn_path_) boost::hash_combine(hash, *attr.origin_vn_path_);
1332  if (!attr.sub_protocol_.empty()) {
1333  boost::hash_combine(hash, attr.sub_protocol_);
1334  }
1335 
1336  return hash;
1337 }
1338 
1339 BgpAttrDB::BgpAttrDB(BgpServer *server) : server_(server) {
1340 }
1341 
1342 // Return a clone of attribute with updated aspath.
1344  AsPathPtr aspath) {
1345  BgpAttr *clone = new BgpAttr(*attr);
1346  clone->set_as_path(aspath);
1347  return Locate(clone);
1348 }
1349 
1350 // Return a clone of attribute with updated community.
1352  CommunityPtr community) {
1353  BgpAttr *clone = new BgpAttr(*attr);
1354  clone->set_community(community);
1355  return Locate(clone);
1356 }
1357 
1358 //Return a clone of attribute with updated origin
1360  BgpAttrOrigin::OriginType origin) {
1361  BgpAttr *clone = new BgpAttr(*attr);
1362  clone->set_origin(origin);
1363  return Locate(clone);
1364 }
1365 
1366 // Return a clone of attribute with updated extended community.
1368  ExtCommunityPtr extcomm) {
1369  BgpAttr *clone = new BgpAttr(*attr);
1370  clone->set_ext_community(extcomm);
1371  return Locate(clone);
1372 }
1373 
1374 // Return a clone of attribute with updated large community.
1376  const BgpAttr *attr, LargeCommunityPtr largecomm) {
1377  BgpAttr *clone = new BgpAttr(*attr);
1378  clone->set_large_community(largecomm);
1379  return Locate(clone);
1380 }
1381 
1382 // Return a clone of attribute with updated origin vn path.
1384  OriginVnPathPtr ovnpath) {
1385  BgpAttr *clone = new BgpAttr(*attr);
1386  clone->set_origin_vn_path(ovnpath);
1387  return Locate(clone);
1388 }
1389 
1390 // Return a clone of attribute with updated local preference.
1392  uint32_t local_pref) {
1393  BgpAttr *clone = new BgpAttr(*attr);
1394  clone->set_local_pref(local_pref);
1395  return Locate(clone);
1396 }
1397 
1398 // Return a clone of attribute with updated originator id.
1400  Ip4Address originator_id) {
1401  BgpAttr *clone = new BgpAttr(*attr);
1402  clone->set_originator_id(originator_id);
1403  return Locate(clone);
1404 }
1405 
1406 // Return a clone of attribute with updated source rd.
1408  const RouteDistinguisher &source_rd) {
1409  BgpAttr *clone = new BgpAttr(*attr);
1410  clone->set_source_rd(source_rd);
1411  return Locate(clone);
1412 }
1413 
1414 // Return a clone of attribute with updated esi.
1416  const EthernetSegmentId &esi) {
1417  BgpAttr *clone = new BgpAttr(*attr);
1418  clone->set_esi(esi);
1419  return Locate(clone);
1420 }
1421 
1422 // Return a clone of attribute with updated olist.
1424  const BgpOListSpec *olist_spec) {
1425  assert(olist_spec->subcode == BgpAttribute::OList);
1426  BgpAttr *clone = new BgpAttr(*attr);
1427  clone->set_olist(olist_spec);
1428  return Locate(clone);
1429 }
1430 
1431 // Return a clone of attribute with updated leaf olist.
1433  const BgpOListSpec *leaf_olist_spec) {
1434  assert(leaf_olist_spec->subcode == BgpAttribute::LeafOList);
1435  BgpAttr *clone = new BgpAttr(*attr);
1436  clone->set_leaf_olist(leaf_olist_spec);
1437  return Locate(clone);
1438 }
1439 
1440 // Return a clone of attribute with updated sub-protocol.
1442  const string &sbp) {
1443  BgpAttr *clone = new BgpAttr(*attr);
1444  clone->set_sub_protocol(sbp);
1445  return Locate(clone);
1446 }
1447 
1448 
1449 // Return a clone of attribute with updated pmsi tunnel.
1451  const PmsiTunnelSpec *pmsi_spec) {
1452  BgpAttr *clone = new BgpAttr(*attr);
1453  clone->set_pmsi_tunnel(pmsi_spec);
1454  return Locate(clone);
1455 }
1456 
1457 // Return a clone of attribute with updated nexthop.
1459  const IpAddress &addr) {
1460  BgpAttr *clone = new BgpAttr(*attr);
1461  clone->set_nexthop(addr);
1462  return Locate(clone);
1463 }
boost::asio::ip::address IpAddress
Definition: address.h:14
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
boost::intrusive_ptr< const AsPath4Byte > AsPath4BytePtr
Definition: bgp_aspath.h:324
boost::intrusive_ptr< const As4Path > As4PathPtr
Definition: bgp_aspath.h:482
boost::intrusive_ptr< const AsPath > AsPathPtr
Definition: bgp_aspath.h:166
std::size_t hash_value(BgpAttr const &attr)
Definition: bgp_attr.cc:1295
std::vector< BgpAttribute * > BgpAttrSpec
Definition: bgp_attr.h:823
boost::intrusive_ptr< const BgpAttr > BgpAttrPtr
Definition: bgp_attr.h:999
#define AS2_MAX
Definition: bgp_common.h:25
uint32_t as_t
Definition: bgp_common.h:22
boost::intrusive_ptr< const OriginVnPath > OriginVnPathPtr
Family
Definition: address.h:25
@ INET
Definition: address.h:27
@ INET6
Definition: address.h:28
@ ErmVpn
Definition: bgp_af.h:34
@ EVpn
Definition: bgp_af.h:29
@ L2Vpn
Definition: bgp_af.h:22
BgpAttrPtr ReplaceOriginatorIdAndLocate(const BgpAttr *attr, Ip4Address originator_id)
Definition: bgp_attr.cc:1399
BgpAttrDB(BgpServer *server)
Definition: bgp_attr.cc:1339
BgpAttrPtr ReplaceLocalPreferenceAndLocate(const BgpAttr *attr, uint32_t local_pref)
Definition: bgp_attr.cc:1391
BgpAttrPtr ReplaceOListAndLocate(const BgpAttr *attr, const BgpOListSpec *olist_spec)
Definition: bgp_attr.cc:1423
BgpAttrPtr ReplaceNexthopAndLocate(const BgpAttr *attr, const IpAddress &addr)
Definition: bgp_attr.cc:1458
BgpAttrPtr ReplaceLeafOListAndLocate(const BgpAttr *attr, const BgpOListSpec *leaf_olist_spec)
Definition: bgp_attr.cc:1432
BgpAttrPtr ReplaceSubProtocolAndLocate(const BgpAttr *attr, const std::string &sbp)
Definition: bgp_attr.cc:1441
BgpAttrPtr ReplaceAsPathAndLocate(const BgpAttr *attr, AsPathPtr aspath)
Definition: bgp_attr.cc:1343
BgpAttrPtr ReplaceOriginAndLocate(const BgpAttr *attr, BgpAttrOrigin::OriginType origin)
Definition: bgp_attr.cc:1359
BgpAttrPtr ReplacePmsiTunnelAndLocate(const BgpAttr *attr, const PmsiTunnelSpec *pmsi_spec)
Definition: bgp_attr.cc:1450
BgpServer * server()
Definition: bgp_attr.h:1041
BgpAttrPtr ReplaceExtCommunityAndLocate(const BgpAttr *attr, ExtCommunityPtr extcomm)
Definition: bgp_attr.cc:1367
BgpAttrPtr ReplaceSourceRdAndLocate(const BgpAttr *attr, const RouteDistinguisher &source_rd)
Definition: bgp_attr.cc:1407
BgpAttrPtr ReplaceOriginVnPathAndLocate(const BgpAttr *attr, OriginVnPathPtr ovnpath)
Definition: bgp_attr.cc:1383
BgpAttrPtr ReplaceLargeCommunityAndLocate(const BgpAttr *attr, LargeCommunityPtr largecomm)
Definition: bgp_attr.cc:1375
BgpAttrPtr ReplaceEsiAndLocate(const BgpAttr *attr, const EthernetSegmentId &esi)
Definition: bgp_attr.cc:1415
BgpAttrPtr ReplaceCommunityAndLocate(const BgpAttr *attr, CommunityPtr community)
Definition: bgp_attr.cc:1351
void set_sub_protocol(const std::string &sub_protocol)
Definition: bgp_attr.h:879
as_t aggregator_as_num_
Definition: bgp_attr.h:956
std::unique_ptr< LargeCommunitySpec > deferred_large_spec_
Definition: bgp_attr.h:970
BgpOListPtr olist_
Definition: bgp_attr.h:976
Ip4Address originator_id_
Definition: bgp_attr.h:959
void set_aspath_4byte(AsPath4BytePtr aspath)
Definition: bgp_attr.cc:982
const AsPath * as_path() const
Definition: bgp_attr.h:902
int as_path_count() const
Definition: bgp_attr.h:903
BgpOListPtr leaf_olist_
Definition: bgp_attr.h:977
void set_source_rd(const RouteDistinguisher &source_rd)
Definition: bgp_attr.h:853
MacAddress mac_address() const
Definition: bgp_attr.cc:1231
void set_community(CommunityPtr comm)
Definition: bgp_attr.cc:1002
static BgpAttrOrigin::OriginType OriginFromString(const std::string &bgp_origin_type)
Definition: bgp_attr.cc:1145
void set_params(uint64_t params)
Definition: bgp_attr.h:857
as_t aggregator_as4_num_
Definition: bgp_attr.h:957
bool IsAsPathEmpty() const
Definition: bgp_attr.cc:1122
EthernetSegmentId esi_
Definition: bgp_attr.h:961
void set_leaf_olist(const BgpOListSpec *leaf_olist_spec)
Definition: bgp_attr.cc:1108
std::atomic< int > refcount_
Definition: bgp_attr.h:949
uint32_t med_
Definition: bgp_attr.h:953
void set_esi(const EthernetSegmentId &esi)
Definition: bgp_attr.h:856
IpAddress aggregator_address_
Definition: bgp_attr.h:958
AsPathPtr as_path_
Definition: bgp_attr.h:963
static std::string OriginToString(BgpAttrOrigin::OriginType origin)
Definition: bgp_attr.cc:1130
RouteDistinguisher source_rd_
Definition: bgp_attr.h:960
as_t neighbor_as() const
Definition: bgp_attr.cc:1167
std::string origin_string() const
Definition: bgp_attr.cc:1155
void set_edge_discovery(const EdgeDiscoverySpec *edspec)
Definition: bgp_attr.cc:1078
void set_large_community(LargeCommunityPtr largecomm)
Definition: bgp_attr.cc:1036
void set_as_path(AsPathPtr aspath)
Definition: bgp_attr.cc:958
uint64_t params_
Definition: bgp_attr.h:962
void set_atomic_aggregate(bool ae)
Definition: bgp_attr.h:841
OriginVnPathPtr origin_vn_path_
Definition: bgp_attr.h:971
ExtCommunityPtr ext_community_
Definition: bgp_attr.h:968
void set_med(uint32_t med)
Definition: bgp_attr.h:839
void set_as4_path(As4PathPtr aspath)
Definition: bgp_attr.cc:970
void set_origin_vn_path(OriginVnPathPtr ovnpath)
Definition: bgp_attr.cc:1058
BgpAttrOrigin::OriginType origin_
Definition: bgp_attr.h:951
void set_edge_forwarding(const EdgeForwardingSpec *efspec)
Definition: bgp_attr.cc:1087
EdgeForwardingPtr edge_forwarding_
Definition: bgp_attr.h:974
IpAddress nexthop_
Definition: bgp_attr.h:952
int IsAsPathLoop(as_t asn, uint8_t max_loop_count=0) const
Definition: bgp_attr.cc:1249
EdgeDiscoveryPtr edge_discovery_
Definition: bgp_attr.h:973
LabelBlockPtr label_block() const
Definition: bgp_attr.h:930
void set_local_pref(uint32_t local_pref)
Definition: bgp_attr.h:840
LabelBlockPtr label_block_
Definition: bgp_attr.h:975
bool evpn_sticky_mac() const
Definition: bgp_attr.cc:1189
ClusterListPtr cluster_list_
Definition: bgp_attr.h:966
uint32_t sequence_number() const
Definition: bgp_attr.cc:1175
BgpAttr()
Definition: bgp_attr.cc:902
void set_origin(BgpAttrOrigin::OriginType org)
Definition: bgp_attr.h:837
void set_as4_aggregator(as_t as_num, IpAddress address)
Definition: bgp_attr.h:846
void set_cluster_list(const ClusterListSpec *spec)
Definition: bgp_attr.cc:994
AsPath4BytePtr aspath_4byte_
Definition: bgp_attr.h:964
BgpAttrDB * attr_db_
Definition: bgp_attr.h:950
void set_aggregator(as_t as_num, IpAddress address)
Definition: bgp_attr.h:842
void set_nexthop(IpAddress nexthop)
Definition: bgp_attr.h:838
int aspath_4byte_count() const
Definition: bgp_attr.h:906
void set_label_block(LabelBlockPtr label_block)
Definition: bgp_attr.cc:1096
std::string sub_protocol_
Definition: bgp_attr.h:978
bool evpn_single_active() const
Definition: bgp_attr.cc:1217
int CompareTo(const BgpAttr &rhs) const
Definition: bgp_attr.cc:1264
Address::Family nexthop_family() const
Definition: bgp_attr.cc:1159
const AsPath4Byte * aspath_4byte() const
Definition: bgp_attr.h:905
As4PathPtr as4_path_
Definition: bgp_attr.h:965
PmsiTunnelPtr pmsi_tunnel_
Definition: bgp_attr.h:972
virtual void Remove()
Definition: bgp_attr.cc:1245
void set_ext_community(ExtCommunityPtr extcomm)
Definition: bgp_attr.cc:1014
bool atomic_aggregate_
Definition: bgp_attr.h:955
BgpAttrOrigin::OriginType origin() const
Definition: bgp_attr.h:884
void set_originator_id(Ip4Address originator_id)
Definition: bgp_attr.h:850
CommunityPtr community_
Definition: bgp_attr.h:967
LargeCommunityPtr large_community_
Definition: bgp_attr.h:969
int max_as_path_count() const
Definition: bgp_attr.cc:1116
bool etree_leaf() const
Definition: bgp_attr.cc:1203
const As4Path * as4_path() const
Definition: bgp_attr.h:914
void set_olist(const BgpOListSpec *olist_spec)
Definition: bgp_attr.cc:1100
uint32_t local_pref_
Definition: bgp_attr.h:954
void set_pmsi_tunnel(const PmsiTunnelSpec *pmsi_spec)
Definition: bgp_attr.cc:1070
uint8_t subcode
Definition: bgp_attr_base.h:71
uint8_t flags
Definition: bgp_attr_base.h:72
virtual int CompareTo(const BgpAttribute &rhs) const
uint8_t code
Definition: bgp_attr_base.h:70
BgpOListDB(BgpServer *server)
Definition: bgp_attr.cc:807
bool operator<(const BgpOListElem &rhs) const
Definition: bgp_attr.cc:727
Ip4Address address
Definition: bgp_attr.h:673
std::vector< std::string > encap
Definition: bgp_attr.h:675
uint32_t label
Definition: bgp_attr.h:674
virtual void Remove()
Definition: bgp_attr.cc:803
Elements elements_
Definition: bgp_attr.h:723
const BgpOListSpec & olist() const
Definition: bgp_attr.h:705
BgpOList(BgpOListDB *olist_db, const BgpOListSpec &olist_spec)
Definition: bgp_attr.cc:771
BgpOListSpec olist_spec_
Definition: bgp_attr.h:726
BgpOListDB * olist_db_
Definition: bgp_attr.h:725
const Elements & elements() const
Definition: bgp_attr.h:715
std::atomic< int > refcount_
Definition: bgp_attr.h:724
virtual ~BgpOList()
Definition: bgp_attr.cc:784
int CompareTo(const BgpOList &rhs) const
Definition: bgp_attr.cc:795
void Delete(Type *attr)
TypePtr Locate(Type *attr)
ExtCommunityDB * extcomm_db()
Definition: bgp_server.h:194
AsPathDB * aspath_db()
Definition: bgp_server.h:185
As4PathDB * as4path_db()
Definition: bgp_server.h:187
EdgeDiscoveryDB * edge_discovery_db()
Definition: bgp_server.h:192
AsPath4ByteDB * aspath_4byte_db()
Definition: bgp_server.h:186
PmsiTunnelDB * pmsi_tunnel_db()
Definition: bgp_server.h:197
EdgeForwardingDB * edge_forwarding_db()
Definition: bgp_server.h:193
OriginVnPathDB * ovnpath_db()
Definition: bgp_server.h:196
CommunityDB * comm_db()
Definition: bgp_server.h:191
LargeCommunityDB * largecomm_db()
Definition: bgp_server.h:195
ClusterListDB * cluster_list_db()
Definition: bgp_server.h:190
BgpOListDB * olist_db()
Definition: bgp_server.h:189
ClusterListDB(BgpServer *server)
Definition: bgp_attr.cc:244
std::atomic< int > refcount_
Definition: bgp_attr.h:244
ClusterListDB * cluster_list_db_
Definition: bgp_attr.h:245
ClusterList(ClusterListDB *cluster_list_db, const ClusterListSpec &spec)
Definition: bgp_attr.cc:233
void Remove()
Definition: bgp_attr.cc:240
Definition: etree.h:17
bool leaf() const
Definition: etree.cc:30
EdgeDiscoveryDB(BgpServer *server)
Definition: bgp_attr.cc:571
EdgeDiscoveryDB * edge_discovery_db_
Definition: bgp_attr.h:503
EdgeDiscovery(EdgeDiscoveryDB *edge_discovery_db, const EdgeDiscoverySpec &edspec)
Definition: bgp_attr.cc:535
EdgeList edge_list
Definition: bgp_attr.h:494
virtual void Remove()
Definition: bgp_attr.cc:567
virtual ~EdgeDiscovery()
Definition: bgp_attr.cc:548
std::atomic< int > refcount_
Definition: bgp_attr.h:502
EdgeDiscoverySpec edspec_
Definition: bgp_attr.h:504
int CompareTo(const EdgeDiscovery &rhs) const
Definition: bgp_attr.cc:560
EdgeForwardingDB(BgpServer *server)
Definition: bgp_attr.cc:724
virtual ~EdgeForwarding()
Definition: bgp_attr.cc:701
EdgeForwarding(EdgeForwardingDB *edge_forwarding_db, const EdgeForwardingSpec &efspec)
Definition: bgp_attr.cc:688
int CompareTo(const EdgeForwarding &rhs) const
Definition: bgp_attr.cc:713
std::atomic< int > refcount_
Definition: bgp_attr.h:609
EdgeList edge_list
Definition: bgp_attr.h:601
EdgeForwardingSpec efspec_
Definition: bgp_attr.h:611
virtual void Remove()
Definition: bgp_attr.cc:720
EdgeForwardingDB * edge_forwarding_db_
Definition: bgp_attr.h:610
bool single_active() const
Definition: esi_label.h:25
std::string ToString() const
Definition: esi.cc:121
static bool is_router_mac(const ExtCommunityValue &val)
Definition: community.h:260
static bool is_esi_label(const ExtCommunityValue &val)
Definition: community.h:222
static bool is_mac_mobility(const ExtCommunityValue &val)
Definition: community.h:230
static bool is_etree(const ExtCommunityValue &val)
Definition: community.h:243
bool ContainsTunnelEncapVxlan() const
Definition: community.cc:725
This class encapsulates the wire-format representation of a BGP Large Community attribute and provide...
Definition: community.h:509
static ExtCommunitySpec RemoveTags(const ExtCommunitySpec &ex_spec)
Removes extended communities corresponding to tags from the given ExtCommunitySpec.
Definition: community.cc:249
static LargeCommunitySpec FromTag(const ExtCommunitySpec &ex_spec)
Constructs an instance from an Extened Community specification by distributing its bits inside a new ...
Definition: community.cc:200
std::vector< uint32_t > communities
Vector of community values. Each Large Community value consists of three 4-byte fields (12 bytes tota...
Definition: community.h:541
static const MacAddress kZeroMac
Definition: mac_address.h:150
bool sticky() const
Definition: mac_mobility.cc:29
uint32_t sequence_number() const
Definition: mac_mobility.cc:33
PmsiTunnelDB(BgpServer *server)
Definition: bgp_attr.cc:423
uint8_t tunnel_type_
Definition: bgp_attr.h:395
PmsiTunnel(PmsiTunnelDB *pmsi_tunnel_db, const PmsiTunnelSpec &pmsi_spec)
Definition: bgp_attr.cc:401
uint8_t tunnel_flags_
Definition: bgp_attr.h:394
uint32_t GetLabel(const ExtCommunity *ext) const
Definition: bgp_attr.cc:416
std::atomic< int > refcount_
Definition: bgp_attr.h:398
Ip4Address identifier_
Definition: bgp_attr.h:396
PmsiTunnelSpec pmsi_spec_
Definition: bgp_attr.h:400
PmsiTunnelDB * pmsi_tunnel_db_
Definition: bgp_attr.h:399
virtual void Remove()
Definition: bgp_attr.cc:412
uint32_t label_
Definition: bgp_attr.h:397
std::string ToString() const
Definition: rd.cc:57
MacAddress mac_address() const
Definition: router_mac.cc:24
boost::intrusive_ptr< const LargeCommunity > LargeCommunityPtr
Defines a type for automatic storage of a LargeCommunity instance.
Definition: community.h:687
boost::intrusive_ptr< const Community > CommunityPtr
Definition: community.h:112
boost::intrusive_ptr< const ExtCommunity > ExtCommunityPtr
Definition: community.h:451
boost::intrusive_ptr< LabelBlock > LabelBlockPtr
Definition: label_block.h:20
uint8_t type
Definition: load_balance.h:2
static uint64_t get_value(const uint8_t *data, int size)
Definition: parse_object.h:40
virtual std::string ToString() const
Definition: bgp_attr.cc:122
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:109
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:118
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:130
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:139
virtual std::string ToString() const
Definition: bgp_attr.cc:143
uint32_t address
Definition: bgp_attr.h:163
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:160
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:151
virtual std::string ToString() const
Definition: bgp_attr.cc:164
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:98
virtual std::string ToString() const
Definition: bgp_attr.cc:102
EthernetSegmentId esi
Definition: bgp_attr.h:788
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:855
virtual std::string ToString() const
Definition: bgp_attr.cc:859
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:848
virtual std::string ToString() const
Definition: bgp_attr.cc:822
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:818
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:810
LabelBlockPtr label_block
Definition: bgp_attr.h:658
uint32_t local_pref
Definition: bgp_attr.h:116
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:80
virtual std::string ToString() const
Definition: bgp_attr.cc:91
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:87
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:63
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:69
virtual std::string ToString() const
Definition: bgp_attr.cc:73
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:48
uint32_t nexthop
Definition: bgp_attr.h:83
Ip6Address v6_nexthop
Definition: bgp_attr.h:84
virtual std::string ToString() const
Definition: bgp_attr.cc:56
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:40
virtual std::string ToString() const
Definition: bgp_attr.cc:33
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:22
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:29
virtual std::string ToString() const
Definition: bgp_attr.cc:184
uint32_t originator_id
Definition: bgp_attr.h:198
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:172
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:180
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:873
uint64_t params
Definition: bgp_attr.h:817
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:866
virtual std::string ToString() const
Definition: bgp_attr.cc:877
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:837
virtual std::string ToString() const
Definition: bgp_attr.cc:841
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:829
RouteDistinguisher source_rd
Definition: bgp_attr.h:776
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:891
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:884
virtual std::string ToString() const
Definition: bgp_attr.cc:895
std::string sbp
Definition: bgp_attr.h:800
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:247
uint8_t safi
Definition: bgp_attr.h:309
uint16_t afi
Definition: bgp_attr.h:308
virtual size_t EncodeLength() const
Definition: bgp_attr.cc:267
std::vector< BgpProtoPrefix * > nlri
Definition: bgp_attr.h:312
std::vector< uint8_t > nexthop
Definition: bgp_attr.h:310
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:264
int operator()(const BgpOListElem *lhs, const BgpOListElem *rhs) const
Definition: bgp_attr.cc:789
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:740
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:734
virtual std::string ToString() const
Definition: bgp_attr.cc:750
Elements elements
Definition: bgp_attr.h:695
bool ClusterListLoop(uint32_t cluster_id) const
Definition: bgp_attr.cc:224
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:209
virtual std::string ToString() const
Definition: bgp_attr.cc:213
virtual int CompareTo(const BgpAttribute &rhs) const
Definition: bgp_attr.cc:201
std::vector< uint32_t > cluster_list
Definition: bgp_attr.h:218
int operator()(const EdgeDiscovery::Edge *lhs, const EdgeDiscovery::Edge *rhs) const
Definition: bgp_attr.cc:553
int operator()(const EdgeDiscoverySpec::Edge *lhs, const EdgeDiscoverySpec::Edge *rhs) const
Definition: bgp_attr.cc:470
void SetLabels(uint32_t first_label, uint32_t last_label)
Definition: bgp_attr.cc:463
void SetIp4Address(Ip4Address addr)
Definition: bgp_attr.cc:451
void GetLabels(uint32_t *first_label, uint32_t *last_label) const
Definition: bgp_attr.cc:457
Ip4Address GetIp4Address() const
Definition: bgp_attr.cc:447
std::vector< uint8_t > address
Definition: bgp_attr.h:456
std::vector< uint32_t > labels
Definition: bgp_attr.h:457
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:489
virtual size_t EncodeLength() const
Definition: bgp_attr.cc:510
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:478
virtual std::string ToString() const
Definition: bgp_attr.cc:493
EdgeList edge_list
Definition: bgp_attr.h:460
LabelBlockPtr label_block
Definition: bgp_attr.h:482
Edge(const EdgeDiscoverySpec::Edge *edge_spec)
Definition: bgp_attr.cc:521
Ip4Address address
Definition: bgp_attr.h:481
bool operator<(const Edge &rhs) const
Definition: bgp_attr.cc:528
int operator()(const EdgeForwarding::Edge *lhs, const EdgeForwarding::Edge *rhs) const
Definition: bgp_attr.cc:706
int operator()(const EdgeForwardingSpec::Edge *lhs, const EdgeForwardingSpec::Edge *rhs) const
Definition: bgp_attr.cc:618
Ip4Address GetOutboundIp4Address() const
Definition: bgp_attr.cc:599
std::vector< uint8_t > inbound_address
Definition: bgp_attr.h:562
void SetOutboundIp4Address(Ip4Address addr)
Definition: bgp_attr.cc:610
void SetInboundIp4Address(Ip4Address addr)
Definition: bgp_attr.cc:603
Ip4Address GetInboundIp4Address() const
Definition: bgp_attr.cc:595
std::vector< uint8_t > outbound_address
Definition: bgp_attr.h:562
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:639
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:628
virtual size_t EncodeLength() const
Definition: bgp_attr.cc:661
EdgeList edge_list
Definition: bgp_attr.h:567
virtual std::string ToString() const
Definition: bgp_attr.cc:643
uint32_t outbound_label
Definition: bgp_attr.h:590
Edge(const EdgeForwardingSpec::Edge *edge_spec)
Definition: bgp_attr.cc:673
bool operator<(const Edge &rhs) const
Definition: bgp_attr.cc:680
Ip4Address outbound_address
Definition: bgp_attr.h:589
Ip4Address inbound_address
Definition: bgp_attr.h:589
uint32_t inbound_label
Definition: bgp_attr.h:590
std::string GetTunnelArTypeString() const
Definition: bgp_attr.cc:373
uint8_t tunnel_flags
Definition: bgp_attr.h:359
std::string GetTunnelTypeString() const
Definition: bgp_attr.cc:347
std::vector< std::string > GetTunnelFlagsStrings() const
Definition: bgp_attr.cc:387
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:295
@ AssistedReplicationType
Definition: bgp_attr.h:318
@ EdgeReplicationSupported
Definition: bgp_attr.h:319
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:306
Ip4Address GetIdentifier() const
Definition: bgp_attr.cc:335
std::vector< uint8_t > identifier
Definition: bgp_attr.h:362
virtual std::string ToString() const
Definition: bgp_attr.cc:310
uint32_t GetLabel(const ExtCommunity *ext) const
Definition: bgp_attr.cc:323
@ IngressReplication
Definition: bgp_attr.h:335
@ AssistedReplicationContrail
Definition: bgp_attr.h:337
uint8_t tunnel_type
Definition: bgp_attr.h:360
void SetIdentifier(Ip4Address identifier)
Definition: bgp_attr.cc:341
uint32_t label
Definition: bgp_attr.h:361
void SetLabel(uint32_t label, const ExtCommunity *ext)
Definition: bgp_attr.cc:329
#define KEY_COMPARE(x, y)
Definition: util.h:71
int STLSortedCompare(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2, CompareOp op)
Definition: util.h:79
void STLDeleteValues(Container *container)
Definition: util.h:102
#define BOOL_KEY_COMPARE(x, y)
Definition: util.h:65