A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::ArpCache Class Reference

An ARP cache. More...

#include "arp-cache.h"

+ Inheritance diagram for ns3::ArpCache:
+ Collaboration diagram for ns3::ArpCache:

Classes

class  Entry
 A record that that holds information about an ArpCache entry. More...
 

Public Types

typedef std::pair< Ptr< Packet >, Ipv4HeaderIpv4PayloadHeaderPair
 Pair of a packet and an Ipv4 header.
 

Public Member Functions

 ArpCache ()
 
 ArpCache (const ArpCache &)=delete
 
 ~ArpCache () override
 
ArpCache::EntryAdd (Ipv4Address to)
 Add an Ipv4Address to this ARP cache.
 
void Flush ()
 Clear the ArpCache of all entries.
 
Time GetAliveTimeout () const
 Get the time the entry will be in ALIVE state (unless refreshed)
 
Time GetDeadTimeout () const
 Get the time the entry will be in DEAD state before being removed.
 
Ptr< NetDeviceGetDevice () const
 Returns the NetDevice that this ARP cache is associated with.
 
Ptr< Ipv4InterfaceGetInterface () const
 Returns the Ipv4Interface that this ARP cache is associated with.
 
Time GetWaitReplyTimeout () const
 Get the time the entry will be in WAIT_REPLY state.
 
ArpCache::EntryLookup (Ipv4Address destination)
 Do lookup in the ARP cache against an IP address.
 
std::list< ArpCache::Entry * > LookupInverse (Address destination)
 Do lookup in the ARP cache against a MAC address.
 
ArpCacheoperator= (const ArpCache &)=delete
 
void PrintArpCache (Ptr< OutputStreamWrapper > stream)
 Print the ARP cache entries.
 
void Remove (ArpCache::Entry *entry)
 Remove an entry.
 
void RemoveAutoGeneratedEntries ()
 Clear the ArpCache of all Auto-Generated entries.
 
void SetAliveTimeout (Time aliveTimeout)
 Set the time the entry will be in ALIVE state (unless refreshed)
 
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 the WaitReply time expires and a retransmission must be sent.
 
void SetDeadTimeout (Time deadTimeout)
 Set the time the entry will be in DEAD state before being removed.
 
