A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
olsr-routing-protocol-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2004 Francisco J. Ros
3 * Copyright (c) 2007 INESC Porto
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: Francisco J. Ros <fjrm@dif.um.es>
8 * Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
9 */
10
11#include "ns3/ipv4-header.h"
12#include "ns3/olsr-repositories.h"
13#include "ns3/olsr-routing-protocol.h"
14#include "ns3/test.h"
15
16/**
17 * \ingroup olsr
18 * \defgroup olsr-test olsr module tests
19 */
20
21using namespace ns3;
22using namespace olsr;
23
24/**
25 * \ingroup olsr-test
26 * \ingroup tests
27 *
28 * Testcase for MPR computation mechanism
29 */
31{
32 public:
34 ~OlsrMprTestCase() override;
35 void DoRun() override;
36};
37
39 : TestCase("Check OLSR MPR computing mechanism")
40{
41}
42
46
47void
49{
51 protocol->m_mainAddress = Ipv4Address("10.0.0.1");
52 OlsrState& state = protocol->m_state;
53
54 /*
55 * 1 -- 2
56 * | |
57 * 3 -- 4
58 *
59 * Node 1 must select only one MPR (2 or 3, doesn't matter)
60 */
61 NeighborTuple neighbor;
62 neighbor.status = NeighborTuple::STATUS_SYM;
63 neighbor.willingness = Willingness::DEFAULT;
64 neighbor.neighborMainAddr = Ipv4Address("10.0.0.2");
65 protocol->m_state.InsertNeighborTuple(neighbor);
66 neighbor.neighborMainAddr = Ipv4Address("10.0.0.3");
67 protocol->m_state.InsertNeighborTuple(neighbor);
68 TwoHopNeighborTuple tuple;
69 tuple.expirationTime = Seconds(3600);
70 tuple.neighborMainAddr = Ipv4Address("10.0.0.2");
71 tuple.twoHopNeighborAddr = Ipv4Address("10.0.0.4");
72 protocol->m_state.InsertTwoHopNeighborTuple(tuple);
73 tuple.neighborMainAddr = Ipv4Address("10.0.0.3");
74 tuple.twoHopNeighborAddr = Ipv4Address("10.0.0.4");
75 protocol->m_state.InsertTwoHopNeighborTuple(tuple);
76
77 protocol->MprComputation();
78 NS_TEST_EXPECT_MSG_EQ(state.GetMprSet().size(), 1, "An only address must be chosen.");
79 /*
80 * 1 -- 2 -- 5
81 * | |
82 * 3 -- 4
83 *
84 * Node 1 must select node 2 as MPR.
85 */
86 tuple.neighborMainAddr = Ipv4Address("10.0.0.2");
87 tuple.twoHopNeighborAddr = Ipv4Address("10.0.0.5");
88 protocol->m_state.InsertTwoHopNeighborTuple(tuple);
89
90 protocol->MprComputation();
91 MprSet mpr = state.GetMprSet();
92 NS_TEST_EXPECT_MSG_EQ(mpr.size(), 1, "An only address must be chosen.");
93 NS_TEST_EXPECT_MSG_EQ((mpr.find("10.0.0.2") != mpr.end()),
94 true,
95 "Node 1 must select node 2 as MPR");
96 /*
97 * 1 -- 2 -- 5
98 * | |
99 * 3 -- 4
100 * |
101 * 6
102 *
103 * Node 1 must select nodes 2 and 3 as MPRs.
104 */
105 tuple.neighborMainAddr = Ipv4Address("10.0.0.3");
106 tuple.twoHopNeighborAddr = Ipv4Address("10.0.0.6");
107 protocol->m_state.InsertTwoHopNeighborTuple(tuple);
108
109 protocol->MprComputation();
110 mpr = state.GetMprSet();
111 NS_TEST_EXPECT_MSG_EQ(mpr.size(), 2, "An only address must be chosen.");
112 NS_TEST_EXPECT_MSG_EQ((mpr.find("10.0.0.2") != mpr.end()),
113 true,
114 "Node 1 must select node 2 as MPR");
115 NS_TEST_EXPECT_MSG_EQ((mpr.find("10.0.0.3") != mpr.end()),
116 true,
117 "Node 1 must select node 3 as MPR");
118 /*
119 * 7 (Willingness::ALWAYS)
120 * |
121 * 1 -- 2 -- 5
122 * | |
123 * 3 -- 4
124 * |
125 * 6
126 *
127 * Node 1 must select nodes 2, 3 and 7 (since it is Willingness::ALWAYS) as MPRs.
128 */
129 neighbor.willingness = olsr::Willingness::ALWAYS;
130 neighbor.neighborMainAddr = Ipv4Address("10.0.0.7");
131 protocol->m_state.InsertNeighborTuple(neighbor);
132
133 protocol->MprComputation();
134 mpr = state.GetMprSet();
135 NS_TEST_EXPECT_MSG_EQ(mpr.size(), 3, "An only address must be chosen.");
136 NS_TEST_EXPECT_MSG_EQ((mpr.find("10.0.0.7") != mpr.end()),
137 true,
138 "Node 1 must select node 7 as MPR");
139 /*
140 * 7 <- Willingness::ALWAYS
141 * |
142 * 9 -- 8 -- 1 -- 2 -- 5
143 * | |
144 * ^ 3 -- 4
145 * | |
146 * Willingness::NEVER 6
147 *
148 * Node 1 must select nodes 2, 3 and 7 (since it is Willingness::ALWAYS) as MPRs.
149 * Node 1 must NOT select node 8 as MPR since it is Willingness::NEVER
150 */
151 neighbor.willingness = Willingness::NEVER;
152 neighbor.neighborMainAddr = Ipv4Address("10.0.0.8");
153 protocol->m_state.InsertNeighborTuple(neighbor);
154 tuple.neighborMainAddr = Ipv4Address("10.0.0.8");
155 tuple.twoHopNeighborAddr = Ipv4Address("10.0.0.9");
156 protocol->m_state.InsertTwoHopNeighborTuple(tuple);
157
158 protocol->MprComputation();
159 mpr = state.GetMprSet();
160 NS_TEST_EXPECT_MSG_EQ(mpr.size(), 3, "An only address must be chosen.");
161 NS_TEST_EXPECT_MSG_EQ((mpr.find("10.0.0.9") == mpr.end()),
162 true,
163 "Node 1 must NOT select node 8 as MPR");
164}
165
166/**
167 * \ingroup olsr-test
168 * \ingroup tests
169 *
170 * OLSR protocol test suite
171 */
173{
174 public:
176};
177
179 : TestSuite("routing-olsr", Type::UNIT)
180{
181 AddTestCase(new OlsrMprTestCase(), TestCase::Duration::QUICK);
182}
183
184static OlsrProtocolTestSuite g_olsrProtocolTestSuite; //!< Static variable for test initialization
Testcase for MPR computation mechanism.
void DoRun() override
Implementation to actually run this TestCase.
Ipv4 addresses are stored in host order in this class.
Smart pointer class similar to boost::intrusive_ptr.
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:241
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
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.