A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
31 namespace ns3 {
32 
33 class ConstantVelocityMobilityModel;
34 
77 {
78 public:
83  Ns2MobilityHelper (std::string filename);
84 
91  void Install (void) const;
92 
104  template <typename T>
105  void Install (T begin, T end) const;
106 private:
108  {
109 public:
110  virtual ~ObjectStore () {}
111  virtual Ptr<Object> Get (uint32_t i) const = 0;
112  };
113  void ConfigNodesMovements (const ObjectStore &store) const;
114  Ptr<ConstantVelocityMobilityModel> GetMobilityModel (std::string idString, const ObjectStore &store) const;
115  std::string m_filename;
116 };
117 
118 } // namespace ns3
119 
120 namespace ns3 {
121 
122 template <typename T>
123 void
124 Ns2MobilityHelper::Install (T begin, T end) const
125 {
126  class MyObjectStore : public ObjectStore
127  {
128 public:
129  MyObjectStore (T begin, T end)
130  : m_begin (begin),
131  m_end (end)
132  {}
133  virtual Ptr<Object> Get (uint32_t i) const {
134  T iterator = m_begin;
135  iterator += i;
136  if (iterator >= m_end)
137  {
138  return 0;
139  }
140  return *iterator;
141  }
142 private:
143  T m_begin;
144  T m_end;
145  };
146  ConfigNodesMovements (MyObjectStore (begin, end));
147 }
148 
149 
150 } // namespace ns3
151 
152 #endif /* NS2_MOBILITY_HELPER_H */
void ConfigNodesMovements(const ObjectStore &store) const
Ptr< ConstantVelocityMobilityModel > GetMobilityModel(std::string idString, const ObjectStore &store) const
void Install(void) const
Read the ns2 trace file and configure the movement patterns of all nodes contained in the global ns3:...
Helper class which can read ns-2 movement files and configure nodes mobility.
virtual Ptr< Object > Get(uint32_t i) const =0
Ns2MobilityHelper(std::string filename)