diff --git a/src/routing/manet/aodv/aodv-routing-protocol.cc b/src/routing/manet/aodv/aodv-routing-protocol.cc index b8eab282c..8fecbf56f 100644 --- a/src/routing/manet/aodv/aodv-routing-protocol.cc +++ b/src/routing/manet/aodv/aodv-routing-protocol.cc @@ -308,7 +308,7 @@ RoutingProtocol::RouteInput (Ptr p, const Ipv4Header &header, { return true; } - if (m_dpd.IsDuplicated (p, header)) + if (m_dpd.IsDuplicate (p, header)) { NS_LOG_DEBUG ("Duplicated packet " << p->GetUid () << " from " << origin << ". Drop."); return true; @@ -661,7 +661,7 @@ RoutingProtocol::SendRequest (Ipv4Address dst) Ipv4InterfaceAddress iface = j->second; rreqHeader.SetOrigin (iface.GetLocal ()); - m_rreqIdCache.IsDuplicated (iface.GetLocal (), m_requestId); + m_rreqIdCache.IsDuplicate (iface.GetLocal (), m_requestId); Ptr packet = Create (); packet->AddHeader (rreqHeader); @@ -799,7 +799,7 @@ RoutingProtocol::RecvRequest (Ptr p, Ipv4Address receiver, Ipv4Address s * Node checks to determine whether it has received a RREQ with the same Originator IP Address and RREQ ID. * If such a RREQ has been received, the node silently discards the newly received RREQ. */ - if (m_rreqIdCache.IsDuplicated (origin, id)) + if (m_rreqIdCache.IsDuplicate (origin, id)) { return; } diff --git a/src/routing/manet/aodv/aodv-routing-protocol.h b/src/routing/manet/aodv/aodv-routing-protocol.h index c0cdfd7cd..c2ad625a2 100644 --- a/src/routing/manet/aodv/aodv-routing-protocol.h +++ b/src/routing/manet/aodv/aodv-routing-protocol.h @@ -44,10 +44,9 @@ namespace ns3 { namespace aodv { - -using namespace dpd; /** * \ingroup aodv + * * \brief AODV routing protocol */ class RoutingProtocol : public Ipv4RoutingProtocol @@ -140,9 +139,9 @@ private: /// Request sequence number uint32_t m_seqNo; /// Handle duplicated RREQ - IdCache m_rreqIdCache; + dpd::IdCache m_rreqIdCache; /// Handle duplicated broadcast/multicast packets - DuplicatePacketDetection m_dpd; + dpd::DuplicatePacketDetection m_dpd; /// Handle neighbors Neighbors m_nb; /// Number of RREQs used for RREQ rate control diff --git a/src/routing/manet/dpd/dpd.cc b/src/routing/manet/dpd/dpd.cc index 4c0d67eb8..059a6c546 100644 --- a/src/routing/manet/dpd/dpd.cc +++ b/src/routing/manet/dpd/dpd.cc @@ -28,9 +28,9 @@ namespace dpd { bool -DuplicatePacketDetection::IsDuplicated (Ptr p, const Ipv4Header & header) +DuplicatePacketDetection::IsDuplicate (Ptr p, const Ipv4Header & header) { - return m_idCache.IsDuplicated (header.GetSource (), p->GetUid() ); + return m_idCache.IsDuplicate (header.GetSource (), p->GetUid() ); } void DuplicatePacketDetection::SetLifetime (Time lifetime) diff --git a/src/routing/manet/dpd/dpd.h b/src/routing/manet/dpd/dpd.h index b84cfb8de..77ff6d10e 100644 --- a/src/routing/manet/dpd/dpd.h +++ b/src/routing/manet/dpd/dpd.h @@ -34,22 +34,22 @@ namespace dpd { /** * \ingroup dpd - * \brief Detect duplicated packets + * + * \brief Helper class used to remember already seen packets and detect duplicates. */ - class DuplicatePacketDetection { public: - /// c-tor + /// C-tor DuplicatePacketDetection (Time lifetime) : m_idCache(lifetime) {} /// Check that the packet is duplicated. If not, save information about this packet. - bool IsDuplicated (Ptr p, const Ipv4Header & header); - ///\name Handle lifetime - //\{ + bool IsDuplicate (Ptr p, const Ipv4Header & header); + /// Set duplicate records lifetimes void SetLifetime (Time lifetime); + /// Get duplicate records lifetimes Time GetLifetime () const; - //\} private: + /// Impl IdCache m_idCache; }; diff --git a/src/routing/manet/dpd/id-cache.cc b/src/routing/manet/dpd/id-cache.cc index 45c633027..05166346e 100644 --- a/src/routing/manet/dpd/id-cache.cc +++ b/src/routing/manet/dpd/id-cache.cc @@ -34,7 +34,7 @@ namespace ns3 namespace dpd { bool -IdCache::IsDuplicated (Ipv4Address addr, uint32_t id) +IdCache::IsDuplicate (Ipv4Address addr, uint32_t id) { Purge (); for (std::vector::const_iterator i = m_idCache.begin (); @@ -80,16 +80,16 @@ bool IdCacheTest::DoRun () { NS_TEST_EXPECT_MSG_EQ (cache.GetLifeTime(), Seconds(10), "Lifetime"); - NS_TEST_EXPECT_MSG_EQ (cache.IsDuplicated (Ipv4Address ("1.2.3.4"), 3), false, "Unknown ID & address"); - NS_TEST_EXPECT_MSG_EQ (cache.IsDuplicated (Ipv4Address ("1.2.3.4"), 4), false, "Unknown ID"); - NS_TEST_EXPECT_MSG_EQ (cache.IsDuplicated (Ipv4Address ("4.3.2.1"), 3), false, "Unknown address"); - NS_TEST_EXPECT_MSG_EQ (cache.IsDuplicated (Ipv4Address ("1.2.3.4"), 3), true, "Known address & ID"); + NS_TEST_EXPECT_MSG_EQ (cache.IsDuplicate (Ipv4Address ("1.2.3.4"), 3), false, "Unknown ID & address"); + NS_TEST_EXPECT_MSG_EQ (cache.IsDuplicate (Ipv4Address ("1.2.3.4"), 4), false, "Unknown ID"); + NS_TEST_EXPECT_MSG_EQ (cache.IsDuplicate (Ipv4Address ("4.3.2.1"), 3), false, "Unknown address"); + NS_TEST_EXPECT_MSG_EQ (cache.IsDuplicate (Ipv4Address ("1.2.3.4"), 3), true, "Known address & ID"); cache.SetLifetime(Seconds(15)); NS_TEST_EXPECT_MSG_EQ (cache.GetLifeTime(), Seconds(15), "New lifetime"); - cache.IsDuplicated (Ipv4Address ("1.1.1.1"), 4); - cache.IsDuplicated (Ipv4Address ("1.1.1.1"), 4); - cache.IsDuplicated (Ipv4Address ("2.2.2.2"), 5); - cache.IsDuplicated (Ipv4Address ("3.3.3.3"), 6); + cache.IsDuplicate (Ipv4Address ("1.1.1.1"), 4); + cache.IsDuplicate (Ipv4Address ("1.1.1.1"), 4); + cache.IsDuplicate (Ipv4Address ("2.2.2.2"), 5); + cache.IsDuplicate (Ipv4Address ("3.3.3.3"), 6); NS_TEST_EXPECT_MSG_EQ (cache.GetSize (), 6, "trivial"); Simulator::Schedule (Seconds(5), &IdCacheTest::CheckTimeout1, this); diff --git a/src/routing/manet/dpd/id-cache.h b/src/routing/manet/dpd/id-cache.h index 088fa1dd7..827311e70 100644 --- a/src/routing/manet/dpd/id-cache.h +++ b/src/routing/manet/dpd/id-cache.h @@ -37,10 +37,10 @@ namespace ns3 { namespace dpd { - /** * \ingroup dpd - * \brief packets identification cache + * + * \brief Unique packets identification cache used for simple duplicate detection. */ class IdCache { @@ -48,7 +48,7 @@ public: /// c-tor IdCache (Time lifetime): m_lifetime (lifetime) {} /// Check that entry (addr, id) exists in cache. Add entry, if it doesn't exist. - bool IsDuplicated (Ipv4Address addr, uint32_t id); + bool IsDuplicate (Ipv4Address addr, uint32_t id); /// Remove all expired entries void Purge (); /// Return number of entries in cache @@ -58,10 +58,14 @@ public: /// Return lifetime for existing entries in cache Time GetLifeTime () const { return m_lifetime; } private: + /// Unique packet ID struct UniqueId { + /// ID is supposed to be unique in single address context (e.g. sender address) Ipv4Address m_context; + /// The id uint32_t m_id; + /// When record will expire Time m_expire; }; struct IsExpired @@ -71,7 +75,9 @@ private: return (u.m_expire < Simulator::Now ()); } }; + /// Already seen IDs std::vector m_idCache; + /// Default lifetime for ID records Time m_lifetime; };