45 #include "ns3/unused.h" 
   46 #include "ns3/simulator.h" 
   47 #include "ns3/node-list.h" 
   49 #include "ns3/constant-velocity-mobility-model.h" 
   58 #define  NS2_X_COORD  "X_" 
   59 #define  NS2_Y_COORD  "Y_" 
   60 #define  NS2_Z_COORD  "Z_" 
   61 #define  NS2_SETDEST  "setdest" 
   63 #define  NS2_NODEID   "$node_(" 
   64 #define  NS2_NS_SCH   "$ns_" 
   95     m_startPosition (Vector (0,0,0)),
 
   96     m_speed (Vector (0,0,0)),
 
   97     m_finalPosition (Vector (0,0,0)),
 
   98     m_travelStartTime (0),
 
   99     m_targetArrivalTime (0)
 
  107 static ParseResult 
ParseNs2Line (
const std::string& str);
 
  112 static std::string 
TrimNs2Line (
const std::string& str);
 
  117 static bool IsNumber (
const std::string& s);
 
  126 static bool IsVal (
const std::string& str, T& ret);
 
  171 static DestinationPoint 
SetMovement (Ptr<ConstantVelocityMobilityModel> model, Vector lastPos, 
double at,
 
  172                                      double xFinalPosition, 
double yFinalPosition, 
double speed);
 
  177 static Vector 
SetInitialPosition (Ptr<ConstantVelocityMobilityModel> model, std::string coord, 
double coordVal);
 
  182 static Vector 
