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 #include <unordered_map>
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/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 
75  // Delete default and copy constructor, and assignment operator to avoid misuse
76  NdiscCache (NdiscCache const &) = delete;
77  NdiscCache & operator = (NdiscCache const &) = delete;
78 
83  Ptr<NetDevice> GetDevice () const;
84 
90 
96  virtual NdiscCache::Entry* Lookup (Ipv6Address dst);
97 
103  std::list<NdiscCache::Entry*> LookupInverse (Address dst);
104 
110  virtual NdiscCache::Entry* Add (Ipv6Address to);
111 
116  void Remove (NdiscCache::Entry* entry);
117 
121  void Flush ();
122 
127  void SetUnresQlen (uint32_t unresQlen);
128 
133  uint32_t GetUnresQlen ();
134 
141  void SetDevice (Ptr<NetDevice> device, Ptr<Ipv6Interface> interface, Ptr<Icmpv6L4Protocol> icmpv6);
142 
149 
153  typedef std::pair<Ptr<Packet>, Ipv6Header> Ipv6PayloadHeaderPair;
154 
160  class Entry
161  {
162 public:
167  Entry (NdiscCache* nd);
168 
169  virtual ~Entry() = default;
170 
176 
182  std::list<Ipv6PayloadHeaderPair> MarkReachable (Address mac);
183 
187  void MarkProbe ();
188 
194  std::list<Ipv6PayloadHeaderPair> MarkStale (Address mac);
195 
199  void MarkStale ();
200 
204  void MarkReachable ();
205 
209  void MarkDelay ();
210 
214  void MarkPermanent ();
215 
221 
225  void ClearWaitingPacket ();
226 
231  bool IsStale () const;
232 
237  bool IsReachable () const;
238 
243  bool IsDelay () const;
244 
249  bool IsIncomplete () const;
250 
255  bool IsProbe () const;
256 
261  bool IsPermanent () const;
262 
267  Address GetMacAddress () const;
268 
273  void SetMacAddress (Address mac);
274 
279  bool IsRouter () const;
280 
285  void SetRouter (bool router);
286 
292 
296  void StartReachableTimer ();
297 
301  void UpdateReachableTimer ();
302 
306  void StartRetransmitTimer ();
307 
311  void StartProbeTimer ();
312 
316  void StartDelayTimer ();
317 
321  void StopNudTimer ();
322 
326  void FunctionReachableTimeout ();
327 
334 
338  void FunctionProbeTimeout ();
339 
343  void FunctionDelayTimeout ();
344 
349  void SetIpv6Address (Ipv6Address ipv6Address);
350 
355  Ipv6Address GetIpv6Address (void) const;
356 
362  void Print (std::ostream &os) const;
363 
364 protected:
369 
370 private:
375 
380  {
386  PERMANENT
387  };
388 
393 
398 
402  std::list<Ipv6PayloadHeaderPair> m_waiting;
403 
407  bool m_router;
408 
413 
418 
422  uint8_t m_nsRetransmit;
423  };
424 
425 protected:
429  void DoDispose ();
430 
434  typedef std::unordered_map<Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash> Cache;
438  typedef std::unordered_map<Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash>::iterator CacheI;
439 
444 
445 private:
450 
455 
460 
464  uint32_t m_unresQlen;
465 };
466 
474 std::ostream & operator << (std::ostream& os, NdiscCache::Entry const& entry);
475 
476 
477 } /* namespace ns3 */
478 
479 #endif /* NDISC_CACHE_H */
480 
a polymophic address class
Definition: address.h:91
Describes an IPv6 address.
Definition: ipv6-address.h:50
Packet header for IPv6.
Definition: ipv6-header.h:36
A record that holds information about a NdiscCache entry.
Definition: ndisc-cache.h:161
bool m_router
Type of node (router or host).
Definition: ndisc-cache.h:407
virtual ~Entry()=default
void MarkProbe()
Changes the state to this entry to PROBE.
Definition: ndisc-cache.cc:518
bool IsPermanent() const
Is the entry PERMANENT.
Definition: ndisc-cache.cc:587
void MarkPermanent()
Change the state to this entry to PERMANENT.
Definition: ndisc-cache.cc:550
NdiscCacheEntryState_e m_state
The state of the entry.
Definition: ndisc-cache.h:392
NdiscCacheEntryState_e
The Entry state enumeration.
Definition: ndisc-cache.h:380
@ PROBE
Try to contact IPv6 address to know again its L2 address.
Definition: ndisc-cache.h:385
@ STALE
Mapping is stale.
Definition: ndisc-cache.h:383
@ REACHABLE
Mapping exists between IPv6 and L2 addresses.
Definition: ndisc-cache.h:382
@ PERMANENT
Permanent Mapping exists between IPv6 and L2 addresses.
Definition: ndisc-cache.h:386
@ DELAY
Try to wait contact from remote host.
Definition: ndisc-cache.h:384
@ INCOMPLETE
No mapping between IPv6 and L2 addresses.
Definition: ndisc-cache.h:381
void ClearWaitingPacket()
Clear the waiting packet list.
Definition: ndisc-cache.cc:264
void StartProbeTimer()
Start probe timer.
Definition: ndisc-cache.cc:453
Ipv6Address m_ipv6Address
The IPv6 address.
Definition: ndisc-cache.h:374
void MarkReachable()
Changes the state to this entry to REACHABLE.
Definition: ndisc-cache.cc:530
void StartReachableTimer()
Start the reachable timer.
Definition: ndisc-cache.cc:424
void Print(std::ostream &os) const
Print this entry to the given output stream.
Definition: ndisc-cache.cc:605
void UpdateReachableTimer()
Update the reachable timer.
Definition: ndisc-cache.cc:438
uint8_t m_nsRetransmit
Number of NS retransmission.
Definition: ndisc-cache.h:422
void FunctionProbeTimeout()
Function called when probe timer timeout.
Definition: ndisc-cache.cc:361
void MarkStale()
Changes the state to this entry to STALE.
Definition: ndisc-cache.cc:524
std::list< Ipv6PayloadHeaderPair > m_waiting
The list of packet waiting.
Definition: ndisc-cache.h:402
Time m_lastReachabilityConfirmation
Last time we see a reachability confirmation.
Definition: ndisc-cache.h:417
Address GetMacAddress() const
Get the MAC address of this entry.
Definition: ndisc-cache.cc:593
Ipv6Address GetIpv6Address(void) const
Get the IPv6 address.
Definition: ndisc-cache.cc:412
void StartDelayTimer()
Start delay timer.
Definition: ndisc-cache.cc:466
bool IsIncomplete() const
Is the entry INCOMPLETE.
Definition: ndisc-cache.cc:575
Address m_macAddress
The MAC address.
Definition: ndisc-cache.h:397
void FunctionDelayTimeout()
Function called when delay timer timeout.
Definition: ndisc-cache.cc:326
bool IsDelay() const
Is the entry DELAY.
Definition: ndisc-cache.cc:569
void StartRetransmitTimer()
Start retransmit timer.
Definition: ndisc-cache.cc:479
void SetIpv6Address(Ipv6Address ipv6Address)
Set the IPv6 address.
Definition: ndisc-cache.cc:406
void MarkIncomplete(Ipv6PayloadHeaderPair p)
Changes the state to this entry to INCOMPLETE.
Definition: ndisc-cache.cc:499
bool IsStale() const
Is the entry STALE.
Definition: ndisc-cache.cc:557
void SetMacAddress(Address mac)
Set the MAC address of this entry.
Definition: ndisc-cache.cc:599
bool IsProbe() const
Is the entry PROBE.
Definition: ndisc-cache.cc:581
Time GetLastReachabilityConfirmation() const
Get the time of last reachability confirmation.
Definition: ndisc-cache.cc:418
void FunctionRetransmitTimeout()
Function called when retransmit timer timeout.
Definition: ndisc-cache.cc:277
NdiscCache * m_ndCache
the NdiscCache associated.
Definition: ndisc-cache.h:368
void MarkDelay()
Change the state to this entry to DELAY.
Definition: ndisc-cache.cc:544
Entry(NdiscCache *nd)
Constructor.
Definition: ndisc-cache.cc:228
bool IsRouter() const
If the entry is a host or a router.
Definition: ndisc-cache.cc:245
void SetRouter(bool router)
Set the node type.
Definition: ndisc-cache.cc:239
Timer m_nudTimer
Timer (used for NUD).
Definition: ndisc-cache.h:412
void FunctionReachableTimeout()
Function called when reachable timer timeout.
Definition: ndisc-cache.cc:271
void AddWaitingPacket(Ipv6PayloadHeaderPair p)
Add a packet (or replace old value) in the queue.
Definition: ndisc-cache.cc:251
bool IsReachable() const
Is the entry REACHABLE.
Definition: ndisc-cache.cc:563
void StopNudTimer()
Stop NUD timer and reset the NUD retransmission counter.
Definition: ndisc-cache.cc:492
IPv6 Neighbor Discovery cache.
Definition: ndisc-cache.h:50
NdiscCache & operator=(NdiscCache const &)=delete
std::unordered_map< Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash >::iterator CacheI
Neighbor Discovery Cache container iterator.
Definition: ndisc-cache.h:438
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv6Interface > interface, Ptr< Icmpv6L4Protocol > icmpv6)
Set the device and interface.
Definition: ndisc-cache.cc:73
std::pair< Ptr< Packet >, Ipv6Header > Ipv6PayloadHeaderPair
Pair of a packet and an Ipv4 header.
Definition: ndisc-cache.h:153
virtual NdiscCache::Entry * Add(Ipv6Address to)
Add an entry.
Definition: ndisc-cache.cc:126
void Flush()
Flush the cache.
Definition: ndisc-cache.cc:153
Ptr< Ipv6Interface > m_interface
the interface.
Definition: ndisc-cache.h:454
void Remove(NdiscCache::Entry *entry)
Delete an entry.
Definition: ndisc-cache.cc:137
NdiscCache()
Constructor.
Definition: ndisc-cache.cc:52
void PrintNdiscCache(Ptr< OutputStreamWrapper > stream)
Print the NDISC cache entries.
Definition: ndisc-cache.cc:177
Ptr< NetDevice > m_device
The NetDevice.
Definition: ndisc-cache.h:449
uint32_t GetUnresQlen()
Get the max number of waiting packet.
Definition: ndisc-cache.cc:171
virtual NdiscCache::Entry * Lookup(Ipv6Address dst)
Lookup in the cache.
Definition: ndisc-cache.cc:93
Ptr< NetDevice > GetDevice() const
Get the NetDevice associated with this cache.
Definition: ndisc-cache.cc:87
static const uint32_t DEFAULT_UNRES_QLEN
Default value for unres qlen.
Definition: ndisc-cache.h:63
~NdiscCache()
Destructor.
Definition: ndisc-cache.cc:57
NdiscCache(NdiscCache const &)=delete
static TypeId GetTypeId()
Get the type ID.
Definition: ndisc-cache.cc:38
Cache m_ndCache
A list of Entry.
Definition: ndisc-cache.h:443
std::list< NdiscCache::Entry * > LookupInverse(Address dst)
Lookup in the cache for a MAC address.
Definition: ndisc-cache.cc:108
void SetUnresQlen(uint32_t unresQlen)
Set the max number of waiting packet.
Definition: ndisc-cache.cc:165
void DoDispose()
Dispose this object.
Definition: ndisc-cache.cc:63
Ptr< Icmpv6L4Protocol > m_icmpv6
the icmpv6 L4 protocol for this cache.
Definition: ndisc-cache.h:459
std::unordered_map< Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash > Cache
Neighbor Discovery Cache container.
Definition: ndisc-cache.h:434
Ptr< Ipv6Interface > GetInterface() const
Get the Ipv6Interface associated with this cache.
Definition: ndisc-cache.cc:81
uint32_t m_unresQlen
Max number of packet stored in m_waiting.
Definition: ndisc-cache.h:464
A base class which provides memory management and object aggregation.
Definition: object.h:88
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
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:139
mac
Definition: third.py:99