A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ns2-mobility-helper-test-suite.cc
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 namespace ns3 {
53 
54 // -----------------------------------------------------------------------------
55 // Testing
56 // -----------------------------------------------------------------------------
57 bool AreVectorsEqual (Vector const & actual, Vector const & limit, double tol)
58 {
59  if (actual.x > limit.x + tol || actual.x < limit.x - tol)
60  {
61  return false;
62  }
63  if (actual.y > limit.y + tol || actual.y < limit.y - tol)
64  {
65  return false;
66  }
67  if (actual.z > limit.z + tol || actual.z < limit.z - tol)
68  {
69  return false;
70  }
71  return true;
72 }
73 
82 {
83 public:
86  {
87  std::string node;
91 
92  ReferencePoint (std::string const & id, Time t, Vector const & p, Vector const & v)
93  : node (id),
94  time (t),
95  pos (p),
96  vel (v)
97  {
98  }
100  bool operator< (ReferencePoint const & o) const
101  {
102  return (time < o.time);
103  }
104  };
112  Ns2MobilityHelperTest (std::string const & name, Time timeLimit, uint32_t nodes = 1)
113  : TestCase (name),
114  m_timeLimit (timeLimit),
115  m_nodeCount (nodes),
116  m_nextRefPoint (0)
117  {
118  }
121  {
122  }
124  void SetTrace (std::string const & trace)
125  {
126  m_trace = trace;
127  }
130  {
131  m_reference.push_back (r);
132  }
134  void AddReferencePoint (const char * id, double sec, Vector const & p, Vector const & v)
135  {
136  AddReferencePoint (ReferencePoint (id, Seconds (sec), p, v));
137  }
138 
139 private:
143  uint32_t m_nodeCount;
145  std::string m_trace;
147  std::vector<ReferencePoint> m_reference;
151  std::string m_traceFile;
152 
153 private:
155  bool WriteTrace ()
156  {
157  m_traceFile = CreateTempDirFilename ("Ns2MobilityHelperTest.tcl");
158  std::ofstream of (m_traceFile.c_str ());
159  NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (of.is_open (), true, "Need to write tmp. file");
160  of << m_trace;
161  of.close ();
162  return false; // no errors
163  }
165  void CreateNodes ()
166  {
167  NodeContainer nodes;
168  nodes.Create (m_nodeCount);
169  for (uint32_t i = 0; i < m_nodeCount; ++i)
170  {
171  std::ostringstream os;
172  os << i;
173  Names::Add (os.str (), nodes.Get (i));
174  }
175  }
178  {
179  std::stable_sort (m_reference.begin (), m_reference.end ());
180  while (m_nextRefPoint < m_reference.size () && m_reference[m_nextRefPoint].time == Seconds (0))
181  {
183  Ptr<Node> node = Names::Find<Node> (rp.node);
184  NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (node, 0, "Can't find node with id " << rp.node);
186  NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (mob, 0, "Can't find mobility for node " << rp.node);
187 
188  double tol = 0.001;
189  NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (mob->GetPosition (), rp.pos, tol), true, "Initial position mismatch for node " << rp.node);
190  NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (mob->GetVelocity (), rp.vel, tol), true, "Initial velocity mismatch for node " << rp.node);
191 
192  m_nextRefPoint++;
193  }
194  return IsStatusFailure ();
195  }
197  void CourseChange (std::string context, Ptr<const MobilityModel> mobility)
198  {
199  Time time = Simulator::Now ();
200  Ptr<Node> node = mobility->GetObject<Node> ();
201  NS_ASSERT (node);
202  std::string id = Names::FindName (node);
203  NS_ASSERT (!id.empty ());
204  Vector pos = mobility->GetPosition ();
205  Vector vel = mobility->GetVelocity ();
206 
207  NS_TEST_EXPECT_MSG_LT (m_nextRefPoint, m_reference.size (), "Not enough reference points");
208  if (m_nextRefPoint >= m_reference.size ())
209  {
210  return;
211  }
212 
213  ReferencePoint const & ref = m_reference [m_nextRefPoint++];
214  NS_TEST_EXPECT_MSG_EQ (time, ref.time, "Time mismatch");
215  NS_TEST_EXPECT_MSG_EQ (id, ref.node, "Node ID mismatch at time " << time.GetSeconds () << " s");
216 
217  double tol = 0.001;
218  NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (pos, ref.pos, tol), true, "Position mismatch at time " << time.GetSeconds () << " s for node " << id);
219  NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (vel, ref.vel, tol), true, "Velocity mismatch at time " << time.GetSeconds () << " s for node " << id);
220  }
221 
222  void DoSetup ()
223  {
224  CreateNodes ();
225  }
226 
227  void DoTeardown ()
228  {
229  Names::Clear ();
230  std::remove (m_traceFile.c_str ());
232  }
233 
235  void DoRun ()
236  {
237  NS_TEST_ASSERT_MSG_EQ (m_trace.empty (), false, "Need trace");
238  NS_TEST_ASSERT_MSG_EQ (m_reference.empty (), false, "Need reference");
239 
240  if (WriteTrace ())
241  {
242  return;
243  }
244  Ns2MobilityHelper mobility (m_traceFile);
245  mobility.Install ();
246  if (CheckInitialPositions ())
247  {
248  return;
249  }
250  Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
253  Simulator::Run ();
254  }
255 };
256 
259 {
260 public:
261  Ns2MobilityHelperTestSuite () : TestSuite ("mobility-ns2-trace-helper", UNIT)
262  {
263  SetDataDir (NS_TEST_SOURCEDIR);
264 
265  // to be used as temporary variable for test cases.
266  // Note that test suite takes care of deleting all test cases.
267  Ns2MobilityHelperTest * t (0);
268 
269  // Initial position
270  t = new Ns2MobilityHelperTest ("initial position", Seconds (1));
271  t->SetTrace ("$node_(0) set X_ 1.0\n"
272  "$node_(0) set Y_ 2.0\n"
273  "$node_(0) set Z_ 3.0\n"
274  );
275  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
276  AddTestCase (t, TestCase::QUICK);
277 
278  // Check parsing comments, empty lines and no EOF at the end of file
279  t = new Ns2MobilityHelperTest ("comments", Seconds (1));
280  t->SetTrace ("# comment\n"
281  "\n\n" // empty lines
282  "$node_(0) set X_ 1.0 # comment \n"
283  "$node_(0) set Y_ 2.0 ### \n"
284  "$node_(0) set Z_ 3.0 # $node_(0) set Z_ 3.0\n"
285  "#$node_(0) set Z_ 100 #"
286  );
287  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
288  AddTestCase (t, TestCase::QUICK);
289 
290  // Simple setdest. Arguments are interpreted as x, y, speed by default
291  t = new Ns2MobilityHelperTest ("simple setdest", Seconds (10));
292  t->SetTrace ("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"");
293  // id t position velocity
294  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
295  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0));
296  t->AddReferencePoint ("0", 6, Vector (25, 0, 0), Vector (0, 0, 0));
297  AddTestCase (t, TestCase::QUICK);
298 
299  // Several set and setdest. Arguments are interpreted as x, y, speed by default
300  t = new Ns2MobilityHelperTest ("square setdest", Seconds (6));
301  t->SetTrace ("$node_(0) set X_ 0.0\n"
302  "$node_(0) set Y_ 0.0\n"
303  "$ns_ at 1.0 \"$node_(0) setdest 5 0 5\"\n"
304  "$ns_ at 2.0 \"$node_(0) setdest 5 5 5\"\n"
305  "$ns_ at 3.0 \"$node_(0) setdest 0 5 5\"\n"
306  "$ns_ at 4.0 \"$node_(0) setdest 0 0 5\"\n"
307  );
308  // id t position velocity
309  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
310  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0));
311  t->AddReferencePoint ("0", 2, Vector (5, 0, 0), Vector (0, 0, 0));
312  t->AddReferencePoint ("0", 2, Vector (5, 0, 0), Vector (0, 5, 0));
313  t->AddReferencePoint ("0", 3, Vector (5, 5, 0), Vector (0, 0, 0));
314  t->AddReferencePoint ("0", 3, Vector (5, 5, 0), Vector (-5, 0, 0));
315  t->AddReferencePoint ("0", 4, Vector (0, 5, 0), Vector (0, 0, 0));
316  t->AddReferencePoint ("0", 4, Vector (0, 5, 0), Vector (0, -5, 0));
317  t->AddReferencePoint ("0", 5, Vector (0, 0, 0), Vector (0, 0, 0));
318  AddTestCase (t, TestCase::QUICK);
319 
320  // Copy of previous test case but with the initial positions at
321  // the end of the trace rather than at the beginning.
322  //
323  // Several set and setdest. Arguments are interpreted as x, y, speed by default
324  t = new Ns2MobilityHelperTest ("square setdest (initial positions at end)", Seconds (6));
325  t->SetTrace ("$ns_ at 1.0 \"$node_(0) setdest 15 10 5\"\n"
326  "$ns_ at 2.0 \"$node_(0) setdest 15 15 5\"\n"
327  "$ns_ at 3.0 \"$node_(0) setdest 10 15 5\"\n"
328  "$ns_ at 4.0 \"$node_(0) setdest 10 10 5\"\n"
329  "$node_(0) set X_ 10.0\n"
330  "$node_(0) set Y_ 10.0\n"
331  );
332  // id t position velocity
333  t->AddReferencePoint ("0", 0, Vector (10, 10, 0), Vector (0, 0, 0));
334  t->AddReferencePoint ("0", 1, Vector (10, 10, 0), Vector (5, 0, 0));
335  t->AddReferencePoint ("0", 2, Vector (15, 10, 0), Vector (0, 0, 0));
336  t->AddReferencePoint ("0", 2, Vector (15, 10, 0), Vector (0, 5, 0));
337  t->AddReferencePoint ("0", 3, Vector (15, 15, 0), Vector (0, 0, 0));
338  t->AddReferencePoint ("0", 3, Vector (15, 15, 0), Vector (-5, 0, 0));
339  t->AddReferencePoint ("0", 4, Vector (10, 15, 0), Vector (0, 0, 0));
340  t->AddReferencePoint ("0", 4, Vector (10, 15, 0), Vector (0, -5, 0));
341  t->AddReferencePoint ("0", 5, Vector (10, 10, 0), Vector (0, 0, 0));
342  AddTestCase (t, TestCase::QUICK);
343 
344  // Scheduled set position
345  t = new Ns2MobilityHelperTest ("scheduled set position", Seconds (2));
346  t->SetTrace ("$ns_ at 1.0 \"$node_(0) set X_ 10\"\n"
347  "$ns_ at 1.0 \"$node_(0) set Z_ 10\"\n"
348  "$ns_ at 1.0 \"$node_(0) set Y_ 10\"");
349  // id t position velocity
350  t->AddReferencePoint ("0", 1, Vector (10, 0, 0), Vector (0, 0, 0));
351  t->AddReferencePoint ("0", 1, Vector (10, 0, 10), Vector (0, 0, 0));
352  t->AddReferencePoint ("0", 1, Vector (10, 10, 10), Vector (0, 0, 0));
353  AddTestCase (t, TestCase::QUICK);
354 
355  // Malformed lines
356  t = new Ns2MobilityHelperTest ("malformed lines", Seconds (2));
357  t->SetTrace ("$node() set X_ 1 # node id is not present\n"
358  "$node # incoplete line\"\n"
359  "$node this line is not correct\n"
360  "$node_(0) set X_ 1 # line OK \n"
361  "$node_(0) set Y_ 2 # line OK \n"
362  "$node_(0) set Z_ 3 # line OK \n"
363  "$ns_ at \"$node_(0) setdest 4 4 4\" # time not present\n"
364  "$ns_ at 1 \"$node_(0) setdest 2 2 1 \" # line OK \n");
365  // id t position velocity
366  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
367  t->AddReferencePoint ("0", 1, Vector (1, 2, 3), Vector (1, 0, 0));
368  t->AddReferencePoint ("0", 2, Vector (2, 2, 3), Vector (0, 0, 0));
369  AddTestCase (t, TestCase::QUICK);
370 
371  // Non possible values
372  t = new Ns2MobilityHelperTest ("non possible values", Seconds (2));
373  t->SetTrace ("$node_(0) set X_ 1 # line OK \n"
374  "$node_(0) set Y_ 2 # line OK \n"
375  "$node_(0) set Z_ 3 # line OK \n"
376  "$node_(-22) set Y_ 3 # node id not correct\n"
377  "$node_(3.3) set Y_ 1111 # node id not correct\n"
378  "$ns_ at sss \"$node_(0) setdest 5 5 5\" # time is not a number\n"
379  "$ns_ at 1 \"$node_(0) setdest 2 2 1\" # line OK \n"
380  "$ns_ at 1 \"$node_(0) setdest 2 2 -1\" # negative speed is not correct\n"
381  "$ns_ at 1 \"$node_(0) setdest 2 2 sdfs\" # speed is not a number\n"
382  "$ns_ at 1 \"$node_(0) setdest 2 2 s232dfs\" # speed is not a number\n"
383  "$ns_ at 1 \"$node_(0) setdest 233 2.. s232dfs\" # more than one non numbers\n"
384  "$ns_ at -12 \"$node_(0) setdest 11 22 33\" # time should not be negative\n");
385  // id t position velocity
386  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
387  t->AddReferencePoint ("0", 1, Vector (1, 2, 3), Vector (1, 0, 0));
388  t->AddReferencePoint ("0", 2, Vector (2, 2, 3), Vector (0, 0, 0));
389  AddTestCase (t, TestCase::QUICK);
390 
391  // More than one node
392  t = new Ns2MobilityHelperTest ("few nodes, combinations of set and setdest", Seconds (10), 3);
393  t->SetTrace ("$node_(0) set X_ 1.0\n"
394  "$node_(0) set Y_ 2.0\n"
395  "$node_(0) set Z_ 3.0\n"
396  "$ns_ at 1.0 \"$node_(1) setdest 25 0 5\"\n"
397  "$node_(2) set X_ 0.0\n"
398  "$node_(2) set Y_ 0.0\n"
399  "$ns_ at 1.0 \"$node_(2) setdest 5 0 5\"\n"
400  "$ns_ at 2.0 \"$node_(2) setdest 5 5 5\"\n"
401  "$ns_ at 3.0 \"$node_(2) setdest 0 5 5\"\n"
402  "$ns_ at 4.0 \"$node_(2) setdest 0 0 5\"\n");
403  // id t position velocity
404  t->AddReferencePoint ("0", 0, Vector (1, 2, 3), Vector (0, 0, 0));
405  t->AddReferencePoint ("1", 0, Vector (0, 0, 0), Vector (0, 0, 0));
406  t->AddReferencePoint ("1", 1, Vector (0, 0, 0), Vector (5, 0, 0));
407  t->AddReferencePoint ("1", 6, Vector (25, 0, 0), Vector (0, 0, 0));
408  t->AddReferencePoint ("2", 0, Vector (0, 0, 0), Vector (0, 0, 0));
409  t->AddReferencePoint ("2", 1, Vector (0, 0, 0), Vector (5, 0, 0));
410  t->AddReferencePoint ("2", 2, Vector (5, 0, 0), Vector (0, 0, 0));
411  t->AddReferencePoint ("2", 2, Vector (5, 0, 0), Vector (0, 5, 0));
412  t->AddReferencePoint ("2", 3, Vector (5, 5, 0), Vector (0, 0, 0));
413  t->AddReferencePoint ("2", 3, Vector (5, 5, 0), Vector (-5, 0, 0));
414  t->AddReferencePoint ("2", 4, Vector (0, 5, 0), Vector (0, 0, 0));
415  t->AddReferencePoint ("2", 4, Vector (0, 5, 0), Vector (0, -5, 0));
416  t->AddReferencePoint ("2", 5, Vector (0, 0, 0), Vector (0, 0, 0));
417  AddTestCase (t, TestCase::QUICK);
418 
419  // Test for Speed == 0, that acts as stop the node.
420  t = new Ns2MobilityHelperTest ("setdest with speed cero", Seconds (10));
421  t->SetTrace ("$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"\n"
422  "$ns_ at 7.0 \"$node_(0) setdest 11 22 0\"\n");
423  // id t position velocity
424  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
425  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (5, 0, 0));
426  t->AddReferencePoint ("0", 6, Vector (25, 0, 0), Vector (0, 0, 0));
427  t->AddReferencePoint ("0", 7, Vector (25, 0, 0), Vector (0, 0, 0));
428  AddTestCase (t, TestCase::QUICK);
429 
430 
431  // Test negative positions
432  t = new Ns2MobilityHelperTest ("test negative positions", Seconds (10));
433  t->SetTrace ("$node_(0) set X_ -1.0\n"
434  "$node_(0) set Y_ 0\n"
435  "$ns_ at 1.0 \"$node_(0) setdest 0 0 1\"\n"
436  "$ns_ at 2.0 \"$node_(0) setdest 0 -1 1\"\n");
437  // id t position velocity
438  t->AddReferencePoint ("0", 0, Vector (-1, 0, 0), Vector (0, 0, 0));
439  t->AddReferencePoint ("0", 1, Vector (-1, 0, 0), Vector (1, 0, 0));
440  t->AddReferencePoint ("0", 2, Vector (0, 0, 0), Vector (0, 0, 0));
441  t->AddReferencePoint ("0", 2, Vector (0, 0, 0), Vector (0, -1, 0));
442  t->AddReferencePoint ("0", 3, Vector (0, -1, 0), Vector (0, 0, 0));
443  AddTestCase (t, TestCase::QUICK);
444 
445  // Sqare setdest with values in the form 1.0e+2
446  t = new Ns2MobilityHelperTest ("Foalt numbers in 1.0e+2 format", Seconds (6));
447  t->SetTrace ("$node_(0) set X_ 0.0\n"
448  "$node_(0) set Y_ 0.0\n"
449  "$ns_ at 1.0 \"$node_(0) setdest 1.0e+2 0 1.0e+2\"\n"
450  "$ns_ at 2.0 \"$node_(0) setdest 1.0e+2 1.0e+2 1.0e+2\"\n"
451  "$ns_ at 3.0 \"$node_(0) setdest 0 1.0e+2 1.0e+2\"\n"
452  "$ns_ at 4.0 \"$node_(0) setdest 0 0 1.0e+2\"\n");
453  // id t position velocity
454  t->AddReferencePoint ("0", 0, Vector (0, 0, 0), Vector (0, 0, 0));
455  t->AddReferencePoint ("0", 1, Vector (0, 0, 0), Vector (100, 0, 0));
456  t->AddReferencePoint ("0", 2, Vector (100, 0, 0), Vector (0, 0, 0));
457  t->AddReferencePoint ("0", 2, Vector (100, 0, 0), Vector (0, 100, 0));
458  t->AddReferencePoint ("0", 3, Vector (100, 100, 0), Vector (0, 0, 0));
459  t->AddReferencePoint ("0", 3, Vector (100, 100, 0), Vector (-100, 0, 0));
460  t->AddReferencePoint ("0", 4, Vector (0, 100, 0), Vector (0, 0, 0));
461  t->AddReferencePoint ("0", 4, Vector (0, 100, 0), Vector (0, -100, 0));
462  t->AddReferencePoint ("0", 5, Vector (0, 0, 0), Vector (0, 0, 0));
463  AddTestCase (t, TestCase::QUICK);
464  t = new Ns2MobilityHelperTest ("Bug 1219 testcase", Seconds (16));
465  t->SetTrace ("$node_(0) set X_ 0.0\n"
466  "$node_(0) set Y_ 0.0\n"
467  "$ns_ at 1.0 \"$node_(0) setdest 0 10 1\"\n"
468  "$ns_ at 6.0 \"$node_(0) setdest 0 -10 1\"\n"
469  );
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 (0, 1, 0));
473  t->AddReferencePoint ("0", 6, Vector (0, 5, 0), Vector (0, -1, 0));
474  t->AddReferencePoint ("0", 16, Vector (0, -10, 0), Vector (0, 0, 0));
475  AddTestCase (t, TestCase::QUICK);
476  t = new Ns2MobilityHelperTest ("Bug 1059 testcase", Seconds (16));
477  t->SetTrace ("$node_(0) set X_ 10.0\r\n"
478  "$node_(0) set Y_ 0.0\r\n"
479  );
480  // id t position velocity
481  t->AddReferencePoint ("0", 0, Vector (10, 0, 0), Vector (0, 0, 0));
482  AddTestCase (t, TestCase::QUICK);
483  t = new Ns2MobilityHelperTest ("Bug 1301 testcase", Seconds (16));
484  t->SetTrace ("$node_(0) set X_ 10.0\n"
485  "$node_(0) set Y_ 0.0\n"
486  "$ns_ at 1.0 \"$node_(0) setdest 10 0 1\"\n"
487  );
488  // id t position velocity
489  // Moving to the current position must change nothing. No NaN
490  // speed must be.
491  t->AddReferencePoint ("0", 0, Vector (10, 0, 0), Vector (0, 0, 0));
492  AddTestCase (t, TestCase::QUICK);
493 
494  t = new Ns2MobilityHelperTest ("Bug 1316 testcase", Seconds (1000));
495  t->SetTrace ("$node_(0) set X_ 350.00000000000000\n"
496  "$node_(0) set Y_ 50.00000000000000\n"
497  "$ns_ at 50.00000000000000 \"$node_(0) setdest 400.00000000000000 50.00000000000000 1.00000000000000\"\n"
498  "$ns_ at 150.00000000000000 \"$node_(0) setdest 400.00000000000000 150.00000000000000 4.00000000000000\"\n"
499  "$ns_ at 300.00000000000000 \"$node_(0) setdest 250.00000000000000 150.00000000000000 3.00000000000000\"\n"
500  "$ns_ at 350.00000000000000 \"$node_(0) setdest 250.00000000000000 50.00000000000000 1.00000000000000\"\n"
501  "$ns_ at 600.00000000000000 \"$node_(0) setdest 250.00000000000000 1050.00000000000000 2.00000000000000\"\n"
502  "$ns_ at 900.00000000000000 \"$node_(0) setdest 300.00000000000000 650.00000000000000 2.50000000000000\"\n"
503  );
504  t->AddReferencePoint ("0", 0.000, Vector (350.000, 50.000, 0.000), Vector (0.000, 0.000, 0.000));
505  t->AddReferencePoint ("0", 50.000, Vector (350.000, 50.000, 0.000), Vector (1.000, 0.000, 0.000));
506  t->AddReferencePoint ("0", 100.000, Vector (400.000, 50.000, 0.000), Vector (0.000, 0.000, 0.000));
507  t->AddReferencePoint ("0", 150.000, Vector (400.000, 50.000, 0.000), Vector (0.000, 4.000, 0.000));
508  t->AddReferencePoint ("0", 175.000, Vector (400.000, 150.000, 0.000), Vector (0.000, 0.000, 0.000));
509  t->AddReferencePoint ("0", 300.000, Vector (400.000, 150.000, 0.000), Vector (-3.000, 0.000, 0.000));
510  t->AddReferencePoint ("0", 350.000, Vector (250.000, 150.000, 0.000), Vector (0.000, 0.000, 0.000));
511  t->AddReferencePoint ("0", 350.000, Vector (250.000, 150.000, 0.000), Vector (0.000, -1.000, 0.000));
512  t->AddReferencePoint ("0", 450.000, Vector (250.000, 50.000, 0.000), Vector (0.000, 0.000, 0.000));
513  t->AddReferencePoint ("0", 600.000, Vector (250.000, 50.000, 0.000), Vector (0.000, 2.000, 0.000));
514  t->AddReferencePoint ("0", 900.000, Vector (250.000, 650.000, 0.000), Vector (2.500, 0.000, 0.000));
515  t->AddReferencePoint ("0", 920.000, Vector (300.000, 650.000, 0.000), Vector (0.000, 0.000, 0.000));
516  AddTestCase (t, TestCase::QUICK);
517 
518  }
519 } g_ns2TransmobilityHelperTestSuite;
520 
521 
522 } // namespace ns3
Ns2MobilityHelperTest(std::string const &name, Time timeLimit, uint32_t nodes=1)
void AddReferencePoint(ReferencePoint const &r)
Add next reference point.
keep track of time unit.
Definition: nstime.h:149
A suite of tests to run.
Definition: test.h:962
#define NS_ASSERT(condition)
Definition: assert.h:64
static void Run(void)
Definition: simulator.cc:157
Vector GetPosition(void) const
size_t m_nextRefPoint
Next reference point to be checked.
void DoTeardown()
Implementation to do any local setup required for this test case.
encapsulates test code
Definition: test.h:834
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:728
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
Definition: test.cc:354
a 3d vector
Definition: vector.h:31
Vector GetVelocity(void) const
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
Definition: names.cc:615
Keep track of the current position and velocity of an object.
double GetSeconds(void) const
Definition: nstime.h:262
static void Clear(void)
Definition: names.cc:678
Helper class which can read ns-2 movement files and configure nodes mobility.
make Callback use a separate empty type
Definition: empty.h:8
void CourseChange(std::string context, Ptr< const MobilityModel > mobility)
Listen for course change events.
std::string node
node ID as string, e.g. "1"
std::string m_traceFile
TMP trace file name.
void CreateNodes()
Create and name nodes.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:502
void DoSetup()
Implementation to do any local setup required for this test case.
static void Destroy(void)
Definition: simulator.cc:121
keep track of a set of node pointers.
bool IsStatusFailure(void) const
Definition: test.cc:323
static Time Now(void)
Definition: simulator.cc:179
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
bool WriteTrace()
Dump NS-2 trace to tmp file.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
static void Stop(void)
Definition: simulator.cc:164
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:56
std::string m_trace
Trace as string.
void SetDataDir(std::string directory)
Definition: test.cc:336
uint32_t m_nodeCount
Number of nodes used in the test.
static std::string FindName(Ptr< Object > object)
Definition: names.cc:664
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
bool CheckInitialPositions()
Check that all initial positions are correct.
bool operator<(ReferencePoint const &o) const
Sort by timestamp.
Ptr< T > GetObject(void) const
Definition: object.h:332
void AddReferencePoint(const char *id, double sec, Vector const &p, Vector const &v)
Sugar.
void SetTrace(std::string const &trace)
Set NS-2 trace to read as single large string (don't forget to add \n and quote "'s) ...
std::vector< ReferencePoint > m_reference
Reference mobility.