OpenSDN source code
icmpv6_proto.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef vnsw_agent_icmpv6_proto_h
7 #define vnsw_agent_icmpv6_proto_h
8 
9 #include <atomic>
10 
11 #include "pkt/proto.h"
13 #include "services/ndp_entry.h"
14 
15 #define ICMP_PKT_SIZE 1024
16 #define IPV6_ALL_NODES_ADDRESS "FF02::1"
17 #define IPV6_ALL_ROUTERS_ADDRESS "FF02::2"
18 #define PKT0_LINKLOCAL_ADDRESS "FE80::5E00:0100"
19 
20 #define NDP_TRACE(obj, ...) \
21 do { \
22  Ndp##obj::TraceMsg(Icmpv6TraceBuf, __FILE__, __LINE__, ##__VA_ARGS__); \
23 } while (false) \
24 
25 #define ICMPV6_TRACE(obj, arg) \
26 do { \
27  std::ostringstream _str; \
28  _str << arg; \
29  Icmpv6##obj::TraceMsg(Icmpv6TraceBuf, __FILE__, __LINE__, _str.str()); \
30 } while (false) \
31 
32 class Icmpv6VrfState;
34 
35 class Icmpv6Proto : public Proto {
36 public:
37  static const uint32_t kRouterAdvertTimeout = 30000; // milli seconds
38  static const uint16_t kMaxRetries = 8;
39  static const uint32_t kRetryTimeout = 2000; // milli seconds
40  static const uint32_t kAgingTimeout = (5 * 60 * 1000); // milli seconds
41 
46  };
47 
50  : InterTaskMsg(msg), key(akey), interface_(itf) {}
52  const VrfEntry *vrf, InterfaceConstRef itf) :
53  InterTaskMsg(msg), key(ip, vrf), interface_(itf) {}
54 
57  };
58 
59  struct Icmpv6Stats {
60  Icmpv6Stats() { Reset(); }
61  void Reset() {
67  }
68 
73  uint32_t icmpv6_drop_;
78  };
79 
80  typedef std::map<VmInterface *, Icmpv6Stats> VmInterfaceMap;
81  typedef std::pair<VmInterface *, Icmpv6Stats> VmInterfacePair;
82  typedef std::map<NdpKey, NdpEntry *> NdpCache;
83  typedef std::pair<NdpKey, NdpEntry *> NdpCachePair;
84  typedef std::map<NdpKey, NdpEntry *>::iterator NdpIterator;
85  typedef std::set<NdpKey> NdpKeySet;
86  typedef std::set<NdpEntry *> NdpEntrySet;
87  typedef std::map<NdpKey, NdpEntrySet> UnsolNaCache;
88  typedef std::pair<NdpKey, NdpEntrySet> UnsolNaCachePair;
89  typedef std::map<NdpKey, NdpEntrySet>::iterator UnsolNaIterator;
90 
95  };
96  typedef std::map<uint32_t, InterfaceNdpInfo> InterfaceNdpMap;
97  typedef std::pair<uint32_t, InterfaceNdpInfo> InterfaceNdpPair;
98 
99  void Shutdown();
100  Icmpv6Proto(Agent *agent, boost::asio::io_context &io);
101  virtual ~Icmpv6Proto();
102  ProtoHandler *AllocProtoHandler(boost::shared_ptr<PktInfo> info,
103  boost::asio::io_context &io);
104  void VrfNotify(DBTablePartBase *part, DBEntryBase *entry);
105  void VnNotify(DBEntryBase *entry);
106  void InterfaceNotify(DBEntryBase *entry);
107  void NexthopNotify(DBEntryBase *entry);
109  const VrfEntry *vrf, InterfaceConstRef itf);
110 
112 
122  const Icmpv6Stats &GetStats() const { return stats_; }
123  Icmpv6Stats *VmiToIcmpv6Stats(VmInterface *i);
124  void ClearStats() { stats_.Reset(); }
127 
129  uint32_t ip_fabric_interface_index() const {
131  }
134  }
136  void set_ip_fabric_interface_index(uint32_t ind) {
138  }
141  }
142 
143  bool AddNdpEntry(NdpEntry *entry);
144  bool DeleteNdpEntry(NdpEntry *entry);
145  NdpEntry *FindNdpEntry(const NdpKey &key);
146  std::size_t GetNdpCacheSize() { return ndp_cache_.size(); }
147  const NdpCache& ndp_cache() { return ndp_cache_; }
150 
151  void AddUnsolNaEntry(NdpKey &key);
152  void DeleteUnsolNaEntry(NdpEntry *entry);
153  void HandlePathPreferenceNA(const VrfEntry*, uint32_t, IpAddress);
155  NdpEntry* UnsolNaEntry (const NdpKey &key, const Interface *intf);
157  UnsolNaEntryIterator(const NdpKey &key, bool *key_valid);
159  return vrf_table_listener_id_;
160  }
161 
162 private:
169  bool HandlePacket();
173  InterfaceConstRef itf);
174  // handler to send router advertisements and neighbor solicits
175  boost::scoped_ptr<Icmpv6Handler> icmpv6_handler_;
184 };
185 
186 class Icmpv6VrfState : public DBState {
187 public:
188  typedef std::map<const IpAddress,
190  typedef std::pair<const IpAddress,
192 
194  AgentRouteTable *table, AgentRouteTable *evpn_table);
195  ~Icmpv6VrfState();
196  Agent *agent() const { return agent_; }
197  Icmpv6Proto * icmp_proto() const { return icmp_proto_; }
200  }
203  }
205  void set_default_routes_added(bool value) { default_routes_added_ = value; }
206 
207  void RouteUpdate(DBTablePartBase *part, DBEntryBase *entry);
208  void EvpnRouteUpdate(DBTablePartBase *part, DBEntryBase *entry);
209  void ManagedDelete() { deleted_ = true;}
210  void Delete();
211  bool DeleteRouteState(DBTablePartBase *part, DBEntryBase *entry);
213  bool PreWalkDone(DBTableBase *partition);
214  static void WalkDone(DBTableBase *partition, Icmpv6VrfState *state);
215  bool deleted() const {return deleted_;}
216 
218  void Erase(const IpAddress &ip);
220  return icmpv6_path_preference_map_[ip];
221  }
222 
223  bool l3_walk_completed() const {
224  return l3_walk_completed_;
225  }
226 
227  bool evpn_walk_completed() const {
228  return evpn_walk_completed_;
229  }
232  }
234  return evpn_walk_ref_;
235  }
236 
237 private:
247  bool deleted_;
255 };
256 
258  uint32_t ns_try_count;
259  uint32_t ns_send_count;
260  uint32_t ns_retry_count;
262  ns_retry_count(0) {
263  }
264 };
265 
267 public:
268  static const uint32_t kMaxRetry = 30 * 5; //retries upto 5 minutes,
269  //30 tries/per minutes
270  static const uint32_t kTimeout = 2000;
271 
272  static const uint32_t kTimeoutMultiplier = 5;
273 
274  static const uint32_t kNSTryCount = 9;
275 
276  typedef std::map<uint32_t, InterfaceIcmpv6PathPreferenceInfo> WaitForTrafficIntfMap;
277  typedef std::set<uint32_t> NDTransmittedIntfMap;
278 
280  IpAddress vm_ip_addr, uint8_t plen);
282  bool SendNeighborSolicit();
283  bool SendNeighborSolicit(WaitForTrafficIntfMap &wait_for_traffic_map,
284  NDTransmittedIntfMap &nd_transmitted_map);
285  void SendNeighborSolicitForAllIntf(const AgentRoute *route);
286  void StartTimer();
287  void HandleNA(uint32_t itf);
289  return vrf_state_;
290  }
291 
292  const IpAddress& ip() const {
293  return vm_ip_;
294  }
295 
296  MacAddress mac(void) const { return mac_; }
297 
298  bool IntfPresentInIpMap(uint32_t id) {
299  if (l3_wait_for_traffic_map_.find(id) ==
300  l3_wait_for_traffic_map_.end()) {
301  return false;
302  }
303  return true;
304  }
305 
306  bool IntfPresentInEvpnMap(uint32_t id) {
307  if (evpn_wait_for_traffic_map_.find(id) ==
309  return false;
310  }
311  return true;
312  }
313 
314  uint32_t IntfRetryCountInIpMap(uint32_t id) {
315  return l3_wait_for_traffic_map_[id].ns_retry_count;
316  }
317 
318  uint32_t IntfRetryCountInEvpnMap(uint32_t id) {
319  return evpn_wait_for_traffic_map_[id].ns_retry_count;
320  }
321 
322 private:
327  uint32_t vrf_id_;
330  uint8_t plen_;
334  std::atomic<int> refcount_;
335 };
336 
337 typedef boost::intrusive_ptr<Icmpv6PathPreferenceState>
339 
342 
343 class Icmpv6RouteState : public DBState {
344 public:
345  Icmpv6RouteState(Icmpv6VrfState *vrf_state, uint32_t vrf_id,
346  IpAddress vm_ip_addr, uint8_t plen);
348  void SendNeighborSolicitForAllIntf(const AgentRoute *route);
349 private:
351 };
352 #endif // vnsw_agent_icmpv6_proto_h
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
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
Definition: agent.h:361
int ListenerId
Definition: db_table.h:63
boost::intrusive_ptr< DBTableWalk > DBTableWalkRef
Definition: db_table.h:170
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)
friend void intrusive_ptr_release(Icmpv6PathPreferenceState *ps)
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
friend void intrusive_ptr_add_ref(Icmpv6PathPreferenceState *ps)
Icmpv6VrfState * vrf_state_
Definition: icmpv6_proto.h:325
bool IntfPresentInEvpnMap(uint32_t id)
Definition: icmpv6_proto.h:306
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
uint32_t IntfRetryCountInIpMap(uint32_t id)
Definition: icmpv6_proto.h:314
void HandleNA(uint32_t itf)
bool IntfPresentInIpMap(uint32_t id)
Definition: icmpv6_proto.h:298
static const uint32_t kTimeout
Definition: icmpv6_proto.h:270
void SendNeighborSolicitForAllIntf(const AgentRoute *route)
uint32_t IntfRetryCountInEvpnMap(uint32_t id)
Definition: icmpv6_proto.h:318
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
DBTableBase::ListenerId vrf_table_listener_id() const
Definition: icmpv6_proto.h:158
std::pair< NdpKey, NdpEntrySet > UnsolNaCachePair
Definition: icmpv6_proto.h:88
void ClearStats()
Definition: icmpv6_proto.h:124
Interface * ip_fabric_interface_
Definition: icmpv6_proto.h:182
virtual ~Icmpv6Proto()
Definition: icmpv6_proto.cc:41
VmInterfaceMap vm_interfaces_
Definition: icmpv6_proto.h:165
uint32_t ip_fabric_interface_index() const
Definition: icmpv6_proto.h:129
void VrfNotify(DBTablePartBase *part, DBEntryBase *entry)
Icmpv6Proto(Agent *agent, boost::asio::io_context &io)
Definition: icmpv6_proto.cc:14
static const uint16_t kMaxRetries
Definition: icmpv6_proto.h:38
DISALLOW_COPY_AND_ASSIGN(Icmpv6Proto)
InterfaceNdpMap interface_ndp_map_
Definition: icmpv6_proto.h:168
void IncrementStatsRouterSolicit(VmInterface *vmi)
Icmpv6Stats * VmiToIcmpv6Stats(VmInterface *i)
std::map< uint32_t, InterfaceNdpInfo > InterfaceNdpMap
Definition: icmpv6_proto.h:96
boost::scoped_ptr< Icmpv6Handler > icmpv6_handler_
Definition: icmpv6_proto.h:175
static const uint32_t kRetryTimeout
Definition: icmpv6_proto.h:39
Icmpv6VrfState * CreateAndSetVrfState(VrfEntry *vrf)
Definition: icmpv6_proto.cc:57
void IncrementStatsNeighborAdvertUnSolicited(VmInterface *vmi)
const InterfaceNdpMap & interface_ndp_map()
Definition: icmpv6_proto.h:149
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)
const UnsolNaCache & unsol_na_cache()
Definition: icmpv6_proto.h:148
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
bool HandlePacket()
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)
std::map< NdpKey, NdpEntry * > NdpCache
Definition: icmpv6_proto.h:82
NdpCache ndp_cache_
Definition: icmpv6_proto.h:166
bool HandleMessage()
DBTableBase::ListenerId interface_listener_id_
Definition: icmpv6_proto.h:178
static const uint32_t kAgingTimeout
Definition: icmpv6_proto.h:40
void IncrementStatsDrop()
Definition: icmpv6_proto.h:117
void IncrementStatsNeighborAdvertSolicited(VmInterface *vmi)
std::map< NdpKey, NdpEntrySet > UnsolNaCache
Definition: icmpv6_proto.h:87
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)
const NdpCache & ndp_cache()
Definition: icmpv6_proto.h:147
MacAddress ip_fabric_interface_mac_
Definition: icmpv6_proto.h:181
std::pair< VmInterface *, Icmpv6Stats > VmInterfacePair
Definition: icmpv6_proto.h:81
const MacAddress & ip_fabric_interface_mac() const
Definition: icmpv6_proto.h:132
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
std::set< NdpKey > NdpKeySet
Definition: icmpv6_proto.h:85
uint32_t ip_fabric_interface_index_
Definition: icmpv6_proto.h:180
Icmpv6Stats stats_
Definition: icmpv6_proto.h:164
void IncrementStatsNeighborSolicited(VmInterface *vmi)
std::map< VmInterface *, Icmpv6Stats > VmInterfaceMap
Definition: icmpv6_proto.h:80
const VmInterfaceMap & vm_interfaces()
Definition: icmpv6_proto.h:111
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
const Icmpv6Stats & GetStats() const
Definition: icmpv6_proto.h:122
std::size_t GetNdpCacheSize()
Definition: icmpv6_proto.h:146
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
DISALLOW_COPY_AND_ASSIGN(Icmpv6VrfState)
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
bool default_routes_added_
Definition: icmpv6_proto.h:248
DBTable::DBTableWalkRef evpn_walk_ref()
Definition: icmpv6_proto.h:233
DBTable::DBTableWalkRef managed_delete_walk_ref()
Definition: icmpv6_proto.h:230
std::pair< const IpAddress, Icmpv6PathPreferenceState * > Icmpv6PathPreferenceStatePair
Definition: icmpv6_proto.h:191
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
std::map< const IpAddress, Icmpv6PathPreferenceState * > Icmpv6PathPreferenceStateMap
Definition: icmpv6_proto.h:189
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
void ManagedDelete()
Definition: icmpv6_proto.h:209
Definition: timer.h:58
Definition: vrf.h:90
void intrusive_ptr_release(Icmpv6PathPreferenceState *ps)
void intrusive_ptr_add_ref(Icmpv6PathPreferenceState *ps)
boost::intrusive_ptr< Icmpv6PathPreferenceState > Icmpv6PathPreferenceStatePtr
Definition: icmpv6_proto.h:338
uint8_t type
Definition: load_balance.h:2
Definition: io_utils.cc:12
Icmpv6Ipc(Icmpv6Proto::Icmpv6MsgType msg, NdpKey &akey, InterfaceConstRef itf)
Definition: icmpv6_proto.h:49
InterfaceConstRef interface_
Definition: icmpv6_proto.h:56
Icmpv6Ipc(Icmpv6Proto::Icmpv6MsgType msg, Ip6Address ip, const VrfEntry *vrf, InterfaceConstRef itf)
Definition: icmpv6_proto.h:51
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