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