A Discrete-Event Network Simulator
API
ndisc-cache.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007-2009 Strasbourg University
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  */
20 
21 #ifndef NDISC_CACHE_H
22 #define NDISC_CACHE_H
23 
24 #include <stdint.h>
25 #include <list>
26 
27 #include "ns3/packet.h"
28 #include "ns3/nstime.h"
29 #include "ns3/net-device.h"
30 #include "ns3/ipv6-address.h"
31 #include "ns3/ptr.h"
32 #include "ns3/timer.h"
33 #include "ns3/sgi-hashmap.h"
34 #include "ns3/output-stream-wrapper.h"
35 
36 namespace ns3
37 {
38 
39 class NetDevice;
40 class Ipv6Interface;
41 
46 class NdiscCache : public Object
47 {
48 public:
49  class Entry;
50 
55  static TypeId GetTypeId ();
56 
60  static const uint32_t DEFAULT_UNRES_QLEN = 3;
61 
65  NdiscCache ();
66 
70  ~NdiscCache ();
71 
76  Ptr<NetDevice> GetDevice () const;
77 
82 
89 
96 
101  void Remove (NdiscCache::Entry* entry);
102 
106  void Flush ();
107 
112  void SetUnresQlen (uint32_t unresQlen);
113 
118  uint32_t GetUnresQlen ();
119 
125  void SetDevice (Ptr<NetDevice> device, Ptr<Ipv6Interface> interface);
126 
133 
138  class Entry
139  {
140 public:
145  Entry (NdiscCache* nd);
146 
151  void MarkIncomplete (Ptr<Packet> p);
152 
158  std::list<Ptr<Packet> > MarkReachable (Address mac);
159 
163  void MarkProbe ();
164 
170  std::list<Ptr<Packet> > MarkStale (Address mac);
171 
175  void MarkStale ();
176 
180  void MarkReachable ();
181 
185  void MarkDelay ();
186 
191  void AddWaitingPacket (Ptr<Packet> p);
192 
196  void ClearWaitingPacket ();
197 
202  bool IsStale () const;
203 
208  bool IsReachable () const;
209 
214  bool IsDelay () const;
215 
220  bool IsIncomplete () const;
221 
226  bool IsProbe () const;
227 
232  Address GetMacAddress () const;
233 
238  void SetMacAddress (Address mac);
239 
244  bool IsRouter () const;
245 
250  void SetRouter (bool router);
251 
256  uint8_t GetNSRetransmit () const;
257 
261  void IncNSRetransmit ();
262 
266  void ResetNSRetransmit ();
267 
273 
278 
282  void StartReachableTimer ();
283 
287  void StopReachableTimer ();
288 
292  void StartRetransmitTimer ();
293 
297  void StopRetransmitTimer ();
298 
302  void StartProbeTimer ();
303 
307  void StopProbeTimer ();
308 
312  void StartDelayTimer ();
313 
317  void StopDelayTimer ();
318 
322  void FunctionReachableTimeout ();
323 
330 
334  void FunctionProbeTimeout ();
335 
339  void FunctionDelayTimeout ();
340 
345  void SetIpv6Address (Ipv6Address ipv6Address);
346 
347 private:
352 
357  {
363  };
364 
369 
374 
379 
383  std::list<Ptr<Packet> > m_waiting;
384 
388  bool m_router;
389 
394 
399 
404 
409 
414 
418  uint8_t m_nsRetransmit;
419  };
420 
421 private:
425  typedef sgi::hash_map<Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash> Cache;
429  typedef sgi::hash_map<Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash>::iterator CacheI;
430 
436  NdiscCache (NdiscCache const &);
437 
444  NdiscCache& operator= (NdiscCache const &);
445 
449  void DoDispose ();
450 
455 
460 
464  Cache m_ndCache;
465 
469  uint32_t m_unresQlen;
470 };
471 
472 } /* namespace ns3 */
473 
474 #endif /* NDISC_CACHE_H */
475 
void FunctionDelayTimeout()
Function called when delay timer timeout.
Definition: ndisc-cache.cc:294
Timer m_probeTimer
Probe timer (used for NUD in PROBE state).
Definition: ndisc-cache.h:403
static TypeId GetTypeId()
Get the type ID.
Definition: ndisc-cache.cc:38
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
Time GetLastReachabilityConfirmation() const
Get the time of last reachability confirmation.
Definition: ndisc-cache.cc:400
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void MarkIncomplete(Ptr< Packet > p)
Changes the state to this entry to INCOMPLETE.
Definition: ndisc-cache.cc:487
~NdiscCache()
Destructor.
Definition: ndisc-cache.cc:56
A simple Timer class.
Definition: timer.h:73
Address GetMacAddress() const
Get the MAC address of this entry.
Definition: ndisc-cache.cc:568
NdiscCache::Entry * Add(Ipv6Address to)
Add an entry.
Definition: ndisc-cache.cc:102
void SetUnresQlen(uint32_t unresQlen)
Set the max number of waiting packet.
Definition: ndisc-cache.cc:141
Ipv6Address m_ipv6Address
The IPv6 address.
Definition: ndisc-cache.h:351
uint8_t m_nsRetransmit
Number of NS retransmission.
Definition: ndisc-cache.h:418
Mapping is stale.
Definition: ndisc-cache.h:360
void StopReachableTimer()
Stop the reachable timer.
Definition: ndisc-cache.cc:423
Timer m_delayTimer
Delay timer (used for NUD when in DELAY state).
Definition: ndisc-cache.h:408
NdiscCacheEntryState_e m_state
The state of the entry.
Definition: ndisc-cache.h:368
Try to wait contact from remote host.
Definition: ndisc-cache.h:361
a polymophic address class
Definition: address.h:90
uint32_t GetUnresQlen()
Get the max number of waiting packet.
Definition: ndisc-cache.cc:147
Address m_macAddress
The MAC address.
Definition: ndisc-cache.h:378
Ptr< Ipv6Interface > GetInterface() const
Get the Ipv6Interface associated with this cache.
Definition: ndisc-cache.cc:78
bool IsDelay() const
Is the entry DELAY.
Definition: ndisc-cache.cc:550
Ptr< Ipv6Interface > m_interface
the interface.
Definition: ndisc-cache.h:459
sgi::hash_map< Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash > Cache
Neighbor Discovery Cache container.
Definition: ndisc-cache.h:425
NdiscCacheEntryState_e
The Entry state enumeration.
Definition: ndisc-cache.h:356
void FunctionRetransmitTimeout()
Function called when retransmit timer timeout.
Definition: ndisc-cache.cc:248
void MarkReachable()
Changes the state to this entry to REACHABLE.
Definition: ndisc-cache.cc:518
bool m_router
Type of node (router or host).
Definition: ndisc-cache.h:388
void Flush()
Flush the cache.
Definition: ndisc-cache.cc:129
Introspection did not find any typical Config paths.
Definition: ndisc-cache.h:46
Timer m_retransTimer
Retransmission timer (used for NUD in INCOMPLETE state).
Definition: ndisc-cache.h:398
void PrintNdiscCache(Ptr< OutputStreamWrapper > stream)
Print the NDISC cache entries.
Definition: ndisc-cache.cc:153
Mapping exists between IPv6 and L2 addresses.
Definition: ndisc-cache.h:359
void StopProbeTimer()
Stop probe timer.
Definition: ndisc-cache.cc:441
NdiscCache()
Constructor.
Definition: ndisc-cache.cc:51
void StartRetransmitTimer()
Start retransmit timer.
Definition: ndisc-cache.cc:468
void ClearWaitingPacket()
Clear the waiting packet list.
Definition: ndisc-cache.cc:235
Entry(NdiscCache *nd)
Constructor.
Definition: ndisc-cache.cc:196
bool IsProbe() const
Is the entry PROBE.
Definition: ndisc-cache.cc:562
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void AddWaitingPacket(Ptr< Packet > p)
Add a packet (or replace old value) in the queue.
Definition: ndisc-cache.cc:222
void StartDelayTimer()
Start delay timer.
Definition: ndisc-cache.cc:449
void StartReachableTimer()
Start the reachable timer.
Definition: ndisc-cache.cc:411
bool IsIncomplete() const
Is the entry INCOMPLETE.
Definition: ndisc-cache.cc:556
void FunctionReachableTimeout()
Function called when reachable timer timeout.
Definition: ndisc-cache.cc:242
NdiscCache & operator=(NdiscCache const &)
Copy constructor.
void StartProbeTimer()
Start probe timer.
Definition: ndisc-cache.cc:429
No mapping between IPv6 and L2 addresses.
Definition: ndisc-cache.h:358
static const uint32_t DEFAULT_UNRES_QLEN
Default value for unres qlen.
Definition: ndisc-cache.h:60
void Remove(NdiscCache::Entry *entry)
Delete an entry.
Definition: ndisc-cache.cc:113
void FunctionProbeTimeout()
Function called when probe timer timeout.
Definition: ndisc-cache.cc:331
uint32_t m_unresQlen
Max number of packet stored in m_waiting.
Definition: ndisc-cache.h:469
void SetMacAddress(Address mac)
Set the MAC address of this entry.
Definition: ndisc-cache.cc:574
Time m_lastReachabilityConfirmation
Last time we see a reachability confirmation.
Definition: ndisc-cache.h:413
Describes an IPv6 address.
Definition: ipv6-address.h:47
NdiscCache::Entry * Lookup(Ipv6Address dst)
Lookup in the cache.
Definition: ndisc-cache.cc:90
void MarkStale()
Changes the state to this entry to STALE.
Definition: ndisc-cache.cc:512
void IncNSRetransmit()
Increment NS retransmit.
Definition: ndisc-cache.cc:388
void DoDispose()
Dispose this object.
Definition: ndisc-cache.cc:62
void SetIpv6Address(Ipv6Address ipv6Address)
Set the IPv6 address.
Definition: ndisc-cache.cc:376
void MarkDelay()
Change the state to this entry to DELAY.
Definition: ndisc-cache.cc:532
NdiscCache * m_ndCache
the NdiscCache associated.
Definition: ndisc-cache.h:373
void StopRetransmitTimer()
Stop retransmit timer.
Definition: ndisc-cache.cc:480
void UpdateLastReachabilityconfirmation()
Update the time of last reachability confirmation.
Definition: ndisc-cache.cc:406
void StopDelayTimer()
Stop delay timer.
Definition: ndisc-cache.cc:461
bool IsRouter() const
If the entry is a host or a router.
Definition: ndisc-cache.cc:216
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv6Interface > interface)
Set the device and interface.
Definition: ndisc-cache.cc:71
Cache m_ndCache
A list of Entry.
Definition: ndisc-cache.h:464
A record that holds information about an NdiscCache entry.
Definition: ndisc-cache.h:138
void SetRouter(bool router)
Set the node type.
Definition: ndisc-cache.cc:210
Try to contact IPv6 address to know again its L2 address.
Definition: ndisc-cache.h:362
A base class which provides memory management and object aggregation.
Definition: object.h:87
sgi::hash_map< Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash >::iterator CacheI
Neighbor Discovery Cache container iterator.
Definition: ndisc-cache.h:429
Timer m_reachableTimer
Reachable timer (used for NUD in REACHABLE state).
Definition: ndisc-cache.h:393
bool IsReachable() const
Is the entry REACHABLE.
Definition: ndisc-cache.cc:544
a unique identifier for an interface.
Definition: type-id.h:51
void ResetNSRetransmit()
Reset NS retransmit (=0).
Definition: ndisc-cache.cc:394
Ptr< NetDevice > GetDevice() const
Get the NetDevice associated with this cache.
Definition: ndisc-cache.cc:84
void MarkProbe()
Changes the state to this entry to PROBE.
Definition: ndisc-cache.cc:506
bool IsStale() const
Is the entry STALE.
Definition: ndisc-cache.cc:538
std::list< Ptr< Packet > > m_waiting
The list of packet waiting.
Definition: ndisc-cache.h:383
Ptr< NetDevice > m_device
The NetDevice.
Definition: ndisc-cache.h:454
uint8_t GetNSRetransmit() const
Get the number of NS retransmit.
Definition: ndisc-cache.cc:382