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 289429 : RibExportPolicy::RemovePrivatePolicy::RemovePrivatePolicy()
12 289429 : : enabled(false),
13 289429 : all(false),
14 289429 : replace(false),
15 289429 : peer_loop_check(false) {
16 289429 : }
17 :
18 264544 : RibExportPolicy::RibExportPolicy()
19 264544 : : type(BgpProto::IBGP),
20 264544 : encoding(BGP),
21 264544 : as_number(0),
22 264544 : local_as_number(0),
23 264544 : as_override(false),
24 264546 : affinity(-1),
25 264546 : llgr(false),
26 264546 : as4_supported(false),
27 264544 : cluster_id(0) {
28 264546 : }
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 11056 : RibExportPolicy::RibExportPolicy(BgpProto::BgpPeerType type, Encoding encoding,
43 11056 : int affinity, uint32_t cluster_id)
44 11056 : : type(type),
45 11056 : encoding(encoding),
46 11056 : as_number(0),
47 11056 : local_as_number(0),
48 11056 : as_override(false),
49 11057 : affinity(affinity),
50 11057 : llgr(false),
51 11057 : as4_supported(false),
52 11056 : cluster_id(cluster_id) {
53 11057 : if (encoding == XMPP)
54 10865 : assert(type == BgpProto::XMPP);
55 11057 : if (encoding == BGP)
56 192 : assert(type == BgpProto::IBGP || type == BgpProto::EBGP);
57 11057 : }
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 13017 : 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 13017 : vector<string> &default_tunnel_encap_list, as_t local_as_number) :
82 13017 : type(type),
83 13017 : encoding(BGP),
84 13017 : as_number(as_number),
85 13017 : local_as_number(local_as_number),
86 13017 : as_override(as_override),
87 13017 : nexthop(nexthop),
88 13021 : affinity(affinity),
89 13021 : llgr(llgr),
90 13021 : as4_supported(as4),
91 13021 : cluster_id(cluster_id),
92 13021 : default_tunnel_encap_list(default_tunnel_encap_list) {
93 13013 : assert(type == BgpProto::IBGP || type == BgpProto::EBGP);
94 13013 : assert(encoding == BGP);
95 13013 : }
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 178444 : bool RibExportPolicy::operator<(const RibExportPolicy &rhs) const {
109 178444 : BOOL_KEY_COMPARE(encoding, rhs.encoding);
110 177052 : BOOL_KEY_COMPARE(type, rhs.type);
111 176982 : BOOL_KEY_COMPARE(as_number, rhs.as_number);
112 166701 : BOOL_KEY_COMPARE(local_as_number, rhs.local_as_number);
113 166701 : BOOL_KEY_COMPARE(as_override, rhs.as_override);
114 166694 : BOOL_KEY_COMPARE(nexthop, rhs.nexthop);
115 166360 : BOOL_KEY_COMPARE(affinity, rhs.affinity);
116 166303 : BOOL_KEY_COMPARE(llgr, rhs.llgr);
117 166296 : BOOL_KEY_COMPARE(as4_supported, rhs.as4_supported);
118 166296 : BOOL_KEY_COMPARE(cluster_id, rhs.cluster_id);
119 166040 : BOOL_KEY_COMPARE(remove_private.enabled, rhs.remove_private.enabled);
120 166040 : BOOL_KEY_COMPARE(remove_private.all, rhs.remove_private.all);
121 166040 : BOOL_KEY_COMPARE(remove_private.replace, rhs.remove_private.replace);
122 166040 : BOOL_KEY_COMPARE(
123 : remove_private.peer_loop_check, rhs.remove_private.peer_loop_check);
124 166040 : BOOL_KEY_COMPARE(default_tunnel_encap_list, rhs.default_tunnel_encap_list);
125 166040 : return false;
126 : }
|