A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ndisc-cache.h
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 
26 #include <list>
27 
28 #include "ns3/packet.h"
29 #include "ns3/nstime.h"
30 #include "ns3/net-device.h"
31 #include "ns3/ipv6-address.h"
32 #include "ns3/ptr.h"
33 #include "ns3/timer.h"
34 #include "ns3/sgi-hashmap.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 
131  class Entry
132  {
133 public:
138  Entry (NdiscCache* nd);
139 
144  void MarkIncomplete (Ptr<Packet> p);
145 
151  std::list<Ptr<Packet> > MarkReachable (Address mac);
152 
156  void MarkProbe ();
157 
163  std::list<Ptr<Packet> > MarkStale (Address mac);
164 
168  void MarkStale ();
169 
173  void MarkReachable ();
174 
178  void MarkDelay ();
179 
184  void AddWaitingPacket (Ptr<Packet> p);
185 
189  void ClearWaitingPacket ();
190 
195  bool IsStale () const;
196 
201  bool IsReachable () const;
202 
207  bool IsDelay () const;
208 
213  bool IsIncomplete () const;
214 
219  bool IsProbe () const;
220 
225  Address GetMacAddress () const;
226 
231  void SetMacAddress (Address mac);
232 
237  bool IsRouter () const;
238 
243  void SetRouter (bool router);
244 
249  uint8_t GetNSRetransmit () const;
250 
254  void IncNSRetransmit ();
255 
259  void ResetNSRetransmit ();
260 
266 
271 
275  void StartReachableTimer ();
276 
280  void StopReachableTimer ();
281 
285  void StartRetransmitTimer ();
286 
290  void StopRetransmitTimer ();
291 
295  void StartProbeTimer ();
296 
300  void StopProbeTimer ();
301 
305  void StartDelayTimer ();
306 
310  void StopDelayTimer ();
311 
315  void FunctionReachableTimeout ();
316 
323 
327  void FunctionProbeTimeout ();
328 
332  void FunctionDelayTimeout ();
333 
338  void SetIpv6Address (Ipv6Address ipv6Address);
339 
340 private:
345 
350  {
356  };
357 
362 
367 
372 
376  std::list<Ptr<Packet> > m_waiting;
377 
381  bool m_router;
382 
387 
392 
397 
402 
407 
411  uint8_t m_nsRetransmit;
412  };
413 
414 private:
415  typedef sgi::hash_map<Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash> Cache;
416  typedef sgi::hash_map<Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash>::iterator CacheI;
417 
422  NdiscCache (NdiscCache const &a);
423 
428  NdiscCache& operator= (NdiscCache const &a);
429 
433  void DoDispose ();
434 
439 
444 
448  Cache m_ndCache;
449 
453  uint32_t m_unresQlen;
454 };
455 
456 } /* namespace ns3 */
457 
458 #endif /* NDISC_CACHE_H */
459 
void FunctionDelayTimeout()
Function called when delay timer timeout.
Definition: ndisc-cache.cc:250
Timer m_probeTimer
Probe timer (used for NUD in PROBE state).
Definition: ndisc-cache.h:396
static TypeId GetTypeId()
Get the type ID.
Definition: ndisc-cache.cc:37
keep track of time unit.
Definition: nstime.h:149
NdiscCache & operator=(NdiscCache const &a)
Equal operator.
Time GetLastReachabilityConfirmation() const
Get the time of last reachability confirmation.
Definition: ndisc-cache.cc:356
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
void MarkIncomplete(Ptr< Packet > p)
Changes the state to this entry to INCOMPLETE.
Definition: ndisc-cache.cc:427
~NdiscCache()
Destructor.
Definition: ndisc-cache.cc:55
a simple Timer class
Definition: timer.h:45
Address GetMacAddress() const
Get the MAC address of this entry.
Definition: ndisc-cache.cc:508
NdiscCache::Entry * Add(Ipv6Address to)
Add an entry.
Definition: ndisc-cache.cc:101
void SetUnresQlen(uint32_t unresQlen)
Set the max number of waiting packet.
Definition: ndisc-cache.cc:140
Ipv6Address m_ipv6Address
The IPv6 address.
Definition: ndisc-cache.h:344
uint8_t m_nsRetransmit
Number of NS retransmission.
Definition: ndisc-cache.h:411
Definition: ndisc-cache.h:353
void StopReachableTimer()
Stop the reachable timer.
Definition: ndisc-cache.cc:375
Timer m_delayTimer
Delay timer (used for NUD when in DELAY state).
Definition: ndisc-cache.h:401
NdiscCacheEntryState_e m_state
The state of the entry.
Definition: ndisc-cache.h:361
Definition: ndisc-cache.h:354
a polymophic address class
Definition: address.h:86
uint32_t GetUnresQlen()
Get the max number of waiting packet.
Definition: ndisc-cache.cc:146
Address m_macAddress
The MAC address.
Definition: ndisc-cache.h:371
Ptr< Ipv6Interface > GetInterface() const
Get the Ipv6Interface associated with this cache.
Definition: ndisc-cache.cc:77
bool IsDelay() const
Is the entry DELAY.
Definition: ndisc-cache.cc:490
Ptr< Ipv6Interface > m_interface
the interface.
Definition: ndisc-cache.h:443
NdiscCacheEntryState_e
The Entry state enumeration.
Definition: ndisc-cache.h:349
void FunctionRetransmitTimeout()
Function called when retransmit timer timeout. It verify that the NS retransmit has reached the max s...
Definition: ndisc-cache.cc:204
void MarkReachable()
Changes the state to this entry to REACHABLE.
Definition: ndisc-cache.cc:458
bool m_router
Type of node (router or host).
Definition: ndisc-cache.h:381
void Flush()
Flush the cache.
Definition: ndisc-cache.cc:128
IPv6 Neighbor Discovery cache.
Definition: ndisc-cache.h:46
Timer m_retransTimer
Retransmission timer (used for NUD in INCOMPLETE state).
Definition: ndisc-cache.h:391
Definition: ndisc-cache.h:352
void StopProbeTimer()
Stop probe timer.
Definition: ndisc-cache.cc:389
NdiscCache()
Constructor.
Definition: ndisc-cache.cc:50
void StartRetransmitTimer()
Start retransmit timer.
Definition: ndisc-cache.cc:412
void ClearWaitingPacket()
Clear the waiting packet list.
Definition: ndisc-cache.cc:191
Entry(NdiscCache *nd)
Constructor.
Definition: ndisc-cache.cc:152
bool IsProbe() const
Is the entry PROBE.
Definition: ndisc-cache.cc:502
void AddWaitingPacket(Ptr< Packet > p)
Add a packet (or replace old value) in the queue.
Definition: ndisc-cache.cc:178
void StartDelayTimer()
Start delay timer.
Definition: ndisc-cache.cc:397
void StartReachableTimer()
Start the reachable timer.
Definition: ndisc-cache.cc:367
bool IsIncomplete() const
Is the entry INCOMPLETE.
Definition: ndisc-cache.cc:496
void FunctionReachableTimeout()
Function called when reachable timer timeout.
Definition: ndisc-cache.cc:198
void StartProbeTimer()
Start probe timer.
Definition: ndisc-cache.cc:381
Definition: ndisc-cache.h:351
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:112
void FunctionProbeTimeout()
Function called when probe timer timeout.
Definition: ndisc-cache.cc:287
uint32_t m_unresQlen
Max number of packet stored in m_waiting.
Definition: ndisc-cache.h:453
void SetMacAddress(Address mac)
Set the MAC address of this entry.
Definition: ndisc-cache.cc:514
Time m_lastReachabilityConfirmation
Last time we see a reachability confirmation.
Definition: ndisc-cache.h:406
Describes an IPv6 address.
Definition: ipv6-address.h:44
NdiscCache::Entry * Lookup(Ipv6Address dst)
Lookup in the cache.
Definition: ndisc-cache.cc:89
void MarkStale()
Changes the state to this entry to STALE.
Definition: ndisc-cache.cc:452
void IncNSRetransmit()
Increment NS retransmit.
Definition: ndisc-cache.cc:344
void DoDispose()
Dispose this object.
Definition: ndisc-cache.cc:61
void SetIpv6Address(Ipv6Address ipv6Address)
Set the IPv6 address.
Definition: ndisc-cache.cc:332
void MarkDelay()
Change the state to this entry to DELAY.
Definition: ndisc-cache.cc:472
NdiscCache * m_ndCache
the NdiscCache associated.
Definition: ndisc-cache.h:366
void StopRetransmitTimer()
Stop retransmit timer.
Definition: ndisc-cache.cc:420
void UpdateLastReachabilityconfirmation()
Update the time of last reachability confirmation.
Definition: ndisc-cache.cc:362
void StopDelayTimer()
Stop delay timer.
Definition: ndisc-cache.cc:405
bool IsRouter() const
If the entry is a host or a router.
Definition: ndisc-cache.cc:172
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv6Interface > interface)
Set the device and interface.
Definition: ndisc-cache.cc:70
Cache m_ndCache
A list of Entry.
Definition: ndisc-cache.h:448
A record that holds information about an NdiscCache entry.
Definition: ndisc-cache.h:131
void SetRouter(bool router)
Set the node type.
Definition: ndisc-cache.cc:166
Definition: ndisc-cache.h:355
a base class which provides memory management and object aggregation
Definition: object.h:63
Timer m_reachableTimer
Reachable timer (used for NUD in REACHABLE state).
Definition: ndisc-cache.h:386
bool IsReachable() const
Is the entry REACHABLE.
Definition: ndisc-cache.cc:484
a unique identifier for an interface.
Definition: type-id.h:44
void ResetNSRetransmit()
Reset NS retransmit (=0).
Definition: ndisc-cache.cc:350
Ptr< NetDevice > GetDevice() const
Get the NetDevice associated with this cache.
Definition: ndisc-cache.cc:83
void MarkProbe()
Changes the state to this entry to PROBE.
Definition: ndisc-cache.cc:446
bool IsStale() const
Is the entry STALE.
Definition: ndisc-cache.cc:478
std::list< Ptr< Packet > > m_waiting
The list of packet waiting.
Definition: ndisc-cache.h:376
Ptr< NetDevice > m_device
The NetDevice.
Definition: ndisc-cache.h:438
uint8_t GetNSRetransmit() const
Get the number of NS retransmit.
Definition: ndisc-cache.cc:338