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 class Ipv6Header;
42 class Icmpv6L4Protocol;
43 
49 class NdiscCache : public Object
50 {
51 public:
52  class Entry;
53 
58  static TypeId GetTypeId ();
59 
63  static const uint32_t DEFAULT_UNRES_QLEN = 3;
64 
68  NdiscCache ();
69 
73  ~NdiscCache ();
74 
79  Ptr<NetDevice> GetDevice () const;
80 
86 
93 
99  std::list<NdiscCache::Entry*> LookupInverse (Address dst);
100 
107 
112  void Remove (NdiscCache::Entry* entry);
113 
117  void Flush ();
118 
123  void SetUnresQlen (uint32_t unresQlen);
124 
129  uint32_t GetUnresQlen ();
130 
137  void SetDevice (Ptr<NetDevice> device, Ptr<Ipv6Interface> interface, Ptr<Icmpv6L4Protocol> icmpv6);
138 
145 
149  typedef std::pair<Ptr<Packet>, Ipv6Header> Ipv6PayloadHeaderPair;
150 
156  class Entry
157  {
158 public:
163  Entry (NdiscCache* nd);
164 
170 
176  std::list<Ipv6PayloadHeaderPair> MarkReachable (Address mac);
177 
181  void MarkProbe ();
182 
188  std::list<Ipv6PayloadHeaderPair> MarkStale (Address mac);
189 
193  void MarkStale ();
194 
198  void MarkReachable ();
199 
203  void MarkDelay ();
204 
208  void MarkPermanent ();
209 
215 
219  void ClearWaitingPacket ();
220 
225  bool IsStale () const;
226 
231  bool IsReachable () const;
232 
237  bool IsDelay () const;
238 
243  bool IsIncomplete () const;
244 
249  bool IsProbe () const;
250 
255  bool IsPermanent () const;
256 
261  Address GetMacAddress () const;
262 
267  void SetMacAddress (Address mac);
268 
273  bool IsRouter () const;
274 
279  void SetRouter (bool router);
280 
286 
290  void StartReachableTimer ();
291 
295  void UpdateReachableTimer ();
296 
300  void StartRetransmitTimer ();
301 
305  void StartProbeTimer ();
306 
310  void StartDelayTimer ();
311 
315  void StopNudTimer ();
316 
320  void FunctionReachableTimeout ();
321 
328 
332  void FunctionProbeTimeout ();
333 
337  void FunctionDelayTimeout ();
338 
343  void SetIpv6Address (Ipv6Address ipv6Address);
344 
345 private:
350 
355  {
362  };
363 
368 
373 
378 
382  std::list<Ipv6PayloadHeaderPair> m_waiting;
383 
387  bool m_router;
388 
393 
398 
402  uint8_t m_nsRetransmit;
403  };
404 
405 private:
409  typedef sgi::hash_map<Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash> Cache;
413  typedef sgi::hash_map<Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash>::iterator CacheI;
414 
420  NdiscCache (NdiscCache const &);
421 
428  NdiscCache& operator= (NdiscCache const &);
429 
433  void DoDispose ();
434 
439 
444 
449 
454 
458  uint32_t m_unresQlen;
459 };
460 
461 } /* namespace ns3 */
462 
463 #endif /* NDISC_CACHE_H */
464 
Address GetMacAddress() const
Get the MAC address of this entry.
Definition: ndisc-cache.cc:586
void FunctionDelayTimeout()
Function called when delay timer timeout.
Definition: ndisc-cache.cc:325
static TypeId GetTypeId()
Get the type ID.
Definition: ndisc-cache.cc:38
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Packet header for IPv6.
Definition: ipv6-header.h:34
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
bool IsReachable() const
Is the entry REACHABLE.
Definition: ndisc-cache.cc:556
~NdiscCache()
Destructor.
Definition: ndisc-cache.cc:57
A simple Timer class.
Definition: timer.h:73
NdiscCache::Entry * Add(Ipv6Address to)
Add an entry.
Definition: ndisc-cache.cc:125
void SetUnresQlen(uint32_t unresQlen)
Set the max number of waiting packet.
Definition: ndisc-cache.cc:164
void StopNudTimer()
Stop NUD timer and reset the NUD retransmission counter.
Definition: ndisc-cache.cc:485
Ipv6Address m_ipv6Address
The IPv6 address.
Definition: ndisc-cache.h:349
uint8_t m_nsRetransmit
Number of NS retransmission.
Definition: ndisc-cache.h:402
Ptr< Icmpv6L4Protocol > m_icmpv6
the icmpv6 L4 protocol for this cache.
Definition: ndisc-cache.h:448
bool IsIncomplete() const
Is the entry INCOMPLETE.
Definition: ndisc-cache.cc:568
Mapping is stale.
Definition: ndisc-cache.h:358
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv6Interface > interface, Ptr< Icmpv6L4Protocol > icmpv6)
Set the device and interface.
Definition: ndisc-cache.cc:73
Time GetLastReachabilityConfirmation() const
Get the time of last reachability confirmation.
Definition: ndisc-cache.cc:411
NdiscCacheEntryState_e m_state
The state of the entry.
Definition: ndisc-cache.h:367
void MarkPermanent()
Change the state to this entry to PERMANENT.
Definition: ndisc-cache.cc:543
Try to wait contact from remote host.
Definition: ndisc-cache.h:359
a polymophic address class
Definition: address.h:90
uint32_t GetUnresQlen()
Get the max number of waiting packet.
Definition: ndisc-cache.cc:170
Ptr< NetDevice > GetDevice() const
Get the NetDevice associated with this cache.
Definition: ndisc-cache.cc:87
Address m_macAddress
The MAC address.
Definition: ndisc-cache.h:377
Ptr< Ipv6Interface > m_interface
the interface.
Definition: ndisc-cache.h:443
sgi::hash_map< Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash > Cache
Neighbor Discovery Cache container.
Definition: ndisc-cache.h:409
NdiscCacheEntryState_e
The Entry state enumeration.
Definition: ndisc-cache.h:354
void FunctionRetransmitTimeout()
Function called when retransmit timer timeout.
Definition: ndisc-cache.cc:276
void MarkReachable()
Changes the state to this entry to REACHABLE.
Definition: ndisc-cache.cc:523
bool m_router
Type of node (router or host).
Definition: ndisc-cache.h:387
void Flush()
Flush the cache.
Definition: ndisc-cache.cc:152
mac
Definition: third.py:92
IPv6 Neighbor Discovery cache.
Definition: ndisc-cache.h:49
Ptr< Ipv6Interface > GetInterface() const
Get the Ipv6Interface associated with this cache.
Definition: ndisc-cache.cc:81
void PrintNdiscCache(Ptr< OutputStreamWrapper > stream)
Print the NDISC cache entries.
Definition: ndisc-cache.cc:176
Mapping exists between IPv6 and L2 addresses.
Definition: ndisc-cache.h:357
NdiscCache()
Constructor.
Definition: ndisc-cache.cc:52
void StartRetransmitTimer()
Start retransmit timer.
Definition: ndisc-cache.cc:472
void ClearWaitingPacket()
Clear the waiting packet list.
Definition: ndisc-cache.cc:263
Entry(NdiscCache *nd)
Constructor.
Definition: ndisc-cache.cc:227
bool IsStale() const
Is the entry STALE.
Definition: ndisc-cache.cc:550
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void StartDelayTimer()
Start delay timer.
Definition: ndisc-cache.cc:459
bool IsRouter() const
If the entry is a host or a router.
Definition: ndisc-cache.cc:244
void StartReachableTimer()
Start the reachable timer.
Definition: ndisc-cache.cc:417
void FunctionReachableTimeout()
Function called when reachable timer timeout.
Definition: ndisc-cache.cc:270
NdiscCache & operator=(NdiscCache const &)
Copy constructor.
void StartProbeTimer()
Start probe timer.
Definition: ndisc-cache.cc:446
No mapping between IPv6 and L2 addresses.
Definition: ndisc-cache.h:356
static const uint32_t DEFAULT_UNRES_QLEN
Default value for unres qlen.
Definition: ndisc-cache.h:63
void Remove(NdiscCache::Entry *entry)
Delete an entry.
Definition: ndisc-cache.cc:136
void FunctionProbeTimeout()
Function called when probe timer timeout.
Definition: ndisc-cache.cc:360
uint32_t m_unresQlen
Max number of packet stored in m_waiting.
Definition: ndisc-cache.h:458
void UpdateReachableTimer()
Update the reachable timer.
Definition: ndisc-cache.cc:431
std::list< NdiscCache::Entry * > LookupInverse(Address dst)
Lookup in the cache for a MAC address.
Definition: ndisc-cache.cc:107
void SetMacAddress(Address mac)
Set the MAC address of this entry.
Definition: ndisc-cache.cc:592
Time m_lastReachabilityConfirmation
Last time we see a reachability confirmation.
Definition: ndisc-cache.h:397
Describes an IPv6 address.
Definition: ipv6-address.h:49
bool IsProbe() const
Is the entry PROBE.
Definition: ndisc-cache.cc:574
Permanent Mapping exists between IPv6 and L2 addresses.
Definition: ndisc-cache.h:361
NdiscCache::Entry * Lookup(Ipv6Address dst)
Lookup in the cache.
Definition: ndisc-cache.cc:93
void MarkStale()
Changes the state to this entry to STALE.
Definition: ndisc-cache.cc:517
void DoDispose()
Dispose this object.
Definition: ndisc-cache.cc:63
void SetIpv6Address(Ipv6Address ipv6Address)
Set the IPv6 address.
Definition: ndisc-cache.cc:405
void MarkDelay()
Change the state to this entry to DELAY.
Definition: ndisc-cache.cc:537
NdiscCache * m_ndCache
the NdiscCache associated.
Definition: ndisc-cache.h:372
void MarkIncomplete(Ipv6PayloadHeaderPair p)
Changes the state to this entry to INCOMPLETE.
Definition: ndisc-cache.cc:492
Cache m_ndCache
A list of Entry.
Definition: ndisc-cache.h:453
std::list< Ipv6PayloadHeaderPair > m_waiting
The list of packet waiting.
Definition: ndisc-cache.h:382
A record that holds information about a NdiscCache entry.
Definition: ndisc-cache.h:156
Timer m_nudTimer
Timer (used for NUD).
Definition: ndisc-cache.h:392
void SetRouter(bool router)
Set the node type.
Definition: ndisc-cache.cc:238
Try to contact IPv6 address to know again its L2 address.
Definition: ndisc-cache.h:360
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:413
std::pair< Ptr< Packet >, Ipv6Header > Ipv6PayloadHeaderPair
Pair of a packet and an Ipv4 header.
Definition: ndisc-cache.h:149
bool IsDelay() const
Is the entry DELAY.
Definition: ndisc-cache.cc:562
bool IsPermanent() const
Is the entry PERMANENT.
Definition: ndisc-cache.cc:580
a unique identifier for an interface.
Definition: type-id.h:58
void AddWaitingPacket(Ipv6PayloadHeaderPair p)
Add a packet (or replace old value) in the queue.
Definition: ndisc-cache.cc:250
void MarkProbe()
Changes the state to this entry to PROBE.
Definition: ndisc-cache.cc:511
Ptr< NetDevice > m_device
The NetDevice.
Definition: ndisc-cache.h:438