A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
27
/********** Willingness **********/
28
30
#define OLSR_WILL_NEVER 0
31
32
#define OLSR_WILL_LOW 1
33
34
#define OLSR_WILL_DEFAULT 3
35
36
#define OLSR_WILL_HIGH 6
37
38
#define OLSR_WILL_ALWAYS 7
39
40
namespace
ns3 {
41
namespace
olsr {
42
44
class
OlsrMprTestCase
:
public
TestCase
{
45
public
:
46
OlsrMprTestCase
();
47
~OlsrMprTestCase
();
49
virtual
void
DoRun
(
void
);
50
;
51
};
52
53
54
OlsrMprTestCase::OlsrMprTestCase
()
55
:
TestCase
(
"Check OLSR MPR computing mechanism"
)
56
{
57
}
58
OlsrMprTestCase::~OlsrMprTestCase
()
59
{
60
}
61
void
62
OlsrMprTestCase::DoRun
()
63
{
64
Ptr<RoutingProtocol>
protocol = CreateObject<RoutingProtocol> ();
65
protocol->m_mainAddress =
Ipv4Address
(
"10.0.0.1"
);
66
OlsrState
& state = protocol->m_state;
67
68
/*
69
* 1 -- 2
70
* | |
71
* 3 -- 4
72
*
73
* Node 1 must select only one MPR (2 or 3, doesn't matter)
74
*/
75
NeighborTuple
neigbor;
76
neigbor.
status
=
NeighborTuple::STATUS_SYM
;
77
neigbor.
willingness
=
OLSR_WILL_DEFAULT
;
78
neigbor.
neighborMainAddr
=
Ipv4Address
(
"10.0.0.2"
);
79
protocol->m_state.InsertNeighborTuple (neigbor);
80
neigbor.
neighborMainAddr
=
Ipv4Address
(
"10.0.0.3"
);
81
protocol->m_state.InsertNeighborTuple (neigbor);
82
TwoHopNeighborTuple
tuple;
83
tuple.
expirationTime
=
Seconds
(3600);
84
tuple.
neighborMainAddr
=
Ipv4Address
(
"10.0.0.2"
);
85
tuple.
twoHopNeighborAddr
=
Ipv4Address
(
"10.0.0.4"
);
86
protocol->m_state.InsertTwoHopNeighborTuple (tuple);
87
tuple.
neighborMainAddr
=
Ipv4Address
(
"10.0.0.3"
);
88
tuple.
twoHopNeighborAddr
=
Ipv4Address
(
"10.0.0.4"
);
89
protocol->m_state.InsertTwoHopNeighborTuple (tuple);
90
91
protocol->MprComputation ();
92
NS_TEST_EXPECT_MSG_EQ
(state.
GetMprSet
().size (), 1,
"An only address must be chosen."
);
93
/*
94
* 1 -- 2 -- 5
95
* | |
96
* 3 -- 4
97
*
98
* Node 1 must select node 2 as MPR.
99
*/
100
tuple.
neighborMainAddr
=
Ipv4Address
(
"10.0.0.2"
);
101
tuple.
twoHopNeighborAddr
=
Ipv4Address
(
"10.0.0.5"
);
102
protocol->m_state.InsertTwoHopNeighborTuple (tuple);
103
104
protocol->MprComputation ();
105
MprSet
mpr = state.
GetMprSet
();
106
NS_TEST_EXPECT_MSG_EQ
(mpr.size (), 1,
"An only address must be chosen."
);
107
NS_TEST_EXPECT_MSG_EQ
((mpr.find (
"10.0.0.2"
) != mpr.end ()),
true
,
"Node 1 must select node 2 as MPR"
);
108
/*
109
* 1 -- 2 -- 5
110
* | |
111
* 3 -- 4
112
* |
113
* 6
114
*
115
* Node 1 must select nodes 2 and 3 as MPRs.
116
*/
117
tuple.
neighborMainAddr
=
Ipv4Address
(
"10.0.0.3"
);
118
tuple.
twoHopNeighborAddr
=
Ipv4Address
(
"10.0.0.6"
);
119
protocol->m_state.InsertTwoHopNeighborTuple (tuple);
120
121
protocol->MprComputation ();
122
mpr = state.
GetMprSet
();
123
NS_TEST_EXPECT_MSG_EQ
(mpr.size (), 2,
"An only address must be chosen."
);
124
NS_TEST_EXPECT_MSG_EQ
((mpr.find (
"10.0.0.2"
) != mpr.end ()),
true
,
"Node 1 must select node 2 as MPR"
);
125
NS_TEST_EXPECT_MSG_EQ
((mpr.find (
"10.0.0.3"
) != mpr.end ()),
true
,
"Node 1 must select node 3 as MPR"
);
126
/*
127
* 7 (OLSR_WILL_ALWAYS)
128
* |
129
* 1 -- 2 -- 5
130
* | |
131
* 3 -- 4
132
* |
133
* 6
134
*
135
* Node 1 must select nodes 2, 3 and 7 (since it is WILL_ALWAYS) as MPRs.
136
*/
137
neigbor.
willingness
=
OLSR_WILL_ALWAYS
;
138
neigbor.
neighborMainAddr
=
Ipv4Address
(
"10.0.0.7"
);
139
protocol->m_state.InsertNeighborTuple (neigbor);
140
141
protocol->MprComputation ();
142
mpr = state.
GetMprSet
();
143
NS_TEST_EXPECT_MSG_EQ
(mpr.size (), 3,
"An only address must be chosen."
);
144
NS_TEST_EXPECT_MSG_EQ
((mpr.find (
"10.0.0.7"
) != mpr.end ()),
true
,
"Node 1 must select node 7 as MPR"
);
145
/*
146
* 7 <- WILL_ALWAYS
147
* |
148
* 9 -- 8 -- 1 -- 2 -- 5
149
* | |
150
* ^ 3 -- 4
151
* | |
152
* WILL_NEVER 6
153
*
154
* Node 1 must select nodes 2, 3 and 7 (since it is WILL_ALWAYS) as MPRs.
155
* Node 1 must NOT select node 8 as MPR since it is WILL_NEVER
156
*/
157
neigbor.
willingness
=
OLSR_WILL_NEVER
;
158
neigbor.
neighborMainAddr
=
Ipv4Address
(
"10.0.0.8"
);
159
protocol->m_state.InsertNeighborTuple (neigbor);
160
tuple.
neighborMainAddr
=
Ipv4Address
(
"10.0.0.8"
);
161
tuple.
twoHopNeighborAddr
=
Ipv4Address
(
"10.0.0.9"
);
162
protocol->m_state.InsertTwoHopNeighborTuple (tuple);
163
164
protocol->MprComputation ();
165
mpr = state.
GetMprSet
();
166
NS_TEST_EXPECT_MSG_EQ
(mpr.size (), 3,
"An only address must be chosen."
);
167
NS_TEST_EXPECT_MSG_EQ
((mpr.find (
"10.0.0.9"
) == mpr.end ()),
true
,
"Node 1 must NOT select node 8 as MPR"
);
168
}
169
170
static
class
OlsrProtocolTestSuite
:
public
TestSuite
171
{
172
public
:
173
OlsrProtocolTestSuite
();
174
}
g_olsrProtocolTestSuite
;
175
176
OlsrProtocolTestSuite::OlsrProtocolTestSuite
()
177
:
TestSuite
(
"routing-olsr"
, UNIT)
178
{
179
AddTestCase
(
new
OlsrMprTestCase
(),
TestCase::QUICK
);
180
}
181
182
}
183
}
// namespace olsr, ns3
184
185
src
olsr
test
olsr-routing-protocol-test-suite.cc
Generated on Tue May 14 2013 11:08:31 for ns-3 by
1.8.1.2