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;
30class Icmpv6L4Protocol;
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 Flush the cache.
108 */
109 void Flush();
110
111 /**
112 * \brief Set the max number of waiting packet.
113 * \param unresQlen value to set
114 */
115 void SetUnresQlen(uint32_t unresQlen);
116
117 /**
118 * \brief Get the max number of waiting packet.
119 * \return max number
120 */
122
123 /**
124 * \brief Set the device and interface.
125 * \param device the device
126 * \param interface the IPv6 interface
127 * \param icmpv6 the ICMPv6 protocol
128 */
129 void SetDevice(Ptr<NetDevice> device,
130 Ptr<Ipv6Interface> interface,
131 Ptr<Icmpv6L4Protocol> icmpv6);
132
133 /**
134 * \brief Print the NDISC cache entries
135 *
136 * \param stream the ostream the NDISC cache entries is printed to
137 */
139
140 /**
141 * \brief Clear the NDISC cache of all Auto-Generated entries
142 */
144
145 /**
146 * \brief Pair of a packet and an Ipv4 header.
147 */
148 typedef std::pair<Ptr<Packet>, Ipv6Header> Ipv6PayloadHeaderPair;
149
150 /**
151 * \ingroup ipv6
152 *
153 * \brief A record that holds information about a NdiscCache entry.
154 */
155 class Entry
156 {
157 public:
158 /**
159 * \brief Constructor.
160 * \param nd The NdiscCache this entry belongs to.
161 */
162 Entry(NdiscCache* nd);
163
164 virtual ~Entry() = default;
165
166 /**
167 * \brief The Entry state enumeration.
168 */
170 {
171 INCOMPLETE, /**< No mapping between IPv6 and L2 addresses */
172 REACHABLE, /**< Mapping exists between IPv6 and L2 addresses */
173 STALE, /**< Mapping is stale */
174 DELAY, /**< Try to wait contact from remote host */
175 PROBE, /**< Try to contact IPv6 address to know again its L2 address */
176 PERMANENT, /**< Permanent Mapping exists between IPv6 and L2 addresses */
177 STATIC_AUTOGENERATED /**< Permanent entries generate by NeighborCacheHelper*/
178 };
179
180 /**
181 * \brief The state of the entry.
182 */
184
185 /**
186 * \brief Changes the state to this entry to INCOMPLETE.
187 * \param p packet that wait to be sent
188 */
190
191 /**
192 * \brief Changes the state to this entry to REACHABLE.
193 * \param mac MAC address
194 * \return the list of packet waiting
195 */
196 std::list<Ipv6PayloadHeaderPair> MarkReachable(Address mac);
197
198 /**
199 * \brief Changes the state to this entry to PROBE.
200 */
201 void MarkProbe();
202
203 /**
204 * \brief Changes the state to this entry to STALE.
205 * \param mac L2 address
206 * \return the list of packet waiting
207 */
208 std::list<Ipv6PayloadHeaderPair> MarkStale(Address mac);
209
210 /**
211 * \brief Changes the state to this entry to STALE.
212 */
213 void MarkStale();
214
215 /**
216 * \brief Changes the state to this entry to REACHABLE.
217 */
218 void MarkReachable();
219
220 /**
221 * \brief Change the state to this entry to DELAY.
222 */
223 void MarkDelay();
224
225 /**
226 * \brief Change the state to this entry to PERMANENT.
227 */
228 void MarkPermanent();
229
230 /**
231 * \brief Changes the state of this entry to auto-generated.
232 *
233 * The entry must have a valid MacAddress.
234 */
235 void MarkAutoGenerated();
236
237 /**
238 * \brief Add a packet (or replace old value) in the queue.
239 * \param p packet to add
240 */
242
243 /**
244 * \brief Clear the waiting packet list.
245 */
246 void ClearWaitingPacket();
247
248 /**
249 * \brief Is the entry STALE
250 * \return true if the entry is in STALE state, false otherwise
251 */
252 bool IsStale() const;
253
254 /**
255 * \brief Is the entry REACHABLE
256 * \return true if the entry is in REACHABLE state, false otherwise
257 */
258 bool IsReachable() const;
259
260 /**
261 * \brief Is the entry DELAY
262 * \return true if the entry is in DELAY state, false otherwise
263 */
264 bool IsDelay() const;
265
266 /**
267 * \brief Is the entry INCOMPLETE
268 * \return true if the entry is in INCOMPLETE state, false otherwise
269 */
270 bool IsIncomplete() const;
271
272 /**
273 * \brief Is the entry PROBE
274 * \return true if the entry is in PROBE state, false otherwise
275 */
276 bool IsProbe() const;
277
278 /**
279 * \brief Is the entry PERMANENT
280 * \return true if the entry is in PERMANENT state, false otherwise
281 */
282 bool IsPermanent() const;
283
284 /**
285 * \brief Is the entry STATIC_AUTOGENERATED
286 * \return True if the state of this entry is auto-generated; false otherwise.
287 */
288 bool IsAutoGenerated() const;
289
290 /**
291 * \brief Get the MAC address of this entry.
292 * \return the L2 address
293 */
294 Address GetMacAddress() const;
295
296 /**
297 * \brief Set the MAC address of this entry.
298 * \param mac the MAC address to set
299 */
300 void SetMacAddress(Address mac);
301
302 /**
303 * \brief If the entry is a host or a router.
304 * \return true if the node is a router, 0 if it is a host
305 */
306 bool IsRouter() const;
307
308 /**
309 * \brief Set the node type.
310 * \param router true is a router, false means a host
311 */
312 void SetRouter(bool router);
313
314 /**
315 * \brief Get the time of last reachability confirmation.
316 * \return time
317 */
319
320 /**
321 * \brief Start the reachable timer.
322 */
323 void StartReachableTimer();
324
325 /**
326 * \brief Update the reachable timer.
327 */
329
330 /**
331 * \brief Start retransmit timer.
332 */
334
335 /**
336 * \brief Start probe timer.
337 */
338 void StartProbeTimer();
339
340 /**
341 * \brief Start delay timer.
342 */
343 void StartDelayTimer();
344
345 /**
346 * \brief Stop NUD timer and reset the NUD retransmission counter
347 */
348 void StopNudTimer();
349
350 /**
351 * \brief Function called when reachable timer timeout.
352 */
354
355 /**
356 * \brief Function called when retransmit timer timeout.
357 * It verify that the NS retransmit has reached the max so discard the entry
358 * otherwise it retransmit a NS.
359 */
361
362 /**
363 * \brief Function called when probe timer timeout.
364 */
366
367 /**
368 * \brief Function called when delay timer timeout.
369 */
371
372 /**
373 * \brief Set the IPv6 address.
374 * \param ipv6Address IPv6 address
375 */
376 void SetIpv6Address(Ipv6Address ipv6Address);
377
378 /**
379 * \brief Get the IPv6 address.
380 * \returns The IPv6 address
381 */
383
384 /**
385 * \brief Get the state of the entry.
386 * \returns The state of the entry
387 */
389
390 /**
391 * \brief Print this entry to the given output stream.
392 *
393 * \param os the output stream to which this Ipv6Address is printed
394 */
395 void Print(std::ostream& os) const;
396
397 protected:
398 /**
399 * \brief the NdiscCache associated.
400 */
402
403 private:
404 /**
405 * \brief The IPv6 address.
406 */
408
409 /**
410 * \brief The MAC address.
411 */
413
414 /**
415 * \brief The list of packet waiting.
416 */
417 std::list<Ipv6PayloadHeaderPair> m_waiting;
418
419 /**
420 * \brief Type of node (router or host).
421 */
423
424 /**
425 * \brief Timer (used for NUD).
426 */
428
429 /**
430 * \brief Last time we see a reachability confirmation.
431 */
433
434 /**
435 * \brief Number of NS retransmission.
436 */
438 };
439
440 protected:
441 /**
442 * \brief Dispose this object.
443 */
444 void DoDispose() override;
445
446 /**
447 * \brief Neighbor Discovery Cache container
448 */
449 typedef std::map<Ipv6Address, NdiscCache::Entry*> Cache;
450 /**
451 * \brief Neighbor Discovery Cache container iterator
452 */
453 typedef std::map<Ipv6Address, NdiscCache::Entry*>::iterator CacheI;
454
455 /**
456 * \brief A list of Entry.
457 */
459
460 private:
461 /**
462 * \brief The NetDevice.
463 */
465
466 /**
467 * \brief the interface.
468 */
470
471 /**
472 * \brief the icmpv6 L4 protocol for this cache.
473 */
475
476 /**
477 * \brief Max number of packet stored in m_waiting.
478 */
480};
481
482/**
483 * \brief Stream insertion operator.
484 *
485 * \param os the reference to the output stream
486 * \param entry the NdiscCache::Entry
487 * \returns the reference to the output stream
488 */
489std::ostream& operator<<(std::ostream& os, const NdiscCache::Entry& entry);
490
491} /* namespace ns3 */
492
493#endif /* NDISC_CACHE_H */
a polymophic address class
Definition address.h:90
Describes an IPv6 address.
Packet header for IPv6.
Definition ipv6-header.h:24
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.
IPv6 Neighbor Discovery cache.
Definition ndisc-cache.h:38
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()
Flush the cache.
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.
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
A simple virtual Timer class.
Definition timer.h:67
a unique identifier for an interface.
Definition type-id.h:48
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