Skip to content

Commit

Permalink
Move definition of RibExportPolicy to separate file
Browse files Browse the repository at this point in the history
Change-Id: I9e1bfeb7cf24b76b35528cf3e68d7e0db544ac42
Partial-Bug: 1548570
  • Loading branch information
Nischal Sheth committed Mar 16, 2016
1 parent fdb705e commit dd21d19
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 81 deletions.
1 change: 1 addition & 0 deletions src/bgp/bgp_message_builder.cc
Expand Up @@ -7,6 +7,7 @@
#include <vector>

#include "bgp/bgp_log.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_route.h"
#include "bgp/bgp_server.h"
#include "net/bgp_af.h"
Expand Down
2 changes: 1 addition & 1 deletion src/bgp/bgp_peer.h
Expand Up @@ -22,7 +22,7 @@
#include "bgp/bgp_debug.h"
#include "bgp/bgp_peer_key.h"
#include "bgp/bgp_proto.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_rib_policy.h"
#include "bgp/ipeer.h"
#include "bgp/bgp_peer_close.h"
#include "bgp/state_machine.h"
Expand Down
1 change: 1 addition & 0 deletions src/bgp/bgp_peer_membership.cc
Expand Up @@ -12,6 +12,7 @@
#include "bgp/bgp_log.h"
#include "bgp/bgp_peer_close.h"
#include "bgp/bgp_peer_types.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_ribout_updates.h"
#include "bgp/bgp_route.h"
#include "bgp/routing-instance/routing_instance.h"
Expand Down
2 changes: 1 addition & 1 deletion src/bgp/bgp_peer_membership.h
Expand Up @@ -14,7 +14,7 @@
#include "base/util.h"
#include "base/queue_task.h"
#include "db/db_table_walker.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_rib_policy.h"
#include "bgp/bgp_server.h"
#include "bgp/bgp_table.h"

Expand Down
84 changes: 84 additions & 0 deletions src/bgp/bgp_rib_policy.h
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/

#ifndef SRC_BGP_BGP_RIB_POLICY_H_
#define SRC_BGP_BGP_RIB_POLICY_H_

#include "bgp/bgp_proto.h"

//
// This class represents the export policy for a rib. Given that we do not
// currently support any real policy configuration, this is pretty trivial
// for now.
//
// Including the AS number as part of the policy results in creation of a
// different RibOut for every neighbor AS that we peer with. This allows a
// simplified implementation of the sender side AS path loop check. In most
// practical deployment scenarios all eBGP peers will belong to the same
// neighbor AS anyway.
//
// Including AS override as part of the policy results in creation of a
// different RibOuts for neighbors that need and don't AS override.
//
// Including the nexthop as part of the policy results in creation of a
// different RibOut for each set of BGPaaS clients that belong to the same
// subnet. This allows us to rewrite the nexthop to the specified value.
//
// Including the CPU affinity as part of the RibExportPolicy allows us to
// artificially create more RibOuts than otherwise necessary. This is used
// to achieve higher concurrency at the expense of creating more state.
//
struct RibExportPolicy {
enum Encoding {
BGP,
XMPP,
};

RibExportPolicy()
: type(BgpProto::IBGP), encoding(BGP),
as_number(0), as_override(false), affinity(-1), cluster_id(0) {
}

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(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(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);
}

bool operator<(const RibExportPolicy &rhs) const;

BgpProto::BgpPeerType type;
Encoding encoding;
as_t as_number;
bool as_override;
IpAddress nexthop;
int affinity;
uint32_t cluster_id;
};

#endif // SRC_BGP_BGP_RIB_POLICY_H_
75 changes: 1 addition & 74 deletions src/bgp/bgp_ribout.h
Expand Up @@ -16,6 +16,7 @@
#include "base/index_map.h"
#include "bgp/bgp_attr.h"
#include "bgp/bgp_proto.h"
#include "bgp/bgp_rib_policy.h"
#include "db/db_entry.h"
#include "net/tunnel_encap_type.h"

Expand Down Expand Up @@ -207,80 +208,6 @@ class RouteState : public DBState {
DISALLOW_COPY_AND_ASSIGN(RouteState);
};

//
// This class represents the export policy for a rib. Given that we do not
// currently support any real policy configuration, this is pretty trivial
// for now.
//
// Including the AS number as part of the policy results in creation of a
// different RibOut for every neighbor AS that we peer with. This allows a
// simplified implementation of the sender side AS path loop check. In most
// practical deployment scenarios all eBGP peers will belong to the same
// neighbor AS anyway.
//
// Including AS override as part of the policy results in creation of a
// different RibOuts for neighbors that need and don't AS override.
//
// Including the nexthop as part of the policy results in creation of a
// different RibOut for each set of BGPaaS clients that belong to the same
// subnet. This allows us to rewrite the nexthop to the specified value.
//
// Including the CPU affinity as part of the RibExportPolicy allows us to
// artificially create more RibOuts than otherwise necessary. This is used
// to achieve higher concurrency at the expense of creating more state.
//
struct RibExportPolicy {
enum Encoding {
BGP,
XMPP,
};

RibExportPolicy()
: type(BgpProto::IBGP), encoding(BGP),
as_number(0), as_override(false), affinity(-1), cluster_id(0) {
}

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(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(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);
}

bool operator<(const RibExportPolicy &rhs) const;

BgpProto::BgpPeerType type;
Encoding encoding;
as_t as_number;
bool as_override;
IpAddress nexthop;
int affinity;
uint32_t cluster_id;
};

//
// This class represents per-table state for a collection of peers with the
// same export policy. It is effectively a combination of RibExportPolicy
Expand Down
1 change: 1 addition & 0 deletions src/bgp/bgp_ribout_updates.cc
Expand Up @@ -6,6 +6,7 @@

