A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
bonnmotion-ns2-example.cc
Go to the documentation of this file.
1
/*
2
* Copyright 2012 Eric Gamess
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
*/
18
19
/*
20
* Example program using a ns-2-formatted mobility trace generated
21
* by the BonnMotion mobility framework.
22
*
23
* With the provided tracefile (bonnmotion.ns_movements), the movements of
24
* one node are simulated for 1000 seconds. There are a few other files
25
* that provide metadata about the mobility:
26
* - src/mobility/examples/bonnmotion.ns_params
27
* - src/mobility/examples/bonnmotion.params
28
*
29
* These files are documented in the BonnMotion documentation.
30
*
31
* It is important to remember that the trace file dictates how many nodes
32
* (in this case, one) and how long (in this case, 1000 seconds) that the
33
* ns-3 program should use. If you want to change the mobility pattern,
34
* number of nodes, or duration, you need to use BonnMotion or another
35
* tool to generate a new trace.
36
*
37
* Finally, note that you can visualize this program using the pyviz
38
* visualizer:
39
* ./ns3 run bonnmotion-ns2-example --vis
40
*/
41
42
#include "ns3/core-module.h"
43
#include "ns3/mobility-module.h"
44
45
using namespace
ns3
;
46
47
void
48
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 <<
": Position("
55
<< pos.x <<
", "
<< pos.y <<
", "
<< pos.z <<
"); Speed("
<< speed.
x
<<
", "
56
<< speed.
y
<<
", "
<< speed.
z
<<
")"
<< std::endl;
57
58
Simulator::Schedule
(
Seconds
(deltaTime), &
showPosition
, node, deltaTime);
59
}
60
61
int
62
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
}
showPosition
void showPosition(Ptr< Node > node, double deltaTime)
Definition:
bonnmotion-ns2-example.cc:48
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:232
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition:
mobility-model.h:40
ns3::Ns2MobilityHelper
Helper class which can read ns-2 movement files and configure nodes mobility.
Definition:
ns2-mobility-helper.h:78
ns3::Ns2MobilityHelper::Install
void Install() const
Read the ns2 trace file and configure the movement patterns of all nodes contained in the global ns3:...
Definition:
ns2-mobility-helper.cc:864
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:78
ns3::Simulator::Schedule
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition:
simulator.h:568
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:140
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition:
simulator.cc:199
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition:
simulator.cc:176
ns3::Simulator::Stop
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition:
simulator.cc:184
ns3::Time::GetSeconds
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition:
nstime.h:402
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
uint32_t
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1336
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
ns cmd
Definition:
second.py:33
src
mobility
examples
bonnmotion-ns2-example.cc
Generated on Sun Jul 2 2023 18:21:55 for ns-3 by
1.9.6