diff --git a/samples/main-propagation-loss.cc b/samples/main-propagation-loss.cc index 0af0f536f..aab32e467 100644 --- a/samples/main-propagation-loss.cc +++ b/samples/main-propagation-loss.cc @@ -28,7 +28,10 @@ PrintOne (double minTxpower, double maxTxpower, double stepTxpower, double min, { Ptr a = CreateObject (); Ptr b = CreateObject (); - Ptr model = PropagationLossModel::CreateDefault (); + Ptr log = CreateObjectWith (); + log->SetReferenceModel (CreateObjectWith ()); + + Ptr model = log; a->SetPosition (Vector (0.0, 0.0, 0.0)); for (double x = min; x < max; x+= step) diff --git a/src/devices/wifi/propagation-delay-model.cc b/src/devices/wifi/propagation-delay-model.cc index b55154766..229c1516e 100644 --- a/src/devices/wifi/propagation-delay-model.cc +++ b/src/devices/wifi/propagation-delay-model.cc @@ -19,61 +19,30 @@ */ #include "propagation-delay-model.h" #include "ns3/random-variable.h" -#include "ns3/default-value.h" -#include "ns3/random-variable-default-value.h" #include "ns3/mobility-model.h" +#include "ns3/double.h" namespace ns3 { -enum ModelType -{ - RANDOM, - CONSTANT_SPEED -}; - -static EnumDefaultValue g_modelType -("PropagationDelayModelType", - "The type of propagation delay model to use.", - CONSTANT_SPEED, "ConstantSpeed", - RANDOM, "Random", - 0, (void*)0); - -static NumericDefaultValue g_speed -("PropagationDelayConstantSpeed", - "The speed (m/s) of propagation if a ConstantSpeed propagation delay model is used.", - 300000000.0); - -static RandomVariableDefaultValue g_random -("PropagationDelayRandomDistribution", - "The delay distribution to use if a Random propagation delay model is used.", - "Uniform:0:1.0"); - - PropagationDelayModel::~PropagationDelayModel () {} -Ptr -PropagationDelayModel::CreateDefault (void) + +TypeId +RandomPropagationDelayModel::GetTypeId (void) { - switch (g_modelType.GetValue ()) { - case CONSTANT_SPEED: - return CreateObject (g_speed.GetValue ()); - break; - case RANDOM: - return CreateObject (); - break; - default: - NS_ASSERT (false); - return 0; - break; - } + static TypeId tid = TypeId ("RandomPropagationDelayModel") + .SetParent () + .AddConstructor () + .AddAttribute ("Variable", + "The random variable which generates random delays (s).", + UniformVariable (0.0, 1.0), + MakeRandomVariableAccessor (&RandomPropagationDelayModel::m_variable), + MakeRandomVariableChecker ()) + ; + return tid; } RandomPropagationDelayModel::RandomPropagationDelayModel () - : m_variable (g_random.Get ()) -{} - -RandomPropagationDelayModel::RandomPropagationDelayModel (const RandomVariable &variable) - : m_variable (variable) {} RandomPropagationDelayModel::~RandomPropagationDelayModel () {} @@ -83,8 +52,20 @@ RandomPropagationDelayModel::GetDelay (Ptr a, Ptr return Seconds (m_variable.GetValue ()); } -ConstantSpeedPropagationDelayModel::ConstantSpeedPropagationDelayModel (double speed) - : m_speed (speed) +TypeId +ConstantSpeedPropagationDelayModel::GetTypeId (void) +{ + static TypeId tid = TypeId ("ConstantSpeedPropagationDelayModel") + .SetParent () + .AddAttribute ("Speed", "The speed (m/s)", + Double (300000000.0), + MakeDoubleAccessor (&ConstantSpeedPropagationDelayModel::m_speed), + MakeDoubleChecker ()) + ; + return tid; +} + +ConstantSpeedPropagationDelayModel::ConstantSpeedPropagationDelayModel () {} Time ConstantSpeedPropagationDelayModel::GetDelay (Ptr a, Ptr b) const diff --git a/src/devices/wifi/propagation-delay-model.h b/src/devices/wifi/propagation-delay-model.h index 4fb80f685..966447edb 100644 --- a/src/devices/wifi/propagation-delay-model.h +++ b/src/devices/wifi/propagation-delay-model.h @@ -45,11 +45,6 @@ public: * source and destination. */ virtual Time GetDelay (Ptr a, Ptr b) const = 0; - /** - * \returns the default propagation loss model as specified - * by the PropagationDelayModelType ns3::DefaultValue. - */ - static Ptr CreateDefault (void); }; /** @@ -58,15 +53,12 @@ public: class RandomPropagationDelayModel : public PropagationDelayModel { public: + static TypeId GetTypeId (void); + /** * Use the default parameters from PropagationDelayRandomDistribution. */ RandomPropagationDelayModel (); - /** - * \param variable the random distribution to use for this - * instance - */ - RandomPropagationDelayModel (const RandomVariable &variable); virtual ~RandomPropagationDelayModel (); virtual Time GetDelay (Ptr a, Ptr b) const; private: @@ -79,15 +71,12 @@ private: class ConstantSpeedPropagationDelayModel : public PropagationDelayModel { public: + static TypeId GetTypeId (void); + /** * Use the default parameters from PropagationDelayConstantSpeed. */ ConstantSpeedPropagationDelayModel (); - /** - * \param speed the speed (m/s) of the propagation to use for this - * instance - */ - ConstantSpeedPropagationDelayModel (double speed); virtual Time GetDelay (Ptr a, Ptr b) const; /** * \param speed the new speed (m/s) diff --git a/src/devices/wifi/propagation-loss-model.cc b/src/devices/wifi/propagation-loss-model.cc index 407d25b08..e583af025 100644 --- a/src/devices/wifi/propagation-loss-model.cc +++ b/src/devices/wifi/propagation-loss-model.cc @@ -18,98 +18,38 @@ * Author: Mathieu Lacage */ #include "propagation-loss-model.h" -#include "ns3/default-value.h" -#include "ns3/random-variable-default-value.h" #include "ns3/log.h" #include "ns3/mobility-model.h" #include "ns3/static-mobility-model.h" +#include "ns3/double.h" #include NS_LOG_COMPONENT_DEFINE ("PropagationLossModel"); namespace ns3 { -enum ModelType { - FRIIS, - RANDOM, - LOG_DISTANCE -}; - -static EnumDefaultValue g_modelType -("PropagationLossModelType", - "The type of propagation loss model.", - LOG_DISTANCE, "LogDistance", - FRIIS, "Friis", - RANDOM, "Random", - 0, (void *)0); - -static NumericDefaultValue g_friisLambda -("FriisPropagationLossLambda", - "The wavelength to use by default for every FriisPropagationLossModel (default is 5.15 GHz at 300 000 km/s).", - 300000000.0 / 5.150e9); - -static NumericDefaultValue g_friisSystemLoss -("FriisPropagationLossSystemLoss", - "The system loss to use by default for every FriisPropagationLossModel", - 1.0); -static NumericDefaultValue g_friisPropagationLossMinDistance -("FriisPropagationLossMinDistance", - "The distance under which the propagation model refuses to give results (m)", - 0.5); - -static RandomVariableDefaultValue g_random -("RandomPropagationLossDistribution", - "The distribution (in dbm) to choose the propagation loss.", - "Constant:1.0"); - -static NumericDefaultValue g_logDistanceExponent -("LogDistancePropagationLossExponent", - "The exponent of the Path Loss propagation model", - 3.0); - -static NumericDefaultValue g_logDistanceReferenceDistance -("LogDistancePropagationLossReferenceDistance", - "The distance at which the reference loss is calculated (m)", - 1.0); - -static EnumDefaultValue g_logDistanceReferenceType -("LogDistancePropagationLossReferenceType", - "The type of reference propagation model.", - FRIIS, "Friis", - RANDOM, "Random", - 0, (void *)0); const double FriisPropagationLossModel::PI = 3.1415; PropagationLossModel::~PropagationLossModel () {} -Ptr -PropagationLossModel::CreateDefault (void) +TypeId +RandomPropagationLossModel::GetTypeId (void) { - switch (g_modelType.GetValue ()) { - case FRIIS: - return CreateObject (); - break; - case RANDOM: - return CreateObject (); - break; - case LOG_DISTANCE: - return CreateObject (); - break; - default: - NS_ASSERT (false); - return 0; - break; - } + static TypeId tid = TypeId ("RandomPropagationLossModel") + .SetParent () + .AddConstructor () + .AddAttribute ("Variable", "XXX", + ConstantVariable (1.0), + MakeRandomVariableAccessor (&RandomPropagationLossModel::m_variable), + MakeRandomVariableChecker ()) + ; + return tid; } RandomPropagationLossModel::RandomPropagationLossModel () - : m_variable (g_random.Get ()) {} -RandomPropagationLossModel::RandomPropagationLossModel (const RandomVariable &variable) - : m_variable (variable) -{} RandomPropagationLossModel::~RandomPropagationLossModel () {} @@ -123,10 +63,31 @@ RandomPropagationLossModel::GetRxPower (double txPowerDbm, return rxPower; } +TypeId +FriisPropagationLossModel::GetTypeId (void) +{ + static TypeId tid = TypeId ("FriisPropagationLossModel") + .SetParent () + .AddConstructor () + .AddAttribute ("Lambda", + "The wavelength (default is 5.15 GHz at 300 000 km/s).", + Double (300000000.0 / 5.150e9), + MakeDoubleAccessor (&FriisPropagationLossModel::m_lambda), + MakeDoubleChecker ()) + .AddAttribute ("SystemLoss", "The system loss", + Double (1.0), + MakeDoubleAccessor (&FriisPropagationLossModel::m_systemLoss), + MakeDoubleChecker ()) + .AddAttribute ("MinDistance", + "The distance under which the propagation model refuses to give results (m)", + Double (0.5), + MakeDoubleAccessor (&FriisPropagationLossModel::m_minDistance), + MakeDoubleChecker ()) + ; + return tid; +} + FriisPropagationLossModel::FriisPropagationLossModel () - : m_lambda (g_friisLambda.GetValue ()), - m_systemLoss (g_friisSystemLoss.GetValue ()), - m_minDistance (g_friisPropagationLossMinDistance.GetValue ()) {} void FriisPropagationLossModel::SetSystemLoss (double systemLoss) @@ -216,11 +177,33 @@ FriisPropagationLossModel::GetRxPower (double txPowerDbm, return rxPowerDbm; } +TypeId +LogDistancePropagationLossModel::GetTypeId (void) +{ + static TypeId tid = TypeId ("LogDistancePropagationLossModel") + .SetParent () + .AddConstructor () + .AddAttribute ("Exponent", + "The exponent of the Path Loss propagation model", + Double (3.0), + MakeDoubleAccessor (&LogDistancePropagationLossModel::m_exponent), + MakeDoubleChecker ()) + .AddAttribute ("ReferenceDistance", + "The distance at which the reference loss is calculated (m)", + Double (1.0), + MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceDistance), + MakeDoubleChecker ()) + .AddAttribute ("ReferenceModel", + "The reference model at the reference distance.", + Ptr (0), + MakePtrAccessor (&LogDistancePropagationLossModel::m_reference), + MakePtrChecker ()) + ; + return tid; + +} LogDistancePropagationLossModel::LogDistancePropagationLossModel () - : m_exponent (g_logDistanceExponent.GetValue ()), - m_referenceDistance (g_logDistanceReferenceDistance.GetValue ()), - m_reference (CreateDefaultReference ()) {} void @@ -243,24 +226,6 @@ LogDistancePropagationLossModel::GetPathLossExponent (void) const { return m_exponent; } - -Ptr -LogDistancePropagationLossModel::CreateDefaultReference (void) -{ - switch (g_logDistanceReferenceType.GetValue ()) { - case RANDOM: - return CreateObject (); - break; - case FRIIS: - return CreateObject (); - break; - case LOG_DISTANCE: - default: - NS_ASSERT (false); - return 0; - break; - } -} double LogDistancePropagationLossModel::GetRxPower (double txPowerDbm, diff --git a/src/devices/wifi/propagation-loss-model.h b/src/devices/wifi/propagation-loss-model.h index 41064619a..08820621d 100644 --- a/src/devices/wifi/propagation-loss-model.h +++ b/src/devices/wifi/propagation-loss-model.h @@ -46,12 +46,6 @@ public: virtual double GetRxPower (double txPowerDbm, Ptr a, Ptr b) const = 0; - - /** - * \returns the default propagation loss model as specified - * by \valueref{PropagationLossModelType}. - */ - static Ptr CreateDefault (void); }; /** @@ -60,15 +54,12 @@ public: class RandomPropagationLossModel : public PropagationLossModel { public: + static TypeId GetTypeId (void); + /** * Use the default parameters from \valueref{RandomPropagationLossDistribution}. */ RandomPropagationLossModel (); - /** - * \param variable the RandomVariable to use for this - * instance. - */ - RandomPropagationLossModel (const RandomVariable &variable); virtual ~RandomPropagationLossModel (); virtual double GetRxPower (double txPowerDbm, @@ -114,6 +105,7 @@ private: class FriisPropagationLossModel : public PropagationLossModel { public: + static TypeId GetTypeId (void); /** * Use the default parameters from \valueref{FriisPropagationLossLambda}, * \valueref{FriisPropagationLossSystemLoss}, and, @@ -193,6 +185,7 @@ private: class LogDistancePropagationLossModel : public PropagationLossModel { public: + static TypeId GetTypeId (void); /** * Use the default parameters from * \valueref{LogDistancePropagationLossExponent}, and, diff --git a/src/devices/wifi/wifi-channel.cc b/src/devices/wifi/wifi-channel.cc index 5e0d2d1c0..3dd4213ff 100644 --- a/src/devices/wifi/wifi-channel.cc +++ b/src/devices/wifi/wifi-channel.cc @@ -31,9 +31,25 @@ NS_LOG_COMPONENT_DEFINE ("WifiChannel"); namespace ns3 { +TypeId +WifiChannel::GetTypdId (void) +{ + static TypeId tid = TypeId ("WifiChannel") + .SetParent () + .AddConstructor () + .AddAttribute ("PropagationLossModel", "XXX", + Ptr (0), + MakePtrAccessor (&WifiChannel::m_loss), + MakePtrChecker ()) + .AddAttribute ("PropagationDelayModel", "XXX", + Ptr (0), + MakePtrAccessor (&WifiChannel::m_delay), + MakePtrChecker ()) + ; + return tid; +} + WifiChannel::WifiChannel () - : m_loss (PropagationLossModel::CreateDefault ()), - m_delay (PropagationDelayModel::CreateDefault ()) {} WifiChannel::~WifiChannel () { diff --git a/src/devices/wifi/wifi-channel.h b/src/devices/wifi/wifi-channel.h index 7cab7005a..891608a78 100644 --- a/src/devices/wifi/wifi-channel.h +++ b/src/devices/wifi/wifi-channel.h @@ -48,6 +48,8 @@ class PropagationDelayModel; class WifiChannel : public Channel { public: + static TypeId GetTypdId (void); + /** * arg1: the packet to receive * arg2: the rx power of the packet to receive (dbm) diff --git a/src/devices/wifi/wifi-helper.cc b/src/devices/wifi/wifi-helper.cc index bbb2adbf5..1334a1a0e 100644 --- a/src/devices/wifi/wifi-helper.cc +++ b/src/devices/wifi/wifi-helper.cc @@ -4,6 +4,8 @@ #include "wifi-phy.h" #include "wifi-remote-station-manager.h" #include "wifi-channel.h" +#include "propagation-delay-model.h" +#include "propagation-loss-model.h" #include "ns3/mobility-model.h" #include "ns3/log.h" @@ -91,6 +93,10 @@ NetDeviceContainer WifiHelper::Build (NodeContainer c) const { Ptr channel = CreateObjectWith (); + channel->SetPropagationDelayModel (CreateObjectWith ()); + Ptr log = CreateObjectWith (); + log->SetReferenceModel (CreateObjectWith ()); + channel->SetPropagationLossModel (log); return Build (c, channel); } NetDeviceContainer