A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
37 namespace ns3 {
38 
39 class NetDevice;
40 class Ipv4Interface;
41 
49 class ArpCache : public Object
50 {
51 private:
52  ArpCache (ArpCache const &);
53  ArpCache& operator= (ArpCache const &);
54 
55 public:
56  static TypeId GetTypeId (void);
57  class Entry;
58  ArpCache ();
59  ~ArpCache ();
60 
65  void SetDevice (Ptr<NetDevice> device, Ptr<Ipv4Interface> interface);
69  Ptr<NetDevice> GetDevice (void) const;
73  Ptr<Ipv4Interface> GetInterface (void) const;
74 
75  void SetAliveTimeout (Time aliveTimeout);
76  void SetDeadTimeout (Time deadTimeout);
77  void SetWaitReplyTimeout (Time waitReplyTimeout);
78  Time GetAliveTimeout (void) const;
79  Time GetDeadTimeout (void) const;
80  Time GetWaitReplyTimeout (void) const;
81 
90  Ipv4Address> arpRequestCallback);
96  void StartWaitReplyTimer (void);
103  ArpCache::Entry *Lookup (Ipv4Address destination);
111  void Flush (void);
112 
116  class Entry {
117 public:
122  Entry (ArpCache *arp);
123 
127  void MarkDead (void);
131  void MarkAlive (Address macAddress);
135  void MarkWaitReply (Ptr<Packet> waiting);
140  bool UpdateWaitReply (Ptr<Packet> waiting);
144  bool IsDead (void);
148  bool IsAlive (void);
152  bool IsWaitReply (void);
153 
157  Address GetMacAddress (void) const;
161  Ipv4Address GetIpv4Address (void) const;
165  void SetIpv4Address (Ipv4Address destination);
172  bool IsExpired (void) const;
182  uint32_t GetRetries (void) const;
186  void IncrementRetries (void);
190  void ClearRetries (void);
191 
192 private:
197  };
198 
199  void UpdateSeen (void);
200  Time GetTimeout (void) const;
206  std::list<Ptr<Packet> > m_pending;
207  uint32_t m_retries;
208  };
209 
210 private:
211  typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash> Cache;
212  typedef sgi::hash_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash>::iterator CacheI;
213 
214  virtual void DoDispose (void);
215 
223  uint32_t m_maxRetries;
229  void HandleWaitReplyTimeout (void);
233 };
234 
235 
236 } // namespace ns3
237 
238 #endif /* ARP_CACHE_H */
uint32_t m_retries
Definition: arp-cache.h:207
ArpCacheEntryState_e m_state
Definition: arp-cache.h:202
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
Definition: arp-cache.cc:102
uint32_t m_maxRetries
Definition: arp-cache.h:223
void StartWaitReplyTimer(void)
Definition: arp-cache.cc:170
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
void SetArpRequestCallback(Callback< void, Ptr< const ArpCache >, Ipv4Address > arpRequestCallback)
Definition: arp-cache.cc:162
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Callback template class.
Definition: callback.h:920
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
Definition: arp-cache.cc:258
virtual void DoDispose(void)
Definition: arp-cache.cc:88
static TypeId GetTypeId(void)
Definition: arp-cache.cc:39
Definition: arp-cache.h:194
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
Definition: arp-cache.h:222
Time GetDeadTimeout(void) const
Definition: arp-cache.cc:149
Ptr< NetDevice > GetDevice(void) const
Definition: arp-cache.cc:110
Address m_macAddress
Definition: arp-cache.h:204
ArpCache * m_arp
Definition: arp-cache.h:201
bool IsAlive(void)
Definition: arp-cache.cc:285
EventId m_waitReplyTimer
Definition: arp-cache.h:221
a polymophic address class
Definition: address.h:86
Cache m_arpCache
Definition: arp-cache.h:231
void SetIpv4Address(Ipv4Address destination)
Definition: arp-cache.cc:359
void HandleWaitReplyTimeout(void)
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
Definition: arp-cache.h:217
bool IsExpired(void) const
Definition: arp-cache.cc:382
Ipv4Address GetIpv4Address(void) const
Definition: arp-cache.cc:353
Time m_waitReplyTimeout
Definition: arp-cache.h:220
Address GetMacAddress(void) const
Definition: arp-cache.cc:346
void SetDeadTimeout(Time deadTimeout)
Definition: arp-cache.cc:130
void SetAliveTimeout(Time aliveTimeout)
Definition: arp-cache.cc:124
Ptr< Ipv4Interface > GetInterface(void) const
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
Definition: arp-cache.cc:143
A record that that holds information about an ArpCache entry.
Definition: arp-cache.h:116
void Flush(void)
Clear the ArpCache of all entries.
Definition: arp-cache.cc:230
ArpCacheEntryState_e
Definition: arp-cache.h:193
Entry(ArpCache *arp)
Constructor.
Definition: arp-cache.cc:269
Time GetTimeout(void) const
Definition: arp-cache.cc:365
void UpdateSeen(void)
Definition: arp-cache.cc:410
TracedCallback< Ptr< const Packet > > m_dropTrace
Definition: arp-cache.h:232
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
Definition: arp-cache.h:212
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
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
Definition: arp-cache.h:216
void MarkDead(void)
Changes the state of this entry to dead.
Definition: arp-cache.cc:299
Time m_deadTimeout
Definition: arp-cache.h:219
Definition: arp-cache.h:196
a base class which provides memory management and object aggregation
Definition: object.h:63
Time m_lastSeen
Definition: arp-cache.h:203
uint32_t m_pendingQueueSize
Definition: arp-cache.h:230
void SetWaitReplyTimeout(Time waitReplyTimeout)
Definition: arp-cache.cc:136
Time m_aliveTimeout
Definition: arp-cache.h:218
a unique identifier for an interface.
Definition: type-id.h:49
ArpCache & operator=(ArpCache const &)
std::list< Ptr< Packet > > m_pending
Definition: arp-cache.h:206
Definition: arp-cache.h:195
sgi::hash_map< Ipv4Address, ArpCache::Entry *, Ipv4AddressHash > Cache
Definition: arp-cache.h:211
Ipv4Address m_ipv4Address
Definition: arp-cache.h:205