A Discrete-Event Network Simulator
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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 <unordered_map>
26#include "ns3/simulator.h"
27#include "ns3/callback.h"
28#include "ns3/packet.h"
29#include "ns3/nstime.h"
30#include "ns3/net-device.h"
31#include "ns3/ipv4-address.h"
32#include "ns3/address.h"
33#include "ns3/ptr.h"
34#include "ns3/object.h"
35#include "ns3/traced-callback.h"
36#include "ns3/output-stream-wrapper.h"
38namespace ns3 {
40class NetDevice;
41class Ipv4Interface;
42class Ipv4Header;
51class ArpCache : public Object
58 static TypeId GetTypeId (void);
59 class Entry;
61 ArpCache ();
62 ~ArpCache ();
64 // Delete copy constructor and assignment operator to avoid misuse
65 ArpCache (ArpCache const &) = delete;
66 ArpCache & operator = (ArpCache const &) = delete;
74 void SetDevice (Ptr<NetDevice> device, Ptr<Ipv4Interface> interface);
79 Ptr<NetDevice> GetDevice (void) const;
90 void SetAliveTimeout (Time aliveTimeout);
95 void SetDeadTimeout (Time deadTimeout);
100 void SetWaitReplyTimeout (Time waitReplyTimeout);
106 Time GetAliveTimeout (void) const;
111 Time GetDeadTimeout (void) const;
116 Time GetWaitReplyTimeout (void) const;
126 Ipv4Address> arpRequestCallback);
132 void StartWaitReplyTimer (void);
139 ArpCache::Entry *Lookup (Ipv4Address destination);
146 std::list<ArpCache::Entry *> LookupInverse (Address destination);
157 void Remove (ArpCache::Entry *entry);
161 void Flush (void);
173 typedef std::pair<Ptr<Packet>, Ipv4Header> Ipv4PayloadHeaderPair;
178 class Entry {
184 Entry (ArpCache *arp);
189 void MarkDead (void);
193 void MarkAlive (Address macAddress);
203 void MarkPermanent (void);
212 bool IsDead (void);
216 bool IsAlive (void);
220 bool IsWaitReply (void);
224 bool IsPermanent (void);
228 Address GetMacAddress (void) const;
232 Ipv4Address GetIpv4Address (void) const;
236 void SetMacAddress (Address macAddress);
240 void SetIpv4Address (Ipv4Address destination);
247 bool IsExpired (void) const;
256 void ClearPendingPacket (void);
261 uint32_t GetRetries (void) const;
265 void IncrementRetries (void);
269 void ClearRetries (void);
274 void UpdateSeen (void);
285 };
291 Time GetTimeout (void) const;
298 std::list<Ipv4PayloadHeaderPair> m_pending;
300 };
306 typedef std::unordered_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash> Cache;
310 typedef std::unordered_map<Ipv4Address, ArpCache::Entry *, Ipv4AddressHash>::iterator CacheI;
312 virtual void DoDispose (void);
328 void HandleWaitReplyTimeout (void);
335} // namespace ns3
337#endif /* ARP_CACHE_H */
a polymophic address class
Definition: address.h:91
A record that that holds information about an ArpCache entry.
Definition: arp-cache.h:178
void SetIpv4Address(Ipv4Address destination)
Definition: arp-cache.cc:472
std::list< Ipv4PayloadHeaderPair > m_pending
list of pending packets for the entry's IP
Definition: arp-cache.h:298
ArpCache * m_arp
pointer to the ARP cache owning the entry
Definition: arp-cache.h:293
void ClearRetries(void)
Zero the counter of number of retries for an entry.
Definition: arp-cache.cc:551
Ipv4Address m_ipv4Address
entry's IP address
Definition: arp-cache.h:297
Time m_lastSeen
last moment a packet from that address has been seen
Definition: arp-cache.h:295
bool UpdateWaitReply(Ipv4PayloadHeaderPair waiting)
Definition: arp-cache.cc:424
Time GetTimeout(void) const
Returns the entry timeout.
Definition: arp-cache.cc:478
bool IsAlive(void)
Definition: arp-cache.cc:375
Address m_macAddress
entry's MAC address
Definition: arp-cache.h:296
Ipv4PayloadHeaderPair DequeuePending(void)
Definition: arp-cache.cc:510
void MarkPermanent(void)
Changes the state of this entry to Permanent.
Definition: arp-cache.cc:414
bool IsWaitReply(void)
Definition: arp-cache.cc:381
void ClearPendingPacket(void)
Clear the pending packet list.
Definition: arp-cache.cc:526
bool IsDead(void)
Definition: arp-cache.cc:369
ARP cache entry states.
Definition: arp-cache.h:280
Definition: arp-cache.h:282
Definition: arp-cache.h:281
Definition: arp-cache.h:284
Definition: arp-cache.h:283
bool IsPermanent(void)
Definition: arp-cache.cc:387
uint32_t m_retries
rerty counter
Definition: arp-cache.h:299
void MarkDead(void)
Changes the state of this entry to dead.
Definition: arp-cache.cc:395
void IncrementRetries(void)
Increment the counter of number of retries for an entry.
Definition: arp-cache.cc:544
void MarkAlive(Address macAddress)
Definition: arp-cache.cc:404
void SetMacAddress(Address macAddress)
Definition: arp-cache.cc:460
Ipv4Address GetIpv4Address(void) const
Definition: arp-cache.cc:466
void MarkWaitReply(Ipv4PayloadHeaderPair waiting)
Definition: arp-cache.cc:440
void UpdateSeen(void)
Update the entry when seeing a packet.
Definition: arp-cache.cc:532
uint32_t GetRetries(void) const
Definition: arp-cache.cc:538
ArpCacheEntryState_e m_state
state of the entry
Definition: arp-cache.h:294
Address GetMacAddress(void) const
Definition: arp-cache.cc:454
bool IsExpired(void) const
Definition: arp-cache.cc:497
Entry(ArpCache *arp)
Definition: arp-cache.cc:359
An ARP cache.
Definition: arp-cache.h:52
void Remove(ArpCache::Entry *entry)
Remove an entry.
Definition: arp-cache.cc:342
void SetWaitReplyTimeout(Time waitReplyTimeout)
Set the time the entry will be in WAIT_REPLY state.
Definition: arp-cache.cc:148
uint32_t m_maxRetries
max retries for a resolution
Definition: arp-cache.h:321
EventId m_waitReplyTimer
cache alive state timer
Definition: arp-cache.h:319
Time m_aliveTimeout
cache alive state timeout
Definition: arp-cache.h:316
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
Time m_deadTimeout
cache dead state timeout
Definition: arp-cache.h:317
Time m_waitReplyTimeout
cache reply state timeout
Definition: arp-cache.h:318
Ptr< Ipv4Interface > m_interface
Ipv4Interface associated with the cache.
Definition: arp-cache.h:315
void PrintArpCache(Ptr< OutputStreamWrapper > stream)
Print the ARP cache entries.
Definition: arp-cache.cc:260
void SetAliveTimeout(Time aliveTimeout)
Set the time the entry will be in ALIVE state (unless refreshed)
Definition: arp-cache.cc:136
uint32_t m_pendingQueueSize
number of packets waiting for a resolution
Definition: arp-cache.h:329
std::unordered_map< Ipv4Address, ArpCache::Entry *, Ipv4AddressHash > Cache
ARP Cache container.
Definition: arp-cache.h:306
Ptr< Ipv4Interface > GetInterface(void) const
Returns the Ipv4Interface that this ARP cache is associated with.
Definition: arp-cache.cc:129
Time GetAliveTimeout(void) const
Get the time the entry will be in ALIVE state (unless refreshed)
Definition: arp-cache.cc:155
TracedCallback< Ptr< const Packet > > m_dropTrace
trace for packets dropped by the ARP cache queue
Definition: arp-cache.h:331
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
Definition: arp-cache.cc:330
void Flush(void)
Clear the ArpCache of all entries.
Definition: arp-cache.cc:244
virtual void DoDispose(void)
Destructor implementation.
Definition: arp-cache.cc:100
std::unordered_map< Ipv4Address, ArpCache::Entry *, Ipv4AddressHash >::iterator CacheI
ARP Cache container iterator.
Definition: arp-cache.h:310
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
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
Set the NetDevice and Ipv4Interface associated with the ArpCache.
Definition: arp-cache.cc:114
std::list< ArpCache::Entry * > LookupInverse(Address destination)
Do lookup in the ARP cache against a MAC address.
Definition: arp-cache.cc:300
Callback< void, Ptr< const ArpCache >, Ipv4Address > m_arpRequestCallback
reply timeout callback
Definition: arp-cache.h:320
Time GetDeadTimeout(void) const
Get the time the entry will be in DEAD state before being removed.
Definition: arp-cache.cc:161
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
Definition: arp-cache.cc:318
Cache m_arpCache
the ARP cache
Definition: arp-cache.h:330
ArpCache & operator=(ArpCache const &)=delete
Ptr< NetDevice > GetDevice(void) const
Returns the NetDevice that this ARP cache is associated with.
Definition: arp-cache.cc:122
Ptr< NetDevice > m_device
NetDevice associated with the cache.
Definition: arp-cache.h:314
std::pair< Ptr< Packet >, Ipv4Header > Ipv4PayloadHeaderPair
Pair of a packet and an Ipv4 header.
Definition: arp-cache.h:173
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
Time GetWaitReplyTimeout(void) const
Get the time the entry will be in WAIT_REPLY state.
Definition: arp-cache.cc:167
static TypeId GetTypeId(void)
Get the type ID.
Definition: arp-cache.cc:41
void SetDeadTimeout(Time deadTimeout)
Set the time the entry will be in DEAD state before being removed.
Definition: arp-cache.cc:142
ArpCache(ArpCache const &)=delete
Callback template class.
Definition: callback.h:1279
An identifier for simulation events.
Definition: event-id.h:54
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Packet header for IPv4.
Definition: ipv4-header.h:34
A base class which provides memory management and object aggregation.
Definition: object.h:88
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.