OpenSDN source code
inet_unicast_route.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include <boost/uuid/uuid_io.hpp>
7 
8 #include <base/address_util.h>
10 #include <boost/foreach.hpp>
11 #include <cmn/agent_cmn.h>
12 #include <route/route.h>
13 #include <oper/ecmp.h>
14 #include <oper/ecmp_load_balance.h>
15 #include <oper/route_common.h>
16 #include <oper/vrf.h>
17 #include <oper/tunnel_nh.h>
18 #include <oper/mpls.h>
19 #include <oper/vxlan.h>
20 #include <oper/mirror_table.h>
21 #include <oper/multicast.h>
25 #include <oper/agent_sandesh.h>
26 
27 using namespace std;
28 using namespace boost::asio;
29 
30 AgentRoute *
31 InetUnicastRouteKey::AllocRouteEntry(VrfEntry *vrf, bool is_multicast) const {
32  InetUnicastRouteEntry * entry =
33  new InetUnicastRouteEntry(vrf, dip_, plen_, is_multicast);
34  return static_cast<AgentRoute *>(entry);
35 }
36 
38  return (new InetUnicastRouteKey(peer(), vrf_name_, dip_, plen_));
39 }
40 
42  return (new InetMplsUnicastRouteKey(peer(), vrf_name_, dip_, plen_));
43 }
45 // InetUnicastAgentRouteTable functions
48  const std::string &name) :
49  AgentRouteTable(db, name), walkid_(DBTableWalker::kInvalidWalkerId) {
50 
51  if (name.find("uc.route.0") != std::string::npos) {
53  } else if (name.find("uc.route.3") != std::string::npos) {
55  } else if (name.find("uc.route6.0") != std::string::npos) {
57  } else if (name.find("evpn.route.0") != std::string::npos) {
59  } else if (name.find("l2.route.0") != std::string::npos) {
61  } else if (name.find("mc.route.0") != std::string::npos) {
63  } else {
65  }
66 }
67 
69 InetUnicastAgentRouteTable::CreateTable(DB *db, const std::string &name) {
71  table->Init();
72  return table;
73 }
74 
77  uint32_t plen = 128;
78  if (ip.is_v4()) {
79  plen = 32;
80  }
81  InetUnicastRouteEntry key(NULL, ip, plen, false);
82  return tree_.LPMFind(&key);
83 }
84 
87  return tree_.LPMFind(&rt_key);
88 }
89 
92  uint8_t plen = 32;
93  InetUnicastRouteEntry *rt = NULL;
94  do {
95  InetUnicastRouteEntry key(NULL, ip, plen, false);
96  rt = tree_.LPMFind(&key);
97  if (rt) {
98  const NextHop *nh = rt->GetActiveNextHop();
99  if (nh && nh->GetType() == NextHop::RESOLVE)
100  return rt;
101  }
102  } while (rt && --plen);
103 
104  return NULL;
105 }
106 
109  const Ip4Address &ip) {
110  VrfEntry *vrf =
112  InetUnicastAgentRouteTable *rt_table =
113  static_cast<InetUnicastAgentRouteTable *>
114  (vrf->GetInet4UnicastRouteTable());
115  return rt_table->FindResolveRoute(ip);
116 }
117 
118 static void Inet4UnicastTableEnqueue(Agent *agent, DBRequest *req) {
120  if (table) {
121  table->Enqueue(req);
122  }
123 }
124 
125 static void Inet4MplsUnicastTableEnqueue(Agent *agent, DBRequest *req) {
126  AgentRouteTable *table = agent->fabric_inet4_mpls_table();
127  if (table) {
128  table->Enqueue(req);
129  }
130 }
131 
132 static void Inet6UnicastTableEnqueue(Agent *agent, const string &vrf_name,
133  DBRequest *req) {
135  if (table) {
136  table->Enqueue(req);
137  }
138 }
139 
140 static void InetUnicastTableEnqueue(Agent *agent, const string &vrf,
141  DBRequest *req) {
142  InetUnicastRouteKey *key = static_cast<InetUnicastRouteKey *>(req->key.get());
143  if (key->addr().is_v4()) {
144  Inet4UnicastTableEnqueue(agent, req);
145  } else if (key->addr().is_v6()) {
146  Inet6UnicastTableEnqueue(agent, vrf, req);
147  }
148 }
149 
150 static void Inet4UnicastTableProcess(Agent *agent, const string &vrf_name,
151  DBRequest &req) {
152  AgentRouteTable *table =
153  agent->vrf_table()->GetInet4UnicastRouteTable(vrf_name);
154  if (table) {
155  table->Process(req);
156  }
157 }
158 
159 static void Inet6UnicastTableProcess(Agent *agent, const string &vrf_name,
160  DBRequest &req) {
161  AgentRouteTable *table =
162  agent->vrf_table()->GetInet6UnicastRouteTable(vrf_name);
163  if (table) {
164  table->Process(req);
165  }
166 }
167 
168 static void InetUnicastTableProcess(Agent *agent, const string &vrf_name,
169  DBRequest &req) {
170  InetUnicastRouteKey *key = static_cast<InetUnicastRouteKey *>(req.key.get());
171  if (key->addr().is_v4()) {
172  Inet4UnicastTableProcess(agent, vrf_name, req);
173  } else if (key->addr().is_v6()) {
174  Inet6UnicastTableProcess(agent, vrf_name, req);
175  }
176 }
177 
178 /*
179  * Traverse all smaller subnets w.r.t. route sent and mark the arp flood flag
180  * accordingly.
181  */
183 (const InetUnicastRouteEntry *rt, bool val) {
184  const IpAddress addr = rt->prefix_address();
185  uint16_t plen = rt->prefix_length();
187 
188  Ip4Address v4_parent_mask;
189  Ip6Address v6_parent_mask;
190 
192  v4_parent_mask = Address::GetIp4SubnetAddress(addr.to_v4(),
193  plen);
194  } else if (GetTableType() == Agent::INET6_UNICAST) {
195  v6_parent_mask = Address::GetIp6SubnetAddress(addr.to_v6(),
196  plen);
197  } else {
198  // skip processing for inet4_mpls table
199  // not expected
200  return false;
201  }
202 
203 
204  // Iterate thru all the routes under this subnet and update route flags
205  while ((lpm_rt != NULL) && (plen < lpm_rt->prefix_length())) {
207  Ip4Address node_mask =
209  plen);
210  if (v4_parent_mask != node_mask)
211  break;
212 
213  } else if (GetTableType() == Agent::INET6_UNICAST) {
214  Ip6Address node_mask =
216  plen);
217  if (v6_parent_mask != node_mask)
218  break;
219  }
220 
221  // Update ipam_host_route_ and proxy_arp_ flags for host-routes
222  bool notify = false;
223  if (lpm_rt->UpdateIpamHostFlags(val)) {
224  notify = true;
225  }
226 
227  if (notify) {
228  NotifyEntry(lpm_rt);
229  }
230 
231  lpm_rt = GetNextNonConst(lpm_rt);
232  }
233  return false;
234 }
235 
236 //Null peer means sync is done on routes.
237 //If peer is specified then path belonging to peer will be resync'd
238 //Functions in TraverseHostRoutesInSubnet:
239 //1) If subnet rt added does not have any supernet then visit all unresolved
240 // routes and resync them.
241 //2) If supernet route is present then traverse lpm routes under this newly
242 // added subnet and resync all host routes pointing to supernet route of this
243 // subnet.
244 //3) Skip all the host routes present under this subnet belonging to a better
245 // subnet(better subnet is the one which comes under subnet being added).
246 // e.g. 1.1.1.10/24 is a better subnet in 1.1.1.10/16 while supernet can be
247 // 1.1.1.0/8
248 void
250  const Peer *peer)
251 {
252  const IpAddress addr = rt->prefix_address();
253  uint16_t plen = rt->prefix_length();
255 
256  //If supernet route is NULL, then this is the default route and visit to
257  //unresolved route for resync should suffice.
258  if (supernet_rt == NULL) {
259  //Resync all unresolved routes.
261  return;
262  }
263  //So suernet route is present and this subnet route is a better route.
264  //Look for all routes which were pointing to supernet route and move them
265  //to this subnet route, if they fall in same subnet.
266  IpAddress parent_mask = GetSubnetAddress(addr, plen);
267  for (InetUnicastRouteEntry *lpm_rt = GetNextNonConst(rt);
268  (lpm_rt != NULL) && (plen < lpm_rt->prefix_length());
269  lpm_rt= GetNextNonConst(lpm_rt)) {
270  IpAddress node_mask = GetSubnetAddress(lpm_rt->prefix_address(), plen);
271  if (parent_mask != node_mask)
272  break;
273 
274  //Non host route, lets continue as this route will have its own NH and it
275  //need not be modified.
276  if (lpm_rt->IsHostRoute() == false) {
277  continue;
278  }
279 
280  //If supernet route of this subnet route is not parent of lpm_rt added,
281  //then skip as its not lpm_rt dependant as well.
282  //There may be some other subnet which is handling it.
283  //e.g. 1.1.0.0/8, 1.1.0.0/16, 1.1.1.0/24, 1.1.1.1, 1.1.0.1
284  //Here parent of 1.1.1.1 will be 1.1.1.0/24 and not 1.1.0.0/16.
285  //So if subnet route getting added is 1.1.0.0/16 in presence of 1.1.1.0/24
286  //then 1.1.1.1 should not be modified.
287  if (lpm_rt->GetActivePath()->dependant_rt() != supernet_rt)
288  continue;
289 
290 
291  //Proceed only for host route
292  //Resync will ensure that subnet route is added to lpm host route
293  //dependant rt(gw_ip).
294  lpm_rt->EnqueueRouteResync();
295  }
296 }
297 
298 IpAddress
300  uint16_t plen) const {
301  if (type_ == Agent::INET4_UNICAST) {
302  return (Address::GetIp4SubnetAddress(addr.to_v4(), plen));
303  } else if (type_ == Agent::INET6_UNICAST) {
304  return (Address::GetIp6SubnetAddress(addr.to_v6(), plen));
305  }
306  return IpAddress(Ip4Address());
307 }
308 
309 //Tries searching for subnet route to which this route belongs.
310 //Route itself can be a subnet/host. To search for supernet plen is reduced by
311 //one and findlpm is issued.
314  InetUnicastRouteEntry key(NULL, addr, (GetHostPlen(addr) - 1),
315  false);
316  InetUnicastRouteEntry *parent_key = FindLPM(key);
317  return parent_key;
318 }
319 
321 // Inet4UnicastAgentRouteEntry functions
324  const IpAddress &addr,
325  uint8_t plen,
326  bool is_multicast) :
327  AgentRoute(vrf, is_multicast), AgentRoutePrefix(addr, plen),
328  ipam_subnet_route_(false),
329  ipam_host_route_(false), proxy_arp_(false) {
330  if (addr.is_v4()) {
331  prefix_address_ = Address::GetIp4SubnetAddress(addr.to_v4(), plen);
332  } else {
333  prefix_address_ = Address::GetIp6SubnetAddress(addr.to_v6(), plen);
334  }
335 }
336 
338  ostringstream str;
339  str << dip_.to_string();
340  str << "/";
341  str << (int)plen_;
342  return str.str();
343 }
344 
346  ostringstream str;
347  str << prefix_address_.to_string();
348  str << "/";
349  str << (int)prefix_length();
350  return str.str();
351 }
352 
353 
355  return ((InetUnicastAgentRouteTable *)get_table())->GetTableType();
356 }
357 
359  const InetUnicastRouteEntry &a =
360  static_cast<const InetUnicastRouteEntry &>(rhs);
361 
363  return -1;
364  }
365 
367  return 1;
368  }
369 
370  if (prefix_length() < a.prefix_length()) {
371  return -1;
372  }
373 
374  if (prefix_length() > a.prefix_length()) {
375  return 1;
376  }
377 
378  return 0;
379 }
380 
383  (static_cast<InetUnicastAgentRouteTable *>(get_table()));
384  Agent *agent = table->agent();
385  InetUnicastRouteKey *key = NULL;
386  if ((table->GetTableType() == Agent::INET4_MPLS)) {
387  key =
388  new InetMplsUnicastRouteKey(agent->local_peer(),
389  vrf()->GetName(), prefix_address_, prefix_length());
390  } else {
391  key =
392  new InetUnicastRouteKey(agent->local_peer(),
393  vrf()->GetName(), prefix_address_, prefix_length());
394  }
395 
396  return DBEntryBase::KeyPtr(key);
397 }
398 
400  Agent *agent =
401  (static_cast<InetUnicastAgentRouteTable *>(get_table()))->agent();
402  const InetUnicastRouteKey *k =
403  static_cast<const InetUnicastRouteKey*>(key);
404  SetVrf(agent->vrf_table()->FindVrfFromName(k->vrf_name()));
405  IpAddress tmp(k->addr());
406  set_addr(tmp);
407  set_prefix_length(k->plen());
408 }
409 
412  static_cast<InetUnicastAgentRouteTable *>(get_table());
413  if (table->GetTableType() == Agent::INET4_UNICAST) {
415  return false;
416  } else if (table->GetTableType() == Agent::INET6_UNICAST) {
418  return false;
419  }
420  return true;
421 }
422 
423 /*
424  * This routine finds out if there is supernet for this subnet route and that
425  * is used to inherit flood flag. In case supernet is pointing to resolve i.e.
426  * gateway without having Ipam path, then search continues further
427  */
429  return (GetIpamSuperNetRoute() != NULL);
430 }
431 
434  if (prefix_length() == 0)
435  return NULL;
436 
437  //Local path present means that this route itself was programmed
438  //because of IPAM add as well and hence its eligible for flood in
439  //all paths where NH is tunnel.
441  static_cast<InetUnicastAgentRouteTable *>(get_table());
442 
443  //Search for supernet, if none then dont flood else again search for
444  //local path. If found then mark for flood otherwise check for active path
445  //and retain flood flag from that path.
446  uint16_t plen = prefix_length() - 1;
447  while (plen != 0) {
448  assert(plen < prefix_length());
449  InetUnicastRouteEntry key(vrf(), prefix_address_, plen, false);
450  // Find next highest matching route
451  InetUnicastRouteEntry *supernet_rt = table->FindRouteUsingKey(key);
452 
453  if (supernet_rt == NULL)
454  return NULL;
455 
456  if (supernet_rt->ipam_subnet_route())
457  return supernet_rt;
458 
459  plen--;
460  }
461 
462  return NULL;
463 }
464 
466  bool ret = false;
467  InetUnicastAgentRouteTable *uc_rt_table =
468  static_cast<InetUnicastAgentRouteTable *>(get_table());
469  if (IsHostRoute() == false)
470  uc_rt_table->TraverseHostRoutesInSubnet(this,
471  uc_rt_table->agent()->
472  inet_evpn_peer());
473 
474  if (path->nexthop() && path->nexthop()->IsValid() &&
475  path->nexthop()->GetType() == NextHop::ARP) {
476  //Add bridge route for IP fabric ARP routes, so that
477  //MAC stitching can be done for VM routes based on corresponding
478  //compute node
479  const ArpNH *arp_nh = static_cast<const ArpNH *>(path->nexthop());
480  BridgeAgentRouteTable *table =
481  static_cast<BridgeAgentRouteTable *>(vrf()->GetBridgeRouteTable());
482  table->AddMacVmBindingRoute(path->peer(), vrf()->GetName(), arp_nh->GetMac(),
483  NULL, false);
484  }
485 
486  // ECMP path are managed by route module. Update ECMP path with
487  // addition of new path
488  EcmpData ecmp_data(uc_rt_table->agent(), vrf()->GetName(), ToString(),
489  path, false);
490  ret |= ecmp_data.Update(this);
491  return ret;
492 }
493 
495  if (IsHostRoute() == false) {
496  //TODO merge both evpn inet and subnet routes handling
498  }
499 
500 
501  if (path->nexthop() && path->nexthop()->GetType() == NextHop::ARP) {
502  const ArpNH *arp_nh =
503  static_cast<const ArpNH *>(path->nexthop());
504  BridgeAgentRouteTable *table =
505  static_cast<BridgeAgentRouteTable *>(vrf()->GetBridgeRouteTable());
506  table->DeleteMacVmBindingRoute(path->peer(), vrf()->GetName(),
507  arp_nh->GetMac(), NULL);
508  }
509 
510  InetUnicastAgentRouteTable *uc_rt_table =
511  static_cast<InetUnicastAgentRouteTable *>(get_table());
512  //Subnet discard = Ipam subnet route.
513  //Ipam path is getting deleted so all the smaller subnets should be
514  //resynced to remove the arp flood marking.
515  if (path->is_subnet_discard()) {
516  // Reset flag on route as ipam is going off.
517  UpdateRouteFlags(false, false, false);
518  uc_rt_table->ResyncSubnetRoutes(this, false);
519  return true;
520  }
521  // ECMP path are managed by route module. Update ECMP path with
522  // deletion of new path
523  EcmpData ecmp_data(uc_rt_table->agent(), vrf()->GetName(), ToString(),
524  path, true);
525  return ecmp_data.Update(this);
526 }
527 
528 // ipam_host_route_ flag:
529 // ipam_host_route_ is set if this is host-route and falls in ipam-subnet range
530 //
531 // proxy_arp_ flag:
532 // For hosts within subnet, we assume ARP must not be proxied and should be
533 // flooded instead. If we get EVPN route, in KSYNC the EVPN path processing
534 // will take preference and KSYNC will set Proxy flag
535 bool InetUnicastRouteEntry::UpdateIpamHostFlags(bool ipam_host_route) {
536  // For non-host routes, set proxy always
537  if (IsHostRoute() == false) {
538  return UpdateRouteFlags(false, false, true);
539  }
540 
541  bool proxy_arp = ipam_host_route ? false : true;
543 }
544 
545 bool InetUnicastRouteEntry::UpdateRouteFlags(bool ipam_subnet_route,
546  bool ipam_host_route,
547  bool proxy_arp) {
548  bool ret = false;
551  ret = true;
552  }
553 
556  ret = true;
557  }
558 
559  if (proxy_arp_ != proxy_arp) {
561  ret = true;
562  }
563 
564  return ret;
565 }
567 (const AgentRouteKey *key, const AgentRouteData *data) const {
568  const Peer *peer = key->peer();
569  const InetEvpnPeer *evpn_peer = dynamic_cast<const InetEvpnPeer*>(peer);
570  assert(evpn_peer != NULL);
571 
572  Route::PathList::const_iterator it;
573  for (it = GetPathList().begin(); it != GetPathList().end(); it++) {
574  const AgentPath *path = static_cast<const AgentPath *>(it.operator->());
575  if (path->peer() != key->peer())
576  continue;
577 
578  //Handle mac route added via evpn route.
579  const InetEvpnRoutePath *evpn_path =
580  dynamic_cast<const InetEvpnRoutePath *>(path);
581  const InetEvpnRouteData *evpn_data =
582  dynamic_cast<const InetEvpnRouteData *>(data);
583  assert(evpn_path != NULL);
584  assert(evpn_data != NULL);
585  if (evpn_path->MacAddr() != evpn_data->MacAddr())
586  continue;
587  return const_cast<AgentPath *>(path);
588  }
589  return NULL;
590 }
592 (const AgentRouteKey *key, const AgentRouteData *data) const {
593  const Peer *peer = key->peer();
594  const InetEvpnPeer *inet_evpn_peer =
595  dynamic_cast<const InetEvpnPeer*>(peer);
596  if (inet_evpn_peer != NULL)
597  return FindEvpnPathUsingKeyData(key, data);
598 
599  return FindPath(peer);
600 }
601 
603 // AgentRouteData virtual functions
605 
607  const AgentRoute *rt) {
608  bool ret = true;
609 
611  NextHop *nh =
612  static_cast<NextHop *>(agent->nexthop_table()->FindActiveEntry(&key));
613  path->set_unresolved(false);
614 
615  if (path->dest_vn_list() != vn_list_) {
616  path->set_dest_vn_list(vn_list_);
617  ret = true;
618  }
619 
620  if (path->sg_list() != sg_list_) {
621  path->set_sg_list(sg_list_);
622  ret = true;
623  }
624 
625  if (path->tag_list() != tag_list_) {
626  path->set_tag_list(tag_list_);
627  ret = true;
628  }
629 
630  if (path->ChangeNH(agent, nh) == true)
631  ret = true;
632 
633  if (nh) {
634  if (path->CopyArpData()) {
635  ret = true;
636  }
637  }
638 
640 
641  return ret;
642 }
643 
645  const AgentRoute *rt) {
646  bool ret = true;
647 
649  NextHop *nh =
650  static_cast<NextHop *>(agent->nexthop_table()->FindActiveEntry(&key));
651  path->set_unresolved(false);
652 
653  if (path->dest_vn_list() != vn_list_) {
654  path->set_dest_vn_list(vn_list_);
655  ret = true;
656  }
657 
658  if (path->sg_list() != sg_list_) {
659  path->set_sg_list(sg_list_);
660  ret = true;
661  }
662 
663  if (path->tag_list() != tag_list_) {
664  path->set_tag_list(tag_list_);
665  ret = true;
666  }
667 
668  if (path->ChangeNH(agent, nh) == true)
669  ret = true;
670 
671  if (nh) {
672  if (path->CopyNdpData()) {
673  ret = true;
674  }
675  }
676 
678 
679  return ret;
680 }
681 
683  const AgentRoute *agent_rt) {
684  path->set_vrf_name(vrf_name_);
685  NextHop *nh = NULL;
686  InetUnicastRouteEntry *rt = NULL;
687 
688  if (gw_list_.empty() || gw_list_.size() == 1) { /* SH case */
689  InetUnicastAgentRouteTable *table = NULL;
690  table = static_cast<InetUnicastAgentRouteTable *>
692  IpAddress gw_ip = gw_list_.empty() ? Ip4Address(0) : gw_list_[0];
693  rt = table->FindRoute(gw_ip);
694  const NextHop *anh;
695  if (rt == NULL || rt->prefix_length() == 0 || (anh = rt->GetActiveNextHop()) == NULL) {
696  path->set_unresolved(true);
697  } else if (anh->GetType() == NextHop::RESOLVE) {
698  const ResolveNH *nh =
699  static_cast<const ResolveNH *>(anh);
700  path->set_unresolved(true);
701  std::string nexthop_vrf = nh->get_interface()->vrf()->GetName();
702  if (nh->get_interface()->vrf()->forwarding_vrf()) {
703  nexthop_vrf = nh->get_interface()->vrf()->forwarding_vrf()->GetName();
704  }
706  nexthop_vrf,
707  nh->get_interface(), nh->PolicyEnabled(),
709  } else {
710  path->set_unresolved(false);
711  }
712  } else { /* MH case */
713  CompositeNHKey *comp_key;
714  bool comp_nh_policy = false;
716 
719 
720  ComponentNHKeyList comp_nh_list;
721  AddressList::const_iterator ptr;
722  for (ptr = gw_list_.begin(); ptr < gw_list_.end(); ptr++) {
723  InetUnicastRouteEntry *uc_rt = table->FindRoute(*ptr);
724  rt = uc_rt;
725  if (uc_rt == NULL || uc_rt->prefix_length() == 0) {
726  path->set_unresolved(true);
727  break;
728  } else if (uc_rt->GetActiveNextHop()->GetType() == NextHop::RESOLVE) {
729  path->set_unresolved(true);
730  const ResolveNH *nh =
731  static_cast<const ResolveNH *>(uc_rt->GetActiveNextHop());
732  path->set_unresolved(true);
733  std::string nexthop_vrf = nh->get_interface()->vrf()->GetName();
734  if (nh->get_interface()->vrf()->forwarding_vrf()) {
735  nexthop_vrf = nh->get_interface()->vrf()->forwarding_vrf()->GetName();
736  }
738  nexthop_vrf, nh->get_interface(), nh->PolicyEnabled(),
740  } else {
741  DBEntryBase::KeyPtr key =
742  uc_rt->GetActiveNextHop()->GetDBRequestKey();
743  NextHopKey *nh_key = static_cast<NextHopKey *>(key.release());
744  std::unique_ptr<const NextHopKey> nh_key_ptr(nh_key);
745  ComponentNHKeyPtr component_nh_key(new ComponentNHKey(-1,
746  std::move(nh_key_ptr)));
747  comp_nh_list.push_back(component_nh_key);
748  }
749  }
750 
751  if (comp_nh_list.size() == gw_list_.size()) {
752  path->set_unresolved(false);
753  nh_req.key.reset(new CompositeNHKey(Composite::ECMP, comp_nh_policy,
754  comp_nh_list, vrf_name_));
755  nh_req.data.reset(new CompositeNHData());
756  comp_key =
757  static_cast<CompositeNHKey *>(nh_req.key.get());
758  nh = static_cast<NextHop *>(agent->nexthop_table()->
759  FindActiveEntry(comp_key));
760  if (!nh) {
761  agent->nexthop_table()->Process(nh_req);
762  nh = static_cast<NextHop *>(agent->nexthop_table()->
763  FindActiveEntry(comp_key));
764  }
765  }
766  }
767 
768  if (path->label() != mpls_label_) {
769  path->set_label(mpls_label_);
770  }
771 
772  if (agent->is_l3mh() == false) {
773  path->set_nexthop(nh);
774  }
775 
776  SecurityGroupList path_sg_list;
777  path_sg_list = path->sg_list();
778  if (path_sg_list != sg_list_) {
779  path->set_sg_list(sg_list_);
780  }
781 
782  TagList path_tag_list;
783  path_tag_list = path->tag_list();
784  if (path_tag_list != tag_list_) {
785  path->set_tag_list(tag_list_);
786  }
787 
788  CommunityList path_communities;
789  path_communities = path->communities();
790  if (path_communities != communities_) {
792  }
793 
794  //Reset to new gateway route, no nexthop for indirect route
795  if (agent->is_l3mh() == false) {
796  IpAddress gw_ip = gw_list_.empty() ? Ip4Address(0) : gw_list_[0];
797  path->set_gw_ip(gw_ip);
798  path->ResetDependantRoute(rt);
799  }
800 
801  if (rt) {
802  path->set_tunnel_bmap(rt->GetActivePath()->tunnel_bmap());
803  }
804 
805  if (native_encap_) {
806  path->set_tunnel_bmap(path->tunnel_bmap() | (1 << TunnelType::NATIVE));
807  }
808 
809  if (path->dest_vn_list() != vn_list_) {
810  path->set_dest_vn_list(vn_list_);
811  }
812 
813  if (agent->is_l3mh() && (path->unresolved() == false) &&
814  path->ChangeNH(agent, nh) == true) {
815  return true;
816  }
817 
818  return true;
819 }
820 
822  const MacAddress& mac,
823  const std::string& parent,
824  AgentRoute *rt) :
825  AgentPath(peer, rt), mac_(mac), parent_(parent) {
826 }
827 
829  //In InetEvpnRoutePath nexthop will always be NULL.
830  //Valid NH is dependant on parent route(subnet).
831  if (dependant_rt()) {
832  const AgentPath *path = dependant_rt()->GetActivePath();
833  if (path != NULL)
834  return path;
835  }
836  return this;
837 }
838 
840  const InetUnicastRouteEntry *dependant_route =
841  dynamic_cast<const InetUnicastRouteEntry *>(dependant_rt());
843  static_cast<InetUnicastAgentRouteTable *>(sync_route->get_table());
844  InetUnicastRouteEntry *parent_subnet_route =
845  table->GetSuperNetRoute(dynamic_cast<const InetUnicastRouteEntry *>
846  (sync_route)->prefix_address());
847 
848  if (parent_subnet_route != dependant_route) {
849  set_gw_ip(parent_subnet_route ? parent_subnet_route->prefix_address() :
850  IpAddress());
851  if (parent_subnet_route) {
852  ResetDependantRoute(parent_subnet_route);
853  set_unresolved(false);
854  } else {
855  //Clear old dependant route
857  set_unresolved(true);
858  }
859  return true;
860  }
861  return false;
862 }
863 
865  return SyncDependantRoute(sync_route);
866 }
867 
869  //InetEvpnRoutePath is deleted when parent evpn route is going off.
870  //Now it may happen that supernet route which was used as dependant_rt in
871  //this path has been deleted.
872  if ((dependant_rt() == NULL) ||
873  (dependant_rt()->GetActiveNextHop() == NULL)) {
874  DiscardNH key;
875  return static_cast<NextHop *>
876  (agent->nexthop_table()->FindActiveEntry(&key));
877  }
878 
879  return AgentPath::ComputeNextHop(agent);
880 }
881 
882 bool InetEvpnRoutePath::IsLess(const AgentPath &r_path) const {
883  const InetEvpnRoutePath *r_evpn_path =
884  dynamic_cast<const InetEvpnRoutePath *>(&r_path);
885  if (r_evpn_path != NULL) {
886  if (r_evpn_path->MacAddr() != mac_) {
887  return (mac_ < r_evpn_path->MacAddr());
888  }
889  }
890 
891  return peer()->IsLess(r_path.peer());
892 }
894  AgentRouteData(AgentRouteData::ADD_DEL_CHANGE,
895  evpn_rt->is_multicast(), 0),
896  mac_(evpn_rt->mac()) {
897  std::stringstream s;
898  s << evpn_rt->ToString();
899  s << " ";
900  parent_ = s.str();
901 }
902 
904  AgentRoute *rt) const {
905  return (new InetEvpnRoutePath(peer, mac_, parent_, rt));
906 }
907 
909  AgentPath *path,
910  const AgentRoute *route) {
911  return dynamic_cast<InetEvpnRoutePath *>(path)->SyncDependantRoute(route);
912 }
913 
915  const AgentRoute *rt) const {
916  const InetEvpnRoutePath *evpn_path =
917  dynamic_cast<const InetEvpnRoutePath *>(path);
918  if (evpn_path == NULL) {
919  return true;
920  }
921  return (evpn_path->MacAddr() == MacAddr());
922 }
923 
925 (const PhysicalInterface *intrface, const std::string &vn_name) :
926  AgentRouteData(AgentRouteData::ADD_DEL_CHANGE, false, 0),
927  interface_key_(new PhysicalInterfaceKey(intrface->name())),
928  vn_name_(vn_name) {
929 }
930 
932  const AgentRoute *rt) {
933  bool ret = false;
934 
935  path->set_unresolved(false);
936  VnListType vn_list;
937  vn_list.insert(agent->fabric_vn_name());
938  if (path->dest_vn_list() != vn_list) {
939  path->set_dest_vn_list(vn_list);
940  ret = true;
941  }
942 
943  Interface *intf = static_cast<Interface *>(
945  assert(intf);
946  InterfaceNHKey key(interface_key_->Clone(), false,
947  InterfaceNHFlags::INET4, intf->mac());
948  NextHop *nh = static_cast<NextHop *>
949  (agent->nexthop_table()->FindActiveEntry(&key));
950  assert(nh);
951  if (path->ChangeNH(agent, nh) == true) {
952  ret = true;
953  }
954 
955  return ret;
956 }
957 
959 // Sandesh functions
961 
962 bool InetUnicastRouteEntry::DBEntrySandesh(Sandesh *sresp, bool stale) const {
963 
964  RouteUcSandeshData data;
965  data.set_src_ip(prefix_address_.to_string());
966  data.set_src_plen(prefix_length());
967  data.set_ipam_subnet_route(ipam_subnet_route_);
968  data.set_ipam_host_route(ipam_host_route_);
969  data.set_proxy_arp(proxy_arp_);
970  data.set_src_vrf(vrf()->GetName());
971  data.set_multicast(AgentRoute::is_multicast());
972  data.set_intf_route_type(AgentRoute::intf_route_type());
973  for (Route::PathList::const_iterator it = GetPathList().begin();
974  it != GetPathList().end(); it++) {
975  const AgentPath *path = static_cast<const AgentPath *>(it.operator->());
976  if (path) {
977  PathSandeshData pdata;
978  path->SetSandeshData(pdata);
980  && (path->tunnel_bmap() & TunnelType::NativeType())) {
981  pdata.set_active_tunnel_type("Native");
982  }
983  data.path_list.push_back(pdata);
984  }
985  }
986 
987  if (prefix_address_.is_v4()) {
988  Inet4UcRouteResp *v4_resp = static_cast<Inet4UcRouteResp *>(sresp);
989  std::vector<RouteUcSandeshData> &list =
990  const_cast<std::vector<RouteUcSandeshData>&>(v4_resp->get_route_list());
991  list.push_back(data);
992  } else {
993  Inet6UcRouteResp *v6_resp = static_cast<Inet6UcRouteResp *>(sresp);
994  std::vector<RouteUcSandeshData> &list =
995  const_cast<std::vector<RouteUcSandeshData>&>(v6_resp->get_route_list());
996  list.push_back(data);
997  }
998  return true;
999 }
1000 
1002  uint8_t plen, bool stale) const {
1003  if (prefix_address_ == addr && prefix_length() == plen) {
1004  return DBEntrySandesh(sresp, stale);
1005  }
1006 
1007  return false;
1008 }
1009 
1010 void UnresolvedRoute::HandleRequest() const {
1012  if (!vrf) {
1013  ErrorResp *resp = new ErrorResp();
1014  resp->set_context(context());
1015  resp->Response();
1016  return;
1017  }
1018 
1019  int count = 0;
1020  Inet4UcRouteResp *resp = new Inet4UcRouteResp();
1021 
1022  //TODO - Convert inet4ucroutetable to agentroutetable
1023  AgentRouteTable *rt_table = static_cast<AgentRouteTable *>
1024  (vrf->GetInet4UnicastRouteTable());
1025  InetUnicastAgentRouteTable::UnresolvedRouteTree::const_iterator it;
1026  it = rt_table->unresolved_route_begin();
1027  for (;it != rt_table->unresolved_route_end(); it++) {
1028  count++;
1029  const AgentRoute *rt = *it;
1030  rt->DBEntrySandesh(resp, false);
1031  if (count == 1) {
1032  resp->set_context(context()+"$");
1033  resp->Response();
1034  count = 0;
1035  resp = new Inet4UcRouteResp();
1036  }
1037  }
1038 
1039  resp->set_context(context());
1040  resp->Response();
1041  return;
1042 }
1043 
1044 void Inet4UcRouteReq::HandleRequest() const {
1045  VrfEntry *vrf =
1046  Agent::GetInstance()->vrf_table()->FindVrfFromId(get_vrf_index());
1047  if (!vrf) {
1048  ErrorResp *resp = new ErrorResp();
1049  resp->set_context(context());
1050  resp->Response();
1051  return;
1052  }
1053 
1054  AgentSandeshPtr sand;
1055  if (get_src_ip().empty()) {
1056  sand.reset(new AgentInet4UcRtSandesh(vrf, context(), get_stale()));
1057  } else {
1058  boost::system::error_code ec;
1059  Ip4Address src_ip = Ip4Address::from_string(get_src_ip(), ec);
1060  sand.reset(new AgentInet4UcRtSandesh(vrf, context(), src_ip,
1061  (uint8_t)get_prefix_len(),
1062  get_stale()));
1063  }
1064  sand->DoSandesh(sand);
1065 }
1066 
1067 void Inet4MplsUcRouteReq::HandleRequest() const {
1068  VrfEntry *vrf =
1069  Agent::GetInstance()->vrf_table()->FindVrfFromId(get_vrf_index());
1070  if (!vrf) {
1071  ErrorResp *resp = new ErrorResp();
1072  resp->set_context(context());
1073  resp->Response();
1074  return;
1075  }
1076 
1077  AgentSandeshPtr sand;
1078  if (get_src_ip().empty()) {
1079  sand.reset(new AgentInet4MplsUcRtSandesh(vrf, context(), get_stale()));
1080  } else {
1081  boost::system::error_code ec;
1082  Ip4Address src_ip = Ip4Address::from_string(get_src_ip(), ec);
1083  sand.reset(new AgentInet4MplsUcRtSandesh(vrf, context(), src_ip,
1084  (uint8_t)get_prefix_len(),
1085  get_stale()));
1086  }
1087  sand->DoSandesh(sand);
1088 }
1089 
1091 (const AgentSandeshArguments *args, const std::string &context) {
1092  if (type_ == Agent::INET4_UNICAST) {
1093  return AgentSandeshPtr(new AgentInet4UcRtSandesh(vrf_entry(), context,
1094  false));
1095  } else if (type_ == Agent::INET4_MPLS) {
1096  return AgentSandeshPtr(new AgentInet4MplsUcRtSandesh(vrf_entry(), context,
1097  false));
1098  } else {
1099  return AgentSandeshPtr(new AgentInet6UcRtSandesh(vrf_entry(), context,
1100  false));
1101  }
1102 }
1103 
1104 void Inet6UcRouteReq::HandleRequest() const {
1105  VrfEntry *vrf =
1106  Agent::GetInstance()->vrf_table()->FindVrfFromId(get_vrf_index());
1107  if (!vrf) {
1108  ErrorResp *resp = new ErrorResp();
1109  resp->set_context(context());
1110  resp->Response();
1111  return;
1112  }
1113 
1114  AgentSandeshPtr sand;
1115  if (get_src_ip().empty()) {
1116  sand.reset(new AgentInet6UcRtSandesh(vrf, context(), get_stale()));
1117  } else {
1118  boost::system::error_code ec;
1119  Ip6Address src_ip = Ip6Address::from_string(get_src_ip(), ec);
1120  sand.reset(new AgentInet6UcRtSandesh(vrf, context(), src_ip,
1121  (uint8_t)get_prefix_len(),
1122  get_stale()));
1123  }
1124  sand->DoSandesh(sand);
1125 }
1126 
1128 // Helper functions to enqueue request or process inline
1130 
1131 // Request to delete an entry
1132 void
1133 InetUnicastAgentRouteTable::DeleteReq(const Peer *peer, const string &vrf_name,
1134  const IpAddress &addr, uint8_t plen,
1135  AgentRouteData *data) {
1137  req.key.reset(new InetUnicastRouteKey(peer, vrf_name, addr, plen));
1138  req.data.reset(data);
1140 
1141 }
1142 
1143 // Inline delete request
1144 void
1145 InetUnicastAgentRouteTable::Delete(const Peer *peer, const string &vrf_name,
1146  const IpAddress &addr, uint8_t plen) {
1148  req.key.reset(new InetUnicastRouteKey(peer, vrf_name, addr, plen));
1149  req.data.reset(NULL);
1151 }
1152 
1153 void
1154 InetUnicastAgentRouteTable::Delete(const Peer *peer, const string &vrf_name,
1155  const IpAddress &addr, uint8_t plen,
1156  AgentRouteData *data) {
1158  req.key.reset(new InetUnicastRouteKey(peer, vrf_name, addr, plen));
1159  req.data.reset(data);
1161 }
1162 
1163 void
1164 InetUnicastAgentRouteTable::DeleteMplsRouteReq(const Peer *peer, const string &vrf_name,
1165  const IpAddress &addr, uint8_t plen,
1166  AgentRouteData *data) {
1168  req.key.reset(new InetMplsUnicastRouteKey(peer, vrf_name, addr, plen));
1169  req.data.reset(data);
1171 }
1172 
1173 // Utility function to create a route to trap packets to agent.
1174 // Assumes that Interface-NH for "HOST Interface" is already present
1175 void
1177  const IpAddress &addr,
1178  uint8_t plen,
1179  const std::string &dest_vn_name,
1180  bool policy) {
1183  req.key.reset(new InetUnicastRouteKey(agent->local_peer(), vrf_name,
1184  addr, plen));
1185 
1186  PacketInterfaceKey intf_key(boost::uuids::nil_uuid(),
1188  HostRoute *data = new HostRoute(intf_key, dest_vn_name);
1189  data->set_policy(policy);
1190  req.data.reset(data);
1191 
1193 }
1194 
1195 // Create Route with VLAN NH
1196 void
1198  const string &vm_vrf,
1199  const IpAddress &addr,
1200  uint8_t plen,
1201  VlanNhRoute *data) {
1203  req.key.reset(new InetUnicastRouteKey(peer, vm_vrf, addr, plen));
1204  req.data.reset(data);
1206 }
1207 
1208 void
1210  const string &vm_vrf,
1211  const IpAddress &addr,
1212  uint8_t plen,
1213  const boost::uuids::uuid &intf_uuid,
1214  uint16_t tag,
1215  uint32_t label,
1216  const VnListType &dest_vn_list,
1217  const SecurityGroupList &sg_list,
1218  const TagList &tag_list,
1219  const PathPreference
1220  &path_preference) {
1221  VmInterfaceKey intf_key(AgentKey::ADD_DEL_CHANGE, intf_uuid, "");
1222  VlanNhRoute *data = new VlanNhRoute(intf_key, tag, label, dest_vn_list,
1223  sg_list, tag_list, path_preference,
1224  peer->sequence_number());
1225  AddVlanNHRouteReq(peer, vm_vrf, addr, plen, data);
1226 }
1227 
1228 // Create Route with VLAN NH
1229 void
1231  const string &vm_vrf,
1232  const IpAddress &addr,
1233  uint8_t plen,
1234  const boost::uuids::uuid &intf_uuid,
1235  uint16_t tag,
1236  uint32_t label,
1237  const VnListType &dest_vn_list,
1238  const SecurityGroupList &sg_list,
1239  const TagList &tag_list,
1240  const PathPreference
1241  &path_preference) {
1243  req.key.reset(new InetUnicastRouteKey(peer, vm_vrf, addr, plen));
1244 
1245  VmInterfaceKey intf_key(AgentKey::ADD_DEL_CHANGE, intf_uuid, "");
1246  req.data.reset(new VlanNhRoute(intf_key, tag, label, dest_vn_list,
1247  sg_list, tag_list, path_preference,
1248  peer->sequence_number()));
1250 }
1251 
1252 void
1254  const string &vm_vrf,
1255  const IpAddress &addr,
1256  uint8_t plen,
1257  LocalVmRoute *data) {
1259  req.key.reset(new InetUnicastRouteKey(peer, vm_vrf, addr, plen));
1260 
1261  req.data.reset(data);
1262 
1264 }
1265 
1266 void
1268  const string &vm_vrf,
1269  const IpAddress &addr,
1270  uint8_t plen,
1271  const boost::uuids::uuid &intf_uuid,
1272  const VnListType &vn_list,
1273  uint32_t label,
1274  const SecurityGroupList &sg_list,
1275  const TagList &tag_list,
1276  const CommunityList &communities,
1277  bool force_policy,
1278  const PathPreference
1279  &path_preference,
1280  const IpAddress &subnet_service_ip,
1281  const EcmpLoadBalance &ecmp_load_balance,
1282  bool is_local,
1283  bool is_health_check_service,
1284  bool native_encap,
1285  const std::string &intf_name,
1286  bool is_learnt_route)
1287 {
1288  VmInterfaceKey intf_key(AgentKey::ADD_DEL_CHANGE, intf_uuid, intf_name);
1289  LocalVmRoute *data = new LocalVmRoute(intf_key, label,
1290  VxLanTable::kInvalidvxlan_id, force_policy,
1291  vn_list, InterfaceNHFlags::INET4, sg_list,
1292  tag_list, communities, path_preference,
1293  subnet_service_ip, ecmp_load_balance,
1294  is_local, is_health_check_service,
1295  peer->sequence_number(),
1296  false, native_encap);
1297 
1298  AddLocalVmRouteReq(peer, vm_vrf, addr, plen, data);
1299 }
1300 
1302  const string &vrf,
1303  const IpAddress &addr,
1304  uint8_t plen) {
1306 
1307  InetUnicastRouteKey *key = new InetUnicastRouteKey(peer, vrf, addr, plen);
1308  key->sub_op_ = AgentKey::RESYNC;
1309  req.key.reset(key);
1310  req.data.reset(NULL);
1312 }
1313 
1314 void
1316  const string &vm_vrf,
1317  const IpAddress &addr,
1318  uint8_t plen,
1319  ClonedLocalPath *data) {
1321  req.key.reset(new InetUnicastRouteKey(peer, vm_vrf, addr, plen));
1322  req.data.reset(data);
1324 }
1325 
1326 // Create Route for a local VM
1327 // Assumes that Interface-NH for "VM Port" is already present
1328 void
1330  const string &vm_vrf,
1331  const IpAddress &addr,
1332  uint8_t plen,
1333  const boost::uuids::uuid &intf_uuid,
1334  const VnListType &vn_list,
1335  uint32_t label,
1336  const SecurityGroupList &sg_list,
1337  const TagList &tag_list,
1338  const CommunityList &communities,
1339  bool force_policy,
1340  const PathPreference
1341  &path_preference,
1342  const IpAddress &subnet_service_ip,
1343  const EcmpLoadBalance &ecmp_load_balance,
1344  bool is_local,
1345  bool is_health_check_service,
1346  const std::string &intf_name,
1347  bool native_encap,
1348  const std::string &intf_route_type,
1349  bool is_learnt_route)
1350 {
1352  req.key.reset(new InetUnicastRouteKey(peer, vm_vrf, addr, plen));
1353 
1354  VmInterfaceKey intf_key(AgentKey::ADD_DEL_CHANGE, intf_uuid, intf_name);
1355  req.data.reset(new LocalVmRoute(intf_key, label, VxLanTable::kInvalidvxlan_id,
1356  force_policy, vn_list,
1357  InterfaceNHFlags::INET4, sg_list, tag_list,
1358  communities, path_preference,
1359  subnet_service_ip,
1360  ecmp_load_balance, is_local,
1361  is_health_check_service,
1362  peer->sequence_number(), false, native_encap,
1363  intf_route_type,
1364  is_learnt_route));
1366 }
1367 
1368 void
1370  const string &vm_vrf,
1371  const IpAddress &vm_addr,
1372  uint8_t plen,
1373  AgentRouteData *data) {
1374  if (Agent::GetInstance()->simulate_evpn_tor())
1375  return;
1377  req.key.reset(new InetUnicastRouteKey(peer, vm_vrf, vm_addr, plen));
1378  req.data.reset(data);
1380 }
1381 
1382 void
1383 InetUnicastAgentRouteTable::AddArpReq(const string &route_vrf_name,
1384  const Ip4Address &ip,
1385  const string &nexthop_vrf_name,
1386  const Interface *intf, bool policy,
1387  const VnListType &vn_list,
1388  const SecurityGroupList &sg_list,
1389  const TagList &tag_list) {
1391  ArpNHKey key(route_vrf_name, ip, policy);
1392  NextHop *nh =
1393  static_cast<NextHop *>(agent->nexthop_table()->FindActiveEntry(&key));
1394  if (!nh) {
1396  nh_req.key.reset(new ArpNHKey(route_vrf_name, ip, policy));
1397  nh_req.data.reset(new ArpNHData(
1398  static_cast<InterfaceKey *>(intf->GetDBRequestKey().release())));
1399  agent->nexthop_table()->Enqueue(&nh_req);
1400  }
1402  rt_req.key.reset(new InetUnicastRouteKey(agent->local_peer(),
1403  route_vrf_name, ip, 32));
1404  rt_req.data.reset(new Inet4UnicastArpRoute(nexthop_vrf_name, ip, policy,
1405  vn_list, sg_list, tag_list));
1406  Inet4UnicastTableEnqueue(agent, &rt_req);
1407 }
1408 
1409 void
1411  const string &route_vrf_name,
1412  const Ip4Address &ip,
1413  const MacAddress &mac,
1414  const string &nexthop_vrf_name,
1415  const Interface &intf,
1416  bool resolved,
1417  const uint8_t plen,
1418  bool policy,
1419  const VnListType &vn_list,
1420  const SecurityGroupList &sg,
1421  const TagList &tag) {
1424  ArpNHKey *nh_key = new ArpNHKey(nexthop_vrf_name, ip, policy);
1425  if (op == DBRequest::DB_ENTRY_DELETE) {
1426  //In case of delete we want to set the
1427  //nexthop as invalid, hence use resync operation
1428  //We dont want the nexthop to created again
1429  //in case of duplicate delete
1430  nh_key->sub_op_ = AgentKey::RESYNC;
1431  }
1432  nh_req.key.reset(nh_key);
1433  ArpNHData *arp_data = new ArpNHData(mac,
1434  static_cast<InterfaceKey *>(intf.GetDBRequestKey().release()),
1435  resolved);
1436  nh_req.data.reset(arp_data);
1437 
1438  DBRequest rt_req(op);
1439  InetUnicastRouteKey *rt_key =
1440  new InetUnicastRouteKey(agent->local_peer(), route_vrf_name, ip, plen);
1441  Inet4UnicastArpRoute *data = NULL;
1442 
1443  switch(op) {
1445  agent->nexthop_table()->Enqueue(&nh_req);
1446  data = new Inet4UnicastArpRoute(nexthop_vrf_name, ip, policy,
1447  vn_list, sg, tag);
1448  break;
1449 
1451  VrfEntry *vrf = agent->vrf_table()->FindVrfFromName(route_vrf_name);
1452  InetUnicastRouteEntry *rt =
1453  static_cast<InetUnicastRouteEntry *>(vrf->
1454  GetInet4UnicastRouteTable()->Find(rt_key));
1455  assert(resolved==false);
1456  agent->nexthop_table()->Enqueue(&nh_req);
1457 
1458  // If no other route is dependent on this, remove the route; else ignore
1459  if (rt && rt->IsDependantRouteEmpty() && rt->IsTunnelNHListEmpty()) {
1460  data = new Inet4UnicastArpRoute(nexthop_vrf_name, ip, policy,
1461  vn_list, sg, tag);
1462  } else {
1463  rt_key->sub_op_ = AgentKey::RESYNC;
1465  }
1466  break;
1467  }
1468 
1469  default:
1470  assert(0);
1471  }
1472 
1473  rt_req.key.reset(rt_key);
1474  rt_req.data.reset(data);
1475  Inet4UnicastTableEnqueue(agent, &rt_req);
1476 }
1477 
1478 void
1480  const string &route_vrf_name,
1481  const IpAddress &ip,
1482  const MacAddress &mac,
1483  const string &nexthop_vrf_name,
1484  const Interface &intf,
1485  bool resolved,
1486  const uint8_t plen,
1487  bool policy,
1488  const VnListType &vn_list,
1489  const SecurityGroupList &sg,
1490  const TagList &tag) {
1493  NdpNHKey *nh_key = new NdpNHKey(nexthop_vrf_name, ip, policy);
1494  if (op == DBRequest::DB_ENTRY_DELETE) {
1495  //In case of delete we want to set the
1496  //nexthop as invalid, hence use resync operation
1497  //We dont want the nexthop to created again
1498  //in case of duplicate delete
1499  nh_key->sub_op_ = AgentKey::RESYNC;
1500  }
1501  nh_req.key.reset(nh_key);
1502  NdpNHData *ndp_data = new NdpNHData(mac,
1503  static_cast<InterfaceKey *>(intf.GetDBRequestKey().release()),
1504  resolved);
1505  nh_req.data.reset(ndp_data);
1506 
1507  DBRequest rt_req(op);
1508  InetUnicastRouteKey *rt_key =
1509  new InetUnicastRouteKey(agent->local_peer(), route_vrf_name, ip, plen);
1510  InetUnicastNdpRoute *data = NULL;
1511 
1512  switch(op) {
1514  agent->nexthop_table()->Enqueue(&nh_req);
1515  data = new InetUnicastNdpRoute(nexthop_vrf_name, ip, policy,
1516  vn_list, sg, tag);
1517  break;
1518 
1520  VrfEntry *vrf = agent->vrf_table()->FindVrfFromName(route_vrf_name);
1521  InetUnicastRouteEntry *rt =
1522  static_cast<InetUnicastRouteEntry *>(vrf->
1523  GetInet6UnicastRouteTable()->Find(rt_key));
1524  assert(resolved==false);
1525  agent->nexthop_table()->Enqueue(&nh_req);
1526 
1527  // If no other route is dependent on this, remove the route; else ignore
1528  if (rt && rt->IsDependantRouteEmpty() && rt->IsTunnelNHListEmpty()) {
1529  data = new InetUnicastNdpRoute(nexthop_vrf_name, ip, policy,
1530  vn_list, sg, tag);
1531  } else {
1532  rt_key->sub_op_ = AgentKey::RESYNC;
1534  }
1535  break;
1536  }
1537 
1538  default:
1539  assert(0);
1540  }
1541 
1542  rt_req.key.reset(rt_key);
1543  rt_req.data.reset(data);
1544  Inet6UnicastTableEnqueue(agent, route_vrf_name, &rt_req);
1545 }
1546 
1548  if (ip == Agent::GetInstance()->router_id() ||
1549  !IsIp4SubnetMember(ip, Agent::GetInstance()->router_id(),
1550  Agent::GetInstance()->vhost_prefix_len())) {
1551  // TODO: add Arp request for GW
1552  // Currently, default GW Arp is added during init
1553  return false;
1554  }
1555 
1556  return true;
1557 }
1558 
1559 void
1561  const Ip4Address &ip,
1562  const MacAddress &mac,
1563  const Interface *intf,
1564  bool resolved,
1565  const VnListType &vn_list,
1566  const SecurityGroupList &sg,
1567  const TagList &tag) {
1568  if (!ShouldAddArp(ip)) {
1569  return;
1570  }
1571  std::string nexthop_vrf = intf->vrf()->GetName();
1572  if (intf->vrf()->forwarding_vrf()) {
1573  nexthop_vrf = intf->vrf()->forwarding_vrf()->GetName();
1574  }
1575  ArpRoute(DBRequest::DB_ENTRY_ADD_CHANGE, route_vrf_name, ip, mac,
1576  nexthop_vrf, *intf, resolved, 32, false, vn_list, sg, tag);
1577 }
1578 
1579 void
1581  const Ip4Address &ip,
1582  const Interface *intf,
1583  const VnListType &vn_list,
1584  const SecurityGroupList &sg,
1585  const TagList &tag) {
1586 
1587  if (!ShouldAddArp(ip)) {
1588  return;
1589  }
1590  std::string nexthop_vrf = intf->vrf()->GetName();
1591  if (intf->vrf()->forwarding_vrf()) {
1592  nexthop_vrf = intf->vrf()->forwarding_vrf()->GetName();
1593  }
1594  AddArpReq(vrf_name, ip, nexthop_vrf, intf, false, vn_list, sg, tag);
1595 }
1596 
1598  const string &vrf_name,
1599  const Ip4Address &ip,
1600  const uint8_t plen,
1601  const InterfaceKey &intf,
1602  const uint32_t label,
1603  bool policy,
1604  const std::string &vn_name,
1605  const SecurityGroupList
1606  &sg_list,
1607  const TagList
1608  &tag_list) {
1610  ResolveNH::CreateReq(&intf, policy);
1612  req.key.reset(new InetUnicastRouteKey(peer, vrf_name, ip,
1613  plen));
1614  req.data.reset(new ResolveRoute(&intf, policy, label, vn_name, sg_list, tag_list));
1616 }
1617 
1618 // Create Route for a interface NH.
1619 // Used to create interface-nh pointing routes to vhost interfaces
1621  const string &vm_vrf,
1622  const Ip4Address &addr,
1623  uint8_t plen,
1624  const string &interface,
1625  uint32_t label,
1626  const VnListType &vn_list) {
1627  InetInterfaceKey intf_key(interface);
1629  (intf_key, label, TunnelType::MplsType(), vn_list,
1630  peer->sequence_number());
1631 
1632  AddInetInterfaceRouteReq(peer, vm_vrf, addr, plen, data);
1633 }
1634 
1636  const string &vm_vrf,
1637  const Ip4Address &addr,
1638  uint8_t plen,
1639  InetInterfaceRoute *data) {
1641  req.key.reset(new InetUnicastRouteKey(peer, vm_vrf, addr, plen));
1642  req.data.reset(data);
1643 
1645 }
1646 
1647 static void AddVHostRecvRouteInternal(DBRequest *req, const Peer *peer,
1648  const string &vrf,
1649  const InterfaceKey &intf_key,
1650  const IpAddress &addr, uint8_t plen,
1651  const string &vn_name, bool policy,
1652  bool native_encap) {
1654  req->key.reset(new InetUnicastRouteKey(peer, vrf, addr, plen));
1655 
1656  int tunnel_bmap = TunnelType::AllType();
1657  if (native_encap) {
1658  tunnel_bmap |= TunnelType::NativeType();
1659  }
1660 
1661  req->data.reset(new ReceiveRoute(intf_key, MplsTable::kInvalidExportLabel,
1662  tunnel_bmap, policy, vn_name));
1663 }
1664 
1665 static void AddVHostMplsRecvRouteInternal(DBRequest *req, const Peer *peer,
1666  const string &vrf,
1667  const InterfaceKey &intf_key,
1668  const IpAddress &addr, uint8_t plen,
1669  const string &vn_name, bool policy,
1670  bool native_encap) {
1672  req->key.reset(new InetMplsUnicastRouteKey(peer, vrf, addr, plen));
1673 
1674  int tunnel_bmap = TunnelType::AllType();
1675  if (native_encap) {
1676  tunnel_bmap |= TunnelType::NativeType();
1677  }
1678 
1679  req->data.reset(new ReceiveRoute(intf_key, MplsTable::kImplicitNullLabel,
1680  tunnel_bmap, policy, vn_name));
1681 }
1683  (const Peer *peer, const string &vrf, const InterfaceKey &intf_key,
1684  const IpAddress &addr, uint8_t plen, const string &vn_name, bool policy,
1685  bool native_encap) {
1686  DBRequest req;
1687  AddVHostMplsRecvRouteInternal(&req, peer, vrf, intf_key, addr, plen,
1688  vn_name, policy, native_encap);
1690 }
1692  const string &vrf,
1693  const InterfaceKey &intf_key,
1694  const IpAddress &addr,
1695  uint8_t plen,
1696  const string &vn_name,
1697  bool policy, bool native_encap, bool ipam_host_route) {
1698  DBRequest req;
1699  AddVHostRecvRouteInternal(&req, peer, vrf, intf_key, addr, plen,
1700  vn_name, policy, native_encap);
1701  static_cast<ReceiveRoute *>(req.data.get())->SetProxyArp(true);
1702  static_cast<ReceiveRoute *>(req.data.get())->SetIpamHostRoute(ipam_host_route);
1703  if (addr.is_v4()) {
1705  } else if (addr.is_v6()) {
1707  }
1708 }
1709 
1711  (const Peer *peer, const string &vrf, const InterfaceKey &intf_key,
1712  const IpAddress &addr, uint8_t plen, const string &vn_name, bool policy,
1713  bool native_encap) {
1714  DBRequest req;
1715  AddVHostRecvRouteInternal(&req, peer, vrf, intf_key, addr, plen,
1716  vn_name, policy, native_encap);
1717  static_cast<ReceiveRoute *>(req.data.get())->SetProxyArp(true);
1718  static_cast<ReceiveRoute *>(req.data.get())->SetIpamHostRoute(true);
1719  if (addr.is_v4()) {
1721  } else if (addr.is_v6()) {
1723  }
1724 }
1725 
1726 void
1728  const string &vrf,
1729  const InterfaceKey &intf_key,
1730  const Ip4Address &addr,
1731  uint8_t plen,
1732  const string &vn_name,
1733  bool policy) {
1734  DBRequest req;
1735  AddVHostRecvRouteInternal(&req, peer, vrf, intf_key, addr, plen,
1736  vn_name, policy, true);
1738 }
1739 
1741  const Ip4Address &addr,
1742  uint8_t plen,
1743  const string &vn_name) {
1746  req.key.reset(new InetUnicastRouteKey(agent->local_peer(), vm_vrf,
1747  Address::GetIp4SubnetAddress(addr, plen),
1748  plen));
1749  req.data.reset(new DropRoute(vn_name));
1751 }
1752 
1754  const Ip4Address &addr,
1755  uint8_t plen) {
1756  DeleteReq(Agent::GetInstance()->local_peer(), vm_vrf,
1757  Address::GetIp4SubnetAddress(addr, plen), 32, NULL);
1758 }
1759 
1760 static void AddGatewayRouteInternal(const Peer *peer,
1761  DBRequest *req, const string &vrf_name,
1762  const Ip4Address &dst_addr, uint8_t plen,
1763  const AddressList &gw_list,
1764  const VnListType &vn_name, uint32_t label,
1765  const SecurityGroupList &sg_list,
1766  const TagList &tag_list,
1767  const CommunityList &communities,
1768  bool native_encap) {
1770  req->key.reset(new InetUnicastRouteKey(peer,
1771  vrf_name, dst_addr, plen));
1772  req->data.reset(new Inet4UnicastGatewayRoute(gw_list, vrf_name,
1773  vn_name, label, sg_list,
1774  tag_list, communities,
1775  native_encap));
1776 }
1777 
1779  const string &vrf_name,
1780  const Ip4Address &dst_addr,
1781  uint8_t plen,
1782  const AddressList &gw_list,
1783  const VnListType &vn_name,
1784  uint32_t label,
1785  const SecurityGroupList
1786  &sg_list,
1787  const TagList
1788  &tag_list,
1789  const CommunityList
1790  &communities,
1791  bool native_encap) {
1792  DBRequest req;
1793  AddGatewayRouteInternal(peer, &req, vrf_name, dst_addr, plen, gw_list, vn_name,
1794  label, sg_list, tag_list, communities, native_encap);
1796 }
1797 
1798 void
1800  const string &vrf_name,
1801  const Ip4Address &dst_addr,
1802  uint8_t plen,
1803  const AddressList &gw_list,
1804  const VnListType &vn_list,
1805  uint32_t label,
1806  const SecurityGroupList
1807  &sg_list,
1808  const TagList
1809  &tag_list,
1810  const CommunityList
1811  &communities,
1812  bool native_encap) {
1813  DBRequest req;
1814  AddGatewayRouteInternal(peer, &req, vrf_name, dst_addr, plen, gw_list,
1815  vn_list, label, sg_list, tag_list, communities,
1816  native_encap);
1818 }
1819 
1820 void
1822  const string &vrf_name,
1823  const IpAddress &dst_addr,
1824  uint8_t plen,
1825  AgentRouteData *data ) {
1827  req.key.reset(new InetMplsUnicastRouteKey(peer, vrf_name, dst_addr, plen));
1828  req.data.reset(data);
1830 }
1831 void
1833  const IpAddress &dst_addr,
1834  uint8_t plen,
1835  const string &vn_name) {
1836  Agent *agent_ptr = agent();
1837  AgentRouteTable *table = NULL;
1838  if (dst_addr.is_v4()) {
1839  table = agent_ptr->vrf_table()->GetInet4UnicastRouteTable(vrf_name);
1840  } else if (dst_addr.is_v6()) {
1841  table = agent_ptr->vrf_table()->GetInet6UnicastRouteTable(vrf_name);
1842  }
1843 
1844  //Add local peer path with discard NH
1846  dscd_nh_req.key.reset(new DiscardNHKey());
1847  dscd_nh_req.data.reset(NULL);
1848 
1849  DBRequest req;
1851  req.key.reset(new InetUnicastRouteKey(agent_ptr->local_peer(),
1852  vrf_name, dst_addr, plen));
1853  req.data.reset(new IpamSubnetRoute(dscd_nh_req, vn_name));
1854  if (table) {
1855  table->Process(req);
1856  }
1857 }
1858 
1859 void
1861  uint8_t plen) {
1862  /* Only IPv4 is supported */
1863  if (!dst_addr.is_v4()) {
1864  return;
1865  }
1866  const string &vrf_name = agent()->fabric_vrf_name();
1867  InetUnicastAgentRouteTable *table = NULL;
1869  const Peer *peer = agent()->fabric_rt_export_peer();
1870 
1871  VnListType vn_list;
1872  vn_list.insert(agent()->fabric_vn_name());
1873  const Ip4Address &gw = agent()->router_id();
1874  table->AddGatewayRoute(peer, vrf_name, dst_addr.to_v4(), plen, AddressList(1, gw), vn_list, /* PKC: Make it as a list */
1876  TagList(), CommunityList(), true);
1877 }
1878 
1879 void
1881  const Peer *peer) {
1882  /* Only IPv4 is supported */
1883  if (!vhost_addr.is_v4()) {
1884  return;
1885  }
1886  const string &vrf_name = agent()->fabric_vrf_name();
1887  InetUnicastAgentRouteTable *table = NULL;
1889 
1890  VmInterfaceKey vmi_key(AgentKey::ADD_DEL_CHANGE, boost::uuids::nil_uuid(),
1891  agent()->vhost_interface_name());
1892  table->AddVHostMplsRecvRouteReq(peer, vrf_name, vmi_key, vhost_addr,
1893  32, agent()->fabric_vn_name(), false, false);
1894 }
1896  if (ip_addr.is_v4()) {
1897  return Address::kMaxV4PrefixLen;
1898  } else {
1899  return Address::kMaxV6PrefixLen;
1900  }
1901 }
1902 
1903 void
1905  const string &vrf_name,
1906  const Ip4Address &ip,
1907  uint8_t plen,
1908  const Interface *intrface,
1909  const string &vn_name) {
1910 
1911  assert(intrface->type() == Interface::PHYSICAL);
1913  rt_req.key.reset(new InetUnicastRouteKey(agent->local_peer(),
1914  vrf_name, ip, plen));
1915  const PhysicalInterface *phy_intf = static_cast<const PhysicalInterface *>
1916  (intrface);
1917  rt_req.data.reset(new Inet4UnicastInterfaceRoute(phy_intf, vn_name));
1918  Inet4UnicastTableEnqueue(agent, &rt_req);
1919 }
1920 
1922  const EvpnRouteEntry *evpn_route =
1923  dynamic_cast<const EvpnRouteEntry *>(route);
1924  const IpAddress &ip_addr = evpn_route->prefix_address();
1925  //No installation for evpn route with zero Ip prefix.
1926  if (ip_addr.is_unspecified())
1927  return;
1928 
1929  //label and parent-ip for NH need to be picket from parent route
1930  DBRequest req;
1932  const uint32_t plen = evpn_route->IsType5() ?
1933  evpn_route->prefix_length() : GetHostPlen(ip_addr);
1934  //Set key and data
1935  req.key.reset(new InetUnicastRouteKey(agent()->inet_evpn_peer(),
1936  evpn_route->vrf()->GetName(),
1937  ip_addr,
1938  plen));
1939  req.data.reset(new InetEvpnRouteData(evpn_route));
1940  Process(req);
1941 }
1942 
1944  const EvpnRouteEntry *evpn_route =
1945  static_cast<const EvpnRouteEntry *>(rt);
1946  const IpAddress &ip_addr = evpn_route->prefix_address();
1948  const Peer *peer = agent()->inet_evpn_peer();
1949  if (evpn_route->IsType5()) {
1950  peer = agent()->evpn_routing_peer();
1951  }
1952  const uint32_t plen = evpn_route->IsType5() ?
1953  evpn_route->prefix_length() : GetHostPlen(ip_addr);
1954  req.key.reset(new InetUnicastRouteKey(peer,
1955  evpn_route->vrf()->GetName(),
1956  ip_addr,
1957  plen));
1958  req.data.reset(new InetEvpnRouteData(evpn_route));
1959  Process(req);
1960 }
1961 
1963  uint8_t plen,
1964  const VrfEntry *vrf,
1965  const Peer *peer,
1966  const SecurityGroupList &sg_list,
1967  const CommunityList &communities,
1968  const PathPreference &path_preference,
1969  const EcmpLoadBalance &ecmp_load_balance,
1970  const TagList &tag_list,
1971  DBRequest &nh_req,
1972  uint32_t vxlan_id,
1973  const VnListType& vn_list,
1974  const std::string& origin_vn) {
1975  DBRequest req;
1977  //Set key and data
1978  req.key.reset(new InetUnicastRouteKey(peer,
1979  vrf_entry()->GetName(),
1980  ip_addr,
1981  plen));
1982  req.data.reset(new EvpnRoutingData(nh_req,
1983  sg_list,
1984  communities,
1985  path_preference,
1986  ecmp_load_balance,
1987  tag_list,
1988  vrf,
1989  vxlan_id,
1990  vn_list,
1991  origin_vn));
1992  Process(req);
1993 }
1994 
1996  uint8_t plen,
1997  const VrfEntry *vrf,
1998  const Peer *peer,
1999  const SecurityGroupList &sg_list,
2000  const CommunityList &communities,
2001  const PathPreference &path_preference,
2002  const EcmpLoadBalance &ecmp_load_balance,
2003  const TagList &tag_list,
2004  DBRequest &nh_req,
2005  uint32_t vxlan_id,
2006  const VnListType& vn_list,
2007  const std::string& origin_vn) {
2008  DBRequest req;
2010  //Set key and data
2011  req.key.reset(new InetUnicastRouteKey(peer,
2012  vrf_entry()->GetName(),
2013  ip_addr,
2014  plen));
2015  req.data.reset(new EvpnRoutingData(nh_req,
2016  sg_list,
2017  communities,
2018  path_preference,
2019  ecmp_load_balance,
2020  tag_list,
2021  vrf,
2022  vxlan_id,
2023  vn_list,
2024  origin_vn));
2026 }
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:16
boost::asio::ip::address IpAddress
Definition: address.h:14
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
bool IsIp4SubnetMember(const Ip4Address &ip, const Ip4Address &prefix_ip, uint16_t plen)
Definition: address_util.cc:20
std::vector< uint64_t > TagList
Definition: agent.h:203
std::vector< int > SecurityGroupList
Definition: agent.h:202
std::vector< Ip4Address > AddressList
Definition: agent.h:218
std::set< std::string > VnListType
Definition: agent.h:213
class boost::shared_ptr< AgentSandesh > AgentSandeshPtr
Definition: agent_db.h:21
std::vector< std::string > CommunityList
Definition: bgp_config.h:348
static const uint8_t kMaxV4PrefixLen
Definition: address.h:21
static Ip4Address GetIp4SubnetAddress(const Ip4Address &prefix, uint16_t plen)
Definition: address.cc:180
static const uint8_t kMaxV6PrefixLen
Definition: address.h:23
static Ip6Address GetIp6SubnetAddress(const Ip6Address &prefix, uint16_t plen)
Definition: address.cc:201
AgentDBEntry * FindActiveEntry(const DBEntry *key)
Definition: agent_db.cc:111
void set_label(uint32_t label)
Definition: agent_path.h:283
void set_tunnel_bmap(TunnelType::TypeBmap bmap)
Definition: agent_path.h:290
void ResetDependantRoute(AgentRoute *rt)
Definition: agent_path.h:316
void set_dest_vn_list(const VnListType &dest_vn_list)
Definition: agent_path.h:284
void set_communities(const CommunityList &communities)
Definition: agent_path.h:294
const VnListType & dest_vn_list() const
Definition: agent_path.h:259
NextHop * nexthop() const
Definition: agent_path.cc:88
bool is_subnet_discard() const
Definition: agent_path.h:274
void set_sg_list(const SecurityGroupList &sg)
Definition: agent_path.h:292
void set_nexthop(NextHop *nh)
Definition: agent_path.cc:579
void SetSandeshData(PathSandeshData &data) const
Definition: agent_path.cc:1721
const AgentRoute * dependant_rt() const
Definition: agent_path.h:317
const SecurityGroupList & sg_list() const
Definition: agent_path.h:249
void set_tag_list(const TagList &tag)
Definition: agent_path.h:293
uint32_t tunnel_bmap() const
Definition: agent_path.h:268
void set_gw_ip(const IpAddress &addr)
Definition: agent_path.h:287
void set_unresolved(bool unresolved)
Definition: agent_path.h:286
const Peer * peer() const
Definition: agent_path.h:264
const bool unresolved() const
Definition: agent_path.h:272
const TagList & tag_list() const
Definition: agent_path.h:250
uint32_t label() const
Definition: agent_path.h:265
bool ChangeNH(Agent *agent, NextHop *nh)
Definition: agent_path.cc:120
bool CopyNdpData()
Definition: agent_path.cc:605
void set_vrf_name(const std::string &vrf_name)
Definition: agent_path.h:289
const CommunityList & communities() const
Definition: agent_path.h:251
void ClearDependantRoute()
Definition: agent_path.h:315
bool CopyArpData()
Definition: agent_path.cc:583
virtual const NextHop * ComputeNextHop(Agent *agent) const
Definition: agent_path.cc:92
This class defines interfaces for manipulating the prefix of a route stored in an Agent VRF table.
Definition: agent_route.h:378
virtual const PrefixType & prefix_address() const
Returns the value of a stored prefix address (IPv4, IPv6 or MAC address)
Definition: agent_route.h:390
IpAddress prefix_address_
The prefix address.
Definition: agent_route.h:400
void set_prefix_length(uint8_t new_plen)
Sets the length of a stored prefix address.
Definition: agent_route.h:393
Agent supports multiple route tables - Inet-unicast (IPv4/IPv6), Inet-multicast, bridge,...
Definition: agent_route.h:110
const std::string & vrf_name() const
Definition: agent_route.cc:456
void Process(DBRequest &req)
Definition: agent_route.cc:187
Agent * agent() const
Definition: agent_route.h:160
UnresolvedRouteTree::const_iterator unresolved_route_end() const
Definition: agent_route.h:141
void EvaluateUnresolvedRoutes(void)
Definition: agent_route.cc:400
VrfEntry * vrf_entry() const
Definition: agent_route.cc:460
virtual void NotifyEntry(AgentRoute *entry)
Definition: agent_route.cc:175
UnresolvedRouteTree::const_iterator unresolved_route_begin() const
Definition: agent_route.h:138
Base class for all Route entries in agent.
Definition: agent_route.h:225
bool IsTunnelNHListEmpty()
Definition: agent_route.h:318
void SetVrf(VrfEntry *vrf)
Definition: agent_route.h:339
const AgentPath * GetActivePath() const
Definition: agent_route.cc:878
bool IsDependantRouteEmpty()
Definition: agent_route.h:317
VrfEntry * vrf() const
Definition: agent_route.h:276
const NextHop * GetActiveNextHop() const
Definition: agent_route.cc:883
virtual bool DBEntrySandesh(Sandesh *sresp, bool stale) const =0
void UpdateDependantRoutes()
Definition: agent_route.cc:937
bool is_multicast() const
Definition: agent_route.h:275
virtual AgentPath * FindPath(const Peer *peer) const
Definition: agent_route.cc:866
const std::string & intf_route_type() const
Definition: agent_route.h:278
Definition: agent.h:361
InterfaceTable * interface_table() const
Definition: agent.h:468
RouteTableType
Definition: agent.h:418
@ INET4_MULTICAST
Definition: agent.h:421
@ INET6_UNICAST
Definition: agent.h:424
@ BRIDGE
Definition: agent.h:423
@ INET4_MPLS
Definition: agent.h:425
@ INET4_UNICAST
Definition: agent.h:420
@ INVALID
Definition: agent.h:419
@ EVPN
Definition: agent.h:422
const std::string & GetHostInterfaceName() const
Definition: agent.cc:94
VrfTable * vrf_table() const
Definition: agent.h:488
const Peer * local_peer() const
Definition: agent.h:1025
const Peer * fabric_rt_export_peer() const
Definition: agent.h:1040
const Peer * inet_evpn_peer() const
Definition: agent.h:1038
const std::string & fabric_vn_name() const
Definition: agent.h:904
bool is_l3mh() const
Definition: agent.h:728
const Peer * evpn_routing_peer() const
Definition: agent.h:1030
NextHopTable * nexthop_table() const
Definition: agent.h:478
static Agent * GetInstance()
Definition: agent.h:439
InetUnicastAgentRouteTable * fabric_inet4_unicast_table() const
Definition: agent.h:581
InetUnicastAgentRouteTable * fabric_inet4_mpls_table() const
Definition: agent.h:592
const std::string & fabric_vrf_name() const
Definition: agent.h:906
Ip4Address router_id() const
Definition: agent.h:669
Definition: nexthop.h:821
const MacAddress & GetMac() const
Definition: nexthop.h:837
void AddMacVmBindingRoute(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const VmInterface *vm_intf, bool flood_dhcp)
void DeleteMacVmBindingRoute(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const VmInterface *vm_intf)
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
DBTableBase * get_table() const
Definition: db_entry.cc:120
virtual KeyPtr GetDBRequestKey() const =0
bool Enqueue(DBRequest *req)
Definition: db_table.cc:221
const std::string & name() const
Definition: db_table.h:111
void Init()
Definition: db_table.cc:414
Definition: db.h:25
Definition: ecmp.h:16
bool Update(AgentRoute *rt)
Definition: ecmp.cc:45
uint8_t prefix_length() const
!
virtual std::string ToString() const
void set_policy(bool policy)
Definition: agent_path.h:782
VnListType vn_list_
Definition: agent_path.h:983
virtual bool AddChangePathExtended(Agent *agent, AgentPath *path, const AgentRoute *rt)
SecurityGroupList sg_list_
Definition: agent_path.h:984
std::string vrf_name_
Definition: agent_path.h:980
const SecurityGroupList sg_list_
Definition: agent_path.h:1038
virtual bool AddChangePathExtended(Agent *agent, AgentPath *path, const AgentRoute *rt)
const TagList tag_list_
Definition: agent_path.h:1039
const CommunityList communities_
Definition: agent_path.h:1040
std::unique_ptr< InterfaceKey > interface_key_
Definition: agent_path.h:1070
Inet4UnicastInterfaceRoute(const PhysicalInterface *intrface, const std::string &vn_name)
virtual bool AddChangePathExtended(Agent *agent, AgentPath *path, const AgentRoute *rt)
const MacAddress & MacAddr() const
Definition: agent_path.h:1173
InetEvpnRouteData(const EvpnRouteEntry *evpn_rt)
const MacAddress mac_
Definition: agent_path.h:1179
std::string parent_
Definition: agent_path.h:1180
virtual bool CanDeletePath(Agent *agent, AgentPath *path, const AgentRoute *rt) const
virtual bool AddChangePathExtended(Agent *agent, AgentPath *path, const AgentRoute *rt)
virtual AgentPath * CreateAgentPath(const Peer *peer, AgentRoute *rt) const
virtual const NextHop * ComputeNextHop(Agent *agent) const
virtual bool Sync(AgentRoute *sync_route)
const MacAddress & MacAddr() const
Definition: agent_path.h:1153
virtual const AgentPath * UsablePath() const
bool SyncDependantRoute(const AgentRoute *sync_route)
MacAddress mac_
Definition: agent_path.h:1160
virtual bool IsLess(const AgentPath &rhs) const
InetEvpnRoutePath(const Peer *peer, const MacAddress &mac, const std::string &parent, AgentRoute *rt)
virtual AgentRouteKey * Clone() const
Agent::RouteTableType type_
InetUnicastRouteEntry * FindResolveRoute(const Ip4Address &ip)
static void AddMplsRouteReq(const Peer *peer, const string &vrf_name, const IpAddress &dst_addr, uint8_t plen, AgentRouteData *data)
static void AddVHostRecvRoute(const Peer *peer, const string &vrf, const InterfaceKey &interface, const IpAddress &addr, uint8_t plen, const string &vn_name, bool policy, bool native_encap, bool ipam_host_route=true)
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, const TagList &tag_list)
static void NdpRoute(DBRequest::DBOperation op, const string &route_vrf_name, const IpAddress &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, const TagList &tag_list)
static void Delete(const Peer *peer, const string &vrf_name, const IpAddress &addr, uint8_t plen)
void TraverseHostRoutesInSubnet(InetUnicastRouteEntry *rt, const Peer *peer)
static bool ShouldAddArp(const Ip4Address &ip)
static void AddVHostRecvRouteReq(const Peer *peer, const string &vrf, const InterfaceKey &interface, const IpAddress &addr, uint8_t plen, const string &vn_name, bool policy, bool native_encap)
uint8_t GetHostPlen(const IpAddress &ip_addr) const
void AddEvpnRoutingRoute(const IpAddress &ip_addr, uint8_t plen, const VrfEntry *vrf, const Peer *peer, const SecurityGroupList &sg_list, const CommunityList &communities, const PathPreference &path_preference, const EcmpLoadBalance &ecmp_load_balance, const TagList &tag_list, DBRequest &nh_req, uint32_t vxlan_id, const VnListType &vn_list, const std::string &origin_vn="")
InetUnicastRouteEntry * FindRouteUsingKey(InetUnicastRouteEntry &key)
bool ResyncSubnetRoutes(const InetUnicastRouteEntry *rt, bool val)
InetUnicastRouteEntry * FindRoute(const IpAddress &ip)
void AddInterfaceRouteReq(Agent *agent, const Peer *peer, const string &vrf_name, const Ip4Address &ip, uint8_t plen, const Interface *intrface, const std::string &vn_name)
static void AddRemoteVmRouteReq(const Peer *peer, const string &vm_vrf, const IpAddress &vm_addr, uint8_t plen, AgentRouteData *data)
static void AddVHostSubnetRecvRoute(const Peer *peer, const string &vrf, const InterfaceKey &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)
void AddIpamSubnetRoute(const string &vm_vrf, const IpAddress &addr, uint8_t plen, const std::string &vn_name)
InetUnicastRouteEntry * FindLPM(const IpAddress &ip)
void AddClonedLocalPathReq(const Peer *peer, const string &vm_vrf, const IpAddress &addr, uint8_t plen, ClonedLocalPath *data)
static void AddVHostMplsRecvRouteReq(const Peer *peer, const string &vrf, const InterfaceKey &interface, const IpAddress &addr, uint8_t plen, const string &vn_name, bool policy, bool native_encap)
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, const TagList &tag_list)
static void AddLocalVmRoute(const Peer *peer, const string &vm_vrf, const IpAddress &addr, uint8_t plen, const boost::uuids::uuid &intf_uuid, const VnListType &vn_list, uint32_t label, const SecurityGroupList &sg_list, const TagList &tag_list, const CommunityList &communities, bool force_policy, const PathPreference &path_preference, const IpAddress &subnet_service_ip, const EcmpLoadBalance &ecmp_load_balance, bool is_local, bool is_health_check_service, const std::string &intf_name, bool native_encap, const std::string &intf_route_type=VmInterface::kInterface, bool is_learnt_route=false)
void DeleteEvpnRoute(const AgentRoute *rt)
void ResyncRoute(const Peer *peer, const string &vrf, const IpAddress &addr, uint8_t plen)
static void CheckAndAddArpReq(const string &vrf_name, const Ip4Address &ip, const Interface *intf, const VnListType &vn_list, const SecurityGroupList &sg, const TagList &tag)
void AddInetInterfaceRouteReq(const Peer *peer, const string &vm_vrf, const Ip4Address &addr, uint8_t plen, InetInterfaceRoute *data)
static void CheckAndAddArpRoute(const string &route_vrf_name, const Ip4Address &ip, const MacAddress &mac, const Interface *intf, bool resolved, const VnListType &vn_list, const SecurityGroupList &sg, const TagList &tag)
InetUnicastRouteEntry * GetNextNonConst(const InetUnicastRouteEntry *rt)
void AddLocalVmRouteReq(const Peer *peer, const string &vm_vrf, const IpAddress &addr, uint8_t plen, LocalVmRoute *data)
InetUnicastRouteEntry * GetSuperNetRoute(const IpAddress &addr)
void AddEvpnRoutingRouteReq(const IpAddress &ip_addr, uint8_t plen, const VrfEntry *vrf, const Peer *peer, const SecurityGroupList &sg_list, const CommunityList &communities, const PathPreference &path_preference, const EcmpLoadBalance &ecmp_load_balance, const TagList &tag_list, DBRequest &nh_req, uint32_t vxlan_id, const VnListType &vn_list, const std::string &origin_vn="")
void AddVrouterSubnetRoute(const IpAddress &dst_addr, uint8_t plen)
void AddEvpnRoute(const AgentRoute *evpn_entry)
InetUnicastAgentRouteTable(DB *db, const std::string &name)
static void AddDropRoute(const string &vm_vrf, const Ip4Address &addr, uint8_t plen, const string &vn_name)
static void DeleteReq(const Peer *peer, const string &vrf_name, const IpAddress &addr, uint8_t plen, AgentRouteData *data)
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, const TagList &tag_list)
static void AddGatewayRoute(const Peer *peer, const string &vrf_name, const Ip4Address &dst_addr, uint8_t plen, const AddressList &gw_list, const VnListType &vn_name, uint32_t label, const SecurityGroupList &sg_list, const TagList &tag_list, const CommunityList &communities, bool native_encap)
IpAddress GetSubnetAddress(const IpAddress &addr, uint16_t plen) const
static void AddVlanNHRoute(const Peer *peer, const string &vm_vrf, const IpAddress &addr, uint8_t plen, const boost::uuids::uuid &intf_uuid, uint16_t tag, uint32_t label, const VnListType &dest_vn_list, const SecurityGroupList &sg_list_, const TagList &tag_list, const PathPreference &path_preference)
static void DeleteMplsRouteReq(const Peer *peer, const string &vrf_name, const IpAddress &addr, uint8_t plen, AgentRouteData *data)
virtual Agent::RouteTableType GetTableType() const
static void AddHostRoute(const string &vrf_name, const IpAddress &addr, uint8_t plen, const std::string &dest_vn_name, bool policy)
virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, const std::string &context)
void AddVlanNHRouteReq(const Peer *peer, const string &vm_vrf, const IpAddress &addr, uint8_t plen, VlanNhRoute *data)
static void AddGatewayRouteReq(const Peer *peer, const string &vrf_name, const Ip4Address &dst_addr, uint8_t plen, const AddressList &gw_list, const VnListType &vn_name, uint32_t label, const SecurityGroupList &sg_list, const TagList &tag_list, const CommunityList &communities, bool native_encap)
void AddVhostMplsRoute(const IpAddress &vhost_addr, const Peer *peer)
static DBTableBase * CreateTable(DB *db, const std::string &name)
std::string vrf_name_
Definition: agent_path.h:1005
SecurityGroupList sg_list_
Definition: agent_path.h:1009
virtual bool AddChangePathExtended(Agent *agent, AgentPath *path, const AgentRoute *rt)
VnListType vn_list_
Definition: agent_path.h:1008
virtual void SetKey(const DBRequestKey *key)
virtual std::string ToString() const
virtual bool ReComputePathAdd(AgentPath *path)
bool IpamSubnetRouteAvailable() const
virtual bool DBEntrySandesh(Sandesh *sresp, bool stale) const
virtual Agent::RouteTableType GetTableType() const
InetUnicastRouteEntry(VrfEntry *vrf, const IpAddress &addr, uint8_t plen, bool is_multicast)
uint8_t prefix_length() const
!
virtual AgentPath * FindPathUsingKeyData(const AgentRouteKey *key, const AgentRouteData *data) const
virtual KeyPtr GetDBRequestKey() const
InetUnicastRouteEntry * GetIpamSuperNetRoute() const
void set_addr(IpAddress addr)
bool UpdateIpamHostFlags(bool ipam_host_route)
virtual bool ReComputePathDeletion(AgentPath *path)
bool UpdateRouteFlags(bool ipam_subnet_route, bool ipam_host_route, bool proxy_arp)
virtual int CompareTo(const Route &rhs) const
AgentPath * FindEvpnPathUsingKeyData(const AgentRouteKey *key, const AgentRouteData *data) const
const IpAddress & addr() const
virtual AgentRouteKey * Clone() const
virtual string ToString() const
uint8_t plen() const
AgentRoute * AllocRouteEntry(VrfEntry *vrf, bool is_multicast) const
@ PHYSICAL
Definition: interface.h:32
const MacAddress & mac() const
Definition: interface.h:134
VrfEntry * vrf() const
Definition: interface.h:118
virtual KeyPtr GetDBRequestKey() const =0
Type type() const
Definition: interface.h:115
static const uint32_t kImplicitNullLabel
Definition: mpls.h:106
static const uint32_t kInvalidExportLabel
Definition: mpls.h:103
void Process(DBRequest &req)
Definition: nexthop.cc:368
bool IsValid() const
Definition: nexthop.h:407
bool PolicyEnabled() const
Definition: nexthop.h:408
@ RESOLVE
Definition: nexthop.h:349
@ ARP
Definition: nexthop.h:350
Type GetType() const
Definition: nexthop.h:406
D * LPMFind(const D *data)
Definition: patricia.h:108
Definition: peer.h:45
bool IsLess(const Peer *rhs) const
Definition: peer.h:74
uint64_t sequence_number() const
Definition: peer.h:95
const Interface * get_interface() const
Definition: nexthop.h:755
static void CreateReq(const InterfaceKey *intf, bool policy)
Definition: nexthop.cc:1591
Definition: route.h:15
const PathList & GetPathList() const
Definition: route.h:47
static TypeBmap AllType()
Definition: nexthop.h:322
static TypeBmap NativeType()
Definition: nexthop.h:326
static TypeBmap MplsType()
Definition: nexthop.h:313
Definition: vrf.h:90
const string & GetName() const
Definition: vrf.h:104
AgentRouteTable * GetBridgeRouteTable() const
Definition: vrf.cc:335
InetUnicastAgentRouteTable * GetInet4UnicastRouteTable() const
Definition: vrf.cc:320
VrfEntry * forwarding_vrf() const
Definition: vrf.h:221
VrfEntry * FindVrfFromName(const string &name)
Definition: vrf.cc:874
InetUnicastAgentRouteTable * GetInet6UnicastRouteTable(const std::string &vrf_name)
Definition: vrf.cc:923
VrfEntry * FindVrfFromId(size_t index)
Definition: vrf.cc:885
InetUnicastAgentRouteTable * GetInet4UnicastRouteTable(const std::string &vrf_name)
Definition: vrf.cc:899
InetUnicastAgentRouteTable * GetInet4MplsUnicastRouteTable(const std::string &vrf_name)
Definition: vrf.cc:905
static const uint32_t kInvalidvxlan_id
Definition: vxlan.h:141
static void Inet6UnicastTableProcess(Agent *agent, const string &vrf_name, DBRequest &req)
static void AddVHostRecvRouteInternal(DBRequest *req, const Peer *peer, const string &vrf, const InterfaceKey &intf_key, const IpAddress &addr, uint8_t plen, const string &vn_name, bool policy, bool native_encap)
static void Inet4MplsUnicastTableEnqueue(Agent *agent, DBRequest *req)
static void Inet4UnicastTableEnqueue(Agent *agent, DBRequest *req)
static void AddGatewayRouteInternal(const Peer *peer, DBRequest *req, const string &vrf_name, const Ip4Address &dst_addr, uint8_t plen, const AddressList &gw_list, const VnListType &vn_name, uint32_t label, const SecurityGroupList &sg_list, const TagList &tag_list, const CommunityList &communities, bool native_encap)
static void Inet4UnicastTableProcess(Agent *agent, const string &vrf_name, DBRequest &req)
static void InetUnicastTableEnqueue(Agent *agent, const string &vrf, DBRequest *req)
static void AddVHostMplsRecvRouteInternal(DBRequest *req, const Peer *peer, const string &vrf, const InterfaceKey &intf_key, const IpAddress &addr, uint8_t plen, const string &vn_name, bool policy, bool native_encap)
static void Inet6UnicastTableEnqueue(Agent *agent, const string &vrf_name, DBRequest *req)
static void InetUnicastTableProcess(Agent *agent, const string &vrf_name, DBRequest &req)
boost::shared_ptr< const ComponentNHKey > ComponentNHKeyPtr
Definition: nexthop.h:1640
std::vector< ComponentNHKeyPtr > ComponentNHKeyList
Definition: nexthop.h:1642
@ ADD_DEL_CHANGE
Definition: agent_db.h:101
@ RESYNC
Definition: agent_db.h:104
uint8_t sub_op_
Definition: agent_db.h:109
const Peer * peer() const
Definition: agent_route.h:48
const std::string & vrf_name() const
Definition: agent_route.h:47
DBOperation oper
Definition: db_table.h:43
@ DB_ENTRY_DELETE
Definition: db_table.h:40
@ DB_ENTRY_ADD_CHANGE
Definition: db_table.h:39
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:49
std::unique_ptr< DBRequestData > data
Definition: db_table.h:50
boost::uuids::uuid uuid