24 if (ret != 0)
return ret;
35 snprintf(repr,
sizeof(repr),
"ORIGIN <code: %d, flags: %02x> : %02x",
42 if (ret != 0)
return ret;
58 snprintf(repr,
sizeof(repr),
"NEXTHOP <code: %d, flags: %02x> : %04x",
65 if (ret != 0)
return ret;
75 snprintf(repr,
sizeof(repr),
"MED <code: %d, flags: %02x> : %d",
82 if (ret != 0)
return ret;
93 snprintf(repr,
sizeof(repr),
"LOCAL_PREF <code: %d, flags: %02x> : %d",
104 snprintf(repr,
sizeof(repr),
"ATOMIC_AGGR <code: %d, flags: %02x>",
111 if (ret != 0)
return ret;
124 snprintf(repr,
sizeof(repr),
125 "Aggregator <code: %d, flags: %02x> : %d:%08x",
132 if (ret != 0)
return ret;
145 snprintf(repr,
sizeof(repr),
146 "Aggregator <code: %d, flags: %02x> : %d:%08x",
153 if (ret != 0)
return ret;
166 snprintf(repr,
sizeof(repr),
167 "Aggregator <code: %d, flags: %02x> : %d:%08x",
174 if (ret != 0)
return ret;
186 snprintf(repr,
sizeof(repr),
"OriginatorId <code: %d, flags: 0x%02x> : %s",
203 if (ret != 0)
return ret;
214 std::stringstream repr;
215 repr <<
"CLUSTER_LIST <code: " << int(
code);
216 repr <<
", flags: 0x" << std::hex << int(
flags) <<
"> :";
217 for (vector<uint32_t>::const_iterator iter =
cluster_list.begin();
225 for (vector<uint32_t>::const_iterator iter =
cluster_list.begin();
227 if (*iter == cluster_id)
235 : cluster_list_db_(cluster_list_db),
249 if (ret != 0)
return ret;
256 for (
size_t i = 0; i <
nlri.size(); i++) {
272 for (vector<BgpProtoPrefix*>::const_iterator iter =
nlri.begin();
273 iter !=
nlri.end(); ++iter) {
277 bytes = (*iter)->prefixlen;
279 bytes = ((*iter)->prefixlen + 7) / 8;
288 tunnel_flags(0), tunnel_type(0), label(0) {
292 :
BgpAttribute(rhs), tunnel_flags(0), tunnel_type(0), label(0) {
297 if (ret != 0)
return ret;
311 std::ostringstream oss;
312 oss <<
"PmsiTunnel <code: " << int(
code);
313 oss <<
", flags: 0x" << std::hex << int(
flags) << std::dec <<
">";
314 oss <<
" Tunnel Flags: 0x" << std::hex << int(
tunnel_flags) << std::dec;
316 oss <<
" Label: 0x" << std::hex << int(
label) << std::dec;
317 oss <<
" (" << int(
label) <<
")";
332 label = (is_vni ? in_label : (in_label << 4 | 0x01));
343 const Ip4Address::bytes_type &bytes = in_identifier.to_bytes();
344 std::copy(bytes.begin(), bytes.begin() + 4,
identifier.begin());
350 return "RsvpP2mpLsp";
358 return "BidirPimTree";
360 return "IngressReplication";
362 return "MldpMp2mpLsp";
364 return "AssistedReplication";
368 std::ostringstream oss;
378 return "ARReplicator";
388 vector<string>
flags;
390 flags.push_back(
"LeafInfoRequired");
393 flags.push_back(
"EdgeReplicationSupported");
396 flags.push_back(
"None");
403 : pmsi_tunnel_db_(pmsi_tunnel_db),
404 pmsi_spec_(pmsi_spec) {
436 for (
size_t i = 0; i < rhs.
edge_list.size(); i++) {
452 address.resize(4, 0);
453 const Ip4Address::bytes_type &addr_bytes = addr.to_bytes();
454 std::copy(addr_bytes.begin(), addr_bytes.begin() + 4, address.begin());
458 uint32_t *first_label, uint32_t *last_label)
const {
459 *first_label = labels[0];
460 *last_label = labels[1];
464 uint32_t first_label, uint32_t last_label) {
465 labels.push_back(first_label);
466 labels.push_back(last_label);
480 if (ret != 0)
return ret;
494 std::ostringstream oss;
495 oss <<
"EdgeDiscovery <code: " << int(
code);
496 oss <<
", flags: 0x" << std::hex << int(
flags) << std::dec <<
">";
498 for (EdgeList::const_iterator it =
edge_list.begin();
500 const Edge *edge = *it;
501 uint32_t first_label, last_label;
502 edge->
GetLabels(&first_label, &last_label);
503 oss <<
" Edge[" << idx <<
"] = (" << edge->
GetIp4Address() <<
", ";
504 oss << first_label <<
"-" << last_label <<
")";
512 for (EdgeList::const_iterator iter =
edge_list.begin();
515 sz += (*iter)->address.size();
516 sz += (*iter)->labels.size() *
sizeof(uint32_t);
523 uint32_t first_label, last_label;
524 spec_edge->
GetLabels(&first_label, &last_label);
525 label_block =
new LabelBlock(first_label, last_label);
537 : edge_discovery_db_(edge_discovery_db),
540 for (EdgeDiscoverySpec::EdgeList::const_iterator it =
584 for (
size_t i = 0; i < rhs.
edge_list.size(); i++) {
604 inbound_address.resize(4, 0);
605 const Ip4Address::bytes_type &addr_bytes = addr.to_bytes();
606 std::copy(addr_bytes.begin(), addr_bytes.begin() + 4,
607 inbound_address.begin());
611 outbound_address.resize(4, 0);
612 const Ip4Address::bytes_type &addr_bytes = addr.to_bytes();
613 std::copy(addr_bytes.begin(), addr_bytes.begin() + 4,
614 outbound_address.begin());
630 if (ret != 0)
return ret;
644 std::ostringstream oss;
645 oss <<
"EdgeForwarding <code: " << int(
code);
646 oss <<
", flags: 0x" << std::hex << int(
flags) << std::dec <<
">";
648 for (EdgeList::const_iterator it =
edge_list.begin();
650 const Edge *edge = *it;
651 oss <<
" Edge[" << idx <<
"] = (";
663 for (EdgeList::const_iterator iter =
edge_list.begin();
666 sz += (*iter)->inbound_address.size();
667 sz += (*iter)->outbound_address.size();
690 : edge_forwarding_db_(edge_forwarding_db),
693 for (EdgeForwardingSpec::EdgeList::const_iterator it =
736 if (ret != 0)
return ret;
751 std::ostringstream oss;
752 oss <<
"OList <subcode: " << int(
subcode) <<
">";
754 for (Elements::const_iterator it =
elements.begin();
755 it !=
elements.end(); ++it, ++idx) {
757 oss <<
"OList[" << idx <<
"] = (";
758 oss <<
"address: " << elem.
address <<
", ";
759 oss <<
"label: " << elem.
label <<
", ";
760 oss <<
"encap-list:";
762 for (vector<string>::const_iterator e_it = elem.
encap.begin();
763 e_it != elem.
encap.end(); ++e_it, ++eid) {
772 : olist_db_(olist_db),
773 olist_spec_(olist_spec) {
775 for (BgpOListSpec::Elements::const_iterator it =
812 if (ret != 0)
return ret;
824 snprintf(repr,
sizeof(repr),
"LabelBlock <subcode: %d> : %d-%d",
831 if (ret != 0)
return ret;
843 snprintf(repr,
sizeof(repr),
"SourceRd <subcode: %d> : %s",
850 if (ret != 0)
return ret;
861 snprintf(repr,
sizeof(repr),
"Esi <subcode: %d> : %s",
868 if (ret != 0)
return ret;
879 snprintf(repr,
sizeof(repr),
"Params <subcode: %d> : 0x%016jx",
886 if (ret != 0)
return ret;
897 snprintf(repr,
sizeof(repr),
"SubProtocol <subcode: %d> : %s",
903 : attr_db_(NULL), origin_(
BgpAttrOrigin::INCOMPLETE), nexthop_(),
904 med_(0), local_pref_(0), atomic_aggregate_(false),
905 aggregator_as_num_(0), aggregator_as4_num_(0), params_(0) {
911 nexthop_(), med_(0), local_pref_(0), atomic_aggregate_(false),
912 aggregator_as_num_(0), aggregator_as4_num_(0), params_(0) {
920 atomic_aggregate_(false),
921 aggregator_as_num_(0), aggregator_as4_num_(0),
922 aggregator_address_(), params_(0) {
924 for (vector<BgpAttribute *>::const_iterator it = spec.begin();
925 it < spec.end(); it++) {
926 (*it)->ToCanonical(
this);
931 : attr_db_(rhs.attr_db_), origin_(rhs.origin_), nexthop_(rhs.nexthop_),
932 med_(rhs.med_), local_pref_(rhs.local_pref_),
933 atomic_aggregate_(rhs.atomic_aggregate_),
934 aggregator_as_num_(rhs.aggregator_as_num_),
935 aggregator_as4_num_(rhs.aggregator_as4_num_),
936 aggregator_address_(rhs.aggregator_address_),
937 originator_id_(rhs.originator_id_),
938 source_rd_(rhs.source_rd_), esi_(rhs.esi_), params_(rhs.params_),
939 as_path_(rhs.as_path_),
940 aspath_4byte_(rhs.aspath_4byte_),
941 as4_path_(rhs.as4_path_),
942 cluster_list_(rhs.cluster_list_),
943 community_(rhs.community_),
944 ext_community_(rhs.ext_community_),
945 large_community_(rhs.large_community_),
946 deferred_large_spec_(nullptr),
947 origin_vn_path_(rhs.origin_vn_path_),
948 pmsi_tunnel_(rhs.pmsi_tunnel_),
949 edge_discovery_(rhs.edge_discovery_),
950 edge_forwarding_(rhs.edge_forwarding_),
951 label_block_(rhs.label_block_),
953 leaf_olist_(rhs.leaf_olist_),
954 sub_protocol_(rhs.sub_protocol_) {
1109 if (leaf_olist_spec) {
1119 return as_count > as4_count ? as_count : as4_count;
1139 return "incomplete";
1146 const string &bgp_origin_type) {
1147 if(bgp_origin_type ==
"IGP"){
1149 }
else if( bgp_origin_type ==
"EGP") {
1178 for (ExtCommunity::ExtCommunityList::const_iterator it =
1192 for (ExtCommunity::ExtCommunityList::const_iterator it =
1206 for (ExtCommunity::ExtCommunityList::const_iterator it =
1211 return etree.
leaf();
1220 for (ExtCommunity::ExtCommunityList::const_iterator it =
1234 for (ExtCommunity::ExtCommunityList::const_iterator it =
1250 if (
as_path() &&
as_path()->path().AsPathLoop(asn, max_loop_count)) {
1254 aspath_4byte()->path().AsPathLoop(asn, max_loop_count)) {
1258 as4_path()->path().AsPathLoop(asn, max_loop_count)) {
1298 boost::hash_combine(hash, attr.
origin_);
1299 boost::hash_combine(hash, attr.
nexthop_.to_string());
1300 boost::hash_combine(hash, attr.
med_);
1307 boost::hash_combine(hash, attr.
params_);
1317 boost::hash_range(hash, attr.
olist_->elements().begin(),
1318 attr.
olist_->elements().end());
1321 boost::hash_range(hash, attr.
leaf_olist_->elements().begin(),
1392 uint32_t local_pref) {
1442 const string &sbp) {
boost::asio::ip::address IpAddress
boost::asio::ip::address_v4 Ip4Address
boost::intrusive_ptr< const AsPath4Byte > AsPath4BytePtr
boost::intrusive_ptr< const As4Path > As4PathPtr
boost::intrusive_ptr< const AsPath > AsPathPtr
std::size_t hash_value(BgpAttr const &attr)
std::vector< BgpAttribute * > BgpAttrSpec
boost::intrusive_ptr< const BgpAttr > BgpAttrPtr
boost::intrusive_ptr< const OriginVnPath > OriginVnPathPtr
BgpAttrPtr ReplaceOriginatorIdAndLocate(const BgpAttr *attr, Ip4Address originator_id)
BgpAttrDB(BgpServer *server)
BgpAttrPtr ReplaceLocalPreferenceAndLocate(const BgpAttr *attr, uint32_t local_pref)
BgpAttrPtr ReplaceOListAndLocate(const BgpAttr *attr, const BgpOListSpec *olist_spec)
BgpAttrPtr ReplaceNexthopAndLocate(const BgpAttr *attr, const IpAddress &addr)
BgpAttrPtr ReplaceLeafOListAndLocate(const BgpAttr *attr, const BgpOListSpec *leaf_olist_spec)
BgpAttrPtr ReplaceSubProtocolAndLocate(const BgpAttr *attr, const std::string &sbp)
BgpAttrPtr ReplaceAsPathAndLocate(const BgpAttr *attr, AsPathPtr aspath)
BgpAttrPtr ReplaceOriginAndLocate(const BgpAttr *attr, BgpAttrOrigin::OriginType origin)
BgpAttrPtr ReplacePmsiTunnelAndLocate(const BgpAttr *attr, const PmsiTunnelSpec *pmsi_spec)
BgpAttrPtr ReplaceExtCommunityAndLocate(const BgpAttr *attr, ExtCommunityPtr extcomm)
BgpAttrPtr ReplaceSourceRdAndLocate(const BgpAttr *attr, const RouteDistinguisher &source_rd)
BgpAttrPtr ReplaceOriginVnPathAndLocate(const BgpAttr *attr, OriginVnPathPtr ovnpath)
BgpAttrPtr ReplaceLargeCommunityAndLocate(const BgpAttr *attr, LargeCommunityPtr largecomm)
BgpAttrPtr ReplaceEsiAndLocate(const BgpAttr *attr, const EthernetSegmentId &esi)
BgpAttrPtr ReplaceCommunityAndLocate(const BgpAttr *attr, CommunityPtr community)
void set_sub_protocol(const std::string &sub_protocol)
std::unique_ptr< LargeCommunitySpec > deferred_large_spec_
Ip4Address originator_id_
void set_aspath_4byte(AsPath4BytePtr aspath)
const AsPath * as_path() const
int as_path_count() const
void set_source_rd(const RouteDistinguisher &source_rd)
MacAddress mac_address() const
void set_community(CommunityPtr comm)
static BgpAttrOrigin::OriginType OriginFromString(const std::string &bgp_origin_type)
void set_params(uint64_t params)
bool IsAsPathEmpty() const
void set_leaf_olist(const BgpOListSpec *leaf_olist_spec)
std::atomic< int > refcount_
void set_esi(const EthernetSegmentId &esi)
IpAddress aggregator_address_
static std::string OriginToString(BgpAttrOrigin::OriginType origin)
RouteDistinguisher source_rd_
std::string origin_string() const
void set_edge_discovery(const EdgeDiscoverySpec *edspec)
void set_large_community(LargeCommunityPtr largecomm)
void set_as_path(AsPathPtr aspath)
void set_atomic_aggregate(bool ae)
OriginVnPathPtr origin_vn_path_
ExtCommunityPtr ext_community_
void set_med(uint32_t med)
void set_as4_path(As4PathPtr aspath)
void set_origin_vn_path(OriginVnPathPtr ovnpath)
BgpAttrOrigin::OriginType origin_
void set_edge_forwarding(const EdgeForwardingSpec *efspec)
EdgeForwardingPtr edge_forwarding_
int IsAsPathLoop(as_t asn, uint8_t max_loop_count=0) const
EdgeDiscoveryPtr edge_discovery_
LabelBlockPtr label_block() const
void set_local_pref(uint32_t local_pref)
LabelBlockPtr label_block_
bool evpn_sticky_mac() const
ClusterListPtr cluster_list_
uint32_t sequence_number() const
void set_origin(BgpAttrOrigin::OriginType org)
void set_as4_aggregator(as_t as_num, IpAddress address)
void set_cluster_list(const ClusterListSpec *spec)
AsPath4BytePtr aspath_4byte_
void set_aggregator(as_t as_num, IpAddress address)
void set_nexthop(IpAddress nexthop)
int aspath_4byte_count() const
void set_label_block(LabelBlockPtr label_block)
std::string sub_protocol_
bool evpn_single_active() const
int CompareTo(const BgpAttr &rhs) const
Address::Family nexthop_family() const
const AsPath4Byte * aspath_4byte() const
PmsiTunnelPtr pmsi_tunnel_
void set_ext_community(ExtCommunityPtr extcomm)
BgpAttrOrigin::OriginType origin() const
void set_originator_id(Ip4Address originator_id)
LargeCommunityPtr large_community_
int max_as_path_count() const
const As4Path * as4_path() const
void set_olist(const BgpOListSpec *olist_spec)
void set_pmsi_tunnel(const PmsiTunnelSpec *pmsi_spec)
virtual int CompareTo(const BgpAttribute &rhs) const
BgpOListDB(BgpServer *server)
bool operator<(const BgpOListElem &rhs) const
std::vector< std::string > encap
const BgpOListSpec & olist() const
BgpOList(BgpOListDB *olist_db, const BgpOListSpec &olist_spec)
const Elements & elements() const
std::atomic< int > refcount_
int CompareTo(const BgpOList &rhs) const
TypePtr Locate(Type *attr)
ExtCommunityDB * extcomm_db()
EdgeDiscoveryDB * edge_discovery_db()
AsPath4ByteDB * aspath_4byte_db()
PmsiTunnelDB * pmsi_tunnel_db()
EdgeForwardingDB * edge_forwarding_db()
OriginVnPathDB * ovnpath_db()
LargeCommunityDB * largecomm_db()
ClusterListDB * cluster_list_db()
ClusterListDB(BgpServer *server)
std::atomic< int > refcount_
ClusterListDB * cluster_list_db_
ClusterList(ClusterListDB *cluster_list_db, const ClusterListSpec &spec)
EdgeDiscoveryDB(BgpServer *server)
EdgeDiscoveryDB * edge_discovery_db_
EdgeDiscovery(EdgeDiscoveryDB *edge_discovery_db, const EdgeDiscoverySpec &edspec)
std::atomic< int > refcount_
EdgeDiscoverySpec edspec_
int CompareTo(const EdgeDiscovery &rhs) const
EdgeForwardingDB(BgpServer *server)
virtual ~EdgeForwarding()
EdgeForwarding(EdgeForwardingDB *edge_forwarding_db, const EdgeForwardingSpec &efspec)
int CompareTo(const EdgeForwarding &rhs) const
std::atomic< int > refcount_
EdgeForwardingSpec efspec_
EdgeForwardingDB * edge_forwarding_db_
bool single_active() const
std::string ToString() const
static const MacAddress kZeroMac
uint32_t sequence_number() const
PmsiTunnelDB(BgpServer *server)
PmsiTunnel(PmsiTunnelDB *pmsi_tunnel_db, const PmsiTunnelSpec &pmsi_spec)
uint32_t GetLabel(const ExtCommunity *ext) const
std::atomic< int > refcount_
PmsiTunnelSpec pmsi_spec_
PmsiTunnelDB * pmsi_tunnel_db_
std::string ToString() const
MacAddress mac_address() const
boost::intrusive_ptr< LabelBlock > LabelBlockPtr
static uint64_t get_value(const uint8_t *data, int size)
virtual std::string ToString() const
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual void ToCanonical(BgpAttr *attr)
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual void ToCanonical(BgpAttr *attr)
virtual std::string ToString() const
virtual void ToCanonical(BgpAttr *attr)
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual std::string ToString() const
virtual void ToCanonical(BgpAttr *attr)
virtual std::string ToString() const
virtual void ToCanonical(BgpAttr *attr)
virtual std::string ToString() const
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual std::string ToString() const
virtual void ToCanonical(BgpAttr *attr)
virtual int CompareTo(const BgpAttribute &rhs_attr) const
LabelBlockPtr label_block
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual std::string ToString() const
virtual void ToCanonical(BgpAttr *attr)
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual void ToCanonical(BgpAttr *attr)
virtual std::string ToString() const
virtual void ToCanonical(BgpAttr *attr)
virtual std::string ToString() const
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual std::string ToString() const
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual void ToCanonical(BgpAttr *attr)
virtual std::string ToString() const
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual void ToCanonical(BgpAttr *attr)
virtual void ToCanonical(BgpAttr *attr)
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual std::string ToString() const
virtual void ToCanonical(BgpAttr *attr)
virtual std::string ToString() const
virtual int CompareTo(const BgpAttribute &rhs_attr) const
RouteDistinguisher source_rd
virtual void ToCanonical(BgpAttr *attr)
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual std::string ToString() const
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual size_t EncodeLength() const
std::vector< BgpProtoPrefix * > nlri
std::vector< uint8_t > nexthop
virtual void ToCanonical(BgpAttr *attr)
int operator()(const BgpOListElem *lhs, const BgpOListElem *rhs) const
virtual void ToCanonical(BgpAttr *attr)
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual std::string ToString() const
bool ClusterListLoop(uint32_t cluster_id) const
virtual void ToCanonical(BgpAttr *attr)
virtual std::string ToString() const
virtual int CompareTo(const BgpAttribute &rhs) const
std::vector< uint32_t > cluster_list
int operator()(const EdgeDiscovery::Edge *lhs, const EdgeDiscovery::Edge *rhs) const
int operator()(const EdgeDiscoverySpec::Edge *lhs, const EdgeDiscoverySpec::Edge *rhs) const
void SetLabels(uint32_t first_label, uint32_t last_label)
void SetIp4Address(Ip4Address addr)
void GetLabels(uint32_t *first_label, uint32_t *last_label) const
Ip4Address GetIp4Address() const
std::vector< uint8_t > address
std::vector< uint32_t > labels
virtual void ToCanonical(BgpAttr *attr)
virtual size_t EncodeLength() const
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual std::string ToString() const
LabelBlockPtr label_block
Edge(const EdgeDiscoverySpec::Edge *edge_spec)
bool operator<(const Edge &rhs) const
int operator()(const EdgeForwarding::Edge *lhs, const EdgeForwarding::Edge *rhs) const
int operator()(const EdgeForwardingSpec::Edge *lhs, const EdgeForwardingSpec::Edge *rhs) const
Ip4Address GetOutboundIp4Address() const
std::vector< uint8_t > inbound_address
void SetOutboundIp4Address(Ip4Address addr)
void SetInboundIp4Address(Ip4Address addr)
Ip4Address GetInboundIp4Address() const
std::vector< uint8_t > outbound_address
virtual void ToCanonical(BgpAttr *attr)
virtual int CompareTo(const BgpAttribute &rhs_attr) const
virtual size_t EncodeLength() const
virtual std::string ToString() const
Edge(const EdgeForwardingSpec::Edge *edge_spec)
bool operator<(const Edge &rhs) const
Ip4Address outbound_address
Ip4Address inbound_address
std::string GetTunnelArTypeString() const
std::string GetTunnelTypeString() const
std::vector< std::string > GetTunnelFlagsStrings() const
virtual int CompareTo(const BgpAttribute &rhs_attr) const
@ AssistedReplicationType
@ EdgeReplicationSupported
virtual void ToCanonical(BgpAttr *attr)
Ip4Address GetIdentifier() const
std::vector< uint8_t > identifier
virtual std::string ToString() const
uint32_t GetLabel(const ExtCommunity *ext) const
@ AssistedReplicationContrail
void SetIdentifier(Ip4Address identifier)
void SetLabel(uint32_t label, const ExtCommunity *ext)
#define KEY_COMPARE(x, y)
int STLSortedCompare(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2, CompareOp op)
void STLDeleteValues(Container *container)
#define BOOL_KEY_COMPARE(x, y)