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)
115 return (time < o.
time);
127 m_timeLimit (timeLimit),
144 m_reference.push_back (r);
170 m_traceFile = CreateTempDirFilename (
"Ns2MobilityHelperTest.tcl");
171 std::ofstream of (m_traceFile.c_str ());
181 nodes.Create (m_nodeCount);
182 for (uint32_t i = 0; i < m_nodeCount; ++i)
184 std::ostringstream os;
192 std::stable_sort (m_reference.begin (), m_reference.end ());
193 while (m_nextRefPoint < m_reference.size () && m_reference[m_nextRefPoint].time ==
Seconds (0))
207 return IsStatusFailure ();
217 Vector pos =
mobility->GetPosition ();
218 Vector vel =
mobility->GetVelocity ();
221 if (m_nextRefPoint >= m_reference.size ())
258 if (CheckInitialPositions ())
280 SetDataDir (NS_TEST_SOURCEDIR);
288 t->
SetTrace (
"$node_(0) set X_ 1.0\n" 289 "$node_(0) set Y_ 2.0\n" 290 "$node_(0) set Z_ 3.0\n" 299 "$node_(0) set X_ 1.0 # comment \n" 300 "$node_(0) set Y_ 2.0 ### \n" 301 "$node_(0) set Z_ 3.0 # $node_(0) set Z_ 3.0\n" 302 "#$node_(0) set Z_ 100 #" 309 t->
SetTrace (
"$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"");
318 t->
SetTrace (
"$node_(0) set X_ 0.0\n" 319 "$node_(0) set Y_ 0.0\n" 320 "$ns_ at 1.0 \"$node_(0) setdest 5 0 5\"\n" 321 "$ns_ at 2.0 \"$node_(0) setdest 5 5 5\"\n" 322 "$ns_ at 3.0 \"$node_(0) setdest 0 5 5\"\n" 323 "$ns_ at 4.0 \"$node_(0) setdest 0 0 5\"\n" 342 t->
SetTrace (
"$ns_ at 1.0 \"$node_(0) setdest 15 10 5\"\n" 343 "$ns_ at 2.0 \"$node_(0) setdest 15 15 5\"\n" 344 "$ns_ at 3.0 \"$node_(0) setdest 10 15 5\"\n" 345 "$ns_ at 4.0 \"$node_(0) setdest 10 10 5\"\n" 346 "$node_(0) set X_ 10.0\n" 347 "$node_(0) set Y_ 10.0\n" 363 t->
SetTrace (
"$ns_ at 1.0 \"$node_(0) set X_ 10\"\n" 364 "$ns_ at 1.0 \"$node_(0) set Z_ 10\"\n" 365 "$ns_ at 1.0 \"$node_(0) set Y_ 10\"");
374 t->
SetTrace (
"$node() set X_ 1 # node id is not present\n" 375 "$node # incoplete line\"\n" 376 "$node this line is not correct\n" 377 "$node_(0) set X_ 1 # line OK \n" 378 "$node_(0) set Y_ 2 # line OK \n" 379 "$node_(0) set Z_ 3 # line OK \n" 380 "$ns_ at \"$node_(0) setdest 4 4 4\" # time not present\n" 381 "$ns_ at 1 \"$node_(0) setdest 2 2 1 \" # line OK \n");
390 t->
SetTrace (
"$node_(0) set X_ 1 # line OK \n" 391 "$node_(0) set Y_ 2 # line OK \n" 392 "$node_(0) set Z_ 3 # line OK \n" 393 "$node_(-22) set Y_ 3 # node id not correct\n" 394 "$node_(3.3) set Y_ 1111 # node id not correct\n" 395 "$ns_ at sss \"$node_(0) setdest 5 5 5\" # time is not a number\n" 396 "$ns_ at 1 \"$node_(0) setdest 2 2 1\" # line OK \n" 397 "$ns_ at 1 \"$node_(0) setdest 2 2 -1\" # negative speed is not correct\n" 398 "$ns_ at 1 \"$node_(0) setdest 2 2 sdfs\" # speed is not a number\n" 399 "$ns_ at 1 \"$node_(0) setdest 2 2 s232dfs\" # speed is not a number\n" 400 "$ns_ at 1 \"$node_(0) setdest 233 2.. s232dfs\" # more than one non numbers\n" 401 "$ns_ at -12 \"$node_(0) setdest 11 22 33\" # time should not be negative\n");
410 t->
SetTrace (
"$node_(0) set X_ 1.0\n" 411 "$node_(0) set Y_ 2.0\n" 412 "$node_(0) set Z_ 3.0\n" 413 "$ns_ at 1.0 \"$node_(1) setdest 25 0 5\"\n" 414 "$node_(2) set X_ 0.0\n" 415 "$node_(2) set Y_ 0.0\n" 416 "$ns_ at 1.0 \"$node_(2) setdest 5 0 5\"\n" 417 "$ns_ at 2.0 \"$node_(2) setdest 5 5 5\"\n" 418 "$ns_ at 3.0 \"$node_(2) setdest 0 5 5\"\n" 419 "$ns_ at 4.0 \"$node_(2) setdest 0 0 5\"\n");
438 t->
SetTrace (
"$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"\n" 439 "$ns_ at 7.0 \"$node_(0) setdest 11 22 0\"\n");
450 t->
SetTrace (
"$node_(0) set X_ -1.0\n" 451 "$node_(0) set Y_ 0\n" 452 "$ns_ at 1.0 \"$node_(0) setdest 0 0 1\"\n" 453 "$ns_ at 2.0 \"$node_(0) setdest 0 -1 1\"\n");
464 t->
SetTrace (
"$node_(0) set X_ 0.0\n" 465 "$node_(0) set Y_ 0.0\n" 466 "$ns_ at 1.0 \"$node_(0) setdest 1.0e+2 0 1.0e+2\"\n" 467 "$ns_ at 2.0 \"$node_(0) setdest 1.0e+2 1.0e+2 1.0e+2\"\n" 468 "$ns_ at 3.0 \"$node_(0) setdest 0 1.0e+2 1.0e+2\"\n" 469 "$ns_ at 4.0 \"$node_(0) setdest 0 0 1.0e+2\"\n");
482 t->
SetTrace (
"$node_(0) set X_ 0.0\n" 483 "$node_(0) set Y_ 0.0\n" 484 "$ns_ at 1.0 \"$node_(0) setdest 0 10 1\"\n" 485 "$ns_ at 6.0 \"$node_(0) setdest 0 -10 1\"\n" 494 t->
SetTrace (
"$node_(0) set X_ 10.0\r\n" 495 "$node_(0) set Y_ 0.0\r\n" 501 t->
SetTrace (
"$node_(0) set X_ 10.0\n" 502 "$node_(0) set Y_ 0.0\n" 503 "$ns_ at 1.0 \"$node_(0) setdest 10 0 1\"\n" 512 t->
SetTrace (
"$node_(0) set X_ 350.00000000000000\n" 513 "$node_(0) set Y_ 50.00000000000000\n" 514 "$ns_ at 50.00000000000000 \"$node_(0) setdest 400.00000000000000 50.00000000000000 1.00000000000000\"\n" 515 "$ns_ at 150.00000000000000 \"$node_(0) setdest 400.00000000000000 150.00000000000000 4.00000000000000\"\n" 516 "$ns_ at 300.00000000000000 \"$node_(0) setdest 250.00000000000000 150.00000000000000 3.00000000000000\"\n" 517 "$ns_ at 350.00000000000000 \"$node_(0) setdest 250.00000000000000 50.00000000000000 1.00000000000000\"\n" 518 "$ns_ at 600.00000000000000 \"$node_(0) setdest 250.00000000000000 1050.00000000000000 2.00000000000000\"\n" 519 "$ns_ at 900.00000000000000 \"$node_(0) setdest 300.00000000000000 650.00000000000000 2.50000000000000\"\n" 521 t->
AddReferencePoint (
"0", 0.000, Vector (350.000, 50.000, 0.000), Vector (0.000, 0.000, 0.000));
522 t->
AddReferencePoint (
"0", 50.000, Vector (350.000, 50.000, 0.000), Vector (1.000, 0.000, 0.000));
523 t->
AddReferencePoint (
"0", 100.000, Vector (400.000, 50.000, 0.000), Vector (0.000, 0.000, 0.000));
524 t->
AddReferencePoint (
"0", 150.000, Vector (400.000, 50.000, 0.000), Vector (0.000, 4.000, 0.000));
525 t->
AddReferencePoint (
"0", 175.000, Vector (400.000, 150.000, 0.000), Vector (0.000, 0.000, 0.000));
526 t->
AddReferencePoint (
"0", 300.000, Vector (400.000, 150.000, 0.000), Vector (-3.000, 0.000, 0.000));
527 t->
AddReferencePoint (
"0", 350.000, Vector (250.000, 150.000, 0.000), Vector (0.000, 0.000, 0.000));
528 t->
AddReferencePoint (
"0", 350.000, Vector (250.000, 150.000, 0.000), Vector (0.000, -1.000, 0.000));
529 t->
AddReferencePoint (
"0", 450.000, Vector (250.000, 50.000, 0.000), Vector (0.000, 0.000, 0.000));
530 t->
AddReferencePoint (
"0", 600.000, Vector (250.000, 50.000, 0.000), Vector (0.000, 2.000, 0.000));
531 t->
AddReferencePoint (
"0", 900.000, Vector (250.000, 650.000, 0.000), Vector (2.500, 0.000, 0.000));
532 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.
double GetSeconds(void) 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...
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.
Ns2MobilityHelperTestSuite()
std::string m_traceFile
TMP trace file name.
uint32_t m_nodeCount
Number of nodes used in the test.
bool operator<(const EventId &a, const EventId &b)
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
Ns2MobilityHelperTestSuite g_ns2TransmobilityHelperTestSuite
the test suite
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.
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.
void Connect(std::string path, const CallbackBase &cb)
Vector pos
reference position
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
std::string node
node ID as string, e.g. "1"
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Time m_timeLimit
Test time limit.
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)
Constructor.
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
Vector GetPosition(void) const
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
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 DoTeardown()
Implementation to do any local setup required for this TestCase.
Vector GetVelocity(void) const