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
aodv-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) 2009 IITP RAS
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Authors: Pavel Boyko <boyko@iitp.ru>
19
*/
20
#include "ns3/test.h"
21
#include "ns3/aodv-neighbor.h"
22
#include "ns3/aodv-packet.h"
23
#include "ns3/aodv-rqueue.h"
24
#include "ns3/aodv-rtable.h"
25
#include "ns3/ipv4-route.h"
26
27
namespace
ns3
28
{
29
namespace
aodv
30
{
31
33
struct
NeighborTest
:
public
TestCase
34
{
35
NeighborTest
() :
TestCase
(
"Neighbor"
),
neighbor
(0) { }
36
virtual
void
DoRun
();
37
void
Handler
(
Ipv4Address
addr);
38
void
CheckTimeout1
();
39
void
CheckTimeout2
();
40
void
CheckTimeout3
();
41
Neighbors
*
neighbor
;
42
};
43
44
void
45
NeighborTest::Handler
(
Ipv4Address
addr)
46
{
47
}
48
49
void
50
NeighborTest::CheckTimeout1
()
51
{
52
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"1.2.3.4"
)),
true
,
"Neighbor exists"
);
53
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"1.1.1.1"
)),
true
,
"Neighbor exists"
);
54
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"2.2.2.2"
)),
true
,
"Neighbor exists"
);
55
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"3.3.3.3"
)),
true
,
"Neighbor exists"
);
56
}
57
void
58
NeighborTest::CheckTimeout2
()
59
{
60
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"1.2.3.4"
)),
false
,
"Neighbor doesn't exist"
);
61
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"1.1.1.1"
)),
false
,
"Neighbor doesn't exist"
);
62
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"2.2.2.2"
)),
false
,
"Neighbor doesn't exist"
);
63
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"3.3.3.3"
)),
true
,
"Neighbor exists"
);
64
}
65
void
66
NeighborTest::CheckTimeout3
()
67
{
68
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"1.2.3.4"
)),
false
,
"Neighbor doesn't exist"
);
69
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"1.1.1.1"
)),
false
,
"Neighbor doesn't exist"
);
70
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"2.2.2.2"
)),
false
,
"Neighbor doesn't exist"
);
71
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"3.3.3.3"
)),
false
,
"Neighbor doesn't exist"
);
72
}
73
74
void
75
NeighborTest::DoRun
()
76
{
77
Neighbors
nb (
Seconds
(1));
78
neighbor
= &nb;
79
neighbor
->
SetCallback
(
MakeCallback
(&
NeighborTest::Handler
,
this
));
80
neighbor
->
Update
(
Ipv4Address
(
"1.2.3.4"
),
Seconds
(1));
81
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"1.2.3.4"
)),
true
,
"Neighbor exists"
);
82
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"4.3.2.1"
)),
false
,
"Neighbor doesn't exist"
);
83
neighbor
->
Update
(
Ipv4Address
(
"1.2.3.4"
),
Seconds
(10));
84
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
IsNeighbor
(
Ipv4Address
(
"1.2.3.4"
)),
true
,
"Neighbor exists"
);
85
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
GetExpireTime
(
Ipv4Address
(
"1.2.3.4"
)),
Seconds
(10),
"Known expire time"
);
86
NS_TEST_EXPECT_MSG_EQ
(
neighbor
->
GetExpireTime
(
Ipv4Address
(
"4.3.2.1"
)),
Seconds
(0),
"Known expire time"
);
87
neighbor
->
Update
(
Ipv4Address
(
"1.1.1.1"
),
Seconds
(5));
88
neighbor
->
Update
(
Ipv4Address
(
"2.2.2.2"
),
Seconds
(10));
89
neighbor
->
Update
(
Ipv4Address
(
"3.3.3.3"
),
Seconds
(20));
90
91
Simulator::Schedule
(
Seconds
(2), &
NeighborTest::CheckTimeout1
,
this
);
92
Simulator::Schedule
(
Seconds
(15), &
NeighborTest::CheckTimeout2
,
this
);
93
Simulator::Schedule
(
Seconds
(30), &
NeighborTest::CheckTimeout3
,
this
);
94
Simulator::Run
();
95
Simulator::Destroy
();
96
}
97
//-----------------------------------------------------------------------------
98
struct
TypeHeaderTest
:
public
TestCase
99
{
100
TypeHeaderTest
() :
TestCase
(
"AODV TypeHeader"
)
101
{
102
}
103
virtual
void
DoRun
()
104
{
105
TypeHeader
h (
AODVTYPE_RREQ
);
106
NS_TEST_EXPECT_MSG_EQ
(h.
IsValid
(),
true
,
"Default header is valid"
);
107
NS_TEST_EXPECT_MSG_EQ
(h.
Get
(),
AODVTYPE_RREQ
,
"Default header is RREQ"
);
108
109
Ptr<Packet>
p = Create<Packet> ();
110
p->
AddHeader
(h);
111
TypeHeader
h2 (
AODVTYPE_RREP
);
112
uint32_t bytes = p->RemoveHeader (h2);
113
NS_TEST_EXPECT_MSG_EQ
(bytes, 1,
"Type header is 1 byte long"
);
114
NS_TEST_EXPECT_MSG_EQ
(h, h2,
"Round trip serialization works"
);
115
}
116
};
117
//-----------------------------------------------------------------------------
119
struct
RreqHeaderTest
:
public
TestCase
120
{
121
RreqHeaderTest
() :
TestCase
(
"AODV RREQ"
)
122
{
123
}
124
virtual
void
DoRun
()
125
{
126
RreqHeader
h (
/*flags*/
0,
/*reserved*/
0,
/*hopCount*/
6,
/*requestID*/
1,
/*dst*/
Ipv4Address
(
"1.2.3.4"
),
127
/*dstSeqNo*/
40,
/*origin*/
Ipv4Address
(
"4.3.2.1"
),
/*originSeqNo*/
10);
128
NS_TEST_EXPECT_MSG_EQ
(h.
GetGratiousRrep
(),
false
,
"trivial"
);
129
NS_TEST_EXPECT_MSG_EQ
(h.
GetDestinationOnly
(),
false
,
"trivial"
);
130
NS_TEST_EXPECT_MSG_EQ
(h.
GetHopCount
(), 6,
"trivial"
);
131
NS_TEST_EXPECT_MSG_EQ
(h.
GetId
(), 1,
"trivial"
);
132
NS_TEST_EXPECT_MSG_EQ
(h.
GetDst
(),
Ipv4Address
(
"1.2.3.4"
),
"trivial"
);
133
NS_TEST_EXPECT_MSG_EQ
(h.
GetDstSeqno
(), 40,
"trivial"
);
134
NS_TEST_EXPECT_MSG_EQ
(h.
GetOrigin
(),
Ipv4Address
(
"4.3.2.1"
),
"trivial"
);
135
NS_TEST_EXPECT_MSG_EQ
(h.
GetOriginSeqno
(), 10,
"trivial"
);
136
137
h.
SetGratiousRrep
(
true
);
138
NS_TEST_EXPECT_MSG_EQ
(h.
GetGratiousRrep
(),
true
,
"trivial"
);
139
h.
SetDestinationOnly
(
true
);
140
NS_TEST_EXPECT_MSG_EQ
(h.
GetDestinationOnly
(),
true
,
"trivial"
);
141
h.
SetUnknownSeqno
(
true
);
142
NS_TEST_EXPECT_MSG_EQ
(h.
GetUnknownSeqno
(),
true
,
"trivial"
);
143
h.
SetDst
(
Ipv4Address
(
"1.1.1.1"
));
144
NS_TEST_EXPECT_MSG_EQ
(h.
GetDst
(),
Ipv4Address
(
"1.1.1.1"
),
"trivial"
);
145
h.
SetDstSeqno
(5);
146
NS_TEST_EXPECT_MSG_EQ
(h.
GetDstSeqno
(), 5,
"trivial"
);
147
h.
SetHopCount
(7);
148
NS_TEST_EXPECT_MSG_EQ
(h.
GetHopCount
(), 7,
"trivial"
);
149
h.
SetId
(55);
150
NS_TEST_EXPECT_MSG_EQ
(h.
GetId
(), 55,
"trivial"
);
151
h.
SetOrigin
(
Ipv4Address
(
"4.4.4.4"
));
152
NS_TEST_EXPECT_MSG_EQ
(h.
GetOrigin
(),
Ipv4Address
(
"4.4.4.4"
),
"trivial"
);
153
h.
SetOriginSeqno
(23);
154
NS_TEST_EXPECT_MSG_EQ
(h.
GetOriginSeqno
(), 23,
"trivial"
);
155
156
Ptr<Packet>
p = Create<Packet> ();
157
p->
AddHeader
(h);
158
RreqHeader
h2;
159
uint32_t bytes = p->RemoveHeader (h2);
160
NS_TEST_EXPECT_MSG_EQ
(bytes, 23,
"RREP is 23 bytes long"
);
161
NS_TEST_EXPECT_MSG_EQ
(h, h2,
"Round trip serialization works"
);
162
163
}
164
};
165
//-----------------------------------------------------------------------------
167
struct
RrepHeaderTest
:
public
TestCase
168
{
169
RrepHeaderTest
() :
TestCase
(
"AODV RREP"
) {}
170
virtual
void
DoRun
()
171
{
172
RrepHeader
h (
/*prefixSize*/
0,
/*hopCount*/
12,
/*dst*/
Ipv4Address
(
"1.2.3.4"
),
/*dstSeqNo*/
2,
173
/*origin*/
Ipv4Address
(
"4.3.2.1"
),
/*lifetime*/
Seconds
(3));
174
NS_TEST_EXPECT_MSG_EQ
(h.
GetPrefixSize
(), 0,
"trivial"
);
175
NS_TEST_EXPECT_MSG_EQ
(h.
GetHopCount
(), 12,
"trivial"
);
176
NS_TEST_EXPECT_MSG_EQ
(h.
GetDst
(),
Ipv4Address
(
"1.2.3.4"
),
"trivial"
);
177
NS_TEST_EXPECT_MSG_EQ
(h.
GetDstSeqno
(), 2,
"trivial"
);
178
NS_TEST_EXPECT_MSG_EQ
(h.
GetOrigin
(),
Ipv4Address
(
"4.3.2.1"
),
"trivial"
);
179
NS_TEST_EXPECT_MSG_EQ
(h.
GetLifeTime
(),
Seconds
(3),
"trivial"
);
180
h.
SetDst
(
Ipv4Address
(
"1.1.1.1"
));
181
NS_TEST_EXPECT_MSG_EQ
(h.
GetDst
(),
Ipv4Address
(
"1.1.1.1"
),
"trivial"
);
182
h.
SetDstSeqno
(123);
183
NS_TEST_EXPECT_MSG_EQ
(h.
GetDstSeqno
(), 123,
"trivial"
);
184
h.
SetOrigin
(
Ipv4Address
(
"4.4.4.4"
));
185
NS_TEST_EXPECT_MSG_EQ
(h.
GetOrigin
(),
Ipv4Address
(
"4.4.4.4"
),
"trivial"
);
186
h.
SetLifeTime
(
MilliSeconds
(1200));
187
NS_TEST_EXPECT_MSG_EQ
(h.
GetLifeTime
(),
MilliSeconds
(1200),
"trivial"
);
188
h.
SetAckRequired
(
true
);
189
NS_TEST_EXPECT_MSG_EQ
(h.
GetAckRequired
(),
true
,
"trivial"
);
190
h.
SetAckRequired
(
false
);
191
NS_TEST_EXPECT_MSG_EQ
(h.
GetAckRequired
(),
false
,
"trivial"
);
192
h.
SetPrefixSize
(2);
193
NS_TEST_EXPECT_MSG_EQ
(h.
GetPrefixSize
(), 2,
"trivial"
);
194
h.
SetHopCount
(15);
195
NS_TEST_EXPECT_MSG_EQ
(h.
GetHopCount
(), 15,
"trivial"
);
196
197
h.
SetHello
(
Ipv4Address
(
"10.0.0.2"
), 9,
Seconds
(15));
198
NS_TEST_EXPECT_MSG_EQ
(h.
GetDst
(), h.
GetOrigin
(),
"trivial"
);
199
NS_TEST_EXPECT_MSG_EQ
(h.
GetDstSeqno
(), 9,
"trivial"
);
200
NS_TEST_EXPECT_MSG_EQ
(h.
GetLifeTime
(),
Seconds
(15),
"trivial"
);
201
202
Ptr<Packet>
p = Create<Packet> ();
203
p->
AddHeader
(h);
204
RrepHeader
h2;
205
uint32_t bytes = p->RemoveHeader (h2);
206
NS_TEST_EXPECT_MSG_EQ
(bytes, 19,
"RREP is 19 bytes long"
);
207
NS_TEST_EXPECT_MSG_EQ
(h, h2,
"Round trip serialization works"
);
208
}
209
};
210
//-----------------------------------------------------------------------------
212
struct
RrepAckHeaderTest
:
public
TestCase
213
{
214
RrepAckHeaderTest
() :
TestCase
(
"AODV RREP-ACK"
)
215
{
216
}
217
virtual
void
DoRun
()
218
{
219
RrepAckHeader
h;
220
Ptr<Packet>
p = Create<Packet> ();
221
p->
AddHeader
(h);
222
RrepAckHeader
h2;
223
uint32_t bytes = p->
RemoveHeader
(h2);
224
NS_TEST_EXPECT_MSG_EQ
(bytes, 1,
"ACK is 1 byte long"
);
225
NS_TEST_EXPECT_MSG_EQ
(h, h2,
"Round trip serialization works"
);
226
}
227
};
228
//-----------------------------------------------------------------------------
230
struct
RerrHeaderTest
:
public
TestCase
231
{
232
RerrHeaderTest
() :
TestCase
(
"AODV RERR"
)
233
{
234
}
235
virtual
void
DoRun
()
236
{
237
RerrHeader
h;
238
h.
SetNoDelete
(
true
);
239
NS_TEST_EXPECT_MSG_EQ
(h.
GetNoDelete
(),
true
,
"trivial"
);
240
Ipv4Address
dst =
Ipv4Address
(
"1.2.3.4"
);
241
NS_TEST_EXPECT_MSG_EQ
(h.
AddUnDestination
(dst, 12),
true
,
"trivial"
);
242
NS_TEST_EXPECT_MSG_EQ
(h.
GetDestCount
(), 1,
"trivial"
);
243
NS_TEST_EXPECT_MSG_EQ
(h.
AddUnDestination
(dst, 13),
true
,
"trivial"
);
244
Ipv4Address
dst2 =
Ipv4Address
(
"4.3.2.1"
);
245
NS_TEST_EXPECT_MSG_EQ
(h.
AddUnDestination
(dst2, 12),
true
,
"trivial"
);
246
NS_TEST_EXPECT_MSG_EQ
(h.
GetDestCount
(), 2,
"trivial"
);
247
248
Ptr<Packet>
p = Create<Packet> ();
249
p->
AddHeader
(h);
250
RerrHeader
h2;
251
uint32_t bytes = p->RemoveHeader (h2);
252
NS_TEST_EXPECT_MSG_EQ
(bytes, h.
GetSerializedSize
(),
"(De)Serialized size match"
);
253
NS_TEST_EXPECT_MSG_EQ
(h, h2,
"Round trip serialization works"
);
254
}
255
};
256
//-----------------------------------------------------------------------------
258
struct
QueueEntryTest
:
public
TestCase
259
{
260
QueueEntryTest
() :
TestCase
(
"QueueEntry"
) {}
261
void
Unicast
(
Ptr<Ipv4Route>
route,
Ptr<const Packet>
packet,
const
Ipv4Header
& header) {}
262
void
Error
(
Ptr<const Packet>
,
const
Ipv4Header
&,
Socket::SocketErrno
) {}
263
void
Unicast2
(
Ptr<Ipv4Route>
route,
Ptr<const Packet>
packet,
const
Ipv4Header
& header) {}
264
void
Error2
(
Ptr<const Packet>
,
const
Ipv4Header
&,
Socket::SocketErrno
) {}
265
virtual
void
DoRun
()
266
{
267
Ptr<const Packet>
packet = Create<Packet> ();
268
Ipv4Header
h;
269
h.
SetDestination
(
Ipv4Address
(
"1.2.3.4"
));
270
h.SetSource (
Ipv4Address
(
"4.3.2.1"
));
271
Ipv4RoutingProtocol::UnicastForwardCallback
ucb =
MakeCallback
(&
QueueEntryTest::Unicast
,
this
);
272
Ipv4RoutingProtocol::ErrorCallback
ecb =
MakeCallback
(&
QueueEntryTest::Error
,
this
);
273
QueueEntry
entry (packet, h, ucb, ecb,
Seconds
(1));
274
NS_TEST_EXPECT_MSG_EQ
(h.GetDestination (), entry.
GetIpv4Header
().
GetDestination
(),
"trivial"
);
275
NS_TEST_EXPECT_MSG_EQ
(h.GetSource (), entry.
GetIpv4Header
().
GetSource
(),
"trivial"
);
276
NS_TEST_EXPECT_MSG_EQ
(ucb.
IsEqual
(entry.
GetUnicastForwardCallback
()),
true
,
"trivial"
);
277
NS_TEST_EXPECT_MSG_EQ
(ecb.
IsEqual
(entry.
GetErrorCallback
()),
true
,
"trivial"
);
278
NS_TEST_EXPECT_MSG_EQ
(entry.
GetExpireTime
(),
Seconds
(1),
"trivial"
);
279
NS_TEST_EXPECT_MSG_EQ
(entry.
GetPacket
(), packet,
"trivial"
);
280
entry.
SetExpireTime
(
Seconds
(3));
281
NS_TEST_EXPECT_MSG_EQ
(entry.
GetExpireTime
(),
Seconds
(3),
"trivial"
);
282
Ipv4Header
h2;
283
h2.
SetDestination
(
Ipv4Address
(
"1.1.1.1"
));
284
entry.
SetIpv4Header
(h2);
285
NS_TEST_EXPECT_MSG_EQ
(entry.
GetIpv4Header
().
GetDestination
(),
Ipv4Address
(
"1.1.1.1"
),
"trivial"
);
286
Ipv4RoutingProtocol::UnicastForwardCallback
ucb2 =
MakeCallback
(&
QueueEntryTest::Unicast2
,
this
);
287
Ipv4RoutingProtocol::ErrorCallback
ecb2 =
MakeCallback
(&
QueueEntryTest::Error2
,
this
);
288
entry.
SetErrorCallback
(ecb2);
289
NS_TEST_EXPECT_MSG_EQ
(ecb2.
IsEqual
(entry.
GetErrorCallback
()),
true
,
"trivial"
);
290
entry.
SetUnicastForwardCallback
(ucb2);
291
NS_TEST_EXPECT_MSG_EQ
(ucb2.IsEqual (entry.
GetUnicastForwardCallback
()),
true
,
"trivial"
);
292
}
293
};
294
//-----------------------------------------------------------------------------
296
struct
AodvRqueueTest
:
public
TestCase
297
{
298
AodvRqueueTest
() :
TestCase
(
"Rqueue"
),
q
(64,
Seconds
(30)) {}
299
virtual
void
DoRun
();
300
void
Unicast
(
Ptr<Ipv4Route>
route,
Ptr<const Packet>
packet,
const
Ipv4Header
& header) {}
301
void
Error
(
Ptr<const Packet>
,
const
Ipv4Header
&,
Socket::SocketErrno
) {}
302
void
CheckSizeLimit
();
303
void
CheckTimeout
();
304
305
RequestQueue
q
;
306
};
307
308
void
309
AodvRqueueTest::DoRun
()
310
{
311
NS_TEST_EXPECT_MSG_EQ
(
q
.
GetMaxQueueLen
(), 64,
"trivial"
);
312
q
.
SetMaxQueueLen
(32);
313
NS_TEST_EXPECT_MSG_EQ
(
q
.
GetMaxQueueLen
(), 32,
"trivial"
);
314
NS_TEST_EXPECT_MSG_EQ
(
q
.
GetQueueTimeout
(),
Seconds
(30),
"trivial"
);
315
q
.
SetQueueTimeout
(
Seconds
(10));
316
NS_TEST_EXPECT_MSG_EQ
(
q
.
GetQueueTimeout
(),
Seconds
(10),
"trivial"
);
317
318
Ptr<const Packet>
packet = Create<Packet> ();
319
Ipv4Header
h;
320
h.
SetDestination
(
Ipv4Address
(
"1.2.3.4"
));
321
h.SetSource (
Ipv4Address
(
"4.3.2.1"
));
322
Ipv4RoutingProtocol::UnicastForwardCallback
ucb =
MakeCallback
(&
AodvRqueueTest::Unicast
,
this
);
323
Ipv4RoutingProtocol::ErrorCallback
ecb =
MakeCallback
(&
AodvRqueueTest::Error
,
this
);
324
QueueEntry
e1 (packet, h, ucb, ecb,
Seconds
(1));
325
q
.
Enqueue
(e1);
326
q
.
Enqueue
(e1);
327
q
.
Enqueue
(e1);
328
NS_TEST_EXPECT_MSG_EQ
(
q
.
Find
(
Ipv4Address
(
"1.2.3.4"
)),
true
,
"trivial"
);
329
NS_TEST_EXPECT_MSG_EQ
(
q
.
Find
(
Ipv4Address
(
"1.1.1.1"
)),
false
,
"trivial"
);
330
NS_TEST_EXPECT_MSG_EQ
(
q
.
GetSize
(), 1,
"trivial"
);
331
q
.
DropPacketWithDst
(
Ipv4Address
(
"1.2.3.4"
));
332
NS_TEST_EXPECT_MSG_EQ
(
q
.
Find
(
Ipv4Address
(
"1.2.3.4"
)),
false
,
"trivial"
);
333
NS_TEST_EXPECT_MSG_EQ
(
q
.
GetSize
(), 0,
"trivial"
);
334
335
h.SetDestination (
Ipv4Address
(
"2.2.2.2"
));
336
QueueEntry
e2 (packet, h, ucb, ecb,
Seconds
(1));
337
q
.
Enqueue
(e1);
338
q
.
Enqueue
(e2);
339
Ptr<Packet>
packet2 = Create<Packet> ();
340
QueueEntry
e3 (packet2, h, ucb, ecb,
Seconds
(1));
341
NS_TEST_EXPECT_MSG_EQ
(
q
.
Dequeue
(
Ipv4Address
(
"3.3.3.3"
), e3),
false
,
"trivial"
);
342
NS_TEST_EXPECT_MSG_EQ
(
q
.
Dequeue
(
Ipv4Address
(
"2.2.2.2"
), e3),
true
,
"trivial"
);
343
NS_TEST_EXPECT_MSG_EQ
(
q
.
Find
(
Ipv4Address
(
"2.2.2.2"
)),
false
,
"trivial"
);
344
q
.
Enqueue
(e2);
345
q
.
Enqueue
(e3);
346
NS_TEST_EXPECT_MSG_EQ
(
q
.
GetSize
(), 2,
"trivial"
);
347
Ptr<Packet>
packet4 = Create<Packet> ();
348
h.SetDestination (
Ipv4Address
(
"1.2.3.4"
));
349
QueueEntry
e4 (packet4, h, ucb, ecb,
Seconds
(20));
350
q
.
Enqueue
(e4);
351
NS_TEST_EXPECT_MSG_EQ
(
q
.
GetSize
(), 3,
"trivial"
);
352
q
.
DropPacketWithDst
(
Ipv4Address
(
"1.2.3.4"
));
353
NS_TEST_EXPECT_MSG_EQ
(
q
.
GetSize
(), 1,
"trivial"
);
354
355
CheckSizeLimit
();
356
357
Ipv4Header
header2;
358
Ipv4Address
dst2 (
"1.2.3.4"
);
359
header2.
SetDestination
(dst2);
360
361
Simulator::Schedule
(
q
.
GetQueueTimeout
() +
Seconds
(1), &
AodvRqueueTest::CheckTimeout
,
this
);
362
363
Simulator::Run
();
364
Simulator::Destroy
();
365
}
366
367
void
368
AodvRqueueTest::CheckSizeLimit
()
369
{
370
Ptr<Packet>
packet = Create<Packet> ();
371
Ipv4Header
header;
372
Ipv4RoutingProtocol::UnicastForwardCallback
ucb =
MakeCallback
(&
AodvRqueueTest::Unicast
,
this
);
373
Ipv4RoutingProtocol::ErrorCallback
ecb =
MakeCallback
(&
AodvRqueueTest::Error
,
this
);
374
QueueEntry
e1 (packet, header, ucb, ecb,
Seconds
(1));
375
376
for
(uint32_t i = 0; i <
q
.
GetMaxQueueLen
(); ++i)
377
q
.
Enqueue
(e1);
378
NS_TEST_EXPECT_MSG_EQ
(
q
.
GetSize
(), 2,
"trivial"
);
379
380
for
(uint32_t i = 0; i <
q
.
GetMaxQueueLen
(); ++i)
381
q
.
Enqueue
(e1);
382
NS_TEST_EXPECT_MSG_EQ
(
q
.
GetSize
(), 2,
"trivial"
);
383
}
384
385
void
386
AodvRqueueTest::CheckTimeout
()
387
{
388
NS_TEST_EXPECT_MSG_EQ
(
q
.
GetSize
(), 0,
"Must be empty now"
);
389
}
390
//-----------------------------------------------------------------------------
392
struct
AodvRtableEntryTest
:
public
TestCase
393
{
394
AodvRtableEntryTest
() :
TestCase
(
"RtableEntry"
) {}
395
virtual
void
DoRun
()
396
{
397
Ptr<NetDevice>
dev;
398
Ipv4InterfaceAddress
iface;
399
RoutingTableEntry
rt (
/*output device*/
dev,
/*dst*/
Ipv4Address
(
"1.2.3.4"
),
/*validSeqNo*/
true
,
/*seqNo*/
10,
400
/*interface*/
iface,
/*hop*/
5,
/*next hop*/
Ipv4Address
(
"3.3.3.3"
),
/*lifetime*/
Seconds
(10));
401
NS_TEST_EXPECT_MSG_EQ
(rt.
GetOutputDevice
(), dev,
"trivial"
);
402
NS_TEST_EXPECT_MSG_EQ
(rt.
GetDestination
(),
Ipv4Address
(
"1.2.3.4"
),
"trivial"
);
403
NS_TEST_EXPECT_MSG_EQ
(rt.
GetValidSeqNo
(),
true
,
"trivial"
);
404
NS_TEST_EXPECT_MSG_EQ
(rt.
GetSeqNo
(), 10,
"trivial"
);
405
NS_TEST_EXPECT_MSG_EQ
(rt.
GetInterface
(), iface,
"trivial"
);
406
NS_TEST_EXPECT_MSG_EQ
(rt.
GetHop
(), 5,
"trivial"
);
407
NS_TEST_EXPECT_MSG_EQ
(rt.
GetNextHop
(),
Ipv4Address
(
"3.3.3.3"
),
"trivial"
);
408
NS_TEST_EXPECT_MSG_EQ
(rt.
GetLifeTime
(),
Seconds
(10),
"trivial"
);
409
NS_TEST_EXPECT_MSG_EQ
(rt.
GetFlag
(),
VALID
,
"trivial"
);
410
NS_TEST_EXPECT_MSG_EQ
(rt.
GetRreqCnt
(), 0,
"trivial"
);
411
NS_TEST_EXPECT_MSG_EQ
(rt.
IsPrecursorListEmpty
(),
true
,
"trivial"
);
412
413
Ptr<NetDevice>
dev2;
414
Ipv4InterfaceAddress
iface2;
415
rt.
SetOutputDevice
(dev2);
416
NS_TEST_EXPECT_MSG_EQ
(rt.
GetOutputDevice
(), dev2,
"trivial"
);
417
rt.
SetInterface
(iface2);
418
NS_TEST_EXPECT_MSG_EQ
(rt.
GetInterface
(), iface2,
"trivial"
);
419
rt.
SetValidSeqNo
(
false
);
420
NS_TEST_EXPECT_MSG_EQ
(rt.
GetValidSeqNo
(),
false
,
"trivial"
);
421
rt.
SetFlag
(
INVALID
);
422
NS_TEST_EXPECT_MSG_EQ
(rt.
GetFlag
(),
INVALID
,
"trivial"
);
423
rt.
SetFlag
(
IN_SEARCH
);
424
NS_TEST_EXPECT_MSG_EQ
(rt.
GetFlag
(),
IN_SEARCH
,
"trivial"
);
425
rt.
SetHop
(12);
426
NS_TEST_EXPECT_MSG_EQ
(rt.
GetHop
(), 12,
"trivial"
);
427
rt.
SetLifeTime
(
Seconds
(1));
428
NS_TEST_EXPECT_MSG_EQ
(rt.
GetLifeTime
(),
Seconds
(1),
"trivial"
);
429
rt.
SetNextHop
(
Ipv4Address
(
"1.1.1.1"
));
430
NS_TEST_EXPECT_MSG_EQ
(rt.
GetNextHop
(),
Ipv4Address
(
"1.1.1.1"
),
"trivial"
);
431
rt.
SetUnidirectional
(
true
);
432
NS_TEST_EXPECT_MSG_EQ
(rt.
IsUnidirectional
(),
true
,
"trivial"
);
433
rt.
SetBalcklistTimeout
(
Seconds
(7));
434
NS_TEST_EXPECT_MSG_EQ
(rt.
GetBlacklistTimeout
(),
Seconds
(7),
"trivial"
);
435
rt.
SetRreqCnt
(2);
436
NS_TEST_EXPECT_MSG_EQ
(rt.
GetRreqCnt
(), 2,
"trivial"
);
437
rt.
IncrementRreqCnt
();
438
NS_TEST_EXPECT_MSG_EQ
(rt.
GetRreqCnt
(), 3,
"trivial"
);
439
rt.
Invalidate
(
Seconds
(13));
440
NS_TEST_EXPECT_MSG_EQ
(rt.
GetFlag
(),
INVALID
,
"trivial"
);
441
NS_TEST_EXPECT_MSG_EQ
(rt.
GetLifeTime
(),
Seconds
(13),
"trivial"
);
442
rt.
SetLifeTime
(
MilliSeconds
(100));
443
NS_TEST_EXPECT_MSG_EQ
(rt.
GetLifeTime
(),
MilliSeconds
(100),
"trivial"
);
444
Ptr<Ipv4Route>
route = rt.
GetRoute
();
445
NS_TEST_EXPECT_MSG_EQ
(route->GetDestination (),
Ipv4Address
(
"1.2.3.4"
),
"trivial"
);
446
447
NS_TEST_EXPECT_MSG_EQ
(rt.
InsertPrecursor
(
Ipv4Address
(
"10.0.0.1"
)),
true
,
"trivial"
);
448
NS_TEST_EXPECT_MSG_EQ
(rt.
IsPrecursorListEmpty
(),
false
,
"trivial"
);
449
NS_TEST_EXPECT_MSG_EQ
(rt.
InsertPrecursor
(
Ipv4Address
(
"10.0.0.2"
)),
true
,
"trivial"
);
450
NS_TEST_EXPECT_MSG_EQ
(rt.
InsertPrecursor
(
Ipv4Address
(
"10.0.0.2"
)),
false
,
"trivial"
);
451
NS_TEST_EXPECT_MSG_EQ
(rt.
LookupPrecursor
(
Ipv4Address
(
"10.0.0.3"
)),
false
,
"trivial"
);
452
NS_TEST_EXPECT_MSG_EQ
(rt.
LookupPrecursor
(
Ipv4Address
(
"10.0.0.1"
)),
true
,
"trivial"
);
453
NS_TEST_EXPECT_MSG_EQ
(rt.
DeletePrecursor
(
Ipv4Address
(
"10.0.0.2"
)),
true
,
"trivial"
);
454
NS_TEST_EXPECT_MSG_EQ
(rt.
LookupPrecursor
(
Ipv4Address
(
"10.0.0.2"
)),
false
,
"trivial"
);
455
std::vector<Ipv4Address> prec;
456
rt.
GetPrecursors
(prec);
457
NS_TEST_EXPECT_MSG_EQ
(prec.size (), 1,
"trivial"
);
458
NS_TEST_EXPECT_MSG_EQ
(rt.
InsertPrecursor
(
Ipv4Address
(
"10.0.0.4"
)),
true
,
"trivial"
);
459
NS_TEST_EXPECT_MSG_EQ
(rt.
DeletePrecursor
(
Ipv4Address
(
"10.0.0.5"
)),
false
,
"trivial"
);
460
rt.
GetPrecursors
(prec);
461
NS_TEST_EXPECT_MSG_EQ
(prec.size (), 2,
"trivial"
);
462
rt.
DeleteAllPrecursors
();
463
NS_TEST_EXPECT_MSG_EQ
(rt.
IsPrecursorListEmpty
(),
true
,
"trivial"
);
464
rt.
GetPrecursors
(prec);
465
NS_TEST_EXPECT_MSG_EQ
(prec.size (), 2,
"trivial"
);
466
Simulator::Destroy
();
467
}
468
};
469
//-----------------------------------------------------------------------------
471
struct
AodvRtableTest
:
public
TestCase
472
{
473
AodvRtableTest
() :
TestCase
(
"Rtable"
) {}
474
virtual
void
DoRun
()
475
{
476
RoutingTable
rtable (
Seconds
(2));
477
NS_TEST_EXPECT_MSG_EQ
(rtable.
GetBadLinkLifetime
(),
Seconds
(2),
"trivial"
);
478
rtable.
SetBadLinkLifetime
(
Seconds
(1));
479
NS_TEST_EXPECT_MSG_EQ
(rtable.
GetBadLinkLifetime
(),
Seconds
(1),
"trivial"
);
480
Ptr<NetDevice>
dev;
481
Ipv4InterfaceAddress
iface;
482
RoutingTableEntry
rt (
/*output device*/
dev,
/*dst*/
Ipv4Address
(
"1.2.3.4"
),
/*validSeqNo*/
true
,
/*seqNo*/
10,
483
/*interface*/
iface,
/*hop*/
5,
/*next hop*/
Ipv4Address
(
"1.1.1.1"
),
/*lifetime*/
Seconds
(10));
484
NS_TEST_EXPECT_MSG_EQ
(rtable.
AddRoute
(rt),
true
,
"trivial"
);
485
NS_TEST_EXPECT_MSG_EQ
(rtable.
AddRoute
(rt),
false
,
"trivial"
);
486
RoutingTableEntry
rt2 (
/*output device*/
dev,
/*dst*/
Ipv4Address
(
"4.3.2.1"
),
/*validSeqNo*/
false
,
/*seqNo*/
0,
487
/*interface*/
iface,
/*hop*/
15,
/*next hop*/
Ipv4Address
(
"1.1.1.1"
),
/*lifetime*/
Seconds
(1));
488
NS_TEST_EXPECT_MSG_EQ
(rtable.
AddRoute
(rt2),
true
,
"trivial"
);
489
NS_TEST_EXPECT_MSG_EQ
(rtable.
LookupRoute
(rt2.GetDestination (), rt),
true
,
"trivial"
);
490
NS_TEST_EXPECT_MSG_EQ
(rt2.GetDestination (), rt.
GetDestination
(),
"trivial"
);
491
rt.
SetHop
(20);
492
rt.
InsertPrecursor
(
Ipv4Address
(
"10.0.0.3"
));
493
NS_TEST_EXPECT_MSG_EQ
(rtable.
Update
(rt),
true
,
"trivial"
);
494
RoutingTableEntry
rt3;
495
NS_TEST_EXPECT_MSG_EQ
(rtable.
LookupRoute
(
Ipv4Address
(
"10.0.0.1"
), rt),
false
,
"trivial"
);
496
NS_TEST_EXPECT_MSG_EQ
(rtable.
Update
(rt3),
false
,
"trivial"
);
497
NS_TEST_EXPECT_MSG_EQ
(rtable.
SetEntryState
(
Ipv4Address
(
"10.0.0.1"
),
INVALID
),
false
,
"trivial"
);
498
NS_TEST_EXPECT_MSG_EQ
(rtable.
SetEntryState
(
Ipv4Address
(
"1.2.3.4"
),
IN_SEARCH
),
true
,
"trivial"
);
499
NS_TEST_EXPECT_MSG_EQ
(rtable.
DeleteRoute
(
Ipv4Address
(
"5.5.5.5"
)),
false
,
"trivial"
);
500
RoutingTableEntry
rt4 (
/*output device*/
dev,
/*dst*/
Ipv4Address
(
"5.5.5.5"
),
/*validSeqNo*/
false
,
/*seqNo*/
0,
501
/*interface*/
iface,
/*hop*/
15,
/*next hop*/
Ipv4Address
(
"1.1.1.1"
),
/*lifetime*/
Seconds
(-10));
502
NS_TEST_EXPECT_MSG_EQ
(rtable.
AddRoute
(rt4),
true
,
"trivial"
);
503
NS_TEST_EXPECT_MSG_EQ
(rtable.
SetEntryState
(
Ipv4Address
(
"5.5.5.5"
),
INVALID
),
true
,
"trivial"
);
504
NS_TEST_EXPECT_MSG_EQ
(rtable.
LookupRoute
(
Ipv4Address
(
"5.5.5.5"
), rt),
false
,
"trivial"
);
505
NS_TEST_EXPECT_MSG_EQ
(rtable.
MarkLinkAsUnidirectional
(
Ipv4Address
(
"1.2.3.4"
),
Seconds
(2)),
true
,
"trivial"
);
506
NS_TEST_EXPECT_MSG_EQ
(rtable.
LookupRoute
(
Ipv4Address
(
"1.2.3.4"
), rt),
true
,
"trivial"
);
507
NS_TEST_EXPECT_MSG_EQ
(rt.
IsUnidirectional
(),
true
,
"trivial"
);
508
rt.
SetLifeTime
(
Seconds
(-5));
509
NS_TEST_EXPECT_MSG_EQ
(rtable.
Update
(rt),
true
,
"trivial"
);
510
std::map<Ipv4Address, uint32_t> unreachable;
511
rtable.
GetListOfDestinationWithNextHop
(
Ipv4Address
(
"1.1.1.1"
), unreachable);
512
NS_TEST_EXPECT_MSG_EQ
(unreachable.size (), 2,
"trivial"
);
513
unreachable.insert (std::make_pair (
Ipv4Address
(
"4.3.2.1"
), 3));
514
rtable.
InvalidateRoutesWithDst
(unreachable);
515
NS_TEST_EXPECT_MSG_EQ
(rtable.
LookupRoute
(
Ipv4Address
(
"4.3.2.1"
), rt),
true
,
"trivial"
);
516
NS_TEST_EXPECT_MSG_EQ
(rt.
GetFlag
(),
INVALID
,
"trivial"
);
517
NS_TEST_EXPECT_MSG_EQ
(rtable.
DeleteRoute
(
Ipv4Address
(
"1.2.3.4"
)),
true
,
"trivial"
);
518
NS_TEST_EXPECT_MSG_EQ
(rtable.
DeleteRoute
(
Ipv4Address
(
"1.2.3.4"
)),
false
,
"trivial"
);
519
Simulator::Destroy
();
520
}
521
};
522
//-----------------------------------------------------------------------------
523
class
AodvTestSuite
:
public
TestSuite
524
{
525
public
:
526
AodvTestSuite
() :
TestSuite
(
"routing-aodv"
,
UNIT
)
527
{
528
AddTestCase
(
new
NeighborTest
);
529
AddTestCase
(
new
TypeHeaderTest
);
530
AddTestCase
(
new
RreqHeaderTest
);
531
AddTestCase
(
new
RrepHeaderTest
);
532
AddTestCase
(
new
RrepAckHeaderTest
);
533
AddTestCase
(
new
RerrHeaderTest
);
534
AddTestCase
(
new
QueueEntryTest
);
535
AddTestCase
(
new
AodvRqueueTest
);
536
AddTestCase
(
new
AodvRtableEntryTest
);
537
AddTestCase
(
new
AodvRtableTest
);
538
}
539
}
g_aodvTestSuite
;
540
541
}
542
}
src
aodv
test
aodv-test-suite.cc
Generated on Tue Oct 9 2012 16:45:32 for ns-3 by
1.8.1.2