A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
bonnmotion-ns2-example.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright 2012 Eric Gamess
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
*/
19
20
/*
21
* Example program using a ns-2-formatted mobility trace generated
22
* by the BonnMotion mobility framework.
23
*
24
* With the provided tracefile (bonnmotion.ns_movements), the movements of
25
* one node are simulated for 1000 seconds. There are a few other files
26
* that provide metadata about the mobility:
27
* - src/mobility/examples/bonnmotion.ns_params
28
* - src/mobility/examples/bonnmotion.params
29
*
30
* These files are documented in the BonnMotion documentation.
31
*
32
* It is important to remember that the trace file dictates how many nodes
33
* (in this case, one) and how long (in this case, 1000 seconds) that the
34
* ns-3 program should use. If you want to change the mobility pattern,
35
* number of nodes, or duration, you need to use BonnMotion or another
36
* tool to generate a new trace.
37
*
38
* Finally, note that you can visualize this program using the pyviz
39
* visualizer:
40
* ./ns3 run bonnmotion-ns2-example --vis
41
*/
42
43
#include "ns3/core-module.h"
44
#include "ns3/mobility-module.h"
45
46
using namespace
ns3
;
47
48
void
showPosition
(
Ptr<Node>
node,
double
deltaTime)
49
{
50
uint32_t nodeId = node->
GetId
();
51
Ptr<MobilityModel>
mobModel = node->
GetObject
<
MobilityModel
> ();
52
Vector3D
pos = mobModel->
GetPosition
();
53
Vector3D
speed = mobModel->
GetVelocity
();
54
std::cout <<
"At "
<<
Simulator::Now
().
GetSeconds
() <<
" node "
<< nodeId
55
<<
": Position("
<< pos.x <<
", "
<< pos.y <<
", "
<< pos.z
56
<<
"); Speed("
<< speed.
x
<<
", "
<< speed.
y
<<
", "
<< speed.
z
57
<<
")"
<< std::endl;
58
59
Simulator::Schedule
(
Seconds
(deltaTime), &
showPosition
, node, deltaTime);
60
}
61
62
int
main (
int
argc,
char
*argv[])
63
{
64
std::cout.precision (2);
65
std::cout.setf (std::ios::fixed);
66
67
double
deltaTime = 100;
68
std::string traceFile =
"src/mobility/examples/bonnmotion.ns_movements"
;
69
70
CommandLine
cmd
(__FILE__);
71
cmd
.AddValue (
"traceFile"
,
"Ns2 movement trace file"
, traceFile);
72
cmd
.AddValue (
"deltaTime"
,
"time interval (s) between updates (default 100)"
, deltaTime);
73
cmd
.Parse (argc, argv);
74
75
Ptr<Node>
n0 = CreateObject<Node> ();
76
77
Ns2MobilityHelper
ns2 =
Ns2MobilityHelper
(traceFile);
78
ns2.
Install
();
79
80
Simulator::Schedule
(
Seconds
(0.0), &
showPosition
, n0, deltaTime);
81
82
Simulator::Stop
(
Seconds
(1000.0));
83
Simulator::Run
();
84
Simulator::Destroy
();
85
return
0;
86
}
87
88
showPosition
void showPosition(Ptr< Node > node, double deltaTime)
Definition:
bonnmotion-ns2-example.cc:48
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:229
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition:
mobility-model.h:40
ns3::MobilityModel::GetVelocity
Vector GetVelocity(void) const
Definition:
mobility-model.cc:82
ns3::MobilityModel::GetPosition
Vector GetPosition(void) const
Definition:
mobility-model.cc:64
ns3::Node::GetId
uint32_t GetId(void) const
Definition:
node.cc:109
ns3::Ns2MobilityHelper
Helper class which can read ns-2 movement files and configure nodes mobility.
Definition:
ns2-mobility-helper.h:77
ns3::Ns2MobilityHelper::Install
void Install(void) const
Read the ns2 trace file and configure the movement patterns of all nodes contained in the global ns3:...
Definition:
ns2-mobility-helper.cc:849
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition:
object.h:470
ns3::Ptr< Node >
ns3::Simulator::Stop
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition:
simulator.cc:180
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:136
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition:
simulator.h:556
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition:
simulator.cc:172
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition:
simulator.cc:195
ns3::Time::GetSeconds
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition:
nstime.h:379
ns3::Vector3D
a 3d vector
Definition:
vector.h:46
ns3::Vector3D::x
double x
x coordinate of vector
Definition:
vector.h:59
ns3::Vector3D::z
double z
z coordinate of vector
Definition:
vector.h:61
ns3::Vector3D::y
double y
y coordinate of vector
Definition:
vector.h:60
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1244
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
cmd
Definition:
second.py:35
src
mobility
examples
bonnmotion-ns2-example.cc
Generated on Tue Feb 6 2024 19:21:24 for ns-3 by
1.9.1