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
ns2-mobility-helper.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2007 INRIA
3
* 2009,2010 Contributors
4
*
5
* SPDX-License-Identifier: GPL-2.0-only
6
*
7
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8
* Contributors: Thomas Waldecker <twaldecker@rocketmail.com>
9
* MartÃn Giachino <martin.giachino@gmail.com>
10
*/
11
#ifndef NS2_MOBILITY_HELPER_H
12
#define NS2_MOBILITY_HELPER_H
13
14
#include "ns3/object.h"
15
#include "ns3/ptr.h"
16
17
#include <stdint.h>
18
#include <string>
19
20
namespace
ns3
21
{
22
23
class
ConstantVelocityMobilityModel;
24
25
/**
26
* \ingroup mobility
27
* \brief Helper class which can read ns-2 movement files and configure nodes mobility.
28
*
29
* This implementation is based on the ns2 movement documentation of ns2
30
* as described in http://www.isi.edu/nsnam/ns/doc/node172.html
31
*
32
* Valid trace files use the following ns2 statements:
33
\verbatim
34
$node set X_ x1
35
$node set Y_ y1
36
$node set Z_ z1
37
$ns at $time $node setdest x2 y2 speed
38
$ns at $time $node set X_ x1
39
$ns at $time $node set Y_ Y1
40
$ns at $time $node set Z_ Z1
41
\endverbatim
42
*
43
* Note that initial position statements may also appear at the end of
44
* the mobility file like this:
45
\verbatim
46
$ns at $time $node setdest x2 y2 speed
47
$ns at $time $node set X_ x1
48
$ns at $time $node set Y_ Y1
49
$ns at $time $node set Z_ Z1
50
$node set X_ x1
51
$node set Y_ y1
52
$node set Z_ z1
53
\endverbatim
54
*
55
* The following tools are known to support this format:
56
* - BonnMotion http://net.cs.uni-bonn.de/wg/cs/applications/bonnmotion/
57
* - SUMO http://sourceforge.net/apps/mediawiki/sumo/index.php?title=Main_Page
58
* - TraNS https://web.archive.org/web/20190512111856/http://lca.epfl.ch/projects/trans/
59
*
60
* See usage example in examples/mobility/ns2-mobility-trace.cc
61
*
62
* \bug Rounding errors may cause movement to diverge from the mobility
63
* pattern in ns-2 (using the same trace).
64
* See https://www.nsnam.org/bugzilla/show_bug.cgi?id=1316
65
*/
66
class
Ns2MobilityHelper
67
{
68
public
:
69
/**
70
* \param filename filename of file which contains the
71
* ns2 movement trace.
72
*/
73
Ns2MobilityHelper
(std::string filename);
74
75
/**
76
* Read the ns2 trace file and configure the movement
77
* patterns of all nodes contained in the global ns3::NodeList
78
* whose nodeId is matches the nodeId of the nodes in the trace
79
* file.
80
*/
81
void
Install
()
const
;
82
83
/**
84
* \param begin an iterator which points to the start of the input
85
* object array.
86
* \param end an iterator which points to the end of the input
87
* object array.
88
*
89
* Read the ns2 trace file and configure the movement
90
* patterns of all input objects. Each input object
91
* is identified by a unique node id which reflects
92
* the index of the object in the input array.
93
*/
94
template
<
typename
T>
95
void
Install
(T begin, T end)
const
;
96
97
private
:
98
/**
99
* \brief a class to hold input objects internally
100
*/
101
class
ObjectStore
102
{
103
public
:
104
virtual
~ObjectStore
()
105
{
106
}
107
108
/**
109
* Return ith object in store
110
* \param i index
111
* \return pointer to object
112
*/
113
virtual
Ptr<Object>
Get
(
uint32_t
i)
const
= 0;
114
};
115
116
/**
117
* Parses ns-2 mobility file to create ns-3 mobility events
118
* \param store Object store containing ns-3 mobility models
119
*/
120
void
ConfigNodesMovements
(
const
ObjectStore
& store)
const
;
121
/**
122
* Get or create a ConstantVelocityMobilityModel corresponding to idString
123
* \param idString string name for a node
124
* \param store Object store containing ns-3 mobility models
125
* \return pointer to a ConstantVelocityMobilityModel
126
*/
127
Ptr<ConstantVelocityMobilityModel>
GetMobilityModel
(std::string idString,
128
const
ObjectStore
& store)
const
;
129
std::string
m_filename
;
//!< filename of file containing ns-2 mobility trace
130
};
131
132
}
// namespace ns3
133
134
namespace
ns3
135
{
136
137
template
<
typename
T>
138
void
139
Ns2MobilityHelper::Install
(T begin, T end)
const
140
{
141
class
MyObjectStore :
public
ObjectStore
142
{
143
public
:
144
MyObjectStore(T begin, T end)
145
: m_begin(begin),
146
m_end(end)
147
{
148
}
149
150
Ptr<Object>
Get(
uint32_t
i)
const override
151
{
152
T iterator = m_begin;
153
iterator += i;
154
if
(iterator >= m_end)
155
{
156
return
nullptr
;
157
}
158
return
*iterator;
159
}
160
161
private
:
162
T m_begin;
163
T m_end;
164
};
165
166
ConfigNodesMovements
(MyObjectStore(begin, end));
167
}
168
169
}
// namespace ns3
170
171
#endif
/* NS2_MOBILITY_HELPER_H */
ns3::Ns2MobilityHelper::ObjectStore
a class to hold input objects internally
Definition
ns2-mobility-helper.h:102
ns3::Ns2MobilityHelper::ObjectStore::Get
virtual Ptr< Object > Get(uint32_t i) const =0
Return ith object in store.
ns3::Ns2MobilityHelper::ObjectStore::~ObjectStore
virtual ~ObjectStore()
Definition
ns2-mobility-helper.h:104
ns3::Ns2MobilityHelper
Helper class which can read ns-2 movement files and configure nodes mobility.
Definition
ns2-mobility-helper.h:67
ns3::Ns2MobilityHelper::ConfigNodesMovements
void ConfigNodesMovements(const ObjectStore &store) const
Parses ns-2 mobility file to create ns-3 mobility events.
Definition
ns2-mobility-helper.cc:255
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::Ns2MobilityHelper::m_filename
std::string m_filename
filename of file containing ns-2 mobility trace
Definition
ns2-mobility-helper.h:129
ns3::Ns2MobilityHelper::GetMobilityModel
Ptr< ConstantVelocityMobilityModel > GetMobilityModel(std::string idString, const ObjectStore &store) const
Get or create a ConstantVelocityMobilityModel corresponding to idString.
Definition
ns2-mobility-helper.cc:234
ns3::Ns2MobilityHelper::Ns2MobilityHelper
Ns2MobilityHelper(std::string filename)
Definition
ns2-mobility-helper.cc:222
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
uint32_t
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
mobility
helper
ns2-mobility-helper.h
Generated on Fri Nov 8 2024 13:59:04 for ns-3 by
1.11.0