--- a/src/routing/aodv/aodv-neighbor.cc Wed Aug 05 17:55:12 2009 +0400
+++ b/src/routing/aodv/aodv-neighbor.cc Wed Aug 05 18:26:17 2009 +0400
@@ -43,18 +43,6 @@
}
bool
-Neighbors::Lookup (Ipv4Address addr)
-{
- Purge ();
- for (std::vector<Neighbor>::const_iterator i = m_nb.begin (); i != m_nb.end (); ++i)
- if (i->m_neighborAddress == addr)
- {
- return true;
- }
- return false;
-}
-
-bool
Neighbors::IsNeighbor (Ipv4Address addr )
{
Purge ();
@@ -110,6 +98,7 @@
void
Neighbors::ScheduleTimer ()
{
+ m_ntimer.Cancel();
m_ntimer.Schedule();
}
@@ -118,8 +107,7 @@
/// Unit test for neighbors
struct NeighborTest : public Test
{
- NeighborTest () : Test ("AODV/Neighbor"),
- result(true) { }
+ NeighborTest () : Test ("AODV/Neighbor"), neighbor(0), result(true) { }
virtual bool RunTests();
void Handler (Ipv4Address addr);
void CheckTimeout1 ();
@@ -128,7 +116,6 @@
Neighbors * neighbor;
bool result;
};
-
/// Test instance
static NeighborTest g_NeighborTest;
@@ -140,26 +127,26 @@
void
NeighborTest::CheckTimeout1 ()
{
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("1.2.3.4")), true);
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("1.1.1.1")), true);
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("2.2.2.2")), true);
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("3.3.3.3")), true);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("1.1.1.1")), true);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("2.2.2.2")), true);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("3.3.3.3")), true);
}
void
NeighborTest::CheckTimeout2 ()
{
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("1.2.3.4")), false);
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("1.1.1.1")), false);
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("2.2.2.2")), false);
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("3.3.3.3")), true);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), false);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("1.1.1.1")), false);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("2.2.2.2")), false);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("3.3.3.3")), true);
}
void
NeighborTest::CheckTimeout3 ()
{
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("1.2.3.4")), false);
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("1.1.1.1")), false);
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("2.2.2.2")), false);
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("3.3.3.3")), false);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), false);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("1.1.1.1")), false);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("2.2.2.2")), false);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("3.3.3.3")), false);
}
bool
@@ -169,10 +156,10 @@
neighbor = &nb;
neighbor->SetCallback(MakeCallback(&NeighborTest::Handler, this));
neighbor->Update (Ipv4Address("1.2.3.4"), Seconds(1));
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("1.2.3.4")), true);
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("4.3.2.1")), false);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("4.3.2.1")), false);
neighbor->Update (Ipv4Address("1.2.3.4"), Seconds(10));
- NS_TEST_ASSERT_EQUAL (neighbor->Lookup(Ipv4Address("1.2.3.4")), true);
+ NS_TEST_ASSERT_EQUAL (neighbor->IsNeighbor(Ipv4Address("1.2.3.4")), true);
NS_TEST_ASSERT_EQUAL (neighbor->GetExpireTime (Ipv4Address("1.2.3.4")), Seconds(10));
NS_TEST_ASSERT_EQUAL (neighbor->GetExpireTime (Ipv4Address("4.3.2.1")), Seconds(0));
neighbor->Update (Ipv4Address("1.1.1.1"), Seconds(5));
--- a/src/routing/aodv/aodv-neighbor.h Wed Aug 05 17:55:12 2009 +0400
+++ b/src/routing/aodv/aodv-neighbor.h Wed Aug 05 18:26:17 2009 +0400
@@ -43,29 +43,35 @@
namespace aodv
{
class RoutingProtocol;
+/**
+ * \ingroup aodv
+ * \brief maintain list of active neighbors
+ */
class Neighbors
{
public:
+ /// c-tor
Neighbors (Time delay);
struct Neighbor
{
Ipv4Address m_neighborAddress;
Time m_expireTime;
};
- /**
- * Lookup neighbor with address addr
- * @param addr - neighbor's IP address
- * @return true on success
- */
- bool Lookup (Ipv4Address addr);
/// Return expire time for neighbor node with address addr, if exists, else return 0.
Time GetExpireTime (Ipv4Address addr);
/// Check that node with address addr is neighbor
bool IsNeighbor (Ipv4Address addr);
+ /// Update expire time for entry with address addr, if it exists, else add new entry
void Update (Ipv4Address addr, Time expire);
+ /// Remove all expired entries
void Purge ();
+ /// Schedule m_ntimer.
void ScheduleTimer ();
+ ///\name Handle link failure callback
+ //\{
void SetCallback (Callback<void, Ipv4Address> cb) { m_handleLinleFailure = cb;}
+ Callback<void, Ipv4Address> GetCallback () const { return m_handleLinleFailure; }
+ //\}
private:
struct IsExpired
{
@@ -74,9 +80,11 @@
return (nb.m_expireTime < Simulator::Now());
}
};
-
+ /// link failure callback
Callback<void, Ipv4Address> m_handleLinleFailure;
+ /// Timer for neighbor's list. Schedule Purge().
Timer m_ntimer;
+ /// vector of entries
std::vector<Neighbor> m_nb;
};
--- a/src/routing/aodv/aodv-routing-protocol.h Wed Aug 05 17:55:12 2009 +0400
+++ b/src/routing/aodv/aodv-routing-protocol.h Wed Aug 05 18:26:17 2009 +0400
@@ -150,8 +150,6 @@
* 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 ();
/**
* Update route lifetime.
* \param addr - destination address
--- a/src/routing/aodv/id-cache.h Wed Aug 05 17:55:12 2009 +0400
+++ b/src/routing/aodv/id-cache.h Wed Aug 05 18:26:17 2009 +0400
@@ -46,10 +46,15 @@
class IdCache
{
public:
+ /// c-tor
IdCache () {}
+ /// Insert entry (addr, id) in cache if it does not exist before
void InsertId (Ipv4Address addr, uint32_t id, Time saveTime);
+ /// Check that entry (addr, id) exists in cache
bool LookupId (Ipv4Address addr, uint32_t id);
+ /// Remove all expired entries
void Purge ();
+ /// Return number of entries in cache
uint32_t GetSize ();
private:
struct UniqueId