20 #include "ns3/assert.h"
21 #include "ns3/packet.h"
22 #include "ns3/simulator.h"
23 #include "ns3/uinteger.h"
26 #include "ns3/trace-source-accessor.h"
44 .AddAttribute (
"AliveTimeout",
45 "When this timeout expires, the matching cache entry needs refreshing",
49 .AddAttribute (
"DeadTimeout",
50 "When this timeout expires, a new attempt to resolve the matching entry is made",
54 .AddAttribute (
"WaitReplyTimeout",
55 "When this timeout expires, the cache entries will be scanned and entries in WaitReply state will resend ArpRequest unless MaxRetries has been exceeded, in which case the entry is marked dead",
59 .AddAttribute (
"MaxRetries",
60 "Number of retransmissions of ArpRequest before marking dead",
63 MakeUintegerChecker<uint32_t> ())
64 .AddAttribute (
"PendingQueueSize",
65 "The size of the queue for packets pending an arp reply.",
68 MakeUintegerChecker<uint32_t> ())
69 .AddTraceSource (
"Drop",
70 "Packet dropped due to ArpCache entry in WaitReply expiring.",
188 bool restartWaitReplyTimer =
false;
198 " expired -- retransmitting arp request since retries = " <<
201 restartWaitReplyTimer =
true;
208 " expired -- drop since max retries exceeded: " <<
222 if (restartWaitReplyTimer)
266 entry->SetIpv4Address (to);
283 return (m_state == DEAD) ?
true :
false;
289 return (m_state == ALIVE) ?
true :
false;
295 return (m_state == WAIT_REPLY) ?
true :
false;
312 m_macAddress = macAddress;
327 if (m_pending.size () >= m_arp->m_pendingQueueSize)
331 m_pending.push_back (waiting);
338 NS_ASSERT (m_state == ALIVE || m_state == DEAD);
340 m_state = WAIT_REPLY;
341 m_pending.push_back (waiting);
343 m_arp->StartWaitReplyTimer ();
357 return m_ipv4Address;
363 m_ipv4Address = destination;
371 return m_arp->GetWaitReplyTimeout ();
373 return m_arp->GetDeadTimeout ();
375 return m_arp->GetAliveTimeout ();
399 if (m_pending.empty ())
406 m_pending.pop_front ();
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
Set the NetDevice and Ipv4Interface associated with the ArpCache.
uint32_t m_maxRetries
max retries for a resolution
void StartWaitReplyTimer(void)
This method will schedule a timeout at WaitReplyTimeout interval in the future, unless a timer is alr...
keep track of time values and allow control of global simulation resolution
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...
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
static TypeId GetTypeId(void)
Get the type ID.
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
#define NS_ASSERT(condition)
Callback< void, Ptr< const ArpCache >, Ipv4Address > m_arpRequestCallback
reply timeout callback
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
#define NS_LOG_COMPONENT_DEFINE(name)
Time GetDeadTimeout(void) const
Get the time the entry will be in DEAD state before being removed.
Ptr< NetDevice > GetDevice(void) const
Returns the NetDevice that this ARP cache is associated with.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
bool IsRunning(void) const
This method is syntactic sugar for the ns3::Simulator::isExpired method.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
EventId m_waitReplyTimer
cache alive state timer
a polymophic address class
Cache m_arpCache
the ARP cache
double GetSeconds(void) const
void SetIpv4Address(Ipv4Address destination)
void HandleWaitReplyTimeout(void)
This function is an event handler for the event that the ArpCache wants to check whether it must retr...
hold objects of type ns3::Time
void MarkWaitReply(Ptr< Packet > waiting)
Hold an unsigned integer type.
uint32_t GetRetries(void) const
Ptr< Ipv4Interface > m_interface
Ipv4Interface associated with the cache.
bool IsExpired(void) const
Ipv4Address GetIpv4Address(void) const
Time m_waitReplyTimeout
cache reply state timeout
#define NS_LOG_LOGIC(msg)
Address GetMacAddress(void) const
void SetDeadTimeout(Time deadTimeout)
Set the time the entry will be in DEAD state before being removed.
void SetAliveTimeout(Time aliveTimeout)
Set the time the entry will be in ALIVE state (unless refreshed)
Ptr< Ipv4Interface > GetInterface(void) const
Returns the Ipv4Interface that this ARP cache is associated with.
static void Remove(const EventId &id)
Remove an event from the event list.
void IncrementRetries(void)
Increment the counter of number of retries for an entry.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void MarkAlive(Address macAddress)
Time GetAliveTimeout(void) const
Get the time the entry will be in ALIVE state (unless refreshed)
A record that that holds information about an ArpCache entry.
static Time Now(void)
Return the "current simulation time".
void Flush(void)
Clear the ArpCache of all entries.
Entry(ArpCache *arp)
Constructor.
Time GetTimeout(void) const
Returns the entry timeout.
void UpdateSeen(void)
Update the entry when seeing a packet.
TracedCallback< Ptr< const Packet > > m_dropTrace
trace for packets dropped by the ARP cache queue
bool UpdateWaitReply(Ptr< Packet > waiting)
Ipv4 addresses are stored in host order in this class.
sgi::hash_map< Ipv4Address, ArpCache::Entry *, Ipv4AddressHash >::iterator CacheI
ARP Cache container iterator.
#define NS_LOG_DEBUG(msg)
Ptr< Packet > DequeuePending(void)
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::cancel method.
Time GetWaitReplyTimeout(void) const
Get the time the entry will be in WAIT_REPLY state.
void ClearRetries(void)
Zero the counter of number of retries for an entry.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Ptr< NetDevice > m_device
NetDevice associated with the cache.
void MarkDead(void)
Changes the state of this entry to dead.
Time m_deadTimeout
cache dead state timeout
a base class which provides memory management and object aggregation
uint32_t m_pendingQueueSize
number of packets waiting for a resolution
void SetWaitReplyTimeout(Time waitReplyTimeout)
Set the time the entry will be in WAIT_REPLY state.
Time m_aliveTimeout
cache alive state timeout
a unique identifier for an interface.
TypeId SetParent(TypeId tid)