118 lines
3.1 KiB
C++
118 lines
3.1 KiB
C++
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
|
/*
|
|
* Copyright (c) 2007 INRIA
|
|
* All rights reserved.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation;
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*
|
|
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
|
*/
|
|
#ifndef NS2_MOBILITY_FILE_TOPOLOGY_H
|
|
#define NS2_MOBILITY_FILE_TOPOLOGY_H
|
|
|
|
#include <string>
|
|
#include <stdint.h>
|
|
#include "ns3/ptr.h"
|
|
#include "ns3/object.h"
|
|
#include "static-speed-mobility-model.h"
|
|
|
|
namespace ns3 {
|
|
|
|
/**
|
|
* \brief a topology object which can read ns2's movement files
|
|
* generated by the CMU setdest tool.
|
|
*/
|
|
class Ns2MobilityHelper
|
|
{
|
|
public:
|
|
/**
|
|
* \param filename filename of file which contains the
|
|
* ns2 movement trace.
|
|
*/
|
|
Ns2MobilityHelper (std::string filename);
|
|
|
|
void EnableNotifier (void);
|
|
void DisableNotifier (void);
|
|
|
|
/**
|
|
* Read the ns2 trace file and configure the movement
|
|
* patterns of all nodes contained in the global ns3::NodeList
|
|
* whose nodeId is matches the nodeId of the nodes in the trace
|
|
* file.
|
|
*/
|
|
void Layout (void) const;
|
|
|
|
/**
|
|
* \param begin an iterator which points to the start of the input
|
|
* object array.
|
|
* \param end an iterator which points to the end of the input
|
|
* object array.
|
|
*
|
|
* Read the ns2 trace file and configure the movement
|
|
* patterns of all input objects. Each input object
|
|
* is identified by a unique node id which reflects
|
|
* the index of the object in the input array.
|
|
*/
|
|
template <typename T>
|
|
void Layout (T begin, T end) const;
|
|
private:
|
|
class ObjectStore
|
|
{
|
|
public:
|
|
virtual ~ObjectStore () {}
|
|
virtual Ptr<Object> Get (uint32_t i) const = 0;
|
|
};
|
|
void LayoutObjectStore (const ObjectStore &store) const;
|
|
Ptr<StaticSpeedMobilityModel> GetMobilityModel (std::string idString, const ObjectStore &store) const;
|
|
double ReadDouble (std::string valueString) const;
|
|
std::string m_filename;
|
|
bool m_notifierEnabled;
|
|
};
|
|
|
|
} // namespace ns3
|
|
|
|
namespace ns3 {
|
|
|
|
template <typename T>
|
|
void
|
|
Ns2MobilityHelper::Layout (T begin, T end) const
|
|
{
|
|
class MyObjectStore : public ObjectStore
|
|
{
|
|
public:
|
|
MyObjectStore (T begin, T end)
|
|
: m_begin (begin),
|
|
m_end (end)
|
|
{}
|
|
virtual Ptr<Object> Get (uint32_t i) const {
|
|
T iterator = m_begin;
|
|
iterator += i;
|
|
if (iterator >= m_end)
|
|
{
|
|
return 0;
|
|
}
|
|
return *iterator;
|
|
}
|
|
private:
|
|
T m_begin;
|
|
T m_end;
|
|
};
|
|
LayoutObjectStore (MyObjectStore (begin, end));
|
|
}
|
|
|
|
|
|
} // namespace ns3
|
|
|
|
#endif /* NS2_MOBILITY_FILE_TOPOLOGY_H */
|