39 #include "ns3/config.h"
40 #include "ns3/constant-velocity-mobility-model.h"
42 #include "ns3/names.h"
43 #include "ns3/node-container.h"
44 #include "ns3/node-list.h"
46 #include "ns3/ns2-mobility-helper.h"
47 #include "ns3/simulator.h"
62 if (actual.x > limit.x + tol || actual.x < limit.x - tol)
66 if (actual.y > limit.y + tol || actual.y < limit.y - tol)
70 if (actual.z > limit.z + tol || actual.z < limit.z - tol)
121 return time < o.
time;
134 m_timeLimit(timeLimit),
160 m_reference.push_back(r);
196 m_traceFile = CreateTempDirFilename(
"Ns2MobilityHelperTest.tcl");
197 std::ofstream of(m_traceFile);
209 for (uint32_t i = 0; i < m_nodeCount; ++i)
211 std::ostringstream os;
223 std::stable_sort(m_reference.begin(), m_reference.end());
224 while (m_nextRefPoint < m_reference.size() &&
225 m_reference[m_nextRefPoint].time ==
Seconds(0))
231 "Can't find node with id " << rp.
node);
235 "Can't find mobility for node " << rp.
node);
240 "Initial position mismatch for node " << rp.
node);
243 "Initial velocity mismatch for node " << rp.
node);
247 return IsStatusFailure();
262 Vector pos =
mobility->GetPosition();
263 Vector vel =
mobility->GetVelocity();
266 if (m_nextRefPoint >= m_reference.size())
275 "Node ID mismatch at time " << time.
GetSeconds() <<
" s");
280 "Position mismatch at time " << time.
GetSeconds() <<
" s for node "
284 "Velocity mismatch at time " << time.
GetSeconds() <<
" s for node "
311 if (CheckInitialPositions())
331 :
TestSuite(
"mobility-ns2-trace-helper", UNIT)
333 SetDataDir(NS_TEST_SOURCEDIR);
341 t->
SetTrace(
"$node_(0) set X_ 1.0\n"
342 "$node_(0) set Y_ 2.0\n"
343 "$node_(0) set Z_ 3.0\n");
351 "$node_(0) set X_ 1.0 # comment \n"
352 "$node_(0) set Y_ 2.0 ### \n"
353 "$node_(0) set Z_ 3.0 # $node_(0) set Z_ 3.0\n"
354 "#$node_(0) set Z_ 100 #");
360 t->
SetTrace(
"$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"");
369 t->
SetTrace(
"$node_(0) set X_ 0.0\n"
370 "$node_(0) set Y_ 0.0\n"
371 "$ns_ at 1.0 \"$node_(0) setdest 5 0 5\"\n"
372 "$ns_ at 2.0 \"$node_(0) setdest 5 5 5\"\n"
373 "$ns_ at 3.0 \"$node_(0) setdest 0 5 5\"\n"
374 "$ns_ at 4.0 \"$node_(0) setdest 0 0 5\"\n");
392 t->
SetTrace(
"$ns_ at 1.0 \"$node_(0) setdest 15 10 5\"\n"
393 "$ns_ at 2.0 \"$node_(0) setdest 15 15 5\"\n"
394 "$ns_ at 3.0 \"$node_(0) setdest 10 15 5\"\n"
395 "$ns_ at 4.0 \"$node_(0) setdest 10 10 5\"\n"
396 "$node_(0) set X_ 10.0\n"
397 "$node_(0) set Y_ 10.0\n");
412 t->
SetTrace(
"$ns_ at 1.0 \"$node_(0) set X_ 10\"\n"
413 "$ns_ at 1.0 \"$node_(0) set Z_ 10\"\n"
414 "$ns_ at 1.0 \"$node_(0) set Y_ 10\"");
423 t->
SetTrace(
"$node() set X_ 1 # node id is not present\n"
424 "$node # incoplete line\"\n"
425 "$node this line is not correct\n"
426 "$node_(0) set X_ 1 # line OK \n"
427 "$node_(0) set Y_ 2 # line OK \n"
428 "$node_(0) set Z_ 3 # line OK \n"
429 "$ns_ at \"$node_(0) setdest 4 4 4\" # time not present\n"
430 "$ns_ at 1 \"$node_(0) setdest 2 2 1 \" # line OK \n");
440 "$node_(0) set X_ 1 # line OK \n"
441 "$node_(0) set Y_ 2 # line OK \n"
442 "$node_(0) set Z_ 3 # line OK \n"
443 "$node_(-22) set Y_ 3 # node id not correct\n"
444 "$node_(3.3) set Y_ 1111 # node id not correct\n"
445 "$ns_ at sss \"$node_(0) setdest 5 5 5\" # time is not a number\n"
446 "$ns_ at 1 \"$node_(0) setdest 2 2 1\" # line OK \n"
447 "$ns_ at 1 \"$node_(0) setdest 2 2 -1\" # negative speed is not correct\n"
448 "$ns_ at 1 \"$node_(0) setdest 2 2 sdfs\" # speed is not a number\n"
449 "$ns_ at 1 \"$node_(0) setdest 2 2 s232dfs\" # speed is not a number\n"
450 "$ns_ at 1 \"$node_(0) setdest 233 2.. s232dfs\" # more than one non numbers\n"
451 "$ns_ at -12 \"$node_(0) setdest 11 22 33\" # time should not be negative\n");
460 t->
SetTrace(
"$node_(0) set X_ 1.0\n"
461 "$node_(0) set Y_ 2.0\n"
462 "$node_(0) set Z_ 3.0\n"
463 "$ns_ at 1.0 \"$node_(1) setdest 25 0 5\"\n"
464 "$node_(2) set X_ 0.0\n"
465 "$node_(2) set Y_ 0.0\n"
466 "$ns_ at 1.0 \"$node_(2) setdest 5 0 5\"\n"
467 "$ns_ at 2.0 \"$node_(2) setdest 5 5 5\"\n"
468 "$ns_ at 3.0 \"$node_(2) setdest 0 5 5\"\n"
469 "$ns_ at 4.0 \"$node_(2) setdest 0 0 5\"\n");
488 t->
SetTrace(
"$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"\n"
489 "$ns_ at 7.0 \"$node_(0) setdest 11 22 0\"\n");
499 t->
SetTrace(
"$node_(0) set X_ -1.0\n"
500 "$node_(0) set Y_ 0\n"
501 "$ns_ at 1.0 \"$node_(0) setdest 0 0 1\"\n"
502 "$ns_ at 2.0 \"$node_(0) setdest 0 -1 1\"\n");
513 t->
SetTrace(
"$node_(0) set X_ 0.0\n"
514 "$node_(0) set Y_ 0.0\n"
515 "$ns_ at 1.0 \"$node_(0) setdest 1.0e+2 0 1.0e+2\"\n"
516 "$ns_ at 2.0 \"$node_(0) setdest 1.0e+2 1.0e+2 1.0e+2\"\n"
517 "$ns_ at 3.0 \"$node_(0) setdest 0 1.0e+2 1.0e+2\"\n"
518 "$ns_ at 4.0 \"$node_(0) setdest 0 0 1.0e+2\"\n");
531 t->
SetTrace(
"$node_(0) set X_ 0.0\n"
532 "$node_(0) set Y_ 0.0\n"
533 "$ns_ at 1.0 \"$node_(0) setdest 0 10 1\"\n"
534 "$ns_ at 6.0 \"$node_(0) setdest 0 -10 1\"\n");
542 t->
SetTrace(
"$node_(0) set X_ 10.0\r\n"
543 "$node_(0) set Y_ 0.0\r\n");
548 t->
SetTrace(
"$node_(0) set X_ 10.0\n"
549 "$node_(0) set Y_ 0.0\n"
550 "$ns_ at 1.0 \"$node_(0) setdest 10 0 1\"\n");
558 t->
SetTrace(
"$node_(0) set X_ 350.00000000000000\n"
559 "$node_(0) set Y_ 50.00000000000000\n"
560 "$ns_ at 50.00000000000000 \"$node_(0) setdest 400.00000000000000 "
561 "50.00000000000000 1.00000000000000\"\n"
562 "$ns_ at 150.00000000000000 \"$node_(0) setdest 400.00000000000000 "
563 "150.00000000000000 4.00000000000000\"\n"
564 "$ns_ at 300.00000000000000 \"$node_(0) setdest 250.00000000000000 "
565 "150.00000000000000 3.00000000000000\"\n"
566 "$ns_ at 350.00000000000000 \"$node_(0) setdest 250.00000000000000 "
567 "50.00000000000000 1.00000000000000\"\n"
568 "$ns_ at 600.00000000000000 \"$node_(0) setdest 250.00000000000000 "
569 "1050.00000000000000 2.00000000000000\"\n"
570 "$ns_ at 900.00000000000000 \"$node_(0) setdest 300.00000000000000 "
571 "650.00000000000000 2.50000000000000\"\n");
574 Vector(350.000, 50.000, 0.000),
575 Vector(0.000, 0.000, 0.000));
578 Vector(350.000, 50.000, 0.000),
579 Vector(1.000, 0.000, 0.000));
582 Vector(400.000, 50.000, 0.000),
583 Vector(0.000, 0.000, 0.000));
586 Vector(400.000, 50.000, 0.000),
587 Vector(0.000, 4.000, 0.000));
590 Vector(400.000, 150.000, 0.000),
591 Vector(0.000, 0.000, 0.000));
594 Vector(400.000, 150.000, 0.000),
595 Vector(-3.000, 0.000, 0.000));
598 Vector(250.000, 150.000, 0.000),
599 Vector(0.000, 0.000, 0.000));
602 Vector(250.000, 150.000, 0.000),
603 Vector(0.000, -1.000, 0.000));
606 Vector(250.000, 50.000, 0.000),
607 Vector(0.000, 0.000, 0.000));
610 Vector(250.000, 50.000, 0.000),
611 Vector(0.000, 2.000, 0.000));
614 Vector(250.000, 650.000, 0.000),
615 Vector(2.500, 0.000, 0.000));
618 Vector(300.000, 650.000, 0.000),
619 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, const Vector &p, const Vector &v)
Add next reference point.
void CourseChange(std::string context, Ptr< const MobilityModel > mobility)
Listen for course change events.
void AddReferencePoint(const ReferencePoint &r)
Add next reference point.
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 DoTeardown() override
Implementation to do any local setup required for this TestCase.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
~Ns2MobilityHelperTest() override
Empty.
void SetTrace(const std::string &trace)
Set NS-2 trace to read as single large string (don't forget to add \n and quote "'s)
Ns2MobilityHelperTest(const std::string &name, Time timeLimit, uint32_t nodes=1)
Create new test case.
uint32_t m_nodeCount
Number of nodes used in the test.
void CreateNodes() const
Create and name nodes.
Ns2MobilityHelperTestSuite()
Keep track of the current position and velocity of an object.
Vector GetVelocity() const
Vector GetPosition() const
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
static void Clear()
Clear the list of objects associated with names.
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,...
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Helper class which can read ns-2 movement files and configure nodes mobility.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
#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.
Ns2MobilityHelperTestSuite g_ns2TransmobilityHelperTestSuite
the test suite
#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.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
bool AreVectorsEqual(const Vector &actual, const Vector &limit, double tol)
Single record in mobility reference.
std::string node
node ID as string, e.g. "1"
Vector pos
reference position
ReferencePoint(const std::string &id, Time t, const Vector &p, const Vector &v)
Constructor.
Vector vel
reference velocity
bool operator<(const ReferencePoint &o) const
Less-than operator - used to sort by timestamp.