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"
27 #include "ns3/names.h"
44 .AddAttribute (
"AliveTimeout",
45 "When this timeout expires, "
46 "the matching cache entry needs refreshing",
50 .AddAttribute (
"DeadTimeout",
51 "When this timeout expires, "
52 "a new attempt to resolve the matching entry is made",
56 .AddAttribute (
"WaitReplyTimeout",
57 "When this timeout expires, "
58 "the cache entries will be scanned and "
59 "entries in WaitReply state will resend ArpRequest "
60 "unless MaxRetries has been exceeded, "
61 "in which case the entry is marked dead",
65 .AddAttribute (
"MaxRetries",
66 "Number of retransmissions of ArpRequest "
67 "before marking dead",
70 MakeUintegerChecker<uint32_t> ())
71 .AddAttribute (
"PendingQueueSize",
72 "The size of the queue for packets pending an arp reply.",
75 MakeUintegerChecker<uint32_t> ())
76 .AddTraceSource (
"Drop",
77 "Packet dropped due to ArpCache entry "
78 "in WaitReply expiring.",
80 "ns3::Packet::TracedCallback")
197 bool restartWaitReplyTimer =
false;
207 " expired -- retransmitting arp request since retries = " <<
210 restartWaitReplyTimer =
true;
217 " expired -- drop since max retries exceeded: " <<
231 if (restartWaitReplyTimer)
263 *os << i->first <<
" dev ";
271 *os << static_cast<int> (
m_device->GetIfIndex ());
274 *os <<
" lladdr " << i->second->GetMacAddress ();
276 if (i->second->IsAlive ())
278 *os <<
" REACHABLE\n";
280 else if (i->second->IsWaitReply ())
311 entry->SetIpv4Address (to);
328 return (m_state == DEAD) ?
true :
false;
334 return (m_state == ALIVE) ?
true :
false;
340 return (m_state == WAIT_REPLY) ?
true :
false;
357 m_macAddress = macAddress;
372 if (m_pending.size () >= m_arp->m_pendingQueueSize)
376 m_pending.push_back (waiting);
383 NS_ASSERT (m_state == ALIVE || m_state == DEAD);
385 m_state = WAIT_REPLY;
386 m_pending.push_back (waiting);
388 m_arp->StartWaitReplyTimer ();
401 return m_ipv4Address;
407 m_ipv4Address = destination;
415 return m_arp->GetWaitReplyTimeout ();
417 return m_arp->GetDeadTimeout ();
419 return m_arp->GetAliveTimeout ();
443 if (m_pending.empty ())
450 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...
Simulation virtual time values and 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)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
virtual void DoDispose(void)
Destructor implementation.
static TypeId GetTypeId(void)
Get the type ID.
void PrintArpCache(Ptr< OutputStreamWrapper > stream)
Print the ARP cache entries.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Callback< void, Ptr< const ArpCache >, Ipv4Address > m_arpRequestCallback
reply timeout callback
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific 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)
Destructor implementation.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
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
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Cache m_arpCache
the ARP cache
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
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...
AttributeValue implementation for 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)
Use NS_LOG to output a message of level LOG_LOGIC.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
static Time Now(void)
Return the current simulation virtual 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)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< Packet > DequeuePending(void)
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and...
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< 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
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.