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() && m_reference[m_nextRefPoint].time.IsZero())
214 {
218 nullptr,
219 "Can't find node with id " << rp.node);
220 Ptr<MobilityModel> mob = node->GetObject<MobilityModel>();
222 nullptr,
223 "Can't find mobility for node " << rp.node);
224
225 double tol = 0.001;
226 NS_TEST_EXPECT_MSG_EQ(AreVectorsEqual(mob->GetPosition(), rp.pos, tol),
227 true,
228 "Initial position mismatch for node " << rp.node);
229 NS_TEST_EXPECT_MSG_EQ(AreVectorsEqual(mob->GetVelocity(), rp.vel, tol),
230 true,
231 "Initial velocity mismatch for node " << rp.node);
232
234 }
235 return IsStatusFailure();
236 }
237
238 /**
239 * Listen for course change events
240 * @param context event context
241 * @param mobility a pointer to the mobility model
242 */
243 void CourseChange(std::string context, Ptr<const MobilityModel> mobility)
244 {
245 Time time = Simulator::Now();
246 Ptr<Node> node = mobility->GetObject<Node>();
247 NS_ASSERT(node);
248 std::string id = Names::FindName(node);
249 NS_ASSERT(!id.empty());
250 Vector pos = mobility->GetPosition();
251 Vector vel = mobility->GetVelocity();
252
253 NS_TEST_EXPECT_MSG_LT(m_nextRefPoint, m_reference.size(), "Not enough reference points");
254 if (m_nextRefPoint >= m_reference.size())
255 {
256 return;
257 }
258
260 NS_TEST_EXPECT_MSG_EQ(time, ref.time, "Time mismatch");
262 ref.node,
263 "Node ID mismatch at time " << time.GetSeconds() << " s");
264
265 double tol = 0.001;
267 true,
268 "Position mismatch at time " << time.GetSeconds() << " s for node "
269 << id);
271 true,
272 "Velocity mismatch at time " << time.GetSeconds() << " s for node "
273 << id);
274 }
275
276 void DoSetup() override
277 {
278 CreateNodes();
279 }
280
281 void DoTeardown() override
282 {
283 Names::Clear();
285 }
286
287 /// Go
288 void DoRun() override
289 {
290 NS_TEST_ASSERT_MSG_EQ(m_trace.empty(), false, "Need trace");
291 NS_TEST_ASSERT_MSG_EQ(m_reference.empty(), false, "Need reference");
292
293 if (WriteTrace())
294 {
295 return;
296 }
298 mobility.Install();
300 {
301 return;
302 }
303 Config::Connect("/NodeList/*/$ns3::MobilityModel/CourseChange",
307 }
308};
309
310/**
311 * @ingroup mobility-test
312 *
313 * @brief The test suite
314 */
316{
317 public:
319 : TestSuite("mobility-ns2-trace-helper", Type::UNIT)
320 {
321 SetDataDir(NS_TEST_SOURCEDIR);
322
323 // to be used as temporary variable for test cases.
324 // Note that test suite takes care of deleting all test cases.
325 Ns2MobilityHelperTest* t(nullptr);
326
327 // Initial position
328 t = new Ns2MobilityHelperTest("initial position", Seconds(1));
329 t->SetTrace("$node_(0) set X_ 1.0\n"
330 "$node_(0) set Y_ 2.0\n"
331 "$node_(0) set Z_ 3.0\n");
332 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
333 AddTestCase(t, TestCase::Duration::QUICK);
334
335 // Check parsing comments, empty lines and no EOF at the end of file
336 t = new Ns2MobilityHelperTest("comments", Seconds(1));
337 t->SetTrace("# comment\n"
338 "\n\n" // empty lines
339 "$node_(0) set X_ 1.0 # comment \n"
340 "$node_(0) set Y_ 2.0 ### \n"
341 "$node_(0) set Z_ 3.0 # $node_(0) set Z_ 3.0\n"
342 "#$node_(0) set Z_ 100 #");
343 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
344 AddTestCase(t, TestCase::Duration::QUICK);
345
346 // Simple setdest. Arguments are interpreted as x, y, speed by default
347 t = new Ns2MobilityHelperTest("simple setdest", Seconds(10));
348 t->SetTrace("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"");
349 // id t position velocity
350 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
351 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(5, 0, 0));
352 t->AddReferencePoint("0", 6, Vector(25, 0, 0), Vector(0, 0, 0));
353 AddTestCase(t, TestCase::Duration::QUICK);
354
355 // Several set and setdest. Arguments are interpreted as x, y, speed by default
356 t = new Ns2MobilityHelperTest("square setdest", Seconds(6));
357 t->SetTrace("$node_(0) set X_ 0.0\n"
358 "$node_(0) set Y_ 0.0\n"
359 "$ns_ at 1.0 \"$node_(0) setdest 5 0 5\"\n"
360 "$ns_ at 2.0 \"$node_(0) setdest 5 5 5\"\n"
361 "$ns_ at 3.0 \"$node_(0) setdest 0 5 5\"\n"
362 "$ns_ at 4.0 \"$node_(0) setdest 0 0 5\"\n");
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", 2, Vector(5, 0, 0), Vector(0, 0, 0));
367 t->AddReferencePoint("0", 2, Vector(5, 0, 0), Vector(0, 5, 0));
368 t->AddReferencePoint("0", 3, Vector(5, 5, 0), Vector(0, 0, 0));
369 t->AddReferencePoint("0", 3, Vector(5, 5, 0), Vector(-5, 0, 0));
370 t->AddReferencePoint("0", 4, Vector(0, 5, 0), Vector(0, 0, 0));
371 t->AddReferencePoint("0", 4, Vector(0, 5, 0), Vector(0, -5, 0));
372 t->AddReferencePoint("0", 5, Vector(0, 0, 0), Vector(0, 0, 0));
373 AddTestCase(t, TestCase::Duration::QUICK);
374
375 // Copy of previous test case but with the initial positions at
376 // the end of the trace rather than at the beginning.
377 //
378 // Several set and setdest. Arguments are interpreted as x, y, speed by default
379 t = new Ns2MobilityHelperTest("square setdest (initial positions at end)", Seconds(6));
380 t->SetTrace("$ns_ at 1.0 \"$node_(0) setdest 15 10 5\"\n"
381 "$ns_ at 2.0 \"$node_(0) setdest 15 15 5\"\n"
382 "$ns_ at 3.0 \"$node_(0) setdest 10 15 5\"\n"
383 "$ns_ at 4.0 \"$node_(0) setdest 10 10 5\"\n"
384 "$node_(0) set X_ 10.0\n"
385 "$node_(0) set Y_ 10.0\n");
386 // id t position velocity
387 t->AddReferencePoint("0", 0, Vector(10, 10, 0), Vector(0, 0, 0));
388 t->AddReferencePoint("0", 1, Vector(10, 10, 0), Vector(5, 0, 0));
389 t->AddReferencePoint("0", 2, Vector(15, 10, 0), Vector(0, 0, 0));
390 t->AddReferencePoint("0", 2, Vector(15, 10, 0), Vector(0, 5, 0));
391 t->AddReferencePoint("0", 3, Vector(15, 15, 0), Vector(0, 0, 0));
392 t->AddReferencePoint("0", 3, Vector(15, 15, 0), Vector(-5, 0, 0));
393 t->AddReferencePoint("0", 4, Vector(10, 15, 0), Vector(0, 0, 0));
394 t->AddReferencePoint("0", 4, Vector(10, 15, 0), Vector(0, -5, 0));
395 t->AddReferencePoint("0", 5, Vector(10, 10, 0), Vector(0, 0, 0));
396 AddTestCase(t, TestCase::Duration::QUICK);
397
398 // Scheduled set position
399 t = new Ns2MobilityHelperTest("scheduled set position", Seconds(2));
400 t->SetTrace("$ns_ at 1.0 \"$node_(0) set X_ 10\"\n"
401 "$ns_ at 1.0 \"$node_(0) set Z_ 10\"\n"
402 "$ns_ at 1.0 \"$node_(0) set Y_ 10\"");
403 // id t position velocity
404 t->AddReferencePoint("0", 1, Vector(10, 0, 0), Vector(0, 0, 0));
405 t->AddReferencePoint("0", 1, Vector(10, 0, 10), Vector(0, 0, 0));
406 t->AddReferencePoint("0", 1, Vector(10, 10, 10), Vector(0, 0, 0));
407 AddTestCase(t, TestCase::Duration::QUICK);
408
409 // Malformed lines
410 t = new Ns2MobilityHelperTest("malformed lines", Seconds(2));
411 t->SetTrace("$node() set X_ 1 # node id is not present\n"
412 "$node # incoplete line\"\n"
413 "$node this line is not correct\n"
414 "$node_(0) set X_ 1 # line OK \n"
415 "$node_(0) set Y_ 2 # line OK \n"
416 "$node_(0) set Z_ 3 # line OK \n"
417 "$ns_ at \"$node_(0) setdest 4 4 4\" # time not present\n"
418 "$ns_ at 1 \"$node_(0) setdest 2 2 1 \" # line OK \n");
419 // id t position velocity
420 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
421 t->AddReferencePoint("0", 1, Vector(1, 2, 3), Vector(1, 0, 0));
422 t->AddReferencePoint("0", 2, Vector(2, 2, 3), Vector(0, 0, 0));
423 AddTestCase(t, TestCase::Duration::QUICK);
424
425 // Non possible values
426 t = new Ns2MobilityHelperTest("non possible values", Seconds(2));
427 t->SetTrace(
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 "$node_(-22) set Y_ 3 # node id not correct\n"
432 "$node_(3.3) set Y_ 1111 # node id not correct\n"
433 "$ns_ at sss \"$node_(0) setdest 5 5 5\" # time is not a number\n"
434 "$ns_ at 1 \"$node_(0) setdest 2 2 1\" # line OK \n"
435 "$ns_ at 1 \"$node_(0) setdest 2 2 -1\" # negative speed is not correct\n"
436 "$ns_ at 1 \"$node_(0) setdest 2 2 sdfs\" # speed is not a number\n"
437 "$ns_ at 1 \"$node_(0) setdest 2 2 s232dfs\" # speed is not a number\n"
438 "$ns_ at 1 \"$node_(0) setdest 233 2.. s232dfs\" # more than one non numbers\n"
439 "$ns_ at -12 \"$node_(0) setdest 11 22 33\" # time should not be negative\n");
440 // id t position velocity
441 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
442 t->AddReferencePoint("0", 1, Vector(1, 2, 3), Vector(1, 0, 0));
443 t->AddReferencePoint("0", 2, Vector(2, 2, 3), Vector(0, 0, 0));
444 AddTestCase(t, TestCase::Duration::QUICK);
445
446 // More than one node
447 t = new Ns2MobilityHelperTest("few nodes, combinations of set and setdest", Seconds(10), 3);
448 t->SetTrace("$node_(0) set X_ 1.0\n"
449 "$node_(0) set Y_ 2.0\n"
450 "$node_(0) set Z_ 3.0\n"
451 "$ns_ at 1.0 \"$node_(1) setdest 25 0 5\"\n"
452 "$node_(2) set X_ 0.0\n"
453 "$node_(2) set Y_ 0.0\n"
454 "$ns_ at 1.0 \"$node_(2) setdest 5 0 5\"\n"
455 "$ns_ at 2.0 \"$node_(2) setdest 5 5 5\"\n"
456 "$ns_ at 3.0 \"$node_(2) setdest 0 5 5\"\n"
457 "$ns_ at 4.0 \"$node_(2) setdest 0 0 5\"\n");
458 // id t position velocity
459 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
460 t->AddReferencePoint("1", 0, Vector(0, 0, 0), Vector(0, 0, 0));
461 t->AddReferencePoint("1", 1, Vector(0, 0, 0), Vector(5, 0, 0));
462 t->AddReferencePoint("1", 6, Vector(25, 0, 0), Vector(0, 0, 0));
463 t->AddReferencePoint("2", 0, Vector(0, 0, 0), Vector(0, 0, 0));
464 t->AddReferencePoint("2", 1, Vector(0, 0, 0), Vector(5, 0, 0));
465 t->AddReferencePoint("2", 2, Vector(5, 0, 0), Vector(0, 0, 0));
466 t->AddReferencePoint("2", 2, Vector(5, 0, 0), Vector(0, 5, 0));
467 t->AddReferencePoint("2", 3, Vector(5, 5, 0), Vector(0, 0, 0));
468 t->AddReferencePoint("2", 3, Vector(5, 5, 0), Vector(-5, 0, 0));
469 t->AddReferencePoint("2", 4, Vector(0, 5, 0), Vector(0, 0, 0));
470 t->AddReferencePoint("2", 4, Vector(0, 5, 0), Vector(0, -5, 0));
471 t->AddReferencePoint("2", 5, Vector(0, 0, 0), Vector(0, 0, 0));
472 AddTestCase(t, TestCase::Duration::QUICK);
473
474 // Test for Speed == 0, that acts as stop the node.
475 t = new Ns2MobilityHelperTest("setdest with speed cero", Seconds(10));
476 t->SetTrace("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"\n"
477 "$ns_ at 7.0 \"$node_(0) setdest 11 22 0\"\n");
478 // id t position velocity
479 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
480 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(5, 0, 0));
481 t->AddReferencePoint("0", 6, Vector(25, 0, 0), Vector(0, 0, 0));
482 t->AddReferencePoint("0", 7, Vector(25, 0, 0), Vector(0, 0, 0));
483 AddTestCase(t, TestCase::Duration::QUICK);
484
485 // Test negative positions
486 t = new Ns2MobilityHelperTest("test negative positions", Seconds(10));
487 t->SetTrace("$node_(0) set X_ -1.0\n"
488 "$node_(0) set Y_ 0\n"
489 "$ns_ at 1.0 \"$node_(0) setdest 0 0 1\"\n"
490 "$ns_ at 2.0 \"$node_(0) setdest 0 -1 1\"\n");
491 // id t position velocity
492 t->AddReferencePoint("0", 0, Vector(-1, 0, 0), Vector(0, 0, 0));
493 t->AddReferencePoint("0", 1, Vector(-1, 0, 0), Vector(1, 0, 0));
494 t->AddReferencePoint("0", 2, Vector(0, 0, 0), Vector(0, 0, 0));
495 t->AddReferencePoint("0", 2, Vector(0, 0, 0), Vector(0, -1, 0));
496 t->AddReferencePoint("0", 3, Vector(0, -1, 0), Vector(0, 0, 0));
497 AddTestCase(t, TestCase::Duration::QUICK);
498
499 // Square setdest with values in the form 1.0e+2
500 t = new Ns2MobilityHelperTest("Foalt numbers in 1.0e+2 format", Seconds(6));
501 t->SetTrace("$node_(0) set X_ 0.0\n"
502 "$node_(0) set Y_ 0.0\n"
503 "$ns_ at 1.0 \"$node_(0) setdest 1.0e+2 0 1.0e+2\"\n"
504 "$ns_ at 2.0 \"$node_(0) setdest 1.0e+2 1.0e+2 1.0e+2\"\n"
505 "$ns_ at 3.0 \"$node_(0) setdest 0 1.0e+2 1.0e+2\"\n"
506 "$ns_ at 4.0 \"$node_(0) setdest 0 0 1.0e+2\"\n");
507 // id t position velocity
508 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
509 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(100, 0, 0));
510 t->AddReferencePoint("0", 2, Vector(100, 0, 0), Vector(0, 0, 0));
511 t->AddReferencePoint("0", 2, Vector(100, 0, 0), Vector(0, 100, 0));
512 t->AddReferencePoint("0", 3, Vector(100, 100, 0), Vector(0, 0, 0));
513 t->AddReferencePoint("0", 3, Vector(100, 100, 0), Vector(-100, 0, 0));
514 t->AddReferencePoint("0", 4, Vector(0, 100, 0), Vector(0, 0, 0));
515 t->AddReferencePoint("0", 4, Vector(0, 100, 0), Vector(0, -100, 0));
516 t->AddReferencePoint("0", 5, Vector(0, 0, 0), Vector(0, 0, 0));
517 AddTestCase(t, TestCase::Duration::QUICK);
518 t = new Ns2MobilityHelperTest("Bug 1219 testcase", Seconds(16));
519 t->SetTrace("$node_(0) set X_ 0.0\n"
520 "$node_(0) set Y_ 0.0\n"
521 "$ns_ at 1.0 \"$node_(0) setdest 0 10 1\"\n"
522 "$ns_ at 6.0 \"$node_(0) setdest 0 -10 1\"\n");
523 // id t position velocity
524 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
525 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(0, 1, 0));
526 t->AddReferencePoint("0", 6, Vector(0, 5, 0), Vector(0, -1, 0));
527 t->AddReferencePoint("0", 16, Vector(0, -10, 0), Vector(0, 0, 0));
528 AddTestCase(t, TestCase::Duration::QUICK);
529 t = new Ns2MobilityHelperTest("Bug 1059 testcase", Seconds(16));
530 t->SetTrace("$node_(0) set X_ 10.0\r\n"
531 "$node_(0) set Y_ 0.0\r\n");
532 // id t position velocity
533 t->AddReferencePoint("0", 0, Vector(10, 0, 0), Vector(0, 0, 0));
534 AddTestCase(t, TestCase::Duration::QUICK);
535 t = new Ns2MobilityHelperTest("Bug 1301 testcase", Seconds(16));
536 t->SetTrace("$node_(0) set X_ 10.0\n"
537 "$node_(0) set Y_ 0.0\n"
538 "$ns_ at 1.0 \"$node_(0) setdest 10 0 1\"\n");
539 // id t position velocity
540 // Moving to the current position must change nothing. No NaN
541 // speed must be.
542 t->AddReferencePoint("0", 0, Vector(10, 0, 0), Vector(0, 0, 0));
543 AddTestCase(t, TestCase::Duration::QUICK);
544
545 t = new Ns2MobilityHelperTest("Bug 1316 testcase", Seconds(1000));
546 t->SetTrace("$node_(0) set X_ 350.00000000000000\n"
547 "$node_(0) set Y_ 50.00000000000000\n"
548 "$ns_ at 50.00000000000000 \"$node_(0) setdest 400.00000000000000 "
549 "50.00000000000000 1.00000000000000\"\n"
550 "$ns_ at 150.00000000000000 \"$node_(0) setdest 400.00000000000000 "
551 "150.00000000000000 4.00000000000000\"\n"
552 "$ns_ at 300.00000000000000 \"$node_(0) setdest 250.00000000000000 "
553 "150.00000000000000 3.00000000000000\"\n"
554 "$ns_ at 350.00000000000000 \"$node_(0) setdest 250.00000000000000 "
555 "50.00000000000000 1.00000000000000\"\n"
556 "$ns_ at 600.00000000000000 \"$node_(0) setdest 250.00000000000000 "
557 "1050.00000000000000 2.00000000000000\"\n"
558 "$ns_ at 900.00000000000000 \"$node_(0) setdest 300.00000000000000 "
559 "650.00000000000000 2.50000000000000\"\n");
560 t->AddReferencePoint("0",
561 0.000,
562 Vector(350.000, 50.000, 0.000),
563 Vector(0.000, 0.000, 0.000));
564 t->AddReferencePoint("0",
565 50.000,
566 Vector(350.000, 50.000, 0.000),
567 Vector(1.000, 0.000, 0.000));
568 t->AddReferencePoint("0",
569 100.000,
570 Vector(400.000, 50.000, 0.000),
571 Vector(0.000, 0.000, 0.000));
572 t->AddReferencePoint("0",
573 150.000,
574 Vector(400.000, 50.000, 0.000),
575 Vector(0.000, 4.000, 0.000));
576 t->AddReferencePoint("0",
577 175.000,
578 Vector(400.000, 150.000, 0.000),
579 Vector(0.000, 0.000, 0.000));
580 t->AddReferencePoint("0",
581 300.000,
582 Vector(400.000, 150.000, 0.000),
583 Vector(-3.000, 0.000, 0.000));
584 t->AddReferencePoint("0",
585 350.000,
586 Vector(250.000, 150.000, 0.000),
587 Vector(0.000, 0.000, 0.000));
588 t->AddReferencePoint("0",
589 350.000,
590 Vector(250.000, 150.000, 0.000),
591 Vector(0.000, -1.000, 0.000));
592 t->AddReferencePoint("0",
593 450.000,
594 Vector(250.000, 50.000, 0.000),
595 Vector(0.000, 0.000, 0.000));
596 t->AddReferencePoint("0",
597 600.000,
598 Vector(250.000, 50.000, 0.000),
599 Vector(0.000, 2.000, 0.000));
600 t->AddReferencePoint("0",
601 900.000,
602 Vector(250.000, 650.000, 0.000),
603 Vector(2.500, 0.000, 0.000));
604 t->AddReferencePoint("0",
605 920.000,
606 Vector(300.000, 650.000, 0.000),
607 Vector(0.000, 0.000, 0.000));
608 AddTestCase(t, TestCase::Duration::QUICK);
609 }
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:1344
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.