42 #include "ns3/simulator.h"
43 #include "ns3/node-list.h"
45 #include "ns3/constant-velocity-mobility-model.h"
47 #include "ns3/node-container.h"
48 #include "ns3/names.h"
49 #include "ns3/config.h"
50 #include "ns3/ns2-mobility-helper.h"
61 if (actual.x > limit.x + tol || actual.x < limit.x - tol)
65 if (actual.y > limit.y + tol || actual.y < limit.y - tol)
69 if (actual.z > limit.z + tol || actual.z < limit.z - tol)
104 return (time < o.
time);
116 m_timeLimit (timeLimit),
133 m_reference.push_back (r);
159 m_traceFile = CreateTempDirFilename (
"Ns2MobilityHelperTest.tcl");
160 std::ofstream of (m_traceFile.c_str ());
170 nodes.
Create (m_nodeCount);
171 for (uint32_t i = 0; i < m_nodeCount; ++i)
173 std::ostringstream os;
181 std::stable_sort (m_reference.begin (), m_reference.end ());
182 while (m_nextRefPoint < m_reference.size () && m_reference[m_nextRefPoint].time ==
Seconds (0))
196 return IsStatusFailure ();
210 if (m_nextRefPoint >= m_reference.size ())
247 if (CheckInitialPositions ())
264 SetDataDir (NS_TEST_SOURCEDIR);
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"
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 #"
293 t->
SetTrace (
"$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"");
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"
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"
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\"");
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");
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");
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");
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");
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");
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");
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"
478 t->
SetTrace (
"$node_(0) set X_ 10.0\r\n"
479 "$node_(0) set Y_ 0.0\r\n"
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"
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"
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));
Simulation virtual time values and global simulation resolution.
bool AreVectorsEqual(Vector const &actual, Vector const &limit, double tol)
std::vector< ReferencePoint > m_reference
Reference mobility.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Vector GetPosition(void) const
Ns2MobilityHelperTestSuite()
void Connect(std::string path, const CallbackBase &cb)
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
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.
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.
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.
Helper class which can read ns-2 movement files and configure nodes mobility.
make Callback use a separate empty type
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...
#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.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
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.
virtual ~Ns2MobilityHelperTest()
Empty.
Vector pos
reference position
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
bool operator<(const int64x64_t &lhs, const int64x64_t &rhs)
Less than operator.
std::string node
node ID as string, e.g. "1"
Time m_timeLimit
Test time limit.
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.
Every test case is supposed to:
void DoSetup()
Implementation to do any local setup required for this TestCase.
Vector vel
reference velocity
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Time Seconds(double value)
Construct a Time in the indicated unit.
#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report if not.
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...
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.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.