A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ns2-mobility-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 INRIA
4  * 2009,2010 Contributors
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Contributors: Thomas Waldecker <twaldecker@rocketmail.com>
21  * Martín Giachino <martin.giachino@gmail.com>
22  *
23  * Brief description: Implementation of a ns2 movement trace file reader.
24  *
25  * This implementation is based on the ns2 movement documentation of ns2
26  * as described in http://www.isi.edu/nsnam/ns/doc/node172.html
27  *
28  * Valid trace files use the following ns2 statements:
29  *
30  * $node set X_ x1
31  * $node set Y_ y1
32  * $node set Z_ z1
33  * $ns at $time $node setdest x2 y2 speed
34  * $ns at $time $node set X_ x1
35  * $ns at $time $node set Y_ Y1
36  * $ns at $time $node set Z_ Z1
37  *
38  */
39 
40 
41 #include <fstream>
42 #include <sstream>
43 #include <map>
44 #include "ns3/log.h"
45 #include "ns3/unused.h"
46 #include "ns3/simulator.h"
47 #include "ns3/node-list.h"
48 #include "ns3/node.h"
49 #include "ns3/constant-velocity-mobility-model.h"
50 #include "ns2-mobility-helper.h"
51 
52 NS_LOG_COMPONENT_DEFINE ("Ns2MobilityHelper");
53 
54 namespace ns3 {
55 
56 // Constants definitions
57 #define NS2_AT "at"
58 #define NS2_X_COORD "X_"
59 #define NS2_Y_COORD "Y_"
60 #define NS2_Z_COORD "Z_"
61 #define NS2_SETDEST "setdest"
62 #define NS2_SET "set"
63 #define NS2_NODEID "$node_("
64 #define NS2_NS_SCH "$ns_"
65 
66 
67 // Type to maintain line parsed and its values
69 {
70  std::vector<std::string> tokens; // tokens from a line
71  std::vector<int> ivals; // int values for each tokens
72  std::vector<bool> has_ival; // points if a tokens has an int value
73  std::vector<double> dvals; // double values for each tokens
74  std::vector<bool> has_dval; // points if a tokens has a double value
75  std::vector<std::string> svals; // string value for each token
76 };
85 {
86  Vector m_startPosition; // Start position of last movement
87  Vector m_speed; // Speed of the last movement (needed to derive reached destination at next schedule = start + velocity * actuallyTravelled)
88  Vector m_finalPosition; // Final destination to be reached before next schedule. Replaced with actually reached if needed.
89  EventId m_stopEvent; // Event scheduling node's stop. May be canceled if needed.
90  double m_travelStartTime; // Travel start time is needed to calculate actually traveled time
91  double m_targetArrivalTime; // When a station arrives to a destination
93  m_startPosition (Vector (0,0,0)),
94  m_speed (Vector (0,0,0)),
95  m_finalPosition (Vector (0,0,0)),
98  {};
99 };
100 
101 
102 // Parses a line of ns2 mobility
103 static ParseResult ParseNs2Line (const std::string& str);
104 
105 // Put out blank spaces at the start and end of a line
106 static std::string TrimNs2Line (const std::string& str);
107 
108 // Checks if a string represents a number or it has others characters than digits an point.
109 static bool IsNumber (const std::string& s);
110 
111 // Check if s string represents a numeric value
112 template<class T>
113 static bool IsVal (const std::string& str, T& ret);
114 
115 // Checks if the value between brackets is a correct nodeId number
116 static bool HasNodeIdNumber (std::string str);
117 
118 // Gets nodeId number in string format from the string like $node_(4)
119 static std::string GetNodeIdFromToken (std::string str);
120 
121 // Get node id number in int format
122 static int GetNodeIdInt (ParseResult pr);
123 
124 // Get node id number in string format
125 static std::string GetNodeIdString (ParseResult pr);
126 
127 // Add one coord to a vector position
128 static Vector SetOneInitialCoord (Vector actPos, std::string& coord, double value);
129 
130 // Check if this corresponds to a line like this: $node_(0) set X_ 123
131 static bool IsSetInitialPos (ParseResult pr);
132 
133 // Check if this corresponds to a line like this: $ns_ at 1 "$node_(0) setdest 2 3 4"
134 static bool IsSchedSetPos (ParseResult pr);
135 
136 // Check if this corresponds to a line like this: $ns_ at 1 "$node_(0) set X_ 2"
137 static bool IsSchedMobilityPos (ParseResult pr);
138 
139 // Set waypoints and speed for movement.
140 static DestinationPoint SetMovement (Ptr<ConstantVelocityMobilityModel> model, Vector lastPos, double at,
141  double xFinalPosition, double yFinalPosition, double speed);
142 
143 // Set initial position for a node
144 static Vector SetInitialPosition (Ptr<ConstantVelocityMobilityModel> model, std::string coord, double coordVal);
145 
146 // Schedule a set of position for a node
147 static Vector SetSchedPosition (Ptr<ConstantVelocityMobilityModel> model, double at, std::string coord, double coordVal);
148 
149 
151  : m_filename (filename)
152 {
153  std::ifstream file (m_filename.c_str (), std::ios::in);
154  if (!(file.is_open ())) NS_FATAL_ERROR("Could not open trace file " << m_filename.c_str() << " for reading, aborting here \n");
155 }
156 
158 Ns2MobilityHelper::GetMobilityModel (std::string idString, const ObjectStore &store) const
159 {
160  std::istringstream iss;
161  iss.str (idString);
162  uint32_t id (0);
163  iss >> id;
164  Ptr<Object> object = store.Get (id);
165  if (object == 0)
166  {
167  return 0;
168  }
170  if (model == 0)
171  {
172  model = CreateObject<ConstantVelocityMobilityModel> ();
173  object->AggregateObject (model);
174  }
175  return model;
176 }
177 
178 
179 void
181 {
182  std::map<int, DestinationPoint> last_pos; // Stores previous movement scheduled for each node
183 
184  //*****************************************************************
185  // Parse the file the first time to get the initial node positions.
186  //*****************************************************************
187 
188  // Look through the whole the file for the the initial node
189  // positions to make this helper robust to handle trace files with
190  // the initial node positions at the end.
191  std::ifstream file (m_filename.c_str (), std::ios::in);
192  if (file.is_open ())
193  {
194  while (!file.eof () )
195  {
196  int iNodeId = 0;
197  std::string nodeId;
198  std::string line;
199 
200  getline (file, line);
201 
202  // ignore empty lines
203  if (line.empty ())
204  {
205  continue;
206  }
207 
208  ParseResult pr = ParseNs2Line (line); // Parse line and obtain tokens
209 
210  // Check if the line corresponds with setting the initial
211  // node positions
212  if (pr.tokens.size () != 4)
213  {
214  continue;
215  }
216 
217  // Get the node Id
218  nodeId = GetNodeIdString (pr);
219  iNodeId = GetNodeIdInt (pr);
220  if (iNodeId == -1)
221  {
222  NS_LOG_ERROR ("Node number couldn't be obtained (corrupted file?): " << line << "\n");
223  continue;
224  }
225 
226  // get mobility model of node
228 
229  // if model not exists, continue
230  if (model == 0)
231  {
232  NS_LOG_ERROR ("Unknown node ID (corrupted file?): " << nodeId << "\n");
233  continue;
234  }
235 
236 
237  /*
238  * In this case a initial position is being seted
239  * line like $node_(0) set X_ 151.05190721688197
240  */
241  if (IsSetInitialPos (pr))
242  {
243  DestinationPoint point;
244  // coord coord value
245  point.m_finalPosition = SetInitialPosition (model, pr.tokens[2], pr.dvals[3]);
246  last_pos[iNodeId] = point;
247 
248  // Log new position
249  NS_LOG_DEBUG ("Positions after parse for node " << iNodeId << " " << nodeId <<
250  " position = " << last_pos[iNodeId].m_finalPosition);
251  }
252  }
253  file.close ();
254  }
255 
256  //*****************************************************************
257  // Parse the file a second time to get the rest of its values
258  //*****************************************************************
259 
260  // The reason the file is parsed again is to make this helper robust
261  // to handle trace files with the initial node positions at the end.
262  file.open (m_filename.c_str (), std::ios::in);
263  if (file.is_open ())
264  {
265  while (!file.eof () )
266  {
267  int iNodeId = 0;
268  std::string nodeId;
269  std::string line;
270 
271  getline (file, line);
272 
273  // ignore empty lines
274  if (line.empty ())
275  {
276  continue;
277  }
278 
279  ParseResult pr = ParseNs2Line (line); // Parse line and obtain tokens
280 
281  // Check if the line corresponds with one of the three types of line
282  if (pr.tokens.size () != 4 && pr.tokens.size () != 7 && pr.tokens.size () != 8)
283  {
284  NS_LOG_ERROR ("Line has not correct number of parameters (corrupted file?): " << line << "\n");
285  continue;
286  }
287 
288  // Get the node Id
289  nodeId = GetNodeIdString (pr);
290  iNodeId = GetNodeIdInt (pr);
291  if (iNodeId == -1)
292  {
293  NS_LOG_ERROR ("Node number couldn't be obtained (corrupted file?): " << line << "\n");
294  continue;
295  }
296 
297  // get mobility model of node
299 
300  // if model not exists, continue
301  if (model == 0)
302  {
303  NS_LOG_ERROR ("Unknown node ID (corrupted file?): " << nodeId << "\n");
304  continue;
305  }
306 
307 
308  /*
309  * In this case a initial position is being seted
310  * line like $node_(0) set X_ 151.05190721688197
311  */
312  if (IsSetInitialPos (pr))
313  {
314  // This is the second time this file has been parsed,
315  // and the initial node positions were already set the
316  // first time. So, do nothing this time with this line.
317  continue;
318  }
319 
320  else // NOW EVENTS TO BE SCHEDULED
321  {
322 
323  // This is a scheduled event, so time at should be present
324  double at;
325 
326  if (!IsNumber (pr.tokens[2]))
327  {
328  NS_LOG_WARN ("Time is not a number: " << pr.tokens[2]);
329  continue;
330  }
331 
332  at = pr.dvals[2]; // set time at
333 
334  if ( at < 0 )
335  {
336  NS_LOG_WARN ("Time is less than cero: " << at);
337  continue;
338  }
339 
340 
341 
342  /*
343  * In this case a new waypoint is added
344  * line like $ns_ at 1 "$node_(0) setdest 2 3 4"
345  */
346  if (IsSchedMobilityPos (pr))
347  {
348  if (last_pos[iNodeId].m_targetArrivalTime > at)
349  {
350  NS_LOG_LOGIC ("Did not reach a destination! stoptime = " << last_pos[iNodeId].m_targetArrivalTime << ", at = "<< at);
351  double actuallytraveled = at - last_pos[iNodeId].m_travelStartTime;
352  Vector reached = Vector (
353  last_pos[iNodeId].m_startPosition.x + last_pos[iNodeId].m_speed.x * actuallytraveled,
354  last_pos[iNodeId].m_startPosition.y + last_pos[iNodeId].m_speed.y * actuallytraveled,
355  0
356  );
357  NS_LOG_LOGIC ("Final point = " << last_pos[iNodeId].m_finalPosition << ", actually reached = " << reached);
358  last_pos[iNodeId].m_stopEvent.Cancel ();
359  last_pos[iNodeId].m_finalPosition = reached;
360  }
361  // last position time X coord Y coord velocity
362  last_pos[iNodeId] = SetMovement (model, last_pos[iNodeId].m_finalPosition, at, pr.dvals[5], pr.dvals[6], pr.dvals[7]);
363 
364  // Log new position
365  NS_LOG_DEBUG ("Positions after parse for node " << iNodeId << " " << nodeId << " position =" << last_pos[iNodeId].m_finalPosition);
366  }
367 
368 
369  /*
370  * Scheduled set position
371  * line like $ns_ at 4.634906291962 "$node_(0) set X_ 28.675920486450"
372  */
373  else if (IsSchedSetPos (pr))
374  {
375  // time coordinate coord value
376  last_pos[iNodeId].m_finalPosition = SetSchedPosition (model, at, pr.tokens[5], pr.dvals[6]);
377  if (last_pos[iNodeId].m_targetArrivalTime > at)
378  {
379  last_pos[iNodeId].m_stopEvent.Cancel ();
380  }
381  last_pos[iNodeId].m_targetArrivalTime = at;
382  last_pos[iNodeId].m_travelStartTime = at;
383  // Log new position
384  NS_LOG_DEBUG ("Positions after parse for node " << iNodeId << " " << nodeId <<
385  " position =" << last_pos[iNodeId].m_finalPosition);
386  }
387  else
388  {
389  NS_LOG_WARN ("Format Line is not correct: " << line << "\n");
390  }
391  }
392  }
393  file.close ();
394  }
395 }
396 
397 
399 ParseNs2Line (const std::string& str)
400 {
401  ParseResult ret;
402  std::istringstream s;
403  std::string line;
404 
405  // ignore comments (#)
406  size_t pos_sharp = str.find_first_of ('#');
407  if (pos_sharp != std::string::npos)
408  {
409  line = str.substr (0, pos_sharp);
410  }
411  else
412  {
413  line = str;
414  }
415 
416  line = TrimNs2Line (line);
417 
418  // If line hasn't a correct node Id
419  if (!HasNodeIdNumber (line))
420  {
421  NS_LOG_WARN ("Line has no node Id: " << line);
422  return ret;
423  }
424 
425  s.str (line);
426 
427  while (!s.eof ())
428  {
429  std::string x;
430  s >> x;
431  if (x.length () == 0)
432  {
433  continue;
434  }
435  ret.tokens.push_back (x);
436  int ii (0);
437  double d (0);
438  if (HasNodeIdNumber (x))
439  {
440  x = GetNodeIdFromToken (x);
441  }
442  ret.has_ival.push_back (IsVal<int> (x, ii));
443  ret.ivals.push_back (ii);
444  ret.has_dval.push_back (IsVal<double> (x, d));
445  ret.dvals.push_back (d);
446  ret.svals.push_back (x);
447  }
448 
449  size_t tokensLength = ret.tokens.size (); // number of tokens in line
450  size_t lasTokenLength = ret.tokens[tokensLength - 1].size (); // length of the last token
451 
452  // if it is a scheduled set _[XYZ] or a setdest I need to remove the last "
453  // and re-calculate values
454  if ( (tokensLength == 7 || tokensLength == 8)
455  && (ret.tokens[tokensLength - 1][lasTokenLength - 1] == '"') )
456  {
457 
458  // removes " from the last position
459  ret.tokens[tokensLength - 1] = ret.tokens[tokensLength - 1].substr (0,lasTokenLength - 1);
460 
461  std::string x;
462  x = ret.tokens[tokensLength - 1];
463 
464  if (HasNodeIdNumber (x))
465  {
466  x = GetNodeIdFromToken (x);
467  }
468 
469  // Re calculate values
470  int ii (0);
471  double d (0);
472  ret.has_ival[tokensLength - 1] = IsVal<int> (x, ii);
473  ret.ivals[tokensLength - 1] = ii;
474  ret.has_dval[tokensLength - 1] = IsVal<double> (x, d);
475  ret.dvals[tokensLength - 1] = d;
476  ret.svals[tokensLength - 1] = x;
477 
478  }
479  else if ( (tokensLength == 9 && ret.tokens[tokensLength - 1] == "\"")
480  || (tokensLength == 8 && ret.tokens[tokensLength - 1] == "\""))
481  {
482  // if the line has the " character in this way: $ns_ at 1 "$node_(0) setdest 2 2 1 "
483  // or in this: $ns_ at 4 "$node_(0) set X_ 2 " we need to ignore this last token
484 
485  ret.tokens.erase (ret.tokens.begin () + tokensLength - 1);
486  ret.has_ival.erase (ret.has_ival.begin () + tokensLength - 1);
487  ret.ivals.erase (ret.ivals.begin () + tokensLength - 1);
488  ret.has_dval.erase (ret.has_dval.begin () + tokensLength - 1);
489  ret.dvals.erase (ret.dvals.begin () + tokensLength - 1);
490  ret.svals.erase (ret.svals.begin () + tokensLength - 1);
491 
492  }
493 
494 
495 
496  return ret;
497 }
498 
499 
500 std::string
501 TrimNs2Line (const std::string& s)
502 {
503  std::string ret = s;
504 
505  while (ret.size () > 0 && isblank (ret[0]))
506  {
507  ret.erase (0, 1); // Removes blank spaces at the begining of the line
508  }
509 
510  while (ret.size () > 0 && isblank (ret[ret.size () - 1]))
511  {
512  ret.erase (ret.size () - 1, 1); // Removes blank spaces from at end of line
513  }
514 
515  return ret;
516 }
517 
518 
519 bool
520 IsNumber (const std::string& s)
521 {
522  char *endp;
523  double v = strtod (s.c_str (), &endp); // declared with warn_unused_result
524  NS_UNUSED (v); // suppress "set but not used" compiler warning
525  return endp == s.c_str () + s.size ();
526 }
527 
528 
529 template<class T>
530 bool IsVal (const std::string& str, T& ret)
531 {
532  if (str.size () == 0)
533  {
534  return false;
535  }
536  else if (IsNumber (str))
537  {
538  std::string s2 = str;
539  std::istringstream s (s2);
540  s >> ret;
541  return true;
542  }
543  else
544  {
545  return false;
546  }
547 }
548 
549 
550 bool
551 HasNodeIdNumber (std::string str)
552 {
553 
554  // find brackets
555  std::string::size_type startNodeId = str.find_first_of ("("); // index of left bracket
556  std::string::size_type endNodeId = str.find_first_of (")"); // index of right bracket
557 
558  // Get de nodeId in a string and in a int value
559  std::string nodeId; // node id
560 
561  // if no brackets, continue!
562  if (startNodeId == std::string::npos || endNodeId == std::string::npos)
563  {
564  return false;
565  }
566 
567  nodeId = str.substr (startNodeId + 1, endNodeId - (startNodeId + 1)); // set node id
568 
569  // is number is integer is not negative
570  if (IsNumber (nodeId) && (nodeId.find_first_of (".") == std::string::npos) && (nodeId[0] != '-'))
571  {
572  return true;
573  }
574  else
575  {
576  return false;
577  }
578 }
579 
580 
581 std::string
582 GetNodeIdFromToken (std::string str)
583 {
584  if (HasNodeIdNumber (str))
585  {
586  // find brackets
587  std::string::size_type startNodeId = str.find_first_of ("("); // index of left bracket
588  std::string::size_type endNodeId = str.find_first_of (")"); // index of right bracket
589 
590  return str.substr (startNodeId + 1, endNodeId - (startNodeId + 1)); // set node id
591  }
592  else
593  {
594  return "";
595  }
596 }
597 
598 
599 int
601 {
602  int result = -1;
603  switch (pr.tokens.size ())
604  {
605  case 4: // line like $node_(0) set X_ 11
606  result = pr.ivals[0];
607  break;
608  case 7: // line like $ns_ at 4 "$node_(0) set X_ 28"
609  result = pr.ivals[3];
610  break;
611  case 8: // line like $ns_ at 1 "$node_(0) setdest 2 3 4"
612  result = pr.ivals[3];
613  break;
614  default:
615  result = -1;
616  }
617  return result;
618 }
619 
620 // Get node id number in string format
621 std::string
623 {
624  switch (pr.tokens.size ())
625  {
626  case 4: // line like $node_(0) set X_ 11
627  return pr.svals[0];
628  break;
629  case 7: // line like $ns_ at 4 "$node_(0) set X_ 28"
630  return pr.svals[3];
631  break;
632  case 8: // line like $ns_ at 1 "$node_(0) setdest 2 3 4"
633  return pr.svals[3];
634  break;
635  default:
636  return "";
637  }
638 }
639 
640 
641 Vector
642 SetOneInitialCoord (Vector position, std::string& coord, double value)
643 {
644 
645  // set the position for the coord.
646  if (coord == NS2_X_COORD)
647  {
648  position.x = value;
649  NS_LOG_DEBUG ("X=" << value);
650  }
651  else if (coord == NS2_Y_COORD)
652  {
653  position.y = value;
654  NS_LOG_DEBUG ("Y=" << value);
655  }
656  else if (coord == NS2_Z_COORD)
657  {
658  position.z = value;
659  NS_LOG_DEBUG ("Z=" << value);
660  }
661  return position;
662 }
663 
664 
665 bool
667 {
668  // number of tokens has $node_( ? has "set" has doble for position?
669  return pr.tokens.size () == 4 && HasNodeIdNumber (pr.tokens[0]) && pr.tokens[1] == NS2_SET && pr.has_dval[3]
670  // coord name is X_, Y_ or Z_ ?
671  && (pr.tokens[2] == NS2_X_COORD || pr.tokens[2] == NS2_Y_COORD || pr.tokens[2] == NS2_Z_COORD);
672 
673 }
674 
675 
676 bool
678 {
679  // correct number of tokens, has $ns_ and at
680  return pr.tokens.size () == 7 && pr.tokens[0] == NS2_NS_SCH && pr.tokens[1] == NS2_AT
681  && pr.tokens[4] == NS2_SET && pr.has_dval[2] && pr.has_dval[3] // has set and double value for time and nodeid
682  && ( pr.tokens[5] == NS2_X_COORD || pr.tokens[5] == NS2_Y_COORD || pr.tokens[5] == NS2_Z_COORD) // has X_, Y_ or Z_?
683  && pr.has_dval[2]; // time is a number
684 }
685 
686 bool
688 {
689  // number of tokens and has $ns_ and has at
690  return pr.tokens.size () == 8 && pr.tokens[0] == NS2_NS_SCH && pr.tokens[1] == NS2_AT
691  // time x coord y coord velocity are numbers?
692  && pr.has_dval[2] && pr.has_dval[5] && pr.has_dval[6] && pr.has_dval[7]
693  && pr.tokens[4] == NS2_SETDEST; // and has setdest
694 
695 }
696 
697 DestinationPoint
699  double xFinalPosition, double yFinalPosition, double speed)
700 {
701  DestinationPoint retval;
702  retval.m_startPosition = last_pos;
703  retval.m_finalPosition = last_pos;
704  retval.m_travelStartTime = at;
705  retval.m_targetArrivalTime = at;
706 
707  if (speed == 0)
708  {
709  // We have to maintain last position, and stop the movement
711  Vector (0, 0, 0));
712  return retval;
713  }
714  if (speed > 0)
715  {
716  // first calculate the time; time = distance / speed
717  double time = std::sqrt (std::pow (xFinalPosition - retval.m_finalPosition.x, 2) + std::pow (yFinalPosition - retval.m_finalPosition.y, 2)) / speed;
718  NS_LOG_DEBUG ("at=" << at << " time=" << time);
719  if (time == 0)
720  {
721  return retval;
722  }
723  // now calculate the xSpeed = distance / time
724  double xSpeed = (xFinalPosition - retval.m_finalPosition.x) / time;
725  double ySpeed = (yFinalPosition - retval.m_finalPosition.y) / time; // & same with ySpeed
726  retval.m_speed = Vector (xSpeed, ySpeed, 0);
727 
728  // quick and dirty set zSpeed = 0
729  double zSpeed = 0;
730 
731  NS_LOG_DEBUG ("Calculated Speed: X=" << xSpeed << " Y=" << ySpeed << " Z=" << zSpeed);
732 
733  // Set the Values
734  Simulator::Schedule (Seconds (at), &ConstantVelocityMobilityModel::SetVelocity, model, Vector (xSpeed, ySpeed, zSpeed));
735  retval.m_stopEvent = Simulator::Schedule (Seconds (at + time), &ConstantVelocityMobilityModel::SetVelocity, model, Vector (0, 0, 0));
736  retval.m_finalPosition.x += xSpeed * time;
737  retval.m_finalPosition.y += ySpeed * time;
738  retval.m_targetArrivalTime += time;
739  }
740  return retval;
741 }
742 
743 
744 Vector
745 SetInitialPosition (Ptr<ConstantVelocityMobilityModel> model, std::string coord, double coordVal)
746 {
747  model->SetPosition (SetOneInitialCoord (model->GetPosition (), coord, coordVal));
748 
749  Vector position;
750  position.x = model->GetPosition ().x;
751  position.y = model->GetPosition ().y;
752  position.z = model->GetPosition ().z;
753 
754  return position;
755 }
756 
757 // Schedule a set of position for a node
758 Vector
759 SetSchedPosition (Ptr<ConstantVelocityMobilityModel> model, double at, std::string coord, double coordVal)
760 {
761  // update position
762  model->SetPosition (SetOneInitialCoord (model->GetPosition (), coord, coordVal));
763 
764  Vector position;
765  position.x = model->GetPosition ().x;
766  position.y = model->GetPosition ().y;
767  position.z = model->GetPosition ().z;
768 
769  // Chedule next positions
770  Simulator::Schedule (Seconds (at), &ConstantVelocityMobilityModel::SetPosition, model,position);
771 
772  return position;
773 }
774 
775 void
777 {
779 }
780 
781 } // namespace ns3
void ConfigNodesMovements(const ObjectStore &store) const
std::vector< bool > has_dval
double x
x coordinate of vector
Definition: vector.h:49
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
std::vector< bool > has_ival
static Vector SetOneInitialCoord(Vector actPos, std::string &coord, double value)
#define NS2_SETDEST
#define NS2_NS_SCH
static Vector SetInitialPosition(Ptr< ConstantVelocityMobilityModel > model, std::string coord, double coordVal)
static bool IsSchedSetPos(ParseResult pr)
static int GetNodeIdInt(ParseResult pr)
#define NS2_AT
static bool HasNodeIdNumber(std::string str)
Vector GetPosition(void) const
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:824
#define NS2_SET
Ptr< ConstantVelocityMobilityModel > GetMobilityModel(std::string idString, const ObjectStore &store) const
a 3d vector
Definition: vector.h:31
std::vector< std::string > tokens
#define NS2_Z_COORD
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
NS_LOG_COMPONENT_DEFINE("Ns2MobilityHelper")
void Install(void) const
Read the ns2 trace file and configure the movement patterns of all nodes contained in the global ns3:...
static bool IsSetInitialPos(ParseResult pr)
static Iterator End(void)
Definition: node-list.cc:188
Ptr< SampleEmitter > s
static std::string GetNodeIdFromToken(std::string str)
Vector3D Vector
Definition: vector.h:118
static DestinationPoint SetMovement(Ptr< ConstantVelocityMobilityModel > model, Vector lastPos, double at, double xFinalPosition, double yFinalPosition, double speed)
#define NS2_Y_COORD
std::vector< std::string > svals
virtual Ptr< Object > Get(uint32_t i) const =0
static ParseResult ParseNs2Line(const std::string &str)
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
#define NS2_X_COORD
static std::string GetNodeIdString(ParseResult pr)
std::vector< double > dvals
double y
y coordinate of vector
Definition: vector.h:53
Keeps last movement schedule.
Ns2MobilityHelper(std::string filename)
static Vector SetSchedPosition(Ptr< ConstantVelocityMobilityModel > model, double at, std::string coord, double coordVal)
void SetPosition(const Vector &position)
std::vector< int > ivals
an identifier for simulation events.
Definition: event-id.h:46
#define NS_LOG_WARN(msg)
Definition: log.h:280
static Iterator Begin(void)
Definition: node-list.cc:182
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
Mobility model for which the current speed does not change once it has been set and until it is set a...
#define NS_UNUSED(x)
Definition: unused.h:5
static std::string TrimNs2Line(const std::string &str)
#define NS_LOG_ERROR(msg)
Definition: log.h:271
static bool IsSchedMobilityPos(ParseResult pr)
static bool IsVal(const std::string &str, T &ret)
static bool IsNumber(const std::string &s)
double z
z coordinate of vector
Definition: vector.h:57