OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  origin_vn_path_(rhs.origin_vn_path_),
945  pmsi_tunnel_(rhs.pmsi_tunnel_),
946  edge_discovery_(rhs.edge_discovery_),
947  edge_forwarding_(rhs.edge_forwarding_),
948  label_block_(rhs.label_block_),
949  olist_(rhs.olist_),
950  leaf_olist_(rhs.leaf_olist_),
951  sub_protocol_(rhs.sub_protocol_) {
952  refcount_ = 0;
953 }
954 
956  as_path_ = aspath;
957 }
958 
959 void BgpAttr::set_as_path(const AsPathSpec *spec) {
960  if (spec) {
961  as_path_ = attr_db_->server()->aspath_db()->Locate(*spec);
962  } else {
963  as_path_ = NULL;
964  }
965 }
966 
968  as4_path_ = aspath;
969 }
970 
972  if (spec) {
973  as4_path_ = attr_db_->server()->as4path_db()->Locate(*spec);
974  } else {
975  as4_path_ = NULL;
976  }
977 }
978 
980  aspath_4byte_ = aspath;
981 }
982 
984  if (spec) {
986  } else {
987  aspath_4byte_ = NULL;
988  }
989 }
990 
992  if (spec) {
994  } else {
995  cluster_list_ = NULL;
996  }
997 }
998 
1000  community_ = comm;
1001 }
1002 
1004  if (comm) {
1005  community_ = attr_db_->server()->comm_db()->Locate(*comm);
1006  } else {
1007  community_ = NULL;
1008  }
1009 }
1010 
1012  ext_community_ = extcomm;
1013 }
1014 
1016  if (extcomm) {
1017  ext_community_ = attr_db_->server()->extcomm_db()->Locate(*extcomm);
1018  } else {
1019  ext_community_ = NULL;
1020  }
1021 }
1022 
1024  origin_vn_path_ = ovnpath;
1025 }
1026 
1028  if (spec) {
1030  } else {
1031  origin_vn_path_ = NULL;
1032  }
1033 }
1034 
1036  if (pmsi_spec) {
1037  pmsi_tunnel_ = attr_db_->server()->pmsi_tunnel_db()->Locate(*pmsi_spec);
1038  } else {
1039  pmsi_tunnel_ = NULL;
1040  }
1041 }
1042 
1044  if (edspec) {
1045  edge_discovery_ =
1046  attr_db_->server()->edge_discovery_db()->Locate(*edspec);
1047  } else {
1048  edge_discovery_ = NULL;
1049  }
1050 }
1051 
1053  if (efspec) {
1055  attr_db_->server()->edge_forwarding_db()->Locate(*efspec);
1056  } else {
1057  edge_forwarding_ = NULL;
1058  }
1059 }
1060 
1063 }
1064 
1065 void BgpAttr::set_olist(const BgpOListSpec *olist_spec) {
1066  if (olist_spec) {
1067  olist_ = attr_db_->server()->olist_db()->Locate(*olist_spec);
1068  } else {
1069  olist_ = NULL;
1070  }
1071 }
1072 
1073 void BgpAttr::set_leaf_olist(const BgpOListSpec *leaf_olist_spec) {
1074  if (leaf_olist_spec) {
1075  leaf_olist_ = attr_db_->server()->olist_db()->Locate(*leaf_olist_spec);
1076  } else {
1077  leaf_olist_ = NULL;
1078  }
1079 }
1080 
1082  int as_count = as_path_count();
1083  int as4_count = aspath_4byte_count();
1084  return as_count > as4_count ? as_count : as4_count;
1085 }
1086 
1088  if (as_path_ && !as_path_->empty())
1089  return false;
1090  if (aspath_4byte_ && !aspath_4byte_->empty())
1091  return false;
1092  return true;
1093 }
1094 
1096  switch (origin) {
1097  case BgpAttrOrigin::IGP:
1098  return "igp";
1099  break;
1100  case BgpAttrOrigin::EGP:
1101  return "egp";
1102  break;
1104  return "incomplete";
1105  break;
1106  }
1107  return "unknown";
1108 }
1109 
1111  const string &bgp_origin_type) {
1112  if(bgp_origin_type == "IGP"){
1113  return BgpAttrOrigin::IGP;
1114  } else if( bgp_origin_type == "EGP") {
1115  return BgpAttrOrigin::EGP;
1116  }
1118 }
1119 
1120 string BgpAttr::origin_string() const {
1121  return OriginToString(origin());
1122 }
1123 
1125  if (nexthop_.is_v6()) {
1126  return Address::INET6;
1127  } else {
1128  return Address::INET;
1129  }
1130 }
1131 
1133  if (as_path_.get())
1134  return as_path_->neighbor_as();
1135  if (aspath_4byte_.get())
1136  return aspath_4byte_->neighbor_as();
1137  return 0;
1138 }
1139 
1140 uint32_t BgpAttr::sequence_number() const {
1141  if (!ext_community_)
1142  return 0;
1143  for (ExtCommunity::ExtCommunityList::const_iterator it =
1144  ext_community_->communities().begin();
1145  it != ext_community_->communities().end(); ++it) {
1146  if (ExtCommunity::is_mac_mobility(*it)) {
1147  MacMobility mm(*it);
1148  return mm.sequence_number();
1149  }
1150  }
1151  return 0;
1152 }
1153 
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.sticky();
1163  }
1164  }
1165  return 0;
1166 }
1167 
1168 bool BgpAttr::etree_leaf() const {
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_etree(*it)) {
1175  ETree etree(*it);
1176  return etree.leaf();
1177  }
1178  }
1179  return 0;
1180 }
1181 
1183  if (!ext_community_)
1184  return false;
1185  for (ExtCommunity::ExtCommunityList::const_iterator it =
1186  ext_community_->communities().begin();
1187  it != ext_community_->communities().end(); ++it) {
1188  if (ExtCommunity::is_esi_label(*it)) {
1189  EsiLabel esi_label(*it);
1190  return esi_label.single_active();
1191  }
1192  }
1193  return true;
1194 }
1195 
1197  if (!ext_community_)
1198  return MacAddress::kZeroMac;
1199  for (ExtCommunity::ExtCommunityList::const_iterator it =
1200  ext_community_->communities().begin();
1201  it != ext_community_->communities().end(); ++it) {
1202  if (ExtCommunity::is_router_mac(*it)) {
1203  RouterMac router_mac(*it);
1204  return router_mac.mac_address();
1205  }
1206  }
1207  return MacAddress::kZeroMac;
1208 }
1209 
1211  attr_db_->Delete(this);
1212 }
1213 
1214 int BgpAttr::IsAsPathLoop(as_t asn, uint8_t max_loop_count) const {
1215  if (as_path() && as_path()->path().AsPathLoop(asn, max_loop_count)) {
1216  return true;
1217  }
1218  if (aspath_4byte() &&
1219  aspath_4byte()->path().AsPathLoop(asn, max_loop_count)) {
1220  return true;
1221  }
1222  if (asn > AS2_MAX && as4_path() &&
1223  as4_path()->path().AsPathLoop(asn, max_loop_count)) {
1224  return true;
1225  }
1226  return false;
1227 }
1228 
1229 int BgpAttr::CompareTo(const BgpAttr &rhs) const {
1230  KEY_COMPARE(origin_, rhs.origin_);
1232  KEY_COMPARE(med_, rhs.med_);
1239  KEY_COMPARE(pmsi_tunnel_.get(), rhs.pmsi_tunnel_.get());
1240  KEY_COMPARE(edge_discovery_.get(), rhs.edge_discovery_.get());
1241  KEY_COMPARE(edge_forwarding_.get(), rhs.edge_forwarding_.get());
1242  KEY_COMPARE(esi_, rhs.esi_);
1243  KEY_COMPARE(params_, rhs.params_);
1245  KEY_COMPARE(label_block_.get(), rhs.label_block_.get());
1246  KEY_COMPARE(olist_.get(), rhs.olist_.get());
1247  KEY_COMPARE(leaf_olist_.get(), rhs.leaf_olist_.get());
1248  KEY_COMPARE(as_path_.get(), rhs.as_path_.get());
1249  KEY_COMPARE(aspath_4byte_.get(), rhs.aspath_4byte_.get());
1250  KEY_COMPARE(as4_path_.get(), rhs.as4_path_.get());
1251  KEY_COMPARE(cluster_list_.get(), rhs.cluster_list_.get());
1252  KEY_COMPARE(community_.get(), rhs.community_.get());
1253  KEY_COMPARE(ext_community_.get(), rhs.ext_community_.get());
1254  KEY_COMPARE(origin_vn_path_.get(), rhs.origin_vn_path_.get());
1256  return 0;
1257 }
1258 
1259 std::size_t hash_value(BgpAttr const &attr) {
1260  size_t hash = 0;
1261 
1262  boost::hash_combine(hash, attr.origin_);
1263  boost::hash_combine(hash, attr.nexthop_.to_string());
1264  boost::hash_combine(hash, attr.med_);
1265  boost::hash_combine(hash, attr.local_pref_);
1266  boost::hash_combine(hash, attr.atomic_aggregate_);
1267  boost::hash_combine(hash, attr.aggregator_as_num_);
1268  boost::hash_combine(hash, attr.aggregator_as4_num_);
1269  boost::hash_combine(hash, attr.aggregator_address_.to_string());
1270  boost::hash_combine(hash, attr.originator_id_.to_string());
1271  boost::hash_combine(hash, attr.params_);
1272  boost::hash_combine(hash, attr.source_rd_.ToString());
1273  boost::hash_combine(hash, attr.esi_.ToString());
1274 
1275  if (attr.label_block_) {
1276  boost::hash_combine(hash, attr.label_block_->first());
1277  boost::hash_combine(hash, attr.label_block_->last());
1278  }
1279 
1280  if (attr.olist_) {
1281  boost::hash_range(hash, attr.olist_->elements().begin(),
1282  attr.olist_->elements().end());
1283  }
1284  if (attr.leaf_olist_) {
1285  boost::hash_range(hash, attr.leaf_olist_->elements().begin(),
1286  attr.leaf_olist_->elements().end());
1287  }
1288 
1289  if (attr.as_path_) boost::hash_combine(hash, *attr.as_path_);
1290  if (attr.aspath_4byte_) boost::hash_combine(hash, *attr.aspath_4byte_);
1291  if (attr.as4_path_) boost::hash_combine(hash, *attr.as4_path_);
1292  if (attr.community_) boost::hash_combine(hash, *attr.community_);
1293  if (attr.ext_community_) boost::hash_combine(hash, *attr.ext_community_);
1294  if (attr.origin_vn_path_) boost::hash_combine(hash, *attr.origin_vn_path_);
1295  if (!attr.sub_protocol_.empty()) {
1296  boost::hash_combine(hash, attr.sub_protocol_);
1297  }
1298 
1299  return hash;
1300 }
1301 
1302 BgpAttrDB::BgpAttrDB(BgpServer *server) : server_(server) {
1303 }
1304 
1305 // Return a clone of attribute with updated aspath.
1307  AsPathPtr aspath) {
1308  BgpAttr *clone = new BgpAttr(*attr);
1309  clone->set_as_path(aspath);
1310  return Locate(clone);
1311 }
1312 
1313 // Return a clone of attribute with updated community.
1315  CommunityPtr community) {
1316  BgpAttr *clone = new BgpAttr(*attr);
1317  clone->set_community(community);
1318  return Locate(clone);
1319 }
1320 
1321 //Return a clone of attribute with updated origin
1323  BgpAttrOrigin::OriginType origin) {
1324  BgpAttr *clone = new BgpAttr(*attr);
1325  clone->set_origin(origin);
1326  return Locate(clone);
1327 }
1328 
1329 // Return a clone of attribute with updated extended community.
1331  ExtCommunityPtr extcomm) {
1332  BgpAttr *clone = new BgpAttr(*attr);
1333  clone->set_ext_community(extcomm);
1334  return Locate(clone);
1335 }
1336 
1337 // Return a clone of attribute with updated origin vn path.
1339  OriginVnPathPtr ovnpath) {
1340  BgpAttr *clone = new BgpAttr(*attr);
1341  clone->set_origin_vn_path(ovnpath);
1342  return Locate(clone);
1343 }
1344 
1345 // Return a clone of attribute with updated local preference.
1347  uint32_t local_pref) {
1348  BgpAttr *clone = new BgpAttr(*attr);
1349  clone->set_local_pref(local_pref);
1350  return Locate(clone);
1351 }
1352 
1353 // Return a clone of attribute with updated originator id.
1355  Ip4Address originator_id) {
1356  BgpAttr *clone = new BgpAttr(*attr);
1357  clone->set_originator_id(originator_id);
1358  return Locate(clone);
1359 }
1360 
1361 // Return a clone of attribute with updated source rd.
1363  const RouteDistinguisher &source_rd) {
1364  BgpAttr *clone = new BgpAttr(*attr);
1365  clone->set_source_rd(source_rd);
1366  return Locate(clone);
1367 }
1368 
1369 // Return a clone of attribute with updated esi.
1371  const EthernetSegmentId &esi) {
1372  BgpAttr *clone = new BgpAttr(*attr);
1373  clone->set_esi(esi);
1374  return Locate(clone);
1375 }
1376 
1377 // Return a clone of attribute with updated olist.
1379  const BgpOListSpec *olist_spec) {
1380  assert(olist_spec->subcode == BgpAttribute::OList);
1381  BgpAttr *clone = new BgpAttr(*attr);
1382  clone->set_olist(olist_spec);
1383  return Locate(clone);
1384 }
1385 
1386 // Return a clone of attribute with updated leaf olist.
1388  const BgpOListSpec *leaf_olist_spec) {
1389  assert(leaf_olist_spec->subcode == BgpAttribute::LeafOList);
1390  BgpAttr *clone = new BgpAttr(*attr);
1391  clone->set_leaf_olist(leaf_olist_spec);
1392  return Locate(clone);
1393 }
1394 
1395 // Return a clone of attribute with updated sub-protocol.
1397  const string &sbp) {
1398  BgpAttr *clone = new BgpAttr(*attr);
1399  clone->set_sub_protocol(sbp);
1400  return Locate(clone);
1401 }
1402 
1403 
1404 // Return a clone of attribute with updated pmsi tunnel.
1406  const PmsiTunnelSpec *pmsi_spec) {
1407  BgpAttr *clone = new BgpAttr(*attr);
1408  clone->set_pmsi_tunnel(pmsi_spec);
1409  return Locate(clone);
1410 }
1411 
1412 // Return a clone of attribute with updated nexthop.
1414  const IpAddress &addr) {
1415  BgpAttr *clone = new BgpAttr(*attr);
1416  clone->set_nexthop(addr);
1417  return Locate(clone);
1418 }
EthernetSegmentId esi
Definition: bgp_attr.h:787
virtual ~EdgeForwarding()
Definition: bgp_attr.cc:700
virtual void Remove()
Definition: bgp_attr.cc:719
tbb::atomic< int > refcount_
Definition: bgp_attr.h:397
EdgeForwardingDB * edge_forwarding_db()
Definition: bgp_server.h:186
boost::intrusive_ptr< const AsPath > AsPathPtr
Definition: bgp_aspath.h:165
EdgeDiscoveryPtr edge_discovery_
Definition: bgp_attr.h:965
void SetIp4Address(Ip4Address addr)
Definition: bgp_attr.cc:450
BgpOListDB * olist_db()
Definition: bgp_server.h:182
BgpAttrPtr ReplaceLeafOListAndLocate(const BgpAttr *attr, const BgpOListSpec *leaf_olist_spec)
Definition: bgp_attr.cc:1387
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:47
Elements elements
Definition: bgp_attr.h:694
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:150
std::vector< std::string > encap
Definition: bgp_attr.h:674
Ip4Address GetIdentifier() const
Definition: bgp_attr.cc:334
Ip4Address GetInboundIp4Address() const
Definition: bgp_attr.cc:594
Elements elements_
Definition: bgp_attr.h:722
const BgpOListSpec & olist() const
Definition: bgp_attr.h:704
uint16_t afi
Definition: bgp_attr.h:307
as_t neighbor_as() const
Definition: bgp_attr.cc:1132
tbb::atomic< int > refcount_
Definition: bgp_attr.h:723
std::vector< BgpProtoPrefix * > nlri
Definition: bgp_attr.h:311
uint32_t originator_id
Definition: bgp_attr.h:197
int operator()(const EdgeForwardingSpec::Edge *lhs, const EdgeForwardingSpec::Edge *rhs) const
Definition: bgp_attr.cc:617
tbb::atomic< int > refcount_
Definition: bgp_attr.h:243
int operator()(const EdgeDiscovery::Edge *lhs, const EdgeDiscovery::Edge *rhs) const
Definition: bgp_attr.cc:552
EdgeForwarding(EdgeForwardingDB *edge_forwarding_db, const EdgeForwardingSpec &efspec)
Definition: bgp_attr.cc:687
void STLDeleteValues(Container *container)
Definition: util.h:101
BgpAttrPtr ReplaceOriginatorIdAndLocate(const BgpAttr *attr, Ip4Address originator_id)
Definition: bgp_attr.cc:1354
ExtCommunityPtr ext_community_
Definition: bgp_attr.h:962
int operator()(const EdgeForwarding::Edge *lhs, const EdgeForwarding::Edge *rhs) const
Definition: bgp_attr.cc:705
void set_pmsi_tunnel(const PmsiTunnelSpec *pmsi_spec)
Definition: bgp_attr.cc:1035
bool etree_leaf() const
Definition: bgp_attr.cc:1168
Definition: etree.h:16
TypePtr Locate(Type *attr)
LabelBlockPtr label_block() const
Definition: bgp_attr.h:924
std::vector< uint8_t > outbound_address
Definition: bgp_attr.h:561
void GetLabels(uint32_t *first_label, uint32_t *last_label) const
Definition: bgp_attr.cc:456
virtual std::string ToString() const
Definition: bgp_attr.cc:492
virtual size_t EncodeLength() const
Definition: bgp_attr.cc:509
void set_nexthop(IpAddress nexthop)
Definition: bgp_attr.h:837
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:809
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:305
std::vector< std::string > GetTunnelFlagsStrings() const
Definition: bgp_attr.cc:386
std::string sub_protocol_
Definition: bgp_attr.h:970
BgpAttrPtr ReplaceCommunityAndLocate(const BgpAttr *attr, CommunityPtr community)
Definition: bgp_attr.cc:1314
void set_cluster_list(const ClusterListSpec *spec)
Definition: bgp_attr.cc:991
tbb::atomic< int > refcount_
Definition: bgp_attr.h:943
boost::intrusive_ptr< const As4Path > As4PathPtr
Definition: bgp_aspath.h:481
RouteDistinguisher source_rd_
Definition: bgp_attr.h:954
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:21
virtual std::string ToString() const
Definition: bgp_attr.cc:212
As4PathPtr as4_path_
Definition: bgp_attr.h:959
void set_origin(BgpAttrOrigin::OriginType org)
Definition: bgp_attr.h:836
Family
Definition: address.h:24
#define KEY_COMPARE(x, y)
Definition: util.h:70
uint32_t local_pref_
Definition: bgp_attr.h:948
CommunityDB * comm_db()
Definition: bgp_server.h:184
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:836
boost::asio::ip::address IpAddress
Definition: address.h:13
static const MacAddress kZeroMac
Definition: mac_address.h:149
EdgeDiscovery(EdgeDiscoveryDB *edge_discovery_db, const EdgeDiscoverySpec &edspec)
Definition: bgp_attr.cc:534
PmsiTunnelSpec pmsi_spec_
Definition: bgp_attr.h:399
std::vector< uint8_t > address
Definition: bgp_attr.h:455
PmsiTunnel(PmsiTunnelDB *pmsi_tunnel_db, const PmsiTunnelSpec &pmsi_spec)
Definition: bgp_attr.cc:400
void SetOutboundIp4Address(Ip4Address addr)
Definition: bgp_attr.cc:609
EdgeList edge_list
Definition: bgp_attr.h:459
uint8_t flags
Definition: bgp_attr_base.h:70
virtual void Remove()
Definition: bgp_attr.cc:566
uint32_t label_
Definition: bgp_attr.h:396
virtual std::string ToString() const
Definition: bgp_attr.cc:840
int CompareTo(const EdgeForwarding &rhs) const
Definition: bgp_attr.cc:712
EdgeForwardingSpec efspec_
Definition: bgp_attr.h:610
IpAddress aggregator_address_
Definition: bgp_attr.h:952
boost::intrusive_ptr< LabelBlock > LabelBlockPtr
Definition: label_block.h:18
BgpAttrPtr ReplaceNexthopAndLocate(const BgpAttr *attr, const IpAddress &addr)
Definition: bgp_attr.cc:1413
OriginVnPathPtr origin_vn_path_
Definition: bgp_attr.h:963
virtual std::string ToString() const
Definition: bgp_attr.cc:183
uint8_t tunnel_type
Definition: bgp_attr.h:359
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:171
LabelBlockPtr label_block
Definition: bgp_attr.h:481
Ip6Address v6_nexthop
Definition: bgp_attr.h:83
void set_edge_discovery(const EdgeDiscoverySpec *edspec)
Definition: bgp_attr.cc:1043
void set_community(CommunityPtr comm)
Definition: bgp_attr.cc:999
as_t aggregator_as4_num_
Definition: bgp_attr.h:951
virtual void Remove()
Definition: bgp_attr.cc:411
std::vector< BgpAttribute * > BgpAttrSpec
Definition: bgp_attr.h:822
virtual ~BgpOList()
Definition: bgp_attr.cc:783
void Remove()
Definition: bgp_attr.cc:239
EdgeList edge_list
Definition: bgp_attr.h:600
BgpAttr()
Definition: bgp_attr.cc:901
uint64_t params_
Definition: bgp_attr.h:956
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:847
virtual std::string ToString() const
Definition: bgp_attr.cc:894
virtual std::string ToString() const
Definition: bgp_attr.cc:821
virtual std::string ToString() const
Definition: bgp_attr.cc:749
uint32_t as_t
Definition: bgp_common.h:21
Edge(const EdgeDiscoverySpec::Edge *edge_spec)
Definition: bgp_attr.cc:520
static uint64_t get_value(const uint8_t *data, int size)
Definition: parse_object.h:39
PmsiTunnelDB * pmsi_tunnel_db()
Definition: bgp_server.h:189
EdgeDiscoveryDB * edge_discovery_db()
Definition: bgp_server.h:185
BgpAttrDB * attr_db_
Definition: bgp_attr.h:944
uint32_t inbound_label
Definition: bgp_attr.h:589
std::string origin_string() const
Definition: bgp_attr.cc:1120
tbb::atomic< int > refcount_
Definition: bgp_attr.h:608
std::vector< uint32_t > cluster_list
Definition: bgp_attr.h:217
Ip4Address address
Definition: bgp_attr.h:672
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:138
virtual std::string ToString() const
Definition: bgp_attr.cc:142
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:97
AsPath4ByteDB * aspath_4byte_db()
Definition: bgp_server.h:179
void set_as_path(AsPathPtr aspath)
Definition: bgp_attr.cc:955
void set_source_rd(const RouteDistinguisher &source_rd)
Definition: bgp_attr.h:852
OriginVnPathDB * ovnpath_db()
Definition: bgp_server.h:188
Ip4Address originator_id_
Definition: bgp_attr.h:953
static bool is_esi_label(const ExtCommunityValue &val)
Definition: community.h:219
BgpAttrPtr ReplaceExtCommunityAndLocate(const BgpAttr *attr, ExtCommunityPtr extcomm)
Definition: bgp_attr.cc:1330
virtual std::string ToString() const
Definition: bgp_attr.cc:121
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:477
void set_aggregator(as_t as_num, IpAddress address)
Definition: bgp_attr.h:841
bool operator<(const Edge &rhs) const
Definition: bgp_attr.cc:527
virtual size_t EncodeLength() const
Definition: bgp_attr.cc:660
int IsAsPathLoop(as_t asn, uint8_t max_loop_count=0) const
Definition: bgp_attr.cc:1214
MacAddress mac_address() const
Definition: bgp_attr.cc:1196
boost::intrusive_ptr< const OriginVnPath > OriginVnPathPtr
virtual int CompareTo(const BgpAttribute &rhs) const
Definition: bgp_attr.cc:200
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:159
boost::intrusive_ptr< const AsPath4Byte > AsPath4BytePtr
Definition: bgp_aspath.h:323
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:865
void set_sub_protocol(const std::string &sub_protocol)
Definition: bgp_attr.h:876
Ip4Address GetIp4Address() const
Definition: bgp_attr.cc:446
void set_esi(const EthernetSegmentId &esi)
Definition: bgp_attr.h:855
Ip4Address address
Definition: bgp_attr.h:480
boost::intrusive_ptr< const BgpAttr > BgpAttrPtr
Definition: bgp_attr.h:991
Ip4Address inbound_address
Definition: bgp_attr.h:588
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:739
virtual std::string ToString() const
Definition: bgp_attr.cc:55
virtual void Remove()
Definition: bgp_attr.cc:1210
Ip4Address GetOutboundIp4Address() const
Definition: bgp_attr.cc:598
uint8_t tunnel_type_
Definition: bgp_attr.h:394
bool single_active() const
Definition: esi_label.h:24
void SetInboundIp4Address(Ip4Address addr)
Definition: bgp_attr.cc:602
bool sticky() const
Definition: mac_mobility.cc:28
void set_params(uint64_t params)
Definition: bgp_attr.h:856
MacAddress mac_address() const
Definition: router_mac.cc:23
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:294
BgpAttrPtr ReplaceEsiAndLocate(const BgpAttr *attr, const EthernetSegmentId &esi)
Definition: bgp_attr.cc:1370
uint8_t type
Definition: load_balance.h:109
void set_leaf_olist(const BgpOListSpec *leaf_olist_spec)
Definition: bgp_attr.cc:1073
const AsPath4Byte * aspath_4byte() const
Definition: bgp_attr.h:902
PmsiTunnelPtr pmsi_tunnel_
Definition: bgp_attr.h:964
#define BOOL_KEY_COMPARE(x, y)
Definition: util.h:64
bool evpn_single_active() const
Definition: bgp_attr.cc:1182
BgpAttrOrigin::OriginType origin_
Definition: bgp_attr.h:945
uint32_t outbound_label
Definition: bgp_attr.h:589
virtual int CompareTo(const BgpAttribute &rhs) const
static std::string OriginToString(BgpAttrOrigin::OriginType origin)
Definition: bgp_attr.cc:1095
bool operator<(const Edge &rhs) const
Definition: bgp_attr.cc:679
ExtCommunityDB * extcomm_db()
Definition: bgp_server.h:187
static bool is_router_mac(const ExtCommunityValue &val)
Definition: community.h:257
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:627
uint32_t label
Definition: bgp_attr.h:360
void SetLabels(uint32_t first_label, uint32_t last_label)
Definition: bgp_attr.cc:462
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:28
BgpOListSpec olist_spec_
Definition: bgp_attr.h:725
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:117
boost::intrusive_ptr< const ExtCommunity > ExtCommunityPtr
Definition: community.h:448
int CompareTo(const EdgeDiscovery &rhs) const
Definition: bgp_attr.cc:559
BgpAttrPtr ReplaceSubProtocolAndLocate(const BgpAttr *attr, const std::string &sbp)
Definition: bgp_attr.cc:1396
ClusterList(ClusterListDB *cluster_list_db, const ClusterListSpec &spec)
Definition: bgp_attr.cc:232
std::string GetTunnelArTypeString() const
Definition: bgp_attr.cc:372
void Delete(Type *attr)
void SetIdentifier(Ip4Address identifier)
Definition: bgp_attr.cc:340
BgpAttrPtr ReplaceLocalPreferenceAndLocate(const BgpAttr *attr, uint32_t local_pref)
Definition: bgp_attr.cc:1346
int CompareTo(const BgpAttr &rhs) const
Definition: bgp_attr.cc:1229
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:39
EdgeDiscoveryDB(BgpServer *server)
Definition: bgp_attr.cc:570
BgpAttrPtr ReplaceSourceRdAndLocate(const BgpAttr *attr, const RouteDistinguisher &source_rd)
Definition: bgp_attr.cc:1362
BgpOList(BgpOListDB *olist_db, const BgpOListSpec &olist_spec)
Definition: bgp_attr.cc:770
virtual std::string ToString() const
Definition: bgp_attr.cc:32
uint32_t nexthop
Definition: bgp_attr.h:82
As4PathDB * as4path_db()
Definition: bgp_server.h:180
Ip4Address identifier_
Definition: bgp_attr.h:395
virtual std::string ToString() const
Definition: bgp_attr.cc:72
const As4Path * as4_path() const
Definition: bgp_attr.h:911
EdgeList edge_list
Definition: bgp_attr.h:493
BgpServer * server()
Definition: bgp_attr.h:1031
ClusterListDB * cluster_list_db()
Definition: bgp_server.h:183
virtual std::string ToString() const
Definition: bgp_attr.cc:309
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:208
BgpOListPtr olist_
Definition: bgp_attr.h:968
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:817
ClusterListDB(BgpServer *server)
Definition: bgp_attr.cc:243
bool IsAsPathEmpty() const
Definition: bgp_attr.cc:1087
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:129
BgpAttrPtr ReplaceOriginAndLocate(const BgpAttr *attr, BgpAttrOrigin::OriginType origin)
Definition: bgp_attr.cc:1322
uint32_t sequence_number() const
Definition: mac_mobility.cc:32
void SetLabel(uint32_t label, const ExtCommunity *ext)
Definition: bgp_attr.cc:328
virtual std::string ToString() const
Definition: bgp_attr.cc:876
boost::intrusive_ptr< const Community > CommunityPtr
Definition: community.h:109
BgpAttrPtr ReplacePmsiTunnelAndLocate(const BgpAttr *attr, const PmsiTunnelSpec *pmsi_spec)
Definition: bgp_attr.cc:1405
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
bool leaf() const
Definition: etree.cc:29
const AsPath * as_path() const
Definition: bgp_attr.h:899
void set_local_pref(uint32_t local_pref)
Definition: bgp_attr.h:839
int STLSortedCompare(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2, CompareOp op)
Definition: util.h:78
std::vector< uint8_t > identifier
Definition: bgp_attr.h:361
virtual std::string ToString() const
Definition: bgp_attr.cc:642
void set_edge_forwarding(const EdgeForwardingSpec *efspec)
Definition: bgp_attr.cc:1052
uint8_t tunnel_flags_
Definition: bgp_attr.h:393
EdgeDiscoveryDB * edge_discovery_db_
Definition: bgp_attr.h:502
void set_originator_id(Ip4Address originator_id)
Definition: bgp_attr.h:849
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:263
static BgpAttrOrigin::OriginType OriginFromString(const std::string &bgp_origin_type)
Definition: bgp_attr.cc:1110
Address::Family nexthop_family() const
Definition: bgp_attr.cc:1124
void set_label_block(LabelBlockPtr label_block)
Definition: bgp_attr.cc:1061
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:733
BgpOListDB(BgpServer *server)
Definition: bgp_attr.cc:806
uint8_t tunnel_flags
Definition: bgp_attr.h:358
BgpAttrPtr ReplaceAsPathAndLocate(const BgpAttr *attr, AsPathPtr aspath)
Definition: bgp_attr.cc:1306
Ip4Address outbound_address
Definition: bgp_attr.h:588
std::string sbp
Definition: bgp_attr.h:799
uint8_t safi
Definition: bgp_attr.h:308
const Elements & elements() const
Definition: bgp_attr.h:714
BgpAttrPtr ReplaceOListAndLocate(const BgpAttr *attr, const BgpOListSpec *olist_spec)
Definition: bgp_attr.cc:1378
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:883
PmsiTunnelDB(BgpServer *server)
Definition: bgp_attr.cc:422
int max_as_path_count() const
Definition: bgp_attr.cc:1081
virtual size_t EncodeLength() const
Definition: bgp_attr.cc:266
IpAddress nexthop_
Definition: bgp_attr.h:946
BgpAttrOrigin::OriginType origin() const
Definition: bgp_attr.h:881
uint32_t label
Definition: bgp_attr.h:673
bool ContainsTunnelEncapVxlan() const
Definition: community.cc:655
ClusterListPtr cluster_list_
Definition: bgp_attr.h:960
std::string ToString() const
Definition: esi.cc:120
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:488
int aspath_4byte_count() const
Definition: bgp_attr.h:903
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:79
int operator()(const BgpOListElem *lhs, const BgpOListElem *rhs) const
Definition: bgp_attr.cc:788
void set_med(uint32_t med)
Definition: bgp_attr.h:838
std::string ToString() const
Definition: rd.cc:56
EdgeDiscoverySpec edspec_
Definition: bgp_attr.h:503
uint32_t GetLabel(const ExtCommunity *ext) const
Definition: bgp_attr.cc:322
uint32_t address
Definition: bgp_attr.h:162
uint64_t params
Definition: bgp_attr.h:816
AsPathPtr as_path_
Definition: bgp_attr.h:957
LabelBlockPtr label_block_
Definition: bgp_attr.h:967
as_t aggregator_as_num_
Definition: bgp_attr.h:950
EthernetSegmentId esi_
Definition: bgp_attr.h:955
uint32_t sequence_number() const
Definition: bgp_attr.cc:1140
std::string GetTunnelTypeString() const
Definition: bgp_attr.cc:346
bool operator<(const BgpOListElem &rhs) const
Definition: bgp_attr.cc:726
EdgeList edge_list
Definition: bgp_attr.h:566
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:86
static bool is_etree(const ExtCommunityValue &val)
Definition: community.h:240
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:62
void set_ext_community(ExtCommunityPtr extcomm)
Definition: bgp_attr.cc:1011
int as_path_count() const
Definition: bgp_attr.h:900
int CompareTo(const BgpOList &rhs) const
Definition: bgp_attr.cc:794
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:179
Edge(const EdgeForwardingSpec::Edge *edge_spec)
Definition: bgp_attr.cc:672
EdgeForwardingPtr edge_forwarding_
Definition: bgp_attr.h:966
void set_origin_vn_path(OriginVnPathPtr ovnpath)
Definition: bgp_attr.cc:1023
RouteDistinguisher source_rd
Definition: bgp_attr.h:775
void set_olist(const BgpOListSpec *olist_spec)
Definition: bgp_attr.cc:1065
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:108
bool ClusterListLoop(uint32_t cluster_id) const
Definition: bgp_attr.cc:223
std::vector< uint8_t > nexthop
Definition: bgp_attr.h:309
void set_atomic_aggregate(bool ae)
Definition: bgp_attr.h:840
std::size_t hash_value(BgpAttr const &attr)
Definition: bgp_attr.cc:1259
virtual std::string ToString() const
Definition: bgp_attr.cc:163
uint32_t med_
Definition: bgp_attr.h:947
ClusterListDB * cluster_list_db_
Definition: bgp_attr.h:244
void set_aspath_4byte(AsPath4BytePtr aspath)
Definition: bgp_attr.cc:979
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:638
LabelBlockPtr label_block
Definition: bgp_attr.h:657
void set_as4_path(As4PathPtr aspath)
Definition: bgp_attr.cc:967
virtual std::string ToString() const
Definition: bgp_attr.cc:858
uint32_t local_pref
Definition: bgp_attr.h:115
std::vector< uint8_t > inbound_address
Definition: bgp_attr.h:561
uint8_t subcode
Definition: bgp_attr_base.h:69
tbb::atomic< int > refcount_
Definition: bgp_attr.h:501
virtual std::string ToString() const
Definition: bgp_attr.cc:90
AsPathDB * aspath_db()
Definition: bgp_server.h:178
EdgeForwardingDB * edge_forwarding_db_
Definition: bgp_attr.h:609
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:872
BgpAttrDB(BgpServer *server)
Definition: bgp_attr.cc:1302
virtual std::string ToString() const
Definition: bgp_attr.cc:101
uint8_t code
Definition: bgp_attr_base.h:68
BgpAttrPtr ReplaceOriginVnPathAndLocate(const BgpAttr *attr, OriginVnPathPtr ovnpath)
Definition: bgp_attr.cc:1338
bool atomic_aggregate_
Definition: bgp_attr.h:949
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:68
bool evpn_sticky_mac() const
Definition: bgp_attr.cc:1154
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:828
int operator()(const EdgeDiscoverySpec::Edge *lhs, const EdgeDiscoverySpec::Edge *rhs) const
Definition: bgp_attr.cc:469
virtual ~EdgeDiscovery()
Definition: bgp_attr.cc:547
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:890
uint32_t GetLabel(const ExtCommunity *ext) const
Definition: bgp_attr.cc:415
EdgeForwardingDB(BgpServer *server)
Definition: bgp_attr.cc:723
AsPath4BytePtr aspath_4byte_
Definition: bgp_attr.h:958
BgpOListDB * olist_db_
Definition: bgp_attr.h:724
virtual void ToCanonical(BgpAttr *attr)
Definition: bgp_attr.cc:854
static bool is_mac_mobility(const ExtCommunityValue &val)
Definition: community.h:227
BgpOListPtr leaf_olist_
Definition: bgp_attr.h:969
std::vector< uint32_t > labels
Definition: bgp_attr.h:456
CommunityPtr community_
Definition: bgp_attr.h:961
PmsiTunnelDB * pmsi_tunnel_db_
Definition: bgp_attr.h:398
#define AS2_MAX
Definition: bgp_common.h:24
void set_as4_aggregator(as_t as_num, IpAddress address)
Definition: bgp_attr.h:845
virtual void Remove()
Definition: bgp_attr.cc:802
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: bgp_attr.cc:246