A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ndisc-cache.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2009 Strasbourg University
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
7 */
8
9#ifndef NDISC_CACHE_H
10#define NDISC_CACHE_H
11
12#include "ns3/ipv6-address.h"
13#include "ns3/net-device.h"
14#include "ns3/nstime.h"
15#include "ns3/output-stream-wrapper.h"
16#include "ns3/packet.h"
17#include "ns3/ptr.h"
18#include "ns3/timer.h"
19
20#include <list>
21#include <map>
22#include <stdint.h>
23
24namespace ns3
25{
26
27class NetDevice;
28class Ipv6Interface;
29class Ipv6Header;
31
32/**
33 * @ingroup ipv6
34 *
35 * @brief IPv6 Neighbor Discovery cache.
36 */
37class NdiscCache : public Object
38{
39 public:
40 class Entry;
41
42 /**
43 * @brief Get the type ID
44 * @return type ID
45 */
46 static TypeId GetTypeId();
47
48 /**
49 * @brief Default value for unres qlen.
50 */
51 static const uint32_t DEFAULT_UNRES_QLEN = 3;
52
53 /**
54 * @brief Constructor.
55 */
56 NdiscCache();
57
58 /**
59 * @brief Destructor.
60 */
61 ~NdiscCache() override;
62
63 // Delete default and copy constructor, and assignment operator to avoid misuse
64 NdiscCache(const NdiscCache&) = delete;
65 NdiscCache& operator=(const NdiscCache&) = delete;
66
67 /**
68 * @brief Get the NetDevice associated with this cache.
69 * @return NetDevice
70 */
72
73 /**
74 * @brief Get the Ipv6Interface associated with this cache.
75 * @returns The Ipv6Interface.
76 */
78
79 /**
80 * @brief Lookup in the cache.
81 * @param dst destination address.
82 * @return the entry if found, 0 otherwise.
83 */
85
86 /**
87 * @brief Lookup in the cache for a MAC address.
88 * @param dst destination MAC address.
89 * @return a list of matching entries.
90 */
91 std::list<NdiscCache::Entry*> LookupInverse(Address dst);
92
93 /**
94 * @brief Add an entry.
95 * @param to address to add
96 * @return an new Entry
97 */
99
100 /**
101 * @brief Delete an entry.
102 * @param entry pointer to delete from the list.
103 */
104 void Remove(NdiscCache::Entry* entry);
105
106 /**
107 * @brief Clear the cache of all entries except auto-generated entries
108 *
109 * If you wish to remove all entries, including auto-generated entries,
110 * call this method and then also call RemoveAutoGeneratedEntries().
111 *
112 * @see RemoveAutoGenerated
113 */
114 void Flush();
115
116 /**
117 * @brief Set the max number of waiting packet.
118 * @param unresQlen value to set
119 */
120 void SetUnresQlen(uint32_t unresQlen);
121
122 /**
123 * @brief Get the max number of waiting packet.
124 * @return max number
125 */
127
128 /**
129 * @brief Set the device and interface.
130 * @param device the device
131 * @param interface the IPv6 interface
132 * @param icmpv6 the ICMPv6 protocol
133 */
134 void SetDevice(Ptr<NetDevice> device,
135 Ptr<Ipv6Interface> interface,
136 Ptr<Icmpv6L4Protocol> icmpv6);
137
138 /**
139 * @brief Print the NDISC cache entries
140 *
141 * @param stream the ostream the NDISC cache entries is printed to
142 */
144
145 /**
146 * @brief Clear the NDISC cache of all Auto-Generated entries
147 */
149
150 /**
151 * @brief Pair of a packet and an Ipv4 header.
152 */
153 typedef std::pair<Ptr<Packet>, Ipv6Header> Ipv6PayloadHeaderPair;
154
155 /**
156 * @ingroup ipv6
157 *
158 * @brief A record that holds information about a NdiscCache entry.
159 */
160 class Entry
161 {
162 public:
163 /**
164 * @brief Constructor.
165 * @param nd The NdiscCache this entry belongs to.
166 */
167 Entry(NdiscCache* nd);
168
169 virtual ~Entry() = default;
170
171 /**
172 * @brief The Entry state enumeration.
173 */
175 {
176 INCOMPLETE, /**< No mapping between IPv6 and L2 addresses */
177 REACHABLE, /**< Mapping exists between IPv6 and L2 addresses */
178 STALE, /**< Mapping is stale */
179 DELAY, /**< Try to wait contact from remote host */
180 PROBE, /**< Try to contact IPv6 address to know again its L2 address */
181 PERMANENT, /**< Permanent Mapping exists between IPv6 and L2 addresses */
182 STATIC_AUTOGENERATED /**< Permanent entries generate by NeighborCacheHelper*/
183 };
184
185 /**
186 * @brief The state of the entry.
187 */
189
190 /**
191 * @brief Changes the state to this entry to INCOMPLETE.
192 * @param p packet that wait to be sent
193 */
195
196 /**
197 * @brief Changes the state to this entry to REACHABLE.
198 * @param mac MAC address
199 * @return the list of packet waiting
200 */
201 std::list<Ipv6PayloadHeaderPair> MarkReachable(Address mac);
202
203 /**
204 * @brief Changes the state to this entry to PROBE.
205 */
206 void MarkProbe();
207
208 /**
209 * @brief Changes the state to this entry to STALE.
210 * @param mac L2 address
211 * @return the list of packet waiting
212 */
213 std::list<Ipv6PayloadHeaderPair> MarkStale(Address mac);
214
215 /**
216 * @brief Changes the state to this entry to STALE.
217 */
218 void MarkStale();
219
220 /**
221 * @brief Changes the state to this entry to REACHABLE.
222 */
223 void MarkReachable();
224
225 /**
226 * @brief Change the state to this entry to DELAY.
227 */
228 void MarkDelay();
229
230 /**
231 * @brief Change the state to this entry to PERMANENT.
232 */
233 void MarkPermanent();
234
235 /**
236 * @brief Changes the state of this entry to auto-generated.
237 *
238 * The entry must have a valid MacAddress.
239 */
240 void MarkAutoGenerated();
241
242 /**
243 * @brief Add a packet (or replace old value) in the queue.
244 * @param p packet to add
245 */
247
248 /**
249 * @brief Clear the waiting packet list.
250 */
251 void ClearWaitingPacket();
252
253 /**
254 * @brief Is the entry STALE
255 * @return true if the entry is in STALE state, false otherwise
256 */
257 bool IsStale() const;
258
259 /**
260 * @brief Is the entry REACHABLE
261 * @return true if the entry is in REACHABLE state, false otherwise
262 */
263 bool IsReachable() const;
264
265 /**
266 * @brief Is the entry DELAY
267 * @return true if the entry is in DELAY state, false otherwise
268 */
269 bool IsDelay() const;
270
271 /**
272 * @brief Is the entry INCOMPLETE
273 * @return true if the entry is in INCOMPLETE state, false otherwise
274 */
275 bool IsIncomplete() const;
276
277 /**
278 * @brief Is the entry PROBE
279 * @return true if the entry is in PROBE state, false otherwise
280 */
281 bool IsProbe() const;
282
283 /**
284 * @brief Is the entry PERMANENT
285 * @return true if the entry is in PERMANENT state, false otherwise
286 */
287 bool IsPermanent() const;
288
289 /**
290 * @brief Is the entry STATIC_AUTOGENERATED
291 * @return True if the state of this entry is auto-generated; false otherwise.
292 */
293 bool IsAutoGenerated() const;
294
295 /**
296 * @brief Get the MAC address of this entry.
297 * @return the L2 address
298 */
299 Address GetMacAddress() const;
300
301 /**
302 * @brief Set the MAC address of this entry.
303 * @param mac the MAC address to set
304 */
305 void SetMacAddress(Address mac);
306
307 /**
308 * @brief If the entry is a host or a router.
309 * @return true if the node is a router, 0 if it is a host
310 */
311 bool IsRouter() const;
312
313 /**
314 * @brief Set the node type.
315 * @param router true is a router, false means a host
316 */
317 void SetRouter(bool router);
318
319 /**
320 * @brief Get the time of last reachability confirmation.
321 * @return time
322 */
324
325 /**
326 * @brief Start the reachable timer.
327 */
328 void StartReachableTimer();
329
330 /**
331 * @brief Update the reachable timer.
332 */
334
335 /**
336 * @brief Start retransmit timer.
337 */
339
340 /**
341 * @brief Start probe timer.
342 */
343 void StartProbeTimer();
344
345 /**
346 * @brief Start delay timer.
347 */
348 void StartDelayTimer();
349
350 /**
351 * @brief Stop NUD timer and reset the NUD retransmission counter
352 */
353 void StopNudTimer();
354
355 /**
356 * @brief Function called when reachable timer timeout.
357 */
359
360 /**
361 * @brief Function called when retransmit timer timeout.
362 * It verify that the NS retransmit has reached the max so discard the entry
363 * otherwise it retransmit a NS.
364 */
366
367 /**
368 * @brief Function called when probe timer timeout.
369 */
371
372 /**
373 * @brief Function called when delay timer timeout.
374 */
376
377 /**
378 * @brief Set the IPv6 address.
379 * @param ipv6Address IPv6 address
380 */
381 void SetIpv6Address(Ipv6Address ipv6Address);
382
383 /**
384 * @brief Get the IPv6 address.
385 * @returns The IPv6 address
386 */
388
389 /**
390 * @brief Get the state of the entry.
391 * @returns The state of the entry
392 */
394
395 /**
396 * @brief Print this entry to the given output stream.
397 *
398 * @param os the output stream to which this Ipv6Address is printed
399 */
400 void Print(std::ostream& os) const;
401
402 protected:
403 /**
404 * @brief the NdiscCache associated.
405 */
407
408 private:
409 /**
410 * @brief The IPv6 address.
411 */
413
414 /**
415 * @brief The MAC address.
416 */
418
419 /**
420 * @brief The list of packet waiting.
421 */
422 std::list<Ipv6PayloadHeaderPair> m_waiting;
423
424 /**
425 * @brief Type of node (router or host).
426 */
428
429 /**
430 * @brief Timer (used for NUD).
431 */
433
434 /**
435 * @brief Last time we see a reachability confirmation.
436 */
438
439 /**
440 * @brief Number of NS retransmission.
441 */
443 };
444
445 protected:
446 /**
447 * @brief Dispose this object.
448 */
449 void DoDispose() override;
450
451 /**
452 * @brief Neighbor Discovery Cache container
453 */
454 typedef std::map<Ipv6Address, NdiscCache::Entry*> Cache;
455 /**
456 * @brief Neighbor Discovery Cache container iterator
457 */
458 typedef std::map<Ipv6Address, NdiscCache::Entry*>::iterator CacheI;
459
460 /**
461 * @brief A list of Entry.
462 */
464
465 private:
466 /**
467 * @brief The NetDevice.
468 */
470
471 /**
472 * @brief the interface.
473 */
475
476 /**
477 * @brief the icmpv6 L4 protocol for this cache.
478 */
480
481 /**
482 * @brief Max number of packet stored in m_waiting.
483 */
485};
486
487/**
488 * @brief Stream insertion operator.
489 *
490 * @param os the reference to the output stream
491 * @param entry the NdiscCache::Entry
492 * @returns the reference to the output stream
493 */
494std::ostream& operator<<(std::ostream& os, const NdiscCache::Entry& entry);
495
496} /* namespace ns3 */
497
498#endif /* NDISC_CACHE_H */
a polymophic address class
Definition address.h:90
An implementation of the ICMPv6 protocol.
Describes an IPv6 address.
Packet header for IPv6.
Definition ipv6-header.h:24
The IPv6 representation of a network interface.
A record that holds information about a NdiscCache entry.
bool m_router
Type of node (router or host).
virtual ~Entry()=default
void MarkProbe()
Changes the state to this entry to PROBE.
bool IsPermanent() const
Is the entry PERMANENT.
void MarkPermanent()
Change the state to this entry to PERMANENT.
NdiscCacheEntryState_e m_state
The state of the entry.
NdiscCacheEntryState_e
The Entry state enumeration.
@ PROBE
Try to contact IPv6 address to know again its L2 address.
@ STALE
Mapping is stale.
@ REACHABLE
Mapping exists between IPv6 and L2 addresses.
@ PERMANENT
Permanent Mapping exists between IPv6 and L2 addresses.
@ DELAY
Try to wait contact from remote host.
@ INCOMPLETE
No mapping between IPv6 and L2 addresses.
@ STATIC_AUTOGENERATED
Permanent entries generate by NeighborCacheHelper.
void ClearWaitingPacket()
Clear the waiting packet list.
void StartProbeTimer()
Start probe timer.
Ipv6Address m_ipv6Address
The IPv6 address.
void MarkReachable()
Changes the state to this entry to REACHABLE.
NdiscCacheEntryState_e GetEntryState() const
Get the state of the entry.
void StartReachableTimer()
Start the reachable timer.
void Print(std::ostream &os) const
Print this entry to the given output stream.
void UpdateReachableTimer()
Update the reachable timer.
uint8_t m_nsRetransmit
Number of NS retransmission.
void FunctionProbeTimeout()
Function called when probe timer timeout.
void MarkStale()
Changes the state to this entry to STALE.
std::list< Ipv6PayloadHeaderPair > m_waiting
The list of packet waiting.
Time m_lastReachabilityConfirmation
Last time we see a reachability confirmation.
Address GetMacAddress() const
Get the MAC address of this entry.
Ipv6Address GetIpv6Address() const
Get the IPv6 address.
void StartDelayTimer()
Start delay timer.
void MarkAutoGenerated()
Changes the state of this entry to auto-generated.
bool IsIncomplete() const
Is the entry INCOMPLETE.
Address m_macAddress
The MAC address.
void FunctionDelayTimeout()
Function called when delay timer timeout.
bool IsDelay() const
Is the entry DELAY.
void StartRetransmitTimer()
Start retransmit timer.
void SetIpv6Address(Ipv6Address ipv6Address)
Set the IPv6 address.
void MarkIncomplete(Ipv6PayloadHeaderPair p)
Changes the state to this entry to INCOMPLETE.
bool IsStale() const
Is the entry STALE.
void SetMacAddress(Address mac)
Set the MAC address of this entry.
bool IsProbe() const
Is the entry PROBE.
Time GetLastReachabilityConfirmation() const
Get the time of last reachability confirmation.
void FunctionRetransmitTimeout()
Function called when retransmit timer timeout.
NdiscCache * m_ndCache
the NdiscCache associated.
void MarkDelay()
Change the state to this entry to DELAY.
Entry(NdiscCache *nd)
Constructor.
bool IsRouter() const
If the entry is a host or a router.
void SetRouter(bool router)
Set the node type.
Timer m_nudTimer
Timer (used for NUD).
void FunctionReachableTimeout()
Function called when reachable timer timeout.
bool IsAutoGenerated() const
Is the entry STATIC_AUTOGENERATED.
void AddWaitingPacket(Ipv6PayloadHeaderPair p)
Add a packet (or replace old value) in the queue.
bool IsReachable() const
Is the entry REACHABLE.
void StopNudTimer()
Stop NUD timer and reset the NUD retransmission counter.
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv6Interface > interface, Ptr< Icmpv6L4Protocol > icmpv6)
Set the device and interface.
std::pair< Ptr< Packet >, Ipv6Header > Ipv6PayloadHeaderPair
Pair of a packet and an Ipv4 header.
virtual NdiscCache::Entry * Add(Ipv6Address to)
Add an entry.
void Flush()
Clear the cache of all entries except auto-generated entries.
Ptr< Ipv6Interface > m_interface
the interface.
void Remove(NdiscCache::Entry *entry)
Delete an entry.
std::map< Ipv6Address, NdiscCache::Entry * >::iterator CacheI
Neighbor Discovery Cache container iterator.
NdiscCache()
Constructor.
void PrintNdiscCache(Ptr< OutputStreamWrapper > stream)
Print the NDISC cache entries.
~NdiscCache() override
Destructor.
Ptr< NetDevice > m_device
The NetDevice.
uint32_t GetUnresQlen()
Get the max number of waiting packet.
virtual NdiscCache::Entry * Lookup(Ipv6Address dst)
Lookup in the cache.
void RemoveAutoGeneratedEntries()
Clear the NDISC cache of all Auto-Generated entries.
void DoDispose() override
Dispose this object.
Ptr< NetDevice > GetDevice() const
Get the NetDevice associated with this cache.
std::map< Ipv6Address, NdiscCache::Entry * > Cache
Neighbor Discovery Cache container.
static const uint32_t DEFAULT_UNRES_QLEN
Default value for unres qlen.
Definition ndisc-cache.h:51
NdiscCache & operator=(const NdiscCache &)=delete
static TypeId GetTypeId()
Get the type ID.
Cache m_ndCache
A list of Entry.
NdiscCache(const NdiscCache &)=delete
std::list< NdiscCache::Entry * > LookupInverse(Address dst)
Lookup in the cache for a MAC address.
void SetUnresQlen(uint32_t unresQlen)
Set the max number of waiting packet.
Ptr< Icmpv6L4Protocol > m_icmpv6
the icmpv6 L4 protocol for this cache.
Ptr< Ipv6Interface > GetInterface() const
Get the Ipv6Interface associated with this cache.
uint32_t m_unresQlen
Max number of packet stored in m_waiting.
Network layer to device interface.
Definition net-device.h:87
Object()
Constructor.
Definition object.cc:96
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
Simulation virtual time values and global simulation resolution.
Definition nstime.h:96
A simple virtual Timer class.
Definition timer.h:67
a unique identifier for an interface.
Definition type-id.h:49
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148