rework slightly ns2 mobility support

This commit is contained in:
Mathieu Lacage
2008-02-08 17:27:38 +01:00
parent 16a94230d2
commit cf48df0f49
3 changed files with 35 additions and 12 deletions

View File

@@ -24,21 +24,34 @@
#include "ns3/simulator.h"
#include "ns3/node-list.h"
#include "ns3/node.h"
#include "ns2-mobility-file-topology.h"
#include "ns2-mobility-helper.h"
#include "static-speed-mobility-model.h"
#include "mobility-model-notifier.h"
NS_LOG_COMPONENT_DEFINE ("Ns2MobilityFileTopology");
NS_LOG_COMPONENT_DEFINE ("Ns2MobilityHelper");
namespace ns3 {
Ns2MobilityFileTopology::Ns2MobilityFileTopology (std::string filename)
Ns2MobilityHelper::Ns2MobilityHelper (std::string filename)
: m_filename (filename)
{}
void
Ns2MobilityHelper::EnableNotifier (void)
{
m_notifierEnabled = true;
}
void
Ns2MobilityHelper::DisableNotifier (void)
{
m_notifierEnabled = false;
}
Ptr<StaticSpeedMobilityModel>
Ns2MobilityFileTopology::GetMobilityModel (std::string idString, const ObjectStore &store) const
Ns2MobilityHelper::GetMobilityModel (std::string idString, const ObjectStore &store) const
{
std::istringstream iss;
iss.str (idString);
@@ -55,11 +68,17 @@ Ns2MobilityFileTopology::GetMobilityModel (std::string idString, const ObjectSto
model = CreateObject<StaticSpeedMobilityModel> ();
object->AddInterface (model);
}
Ptr<MobilityModelNotifier> notifier = object->QueryInterface<MobilityModelNotifier> ();
if (notifier == 0)
{
notifier = CreateObject<MobilityModelNotifier> ();
object->AddInterface (notifier);
}
return model;
}
double
Ns2MobilityFileTopology::ReadDouble (std::string valueString) const
Ns2MobilityHelper::ReadDouble (std::string valueString) const
{
std::istringstream iss;
iss.str (valueString);
@@ -69,7 +88,7 @@ Ns2MobilityFileTopology::ReadDouble (std::string valueString) const
}
void
Ns2MobilityFileTopology::LayoutObjectStore (const ObjectStore &store) const
Ns2MobilityHelper::LayoutObjectStore (const ObjectStore &store) const
{
std::ifstream file (m_filename.c_str (), std::ios::in);
if (file.is_open())
@@ -136,7 +155,7 @@ Ns2MobilityFileTopology::LayoutObjectStore (const ObjectStore &store) const
}
void
Ns2MobilityFileTopology::Layout (void) const
Ns2MobilityHelper::Layout (void) const
{
Layout (NodeList::Begin (), NodeList::End ());
}

View File

@@ -33,14 +33,17 @@ namespace ns3 {
* \brief a topology object which can read ns2's movement files
* generated by the CMU setdest tool.
*/
class Ns2MobilityFileTopology
class Ns2MobilityHelper
{
public:
/**
* \param filename filename of file which contains the
* ns2 movement trace.
*/
Ns2MobilityFileTopology (std::string filename);
Ns2MobilityHelper (std::string filename);
void EnableNotifier (void);
void DisableNotifier (void);
/**
* Read the ns2 trace file and configure the movement
@@ -74,6 +77,7 @@ private:
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
@@ -82,7 +86,7 @@ namespace ns3 {
template <typename T>
void
Ns2MobilityFileTopology::Layout (T begin, T end) const
Ns2MobilityHelper::Layout (T begin, T end) const
{
class MyObjectStore : public ObjectStore
{

View File

@@ -16,7 +16,7 @@ def build(bld):
'random-waypoint-mobility-model.cc',
'random-walk-2d-mobility-model.cc',
'random-direction-2d-mobility-model.cc',
'ns2-mobility-file-topology.cc',
'ns2-mobility-helper.cc',
'mobility-helper.cc',
]
@@ -35,6 +35,6 @@ def build(bld):
'random-waypoint-mobility-model.h',
'random-walk-2d-mobility-model.h',
'random-direction-2d-mobility-model.h',
'ns2-mobility-file-topology.h',
'ns2-mobility-helper.h',
'mobility-helper.h',
]