OpenSDN source code
icmpv6_proto.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 "base/os.h"
7 #include <init/agent_init.h>
8 #include <pkt/pkt_handler.h>
9 #include "pkt/pkt_init.h"
10 #include <oper/route_common.h>
11 #include <services/icmpv6_proto.h>
13 
14 Icmpv6Proto::Icmpv6Proto(Agent *agent, boost::asio::io_context &io) :
15  Proto(agent, "Agent::Services", PktHandler::ICMPV6, io) {
16  // limit the number of entries in the workqueue
18  work_queue_.SetBounded(true);
19 
21  boost::bind(&Icmpv6Proto::VnNotify, this, _2));
23  boost::bind(&Icmpv6Proto::VrfNotify, this, _1, _2));
25  boost::bind(&Icmpv6Proto::InterfaceNotify,
26  this, _2));
28  boost::bind(&Icmpv6Proto::NexthopNotify, this, _2));
29 
30  boost::shared_ptr<PktInfo> pkt_info(new PktInfo(PktHandler::ICMPV6, NULL));
31  icmpv6_handler_.reset(new Icmpv6Handler(agent, pkt_info, io));
32 
33  timer_ = TimerManager::CreateTimer(io, "Icmpv6Timer",
34  TaskScheduler::GetInstance()->GetTaskId("Agent::Services"),
38  icmpv6_handler_.get(), this));
39 }
40 
42 }
43 
48  timer_->Cancel();
50 }
51 
52 ProtoHandler *Icmpv6Proto::AllocProtoHandler(boost::shared_ptr<PktInfo> info,
53  boost::asio::io_context &io) {
54  return new Icmpv6Handler(agent(), info, io);
55 }
56 
58  Icmpv6VrfState *state = new Icmpv6VrfState(agent_, this, vrf,
60  vrf->GetEvpnRouteTable());
62  Register(boost::bind(&Icmpv6VrfState::RouteUpdate, state, _1, _2)));
64  Register(boost::bind(&Icmpv6VrfState::EvpnRouteUpdate, state, _1, _2)));
65  vrf->SetState(vrf->get_table_partition()->parent(),
66  vrf_table_listener_id_, state);
67  return state;
68 }
69 
71  if (entry->IsDeleted()) return;
72 
73  VnEntry *vn = static_cast<VnEntry *>(entry);
74  VrfEntry *vrf = vn->GetVrf();
75  if (!vrf || vrf->IsDeleted()) return;
76 
77  if (vrf->GetName() == agent_->fabric_vrf_name())
78  return;
79 
80  if (vn->layer3_forwarding()) {
81  Icmpv6VrfState *state = static_cast<Icmpv6VrfState *>(vrf->GetState(
82  vrf->get_table_partition()->parent(),
84  if (state == NULL) {
85  state = CreateAndSetVrfState(vrf);
86  }
87  if (state->default_routes_added()) {
88  return;
89  }
90 
91  boost::system::error_code ec;
92  Ip6Address addr = Ip6Address::from_string(IPV6_ALL_ROUTERS_ADDRESS, ec);
93  static_cast<InetUnicastAgentRouteTable *>
94  (vrf->GetInet6UnicastRouteTable())->AddHostRoute(vrf->GetName(),
95  addr, 128,
96  vn->GetName(), false);
97  addr = Ip6Address::from_string(IPV6_ALL_NODES_ADDRESS, ec);
98  static_cast<InetUnicastAgentRouteTable *>
99  (vrf->GetInet6UnicastRouteTable())->AddHostRoute(vrf->GetName(),
100  addr, 128,
101  vn->GetName(), false);
102  /* We need route for PKT0_LINKLOCAL_ADDRESS so that vrouter can respond
103  * to NDP requests for PKT0_LINKLOCAL_ADDRESS. Even though the nexthop
104  * for this route is pkt0, vrouter never sends pkts pointing to this
105  * route on pkt0.
106  */
107  addr = Ip6Address::from_string(PKT0_LINKLOCAL_ADDRESS, ec);
108  static_cast<InetUnicastAgentRouteTable *>
109  (vrf->GetInet6UnicastRouteTable())->AddHostRoute(vrf->GetName(),
110  addr, 128,
111  vn->GetName(), false);
112  state->set_default_routes_added(true);
113  }
114 }
115 
117  VrfEntry *vrf = static_cast<VrfEntry *>(entry);
118 
119  Icmpv6VrfState *state = static_cast<Icmpv6VrfState *>(vrf->GetState(
120  vrf->get_table_partition()->parent(),
122  if (entry->IsDeleted()) {
123  if (state) {
124  boost::system::error_code ec;
125  Ip6Address addr =
126  Ip6Address::from_string(IPV6_ALL_ROUTERS_ADDRESS, ec);
127  // enqueue delete request on fabric VRF
129  agent_->local_peer(), vrf->GetName(), addr, 128, NULL);
130  addr = Ip6Address::from_string(IPV6_ALL_NODES_ADDRESS, ec);
132  agent_->local_peer(), vrf->GetName(), addr, 128, NULL);
133  addr = Ip6Address::from_string(PKT0_LINKLOCAL_ADDRESS, ec);
135  agent_->local_peer(), vrf->GetName(), addr, 128, NULL);
136  state->set_default_routes_added(false);
137  state->Delete();
138  }
139  return;
140  }
141  if (!state) {
143  }
144 }
145 
147  Interface *intrface = static_cast<Interface *>(entry);
148  if (intrface->type() != Interface::VM_INTERFACE)
149  return;
150 
151  Icmpv6Stats stats;
152  VmInterface *vm_interface = static_cast<VmInterface *>(entry);
153  VmInterfaceMap::iterator it = vm_interfaces_.find(vm_interface);
154  if (intrface->IsDeleted()) {
155  if (it != vm_interfaces_.end()) {
156  vm_interfaces_.erase(it);
157  }
158  if (vm_interface->vmi_type() == VmInterface::VHOST) {
161  }
162  } else {
163  if (it == vm_interfaces_.end()) {
164  vm_interfaces_.insert(VmInterfacePair(vm_interface, stats));
165  }
166  if (vm_interface->vmi_type() == VmInterface::VHOST) {
167  set_ip_fabric_interface(intrface);
168  set_ip_fabric_interface_index(intrface->id());
169  set_ip_fabric_interface_mac(intrface->mac());
170  }
171  }
172 }
173 
175  const VrfEntry *vrf, InterfaceConstRef itf) {
176  Icmpv6Ipc *ipc = new Icmpv6Ipc(type, ip, vrf, itf);
178 }
179 
181  InterfaceConstRef itf) {
182  Icmpv6Ipc *ipc = new Icmpv6Ipc(type, key, itf);
184 }
185 
187  NextHop *nh = static_cast<NextHop *>(entry);
188 
189  switch(nh->GetType()) {
190  case NextHop::NDP: {
191  NdpNH *ndp_nh = (static_cast<NdpNH *>(nh));
192  if (ndp_nh->IsDeleted()) {
193  SendIcmpv6Ipc(Icmpv6Proto::NDP_DELETE, ndp_nh->GetIp()->to_v6(),
194  ndp_nh->GetVrf(), ndp_nh->GetInterface());
195  } else if (ndp_nh->IsValid() == false && ndp_nh->GetInterface()) {
196  SendIcmpv6Ipc(Icmpv6Proto::NDP_RESOLVE, ndp_nh->GetIp()->to_v6(),
197  ndp_nh->GetVrf(), ndp_nh->GetInterface());
198  }
199  break;
200  }
201 
202  default:
203  break;
204  }
205 }
206 
208  Icmpv6VrfState *vrf_state) {
209  if (!vrf->IsDeleted()) {
210  return false;
211  }
212 
213  if (vrf_state->l3_walk_completed() == false) {
214  return false;
215  }
216 
217  if (vrf_state->evpn_walk_completed() == false) {
218  return false;
219  }
220 
221  if (vrf_state->managed_delete_walk_ref().get() != NULL ||
222  vrf_state->evpn_walk_ref().get() != NULL) {
223  return false;
224  }
225 
226  DBState *state = static_cast<DBState *>
227  (vrf->GetState(vrf->get_table_partition()->parent(),
229  if (state) {
230  vrf->ClearState(vrf->get_table_partition()->parent(),
232  }
233  return true;
234 }
235 
237  InetUnicastRouteEntry *route = static_cast<InetUnicastRouteEntry *>(entry);
238 
239  Icmpv6RouteState *state = static_cast<Icmpv6RouteState *>
240  (entry->GetState(part->parent(), route_table_listener_id_));
241 
242 #if 0
243  // This is the code for sending unsolicited NA for vhost0 but it should
244  // be taken care of by linux itself
245  const InterfaceNH *intf_nh = dynamic_cast<const InterfaceNH *>(
246  route->GetActiveNextHop());
247  const Interface *intf = (intf_nh) ?
248  static_cast<const Interface *>(intf_nh->GetInterface()) : NULL;
249 
250  NdpKey key(route->prefix_address().to_v6(), route->vrf());
251  NdpEntry *ndpentry = icmp_proto_->UnsolNaEntry(key, intf);
252  if (route->vrf()->GetName() == agent_->fabric_vrf_name()) {
254  }
255 #endif
256  if (entry->IsDeleted() || deleted_) {
257  if (state) {
258  //icmp_proto_->DeleteUnsolNaEntry(ndpentry);
259  entry->ClearState(part->parent(), route_table_listener_id_);
260  delete state;
261  }
262  return;
263  }
264 
265  if (!state) {
266  state = new Icmpv6RouteState(this, route->vrf_id(), route->prefix_address(),
267  route->prefix_length());
268  entry->SetState(part->parent(), route_table_listener_id_, state);
269  }
270 
271 #if 0
272  // May not be needed since kernel can take care of sending unsolicited NA
273  if (route->vrf()->GetName() == agent_->fabric_vrf_name() &&
274  route->GetActiveNextHop()->GetType() == NextHop::RECEIVE &&
275  icmp_proto_->agent()->router_id6() == route->prefix_address().to_v6()) {
276  //Send unsolicited NA
279  route->prefix_address().to_v6(), route->vrf(),
281  }
282 #endif
283 
284  //Check if there is a local VM path, if yes send a
285  //Neighbor Solicit request, to trigger route preference state machine
286  if (state && route->GetTableType() == Agent::INET6_UNICAST &&
287  route->vrf()->GetName() != agent_->fabric_vrf_name()) {
288  state->SendNeighborSolicitForAllIntf(route);
289  }
290 }
291 
293  EvpnRouteEntry *route = static_cast<EvpnRouteEntry *>(entry);
294 
295  Icmpv6RouteState *state = static_cast<Icmpv6RouteState *>
296  (entry->GetState(part->parent(), evpn_route_table_listener_id_));
297 
298  if (entry->IsDeleted() || deleted_) {
299  if (state) {
301  delete state;
302  }
303  return;
304  }
305 
306  if (!state) {
307  state = new Icmpv6RouteState(this, route->vrf_id(), route->prefix_address(),
308  route->prefix_length());
309  entry->SetState(part->parent(), evpn_route_table_listener_id_, state);
310  }
311 
312  //Check if there is a local VM path, if yes send a
313  //Neighbor Solicit request, to trigger route preference state machine
314  if (state && route->vrf()->GetName() != agent_->fabric_vrf_name()) {
315  state->SendNeighborSolicitForAllIntf(route);
316  }
317 }
318 
320  RouteUpdate(part, ent);
321  return true;
322 }
323 
325  DBEntryBase *ent) {
326  EvpnRouteUpdate(part, ent);
327  return true;
328 }
329 
331  if (managed_delete_walk_ref_.get() == NULL)
332  return;
333 
335  if (evpn_walk_ref_.get())
337  deleted_ = true;
338 }
339 
341  if (icmp_proto_->ValidateAndClearVrfState(vrf_, this) == false) {
342  return false;
343  }
344 
346  table_delete_ref_.Reset(NULL);
347 
350  return true;
351 }
352 
354  if (partition == state->rt_table_) {
356  state->managed_delete_walk_ref_ = NULL;
357  state->l3_walk_completed_ = true;
358  } else {
360  state->evpn_walk_ref_ = NULL;
361  state->evpn_walk_completed_ = true;
362  }
363 
364  if (state->PreWalkDone(partition)) {
365  delete state;
366  }
367 }
368 
371  if (ptr == NULL) {
372  ptr = new Icmpv6PathPreferenceState(this, vrf_->vrf_id(), ip, 128);
373  icmpv6_path_preference_map_[ip] = ptr;
374  }
375  return ptr;
376 }
377 
379  WaitForTrafficIntfMap::iterator it = l3_wait_for_traffic_map_.find(itf);
380  if (it == l3_wait_for_traffic_map_.end()) {
381  return;
382  }
383  InterfaceIcmpv6PathPreferenceInfo &data = it->second;
384 
385  // resetting ns_try_count as interface sent NA
386  data.ns_try_count = 0;
387 
388 }
389 
390 void Icmpv6Proto::HandlePathPreferenceNA(const VrfEntry *vrf, uint32_t itf,
391  IpAddress sip) {
392  if (!vrf) {
393  return;
394  }
395  InetUnicastRouteEntry *rt = vrf->GetUcRoute(sip);
396  if (!rt) {
397  return;
398  }
399 
400  Icmpv6VrfState *state = static_cast<Icmpv6VrfState *>
401  (vrf->GetState(vrf->get_table_partition()->parent(),
403  if (!state) {
404  return;
405  }
406  Icmpv6PathPreferenceState *pstate = state->Get(sip);
407  if (!pstate) {
408  return;
409  }
410  pstate->HandleNA(itf);
411 }
412 
414  icmpv6_path_preference_map_.erase(ip);
415 }
416 
418  VrfEntry *vrf_entry, AgentRouteTable *table,
419  AgentRouteTable *evpn_rt_table):
420  agent_(agent_ptr), icmp_proto_(proto), vrf_(vrf_entry), rt_table_(table),
421  evpn_rt_table_(evpn_rt_table),
422  route_table_listener_id_(DBTableBase::kInvalidId),
423  evpn_route_table_listener_id_(DBTableBase::kInvalidId),
424  table_delete_ref_(this, table->deleter()),
425  evpn_table_delete_ref_(this, evpn_rt_table_->deleter()),
426  deleted_(false),
427  default_routes_added_(false), l3_walk_completed_(false),
428  evpn_walk_completed_(false) {
430  boost::bind(&Icmpv6VrfState::DeleteEvpnRouteState, this, _1, _2),
431  boost::bind(&Icmpv6VrfState::WalkDone, _2, this));
433  boost::bind(&Icmpv6VrfState::DeleteRouteState, this, _1, _2),
434  boost::bind(&Icmpv6VrfState::WalkDone, _2, this));
435 }
436 
438  assert(icmpv6_path_preference_map_.size() == 0);
439 }
440 
442  ps->refcount_++;
443 }
444 
446  Icmpv6VrfState *state = ps->vrf_state();
447  int prev = ps->refcount_.fetch_sub(1);
448  if (prev == 1) {
449  state->Erase(ps->ip());
450  delete ps;
451  }
452 }
453 
455  Icmpv6VrfState *vrf_state, uint32_t vrf_id,
456  IpAddress ip, uint8_t plen) :
457  vrf_state_(vrf_state), ns_req_timer_(NULL), vrf_id_(vrf_id), vm_ip_(ip),
458  plen_(plen), svc_ip_(Ip6Address()) {
459  refcount_ = 0;
460 }
461 
463  if (ns_req_timer_) {
466  }
467  assert(refcount_ == 0);
468 }
469 
471  &wait_for_traffic_map,
473  &nd_transmitted_map) {
474  bool ret = false;
475  boost::shared_ptr<PktInfo> pkt(new PktInfo(vrf_state_->agent(),
477  PktHandler::ICMPV6, 0));
478  Icmpv6Handler handler(vrf_state_->agent(), pkt,
480 
481  WaitForTrafficIntfMap::iterator it = wait_for_traffic_map.begin();
482  for (;it != wait_for_traffic_map.end(); it++) {
483 
484  VmInterface *vm_intf = static_cast<VmInterface *>(
485  vrf_state_->agent()->interface_table()->FindInterface(it->first));
486  if (!vm_intf) {
487  continue;
488  }
489  InterfaceIcmpv6PathPreferenceInfo &data = it->second;
490  bool inserted = nd_transmitted_map.insert(it->first).second;
491  ++data.ns_retry_count;
492  if (inserted == false) {
493  continue;
494  }
495 
497  GetMacIpLearningTable()->GetPairedMacAddress(
498  vm_intf->vrf_id(), ip());
499  if (mil_mac != MacAddress()) {
500  ++data.ns_try_count;
501  if (data.ns_try_count == kNSTryCount) {
502  IpAddress ip = vm_ip_;
503  MacAddress mac = mil_mac;
505  GetMacIpLearningTable()->MacIpEntryUnreachable(
506  vm_intf->vrf_id(), ip, mac);
507  return true;
508  }
509  }
510 
511  Ip6Address src_addr;
512  if (svc_ip_.is_unspecified() == false && svc_ip_.is_v6())
513  src_addr = svc_ip_.to_v6();
514  handler.SendNeighborSolicit(src_addr, vm_ip_.to_v6(), vm_intf, vrf_id_);
515 
517  ++data.ns_send_count;
518 
519  // reduce the frequency of NS requests after some tries
520  if (data.ns_send_count >= kMaxRetry) {
521  // change frequency only if not in gateway mode with remote VMIs and
522  // learnt mac is not present
523  if (vm_intf->vmi_type() != VmInterface::REMOTE_VM
524  && mil_mac == MacAddress()) {
526  }
527  }
528 
529  ret = true;
530  }
531  return ret;
532 }
533 
535  if (l3_wait_for_traffic_map_.size() == 0 &&
536  evpn_wait_for_traffic_map_.size() == 0) {
537  return false;
538  }
539 
540  bool ret = false;
541  NDTransmittedIntfMap nd_transmitted_map;
542  if (SendNeighborSolicit(l3_wait_for_traffic_map_, nd_transmitted_map)) {
543  ret = true;
544  }
545 
546  if (SendNeighborSolicit(evpn_wait_for_traffic_map_, nd_transmitted_map)) {
547  ret = true;
548  }
549  return ret;
550 }
551 
553  if (ns_req_timer_ == NULL) {
556  "Neighbor Solicit Request timer for VM",
557  TaskScheduler::GetInstance()->GetTaskId("Agent::Services"),
559  }
561  boost::bind(&Icmpv6PathPreferenceState::
563  this));
564 }
565 
567  uint32_t vrf_id, IpAddress ip,
568  uint8_t plen) {
569  if (plen == Address::kMaxV6PrefixLen) {
570  icmpv6_path_preference_state_ = vrf_state->Locate(ip);
571  }
572 }
573 
575  icmpv6_path_preference_state_.reset(NULL);
576 }
577 
579  if (icmpv6_path_preference_state_.get()) {
580  icmpv6_path_preference_state_->SendNeighborSolicitForAllIntf(route);
581  }
582 }
583 
584 //Send Neighbor Solicit request on interface in Active-BackUp mode
585 //So that preference of route can be incremented if the VM replies with
586 //Neighbor Advertisement
588  (const AgentRoute *route) {
589 
590  WaitForTrafficIntfMap wait_for_traffic_map = evpn_wait_for_traffic_map_;
591  if (dynamic_cast<const InetUnicastRouteEntry *>(route)) {
592  wait_for_traffic_map = l3_wait_for_traffic_map_;
593  }
594 
595  WaitForTrafficIntfMap new_wait_for_traffic_map;
596  for (Route::PathList::const_iterator it = route->GetPathList().begin();
597  it != route->GetPathList().end(); it++) {
598  const AgentPath *path = static_cast<const AgentPath *>(it.operator->());
599  if (path->peer() &&
600  path->peer()->GetType() == Peer::LOCAL_VM_PORT_PEER) {
601  const NextHop *nh = path->ComputeNextHop(vrf_state_->agent());
602  if (nh->GetType() != NextHop::INTERFACE) {
603  continue;
604  }
605 
606  const InterfaceNH *intf_nh =
607  static_cast<const InterfaceNH *>(nh);
608  const Interface *intf =
609  static_cast<const Interface *>(intf_nh->GetInterface());
610  if (intf->type() != Interface::VM_INTERFACE) {
611  //Ignore non vm interface nexthop
612  continue;
613  }
614  if (dynamic_cast<const InetUnicastRouteEntry *>(route)) {
615  const VmInterface *vm_intf =
616  static_cast<const VmInterface *>(intf);
617  if (vm_intf->primary_ip6_addr().is_unspecified() == false) {
618  svc_ip_ = vm_intf->GetServiceIp(vm_intf->primary_ip6_addr());
619  }
620  }
621 
622  if (path->path_preference().IsDependentRt() == true) {
623  continue;
624  }
625 
626  uint32_t intf_id = intf->id();
627  WaitForTrafficIntfMap::const_iterator wait_for_traffic_it =
628  wait_for_traffic_map.find(intf_id);
629  if (wait_for_traffic_it == wait_for_traffic_map.end()) {
631  new_wait_for_traffic_map.insert(std::make_pair(intf_id, data));
632  } else {
633  new_wait_for_traffic_map.insert(std::make_pair(intf_id,
634  wait_for_traffic_it->second));
635  }
636  }
637  }
638 
639 
640  if (dynamic_cast<const InetUnicastRouteEntry *>(route)) {
641  l3_wait_for_traffic_map_ = new_wait_for_traffic_map;
642  } else {
643  evpn_wait_for_traffic_map_ = new_wait_for_traffic_map;
644  }
645  if (new_wait_for_traffic_map.size() > 0) {
647  StartTimer();
648  }
649 }
650 
652  VmInterfaceMap::iterator it = vm_interfaces_.find(i);
653  if (it == vm_interfaces_.end()) {
654  return NULL;
655  }
656  return &it->second;
657 }
658 
661  Icmpv6Stats *stats = VmiToIcmpv6Stats(vmi);
662  if (stats) {
663  stats->icmpv6_router_solicit_++;
664  }
665 }
666 
669  Icmpv6Stats *stats = VmiToIcmpv6Stats(vmi);
670  if (stats) {
671  stats->icmpv6_router_advert_++;
672  }
673 }
674 
677  Icmpv6Stats *stats = VmiToIcmpv6Stats(vmi);
678  if (stats) {
679  stats->icmpv6_ping_request_++;
680  }
681 }
682 
685  Icmpv6Stats *stats = VmiToIcmpv6Stats(vmi);
686  if (stats) {
687  stats->icmpv6_ping_response_++;
688  }
689 }
690 
693  Icmpv6Stats *stats = VmiToIcmpv6Stats(vmi);
694  if (stats) {
695  stats->icmpv6_neighbor_solicit_++;
696  }
697 }
698 
701  Icmpv6Stats *stats = VmiToIcmpv6Stats(vmi);
702  if (stats) {
704  }
705 }
706 
709  Icmpv6Stats *stats = VmiToIcmpv6Stats(vmi);
710  if (stats) {
712  }
713 }
714 
717  Icmpv6Stats *stats = VmiToIcmpv6Stats(vmi);
718  if (stats) {
720  }
721 }
722 
725  if (iter == unsol_na_cache_.end()) {
726  return NULL;
727  }
728  return *iter->second.begin();
729 }
730 
732  NdpEntrySet empty_set;
733  unsol_na_cache_.insert(UnsolNaCachePair(key, empty_set));
734 }
735 
737  if (!entry)
738  return ;
739 
740  Icmpv6Proto::UnsolNaIterator iter = unsol_na_cache_.find(entry->key());
741  if (iter == unsol_na_cache_.end()) {
742  return;
743  }
744 
745  iter->second.erase(entry);
746  delete entry;
747  if (iter->second.empty()) {
748  unsol_na_cache_.erase(iter);
749  }
750 }
751 
752 NdpEntry *
753 Icmpv6Proto::UnsolNaEntry(const NdpKey &key, const Interface *intf) {
755  if (it == unsol_na_cache_.end())
756  return NULL;
757 
758  for (NdpEntrySet::iterator sit = it->second.begin();
759  sit != it->second.end(); sit++) {
760  NdpEntry *entry = *sit;
761  if (entry->get_interface() == intf)
762  return *sit;
763  }
764 
765  return NULL;
766 }
767 
769 Icmpv6Proto::UnsolNaEntryIterator(const NdpKey &key, bool *key_valid) {
771  if (it == unsol_na_cache_.end())
772  return it;
773  const VrfEntry *vrf = key.vrf;
774  if (!vrf)
775  return it;
776  const Icmpv6VrfState *state = static_cast<const Icmpv6VrfState *>
777  (vrf->GetState(vrf->get_table_partition()->parent(),
779  // If VRF is delete marked, do not add Ndp entries to cache
780  if (state == NULL || state->deleted() == true)
781  return it;
782  *key_valid = true;
783  return it;
784 }
785 
787  const VrfEntry *vrf = entry->key().vrf;
788  const Icmpv6VrfState *state = static_cast<const Icmpv6VrfState *>
789  (vrf->GetState(vrf->get_table_partition()->parent(),
791  // If VRF is delete marked, do not add Ndp entries to cache
792  if (state == NULL || state->deleted() == true)
793  return false;
794 
795  bool ret = ndp_cache_.insert(NdpCachePair(entry->key(), entry)).second;
796  uint32_t intf_id = entry->get_interface()->id();
797  InterfaceNdpMap::iterator it = interface_ndp_map_.find(intf_id);
798  if (it == interface_ndp_map_.end()) {
799  InterfaceNdpInfo intf_entry;
800  intf_entry.ndp_key_list.insert(entry->key());
801  interface_ndp_map_.insert(InterfaceNdpPair(intf_id, intf_entry));
802  } else {
803  InterfaceNdpInfo &intf_entry = it->second;
804  NdpKeySet::iterator key_it = intf_entry.ndp_key_list.find(entry->key());
805  if (key_it == intf_entry.ndp_key_list.end()) {
806  intf_entry.ndp_key_list.insert(entry->key());
807  }
808  }
809  return ret;
810 }
811 
813  if (!entry)
814  return false;
815 
816  Icmpv6Proto::NdpIterator iter = ndp_cache_.find(entry->key());
817  if (iter == ndp_cache_.end()) {
818  return false;
819  }
820 
821  DeleteNdpEntry(iter);
822  return true;
823 }
824 
827  NdpEntry *entry = iter->second;
828  ndp_cache_.erase(iter++);
829  delete entry;
830  return iter;
831 }
832 
834  NdpIterator it = ndp_cache_.find(key);
835  if (it == ndp_cache_.end())
836  return NULL;
837  return it->second;
838 }
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:16
boost::asio::ip::address IpAddress
Definition: address.h:14
boost::intrusive_ptr< const Interface > InterfaceConstRef
Definition: agent.h:52
static const uint8_t kMaxV6PrefixLen
Definition: address.h:23
uint32_t services_queue_limit()
Definition: agent_param.h:416
const PathPreference & path_preference() const
Definition: agent_path.h:330
const Peer * peer() const
Definition: agent_path.h:264
virtual const NextHop * ComputeNextHop(Agent *agent) const
Definition: agent_path.cc:92
virtual const PrefixType & prefix_address() const
Returns the value of a stored prefix address (IPv4, IPv6 or MAC address)
Definition: agent_route.h:390
Agent supports multiple route tables - Inet-unicast (IPv4/IPv6), Inet-multicast, bridge,...
Definition: agent_route.h:110
Base class for all Route entries in agent.
Definition: agent_route.h:225
VrfEntry * vrf() const
Definition: agent_route.h:276
const NextHop * GetActiveNextHop() const
Definition: agent_route.cc:883
uint32_t vrf_id() const
Definition: agent.h:361
InterfaceTable * interface_table() const
Definition: agent.h:468
AgentParam * params() const
Definition: agent.h:1227
@ INET6_UNICAST
Definition: agent.h:424
MacLearningProto * mac_learning_proto() const
Definition: agent.h:1008
VrfTable * vrf_table() const
Definition: agent.h:488
const Peer * local_peer() const
Definition: agent.h:1025
EventManager * event_manager() const
Definition: agent.h:1106
VnTable * vn_table() const
Definition: agent.h:498
NextHopTable * nexthop_table() const
Definition: agent.h:478
IpAddress router_id6() const
Definition: agent.h:670
InetUnicastAgentRouteTable * fabric_inet4_unicast_table() const
Definition: agent.h:581
const std::string & fabric_vrf_name() const
Definition: agent.h:906
PktModule * pkt() const
Definition: agent.cc:969
DBState * GetState(DBTableBase *tbl_base, ListenerId listener) const
Definition: db_entry.cc:38
void ClearState(DBTableBase *tbl_base, ListenerId listener)
Definition: db_entry.cc:74
bool IsDeleted() const
Definition: db_entry.h:49
DBTablePartBase * get_table_partition() const
Definition: db_entry.cc:116
void SetState(DBTableBase *tbl_base, ListenerId listener, DBState *state)
Definition: db_entry.cc:23
ListenerId Register(ChangeCallback callback, const std::string &name="unspecified")
Definition: db_table.cc:208
void Unregister(ListenerId listener)
Definition: db_table.cc:213
DBTableBase * parent()
void WalkAgain(DBTableWalkRef walk)
Definition: db_table.cc:658
DBTableWalkRef AllocWalker(WalkFn walk_fn, WalkCompleteFn walk_complete)
Definition: db_table.cc:640
void ReleaseWalker(DBTableWalkRef &walk)
Definition: db_table.cc:646
boost::asio::io_context * io_service()
Definition: event_manager.h:43
uint8_t prefix_length() const
!
void SendNeighborSolicit(const Ip6Address &sip, const Ip6Address &dip, const VmInterface *vmi, uint32_t vrf, bool send_unicast=false)
bool RouterAdvertisement(Icmpv6Proto *proto)
static const uint32_t kTimeoutMultiplier
Definition: icmpv6_proto.h:272
Icmpv6PathPreferenceState(Icmpv6VrfState *vrf_state, uint32_t vrf_id, IpAddress vm_ip_addr, uint8_t plen)
MacAddress mac(void) const
Definition: icmpv6_proto.h:296
WaitForTrafficIntfMap l3_wait_for_traffic_map_
Definition: icmpv6_proto.h:332
std::map< uint32_t, InterfaceIcmpv6PathPreferenceInfo > WaitForTrafficIntfMap
Definition: icmpv6_proto.h:276
Icmpv6VrfState * vrf_state_
Definition: icmpv6_proto.h:325
static const uint32_t kNSTryCount
Definition: icmpv6_proto.h:274
std::atomic< int > refcount_
Definition: icmpv6_proto.h:334
const IpAddress & ip() const
Definition: icmpv6_proto.h:292
WaitForTrafficIntfMap evpn_wait_for_traffic_map_
Definition: icmpv6_proto.h:333
void HandleNA(uint32_t itf)
static const uint32_t kTimeout
Definition: icmpv6_proto.h:270
void SendNeighborSolicitForAllIntf(const AgentRoute *route)
std::set< uint32_t > NDTransmittedIntfMap
Definition: icmpv6_proto.h:277
static const uint32_t kMaxRetry
Definition: icmpv6_proto.h:268
Icmpv6VrfState * vrf_state()
Definition: icmpv6_proto.h:288
void DeleteUnsolNaEntry(NdpEntry *entry)
std::map< NdpKey, NdpEntry * >::iterator NdpIterator
Definition: icmpv6_proto.h:84
std::pair< NdpKey, NdpEntrySet > UnsolNaCachePair
Definition: icmpv6_proto.h:88
virtual ~Icmpv6Proto()
Definition: icmpv6_proto.cc:41
VmInterfaceMap vm_interfaces_
Definition: icmpv6_proto.h:165
void VrfNotify(DBTablePartBase *part, DBEntryBase *entry)
Icmpv6Proto(Agent *agent, boost::asio::io_context &io)
Definition: icmpv6_proto.cc:14
InterfaceNdpMap interface_ndp_map_
Definition: icmpv6_proto.h:168
void IncrementStatsRouterSolicit(VmInterface *vmi)
Icmpv6Stats * VmiToIcmpv6Stats(VmInterface *i)
boost::scoped_ptr< Icmpv6Handler > icmpv6_handler_
Definition: icmpv6_proto.h:175
Icmpv6VrfState * CreateAndSetVrfState(VrfEntry *vrf)
Definition: icmpv6_proto.cc:57
void IncrementStatsNeighborAdvertUnSolicited(VmInterface *vmi)
bool ValidateAndClearVrfState(VrfEntry *vrf, Icmpv6VrfState *state)
std::pair< NdpKey, NdpEntry * > NdpCachePair
Definition: icmpv6_proto.h:83
Icmpv6Proto::UnsolNaIterator UnsolNaEntryIterator(const NdpKey &key, bool *key_valid)
bool DeleteNdpEntry(NdpEntry *entry)
NdpEntry * FindNdpEntry(const NdpKey &key)
std::map< NdpKey, NdpEntrySet >::iterator UnsolNaIterator
Definition: icmpv6_proto.h:89
void IncrementStatsPingResponse(VmInterface *vmi)
void IncrementStatsRouterAdvert(VmInterface *vmi)
ProtoHandler * AllocProtoHandler(boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
Definition: icmpv6_proto.cc:52
NdpEntry * UnsolNaEntry(const NdpKey &key, const Interface *intf)
DBTableBase::ListenerId vrf_table_listener_id_
Definition: icmpv6_proto.h:177
Timer * timer_
Definition: icmpv6_proto.h:163
std::set< NdpEntry * > NdpEntrySet
Definition: icmpv6_proto.h:86
DBTableBase::ListenerId nexthop_listener_id_
Definition: icmpv6_proto.h:179
void SendIcmpv6Ipc(Icmpv6Proto::Icmpv6MsgType type, Ip6Address ip, const VrfEntry *vrf, InterfaceConstRef itf)
void IncrementStatsPingRequest(VmInterface *vmi)
NdpCache ndp_cache_
Definition: icmpv6_proto.h:166
DBTableBase::ListenerId interface_listener_id_
Definition: icmpv6_proto.h:178
void IncrementStatsNeighborAdvertSolicited(VmInterface *vmi)
std::pair< uint32_t, InterfaceNdpInfo > InterfaceNdpPair
Definition: icmpv6_proto.h:97
bool AddNdpEntry(NdpEntry *entry)
void VnNotify(DBEntryBase *entry)
Definition: icmpv6_proto.cc:70
void set_ip_fabric_interface(Interface *itf)
Definition: icmpv6_proto.h:135
void AddUnsolNaEntry(NdpKey &key)
std::pair< VmInterface *, Icmpv6Stats > VmInterfacePair
Definition: icmpv6_proto.h:81
Interface * ip_fabric_interface() const
Definition: icmpv6_proto.h:128
void set_ip_fabric_interface_index(uint32_t ind)
Definition: icmpv6_proto.h:136
void InterfaceNotify(DBEntryBase *entry)
NdpEntry * FindUnsolNaEntry(NdpKey &key)
void set_ip_fabric_interface_mac(const MacAddress &mac)
Definition: icmpv6_proto.h:139
UnsolNaCache unsol_na_cache_
Definition: icmpv6_proto.h:167
void HandlePathPreferenceNA(const VrfEntry *, uint32_t, IpAddress)
static const uint32_t kRouterAdvertTimeout
Definition: icmpv6_proto.h:37
Icmpv6Stats stats_
Definition: icmpv6_proto.h:164
void IncrementStatsNeighborSolicited(VmInterface *vmi)
void NexthopNotify(DBEntryBase *entry)
void IncrementStatsNeighborSolicit(VmInterface *vmi)
DBTableBase::ListenerId vn_table_listener_id_
Definition: icmpv6_proto.h:176
void Shutdown()
Definition: icmpv6_proto.cc:44
Icmpv6RouteState(Icmpv6VrfState *vrf_state, uint32_t vrf_id, IpAddress vm_ip_addr, uint8_t plen)
void SendNeighborSolicitForAllIntf(const AgentRoute *route)
Icmpv6PathPreferenceStatePtr icmpv6_path_preference_state_
Definition: icmpv6_proto.h:350
Icmpv6PathPreferenceState * Get(const IpAddress ip)
Definition: icmpv6_proto.h:219
DBTable::DBTableWalkRef evpn_walk_ref_
Definition: icmpv6_proto.h:250
bool l3_walk_completed_
Definition: icmpv6_proto.h:252
static void WalkDone(DBTableBase *partition, Icmpv6VrfState *state)
void Erase(const IpAddress &ip)
bool PreWalkDone(DBTableBase *partition)
bool default_routes_added() const
Definition: icmpv6_proto.h:204
LifetimeRef< Icmpv6VrfState > table_delete_ref_
Definition: icmpv6_proto.h:245
Icmpv6PathPreferenceStateMap icmpv6_path_preference_map_
Definition: icmpv6_proto.h:251
void set_route_table_listener_id(const DBTableBase::ListenerId &id)
Definition: icmpv6_proto.h:198
AgentRouteTable * rt_table_
Definition: icmpv6_proto.h:241
void set_evpn_route_table_listener_id(const DBTableBase::ListenerId &id)
Definition: icmpv6_proto.h:201
DBTable::DBTableWalkRef managed_delete_walk_ref_
Definition: icmpv6_proto.h:249
DBTable::DBTableWalkRef evpn_walk_ref()
Definition: icmpv6_proto.h:233
DBTable::DBTableWalkRef managed_delete_walk_ref()
Definition: icmpv6_proto.h:230
VrfEntry * vrf_
Definition: icmpv6_proto.h:240
Agent * agent() const
Definition: icmpv6_proto.h:196
Icmpv6PathPreferenceState * Locate(const IpAddress &ip)
Icmpv6VrfState(Agent *agent, Icmpv6Proto *proto, VrfEntry *vrf, AgentRouteTable *table, AgentRouteTable *evpn_table)
AgentRouteTable * evpn_rt_table_
Definition: icmpv6_proto.h:242
Icmpv6Proto * icmp_proto_
Definition: icmpv6_proto.h:239
bool DeleteEvpnRouteState(DBTablePartBase *part, DBEntryBase *entry)
void RouteUpdate(DBTablePartBase *part, DBEntryBase *entry)
bool DeleteRouteState(DBTablePartBase *part, DBEntryBase *entry)
bool evpn_walk_completed_
Definition: icmpv6_proto.h:253
Icmpv6Proto * icmp_proto() const
Definition: icmpv6_proto.h:197
void set_default_routes_added(bool value)
Definition: icmpv6_proto.h:205
void EvpnRouteUpdate(DBTablePartBase *part, DBEntryBase *entry)
LifetimeRef< Icmpv6VrfState > evpn_table_delete_ref_
Definition: icmpv6_proto.h:246
DBTableBase::ListenerId evpn_route_table_listener_id_
Definition: icmpv6_proto.h:244
bool l3_walk_completed() const
Definition: icmpv6_proto.h:223
DBTableBase::ListenerId route_table_listener_id_
Definition: icmpv6_proto.h:243
bool evpn_walk_completed() const
Definition: icmpv6_proto.h:227
bool deleted() const
Definition: icmpv6_proto.h:215
static void DeleteReq(const Peer *peer, const string &vrf_name, const IpAddress &addr, uint8_t plen, AgentRouteData *data)
virtual Agent::RouteTableType GetTableType() const
uint8_t prefix_length() const
!
const Interface * GetInterface() const
Definition: nexthop.h:1294
const Interface * FindInterface(size_t index) const
Definition: interface.cc:323
@ VM_INTERFACE
Definition: interface.h:38
const MacAddress & mac() const
Definition: interface.h:134
uint32_t vrf_id() const
Definition: interface.cc:621
Type type() const
Definition: interface.h:115
const uint32_t id() const
Definition: interface.h:126
void Reset(LifetimeActor *actor)
Definition: lifetime.h:83
const NdpKey & key() const
Definition: ndp_entry.h:58
const Interface * get_interface() const
Definition: ndp_entry.h:59
Definition: nexthop.h:910
const Interface * GetInterface() const
Definition: nexthop.h:927
const VrfEntry * GetVrf() const
Definition: nexthop.h:931
const IpAddress * GetIp() const
Definition: nexthop.h:930
bool IsValid() const
Definition: nexthop.h:407
@ RECEIVE
Definition: nexthop.h:348
@ NDP
Definition: nexthop.h:358
@ INTERFACE
Definition: nexthop.h:352
Type GetType() const
Definition: nexthop.h:406
bool IsDependentRt(void) const
Definition: agent_path.h:157
const Type GetType() const
Definition: peer.h:88
@ LOCAL_VM_PORT_PEER
Definition: peer.h:57
void SendMessage(PktModuleName mod, InterTaskMsg *msg)
PktHandler * pkt_handler() const
Definition: pkt_init.h:32
const PathList & GetPathList() const
Definition: route.h:47
int GetTaskId(const std::string &name)
Definition: task.cc:884
static TaskScheduler * GetInstance()
Definition: task.cc:574
static bool DeleteTimer(Timer *Timer)
Definition: timer.cc:222
static Timer * CreateTimer(boost::asio::io_context &service, const std::string &name, int task_id=Timer::GetTimerTaskId(), int task_instance=Timer::GetTimerInstanceId(), bool delete_on_completion=false)
Definition: timer.cc:201
bool Cancel()
Definition: timer.cc:150
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
Definition: timer.cc:108
bool Reschedule(int time)
Definition: timer.cc:137
VmInterface::VmiType vmi_type() const
IpAddress GetServiceIp(const IpAddress &ip) const
const Ip6Address & primary_ip6_addr() const
Definition: vn.h:152
VrfEntry * GetVrf() const
Definition: vn.h:171
const string & GetName() const
Definition: vn.h:163
bool layer3_forwarding() const
Definition: vn.h:196
Definition: vrf.h:90
const string & GetName() const
Definition: vrf.h:104
InetUnicastRouteEntry * GetUcRoute(const IpAddress &addr) const
Definition: vrf.cc:238
InetUnicastAgentRouteTable * GetInet6UnicastRouteTable() const
Definition: vrf.cc:339
const uint32_t vrf_id() const
Definition: vrf.h:103
AgentRouteTable * GetEvpnRouteTable() const
Definition: vrf.cc:331
void SetBounded(bool bounded)
Definition: queue_task.h:201
void SetSize(size_t size)
Definition: queue_task.h:197
void intrusive_ptr_release(Icmpv6PathPreferenceState *ps)
void intrusive_ptr_add_ref(Icmpv6PathPreferenceState *ps)
#define PKT0_LINKLOCAL_ADDRESS
Definition: icmpv6_proto.h:18
#define IPV6_ALL_NODES_ADDRESS
Definition: icmpv6_proto.h:16
#define ICMP_PKT_SIZE
Definition: icmpv6_proto.h:15
#define IPV6_ALL_ROUTERS_ADDRESS
Definition: icmpv6_proto.h:17
uint8_t type
Definition: load_balance.h:2
Definition: io_utils.cc:12
uint32_t icmpv6_neighbor_advert_solicited_
Definition: icmpv6_proto.h:76
uint32_t icmpv6_neighbor_solicited_
Definition: icmpv6_proto.h:75
uint32_t icmpv6_neighbor_solicit_
Definition: icmpv6_proto.h:74
uint32_t icmpv6_neighbor_advert_unsolicited_
Definition: icmpv6_proto.h:77
const VrfEntry * vrf
Definition: ndp_entry.h:32