id cache moved in separate class
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,7 @@
|
||||
#include "aodv-rtable.h"
|
||||
#include "aodv-rqueue.h"
|
||||
#include "aodv-packet.h"
|
||||
#include "id-cache.h"
|
||||
|
||||
#include "src/internet-stack/ipv4-l3-protocol.h"
|
||||
|
||||
@@ -47,6 +48,8 @@ namespace ns3
|
||||
{
|
||||
namespace aodv
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* \ingroup aodv
|
||||
* \brief AODV routing protocol
|
||||
@@ -76,72 +79,33 @@ public:
|
||||
private:
|
||||
///\name Protocol parameters. TODO document
|
||||
//\{
|
||||
Time MAX_QUEUE_TIME;
|
||||
uint32_t RREQ_RETRIES; // 2
|
||||
Time ACTIVE_ROUTE_TIMEOUT; // 3 seconds
|
||||
Time MY_ROUTE_TIMEOUT; // 2 * ACTIVE_ROUTE_TIMEOUT
|
||||
uint16_t NET_DIAMETER;
|
||||
Time NODE_TRAVERSAL_TIME; // 40 milliseconds
|
||||
Time NET_TRAVERSAL_TIME; // 2 * NODE_TRAVERSAL_TIME * NET_DIAMETER
|
||||
Time BCAST_ID_SAVE;
|
||||
Time HELLO_INTERVAL;
|
||||
uint32_t ALLOWED_HELLO_LOSS;
|
||||
Time DELETE_PERIOD;
|
||||
Time MaxHelloInterval; // (1.25 * HELLO_INTERVAL)
|
||||
Time MinHelloInterval; // (0.75 * HELLO_INTERVAL)
|
||||
uint32_t RreqRetries; // 2
|
||||
Time ActiveRouteTimeout; // 3 seconds
|
||||
Time MyRouteTimeout; // 2 * ActiveRouteTimeout
|
||||
uint16_t NetDiameter;
|
||||
Time NodeTraversalTime; // 40 milliseconds
|
||||
Time NetTraversalTime; // 2 * NodeTraversalTime * NetDiameter
|
||||
Time PathDiscoveryTime;
|
||||
Time HelloInterval;
|
||||
uint32_t AllowedHelloLoss;
|
||||
/**
|
||||
* DeletePeriod is intended to provide an upper bound on the time for which an upstream node A
|
||||
* can have a neighbor B as an active next hop for destination D, while B has invalidated the route to D.
|
||||
*/
|
||||
Time DeletePeriod;
|
||||
Time MaxHelloInterval; // (1.25 * HelloInterval)
|
||||
Time MinHelloInterval; // (0.75 * HelloInterval)
|
||||
Time FREQUENCY;
|
||||
Time NEXT_HOP_WAIT;
|
||||
uint16_t TTL_START;
|
||||
uint16_t TTL_INCREMENT;
|
||||
uint16_t TTL_THRESHOLD;
|
||||
uint16_t MAX_REPAIR_TTL; // 0.3 * NET_DIAMETER
|
||||
Time NextHopWait;
|
||||
uint16_t TtlStart;
|
||||
uint16_t TtlIncrement;
|
||||
uint16_t TtlThreshold;
|
||||
uint16_t MaxRepairTtl; // 0.3 * NetDiameter
|
||||
uint16_t LOCAL_ADD_TTL;
|
||||
uint16_t TIMEOUT_BUFFER;
|
||||
Time BLACKLIST_TIMEOUT;
|
||||
uint32_t MaxQueueLen;
|
||||
Time QueueTimeout;
|
||||
//\}
|
||||
|
||||
/// \name Handle Broadcast sequence number cache
|
||||
//\{
|
||||
void InsertRequestId (Ipv4Address origin, uint32_t rid);
|
||||
bool LookupRequestId (Ipv4Address origin, uint32_t rid);
|
||||
void PurgeRequestId ();
|
||||
struct RequestId
|
||||
{
|
||||
Ipv4Address m_origin;
|
||||
uint32_t m_id;
|
||||
Time m_expire;
|
||||
};
|
||||
struct IsExpiredForRequest
|
||||
{
|
||||
bool operator()(const struct RequestId & b) const
|
||||
{
|
||||
return (b.m_expire < Simulator::Now());
|
||||
}
|
||||
};
|
||||
std::vector<RequestId> m_requestIdCache;
|
||||
//\}
|
||||
|
||||
///\name Handle duplicated packets
|
||||
//\{
|
||||
void InsertPacketUid (Ipv4Address src, uint32_t bid);
|
||||
bool LookupPacketUid (Ipv4Address src, uint32_t bid);
|
||||
void PurgePacketUid ();
|
||||
struct PacketUid
|
||||
{
|
||||
Ipv4Address m_src;
|
||||
uint32_t m_packetUid;
|
||||
Time m_expire;
|
||||
};
|
||||
struct IsExpiredForBroadcast
|
||||
{
|
||||
bool operator()(const struct PacketUid & p) const
|
||||
{
|
||||
return (p.m_expire < Simulator::Now());
|
||||
}
|
||||
};
|
||||
std::vector<PacketUid> m_packetUidCache;
|
||||
Time MaxQueueTime;
|
||||
//\}
|
||||
|
||||
/**\name Handle neighbors
|
||||
@@ -182,6 +146,8 @@ private:
|
||||
uint32_t m_requestId;
|
||||
/// Request sequence number
|
||||
uint32_t m_seqNo;
|
||||
/// Handle duplicated packets
|
||||
IdCache m_idCache;
|
||||
|
||||
UnicastForwardCallback m_scb;
|
||||
ErrorCallback m_ecb;
|
||||
|
||||
@@ -30,11 +30,46 @@
|
||||
#include "ns3/test.h"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include "ns3/ipv4-route.h"
|
||||
#include "ns3/log.h"
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("AodvRequestQueue");
|
||||
|
||||
namespace ns3 {
|
||||
namespace aodv {
|
||||
|
||||
#if 0
|
||||
#ifdef RUN_SELF_TESTS
|
||||
/// Unit test for AODV routing table entry
|
||||
struct QueueEntryTest : public Test
|
||||
{
|
||||
QueueEntryTest () : Test ("AODV/QueueEntry"), result(true) {}
|
||||
virtual bool RunTests();
|
||||
void Unicast (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header);
|
||||
void Error (Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno);
|
||||
bool result;
|
||||
};
|
||||
|
||||
/// Test instance
|
||||
static QueueEntryTest g_QueueEntryTest;
|
||||
|
||||
bool
|
||||
QueueEntryTest::RunTests ()
|
||||
{
|
||||
Ptr<Packet> packet;
|
||||
Ipv4Header h;
|
||||
h.SetDestination (Ipv4Address("1.2.3.4"));
|
||||
h.SetSource (Ipv4Address("4.3.2.1"));
|
||||
Ipv4RoutingProtocol::UnicastForwardCallback ucb = MakeCallback (&QueueEntryTest::Unicast, this);
|
||||
Ipv4RoutingProtocol::ErrorCallback ecb = MakeCallback (&QueueEntryTest::Error, this);
|
||||
QueueEntry entry (packet, h, ucb, ecb, Seconds(5));
|
||||
// NS_TEST_ASSERT_EQUAL (h.GetDestination (), entry.GetIpv4Header ().GetDestination ());
|
||||
// NS_TEST_ASSERT_EQUAL (h.GetSource (), entry.GetIpv4Header ().GetSource ());
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uint32_t
|
||||
RequestQueue::GetSize ()
|
||||
@@ -49,24 +84,30 @@ RequestQueue::Enqueue(QueueEntry & entry)
|
||||
Purge();
|
||||
entry.SetExpireTime (m_queueTimeout);
|
||||
|
||||
if (m_queue.size() == m_maxLen) Drop(RemoveHead()); // Drop the most aged packet
|
||||
if (m_queue.size() == m_maxLen) Drop(Pop(), "Drop the most aged packet"); // Drop the most aged packet
|
||||
m_queue.push_back(entry);
|
||||
}
|
||||
|
||||
QueueEntry
|
||||
RequestQueue::Dequeue()
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
Purge();
|
||||
return RemoveHead();
|
||||
return Pop();
|
||||
}
|
||||
|
||||
void
|
||||
RequestQueue::DropPacketWithDst (Ipv4Address dst)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << dst);
|
||||
Purge();
|
||||
const Ipv4Address addr = dst;
|
||||
std::vector<QueueEntry>::iterator i = std::remove_if (m_queue.begin(), m_queue.end(), std::bind2nd(std::ptr_fun( RequestQueue::IsEqual), dst) );
|
||||
m_queue.erase (i, m_queue.end());
|
||||
for(std::vector<QueueEntry>::iterator j = i; i != m_queue.end(); ++j)
|
||||
{
|
||||
Drop(*j, "DropPacketWithDst ");
|
||||
}
|
||||
m_queue.erase(i, m_queue.end());
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -93,8 +134,9 @@ RequestQueue::Find(Ipv4Address dst)
|
||||
}
|
||||
|
||||
QueueEntry
|
||||
RequestQueue::RemoveHead()
|
||||
RequestQueue::Pop()
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
QueueEntry entry = m_queue.front();
|
||||
m_queue.erase(m_queue.begin());
|
||||
return entry;
|
||||
@@ -113,14 +155,16 @@ RequestQueue::Purge()
|
||||
{
|
||||
std::vector<QueueEntry>::iterator i = std::remove_if(m_queue.begin(), m_queue.end(), IsExpired());
|
||||
for (std::vector<QueueEntry>::iterator j = i ; j < m_queue.end(); ++j)
|
||||
Drop (*j);
|
||||
{
|
||||
Drop (*j, "Drop outdated packet ");
|
||||
}
|
||||
m_queue.erase(i, m_queue.end());
|
||||
}
|
||||
|
||||
void
|
||||
RequestQueue::Drop(QueueEntry)
|
||||
RequestQueue::Drop(QueueEntry en, std::string reason)
|
||||
{
|
||||
// TODO do nothing now.
|
||||
NS_LOG_LOGIC (reason << en.GetPacket ()->GetUid ());
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
@@ -61,7 +61,8 @@ public:
|
||||
{
|
||||
return ((m_packet == o.m_packet)/*&& header == o.header*/ && (m_expire == o.m_expire));
|
||||
}
|
||||
|
||||
///\name Fields
|
||||
//\{
|
||||
UnicastForwardCallback GetUnicastForwardCallback () const { return m_ucb; }
|
||||
void SetUnicastForwardCallback (UnicastForwardCallback ucb) { m_ucb = ucb; }
|
||||
ErrorCallback GetErrorCallback () const { return m_ecb; }
|
||||
@@ -72,6 +73,7 @@ public:
|
||||
void SetIpv4Header (Ipv4Header h) { m_header = h; }
|
||||
void SetExpireTime (Time exp) { m_expire = exp + Simulator::Now(); }
|
||||
Time GetExpireTime () const { return m_expire - Simulator::Now(); }
|
||||
//\}
|
||||
private:
|
||||
Ptr<const Packet> m_packet;
|
||||
Ipv4Header m_header;
|
||||
@@ -114,11 +116,11 @@ public:
|
||||
private:
|
||||
std::vector<QueueEntry> m_queue;
|
||||
/// Remove and return first entry from queue
|
||||
QueueEntry RemoveHead();
|
||||
QueueEntry Pop();
|
||||
/// Remove all expired entries
|
||||
void Purge();
|
||||
/// Notify that packet is dropped from queue by timeout
|
||||
void Drop (QueueEntry e);
|
||||
void Drop (QueueEntry en, std::string reason);
|
||||
/// The maximum number of packets that we allow a routing protocol to buffer.
|
||||
uint32_t m_maxLen;
|
||||
/// The maximum period of time that a routing protocol is allowed to buffer a packet for, seconds.
|
||||
|
||||
59
src/routing/aodv/id-cache.cc
Normal file
59
src/routing/aodv/id-cache.cc
Normal file
@@ -0,0 +1,59 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 IITP RAS
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Based on
|
||||
* NS-2 AODV model developed by the CMU/MONARCH group and optimized and
|
||||
* tuned by Samir Das and Mahesh Marina, University of Cincinnati;
|
||||
*
|
||||
* AODV-UU implementation by Erik Nordström of Uppsala University
|
||||
* http://core.it.uu.se/core/index.php/AODV-UU
|
||||
*
|
||||
* Authors: Elena Borovkova <borovkovaes@iitp.ru>
|
||||
* Pavel Boyko <boyko@iitp.ru>
|
||||
*/
|
||||
#include "id-cache.h"
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
namespace aodv
|
||||
{
|
||||
void
|
||||
IdCache::InsertId (Ipv4Address addr, uint32_t id, Time saveTime)
|
||||
{
|
||||
if (LookupId (addr, id))
|
||||
return;
|
||||
struct UniqueId uniqueId = { addr, id, saveTime + Simulator::Now () };
|
||||
m_idCache.push_back (uniqueId);
|
||||
}
|
||||
bool
|
||||
IdCache::LookupId (Ipv4Address addr, uint32_t id )
|
||||
{
|
||||
Purge ();
|
||||
for (std::vector<UniqueId>::const_iterator i = m_idCache.begin (); i != m_idCache.end (); ++i)
|
||||
if (i->m_context == addr && i->m_id == id)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
void
|
||||
IdCache::Purge ()
|
||||
{
|
||||
std::vector<UniqueId>::iterator i = remove_if (m_idCache.begin (), m_idCache.end (), IsExpired ());
|
||||
m_idCache.erase (i, m_idCache.end ());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
72
src/routing/aodv/id-cache.h
Normal file
72
src/routing/aodv/id-cache.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 IITP RAS
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Based on
|
||||
* NS-2 AODV model developed by the CMU/MONARCH group and optimized and
|
||||
* tuned by Samir Das and Mahesh Marina, University of Cincinnati;
|
||||
*
|
||||
* AODV-UU implementation by Erik Nordström of Uppsala University
|
||||
* http://core.it.uu.se/core/index.php/AODV-UU
|
||||
*
|
||||
* Authors: Elena Borovkova <borovkovaes@iitp.ru>
|
||||
* Pavel Boyko <boyko@iitp.ru>
|
||||
*/
|
||||
|
||||
#ifndef IDCACHE_H_
|
||||
#define IDCACHE_H_
|
||||
|
||||
#include "ns3/ipv4-address.h"
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include <vector>
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
namespace aodv
|
||||
{
|
||||
|
||||
/**
|
||||
* \ingroup aodv
|
||||
* \brief packets identification cache
|
||||
*/
|
||||
class IdCache
|
||||
{
|
||||
public:
|
||||
void InsertId (Ipv4Address addr, uint32_t id, Time saveTime);
|
||||
bool LookupId (Ipv4Address addr, uint32_t id);
|
||||
void Purge ();
|
||||
private:
|
||||
struct UniqueId
|
||||
{
|
||||
Ipv4Address m_context;
|
||||
uint32_t m_id;
|
||||
Time m_expire;
|
||||
};
|
||||
struct IsExpired
|
||||
{
|
||||
bool
|
||||
operator() (const struct UniqueId & u ) const
|
||||
{
|
||||
return (u.m_expire < Simulator::Now ());
|
||||
}
|
||||
};
|
||||
std::vector<UniqueId> m_idCache;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif /* IDCACHE_H_ */
|
||||
@@ -7,6 +7,7 @@ def build(bld):
|
||||
'aodv-rtable.cc',
|
||||
'aodv-rqueue.cc',
|
||||
'aodv-packet.cc',
|
||||
'id-cache.cc',
|
||||
'aodv-routing-protocol.cc',
|
||||
]
|
||||
|
||||
@@ -16,6 +17,7 @@ def build(bld):
|
||||
'aodv-rtable.h',
|
||||
'aodv-rqueue.h',
|
||||
'aodv-packet.h',
|
||||
'id-cache.h',
|
||||
'aodv-routing-protocol.h',
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user