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 290025 : RibExportPolicy::RemovePrivatePolicy::RemovePrivatePolicy()
12 290025 : : enabled(false),
13 290025 : all(false),
14 290025 : replace(false),
15 290025 : peer_loop_check(false) {
16 290025 : }
17 :
18 265014 : RibExportPolicy::RibExportPolicy()
19 265014 : : type(BgpProto::IBGP),
20 265014 : encoding(BGP),
21 265014 : as_number(0),
22 265014 : local_as_number(0),
23 265014 : as_override(false),
24 265015 : affinity(-1),
25 265015 : llgr(false),
26 265015 : as4_supported(false),
27 265014 : cluster_id(0) {
28 265016 : }
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 11061 : RibExportPolicy::RibExportPolicy(BgpProto::BgpPeerType type, Encoding encoding,
43 11061 : int affinity, uint32_t cluster_id)
44 11061 : : type(type),
45 11061 : encoding(encoding),
46 11061 : as_number(0),
47 11061 : local_as_number(0),
48 11061 : as_override(false),
49 11061 : affinity(affinity),
50 11061 : llgr(false),
51 11061 : as4_supported(false),
52 11061 : cluster_id(cluster_id) {
53 11061 : if (encoding == XMPP)
54 10869 : assert(type == BgpProto::XMPP);
55 11061 : if (encoding == BGP)
56 192 : assert(type == BgpProto::IBGP || type == BgpProto::EBGP);
57 11061 : }
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 13139 : 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 13139 : vector<string> &default_tunnel_encap_list, as_t local_as_number) :
82 13139 : type(type),
83 13139 : encoding(BGP),
84 13139 : as_number(as_number),
85 13139 : local_as_number(local_as_number),
86 13139 : as_override(as_override),
87 13139 : nexthop(nexthop),
88 13141 : affinity(affinity),
89 13141 : llgr(llgr),
90 13141 : as4_supported(as4),
91 13141 : cluster_id(cluster_id),
92 13141 : default_tunnel_encap_list(default_tunnel_encap_list) {
93 13138 : assert(type == BgpProto::IBGP || type == BgpProto::EBGP);
94 13138 : assert(encoding == BGP);
95 13138 : }
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 178950 : bool RibExportPolicy::operator<(const RibExportPolicy &rhs) const {
109 178950 : BOOL_KEY_COMPARE(encoding, rhs.encoding);
110 177567 : BOOL_KEY_COMPARE(type, rhs.type);
111 177494 : BOOL_KEY_COMPARE(as_number, rhs.as_number);
112 166894 : BOOL_KEY_COMPARE(local_as_number, rhs.local_as_number);
113 166894 : BOOL_KEY_COMPARE(as_override, rhs.as_override);
114 166887 : BOOL_KEY_COMPARE(nexthop, rhs.nexthop);
115 166553 : BOOL_KEY_COMPARE(affinity, rhs.affinity);
116 166495 : BOOL_KEY_COMPARE(llgr, rhs.llgr);
117 166488 : BOOL_KEY_COMPARE(as4_supported, rhs.as4_supported);
118 166488 : BOOL_KEY_COMPARE(cluster_id, rhs.cluster_id);
119 166232 : BOOL_KEY_COMPARE(remove_private.enabled, rhs.remove_private.enabled);
120 166232 : BOOL_KEY_COMPARE(remove_private.all, rhs.remove_private.all);
121 166232 : BOOL_KEY_COMPARE(remove_private.replace, rhs.remove_private.replace);
122 166232 : BOOL_KEY_COMPARE(
123 : remove_private.peer_loop_check, rhs.remove_private.peer_loop_check);
124 166232 : BOOL_KEY_COMPARE(default_tunnel_encap_list, rhs.default_tunnel_encap_list);
125 166232 : return false;
126 : }
|