From ca5532bb82788909b0e9d8582ab9a75d5a60168a Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Tue, 30 Dec 2008 11:35:31 -0800 Subject: [PATCH] fix for bug451-- arp cache --- src/internet-stack/arp-cache.cc | 52 ++++++++++++++++++++------------- src/internet-stack/arp-cache.h | 21 +++++++++++-- 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/internet-stack/arp-cache.cc b/src/internet-stack/arp-cache.cc index cf6a15bf4..8d1bf32d8 100644 --- a/src/internet-stack/arp-cache.cc +++ b/src/internet-stack/arp-cache.cc @@ -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 (Ipv4Address destination) 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 @@ ArpCache::Entry::DequeuePending (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 --git a/src/internet-stack/arp-cache.h b/src/internet-stack/arp-cache.h index a161b898e..afa148b24 100644 --- a/src/internet-stack/arp-cache.h +++ b/src/internet-stack/arp-cache.h @@ -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;