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"
57 bool AreVectorsEqual (Vector
const & actual, Vector
const & limit,
double tol)
59 if (actual.x > limit.x + tol || actual.x < limit.x - tol)
63 if (actual.y > limit.y + tol || actual.y < limit.y - tol)
67 if (actual.z > limit.z + tol || actual.z < limit.z - tol)
157 m_traceFile = CreateTempDirFilename (
"Ns2MobilityHelperTest.tcl");
159 NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (of.is_open (),
true,
"Need to write tmp. file");
171 std::ostringstream os;
184 NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (node, 0,
"Can't find node with id " << rp.
node);
186 NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (mob, 0,
"Can't find mobility for node " << rp.
node);
189 NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (mob->
GetPosition (), rp.
pos, tol),
true,
"Initial position mismatch for node " << rp.
node);
190 NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (mob->
GetVelocity (), rp.
vel, tol),
true,
"Initial velocity mismatch for node " << rp.
node);
204 Vector pos = mobility->GetPosition ();
205 Vector vel = mobility->GetVelocity ();
214 NS_TEST_EXPECT_MSG_EQ (time, ref.
time,
"Time mismatch");
215 NS_TEST_EXPECT_MSG_EQ (
id, ref.
node,
"Node ID mismatch at time " << time.
GetSeconds () <<
" s");
218 NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (pos, ref.
pos, tol),
true,
"Position mismatch at time " << time.
GetSeconds () <<
" s for node " << id);
219 NS_TEST_EXPECT_MSG_EQ (AreVectorsEqual (vel, ref.
vel, tol),
true,
"Velocity mismatch at time " << time.
GetSeconds () <<
" s for node " << id);
237 NS_TEST_ASSERT_MSG_EQ (
m_trace.empty (),
false,
"Need trace");
238 NS_TEST_ASSERT_MSG_EQ (
m_reference.empty (),
false,
"Need reference");
271 t->
SetTrace (
"$node_(0) set X_ 1.0\n"
272 "$node_(0) set Y_ 2.0\n"
273 "$node_(0) set Z_ 3.0\n"
282 "$node_(0) set X_ 1.0 # comment \n"
283 "$node_(0) set Y_ 2.0 ### \n"
284 "$node_(0) set Z_ 3.0 # $node_(0) set Z_ 3.0\n"
285 "#$node_(0) set Z_ 100 #"
292 t->
SetTrace (
"$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"");
301 t->
SetTrace (
"$node_(0) set X_ 0.0\n"
302 "$node_(0) set Y_ 0.0\n"
303 "$ns_ at 1.0 \"$node_(0) setdest 5 0 5\"\n"
304 "$ns_ at 2.0 \"$node_(0) setdest 5 5 5\"\n"
305 "$ns_ at 3.0 \"$node_(0) setdest 0 5 5\"\n"
306 "$ns_ at 4.0 \"$node_(0) setdest 0 0 5\"\n"
325 t->
SetTrace (
"$ns_ at 1.0 \"$node_(0) setdest 15 10 5\"\n"
326 "$ns_ at 2.0 \"$node_(0) setdest 15 15 5\"\n"
327 "$ns_ at 3.0 \"$node_(0) setdest 10 15 5\"\n"
328 "$ns_ at 4.0 \"$node_(0) setdest 10 10 5\"\n"
329 "$node_(0) set X_ 10.0\n"
330 "$node_(0) set Y_ 10.0\n"
346 t->
SetTrace (
"$ns_ at 1.0 \"$node_(0) set X_ 10\"\n"
347 "$ns_ at 1.0 \"$node_(0) set Z_ 10\"\n"
348 "$ns_ at 1.0 \"$node_(0) set Y_ 10\"");
357 t->
SetTrace (
"$node() set X_ 1 # node id is not present\n"
358 "$node # incoplete line\"\n"
359 "$node this line is not correct\n"
360 "$node_(0) set X_ 1 # line OK \n"
361 "$node_(0) set Y_ 2 # line OK \n"
362 "$node_(0) set Z_ 3 # line OK \n"
363 "$ns_ at \"$node_(0) setdest 4 4 4\" # time not present\n"
364 "$ns_ at 1 \"$node_(0) setdest 2 2 1 \" # line OK \n");
373 t->
SetTrace (
"$node_(0) set X_ 1 # line OK \n"
374 "$node_(0) set Y_ 2 # line OK \n"
375 "$node_(0) set Z_ 3 # line OK \n"
376 "$node_(-22) set Y_ 3 # node id not correct\n"
377 "$node_(3.3) set Y_ 1111 # node id not correct\n"
378 "$ns_ at sss \"$node_(0) setdest 5 5 5\" # time is not a number\n"
379 "$ns_ at 1 \"$node_(0) setdest 2 2 1\" # line OK \n"
380 "$ns_ at 1 \"$node_(0) setdest 2 2 -1\" # negative speed is not correct\n"
381 "$ns_ at 1 \"$node_(0) setdest 2 2 sdfs\" # speed is not a number\n"
382 "$ns_ at 1 \"$node_(0) setdest 2 2 s232dfs\" # speed is not a number\n"
383 "$ns_ at 1 \"$node_(0) setdest 233 2.. s232dfs\" # more than one non numbers\n"
384 "$ns_ at -12 \"$node_(0) setdest 11 22 33\" # time should not be negative\n");
393 t->
SetTrace (
"$node_(0) set X_ 1.0\n"
394 "$node_(0) set Y_ 2.0\n"
395 "$node_(0) set Z_ 3.0\n"
396 "$ns_ at 1.0 \"$node_(1) setdest 25 0 5\"\n"
397 "$node_(2) set X_ 0.0\n"
398 "$node_(2) set Y_ 0.0\n"
399 "$ns_ at 1.0 \"$node_(2) setdest 5 0 5\"\n"
400 "$ns_ at 2.0 \"$node_(2) setdest 5 5 5\"\n"
401 "$ns_ at 3.0 \"$node_(2) setdest 0 5 5\"\n"
402 "$ns_ at 4.0 \"$node_(2) setdest 0 0 5\"\n");
421 t->
SetTrace (
"$ns_ at 1.0 \"$node_(0) setdest 25 0 5\"\n"
422 "$ns_ at 7.0 \"$node_(0) setdest 11 22 0\"\n");
433 t->
SetTrace (
"$node_(0) set X_ -1.0\n"
434 "$node_(0) set Y_ 0\n"
435 "$ns_ at 1.0 \"$node_(0) setdest 0 0 1\"\n"
436 "$ns_ at 2.0 \"$node_(0) setdest 0 -1 1\"\n");
447 t->
SetTrace (
"$node_(0) set X_ 0.0\n"
448 "$node_(0) set Y_ 0.0\n"
449 "$ns_ at 1.0 \"$node_(0) setdest 1.0e+2 0 1.0e+2\"\n"
450 "$ns_ at 2.0 \"$node_(0) setdest 1.0e+2 1.0e+2 1.0e+2\"\n"
451 "$ns_ at 3.0 \"$node_(0) setdest 0 1.0e+2 1.0e+2\"\n"
452 "$ns_ at 4.0 \"$node_(0) setdest 0 0 1.0e+2\"\n");
465 t->
SetTrace (
"$node_(0) set X_ 0.0\n"
466 "$node_(0) set Y_ 0.0\n"
467 "$ns_ at 1.0 \"$node_(0) setdest 0 10 1\"\n"
468 "$ns_ at 6.0 \"$node_(0) setdest 0 -10 1\"\n"
477 t->
SetTrace (
"$node_(0) set X_ 10.0\r\n"
478 "$node_(0) set Y_ 0.0\r\n"
484 t->
SetTrace (
"$node_(0) set X_ 10.0\n"
485 "$node_(0) set Y_ 0.0\n"
486 "$ns_ at 1.0 \"$node_(0) setdest 10 0 1\"\n"
495 t->
SetTrace (
"$node_(0) set X_ 350.00000000000000\n"
496 "$node_(0) set Y_ 50.00000000000000\n"
497 "$ns_ at 50.00000000000000 \"$node_(0) setdest 400.00000000000000 50.00000000000000 1.00000000000000\"\n"
498 "$ns_ at 150.00000000000000 \"$node_(0) setdest 400.00000000000000 150.00000000000000 4.00000000000000\"\n"
499 "$ns_ at 300.00000000000000 \"$node_(0) setdest 250.00000000000000 150.00000000000000 3.00000000000000\"\n"
500 "$ns_ at 350.00000000000000 \"$node_(0) setdest 250.00000000000000 50.00000000000000 1.00000000000000\"\n"
501 "$ns_ at 600.00000000000000 \"$node_(0) setdest 250.00000000000000 1050.00000000000000 2.00000000000000\"\n"
502 "$ns_ at 900.00000000000000 \"$node_(0) setdest 300.00000000000000 650.00000000000000 2.50000000000000\"\n"
519 } g_ns2TransmobilityHelperTestSuite;
Single record in mobility reference.
Ns2MobilityHelperTest(std::string const &name, Time timeLimit, uint32_t nodes=1)
void AddReferencePoint(ReferencePoint const &r)
Add next reference point.
virtual ~Ns2MobilityHelperTest()
Empty.
#define NS_ASSERT(condition)
Vector GetPosition(void) const
size_t m_nextRefPoint
Next reference point to be checked.
void DoTeardown()
Implementation to do any local setup required for this test case.
void Connect(std::string path, const CallbackBase &cb)
Vector pos
reference position
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
Vector GetVelocity(void) const
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
Keep track of the current position and velocity of an object.
double GetSeconds(void) const
Helper class which can read ns-2 movement files and configure nodes mobility.
make Callback use a separate empty type
void CourseChange(std::string context, Ptr< const MobilityModel > mobility)
Listen for course change events.
std::string node
node ID as string, e.g. "1"
std::string m_traceFile
TMP trace file name.
Time m_timeLimit
Test time limit.
Vector vel
reference velocity
void CreateNodes()
Create and name nodes.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void DoSetup()
Implementation to do any local setup required for this test case.
static void Destroy(void)
keep track of a set of node pointers.
bool IsStatusFailure(void) const
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
bool WriteTrace()
Dump NS-2 trace to tmp file.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
std::string m_trace
Trace as string.
void SetDataDir(std::string directory)
uint32_t m_nodeCount
Number of nodes used in the test.
static std::string FindName(Ptr< Object > object)
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
bool CheckInitialPositions()
Check that all initial positions are correct.
bool operator<(ReferencePoint const &o) const
Sort by timestamp.
Ptr< T > GetObject(void) const
void AddReferencePoint(const char *id, double sec, Vector const &p, Vector const &v)
Sugar.
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) ...
std::vector< ReferencePoint > m_reference
Reference mobility.