diff -r eadb84419eb8 src/routing/olsr/olsr-header.cc --- a/src/routing/olsr/olsr-header.cc Wed Nov 11 15:35:03 2009 +0300 +++ b/src/routing/olsr/olsr-header.cc Thu Nov 12 18:40:41 2009 +0300 @@ -785,7 +785,7 @@ } g_olsrTestSuite; OlsrTestSuite::OlsrTestSuite() - : TestSuite("olsr-routing", UNIT) + : TestSuite("Routing-OLSR-header", UNIT) { AddTestCase(new OlsrHnaTestCase()); AddTestCase(new OlsrTcTestCase()); diff -r eadb84419eb8 src/routing/olsr/olsr-routing-protocol.cc --- a/src/routing/olsr/olsr-routing-protocol.cc Wed Nov 11 15:35:03 2009 +0300 +++ b/src/routing/olsr/olsr-routing-protocol.cc Thu Nov 12 18:40:41 2009 +0300 @@ -2832,6 +2839,128 @@ } return false; } +OlsrMprTestCase::OlsrMprTestCase () + : TestCase ("Check OLSR MPR computing mechanism") +{ +} +OlsrMprTestCase::~OlsrMprTestCase () +{ +} +bool +OlsrMprTestCase::DoRun () +{ + /* + * Create a 3x3 grid like the following: + * 3---6---9 + * |\ /|\ /| + * | X | X | + * |/ \|/ \| + * 2---5---8 + * |\ /|\ /| + * | X | X | + * |/ \|/ \| + * 1---4---7 + * PrepareTopology fills all 2-hop neighbors of station 1 and creates a routing protocol + * We are the station number 2. Obvious, that an only MPR in this case is 5 + */ + Ptr m_protocol = CreateObject (); + m_protocol->m_mainAddress = Ipv4Address ("10.0.0.2"); + // we fill all possible 2-hop neighborhood + TwoHopNeighborTuple tuple; + tuple.expirationTime = Seconds (3600); + // All neighbor stations which are seen from station 5 + tuple.neighborMainAddr = Ipv4Address ("10.0.0.5"); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.1"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.3"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.4"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.6"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.7"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.8"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.9"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + // All neighbor stations which are seen from station 4 + tuple.neighborMainAddr = Ipv4Address ("10.0.0.4"); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.1"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.8"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.7"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + + // All neighbor stations which are seen from station 6 + tuple.neighborMainAddr = Ipv4Address ("10.0.0.6"); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.3"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.8"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.9"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + + // All neighbor stations which are seen from station 1 + tuple.neighborMainAddr = Ipv4Address ("10.0.0.1"); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.4"); + + // All neighbor stations which are seen from station 3 + tuple.neighborMainAddr = Ipv4Address ("10.0.0.3"); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5"); + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple); + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.6"); + // First, we fill all neighbors + // If neighbors willingness = OLSR_WILL_DEFAULT, an only station number 5 will be an MPR + NeighborTuple neigbor; + neigbor.status = NeighborTuple::STATUS_SYM; + neigbor.willingness = OLSR_WILL_DEFAULT; + neigbor.neighborMainAddr = Ipv4Address ("10.0.0.3"); + m_protocol->m_state.InsertNeighborTuple (neigbor); + neigbor.neighborMainAddr = Ipv4Address ("10.0.0.6"); + m_protocol->m_state.InsertNeighborTuple (neigbor); + neigbor.neighborMainAddr = Ipv4Address ("10.0.0.5"); + m_protocol->m_state.InsertNeighborTuple (neigbor); + neigbor.neighborMainAddr = Ipv4Address ("10.0.0.4"); + m_protocol->m_state.InsertNeighborTuple (neigbor); + neigbor.neighborMainAddr = Ipv4Address ("10.0.0.1"); + m_protocol->m_state.InsertNeighborTuple (neigbor); + //Now, calculateMPR + m_protocol->MprComputation (); + //Check results + NS_TEST_ASSERT_MSG_EQ (m_protocol->m_state.FindMprAddress (Ipv4Address ("10.0.0.5")), true, "MPR is incorrect!"); + NS_TEST_ASSERT_MSG_EQ (m_protocol->m_state.GetMprSet ().size (), 1 , "An only address must be chosen!\n"); + return false; +} + +static class OlsrProtocolTestSuite : public TestSuite +{ +public: + OlsrProtocolTestSuite (); +} g_olsrProtocolTestSuite; + +OlsrProtocolTestSuite::OlsrProtocolTestSuite() + : TestSuite("Routing-OLSR", UNIT) +{ + AddTestCase (new OlsrMprTestCase ()); +} }} // namespace olsr, ns3 diff -r eadb84419eb8 src/routing/olsr/olsr-routing-protocol.h --- a/src/routing/olsr/olsr-routing-protocol.h Wed Nov 11 15:35:03 2009 +0300 +++ b/src/routing/olsr/olsr-routing-protocol.h Thu Nov 12 18:40:41 2009 +0300 @@ -25,6 +25,7 @@ #define __OLSR_AGENT_IMPL_H__ #include "olsr-header.h" +#include "ns3/test.h" #include "olsr-state.h" #include "olsr-repositories.h" @@ -58,11 +59,21 @@ destAddr (), nextAddr (), interface (0), distance (0) {}; }; +class RoutingProtocol; +/// Testcase for MPR computation mechanism +class OlsrMprTestCase : public TestCase { +public: + OlsrMprTestCase (); + ~OlsrMprTestCase (); + virtual bool DoRun (void); + ; +}; class RoutingProtocol : public Ipv4RoutingProtocol { public: + friend class OlsrMprTestCase; static TypeId GetTypeId (void); RoutingProtocol (); diff -r eadb84419eb8 src/routing/olsr/olsr-state.cc --- a/src/routing/olsr/olsr-state.cc Wed Nov 11 15:35:03 2009 +0300 +++ b/src/routing/olsr/olsr-state.cc Thu Nov 12 18:40:41 2009 +0300 @@ -272,6 +272,11 @@ { m_mprSet = mprSet; } +MprSet +OlsrState::GetMprSet () const +{ + return m_mprSet; +} /********** Duplicate Set Manipulation **********/ diff -r eadb84419eb8 src/routing/olsr/olsr-state.h --- a/src/routing/olsr/olsr-state.h Wed Nov 11 15:35:03 2009 +0300 +++ b/src/routing/olsr/olsr-state.h Thu Nov 12 18:40:41 2009 +0300 @@ -99,6 +99,7 @@ // MPR bool FindMprAddress (const Ipv4Address &address); void SetMprSet (MprSet mprSet); + MprSet GetMprSet () const; // Duplicate DuplicateTuple* FindDuplicateTuple (const Ipv4Address &address,