13#include "ns3/assert.h"
17#include "ns3/packet.h"
18#include "ns3/simulator.h"
19#include "ns3/trace-source-accessor.h"
20#include "ns3/uinteger.h"
34 .SetGroupName(
"Internet")
35 .AddAttribute(
"AliveTimeout",
36 "When this timeout expires, "
37 "the matching cache entry needs refreshing",
41 .AddAttribute(
"DeadTimeout",
42 "When this timeout expires, "
43 "a new attempt to resolve the matching entry is made",
47 .AddAttribute(
"WaitReplyTimeout",
48 "When this timeout expires, "
49 "the cache entries will be scanned and "
50 "entries in WaitReply state will resend ArpRequest "
51 "unless MaxRetries has been exceeded, "
52 "in which case the entry is marked dead",
56 .AddAttribute(
"MaxRetries",
57 "Number of retransmissions of ArpRequest "
58 "before marking dead",
62 .AddAttribute(
"PendingQueueSize",
63 "The size of the queue for packets pending an arp reply.",
67 .AddTraceSource(
"Drop",
68 "Packet dropped due to ArpCache entry "
69 "in WaitReply expiring.",
71 "ns3::Packet::TracedCallback");
190 bool restartWaitReplyTimer =
false;
200 <<
" expired -- retransmitting arp request since retries = "
203 restartWaitReplyTimer =
true;
210 <<
" expired -- drop since max retries exceeded: "
215 while (pending.first)
218 pending.first->AddHeader(pending.second);
225 if (restartWaitReplyTimer)
245 <<
" due to ArpCache flush");
254 std::ostream* os = stream->GetStream();
258 *os << i->first <<
" dev ";
266 *os << static_cast<int>(
m_device->GetIfIndex());
269 *os <<
" lladdr " << i->second->GetMacAddress();
271 if (i->second->IsAlive())
273 *os <<
" REACHABLE\n";
275 else if (i->second->IsWaitReply())
279 else if (i->second->IsPermanent())
281 *os <<
" PERMANENT\n";
283 else if (i->second->IsAutoGenerated())
285 *os <<
" STATIC_AUTOGENERATED\n";
300 if (i->second->IsAutoGenerated())
302 i->second->ClearPendingPacket();
311std::list<ArpCache::Entry*>
316 std::list<ArpCache::Entry*> entryList;
322 entryList.push_back(entry);
348 entry->SetIpv4Address(to);
359 if ((*i).second == entry)
382 return (m_state == DEAD);
389 return (m_state == ALIVE);
396 return (m_state == WAIT_REPLY);
403 return (m_state == PERMANENT);
410 return (m_state == STATIC_AUTOGENERATED);
417 NS_ASSERT(m_state == ALIVE || m_state == WAIT_REPLY || m_state == DEAD);
428 m_macAddress = macAddress;
451 m_state = STATIC_AUTOGENERATED;
465 if (m_pending.size() >= m_arp->m_pendingQueueSize)
469 m_pending.push_back(waiting);
477 NS_ASSERT(m_state == ALIVE || m_state == DEAD);
479 NS_ASSERT_MSG(waiting.first,
"Can not add a null packet to the ARP queue");
481 m_state = WAIT_REPLY;
482 m_pending.push_back(waiting);
484 m_arp->StartWaitReplyTimer();
498 m_macAddress = macAddress;
505 return m_ipv4Address;
512 m_ipv4Address = destination;
522 return m_arp->GetWaitReplyTimeout();
524 return m_arp->GetDeadTimeout();
526 return m_arp->GetAliveTimeout();
548 if (m_pending.empty())
556 m_pending.pop_front();
a polymophic address class
A record that that holds information about an ArpCache entry.
void SetIpv4Address(Ipv4Address destination)
void MarkAutoGenerated()
Changes the state of this entry to auto-generated.
bool UpdateWaitReply(Ipv4PayloadHeaderPair waiting)
Address GetMacAddress() const
void ClearPendingPacket()
Clear the pending packet list.
void MarkPermanent()
Changes the state of this entry to Permanent.
void ClearRetries()
Zero the counter of number of retries for an entry.
uint32_t GetRetries() const
void UpdateSeen()
Update the entry when seeing a packet.
void IncrementRetries()
Increment the counter of number of retries for an entry.
void MarkAlive(Address macAddress)
void MarkDead()
Changes the state of this entry to dead.
void SetMacAddress(Address macAddress)
void MarkWaitReply(Ipv4PayloadHeaderPair waiting)
Ipv4PayloadHeaderPair DequeuePending()
Ipv4Address GetIpv4Address() const
Time GetTimeout() const
Returns the entry timeout.
Entry(ArpCache *arp)
Constructor.
Time GetWaitReplyTimeout() const
Get the time the entry will be in WAIT_REPLY state.
void Remove(ArpCache::Entry *entry)
Remove an entry.
void SetWaitReplyTimeout(Time waitReplyTimeout)
Set the time the entry will be in WAIT_REPLY state.
void HandleWaitReplyTimeout()
This function is an event handler for the event that the ArpCache wants to check whether it must retr...
Time GetAliveTimeout() const
Get the time the entry will be in ALIVE state (unless refreshed)
uint32_t m_maxRetries
max retries for a resolution
EventId m_waitReplyTimer
cache alive state timer
Time m_aliveTimeout
cache alive state timeout
void DoDispose() override
Destructor implementation.
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...
Time m_deadTimeout
cache dead state timeout
Time m_waitReplyTimeout
cache reply state timeout
Ptr< Ipv4Interface > m_interface
Ipv4Interface associated with the cache.
void PrintArpCache(Ptr< OutputStreamWrapper > stream)
Print the ARP cache entries.
void Flush()
Clear the ArpCache of all entries.
void SetAliveTimeout(Time aliveTimeout)
Set the time the entry will be in ALIVE state (unless refreshed)
uint32_t m_pendingQueueSize
number of packets waiting for a resolution
TracedCallback< Ptr< const Packet > > m_dropTrace
trace for packets dropped by the ARP cache queue
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
Set the NetDevice and Ipv4Interface associated with the ArpCache.
Ptr< Ipv4Interface > GetInterface() const
Returns the Ipv4Interface that this ARP cache is associated with.
std::list< ArpCache::Entry * > LookupInverse(Address destination)
Do lookup in the ARP cache against a MAC address.
Callback< void, Ptr< const ArpCache >, Ipv4Address > m_arpRequestCallback
reply timeout callback
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
Cache m_arpCache
the ARP cache
void RemoveAutoGeneratedEntries()
Clear the ArpCache of all Auto-Generated entries.
Ptr< NetDevice > m_device
NetDevice associated with the cache.
void StartWaitReplyTimer()
This method will schedule a timeout at WaitReplyTimeout interval in the future, unless a timer is alr...
Time GetDeadTimeout() const
Get the time the entry will be in DEAD state before being removed.
static TypeId GetTypeId()
Get the type ID.
std::pair< Ptr< Packet >, Ipv4Header > Ipv4PayloadHeaderPair
Pair of a packet and an Ipv4 header.
void SetDeadTimeout(Time deadTimeout)
Set the time the entry will be in DEAD state before being removed.
Ptr< NetDevice > GetDevice() const
Returns the NetDevice that this ARP cache is associated with.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Ipv4 addresses are stored in host order in this class.
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,...
A base class which provides memory management and object aggregation.
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.