OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
icmpv6_proto.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_agent_icmpv6_proto_h
6 #define vnsw_agent_icmpv6_proto_h
7 
8 #include "pkt/proto.h"
10 #include "services/ndp_entry.h"
11 
12 #define ICMP_PKT_SIZE 1024
13 #define IPV6_ALL_NODES_ADDRESS "FF02::1"
14 #define IPV6_ALL_ROUTERS_ADDRESS "FF02::2"
15 #define PKT0_LINKLOCAL_ADDRESS "FE80::5E00:0100"
16 
17 #define NDP_TRACE(obj, ...) \
18 do { \
19  Ndp##obj::TraceMsg(Icmpv6TraceBuf, __FILE__, __LINE__, ##__VA_ARGS__); \
20 } while (false) \
21 
22 #define ICMPV6_TRACE(obj, arg) \
23 do { \
24  std::ostringstream _str; \
25  _str << arg; \
26  Icmpv6##obj::TraceMsg(Icmpv6TraceBuf, __FILE__, __LINE__, _str.str()); \
27 } while (false) \
28 
29 class Icmpv6VrfState;
31 
32 class Icmpv6Proto : public Proto {
33 public:
34  static const uint32_t kRouterAdvertTimeout = 30000; // milli seconds
35  static const uint16_t kMaxRetries = 8;
36  static const uint32_t kRetryTimeout = 2000; // milli seconds
37  static const uint32_t kAgingTimeout = (5 * 60 * 1000); // milli seconds
38 
43  };
44 
47  : InterTaskMsg(msg), key(akey), interface_(itf) {}
49  const VrfEntry *vrf, InterfaceConstRef itf) :
50  InterTaskMsg(msg), key(ip, vrf), interface_(itf) {}
51 
54  };
55 
56  struct Icmpv6Stats {
57  Icmpv6Stats() { Reset(); }
58  void Reset() {
64  }
65 
70  uint32_t icmpv6_drop_;
75  };
76 
77  typedef std::map<VmInterface *, Icmpv6Stats> VmInterfaceMap;
78  typedef std::pair<VmInterface *, Icmpv6Stats> VmInterfacePair;
79  typedef std::map<NdpKey, NdpEntry *> NdpCache;
80  typedef std::pair<NdpKey, NdpEntry *> NdpCachePair;
81  typedef std::map<NdpKey, NdpEntry *>::iterator NdpIterator;
82  typedef std::set<NdpKey> NdpKeySet;
83  typedef std::set<NdpEntry *> NdpEntrySet;
84  typedef std::map<NdpKey, NdpEntrySet> UnsolNaCache;
85  typedef std::pair<NdpKey, NdpEntrySet> UnsolNaCachePair;
86  typedef std::map<NdpKey, NdpEntrySet>::iterator UnsolNaIterator;
87 
92  };
93  typedef std::map<uint32_t, InterfaceNdpInfo> InterfaceNdpMap;
94  typedef std::pair<uint32_t, InterfaceNdpInfo> InterfaceNdpPair;
95 
96  void Shutdown();
97  Icmpv6Proto(Agent *agent, boost::asio::io_context &io);
98  virtual ~Icmpv6Proto();
99  ProtoHandler *AllocProtoHandler(boost::shared_ptr<PktInfo> info,
100  boost::asio::io_context &io);
101  void VrfNotify(DBTablePartBase *part, DBEntryBase *entry);
102  void VnNotify(DBEntryBase *entry);
103  void InterfaceNotify(DBEntryBase *entry);
104  void NexthopNotify(DBEntryBase *entry);
106  const VrfEntry *vrf, InterfaceConstRef itf);
107 
109 
119  const Icmpv6Stats &GetStats() const { return stats_; }
120  Icmpv6Stats *VmiToIcmpv6Stats(VmInterface *i);
121  void ClearStats() { stats_.Reset(); }
124 
126  uint32_t ip_fabric_interface_index() const {
128  }
131  }
133  void set_ip_fabric_interface_index(uint32_t ind) {
135  }
138  }
139 
140  bool AddNdpEntry(NdpEntry *entry);
141  bool DeleteNdpEntry(NdpEntry *entry);
142  NdpEntry *FindNdpEntry(const NdpKey &key);
143  std::size_t GetNdpCacheSize() { return ndp_cache_.size(); }
144  const NdpCache& ndp_cache() { return ndp_cache_; }
147 
148  void AddUnsolNaEntry(NdpKey &key);
149  void DeleteUnsolNaEntry(NdpEntry *entry);
150  void HandlePathPreferenceNA(const VrfEntry*, uint32_t, IpAddress);
152  NdpEntry* UnsolNaEntry (const NdpKey &key, const Interface *intf);
154  UnsolNaEntryIterator(const NdpKey &key, bool *key_valid);
156  return vrf_table_listener_id_;
157  }
158 
159 private:
166  bool HandlePacket();
167  bool HandleMessage();
170  InterfaceConstRef itf);
171  // handler to send router advertisements and neighbor solicits
172  boost::scoped_ptr<Icmpv6Handler> icmpv6_handler_;
181 };
182 
183 class Icmpv6VrfState : public DBState {
184 public:
185  typedef std::map<const IpAddress,
187  typedef std::pair<const IpAddress,
189 
191  AgentRouteTable *table, AgentRouteTable *evpn_table);
192  ~Icmpv6VrfState();
193  Agent *agent() const { return agent_; }
194  Icmpv6Proto * icmp_proto() const { return icmp_proto_; }
197  }
200  }
202  void set_default_routes_added(bool value) { default_routes_added_ = value; }
203 
204  void RouteUpdate(DBTablePartBase *part, DBEntryBase *entry);
205  void EvpnRouteUpdate(DBTablePartBase *part, DBEntryBase *entry);
206  void ManagedDelete() { deleted_ = true;}
207  void Delete();
208  bool DeleteRouteState(DBTablePartBase *part, DBEntryBase *entry);
210  bool PreWalkDone(DBTableBase *partition);
211  static void WalkDone(DBTableBase *partition, Icmpv6VrfState *state);
212  bool deleted() const {return deleted_;}
213 
215  void Erase(const IpAddress &ip);
217  return icmpv6_path_preference_map_[ip];
218  }
219 
220  bool l3_walk_completed() const {
221  return l3_walk_completed_;
222  }
223 
224  bool evpn_walk_completed() const {
225  return evpn_walk_completed_;
226  }
229  }
231  return evpn_walk_ref_;
232  }
233 
234 private:
244  bool deleted_;
252 };
253 
255  uint32_t ns_try_count;
256  uint32_t ns_send_count;
257  uint32_t ns_retry_count;
259  ns_retry_count(0) {
260  }
261 };
262 
264 public:
265  static const uint32_t kMaxRetry = 30 * 5; //retries upto 5 minutes,
266  //30 tries/per minutes
267  static const uint32_t kTimeout = 2000;
268 
269  static const uint32_t kTimeoutMultiplier = 5;
270 
271  static const uint32_t kNSTryCount = 9;
272 
273  typedef std::map<uint32_t, InterfaceIcmpv6PathPreferenceInfo> WaitForTrafficIntfMap;
274  typedef std::set<uint32_t> NDTransmittedIntfMap;
275 
277  IpAddress vm_ip_addr, uint8_t plen);
279  bool SendNeighborSolicit();
280  bool SendNeighborSolicit(WaitForTrafficIntfMap &wait_for_traffic_map,
281  NDTransmittedIntfMap &nd_transmitted_map);
282  void SendNeighborSolicitForAllIntf(const AgentRoute *route);
283  void StartTimer();
284  void HandleNA(uint32_t itf);
286  return vrf_state_;
287  }
288 
289  const IpAddress& ip() const {
290  return vm_ip_;
291  }
292 
293  MacAddress mac(void) const { return mac_; }
294 
295  bool IntfPresentInIpMap(uint32_t id) {
296  if (l3_wait_for_traffic_map_.find(id) ==
297  l3_wait_for_traffic_map_.end()) {
298  return false;
299  }
300  return true;
301  }
302 
303  bool IntfPresentInEvpnMap(uint32_t id) {
304  if (evpn_wait_for_traffic_map_.find(id) ==
306  return false;
307  }
308  return true;
309  }
310 
311  uint32_t IntfRetryCountInIpMap(uint32_t id) {
312  return l3_wait_for_traffic_map_[id].ns_retry_count;
313  }
314 
315  uint32_t IntfRetryCountInEvpnMap(uint32_t id) {
316  return evpn_wait_for_traffic_map_[id].ns_retry_count;
317  }
318 
319 private:
324  uint32_t vrf_id_;
327  uint8_t plen_;
331  tbb::atomic<int> refcount_;
332 };
333 
334 typedef boost::intrusive_ptr<Icmpv6PathPreferenceState>
336 
339 
340 class Icmpv6RouteState : public DBState {
341 public:
342  Icmpv6RouteState(Icmpv6VrfState *vrf_state, uint32_t vrf_id,
343  IpAddress vm_ip_addr, uint8_t plen);
345  void SendNeighborSolicitForAllIntf(const AgentRoute *route);
346 private:
348 };
349 #endif // vnsw_agent_icmpv6_proto_h
std::map< NdpKey, NdpEntrySet >::iterator UnsolNaIterator
Definition: icmpv6_proto.h:86
DBTable::DBTableWalkRef managed_delete_walk_ref()
Definition: icmpv6_proto.h:227
const InterfaceNdpMap & interface_ndp_map()
Definition: icmpv6_proto.h:146
static const uint16_t kMaxRetries
Definition: icmpv6_proto.h:35
int intrusive_ptr_add_ref(const AsPath *cpath)
Definition: bgp_aspath.h:147
std::map< VmInterface *, Icmpv6Stats > VmInterfaceMap
Definition: icmpv6_proto.h:77
NdpEntry * FindNdpEntry(const NdpKey &key)
bool l3_walk_completed() const
Definition: icmpv6_proto.h:220
Icmpv6Proto * icmp_proto_
Definition: icmpv6_proto.h:236
Icmpv6PathPreferenceState * Locate(const IpAddress &ip)
void HandlePathPreferenceNA(const VrfEntry *, uint32_t, IpAddress)
bool deleted() const
Definition: icmpv6_proto.h:212
bool DeleteNdpEntry(NdpEntry *entry)
static const uint32_t kNSTryCount
Definition: icmpv6_proto.h:271
Definition: vrf.h:86
std::pair< VmInterface *, Icmpv6Stats > VmInterfacePair
Definition: icmpv6_proto.h:78
Interface * ip_fabric_interface_
Definition: icmpv6_proto.h:179
Icmpv6Proto * icmp_proto() const
Definition: icmpv6_proto.h:194
DBTableBase::ListenerId vrf_table_listener_id() const
Definition: icmpv6_proto.h:155
void VrfNotify(DBTablePartBase *part, DBEntryBase *entry)
DBTable::DBTableWalkRef evpn_walk_ref()
Definition: icmpv6_proto.h:230
Icmpv6VrfState(Agent *agent, Icmpv6Proto *proto, VrfEntry *vrf, AgentRouteTable *table, AgentRouteTable *evpn_table)
Icmpv6VrfState * vrf_state_
Definition: icmpv6_proto.h:322
std::map< NdpKey, NdpEntrySet > UnsolNaCache
Definition: icmpv6_proto.h:84
std::map< const IpAddress, Icmpv6PathPreferenceState * > Icmpv6PathPreferenceStateMap
Definition: icmpv6_proto.h:186
WaitForTrafficIntfMap l3_wait_for_traffic_map_
Definition: icmpv6_proto.h:329
Agent supports multiple route tables - Inet-unicast (IPv4/IPv6), Inet-multicast, bridge, EVPN (Type2/Type5). This base class contains common code for all types of route tables.
Definition: agent_route.h:109
uint32_t ip_fabric_interface_index() const
Definition: icmpv6_proto.h:126
bool IntfPresentInEvpnMap(uint32_t id)
Definition: icmpv6_proto.h:303
void IncrementStatsNeighborAdvertUnSolicited(VmInterface *vmi)
void set_route_table_listener_id(const DBTableBase::ListenerId &id)
Definition: icmpv6_proto.h:195
bool PreWalkDone(DBTableBase *partition)
void SendNeighborSolicitForAllIntf(const AgentRoute *route)
DBTableBase::ListenerId evpn_route_table_listener_id_
Definition: icmpv6_proto.h:241
Icmpv6RouteState(Icmpv6VrfState *vrf_state, uint32_t vrf_id, IpAddress vm_ip_addr, uint8_t plen)
DBTableBase::ListenerId vrf_table_listener_id_
Definition: icmpv6_proto.h:174
boost::asio::ip::address IpAddress
Definition: address.h:13
uint32_t icmpv6_neighbor_advert_solicited_
Definition: icmpv6_proto.h:73
AgentRouteTable * rt_table_
Definition: icmpv6_proto.h:238
tbb::atomic< int > refcount_
Definition: icmpv6_proto.h:331
int ListenerId
Definition: db_table.h:62
Icmpv6Stats * VmiToIcmpv6Stats(VmInterface *i)
DISALLOW_COPY_AND_ASSIGN(Icmpv6VrfState)
UnsolNaCache unsol_na_cache_
Definition: icmpv6_proto.h:164
uint32_t icmpv6_neighbor_solicit_
Definition: icmpv6_proto.h:71
Icmpv6PathPreferenceStatePtr icmpv6_path_preference_state_
Definition: icmpv6_proto.h:347
void ManagedDelete()
Definition: icmpv6_proto.h:206
void SendIcmpv6Ipc(Icmpv6Proto::Icmpv6MsgType type, Ip6Address ip, const VrfEntry *vrf, InterfaceConstRef itf)
bool default_routes_added() const
Definition: icmpv6_proto.h:201
void set_evpn_route_table_listener_id(const DBTableBase::ListenerId &id)
Definition: icmpv6_proto.h:198
const NdpCache & ndp_cache()
Definition: icmpv6_proto.h:144
static const uint32_t kTimeoutMultiplier
Definition: icmpv6_proto.h:269
Agent * agent() const
Definition: icmpv6_proto.h:193
friend void intrusive_ptr_add_ref(Icmpv6PathPreferenceState *ps)
ProtoHandler * AllocProtoHandler(boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
Definition: icmpv6_proto.cc:51
void IncrementStatsNeighborSolicit(VmInterface *vmi)
bool HandlePacket()
Base class for all Route entries in agent.
Definition: agent_route.h:224
void set_ip_fabric_interface_mac(const MacAddress &mac)
Definition: icmpv6_proto.h:136
bool HandleMessage()
DBTableBase::ListenerId interface_listener_id_
Definition: icmpv6_proto.h:175
Icmpv6VrfState * vrf_state()
Definition: icmpv6_proto.h:285
LifetimeRef< Icmpv6VrfState > evpn_table_delete_ref_
Definition: icmpv6_proto.h:243
uint32_t ip_fabric_interface_index_
Definition: icmpv6_proto.h:177
void ClearStats()
Definition: icmpv6_proto.h:121
static const uint32_t kMaxRetry
Definition: icmpv6_proto.h:265
bool IntfPresentInIpMap(uint32_t id)
Definition: icmpv6_proto.h:295
const Icmpv6Stats & GetStats() const
Definition: icmpv6_proto.h:119
void IncrementStatsDrop()
Definition: icmpv6_proto.h:114
void IncrementStatsRouterSolicit(VmInterface *vmi)
void IncrementStatsPingResponse(VmInterface *vmi)
std::map< uint32_t, InterfaceNdpInfo > InterfaceNdpMap
Definition: icmpv6_proto.h:93
std::set< uint32_t > NDTransmittedIntfMap
Definition: icmpv6_proto.h:274
static const uint32_t kRouterAdvertTimeout
Definition: icmpv6_proto.h:34
static void WalkDone(DBTableBase *partition, Icmpv6VrfState *state)
void IncrementStatsNeighborSolicited(VmInterface *vmi)
uint8_t type
Definition: load_balance.h:109
void HandleNA(uint32_t itf)
NdpEntry * UnsolNaEntry(const NdpKey &key, const Interface *intf)
void IncrementStatsNeighborAdvertSolicited(VmInterface *vmi)
Definition: agent.h:358
bool ValidateAndClearVrfState(VrfEntry *vrf, Icmpv6VrfState *state)
void IncrementStatsRouterAdvert(VmInterface *vmi)
AgentRouteTable * evpn_rt_table_
Definition: icmpv6_proto.h:239
std::size_t GetNdpCacheSize()
Definition: icmpv6_proto.h:143
DISALLOW_COPY_AND_ASSIGN(Icmpv6Proto)
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:15
void set_ip_fabric_interface_index(uint32_t ind)
Definition: icmpv6_proto.h:133
uint32_t icmpv6_neighbor_advert_unsolicited_
Definition: icmpv6_proto.h:74
Icmpv6PathPreferenceState(Icmpv6VrfState *vrf_state, uint32_t vrf_id, IpAddress vm_ip_addr, uint8_t plen)
void set_ip_fabric_interface(Interface *itf)
Definition: icmpv6_proto.h:132
void NexthopNotify(DBEntryBase *entry)
DBTableBase::ListenerId vn_table_listener_id_
Definition: icmpv6_proto.h:173
void Erase(const IpAddress &ip)
boost::intrusive_ptr< const Interface > InterfaceConstRef
Definition: agent.h:51
bool default_routes_added_
Definition: icmpv6_proto.h:245
Icmpv6Stats stats_
Definition: icmpv6_proto.h:161
void SendNeighborSolicitForAllIntf(const AgentRoute *route)
static const uint32_t kRetryTimeout
Definition: icmpv6_proto.h:36
DBTable::DBTableWalkRef managed_delete_walk_ref_
Definition: icmpv6_proto.h:246
std::set< NdpEntry * > NdpEntrySet
Definition: icmpv6_proto.h:83
void AddUnsolNaEntry(NdpKey &key)
uint32_t IntfRetryCountInIpMap(uint32_t id)
Definition: icmpv6_proto.h:311
uint32_t IntfRetryCountInEvpnMap(uint32_t id)
Definition: icmpv6_proto.h:315
void DeleteUnsolNaEntry(NdpEntry *entry)
MacAddress ip_fabric_interface_mac_
Definition: icmpv6_proto.h:178
Icmpv6Proto::UnsolNaIterator UnsolNaEntryIterator(const NdpKey &key, bool *key_valid)
std::pair< NdpKey, NdpEntry * > NdpCachePair
Definition: icmpv6_proto.h:80
boost::scoped_ptr< Icmpv6Handler > icmpv6_handler_
Definition: icmpv6_proto.h:172
void EvpnRouteUpdate(DBTablePartBase *part, DBEntryBase *entry)
std::pair< uint32_t, InterfaceNdpInfo > InterfaceNdpPair
Definition: icmpv6_proto.h:94
NdpCache ndp_cache_
Definition: icmpv6_proto.h:163
void RouteUpdate(DBTablePartBase *part, DBEntryBase *entry)
MacAddress mac(void) const
Definition: icmpv6_proto.h:293
std::map< NdpKey, NdpEntry * > NdpCache
Definition: icmpv6_proto.h:79
static const uint32_t kTimeout
Definition: icmpv6_proto.h:267
bool DeleteEvpnRouteState(DBTablePartBase *part, DBEntryBase *entry)
std::set< NdpKey > NdpKeySet
Definition: icmpv6_proto.h:82
boost::intrusive_ptr< Icmpv6PathPreferenceState > Icmpv6PathPreferenceStatePtr
Definition: icmpv6_proto.h:335
NdpEntry * FindUnsolNaEntry(NdpKey &key)
Icmpv6PathPreferenceState * Get(const IpAddress ip)
Definition: icmpv6_proto.h:216
VmInterfaceMap vm_interfaces_
Definition: icmpv6_proto.h:162
Icmpv6PathPreferenceStateMap icmpv6_path_preference_map_
Definition: icmpv6_proto.h:248
std::pair< NdpKey, NdpEntrySet > UnsolNaCachePair
Definition: icmpv6_proto.h:85
Icmpv6Ipc(Icmpv6Proto::Icmpv6MsgType msg, Ip6Address ip, const VrfEntry *vrf, InterfaceConstRef itf)
Definition: icmpv6_proto.h:48
std::map< uint32_t, InterfaceIcmpv6PathPreferenceInfo > WaitForTrafficIntfMap
Definition: icmpv6_proto.h:273
Timer * timer_
Definition: icmpv6_proto.h:160
LifetimeRef< Icmpv6VrfState > table_delete_ref_
Definition: icmpv6_proto.h:242
const VmInterfaceMap & vm_interfaces()
Definition: icmpv6_proto.h:108
virtual ~Icmpv6Proto()
Definition: icmpv6_proto.cc:40
void intrusive_ptr_release(const AsPath *cpath)
Definition: bgp_aspath.h:155
bool AddNdpEntry(NdpEntry *entry)
const MacAddress & ip_fabric_interface_mac() const
Definition: icmpv6_proto.h:129
void set_default_routes_added(bool value)
Definition: icmpv6_proto.h:202
DBTable::DBTableWalkRef evpn_walk_ref_
Definition: icmpv6_proto.h:247
const IpAddress & ip() const
Definition: icmpv6_proto.h:289
InterfaceNdpMap interface_ndp_map_
Definition: icmpv6_proto.h:165
DBTableBase::ListenerId nexthop_listener_id_
Definition: icmpv6_proto.h:176
void VnNotify(DBEntryBase *entry)
Definition: icmpv6_proto.cc:69
bool DeleteRouteState(DBTablePartBase *part, DBEntryBase *entry)
InterfaceConstRef interface_
Definition: icmpv6_proto.h:53
uint32_t icmpv6_neighbor_solicited_
Definition: icmpv6_proto.h:72
void IncrementStatsPingRequest(VmInterface *vmi)
boost::intrusive_ptr< DBTableWalk > DBTableWalkRef
Definition: db_table.h:169
friend void intrusive_ptr_release(Icmpv6PathPreferenceState *ps)
const UnsolNaCache & unsol_na_cache()
Definition: icmpv6_proto.h:145
bool evpn_walk_completed_
Definition: icmpv6_proto.h:250
Definition: timer.h:54
Icmpv6VrfState * CreateAndSetVrfState(VrfEntry *vrf)
Definition: icmpv6_proto.cc:56
Icmpv6Proto(Agent *agent, boost::asio::io_context &io)
Definition: icmpv6_proto.cc:13
static const uint32_t kAgingTimeout
Definition: icmpv6_proto.h:37
Interface * ip_fabric_interface() const
Definition: icmpv6_proto.h:125
Icmpv6Ipc(Icmpv6Proto::Icmpv6MsgType msg, NdpKey &akey, InterfaceConstRef itf)
Definition: icmpv6_proto.h:46
std::pair< const IpAddress, Icmpv6PathPreferenceState * > Icmpv6PathPreferenceStatePair
Definition: icmpv6_proto.h:188
VrfEntry * vrf_
Definition: icmpv6_proto.h:237
DBTableBase::ListenerId route_table_listener_id_
Definition: icmpv6_proto.h:240
std::map< NdpKey, NdpEntry * >::iterator NdpIterator
Definition: icmpv6_proto.h:81
void InterfaceNotify(DBEntryBase *entry)
WaitForTrafficIntfMap evpn_wait_for_traffic_map_
Definition: icmpv6_proto.h:330
void Shutdown()
Definition: icmpv6_proto.cc:43
bool evpn_walk_completed() const
Definition: icmpv6_proto.h:224
bool l3_walk_completed_
Definition: icmpv6_proto.h:249