A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
21
using namespace
ns3
;
22
using namespace
olsr
;
23
24
/**
25
* @ingroup olsr-test
26
* @ingroup tests
27
*
28
* Testcase for MPR computation mechanism
29
*/
30
class
OlsrMprTestCase
:
public
TestCase
31
{
32
public
:
33
OlsrMprTestCase
();
34
~OlsrMprTestCase
()
override
;
35
void
DoRun
()
override
;
36
};
37
38
OlsrMprTestCase::OlsrMprTestCase
()
39
:
TestCase
(
"Check OLSR MPR computing mechanism"
)
40
{
41
}
42
43
OlsrMprTestCase::~OlsrMprTestCase
()
44
{
45
}
46
47
void
48
OlsrMprTestCase::DoRun
()
49
{
50
Ptr<RoutingProtocol>
protocol =
CreateObject<RoutingProtocol>
();
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
*/
172
class
OlsrProtocolTestSuite
:
public
TestSuite
173
{
174
public
:
175
OlsrProtocolTestSuite
();
176
};
177
178
OlsrProtocolTestSuite::OlsrProtocolTestSuite
()
179
:
TestSuite
(
"routing-olsr"
,
Type
::UNIT)
180
{
181
AddTestCase
(
new
OlsrMprTestCase
(), TestCase::Duration::QUICK);
182
}
183
184
static
OlsrProtocolTestSuite
g_olsrProtocolTestSuite
;
//!< Static variable for test initialization
OlsrMprTestCase
Testcase for MPR computation mechanism.
Definition
olsr-routing-protocol-test-suite.cc:31
OlsrMprTestCase::~OlsrMprTestCase
~OlsrMprTestCase() override
Definition
olsr-routing-protocol-test-suite.cc:43
OlsrMprTestCase::OlsrMprTestCase
OlsrMprTestCase()
Definition
olsr-routing-protocol-test-suite.cc:38
OlsrMprTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
olsr-routing-protocol-test-suite.cc:48
OlsrProtocolTestSuite
OLSR protocol test suite.
Definition
olsr-routing-protocol-test-suite.cc:173
OlsrProtocolTestSuite::OlsrProtocolTestSuite
OlsrProtocolTestSuite()
Definition
olsr-routing-protocol-test-suite.cc:178
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
NS_TEST_EXPECT_MSG_EQ
#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
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1344
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
olsr
Definition
olsr.py:1
g_olsrProtocolTestSuite
static OlsrProtocolTestSuite g_olsrProtocolTestSuite
Static variable for test initialization.
Definition
olsr-routing-protocol-test-suite.cc:184
src
olsr
test
olsr-routing-protocol-test-suite.cc
Generated on Mon Dec 15 2025 15:22:02 for ns-3 by
1.9.8