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" 
   28 #include "arp-cache.h" 
   29 #include "arp-header.h" 
   30 #include "ipv4-interface.h" 
   36 NS_OBJECT_ENSURE_REGISTERED (ArpCache);
 
   39 ArpCache::GetTypeId (
void)
 
   41   static TypeId tid = TypeId (
"ns3::ArpCache")
 
   43     .AddAttribute (
"AliveTimeout",
 
   44                    "When this timeout expires, the matching cache entry needs refreshing",
 
   46                    MakeTimeAccessor (&ArpCache::m_aliveTimeout),
 
   48     .AddAttribute (
"DeadTimeout",
 
   49                    "When this timeout expires, a new attempt to resolve the matching entry is made",
 
   51                    MakeTimeAccessor (&ArpCache::m_deadTimeout),
 
   53     .AddAttribute (
"WaitReplyTimeout",
 
   54                    "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",
 
   56                    MakeTimeAccessor (&ArpCache::m_waitReplyTimeout),
 
   58     .AddAttribute (
"MaxRetries",
 
   59                    "Number of retransmissions of ArpRequest before marking dead",
 
   61                    MakeUintegerAccessor (&ArpCache::m_maxRetries),
 
   62                    MakeUintegerChecker<uint32_t> ())
 
   63     .AddAttribute (
"PendingQueueSize",
 
   64                    "The size of the queue for packets pending an arp reply.",
 
   66                    MakeUintegerAccessor (&ArpCache::m_pendingQueueSize),
 
   67                    MakeUintegerChecker<uint32_t> ())
 
   68     .AddTraceSource (
"Drop",
 
   69                      "Packet dropped due to ArpCache entry in WaitReply expiring.",
 
   82 ArpCache::~ArpCache ()
 
  106   m_interface = interface;
 
  124 ArpCache::SetAliveTimeout (
Time aliveTimeout)
 
  127   m_aliveTimeout = aliveTimeout;
 
  130 ArpCache::SetDeadTimeout (Time deadTimeout)
 
  133   m_deadTimeout = deadTimeout;
 
  136 ArpCache::SetWaitReplyTimeout (Time waitReplyTimeout)
 
  139   m_waitReplyTimeout = waitReplyTimeout;
 
  143 ArpCache::GetAliveTimeout (
void)
 const 
  146   return m_aliveTimeout;
 
  149 ArpCache::GetDeadTimeout (
void)
 const 
  152   return m_deadTimeout;
 
  155 ArpCache::GetWaitReplyTimeout (
void)
 const 
  158   return m_waitReplyTimeout;
 
  166   m_arpRequestCallback = arpRequestCallback;
 
  187   bool restartWaitReplyTimer = 
false;
 
  188   for (CacheI i = m_arpCache.begin (); i != m_arpCache.end (); i++) 
 
  195               NS_LOG_LOGIC (
"node="<< m_device->GetNode ()->GetId () <<
 
  197                             " expired -- retransmitting arp request since retries = " <<
 
  200               restartWaitReplyTimer = 
true;
 
  205               NS_LOG_LOGIC (
"node="<<m_device->GetNode ()->GetId () <<
 
  207                             " expired -- drop since max retries exceeded: " <<
 
  214                   m_dropTrace (pending);
 
  221   if (restartWaitReplyTimer)
 
  233   for (CacheI i = m_arpCache.begin (); i != m_arpCache.end (); i++) 
 
  237   m_arpCache.erase (m_arpCache.begin (), m_arpCache.end ());
 
  241       m_waitReplyTimer.
Cancel ();
 
  249   if (m_arpCache.find (to) != m_arpCache.end ()) 
 
  261   NS_ASSERT (m_arpCache.find (to) == m_arpCache.end ());
 
  264   m_arpCache[to] = entry;
 
  265   entry->SetIpv4Address (to);
 
  282   return (m_state == DEAD) ? 
true : 
false;
 
  288   return (m_state == ALIVE) ? 
true : 
false;
 
  294   return (m_state == WAIT_REPLY) ? 
true : 
false;
 
  311   m_macAddress = macAddress;
 
  326   if (m_pending.size () >= m_arp->m_pendingQueueSize)
 
  330   m_pending.push_back (waiting);
 
  337   NS_ASSERT (m_state == ALIVE || m_state == DEAD);
 
  339   m_state = WAIT_REPLY;
 
  340   m_pending.push_back (waiting);
 
  342   m_arp->StartWaitReplyTimer ();
 
  356   return m_ipv4Address;
 
  362   m_ipv4Address = destination;
 
  365 ArpCache::Entry::GetTimeout (
void)
 const 
  369     case ArpCache::Entry::WAIT_REPLY:
 
  370       return m_arp->GetWaitReplyTimeout ();
 
  371     case ArpCache::Entry::DEAD:
 
  372       return m_arp->GetDeadTimeout ();
 
  373     case ArpCache::Entry::ALIVE:
 
  374       return m_arp->GetAliveTimeout ();
 
  385   Time timeout = GetTimeout ();
 
  398   if (m_pending.empty ())
 
  405       m_pending.pop_front ();
 
  410 ArpCache::Entry::UpdateSeen (
void)
 
void SetDevice(Ptr< NetDevice > device, Ptr< Ipv4Interface > interface)
void StartWaitReplyTimer(void)
void SetArpRequestCallback(Callback< void, Ptr< const ArpCache >, Ipv4Address > arpRequestCallback)
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)
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address. 
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
Ptr< NetDevice > GetDevice(void) const 
virtual void DoDispose(void)
bool IsRunning(void) const 
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
a polymophic address class 
double GetSeconds(void) const 
void SetIpv4Address(Ipv4Address destination)
void HandleWaitReplyTimeout(void)
void MarkWaitReply(Ptr< Packet > waiting)
uint32_t GetRetries(void) const 
bool IsExpired(void) const 
Ipv4Address GetIpv4Address(void) const 
#define NS_LOG_LOGIC(msg)
Address GetMacAddress(void) const 
Ptr< Ipv4Interface > GetInterface(void) const 
static void Remove(const EventId &id)
void IncrementRetries(void)
Increment the counter of number of retries for an entry. 
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void MarkAlive(Address macAddress)
A record that that holds information about an ArpCache entry. 
void Flush(void)
Clear the ArpCache of all entries. 
Entry(ArpCache *arp)
Constructor. 
bool UpdateWaitReply(Ptr< Packet > waiting)
Ipv4 addresses are stored in host order in this class. 
Time Seconds(double seconds)
create ns3::Time instances in units of seconds. 
#define NS_LOG_DEBUG(msg)
Ptr< Packet > DequeuePending(void)
void ClearRetries(void)
Zero the counter of number of retries for an entry. 
void MarkDead(void)
Changes the state of this entry to dead.