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 * 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
77/**
78 * \ingroup mobility-test
79 *
80 * \brief Every test case is supposed to:
81 * 1. Generate short mobility trace file
82 * 2. Read it back using Ns2MobilityHelper
83 * 3. Check initial node positions and speeds.
84 * 4. Run simulation listening for all CourseChange events and compare actual mobility with the
85 * reference
86 */
88{
89 public:
90 /// Single record in mobility reference
92 {
93 std::string node; ///< node ID as string, e.g. "1"
94 Time time; ///< timestamp
95 Vector pos; ///< reference position
96 Vector vel; ///< reference velocity
97
98 /**
99 * Constructor
100 *
101 * \param id reference ID
102 * \param t time
103 * \param p position
104 * \param v velocity
105 */
106 ReferencePoint(const std::string& id, Time t, const Vector& p, const Vector& v)
107 : node(id),
108 time(t),
109 pos(p),
110 vel(v)
111 {
112 }
113
114 /**
115 * Less-than operator - used to sort by timestamp
116 * \param o object to compare to
117 * \returns true if the timestamp of the 1st operand is less than the other one's
118 */
119 bool operator<(const ReferencePoint& o) const
120 {
121 return time < o.time;
122 }
123 };
124
125 /**
126 * Create new test case. To make it useful SetTrace () and AddReferencePoint () must be called
127 *
128 * \param name Short description
129 * \param timeLimit Test time limit
130 * \param nodes Number of nodes used in the test trace, 1 by default
131 */
132 Ns2MobilityHelperTest(const std::string& name, Time timeLimit, uint32_t nodes = 1)
133 : TestCase(name),
134 m_timeLimit(timeLimit),
137 {
138 }
139
140 /// Empty
142 {
143 }
144
145 /**
146 * Set NS-2 trace to read as single large string (don't forget to add \\n and quote \"'s)
147 * \param trace the mobility trace
148 */
149 void SetTrace(const std::string& trace)
150 {
151 m_trace = trace;
152 }
153
154 /**
155 * Add next reference point
156 * \param r reference point to add
157 */
159 {
160 m_reference.push_back(r);
161 }
162
163 /**
164 * Add next reference point
165 * \param id reference point id
166 * \param sec reference point ime (in seconds)
167 * \param p reference point position
168 * \param v reference point velocity
169 */
170 void AddReferencePoint(const char* id, double sec, const Vector& p, const Vector& v)
171 {
173 }
174
175 private:
176 /// Test time limit
178 /// Number of nodes used in the test
180 /// Trace as string
181 std::string m_trace;
182 /// Reference mobility
183 std::vector<ReferencePoint> m_reference;
184 /// Next reference point to be checked
186 /// TMP trace file name
187 std::string m_traceFile;
188
189 private:
190 /**
191 * Dump NS-2 trace to tmp file
192 * \return true on error.
193 */
195 {
196 m_traceFile = CreateTempDirFilename("Ns2MobilityHelperTest.tcl");
197 std::ofstream of(m_traceFile);
198 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(of.is_open(), true, "Need to write tmp. file");
199 of << m_trace;
200 of.close();
201 return false; // no errors
202 }
203
204 /// Create and name nodes
205 void CreateNodes() const
206 {
209 for (uint32_t i = 0; i < m_nodeCount; ++i)
210 {
211 std::ostringstream os;
212 os << i;
213 Names::Add(os.str(), nodes.Get(i));
214 }
215 }
216
217 /**
218 * Check that all initial positions are correct
219 * \return true on error.
220 */
222 {
223 std::stable_sort(m_reference.begin(), m_reference.end());
224 while (m_nextRefPoint < m_reference.size() &&
226 {
228 Ptr<Node> node = Names::Find<Node>(rp.node);
230 nullptr,
231 "Can't find node with id " << rp.node);
232 Ptr<MobilityModel> mob = node->GetObject<MobilityModel>();
234 nullptr,
235 "Can't find mobility for node " << rp.node);
236
237 double tol = 0.001;
238 NS_TEST_EXPECT_MSG_EQ(AreVectorsEqual(mob->GetPosition(), rp.pos, tol),
239 true,
240 "Initial position mismatch for node " << rp.node);
241 NS_TEST_EXPECT_MSG_EQ(AreVectorsEqual(mob->GetVelocity(), rp.vel, tol),
242 true,
243 "Initial velocity mismatch for node " << rp.node);
244
246 }
247 return IsStatusFailure();
248 }
249
250 /**
251 * Listen for course change events
252 * \param context event context
253 * \param mobility a pointer to the mobility model
254 */
255 void CourseChange(std::string context, Ptr<const MobilityModel> mobility)
256 {
257 Time time = Simulator::Now();
258 Ptr<Node> node = mobility->GetObject<Node>();
259 NS_ASSERT(node);
260 std::string id = Names::FindName(node);
261 NS_ASSERT(!id.empty());
262 Vector pos = mobility->GetPosition();
263 Vector vel = mobility->GetVelocity();
264
265 NS_TEST_EXPECT_MSG_LT(m_nextRefPoint, m_reference.size(), "Not enough reference points");
266 if (m_nextRefPoint >= m_reference.size())
267 {
268 return;
269 }
270
272 NS_TEST_EXPECT_MSG_EQ(time, ref.time, "Time mismatch");
274 ref.node,
275 "Node ID mismatch at time " << time.GetSeconds() << " s");
276
277 double tol = 0.001;
279 true,
280 "Position mismatch at time " << time.GetSeconds() << " s for node "
281 << id);
283 true,
284 "Velocity mismatch at time " << time.GetSeconds() << " s for node "
285 << id);
286 }
287
288 void DoSetup() override
289 {
290 CreateNodes();
291 }
292
293 void DoTeardown() override
294 {
295 Names::Clear();
297 }
298
299 /// Go
300 void DoRun() override
301 {
302 NS_TEST_ASSERT_MSG_EQ(m_trace.empty(), false, "Need trace");
303 NS_TEST_ASSERT_MSG_EQ(m_reference.empty(), false, "Need reference");
304
305 if (WriteTrace())
306 {
307 return;
308 }
310 mobility.Install();
312 {
313 return;
314 }
315 Config::Connect("/NodeList/*/$ns3::MobilityModel/CourseChange",
319 }
320};
321
322/**
323 * \ingroup mobility-test
324 *
325 * \brief The test suite
326 */
328{
329 public:
331 : TestSuite("mobility-ns2-trace-helper", Type::UNIT)
332 {
333 SetDataDir(NS_TEST_SOURCEDIR);
334
335 // to be used as temporary variable for test cases.
336 // Note that test suite takes care of deleting all test cases.
337 Ns2MobilityHelperTest* t(nullptr);
338
339 // Initial position
340 t = new Ns2MobilityHelperTest("initial position", Seconds(1));
341 t->SetTrace("$node_(0) set X_ 1.0\n"
342 "$node_(0) set Y_ 2.0\n"
343 "$node_(0) set Z_ 3.0\n");
344 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
345 AddTestCase(t, TestCase::Duration::QUICK);
346
347 // Check parsing comments, empty lines and no EOF at the end of file
348 t = new Ns2MobilityHelperTest("comments", Seconds(1));
349 t->SetTrace("# comment\n"
350 "\n\n" // empty lines
351 "$node_(0) set X_ 1.0 # comment \n"
352 "$node_(0) set Y_ 2.0 ### \n"
353 "$node_(0) set Z_ 3.0 # $node_(0) set Z_ 3.0\n"
354 "#$node_(0) set Z_ 100 #");
355 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
356 AddTestCase(t, TestCase::Duration::QUICK);
357
358 // Simple setdest. Arguments are interpreted as x, y, speed by default
359 t = new Ns2MobilityHelperTest("simple setdest", Seconds(10));
360 t->SetTrace("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"");
361 // id t position velocity
362 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
363 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(5, 0, 0));
364 t->AddReferencePoint("0", 6, Vector(25, 0, 0), Vector(0, 0, 0));
365 AddTestCase(t, TestCase::Duration::QUICK);
366
367 // Several set and setdest. Arguments are interpreted as x, y, speed by default
368 t = new Ns2MobilityHelperTest("square setdest", Seconds(6));
369 t->SetTrace("$node_(0) set X_ 0.0\n"
370 "$node_(0) set Y_ 0.0\n"
371 "$ns_ at 1.0 \"$node_(0) setdest 5 0 5\"\n"
372 "$ns_ at 2.0 \"$node_(0) setdest 5 5 5\"\n"
373 "$ns_ at 3.0 \"$node_(0) setdest 0 5 5\"\n"
374 "$ns_ at 4.0 \"$node_(0) setdest 0 0 5\"\n");
375 // id t position velocity
376 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
377 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(5, 0, 0));
378 t->AddReferencePoint("0", 2, Vector(5, 0, 0), Vector(0, 0, 0));
379 t->AddReferencePoint("0", 2, Vector(5, 0, 0), Vector(0, 5, 0));
380 t->AddReferencePoint("0", 3, Vector(5, 5, 0), Vector(0, 0, 0));
381 t->AddReferencePoint("0", 3, Vector(5, 5, 0), Vector(-5, 0, 0));
382 t->AddReferencePoint("0", 4, Vector(0, 5, 0), Vector(0, 0, 0));
383 t->AddReferencePoint("0", 4, Vector(0, 5, 0), Vector(0, -5, 0));
384 t->AddReferencePoint("0", 5, Vector(0, 0, 0), Vector(0, 0, 0));
385 AddTestCase(t, TestCase::Duration::QUICK);
386
387 // Copy of previous test case but with the initial positions at
388 // the end of the trace rather than at the beginning.
389 //
390 // Several set and setdest. Arguments are interpreted as x, y, speed by default
391 t = new Ns2MobilityHelperTest("square setdest (initial positions at end)", Seconds(6));
392 t->SetTrace("$ns_ at 1.0 \"$node_(0) setdest 15 10 5\"\n"
393 "$ns_ at 2.0 \"$node_(0) setdest 15 15 5\"\n"
394 "$ns_ at 3.0 \"$node_(0) setdest 10 15 5\"\n"
395 "$ns_ at 4.0 \"$node_(0) setdest 10 10 5\"\n"
396 "$node_(0) set X_ 10.0\n"
397 "$node_(0) set Y_ 10.0\n");
398 // id t position velocity
399 t->AddReferencePoint("0", 0, Vector(10, 10, 0), Vector(0, 0, 0));
400 t->AddReferencePoint("0", 1, Vector(10, 10, 0), Vector(5, 0, 0));
401 t->AddReferencePoint("0", 2, Vector(15, 10, 0), Vector(0, 0, 0));
402 t->AddReferencePoint("0", 2, Vector(15, 10, 0), Vector(0, 5, 0));
403 t->AddReferencePoint("0", 3, Vector(15, 15, 0), Vector(0, 0, 0));
404 t->AddReferencePoint("0", 3, Vector(15, 15, 0), Vector(-5, 0, 0));
405 t->AddReferencePoint("0", 4, Vector(10, 15, 0), Vector(0, 0, 0));
406 t->AddReferencePoint("0", 4, Vector(10, 15, 0), Vector(0, -5, 0));
407 t->AddReferencePoint("0", 5, Vector(10, 10, 0), Vector(0, 0, 0));
408 AddTestCase(t, TestCase::Duration::QUICK);
409
410 // Scheduled set position
411 t = new Ns2MobilityHelperTest("scheduled set position", Seconds(2));
412 t->SetTrace("$ns_ at 1.0 \"$node_(0) set X_ 10\"\n"
413 "$ns_ at 1.0 \"$node_(0) set Z_ 10\"\n"
414 "$ns_ at 1.0 \"$node_(0) set Y_ 10\"");
415 // id t position velocity
416 t->AddReferencePoint("0", 1, Vector(10, 0, 0), Vector(0, 0, 0));
417 t->AddReferencePoint("0", 1, Vector(10, 0, 10), Vector(0, 0, 0));
418 t->AddReferencePoint("0", 1, Vector(10, 10, 10), Vector(0, 0, 0));
419 AddTestCase(t, TestCase::Duration::QUICK);
420
421 // Malformed lines
422 t = new Ns2MobilityHelperTest("malformed lines", Seconds(2));
423 t->SetTrace("$node() set X_ 1 # node id is not present\n"
424 "$node # incoplete line\"\n"
425 "$node this line is not correct\n"
426 "$node_(0) set X_ 1 # line OK \n"
427 "$node_(0) set Y_ 2 # line OK \n"
428 "$node_(0) set Z_ 3 # line OK \n"
429 "$ns_ at \"$node_(0) setdest 4 4 4\" # time not present\n"
430 "$ns_ at 1 \"$node_(0) setdest 2 2 1 \" # line OK \n");
431 // id t position velocity
432 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
433 t->AddReferencePoint("0", 1, Vector(1, 2, 3), Vector(1, 0, 0));
434 t->AddReferencePoint("0", 2, Vector(2, 2, 3), Vector(0, 0, 0));
435 AddTestCase(t, TestCase::Duration::QUICK);
436
437 // Non possible values
438 t = new Ns2MobilityHelperTest("non possible values", Seconds(2));
439 t->SetTrace(
440 "$node_(0) set X_ 1 # line OK \n"
441 "$node_(0) set Y_ 2 # line OK \n"
442 "$node_(0) set Z_ 3 # line OK \n"
443 "$node_(-22) set Y_ 3 # node id not correct\n"
444 "$node_(3.3) set Y_ 1111 # node id not correct\n"
445 "$ns_ at sss \"$node_(0) setdest 5 5 5\" # time is not a number\n"
446 "$ns_ at 1 \"$node_(0) setdest 2 2 1\" # line OK \n"
447 "$ns_ at 1 \"$node_(0) setdest 2 2 -1\" # negative speed is not correct\n"
448 "$ns_ at 1 \"$node_(0) setdest 2 2 sdfs\" # speed is not a number\n"
449 "$ns_ at 1 \"$node_(0) setdest 2 2 s232dfs\" # speed is not a number\n"
450 "$ns_ at 1 \"$node_(0) setdest 233 2.. s232dfs\" # more than one non numbers\n"
451 "$ns_ at -12 \"$node_(0) setdest 11 22 33\" # time should not be negative\n");
452 // id t position velocity
453 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
454 t->AddReferencePoint("0", 1, Vector(1, 2, 3), Vector(1, 0, 0));
455 t->AddReferencePoint("0", 2, Vector(2, 2, 3), Vector(0, 0, 0));
456 AddTestCase(t, TestCase::Duration::QUICK);
457
458 // More than one node
459 t = new Ns2MobilityHelperTest("few nodes, combinations of set and setdest", Seconds(10), 3);
460 t->SetTrace("$node_(0) set X_ 1.0\n"
461 "$node_(0) set Y_ 2.0\n"
462 "$node_(0) set Z_ 3.0\n"
463 "$ns_ at 1.0 \"$node_(1) setdest 25 0 5\"\n"
464 "$node_(2) set X_ 0.0\n"
465 "$node_(2) set Y_ 0.0\n"
466 "$ns_ at 1.0 \"$node_(2) setdest 5 0 5\"\n"
467 "$ns_ at 2.0 \"$node_(2) setdest 5 5 5\"\n"
468 "$ns_ at 3.0 \"$node_(2) setdest 0 5 5\"\n"
469 "$ns_ at 4.0 \"$node_(2) setdest 0 0 5\"\n");
470 // id t position velocity
471 t->AddReferencePoint("0", 0, Vector(1, 2, 3), Vector(0, 0, 0));
472 t->AddReferencePoint("1", 0, Vector(0, 0, 0), Vector(0, 0, 0));
473 t->AddReferencePoint("1", 1, Vector(0, 0, 0), Vector(5, 0, 0));
474 t->AddReferencePoint("1", 6, Vector(25, 0, 0), Vector(0, 0, 0));
475 t->AddReferencePoint("2", 0, Vector(0, 0, 0), Vector(0, 0, 0));
476 t->AddReferencePoint("2", 1, Vector(0, 0, 0), Vector(5, 0, 0));
477 t->AddReferencePoint("2", 2, Vector(5, 0, 0), Vector(0, 0, 0));
478 t->AddReferencePoint("2", 2, Vector(5, 0, 0), Vector(0, 5, 0));
479 t->AddReferencePoint("2", 3, Vector(5, 5, 0), Vector(0, 0, 0));
480 t->AddReferencePoint("2", 3, Vector(5, 5, 0), Vector(-5, 0, 0));
481 t->AddReferencePoint("2", 4, Vector(0, 5, 0), Vector(0, 0, 0));
482 t->AddReferencePoint("2", 4, Vector(0, 5, 0), Vector(0, -5, 0));
483 t->AddReferencePoint("2", 5, Vector(0, 0, 0), Vector(0, 0, 0));
484 AddTestCase(t, TestCase::Duration::QUICK);
485
486 // Test for Speed == 0, that acts as stop the node.
487 t = new Ns2MobilityHelperTest("setdest with speed cero", Seconds(10));
488 t->SetTrace("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"\n"
489 "$ns_ at 7.0 \"$node_(0) setdest 11 22 0\"\n");
490 // id t position velocity
491 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
492 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(5, 0, 0));
493 t->AddReferencePoint("0", 6, Vector(25, 0, 0), Vector(0, 0, 0));
494 t->AddReferencePoint("0", 7, Vector(25, 0, 0), Vector(0, 0, 0));
495 AddTestCase(t, TestCase::Duration::QUICK);
496
497 // Test negative positions
498 t = new Ns2MobilityHelperTest("test negative positions", Seconds(10));
499 t->SetTrace("$node_(0) set X_ -1.0\n"
500 "$node_(0) set Y_ 0\n"
501 "$ns_ at 1.0 \"$node_(0) setdest 0 0 1\"\n"
502 "$ns_ at 2.0 \"$node_(0) setdest 0 -1 1\"\n");
503 // id t position velocity
504 t->AddReferencePoint("0", 0, Vector(-1, 0, 0), Vector(0, 0, 0));
505 t->AddReferencePoint("0", 1, Vector(-1, 0, 0), Vector(1, 0, 0));
506 t->AddReferencePoint("0", 2, Vector(0, 0, 0), Vector(0, 0, 0));
507 t->AddReferencePoint("0", 2, Vector(0, 0, 0), Vector(0, -1, 0));
508 t->AddReferencePoint("0", 3, Vector(0, -1, 0), Vector(0, 0, 0));
509 AddTestCase(t, TestCase::Duration::QUICK);
510
511 // Square setdest with values in the form 1.0e+2
512 t = new Ns2MobilityHelperTest("Foalt numbers in 1.0e+2 format", Seconds(6));
513 t->SetTrace("$node_(0) set X_ 0.0\n"
514 "$node_(0) set Y_ 0.0\n"
515 "$ns_ at 1.0 \"$node_(0) setdest 1.0e+2 0 1.0e+2\"\n"
516 "$ns_ at 2.0 \"$node_(0) setdest 1.0e+2 1.0e+2 1.0e+2\"\n"
517 "$ns_ at 3.0 \"$node_(0) setdest 0 1.0e+2 1.0e+2\"\n"
518 "$ns_ at 4.0 \"$node_(0) setdest 0 0 1.0e+2\"\n");
519 // id t position velocity
520 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
521 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(100, 0, 0));
522 t->AddReferencePoint("0", 2, Vector(100, 0, 0), Vector(0, 0, 0));
523 t->AddReferencePoint("0", 2, Vector(100, 0, 0), Vector(0, 100, 0));
524 t->AddReferencePoint("0", 3, Vector(100, 100, 0), Vector(0, 0, 0));
525 t->AddReferencePoint("0", 3, Vector(100, 100, 0), Vector(-100, 0, 0));
526 t->AddReferencePoint("0", 4, Vector(0, 100, 0), Vector(0, 0, 0));
527 t->AddReferencePoint("0", 4, Vector(0, 100, 0), Vector(0, -100, 0));
528 t->AddReferencePoint("0", 5, Vector(0, 0, 0), Vector(0, 0, 0));
529 AddTestCase(t, TestCase::Duration::QUICK);
530 t = new Ns2MobilityHelperTest("Bug 1219 testcase", Seconds(16));
531 t->SetTrace("$node_(0) set X_ 0.0\n"
532 "$node_(0) set Y_ 0.0\n"
533 "$ns_ at 1.0 \"$node_(0) setdest 0 10 1\"\n"
534 "$ns_ at 6.0 \"$node_(0) setdest 0 -10 1\"\n");
535 // id t position velocity
536 t->AddReferencePoint("0", 0, Vector(0, 0, 0), Vector(0, 0, 0));
537 t->AddReferencePoint("0", 1, Vector(0, 0, 0), Vector(0, 1, 0));
538 t->AddReferencePoint("0", 6, Vector(0, 5, 0), Vector(0, -1, 0));
539 t->AddReferencePoint("0", 16, Vector(0, -10, 0), Vector(0, 0, 0));
540 AddTestCase(t, TestCase::Duration::QUICK);
541 t = new Ns2MobilityHelperTest("Bug 1059 testcase", Seconds(16));
542 t->SetTrace("$node_(0) set X_ 10.0\r\n"
543 "$node_(0) set Y_ 0.0\r\n");
544 // id t position velocity
545 t->AddReferencePoint("0", 0, Vector(10, 0, 0), Vector(0, 0, 0));
546 AddTestCase(t, TestCase::Duration::QUICK);
547 t = new Ns2MobilityHelperTest("Bug 1301 testcase", Seconds(16));
548 t->SetTrace("$node_(0) set X_ 10.0\n"
549 "$node_(0) set Y_ 0.0\n"
550 "$ns_ at 1.0 \"$node_(0) setdest 10 0 1\"\n");
551 // id t position velocity
552 // Moving to the current position must change nothing. No NaN
553 // speed must be.
554 t->AddReferencePoint("0", 0, Vector(10, 0, 0), Vector(0, 0, 0));
555 AddTestCase(t, TestCase::Duration::QUICK);
556
557 t = new Ns2MobilityHelperTest("Bug 1316 testcase", Seconds(1000));
558 t->SetTrace("$node_(0) set X_ 350.00000000000000\n"
559 "$node_(0) set Y_ 50.00000000000000\n"
560 "$ns_ at 50.00000000000000 \"$node_(0) setdest 400.00000000000000 "
561 "50.00000000000000 1.00000000000000\"\n"
562 "$ns_ at 150.00000000000000 \"$node_(0) setdest 400.00000000000000 "
563 "150.00000000000000 4.00000000000000\"\n"
564 "$ns_ at 300.00000000000000 \"$node_(0) setdest 250.00000000000000 "
565 "150.00000000000000 3.00000000000000\"\n"
566 "$ns_ at 350.00000000000000 \"$node_(0) setdest 250.00000000000000 "
567 "50.00000000000000 1.00000000000000\"\n"
568 "$ns_ at 600.00000000000000 \"$node_(0) setdest 250.00000000000000 "
569 "1050.00000000000000 2.00000000000000\"\n"
570 "$ns_ at 900.00000000000000 \"$node_(0) setdest 300.00000000000000 "
571 "650.00000000000000 2.50000000000000\"\n");
572 t->AddReferencePoint("0",
573 0.000,
574 Vector(350.000, 50.000, 0.000),
575 Vector(0.000, 0.000, 0.000));
576 t->AddReferencePoint("0",
577 50.000,
578 Vector(350.000, 50.000, 0.000),
579 Vector(1.000, 0.000, 0.000));
580 t->AddReferencePoint("0",
581 100.000,
582 Vector(400.000, 50.000, 0.000),
583 Vector(0.000, 0.000, 0.000));
584 t->AddReferencePoint("0",
585 150.000,
586 Vector(400.000, 50.000, 0.000),
587 Vector(0.000, 4.000, 0.000));
588 t->AddReferencePoint("0",
589 175.000,
590 Vector(400.000, 150.000, 0.000),
591 Vector(0.000, 0.000, 0.000));
592 t->AddReferencePoint("0",
593 300.000,
594 Vector(400.000, 150.000, 0.000),
595 Vector(-3.000, 0.000, 0.000));
596 t->AddReferencePoint("0",
597 350.000,
598 Vector(250.000, 150.000, 0.000),
599 Vector(0.000, 0.000, 0.000));
600 t->AddReferencePoint("0",
601 350.000,
602 Vector(250.000, 150.000, 0.000),
603 Vector(0.000, -1.000, 0.000));
604 t->AddReferencePoint("0",
605 450.000,
606 Vector(250.000, 50.000, 0.000),
607 Vector(0.000, 0.000, 0.000));
608 t->AddReferencePoint("0",
609 600.000,
610 Vector(250.000, 50.000, 0.000),
611 Vector(0.000, 2.000, 0.000));
612 t->AddReferencePoint("0",
613 900.000,
614 Vector(250.000, 650.000, 0.000),
615 Vector(2.500, 0.000, 0.000));
616 t->AddReferencePoint("0",
617 920.000,
618 Vector(300.000, 650.000, 0.000),
619 Vector(0.000, 0.000, 0.000));
620 AddTestCase(t, TestCase::Duration::QUICK);
621 }
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:775
static void Clear()
Clear the list of objects associated with names.
Definition: names.cc:843
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:829
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:57
Helper class which can read ns-2 movement files and configure nodes mobility.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
encapsulates test code
Definition: test.h:1061
bool IsStatusFailure() const
Check if any tests failed.
Definition: test.cc:464
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition: test.cc:438
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition: test.cc:478
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
static constexpr auto UNIT
Definition: test.h:1286
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:403
#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:978
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
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:145
#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:200
#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:791
#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:252
#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:616
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
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:706
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.