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