void SetDevice (Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
 Set the NetDevice and Ipv4Interface associated with the ArpCache.
 
void SetWaitReplyTimeout (Time waitReplyTimeout)
 Set the time the entry will be in WAIT_REPLY state.
 
void StartWaitReplyTimer ()
 This method will schedule a timeout at WaitReplyTimeout interval in the future, unless a timer is already running for the cache, in which case this method does nothing.
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor.
 
 ~Object () override
 Destructor.
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together.
 
void Dispose ()
 Dispose of this Object.
 
AggregateIterator GetAggregateIterator () const
 Get an iterator to the Objects aggregated to this one.
 
TypeId GetInstanceTypeId () const override
 Get the most derived TypeId for this Object.
 
template<typename T >
Ptr< T > GetObject () const
 Get a pointer to the requested aggregated Object.
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object.
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId.
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object.
 
void Initialize ()
 Invoke DoInitialize on all Objects aggregated to this one.
 
bool IsInitialized () const
 Check if the object has been initialized.
 
void UnidirectionalAggregateObject (Ptr< Object > other)
 Aggregate an Object to another Object.
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor.
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor.
 
uint32_t GetReferenceCount () const
 Get the reference count of the object.
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator.
 
void Ref () const
 Increment the reference count.
 
void Unref () const
 Decrement the reference count.
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor.
 
void GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const
 Get the value of an attribute, raising fatal errors if unsuccessful.
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors.
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful.
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors.
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context.
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context.
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context.
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context.
 

Static Public Member Functions

static TypeId GetTypeId ()
 Get the type ID.
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId ()
 Register this type.
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID.
 

Private Types

typedef std::map< Ipv4Address, ArpCache::Entry * > Cache
 ARP Cache container.
 
typedef std::map< Ipv4Address, ArpCache::Entry * >::iterator CacheI
 ARP Cache container iterator.
 

Private Member Functions

void DoDispose () override
 Destructor implementation.
 
void HandleWaitReplyTimeout ()
 This function is an event handler for the event that the ArpCache wants to check whether it must retry any Arp requests.
 

Private Attributes

Time m_aliveTimeout
 cache alive state timeout
 
Cache m_arpCache
 the ARP cache
 
Callback< void, Ptr< const ArpCache >, Ipv4Addressm_arpRequestCallback
 reply timeout callback
 
Time m_deadTimeout
 cache dead state timeout
 
Ptr< NetDevicem_device
 NetDevice associated with the cache.
 
TracedCallback< Ptr< const Packet > > m_dropTrace
 trace for packets dropped by the ARP cache queue
 
Ptr< Ipv4Interfacem_interface
 Ipv4Interface associated with the cache.
 
uint32_t m_maxRetries
 max retries for a resolution
 
uint32_t m_pendingQueueSize
 number of packets waiting for a resolution
 
Time m_waitReplyTimeout
 cache reply state timeout
 
EventId m_waitReplyTimer
 cache alive state timer
 

Additional Inherited Members

- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object.
 
virtual void DoInitialize ()
 Initialize() implementation.
 
virtual void NotifyNewAggregate ()
 Notify all Objects aggregated to this one of a new Object being aggregated.
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes.
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed.
 

Detailed Description

An ARP cache.

A cached lookup table for translating layer 3 addresses to layer 2. This implementation does lookups from IPv4 to a MAC address

Definition at line 41 of file arp-cache.h.

Member Typedef Documentation

◆ Cache

typedef std::map<Ipv4Address, ArpCache::Entry*> ns3::ArpCache::Cache
private

ARP Cache container.

Definition at line 313 of file arp-cache.h.

◆ CacheI

typedef std::map<Ipv4Address,ArpCache::Entry*>::iterator ns3::ArpCache::CacheI
private

ARP Cache container iterator.

Definition at line 317 of file arp-cache.h.

◆ Ipv4PayloadHeaderPair

Pair of a packet and an Ipv4 header.

Definition at line 167 of file arp-cache.h.

Constructor & Destructor Documentation

◆ ArpCache() [1/2]

ns3::ArpCache::ArpCache ( )

Definition at line 75 of file arp-cache.cc.

References NS_LOG_FUNCTION.

◆ ~ArpCache()

ns3::ArpCache::~ArpCache ( )
override

Definition at line 82 of file arp-cache.cc.

References NS_LOG_FUNCTION.

◆ ArpCache() [2/2]

ns3::ArpCache::ArpCache ( const ArpCache & )
delete

Member Function Documentation

◆ Add()

ArpCache::Entry * ns3::ArpCache::Add ( Ipv4Address to)

Add an Ipv4Address to this ARP cache.

Parameters
tothe destination address of the ARP entry.
Returns
A pointer to a new ARP Entry.

Definition at line 341 of file arp-cache.cc.

References m_arpCache, NS_ASSERT, and NS_LOG_FUNCTION.

◆ DoDispose()

void ns3::ArpCache::DoDispose ( )
overrideprivatevirtual

Destructor implementation.

This method is called by Dispose() or by the Object's destructor, whichever comes first.

Subclasses are expected to implement their real destruction code in an overridden version of this method and chain up to their parent's implementation once they are done. i.e, for simplicity, the destructor of every subclass should be empty and its content should be moved to the associated DoDispose() method.

It is safe to call GetObject() from within this method.

Reimplemented from ns3::Object.

Definition at line 88 of file arp-cache.cc.

References ns3::EventId::Cancel(), ns3::Object::DoDispose(), Flush(), ns3::EventId::IsPending(), m_device, m_interface, m_waitReplyTimer, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ Flush()

void ns3::ArpCache::Flush ( )

Clear the ArpCache of all entries.

Definition at line 234 of file arp-cache.cc.

References ns3::EventId::Cancel(), ns3::EventId::IsPending(), m_arpCache, m_waitReplyTimer, ns3::Simulator::Now(), NS_LOG_FUNCTION, and NS_LOG_LOGIC.

Referenced by ns3::ArpL3Protocol::CreateCache(), and DoDispose().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetAliveTimeout()

Time ns3::ArpCache::GetAliveTimeout ( ) const

Get the time the entry will be in ALIVE state (unless refreshed)

Returns
the Alive state timeout

Definition at line 145 of file arp-cache.cc.

References m_aliveTimeout, and NS_LOG_FUNCTION.

◆ GetDeadTimeout()

Time ns3::ArpCache::GetDeadTimeout ( ) const

Get the time the entry will be in DEAD state before being removed.

Returns
the Dead state timeout

Definition at line 152 of file arp-cache.cc.

References m_deadTimeout, and NS_LOG_FUNCTION.

◆ GetDevice()

Ptr< NetDevice > ns3::ArpCache::GetDevice ( ) const

Returns the NetDevice that this ARP cache is associated with.

Returns
The NetDevice that this ARP cache is associated with

Definition at line 110 of file arp-cache.cc.

References m_device, and NS_LOG_FUNCTION.

◆ GetInterface()

Ptr< Ipv4Interface > ns3::ArpCache::GetInterface ( ) const

Returns the Ipv4Interface that this ARP cache is associated with.

Returns
the Ipv4Interface that this ARP cache is associated with

Definition at line 117 of file arp-cache.cc.

References m_interface, and NS_LOG_FUNCTION.

◆ GetTypeId()

TypeId ns3::ArpCache::GetTypeId ( )
static

Get the type ID.

Returns
the object TypeId

Definition at line 30 of file arp-cache.cc.

References m_aliveTimeout, m_deadTimeout, m_dropTrace, m_maxRetries, m_pendingQueueSize, m_waitReplyTimeout, ns3::MakeTimeAccessor(), ns3::MakeTimeChecker(), ns3::MakeTraceSourceAccessor(), ns3::MakeUintegerAccessor(), ns3::MakeUintegerChecker(), ns3::Seconds(), and ns3::TypeId::SetParent().

+ Here is the call graph for this function:

◆ GetWaitReplyTimeout()

Time ns3::ArpCache::GetWaitReplyTimeout ( ) const

Get the time the entry will be in WAIT_REPLY state.

Returns
the WAIT_REPLY state timeout

Definition at line 159 of file arp-cache.cc.

References m_waitReplyTimeout, and NS_LOG_FUNCTION.

◆ HandleWaitReplyTimeout()

void ns3::ArpCache::HandleWaitReplyTimeout ( )
private

This function is an event handler for the event that the ArpCache wants to check whether it must retry any Arp requests.

If there are no Arp requests pending, this event is not scheduled.

Definition at line 186 of file arp-cache.cc.

References ns3::ArpCache::Entry::ClearRetries(), ns3::ArpCache::Entry::DequeuePending(), ns3::ArpCache::Entry::GetIpv4Address(), ns3::ArpCache::Entry::GetRetries(), HandleWaitReplyTimeout(), ns3::ArpCache::Entry::IncrementRetries(), ns3::ArpCache::Entry::IsWaitReply(), m_arpCache, m_arpRequestCallback, m_device, m_dropTrace, m_maxRetries, m_waitReplyTimeout, m_waitReplyTimer, ns3::ArpCache::Entry::MarkDead(), ns3::Simulator::Now(), NS_LOG_FUNCTION, NS_LOG_LOGIC, and ns3::Simulator::Schedule().

Referenced by HandleWaitReplyTimeout(), and StartWaitReplyTimer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Lookup()

ArpCache::Entry * ns3::ArpCache::Lookup ( Ipv4Address destination)

Do lookup in the ARP cache against an IP address.

Parameters
destinationThe destination IPv4 address to lookup the MAC address of
Returns
An ArpCache::Entry with info about layer 2

Definition at line 329 of file arp-cache.cc.

References m_arpCache, and NS_LOG_FUNCTION.

◆ LookupInverse()

std::list< ArpCache::Entry * > ns3::ArpCache::LookupInverse ( Address destination)

Do lookup in the ARP cache against a MAC address.

Parameters
destinationThe destination MAC address to lookup of
Returns
A std::list of ArpCache::Entry with info about layer 2

Definition at line 312 of file arp-cache.cc.

References ns3::ArpCache::Entry::GetMacAddress(), m_arpCache, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ operator=()

ArpCache & ns3::ArpCache::operator= ( const ArpCache & )
delete

◆ PrintArpCache()

void ns3::ArpCache::PrintArpCache ( Ptr< OutputStreamWrapper > stream)

Print the ARP cache entries.

Parameters
streamthe ostream the ARP cache entries is printed to

Definition at line 251 of file arp-cache.cc.

References ns3::Names::FindName(), m_arpCache, m_device, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ Remove()

void ns3::ArpCache::Remove ( ArpCache::Entry * entry)

Remove an entry.

Parameters
entrypointer to delete it from the list

Definition at line 353 of file arp-cache.cc.

References ns3::ArpCache::Entry::ClearPendingPacket(), m_arpCache, NS_LOG_FUNCTION, and NS_LOG_WARN.

+ Here is the call graph for this function:

◆ RemoveAutoGeneratedEntries()

void ns3::ArpCache::RemoveAutoGeneratedEntries ( )

Clear the ArpCache of all Auto-Generated entries.

Definition at line 295 of file arp-cache.cc.

References m_arpCache, and NS_LOG_FUNCTION.

◆ SetAliveTimeout()

void ns3::ArpCache::SetAliveTimeout ( Time aliveTimeout)

Set the time the entry will be in ALIVE state (unless refreshed)

Parameters
aliveTimeoutthe Alive state timeout

Definition at line 124 of file arp-cache.cc.

References m_aliveTimeout, and NS_LOG_FUNCTION.

◆ SetArpRequestCallback()

void ns3::ArpCache::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 the WaitReply time expires and a retransmission must be sent.

Parameters
arpRequestCallbackCallback for transmitting an Arp request.

Definition at line 166 of file arp-cache.cc.

References m_arpRequestCallback, and NS_LOG_FUNCTION.

◆ SetDeadTimeout()

void ns3::ArpCache::SetDeadTimeout ( Time deadTimeout)

Set the time the entry will be in DEAD state before being removed.

Parameters
deadTimeoutthe Dead state timeout

Definition at line 131 of file arp-cache.cc.

References m_deadTimeout, and NS_LOG_FUNCTION.

◆ SetDevice()

void ns3::ArpCache::SetDevice ( Ptr< NetDevice > device,
Ptr< Ipv4Interface > interface )

Set the NetDevice and Ipv4Interface associated with the ArpCache.

Parameters
deviceThe hardware NetDevice associated with this ARP cache
interfacethe Ipv4Interface associated with this ARP cache

Definition at line 102 of file arp-cache.cc.

References m_device, m_interface, and NS_LOG_FUNCTION.

◆ SetWaitReplyTimeout()

void ns3::ArpCache::SetWaitReplyTimeout ( Time waitReplyTimeout)

Set the time the entry will be in WAIT_REPLY state.

Parameters
waitReplyTimeoutthe WAIT_REPLY state timeout

Definition at line 138 of file arp-cache.cc.

References m_waitReplyTimeout, and NS_LOG_FUNCTION.

◆ StartWaitReplyTimer()

void ns3::ArpCache::StartWaitReplyTimer ( )

This method will schedule a timeout at WaitReplyTimeout interval in the future, unless a timer is already running for the cache, in which case this method does nothing.

Definition at line 173 of file arp-cache.cc.

References HandleWaitReplyTimeout(), ns3::EventId::IsPending(), m_waitReplyTimeout, m_waitReplyTimer, ns3::Simulator::Now(), NS_LOG_FUNCTION, NS_LOG_LOGIC, and ns3::Simulator::Schedule().

+ Here is the call graph for this function:

Member Data Documentation

◆ m_aliveTimeout

Time ns3::ArpCache::m_aliveTimeout
private

cache alive state timeout

Definition at line 323 of file arp-cache.h.

Referenced by GetAliveTimeout(), GetTypeId(), and SetAliveTimeout().

◆ m_arpCache

Cache ns3::ArpCache::m_arpCache
private

◆ m_arpRequestCallback

Callback<void, Ptr<const ArpCache>, Ipv4Address> ns3::ArpCache::m_arpRequestCallback
private

reply timeout callback

Definition at line 328 of file arp-cache.h.

Referenced by HandleWaitReplyTimeout(), and SetArpRequestCallback().

◆ m_deadTimeout

Time ns3::ArpCache::m_deadTimeout
private

cache dead state timeout

Definition at line 324 of file arp-cache.h.

Referenced by GetDeadTimeout(), GetTypeId(), and SetDeadTimeout().

◆ m_device

Ptr<NetDevice> ns3::ArpCache::m_device
private

NetDevice associated with the cache.

Definition at line 321 of file arp-cache.h.

Referenced by DoDispose(), GetDevice(), HandleWaitReplyTimeout(), PrintArpCache(), and SetDevice().

◆ m_dropTrace

TracedCallback<Ptr<const Packet> > ns3::ArpCache::m_dropTrace
private

trace for packets dropped by the ARP cache queue

Definition at line 340 of file arp-cache.h.

Referenced by GetTypeId(), and HandleWaitReplyTimeout().

◆ m_interface

Ptr<Ipv4Interface> ns3::ArpCache::m_interface
private

Ipv4Interface associated with the cache.

Definition at line 322 of file arp-cache.h.

Referenced by DoDispose(), GetInterface(), and SetDevice().

◆ m_maxRetries

uint32_t ns3::ArpCache::m_maxRetries
private

max retries for a resolution

Definition at line 329 of file arp-cache.h.

Referenced by GetTypeId(), and HandleWaitReplyTimeout().

◆ m_pendingQueueSize

uint32_t ns3::ArpCache::m_pendingQueueSize
private

number of packets waiting for a resolution

Definition at line 337 of file arp-cache.h.

Referenced by GetTypeId().

◆ m_waitReplyTimeout

Time ns3::ArpCache::m_waitReplyTimeout
private

cache reply state timeout

Definition at line 325 of file arp-cache.h.

Referenced by GetTypeId(), GetWaitReplyTimeout(), HandleWaitReplyTimeout(), SetWaitReplyTimeout(), and StartWaitReplyTimer().

◆ m_waitReplyTimer

EventId ns3::ArpCache::m_waitReplyTimer
private

cache alive state timer

Definition at line 326 of file arp-cache.h.

Referenced by DoDispose(), Flush(), HandleWaitReplyTimeout(), and StartWaitReplyTimer().


The documentation for this class was generated from the following files: