src/internet-stack/arp-cache.cc
changeset 4084 dd514b5e0bc6
parent 3823 761f94afe2a2
child 4250 724c9442a9f0
equal deleted inserted replaced
4083:5a5d8b94047a 4084:dd514b5e0bc6
   183   ArpCache::Entry* entry;
   183   ArpCache::Entry* entry;
   184   bool restartWaitReplyTimer = false;
   184   bool restartWaitReplyTimer = false;
   185   for (CacheI i = m_arpCache.begin (); i != m_arpCache.end (); i++) 
   185   for (CacheI i = m_arpCache.begin (); i != m_arpCache.end (); i++) 
   186     {
   186     {
   187       entry = (*i).second;
   187       entry = (*i).second;
   188       if (entry != 0 && entry->IsWaitReply () && entry->IsExpired ())
   188       if (entry != 0 && entry->IsWaitReply () && entry->IsExpiring () )
   189           {
   189           {
   190           if (entry->GetRetries () < m_maxRetries)
   190           if (entry->GetRetries () < m_maxRetries)
   191             {
   191             {
   192               NS_LOG_LOGIC ("node="<< m_device->GetNode ()->GetId () <<
   192               NS_LOG_LOGIC ("node="<< m_device->GetNode ()->GetId () <<
   193                 ", ArpWaitTimeout for " << entry->GetIpv4Address () <<
   193                 ", ArpWaitTimeout for " << entry->GetIpv4Address () <<
   356 ArpCache::Entry::SetIpv4Address (Ipv4Address destination)
   356 ArpCache::Entry::SetIpv4Address (Ipv4Address destination)
   357 {
   357 {
   358   NS_LOG_FUNCTION (this << destination);
   358   NS_LOG_FUNCTION (this << destination);
   359   m_ipv4Address = destination;
   359   m_ipv4Address = destination;
   360 }
   360 }
   361 
   361 Time
   362 bool 
   362 ArpCache::Entry::GetTimeout (void) const
   363 ArpCache::Entry::IsExpired (void)
   363 {
   364 {
       
   365   NS_LOG_FUNCTION_NOARGS ();
       
   366   Time timeout;
       
   367   switch (m_state) {
   364   switch (m_state) {
   368   case ArpCache::Entry::WAIT_REPLY:
   365   case ArpCache::Entry::WAIT_REPLY:
   369     timeout = m_arp->GetWaitReplyTimeout ();
   366     return m_arp->GetWaitReplyTimeout ();
   370     break;
       
   371   case ArpCache::Entry::DEAD:
   367   case ArpCache::Entry::DEAD:
   372     timeout = m_arp->GetDeadTimeout ();
   368     return m_arp->GetDeadTimeout ();
   373     break;
       
   374   case ArpCache::Entry::ALIVE:
   369   case ArpCache::Entry::ALIVE:
   375     timeout = m_arp->GetAliveTimeout ();
   370     return m_arp->GetAliveTimeout ();
   376     break;
       
   377   default:
   371   default:
   378     NS_ASSERT (false);
   372     NS_ASSERT (false);
   379     timeout = Seconds (0);
   373     return Seconds (0);
   380     /* NOTREACHED */
   374     /* NOTREACHED */
   381     break;
       
   382   }
   375   }
       
   376 }
       
   377 bool
       
   378 ArpCache::Entry::IsExpiring (void) const
       
   379 {
       
   380   NS_LOG_FUNCTION_NOARGS ();
       
   381   Time timeout = GetTimeout ();
   383   Time delta = Simulator::Now () - m_lastSeen;
   382   Time delta = Simulator::Now () - m_lastSeen;
   384   if (delta >= timeout) 
   383   NS_LOG_DEBUG ("delta=" << delta.GetSeconds () << "s");
       
   384   if (delta >= timeout)
       
   385     {
       
   386       return true;
       
   387     }
       
   388   return false;
       
   389 }
       
   390 bool 
       
   391 ArpCache::Entry::IsExpired (void) const
       
   392 {
       
   393   NS_LOG_FUNCTION_NOARGS ();
       
   394   Time timeout = GetTimeout ();
       
   395   Time delta = Simulator::Now () - m_lastSeen;
       
   396   NS_LOG_DEBUG ("delta=" << delta.GetSeconds () << "s");
       
   397   if (delta > timeout) 
   385     {
   398     {
   386       return true;
   399       return true;
   387     } 
   400     } 
   388   else 
   401   return false;
   389     {
       
   390       return false;
       
   391     }
       
   392 }
   402 }
   393 Ptr<Packet> 
   403 Ptr<Packet> 
   394 ArpCache::Entry::DequeuePending (void)
   404 ArpCache::Entry::DequeuePending (void)
   395 {
   405 {
   396   NS_LOG_FUNCTION_NOARGS ();
   406   NS_LOG_FUNCTION_NOARGS ();
   406     }
   416     }
   407 }
   417 }
   408 void 
   418 void 
   409 ArpCache::Entry::UpdateSeen (void)
   419 ArpCache::Entry::UpdateSeen (void)
   410 {
   420 {
   411   NS_LOG_FUNCTION_NOARGS ();
   421   NS_LOG_FUNCTION (m_macAddress << m_ipv4Address);
   412   m_lastSeen = Simulator::Now ();
   422   m_lastSeen = Simulator::Now ();
   413 }
   423 }
   414 uint32_t
   424 uint32_t
   415 ArpCache::Entry::GetRetries (void) const
   425 ArpCache::Entry::GetRetries (void) const
   416 {
   426 {
   417   NS_LOG_FUNCTION_NOARGS ();
   427   NS_LOG_FUNCTION (m_macAddress << m_ipv4Address);
   418   return m_retries;
   428   return m_retries;
   419 }
   429 }
   420 void
   430 void
   421 ArpCache::Entry::IncrementRetries (void)
   431 ArpCache::Entry::IncrementRetries (void)
   422 {
   432 {