#include "base/task_annotations.h"
#include "bgp/bgp_log.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_route.h"
#include "bgp/bgp_update_queue.h"
#include "bgp/bgp_update_monitor.h"
Expand Down
8 changes: 7 additions & 1 deletion src/bgp/bgp_ribout_updates.h
Expand Up @@ -5,14 +5,20 @@
#ifndef SRC_BGP_BGP_RIBOUT_UPDATES_H_
#define SRC_BGP_BGP_RIBOUT_UPDATES_H_

#include <boost/scoped_ptr.hpp>

#include <vector>

#include "bgp/bgp_ribout.h"
#include "base/util.h"

class BgpTable;
class DBEntryBase;
class IPeerUpdate;
class Message;
class MessageBuilder;
class RibPeerSet;
class RibUpdateMonitor;
class RibOut;
class RouteUpdate;
class RouteUpdatePtr;
class UpdateQueue;
Expand Down
1 change: 1 addition & 0 deletions src/bgp/bgp_table.cc
Expand Up @@ -8,6 +8,7 @@

#include "base/task_annotations.h"
#include "bgp/bgp_log.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_ribout_updates.h"
#include "bgp/bgp_route.h"
#include "bgp/bgp_server.h"
Expand Down
5 changes: 4 additions & 1 deletion src/bgp/bgp_table.h
Expand Up @@ -12,15 +12,18 @@
#include <vector>

#include "base/lifetime.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_rib_policy.h"
#include "db/db_table_walker.h"
#include "route/table.h"

class BgpServer;
class BgpRoute;
class BgpPath;
class IPeer;
class Path;
class PathResolver;
class RibOut;
class RibPeerSet;
class Route;
class RoutingInstance;
class SchedulingGroupManager;
Expand Down
2 changes: 1 addition & 1 deletion src/bgp/bgp_xmpp_channel.h
Expand Up @@ -15,7 +15,7 @@
#include <utility>

#include "base/queue_task.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_rib_policy.h"
#include "bgp/routing-instance/routing_instance.h"
#include "io/tcp_session.h"
#include "net/rd.h"
Expand Down
11 changes: 9 additions & 2 deletions src/bgp/message_builder.h
Expand Up @@ -5,11 +5,14 @@
#ifndef SRC_BGP_MESSAGE_BUILDER_H_
#define SRC_BGP_MESSAGE_BUILDER_H_

#include "bgp/bgp_ribout.h"
#include "bgp/bgp_rib_policy.h"

class BgpRoute;
class BgpMessageBuilder;
class BgpRoute;
class BgpTable;
class BgpXmppMessageBuilder;
class IPeerUpdate;
class RibOutAttr;

class Message {
public:
Expand All @@ -26,9 +29,13 @@ class Message {
uint32_t num_unreach_routes() const {
return num_unreach_route_;
}

protected:
uint32_t num_reach_route_;
uint32_t num_unreach_route_;

private:
DISALLOW_COPY_AND_ASSIGN(Message);
};

class MessageBuilder {
Expand Down
1 change: 1 addition & 0 deletions src/bgp/routing-instance/rtarget_group_mgr.cc
Expand Up @@ -13,6 +13,7 @@
#include "base/task_trigger.h"
#include "bgp/bgp_config.h"
#include "bgp/bgp_peer.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_server.h"
#include "bgp/bgp_table.h"
#include "bgp/routing-instance/routing_instance.h"
Expand Down
1 change: 1 addition & 0 deletions src/bgp/scheduling_group.cc
Expand Up @@ -12,6 +12,7 @@
#include "base/task_annotations.h"
#include "bgp/bgp_factory.h"
#include "bgp/bgp_log.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_ribout_updates.h"

using std::auto_ptr;
Expand Down
1 change: 1 addition & 0 deletions src/bgp/test/bgp_msg_builder_test.cc
Expand Up @@ -8,6 +8,7 @@
#include "bgp/bgp_factory.h"
#include "bgp/bgp_log.h"
#include "bgp/bgp_peer.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_server.h"
#include "bgp/l3vpn/inetvpn_route.h"
#include "bgp/bgp_message_builder.h"
Expand Down
1 change: 1 addition & 0 deletions src/bgp/test/bgp_sg_test.cc
Expand Up @@ -11,6 +11,7 @@
#include "base/test/task_test_util.h"
#include "bgp/bgp_factory.h"
#include "bgp/bgp_log.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_ribout_updates.h"
#include "bgp/bgp_server.h"
#include "bgp/inet/inet_table.h"
Expand Down
1 change: 1 addition & 0 deletions src/bgp/test/ribout_attributes_test.cc
Expand Up @@ -5,6 +5,7 @@
#include "base/test/task_test_util.h"

#include "bgp/bgp_log.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_server.h"
#include "bgp/extended-community/mac_mobility.h"
#include "bgp/inet/inet_route.h"
Expand Down
1 change: 1 addition & 0 deletions src/bgp/test/scheduling_group_test.cc
Expand Up @@ -8,6 +8,7 @@
#include "base/test/task_test_util.h"
#include "control-node/control_node.h"
#include "bgp/bgp_log.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_ribout_updates.h"
#include "bgp/scheduling_group.h"
#include "bgp/l3vpn/inetvpn_table.h"
Expand Down
1 change: 1 addition & 0 deletions src/bgp/xmpp_message_builder.cc
Expand Up @@ -11,6 +11,7 @@
#include <vector>

#include "bgp/ipeer.h"
#include "bgp/bgp_ribout.h"
#include "bgp/bgp_server.h"
#include "bgp/bgp_table.h"
#include "bgp/extended-community/load_balance.h"
Expand Down

0 comments on commit dd21d19

Please sign in to comment.