neighbor's timer moved in class Neighbors
This commit is contained in:
@@ -28,12 +28,21 @@
|
||||
|
||||
#include "aodv-neighbor.h"
|
||||
#include "ns3/test.h"
|
||||
#include "ns3/log.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
namespace aodv
|
||||
{
|
||||
|
||||
Neighbors::Neighbors (Callback<void, Ipv4Address> cb, Time delay) : m_handleLinleFailure (cb), m_ntimer (Timer::CANCEL_ON_DESTROY)
|
||||
{
|
||||
m_ntimer.SetDelay(delay);
|
||||
m_ntimer.SetFunction(&Neighbors::Purge, this);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Neighbors::Lookup (Ipv4Address addr)
|
||||
{
|
||||
@@ -86,21 +95,28 @@ void
|
||||
Neighbors::Purge ()
|
||||
{
|
||||
if (m_nb.empty ()) return;
|
||||
for (std::vector<Neighbor>::const_iterator i = m_nb.begin (); i != m_nb.end (); ++i)
|
||||
if (i->m_expireTime < Simulator::Now ())
|
||||
{
|
||||
m_handleLinleFailure (i->m_neighborAddress);
|
||||
}
|
||||
std::vector<Neighbor>::iterator i = remove_if (m_nb.begin (), m_nb.end (), IsExpired ());
|
||||
for (std::vector<Neighbor>::const_iterator j = i; j != m_nb.end (); ++j)
|
||||
{
|
||||
m_handleLinleFailure (i->m_neighborAddress);
|
||||
}
|
||||
m_nb.erase (i, m_nb.end ());
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
Neighbors::Shedule ()
|
||||
{
|
||||
m_ntimer.Cancel();
|
||||
m_ntimer.Schedule();
|
||||
}
|
||||
|
||||
|
||||
#ifdef RUN_SELF_TESTS
|
||||
/// Unit test for neighbors
|
||||
struct NeighborTest : public Test
|
||||
{
|
||||
NeighborTest () : Test ("AODV/Neighbor"), neighbor(MakeCallback(&NeighborTest::Handler, this)), result(true) {}
|
||||
NeighborTest () : Test ("AODV/Neighbor"), neighbor(MakeCallback(&NeighborTest::Handler, this), Seconds(1)), result(true) {}
|
||||
virtual bool RunTests();
|
||||
void Handler (Ipv4Address addr);
|
||||
void CheckTimeout1 ();
|
||||
|
||||
@@ -31,19 +31,22 @@
|
||||
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/timer.h"
|
||||
#include "ns3/ipv4-address.h"
|
||||
#include "ns3/callback.h"
|
||||
#include <vector>
|
||||
#
|
||||
|
||||
|
||||
namespace ns3
|
||||
{
|
||||
namespace aodv
|
||||
{
|
||||
class RoutingProtocol;
|
||||
class Neighbors
|
||||
{
|
||||
public:
|
||||
Neighbors (Callback<void, Ipv4Address> cb) : m_handleLinleFailure (cb) {}
|
||||
Neighbors (Callback<void, Ipv4Address> cb, Time delay);
|
||||
struct Neighbor
|
||||
{
|
||||
Ipv4Address m_neighborAddress;
|
||||
@@ -61,6 +64,7 @@ public:
|
||||
bool IsNeighbor (Ipv4Address addr);
|
||||
void Update (Ipv4Address addr, Time expire);
|
||||
void Purge ();
|
||||
void Shedule ();
|
||||
private:
|
||||
struct IsExpired
|
||||
{
|
||||
@@ -71,6 +75,7 @@ private:
|
||||
};
|
||||
|
||||
Callback<void, Ipv4Address> m_handleLinleFailure;
|
||||
Timer m_ntimer;
|
||||
std::vector<Neighbor> m_nb;
|
||||
};
|
||||
|
||||
|
||||
@@ -83,11 +83,12 @@ RoutingProtocol::RoutingProtocol () :
|
||||
BLACKLIST_TIMEOUT( Scalar ( (((TtlThreshold - TtlStart)/TtlIncrement) + 1 + RreqRetries) )*NetTraversalTime ),
|
||||
MaxQueueLen (64), MaxQueueTime (Seconds(30)), DestinationOnly (false), GratuitousReply (true),
|
||||
m_routingTable (DeletePeriod), m_queue (MaxQueueLen, MaxQueueTime),
|
||||
m_requestId (0), m_seqNo (0), m_nb(MakeCallback(&RoutingProtocol::HandleLinkFailure, this)),
|
||||
htimer (Timer::CANCEL_ON_DESTROY), ntimer (Timer::CANCEL_ON_DESTROY),
|
||||
m_requestId (0), m_seqNo (0), m_nb(MakeCallback(&RoutingProtocol::HandleLinkFailure, this), HelloInterval),
|
||||
htimer (Timer::CANCEL_ON_DESTROY),
|
||||
rtimer (Timer::CANCEL_ON_DESTROY), lrtimer (Timer::CANCEL_ON_DESTROY)
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TypeId
|
||||
@@ -208,7 +209,7 @@ RoutingProtocol::Start ()
|
||||
m_scb = MakeCallback (&RoutingProtocol::Send, this);
|
||||
m_ecb = MakeCallback (&RoutingProtocol::Drop, this);
|
||||
|
||||
ntimer.Schedule();
|
||||
m_nb.Shedule();
|
||||
rtimer.Schedule();
|
||||
}
|
||||
|
||||
@@ -361,7 +362,6 @@ RoutingProtocol::SetIpv4 (Ptr<Ipv4> ipv4)
|
||||
NS_ASSERT (ipv4 != 0);
|
||||
NS_ASSERT (m_ipv4 == 0);
|
||||
|
||||
ntimer.SetFunction (&RoutingProtocol::NeighborTimerExpire, this);
|
||||
rtimer.SetFunction (&RoutingProtocol::RouteCacheTimerExpire, this);
|
||||
lrtimer.SetFunction (&RoutingProtocol::LocalRepairTimerExpire, this);
|
||||
htimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this);
|
||||
@@ -475,35 +475,35 @@ RoutingProtocol::SendRequest (Ipv4Address dst, uint16_t ttl )
|
||||
/*destination address*/iface.GetBroadcast (), /*id*/0, /*TTL*/ttl);
|
||||
socket->Send (packet);
|
||||
}
|
||||
|
||||
/*
|
||||
* Schedule RREQ retry.
|
||||
*
|
||||
* To reduce congestion in a network, repeated attempts by a source node at route discovery
|
||||
* for a single destination MUST utilize a binary exponential backoff.
|
||||
*/
|
||||
if (m_addressReqTimer.find (dst) == m_addressReqTimer.end ())
|
||||
{
|
||||
Timer timer (Timer::CANCEL_ON_DESTROY);
|
||||
m_addressReqTimer[dst] = timer;
|
||||
}
|
||||
m_addressReqTimer[dst].SetFunction (&RoutingProtocol::RouteRequestTimerExpire, this);
|
||||
m_addressReqTimer[dst].Cancel ();
|
||||
m_addressReqTimer[dst].SetArguments (dst, ttl);
|
||||
m_routingTable.LookupRoute (dst, rt);
|
||||
if (ttl == NetDiameter)
|
||||
{
|
||||
rt.IncrementRreqCnt ();
|
||||
m_routingTable.Update (rt);
|
||||
m_addressReqTimer[dst].Schedule (Scalar (rt.GetRreqCnt ()) * NetTraversalTime);
|
||||
}
|
||||
else
|
||||
m_addressReqTimer[dst].Schedule (Scalar (2) * NodeTraversalTime * Scalar (ttl + TIMEOUT_BUFFER));
|
||||
|
||||
ScheduleRreqRetry (dst, ttl);
|
||||
htimer.Cancel ();
|
||||
htimer.Schedule (HelloInterval);
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::ScheduleRreqRetry (Ipv4Address dst, uint16_t ttl)
|
||||
{
|
||||
if (m_addressReqTimer.find (dst) == m_addressReqTimer.end ())
|
||||
{
|
||||
Timer timer (Timer::CANCEL_ON_DESTROY);
|
||||
m_addressReqTimer[dst] = timer;
|
||||
}
|
||||
m_addressReqTimer[dst].SetFunction (&RoutingProtocol::RouteRequestTimerExpire, this);
|
||||
m_addressReqTimer[dst].Cancel ();
|
||||
m_addressReqTimer[dst].SetArguments (dst, ttl);
|
||||
RoutingTableEntry rt;
|
||||
m_routingTable.LookupRoute (dst, rt);
|
||||
if (ttl == NetDiameter)
|
||||
{
|
||||
rt.IncrementRreqCnt ();
|
||||
m_routingTable.Update (rt);
|
||||
m_addressReqTimer[dst].Schedule (Scalar (rt.GetRreqCnt ()) * NetTraversalTime);
|
||||
}
|
||||
else
|
||||
m_addressReqTimer[dst].Schedule (Scalar (2) * NodeTraversalTime * Scalar (ttl + TIMEOUT_BUFFER));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RoutingProtocol::RecvAodv (Ptr<Socket> socket )
|
||||
{
|
||||
@@ -1065,15 +1065,6 @@ RoutingProtocol::HelloTimerExpire ()
|
||||
htimer.Schedule (HelloInterval + Seconds(UniformVariable().GetValue (0, 0.01)) );
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::NeighborTimerExpire ()
|
||||
{
|
||||
NS_LOG_FUNCTION(this);
|
||||
m_nb.Purge ();
|
||||
ntimer.Cancel ();
|
||||
ntimer.Schedule (HelloInterval);
|
||||
}
|
||||
|
||||
void
|
||||
RoutingProtocol::RouteCacheTimerExpire ()
|
||||
{
|
||||
|
||||
@@ -145,6 +145,11 @@ private:
|
||||
void LocalRouteRepair (Ipv4Address dst, Ipv4Address origin);
|
||||
/// Process broken link
|
||||
void HandleLinkFailure (Ipv4Address id);
|
||||
/**
|
||||
* To reduce congestion in a network, repeated attempts by a source node at route discovery
|
||||
* for a single destination MUST utilize a binary exponential backoff.
|
||||
*/
|
||||
void ScheduleRreqRetry (Ipv4Address dst, uint16_t ttl);
|
||||
/// Purge all expired records from m_routingTable
|
||||
void RtPurge ();
|
||||
/**
|
||||
@@ -219,8 +224,6 @@ private:
|
||||
//\{
|
||||
Timer htimer; // TODO independent hello timers for all interfaces
|
||||
void HelloTimerExpire ();
|
||||
Timer ntimer;
|
||||
void NeighborTimerExpire ();
|
||||
Timer rtimer;
|
||||
void RouteCacheTimerExpire ();
|
||||
Timer lrtimer;
|
||||
|
||||
Reference in New Issue
Block a user