From dd21d19e54b28faff0aac268fd0c8fa7e9f0a927 Mon Sep 17 00:00:00 2001 From: Nischal Sheth Date: Mon, 14 Mar 2016 13:17:53 -0700 Subject: [PATCH] Move definition of RibExportPolicy to separate file Change-Id: I9e1bfeb7cf24b76b35528cf3e68d7e0db544ac42 Partial-Bug: 1548570 --- src/bgp/bgp_message_builder.cc | 1 + src/bgp/bgp_peer.h | 2 +- src/bgp/bgp_peer_membership.cc | 1 + src/bgp/bgp_peer_membership.h | 2 +- src/bgp/bgp_rib_policy.h | 84 +++++++++++++++++++ src/bgp/bgp_ribout.h | 75 +---------------- src/bgp/bgp_ribout_updates.cc | 1 + src/bgp/bgp_ribout_updates.h | 8 +- src/bgp/bgp_table.cc | 1 + src/bgp/bgp_table.h | 5 +- src/bgp/bgp_xmpp_channel.h | 2 +- src/bgp/message_builder.h | 11 ++- src/bgp/routing-instance/rtarget_group_mgr.cc | 1 + src/bgp/scheduling_group.cc | 1 + src/bgp/test/bgp_msg_builder_test.cc | 1 + src/bgp/test/bgp_sg_test.cc | 1 + src/bgp/test/ribout_attributes_test.cc | 1 + src/bgp/test/scheduling_group_test.cc | 1 + src/bgp/xmpp_message_builder.cc | 1 + 19 files changed, 119 insertions(+), 81 deletions(-) create mode 100644 src/bgp/bgp_rib_policy.h diff --git a/src/bgp/bgp_message_builder.cc b/src/bgp/bgp_message_builder.cc index ed4b12f1793..6e5bf69a6d2 100644 --- a/src/bgp/bgp_message_builder.cc +++ b/src/bgp/bgp_message_builder.cc @@ -7,6 +7,7 @@ #include #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" diff --git a/src/bgp/bgp_peer.h b/src/bgp/bgp_peer.h index f10b93d2773..1e7530f8cc3 100644 --- a/src/bgp/bgp_peer.h +++ b/src/bgp/bgp_peer.h @@ -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" diff --git a/src/bgp/bgp_peer_membership.cc b/src/bgp/bgp_peer_membership.cc index e4425b45434..455f8c81ae8 100644 --- a/src/bgp/bgp_peer_membership.cc +++ b/src/bgp/bgp_peer_membership.cc @@ -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" diff --git a/src/bgp/bgp_peer_membership.h b/src/bgp/bgp_peer_membership.h index 9d331621578..48da1a1b8b2 100644 --- a/src/bgp/bgp_peer_membership.h +++ b/src/bgp/bgp_peer_membership.h @@ -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" diff --git a/src/bgp/bgp_rib_policy.h b/src/bgp/bgp_rib_policy.h new file mode 100644 index 00000000000..d7256e0dd37 --- /dev/null +++ b/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_ diff --git a/src/bgp/bgp_ribout.h b/src/bgp/bgp_ribout.h index 221a265774f..8e1cdecead4 100644 --- a/src/bgp/bgp_ribout.h +++ b/src/bgp/bgp_ribout.h @@ -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" @@ -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 diff --git a/src/bgp/bgp_ribout_updates.cc b/src/bgp/bgp_ribout_updates.cc index 62ebfa72e21..b993613a197 100644 --- a/src/bgp/bgp_ribout_updates.cc +++ b/src/bgp/bgp_ribout_updates.cc @@ -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" diff --git a/src/bgp/bgp_ribout_updates.h b/src/bgp/bgp_ribout_updates.h index a5db8f3682c..3faeabe26ef 100644 --- a/src/bgp/bgp_ribout_updates.h +++ b/src/bgp/bgp_ribout_updates.h @@ -5,14 +5,20 @@ #ifndef SRC_BGP_BGP_RIBOUT_UPDATES_H_ #define SRC_BGP_BGP_RIBOUT_UPDATES_H_ +#include + #include -#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; diff --git a/src/bgp/bgp_table.cc b/src/bgp/bgp_table.cc index 9eb7361be08..064015dc523 100644 --- a/src/bgp/bgp_table.cc +++ b/src/bgp/bgp_table.cc @@ -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" diff --git a/src/bgp/bgp_table.h b/src/bgp/bgp_table.h index 42f7d51ded1..02984e6feb7 100644 --- a/src/bgp/bgp_table.h +++ b/src/bgp/bgp_table.h @@ -12,15 +12,18 @@ #include #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; diff --git a/src/bgp/bgp_xmpp_channel.h b/src/bgp/bgp_xmpp_channel.h index aa1cc9a29ff..3f8a2ff4cea 100644 --- a/src/bgp/bgp_xmpp_channel.h +++ b/src/bgp/bgp_xmpp_channel.h @@ -15,7 +15,7 @@ #include #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" diff --git a/src/bgp/message_builder.h b/src/bgp/message_builder.h index 46d3e2e8a26..0856a1f1473 100644 --- a/src/bgp/message_builder.h +++ b/src/bgp/message_builder.h @@ -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: @@ -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 { diff --git a/src/bgp/routing-instance/rtarget_group_mgr.cc b/src/bgp/routing-instance/rtarget_group_mgr.cc index 9da2457492f..5b6b652bfdf 100644 --- a/src/bgp/routing-instance/rtarget_group_mgr.cc +++ b/src/bgp/routing-instance/rtarget_group_mgr.cc @@ -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" diff --git a/src/bgp/scheduling_group.cc b/src/bgp/scheduling_group.cc index 43130d4acbb..dacc1c41f73 100644 --- a/src/bgp/scheduling_group.cc +++ b/src/bgp/scheduling_group.cc @@ -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; diff --git a/src/bgp/test/bgp_msg_builder_test.cc b/src/bgp/test/bgp_msg_builder_test.cc index 742649871db..0152b9d0a6d 100644 --- a/src/bgp/test/bgp_msg_builder_test.cc +++ b/src/bgp/test/bgp_msg_builder_test.cc @@ -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" diff --git a/src/bgp/test/bgp_sg_test.cc b/src/bgp/test/bgp_sg_test.cc index a6b96df7b2b..7a31e6fa9ae 100644 --- a/src/bgp/test/bgp_sg_test.cc +++ b/src/bgp/test/bgp_sg_test.cc @@ -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" diff --git a/src/bgp/test/ribout_attributes_test.cc b/src/bgp/test/ribout_attributes_test.cc index ff44c66abce..fe2ba205cc1 100644 --- a/src/bgp/test/ribout_attributes_test.cc +++ b/src/bgp/test/ribout_attributes_test.cc @@ -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" diff --git a/src/bgp/test/scheduling_group_test.cc b/src/bgp/test/scheduling_group_test.cc index 7b56eafaaae..a7591800f5b 100644 --- a/src/bgp/test/scheduling_group_test.cc +++ b/src/bgp/test/scheduling_group_test.cc @@ -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" diff --git a/src/bgp/xmpp_message_builder.cc b/src/bgp/xmpp_message_builder.cc index 336971da51a..2558fe70ef1 100644 --- a/src/bgp/xmpp_message_builder.cc +++ b/src/bgp/xmpp_message_builder.cc @@ -11,6 +11,7 @@ #include #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"