Line data Source code
1 : /*
2 : * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3 : * Copyright Contributors to the OpenSDN project
4 : */
5 :
6 : #include "bgp/bgp_rib_policy.h"
7 :
8 : using std::string;
9 : using std::vector;
10 :
11 288913 : RibExportPolicy::RemovePrivatePolicy::RemovePrivatePolicy()
12 288913 : : enabled(false),
13 288913 : all(false),
14 288913 : replace(false),
15 288913 : peer_loop_check(false) {
16 288913 : }
17 :
18 264089 : RibExportPolicy::RibExportPolicy()
19 264089 : : type(BgpProto::IBGP),
20 264089 : encoding(BGP),
21 264089 : as_number(0),
22 264089 : local_as_number(0),
23 264089 : as_override(false),
24 264088 : affinity(-1),
25 264088 : llgr(false),
26 264088 : as4_supported(false),
27 264089 : cluster_id(0) {
28 264088 : }
29 :
30 83 : RibExportPolicy::RibExportPolicy(uint32_t cluster_id)
31 83 : : type(BgpProto::IBGP),
32 83 : encoding(BGP),
33 83 : as_number(0),
34 83 : local_as_number(0),
35 83 : as_override(false),
36 83 : affinity(-1),
37 83 : llgr(false),
38 83 : as4_supported(false),
39 83 : cluster_id(cluster_id) {
40 83 : }
41 :
42 11062 : RibExportPolicy::RibExportPolicy(BgpProto::BgpPeerType type, Encoding encoding,
43 11062 : int affinity, uint32_t cluster_id)
44 11062 : : type(type),
45 11062 : encoding(encoding),
46 11062 : as_number(0),
47 11062 : local_as_number(0),
48 11062 : as_override(false),
49 11062 : affinity(affinity),
50 11062 : llgr(false),
51 11062 : as4_supported(false),
52 11062 : cluster_id(cluster_id) {
53 11062 : if (encoding == XMPP)
54 10870 : assert(type == BgpProto::XMPP);
55 11062 : if (encoding == BGP)
56 192 : assert(type == BgpProto::IBGP || type == BgpProto::EBGP);
57 11062 : }
58 :
59 724 : RibExportPolicy::RibExportPolicy(BgpProto::BgpPeerType type, Encoding encoding,
60 : as_t as_number, bool as_override, bool llgr, bool as4, int affinity,
61 724 : uint32_t cluster_id, as_t local_as_number)
62 724 : : type(type),
63 724 : encoding(encoding),
64 724 : as_number(as_number),
65 724 : local_as_number(local_as_number),
66 724 : as_override(as_override),
67 724 : affinity(affinity),
68 724 : llgr(llgr),
69 724 : as4_supported(as4),
70 724 : cluster_id(cluster_id) {
71 724 : if (encoding == XMPP)
72 8 : assert(type == BgpProto::XMPP);
73 724 : if (encoding == BGP)
74 716 : assert(type == BgpProto::IBGP || type == BgpProto::EBGP);
75 724 : }
76 :
77 :
78 12957 : RibExportPolicy::RibExportPolicy(BgpProto::BgpPeerType type, Encoding encoding,
79 : as_t as_number, bool as_override, bool llgr, bool as4, IpAddress nexthop,
80 : int affinity, uint32_t cluster_id,
81 12957 : vector<string> &default_tunnel_encap_list, as_t local_as_number) :
82 12957 : type(type),
83 12957 : encoding(BGP),
84 12957 : as_number(as_number),
85 12957 : local_as_number(local_as_number),
86 12957 : as_override(as_override),
87 12957 : nexthop(nexthop),
88 12958 : affinity(affinity),
89 12958 : llgr(llgr),
90 12958 : as4_supported(as4),
91 12958 : cluster_id(cluster_id),
92 12958 : default_tunnel_encap_list(default_tunnel_encap_list) {
93 12955 : assert(type == BgpProto::IBGP || type == BgpProto::EBGP);
94 12955 : assert(encoding == BGP);
95 12955 : }
96 :
97 115 : void RibExportPolicy::SetRemovePrivatePolicy(bool all, bool replace,
98 : bool peer_loop_check) {
99 115 : remove_private.enabled = true;
100 115 : remove_private.all = all;
101 115 : remove_private.replace = replace;
102 115 : remove_private.peer_loop_check = peer_loop_check;
103 115 : }
104 :
105 : //
106 : // Implement operator< for RibExportPolicy by comparing each of the fields.
107 : //
108 178457 : bool RibExportPolicy::operator<(const RibExportPolicy &rhs) const {
109 178457 : BOOL_KEY_COMPARE(encoding, rhs.encoding);
110 177074 : BOOL_KEY_COMPARE(type, rhs.type);
111 177003 : BOOL_KEY_COMPARE(as_number, rhs.as_number);
112 166521 : BOOL_KEY_COMPARE(local_as_number, rhs.local_as_number);
113 166521 : BOOL_KEY_COMPARE(as_override, rhs.as_override);
114 166514 : BOOL_KEY_COMPARE(nexthop, rhs.nexthop);
115 166180 : BOOL_KEY_COMPARE(affinity, rhs.affinity);
116 166123 : BOOL_KEY_COMPARE(llgr, rhs.llgr);
117 166116 : BOOL_KEY_COMPARE(as4_supported, rhs.as4_supported);
118 166116 : BOOL_KEY_COMPARE(cluster_id, rhs.cluster_id);
119 165860 : BOOL_KEY_COMPARE(remove_private.enabled, rhs.remove_private.enabled);
120 165860 : BOOL_KEY_COMPARE(remove_private.all, rhs.remove_private.all);
121 165860 : BOOL_KEY_COMPARE(remove_private.replace, rhs.remove_private.replace);
122 165860 : BOOL_KEY_COMPARE(
123 : remove_private.peer_loop_check, rhs.remove_private.peer_loop_check);
124 165860 : BOOL_KEY_COMPARE(default_tunnel_encap_list, rhs.default_tunnel_encap_list);
125 165860 : return false;
126 : }
|