8751
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
2 |
/*
|
|
3 |
* Copyright (c) 2011 Yufei Cheng
|
|
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 |
* Author: Yufei Cheng <yfcheng@ittc.ku.edu>
|
|
19 |
*
|
|
20 |
* James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
|
|
21 |
* ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
|
|
22 |
* Information and Telecommunication Technology Center (ITTC)
|
|
23 |
* and Department of Electrical Engineering and Computer Science
|
|
24 |
* The University of Kansas Lawrence, KS USA.
|
|
25 |
*
|
|
26 |
* Work supported in part by NSF FIND (Future Internet Design) Program
|
|
27 |
* under grant CNS-0626918 (Postmodern Internet Architecture),
|
|
28 |
* NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
|
|
29 |
* US Department of Defense (DoD), and ITTC at The University of Kansas.
|
|
30 |
*/
|
|
31 |
|
|
32 |
#include <vector>
|
|
33 |
#include "ns3/ptr.h"
|
|
34 |
#include "ns3/boolean.h"
|
|
35 |
#include "ns3/test.h"
|
|
36 |
#include "ns3/ipv4-route.h"
|
|
37 |
#include "ns3/mesh-helper.h"
|
|
38 |
#include "ns3/simulator.h"
|
|
39 |
#include "ns3/double.h"
|
|
40 |
#include "ns3/uinteger.h"
|
|
41 |
#include "ns3/string.h"
|
|
42 |
#include "ns3/ipv4-address-helper.h"
|
|
43 |
|
|
44 |
#include "ns3/dsr-fs-header.h"
|
|
45 |
#include "ns3/dsr-option-header.h"
|
|
46 |
#include "ns3/dsr-rreq-table.h"
|
|
47 |
#include "ns3/dsr-rcache.h"
|
|
48 |
#include "ns3/dsr-rsendbuff.h"
|
|
49 |
#include "ns3/dsr-main-helper.h"
|
|
50 |
#include "ns3/dsr-helper.h"
|
|
51 |
|
|
52 |
namespace ns3 {
|
|
53 |
namespace dsr {
|
|
54 |
|
|
55 |
// -----------------------------------------------------------------------------
|
|
56 |
// / Unit test for DSR Fixed Size Header
|
|
57 |
class DsrFsHeaderTest : public TestCase
|
|
58 |
{
|
|
59 |
public:
|
|
60 |
DsrFsHeaderTest ();
|
|
61 |
~DsrFsHeaderTest ();
|
|
62 |
virtual void
|
|
63 |
DoRun (void);
|
|
64 |
};
|
|
65 |
DsrFsHeaderTest::DsrFsHeaderTest ()
|
|
66 |
: TestCase ("DSR Fixed size Header")
|
|
67 |
{
|
|
68 |
}
|
|
69 |
DsrFsHeaderTest::~DsrFsHeaderTest ()
|
|
70 |
{
|
|
71 |
}
|
|
72 |
void
|
|
73 |
DsrFsHeaderTest::DoRun ()
|
|
74 |
{
|
|
75 |
dsr::DsrRoutingHeader header;
|
|
76 |
dsr::DsrOptionRreqHeader rreqHeader;
|
|
77 |
header.AddDsrOption (rreqHeader); // has an alignment of 4n+0
|
|
78 |
|
|
79 |
NS_TEST_EXPECT_MSG_EQ (header.GetSerializedSize () % 2, 0, "length of routing header is not a multiple of 4");
|
|
80 |
Buffer buf;
|
|
81 |
buf.AddAtStart (header.GetSerializedSize ());
|
|
82 |
header.Serialize (buf.Begin ());
|
|
83 |
|
|
84 |
const uint8_t* data = buf.PeekData ();
|
|
85 |
NS_TEST_EXPECT_MSG_EQ (*(data + 8), rreqHeader.GetType (), "expect the rreqHeader after fixed size header");
|
|
86 |
}
|
|
87 |
// -----------------------------------------------------------------------------
|
|
88 |
// / Unit test for RREQ
|
|
89 |
class DsrRreqHeaderTest : public TestCase
|
|
90 |
{
|
|
91 |
public:
|
|
92 |
DsrRreqHeaderTest ();
|
|
93 |
~DsrRreqHeaderTest ();
|
|
94 |
virtual void
|
|
95 |
DoRun (void);
|
|
96 |
};
|
|
97 |
DsrRreqHeaderTest::DsrRreqHeaderTest ()
|
|
98 |
: TestCase ("DSR RREQ")
|
|
99 |
{
|
|
100 |
}
|
|
101 |
DsrRreqHeaderTest::~DsrRreqHeaderTest ()
|
|
102 |
{
|
|
103 |
}
|
|
104 |
void
|
|
105 |
DsrRreqHeaderTest::DoRun ()
|
|
106 |
{
|
|
107 |
dsr::DsrOptionRreqHeader h;
|
|
108 |
std::vector<Ipv4Address> nodeList;
|
|
109 |
nodeList.push_back (Ipv4Address ("1.1.1.0"));
|
|
110 |
nodeList.push_back (Ipv4Address ("1.1.1.1"));
|
|
111 |
nodeList.push_back (Ipv4Address ("1.1.1.2"));
|
|
112 |
|
|
113 |
h.SetTarget (Ipv4Address ("1.1.1.3"));
|
|
114 |
NS_TEST_EXPECT_MSG_EQ (h.GetTarget (), Ipv4Address ("1.1.1.3"), "trivial");
|
|
115 |
h.SetNodesAddress (nodeList);
|
|
116 |
NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (0), Ipv4Address ("1.1.1.0"), "trivial");
|
|
117 |
NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (1), Ipv4Address ("1.1.1.1"), "trivial");
|
|
118 |
NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (2), Ipv4Address ("1.1.1.2"), "trivial");
|
|
119 |
h.SetId (1);
|
|
120 |
NS_TEST_EXPECT_MSG_EQ (h.GetId (), 1, "trivial");
|
|
121 |
|
|
122 |
Ptr<Packet> p = Create<Packet> ();
|
|
123 |
dsr::DsrRoutingHeader header;
|
|
124 |
header.AddDsrOption (h);
|
|
125 |
p->AddHeader (header);
|
|
126 |
p->RemoveAtStart (8);
|
|
127 |
dsr::DsrOptionRreqHeader h2;
|
|
128 |
h2.SetNumberAddress (3);
|
|
129 |
uint32_t bytes = p->RemoveHeader (h2);
|
|
130 |
NS_TEST_EXPECT_MSG_EQ (bytes, 20, "Total RREP is 20 bytes long");
|
|
131 |
}
|
|
132 |
// -----------------------------------------------------------------------------
|
|
133 |
// / Unit test for RREP
|
|
134 |
class DsrRrepHeaderTest : public TestCase
|
|
135 |
{
|
|
136 |
public:
|
|
137 |
DsrRrepHeaderTest ();
|
|
138 |
~DsrRrepHeaderTest ();
|
|
139 |
virtual void
|
|
140 |
DoRun (void);
|
|
141 |
};
|
|
142 |
DsrRrepHeaderTest::DsrRrepHeaderTest ()
|
|
143 |
: TestCase ("DSR RREP")
|
|
144 |
{
|
|
145 |
}
|
|
146 |
DsrRrepHeaderTest::~DsrRrepHeaderTest ()
|
|
147 |
{
|
|
148 |
}
|
|
149 |
void
|
|
150 |
DsrRrepHeaderTest::DoRun ()
|
|
151 |
{
|
|
152 |
dsr::DsrOptionRrepHeader h;
|
|
153 |
|
|
154 |
std::vector<Ipv4Address> nodeList;
|
|
155 |
nodeList.push_back (Ipv4Address ("1.1.1.0"));
|
|
156 |
nodeList.push_back (Ipv4Address ("1.1.1.1"));
|
|
157 |
nodeList.push_back (Ipv4Address ("1.1.1.2"));
|
|
158 |
h.SetNodesAddress (nodeList);
|
|
159 |
NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (0), Ipv4Address ("1.1.1.0"), "trivial");
|
|
160 |
NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (1), Ipv4Address ("1.1.1.1"), "trivial");
|
|
161 |
NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (2), Ipv4Address ("1.1.1.2"), "trivial");
|
|
162 |
|
|
163 |
Ptr<Packet> p = Create<Packet> ();
|
|
164 |
dsr::DsrRoutingHeader header;
|
|
165 |
header.AddDsrOption (h);
|
|
166 |
p->AddHeader (header);
|
|
167 |
p->RemoveAtStart (8);
|
|
168 |
dsr::DsrOptionRrepHeader h2;
|
|
169 |
h2.SetNumberAddress (3);
|
|
170 |
uint32_t bytes = p->RemoveHeader (h2);
|
|
171 |
NS_TEST_EXPECT_MSG_EQ (bytes, 16, "Total RREP is 16 bytes long");
|
|
172 |
}
|
|
173 |
// -----------------------------------------------------------------------------
|
|
174 |
// / Unit test for Source Route
|
|
175 |
class DsrSRHeaderTest : public TestCase
|
|
176 |
{
|
|
177 |
public:
|
|
178 |
DsrSRHeaderTest ();
|
|
179 |
~DsrSRHeaderTest ();
|
|
180 |
virtual void
|
|
181 |
DoRun (void);
|
|
182 |
};
|
|
183 |
DsrSRHeaderTest::DsrSRHeaderTest ()
|
|
184 |
: TestCase ("DSR Source Route")
|
|
185 |
{
|
|
186 |
}
|
|
187 |
DsrSRHeaderTest::~DsrSRHeaderTest ()
|
|
188 |
{
|
|
189 |
}
|
|
190 |
void
|
|
191 |
DsrSRHeaderTest::DoRun ()
|
|
192 |
{
|
|
193 |
dsr::DsrOptionSRHeader h;
|
|
194 |
std::vector<Ipv4Address> nodeList;
|
|
195 |
nodeList.push_back (Ipv4Address ("1.1.1.0"));
|
|
196 |
nodeList.push_back (Ipv4Address ("1.1.1.1"));
|
|
197 |
nodeList.push_back (Ipv4Address ("1.1.1.2"));
|
|
198 |
h.SetNodesAddress (nodeList);
|
|
199 |
NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (0), Ipv4Address ("1.1.1.0"), "trivial");
|
|
200 |
NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (1), Ipv4Address ("1.1.1.1"), "trivial");
|
|
201 |
NS_TEST_EXPECT_MSG_EQ (h.GetNodeAddress (2), Ipv4Address ("1.1.1.2"), "trivial");
|
|
202 |
|
|
203 |
h.SetSalvage (1);
|
|
204 |
NS_TEST_EXPECT_MSG_EQ (h.GetSalvage (), 1, "trivial");
|
|
205 |
h.SetSegmentsLeft (2);
|
|
206 |
NS_TEST_EXPECT_MSG_EQ (h.GetSegmentsLeft (), 2, "trivial");
|
|
207 |
|
|
208 |
Ptr<Packet> p = Create<Packet> ();
|
|
209 |
dsr::DsrRoutingHeader header;
|
|
210 |
header.AddDsrOption (h);
|
|
211 |
p->AddHeader (header);
|
|
212 |
p->RemoveAtStart (8);
|
|
213 |
dsr::DsrOptionSRHeader h2;
|
|
214 |
h2.SetNumberAddress (3);
|
|
215 |
uint32_t bytes = p->RemoveHeader (h2);
|
|
216 |
NS_TEST_EXPECT_MSG_EQ (bytes, 16, "Total RREP is 16 bytes long");
|
|
217 |
}
|
|
218 |
// -----------------------------------------------------------------------------
|
|
219 |
// / Unit test for RERR
|
|
220 |
class DsrRerrHeaderTest : public TestCase
|
|
221 |
{
|
|
222 |
public:
|
|
223 |
DsrRerrHeaderTest ();
|
|
224 |
~DsrRerrHeaderTest ();
|
|
225 |
virtual void
|
|
226 |
DoRun (void);
|
|
227 |
};
|
|
228 |
DsrRerrHeaderTest::DsrRerrHeaderTest ()
|
|
229 |
: TestCase ("DSR RERR")
|
|
230 |
{
|
|
231 |
}
|
|
232 |
DsrRerrHeaderTest::~DsrRerrHeaderTest ()
|
|
233 |
{
|
|
234 |
}
|
|
235 |
void
|
|
236 |
DsrRerrHeaderTest::DoRun ()
|
|
237 |
{
|
|
238 |
dsr::DsrOptionRerrUnreachHeader h;
|
|
239 |
h.SetErrorSrc (Ipv4Address ("1.1.1.0"));
|
|
240 |
NS_TEST_EXPECT_MSG_EQ (h.GetErrorSrc (), Ipv4Address ("1.1.1.0"), "trivial");
|
|
241 |
h.SetErrorDst (Ipv4Address ("1.1.1.1"));
|
|
242 |
NS_TEST_EXPECT_MSG_EQ (h.GetErrorDst (), Ipv4Address ("1.1.1.1"), "trivial");
|
|
243 |
h.SetSalvage (1);
|
|
244 |
NS_TEST_EXPECT_MSG_EQ (h.GetSalvage (), 1, "trivial");
|
|
245 |
h.SetUnreachNode (Ipv4Address ("1.1.1.2"));
|
|
246 |
NS_TEST_EXPECT_MSG_EQ (h.GetUnreachNode (), Ipv4Address ("1.1.1.2"), "trivial");
|
|
247 |
|
|
248 |
Ptr<Packet> p = Create<Packet> ();
|
|
249 |
dsr::DsrRoutingHeader header;
|
|
250 |
header.AddDsrOption (h);
|
|
251 |
p->AddHeader (header);
|
|
252 |
p->RemoveAtStart (8);
|
|
253 |
dsr::DsrOptionRerrUnreachHeader h2;
|
|
254 |
uint32_t bytes = p->RemoveHeader (h2);
|
8754
|
255 |
NS_TEST_EXPECT_MSG_EQ (bytes, 20, "Total RREP is 20 bytes long");
|
8751
|
256 |
}
|
|
257 |
// -----------------------------------------------------------------------------
|
|
258 |
// / Unit test for ACK-REQ
|
|
259 |
class DsrAckReqHeaderTest : public TestCase
|
|
260 |
{
|
|
261 |
public:
|
|
262 |
DsrAckReqHeaderTest ();
|
|
263 |
~DsrAckReqHeaderTest ();
|
|
264 |
virtual void
|
|
265 |
DoRun (void);
|
|
266 |
};
|
|
267 |
DsrAckReqHeaderTest::DsrAckReqHeaderTest ()
|
|
268 |
: TestCase ("DSR Ack Req")
|
|
269 |
{
|
|
270 |
}
|
|
271 |
DsrAckReqHeaderTest::~DsrAckReqHeaderTest ()
|
|
272 |
{
|
|
273 |
}
|
|
274 |
void
|
|
275 |
DsrAckReqHeaderTest::DoRun ()
|
|
276 |
{
|
|
277 |
dsr::DsrOptionAckReqHeader h;
|
|
278 |
|
|
279 |
h.SetAckId (1);
|
|
280 |
NS_TEST_EXPECT_MSG_EQ (h.GetAckId (), 1, "trivial");
|
|
281 |
|
|
282 |
Ptr<Packet> p = Create<Packet> ();
|
|
283 |
dsr::DsrRoutingHeader header;
|
|
284 |
header.AddDsrOption (h);
|
|
285 |
p->AddHeader (header);
|
|
286 |
p->RemoveAtStart (8);
|
|
287 |
p->AddHeader (header);
|
|
288 |
dsr::DsrOptionAckReqHeader h2;
|
|
289 |
p->RemoveAtStart (8);
|
|
290 |
uint32_t bytes = p->RemoveHeader (h2);
|
|
291 |
NS_TEST_EXPECT_MSG_EQ (bytes, 4, "Total RREP is 4 bytes long");
|
|
292 |
}
|
|
293 |
// -----------------------------------------------------------------------------
|
|
294 |
// / Unit test for ACK
|
|
295 |
class DsrAckHeaderTest : public TestCase
|
|
296 |
{
|
|
297 |
public:
|
|
298 |
DsrAckHeaderTest ();
|
|
299 |
~DsrAckHeaderTest ();
|
|
300 |
virtual void
|
|
301 |
DoRun (void);
|
|
302 |
};
|
|
303 |
DsrAckHeaderTest::DsrAckHeaderTest ()
|
|
304 |
: TestCase ("DSR ACK")
|
|
305 |
{
|
|
306 |
}
|
|
307 |
DsrAckHeaderTest::~DsrAckHeaderTest ()
|
|
308 |
{
|
|
309 |
}
|
|
310 |
void
|
|
311 |
DsrAckHeaderTest::DoRun ()
|
|
312 |
{
|
|
313 |
dsr::DsrOptionAckHeader h;
|
|
314 |
|
|
315 |
h.SetRealSrc (Ipv4Address ("1.1.1.0"));
|
|
316 |
NS_TEST_EXPECT_MSG_EQ (h.GetRealSrc (), Ipv4Address ("1.1.1.0"), "trivial");
|
|
317 |
h.SetRealDst (Ipv4Address ("1.1.1.1"));
|
|
318 |
NS_TEST_EXPECT_MSG_EQ (h.GetRealDst (), Ipv4Address ("1.1.1.1"), "trivial");
|
|
319 |
h.SetAckId (1);
|
|
320 |
NS_TEST_EXPECT_MSG_EQ (h.GetAckId (), 1, "trivial");
|
|
321 |
|
|
322 |
Ptr<Packet> p = Create<Packet> ();
|
|
323 |
dsr::DsrRoutingHeader header;
|
|
324 |
header.AddDsrOption (h);
|
|
325 |
p->AddHeader (header);
|
|
326 |
p->RemoveAtStart (8);
|
|
327 |
p->AddHeader (header);
|
|
328 |
dsr::DsrOptionAckHeader h2;
|
|
329 |
p->RemoveAtStart (8);
|
|
330 |
uint32_t bytes = p->RemoveHeader (h2);
|
|
331 |
NS_TEST_EXPECT_MSG_EQ (bytes, 12, "Total RREP is 12 bytes long");
|
|
332 |
}
|
|
333 |
// -----------------------------------------------------------------------------
|
|
334 |
// / Unit test for DSR route cache entry
|
|
335 |
class DsrCacheEntryTest : public TestCase
|
|
336 |
{
|
|
337 |
public:
|
|
338 |
DsrCacheEntryTest ();
|
|
339 |
~DsrCacheEntryTest ();
|
|
340 |
virtual void
|
|
341 |
DoRun (void);
|
|
342 |
};
|
|
343 |
DsrCacheEntryTest::DsrCacheEntryTest ()
|
|
344 |
: TestCase ("DSR ACK")
|
|
345 |
{
|
|
346 |
}
|
|
347 |
DsrCacheEntryTest::~DsrCacheEntryTest ()
|
|
348 |
{
|
|
349 |
}
|
|
350 |
void
|
|
351 |
DsrCacheEntryTest::DoRun ()
|
|
352 |
{
|
|
353 |
Ptr<dsr::RouteCache> rcache = CreateObject<dsr::RouteCache> ();
|
|
354 |
std::vector<Ipv4Address> ip;
|
|
355 |
ip.push_back (Ipv4Address ("0.0.0.0"));
|
|
356 |
ip.push_back (Ipv4Address ("0.0.0.1"));
|
|
357 |
Ipv4Address dst = Ipv4Address ("0.0.0.1");
|
|
358 |
dsr::RouteCacheEntry entry (ip, dst, Seconds (1));
|
|
359 |
NS_TEST_EXPECT_MSG_EQ (entry.GetVector ().size (), 2, "trivial");
|
|
360 |
NS_TEST_EXPECT_MSG_EQ (entry.GetDestination (), Ipv4Address ("0.0.0.1"), "trivial");
|
|
361 |
NS_TEST_EXPECT_MSG_EQ (entry.GetExpireTime (), Seconds (1), "trivial");
|
|
362 |
|
|
363 |
entry.SetExpireTime (Seconds (3));
|
|
364 |
NS_TEST_EXPECT_MSG_EQ (entry.GetExpireTime (), Seconds (3), "trivial");
|
|
365 |
entry.SetDestination (Ipv4Address ("1.1.1.1"));
|
|
366 |
NS_TEST_EXPECT_MSG_EQ (entry.GetDestination (), Ipv4Address ("1.1.1.1"), "trivial");
|
|
367 |
ip.push_back (Ipv4Address ("0.0.0.2"));
|
|
368 |
entry.SetVector (ip);
|
|
369 |
NS_TEST_EXPECT_MSG_EQ (entry.GetVector ().size (), 3, "trivial");
|
|
370 |
|
|
371 |
NS_TEST_EXPECT_MSG_EQ (rcache->AddRoute (entry), true, "trivial");
|
|
372 |
|
|
373 |
std::vector<Ipv4Address> ip2;
|
|
374 |
ip2.push_back (Ipv4Address ("1.1.1.0"));
|
|
375 |
ip2.push_back (Ipv4Address ("1.1.1.1"));
|
|
376 |
Ipv4Address dst2 = Ipv4Address ("1.1.1.1");
|
|
377 |
dsr::RouteCacheEntry entry2 (ip2, dst2, Seconds (2));
|
|
378 |
dsr::RouteCacheEntry newEntry;
|
|
379 |
NS_TEST_EXPECT_MSG_EQ (rcache->AddRoute (entry2), true, "trivial");
|
|
380 |
NS_TEST_EXPECT_MSG_EQ (rcache->LookupRoute (dst2, newEntry), true, "trivial");
|
|
381 |
NS_TEST_EXPECT_MSG_EQ (rcache->DeleteRoute (Ipv4Address ("2.2.2.2")), false, "trivial");
|
|
382 |
|
|
383 |
NS_TEST_EXPECT_MSG_EQ (rcache->DeleteRoute (Ipv4Address ("1.1.1.1")), true, "trivial");
|
|
384 |
NS_TEST_EXPECT_MSG_EQ (rcache->DeleteRoute (Ipv4Address ("1.1.1.1")), false, "trivial");
|
|
385 |
}
|
|
386 |
// -----------------------------------------------------------------------------
|
|
387 |
// / Unit test for Send Buffer
|
|
388 |
class DsrSendBuffTest : public TestCase
|
|
389 |
{
|
|
390 |
public:
|
|
391 |
DsrSendBuffTest ();
|
|
392 |
~DsrSendBuffTest ();
|
|
393 |
virtual void
|
|
394 |
DoRun (void);
|
|
395 |
void CheckSizeLimit ();
|
|
396 |
void CheckTimeout ();
|
|
397 |
|
|
398 |
dsr::SendBuffer q;
|
|
399 |
};
|
|
400 |
DsrSendBuffTest::DsrSendBuffTest ()
|
|
401 |
: TestCase ("DSR SendBuff"),
|
|
402 |
q ()
|
|
403 |
{
|
|
404 |
}
|
|
405 |
DsrSendBuffTest::~DsrSendBuffTest ()
|
|
406 |
{
|
|
407 |
}
|
|
408 |
void
|
|
409 |
DsrSendBuffTest::DoRun ()
|
|
410 |
{
|
|
411 |
q.SetMaxQueueLen (32);
|
|
412 |
NS_TEST_EXPECT_MSG_EQ (q.GetMaxQueueLen (), 32, "trivial");
|
|
413 |
q.SetSendBufferTimeout (Seconds (10));
|
|
414 |
NS_TEST_EXPECT_MSG_EQ (q.GetSendBufferTimeout (), Seconds (10), "trivial");
|
|
415 |
|
|
416 |
Ptr<const Packet> packet = Create<Packet> ();
|
|
417 |
Ipv4Address dst1 = Ipv4Address ("0.0.0.1");
|
|
418 |
dsr::SendBuffEntry e1 (packet, dst1, Seconds (1));
|
|
419 |
q.Enqueue (e1);
|
|
420 |
q.Enqueue (e1);
|
|
421 |
q.Enqueue (e1);
|
|
422 |
NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("0.0.0.1")), true, "trivial");
|
|
423 |
NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("1.1.1.1")), false, "trivial");
|
|
424 |
NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 1, "trivial");
|
|
425 |
q.DropPacketWithDst (Ipv4Address ("0.0.0.1"));
|
|
426 |
NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("0.0.0.1")), false, "trivial");
|
|
427 |
NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 0, "trivial");
|
|
428 |
|
|
429 |
Ipv4Address dst2 = Ipv4Address ("0.0.0.2");
|
|
430 |
dsr::SendBuffEntry e2 (packet, dst2, Seconds (1));
|
|
431 |
q.Enqueue (e1);
|
|
432 |
q.Enqueue (e2);
|
|
433 |
Ptr<Packet> packet2 = Create<Packet> ();
|
|
434 |
dsr::SendBuffEntry e3 (packet2, dst2, Seconds (1));
|
|
435 |
NS_TEST_EXPECT_MSG_EQ (q.Dequeue (Ipv4Address ("0.0.0.3"), e3), false, "trivial");
|
|
436 |
NS_TEST_EXPECT_MSG_EQ (q.Dequeue (Ipv4Address ("0.0.0.2"), e3), true, "trivial");
|
|
437 |
NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("0.0.0.2")), false, "trivial");
|
|
438 |
q.Enqueue (e2);
|
|
439 |
q.Enqueue (e3);
|
|
440 |
NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2, "trivial");
|
|
441 |
Ptr<Packet> packet4 = Create<Packet> ();
|
|
442 |
Ipv4Address dst4 = Ipv4Address ("0.0.0.4");
|
|
443 |
dsr::SendBuffEntry e4 (packet4, dst4, Seconds (20));
|
|
444 |
q.Enqueue (e4);
|
|
445 |
NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 3, "trivial");
|
|
446 |
q.DropPacketWithDst (Ipv4Address ("0.0.0.4"));
|
|
447 |
NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2, "trivial");
|
|
448 |
|
|
449 |
CheckSizeLimit ();
|
|
450 |
|
|
451 |
Simulator::Schedule (q.GetSendBufferTimeout () + Seconds (1), &DsrSendBuffTest::CheckTimeout, this);
|
|
452 |
|
|
453 |
Simulator::Run ();
|
|
454 |
Simulator::Destroy ();
|
|
455 |
}
|
|
456 |
void
|
|
457 |
DsrSendBuffTest::CheckSizeLimit ()
|
|
458 |
{
|
|
459 |
Ptr<Packet> packet = Create<Packet> ();
|
|
460 |
Ipv4Address dst;
|
|
461 |
dsr::SendBuffEntry e1 (packet, dst, Seconds (1));
|
|
462 |
|
|
463 |
for (uint32_t i = 0; i < q.GetMaxQueueLen (); ++i)
|
|
464 |
{
|
|
465 |
q.Enqueue (e1);
|
|
466 |
}
|
|
467 |
NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 3, "trivial");
|
|
468 |
|
|
469 |
for (uint32_t i = 0; i < q.GetMaxQueueLen (); ++i)
|
|
470 |
{
|
|
471 |
q.Enqueue (e1);
|
|
472 |
}
|
|
473 |
NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 3, "trivial");
|
|
474 |
}
|
|
475 |
void
|
|
476 |
DsrSendBuffTest::CheckTimeout ()
|
|
477 |
{
|
|
478 |
NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 0, "Must be empty now");
|
|
479 |
}
|
|
480 |
// -----------------------------------------------------------------------------
|
|
481 |
// / Unit test for DSR routing table entry
|
|
482 |
class DsrRreqTableTest : public TestCase
|
|
483 |
{
|
|
484 |
public:
|
|
485 |
DsrRreqTableTest ();
|
|
486 |
~DsrRreqTableTest ();
|
|
487 |
virtual void
|
|
488 |
DoRun (void);
|
|
489 |
};
|
|
490 |
DsrRreqTableTest::DsrRreqTableTest ()
|
|
491 |
: TestCase ("DSR RreqTable")
|
|
492 |
{
|
|
493 |
}
|
|
494 |
DsrRreqTableTest::~DsrRreqTableTest ()
|
|
495 |
{
|
|
496 |
}
|
|
497 |
void
|
|
498 |
DsrRreqTableTest::DoRun ()
|
|
499 |
{
|
|
500 |
dsr::RreqTableEntry rt;
|
|
501 |
|
|
502 |
rt.m_reqNo = 2;
|
|
503 |
NS_TEST_EXPECT_MSG_EQ (rt.m_reqNo, 2, "trivial");
|
|
504 |
}
|
|
505 |
// -----------------------------------------------------------------------------
|
|
506 |
class DsrTestSuite : public TestSuite
|
|
507 |
{
|
|
508 |
public:
|
|
509 |
DsrTestSuite () : TestSuite ("routing-dsr", UNIT)
|
|
510 |
{
|
|
511 |
AddTestCase (new DsrFsHeaderTest);
|
|
512 |
AddTestCase (new DsrRreqHeaderTest);
|
|
513 |
AddTestCase (new DsrRrepHeaderTest);
|
|
514 |
AddTestCase (new DsrSRHeaderTest);
|
|
515 |
AddTestCase (new DsrRerrHeaderTest);
|
|
516 |
AddTestCase (new DsrAckReqHeaderTest);
|
|
517 |
AddTestCase (new DsrAckHeaderTest);
|
|
518 |
AddTestCase (new DsrCacheEntryTest);
|
|
519 |
AddTestCase (new DsrSendBuffTest);
|
|
520 |
}
|
|
521 |
} g_dsrTestSuite;
|
|
522 |
} // namespace dsr
|
|
523 |
} // namespace ns3
|