# HG changeset patch # User Tom Henderson # Date 1230665731 28800 # Node ID e8af43dde01b71fdc6b3bccbda56392797dd74c0 # Parent ca0ea1ed6fc8602c4082e343a26b9d2cf3e42341 fix for bug451-- arp cache diff -r ca0ea1ed6fc8 -r e8af43dde01b src/internet-stack/arp-cache.cc --- a/src/internet-stack/arp-cache.cc Sun Dec 28 12:34:28 2008 +0000 +++ b/src/internet-stack/arp-cache.cc Tue Dec 30 11:35:31 2008 -0800 @@ -185,7 +185,7 @@ ArpCache::HandleWaitReplyTimeout (void) 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 @@ ArpCache::Entry::SetIpv4Address (Ipv4Add NS_LOG_FUNCTION (this << destination); m_ipv4Address = destination; } - -bool -ArpCache::Entry::IsExpired (void) +Time +ArpCache::Entry::GetTimeout (void) const +{ + switch (m_state) { + case ArpCache::Entry::WAIT_REPLY: + return m_arp->GetWaitReplyTimeout (); + case ArpCache::Entry::DEAD: + return m_arp->GetDeadTimeout (); + case ArpCache::Entry::ALIVE: + return m_arp->GetAliveTimeout (); + default: + NS_ASSERT (false); + return Seconds (0); + /* NOTREACHED */ + } +} +bool +ArpCache::Entry::IsExpiring (void) const { NS_LOG_FUNCTION_NOARGS (); - Time timeout; - switch (m_state) { - case ArpCache::Entry::WAIT_REPLY: - timeout = m_arp->GetWaitReplyTimeout (); - break; - case ArpCache::Entry::DEAD: - timeout = m_arp->GetDeadTimeout (); - break; - case ArpCache::Entry::ALIVE: - timeout = m_arp->GetAliveTimeout (); - break; - default: - NS_ASSERT (false); - timeout = Seconds (0); - /* NOTREACHED */ - break; - } + 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 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 ca0ea1ed6fc8 -r e8af43dde01b src/internet-stack/arp-cache.h --- a/src/internet-stack/arp-cache.h Sun Dec 28 12:34:28 2008 +0000 +++ b/src/internet-stack/arp-cache.h Tue Dec 30 11:35:31 2008 -0800 @@ -160,9 +160,25 @@ public: */ 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 @@ public: }; void UpdateSeen (void); + Time GetTimeout (void) const; ArpCache *m_arp; ArpCacheEntryState_e m_state; Time m_lastSeen;