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 .SetGroupName (
"Internet")
45 .AddAttribute (
"AliveTimeout",
46 "When this timeout expires, "
47 "the matching cache entry needs refreshing",
51 .AddAttribute (
"DeadTimeout",
52 "When this timeout expires, "
53 "a new attempt to resolve the matching entry is made",
57 .AddAttribute (
"WaitReplyTimeout",
58 "When this timeout expires, "
59 "the cache entries will be scanned and "
60 "entries in WaitReply state will resend ArpRequest "
61 "unless MaxRetries has been exceeded, "
62 "in which case the entry is marked dead",
66 .AddAttribute (
"MaxRetries",
67 "Number of retransmissions of ArpRequest "
68 "before marking dead",
71 MakeUintegerChecker<uint32_t> ())
72 .AddAttribute (
"PendingQueueSize",
73 "The size of the queue for packets pending an arp reply.",
76 MakeUintegerChecker<uint32_t> ())
77 .AddTraceSource (
"Drop",
78 "Packet dropped due to ArpCache entry "
79 "in WaitReply expiring.",
81 "ns3::Packet::TracedCallback")
198 bool restartWaitReplyTimer =
false;
208 " expired -- retransmitting arp request since retries = " <<
211 restartWaitReplyTimer =
true;
218 " expired -- drop since max retries exceeded: " <<
223 while (pending.first != 0)
226 pending.first->AddHeader (pending.second);
234 if (restartWaitReplyTimer)
266 *os << i->first <<
" dev ";
274 *os << static_cast<int> (
m_device->GetIfIndex ());
277 *os <<
" lladdr " << i->second->GetMacAddress ();
279 if (i->second->IsAlive ())
281 *os <<
" REACHABLE\n";
283 else if (i->second->IsWaitReply ())
287 else if (i->second->IsPermanent ())
289 *os <<
" PERMANENT\n";
298 std::list<ArpCache::Entry *>
303 std::list<ArpCache::Entry *> entryList;
309 entryList.push_back (entry);
336 entry->SetIpv4Address (to);
347 if ((*i).second == entry)
371 return (m_state == DEAD) ?
true :
false;
377 return (m_state == ALIVE) ?
true :
false;
383 return (m_state == WAIT_REPLY) ?
true :
false;
389 return (m_state == PERMANENT) ?
true :
false;
397 NS_ASSERT (m_state == ALIVE || m_state == WAIT_REPLY || m_state == DEAD);
407 m_macAddress = macAddress;
431 if (m_pending.size () >= m_arp->m_pendingQueueSize)
435 m_pending.push_back (waiting);
442 NS_ASSERT (m_state == ALIVE || m_state == DEAD);
444 NS_ASSERT_MSG (waiting.first,
"Can not add a null packet to the ARP queue");
446 m_state = WAIT_REPLY;
447 m_pending.push_back (waiting);
449 m_arp->StartWaitReplyTimer ();
462 m_macAddress = macAddress;
468 return m_ipv4Address;
474 m_ipv4Address = destination;
482 return m_arp->GetWaitReplyTimeout ();
484 return m_arp->GetDeadTimeout ();
486 return m_arp->GetAliveTimeout ();
512 if (m_pending.empty ())
520 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...
void MarkPermanent(void)
Changes the state of this entry to Permanent.
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.
void SetMacAddresss(Address macAddress)
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.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
virtual void DoDispose(void)
Destructor implementation.
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.
static Time Max()
Maximum representable Time.
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...
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
AttributeValue implementation for Time.
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
void MarkWaitReply(Ipv4PayloadHeaderPair waiting)
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.
void ClearPendingPacket(void)
Clear the pending packet list.
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.
void Remove(ArpCache::Entry *entry)
Remove an entry.
Entry(ArpCache *arp)
Constructor.
Time GetTimeout(void) const
Returns the entry timeout.
void UpdateSeen(void)
Update the entry when seeing a packet.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
TracedCallback< Ptr< const Packet > > m_dropTrace
trace for packets dropped by the ARP cache queue
bool UpdateWaitReply(Ipv4PayloadHeaderPair waiting)
Ipv4 addresses are stored in host order in this class.
Ipv4PayloadHeaderPair DequeuePending(void)
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
sgi::hash_map< Ipv4Address, ArpCache::Entry *, Ipv4AddressHash >::iterator CacheI
ARP Cache container iterator.
std::pair< Ptr< Packet >, Ipv4Header > Ipv4PayloadHeaderPair
Pair of a packet and an Ipv4 header.
#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.
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.
std::list< ArpCache::Entry * > LookupInverse(Address destination)
Do lookup in the ARP cache against a MAC address.
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)
Set the parent TypeId.
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.