[aodv] DPD cosmetics
This commit is contained in:
@@ -308,7 +308,7 @@ RoutingProtocol::RouteInput (Ptr<const Packet> 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> packet = Create<Packet> ();
|
||||
packet->AddHeader (rreqHeader);
|
||||
@@ -799,7 +799,7 @@ RoutingProtocol::RecvRequest (Ptr<Packet> 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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -28,9 +28,9 @@ namespace dpd
|
||||
{
|
||||
|
||||
bool
|
||||
DuplicatePacketDetection::IsDuplicated (Ptr<const Packet> p, const Ipv4Header & header)
|
||||
DuplicatePacketDetection::IsDuplicate (Ptr<const Packet> 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)
|
||||
|
||||
@@ -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<const Packet> p, const Ipv4Header & header);
|
||||
///\name Handle lifetime
|
||||
//\{
|
||||
bool IsDuplicate (Ptr<const Packet> p, const Ipv4Header & header);
|
||||
/// Set duplicate records lifetimes
|
||||
void SetLifetime (Time lifetime);
|
||||
/// Get duplicate records lifetimes
|
||||
Time GetLifetime () const;
|
||||
//\}
|
||||
private:
|
||||
/// Impl
|
||||
IdCache m_idCache;
|
||||
};
|
||||
|
||||
|
||||
@@ -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<UniqueId>::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);
|
||||
|
||||
@@ -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<UniqueId> m_idCache;
|
||||
/// Default lifetime for ID records
|
||||
Time m_lifetime;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user