SetSchedPosition (Ptr<ConstantVelocityMobilityModel> model, 
double at, std::string coord, 
double coordVal);
 
  186   : m_filename (filename)
 
  195   std::istringstream iss;
 
  207       model = CreateObject<ConstantVelocityMobilityModel> ();
 
  208       object->AggregateObject (model);
 
  217   std::map<int, DestinationPoint> last_pos;    
 
  229       while (!
file.eof () )
 
  235           getline (
file, line);
 
  247           if (pr.
tokens.size () != 4)
 
  257               NS_LOG_ERROR (
"Node number couldn't be obtained (corrupted file?): " << line << 
"\n");
 
  267               NS_LOG_ERROR (
"Unknown node ID (corrupted file?): " << nodeId << 
"\n");
 
  281               last_pos[iNodeId] = point;
 
  284               NS_LOG_DEBUG (
"Positions after parse for node " << iNodeId << 
" " << nodeId <<
 
  285                             " position = " << last_pos[iNodeId].m_finalPosition);
 
  300       while (!
file.eof () )
 
  306           getline (
file, line);
 
  319               NS_LOG_ERROR (
"Line has not correct number of parameters (corrupted file?): " << line << 
"\n");
 
  328               NS_LOG_ERROR (
"Node number couldn't be obtained (corrupted file?): " << line << 
"\n");
 
  338               NS_LOG_ERROR (
"Unknown node ID (corrupted file?): " << nodeId << 
"\n");
 
  383                   if (last_pos[iNodeId].m_targetArrivalTime > at)
 
  385                       NS_LOG_LOGIC (
"Did not reach a destination! stoptime = " << last_pos[iNodeId].m_targetArrivalTime << 
", at = "<<  at);
 
  386                       double actuallytraveled = at - last_pos[iNodeId].m_travelStartTime;
 
  387                       Vector reached = Vector (
 
  388                           last_pos[iNodeId].m_startPosition.x + last_pos[iNodeId].m_speed.x * actuallytraveled,
 
  389                           last_pos[iNodeId].m_startPosition.y + last_pos[iNodeId].m_speed.y * actuallytraveled,
 
  392                       NS_LOG_LOGIC (
"Final point = " << last_pos[iNodeId].m_finalPosition << 
", actually reached = " << reached);
 
  393                       last_pos[iNodeId].m_stopEvent.Cancel ();
 
  394                       last_pos[iNodeId].m_finalPosition = reached;
 
  400                   NS_LOG_DEBUG (
"Positions after parse for node " << iNodeId << 
" " << nodeId << 
" position =" << last_pos[iNodeId].m_finalPosition);
 
  412                   if (last_pos[iNodeId].m_targetArrivalTime > at)
 
  414                       last_pos[iNodeId].m_stopEvent.Cancel ();
 
  416                   last_pos[iNodeId].m_targetArrivalTime = at;
 
  417                   last_pos[iNodeId].m_travelStartTime = at;
 
  419                   NS_LOG_DEBUG (
"Positions after parse for node " << iNodeId << 
" " << nodeId <<
 
  420                                 " position =" << last_pos[iNodeId].m_finalPosition);
 
  424                   NS_LOG_WARN (
"Format Line is not correct: " << line << 
"\n");
 
  437   std::istringstream s;
 
  441   size_t pos_sharp = str.find_first_of (
'#');
 
  442   if (pos_sharp != std::string::npos)
 
  444       line = str.substr (0, pos_sharp);
 
  466       if (x.length () == 0)
 
  477       ret.
has_ival.push_back (IsVal<int> (x, ii));
 
  478       ret.
ivals.push_back (ii);
 
  479       ret.
has_dval.push_back (IsVal<double> (x, d));
 
  480       ret.
dvals.push_back (d);
 
  481       ret.
svals.push_back (x);
 
  484   size_t tokensLength   = ret.
tokens.size ();                 
 
  485   size_t lasTokenLength = ret.
tokens[tokensLength - 1].size (); 
 
  489   if ( (tokensLength == 7 || tokensLength == 8)
 
  490        && (ret.
tokens[tokensLength - 1][lasTokenLength - 1] == 
'"') )
 
  494       ret.
tokens[tokensLength - 1] = ret.
tokens[tokensLength - 1].substr (0,lasTokenLength - 1);
 
  497       x = ret.
tokens[tokensLength - 1];
 
  507       ret.
has_ival[tokensLength - 1] = IsVal<int> (
x, ii);
 
  508       ret.
ivals[tokensLength - 1] = ii;
 
  509       ret.
has_dval[tokensLength - 1] = IsVal<double> (
x, d);
 
  510       ret.
dvals[tokensLength - 1] = d;
 
  511       ret.
svals[tokensLength - 1] = 
x;
 
  514   else if ( (tokensLength == 9 && ret.
tokens[tokensLength - 1] == 
"\"")
 
  515             || (tokensLength == 8 && ret.
tokens[tokensLength - 1] == 
"\""))
 
  520       ret.
tokens.erase (ret.
tokens.begin () + tokensLength - 1);
 
  522       ret.
ivals.erase (ret.
ivals.begin () + tokensLength - 1);
 
  524       ret.
dvals.erase (ret.
dvals.begin () + tokensLength - 1);
 
  525       ret.
svals.erase (ret.
svals.begin () + tokensLength - 1);
 
  540   while (ret.size () > 0 && isblank (ret[0]))
 
  545   while (ret.size () > 0 && (isblank (ret[ret.size () - 1]) || (ret[ret.size () - 1] == 
';')))
 
  547       ret.erase (ret.size () - 1, 1); 
 
  558   double v = strtod (s.c_str (), &endp); 
 
  560   return endp == s.c_str () + s.size ();
 
  565 bool IsVal (
const std::string& str, T& ret)
 
  567   if (str.size () == 0)
 
  573       std::string s2 = str;
 
  574       std::istringstream s (s2);
 
  590   std::string::size_type startNodeId = str.find_first_of (
"("); 
 
  591   std::string::size_type endNodeId   = str.find_first_of (
")"); 
 
  597   if (startNodeId == std::string::npos || endNodeId == std::string::npos)
 
  602   nodeId = str.substr (startNodeId + 1, endNodeId - (startNodeId + 1)); 
 
  605   if (
IsNumber (nodeId) && (nodeId.find_first_of (
".") == std::string::npos) && (nodeId[0] != 
'-'))
 
  622       std::string::size_type startNodeId = str.find_first_of (
"(");     
 
  623       std::string::size_type endNodeId   = str.find_first_of (
")");     
 
  625       return str.substr (startNodeId + 1, endNodeId - (startNodeId + 1)); 
 
  638   switch (pr.
tokens.size ())
 
  641       result = pr.
ivals[0];
 
  644       result = pr.
ivals[3];
 
  647       result = pr.
ivals[3];
 
  659   switch (pr.
tokens.size ())
 
  734              double xFinalPosition, 
double yFinalPosition, 
double speed)
 
  752       double time = std::sqrt (std::pow (xFinalPosition - retval.
m_finalPosition.x, 2) + std::pow (yFinalPosition - retval.
m_finalPosition.y, 2)) / speed;
 
  761       retval.
