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
48class NdiscCache : public Object
49{
50 public:
51 class Entry;
52
57 static TypeId GetTypeId();
58
62 static const uint32_t DEFAULT_UNRES_QLEN = 3;
63
67 NdiscCache();
68
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
83
89
96
102 std::list<NdiscCache::Entry*> LookupInverse(Address dst);
103
109 virtual NdiscCache::Entry* Add(Ipv6Address to);
110
115 void Remove(NdiscCache::Entry* entry);
116
120 void Flush();
121
126 void SetUnresQlen(uint32_t unresQlen);
127
133
140 void SetDevice(Ptr<NetDevice> device,
141 Ptr<Ipv6Interface> interface,
142 Ptr<Icmpv6L4Protocol> icmpv6);
143
150
155
159 typedef std::pair<Ptr<Packet>, Ipv6Header> Ipv6PayloadHeaderPair;
160
166 class Entry
167 {
168 public:
173 Entry(NdiscCache* nd);
174
175 virtual ~Entry() = default;
176
181 {
189 };
190
195
201
207 std::list<Ipv6PayloadHeaderPair> MarkReachable(Address mac);
208
212 void MarkProbe();
213
219 std::list<Ipv6PayloadHeaderPair> MarkStale(Address mac);
220
224 void MarkStale();
225
229 void MarkReachable();
230
234 void MarkDelay();
235
239 void MarkPermanent();
240
246 void MarkAutoGenerated();
247
253
257 void ClearWaitingPacket();
258
263 bool IsStale() const;
264
269 bool IsReachable() const;
270
275 bool IsDelay() const;
276
281 bool IsIncomplete() const;
282
287 bool IsProbe() const;
288
293 bool IsPermanent() const;
294
299 bool IsAutoGenerated() const;
300
305 Address GetMacAddress() const;
306
311 void SetMacAddress(Address mac);
312
317 bool IsRouter() const;
318
323 void SetRouter(bool router);
324
330
334 void StartReachableTimer();
335
340
345
349 void StartProbeTimer();
350
354 void StartDelayTimer();
355
359 void StopNudTimer();
360
365
372
377
382
387 void SetIpv6Address(Ipv6Address ipv6Address);
388
394
400
406 void Print(std::ostream& os) const;
407
408 protected:
413
414 private:
419
424
428 std::list<Ipv6PayloadHeaderPair> m_waiting;
429
434
439
444
449 };
450
451 protected:
455 void DoDispose() override;
456
460 typedef std::map<Ipv6Address, NdiscCache::Entry*> Cache;
464 typedef std::map<Ipv6Address, NdiscCache::Entry*>::iterator CacheI;
465
470
471 private:
476
481
486
491};
492
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:100
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:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
A simple virtual Timer class.
Definition: timer.h:74
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:129