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 * 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
20namespace ns3
21{
22
23class 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 */
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 */
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 */
128 const ObjectStore& store) const;
129 std::string m_filename; //!< filename of file containing ns-2 mobility trace
130};
131
132} // namespace ns3
133
134namespace ns3
135{
136
137template <typename T>
138void
139Ns2MobilityHelper::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 */
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.
Ns2MobilityHelper(std::string filename)
Smart pointer class similar to boost::intrusive_ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.