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)
119 return (time < o.
time);
131 m_timeLimit (timeLimit),
154 m_reference.push_back (r);
189 m_traceFile = CreateTempDirFilename (
"Ns2MobilityHelperTest.tcl");
190 std::ofstream of (m_traceFile.c_str ());
200 nodes.Create (m_nodeCount);
201 for (uint32_t i = 0; i < m_nodeCount; ++i)
203 std::ostringstream os;
214 std::stable_sort (m_reference.begin (), m_reference.end ());
215 while (m_nextRefPoint < m_reference.size () && m_reference[m_nextRefPoint].time ==
Seconds (0))
229 return IsStatusFailure ();
243 Vector pos =
mobility->GetPosition ();
244 Vector vel =
mobility->GetVelocity ();
247 if (m_nextRefPoint >= m_reference.size ())
284 if (CheckInitialPositions ())
306 SetDataDir (NS_TEST_SOURCEDIR);
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"
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 #"
335 t->
SetTrace (
"$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"");
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"
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"
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\"");
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");
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");
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");
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");
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");
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");
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"
520 t->
SetTrace (
"$node_(0) set X_ 10.0\r\n"
521 "$node_(0) set Y_ 0.0\r\n"
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"
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"
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));
Every test case is supposed to:
std::string m_traceFile
TMP trace file name.
bool CheckInitialPositions()
Check that all initial positions are correct.
void AddReferencePoint(const char *id, double sec, Vector const &p, Vector const &v)
Add next reference point.
void DoTeardown()
Implementation to do any local setup required for this TestCase.
void CourseChange(std::string context, Ptr< const MobilityModel > mobility)
Listen for course change events.
bool WriteTrace()
Dump NS-2 trace to tmp file.
std::string m_trace
Trace as string.
size_t m_nextRefPoint
Next reference point to be checked.
Time m_timeLimit
Test time limit.
std::vector< ReferencePoint > m_reference
Reference mobility.
void CreateNodes()
Create and name nodes.
void AddReferencePoint(ReferencePoint const &r)
Add next reference point.
void DoSetup()
Implementation to do any local setup required for this TestCase.
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)
Ns2MobilityHelperTest(std::string const &name, Time timeLimit, uint32_t nodes=1)
Create new test case.
virtual ~Ns2MobilityHelperTest()
Empty.
uint32_t m_nodeCount
Number of nodes used in the test.
Ns2MobilityHelperTestSuite()
Keep track of the current position and velocity of an object.
Vector GetVelocity(void) const
Vector GetPosition(void) const
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
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,...
static void Clear(void)
Clear the list of objects associated with names.
keep track of a set of node pointers.
Helper class which can read ns-2 movement files and configure nodes mobility.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
static void Run(void)
Run the simulation.
static Time Now(void)
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
make Callback use a separate empty type
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
void Connect(std::string path, const CallbackBase &cb)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#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.
#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.
#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
#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.
Ns2MobilityHelperTestSuite g_ns2TransmobilityHelperTestSuite
the test suite
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator<(const EventId &a, const EventId &b)
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...
bool AreVectorsEqual(Vector const &actual, Vector const &limit, double tol)
Single record in mobility reference.
std::string node
node ID as string, e.g. "1"
Vector pos
reference position
ReferencePoint(std::string const &id, Time t, Vector const &p, Vector const &v)
Constructor.
Vector vel
reference velocity