A Discrete-Event Network Simulator
API
arp-cache.h
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
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef ARP_CACHE_H
21 #define ARP_CACHE_H
22 
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"
36 #include "ns3/output-stream-wrapper.h"
37 
38 namespace ns3 {
39 
40 class NetDevice;
41 class Ipv4Interface;
42 
50 class ArpCache : public Object
51 {
52 private:
58  ArpCache (ArpCache const &);
65  ArpCache& operator= (ArpCache const &);
66 
67 public:
72  static TypeId GetTypeId (void);
73  class Entry;
74  ArpCache ();
75  ~ArpCache ();
76 
83  void SetDevice (Ptr<NetDevice> device, Ptr<Ipv4Interface> interface);
88  Ptr<NetDevice> GetDevice (void) const;
93  Ptr<Ipv4Interface> GetInterface (void) const;
94 
99  void SetAliveTimeout (Time aliveTimeout);
104  void SetDeadTimeout (Time deadTimeout);
109  void SetWaitReplyTimeout (Time waitReplyTimeout);
110 
115  Time GetAliveTimeout (void) const;
120  Time GetDeadTimeout (void) const;
125  Time GetWaitReplyTimeout (void) const;
126 
135  Ipv4Address> arpRequestCallback);
141  void StartWaitReplyTimer (void);
148  ArpCache::Entry *Lookup (Ipv4Address destination);
156  void Flush (void);
157 
164 
168  class Entry {
169 public:
174  Entry (ArpCache *arp);
175 
179  void MarkDead (void);
183  void MarkAlive (Address macAddress);
187  void MarkWaitReply (Ptr<Packet> waiting);
192  bool UpdateWaitReply (Ptr<Packet> waiting);
196  bool IsDead (void);
200  bool IsAlive (void);
204  bool IsWaitReply (void);
205 
209  Address GetMacAddress (void) const;
213  Ipv4Address GetIpv4Address (void) const;
217  void SetIpv4Address (Ipv4Address destination);
224  bool IsExpired (void) const;
234  uint32_t GetRetries (void) const;
238  void IncrementRetries (void);
242  void ClearRetries (void);
243 
244 private:
252  };
253 
257  void UpdateSeen (void);
258 
263  Time GetTimeout (void) const;
264 
270  std::list<Ptr<Packet> > m_pending;
271  uint32_t m_retries;
272  };
273 
274 private:
278  typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash> Cache;
282  typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash>::iterator CacheI;
283 
284  virtual void DoDispose (void);
285 
293  uint32_t m_maxRetries;
294 
300  void HandleWaitReplyTimeout (void);
302  Cache m_arpCache;
304 };
305 
306 
307 } // namespace ns3
308 
309 #endif /* ARP_CACHE_H */
uint32_t m_retries
rerty counter
Definition: arp-cache.h:271
ArpCacheEntryState_e m_state
state of the entry
Definition: arp-cache.h:266
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
Set the NetDevice and Ipv4Interface associated with the ArpCache.
Definition: arp-cache.cc:113
uint32_t m_maxRetries
max retries for a resolution
Definition: arp-cache.h:293
void StartWaitReplyTimer(void)
This method will schedule a timeout at WaitReplyTimeout interval in the future, unless a timer is alr...
Definition: arp-cache.cc:181
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
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:173
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Callback template class.
Definition: callback.h:984
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
Definition: arp-cache.cc:305
virtual void DoDispose(void)
Destructor implementation.
Definition: arp-cache.cc:99
static TypeId GetTypeId(void)
Get the type ID.
Definition: arp-cache.cc:40
void PrintArpCache(Ptr< OutputStreamWrapper > stream)
Print the ARP cache entries.
Definition: arp-cache.cc:257
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
Definition: arp-cache.cc:293
Forward calls to a chain of Callback.
Callback< void, Ptr< const ArpCache >, Ipv4Address > m_arpRequestCallback
reply timeout callback
Definition: arp-cache.h:292
Time GetDeadTimeout(void) const
Get the time the entry will be in DEAD state before being removed.
Definition: arp-cache.cc:160
Ptr< NetDevice > GetDevice(void) const
Returns the NetDevice that this ARP cache is associated with.
Definition: arp-cache.cc:121
Address m_macAddress
entry's MAC address
Definition: arp-cache.h:268
ArpCache * m_arp
pointer to the ARP cache owning the entry
Definition: arp-cache.h:265
bool IsAlive(void)
Definition: arp-cache.cc:332
EventId m_waitReplyTimer
cache alive state timer
Definition: arp-cache.h:291
ArpCacheEntryState_e
ARP cache entry states.
Definition: arp-cache.h:248
a polymophic address class
Definition: address.h:90
Cache m_arpCache
the ARP cache
Definition: arp-cache.h:302
void SetIpv4Address(Ipv4Address destination)
Definition: arp-cache.cc:405
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:194
void MarkWaitReply(Ptr< Packet > waiting)
Definition: arp-cache.cc:381
uint32_t GetRetries(void) const
Definition: arp-cache.cc:462
bool IsDead(void)
Definition: arp-cache.cc:326
Ptr< Ipv4Interface > m_interface
Ipv4Interface associated with the cache.
Definition: arp-cache.h:287
bool IsExpired(void) const
Definition: arp-cache.cc:428
Ipv4Address GetIpv4Address(void) const
Definition: arp-cache.cc:399
Time m_waitReplyTimeout
cache reply state timeout
Definition: arp-cache.h:290
Address GetMacAddress(void) const
Definition: arp-cache.cc:393
void SetDeadTimeout(Time deadTimeout)
Set the time the entry will be in DEAD state before being removed.
Definition: arp-cache.cc:141
void SetAliveTimeout(Time aliveTimeout)
Set the time the entry will be in ALIVE state (unless refreshed)
Definition: arp-cache.cc:135
Ptr< Ipv4Interface > GetInterface(void) const
Returns the Ipv4Interface that this ARP cache is associated with.
Definition: arp-cache.cc:128
void IncrementRetries(void)
Increment the counter of number of retries for an entry.
Definition: arp-cache.cc:468
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void MarkAlive(Address macAddress)
Definition: arp-cache.cc:354
Time GetAliveTimeout(void) const
Get the time the entry will be in ALIVE state (unless refreshed)
Definition: arp-cache.cc:154
A record that that holds information about an ArpCache entry.
Definition: arp-cache.h:168
void Flush(void)
Clear the ArpCache of all entries.
Definition: arp-cache.cc:241
Entry(ArpCache *arp)
Constructor.
Definition: arp-cache.cc:316
Time GetTimeout(void) const
Returns the entry timeout.
Definition: arp-cache.cc:411
void UpdateSeen(void)
Update the entry when seeing a packet.
Definition: arp-cache.cc:456
TracedCallback< Ptr< const Packet > > m_dropTrace
trace for packets dropped by the ARP cache queue
Definition: arp-cache.h:303
bool UpdateWaitReply(Ptr< Packet > waiting)
Definition: arp-cache.cc:365
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
An identifier for simulation events.
Definition: event-id.h:53
sgi::hash_map< Ipv4Address, ArpCache::Entry *, Ipv4AddressHash >::iterator CacheI
ARP Cache container iterator.
Definition: arp-cache.h:282
bool IsWaitReply(void)
Definition: arp-cache.cc:338
An ARP cache.
Definition: arp-cache.h:50
Ptr< Packet > DequeuePending(void)
Definition: arp-cache.cc:441
Time GetWaitReplyTimeout(void) const
Get the time the entry will be in WAIT_REPLY state.
Definition: arp-cache.cc:166
void ClearRetries(void)
Zero the counter of number of retries for an entry.
Definition: arp-cache.cc:475
Ptr< NetDevice > m_device
NetDevice associated with the cache.
Definition: arp-cache.h:286
void MarkDead(void)
Changes the state of this entry to dead.
Definition: arp-cache.cc:346
Time m_deadTimeout
cache dead state timeout
Definition: arp-cache.h:289
A base class which provides memory management and object aggregation.
Definition: object.h:87
Time m_lastSeen
last moment a packet from that address has been seen
Definition: arp-cache.h:267
uint32_t m_pendingQueueSize
number of packets waiting for a resolution
Definition: arp-cache.h:301
void SetWaitReplyTimeout(Time waitReplyTimeout)
Set the time the entry will be in WAIT_REPLY state.
Definition: arp-cache.cc:147
Time m_aliveTimeout
cache alive state timeout
Definition: arp-cache.h:288
a unique identifier for an interface.
Definition: type-id.h:57
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:270
sgi::hash_map< Ipv4Address, ArpCache::Entry *, Ipv4AddressHash > Cache
ARP Cache container.
Definition: arp-cache.h:278
Ipv4Address m_ipv4Address
entry's IP address
Definition: arp-cache.h:269