routing table's timer moved in class RoutingTable

This commit is contained in:
Borovkova Elena
2009-08-05 14:51:05 +04:00
parent 2c9182fc2f
commit e43fa493b0
5 changed files with 29 additions and 28 deletions

View File

@@ -42,7 +42,6 @@ Neighbors::Neighbors (Callback<void, Ipv4Address> 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 ();

View File

@@ -64,7 +64,7 @@ public:
bool IsNeighbor (Ipv4Address addr);
void Update (Ipv4Address addr, Time expire);
void Purge ();
void Shedule ();
void ScheduleTimer ();
private:
struct IsExpired
{

View File

@@ -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<Ipv4Route>
@@ -362,12 +362,10 @@ RoutingProtocol::SetIpv4 (Ptr<Ipv4> 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()
}
}
}

View File

@@ -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));

View File

@@ -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<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
Time m_badLinkLifetime;
Timer m_rtimer;
};
}}