# HG changeset patch # User Gustavo J. A. M. Carneiro # Date 1231874999 0 # Node ID 1c88eb82a9b03909ccb22febb911e5cfb2c4460b # Parent 37dbf76b4c6608949c004af5df8375c043381ded# Parent dd514b5e0bc6b5c50530b460a4dca1186ae66440 merge diff -r 37dbf76b4c66 -r 1c88eb82a9b0 src/internet-stack/arp-cache.cc --- a/src/internet-stack/arp-cache.cc Tue Jan 13 19:28:26 2009 +0000 +++ b/src/internet-stack/arp-cache.cc Tue Jan 13 19:29:59 2009 +0000 @@ -185,7 +185,7 @@ for (CacheI i = m_arpCache.begin (); i != m_arpCache.end (); i++) { entry = (*i).second; - if (entry != 0 && entry->IsWaitReply () && entry->IsExpired ()) + if (entry != 0 && entry->IsWaitReply () && entry->IsExpiring () ) { if (entry->GetRetries () < m_maxRetries) { @@ -358,37 +358,47 @@ NS_LOG_FUNCTION (this << destination); m_ipv4Address = destination; } - -bool -ArpCache::Entry::IsExpired (void) +Time +ArpCache::Entry::GetTimeout (void) const { - NS_LOG_FUNCTION_NOARGS (); - Time timeout; switch (m_state) { case ArpCache::Entry::WAIT_REPLY: - timeout = m_arp->GetWaitReplyTimeout (); - break; + return m_arp->GetWaitReplyTimeout (); case ArpCache::Entry::DEAD: - timeout = m_arp->GetDeadTimeout (); - break; + return m_arp->GetDeadTimeout (); case ArpCache::Entry::ALIVE: - timeout = m_arp->GetAliveTimeout (); - break; + return m_arp->GetAliveTimeout (); default: NS_ASSERT (false); - timeout = Seconds (0); + return Seconds (0); /* NOTREACHED */ - break; } +} +bool +ArpCache::Entry::IsExpiring (void) const +{ + NS_LOG_FUNCTION_NOARGS (); + Time timeout = GetTimeout (); Time delta = Simulator::Now () - m_lastSeen; - if (delta >= timeout) + NS_LOG_DEBUG ("delta=" << delta.GetSeconds () << "s"); + if (delta >= timeout) + { + return true; + } + return false; +} +bool +ArpCache::Entry::IsExpired (void) const +{ + NS_LOG_FUNCTION_NOARGS (); + Time timeout = GetTimeout (); + Time delta = Simulator::Now () - m_lastSeen; + NS_LOG_DEBUG ("delta=" << delta.GetSeconds () << "s"); + if (delta > timeout) { return true; } - else - { - return false; - } + return false; } Ptr ArpCache::Entry::DequeuePending (void) @@ -408,13 +418,13 @@ void ArpCache::Entry::UpdateSeen (void) { - NS_LOG_FUNCTION_NOARGS (); + NS_LOG_FUNCTION (m_macAddress << m_ipv4Address); m_lastSeen = Simulator::Now (); } uint32_t ArpCache::Entry::GetRetries (void) const { - NS_LOG_FUNCTION_NOARGS (); + NS_LOG_FUNCTION (m_macAddress << m_ipv4Address); return m_retries; } void diff -r 37dbf76b4c66 -r 1c88eb82a9b0 src/internet-stack/arp-cache.h --- a/src/internet-stack/arp-cache.h Tue Jan 13 19:28:26 2009 +0000 +++ b/src/internet-stack/arp-cache.h Tue Jan 13 19:29:59 2009 +0000 @@ -160,9 +160,25 @@ */ void SetIpv4Address (Ipv4Address destination); /** - * \return True if this entry has timedout; false otherwise. + * \return True if this entry has timed out; false otherwise. + * + * This function returns true if the time elapsed strictly exceeds + * the timeout value (i.e., is not less than or equal to the timeout). + * Differs from IsExpiring() only in the boundary condition + * delta == timeout. + * \see IsExpiring */ - bool IsExpired (void); + bool IsExpired (void) const; + /** + * \return True if this entry is timing out or has already timed out; + * false otherwise. + * + * This function returns true if the time elapsed is equal to or exceeds + * the timeout value. Differs from IsExpired() only in the boundary + * condition delta == timeout. + * \see IsExpired + */ + bool IsExpiring (void) const; /** * \returns 0 is no packet is pending, the next packet to send if @@ -191,6 +207,7 @@ }; void UpdateSeen (void); + Time GetTimeout (void) const; ArpCache *m_arp; ArpCacheEntryState_e m_state; Time m_lastSeen;