A Discrete-Event Network Simulator
API
ns2-mobility-helper.h
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2007 INRIA
4 * 2009,2010 Contributors
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20 * Contributors: Thomas Waldecker <twaldecker@rocketmail.com>
21 * Martín Giachino <martin.giachino@gmail.com>
22 */
23#ifndef NS2_MOBILITY_HELPER_H
24#define NS2_MOBILITY_HELPER_H
25
26#include <string>
27#include <stdint.h>
28#include "ns3/ptr.h"
29#include "ns3/object.h"
30
31namespace ns3 {
32
33class ConstantVelocityMobilityModel;
34
77{
78public:
83 Ns2MobilityHelper (std::string filename);
84
91 void Install (void) const;
92
104 template <typename T>
105 void Install (T begin, T end) const;
106private:
111 {
112public:
113 virtual ~ObjectStore () {}
119 virtual Ptr<Object> Get (uint32_t i) const = 0;
120 };
125 void ConfigNodesMovements (const ObjectStore &store) const;
132 Ptr<ConstantVelocityMobilityModel> GetMobilityModel (std::string idString, const ObjectStore &store) const;
133 std::string m_filename;
134};
135
136} // namespace ns3
137
138namespace ns3 {
139
140template <typename T>
141void
142Ns2MobilityHelper::Install (T begin, T end) const
143{
144 class MyObjectStore : public ObjectStore
145 {
146public:
147 MyObjectStore (T begin, T end)
148 : m_begin (begin),
149 m_end (end)
150 {}
151 virtual Ptr<Object> Get (uint32_t i) const {
152 T iterator = m_begin;
153 iterator += i;
154 if (iterator >= m_end)
155 {
156 return 0;
157 }
158 return *iterator;
159 }
160private:
161 T m_begin;
162 T m_end;
163 };
164 ConfigNodesMovements (MyObjectStore (begin, end));
165}
166
167
168} // namespace ns3
169
170#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.
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)
void Install(void) const
Read the ns2 trace file and configure the movement patterns of all nodes contained in the global ns3:...
Every class exported by the ns3 library is enclosed in the ns3 namespace.