A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
arp-cache.h
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:
193  enum ArpCacheEntryState_e {
194  ALIVE,
195  WAIT_REPLY,
196  DEAD
197  };
198 
199  void UpdateSeen (void);
200  Time GetTimeout (void) const;
201  ArpCache *m_arp;
202  ArpCacheEntryState_e m_state;
203  Time m_lastSeen;
204  Address m_macAddress;
205  Ipv4Address m_ipv4Address;
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 
216  Ptr<NetDevice> m_device;
217  Ptr<Ipv4Interface> m_interface;
218  Time m_aliveTimeout;
219  Time m_deadTimeout;
220  Time m_waitReplyTimeout;
221  EventId m_waitReplyTimer;
222  Callback<void, Ptr<const ArpCache>, Ipv4Address> m_arpRequestCallback;
223  uint32_t m_maxRetries;
229  void HandleWaitReplyTimeout (void);
230  uint32_t m_pendingQueueSize;
231  Cache m_arpCache;
232  TracedCallback<Ptr<const Packet> > m_dropTrace;
233 };
234 
235 
236 } // namespace ns3
237 
238 #endif /* ARP_CACHE_H */
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
Definition: arp-cache.cc:102
void StartWaitReplyTimer(void)
Definition: arp-cache.cc:170
keep track of time unit.
Definition: nstime.h:149
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:369
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
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...
Ptr< NetDevice > GetDevice(void) const
Definition: arp-cache.cc:110
bool IsAlive(void)
Definition: arp-cache.cc:285
a polymophic address class
Definition: address.h:86
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
bool IsExpired(void) const
Definition: arp-cache.cc:382
Ipv4Address GetIpv4Address(void) const
Definition: arp-cache.cc:353
Address GetMacAddress(void) const
Definition: arp-cache.cc:346
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
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
Entry(ArpCache *arp)
Constructor.
Definition: arp-cache.cc:269
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
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
void ClearRetries(void)
Zero the counter of number of retries for an entry.
Definition: arp-cache.cc:429
void MarkDead(void)
Changes the state of this entry to dead.
Definition: arp-cache.cc:299
a base class which provides memory management and object aggregation
Definition: object.h:63
a unique identifier for an interface.
Definition: type-id.h:44