diff --git a/src/bgp/SConscript b/src/bgp/SConscript index 214bcb88f07..7a080dd22e5 100644 --- a/src/bgp/SConscript +++ b/src/bgp/SConscript @@ -51,6 +51,7 @@ libbgp = env.Library('bgp', 'bgp_peer_key.cc', 'bgp_peer_membership.cc', 'bgp_proto.cc', + 'bgp_rib_policy.cc', 'bgp_ribout.cc', 'bgp_ribout_updates.cc', 'bgp_route.cc', diff --git a/src/bgp/bgp_rib_policy.cc b/src/bgp/bgp_rib_policy.cc new file mode 100644 index 00000000000..7fe9c13d501 --- /dev/null +++ b/src/bgp/bgp_rib_policy.cc @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. + */ + +#include "bgp/bgp_rib_policy.h" + +RibExportPolicy::RibExportPolicy() + : type(BgpProto::IBGP), + encoding(BGP), + as_number(0), + as_override(false), + affinity(-1), + cluster_id(0) { +} + +RibExportPolicy::RibExportPolicy(BgpProto::BgpPeerType type, Encoding encoding, + int affinity, u_int32_t cluster_id) + : type(type), + encoding(encoding), + as_number(0), + as_override(false), + affinity(affinity), + cluster_id(cluster_id) { + if (encoding == XMPP) + assert(type == BgpProto::XMPP); + if (encoding == BGP) + assert(type == BgpProto::IBGP || type == BgpProto::EBGP); +} + +RibExportPolicy::RibExportPolicy(BgpProto::BgpPeerType type, Encoding encoding, + as_t as_number, bool as_override, int affinity, u_int32_t cluster_id) + : type(type), + encoding(encoding), + as_number(as_number), + as_override(as_override), + affinity(affinity), + cluster_id(cluster_id) { + if (encoding == XMPP) + assert(type == BgpProto::XMPP); + if (encoding == BGP) + assert(type == BgpProto::IBGP || type == BgpProto::EBGP); +} + +RibExportPolicy::RibExportPolicy(BgpProto::BgpPeerType type, Encoding encoding, + as_t as_number, bool as_override, IpAddress nexthop, int affinity, + u_int32_t cluster_id) + : type(type), + encoding(BGP), + as_number(as_number), + as_override(as_override), + nexthop(nexthop), + affinity(affinity), + cluster_id(cluster_id) { + assert(type == BgpProto::IBGP || type == BgpProto::EBGP); + assert(encoding == BGP); +} + +// +// Implement operator< for RibExportPolicy by comparing each of the fields. +// +bool RibExportPolicy::operator<(const RibExportPolicy &rhs) const { + BOOL_KEY_COMPARE(encoding, rhs.encoding); + BOOL_KEY_COMPARE(type, rhs.type); + BOOL_KEY_COMPARE(as_number, rhs.as_number); + BOOL_KEY_COMPARE(as_override, rhs.as_override); + BOOL_KEY_COMPARE(nexthop, rhs.nexthop); + BOOL_KEY_COMPARE(affinity, rhs.affinity); + BOOL_KEY_COMPARE(cluster_id, rhs.cluster_id); + return false; +} diff --git a/src/bgp/bgp_rib_policy.h b/src/bgp/bgp_rib_policy.h index d7256e0dd37..2fd9d4f5e39 100644 --- a/src/bgp/bgp_rib_policy.h +++ b/src/bgp/bgp_rib_policy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. + * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. */ #ifndef SRC_BGP_BGP_RIB_POLICY_H_ @@ -35,40 +35,14 @@ struct RibExportPolicy { XMPP, }; - RibExportPolicy() - : type(BgpProto::IBGP), encoding(BGP), - as_number(0), as_override(false), affinity(-1), cluster_id(0) { - } - + RibExportPolicy(); RibExportPolicy(BgpProto::BgpPeerType type, Encoding encoding, - int affinity, u_int32_t cluster_id) - : type(type), encoding(encoding), as_number(0), as_override(false), - affinity(affinity), cluster_id(cluster_id) { - if (encoding == XMPP) - assert(type == BgpProto::XMPP); - if (encoding == BGP) - assert(type == BgpProto::IBGP || type == BgpProto::EBGP); - } - + int affinity, u_int32_t cluster_id); RibExportPolicy(BgpProto::BgpPeerType type, Encoding encoding, - as_t as_number, bool as_override, int affinity, u_int32_t cluster_id) - : type(type), encoding(encoding), as_number(as_number), - as_override(as_override), affinity(affinity), cluster_id(cluster_id) { - if (encoding == XMPP) - assert(type == BgpProto::XMPP); - if (encoding == BGP) - assert(type == BgpProto::IBGP || type == BgpProto::EBGP); - } - + as_t as_number, bool as_override, int affinity, u_int32_t cluster_id); RibExportPolicy(BgpProto::BgpPeerType type, Encoding encoding, as_t as_number, bool as_override, IpAddress nexthop, - int affinity, u_int32_t cluster_id) - : type(type), encoding(BGP), as_number(as_number), - as_override(as_override), nexthop(nexthop), - affinity(affinity), cluster_id(cluster_id) { - assert(type == BgpProto::IBGP || type == BgpProto::EBGP); - assert(encoding == BGP); - } + int affinity, u_int32_t cluster_id); bool operator<(const RibExportPolicy &rhs) const; diff --git a/src/bgp/bgp_ribout.cc b/src/bgp/bgp_ribout.cc index f0bd9de0d4e..a9b50412e8d 100644 --- a/src/bgp/bgp_ribout.cc +++ b/src/bgp/bgp_ribout.cc @@ -19,55 +19,6 @@ using std::find; -// -// Implement operator< for RibExportPolicy by comparing each of the fields. -// -bool RibExportPolicy::operator<(const RibExportPolicy &rhs) const { - if (encoding < rhs.encoding) { - return true; - } - if (encoding > rhs.encoding) { - return false; - } - if (type < rhs.type) { - return true; - } - if (type > rhs.type) { - return false; - } - if (as_number < rhs.as_number) { - return true; - } - if (as_number > rhs.as_number) { - return false; - } - if (as_override < rhs.as_override) { - return true; - } - if (as_override > rhs.as_override) { - return false; - } - if (nexthop < rhs.nexthop) { - return true; - } - if (nexthop > rhs.nexthop) { - return false; - } - if (affinity < rhs.affinity) { - return true; - } - if (affinity > rhs.affinity) { - return false; - } - if (cluster_id < rhs.cluster_id) { - return true; - } - if (cluster_id > rhs.cluster_id) { - return false; - } - return false; -} - RibOutAttr::NextHop::NextHop(const BgpTable *table, IpAddress address, uint32_t label, const ExtCommunity *ext_community, bool vrf_originated)