|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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"
45 .SetGroupName (
"Internet")
46 .AddAttribute (
"AliveTimeout",
47 "When this timeout expires, "
48 "the matching cache entry needs refreshing",
52 .AddAttribute (
"DeadTimeout",
53 "When this timeout expires, "
54 "a new attempt to resolve the matching entry is made",
58 .AddAttribute (
"WaitReplyTimeout",
59 "When this timeout expires, "
60 "the cache entries will be scanned and "
61 "entries in WaitReply state will resend ArpRequest "
62 "unless MaxRetries has been exceeded, "
63 "in which case the entry is marked dead",
67 .AddAttribute (
"MaxRetries",
68 "Number of retransmissions of ArpRequest "
69 "before marking dead",
72 MakeUintegerChecker<uint32_t> ())
73 .AddAttribute (
"PendingQueueSize",
74 "The size of the queue for packets pending an arp reply.",
77 MakeUintegerChecker<uint32_t> ())
78 .AddTraceSource (
"Drop",
79 "Packet dropped due to ArpCache entry "
80 "in WaitReply expiring.",
82 "ns3::Packet::TracedCallback")
199 bool restartWaitReplyTimer =
false;
209 " expired -- retransmitting arp request since retries = " <<
212 restartWaitReplyTimer =
true;
219 " expired -- drop since max retries exceeded: " <<
224 while (pending.first != 0)
227 pending.first->AddHeader (pending.second);
235 if (restartWaitReplyTimer)
267 *os << i->first <<
" dev ";
278 *os <<
" lladdr " << i->second->GetMacAddress ();
280 if (i->second->IsAlive ())
282 *os <<
" REACHABLE\n";
284 else if (i->second->IsWaitReply ())
288 else if (i->second->IsPermanent ())
290 *os <<
" PERMANENT\n";
299 std::list<ArpCache::Entry *>
304 std::list<ArpCache::Entry *> entryList;
310 entryList.push_back (entry);
348 if ((*i).second == entry)
372 return (m_state == DEAD) ? true :
false;
378 return (m_state == ALIVE) ? true :
false;
384 return (m_state == WAIT_REPLY) ? true :
false;
390 return (m_state == PERMANENT) ? true :
false;
398 NS_ASSERT (m_state == ALIVE || m_state == WAIT_REPLY || m_state == DEAD);
408 m_macAddress = macAddress;
432 if (m_pending.size () >= m_arp->m_pendingQueueSize)
436 m_pending.push_back (waiting);
443 NS_ASSERT (m_state == ALIVE || m_state == DEAD);
445 NS_ASSERT_MSG (waiting.first,
"Can not add a null packet to the ARP queue");
447 m_state = WAIT_REPLY;
448 m_pending.push_back (waiting);
450 m_arp->StartWaitReplyTimer ();
463 m_macAddress = macAddress;
469 return m_ipv4Address;
475 m_ipv4Address = destination;
483 return m_arp->GetWaitReplyTimeout ();
485 return m_arp->GetDeadTimeout ();
487 return m_arp->GetAliveTimeout ();
513 if (m_pending.empty ())
521 m_pending.pop_front ();
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void ClearRetries(void)
Zero the counter of number of retries for an entry.
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
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< Ipv4Interface > GetInterface(void) const
Returns the Ipv4Interface that this ARP cache is associated with.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
uint32_t m_pendingQueueSize
number of packets waiting for a resolution
Entry(ArpCache *arp)
Constructor.
bool UpdateWaitReply(Ipv4PayloadHeaderPair waiting)
uint32_t GetId(void) const
static Time Now(void)
Return the current simulation virtual time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
A record that that holds information about an ArpCache entry.
void Flush(void)
Clear the ArpCache of all entries.
Time GetDeadTimeout(void) const
Get the time the entry will be in DEAD state before being removed.
static TypeId GetTypeId(void)
Get the type ID.
Cache m_arpCache
the ARP cache
Callback< void, Ptr< const ArpCache >, Ipv4Address > m_arpRequestCallback
reply timeout callback
void SetMacAddress(Address macAddress)
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Time GetWaitReplyTimeout(void) const
Get the time the entry will be in WAIT_REPLY state.
Ipv4 addresses are stored in host order in this class.
std::list< ArpCache::Entry * > LookupInverse(Address destination)
Do lookup in the ARP cache against a MAC address.
Ipv4Address GetIpv4Address(void) const
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
void StartWaitReplyTimer(void)
This method will schedule a timeout at WaitReplyTimeout interval in the future, unless a timer is alr...
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
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...
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< NetDevice > GetDevice(void) const
Returns the NetDevice that this ARP cache is associated with.
Ptr< Ipv4Interface > m_interface
Ipv4Interface associated with the cache.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
a polymophic address class
A base class which provides memory management and object aggregation.
void SetIpv4Address(Ipv4Address destination)
Time GetTimeout(void) const
Returns the entry timeout.
virtual Ptr< Node > GetNode(void) const =0
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,...
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
ArpCache::Entry * Add(Ipv4Address to)
Add an Ipv4Address to this ARP cache.
void HandleWaitReplyTimeout(void)
This function is an event handler for the event that the ArpCache wants to check whether it must retr...
Simulation virtual time values and global simulation resolution.
Address GetMacAddress(void) const
void PrintArpCache(Ptr< OutputStreamWrapper > stream)
Print the ARP cache entries.
void MarkDead(void)
Changes the state of this entry to dead.
void SetAliveTimeout(Time aliveTimeout)
Set the time the entry will be in ALIVE state (unless refreshed)
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< NetDevice > m_device
NetDevice associated with the cache.
std::pair< Ptr< Packet >, Ipv4Header > Ipv4PayloadHeaderPair
Pair of a packet and an Ipv4 header.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
uint32_t GetRetries(void) const
void MarkWaitReply(Ipv4PayloadHeaderPair waiting)
void ClearPendingPacket(void)
Clear the pending packet list.
virtual void DoDispose(void)
Destructor implementation.
void MarkAlive(Address macAddress)
Ipv4PayloadHeaderPair DequeuePending(void)
#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 IncrementRetries(void)
Increment the counter of number of retries for an entry.
Time GetAliveTimeout(void) const
Get the time the entry will be in ALIVE state (unless refreshed)
void MarkPermanent(void)
Changes the state of this entry to Permanent.
AttributeValue implementation for Time.
std::unordered_map< Ipv4Address, ArpCache::Entry *, Ipv4AddressHash >::iterator CacheI
ARP Cache container iterator.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
Hold an unsigned integer type.
Time m_aliveTimeout
cache alive state timeout
bool IsExpired(void) const
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
void SetWaitReplyTimeout(Time waitReplyTimeout)
Set the time the entry will be in WAIT_REPLY state.
void UpdateSeen(void)
Update the entry when seeing a packet.
void Remove(ArpCache::Entry *entry)
Remove an entry.
Time m_waitReplyTimeout
cache reply state timeout
virtual uint32_t GetIfIndex(void) const =0
Time m_deadTimeout
cache dead state timeout
virtual void DoDispose(void)
Destructor implementation.
EventId m_waitReplyTimer
cache alive state timer
TracedCallback< Ptr< const Packet > > m_dropTrace
trace for packets dropped by the ARP cache queue
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
void SetDeadTimeout(Time deadTimeout)
Set the time the entry will be in DEAD state before being removed.