diff --git a/src/node/random-rectangle-topology.cc b/src/node/random-rectangle-topology.cc index 05b3af74d..77efba294 100644 --- a/src/node/random-rectangle-topology.cc +++ b/src/node/random-rectangle-topology.cc @@ -18,58 +18,63 @@ * * Author: Mathieu Lacage */ -#include "random-rectangle-topology.h" -#include "static-mobility-model.h" #include "ns3/random-variable-default-value.h" +#include "random-rectangle-topology.h" +#include "random-2d-position.h" +#include "mobility-model.h" namespace ns3 { -static RandomVariableDefaultValue -g_xVariable ("RandomRectangleTopologyX", - "Random variable to choose the x coordinate of the elements of a RandomRectangleTopology.", - "Uniform:-100:100"); -static RandomVariableDefaultValue -g_yVariable ("RandomRectangleTopologyY", - "Random variable to choose the y coordinate of the elements of a RandomRectangleTopology.", - "Uniform:-100:100"); +static ClassIdDefaultValue +g_position ("Random2dTopologyType", + "The type of initial random position in a 2d topology.", + Random2dPosition::iid, + "Rectangle"); + +static ClassIdDefaultValue +g_mobility ("Random2dTopologyMobilityModelType", + "The type of mobility model attached to an object in a 2d topology.", + MobilityModel::iid, + "StaticMobilityModel"); RandomRectangleTopology::RandomRectangleTopology () - : m_xVariable (g_xVariable.GetCopy ()), - m_yVariable (g_yVariable.GetCopy ()), - m_positionModel (StaticMobilityModel::cid) -{} - -RandomRectangleTopology::RandomRectangleTopology (double xMin, double xMax, double yMin, double yMax) - : m_xVariable (new UniformVariable (xMin, xMax)), - m_yVariable (new UniformVariable (yMin, yMax)), - m_positionModel (StaticMobilityModel::cid) -{} -RandomRectangleTopology::RandomRectangleTopology (const RandomVariable &xVariable, - const RandomVariable &yVariable) - : m_xVariable (xVariable.Copy ()), - m_yVariable (yVariable.Copy ()), - m_positionModel (StaticMobilityModel::cid) + : m_mobilityModel (g_mobility.GetValue ()) +{ + m_positionModel = ComponentManager::Create (g_position.GetValue (), + Random2dPosition::iid); +} +RandomRectangleTopology::RandomRectangleTopology (Ptr positionModel, ClassId mobilityModel) + : m_positionModel (positionModel), + m_mobilityModel (mobilityModel) {} RandomRectangleTopology::~RandomRectangleTopology () { - delete m_xVariable; - delete m_yVariable; - m_xVariable = 0; - m_yVariable = 0; + m_positionModel = 0; } void -RandomRectangleTopology::SetMobilityModelModel (ClassId classId) +RandomRectangleTopology::SetMobilityModel (ClassId classId) { - m_positionModel = classId; + m_mobilityModel = classId; +} + +void +RandomRectangleTopology::SetPositionModel (Ptr positionModel) +{ + m_positionModel = positionModel; } void RandomRectangleTopology::LayoutOne (Ptr object) { - double x = m_xVariable->GetValue (); - double y = m_yVariable->GetValue (); - object->AddInterface (ComponentManager::Create (m_positionModel, x, y)); + Position2d position2d = m_positionModel->Get (); + Ptr mobility = ComponentManager::Create (m_mobilityModel, + MobilityModel::iid); + Position position = mobility->Get (); + position.x = position2d.x; + position.y = position2d.y; + mobility->Set (position); + object->AddInterface (mobility); } diff --git a/src/node/random-rectangle-topology.h b/src/node/random-rectangle-topology.h index 7aa557ca2..4a5aa6621 100644 --- a/src/node/random-rectangle-topology.h +++ b/src/node/random-rectangle-topology.h @@ -21,33 +21,33 @@ #ifndef RANDOM_RECTANGLE_TOPOLOGY_H #define RANDOM_RECTANGLE_TOPOLOGY_H -#include "ns3/random-variable.h" #include "ns3/ptr.h" #include "ns3/object.h" #include "ns3/component-manager.h" namespace ns3 { +class Random2dPosition; + class RandomRectangleTopology { public: - RandomRectangleTopology (); - RandomRectangleTopology (double xMin, double xMax, double yMin, double yMax); - RandomRectangleTopology (const RandomVariable &xVariable, const RandomVariable &yVariable); + RandomRectangleTopology (Ptr positionModel, + ClassId mobilityModel); ~RandomRectangleTopology (); - void SetMobilityModelModel (ClassId classId); + void SetMobilityModel (ClassId classId); + void SetPositionModel (Ptr positionModel); void LayoutOne (Ptr object); template void Layout (const T &begin, const T &end); private: - RandomVariable *m_xVariable; - RandomVariable *m_yVariable; - ClassId m_positionModel; + Ptr m_positionModel; + ClassId m_mobilityModel; }; } // namespace ns3