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