m_speed = Vector (xSpeed, ySpeed, 0);
 
  766       NS_LOG_DEBUG (
"Calculated Speed: X=" << xSpeed << 
" Y=" << ySpeed << 
" Z=" << zSpeed);
 
void ConfigNodesMovements(const ObjectStore &store) const 
Parses ns-2 mobility file to create ns-3 mobility events. 
 
std::vector< bool > has_dval
points if a tokens has a double value 
 
Smart pointer class similar to boost::intrusive_ptr. 
 
std::vector< bool > has_ival
points if a tokens has an int value 
 
static Vector SetOneInitialCoord(Vector actPos, std::string &coord, double value)
Add one coord to a vector position. 
 
std::string m_filename
filename of file containing ns-2 mobility trace 
 
static Vector SetInitialPosition(Ptr< ConstantVelocityMobilityModel > model, std::string coord, double coordVal)
Set initial position for a node. 
 
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 bool HasNodeIdNumber(std::string str)
Checks if the value between brackets is a correct nodeId number. 
 
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name. 
 
#define NS_UNUSED(x)
Mark a local variable as unused. 
 
Vector GetPosition(void) const 
 
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate. 
 
Ptr< ConstantVelocityMobilityModel > GetMobilityModel(std::string idString, const ObjectStore &store) const 
Get or create a ConstantVelocityMobilityModel corresponding to idString. 
 
Vector m_speed
Speed of the last movement (needed to derive reached destination at next schedule = start + velocity ...
 
std::vector< std::string > tokens
tokens from a line 
 
void Install(void) const 
Read the ns2 trace file and configure the movement patterns of all nodes contained in the global ns3:...
 
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay. 
 
static bool IsSetInitialPos(ParseResult pr)
Check if this corresponds to a line like this: $node_(0) set X_ 123. 
 
double m_travelStartTime
Travel start time is needed to calculate actually traveled time. 
 
static Iterator End(void)
 
static std::string GetNodeIdFromToken(std::string str)
Gets nodeId number in string format from the string like $node_(4) 
 
static DestinationPoint SetMovement(Ptr< ConstantVelocityMobilityModel > model, Vector lastPos, double at, double xFinalPosition, double yFinalPosition, double speed)
Set waypoints and speed for movement. 
 
std::vector< std::string > svals
string value for each token 
 
virtual Ptr< Object > Get(uint32_t i) const =0
Return ith object in store. 
 
static ParseResult ParseNs2Line(const std::string &str)
Parses a line of ns2 mobility. 
 
Every class exported by the ns3 library is enclosed in the ns3 namespace. 
 
static std::string GetNodeIdString(ParseResult pr)
Get node id number in string format. 
 
Vector m_startPosition
Start position of last movement. 
 
std::vector< double > dvals
double values for each tokens 
 
Keeps last movement schedule. 
 
Ns2MobilityHelper(std::string filename)
 
static Vector SetSchedPosition(Ptr< ConstantVelocityMobilityModel > model, double at, std::string coord, double coordVal)
Schedule a set of position for a node. 
 
void SetPosition(const Vector &position)
 
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
 
std::vector< int > ivals
int values for each tokens 
 
An identifier for simulation events. 
 
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN. 
 
static Iterator Begin(void)
 
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG. 
 
Time Seconds(double value)
Construct a Time in the indicated unit. 
 
Mobility model for which the current speed does not change once it has been set and until it is set a...
 
static std::string TrimNs2Line(const std::string &str)
Put out blank spaces at the start and end of a line. 
 
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR. 
 
EventId m_stopEvent
Event scheduling node's stop. 
 
Type to maintain line parsed and its values. 
 
static bool IsSchedMobilityPos(ParseResult pr)
Check if this corresponds to a line like this: $ns_ at 1 "$node_(0) set X_ 2". 
 
a class to hold input objects internally 
 
void SetVelocity(const Vector &speed)
 
static bool IsVal(const std::string &str, T &ret)
Check if s string represents a numeric value. 
 
double m_targetArrivalTime
When a station arrives to a destination. 
 
Vector m_finalPosition
Final destination to be reached before next schedule. 
 
static bool IsNumber(const std::string &s)
Checks if a string represents a number or it has others characters than digits an point...