A Discrete-Event Network Simulator
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
31namespace ns3
32{
33
34class 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 */
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 */
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 */
139 const ObjectStore& store) const;
140 std::string m_filename; //!< filename of file containing ns-2 mobility trace
141};
142
143} // namespace ns3
144
145namespace ns3
146{
147
148template <typename T>
149void
150Ns2MobilityHelper::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 */
a class to hold input objects internally
virtual Ptr< Object > Get(uint32_t i) const =0
Return ith object in store.
Helper class which can read ns-2 movement files and configure nodes mobility.
void ConfigNodesMovements(const ObjectStore &store) const
Parses ns-2 mobility file to create ns-3 mobility events.
void Install() const
Read the ns2 trace file and configure the movement patterns of all nodes contained in the global ns3:...
std::string m_filename
filename of file containing ns-2 mobility trace
Ptr< ConstantVelocityMobilityModel > GetMobilityModel(std::string idString, const ObjectStore &store) const
Get or create a ConstantVelocityMobilityModel corresponding to idString.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Every class exported by the ns3 library is enclosed in the ns3 namespace.