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
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
*/
7
8
/*
9
* Example program using a ns-2-formatted mobility trace generated
10
* by the BonnMotion mobility framework.
11
*
12
* With the provided tracefile (bonnmotion.ns_movements), the movements of
13
* one node are simulated for 1000 seconds. There are a few other files
14
* that provide metadata about the mobility:
15
* - src/mobility/examples/bonnmotion.ns_params
16
* - src/mobility/examples/bonnmotion.params
17
*
18
* These files are documented in the BonnMotion documentation.
19
*
20
* It is important to remember that the trace file dictates how many nodes
21
* (in this case, one) and how long (in this case, 1000 seconds) that the
22
* ns-3 program should use. If you want to change the mobility pattern,
23
* number of nodes, or duration, you need to use BonnMotion or another
24
* tool to generate a new trace.
25
*
26
* Finally, note that you can visualize this program using the pyviz
27
* visualizer:
28
* ./ns3 run bonnmotion-ns2-example --vis
29
*/
30
31
#include "ns3/core-module.h"
32
#include "ns3/mobility-module.h"
33
34
using namespace
ns3
;
35
36
void
37
showPosition
(
Ptr<Node>
node,
double
deltaTime)
38
{
39
uint32_t
nodeId = node->GetId();
40
Ptr<MobilityModel>
mobModel = node->GetObject<
MobilityModel
>();
41
Vector3D
pos = mobModel->GetPosition();
42
Vector3D
speed = mobModel->GetVelocity();
43
std::cout <<
"At "
<<
Simulator::Now
().
GetSeconds
() <<
" node "
<< nodeId <<
": Position("
44
<< pos.x <<
", "
<< pos.y <<
", "
<< pos.z <<
"); Speed("
<< speed.
x
<<
", "
45
<< speed.
y
<<
", "
<< speed.
z
<<
")"
<< std::endl;
46
47
Simulator::Schedule
(
Seconds
(deltaTime), &
showPosition
, node, deltaTime);
48
}
49
50
int
51
main(
int
argc,
char
* argv[])
52
{
53
std::cout.precision(2);
54
std::cout.setf(std::ios::fixed);
55
56
double
deltaTime = 100;
57
std::string traceFile =
"src/mobility/examples/bonnmotion.ns_movements"
;
58
59
CommandLine
cmd
(__FILE__);
60
cmd
.AddValue(
"traceFile"
,
"Ns2 movement trace file"
, traceFile);
61
cmd
.AddValue(
"deltaTime"
,
"time interval (s) between updates (default 100)"
, deltaTime);
62
cmd
.Parse(argc, argv);
63
64
Ptr<Node>
n0 =
CreateObject<Node>
();
65
66
Ns2MobilityHelper
ns2 =
Ns2MobilityHelper
(traceFile);
67
ns2.
Install
();
68
69
Simulator::Schedule
(
Seconds
(0.0), &
showPosition
, n0, deltaTime);
70
71
Simulator::Stop
(
Seconds
(1000.0));
72
Simulator::Run
();
73
Simulator::Destroy
();
74
return
0;
75
}
showPosition
void showPosition(Ptr< Node > node, double deltaTime)
Definition
bonnmotion-ns2-example.cc:37
ns3::CommandLine
Parse command-line arguments.
Definition
command-line.h:221
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition
mobility-model.h:29
ns3::Ns2MobilityHelper
Helper class which can read ns-2 movement files and configure nodes mobility.
Definition
ns2-mobility-helper.h:67
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:851
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::Simulator::Schedule
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition
simulator.h:560
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition
simulator.cc:197
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::Simulator::Stop
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition
simulator.cc:175
ns3::Time::GetSeconds
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition
nstime.h:392
ns3::Vector3D
a 3d vector
Definition
vector.h:35
ns3::Vector3D::x
double x
x coordinate of vector
Definition
vector.h:48
ns3::Vector3D::z
double z
z coordinate of vector
Definition
vector.h:50
ns3::Vector3D::y
double y
y coordinate of vector
Definition
vector.h:49
uint32_t
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1308
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
cmd
Definition
second.py:29
src
mobility
examples
bonnmotion-ns2-example.cc
Generated on Fri Nov 8 2024 13:59:04 for ns-3 by
1.11.0