30#include "ns3/constant-velocity-mobility-model.h"
32#include "ns3/node-list.h"
34#include "ns3/simulator.h"
47#define NS2_X_COORD "X_"
48#define NS2_Y_COORD "Y_"
49#define NS2_Z_COORD "Z_"
50#define NS2_SETDEST "setdest"
52#define NS2_NODEID "$node_("
53#define NS2_NS_SCH "$ns_"
108static std::string
TrimNs2Line(
const std::string& str);
115static bool IsNumber(
const std::string& s);
124static bool IsVal(
const std::string& str, T&
ret);
229 if (!(file.is_open()))
232 <<
" for reading, aborting here \n");
239 std::istringstream
iss;
252 object->AggregateObject(
model);
260 std::map<int, DestinationPoint>
last_pos;
290 if (
pr.tokens.size() != 4)
300 NS_LOG_ERROR(
"Node number couldn't be obtained (corrupted file?): " << line
311 NS_LOG_ERROR(
"Unknown node ID (corrupted file?): " << nodeId <<
"\n");
361 if (
pr.tokens.size() != 4 &&
pr.tokens.size() != 7 &&
pr.tokens.size() != 8)
363 NS_LOG_ERROR(
"Line has not correct number of parameters (corrupted file?): "
373 NS_LOG_ERROR(
"Node number couldn't be obtained (corrupted file?): " << line
384 NS_LOG_ERROR(
"Unknown node ID (corrupted file?): " << nodeId <<
"\n");
436 <<
", actually reached = " <<
reached);
477 NS_LOG_WARN(
"Format Line is not correct: " << line <<
"\n");
489 std::istringstream s;
493 size_t pos_sharp = str.find_first_of(
'#');
522 ret.tokens.push_back(x);
530 ret.ivals.push_back(
ii);
532 ret.dvals.push_back(
d);
533 ret.svals.push_back(x);
593 ret.erase(
ret.size() - 1, 1);
604 return endp == s.c_str() + s.size();
618 std::istringstream s(str);
632 std::string::size_type
startNodeId = str.find_first_of(
'(');
633 std::string::size_type
endNodeId = str.find_first_of(
')');
647 return IsNumber(nodeId) && nodeId.find_first_of(
'.') == std::string::npos && nodeId[0] !=
'-';
656 std::string::size_type
startNodeId = str.find_first_of(
'(');
657 std::string::size_type
endNodeId = str.find_first_of(
')');
671 switch (
pr.tokens.size())
674 result =
pr.ivals[0];
678 result =
pr.ivals[3];
690 switch (
pr.tokens.size())
755 &&
pr.has_dval[2] &&
pr.has_dval[5] &&
pr.has_dval[6] &&
pr.has_dval[7] &&
770 retval.m_travelStartTime = at;
771 retval.m_targetArrivalTime = at;
814 retval.m_targetArrivalTime += time;
825 position.x =
model->GetPosition().x;
826 position.y =
model->GetPosition().y;
827 position.z =
model->GetPosition().z;
843 position.x =
model->GetPosition().x;
844 position.y =
model->GetPosition().y;
845 position.z =
model->GetPosition().z;
Mobility model for which the current speed does not change once it has been set and until it is set a...
void SetVelocity(const Vector &speed)
An identifier for simulation events.
void SetPosition(const Vector &position)
a class to hold input objects internally
void ConfigNodesMovements(const ObjectStore &store) const
Parses ns-2 mobility file to create ns-3 mobility events.
void Install() const
Read the ns2 trace file and configure the movement patterns of all nodes contained in the global ns3:...
std::string m_filename
filename of file containing ns-2 mobility trace
Ptr< ConstantVelocityMobilityModel > GetMobilityModel(std::string idString, const ObjectStore &store) const
Get or create a ConstantVelocityMobilityModel corresponding to idString.
Ns2MobilityHelper(std::string filename)
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static bool IsSchedMobilityPos(ParseResult pr)
Check if this corresponds to a line like this: $ns_ at 1 "$node_(0) set X_ 2".
static bool IsNumber(const std::string &s)
Checks if a string represents a number or it has others characters than digits and point.
static std::string TrimNs2Line(const std::string &str)
Put out blank spaces at the start and end of a line.
static unsigned int value(char c)
static ParseResult ParseNs2Line(const std::string &str)
Parses a line of ns2 mobility.
static Vector SetOneInitialCoord(Vector actPos, std::string &coord, double value)
Add one coord to a vector position.
static bool IsSetInitialPos(ParseResult pr)
Check if this corresponds to a line like this: $node_(0) set X_ 123.
static std::string GetNodeIdFromToken(std::string str)
Gets nodeId number in string format from the string like $node_(4)
static bool HasNodeIdNumber(std::string str)
Checks if the value between brackets is a correct nodeId number.
static Vector SetInitialPosition(Ptr< ConstantVelocityMobilityModel > model, std::string coord, double coordVal)
Set initial position for a node.
static DestinationPoint SetMovement(Ptr< ConstantVelocityMobilityModel > model, Vector lastPos, double at, double xFinalPosition, double yFinalPosition, double speed)
Set waypoints and speed for movement.
static Vector SetSchedPosition(Ptr< ConstantVelocityMobilityModel > model, double at, std::string coord, double coordVal)
Schedule a set of position for a node.
static bool IsVal(const std::string &str, T &ret)
Check if s string represents a numeric value.
static bool IsSchedSetPos(ParseResult pr)
Check if this corresponds to a line like this: $ns_ at 1 "$node_(0) setdest 2 3 4".
static int GetNodeIdInt(ParseResult pr)
Get node id number in int format.
static std::string GetNodeIdString(ParseResult pr)
Get node id number in string format.
Keeps last movement schedule.
double m_travelStartTime
Travel start time is needed to calculate actually traveled time.
EventId m_stopEvent
Event scheduling node's stop.
Vector m_finalPosition
Final destination to be reached before next schedule.
double m_targetArrivalTime
When a station arrives to a destination.
Vector m_speed
Speed of the last movement (needed to derive reached destination at next schedule = start + velocity ...
Vector m_startPosition
Start position of last movement.
Type to maintain line parsed and its values.
std::vector< double > dvals
double values for each tokens
std::vector< std::string > svals
string value for each token
std::vector< std::string > tokens
tokens from a line
std::vector< int > ivals
int values for each tokens
std::vector< bool > has_ival
points if a tokens has an int value
std::vector< bool > has_dval
points if a tokens has a double value