A Discrete-Event Network Simulator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006 INRIA
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
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef ARP_CACHE_H
21 #define ARP_CACHE_H
23 #include <stdint.h>
24 #include <list>
25 #include "ns3/simulator.h"
26 #include "ns3/callback.h"
27 #include "ns3/packet.h"
28 #include "ns3/nstime.h"
29 #include "ns3/net-device.h"
30 #include "ns3/ipv4-address.h"
31 #include "ns3/address.h"
32 #include "ns3/ptr.h"
33 #include "ns3/object.h"
34 #include "ns3/traced-callback.h"
35 #include "ns3/sgi-hashmap.h"
37 namespace ns3 {
39 class NetDevice;
40 class Ipv4Interface;
49 class ArpCache : public Object
50 {
51 private:
57  ArpCache (ArpCache const &);
64  ArpCache& operator= (ArpCache const &);
66 public:
71  static TypeId GetTypeId (void);
72  class Entry;
73  ArpCache ();
74  ~ArpCache ();
82  void SetDevice (Ptr<NetDevice> device, Ptr<Ipv4Interface> interface);
87  Ptr<NetDevice> GetDevice (void) const;
92  Ptr<Ipv4Interface> GetInterface (void) const;
98  void SetAliveTimeout (Time aliveTimeout);
103  void SetDeadTimeout (Time deadTimeout);
108  void SetWaitReplyTimeout (Time waitReplyTimeout);
114  Time GetAliveTimeout (void) const;
119  Time GetDeadTimeout (void) const;
124  Time GetWaitReplyTimeout (void) const;
134  Ipv4Address> arpRequestCallback);
140  void StartWaitReplyTimer (void);
147  ArpCache::Entry *Lookup (Ipv4Address destination);
155  void Flush (void);
160  class Entry {
161 public:
166  Entry (ArpCache *arp);
171  void MarkDead (void);
175  void MarkAlive (Address macAddress);
179  void MarkWaitReply (Ptr<Packet> waiting);
184  bool UpdateWaitReply (Ptr<Packet> waiting);
188  bool IsDead (void);
192  bool IsAlive (void);
196  bool IsWaitReply (void);
201  Address GetMacAddress (void) const;
205  Ipv4Address GetIpv4Address (void) const;
209  void SetIpv4Address (Ipv4Address destination);
216  bool IsExpired (void) const;
226  uint32_t GetRetries (void) const;
230  void IncrementRetries (void);
234  void ClearRetries (void);
236 private:
244  };
249  void UpdateSeen (void);
255  Time GetTimeout (void) const;
262  std::list<Ptr<Packet> > m_pending;
263  uint32_t m_retries;
264  };
266 private:
270  typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash> Cache;
274  typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash>::iterator CacheI;
276  virtual void DoDispose (void);
285  uint32_t m_maxRetries;
292  void HandleWaitReplyTimeout (void);
296 };
299 } // namespace ns3
301 #endif /* ARP_CACHE_H */
uint32_t m_retries
rerty counter
Definition: arp-cache.h:263
ArpCacheEntryState_e m_state
state of the entry
Definition: arp-cache.h:258
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
Set the NetDevice and Ipv4Interface associated with the ArpCache.
Definition: arp-cache.cc:102
uint32_t m_maxRetries
max retries for a resolution
Definition: arp-cache.h:285
void StartWaitReplyTimer(void)
This method will schedule a timeout at WaitReplyTimeout interval in the future, unless a timer is alr...
Definition: arp-cache.cc:170
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
void SetArpRequestCallback(Callback< void, Ptr< const ArpCache >, Ipv4Address > arpRequestCallback)
This callback is set when the ArpCache is set up and allows the cache to generate an Arp request when...
Definition: arp-cache.cc:162
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
Callback template class.
Definition: callback.h:924
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
Definition: arp-cache.cc:258
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: arp-cache.cc:88
static TypeId GetTypeId(void)
Get the type ID.
Definition: arp-cache.cc:39
Definition: arp-cache.h:241
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
Definition: arp-cache.cc:246
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
Callback< void, Ptr< const ArpCache >, Ipv4Address > m_arpRequestCallback
reply timeout callback
Definition: arp-cache.h:284
Time GetDeadTimeout(void) const
Get the time the entry will be in DEAD state before being removed.
Definition: arp-cache.cc:149
Ptr< NetDevice > GetDevice(void) const
Returns the NetDevice that this ARP cache is associated with.
Definition: arp-cache.cc:110
Address m_macAddress
entry's MAC address
Definition: arp-cache.h:260
ArpCache * m_arp
pointer to the ARP cache owning the entry
Definition: arp-cache.h:257
bool IsAlive(void)
Definition: arp-cache.cc:285
EventId m_waitReplyTimer
cache alive state timer
Definition: arp-cache.h:283
a polymophic address class
Definition: address.h:86
Cache m_arpCache
the ARP cache
Definition: arp-cache.h:294
void SetIpv4Address(Ipv4Address destination)
Definition: arp-cache.cc:359
void HandleWaitReplyTimeout(void)
This function is an event handler for the event that the ArpCache wants to check whether it must retr...
Definition: arp-cache.cc:183
void MarkWaitReply(Ptr< Packet > waiting)
Definition: arp-cache.cc:334
uint32_t GetRetries(void) const
Definition: arp-cache.cc:416
bool IsDead(void)
Definition: arp-cache.cc:279
Ptr< Ipv4Interface > m_interface
Ipv4Interface associated with the cache.
Definition: arp-cache.h:279
bool IsExpired(void) const
Definition: arp-cache.cc:382
Ipv4Address GetIpv4Address(void) const
Definition: arp-cache.cc:353
Time m_waitReplyTimeout
cache reply state timeout
Definition: arp-cache.h:282
Address GetMacAddress(void) const
Definition: arp-cache.cc:346
void SetDeadTimeout(Time deadTimeout)
Set the time the entry will be in DEAD state before being removed.
Definition: arp-cache.cc:130
void SetAliveTimeout(Time aliveTimeout)
Set the time the entry will be in ALIVE state (unless refreshed)
Definition: arp-cache.cc:124
Ptr< Ipv4Interface > GetInterface(void) const
Returns the Ipv4Interface that this ARP cache is associated with.
Definition: arp-cache.cc:117
void IncrementRetries(void)
Increment the counter of number of retries for an entry.
Definition: arp-cache.cc:422
void MarkAlive(Address macAddress)
Definition: arp-cache.cc:307
Time GetAliveTimeout(void) const
Get the time the entry will be in ALIVE state (unless refreshed)
Definition: arp-cache.cc:143
A record that that holds information about an ArpCache entry.
Definition: arp-cache.h:160
void Flush(void)
Clear the ArpCache of all entries.
Definition: arp-cache.cc:230
ARP cache entry states.
Definition: arp-cache.h:240
Entry(ArpCache *arp)
Definition: arp-cache.cc:269
Time GetTimeout(void) const
Returns the entry timeout.
Definition: arp-cache.cc:365
void UpdateSeen(void)
Update the entry when seeing a packet.
Definition: arp-cache.cc:410
TracedCallback< Ptr< const Packet > > m_dropTrace
trace for packets dropped by the ARP cache queue
Definition: arp-cache.h:295
bool UpdateWaitReply(Ptr< Packet > waiting)
Definition: arp-cache.cc:318
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
an identifier for simulation events.
Definition: event-id.h:46
sgi::hash_map< Ipv4Address, ArpCache::Entry *, Ipv4AddressHash >::iterator CacheI
ARP Cache container iterator.
Definition: arp-cache.h:274
bool IsWaitReply(void)
Definition: arp-cache.cc:291
An ARP cache.
Definition: arp-cache.h:49
Ptr< Packet > DequeuePending(void)
Definition: arp-cache.cc:395
Time GetWaitReplyTimeout(void) const
Get the time the entry will be in WAIT_REPLY state.
Definition: arp-cache.cc:155
void ClearRetries(void)
Zero the counter of number of retries for an entry.
Definition: arp-cache.cc:429
Ptr< NetDevice > m_device
NetDevice associated with the cache.
Definition: arp-cache.h:278
void MarkDead(void)
Changes the state of this entry to dead.
Definition: arp-cache.cc:299
Time m_deadTimeout
cache dead state timeout
Definition: arp-cache.h:281
Definition: arp-cache.h:243
a base class which provides memory management and object aggregation
Definition: object.h:64
Time m_lastSeen
last moment a packet from that address has been seen
Definition: arp-cache.h:259
uint32_t m_pendingQueueSize
number of packets waiting for a resolution
Definition: arp-cache.h:293
void SetWaitReplyTimeout(Time waitReplyTimeout)
Set the time the entry will be in WAIT_REPLY state.
Definition: arp-cache.cc:136
Time m_aliveTimeout
cache alive state timeout
Definition: arp-cache.h:280
a unique identifier for an interface.
Definition: type-id.h:49
ArpCache & operator=(ArpCache const &)
Copy constructor.
std::list< Ptr< Packet > > m_pending
list of pending packets for the entry's IP
Definition: arp-cache.h:262
Definition: arp-cache.h:242
sgi::hash_map< Ipv4Address, ArpCache::Entry *, Ipv4AddressHash > Cache
ARP Cache container.
Definition: arp-cache.h:270
Ipv4Address m_ipv4Address
entry's IP address
Definition: arp-cache.h:261