1.1 --- a/src/routing/olsr/olsr-header.cc Thu Nov 12 14:08:51 2009 +0100
1.2 +++ b/src/routing/olsr/olsr-header.cc Fri Nov 13 11:47:02 2009 +0300
1.3 @@ -785,7 +785,7 @@
1.4 } g_olsrTestSuite;
1.5
1.6 OlsrTestSuite::OlsrTestSuite()
1.7 - : TestSuite("olsr-routing", UNIT)
1.8 + : TestSuite("Routing-OLSR-header", UNIT)
1.9 {
1.10 AddTestCase(new OlsrHnaTestCase());
1.11 AddTestCase(new OlsrTcTestCase());
2.1 --- a/src/routing/olsr/olsr-routing-protocol.cc Thu Nov 12 14:08:51 2009 +0100
2.2 +++ b/src/routing/olsr/olsr-routing-protocol.cc Fri Nov 13 11:47:02 2009 +0300
2.3 @@ -716,6 +716,10 @@
2.4 if (max == NULL || nb_tuple->willingness > max->willingness)
2.5 {
2.6 max = nb_tuple;
2.7 + for (TwoHopNeighborSet::iterator newCovered = N2.begin (); newCovered != N2.end (); newCovered++)
2.8 + {
2.9 + coveredTwoHopNeighbors.insert (newCovered->twoHopNeighborAddr);
2.10 + }
2.11 max_r = r;
2.12 }
2.13 else if (nb_tuple->willingness == max->willingness)
2.14 @@ -740,11 +744,12 @@
2.15 if (max != NULL)
2.16 {
2.17 mprSet.insert (max->neighborMainAddr);
2.18 - for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin ();
2.19 - twoHopNeigh != N2.end (); )
2.20 + // Remove the nodes from N2 which are now covered by a node in the MPR set.
2.21 + for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); twoHopNeigh != N2.end (); )
2.22 {
2.23 - if (twoHopNeigh->neighborMainAddr == max->neighborMainAddr)
2.24 + if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ())
2.25 {
2.26 + NS_LOG_LOGIC ("2-hop neigh. " << twoHopNeigh->twoHopNeighborAddr << " is already covered by an MPR.");
2.27 twoHopNeigh = N2.erase (twoHopNeigh);
2.28 }
2.29 else
2.30 @@ -2780,6 +2785,128 @@
2.31 }
2.32 return retval;
2.33 }
2.34 +OlsrMprTestCase::OlsrMprTestCase ()
2.35 + : TestCase ("Check OLSR MPR computing mechanism")
2.36 +{
2.37 +}
2.38 +OlsrMprTestCase::~OlsrMprTestCase ()
2.39 +{
2.40 +}
2.41 +bool
2.42 +OlsrMprTestCase::DoRun ()
2.43 +{
2.44 + /*
2.45 + * Create a 3x3 grid like the following:
2.46 + * 3---6---9
2.47 + * |\ /|\ /|
2.48 + * | X | X |
2.49 + * |/ \|/ \|
2.50 + * 2---5---8
2.51 + * |\ /|\ /|
2.52 + * | X | X |
2.53 + * |/ \|/ \|
2.54 + * 1---4---7
2.55 + * PrepareTopology fills all 2-hop neighbors of station 1 and creates a routing protocol
2.56 + * We are the station number 2. Obvious, that an only MPR in this case is 5
2.57 + */
2.58 + Ptr<RoutingProtocol> m_protocol = CreateObject<RoutingProtocol> ();
2.59 + m_protocol->m_mainAddress = Ipv4Address ("10.0.0.2");
2.60 + // we fill all possible 2-hop neighborhood
2.61 + TwoHopNeighborTuple tuple;
2.62 + tuple.expirationTime = Seconds (3600);
2.63 + // All neighbor stations which are seen from station 5
2.64 + tuple.neighborMainAddr = Ipv4Address ("10.0.0.5");
2.65 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.1");
2.66 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.67 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2");
2.68 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.69 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.3");
2.70 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.71 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.4");
2.72 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.73 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.6");
2.74 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.75 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.7");
2.76 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.77 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.8");
2.78 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.79 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.9");
2.80 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.81 + // All neighbor stations which are seen from station 4
2.82 + tuple.neighborMainAddr = Ipv4Address ("10.0.0.4");
2.83 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.1");
2.84 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.85 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2");
2.86 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.87 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5");
2.88 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.89 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.8");
2.90 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.91 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.7");
2.92 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.93 +
2.94 + // All neighbor stations which are seen from station 6
2.95 + tuple.neighborMainAddr = Ipv4Address ("10.0.0.6");
2.96 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.3");
2.97 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.98 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2");
2.99 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.100 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5");
2.101 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.102 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.8");
2.103 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.104 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.9");
2.105 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.106 +
2.107 + // All neighbor stations which are seen from station 1
2.108 + tuple.neighborMainAddr = Ipv4Address ("10.0.0.1");
2.109 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2");
2.110 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.111 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5");
2.112 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.113 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.4");
2.114 +
2.115 + // All neighbor stations which are seen from station 3
2.116 + tuple.neighborMainAddr = Ipv4Address ("10.0.0.3");
2.117 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2");
2.118 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.119 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5");
2.120 + m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2.121 + tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.6");
2.122 + // First, we fill all neighbors
2.123 + // If neighbors willingness = OLSR_WILL_DEFAULT, an only station number 5 will be an MPR
2.124 + NeighborTuple neigbor;
2.125 + neigbor.status = NeighborTuple::STATUS_SYM;
2.126 + neigbor.willingness = OLSR_WILL_DEFAULT;
2.127 + neigbor.neighborMainAddr = Ipv4Address ("10.0.0.3");
2.128 + m_protocol->m_state.InsertNeighborTuple (neigbor);
2.129 + neigbor.neighborMainAddr = Ipv4Address ("10.0.0.6");
2.130 + m_protocol->m_state.InsertNeighborTuple (neigbor);
2.131 + neigbor.neighborMainAddr = Ipv4Address ("10.0.0.5");
2.132 + m_protocol->m_state.InsertNeighborTuple (neigbor);
2.133 + neigbor.neighborMainAddr = Ipv4Address ("10.0.0.4");
2.134 + m_protocol->m_state.InsertNeighborTuple (neigbor);
2.135 + neigbor.neighborMainAddr = Ipv4Address ("10.0.0.1");
2.136 + m_protocol->m_state.InsertNeighborTuple (neigbor);
2.137 + //Now, calculateMPR
2.138 + m_protocol->MprComputation ();
2.139 + //Check results
2.140 + NS_TEST_ASSERT_MSG_EQ (m_protocol->m_state.FindMprAddress (Ipv4Address ("10.0.0.5")), true, "MPR is incorrect!");
2.141 + NS_TEST_ASSERT_MSG_EQ (m_protocol->m_state.GetMprSet ().size (), 1 , "An only address must be chosen!\n");
2.142 + return false;
2.143 +}
2.144 +
2.145 +static class OlsrProtocolTestSuite : public TestSuite
2.146 +{
2.147 +public:
2.148 + OlsrProtocolTestSuite ();
2.149 +} g_olsrProtocolTestSuite;
2.150 +
2.151 +OlsrProtocolTestSuite::OlsrProtocolTestSuite()
2.152 + : TestSuite("Routing-OLSR", UNIT)
2.153 +{
2.154 + AddTestCase (new OlsrMprTestCase ());
2.155 +}
2.156
2.157
2.158 }} // namespace olsr, ns3
3.1 --- a/src/routing/olsr/olsr-routing-protocol.h Thu Nov 12 14:08:51 2009 +0100
3.2 +++ b/src/routing/olsr/olsr-routing-protocol.h Fri Nov 13 11:47:02 2009 +0300
3.3 @@ -25,6 +25,7 @@
3.4 #define __OLSR_AGENT_IMPL_H__
3.5
3.6 #include "olsr-header.h"
3.7 +#include "ns3/test.h"
3.8 #include "olsr-state.h"
3.9 #include "olsr-repositories.h"
3.10
3.11 @@ -58,11 +59,21 @@
3.12 destAddr (), nextAddr (),
3.13 interface (0), distance (0) {};
3.14 };
3.15 +class RoutingProtocol;
3.16 +/// Testcase for MPR computation mechanism
3.17 +class OlsrMprTestCase : public TestCase {
3.18 +public:
3.19 + OlsrMprTestCase ();
3.20 + ~OlsrMprTestCase ();
3.21 + virtual bool DoRun (void);
3.22 + ;
3.23 +};
3.24
3.25
3.26 class RoutingProtocol : public Ipv4RoutingProtocol
3.27 {
3.28 public:
3.29 + friend class OlsrMprTestCase;
3.30 static TypeId GetTypeId (void);
3.31
3.32 RoutingProtocol ();
4.1 --- a/src/routing/olsr/olsr-state.cc Thu Nov 12 14:08:51 2009 +0100
4.2 +++ b/src/routing/olsr/olsr-state.cc Fri Nov 13 11:47:02 2009 +0300
4.3 @@ -272,6 +272,11 @@
4.4 {
4.5 m_mprSet = mprSet;
4.6 }
4.7 +MprSet
4.8 +OlsrState::GetMprSet () const
4.9 +{
4.10 + return m_mprSet;
4.11 +}
4.12
4.13 /********** Duplicate Set Manipulation **********/
4.14
5.1 --- a/src/routing/olsr/olsr-state.h Thu Nov 12 14:08:51 2009 +0100
5.2 +++ b/src/routing/olsr/olsr-state.h Fri Nov 13 11:47:02 2009 +0300
5.3 @@ -98,7 +98,10 @@
5.4
5.5 // MPR
5.6 bool FindMprAddress (const Ipv4Address &address);
5.7 + /// MprSet is set by routing protocol after MprCompute
5.8 void SetMprSet (MprSet mprSet);
5.9 + /// Gets an MPR Set needed by tests
5.10 + MprSet GetMprSet () const;
5.11
5.12 // Duplicate
5.13 DuplicateTuple* FindDuplicateTuple (const Ipv4Address &address,