Line data Source code
1 : /*
2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3 : */
4 :
5 : #ifndef vnsw_inet_unicast_route_hpp
6 : #define vnsw_inet_unicast_route_hpp
7 :
8 : class VlanNhRoute;
9 : class LocalVmRoute;
10 : class InetInterfaceRoute;
11 : class ClonedLocalPath;
12 : class EcmpLoadBalance;
13 :
14 : //////////////////////////////////////////////////////////////////
15 : // UNICAST INET
16 : /////////////////////////////////////////////////////////////////
17 : class InetUnicastRouteKey : public AgentRouteKey {
18 : public:
19 692 : InetUnicastRouteKey(const Peer *peer, const string &vrf_name,
20 692 : const IpAddress &dip, uint8_t plen) :
21 692 : AgentRouteKey(peer, vrf_name), dip_(dip), plen_(plen) { }
22 1366 : virtual ~InetUnicastRouteKey() { }
23 :
24 : //Called from oute creation in input of route table
25 : AgentRoute *AllocRouteEntry(VrfEntry *vrf, bool is_multicast) const;
26 834 : virtual Agent::RouteTableType GetRouteTableType() {
27 834 : if (dip_.is_v4()) {
28 499 : return Agent::INET4_UNICAST;
29 : }
30 335 : if (dip_.is_v6()) {
31 335 : return Agent::INET6_UNICAST;
32 : }
33 0 : return Agent::INVALID;
34 : }
35 : virtual string ToString() const;
36 : virtual AgentRouteKey *Clone() const;
37 :
38 433 : const IpAddress &addr() const {return dip_;}
39 0 : uint8_t plen() const {return plen_;}
40 :
41 : protected:
42 : IpAddress dip_;
43 : uint8_t plen_;
44 : private:
45 : DISALLOW_COPY_AND_ASSIGN(InetUnicastRouteKey);
46 : };
47 : class InetMplsUnicastRouteKey : public InetUnicastRouteKey {
48 : public:
49 14 : InetMplsUnicastRouteKey(const Peer *peer, const string &vrf_name,
50 14 : const IpAddress &dip, uint8_t plen) :
51 14 : InetUnicastRouteKey(peer, vrf_name, dip, plen) { }
52 28 : virtual ~InetMplsUnicastRouteKey() { }
53 :
54 19 : virtual Agent::RouteTableType GetRouteTableType() {
55 19 : if (dip_.is_v4()) {
56 19 : return Agent::INET4_MPLS;
57 : }
58 0 : return Agent::INVALID;
59 : }
60 : virtual AgentRouteKey *Clone() const;
61 :
62 : private:
63 : DISALLOW_COPY_AND_ASSIGN(InetMplsUnicastRouteKey);
64 : };
65 :
66 : class InetUnicastRouteEntry : public AgentRoute ,
67 : public AgentRoutePrefix<IpAddress> {
68 : public:
69 : InetUnicastRouteEntry(VrfEntry *vrf, const IpAddress &addr,
70 : uint8_t plen, bool is_multicast);
71 2026 : virtual ~InetUnicastRouteEntry() { }
72 :
73 : virtual int CompareTo(const Route &rhs) const;
74 : virtual std::string ToString() const;
75 : virtual KeyPtr GetDBRequestKey() const;
76 : virtual void SetKey(const DBRequestKey *key);
77 : virtual bool DBEntrySandesh(Sandesh *sresp, bool stale) const;
78 106 : virtual const std::string GetAddressString() const {
79 106 : return prefix_address_.to_string();
80 : }
81 0 : virtual const std::string GetSourceAddressString() const {
82 0 : return "0.0.0.0";
83 : }
84 : virtual Agent::RouteTableType GetTableType() const;
85 : virtual bool ReComputePathDeletion(AgentPath *path);
86 : virtual bool ReComputePathAdd(AgentPath *path);
87 : ///! @brief The length of Inet prefix IP address.
88 19535 : uint8_t prefix_length() const { return prefix_length_; }
89 0 : void set_addr(IpAddress addr) { prefix_address_ = addr; };
90 :
91 : //Key for patricia node lookup
92 : class Rtkey {
93 : public:
94 11365 : static std::size_t BitLength(const InetUnicastRouteEntry *key) {
95 11365 : return key->prefix_length();
96 : }
97 9690 : static char ByteValue(
98 : const InetUnicastRouteEntry *key, std::size_t i) {
99 9690 : if (key->prefix_address().is_v4()) {
100 : Ip4Address::bytes_type addr_bytes;
101 8278 : addr_bytes = key->prefix_address().to_v4().to_bytes();
102 8278 : char res = static_cast<char>(addr_bytes[i]);
103 8278 : return res;
104 : } else {
105 : Ip6Address::bytes_type addr_bytes;
106 1412 : addr_bytes = key->prefix_address().to_v6().to_bytes();
107 1412 : volatile char res = static_cast<char>(addr_bytes[i]);
108 1412 : return res;
109 : }
110 : }
111 : };
112 :
113 : bool DBEntrySandesh(Sandesh *sresp, IpAddress addr, uint8_t plen, bool stale) const;
114 : bool IsHostRoute() const;
115 : bool IpamSubnetRouteAvailable() const;
116 : InetUnicastRouteEntry *GetIpamSuperNetRoute() const;
117 :
118 : bool UpdateIpamHostFlags(bool ipam_host_route);
119 : bool UpdateRouteFlags(bool ipam_subnet_route, bool ipam_host_route,
120 : bool proxy_arp);
121 :
122 278 : bool ipam_subnet_route() const {return ipam_subnet_route_;}
123 79 : bool ipam_host_route() const { return ipam_host_route_; }
124 79 : bool proxy_arp() const {return proxy_arp_;}
125 : virtual AgentPath *FindPathUsingKeyData(const AgentRouteKey *key,
126 : const AgentRouteData *data) const;
127 :
128 : protected:
129 : friend class InetUnicastAgentRouteTable;
130 :
131 : Patricia::Node rtnode_;
132 : // Flag set if route exactly matches a subnet in IPAM
133 : // ARP packets hitting this route must be flooded even if its ECMP route
134 : bool ipam_subnet_route_;
135 : // Flag set if this is host route and falls in an IPAM subnet
136 : // ARP packets hitting this route are flooded if MAC stitching is missing
137 : bool ipam_host_route_;
138 : // Specifies if ARP must be force proxied for this route
139 : bool proxy_arp_;
140 : private:
141 : AgentPath *FindEvpnPathUsingKeyData(const AgentRouteKey *key,
142 : const AgentRouteData *data) const;
143 : DISALLOW_COPY_AND_ASSIGN(InetUnicastRouteEntry);
144 : };
145 :
146 : class InetUnicastAgentRouteTable : public AgentRouteTable {
147 : public:
148 : typedef Patricia::Tree<InetUnicastRouteEntry,
149 : &InetUnicastRouteEntry::rtnode_,
150 : InetUnicastRouteEntry::Rtkey> InetRouteTree;
151 :
152 : InetUnicastAgentRouteTable(DB *db, const std::string &name);
153 72 : virtual ~InetUnicastAgentRouteTable() { }
154 :
155 : InetUnicastRouteEntry *FindLPM(const IpAddress &ip);
156 : InetUnicastRouteEntry *FindLPM(const InetUnicastRouteEntry &rt_key);
157 48 : virtual string GetTableName() const {
158 48 : if (type_ == Agent::INET4_UNICAST) {
159 24 : return "Inet4UnicastAgentRouteTable";
160 : }
161 24 : if (type_ == Agent::INET4_MPLS) {
162 0 : return "Inet4MplsAgentRouteTable";
163 : }
164 24 : if (type_ == Agent::INET6_UNICAST) {
165 24 : return "Inet6UnicastAgentRouteTable";
166 : }
167 0 : return "Unknown";
168 : }
169 1635 : virtual Agent::RouteTableType GetTableType() const {
170 1635 : return type_;
171 : }
172 82 : virtual void ProcessAdd(AgentRoute *rt) {
173 82 : tree_.Insert(static_cast<InetUnicastRouteEntry *>(rt));
174 82 : }
175 82 : virtual void ProcessDelete(AgentRoute *rt) {
176 82 : tree_.Remove(static_cast<InetUnicastRouteEntry *>(rt));
177 82 : }
178 : virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args,
179 : const std::string &context);
180 2 : InetUnicastRouteEntry *FindRouteUsingKey(InetUnicastRouteEntry &key) {
181 2 : return FindLPM(key);
182 : }
183 58 : InetUnicastRouteEntry *FindRoute(const IpAddress &ip) {
184 58 : return FindLPM(ip);
185 : }
186 :
187 0 : const InetUnicastRouteEntry *GetNext(const InetUnicastRouteEntry *rt) {
188 0 : return static_cast<const InetUnicastRouteEntry *>(tree_.FindNext(rt));
189 : }
190 :
191 32 : InetUnicastRouteEntry *GetNextNonConst(const InetUnicastRouteEntry *rt) {
192 32 : return static_cast<InetUnicastRouteEntry *>(tree_.FindNext(rt));
193 : }
194 :
195 : static DBTableBase *CreateTable(DB *db, const std::string &name);
196 : static void DeleteReq(const Peer *peer, const string &vrf_name,
197 : const IpAddress &addr, uint8_t plen,
198 : AgentRouteData *data);
199 : static void DeleteMplsRouteReq(const Peer *peer, const string &vrf_name,
200 : const IpAddress &addr, uint8_t plen,
201 : AgentRouteData *data);
202 : static void Delete(const Peer *peer, const string &vrf_name,
203 : const IpAddress &addr, uint8_t plen);
204 : void Delete(const Peer *peer, const string &vrf_name,
205 : const IpAddress &addr, uint8_t plen,
206 : AgentRouteData *data);
207 : static void AddHostRoute(const string &vrf_name,
208 : const IpAddress &addr, uint8_t plen,
209 : const std::string &dest_vn_name,
210 : bool policy);
211 : void AddLocalVmRouteReq(const Peer *peer, const string &vm_vrf,
212 : const IpAddress &addr, uint8_t plen,
213 : LocalVmRoute *data);
214 : void AddLocalVmRouteReq(const Peer *peer, const string &vm_vrf,
215 : const IpAddress &addr, uint8_t plen,
216 : const boost::uuids::uuid &intf_uuid,
217 : const VnListType &vn_list,
218 : uint32_t label,
219 : const SecurityGroupList &sg_list,
220 : const TagList &tag_list,
221 : const CommunityList &communities,
222 : bool force_policy,
223 : const PathPreference &path_preference,
224 : const IpAddress &subnet_service_ip,
225 : const EcmpLoadBalance &ecmp_load_balance,
226 : bool is_local,
227 : bool is_health_check_service,
228 : bool native_encap,
229 : const std::string &intf_name = "",
230 : bool is_learnt_route = false);
231 : static void AddLocalVmRoute(const Peer *peer, const string &vm_vrf,
232 : const IpAddress &addr, uint8_t plen,
233 : const boost::uuids::uuid &intf_uuid,
234 : const VnListType &vn_list,
235 : uint32_t label,
236 : const SecurityGroupList &sg_list,
237 : const TagList &tag_list,
238 : const CommunityList &communities,
239 : bool force_policy,
240 : const PathPreference &path_preference,
241 : const IpAddress &subnet_service_ip,
242 : const EcmpLoadBalance &ecmp_load_balance,
243 : bool is_local, bool is_health_check_service,
244 : const std::string &intf_name,
245 : bool native_encap,
246 : const std::string &intf_route_type = VmInterface::kInterface,
247 : bool is_learnt_route = false);
248 : void ResyncRoute(const Peer *peer, const string &vrf,
249 : const IpAddress &addr, uint8_t plen);
250 : static void AddRemoteVmRouteReq(const Peer *peer, const string &vm_vrf,
251 : const IpAddress &vm_addr,uint8_t plen,
252 : AgentRouteData *data);
253 : void AddVlanNHRouteReq(const Peer *peer, const string &vm_vrf,
254 : const IpAddress &addr, uint8_t plen,
255 : VlanNhRoute *data);
256 : void AddVlanNHRouteReq(const Peer *peer, const string &vm_vrf,
257 : const IpAddress &addr, uint8_t plen,
258 : const boost::uuids::uuid &intf_uuid, uint16_t tag,
259 : uint32_t label, const VnListType &dest_vn_list,
260 : const SecurityGroupList &sg_list_,
261 : const TagList &tag_list,
262 : const PathPreference &path_preference);
263 : static void AddVlanNHRoute(const Peer *peer, const string &vm_vrf,
264 : const IpAddress &addr, uint8_t plen,
265 : const boost::uuids::uuid &intf_uuid, uint16_t tag,
266 : uint32_t label, const VnListType &dest_vn_list,
267 : const SecurityGroupList &sg_list_,
268 : const TagList &tag_list,
269 : const PathPreference &path_preference);
270 : InetUnicastRouteEntry *FindResolveRoute(const Ip4Address &ip);
271 : static InetUnicastRouteEntry *FindResolveRoute(const string &vrf_name,
272 : const Ip4Address &ip);
273 : static bool ShouldAddArp(const Ip4Address &ip);
274 : static void CheckAndAddArpReq(const string &vrf_name, const Ip4Address &ip,
275 : const Interface *intf,
276 : const VnListType &vn_list,
277 : const SecurityGroupList &sg,
278 : const TagList &tag);
279 : static void CheckAndAddArpRoute(const string &route_vrf_name,
280 : const Ip4Address &ip,
281 : const MacAddress &mac,
282 : const Interface *intf,
283 : bool resolved,
284 : const VnListType &vn_list,
285 : const SecurityGroupList &sg,
286 : const TagList &tag);
287 : static void AddArpReq(const string &route_vrf_name,
288 : const Ip4Address &ip,
289 : const string &nh_vrf_name,
290 : const Interface *intf,
291 : bool policy,
292 : const VnListType &dest_vn_list,
293 : const SecurityGroupList &sg_list,
294 : const TagList &tag_list);
295 : static void ArpRoute(DBRequest::DBOperation op,
296 : const string &route_vrf_name,
297 : const Ip4Address &ip,
298 : const MacAddress &mac,
299 : const string &nh_vrf_name,
300 : const Interface &intf,
301 : bool resolved,
302 : const uint8_t plen,
303 : bool policy,
304 : const VnListType &dest_vn_list,
305 : const SecurityGroupList &sg_list,
306 : const TagList &tag_list);
307 : static void NdpRoute(DBRequest::DBOperation op,
308 : const string &route_vrf_name,
309 : const IpAddress &ip,
310 : const MacAddress &mac,
311 : const string &nh_vrf_name,
312 : const Interface &intf,
313 : bool resolved,
314 : const uint8_t plen,
315 : bool policy,
316 : const VnListType &dest_vn_list,
317 : const SecurityGroupList &sg_list,
318 : const TagList &tag_list);
319 : static void AddResolveRoute(const Peer *peer,
320 : const string &vrf_name, const Ip4Address &ip,
321 : const uint8_t plen,
322 : const InterfaceKey &intf_key,
323 : const uint32_t label, bool policy,
324 : const std::string &vn_name,
325 : const SecurityGroupList &sg_list,
326 : const TagList &tag_list);
327 : void AddInetInterfaceRouteReq(const Peer *peer, const string &vm_vrf,
328 : const Ip4Address &addr, uint8_t plen,
329 : InetInterfaceRoute *data);
330 : void AddInetInterfaceRouteReq(const Peer *peer, const string &vm_vrf,
331 : const Ip4Address &addr, uint8_t plen,
332 : const string &interface,
333 : uint32_t label,
334 : const VnListType &vn_list);
335 :
336 : static void AddVHostRecvRoute(const Peer *peer, const string &vrf,
337 : const InterfaceKey &interface,
338 : const IpAddress &addr, uint8_t plen,
339 : const string &vn_name, bool policy,
340 : bool native_encap,
341 : bool ipam_host_route = true);
342 : static void AddVHostRecvRouteReq(const Peer *peer, const string &vrf,
343 : const InterfaceKey &interface,
344 : const IpAddress &addr, uint8_t plen,
345 : const string &vn_name, bool policy,
346 : bool native_encap);
347 : static void AddVHostMplsRecvRouteReq(const Peer *peer, const string &vrf,
348 : const InterfaceKey &interface,
349 : const IpAddress &addr, uint8_t plen,
350 : const string &vn_name, bool policy,
351 : bool native_encap);
352 : static void AddVHostSubnetRecvRoute(const Peer *peer, const string &vrf,
353 : const InterfaceKey &interface,
354 : const Ip4Address &addr, uint8_t plen,
355 : const std::string &vn_name,
356 : bool policy);
357 : static void DelVHostSubnetRecvRoute(const string &vm_vrf,
358 : const Ip4Address &addr, uint8_t plen);
359 : static void AddDropRoute(const string &vm_vrf,
360 : const Ip4Address &addr, uint8_t plen,
361 : const string &vn_name);
362 : static void AddGatewayRoute(const Peer *peer,
363 : const string &vrf_name,
364 : const Ip4Address &dst_addr,uint8_t plen,
365 : const AddressList &gw_list,
366 : const VnListType &vn_name, uint32_t label,
367 : const SecurityGroupList &sg_list,
368 : const TagList &tag_list,
369 : const CommunityList &communities,
370 : bool native_encap);
371 : static void AddGatewayRouteReq(const Peer *peer,
372 : const string &vrf_name,
373 : const Ip4Address &dst_addr,uint8_t plen,
374 : const AddressList &gw_list,
375 : const VnListType &vn_name, uint32_t label,
376 : const SecurityGroupList &sg_list,
377 : const TagList &tag_list,
378 : const CommunityList &communities,
379 : bool native_encap);
380 : static void AddLocalMplsRouteReq(const Peer *peer,
381 : const string &vrf_name,
382 : const Ip4Address &dst_addr,uint8_t plen,
383 : const Ip4Address &gw_ip,
384 : const VnListType &vn_name, uint32_t label,
385 : const SecurityGroupList &sg_list,
386 : const TagList &tag_list,
387 : const CommunityList &communities,
388 : bool native_encap);
389 : static void AddMplsRouteInternal(const Peer *peer,
390 : DBRequest *req, const string &vrf_name,
391 : const IpAddress &dst_addr, uint8_t plen,
392 : const IpAddress &gw_ip,
393 : const VnListType &vn_name, uint32_t label,
394 : const SecurityGroupList &sg_list,
395 : const TagList &tag_list,
396 : const CommunityList &communities,
397 : bool native_encap);
398 : static void AddMplsRouteReq(const Peer *peer,
399 : const string &vrf_name,
400 : const IpAddress &dst_addr,uint8_t plen,
401 : AgentRouteData *data);
402 : void AddIpamSubnetRoute(const string &vm_vrf, const IpAddress &addr,
403 : uint8_t plen, const std::string &vn_name);
404 : void AddVrouterSubnetRoute(const IpAddress &dst_addr, uint8_t plen);
405 : void AddVhostMplsRoute(const IpAddress &vhost_addr, const Peer *peer);
406 : void AddInterfaceRouteReq(Agent *agent, const Peer *peer,
407 : const string &vrf_name,
408 : const Ip4Address &ip, uint8_t plen,
409 : const Interface *intrface,
410 : const std::string &vn_name);
411 : void AddClonedLocalPathReq(const Peer *peer, const string &vm_vrf,
412 : const IpAddress &addr,
413 : uint8_t plen, ClonedLocalPath *data);
414 : bool ResyncSubnetRoutes(const InetUnicastRouteEntry *rt, bool val);
415 : uint8_t GetHostPlen(const IpAddress &ip_addr) const;
416 : void AddEvpnRoute(const AgentRoute *evpn_entry);
417 : void DeleteEvpnRoute(const AgentRoute *rt);
418 : void TraverseHostRoutesInSubnet(InetUnicastRouteEntry *rt,
419 : const Peer *peer);
420 : IpAddress GetSubnetAddress(const IpAddress &addr,
421 : uint16_t plen) const;
422 : InetUnicastRouteEntry *GetSuperNetRoute(const IpAddress &addr);
423 : void AddEvpnRoutingRoute(const IpAddress &ip_addr,
424 : uint8_t plen,
425 : const VrfEntry *vrf,
426 : const Peer *peer,
427 : const SecurityGroupList &sg_list,
428 : const CommunityList &communities,
429 : const PathPreference &path_preference,
430 : const EcmpLoadBalance &ecmp_load_balance,
431 : const TagList &tag_list,
432 : DBRequest &nh_req,
433 : uint32_t vxlan_id,
434 : const VnListType& vn_list,
435 : const std::string& origin_vn = "");
436 : void AddEvpnRoutingRouteReq(const IpAddress &ip_addr,
437 : uint8_t plen,
438 : const VrfEntry *vrf,
439 : const Peer *peer,
440 : const SecurityGroupList &sg_list,
441 : const CommunityList &communities,
442 : const PathPreference &path_preference,
443 : const EcmpLoadBalance &ecmp_load_balance,
444 : const TagList &tag_list,
445 : DBRequest &nh_req,
446 : uint32_t vxlan_id,
447 : const VnListType& vn_list,
448 : const std::string& origin_vn = "");
449 :
450 :
451 : private:
452 : Agent::RouteTableType type_;
453 : InetRouteTree tree_;
454 : Patricia::Node rtnode_;
455 : DBTableWalker::WalkId walkid_;
456 : DISALLOW_COPY_AND_ASSIGN(InetUnicastAgentRouteTable);
457 : };
458 :
459 : #endif // vnsw_inet_unicast_route_hpp
|