A Discrete-Event Network Simulator
API
ns2-mobility-helper-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INRIA
3 * 2009,2010 Contributors
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 * Contributors: Thomas Waldecker <twaldecker@rocketmail.com>
20 * Martín Giachino <martin.giachino@gmail.com>
21 *
22 * Brief description: Implementation of a ns2 movement trace file reader.
23 *
24 * This implementation is based on the ns2 movement documentation of ns2
25 * as described in http://www.isi.edu/nsnam/ns/doc/node174.html
26 *
27 * Valid trace files use the following ns2 statements:
28 *
29 * $node set X_ x1
30 * $node set Y_ y1
31 * $node set Z_ z1
32 * $ns at $time $node setdest x2 y2 speed
33 * $ns at $time $node set X_ x1
34 * $ns at $time $node set Y_ Y1
35 * $ns at $time $node set Z_ Z1
36 *
37 */
38
39#include "ns3/config.h"
40#include "ns3/constant-velocity-mobility-model.h"
41#include "ns3/log.h"
42#include "ns3/names.h"
43#include "ns3/node-container.h"
44#include "ns3/node-list.h"
45#include "ns3/node.h"
46#include "ns3/ns2-mobility-helper.h"
47#include "ns3/simulator.h"
48#include "ns3/test.h"
49
50#include <algorithm>
51
52using namespace ns3;
53
54NS_LOG_COMPONENT_DEFINE("ns2-mobility-helper-test-suite");
55
56// -----------------------------------------------------------------------------
57// Testing
58// -----------------------------------------------------------------------------
59bool
60AreVectorsEqual(const Vector& actual, const Vector& limit, double tol)
61{
62 if (actual.x > limit.x + tol || actual.x < limit.x - tol)
63 {
64 return false;
65 }
66 if (actual.y > limit.y + tol || actual.y < limit.y - tol)
67 {
68 return false;
69 }
70 if (actual.z > limit.z + tol || actual.z < limit.z - tol)
71 {
72 return false;
73 }
74 return true;
75}
76
89{
90 public:
93 {
94 std::string node;
96 Vector pos;
97 Vector vel;
98
107 ReferencePoint(const std::string& id, Time t, const Vector& p, const Vector& v)
108 : node(id),
109 time(t),
110 pos(p),
111 vel(v)
112 {
113 }
114
120 bool operator<(const ReferencePoint& o) const
121 {
122 return (time < o.time);
123 }
124 };
125
133 Ns2MobilityHelperTest(const std::string& name, Time timeLimit, uint32_t nodes = 1)
134 : TestCase(name),
135 m_timeLimit(timeLimit),
138 {
139 }
140
143 {
144 }
145
150 void SetTrace(const std::string& trace)
151 {
152 m_trace = trace;
153 }
154
160 {
161 m_reference.push_back(r);
162 }
163
171 void AddReferencePoint(const char* id, double sec, const Vector& p, const Vector& v)
172 {
174 }
175
176 private:
182 std::string m_trace;
184 std::vector<ReferencePoint> m_reference;
188 std::string m_traceFile;
189
190 private:
196 {
197 m_traceFile = CreateTempDirFilename("Ns2MobilityHelperTest.tcl");
198 std::ofstream of(m_traceFile);
199 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(of.is_open(), true, "Need to write tmp. file");
200 of << m_trace;
201 of.close();
202 return false; // no errors
203 }
204
207 {
210 for (uint32_t i = 0; i < m_nodeCount; ++i)
211 {
212 std::ostringstream os;
213 os << i;
214 Names::Add(os.str(), nodes.Get(i));
215 }
216 }
217
223 {
224 std::stable_sort(m_reference.begin(), m_reference.end());
225 while (m_nextRefPoint < m_reference.size() &&
227 {
229 Ptr<Node> node = Names::Find<Node>(rp.node);
231 nullptr,
232 "Can't find node with id " << rp.node);
235 nullptr,
236 "Can't find mobility for node " << rp.node);
237
238 double tol = 0.001;
240 true,
241 "Initial position mismatch for node " << rp.node);
243 true,
244 "Initial velocity mismatch for node " << rp.node);
245
247 }
248 return IsStatusFailure();
249 }
250
257 {
258 Time time = Simulator::Now();
259 Ptr<Node> node = mobility->GetObject<Node>();
260 NS_ASSERT(node);
261 std::string id = Names::FindName(node);
262 NS_ASSERT(!id.empty());
263 Vector pos = mobility->GetPosition();
264 Vector vel = mobility->GetVelocity();
265
266 NS_TEST_EXPECT_MSG_LT(m_nextRefPoint, m_reference.size(), "Not enough reference points");
267 if (m_nextRefPoint >= m_reference.size())
268 {
269 return;
270 }
271
273 NS_TEST_EXPECT_MSG_EQ(time, ref.time, "Time mismatch");
275 ref.node,
276 "Node ID mismatch at time " << time.GetSeconds() << " s");
277
278 double tol = 0.001;
280 true,
281 "Position mismatch at time " << time.GetSeconds() << " s for node "
282 << id);
284 true,
285 "Velocity mismatch at time " << time.GetSeconds() << " s for node "
286 << id);
287 }
288
289 void DoSetup() override
290 {
291 CreateNodes();
292 }
293
294 void DoTeardown() override
295 {
296 Names::Clear();
297 Simulator::Destroy();
298 }
299
301 void DoRun() override
302 {
303 NS_TEST_ASSERT_MSG_EQ(m_trace.empty(), false, "Need trace");
304 NS_TEST_ASSERT_MSG_EQ(m_reference.empty(), false, "Need reference");
305
306 if (WriteTrace())
307 {
308 return;
309 }
311 mobility.Install();
313 {
314 return;
315 }
316 Config::Connect("/NodeList/*/$ns3::MobilityModel/CourseChange",
318 Simulator::Stop(m_timeLimit);
319 Simulator::Run();
320 }
321};
322
330{
331 public:
333 : TestSuite("mobility-ns2-trace-helper", UNIT)
334 {
335 SetDataDir(NS_TEST_SOURCEDIR);
336
337 // to be used as temporary variable for test cases.
338 // Note that test suite takes care of deleting all test cases.
339 Ns2MobilityHelperTest* t(nullptr);
340
341 // Initial position
342 t = new Ns2MobilityHelperTest("initial position", Seconds(1));
343 t->SetTrace("$node_(0) set X_ 1.0\n"
344 "$node_(0) set Y_ 2.0\n"
345 "$node_(0) set Z_ 3.0\n");
346 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
347 AddTestCase(t, TestCase::QUICK);
348
349 // Check parsing comments, empty lines and no EOF at the end of file
350 t = new Ns2MobilityHelperTest("comments", Seconds(1));
351 t->SetTrace("# comment\n"
352 "\n\n" // empty lines
353 "$node_(0) set X_ 1.0 # comment \n"
354 "$node_(0) set Y_ 2.0 ### \n"
355 "$node_(0) set Z_ 3.0 # $node_(0) set Z_ 3.0\n"
356 "#$node_(0) set Z_ 100 #");
357 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
358 AddTestCase(t, TestCase::QUICK);
359
360 // Simple setdest. Arguments are interpreted as x, y, speed by default
361 t = new Ns2MobilityHelperTest("simple setdest", Seconds(10));
362 t->SetTrace("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"");
363 // id t position velocity
364 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
365 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(5, 0, 0));
366 t->AddReferencePoint("0", 6, Vector(25, 0, 0), Vector(0, 0, 0));
367 AddTestCase(t, TestCase::QUICK);
368
369 // Several set and setdest. Arguments are interpreted as x, y, speed by default
370 t = new Ns2MobilityHelperTest("square setdest", Seconds(6));
371 t->SetTrace("$node_(0) set X_ 0.0\n"
372 "$node_(0) set Y_ 0.0\n"
373 "$ns_ at 1.0 \"$node_(0) setdest 5 0 5\"\n"
374 "$ns_ at 2.0 \"$node_(0) setdest 5 5 5\"\n"
375 "$ns_ at 3.0 \"$node_(0) setdest 0 5 5\"\n"
376 "$ns_ at 4.0 \"$node_(0) setdest 0 0 5\"\n");
377 // id t position velocity
378 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
379 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(5, 0, 0));
380 t->AddReferencePoint("0", 2, Vector(5, 0, 0), Vector(0, 0, 0));
381 t->AddReferencePoint("0", 2, Vector(5, 0, 0), Vector(0, 5, 0));
382 t->AddReferencePoint("0", 3, Vector(5, 5, 0), Vector(0, 0, 0));
383 t->AddReferencePoint("0", 3, Vector(5, 5, 0), Vector(-5, 0, 0));
384 t->AddReferencePoint("0", 4, Vector(0, 5, 0), Vector(0, 0, 0));
385 t->AddReferencePoint("0", 4, Vector(0, 5, 0), Vector(0, -5, 0));
386 t->AddReferencePoint("0", 5, Vector(0, 0, 0), Vector(0, 0, 0));
387 AddTestCase(t, TestCase::QUICK);
388
389 // Copy of previous test case but with the initial positions at
390 // the end of the trace rather than at the beginning.
391 //
392 // Several set and setdest. Arguments are interpreted as x, y, speed by default
393 t = new Ns2MobilityHelperTest("square setdest (initial positions at end)", Seconds(6));
394 t->SetTrace("$ns_ at 1.0 \"$node_(0) setdest 15 10 5\"\n"
395 "$ns_ at 2.0 \"$node_(0) setdest 15 15 5\"\n"
396 "$ns_ at 3.0 \"$node_(0) setdest 10 15 5\"\n"
397 "$ns_ at 4.0 \"$node_(0) setdest 10 10 5\"\n"
398 "$node_(0) set X_ 10.0\n"
399 "$node_(0) set Y_ 10.0\n");
400 // id t position velocity
401 t->AddReferencePoint("0", 0, Vector(10, 10, 0), Vector(0, 0, 0));
402 t->AddReferencePoint("0", 1, Vector(10, 10, 0), Vector(5, 0, 0));
403 t->AddReferencePoint("0", 2, Vector(15, 10, 0), Vector(0, 0, 0));
404 t->AddReferencePoint("0", 2, Vector(15, 10, 0), Vector(0, 5, 0));
405 t->AddReferencePoint("0", 3, Vector(15, 15, 0), Vector(0, 0, 0));
406 t->AddReferencePoint("0", 3, Vector(15, 15, 0), Vector(-5, 0, 0));
407 t->AddReferencePoint("0", 4, Vector(10, 15, 0), Vector(0, 0, 0));
408 t->AddReferencePoint("0", 4, Vector(10, 15, 0), Vector(0, -5, 0));
409 t->AddReferencePoint("0", 5, Vector(10, 10, 0), Vector(0, 0, 0));
410 AddTestCase(t, TestCase::QUICK);
411
412 // Scheduled set position
413 t = new Ns2MobilityHelperTest("scheduled set position", Seconds(2));
414 t->SetTrace("$ns_ at 1.0 \"$node_(0) set X_ 10\"\n"
415 "$ns_ at 1.0 \"$node_(0) set Z_ 10\"\n"
416 "$ns_ at 1.0 \"$node_(0) set Y_ 10\"");
417 // id t position velocity
418 t->AddReferencePoint("0", 1, Vector(10, 0, 0), Vector(0, 0, 0));
419 t->AddReferencePoint("0", 1, Vector(10, 0, 10), Vector(0, 0, 0));
420 t->AddReferencePoint("0", 1, Vector(10, 10, 10), Vector(0, 0, 0));
421 AddTestCase(t, TestCase::QUICK);
422
423 // Malformed lines
424 t = new Ns2MobilityHelperTest("malformed lines", Seconds(2));
425 t->SetTrace("$node() set X_ 1 # node id is not present\n"
426 "$node # incoplete line\"\n"
427 "$node this line is not correct\n"
428 "$node_(0) set X_ 1 # line OK \n"
429 "$node_(0) set Y_ 2 # line OK \n"
430 "$node_(0) set Z_ 3 # line OK \n"
431 "$ns_ at \"$node_(0) setdest 4 4 4\" # time not present\n"
432 "$ns_ at 1 \"$node_(0) setdest 2 2 1 \" # line OK \n");
433 // id t position velocity
434 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
435 t->AddReferencePoint("0", 1, Vector(1, 2, 3), Vector(1, 0, 0));
436 t->AddReferencePoint("0", 2, Vector(2, 2, 3), Vector(0, 0, 0));
437 AddTestCase(t, TestCase::QUICK);
438
439 // Non possible values
440 t = new Ns2MobilityHelperTest("non possible values", Seconds(2));
441 t->SetTrace(
442 "$node_(0) set X_ 1 # line OK \n"
443 "$node_(0) set Y_ 2 # line OK \n"
444 "$node_(0) set Z_ 3 # line OK \n"
445 "$node_(-22) set Y_ 3 # node id not correct\n"
446 "$node_(3.3) set Y_ 1111 # node id not correct\n"
447 "$ns_ at sss \"$node_(0) setdest 5 5 5\" # time is not a number\n"
448 "$ns_ at 1 \"$node_(0) setdest 2 2 1\" # line OK \n"
449 "$ns_ at 1 \"$node_(0) setdest 2 2 -1\" # negative speed is not correct\n"
450 "$ns_ at 1 \"$node_(0) setdest 2 2 sdfs\" # speed is not a number\n"
451 "$ns_ at 1 \"$node_(0) setdest 2 2 s232dfs\" # speed is not a number\n"
452 "$ns_ at 1 \"$node_(0) setdest 233 2.. s232dfs\" # more than one non numbers\n"
453 "$ns_ at -12 \"$node_(0) setdest 11 22 33\" # time should not be negative\n");
454 // id t position velocity
455 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
456 t->AddReferencePoint("0", 1, Vector(1, 2, 3), Vector(1, 0, 0));
457 t->AddReferencePoint("0", 2, Vector(2, 2, 3), Vector(0, 0, 0));
458 AddTestCase(t, TestCase::QUICK);
459
460 // More than one node
461 t = new Ns2MobilityHelperTest("few nodes, combinations of set and setdest", Seconds(10), 3);
462 t->SetTrace("$node_(0) set X_ 1.0\n"
463 "$node_(0) set Y_ 2.0\n"
464 "$node_(0) set Z_ 3.0\n"
465 "$ns_ at 1.0 \"$node_(1) setdest 25 0 5\"\n"
466 "$node_(2) set X_ 0.0\n"
467 "$node_(2) set Y_ 0.0\n"
468 "$ns_ at 1.0 \"$node_(2) setdest 5 0 5\"\n"
469 "$ns_ at 2.0 \"$node_(2) setdest 5 5 5\"\n"
470 "$ns_ at 3.0 \"$node_(2) setdest 0 5 5\"\n"
471 "$ns_ at 4.0 \"$node_(2) setdest 0 0 5\"\n");
472 // id t position velocity
473 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
474 t->AddReferencePoint("1", 0, Vector(0, 0, 0), Vector(0, 0, 0));
475 t->AddReferencePoint("1", 1, Vector(0, 0, 0), Vector(5, 0, 0));
476 t->AddReferencePoint("1", 6, Vector(25, 0, 0), Vector(0, 0, 0));
477 t->AddReferencePoint("2", 0, Vector(0, 0, 0), Vector(0, 0, 0));
478 t->AddReferencePoint("2", 1, Vector(0, 0, 0), Vector(5, 0, 0));
479 t->AddReferencePoint("2", 2, Vector(5, 0, 0), Vector(0, 0, 0));
480 t->AddReferencePoint("2", 2, Vector(5, 0, 0), Vector(0, 5, 0));
481 t->AddReferencePoint("2", 3, Vector(5, 5, 0), Vector(0, 0, 0));
482 t->AddReferencePoint("2", 3, Vector(5, 5, 0), Vector(-5, 0, 0));
483 t->AddReferencePoint("2", 4, Vector(0, 5, 0), Vector(0, 0, 0));
484 t->AddReferencePoint("2", 4, Vector(0, 5, 0), Vector(0, -5, 0));
485 t->AddReferencePoint("2", 5, Vector(0, 0, 0), Vector(0, 0, 0));
486 AddTestCase(t, TestCase::QUICK);
487
488 // Test for Speed == 0, that acts as stop the node.
489 t = new Ns2MobilityHelperTest("setdest with speed cero", Seconds(10));
490 t->SetTrace("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"\n"
491 "$ns_ at 7.0 \"$node_(0) setdest 11 22 0\"\n");
492 // id t position velocity
493 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
494 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(5, 0, 0));
495 t->AddReferencePoint("0", 6, Vector(25, 0, 0), Vector(0, 0, 0));
496 t->AddReferencePoint("0", 7, Vector(25, 0, 0), Vector(0, 0, 0));
497 AddTestCase(t, TestCase::QUICK);
498
499 // Test negative positions
500 t = new Ns2MobilityHelperTest("test negative positions", Seconds(10));
501 t->SetTrace("$node_(0) set X_ -1.0\n"
502 "$node_(0) set Y_ 0\n"
503 "$ns_ at 1.0 \"$node_(0) setdest 0 0 1\"\n"
504 "$ns_ at 2.0 \"$node_(0) setdest 0 -1 1\"\n");
505 // id t position velocity
506 t->AddReferencePoint("0", 0, Vector(-1, 0, 0), Vector(0, 0, 0));
507 t->AddReferencePoint("0", 1, Vector(-1, 0, 0), Vector(1, 0, 0));
508 t->AddReferencePoint("0", 2, Vector(0, 0, 0), Vector(0, 0, 0));
509 t->AddReferencePoint("0", 2, Vector(0, 0, 0), Vector(0, -1, 0));
510 t->AddReferencePoint("0", 3, Vector(0, -1, 0), Vector(0, 0, 0));
511 AddTestCase(t, TestCase::QUICK);
512
513 // Sqare setdest with values in the form 1.0e+2
514 t = new Ns2MobilityHelperTest("Foalt numbers in 1.0e+2 format", Seconds(6));
515 t->SetTrace("$node_(0) set X_ 0.0\n"
516 "$node_(0) set Y_ 0.0\n"
517 "$ns_ at 1.0 \"$node_(0) setdest 1.0e+2 0 1.0e+2\"\n"
518 "$ns_ at 2.0 \"$node_(0) setdest 1.0e+2 1.0e+2 1.0e+2\"\n"
519 "$ns_ at 3.0 \"$node_(0) setdest 0 1.0e+2 1.0e+2\"\n"
520 "$ns_ at 4.0 \"$node_(0) setdest 0 0 1.0e+2\"\n");
521 // id t position velocity
522 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
523 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(100, 0, 0));
524 t->AddReferencePoint("0", 2, Vector(100, 0, 0), Vector(0, 0, 0));
525 t->AddReferencePoint("0", 2, Vector(100, 0, 0), Vector(0, 100, 0));
526 t->AddReferencePoint("0", 3, Vector(100, 100, 0), Vector(0, 0, 0));
527 t->AddReferencePoint("0", 3, Vector(100, 100, 0), Vector(-100, 0, 0));
528 t->AddReferencePoint("0", 4, Vector(0, 100, 0), Vector(0, 0, 0));
529 t->AddReferencePoint("0", 4, Vector(0, 100, 0), Vector(0, -100, 0));
530 t->AddReferencePoint("0", 5, Vector(0, 0, 0), Vector(0, 0, 0));
531 AddTestCase(t, TestCase::QUICK);
532 t = new Ns2MobilityHelperTest("Bug 1219 testcase", Seconds(16));
533 t->SetTrace("$node_(0) set X_ 0.0\n"
534 "$node_(0) set Y_ 0.0\n"
535 "$ns_ at 1.0 \"$node_(0) setdest 0 10 1\"\n"
536 "$ns_ at 6.0 \"$node_(0) setdest 0 -10 1\"\n");
537 // id t position velocity
538 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
539 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(0, 1, 0));
540 t->AddReferencePoint("0", 6, Vector(0, 5, 0), Vector(0, -1, 0));
541 t->AddReferencePoint("0", 16, Vector(0, -10, 0), Vector(0, 0, 0));
542 AddTestCase(t, TestCase::QUICK);
543 t = new Ns2MobilityHelperTest("Bug 1059 testcase", Seconds(16));
544 t->SetTrace("$node_(0) set X_ 10.0\r\n"
545 "$node_(0) set Y_ 0.0\r\n");
546 // id t position velocity
547 t->AddReferencePoint("0", 0, Vector(10, 0, 0), Vector(0, 0, 0));
548 AddTestCase(t, TestCase::QUICK);
549 t = new Ns2MobilityHelperTest("Bug 1301 testcase", Seconds(16));
550 t->SetTrace("$node_(0) set X_ 10.0\n"
551 "$node_(0) set Y_ 0.0\n"
552 "$ns_ at 1.0 \"$node_(0) setdest 10 0 1\"\n");
553 // id t position velocity
554 // Moving to the current position must change nothing. No NaN
555 // speed must be.
556 t->AddReferencePoint("0", 0, Vector(10, 0, 0), Vector(0, 0, 0));
557 AddTestCase(t, TestCase::QUICK);
558
559 t = new Ns2MobilityHelperTest("Bug 1316 testcase", Seconds(1000));
560 t->SetTrace("$node_(0) set X_ 350.00000000000000\n"
561 "$node_(0) set Y_ 50.00000000000000\n"
562 "$ns_ at 50.00000000000000 \"$node_(0) setdest 400.00000000000000 "
563 "50.00000000000000 1.00000000000000\"\n"
564 "$ns_ at 150.00000000000000 \"$node_(0) setdest 400.00000000000000 "
565 "150.00000000000000 4.00000000000000\"\n"
566 "$ns_ at 300.00000000000000 \"$node_(0) setdest 250.00000000000000 "
567 "150.00000000000000 3.00000000000000\"\n"
568 "$ns_ at 350.00000000000000 \"$node_(0) setdest 250.00000000000000 "
569 "50.00000000000000 1.00000000000000\"\n"
570 "$ns_ at 600.00000000000000 \"$node_(0) setdest 250.00000000000000 "
571 "1050.00000000000000 2.00000000000000\"\n"
572 "$ns_ at 900.00000000000000 \"$node_(0) setdest 300.00000000000000 "
573 "650.00000000000000 2.50000000000000\"\n");
574 t->AddReferencePoint("0",
575 0.000,
576 Vector(350.000, 50.000, 0.000),
577 Vector(0.000, 0.000, 0.000));
578 t->AddReferencePoint("0",
579 50.000,
580 Vector(350.000, 50.000, 0.000),
581 Vector(1.000, 0.000, 0.000));
582 t->AddReferencePoint("0",
583 100.000,
584 Vector(400.000, 50.000, 0.000),
585 Vector(0.000, 0.000, 0.000));
586 t->AddReferencePoint("0",
587 150.000,
588 Vector(400.000, 50.000, 0.000),
589 Vector(0.000, 4.000, 0.000));
590 t->AddReferencePoint("0",
591 175.000,
592 Vector(400.000, 150.000, 0.000),
593 Vector(0.000, 0.000, 0.000));
594 t->AddReferencePoint("0",
595 300.000,
596 Vector(400.000, 150.000, 0.000),
597 Vector(-3.000, 0.000, 0.000));
598 t->AddReferencePoint("0",
599 350.000,
600 Vector(250.000, 150.000, 0.000),
601 Vector(0.000, 0.000, 0.000));
602 t->AddReferencePoint("0",
603 350.000,
604 Vector(250.000, 150.000, 0.000),
605 Vector(0.000, -1.000, 0.000));
606 t->AddReferencePoint("0",
607 450.000,
608 Vector(250.000, 50.000, 0.000),
609 Vector(0.000, 0.000, 0.000));
610 t->AddReferencePoint("0",
611 600.000,
612 Vector(250.000, 50.000, 0.000),
613 Vector(0.000, 2.000, 0.000));
614 t->AddReferencePoint("0",
615 900.000,
616 Vector(250.000, 650.000, 0.000),
617 Vector(2.500, 0.000, 0.000));
618 t->AddReferencePoint("0",
619 920.000,
620 Vector(300.000, 650.000, 0.000),
621 Vector(0.000, 0.000, 0.000));
622 AddTestCase(t, TestCase::QUICK);
623 }
Every test case is supposed to:
std::string m_traceFile
TMP trace file name.
bool CheckInitialPositions()
Check that all initial positions are correct.
void AddReferencePoint(const char *id, double sec, const Vector &p, const Vector &v)
Add next reference point.
void CourseChange(std::string context, Ptr< const MobilityModel > mobility)
Listen for course change events.
void AddReferencePoint(const ReferencePoint &r)
Add next reference point.
bool WriteTrace()
Dump NS-2 trace to tmp file.
std::string m_trace
Trace as string.
size_t m_nextRefPoint
Next reference point to be checked.
std::vector< ReferencePoint > m_reference
Reference mobility.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void CreateNodes()
Create and name nodes.
void SetTrace(const std::string &trace)
Set NS-2 trace to read as single large string (don't forget to add \n and quote "'s)
Ns2MobilityHelperTest(const std::string &name, Time timeLimit, uint32_t nodes=1)
Create new test case.
uint32_t m_nodeCount
Number of nodes used in the test.
Keep track of the current position and velocity of an object.
Vector GetVelocity() const
Vector GetPosition() const
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A network Node.
Definition: node.h:56
Helper class which can read ns-2 movement files and configure nodes mobility.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
encapsulates test code
Definition: test.h:1060
bool IsStatusFailure() const
Check if any tests failed.
Definition: test.cc:468
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition: test.cc:442
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition: test.cc:482
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:402
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:324
Empty class, used as a default parent class for SimpleRefCount.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:975
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:296
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:144
#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:199
#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report if not.
Definition: test.h:790
#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:251
#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Definition: test.h:615
Ns2MobilityHelperTestSuite g_ns2TransmobilityHelperTestSuite
the test suite
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:691
mobility
Definition: third.py:96
bool AreVectorsEqual(const Vector &actual, const Vector &limit, double tol)
std::string node
node ID as string, e.g. "1"
ReferencePoint(const std::string &id, Time t, const Vector &p, const Vector &v)
Constructor.
bool operator<(const ReferencePoint &o) const
Less-than operator - used to sort by timestamp.