OpenSDN source code
vxlan_auxilliary.cc
Go to the documentation of this file.
1 #include <oper/route_common.h>
4 #include <xmpp_enet_types.h>
5 #include <xmpp_unicast_types.h>
6 #include <oper/tunnel_nh.h>
8 #include <oper/bgp_as_service.h>
9 
10 
11 static void AdvertiseLocalRoute(const IpAddress &prefix_ip,
12  const uint32_t plen,
13  DBRequest &nh_req,
14  const Peer *peer,
15  const RouteParameters& params,
16  EvpnAgentRouteTable *evpn_table);
17 
18 static bool IsGivenTypeCompositeNextHop(const NextHop *nh,
19  NextHop::Type nh_type, bool strict_match = true) {
20  if (nh->GetType() != NextHop::COMPOSITE) {
21  return false;
22  }
23  const CompositeNH *composite_nh =
24  dynamic_cast<const CompositeNH*>(nh);
25  uint32_t comp_nh_count = composite_nh->ComponentNHCount();
26  for (uint32_t i=0; i < comp_nh_count; i++) {
27  const NextHop * c_nh = composite_nh->GetNH(i);
28  if (c_nh != NULL) {
29  // return true if at least one componet is interface
30  if (c_nh->GetType() == nh_type &&
31  !strict_match) {
32  return true;
33  }
34  // return true only if all components are interfaces
35  if (c_nh->GetType() != nh_type &&
36  strict_match) {
37  return false;
38  }
39  }
40  }
41  return strict_match;
42 }
43 
44 //
45 // VxlanRoutingManager members
46 //
47 
49  tbb::mutex::scoped_lock lock(mutex_);
50  const NextHop *path_nh = path->nexthop();
51  if (path_nh->GetType() != NextHop::COMPOSITE) {
52  return 0;
53  }
54  loc_sequence_++;
55  return loc_sequence_;
56 }
57 
58 bool VxlanRoutingManager::is_ipv4_string(const std::string& prefix_str) {
59  return (prefix_str.find(".") != std::string::npos);
60 }
61 
62 bool VxlanRoutingManager::is_ipv6_string(const std::string& prefix_str) {
63  return (prefix_str.find(":") != std::string::npos) &&
64  !is_ipv4_string(prefix_str);
65 }
66 
67 uint32_t VxlanRoutingManager::ipv4_prefix_len(const std::string& prefix_str) {
68  const std::string::size_type slash_pos = prefix_str.rfind("/");
69  if (slash_pos == std::string::npos) {
70  return 32;
71  }
72  const std::string len_str = prefix_str.substr(slash_pos + 1);
73  uint32_t prefix_len = 0;
74  std::istringstream(len_str) >> prefix_len;
75  return std::min(uint32_t(32), prefix_len);
76 }
77 
78 std::string VxlanRoutingManager::ipv4_prefix(const std::string& prefix_str) {
79  std::string::size_type first_dot_pos = 0;
80  std::string::size_type last_colon_pos =
81  prefix_str.rfind(":");
82  std::string::size_type slash_pos = prefix_str.rfind("/");
83  std::string ip_str = "0.0.0.0";
84  if ((first_dot_pos = prefix_str.find(".")) != std::string::npos) {
85  if (first_dot_pos - last_colon_pos >= 2 &&
86  first_dot_pos - last_colon_pos <= 4) {
87  ip_str = prefix_str.substr(last_colon_pos + 1);
88  }
89  if (last_colon_pos == string::npos) {
90  ip_str = prefix_str;
91  }
92  if (slash_pos != string::npos) {
93  ip_str = ip_str.substr(0, slash_pos);
94  }
95  }
96  return ip_str;
97 }
98 
99 uint32_t VxlanRoutingManager::ipv6_prefix_len(const std::string& prefix_str) {
100  const std::string::size_type slash_pos = prefix_str.rfind("/");
101  if (slash_pos == std::string::npos) {
102  return 128;
103  }
104  const std::string len_str = prefix_str.substr(slash_pos + 1);
105  uint32_t prefix_len = 0;
106  std::istringstream(len_str) >> prefix_len;
107  return std::min(uint32_t(128), prefix_len);
108 }
109 
110 std::string VxlanRoutingManager::ipv6_prefix(const std::string& prefix_str) {
111  const std::string zero_mac_str = "00:00:00:00:00:00";
112  const std::string::size_type mac_pos = prefix_str.find(zero_mac_str);
113  std::string ip_str = prefix_str;
114 
115  if (mac_pos != std::string::npos) {
116  ip_str = prefix_str.substr(mac_pos + zero_mac_str.size() + 1);
117  }
118 
119  const std::string::size_type slash_pos = ip_str.rfind("/");
120  if (slash_pos != std::string::npos) {
121  ip_str = ip_str.substr(0, slash_pos);
122  }
123  if (ip_str.find(":") == std::string::npos) {
124  ip_str = "::";
125  }
126  return ip_str;
127 }
128 
130  VxlanRoutingManager *vxlan_rt_mgr = NULL;
131  if (agent->oper_db()) {
132  vxlan_rt_mgr = agent->oper_db()->vxlan_routing_manager();
133  }
134  if (vxlan_rt_mgr == NULL) {
135  return false;
136  }
137  return true;
138 }
139 
140 std::string VxlanRoutingManager::GetOriginVn(const VrfEntry *routing_vrf,
141  const IpAddress& ip_addr,
142  const uint8_t& plen) {
143 
144  std::string origin_vn = "";
145  if (routing_vrf->vn()) {
148  [routing_vrf->vn()->logical_router_uuid()];
150  lr_vrf_info.bridge_vn_list_.begin();
151  while (it != lr_vrf_info.bridge_vn_list_.end()) {
153  (*it)->GetVrf()->GetUcRoute(ip_addr);
154  if (rt && RoutePrefixIsEqualTo(rt, ip_addr, plen)) {
155  origin_vn = (*it)->GetName();
156  break;
157  }
158  it++;
159  }
160  }
161 
162  return origin_vn;
163 }
164 
166  const IpAddress& prefix_ip,
167  const uint32_t prefix_len) {
168  if (route == NULL ||
169  route->prefix_address() != prefix_ip ||
170  route->prefix_length() != prefix_len) {
171  return false;
172  }
173  return true;
174 }
175 
177  const IpAddress& prefix_ip,
178  const uint32_t prefix_len) {
179  if (route == NULL ||
180  route->prefix_address() != prefix_ip ||
181  route->prefix_length() != prefix_len) {
182  return false;
183  }
184  return true;
185 }
186 
187 bool VxlanRoutingManager::IsHostRoute(const IpAddress& prefix_ip, uint32_t prefix_len) {
188  if (prefix_ip.is_v4() && prefix_len == 32)
189  return true;
190  if (prefix_ip.is_v6() && prefix_len == 128)
191  return true;
192  return false;
193 }
194 
196  if (evpn_rt != NULL) {
197  return IsHostRoute(evpn_rt->prefix_address(), evpn_rt->prefix_length());
198  }
199  return false;
200 }
201 
203  if(rt->vrf() == NULL || rt->vrf()->vn() == NULL){
204  LOG(ERROR, "Error in VxlanRoutingManager::IsHostRouteFromLocalSubnet"
205  << ", vrf == NULL || vrf()->vn() == NULL");
206  assert(rt->vrf() && rt->vrf()->vn());
207  }
208 
209  if (IsHostRoute(rt) == false) {
210  return false;
211  }
212 
213  const boost::uuids::uuid lr_uuid =
215  if (lr_uuid == boost::uuids::nil_uuid()) {
216  return false;
217  }
218 
219  const VxlanRoutingVrfMapper::RoutedVrfInfo& vr_info =
220  vrf_mapper_.lr_vrf_info_map_.at(lr_uuid);
222  vr_info.bridge_vn_list_;
223 
224  const VnEntry *bridge_vn = NULL;
226  bridge_vns.begin();
227  while (it_br != bridge_vns.end()) {
228  bridge_vn = *it_br;
229  const std::vector<VnIpam> &VnIpams = bridge_vn->GetVnIpam();
230  for (uint32_t j=0; j < VnIpams.size(); j++) {
231  if (VnIpams[j].IsSubnetMember(rt->prefix_address())) {
232  return true;
233  }
234  }
235  it_br++;
236  }
237  return false;
238 }
239 
241  VrfEntry *bridge_vrf) {
242  // check that the Inet table holds the corresponding route
243  InetUnicastRouteEntry local_vm_route_key(
244  bridge_vrf,
245  routing_evpn_rt->prefix_address(),
246  routing_evpn_rt->prefix_length(), false);
247 
248  InetUnicastAgentRouteTable *inet_table =
249  bridge_vrf->GetInetUnicastRouteTable(routing_evpn_rt->prefix_address());
250  InetUnicastRouteEntry *inet_rt =
251  dynamic_cast<InetUnicastRouteEntry *>
252  (inet_table->FindLPM(local_vm_route_key));
253  if (inet_rt && RoutePrefixIsEqualTo(inet_rt, routing_evpn_rt->prefix_address(),
254  routing_evpn_rt->prefix_length())) {
255  return inet_rt->FindPath(agent_->evpn_routing_peer()) ? false : true;
256  }
257  return false;
258 }
259 
261  const Route::PathList & path_list = rt->GetPathList();
262  for (Route::PathList::const_iterator it = path_list.begin();
263  it != path_list.end(); ++it) {
264  const AgentPath* path =
265  dynamic_cast<const AgentPath*>(it.operator->());
266 
267  if (path != NULL &&
268  path->nexthop() != NULL &&
269  path->nexthop()->GetType() == NextHop::VRF) {
270  return true;
271  }
272  }
273  return false;
274 }
275 
277  const Route::PathList & path_list = evpn_rt->GetPathList();
278  for (Route::PathList::const_iterator it = path_list.begin();
279  it != path_list.end(); ++it) {
280  const AgentPath* path =
281  dynamic_cast<const AgentPath*>(it.operator->());
282  if (path != NULL &&
283  path->peer() != NULL &&
284  path->peer()->GetType() == Peer::BGP_PEER) {
285  return true;
286  }
287  }
288  return false;
289 }
290 
292  return vrf && vrf->vn() &&
293  vrf->vn()->vxlan_routing_vn();
294  // An alternative method
295  // if (vrf == NULL) {
296  // return false;
297  // }
298  // if (vrf->vn() == NULL) {
299  // return false;
300  // }
301  // if (vrf_mapper_.lr_vrf_info_map_.count(
302  // vrf->vn()->logical_router_uuid())) {
303  // const VxlanRoutingVrfMapper::RoutedVrfInfo &lr_vrf_info =
304  // vrf_mapper_.lr_vrf_info_map_.at(vrf->vn()->logical_router_uuid());
305  // if (lr_vrf_info.routing_vrf_ == vrf) {
306  // return true;
307  // }
308  // }
309  // return false;
310 }
311 
313  return vrf && vrf->vn() &&
314  !vrf->vn()->vxlan_routing_vn();
315 }
316 
317 
318 bool VxlanRoutingManager::IsRoutingVrf(const std::string vrf_name,
319  const Agent* agent) {
320  VxlanRoutingManager *vxlan_rt_mgr = NULL;
321  const VrfEntry *vrf_cand = NULL;
322  if (agent->oper_db()) {
323  vxlan_rt_mgr = agent->oper_db()->vxlan_routing_manager();
324  }
325  if (vxlan_rt_mgr == NULL) {
326  return false;
327  }
328  if (agent->vrf_table())
329  vrf_cand = agent->vrf_table()->FindVrfFromName(vrf_name);
330  if (vrf_cand == NULL) {
331  return false;
332  }
333  return vxlan_rt_mgr->IsRoutingVrf(vrf_cand);
334 }
335 
337  const AgentRoute *inet_rt,
338  const Peer::Type peer_type) {
339  if (inet_rt == NULL)
340  return NULL;
341 
342  const Route::PathList & path_list = inet_rt->GetPathList();
343  for (Route::PathList::const_iterator it = path_list.begin();
344  it != path_list.end(); ++it) {
345  const AgentPath* path =
346  dynamic_cast<const AgentPath*>(it.operator->());
347 
348  if (path != NULL &&
349  path->peer()->GetType() == peer_type) {
350  return path;
351  }
352  }
353  return NULL;
354 }
355 
357  const AgentRoute *route,
358  const Peer::Type peer_type,
359  const NextHop::Type nh_type,
360  bool strict_match) {
361  if (route == NULL)
362  return NULL;
363 
364  const Route::PathList & path_list = route->GetPathList();
365  for (Route::PathList::const_iterator it = path_list.begin();
366  it != path_list.end(); ++it) {
367  const AgentPath* path =
368  dynamic_cast<const AgentPath*>(it.operator->());
369 
370  if (path != NULL &&
371  path->nexthop() != NULL &&
372  path->peer() != NULL &&
373  path->peer()->GetType() == peer_type) {
374  if (path->nexthop()->GetType() == nh_type) {
375  return path;
376  }
377  if (IsGivenTypeCompositeNextHop(path->nexthop(), nh_type,
378  strict_match)) {
379  return path;
380  }
381  }
382  }
383  return NULL;
384 }
385 
387  const AgentRoute *inet_rt,
388  const Peer::Type peer_type,
389  bool strict_match) {
390  return FindPathWithGivenPeerAndNexthop(inet_rt,
391  peer_type, NextHop::INTERFACE, strict_match);
392 }
393 
395  const AgentRoute *inet_rt,
396  bool strict_match) {
398  strict_match);
399 }
400 
402  const AgentRoute *inet_rt,
403  bool strict_match) {
405  strict_match);
406 }
407 
409  const Agent *agent) {
410  MacAddress compute_mac;
411  VrfEntry *underlay_vrf = agent->fabric_policy_vrf();
412  InetUnicastRouteEntry *router_rt = NULL;
413  router_rt = underlay_vrf->GetUcRoute(compute_ip);
414  if (router_rt != NULL &&
415  router_rt->prefix_address() == compute_ip) {
416  const AgentPath *apath = FindPathWithGivenPeerAndNexthop(router_rt,
418  if (apath) {
419  const TunnelNH * tunl_nh =
420  dynamic_cast<const TunnelNH*>(apath->nexthop());
421  if (tunl_nh->GetDmac()) {
422  compute_mac = *(tunl_nh->GetDmac());
423  }
424  }
425  }
426  return compute_mac;
427 }
428 
429 //Finds route in a EVPN table
431  const std::string &vrf_name,
432  const IpAddress &ip_addr,
433  unsigned int prefix_len,
434  const autogen::EnetNextHopType &nh_item) {
435 
436  const unsigned int ethernet_tag = 0;
437 
438  EvpnRouteEntry *evpn_rt =
440  vrf_name,
441  MacAddress(),
442  ip_addr,
443  prefix_len,
444  ethernet_tag);
445  if (RoutePrefixIsEqualTo(evpn_rt, ip_addr, prefix_len)) {
446  return evpn_rt;
447  }
448  return NULL;
449 }
450 
451 //Finds route in an Inet table
453  const std::string &vrf_name,
454  const IpAddress &ip_addr,
455  unsigned int prefix_len,
456  const autogen::NextHopType &nh_item) {
457 
458  VrfEntry *vrf_entry =
459  agent->vrf_table()->FindVrfFromName(vrf_name);
460  if (vrf_entry == NULL)
461  return NULL;
462 
463  InetUnicastAgentRouteTable *inet_tbl =
464  vrf_entry->GetInetUnicastRouteTable(ip_addr);
465  if (inet_tbl == NULL)
466  return NULL;
467 
468  InetUnicastRouteEntry local_vm_route_key(inet_tbl->vrf_entry(),
469  ip_addr,
470  prefix_len, false);
471  InetUnicastRouteEntry *inet_rt =
472  dynamic_cast<InetUnicastRouteEntry *>
473  (inet_tbl->FindLPM(local_vm_route_key));
474  if (RoutePrefixIsEqualTo(inet_rt, ip_addr, prefix_len)) {
475  return inet_rt;
476  }
477  return NULL;
478 }
479 
480 static bool InitializeNhRequest(const NextHop *path_nh,
481  DBRequest &nh_req,
482  const std::string& vrf_name) {
483  NextHopKey * orig_key = dynamic_cast<NextHopKey*>(
484  path_nh->GetDBRequestKey().get())->Clone();
485 
486  if(orig_key == NULL) {
487  LOG(ERROR, "Error in InitializeNhRequest"
488  << ", orig_key == NULL");
489  assert(orig_key != NULL);
490  }
491 
492  nh_req.key.reset(orig_key);
493  if (path_nh->GetType() == NextHop::INTERFACE) {
494  InterfaceNHKey *intf_orig_key =
495  dynamic_cast<InterfaceNHKey*>(orig_key);
496  if(intf_orig_key == NULL) {
497  LOG(ERROR, "Error in InitializeNhRequest"
498  << ", intf_orig_key == NULL");
499  assert(intf_orig_key != NULL);
500  }
501  // if NH is an interface, then update flags
502  intf_orig_key->set_flags(intf_orig_key->flags() |
504  nh_req.data.reset(new InterfaceNHData(vrf_name));
505  } else if (path_nh->GetType() == NextHop::COMPOSITE) {
506  nh_req.data.reset(new CompositeNHData);
507  } else { // other types of NH are not expected here
508  LOG(ERROR, "Error in InitializeNhRequest"
509  << ", Wrong NH type:" << path_nh->GetType());
510  assert(
511  path_nh->GetType() == NextHop::INTERFACE ||
512  path_nh->GetType() == NextHop::COMPOSITE);
513  return false;
514  }
515  return true;
516 }
517 
518 //
519 // EVPN routes advertising
520 //
521 
522 static void AdvertiseLocalRoute(const IpAddress &prefix_ip,
523  const uint32_t plen,
524  DBRequest &nh_req,
525  const Peer *peer,
526  const RouteParameters& params,
527  EvpnAgentRouteTable *evpn_table
528 ) {
529  EvpnRoutingData *rt_data = new EvpnRoutingData(nh_req,
530  params.sg_list_,
531  params.communities_,
532  params.path_preference_,
533  params.ecmp_load_balance_,
534  params.tag_list_,
535  evpn_table->vrf_entry(),
536  evpn_table->vrf_entry()->vxlan_id(),
537  params.vn_list_);
538  evpn_table->AddType5Route(peer,
539  evpn_table->vrf_entry()->GetName(),
540  prefix_ip,
541  0, // ethernet_tag = 0 for Type5
542  rt_data,
543  plen);
544 }
545 
546 static void AdvertiseInterfaceBgpRoute(const IpAddress &prefix_ip,
547  const uint32_t plen,
548  DBRequest &nh_req,
549  const Peer *peer,
550  const AgentPath* path,
551  EvpnAgentRouteTable *evpn_table
552 ) {
553  const NextHop *path_nh = path->nexthop();
554 
555  const InterfaceNH *intf_nh = dynamic_cast<const InterfaceNH *>
556  (path_nh);
557  const Interface *intf = intf_nh->GetInterface();
558  if (intf->type() != Interface::VM_INTERFACE) {
559  return;
560  }
561  const VmInterface *vm_intf = dynamic_cast<const VmInterface*>
562  (intf);
563  DBEntryBase::KeyPtr tintf_key_ptr = vm_intf->GetDBRequestKey();
564  const VmInterfaceKey* intf_key_ptr =
565  dynamic_cast<const VmInterfaceKey *>(tintf_key_ptr.get());
566 
567  LocalVmRoute *loc_rt_ptr = new LocalVmRoute(
568  *intf_key_ptr,
569  MplsTable::kInvalidLabel, // mpls_label
570  path->vxlan_id(),
571  path->force_policy(),
572  path->dest_vn_list(),
573  intf_nh->GetFlags(), // flags
574  path->sg_list(),
575  path->tag_list(),
576  path->communities(),
577  path->path_preference(),
578  path->subnet_service_ip(),
579  path->ecmp_load_balance(),
580  path->is_local(),
581  path->is_health_check_service(),
582  path->sequence(),
583  path->etree_leaf(),
584  false); // native_encap
585  loc_rt_ptr->set_tunnel_bmap(TunnelType::VxlanType());
586 
587  {
589 
590  req.key.reset(new EvpnRouteKey(peer,
591  evpn_table->vrf_entry()->GetName(),
592  MacAddress(),
593  prefix_ip,
594  plen,
595  0));
596  req.data.reset(loc_rt_ptr);
597  evpn_table->Enqueue(&req);
598  }
599 }
600 
601 static void AdvertiseCompositeInterfaceBgpRoute(const IpAddress &prefix_ip,
602  const uint32_t plen,
603  DBRequest &nh_req,
604  const Peer *peer,
605  const AgentPath* path,
606  EvpnAgentRouteTable *evpn_table
607 ) {
608  const BgpPeer *bgp_peer = dynamic_cast<const BgpPeer*>(peer);
609  std::stringstream prefix_str;
610  prefix_str << prefix_ip.to_string();
611  prefix_str << "/";
612  prefix_str << plen;
613  std::string vrf_name = evpn_table->vrf_name();
614 
616  bgp_peer,
617  path->dest_vn_list(),
618  path->ecmp_load_balance(),
619  path->tag_list(),
620  path->sg_list(),
621  path->path_preference(),
623  nh_req,
624  prefix_str.str(),
625  evpn_table->vrf_name());
626 
628  rt_data->cloned_local_path_list().begin();
629  while (iter != rt_data->cloned_local_path_list().end()) {
630  evpn_table->AddClonedLocalPathReq(bgp_peer, vrf_name,
631  MacAddress(), prefix_ip, 0, (*iter));
632  iter++;
633  }
634 
635  evpn_table->AddRemoteVmRouteReq(bgp_peer,
636  vrf_name, MacAddress(),
637  prefix_ip,
638  plen,
639  0, // ethernet tag is 0 for VxLAN
640  rt_data);
641 }
642 
643 //
644 // Inet routes advertising
645 //
646 static void AdvertiseLocalRoute(const IpAddress &prefix_ip,
647  const uint32_t plen,
648  DBRequest &nh_req,
649  const Peer *peer,
650  const RouteParameters& params,
651  InetUnicastAgentRouteTable *inet_table,
652  const std::string& origin_vn
653 ) {
654  inet_table->AddEvpnRoutingRoute(prefix_ip,
655  plen,
656  inet_table->vrf_entry(),
657  peer,
658  params.sg_list_,
659  params.communities_,
660  params.path_preference_,
661  params.ecmp_load_balance_,
662  params.tag_list_,
663  nh_req,
664  inet_table->vrf_entry()->vxlan_id(),
665  params.vn_list_,
666  origin_vn);
667 }
668 
670  const uint32_t plen,
671  const Peer *peer,
672  EvpnAgentRouteTable *evpn_table) {
673 
674  if (peer != routing_vrf_interface_peer_) {
675  return;
676  }
677 
678  EvpnRouteEntry *rt_entry = evpn_table->FindRoute(MacAddress(),
679  prefix_ip, plen, 0);
680  if (rt_entry && RoutePrefixIsEqualTo(rt_entry, prefix_ip, plen)) {
681  // Delete the old non-BGP path if it exists
682  AgentPath *old_path = rt_entry->FindPath(peer);
683  if (old_path) {
684  rt_entry->DeletePathFromPeer(rt_entry->get_table_partition(),
685  evpn_table, old_path);
686  }
687  }
688 }
689 
691  const IpAddress &prefix_ip,
692  const uint32_t plen,
693  const Peer *peer,
694  const RouteParameters &params,
695  EvpnAgentRouteTable *evpn_table) {
696  const NextHop *path_nh = path != NULL ? path->nexthop() : NULL;
697 
698  if (path_nh == NULL) {
699  return;
700  }
701 
703  if (InitializeNhRequest(path_nh,
704  nh_req, evpn_table->vrf_entry()->GetName()) == false) {
705  return;
706  }
707 
708  if (peer->GetType() == Peer::BGP_PEER) {
709  if (path_nh->GetType() == NextHop::INTERFACE) {
711  prefix_ip, plen, nh_req, peer, path, evpn_table);
712  } else if (path_nh->GetType() == NextHop::COMPOSITE) {
714  prefix_ip, plen, nh_req, peer, path, evpn_table);
715  }
716  } else {
717  AdvertiseLocalRoute(prefix_ip, plen, nh_req, peer, params,
718  evpn_table);
719  }
720 }
721 
723  const uint32_t plen,
724  const Peer *peer,
725  InetUnicastAgentRouteTable *inet_table) {
726  if (peer != routing_vrf_interface_peer_) {
727  return;
728  }
729 
730  InetUnicastRouteEntry old_rt_key(inet_table->vrf_entry(),
731  prefix_ip, plen, false);
732  InetUnicastRouteEntry *rt_entry = inet_table->FindRouteUsingKey(old_rt_key);
733  if (rt_entry && RoutePrefixIsEqualTo(rt_entry, prefix_ip, plen)) {
734  // Delete the old non-BGP path if it exists
735  AgentPath *old_path = rt_entry->FindPath(peer);
736  if (old_path) {
737  rt_entry->DeletePathFromPeer(rt_entry->get_table_partition(),
738  inet_table, old_path);
739  }
740  }
741 }
742 
744  const IpAddress &prefix_ip,
745  const uint32_t plen,
746  const Peer *peer,
747  const RouteParameters &params,
748  InetUnicastAgentRouteTable *inet_table) {
749  const NextHop *path_nh = path != NULL ? path->nexthop() : NULL;
750  if (path_nh == NULL || inet_table == NULL || peer == NULL) {
751  return;
752  }
753 
754 
756  if (InitializeNhRequest(path_nh,
757  nh_req, inet_table->vrf_entry()->GetName()) == false) {
758  return;
759  }
760 
761  std::string origin_vn = "";
762  if (peer->GetType() == Peer::VXLAN_BGP_PEER) {
763  } else {
764  origin_vn = GetOriginVn(inet_table->vrf_entry(), prefix_ip, plen);
765  }
766  AdvertiseLocalRoute(prefix_ip, plen, nh_req, peer, params,
767  inet_table, origin_vn);
768 }
769 
770 
772  if (const_vrf == NULL) {
773  std::cout<< "VxlanRoutingManager::PrintEvpnTable"
774  << ", NULL vrf ptr"
775  << std::endl;
776  return;
777  }
778  VrfEntry* routing_vrf = const_cast<VrfEntry*>(const_vrf);
779  EvpnAgentRouteTable *evpn_table = dynamic_cast<EvpnAgentRouteTable *>
780  (routing_vrf->GetEvpnRouteTable());
781  if (evpn_table == NULL) {
782  std::cout<< "VxlanRoutingManager::PrintEvpnTable"
783  << ", NULL EVPN tbl ptr"
784  << std::endl;
785  return;
786  }
787  EvpnRouteEntry *c_entry = dynamic_cast<EvpnRouteEntry *>
788  (evpn_table->GetTablePartition(0)->GetFirst());
789  if (c_entry) {
790  if (c_entry->IsType5())
791  std::cout << "Evpn Type 5 table:" << std::endl;
792  else
793  std::cout << "Evpn Type 2 table:" << std::endl;
794  }
795  while (c_entry) {
796  const Route::PathList & path_list = c_entry->GetPathList();
797  std::cout<< " IP:" << c_entry->prefix_address()
798  << ", path count = " << path_list.size()
799  << ", ethernet_tag = " << c_entry->ethernet_tag()
800  << std::endl;
801  for (Route::PathList::const_iterator it = path_list.begin();
802  it != path_list.end(); ++it) {
803  const AgentPath* path =
804  dynamic_cast<const AgentPath*>(it.operator->());
805  if (!path)
806  continue;
807  std::cout<< " NH: "
808  << (path->nexthop() ? path->nexthop()->ToString() :
809  "NULL")
810  << ", " << "Peer:"
811  << (path->peer() ? path->peer()->GetName() : "NULL")
812  << std::endl;
813  if (path->nexthop()->GetType() == NextHop::COMPOSITE) {
814  CompositeNH *comp_nh = dynamic_cast<CompositeNH *>
815  (path->nexthop());
816  std::cout<< " n components="
817  << comp_nh->ComponentNHCount()
818  << std::endl;
819  }
820  }
821  if (evpn_table && evpn_table->GetTablePartition(0))
822  c_entry = dynamic_cast<EvpnRouteEntry *>
823  (evpn_table->GetTablePartition(0)->GetNext(c_entry));
824  else
825  break;
826  }
827 }
828 
830  if (const_vrf == NULL) {
831  std::cout<< "VxlanRoutingManager::PrintInetTable"
832  << ", NULL vrf ptr"
833  << std::endl;
834  return;
835  }
836  VrfEntry* routing_vrf = const_cast<VrfEntry*>(const_vrf);
837  InetUnicastAgentRouteTable *inet_table =
838  routing_vrf->GetInet4UnicastRouteTable();
839  if (inet_table == NULL) {
840  std::cout<< "VxlanRoutingManager::PrintInetTable"
841  << ", NULL Inet tbl ptr"
842  << std::endl;
843  return;
844  }
845  InetUnicastRouteEntry *c_entry = dynamic_cast<InetUnicastRouteEntry *>
846  (inet_table->GetTablePartition(0)->GetFirst());
847  if (c_entry) {
848  std::cout << "Inet table:" << std::endl;
849  }
850  while (c_entry) {
851  const Route::PathList & path_list = c_entry->GetPathList();
852  std::cout<< " IP:" << c_entry->prefix_address()
853  << ", path count = " << path_list.size() << std::endl;
854  for (Route::PathList::const_iterator it = path_list.begin();
855  it != path_list.end(); ++it) {
856  const AgentPath* path =
857  dynamic_cast<const AgentPath*>(it.operator->());
858  if (!path)
859  continue;
860  std::cout<< " NH: "
861  << (path->nexthop() ? path->nexthop()->ToString() :
862  "NULL")
863  << ", " << "Peer:"
864  << (path->peer() ? path->peer()->GetName() : "NULL")
865  << ", nh ptr = " << path->nexthop()
866  << ", pt ptr = " << path
867  << std::endl;
868  // if (path->nexthop()->GetType() == NextHop::COMPOSITE) {
869  // CompositeNH *comp_nh = dynamic_cast<CompositeNH *>
870  // (path->nexthop());
871  // std::cout<< " n components="
872  // << comp_nh->ComponentNHCount()
873  // << std::endl;
874  // }
875  }
876  if (inet_table && inet_table->GetTablePartition(0))
877  c_entry = dynamic_cast<InetUnicastRouteEntry *>
878  (inet_table->GetTablePartition(0)->GetNext(c_entry));
879  else
880  break;
881  }
882 }
883 
885  Agent *agent = Agent::GetInstance();
886  if (agent == NULL) {
887  std::cout<<"VxlanRoutingManager::ListAttachedVns agent == NULL"<<std::endl;
888  return;
889  }
890  VxlanRoutingManager *vxlan_rt_mgr = agent->oper_db()->vxlan_routing_manager();
891  if (vxlan_rt_mgr == NULL) {
892  std::cout<<"VxlanRoutingManager::ListAttachedVns rt mgr = NULL"<<std::endl;
893  return;
894  }
897  for(VxlanRoutingVrfMapper::LrVrfInfoMap::iterator it = lr_vrf_info_map.begin();
898  it != lr_vrf_info_map.end(); it++) {
899  std::cout << "VxlanRoutingManager::ListAttachedVns, "
900  << "rt VRF = "
901  << (*it).second.routing_vrf_->GetName()
902  << std::endl;
903  std::cout << "VxlanRoutingManager::ListAttachedVns, "
904  << "size = "
905  << (*it).second.bridge_vn_list_.size()
906  << std::endl;
908  (*it).second.bridge_vn_list_;
909  for(VxlanRoutingVrfMapper::RoutedVrfInfo::BridgeVnList::iterator it_br = reg_br.begin();
910  it_br != reg_br.end(); it_br++) {
911  if ((*it_br))
912  std::cout<< "VxlanRoutingManager::ListAttachedVns, "
913  << "br VN = " << (*it_br)->GetName()
914  << std::endl;
915  }
916  }
917 }
918 
919 //
920 //END-OF-FILE
921 //
boost::asio::ip::address IpAddress
Definition: address.h:13
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
bool is_health_check_service() const
Definition: agent_path.h:380
uint32_t sequence() const
Definition: agent_path.h:328
bool is_local() const
Definition: agent_path.h:372
const VnListType & dest_vn_list() const
Definition: agent_path.h:258
NextHop * nexthop() const
Definition: agent_path.cc:87
const EcmpLoadBalance & ecmp_load_balance() const
Definition: agent_path.h:365
const PathPreference & path_preference() const
Definition: agent_path.h:329
const SecurityGroupList & sg_list() const
Definition: agent_path.h:248
uint32_t vxlan_id() const
Definition: agent_path.h:265
const Peer * peer() const
Definition: agent_path.h:263
bool force_policy() const
Definition: agent_path.h:270
const TagList & tag_list() const
Definition: agent_path.h:249
const IpAddress subnet_service_ip() const
Definition: agent_path.h:274
bool etree_leaf() const
Definition: agent_path.h:388
const CommunityList & communities() const
Definition: agent_path.h:250
virtual const PrefixType & prefix_address() const
Returns the value of a stored prefix address (IPv4, IPv6 or MAC address)
Definition: agent_route.h:389
const std::string & vrf_name() const
Definition: agent_route.cc:455
VrfEntry * vrf_entry() const
Definition: agent_route.cc:459
Base class for all Route entries in agent.
Definition: agent_route.h:224
VrfEntry * vrf() const
Definition: agent_route.h:275
void DeletePathFromPeer(DBTablePartBase *part, AgentRouteTable *table, AgentPath *path)
Definition: agent_route.cc:655
virtual AgentPath * FindPath(const Peer *peer) const
Definition: agent_route.cc:865
Definition: agent.h:360
OperDB * oper_db() const
Definition: agent.cc:1016
VrfTable * vrf_table() const
Definition: agent.h:487
VrfEntry * fabric_policy_vrf() const
Definition: agent.h:919
const Peer * evpn_routing_peer() const
Definition: agent.h:1029
static Agent * GetInstance()
Definition: agent.h:438
size_t ComponentNHCount() const
Definition: nexthop.h:1815
const NextHop * GetNH(uint32_t idx) const
Definition: nexthop.h:1832
ClonedLocalPathList::iterator ClonedLocalPathListIter
ClonedLocalPathList & cloned_local_path_list()
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
virtual KeyPtr GetDBRequestKey() const =0
DBTablePartBase * get_table_partition() const
Definition: db_entry.cc:115
bool Enqueue(DBRequest *req)
Definition: db_table.cc:194
virtual DBEntryBase * GetNext(const DBEntryBase *)=0
virtual DBEntryBase * GetFirst()=0
virtual DBTablePartBase * GetTablePartition(const DBRequestKey *key)
Definition: db_table.cc:436
void AddClonedLocalPathReq(const Peer *peer, const string &vrf_name, const MacAddress &mac, const IpAddress &ip_addr, uint32_t ethernet_tag, ClonedLocalPath *data)
EvpnRouteEntry * FindRoute(const MacAddress &mac, const IpAddress &ip_addr, uint32_t plen, uint32_t ethernet_tag)
static void AddRemoteVmRouteReq(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const IpAddress &ip_addr, uint32_t plen, uint32_t ethernet_tag, AgentRouteData *data)
void AddType5Route(const Peer *peer, const std::string &vrf_name, const IpAddress &ip_addr, uint32_t ethernet_tag, EvpnRoutingData *data, uint8_t plen=0)
uint32_t ethernet_tag() const
uint8_t prefix_length() 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)
InetUnicastRouteEntry * FindLPM(const IpAddress &ip)
uint8_t prefix_length() const
!
void set_flags(uint8_t flags)
Definition: nexthop.h:1215
const uint8_t & flags() const
Definition: nexthop.h:1216
const Interface * GetInterface() const
Definition: nexthop.h:1293
uint8_t GetFlags() const
Definition: nexthop.h:1300
@ VM_INTERFACE
Definition: interface.h:35
Type type() const
Definition: interface.h:112
void set_tunnel_bmap(TunnelType::TypeBmap bmap)
Definition: agent_path.h:679
static const uint32_t kInvalidLabel
Definition: mpls.h:101
@ COMPOSITE
Definition: nexthop.h:354
@ INTERFACE
Definition: nexthop.h:351
@ TUNNEL
Definition: nexthop.h:352
@ VRF
Definition: nexthop.h:350
virtual std::string ToString() const
Definition: nexthop.h:368
Type GetType() const
Definition: nexthop.h:405
VxlanRoutingManager * vxlan_routing_manager() const
Definition: operdb_init.h:98
Definition: peer.h:44
const Type GetType() const
Definition: peer.h:87
Type
Definition: peer.h:48
@ BGP_PEER
Definition: peer.h:51
@ LOCAL_VM_PORT_PEER
Definition: peer.h:56
@ VXLAN_BGP_PEER
Definition: peer.h:55
const std::string & GetName() const
Definition: peer.h:86
const PathList & GetPathList() const
Definition: route.h:46
boost::intrusive::list< Path, PathListMember > PathList
Definition: route.h:20
const MacAddress * GetDmac() const
Definition: tunnel_nh.h:39
static TypeBmap VxlanType()
Definition: nexthop.h:311
KeyPtr GetDBRequestKey() const
Definition: vn.h:151
const std::vector< VnIpam > & GetVnIpam() const
Definition: vn.h:171
const boost::uuids::uuid & logical_router_uuid() const
Definition: vn.h:257
bool vxlan_routing_vn() const
Definition: vn.h:256
Definition: vrf.h:86
const string & GetName() const
Definition: vrf.h:100
InetUnicastRouteEntry * GetUcRoute(const IpAddress &addr) const
Definition: vrf.cc:237
InetUnicastAgentRouteTable * GetInet4UnicastRouteTable() const
Definition: vrf.cc:319
InetUnicastAgentRouteTable * GetInetUnicastRouteTable(const IpAddress &addr) const
Definition: vrf.cc:575
AgentRouteTable * GetEvpnRouteTable() const
Definition: vrf.cc:330
uint32_t vxlan_id() const
Definition: vrf.h:165
VnEntry * vn() const
Definition: vrf.h:101
VrfEntry * FindVrfFromName(const string &name)
Definition: vrf.cc:873
This class manages routes leaking between bridge VRF instances and the routing VRF instance....
static void ListAttachedVns()
Prints all virtual networks attached to logical routers.
static void CopyInterfacePathToEvpnTable(const AgentPath *path, const IpAddress &prefix_ip, const uint32_t plen, const Peer *peer, const RouteParameters &params, EvpnAgentRouteTable *evpn_table)
Copies the path to the prefix address into the EVPN table with the given Peer. The function is used d...
static bool RoutePrefixIsEqualTo(const EvpnRouteEntry *route, const IpAddress &prefix_ip, const uint32_t prefix_len)
Determines whether route prefix in the EVPN route is equal to the given pair of prefix IP address and...
bool HasBgpPeerPath(EvpnRouteEntry *evpn_rt)
Determines whether the given EVPN route has at least one path originating from BGP/XMPP (has Peer typ...
static bool IsVxlanAvailable(const Agent *agent)
Checks whether VxLAN routing manager is enabled or not.
const VxlanRoutingVrfMapper & vrf_mapper() const
Returns the map between LR uuids and associated bridge and routing VRF instances.
static bool is_ipv4_string(const std::string &prefix_str)
Determines whether the address string contains an IPv4 address as substring or not.
static uint32_t loc_sequence_
An always increasing counter for new paths (used to signal controoler about new routes).
static bool IsHostRoute(const IpAddress &prefix_ip, uint32_t prefix_len)
Determines whether the prefix address and the prefix length point to a host route (/32 for IPv4,...
static AgentRoute * FindEvpnOrInetRoute(const Agent *agent, const std::string &vrf_name, const IpAddress &ip_addr, uint32_t prefix_len, const autogen::EnetNextHopType &nh_item)
Finds a route with the given prefix address and len in the EVPN table.
static const AgentPath * FindPathWithGivenPeer(const AgentRoute *inet_rt, const Peer::Type peer_type)
Finds in the given route the path with a specified Peer type.
static std::string ipv6_prefix(const std::string &prefix_str)
Extracts an IPv6 address string from the prefix string.
std::string GetOriginVn(const VrfEntry *routing_vrf, const IpAddress &ip_addr, const uint8_t &plen)
Finds first occurence of a route with the given prefix (IP address and length) in Inet tables of brid...
static const AgentPath * FindInterfacePathWithLocalVmPeer(const AgentRoute *inet_rt, bool strict_match=true)
Finds in the given route the path which has the LOCAL_VM_PEER peer type and the Interface nexthop typ...
static uint32_t GetNewLocalSequence(const AgentPath *)
Auxilliary functions.
static const Peer * routing_vrf_interface_peer_
Internal data of this class.
static bool IsBridgeVrf(const VrfEntry *vrf)
Determines whether the pointer to the VRF instance is of bridge type.
static bool HasVrfNexthop(const AgentRoute *rt)
Determines whether the given route has the path with a VRF nexthop (VrfNH)
static const AgentPath * FindPathWithGivenPeerAndNexthop(const AgentRoute *inet_rt, const Peer::Type peer_type, const NextHop::Type nh_type, bool strict_match=true)
Finds in the given route the path with a specified Peer type and a specified nexthop type.
static void PrintEvpnTable(const VrfEntry *const_vrf)
Prints EVPN table of the given VRF instance.
bool IsHostRouteFromLocalSubnet(const EvpnRouteEntry *rt)
Determines whether the given EVPN route is a host one and belongs to a subnet of a local bridge VRF....
static bool IsRoutingVrf(const VrfEntry *vrf)
Determines whether the pointer to the VRF instance is of routing type.
static uint32_t ipv4_prefix_len(const std::string &prefix_str)
Extracts length of IPv4 subnet address from the prefix string.
static MacAddress NbComputeMac(const Ip4Address &compute_ip, const Agent *agent)
Returns the MAC address for the IP of a given neighbouring compute.
Agent * agent_
A pointer to the Agent instance.
void CopyPathToInetTable(const AgentPath *path, const IpAddress &prefix_ip, const uint32_t plen, const Peer *peer, const RouteParameters &params, InetUnicastAgentRouteTable *inet_table)
Copies the path to the prefix address into the EVPN table with the given Peer. The function is used d...
static const AgentPath * FindInterfacePathWithGivenPeer(const AgentRoute *inet_rt, const Peer::Type peer_type, bool strict_match=true)
Finds in the given route the path with the given Peer type and interface nexthop (InterfaceNH).
static tbb::mutex mutex_
bool IsVrfLocalRoute(EvpnRouteEntry *routing_evpn_rt, VrfEntry *bridge_vrf)
Determines if the given EVPN route has an interface NH or a composite of interfaces NH that belongs t...
static const AgentPath * FindInterfacePathWithBgpPeer(const AgentRoute *inet_rt, bool strict_match=true)
Finds in the given route the path which has the BGP_PEER Peer type and the Interface nexthop type....
static bool is_ipv6_string(const std::string &prefix_str)
Determines whether the address string contains an IPv6 address as substring or not.
static std::string ipv4_prefix(const std::string &prefix_str)
Extracts an IPv4 address string from the prefix string.
static void PrintInetTable(const VrfEntry *const_vrf)
Prints IPv4 Inet table of the given VRF instance.
static uint32_t ipv6_prefix_len(const std::string &prefix_str)
Extracts length of IPv6 subnet address from the prefix string.
VxlanRoutingVrfMapper vrf_mapper_
A map between LR uuids and associated bridge and routing VRF instances.
static void DeleteOldInterfacePath(const IpAddress &prefix_ip, const uint32_t plen, const Peer *peer, EvpnAgentRouteTable *evpn_table)
Routes copying functions.
The class is used to store following information:
LrVrfInfoMap lr_vrf_info_map_
The map between Logical router UUID and RoutedVrfInfo.
const boost::uuids::uuid GetLogicalRouterUuidUsingRoute(const AgentRoute *rt)
Find the UUID of the LR using a given route (AgentRoute).
std::map< boost::uuids::uuid, RoutedVrfInfo > LrVrfInfoMap
A typedef to store map between Logical router UUID and RoutedVrfInfo.
#define LOG(_Level, _Msg)
Definition: logging.h:33
@ DB_ENTRY_ADD_CHANGE
Definition: db_table.h:38
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:48
std::unique_ptr< DBRequestData > data
Definition: db_table.h:49
A structure to hold path parameters during the transfer (routes leaking) of data between VRF instance...
const EcmpLoadBalance & ecmp_load_balance_
A reference to EcmpLoadBalance of the path.
const TagList & tag_list_
A list of tags.
const PathPreference & path_preference_
A reference to the PathPreference of the path.
const CommunityList & communities_
A list of communities.
const SecurityGroupList & sg_list_
A list of security groups.
const VnListType & vn_list_
A list of path destination virtual networks used in policy lookups.
The structure holds information about virtual networks connected to a logical router (LR)
std::set< const VnEntry * > BridgeVnList
A typedef to store the list of bridge virtual networks connected to a LR.
BridgeVnList::iterator BridgeVnListIter
A type for iterator of the list of bridge virtual networks connected to a LR.
BridgeVnList bridge_vn_list_
The list of bridge virtual networks (VirtualNetwork) connected to a LR.
boost::uuids::uuid uuid
static void AdvertiseInterfaceBgpRoute(const IpAddress &prefix_ip, const uint32_t plen, DBRequest &nh_req, const Peer *peer, const AgentPath *path, EvpnAgentRouteTable *evpn_table)
static bool IsGivenTypeCompositeNextHop(const NextHop *nh, NextHop::Type nh_type, bool strict_match=true)
static bool InitializeNhRequest(const NextHop *path_nh, DBRequest &nh_req, const std::string &vrf_name)
static void AdvertiseCompositeInterfaceBgpRoute(const IpAddress &prefix_ip, const uint32_t plen, DBRequest &nh_req, const Peer *peer, const AgentPath *path, EvpnAgentRouteTable *evpn_table)
static void AdvertiseLocalRoute(const IpAddress &prefix_ip, const uint32_t plen, DBRequest &nh_req, const Peer *peer, const RouteParameters &params, EvpnAgentRouteTable *evpn_table)