A Discrete-Event Network Simulator
API
olsr-routing-protocol-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2004 Francisco J. Ros
4  * Copyright (c) 2007 INESC Porto
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors: Francisco J. Ros <fjrm@dif.um.es>
20  * Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
21  */
22 
23 #include "ns3/test.h"
24 #include "ns3/olsr-routing-protocol.h"
25 #include "ns3/ipv4-header.h"
26 
33 /********** Willingness **********/
34 
36 #define OLSR_WILL_NEVER 0
37 #define OLSR_WILL_LOW 1
39 #define OLSR_WILL_DEFAULT 3
41 #define OLSR_WILL_HIGH 6
43 #define OLSR_WILL_ALWAYS 7
45 
46 using namespace ns3;
47 using namespace olsr;
48 
49 
56 class OlsrMprTestCase : public TestCase
57 {
58 public:
59  OlsrMprTestCase ();
60  ~OlsrMprTestCase ();
61  virtual void DoRun (void);
62 };
63 
64 
66  : TestCase ("Check OLSR MPR computing mechanism")
67 {
68 }
70 {
71 }
72 void
74 {
75  Ptr<RoutingProtocol> protocol = CreateObject<RoutingProtocol> ();
76  protocol->m_mainAddress = Ipv4Address ("10.0.0.1");
77  OlsrState & state = protocol->m_state;
78 
79  /*
80  * 1 -- 2
81  * | |
82  * 3 -- 4
83  *
84  * Node 1 must select only one MPR (2 or 3, doesn't matter)
85  */
86  NeighborTuple neigbor;
87  neigbor.status = NeighborTuple::STATUS_SYM;
88  neigbor.willingness = OLSR_WILL_DEFAULT;
89  neigbor.neighborMainAddr = Ipv4Address ("10.0.0.2");
90  protocol->m_state.InsertNeighborTuple (neigbor);
91  neigbor.neighborMainAddr = Ipv4Address ("10.0.0.3");
92  protocol->m_state.InsertNeighborTuple (neigbor);
93  TwoHopNeighborTuple tuple;
94  tuple.expirationTime = Seconds (3600);
95  tuple.neighborMainAddr = Ipv4Address ("10.0.0.2");
96  tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.4");
97  protocol->m_state.InsertTwoHopNeighborTuple (tuple);
98  tuple.neighborMainAddr = Ipv4Address ("10.0.0.3");
99  tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.4");
100  protocol->m_state.InsertTwoHopNeighborTuple (tuple);
101 
102  protocol->MprComputation ();
103  NS_TEST_EXPECT_MSG_EQ (state.GetMprSet ().size (), 1, "An only address must be chosen.");
104  /*
105  * 1 -- 2 -- 5
106  * | |
107  * 3 -- 4
108  *
109  * Node 1 must select node 2 as MPR.
110  */
111  tuple.neighborMainAddr = Ipv4Address ("10.0.0.2");
112  tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5");
113  protocol->m_state.InsertTwoHopNeighborTuple (tuple);
114 
115  protocol->MprComputation ();
116  MprSet mpr = state.GetMprSet ();
117  NS_TEST_EXPECT_MSG_EQ (mpr.size (), 1, "An only address must be chosen.");
118  NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.2") != mpr.end ()), true, "Node 1 must select node 2 as MPR");
119  /*
120  * 1 -- 2 -- 5
121  * | |
122  * 3 -- 4
123  * |
124  * 6
125  *
126  * Node 1 must select nodes 2 and 3 as MPRs.
127  */
128  tuple.neighborMainAddr = Ipv4Address ("10.0.0.3");
129  tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.6");
130  protocol->m_state.InsertTwoHopNeighborTuple (tuple);
131 
132  protocol->MprComputation ();
133  mpr = state.GetMprSet ();
134  NS_TEST_EXPECT_MSG_EQ (mpr.size (), 2, "An only address must be chosen.");
135  NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.2") != mpr.end ()), true, "Node 1 must select node 2 as MPR");
136  NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.3") != mpr.end ()), true, "Node 1 must select node 3 as MPR");
137  /*
138  * 7 (OLSR_WILL_ALWAYS)
139  * |
140  * 1 -- 2 -- 5
141  * | |
142  * 3 -- 4
143  * |
144  * 6
145  *
146  * Node 1 must select nodes 2, 3 and 7 (since it is WILL_ALWAYS) as MPRs.
147  */
148  neigbor.willingness = OLSR_WILL_ALWAYS;
149  neigbor.neighborMainAddr = Ipv4Address ("10.0.0.7");
150  protocol->m_state.InsertNeighborTuple (neigbor);
151 
152  protocol->MprComputation ();
153  mpr = state.GetMprSet ();
154  NS_TEST_EXPECT_MSG_EQ (mpr.size (), 3, "An only address must be chosen.");
155  NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.7") != mpr.end ()), true, "Node 1 must select node 7 as MPR");
156  /*
157  * 7 <- WILL_ALWAYS
158  * |
159  * 9 -- 8 -- 1 -- 2 -- 5
160  * | |
161  * ^ 3 -- 4
162  * | |
163  * WILL_NEVER 6
164  *
165  * Node 1 must select nodes 2, 3 and 7 (since it is WILL_ALWAYS) as MPRs.
166  * Node 1 must NOT select node 8 as MPR since it is WILL_NEVER
167  */
168  neigbor.willingness = OLSR_WILL_NEVER;
169  neigbor.neighborMainAddr = Ipv4Address ("10.0.0.8");
170  protocol->m_state.InsertNeighborTuple (neigbor);
171  tuple.neighborMainAddr = Ipv4Address ("10.0.0.8");
172  tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.9");
173  protocol->m_state.InsertTwoHopNeighborTuple (tuple);
174 
175  protocol->MprComputation ();
176  mpr = state.GetMprSet ();
177  NS_TEST_EXPECT_MSG_EQ (mpr.size (), 3, "An only address must be chosen.");
178  NS_TEST_EXPECT_MSG_EQ ((mpr.find ("10.0.0.9") == mpr.end ()), true, "Node 1 must NOT select node 8 as MPR");
179 }
180 
188 {
189 public:
191 };
192 
194  : TestSuite ("routing-olsr", UNIT)
195 {
196  AddTestCase (new OlsrMprTestCase (), TestCase::QUICK);
197 }
198 
#define OLSR_WILL_ALWAYS
Willingness for forwarding packets from other nodes: always.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
A suite of tests to run.
Definition: test.h:1342
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:285
encapsulates test code
Definition: test.h:1155
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Definition: olsr.py:1
static OlsrProtocolTestSuite g_olsrProtocolTestSuite
Static variable for test initialization.
#define OLSR_WILL_NEVER
Willingness for forwarding packets from other nodes: never.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
virtual void DoRun(void)
Implementation to actually run this TestCase.
std::set< Ipv4Address > MprSet
MPR Set type.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
#define OLSR_WILL_DEFAULT
Willingness for forwarding packets from other nodes: medium.
Testcase for MPR computation mechanism.