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
78{
79 public:
84 Ns2MobilityHelper(std::string filename);
85
92 void Install() const;
93
105 template <typename T>
106 void Install(T begin, T end) const;
107
108 private:
113 {
114 public:
115 virtual ~ObjectStore()
116 {
117 }
118
124 virtual Ptr<Object> Get(uint32_t i) const = 0;
125 };
126
131 void ConfigNodesMovements(const ObjectStore& store) const;
139 const ObjectStore& store) const;
140 std::string m_filename;
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:78
Every class exported by the ns3 library is enclosed in the ns3 namespace.