A Discrete-Event Network Simulator
API
ns2-mobility-helper-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 INRIA
4  * 2009,2010 Contributors
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Contributors: Thomas Waldecker <twaldecker@rocketmail.com>
21  * Martín Giachino <martin.giachino@gmail.com>
22  *
23  * Brief description: Implementation of a ns2 movement trace file reader.
24  *
25  * This implementation is based on the ns2 movement documentation of ns2
26  * as described in http://www.isi.edu/nsnam/ns/doc/node174.html
27  *
28  * Valid trace files use the following ns2 statements:
29  *
30  * $node set X_ x1
31  * $node set Y_ y1
32  * $node set Z_ z1
33  * $ns at $time $node setdest x2 y2 speed
34  * $ns at $time $node set X_ x1
35  * $ns at $time $node set Y_ Y1
36  * $ns at $time $node set Z_ Z1
37  *
38  */
39 
40 #include <algorithm>
41 #include "ns3/log.h"
42 #include "ns3/simulator.h"
43 #include "ns3/node-list.h"
44 #include "ns3/node.h"
45 #include "ns3/constant-velocity-mobility-model.h"
46 #include "ns3/test.h"
47 #include "ns3/node-container.h"
48 #include "ns3/names.h"
49 #include "ns3/config.h"
50 #include "ns3/ns2-mobility-helper.h"
51 
52 using namespace ns3;
53 
54 NS_LOG_COMPONENT_DEFINE ("ns2-mobility-helper-test-suite");
55 
56 // -----------------------------------------------------------------------------
57 // Testing
58 // -----------------------------------------------------------------------------
59 bool AreVectorsEqual (Vector const & actual, Vector const & limit, double tol)
60 {
61  if (actual.x > limit.x + tol || actual.x < limit.x - tol)
62  {
63  return false;
64  }
65  if (actual.y > limit.y + tol || actual.y < limit.y - tol)
66  {
67  return false;
68  }
69  if (actual.z > limit.z + tol || actual.z < limit.z - tol)
70  {
71  return false;
72  }
73  return true;
74 }
75 
87 {
88 public:
91  {
92  std::string node;
94  Vector pos;
95  Vector vel;
96 
105  ReferencePoint (std::string const & id, Time t, Vector const & p, Vector const & v)
106  : node (id),
107  time (t),
108  pos (p),
109  vel (v)
110  {
111  }
117  bool operator< (ReferencePoint const & o) const
118  {
119  return (time < o.time);
120  }
121  };
129  Ns2MobilityHelperTest (std::string const & name, Time timeLimit, uint32_t nodes = 1)
130  : TestCase (name),
131  m_timeLimit (timeLimit),
132  m_nodeCount (nodes),
133  m_nextRefPoint (0)
134  {
135  }
138  {
139  }
144  void SetTrace (std::string const & trace)
145  {
146  m_trace = trace;
147  }
153  {
154  m_reference.push_back (r);
155  }
163  void AddReferencePoint (const char * id, double sec, Vector const & p, Vector const & v)
164  {
165  AddReferencePoint (ReferencePoint (id, Seconds (sec), p, v));
166  }
167 
168 private:
172  uint32_t m_nodeCount;
174  std::string m_trace;
176  std::vector<ReferencePoint> m_reference;
180  std::string m_traceFile;
181 
182 private:
187  bool WriteTrace ()
188  {
189  m_traceFile = CreateTempDirFilename ("Ns2MobilityHelperTest.tcl");
190  std::ofstream of (m_traceFile.c_str ());
191  NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (of.is_open (), true, "Need to write tmp. file");
192  of << m_trace;
193  of.close ();
194  return false; // no errors
195  }
197  void CreateNodes ()
198  {
200  nodes.Create (m_nodeCount);
201  for (uint32_t i = 0; i < m_nodeCount; ++i)
202  {
203  std::ostringstream os;
204  os << i;
205  Names::Add (os.str (), nodes.Get (i));
206  }
207  }
213  {
214  std::stable_sort (m_reference.begin (), m_reference.end ());
215  while (m_nextRefPoint < m_reference.size () && m_reference[m_nextRefPoint].time == Seconds (0))
216  {
217  ReferencePoint const & rp = m_reference[m_nextRefPoint];
218  Ptr<Node> node = Names::Find<Node> (rp.node);
219  NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (node, 0, "Can't find node with id " << rp.node);
221  NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (mob, 0, "Can't find mobility for node " << rp.node);
222 
223  double tol = 0.001;
224  NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (mob->GetPosition (), rp.pos, tol), true, "Initial position mismatch for node " << rp.node);
225  NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (mob->GetVelocity (), rp.vel, tol), true, "Initial velocity mismatch for node " << rp.node);
226 
227  m_nextRefPoint++;
228  }
229  return IsStatusFailure ();
230  }
236  void CourseChange (std::string context, Ptr<const MobilityModel> mobility)
237  {
238  Time time = Simulator::Now ();
239  Ptr<Node> node = mobility->GetObject<Node> ();
240  NS_ASSERT (node);
241  std::string id = Names::FindName (node);
242  NS_ASSERT (!id.empty ());
243  Vector pos = mobility->GetPosition ();
244  Vector vel = mobility->GetVelocity ();
245 
246  NS_TEST_EXPECT_MSG_LT (m_nextRefPoint, m_reference.size (), "Not enough reference points");
247  if (m_nextRefPoint >= m_reference.size ())
248  {
249  return;
250  }
251 
252  ReferencePoint const & ref = m_reference [m_nextRefPoint++];
253  NS_TEST_EXPECT_MSG_EQ (time, ref.time, "Time mismatch");
254  NS_TEST_EXPECT_MSG_EQ (id, ref.node, "Node ID mismatch at time " << time.GetSeconds () << " s");
255 
256  double tol = 0.001;
257  NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (pos, ref.pos, tol), true, "Position mismatch at time " << time.GetSeconds () << " s for node " << id);
258  NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (vel, ref.vel, tol), true, "Velocity mismatch at time " << time.GetSeconds () << " s for node " << id);
259  }
260 
261  void DoSetup ()
262  {
263  CreateNodes ();
264  }
265 
266  void DoTeardown ()
267  {
268  Names::Clear ();
270  }
271 
273  void DoRun ()
274  {
275  NS_TEST_ASSERT_MSG_EQ (m_trace.empty (), false, "Need trace");
276  NS_TEST_ASSERT_MSG_EQ (m_reference.empty (), false, "Need reference");
277 
278  if (WriteTrace ())
279  {
280  return;
281  }
282  Ns2MobilityHelper mobility (m_traceFile);
283  mobility.Install ();
284  if (CheckInitialPositions ())
285  {
286  return;
287  }
288  Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
290  Simulator::Stop (m_timeLimit);
291  Simulator::Run ();
292  }
293 };
294 
302 {
303 public:
304  Ns2MobilityHelperTestSuite () : TestSuite ("mobility-ns2-trace-helper", UNIT)
305  {
306  SetDataDir (NS_TEST_SOURCEDIR);
307 
308  // to be used as temporary variable for test cases.
309  // Note that test suite takes care of deleting all test cases.
310  Ns2MobilityHelperTest * t (0);
311 
312  // Initial position
313  t = new Ns2MobilityHelperTest ("initial position", Seconds (1));
314  t->SetTrace ("$node_(0) set X_ 1.0\n"
315  "$node_(0) set Y_ 2.0\n"
316  "$node_(0) set Z_ 3.0\n"
317  );
318  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
319  AddTestCase (t, TestCase::QUICK);
320 
321  // Check parsing comments, empty lines and no EOF at the end of file
322  t = new Ns2MobilityHelperTest ("comments", Seconds (1));
323  t->SetTrace ("# comment\n"
324  "\n\n" // empty lines
325  "$node_(0) set X_ 1.0 # comment \n"
326  "$node_(0) set Y_ 2.0 ### \n"
327  "$node_(0) set Z_ 3.0 # $node_(0) set Z_ 3.0\n"
328  "#$node_(0) set Z_ 100 #"
329  );
330  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
331  AddTestCase (t, TestCase::QUICK);
332 
333  // Simple setdest. Arguments are interpreted as x, y, speed by default
334  t = new Ns2MobilityHelperTest ("simple setdest", Seconds (10));
335  t->SetTrace ("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"");
336  // id t position velocity
337  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
338  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0));
339  t->AddReferencePoint ("0", 6, Vector (25, 0, 0), Vector (0, 0, 0));
340  AddTestCase (t, TestCase::QUICK);
341 
342  // Several set and setdest. Arguments are interpreted as x, y, speed by default
343  t = new Ns2MobilityHelperTest ("square setdest", Seconds (6));
344  t->SetTrace ("$node_(0) set X_ 0.0\n"
345  "$node_(0) set Y_ 0.0\n"
346  "$ns_ at 1.0 \"$node_(0) setdest 5 0 5\"\n"
347  "$ns_ at 2.0 \"$node_(0) setdest 5 5 5\"\n"
348  "$ns_ at 3.0 \"$node_(0) setdest 0 5 5\"\n"
349  "$ns_ at 4.0 \"$node_(0) setdest 0 0 5\"\n"
350  );
351  // id t position velocity
352  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
353  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0));
354  t->AddReferencePoint ("0", 2, Vector (5, 0, 0), Vector (0, 0, 0));
355  t->AddReferencePoint ("0", 2, Vector (5, 0, 0), Vector (0, 5, 0));
356  t->AddReferencePoint ("0", 3, Vector (5, 5, 0), Vector (0, 0, 0));
357  t->AddReferencePoint ("0", 3, Vector (5, 5, 0), Vector (-5, 0, 0));
358  t->AddReferencePoint ("0", 4, Vector (0, 5, 0), Vector (0, 0, 0));
359  t->AddReferencePoint ("0", 4, Vector (0, 5, 0), Vector (0, -5, 0));
360  t->AddReferencePoint ("0", 5, Vector (0, 0, 0), Vector (0, 0, 0));
361  AddTestCase (t, TestCase::QUICK);
362 
363  // Copy of previous test case but with the initial positions at
364  // the end of the trace rather than at the beginning.
365  //
366  // Several set and setdest. Arguments are interpreted as x, y, speed by default
367  t = new Ns2MobilityHelperTest ("square setdest (initial positions at end)", Seconds (6));
368  t->SetTrace ("$ns_ at 1.0 \"$node_(0) setdest 15 10 5\"\n"
369  "$ns_ at 2.0 \"$node_(0) setdest 15 15 5\"\n"
370  "$ns_ at 3.0 \"$node_(0) setdest 10 15 5\"\n"
371  "$ns_ at 4.0 \"$node_(0) setdest 10 10 5\"\n"
372  "$node_(0) set X_ 10.0\n"
373  "$node_(0) set Y_ 10.0\n"
374  );
375  // id t position velocity
376  t->AddReferencePoint ("0", 0, Vector (10, 10, 0), Vector (0, 0, 0));
377  t->AddReferencePoint ("0", 1, Vector (10, 10, 0), Vector (5, 0, 0));
378  t->AddReferencePoint ("0", 2, Vector (15, 10, 0), Vector (0, 0, 0));
379  t->AddReferencePoint ("0", 2, Vector (15, 10, 0), Vector (0, 5, 0));
380  t->AddReferencePoint ("0", 3, Vector (15, 15, 0), Vector (0, 0, 0));
381  t->AddReferencePoint ("0", 3, Vector (15, 15, 0), Vector (-5, 0, 0));
382  t->AddReferencePoint ("0", 4, Vector (10, 15, 0), Vector (0, 0, 0));
383  t->AddReferencePoint ("0", 4, Vector (10, 15, 0), Vector (0, -5, 0));
384  t->AddReferencePoint ("0", 5, Vector (10, 10, 0), Vector (0, 0, 0));
385  AddTestCase (t, TestCase::QUICK);
386 
387  // Scheduled set position
388  t = new Ns2MobilityHelperTest ("scheduled set position", Seconds (2));
389  t->SetTrace ("$ns_ at 1.0 \"$node_(0) set X_ 10\"\n"
390  "$ns_ at 1.0 \"$node_(0) set Z_ 10\"\n"
391  "$ns_ at 1.0 \"$node_(0) set Y_ 10\"");
392  // id t position velocity
393  t->AddReferencePoint ("0", 1, Vector (10, 0, 0), Vector (0, 0, 0));
394  t->AddReferencePoint ("0", 1, Vector (10, 0, 10), Vector (0, 0, 0));
395  t->AddReferencePoint ("0", 1, Vector (10, 10, 10), Vector (0, 0, 0));
396  AddTestCase (t, TestCase::QUICK);
397 
398  // Malformed lines
399  t = new Ns2MobilityHelperTest ("malformed lines", Seconds (2));
400  t->SetTrace ("$node() set X_ 1 # node id is not present\n"
401  "$node # incoplete line\"\n"
402  "$node this line is not correct\n"
403  "$node_(0) set X_ 1 # line OK \n"
404  "$node_(0) set Y_ 2 # line OK \n"
405  "$node_(0) set Z_ 3 # line OK \n"
406  "$ns_ at \"$node_(0) setdest 4 4 4\" # time not present\n"
407  "$ns_ at 1 \"$node_(0) setdest 2 2 1 \" # line OK \n");
408  // id t position velocity
409  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
410  t->AddReferencePoint ("0", 1, Vector (1, 2, 3), Vector (1, 0, 0));
411  t->AddReferencePoint ("0", 2, Vector (2, 2, 3), Vector (0, 0, 0));
412  AddTestCase (t, TestCase::QUICK);
413 
414  // Non possible values
415  t = new Ns2MobilityHelperTest ("non possible values", Seconds (2));
416  t->SetTrace ("$node_(0) set X_ 1 # line OK \n"
417  "$node_(0) set Y_ 2 # line OK \n"
418  "$node_(0) set Z_ 3 # line OK \n"
419  "$node_(-22) set Y_ 3 # node id not correct\n"
420  "$node_(3.3) set Y_ 1111 # node id not correct\n"
421  "$ns_ at sss \"$node_(0) setdest 5 5 5\" # time is not a number\n"
422  "$ns_ at 1 \"$node_(0) setdest 2 2 1\" # line OK \n"
423  "$ns_ at 1 \"$node_(0) setdest 2 2 -1\" # negative speed is not correct\n"
424  "$ns_ at 1 \"$node_(0) setdest 2 2 sdfs\" # speed is not a number\n"
425  "$ns_ at 1 \"$node_(0) setdest 2 2 s232dfs\" # speed is not a number\n"
426  "$ns_ at 1 \"$node_(0) setdest 233 2.. s232dfs\" # more than one non numbers\n"
427  "$ns_ at -12 \"$node_(0) setdest 11 22 33\" # time should not be negative\n");
428  // id t position velocity
429  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
430  t->AddReferencePoint ("0", 1, Vector (1, 2, 3), Vector (1, 0, 0));
431  t->AddReferencePoint ("0", 2, Vector (2, 2, 3), Vector (0, 0, 0));
432  AddTestCase (t, TestCase::QUICK);
433 
434  // More than one node
435  t = new Ns2MobilityHelperTest ("few nodes, combinations of set and setdest", Seconds (10), 3);
436  t->SetTrace ("$node_(0) set X_ 1.0\n"
437  "$node_(0) set Y_ 2.0\n"
438  "$node_(0) set Z_ 3.0\n"
439  "$ns_ at 1.0 \"$node_(1) setdest 25 0 5\"\n"
440  "$node_(2) set X_ 0.0\n"
441  "$node_(2) set Y_ 0.0\n"
442  "$ns_ at 1.0 \"$node_(2) setdest 5 0 5\"\n"
443  "$ns_ at 2.0 \"$node_(2) setdest 5 5 5\"\n"
444  "$ns_ at 3.0 \"$node_(2) setdest 0 5 5\"\n"
445  "$ns_ at 4.0 \"$node_(2) setdest 0 0 5\"\n");
446  // id t position velocity
447  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
448  t->AddReferencePoint ("1", 0, Vector (0, 0, 0), Vector (0, 0, 0));
449  t->AddReferencePoint ("1", 1, Vector (0, 0, 0), Vector (5, 0, 0));
450  t->AddReferencePoint ("1", 6, Vector (25, 0, 0), Vector (0, 0, 0));
451  t->AddReferencePoint ("2", 0, Vector (0, 0, 0), Vector (0, 0, 0));
452  t->AddReferencePoint ("2", 1, Vector (0, 0, 0), Vector (5, 0, 0));
453  t->AddReferencePoint ("2", 2, Vector (5, 0, 0), Vector (0, 0, 0));
454  t->AddReferencePoint ("2", 2, Vector (5, 0, 0), Vector (0, 5, 0));
455  t->AddReferencePoint ("2", 3, Vector (5, 5, 0), Vector (0, 0, 0));
456  t->AddReferencePoint ("2", 3, Vector (5, 5, 0), Vector (-5, 0, 0));
457  t->AddReferencePoint ("2", 4, Vector (0, 5, 0), Vector (0, 0, 0));
458  t->AddReferencePoint ("2", 4, Vector (0, 5, 0), Vector (0, -5, 0));
459  t->AddReferencePoint ("2", 5, Vector (0, 0, 0), Vector (0, 0, 0));
460  AddTestCase (t, TestCase::QUICK);
461 
462  // Test for Speed == 0, that acts as stop the node.
463  t = new Ns2MobilityHelperTest ("setdest with speed cero", Seconds (10));
464  t->SetTrace ("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"\n"
465  "$ns_ at 7.0 \"$node_(0) setdest 11 22 0\"\n");
466  // id t position velocity
467  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
468  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0));
469  t->AddReferencePoint ("0", 6, Vector (25, 0, 0), Vector (0, 0, 0));
470  t->AddReferencePoint ("0", 7, Vector (25, 0, 0), Vector (0, 0, 0));
471  AddTestCase (t, TestCase::QUICK);
472 
473 
474  // Test negative positions
475  t = new Ns2MobilityHelperTest ("test negative positions", Seconds (10));
476  t->SetTrace ("$node_(0) set X_ -1.0\n"
477  "$node_(0) set Y_ 0\n"
478  "$ns_ at 1.0 \"$node_(0) setdest 0 0 1\"\n"
479  "$ns_ at 2.0 \"$node_(0) setdest 0 -1 1\"\n");
480  // id t position velocity
481  t->AddReferencePoint ("0", 0, Vector (-1, 0, 0), Vector (0, 0, 0));
482  t->AddReferencePoint ("0", 1, Vector (-1, 0, 0), Vector (1, 0, 0));
483  t->AddReferencePoint ("0", 2, Vector (0, 0, 0), Vector (0, 0, 0));
484  t->AddReferencePoint ("0", 2, Vector (0, 0, 0), Vector (0, -1, 0));
485  t->AddReferencePoint ("0", 3, Vector (0, -1, 0), Vector (0, 0, 0));
486  AddTestCase (t, TestCase::QUICK);
487 
488  // Sqare setdest with values in the form 1.0e+2
489  t = new Ns2MobilityHelperTest ("Foalt numbers in 1.0e+2 format", Seconds (6));
490  t->SetTrace ("$node_(0) set X_ 0.0\n"
491  "$node_(0) set Y_ 0.0\n"
492  "$ns_ at 1.0 \"$node_(0) setdest 1.0e+2 0 1.0e+2\"\n"
493  "$ns_ at 2.0 \"$node_(0) setdest 1.0e+2 1.0e+2 1.0e+2\"\n"
494  "$ns_ at 3.0 \"$node_(0) setdest 0 1.0e+2 1.0e+2\"\n"
495  "$ns_ at 4.0 \"$node_(0) setdest 0 0 1.0e+2\"\n");
496  // id t position velocity
497  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
498  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (100, 0, 0));
499  t->AddReferencePoint ("0", 2, Vector (100, 0, 0), Vector (0, 0, 0));
500  t->AddReferencePoint ("0", 2, Vector (100, 0, 0), Vector (0, 100, 0));
501  t->AddReferencePoint ("0", 3, Vector (100, 100, 0), Vector (0, 0, 0));
502  t->AddReferencePoint ("0", 3, Vector (100, 100, 0), Vector (-100, 0, 0));
503  t->AddReferencePoint ("0", 4, Vector (0, 100, 0), Vector (0, 0, 0));
504  t->AddReferencePoint ("0", 4, Vector (0, 100, 0), Vector (0, -100, 0));
505  t->AddReferencePoint ("0", 5, Vector (0, 0, 0), Vector (0, 0, 0));
506  AddTestCase (t, TestCase::QUICK);
507  t = new Ns2MobilityHelperTest ("Bug 1219 testcase", Seconds (16));
508  t->SetTrace ("$node_(0) set X_ 0.0\n"
509  "$node_(0) set Y_ 0.0\n"
510  "$ns_ at 1.0 \"$node_(0) setdest 0 10 1\"\n"
511  "$ns_ at 6.0 \"$node_(0) setdest 0 -10 1\"\n"
512  );
513  // id t position velocity
514  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
515  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (0, 1, 0));
516  t->AddReferencePoint ("0", 6, Vector (0, 5, 0), Vector (0, -1, 0));
517  t->AddReferencePoint ("0", 16, Vector (0, -10, 0), Vector (0, 0, 0));
518  AddTestCase (t, TestCase::QUICK);
519  t = new Ns2MobilityHelperTest ("Bug 1059 testcase", Seconds (16));
520  t->SetTrace ("$node_(0) set X_ 10.0\r\n"
521  "$node_(0) set Y_ 0.0\r\n"
522  );
523  // id t position velocity
524  t->AddReferencePoint ("0", 0, Vector (10, 0, 0), Vector (0, 0, 0));
525  AddTestCase (t, TestCase::QUICK);
526  t = new Ns2MobilityHelperTest ("Bug 1301 testcase", Seconds (16));
527  t->SetTrace ("$node_(0) set X_ 10.0\n"
528  "$node_(0) set Y_ 0.0\n"
529  "$ns_ at 1.0 \"$node_(0) setdest 10 0 1\"\n"
530  );
531  // id t position velocity
532  // Moving to the current position must change nothing. No NaN
533  // speed must be.
534  t->AddReferencePoint ("0", 0, Vector (10, 0, 0), Vector (0, 0, 0));
535  AddTestCase (t, TestCase::QUICK);
536 
537  t = new Ns2MobilityHelperTest ("Bug 1316 testcase", Seconds (1000));
538  t->SetTrace ("$node_(0) set X_ 350.00000000000000\n"
539  "$node_(0) set Y_ 50.00000000000000\n"
540  "$ns_ at 50.00000000000000 \"$node_(0) setdest 400.00000000000000 50.00000000000000 1.00000000000000\"\n"
541  "$ns_ at 150.00000000000000 \"$node_(0) setdest 400.00000000000000 150.00000000000000 4.00000000000000\"\n"
542  "$ns_ at 300.00000000000000 \"$node_(0) setdest 250.00000000000000 150.00000000000000 3.00000000000000\"\n"
543  "$ns_ at 350.00000000000000 \"$node_(0) setdest 250.00000000000000 50.00000000000000 1.00000000000000\"\n"
544  "$ns_ at 600.00000000000000 \"$node_(0) setdest 250.00000000000000 1050.00000000000000 2.00000000000000\"\n"
545  "$ns_ at 900.00000000000000 \"$node_(0) setdest 300.00000000000000 650.00000000000000 2.50000000000000\"\n"
546  );
547  t->AddReferencePoint ("0", 0.000, Vector (350.000, 50.000, 0.000), Vector (0.000, 0.000, 0.000));
548  t->AddReferencePoint ("0", 50.000, Vector (350.000, 50.000, 0.000), Vector (1.000, 0.000, 0.000));
549  t->AddReferencePoint ("0", 100.000, Vector (400.000, 50.000, 0.000), Vector (0.000, 0.000, 0.000));
550  t->AddReferencePoint ("0", 150.000, Vector (400.000, 50.000, 0.000), Vector (0.000, 4.000, 0.000));
551  t->AddReferencePoint ("0", 175.000, Vector (400.000, 150.000, 0.000), Vector (0.000, 0.000, 0.000));
552  t->AddReferencePoint ("0", 300.000, Vector (400.000, 150.000, 0.000), Vector (-3.000, 0.000, 0.000));
553  t->AddReferencePoint ("0", 350.000, Vector (250.000, 150.000, 0.000), Vector (0.000, 0.000, 0.000));
554  t->AddReferencePoint ("0", 350.000, Vector (250.000, 150.000, 0.000), Vector (0.000, -1.000, 0.000));
555  t->AddReferencePoint ("0", 450.000, Vector (250.000, 50.000, 0.000), Vector (0.000, 0.000, 0.000));
556  t->AddReferencePoint ("0", 600.000, Vector (250.000, 50.000, 0.000), Vector (0.000, 2.000, 0.000));
557  t->AddReferencePoint ("0", 900.000, Vector (250.000, 650.000, 0.000), Vector (2.500, 0.000, 0.000));
558  t->AddReferencePoint ("0", 920.000, Vector (300.000, 650.000, 0.000), Vector (0.000, 0.000, 0.000));
559  AddTestCase (t, TestCase::QUICK);
560 
561  }
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
bool AreVectorsEqual(Vector const &actual, Vector const &limit, double tol)
std::vector< ReferencePoint > m_reference
Reference mobility.
A suite of tests to run.
Definition: test.h:1343
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:380
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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:283
encapsulates test code
Definition: test.h:1153
std::string m_traceFile
TMP trace file name.
uint32_t m_nodeCount
Number of nodes used in the test.
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:160
mobility
Definition: third.py:108
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
Definition: names.cc:768
Ns2MobilityHelperTestSuite g_ns2TransmobilityHelperTestSuite
the test suite
void CourseChange(std::string context, Ptr< const MobilityModel > mobility)
Listen for course change events.
#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:225
Keep track of the current position and velocity of an object.
static void Clear(void)
Clear the list of objects associated with names.
Definition: names.cc:831
nodes
Definition: first.py:32
Helper class which can read ns-2 movement files and configure nodes mobility.
make Callback use a separate empty type
Definition: empty.h:33
std::string m_trace
Trace as string.
#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:680
#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:166
bool WriteTrace()
Dump NS-2 trace to tmp file.
Ns2MobilityHelperTest(std::string const &name, Time timeLimit, uint32_t nodes=1)
Create new test case.
size_t m_nextRefPoint
Next reference point to be checked.
void AddReferencePoint(const char *id, double sec, Vector const &p, Vector const &v)
Add next reference point.
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
std::string node
node ID as string, e.g. "1"
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
ReferencePoint(std::string const &id, Time t, Vector const &p, Vector const &v)
Constructor.
void SetTrace(std::string const &trace)
Set NS-2 trace to read as single large string (don&#39;t forget to add \n and quote "&#39;s) ...
void CreateNodes()
Create and name nodes.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Every test case is supposed to:
void DoSetup()
Implementation to do any local setup required for this TestCase.
Fast test.
Definition: test.h:1159
Vector GetPosition(void) const
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
A network Node.
Definition: node.h:56
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
#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:901
bool CheckInitialPositions()
Check that all initial positions are correct.
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:817
void AddReferencePoint(ReferencePoint const &r)
Add next reference point.
Single record in mobility reference.
void DoTeardown()
Implementation to do any local setup required for this TestCase.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642
Vector GetVelocity(void) const