From 2c9182fc2f51689ee2b6e1d96bac257181e670ad Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Wed, 5 Aug 2009 13:56:12 +0400 Subject: [PATCH] neighbor's timer moved in class Neighbors --- src/routing/aodv/aodv-neighbor.cc | 28 ++++++++-- src/routing/aodv/aodv-neighbor.h | 7 ++- src/routing/aodv/aodv-routing-protocol.cc | 67 ++++++++++------------- src/routing/aodv/aodv-routing-protocol.h | 7 ++- 4 files changed, 62 insertions(+), 47 deletions(-) diff --git a/src/routing/aodv/aodv-neighbor.cc b/src/routing/aodv/aodv-neighbor.cc index e7cb1e287..2688cec74 100644 --- a/src/routing/aodv/aodv-neighbor.cc +++ b/src/routing/aodv/aodv-neighbor.cc @@ -28,12 +28,21 @@ #include "aodv-neighbor.h" #include "ns3/test.h" +#include "ns3/log.h" +#include namespace ns3 { namespace aodv { +Neighbors::Neighbors (Callback 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::const_iterator i = m_nb.begin (); i != m_nb.end (); ++i) - if (i->m_expireTime < Simulator::Now ()) - { - m_handleLinleFailure (i->m_neighborAddress); - } std::vector::iterator i = remove_if (m_nb.begin (), m_nb.end (), IsExpired ()); + for (std::vector::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 (); diff --git a/src/routing/aodv/aodv-neighbor.h b/src/routing/aodv/aodv-neighbor.h index bd60710b8..8e2866430 100644 --- a/src/routing/aodv/aodv-neighbor.h +++ b/src/routing/aodv/aodv-neighbor.h @@ -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 +# namespace ns3 { namespace aodv { +class RoutingProtocol; class Neighbors { public: - Neighbors (Callback cb) : m_handleLinleFailure (cb) {} + Neighbors (Callback 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 m_handleLinleFailure; + Timer m_ntimer; std::vector m_nb; }; diff --git a/src/routing/aodv/aodv-routing-protocol.cc b/src/routing/aodv/aodv-routing-protocol.cc index 892bdcb0d..80885363a 100644 --- a/src/routing/aodv/aodv-routing-protocol.cc +++ b/src/routing/aodv/aodv-routing-protocol.cc @@ -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) 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 ) { @@ -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 () { diff --git a/src/routing/aodv/aodv-routing-protocol.h b/src/routing/aodv/aodv-routing-protocol.h index d8259dd46..ca18889f5 100644 --- a/src/routing/aodv/aodv-routing-protocol.h +++ b/src/routing/aodv/aodv-routing-protocol.h @@ -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;