-
Notifications
You must be signed in to change notification settings - Fork 390
/
controller_route_path.h
279 lines (256 loc) · 10.8 KB
/
controller_route_path.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
* Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
*/
#ifndef controller_route_path_hpp
#define controller_route_path_hpp
#include <cmn/agent_cmn.h>
#include <cmn/agent.h>
#include <oper/route_common.h>
//Forward declaration
class AgentXmppChannel;
class AgentRouteData;
class EcmpLoadBalance;
class Peer;
class BgpPeer;
class TunnelNHKey;
class TunnelNHData;
class TunnelType;
class ControllerVmRoute;
class LocalVmRoute;
class InetInterfaceRoute;
class VlanNhRoute;
class VNController;
/*
* Contains all Controller Route data definition.
* Currently there are four kind of routes added from controller:
* - Remote - Native to controller, derived from ControllerPeerPath
* - Local - Derived from LocalVmRoute of agent_path
* - Vlan - Derived from VlanNHRoute from agent_path
* - Inet Interface - Derived from InetInterfaceRoute from agent_path.
*
* All route data passed from controller with peer type BGP, should
* carry AgentXmppChannel and unicast_sequence_number. This is required
* because BGP peer can go off by the time request for add/change/delete of
* route is enqueued in DB. At Route input every data is checked for peer
* validitiy. BGP peer will be valid if AgentXmppChannel is still up and
* sequence number matches.
*
* ControllerPeerPath implements sequence number and agent_xmpp_channel,
* so if there is native controller data it can be derived from same.
*
* In case data is derived from agent_path datas, then he derivative needs to
* carry info on AgentXmppChannel and sequence number and has to implement
* check for peer validity.
*/
class ControllerPeerPath : public AgentRouteData {
public:
static const uint64_t kInvalidPeerIdentifier = 0xFFFFFFFFFFFFFFFFLL;
ControllerPeerPath(const Peer *peer);
~ControllerPeerPath() { }
virtual bool UpdateRoute(AgentRoute *route) {return false;}
// Only to be used for tests
void set_sequence_number(uint64_t sequence_number) {
sequence_number_ = sequence_number;
}
const AgentXmppChannel *channel() const {return channel_;}
uint64_t sequence_number() const {return sequence_number_;}
private:
const Peer *peer_;
const AgentXmppChannel *channel_;
uint64_t sequence_number_;
};
/*
* Implementation for adding remote route data.
*/
class ControllerVmRoute : public ControllerPeerPath {
public:
ControllerVmRoute(const Peer *peer, const string &vrf_name,
const Ip4Address &addr, uint32_t label,
const VnListType &dest_vn_list, int bmap,
const SecurityGroupList &sg_list,
const PathPreference &path_preference,
DBRequest &req, bool ecmp_suppressed):
ControllerPeerPath(peer), server_vrf_(vrf_name), tunnel_dest_(addr),
tunnel_bmap_(bmap), label_(label), dest_vn_list_(dest_vn_list),
sg_list_(sg_list),path_preference_(path_preference),
ecmp_suppressed_(ecmp_suppressed)
{nh_req_.Swap(&req);}
// Data passed in case of delete from BGP peer, to validate
// the request at time of processing.
ControllerVmRoute(const Peer *peer) : ControllerPeerPath(peer) { }
virtual ~ControllerVmRoute() { }
virtual bool AddChangePath(Agent *agent, AgentPath *path,
const AgentRoute *rt);
virtual bool UpdateRoute(AgentRoute *route);
virtual string ToString() const {return "remote VM";}
virtual bool IsPeerValid(const AgentRouteKey *key) const;
const SecurityGroupList &sg_list() const {return sg_list_;}
static ControllerVmRoute *MakeControllerVmRoute(const Peer *peer,
const string &default_vrf,
const Ip4Address &router_id,
const string &vrf_name,
const Ip4Address &tunnel_dest,
TunnelType::TypeBmap bmap,
uint32_t label,
const VnListType &dest_vn_list,
const SecurityGroupList &sg_list,
const PathPreference
&path_preference,
bool ecmp_suppressed);
private:
string server_vrf_;
Ip4Address tunnel_dest_;
TunnelType::TypeBmap tunnel_bmap_;
uint32_t label_;
VnListType dest_vn_list_;
SecurityGroupList sg_list_;
PathPreference path_preference_;
DBRequest nh_req_;
bool ecmp_suppressed_;
DISALLOW_COPY_AND_ASSIGN(ControllerVmRoute);
};
class ControllerEcmpRoute : public ControllerPeerPath {
public:
ControllerEcmpRoute(const Peer *peer, const IpAddress &dest_addr,
uint8_t plen, const VnListType &vn_list,
uint32_t label, bool local_ecmp_nh,
const string &vrf_name, SecurityGroupList sg_list,
const PathPreference &path_preference,
TunnelType::TypeBmap tunnel_bmap,
const EcmpLoadBalance &ecmp_load_balance,
DBRequest &nh_req) :
ControllerPeerPath(peer), dest_addr_(dest_addr), plen_(plen),
vn_list_(vn_list), label_(label), local_ecmp_nh_(local_ecmp_nh),
vrf_name_(vrf_name), sg_list_(sg_list),
path_preference_(path_preference), tunnel_bmap_(tunnel_bmap),
ecmp_load_balance_(ecmp_load_balance)
{nh_req_.Swap(&nh_req);}
virtual ~ControllerEcmpRoute() { }
virtual bool AddChangePath(Agent *agent, AgentPath *path,
const AgentRoute *);
virtual string ToString() const {return "inet4 ecmp";}
virtual bool IsPeerValid(const AgentRouteKey *key) const;
private:
IpAddress dest_addr_;
uint8_t plen_;
VnListType vn_list_;
uint32_t label_;
bool local_ecmp_nh_;
string vrf_name_;
SecurityGroupList sg_list_;
PathPreference path_preference_;
TunnelType::TypeBmap tunnel_bmap_;
EcmpLoadBalance ecmp_load_balance_;
DBRequest nh_req_;
DISALLOW_COPY_AND_ASSIGN(ControllerEcmpRoute);
};
/*
* Route data for adding local route with BGP peer.
* Send agent_xmpp_channel and sequence number to
* validate peeer validity at the time of route operation
*/
class ControllerLocalVmRoute : public LocalVmRoute {
public:
ControllerLocalVmRoute(const VmInterfaceKey &intf, uint32_t mpls_label,
uint32_t vxlan_id, bool force_policy,
const VnListType &vn_list, uint8_t flags,
const SecurityGroupList &sg_list,
const PathPreference &path_preference,
uint64_t sequence_number,
const EcmpLoadBalance &ecmp_load_balance,
const AgentXmppChannel *channel);
virtual ~ControllerLocalVmRoute() { }
virtual bool IsPeerValid(const AgentRouteKey *key) const;
private:
uint64_t sequence_number_;
const AgentXmppChannel *channel_;
DISALLOW_COPY_AND_ASSIGN(ControllerLocalVmRoute);
};
/*
* Route data for adding Inet Interface route with BGP peer.
* Send agent_xmpp_channel and sequence number to
* validate peeer validity at the time of route operation
*/
class ControllerInetInterfaceRoute : public InetInterfaceRoute {
public:
ControllerInetInterfaceRoute(const InetInterfaceKey &intf, uint32_t label,
int tunnel_bmap, const VnListType &dest_vn_list,
uint64_t sequence_number,
const AgentXmppChannel *channel);
virtual ~ControllerInetInterfaceRoute() { }
virtual bool IsPeerValid(const AgentRouteKey *key) const;
private:
uint64_t sequence_number_;
const AgentXmppChannel *channel_;
DISALLOW_COPY_AND_ASSIGN(ControllerInetInterfaceRoute);
};
/*
* Route data for adding Vlan route with BGP peer.
* Send agent_xmpp_channel and sequence number to
* validate peeer validity at the time of route operation
*/
class ControllerVlanNhRoute : public VlanNhRoute {
public:
ControllerVlanNhRoute(const VmInterfaceKey &intf, uint32_t tag,
uint32_t label,
const VnListType &dest_vn_list,
const SecurityGroupList &sg_list,
const PathPreference &path_preference,
uint64_t sequence_number,
const AgentXmppChannel *channel);
virtual ~ControllerVlanNhRoute() { }
virtual bool IsPeerValid(const AgentRouteKey *key) const;
private:
uint64_t sequence_number_;
const AgentXmppChannel *channel_;
DISALLOW_COPY_AND_ASSIGN(ControllerVlanNhRoute);
};
/*
* ClonedLocalPath would be used to pick nexthop from the
* local peer, instead of nexthop pointed by mpls label.
* Currently it gets used in gateway interface. In case of
* gateway interface, label exported by agent would point
* to table nexthop, and the prefix route of gateway
* interface would point resolve nexthop, so that ARP resolution
* can be triggered when packet hits the subnet route.
*/
class ClonedLocalPath : public AgentRouteData {
public:
ClonedLocalPath(uint64_t seq, const AgentXmppChannel *channel,
uint32_t label, const VnListType &vn_list,
const SecurityGroupList &sg_list):
AgentRouteData(false), sequence_number_(seq),
channel_(channel), mpls_label_(label), vn_list_(vn_list), sg_list_(sg_list) {}
virtual ~ClonedLocalPath() {}
virtual bool IsPeerValid(const AgentRouteKey *key) const;
virtual bool AddChangePath(Agent *agent, AgentPath *path,
const AgentRoute *rt);
virtual std::string ToString() const {
return "Nexthop cloned from local path";
}
private:
uint64_t sequence_number_;
const AgentXmppChannel *channel_;
uint32_t mpls_label_;
const VnListType vn_list_;
const SecurityGroupList sg_list_;
DISALLOW_COPY_AND_ASSIGN(ClonedLocalPath);
};
class ControllerMulticastRoute : public MulticastRoute {
public:
ControllerMulticastRoute(const string &vn_name,
uint32_t label,
int vxlan_id,
uint32_t tunnel_type,
DBRequest &nh_req,
COMPOSITETYPE comp_nh_type,
uint64_t sequence_number,
const AgentXmppChannel *channel);
virtual ~ControllerMulticastRoute() { }
virtual bool IsPeerValid(const AgentRouteKey *key) const;
private:
uint64_t sequence_number_;
const AgentXmppChannel *channel_;
DISALLOW_COPY_AND_ASSIGN(ControllerMulticastRoute);
};
#endif //controller_route_path_hpp