Skip to content

Commit

Permalink
Move RibExportPolicy methods to a new file
Browse files Browse the repository at this point in the history
Change-Id: Ib29965ef6cc94e70be5413bb177ef87b12c4f10a
Partial-Bug: 1548570
  • Loading branch information
Nischal Sheth committed Mar 17, 2016
1 parent 282fdd6 commit 4daa767
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 80 deletions.
1 change: 1 addition & 0 deletions src/bgp/SConscript
Expand Up @@ -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',
Expand Down
70 changes: 70 additions & 0 deletions 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;
}
36 changes: 5 additions & 31 deletions 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_
Expand Down Expand Up @@ -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;

Expand Down
49 changes: 0 additions & 49 deletions src/bgp/bgp_ribout.cc
Expand Up @@ -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)
Expand Down

0 comments on commit 4daa767

Please sign in to comment.