A Discrete-Event Network Simulator
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"
36 #include "ns3/output-stream-wrapper.h"
38 namespace ns3 {
40 class NetDevice;
41 class Ipv4Interface;
42 class Ipv4Header;
51 class ArpCache : public Object
52 {
53 private:
59  ArpCache (ArpCache const &);
66  ArpCache& operator= (ArpCache const &);
68 public:
73  static TypeId GetTypeId (void);
74  class Entry;
75  ArpCache ();
76  ~ArpCache ();
84  void SetDevice (Ptr<NetDevice> device, Ptr<Ipv4Interface> interface);
89  Ptr<NetDevice> GetDevice (void) const;
94  Ptr<Ipv4Interface> GetInterface (void) const;
100  void SetAliveTimeout (Time aliveTimeout);
105  void SetDeadTimeout (Time deadTimeout);
110  void SetWaitReplyTimeout (Time waitReplyTimeout);
116  Time GetAliveTimeout (void) const;
121  Time GetDeadTimeout (void) const;
126  Time GetWaitReplyTimeout (void) const;
136  Ipv4Address> arpRequestCallback);
142  void StartWaitReplyTimer (void);
149  ArpCache::Entry *Lookup (Ipv4Address destination);
156  std::list<ArpCache::Entry *> LookupInverse (Address destination);
167  void Remove (ArpCache::Entry *entry);
171  void Flush (void);
183  typedef std::pair<Ptr<Packet>, Ipv4Header> Ipv4PayloadHeaderPair;
188  class Entry {
189 public:
194  Entry (ArpCache *arp);
199  void MarkDead (void);
203  void MarkAlive (Address macAddress);
207  void MarkWaitReply (Ipv4PayloadHeaderPair waiting);
213  void MarkPermanent (void);
218  bool UpdateWaitReply (Ipv4PayloadHeaderPair waiting);
222  bool IsDead (void);
226  bool IsAlive (void);
230  bool IsWaitReply (void);
234  bool IsPermanent (void);
238  Address GetMacAddress (void) const;
242  Ipv4Address GetIpv4Address (void) const;
248  void SetMacAddresss (Address macAddress);
252  void SetMacAddress (Address macAddress);
256  void SetIpv4Address (Ipv4Address destination);
263  bool IsExpired (void) const;
268  Ipv4PayloadHeaderPair DequeuePending (void);
272  void ClearPendingPacket (void);
277  uint32_t GetRetries (void) const;
281  void IncrementRetries (void);
285  void ClearRetries (void);
290  void UpdateSeen (void);
292 private:
301  };
307  Time GetTimeout (void) const;
314  std::list<Ipv4PayloadHeaderPair> m_pending;
315  uint32_t m_retries;
316  };
318 private:
322  typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash> Cache;
326  typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash>::iterator CacheI;
328  virtual void DoDispose (void);
337  uint32_t m_maxRetries;
344  void HandleWaitReplyTimeout (void);
346  Cache m_arpCache;
348 };
351 } // namespace ns3
353 #endif /* ARP_CACHE_H */
uint32_t m_retries
rerty counter
Definition: arp-cache.h:315
ArpCacheEntryState_e m_state
state of the entry
Definition: arp-cache.h:310
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
Set the NetDevice and Ipv4Interface associated with the ArpCache.
Definition: arp-cache.cc:114
uint32_t m_maxRetries
max retries for a resolution
Definition: arp-cache.h:337
void StartWaitReplyTimer(void)
This method will schedule a timeout at WaitReplyTimeout interval in the future, unless a timer is alr...
Definition: arp-cache.cc:182
void MarkPermanent(void)
Changes the state of this entry to Permanent.
Definition: arp-cache.cc:414
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:174
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Callback template class.
Definition: callback.h:1176
void SetMacAddress(Address macAddress)
Definition: arp-cache.cc:466
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
Definition: arp-cache.cc:330
virtual void DoDispose(void)
Destructor implementation.
Definition: arp-cache.cc:100
static TypeId GetTypeId(void)
Get the type ID.
Definition: arp-cache.cc:41
void PrintArpCache(Ptr< OutputStreamWrapper > stream)
Print the ARP cache entries.
Definition: arp-cache.cc:260
NS_DEPRECATED void SetMacAddresss(Address macAddress)
Definition: arp-cache.cc:460
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
Definition: arp-cache.cc:318
Forward calls to a chain of Callback.
bool IsPermanent(void)
Definition: arp-cache.cc:387
Callback< void, Ptr< const ArpCache >, Ipv4Address > m_arpRequestCallback
reply timeout callback
Definition: arp-cache.h:336
Time GetDeadTimeout(void) const
Get the time the entry will be in DEAD state before being removed.
Definition: arp-cache.cc:161
Ptr< NetDevice > GetDevice(void) const
Returns the NetDevice that this ARP cache is associated with.
Definition: arp-cache.cc:122
Address m_macAddress
entry's MAC address
Definition: arp-cache.h:312
ArpCache * m_arp
pointer to the ARP cache owning the entry
Definition: arp-cache.h:309
bool IsAlive(void)
Definition: arp-cache.cc:375
EventId m_waitReplyTimer
cache alive state timer
Definition: arp-cache.h:335
ARP cache entry states.
Definition: arp-cache.h:296
a polymophic address class
Definition: address.h:90
Packet header for IPv4.
Definition: ipv4-header.h:33
Cache m_arpCache
the ARP cache
Definition: arp-cache.h:346
void SetIpv4Address(Ipv4Address destination)
Definition: arp-cache.cc:478
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:195
uint32_t GetRetries(void) const
Definition: arp-cache.cc:544
bool IsDead(void)
Definition: arp-cache.cc:369
Ptr< Ipv4Interface > m_interface
Ipv4Interface associated with the cache.
Definition: arp-cache.h:331
bool IsExpired(void) const
Definition: arp-cache.cc:503
Ipv4Address GetIpv4Address(void) const
Definition: arp-cache.cc:472
void MarkWaitReply(Ipv4PayloadHeaderPair waiting)
Definition: arp-cache.cc:440
Time m_waitReplyTimeout
cache reply state timeout
Definition: arp-cache.h:334
Address GetMacAddress(void) const
Definition: arp-cache.cc:454
void SetDeadTimeout(Time deadTimeout)
Set the time the entry will be in DEAD state before being removed.
Definition: arp-cache.cc:142
void SetAliveTimeout(Time aliveTimeout)
Set the time the entry will be in ALIVE state (unless refreshed)
Definition: arp-cache.cc:136
Ptr< Ipv4Interface > GetInterface(void) const
Returns the Ipv4Interface that this ARP cache is associated with.
Definition: arp-cache.cc:129
void IncrementRetries(void)
Increment the counter of number of retries for an entry.
Definition: arp-cache.cc:550
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void ClearPendingPacket(void)
Clear the pending packet list.
Definition: arp-cache.cc:532
void MarkAlive(Address macAddress)
Definition: arp-cache.cc:404
Time GetAliveTimeout(void) const
Get the time the entry will be in ALIVE state (unless refreshed)
Definition: arp-cache.cc:155
A record that that holds information about an ArpCache entry.
Definition: arp-cache.h:188
void Flush(void)
Clear the ArpCache of all entries.
Definition: arp-cache.cc:244
void Remove(ArpCache::Entry *entry)
Remove an entry.
Definition: arp-cache.cc:342
Entry(ArpCache *arp)
Definition: arp-cache.cc:359
Time GetTimeout(void) const
Returns the entry timeout.
Definition: arp-cache.cc:484
void UpdateSeen(void)
Update the entry when seeing a packet.
Definition: arp-cache.cc:538
TracedCallback< Ptr< const Packet > > m_dropTrace
trace for packets dropped by the ARP cache queue
Definition: arp-cache.h:347
bool UpdateWaitReply(Ipv4PayloadHeaderPair waiting)
Definition: arp-cache.cc:424
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
Mark a function as deprecated.
Definition: deprecated.h:60
Ipv4PayloadHeaderPair DequeuePending(void)
Definition: arp-cache.cc:516
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:326
std::pair< Ptr< Packet >, Ipv4Header > Ipv4PayloadHeaderPair
Pair of a packet and an Ipv4 header.
Definition: arp-cache.h:183
bool IsWaitReply(void)
Definition: arp-cache.cc:381
An ARP cache.
Definition: arp-cache.h:51
std::list< Ipv4PayloadHeaderPair > m_pending
list of pending packets for the entry's IP
Definition: arp-cache.h:314
Time GetWaitReplyTimeout(void) const
Get the time the entry will be in WAIT_REPLY state.
Definition: arp-cache.cc:167
void ClearRetries(void)
Zero the counter of number of retries for an entry.
Definition: arp-cache.cc:557
Ptr< NetDevice > m_device
NetDevice associated with the cache.
Definition: arp-cache.h:330
std::list< ArpCache::Entry * > LookupInverse(Address destination)
Do lookup in the ARP cache against a MAC address.
Definition: arp-cache.cc:300
void MarkDead(void)
Changes the state of this entry to dead.
Definition: arp-cache.cc:395
Time m_deadTimeout
cache dead state timeout
Definition: arp-cache.h:333
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:311
uint32_t m_pendingQueueSize
number of packets waiting for a resolution
Definition: arp-cache.h:345
void SetWaitReplyTimeout(Time waitReplyTimeout)
Set the time the entry will be in WAIT_REPLY state.
Definition: arp-cache.cc:148
Time m_aliveTimeout
cache alive state timeout
Definition: arp-cache.h:332
a unique identifier for an interface.
Definition: type-id.h:58
ArpCache & operator=(ArpCache const &)
Copy constructor.
sgi::hash_map< Ipv4Address, ArpCache::Entry *, Ipv4AddressHash > Cache
ARP Cache container.
Definition: arp-cache.h:322
Ipv4Address m_ipv4Address
entry's IP address
Definition: arp-cache.h:313