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  }
113  bool operator< (ReferencePoint const & o) const
114  {
115  return (time < o.time);
116  }
117  };
125  Ns2MobilityHelperTest (std::string const & name, Time timeLimit, uint32_t nodes = 1)
126  : TestCase (name),
127  m_timeLimit (timeLimit),
128  m_nodeCount (nodes),
129  m_nextRefPoint (0)
130  {
131  }
134  {
135  }
137  void SetTrace (std::string const & trace)
138  {
139  m_trace = trace;
140  }
143  {
144  m_reference.push_back (r);
145  }
147  void AddReferencePoint (const char * id, double sec, Vector const & p, Vector const & v)
148  {
149  AddReferencePoint (ReferencePoint (id, Seconds (sec), p, v));
150  }
151 
152 private:
156  uint32_t m_nodeCount;
158  std::string m_trace;
160  std::vector<ReferencePoint> m_reference;
164  std::string m_traceFile;
165 
166 private:
168  bool WriteTrace ()
169  {
170  m_traceFile = CreateTempDirFilename ("Ns2MobilityHelperTest.tcl");
171  std::ofstream of (m_traceFile.c_str ());
172  NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (of.is_open (), true, "Need to write tmp. file");
173  of << m_trace;
174  of.close ();
175  return false; // no errors
176  }
178  void CreateNodes ()
179  {
181  nodes.Create (m_nodeCount);
182  for (uint32_t i = 0; i < m_nodeCount; ++i)
183  {
184  std::ostringstream os;
185  os << i;
186  Names::Add (os.str (), nodes.Get (i));
187  }
188  }
191  {
192  std::stable_sort (m_reference.begin (), m_reference.end ());
193  while (m_nextRefPoint < m_reference.size () && m_reference[m_nextRefPoint].time == Seconds (0))
194  {
195  ReferencePoint const & rp = m_reference[m_nextRefPoint];
196  Ptr<Node> node = Names::Find<Node> (rp.node);
197  NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (node, 0, "Can't find node with id " << rp.node);
199  NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (mob, 0, "Can't find mobility for node " << rp.node);
200 
201  double tol = 0.001;
202  NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (mob->GetPosition (), rp.pos, tol), true, "Initial position mismatch for node " << rp.node);
203  NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (mob->GetVelocity (), rp.vel, tol), true, "Initial velocity mismatch for node " << rp.node);
204 
205  m_nextRefPoint++;
206  }
207  return IsStatusFailure ();
208  }
210  void CourseChange (std::string context, Ptr<const MobilityModel> mobility)
211  {
212  Time time = Simulator::Now ();
213  Ptr<Node> node = mobility->GetObject<Node> ();
214  NS_ASSERT (node);
215  std::string id = Names::FindName (node);
216  NS_ASSERT (!id.empty ());
217  Vector pos = mobility->GetPosition ();
218  Vector vel = mobility->GetVelocity ();
219 
220  NS_TEST_EXPECT_MSG_LT (m_nextRefPoint, m_reference.size (), "Not enough reference points");
221  if (m_nextRefPoint >= m_reference.size ())
222  {
223  return;
224  }
225 
226  ReferencePoint const & ref = m_reference [m_nextRefPoint++];
227  NS_TEST_EXPECT_MSG_EQ (time, ref.time, "Time mismatch");
228  NS_TEST_EXPECT_MSG_EQ (id, ref.node, "Node ID mismatch at time " << time.GetSeconds () << " s");
229 
230  double tol = 0.001;
231  NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (pos, ref.pos, tol), true, "Position mismatch at time " << time.GetSeconds () << " s for node " << id);
232  NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (vel, ref.vel, tol), true, "Velocity mismatch at time " << time.GetSeconds () << " s for node " << id);
233  }
234 
235  void DoSetup ()
236  {
237  CreateNodes ();
238  }
239 
240  void DoTeardown ()
241  {
242  Names::Clear ();
244  }
245 
247  void DoRun ()
248  {
249  NS_TEST_ASSERT_MSG_EQ (m_trace.empty (), false, "Need trace");
250  NS_TEST_ASSERT_MSG_EQ (m_reference.empty (), false, "Need reference");
251 
252  if (WriteTrace ())
253  {
254  return;
255  }
256  Ns2MobilityHelper mobility (m_traceFile);
257  mobility.Install ();
258  if (CheckInitialPositions ())
259  {
260  return;
261  }
262  Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
264  Simulator::Stop (m_timeLimit);
265  Simulator::Run ();
266  }
267 };
268 
276 {
277 public:
278  Ns2MobilityHelperTestSuite () : TestSuite ("mobility-ns2-trace-helper", UNIT)
279  {
280  SetDataDir (NS_TEST_SOURCEDIR);
281 
282  // to be used as temporary variable for test cases.
283  // Note that test suite takes care of deleting all test cases.
284  Ns2MobilityHelperTest * t (0);
285 
286  // Initial position
287  t = new Ns2MobilityHelperTest ("initial position", Seconds (1));
288  t->SetTrace ("$node_(0) set X_ 1.0\n"
289  "$node_(0) set Y_ 2.0\n"
290  "$node_(0) set Z_ 3.0\n"
291  );
292  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
293  AddTestCase (t, TestCase::QUICK);
294 
295  // Check parsing comments, empty lines and no EOF at the end of file
296  t = new Ns2MobilityHelperTest ("comments", Seconds (1));
297  t->SetTrace ("# comment\n"
298  "\n\n" // empty lines
299  "$node_(0) set X_ 1.0 # comment \n"
300  "$node_(0) set Y_ 2.0 ### \n"
301  "$node_(0) set Z_ 3.0 # $node_(0) set Z_ 3.0\n"
302  "#$node_(0) set Z_ 100 #"
303  );
304  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
305  AddTestCase (t, TestCase::QUICK);
306 
307  // Simple setdest. Arguments are interpreted as x, y, speed by default
308  t = new Ns2MobilityHelperTest ("simple setdest", Seconds (10));
309  t->SetTrace ("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"");
310  // id t position velocity
311  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
312  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0));
313  t->AddReferencePoint ("0", 6, Vector (25, 0, 0), Vector (0, 0, 0));
314  AddTestCase (t, TestCase::QUICK);
315 
316  // Several set and setdest. Arguments are interpreted as x, y, speed by default
317  t = new Ns2MobilityHelperTest ("square setdest", Seconds (6));
318  t->SetTrace ("$node_(0) set X_ 0.0\n"
319  "$node_(0) set Y_ 0.0\n"
320  "$ns_ at 1.0 \"$node_(0) setdest 5 0 5\"\n"
321  "$ns_ at 2.0 \"$node_(0) setdest 5 5 5\"\n"
322  "$ns_ at 3.0 \"$node_(0) setdest 0 5 5\"\n"
323  "$ns_ at 4.0 \"$node_(0) setdest 0 0 5\"\n"
324  );
325  // id t position velocity
326  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
327  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0));
328  t->AddReferencePoint ("0", 2, Vector (5, 0, 0), Vector (0, 0, 0));
329  t->AddReferencePoint ("0", 2, Vector (5, 0, 0), Vector (0, 5, 0));
330  t->AddReferencePoint ("0", 3, Vector (5, 5, 0), Vector (0, 0, 0));
331  t->AddReferencePoint ("0", 3, Vector (5, 5, 0), Vector (-5, 0, 0));
332  t->AddReferencePoint ("0", 4, Vector (0, 5, 0), Vector (0, 0, 0));
333  t->AddReferencePoint ("0", 4, Vector (0, 5, 0), Vector (0, -5, 0));
334  t->AddReferencePoint ("0", 5, Vector (0, 0, 0), Vector (0, 0, 0));
335  AddTestCase (t, TestCase::QUICK);
336 
337  // Copy of previous test case but with the initial positions at
338  // the end of the trace rather than at the beginning.
339  //
340  // Several set and setdest. Arguments are interpreted as x, y, speed by default
341  t = new Ns2MobilityHelperTest ("square setdest (initial positions at end)", Seconds (6));
342  t->SetTrace ("$ns_ at 1.0 \"$node_(0) setdest 15 10 5\"\n"
343  "$ns_ at 2.0 \"$node_(0) setdest 15 15 5\"\n"
344  "$ns_ at 3.0 \"$node_(0) setdest 10 15 5\"\n"
345  "$ns_ at 4.0 \"$node_(0) setdest 10 10 5\"\n"
346  "$node_(0) set X_ 10.0\n"
347  "$node_(0) set Y_ 10.0\n"
348  );
349  // id t position velocity
350  t->AddReferencePoint ("0", 0, Vector (10, 10, 0), Vector (0, 0, 0));
351  t->AddReferencePoint ("0", 1, Vector (10, 10, 0), Vector (5, 0, 0));
352  t->AddReferencePoint ("0", 2, Vector (15, 10, 0), Vector (0, 0, 0));
353  t->AddReferencePoint ("0", 2, Vector (15, 10, 0), Vector (0, 5, 0));
354  t->AddReferencePoint ("0", 3, Vector (15, 15, 0), Vector (0, 0, 0));
355  t->AddReferencePoint ("0", 3, Vector (15, 15, 0), Vector (-5, 0, 0));
356  t->AddReferencePoint ("0", 4, Vector (10, 15, 0), Vector (0, 0, 0));
357  t->AddReferencePoint ("0", 4, Vector (10, 15, 0), Vector (0, -5, 0));
358  t->AddReferencePoint ("0", 5, Vector (10, 10, 0), Vector (0, 0, 0));
359  AddTestCase (t, TestCase::QUICK);
360 
361  // Scheduled set position
362  t = new Ns2MobilityHelperTest ("scheduled set position", Seconds (2));
363  t->SetTrace ("$ns_ at 1.0 \"$node_(0) set X_ 10\"\n"
364  "$ns_ at 1.0 \"$node_(0) set Z_ 10\"\n"
365  "$ns_ at 1.0 \"$node_(0) set Y_ 10\"");
366  // id t position velocity
367  t->AddReferencePoint ("0", 1, Vector (10, 0, 0), Vector (0, 0, 0));
368  t->AddReferencePoint ("0", 1, Vector (10, 0, 10), Vector (0, 0, 0));
369  t->AddReferencePoint ("0", 1, Vector (10, 10, 10), Vector (0, 0, 0));
370  AddTestCase (t, TestCase::QUICK);
371 
372  // Malformed lines
373  t = new Ns2MobilityHelperTest ("malformed lines", Seconds (2));
374  t->SetTrace ("$node() set X_ 1 # node id is not present\n"
375  "$node # incoplete line\"\n"
376  "$node this line is not correct\n"
377  "$node_(0) set X_ 1 # line OK \n"
378  "$node_(0) set Y_ 2 # line OK \n"
379  "$node_(0) set Z_ 3 # line OK \n"
380  "$ns_ at \"$node_(0) setdest 4 4 4\" # time not present\n"
381  "$ns_ at 1 \"$node_(0) setdest 2 2 1 \" # line OK \n");
382  // id t position velocity
383  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
384  t->AddReferencePoint ("0", 1, Vector (1, 2, 3), Vector (1, 0, 0));
385  t->AddReferencePoint ("0", 2, Vector (2, 2, 3), Vector (0, 0, 0));
386  AddTestCase (t, TestCase::QUICK);
387 
388  // Non possible values
389  t = new Ns2MobilityHelperTest ("non possible values", Seconds (2));
390  t->SetTrace ("$node_(0) set X_ 1 # line OK \n"
391  "$node_(0) set Y_ 2 # line OK \n"
392  "$node_(0) set Z_ 3 # line OK \n"
393  "$node_(-22) set Y_ 3 # node id not correct\n"
394  "$node_(3.3) set Y_ 1111 # node id not correct\n"
395  "$ns_ at sss \"$node_(0) setdest 5 5 5\" # time is not a number\n"
396  "$ns_ at 1 \"$node_(0) setdest 2 2 1\" # line OK \n"
397  "$ns_ at 1 \"$node_(0) setdest 2 2 -1\" # negative speed is not correct\n"
398  "$ns_ at 1 \"$node_(0) setdest 2 2 sdfs\" # speed is not a number\n"
399  "$ns_ at 1 \"$node_(0) setdest 2 2 s232dfs\" # speed is not a number\n"
400  "$ns_ at 1 \"$node_(0) setdest 233 2.. s232dfs\" # more than one non numbers\n"
401  "$ns_ at -12 \"$node_(0) setdest 11 22 33\" # time should not be negative\n");
402  // id t position velocity
403  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
404  t->AddReferencePoint ("0", 1, Vector (1, 2, 3), Vector (1, 0, 0));
405  t->AddReferencePoint ("0", 2, Vector (2, 2, 3), Vector (0, 0, 0));
406  AddTestCase (t, TestCase::QUICK);
407 
408  // More than one node
409  t = new Ns2MobilityHelperTest ("few nodes, combinations of set and setdest", Seconds (10), 3);
410  t->SetTrace ("$node_(0) set X_ 1.0\n"
411  "$node_(0) set Y_ 2.0\n"
412  "$node_(0) set Z_ 3.0\n"
413  "$ns_ at 1.0 \"$node_(1) setdest 25 0 5\"\n"
414  "$node_(2) set X_ 0.0\n"
415  "$node_(2) set Y_ 0.0\n"
416  "$ns_ at 1.0 \"$node_(2) setdest 5 0 5\"\n"
417  "$ns_ at 2.0 \"$node_(2) setdest 5 5 5\"\n"
418  "$ns_ at 3.0 \"$node_(2) setdest 0 5 5\"\n"
419  "$ns_ at 4.0 \"$node_(2) setdest 0 0 5\"\n");
420  // id t position velocity
421  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
422  t->AddReferencePoint ("1", 0, Vector (0, 0, 0), Vector (0, 0, 0));
423  t->AddReferencePoint ("1", 1, Vector (0, 0, 0), Vector (5, 0, 0));
424  t->AddReferencePoint ("1", 6, Vector (25, 0, 0), Vector (0, 0, 0));
425  t->AddReferencePoint ("2", 0, Vector (0, 0, 0), Vector (0, 0, 0));
426  t->AddReferencePoint ("2", 1, Vector (0, 0, 0), Vector (5, 0, 0));
427  t->AddReferencePoint ("2", 2, Vector (5, 0, 0), Vector (0, 0, 0));
428  t->AddReferencePoint ("2", 2, Vector (5, 0, 0), Vector (0, 5, 0));
429  t->AddReferencePoint ("2", 3, Vector (5, 5, 0), Vector (0, 0, 0));
430  t->AddReferencePoint ("2", 3, Vector (5, 5, 0), Vector (-5, 0, 0));
431  t->AddReferencePoint ("2", 4, Vector (0, 5, 0), Vector (0, 0, 0));
432  t->AddReferencePoint ("2", 4, Vector (0, 5, 0), Vector (0, -5, 0));
433  t->AddReferencePoint ("2", 5, Vector (0, 0, 0), Vector (0, 0, 0));
434  AddTestCase (t, TestCase::QUICK);
435 
436  // Test for Speed == 0, that acts as stop the node.
437  t = new Ns2MobilityHelperTest ("setdest with speed cero", Seconds (10));
438  t->SetTrace ("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"\n"
439  "$ns_ at 7.0 \"$node_(0) setdest 11 22 0\"\n");
440  // id t position velocity
441  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
442  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0));
443  t->AddReferencePoint ("0", 6, Vector (25, 0, 0), Vector (0, 0, 0));
444  t->AddReferencePoint ("0", 7, Vector (25, 0, 0), Vector (0, 0, 0));
445  AddTestCase (t, TestCase::QUICK);
446 
447 
448  // Test negative positions
449  t = new Ns2MobilityHelperTest ("test negative positions", Seconds (10));
450  t->SetTrace ("$node_(0) set X_ -1.0\n"
451  "$node_(0) set Y_ 0\n"
452  "$ns_ at 1.0 \"$node_(0) setdest 0 0 1\"\n"
453  "$ns_ at 2.0 \"$node_(0) setdest 0 -1 1\"\n");
454  // id t position velocity
455  t->AddReferencePoint ("0", 0, Vector (-1, 0, 0), Vector (0, 0, 0));
456  t->AddReferencePoint ("0", 1, Vector (-1, 0, 0), Vector (1, 0, 0));
457  t->AddReferencePoint ("0", 2, Vector (0, 0, 0), Vector (0, 0, 0));
458  t->AddReferencePoint ("0", 2, Vector (0, 0, 0), Vector (0, -1, 0));
459  t->AddReferencePoint ("0", 3, Vector (0, -1, 0), Vector (0, 0, 0));
460  AddTestCase (t, TestCase::QUICK);
461 
462  // Sqare setdest with values in the form 1.0e+2
463  t = new Ns2MobilityHelperTest ("Foalt numbers in 1.0e+2 format", Seconds (6));
464  t->SetTrace ("$node_(0) set X_ 0.0\n"
465  "$node_(0) set Y_ 0.0\n"
466  "$ns_ at 1.0 \"$node_(0) setdest 1.0e+2 0 1.0e+2\"\n"
467  "$ns_ at 2.0 \"$node_(0) setdest 1.0e+2 1.0e+2 1.0e+2\"\n"
468  "$ns_ at 3.0 \"$node_(0) setdest 0 1.0e+2 1.0e+2\"\n"
469  "$ns_ at 4.0 \"$node_(0) setdest 0 0 1.0e+2\"\n");
470  // id t position velocity
471  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
472  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (100, 0, 0));
473  t->AddReferencePoint ("0", 2, Vector (100, 0, 0), Vector (0, 0, 0));
474  t->AddReferencePoint ("0", 2, Vector (100, 0, 0), Vector (0, 100, 0));
475  t->AddReferencePoint ("0", 3, Vector (100, 100, 0), Vector (0, 0, 0));
476  t->AddReferencePoint ("0", 3, Vector (100, 100, 0), Vector (-100, 0, 0));
477  t->AddReferencePoint ("0", 4, Vector (0, 100, 0), Vector (0, 0, 0));
478  t->AddReferencePoint ("0", 4, Vector (0, 100, 0), Vector (0, -100, 0));
479  t->AddReferencePoint ("0", 5, Vector (0, 0, 0), Vector (0, 0, 0));
480  AddTestCase (t, TestCase::QUICK);
481  t = new Ns2MobilityHelperTest ("Bug 1219 testcase", Seconds (16));
482  t->SetTrace ("$node_(0) set X_ 0.0\n"
483  "$node_(0) set Y_ 0.0\n"
484  "$ns_ at 1.0 \"$node_(0) setdest 0 10 1\"\n"
485  "$ns_ at 6.0 \"$node_(0) setdest 0 -10 1\"\n"
486  );
487  // id t position velocity
488  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
489  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (0, 1, 0));
490  t->AddReferencePoint ("0", 6, Vector (0, 5, 0), Vector (0, -1, 0));
491  t->AddReferencePoint ("0", 16, Vector (0, -10, 0), Vector (0, 0, 0));
492  AddTestCase (t, TestCase::QUICK);
493  t = new Ns2MobilityHelperTest ("Bug 1059 testcase", Seconds (16));
494  t->SetTrace ("$node_(0) set X_ 10.0\r\n"
495  "$node_(0) set Y_ 0.0\r\n"
496  );
497  // id t position velocity
498  t->AddReferencePoint ("0", 0, Vector (10, 0, 0), Vector (0, 0, 0));
499  AddTestCase (t, TestCase::QUICK);
500  t = new Ns2MobilityHelperTest ("Bug 1301 testcase", Seconds (16));
501  t->SetTrace ("$node_(0) set X_ 10.0\n"
502  "$node_(0) set Y_ 0.0\n"
503  "$ns_ at 1.0 \"$node_(0) setdest 10 0 1\"\n"
504  );
505  // id t position velocity
506  // Moving to the current position must change nothing. No NaN
507  // speed must be.
508  t->AddReferencePoint ("0", 0, Vector (10, 0, 0), Vector (0, 0, 0));
509  AddTestCase (t, TestCase::QUICK);
510 
511  t = new Ns2MobilityHelperTest ("Bug 1316 testcase", Seconds (1000));
512  t->SetTrace ("$node_(0) set X_ 350.00000000000000\n"
513  "$node_(0) set Y_ 50.00000000000000\n"
514  "$ns_ at 50.00000000000000 \"$node_(0) setdest 400.00000000000000 50.00000000000000 1.00000000000000\"\n"
515  "$ns_ at 150.00000000000000 \"$node_(0) setdest 400.00000000000000 150.00000000000000 4.00000000000000\"\n"
516  "$ns_ at 300.00000000000000 \"$node_(0) setdest 250.00000000000000 150.00000000000000 3.00000000000000\"\n"
517  "$ns_ at 350.00000000000000 \"$node_(0) setdest 250.00000000000000 50.00000000000000 1.00000000000000\"\n"
518  "$ns_ at 600.00000000000000 \"$node_(0) setdest 250.00000000000000 1050.00000000000000 2.00000000000000\"\n"
519  "$ns_ at 900.00000000000000 \"$node_(0) setdest 300.00000000000000 650.00000000000000 2.50000000000000\"\n"
520  );
521  t->AddReferencePoint ("0", 0.000, Vector (350.000, 50.000, 0.000), Vector (0.000, 0.000, 0.000));
522  t->AddReferencePoint ("0", 50.000, Vector (350.000, 50.000, 0.000), Vector (1.000, 0.000, 0.000));
523  t->AddReferencePoint ("0", 100.000, Vector (400.000, 50.000, 0.000), Vector (0.000, 0.000, 0.000));
524  t->AddReferencePoint ("0", 150.000, Vector (400.000, 50.000, 0.000), Vector (0.000, 4.000, 0.000));
525  t->AddReferencePoint ("0", 175.000, Vector (400.000, 150.000, 0.000), Vector (0.000, 0.000, 0.000));
526  t->AddReferencePoint ("0", 300.000, Vector (400.000, 150.000, 0.000), Vector (-3.000, 0.000, 0.000));
527  t->AddReferencePoint ("0", 350.000, Vector (250.000, 150.000, 0.000), Vector (0.000, 0.000, 0.000));
528  t->AddReferencePoint ("0", 350.000, Vector (250.000, 150.000, 0.000), Vector (0.000, -1.000, 0.000));
529  t->AddReferencePoint ("0", 450.000, Vector (250.000, 50.000, 0.000), Vector (0.000, 0.000, 0.000));
530  t->AddReferencePoint ("0", 600.000, Vector (250.000, 50.000, 0.000), Vector (0.000, 2.000, 0.000));
531  t->AddReferencePoint ("0", 900.000, Vector (250.000, 650.000, 0.000), Vector (2.500, 0.000, 0.000));
532  t->AddReferencePoint ("0", 920.000, Vector (300.000, 650.000, 0.000), Vector (0.000, 0.000, 0.000));
533  AddTestCase (t, TestCase::QUICK);
534 
535  }
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
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:1342
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
#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:170
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
#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:285
encapsulates test code
Definition: test.h:1155
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:153
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:770
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:227
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:833
nodes
Definition: first.py:25
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:682
#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:168
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
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)
Sugar.
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:871
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:134
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:459
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:193
Every test case is supposed to:
void DoSetup()
Implementation to do any local setup required for this TestCase.
Fast test.
Definition: test.h:1160
Vector GetPosition(void) const
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:178
A network Node.
Definition: node.h:56
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
#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:903
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:819
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.
Vector GetVelocity(void) const