/
inet_unicast_route.h
342 lines (320 loc) · 15.9 KB
/
inet_unicast_route.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef vnsw_inet_unicast_route_hpp
#define vnsw_inet_unicast_route_hpp
class VlanNhRoute;
class LocalVmRoute;
class InetInterfaceRoute;
class ClonedLocalPath;
class EcmpLoadBalance;
//////////////////////////////////////////////////////////////////
// UNICAST INET
/////////////////////////////////////////////////////////////////
class InetUnicastRouteKey : public AgentRouteKey {
public:
InetUnicastRouteKey(const Peer *peer, const string &vrf_name,
const IpAddress &dip, uint8_t plen) :
AgentRouteKey(peer, vrf_name), dip_(dip), plen_(plen) { }
virtual ~InetUnicastRouteKey() { }
//Called from oute creation in input of route table
AgentRoute *AllocRouteEntry(VrfEntry *vrf, bool is_multicast) const;
Agent::RouteTableType GetRouteTableType() {
if (dip_.is_v4()) {
return Agent::INET4_UNICAST;
}
if (dip_.is_v6()) {
return Agent::INET6_UNICAST;
}
return Agent::INVALID;
}
virtual string ToString() const;
virtual AgentRouteKey *Clone() const;
const IpAddress &addr() const {return dip_;}
uint8_t plen() const {return plen_;}
private:
IpAddress dip_;
uint8_t plen_;
DISALLOW_COPY_AND_ASSIGN(InetUnicastRouteKey);
};
class InetUnicastRouteEntry : public AgentRoute {
public:
InetUnicastRouteEntry(VrfEntry *vrf, const IpAddress &addr,
uint8_t plen, bool is_multicast);
virtual ~InetUnicastRouteEntry() { }
virtual int CompareTo(const Route &rhs) const;
virtual std::string ToString() const;
virtual KeyPtr GetDBRequestKey() const;
virtual void SetKey(const DBRequestKey *key);
virtual bool DBEntrySandesh(Sandesh *sresp, bool stale) const;
virtual const std::string GetAddressString() const {
return addr_.to_string();
}
virtual Agent::RouteTableType GetTableType() const {
if (addr_.is_v4()) {
return Agent::INET4_UNICAST;
}
if (addr_.is_v6()) {
return Agent::INET6_UNICAST;
}
return Agent::INVALID;
}
virtual bool ReComputePathDeletion(AgentPath *path);
virtual bool ReComputePathAdd(AgentPath *path);
virtual bool EcmpAddPath(AgentPath *path);
virtual bool EcmpDeletePath(AgentPath *path);
void AppendEcmpPath(Agent *agent, AgentPath *path);
void DeleteComponentNH(Agent *agent, AgentPath *path);
AgentPath *AllocateEcmpPath(Agent *agent, const AgentPath *path1,
const AgentPath *path2);
static bool ModifyEcmpPath(const IpAddress &dest_addr,
uint8_t plen, const VnListType &vn_name,
uint32_t label, bool local_ecmp_nh,
const string &vrf_name,
SecurityGroupList sg_list,
const CommunityList &communities,
const PathPreference &path_preference,
TunnelType::TypeBmap tunnel_bmap,
const EcmpLoadBalance &ecmp_ecmp_load_balance,
DBRequest &nh_req,
Agent* agent,
AgentPath *path);
static bool SyncEcmpPath(AgentPath *path, SecurityGroupList sg_list,
const CommunityList &communities,
const PathPreference &path_preference,
TunnelType::TypeBmap tunnel_bmap,
const EcmpLoadBalance &ecmp_ecmp_load_balance);
const IpAddress &addr() const { return addr_; }
void set_addr(IpAddress addr) { addr_ = addr; };
uint8_t plen() const { return plen_; }
void set_plen(int plen) { plen_ = plen; }
//Key for patricia node lookup
class Rtkey {
public:
static std::size_t BitLength(const AgentRoute *key) {
const InetUnicastRouteEntry *uckey =
static_cast<const InetUnicastRouteEntry *>(key);
return uckey->plen();
}
static char ByteValue(const AgentRoute *key, std::size_t i) {
const InetUnicastRouteEntry *uckey =
static_cast<const InetUnicastRouteEntry *>(key);
if (uckey->addr().is_v4()) {
Ip4Address::bytes_type addr_bytes;
addr_bytes = uckey->addr().to_v4().to_bytes();
return static_cast<char>(addr_bytes[i]);
} else {
Ip6Address::bytes_type addr_bytes;
addr_bytes = uckey->addr().to_v6().to_bytes();
return static_cast<char>(addr_bytes[i]);
}
}
};
bool DBEntrySandesh(Sandesh *sresp, IpAddress addr, uint8_t plen, bool stale) const;
const NextHop* GetLocalNextHop() const;
bool IsHostRoute() const;
bool IpamSubnetRouteAvailable() const;
bool ipam_subnet_route() const {return ipam_subnet_route_;}
void set_ipam_subnet_route(bool ipam_subnet_route) {
ipam_subnet_route_ = ipam_subnet_route;}
bool proxy_arp() const {return proxy_arp_;}
void set_proxy_arp(bool proxy_arp) {
proxy_arp_ = proxy_arp;}
private:
friend class InetUnicastAgentRouteTable;
IpAddress addr_;
uint8_t plen_;
Patricia::Node rtnode_;
bool ipam_subnet_route_;
bool proxy_arp_;
DISALLOW_COPY_AND_ASSIGN(InetUnicastRouteEntry);
};
class InetUnicastAgentRouteTable : public AgentRouteTable {
public:
typedef Patricia::Tree<InetUnicastRouteEntry,
&InetUnicastRouteEntry::rtnode_,
InetUnicastRouteEntry::Rtkey> InetRouteTree;
InetUnicastAgentRouteTable(DB *db, const std::string &name);
virtual ~InetUnicastAgentRouteTable() { }
InetUnicastRouteEntry *FindLPM(const IpAddress &ip);
InetUnicastRouteEntry *FindLPM(const InetUnicastRouteEntry &rt_key);
virtual string GetTableName() const {
if (type_ == Agent::INET4_UNICAST) {
return "Inet4UnicastAgentRouteTable";
}
if (type_ == Agent::INET6_UNICAST) {
return "Inet6UnicastAgentRouteTable";
}
return "Unknown";
}
virtual Agent::RouteTableType GetTableType() const {
return type_;
}
virtual void ProcessAdd(AgentRoute *rt) {
tree_.Insert(static_cast<InetUnicastRouteEntry *>(rt));
}
virtual void ProcessDelete(AgentRoute *rt) {
tree_.Remove(static_cast<InetUnicastRouteEntry *>(rt));
}
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args,
const std::string &context);
InetUnicastRouteEntry *FindRouteUsingKey(InetUnicastRouteEntry &key) {
return FindLPM(key);
}
InetUnicastRouteEntry *FindRoute(const IpAddress &ip) {
return FindLPM(ip);
}
const InetUnicastRouteEntry *GetNext(const InetUnicastRouteEntry *rt) {
return static_cast<const InetUnicastRouteEntry *>(tree_.FindNext(rt));
}
InetUnicastRouteEntry *GetNextNonConst(const InetUnicastRouteEntry *rt) {
return static_cast<InetUnicastRouteEntry *>(tree_.FindNext(rt));
}
static DBTableBase *CreateTable(DB *db, const std::string &name);
static void ReEvaluatePaths(const Agent *agent,
const string &vrf_name,
const IpAddress &ip,
uint8_t plen);
static void DeleteReq(const Peer *peer, const string &vrf_name,
const IpAddress &addr, uint8_t plen,
AgentRouteData *data);
static void Delete(const Peer *peer, const string &vrf_name,
const IpAddress &addr, uint8_t plen);
static void AddHostRoute(const string &vrf_name,
const IpAddress &addr, uint8_t plen,
const std::string &dest_vn_name);
void AddLocalVmRouteReq(const Peer *peer, const string &vm_vrf,
const IpAddress &addr, uint8_t plen,
LocalVmRoute *data);
void AddLocalVmRouteReq(const Peer *peer, const string &vm_vrf,
const IpAddress &addr, uint8_t plen,
const uuid &intf_uuid,
const VnListType &vn_list,
uint32_t label,
const SecurityGroupList &sg_list,
const CommunityList &communities,
bool force_policy,
const PathPreference &path_preference,
const IpAddress &subnet_service_ip,
const EcmpLoadBalance &ecmp_load_balance);
static void AddLocalVmRoute(const Peer *peer, const string &vm_vrf,
const IpAddress &addr, uint8_t plen,
const uuid &intf_uuid,
const VnListType &vn_list,
uint32_t label,
const SecurityGroupList &sg_list,
const CommunityList &communities,
bool force_policy,
const PathPreference &path_preference,
const IpAddress &subnet_service_ip,
const EcmpLoadBalance &ecmp_load_balance);
static void AddRemoteVmRouteReq(const Peer *peer, const string &vm_vrf,
const IpAddress &vm_addr,uint8_t plen,
AgentRouteData *data);
void AddVlanNHRouteReq(const Peer *peer, const string &vm_vrf,
const IpAddress &addr, uint8_t plen,
VlanNhRoute *data);
void AddVlanNHRouteReq(const Peer *peer, const string &vm_vrf,
const IpAddress &addr, uint8_t plen,
const uuid &intf_uuid, uint16_t tag,
uint32_t label, const VnListType &dest_vn_list,
const SecurityGroupList &sg_list_,
const PathPreference &path_preference);
static void AddVlanNHRoute(const Peer *peer, const string &vm_vrf,
const IpAddress &addr, uint8_t plen,
const uuid &intf_uuid, uint16_t tag,
uint32_t label, const VnListType &dest_vn_list,
const SecurityGroupList &sg_list_,
const PathPreference &path_preference);
InetUnicastRouteEntry *FindResolveRoute(const Ip4Address &ip);
static InetUnicastRouteEntry *FindResolveRoute(const string &vrf_name,
const Ip4Address &ip);
static void CheckAndAddArpReq(const string &vrf_name, const Ip4Address &ip,
const Interface *intf,
const VnListType &vn_list,
const SecurityGroupList &sg);
static void AddArpReq(const string &route_vrf_name,
const Ip4Address &ip,
const string &nh_vrf_name,
const Interface *intf,
bool policy,
const VnListType &dest_vn_list,
const SecurityGroupList &sg_list);
static void ArpRoute(DBRequest::DBOperation op,
const string &route_vrf_name,
const Ip4Address &ip,
const MacAddress &mac,
const string &nh_vrf_name,
const Interface &intf,
bool resolved,
const uint8_t plen,
bool policy,
const VnListType &dest_vn_list,
const SecurityGroupList &sg_list);
static void AddResolveRoute(const Peer *peer,
const string &vrf_name, const Ip4Address &ip,
const uint8_t plen,
const InterfaceKey &intf_key,
const uint32_t label, bool policy,
const std::string &vn_name,
const SecurityGroupList &sg_list);
void AddInetInterfaceRouteReq(const Peer *peer, const string &vm_vrf,
const Ip4Address &addr, uint8_t plen,
InetInterfaceRoute *data);
void AddInetInterfaceRouteReq(const Peer *peer, const string &vm_vrf,
const Ip4Address &addr, uint8_t plen,
const string &interface,
uint32_t label,
const VnListType &vn_list);
static void AddVHostRecvRoute(const Peer *peer, const string &vrf,
const string &interface,
const IpAddress &addr, uint8_t plen,
const string &vn_name, bool policy);
static void AddVHostRecvRouteReq(const Peer *peer, const string &vrf,
const string &interface,
const IpAddress &addr, uint8_t plen,
const string &vn_name, bool policy);
static void AddVHostSubnetRecvRoute(const Peer *peer, const string &vrf,
const string &interface,
const Ip4Address &addr, uint8_t plen,
const std::string &vn_name,
bool policy);
static void DelVHostSubnetRecvRoute(const string &vm_vrf,
const Ip4Address &addr, uint8_t plen);
static void AddDropRoute(const string &vm_vrf,
const Ip4Address &addr, uint8_t plen,
const string &vn_name);
static void AddGatewayRoute(const Peer *peer,
const string &vrf_name,
const Ip4Address &dst_addr,uint8_t plen,
const Ip4Address &gw_ip,
const std::string &vn_name, uint32_t label,
const SecurityGroupList &sg_list,
const CommunityList &communities);
static void AddGatewayRouteReq(const Peer *peer,
const string &vrf_name,
const Ip4Address &dst_addr,uint8_t plen,
const Ip4Address &gw_ip,
const std::string &vn_name, uint32_t label,
const SecurityGroupList &sg_list,
const CommunityList &communities);
void AddIpamSubnetRoute(const string &vm_vrf, const IpAddress &addr,
uint8_t plen, const std::string &vn_name);
void AddInterfaceRouteReq(Agent *agent, const Peer *peer,
const string &vrf_name,
const Ip4Address &ip, uint8_t plen,
const Interface *interface,
const std::string &vn_name);
void AddClonedLocalPathReq(const Peer *peer, const string &vm_vrf,
const IpAddress &addr,
uint8_t plen, ClonedLocalPath *data);
bool ResyncSubnetRoutes(const InetUnicastRouteEntry *rt,
bool add_change);
private:
Agent::RouteTableType type_;
InetRouteTree tree_;
Patricia::Node rtnode_;
DBTableWalker::WalkId walkid_;
DISALLOW_COPY_AND_ASSIGN(InetUnicastAgentRouteTable);
};
#endif // vnsw_inet_unicast_route_hpp