From e43fa493b0c30a35d14f4d62f06bc8b67fe83d36 Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Wed, 5 Aug 2009 14:51:05 +0400 Subject: [PATCH] routing table's timer moved in class RoutingTable --- src/routing/aodv/aodv-neighbor.cc | 9 ++++----- src/routing/aodv/aodv-neighbor.h | 2 +- src/routing/aodv/aodv-routing-protocol.cc | 23 +++-------------------- src/routing/aodv/aodv-rtable.cc | 19 ++++++++++++++++++- src/routing/aodv/aodv-rtable.h | 4 +++- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/routing/aodv/aodv-neighbor.cc b/src/routing/aodv/aodv-neighbor.cc index 2688cec74..52151ec71 100644 --- a/src/routing/aodv/aodv-neighbor.cc +++ b/src/routing/aodv/aodv-neighbor.cc @@ -42,7 +42,6 @@ Neighbors::Neighbors (Callback cb, Time delay) : m_handleLinl m_ntimer.SetFunction(&Neighbors::Purge, this); } - bool Neighbors::Lookup (Ipv4Address addr) { @@ -101,13 +100,13 @@ Neighbors::Purge () m_handleLinleFailure (i->m_neighborAddress); } m_nb.erase (i, m_nb.end ()); - + m_ntimer.Cancel(); + m_ntimer.Schedule(); } void -Neighbors::Shedule () +Neighbors::ScheduleTimer () { - m_ntimer.Cancel(); m_ntimer.Schedule(); } @@ -173,7 +172,7 @@ NeighborTest::RunTests () neighbor.Update (Ipv4Address("2.2.2.2"), Seconds(10)); neighbor.Update (Ipv4Address("3.3.3.3"), Seconds(20)); - Simulator::Schedule (Seconds(1), &NeighborTest::CheckTimeout1, this); + Simulator::Schedule (Seconds(2), &NeighborTest::CheckTimeout1, this); Simulator::Schedule (Seconds(15), &NeighborTest::CheckTimeout2, this); Simulator::Schedule (Seconds(30), &NeighborTest::CheckTimeout3, this); Simulator::Run (); diff --git a/src/routing/aodv/aodv-neighbor.h b/src/routing/aodv/aodv-neighbor.h index 8e2866430..54a847358 100644 --- a/src/routing/aodv/aodv-neighbor.h +++ b/src/routing/aodv/aodv-neighbor.h @@ -64,7 +64,7 @@ public: bool IsNeighbor (Ipv4Address addr); void Update (Ipv4Address addr, Time expire); void Purge (); - void Shedule (); + void ScheduleTimer (); private: struct IsExpired { diff --git a/src/routing/aodv/aodv-routing-protocol.cc b/src/routing/aodv/aodv-routing-protocol.cc index 80885363a..895e71f92 100644 --- a/src/routing/aodv/aodv-routing-protocol.cc +++ b/src/routing/aodv/aodv-routing-protocol.cc @@ -82,7 +82,7 @@ RoutingProtocol::RoutingProtocol () : TIMEOUT_BUFFER (2), 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_routingTable (DeletePeriod, FREQUENCY), m_queue (MaxQueueLen, MaxQueueTime), 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) @@ -209,8 +209,8 @@ RoutingProtocol::Start () m_scb = MakeCallback (&RoutingProtocol::Send, this); m_ecb = MakeCallback (&RoutingProtocol::Drop, this); - m_nb.Shedule(); - rtimer.Schedule(); + m_nb.ScheduleTimer (); + m_routingTable.ScheduleTimer (); } Ptr @@ -362,12 +362,10 @@ RoutingProtocol::SetIpv4 (Ptr ipv4) NS_ASSERT (ipv4 != 0); NS_ASSERT (m_ipv4 == 0); - rtimer.SetFunction (&RoutingProtocol::RouteCacheTimerExpire, this); lrtimer.SetFunction (&RoutingProtocol::LocalRepairTimerExpire, this); htimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this); htimer.SetDelay (HelloInterval); - rtimer.SetDelay (FREQUENCY); m_ipv4 = ipv4; Simulator::ScheduleNow (&RoutingProtocol::Start, this); @@ -1065,14 +1063,6 @@ RoutingProtocol::HelloTimerExpire () htimer.Schedule (HelloInterval + Seconds(UniformVariable().GetValue (0, 0.01)) ); } -void -RoutingProtocol::RouteCacheTimerExpire () -{ - NS_LOG_FUNCTION(this); - RtPurge (); - rtimer.Schedule (FREQUENCY); -} - void RoutingProtocol::LocalRepairTimerExpire () { @@ -1286,12 +1276,5 @@ RoutingProtocol::HandleLinkFailure (Ipv4Address addr ) // TODO } -void -RoutingProtocol::RtPurge () -{ - NS_LOG_FUNCTION(this); - m_routingTable.Purge (); - // TODO AODV::rt_purge() -} } } diff --git a/src/routing/aodv/aodv-rtable.cc b/src/routing/aodv/aodv-rtable.cc index 18b04631a..f11d6a18f 100644 --- a/src/routing/aodv/aodv-rtable.cc +++ b/src/routing/aodv/aodv-rtable.cc @@ -254,6 +254,13 @@ AodvRtableEntryTest::RunTests () The Routing Table */ +RoutingTable::RoutingTable (Time t, Time delay) : m_badLinkLifetime (t), m_rtimer (Timer::CANCEL_ON_DESTROY) +{ + m_rtimer.SetDelay(delay); + m_rtimer.SetFunction(&RoutingTable::Purge, this); +} + + bool RoutingTable::LookupRoute (Ipv4Address id, RoutingTableEntry & rt ) { @@ -364,6 +371,9 @@ RoutingTable::Purge () } ++i; } + m_rtimer.Cancel(); + m_rtimer.Schedule(); + } bool @@ -390,6 +400,13 @@ RoutingTable::Print (std::ostream &os ) const } +void +RoutingTable::ScheduleTimer () +{ + m_rtimer.Schedule(); +} + + #ifdef RUN_SELF_TESTS /// Unit test for AODV routing table struct AodvRtableTest : public Test @@ -406,7 +423,7 @@ static AodvRtableTest g_AodvRtableTest; bool AodvRtableTest::RunTests () { - RoutingTable rtable (Seconds(2)); + RoutingTable rtable (Seconds(2), Seconds(0.5)); NS_TEST_ASSERT_EQUAL (rtable.GetBadLinkLifetime(), Seconds(2)); rtable.SetBadLinkLifetime(Seconds(1)); NS_TEST_ASSERT_EQUAL (rtable.GetBadLinkLifetime(), Seconds(1)); diff --git a/src/routing/aodv/aodv-rtable.h b/src/routing/aodv/aodv-rtable.h index 3e3fe13f9..5351940ab 100644 --- a/src/routing/aodv/aodv-rtable.h +++ b/src/routing/aodv/aodv-rtable.h @@ -189,7 +189,7 @@ public: class RoutingTable { public: - RoutingTable(Time t) : m_badLinkLifetime (t) {} + RoutingTable(Time t, Time delay); ///\name Handle life time of invalid route //\{ Time GetBadLinkLifetime () const { return m_badLinkLifetime; } @@ -239,10 +239,12 @@ public: bool MarkLinkAsUinidirectional(Ipv4Address neighbor, Time blacklistTimeout); /// Print routing table void Print(std::ostream &os) const; + void ScheduleTimer (); private: std::map m_ipv4AddressEntry; Time m_badLinkLifetime; + Timer m_rtimer; }; }}