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