A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8 * Contributors: Thomas Waldecker <twaldecker@rocketmail.com>
9 * Martín Giachino <martin.giachino@gmail.com>
10 *
11 * Brief description: Implementation of a ns2 movement trace file reader.
12 *
13 * This implementation is based on the ns2 movement documentation of ns2
14 * as described in http://www.isi.edu/nsnam/ns/doc/node174.html
15 *
16 * Valid trace files use the following ns2 statements:
17 *
18 * $node set X_ x1
19 * $node set Y_ y1
20 * $node set Z_ z1
21 * $ns at $time $node setdest x2 y2 speed
22 * $ns at $time $node set X_ x1
23 * $ns at $time $node set Y_ Y1
24 * $ns at $time $node set Z_ Z1
25 *
26 */
27
28#include "ns3/config.h"
29#include "ns3/constant-velocity-mobility-model.h"
30#include "ns3/log.h"
31#include "ns3/names.h"
32#include "ns3/node-container.h"
33#include "ns3/node-list.h"
34#include "ns3/node.h"
35#include "ns3/ns2-mobility-helper.h"
36#include "ns3/simulator.h"
37#include "ns3/test.h"
38
39#include <algorithm>
40
41using namespace ns3;
42
43NS_LOG_COMPONENT_DEFINE("ns2-mobility-helper-test-suite");
44
45// -----------------------------------------------------------------------------
46// Testing
47// -----------------------------------------------------------------------------
48bool
49AreVectorsEqual(const Vector& actual, const Vector& limit, double tol)
50{
51 if (actual.x > limit.x + tol || actual.x < limit.x - tol)
52 {
53 return false;
54 }
55 if (actual.y > limit.y + tol || actual.y < limit.y - tol)
56 {
57 return false;
58 }
59 if (actual.z > limit.z + tol || actual.z < limit.z - tol)
60 {
61 return false;
62 }
63 return true;
64}
65
66/**
67 * \ingroup mobility-test
68 *
69 * \brief Every test case is supposed to:
70 * 1. Generate short mobility trace file
71 * 2. Read it back using Ns2MobilityHelper
72 * 3. Check initial node positions and speeds.
73 * 4. Run simulation listening for all CourseChange events and compare actual mobility with the
74 * reference
75 */
77{
78 public:
79 /// Single record in mobility reference
81 {
82 std::string node; ///< node ID as string, e.g. "1"
83 Time time; ///< timestamp
84 Vector pos; ///< reference position
85 Vector vel; ///< reference velocity
86
87 /**
88 * Constructor
89 *
90 * \param id reference ID
91 * \param t time
92 * \param p position
93 * \param v velocity
94 */
95 ReferencePoint(const std::string& id, Time t, const Vector& p, const Vector& v)
96 : node(id),
97 time(t),
98 pos(p),
99 vel(v)
100 {
101 }
102
103 /**
104 * Less-than operator - used to sort by timestamp
105 * \param o object to compare to
106 * \returns true if the timestamp of the 1st operand is less than the other one's
107 */
108 bool operator<(const ReferencePoint& o) const
109 {
110 return time < o.time;
111 }
112 };
113
114 /**
115 * Create new test case. To make it useful SetTrace () and AddReferencePoint () must be called
116 *
117 * \param name Short description
118 * \param timeLimit Test time limit
119 * \param nodes Number of nodes used in the test trace, 1 by default
120 */
121 Ns2MobilityHelperTest(const std::string& name, Time timeLimit, uint32_t nodes = 1)
122 : TestCase(name),
123 m_timeLimit(timeLimit),
126 {
127 }
128
129 /// Empty
131 {
132 }
133
134 /**
135 * Set NS-2 trace to read as single large string (don't forget to add \\n and quote \"'s)
136 * \param trace the mobility trace
137 */
138 void SetTrace(const std::string& trace)
139 {
140 m_trace = trace;
141 }
142
143 /**
144 * Add next reference point
145 * \param r reference point to add
146 */
148 {
149 m_reference.push_back(r);
150 }
151
152 /**
153 * Add next reference point
154 * \param id reference point id
155 * \param sec reference point ime (in seconds)
156 * \param p reference point position
157 * \param v reference point velocity
158 */
159 void AddReferencePoint(const char* id, double sec, const Vector& p, const Vector& v)
160 {
162 }
163
164 private:
165 /// Test time limit
167 /// Number of nodes used in the test
169 /// Trace as string
170 std::string m_trace;
171 /// Reference mobility
172 std::vector<ReferencePoint> m_reference;
173 /// Next reference point to be checked
175 /// TMP trace file name
176 std::string m_traceFile;
177
178 private:
179 /**
180 * Dump NS-2 trace to tmp file
181 * \return true on error.
182 */
184 {
185 m_traceFile = CreateTempDirFilename("Ns2MobilityHelperTest.tcl");
186 std::ofstream of(m_traceFile);
187 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(of.is_open(), true, "Need to write tmp. file");
188 of << m_trace;
189 of.close();
190 return false; // no errors
191 }
192
193 /// Create and name nodes
194 void CreateNodes() const
195 {
198 for (uint32_t i = 0; i < m_nodeCount; ++i)
199 {
200 std::ostringstream os;
201 os << i;
202 Names::Add(os.str(), nodes.Get(i));
203 }
204 }
205
206 /**
207 * Check that all initial positions are correct
208 * \return true on error.
209 */
211 {
212 std::stable_sort(m_reference.begin(), m_reference.end());
213 while (m_nextRefPoint < m_reference.size() &&
215 {
219 nullptr,
220 "Can't find node with id " << rp.node);
221 Ptr<MobilityModel> mob = node->GetObject<MobilityModel>();
223 nullptr,
224 "Can't find mobility for node " << rp.node);
225
226 double tol = 0.001;
227 NS_TEST_EXPECT_MSG_EQ(AreVectorsEqual(mob->GetPosition(), rp.pos, tol),
228 true,
229 "Initial position mismatch for node " << rp.node);
230 NS_TEST_EXPECT_MSG_EQ(AreVectorsEqual(mob->GetVelocity(), rp.vel, tol),
231 true,
232 "Initial velocity mismatch for node " << rp.node);
233
235 }
236 return IsStatusFailure();
237 }
238
239 /**
240 * Listen for course change events
241 * \param context event context
242 * \param mobility a pointer to the mobility model
243 */
244 void CourseChange(std::string context, Ptr<const MobilityModel> mobility)
245 {
246 Time time = Simulator::Now();
247 Ptr<Node> node = mobility->GetObject<Node>();
248 NS_ASSERT(node);
249 std::string id = Names::FindName(node);
250 NS_ASSERT(!id.empty());
251 Vector pos = mobility->GetPosition();
252 Vector vel = mobility->GetVelocity();
253
254 NS_TEST_EXPECT_MSG_LT(m_nextRefPoint, m_reference.size(), "Not enough reference points");
255 if (m_nextRefPoint >= m_reference.size())
256 {
257 return;
258 }
259
261 NS_TEST_EXPECT_MSG_EQ(time, ref.time, "Time mismatch");
263 ref.node,
264 "Node ID mismatch at time " << time.GetSeconds() << " s");
265
266 double tol = 0.001;
268 true,
269 "Position mismatch at time " << time.GetSeconds() << " s for node "
270 << id);
272 true,
273 "Velocity mismatch at time " << time.GetSeconds() << " s for node "
274 << id);
275 }
276
277 void DoSetup() override
278 {
279 CreateNodes();
280 }
281
282 void DoTeardown() override
283 {
284 Names::Clear();
286 }
287
288 /// Go
289 void DoRun() override
290 {
291 NS_TEST_ASSERT_MSG_EQ(m_trace.empty(), false, "Need trace");
292 NS_TEST_ASSERT_MSG_EQ(m_reference.empty(), false, "Need reference");
293
294 if (WriteTrace())
295 {
296 return;
297 }
299 mobility.Install();
301 {
302 return;
303 }
304 Config::Connect("/NodeList/*/$ns3::MobilityModel/CourseChange",
308 }
309};
310
311/**
312 * \ingroup mobility-test
313 *
314 * \brief The test suite
315 */
317{
318 public:
320 : TestSuite("mobility-ns2-trace-helper", Type::UNIT)
321 {
322 SetDataDir(NS_TEST_SOURCEDIR);
323
324 // to be used as temporary variable for test cases.
325 // Note that test suite takes care of deleting all test cases.
326 Ns2MobilityHelperTest* t(nullptr);
327
328 // Initial position
329 t = new Ns2MobilityHelperTest("initial position", Seconds(1));
330 t->SetTrace("$node_(0) set X_ 1.0\n"
331 "$node_(0) set Y_ 2.0\n"
332 "$node_(0) set Z_ 3.0\n");
333 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
334 AddTestCase(t, TestCase::Duration::QUICK);
335
336 // Check parsing comments, empty lines and no EOF at the end of file
337 t = new Ns2MobilityHelperTest("comments", Seconds(1));
338 t->SetTrace("# comment\n"
339 "\n\n" // empty lines
340 "$node_(0) set X_ 1.0 # comment \n"
341 "$node_(0) set Y_ 2.0 ### \n"
342 "$node_(0) set Z_ 3.0 # $node_(0) set Z_ 3.0\n"
343 "#$node_(0) set Z_ 100 #");
344 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
345 AddTestCase(t, TestCase::Duration::QUICK);
346
347 // Simple setdest. Arguments are interpreted as x, y, speed by default
348 t = new Ns2MobilityHelperTest("simple setdest", Seconds(10));
349 t->SetTrace("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"");
350 // id t position velocity
351 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
352 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(5, 0, 0));
353 t->AddReferencePoint("0", 6, Vector(25, 0, 0), Vector(0, 0, 0));
354 AddTestCase(t, TestCase::Duration::QUICK);
355
356 // Several set and setdest. Arguments are interpreted as x, y, speed by default
357 t = new Ns2MobilityHelperTest("square setdest", Seconds(6));
358 t->SetTrace("$node_(0) set X_ 0.0\n"
359 "$node_(0) set Y_ 0.0\n"
360 "$ns_ at 1.0 \"$node_(0) setdest 5 0 5\"\n"
361 "$ns_ at 2.0 \"$node_(0) setdest 5 5 5\"\n"
362 "$ns_ at 3.0 \"$node_(0) setdest 0 5 5\"\n"
363 "$ns_ at 4.0 \"$node_(0) setdest 0 0 5\"\n");
364 // id t position velocity
365 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
366 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(5, 0, 0));
367 t->AddReferencePoint("0", 2, Vector(5, 0, 0), Vector(0, 0, 0));
368 t->AddReferencePoint("0", 2, Vector(5, 0, 0), Vector(0, 5, 0));
369 t->AddReferencePoint("0", 3, Vector(5, 5, 0), Vector(0, 0, 0));
370 t->AddReferencePoint("0", 3, Vector(5, 5, 0), Vector(-5, 0, 0));
371 t->AddReferencePoint("0", 4, Vector(0, 5, 0), Vector(0, 0, 0));
372 t->AddReferencePoint("0", 4, Vector(0, 5, 0), Vector(0, -5, 0));
373 t->AddReferencePoint("0", 5, Vector(0, 0, 0), Vector(0, 0, 0));
374 AddTestCase(t, TestCase::Duration::QUICK);
375
376 // Copy of previous test case but with the initial positions at
377 // the end of the trace rather than at the beginning.
378 //
379 // Several set and setdest. Arguments are interpreted as x, y, speed by default
380 t = new Ns2MobilityHelperTest("square setdest (initial positions at end)", Seconds(6));
381 t->SetTrace("$ns_ at 1.0 \"$node_(0) setdest 15 10 5\"\n"
382 "$ns_ at 2.0 \"$node_(0) setdest 15 15 5\"\n"
383 "$ns_ at 3.0 \"$node_(0) setdest 10 15 5\"\n"
384 "$ns_ at 4.0 \"$node_(0) setdest 10 10 5\"\n"
385 "$node_(0) set X_ 10.0\n"
386 "$node_(0) set Y_ 10.0\n");
387 // id t position velocity
388 t->AddReferencePoint("0", 0, Vector(10, 10, 0), Vector(0, 0, 0));
389 t->AddReferencePoint("0", 1, Vector(10, 10, 0), Vector(5, 0, 0));
390 t->AddReferencePoint("0", 2, Vector(15, 10, 0), Vector(0, 0, 0));
391 t->AddReferencePoint("0", 2, Vector(15, 10, 0), Vector(0, 5, 0));
392 t->AddReferencePoint("0", 3, Vector(15, 15, 0), Vector(0, 0, 0));
393 t->AddReferencePoint("0", 3, Vector(15, 15, 0), Vector(-5, 0, 0));
394 t->AddReferencePoint("0", 4, Vector(10, 15, 0), Vector(0, 0, 0));
395 t->AddReferencePoint("0", 4, Vector(10, 15, 0), Vector(0, -5, 0));
396 t->AddReferencePoint("0", 5, Vector(10, 10, 0), Vector(0, 0, 0));
397 AddTestCase(t, TestCase::Duration::QUICK);
398
399 // Scheduled set position
400 t = new Ns2MobilityHelperTest("scheduled set position", Seconds(2));
401 t->SetTrace("$ns_ at 1.0 \"$node_(0) set X_ 10\"\n"
402 "$ns_ at 1.0 \"$node_(0) set Z_ 10\"\n"
403 "$ns_ at 1.0 \"$node_(0) set Y_ 10\"");
404 // id t position velocity
405 t->AddReferencePoint("0", 1, Vector(10, 0, 0), Vector(0, 0, 0));
406 t->AddReferencePoint("0", 1, Vector(10, 0, 10), Vector(0, 0, 0));
407 t->AddReferencePoint("0", 1, Vector(10, 10, 10), Vector(0, 0, 0));
408 AddTestCase(t, TestCase::Duration::QUICK);
409
410 // Malformed lines
411 t = new Ns2MobilityHelperTest("malformed lines", Seconds(2));
412 t->SetTrace("$node() set X_ 1 # node id is not present\n"
413 "$node # incoplete line\"\n"
414 "$node this line is not correct\n"
415 "$node_(0) set X_ 1 # line OK \n"
416 "$node_(0) set Y_ 2 # line OK \n"
417 "$node_(0) set Z_ 3 # line OK \n"
418 "$ns_ at \"$node_(0) setdest 4 4 4\" # time not present\n"
419 "$ns_ at 1 \"$node_(0) setdest 2 2 1 \" # line OK \n");
420 // id t position velocity
421 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
422 t->AddReferencePoint("0", 1, Vector(1, 2, 3), Vector(1, 0, 0));
423 t->AddReferencePoint("0", 2, Vector(2, 2, 3), Vector(0, 0, 0));
424 AddTestCase(t, TestCase::Duration::QUICK);
425
426 // Non possible values
427 t = new Ns2MobilityHelperTest("non possible values", Seconds(2));
428 t->SetTrace(
429 "$node_(0) set X_ 1 # line OK \n"
430 "$node_(0) set Y_ 2 # line OK \n"
431 "$node_(0) set Z_ 3 # line OK \n"
432 "$node_(-22) set Y_ 3 # node id not correct\n"
433 "$node_(3.3) set Y_ 1111 # node id not correct\n"
434 "$ns_ at sss \"$node_(0) setdest 5 5 5\" # time is not a number\n"
435 "$ns_ at 1 \"$node_(0) setdest 2 2 1\" # line OK \n"
436 "$ns_ at 1 \"$node_(0) setdest 2 2 -1\" # negative speed is not correct\n"
437 "$ns_ at 1 \"$node_(0) setdest 2 2 sdfs\" # speed is not a number\n"
438 "$ns_ at 1 \"$node_(0) setdest 2 2 s232dfs\" # speed is not a number\n"
439 "$ns_ at 1 \"$node_(0) setdest 233 2.. s232dfs\" # more than one non numbers\n"
440 "$ns_ at -12 \"$node_(0) setdest 11 22 33\" # time should not be negative\n");
441 // id t position velocity
442 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
443 t->AddReferencePoint("0", 1, Vector(1, 2, 3), Vector(1, 0, 0));
444 t->AddReferencePoint("0", 2, Vector(2, 2, 3), Vector(0, 0, 0));
445 AddTestCase(t, TestCase::Duration::QUICK);
446
447 // More than one node
448 t = new Ns2MobilityHelperTest("few nodes, combinations of set and setdest", Seconds(10), 3);
449 t->SetTrace("$node_(0) set X_ 1.0\n"
450 "$node_(0) set Y_ 2.0\n"
451 "$node_(0) set Z_ 3.0\n"
452 "$ns_ at 1.0 \"$node_(1) setdest 25 0 5\"\n"
453 "$node_(2) set X_ 0.0\n"
454 "$node_(2) set Y_ 0.0\n"
455 "$ns_ at 1.0 \"$node_(2) setdest 5 0 5\"\n"
456 "$ns_ at 2.0 \"$node_(2) setdest 5 5 5\"\n"
457 "$ns_ at 3.0 \"$node_(2) setdest 0 5 5\"\n"
458 "$ns_ at 4.0 \"$node_(2) setdest 0 0 5\"\n");
459 // id t position velocity
460 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
461 t->AddReferencePoint("1", 0, Vector(0, 0, 0), Vector(0, 0, 0));
462 t->AddReferencePoint("1", 1, Vector(0, 0, 0), Vector(5, 0, 0));
463 t->AddReferencePoint("1", 6, Vector(25, 0, 0), Vector(0, 0, 0));
464 t->AddReferencePoint("2", 0, Vector(0, 0, 0), Vector(0, 0, 0));
465 t->AddReferencePoint("2", 1, Vector(0, 0, 0), Vector(5, 0, 0));
466 t->AddReferencePoint("2", 2, Vector(5, 0, 0), Vector(0, 0, 0));
467 t->AddReferencePoint("2", 2, Vector(5, 0, 0), Vector(0, 5, 0));
468 t->AddReferencePoint("2", 3, Vector(5, 5, 0), Vector(0, 0, 0));
469 t->AddReferencePoint("2", 3, Vector(5, 5, 0), Vector(-5, 0, 0));
470 t->AddReferencePoint("2", 4, Vector(0, 5, 0), Vector(0, 0, 0));
471 t->AddReferencePoint("2", 4, Vector(0, 5, 0), Vector(0, -5, 0));
472 t->AddReferencePoint("2", 5, Vector(0, 0, 0), Vector(0, 0, 0));
473 AddTestCase(t, TestCase::Duration::QUICK);
474
475 // Test for Speed == 0, that acts as stop the node.
476 t = new Ns2MobilityHelperTest("setdest with speed cero", Seconds(10));
477 t->SetTrace("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"\n"
478 "$ns_ at 7.0 \"$node_(0) setdest 11 22 0\"\n");
479 // id t position velocity
480 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
481 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(5, 0, 0));
482 t->AddReferencePoint("0", 6, Vector(25, 0, 0), Vector(0, 0, 0));
483 t->AddReferencePoint("0", 7, Vector(25, 0, 0), Vector(0, 0, 0));
484 AddTestCase(t, TestCase::Duration::QUICK);
485
486 // Test negative positions
487 t = new Ns2MobilityHelperTest("test negative positions", Seconds(10));
488 t->SetTrace("$node_(0) set X_ -1.0\n"
489 "$node_(0) set Y_ 0\n"
490 "$ns_ at 1.0 \"$node_(0) setdest 0 0 1\"\n"
491 "$ns_ at 2.0 \"$node_(0) setdest 0 -1 1\"\n");
492 // id t position velocity
493 t->AddReferencePoint("0", 0, Vector(-1, 0, 0), Vector(0, 0, 0));
494 t->AddReferencePoint("0", 1, Vector(-1, 0, 0), Vector(1, 0, 0));
495 t->AddReferencePoint("0", 2, Vector(0, 0, 0), Vector(0, 0, 0));
496 t->AddReferencePoint("0", 2, Vector(0, 0, 0), Vector(0, -1, 0));
497 t->AddReferencePoint("0", 3, Vector(0, -1, 0), Vector(0, 0, 0));
498 AddTestCase(t, TestCase::Duration::QUICK);
499
500 // Square setdest with values in the form 1.0e+2
501 t = new Ns2MobilityHelperTest("Foalt numbers in 1.0e+2 format", Seconds(6));
502 t->SetTrace("$node_(0) set X_ 0.0\n"
503 "$node_(0) set Y_ 0.0\n"
504 "$ns_ at 1.0 \"$node_(0) setdest 1.0e+2 0 1.0e+2\"\n"
505 "$ns_ at 2.0 \"$node_(0) setdest 1.0e+2 1.0e+2 1.0e+2\"\n"
506 "$ns_ at 3.0 \"$node_(0) setdest 0 1.0e+2 1.0e+2\"\n"
507 "$ns_ at 4.0 \"$node_(0) setdest 0 0 1.0e+2\"\n");
508 // id t position velocity
509 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
510 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(100, 0, 0));
511 t->AddReferencePoint("0", 2, Vector(100, 0, 0), Vector(0, 0, 0));
512 t->AddReferencePoint("0", 2, Vector(100, 0, 0), Vector(0, 100, 0));
513 t->AddReferencePoint("0", 3, Vector(100, 100, 0), Vector(0, 0, 0));
514 t->AddReferencePoint("0", 3, Vector(100, 100, 0), Vector(-100, 0, 0));
515 t->AddReferencePoint("0", 4, Vector(0, 100, 0), Vector(0, 0, 0));
516 t->AddReferencePoint("0", 4, Vector(0, 100, 0), Vector(0, -100, 0));
517 t->AddReferencePoint("0", 5, Vector(0, 0, 0), Vector(0, 0, 0));
518 AddTestCase(t, TestCase::Duration::QUICK);
519 t = new Ns2MobilityHelperTest("Bug 1219 testcase", Seconds(16));
520 t->SetTrace("$node_(0) set X_ 0.0\n"
521 "$node_(0) set Y_ 0.0\n"
522 "$ns_ at 1.0 \"$node_(0) setdest 0 10 1\"\n"
523 "$ns_ at 6.0 \"$node_(0) setdest 0 -10 1\"\n");
524 // id t position velocity
525 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
526 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(0, 1, 0));
527 t->AddReferencePoint("0", 6, Vector(0, 5, 0), Vector(0, -1, 0));
528 t->AddReferencePoint("0", 16, Vector(0, -10, 0), Vector(0, 0, 0));
529 AddTestCase(t, TestCase::Duration::QUICK);
530 t = new Ns2MobilityHelperTest("Bug 1059 testcase", Seconds(16));
531 t->SetTrace("$node_(0) set X_ 10.0\r\n"
532 "$node_(0) set Y_ 0.0\r\n");
533 // id t position velocity
534 t->AddReferencePoint("0", 0, Vector(10, 0, 0), Vector(0, 0, 0));
535 AddTestCase(t, TestCase::Duration::QUICK);
536 t = new Ns2MobilityHelperTest("Bug 1301 testcase", Seconds(16));
537 t->SetTrace("$node_(0) set X_ 10.0\n"
538 "$node_(0) set Y_ 0.0\n"
539 "$ns_ at 1.0 \"$node_(0) setdest 10 0 1\"\n");
540 // id t position velocity
541 // Moving to the current position must change nothing. No NaN
542 // speed must be.
543 t->AddReferencePoint("0", 0, Vector(10, 0, 0), Vector(0, 0, 0));
544 AddTestCase(t, TestCase::Duration::QUICK);
545
546 t = new Ns2MobilityHelperTest("Bug 1316 testcase", Seconds(1000));
547 t->SetTrace("$node_(0) set X_ 350.00000000000000\n"
548 "$node_(0) set Y_ 50.00000000000000\n"
549 "$ns_ at 50.00000000000000 \"$node_(0) setdest 400.00000000000000 "
550 "50.00000000000000 1.00000000000000\"\n"
551 "$ns_ at 150.00000000000000 \"$node_(0) setdest 400.00000000000000 "
552 "150.00000000000000 4.00000000000000\"\n"
553 "$ns_ at 300.00000000000000 \"$node_(0) setdest 250.00000000000000 "
554 "150.00000000000000 3.00000000000000\"\n"
555 "$ns_ at 350.00000000000000 \"$node_(0) setdest 250.00000000000000 "
556 "50.00000000000000 1.00000000000000\"\n"
557 "$ns_ at 600.00000000000000 \"$node_(0) setdest 250.00000000000000 "
558 "1050.00000000000000 2.00000000000000\"\n"
559 "$ns_ at 900.00000000000000 \"$node_(0) setdest 300.00000000000000 "
560 "650.00000000000000 2.50000000000000\"\n");
561 t->AddReferencePoint("0",
562 0.000,
563 Vector(350.000, 50.000, 0.000),
564 Vector(0.000, 0.000, 0.000));
565 t->AddReferencePoint("0",
566 50.000,
567 Vector(350.000, 50.000, 0.000),
568 Vector(1.000, 0.000, 0.000));
569 t->AddReferencePoint("0",
570 100.000,
571 Vector(400.000, 50.000, 0.000),
572 Vector(0.000, 0.000, 0.000));
573 t->AddReferencePoint("0",
574 150.000,
575 Vector(400.000, 50.000, 0.000),
576 Vector(0.000, 4.000, 0.000));
577 t->AddReferencePoint("0",
578 175.000,
579 Vector(400.000, 150.000, 0.000),
580 Vector(0.000, 0.000, 0.000));
581 t->AddReferencePoint("0",
582 300.000,
583 Vector(400.000, 150.000, 0.000),
584 Vector(-3.000, 0.000, 0.000));
585 t->AddReferencePoint("0",
586 350.000,
587 Vector(250.000, 150.000, 0.000),
588 Vector(0.000, 0.000, 0.000));
589 t->AddReferencePoint("0",
590 350.000,
591 Vector(250.000, 150.000, 0.000),
592 Vector(0.000, -1.000, 0.000));
593 t->AddReferencePoint("0",
594 450.000,
595 Vector(250.000, 50.000, 0.000),
596 Vector(0.000, 0.000, 0.000));
597 t->AddReferencePoint("0",
598 600.000,
599 Vector(250.000, 50.000, 0.000),
600 Vector(0.000, 2.000, 0.000));
601 t->AddReferencePoint("0",
602 900.000,
603 Vector(250.000, 650.000, 0.000),
604 Vector(2.500, 0.000, 0.000));
605 t->AddReferencePoint("0",
606 920.000,
607 Vector(300.000, 650.000, 0.000),
608 Vector(0.000, 0.000, 0.000));
609 AddTestCase(t, TestCase::Duration::QUICK);
610 }
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 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.
void CreateNodes() const
Create and name nodes.
Keep track of the current position and velocity of an object.
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
Definition names.cc:764
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
Definition names.h:443
static void Clear()
Clear the list of objects associated with names.
Definition names.cc:832
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and,...
Definition names.cc:818
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:46
Helper class which can read ns-2 movement files and configure nodes mobility.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
encapsulates test code
Definition test.h:1050
bool IsStatusFailure() const
Check if any tests failed.
Definition test.cc:458
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition test.cc:432
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition test.cc:472
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
void Connect(std::string path, const CallbackBase &cb)
Definition config.cc:967
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ns2MobilityHelperTestSuite g_ns2TransmobilityHelperTestSuite
the test suite
#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:134
#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:189
#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:780
#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
#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:605
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
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:684
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.