diff --git a/src/internet/model/arp-cache.cc b/src/internet/model/arp-cache.cc index 322a504..5f1b299 100644 --- a/src/internet/model/arp-cache.cc +++ b/src/internet/model/arp-cache.cc @@ -313,6 +313,24 @@ ArpCache::Add (Ipv4Address to) return entry; } +void +ArpCache::Remove (ArpCache::Entry *entry) +{ + NS_LOG_FUNCTION (this << entry); + + for (CacheI i = m_arpCache.begin (); i != m_arpCache.end (); i++) + { + if ((*i).second == entry) + { + m_arpCache.erase (i); + entry->ClearPendingPacket (); //clear the pending packets for entry's ipaddress + delete entry; + return; + } + } + NS_LOG_WARN ("Entry not found in this ARP Cache"); +} + ArpCache::Entry::Entry (ArpCache *arp) : m_arp (arp), m_state (ALIVE), @@ -340,12 +358,19 @@ ArpCache::Entry::IsWaitReply (void) NS_LOG_FUNCTION (this); return (m_state == WAIT_REPLY) ? true : false; } +bool +ArpCache::Entry::IsPermanent (void) +{ + NS_LOG_FUNCTION (this); + return (m_state == PERMANENT) ? true : false; +} void ArpCache::Entry::MarkDead (void) { NS_LOG_FUNCTION (this); + NS_ASSERT (m_state == ALIVE || m_state == WAIT_REPLY || m_state == DEAD); m_state = DEAD; ClearRetries (); UpdateSeen (); @@ -360,7 +385,26 @@ ArpCache::Entry::MarkAlive (Address macAddress) ClearRetries (); UpdateSeen (); } - +void +ArpCache::Entry::MarkPermanent (void) +{ + NS_LOG_FUNCTION (this); + NS_ASSERT (m_state == ALIVE); + m_state = PERMANENT; + ClearRetries (); + UpdateSeen (); +} +void +ArpCache::Entry::MarkWaitReply (Ptr waiting) +{ + NS_LOG_FUNCTION (this << waiting); + NS_ASSERT (m_state == ALIVE || m_state == DEAD); + NS_ASSERT (m_pending.empty ()); + m_state = WAIT_REPLY; + m_pending.push_back (waiting); + UpdateSeen (); + m_arp->StartWaitReplyTimer (); +} bool ArpCache::Entry::UpdateWaitReply (Ptr waiting) { @@ -377,17 +421,7 @@ ArpCache::Entry::UpdateWaitReply (Ptr waiting) m_pending.push_back (waiting); return true; } -void -ArpCache::Entry::MarkWaitReply (Ptr waiting) -{ - NS_LOG_FUNCTION (this << waiting); - NS_ASSERT (m_state == ALIVE || m_state == DEAD); - NS_ASSERT (m_pending.empty ()); - m_state = WAIT_REPLY; - m_pending.push_back (waiting); - UpdateSeen (); - m_arp->StartWaitReplyTimer (); -} + Address ArpCache::Entry::GetMacAddress (void) const @@ -418,6 +452,8 @@ ArpCache::Entry::GetTimeout (void) const return m_arp->GetDeadTimeout (); case ArpCache::Entry::ALIVE: return m_arp->GetAliveTimeout (); + case ArpCache::Entry::PERMANENT: + return Time::Max (); default: NS_ASSERT (false); return Seconds (0); @@ -453,6 +489,12 @@ ArpCache::Entry::DequeuePending (void) } } void +ArpCache::Entry::ClearPendingPacket (void) +{ + NS_LOG_FUNCTION (this); + m_pending.clear (); +} +void ArpCache::Entry::UpdateSeen (void) { NS_LOG_FUNCTION (this); diff --git a/src/internet/model/arp-cache.h b/src/internet/model/arp-cache.h index f9a69e6..2940b8f 100644 --- a/src/internet/model/arp-cache.h +++ b/src/internet/model/arp-cache.h @@ -151,6 +151,11 @@ public: */ ArpCache::Entry *Add (Ipv4Address to); /** + * \brief Remove an entry. + * \param entry pointer to delete it from the list + */ + void Remove (ArpCache::Entry *entry); + /** * \brief Clear the ArpCache of all entries */ void Flush (void); @@ -186,6 +191,10 @@ public: */ void MarkWaitReply (Ptr waiting); /** + * \brief Changes the state of this entry to Permanent if it was Alive + */ + void MarkPermanent (void); + /** * \param waiting * \return */ @@ -202,10 +211,14 @@ public: * \return True if the state of this entry is wait_reply; false otherwise. */ bool IsWaitReply (void); - + /** + * \return True if the state of this entry is permanent; false otherwise. + */ + bool IsPermanent (void); /** * \return The MacAddress of this entry */ + Address GetMacAddress (void) const; /** * \return The Ipv4Address for this entry @@ -228,6 +241,10 @@ public: */ Ptr DequeuePending (void); /** + * \brief Clear the pending packet list + */ + void ClearPendingPacket (void); + /** * \returns number of retries that have been sent for an ArpRequest * in WaitReply state. */ @@ -248,7 +265,8 @@ private: enum ArpCacheEntryState_e { ALIVE, WAIT_REPLY, - DEAD + DEAD, + PERMANENT }; /**