port propagation models and channel to attributes.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 03 Mar 2008 18:30:29 +0100
changeset 2549 fe90cf0b2c63
parent 2548 fde3236f0e9c
child 2550 ab5aaa022458
port propagation models and channel to attributes.
samples/main-propagation-loss.cc
src/devices/wifi/propagation-delay-model.cc
src/devices/wifi/propagation-delay-model.h
src/devices/wifi/propagation-loss-model.cc
src/devices/wifi/propagation-loss-model.h
src/devices/wifi/wifi-channel.cc
src/devices/wifi/wifi-channel.h
src/devices/wifi/wifi-helper.cc
--- a/samples/main-propagation-loss.cc	Mon Mar 03 05:11:11 2008 +0100
+++ b/samples/main-propagation-loss.cc	Mon Mar 03 18:30:29 2008 +0100
@@ -28,7 +28,10 @@
 {
   Ptr<StaticMobilityModel> a = CreateObject<StaticMobilityModel> ();
   Ptr<StaticMobilityModel> b = CreateObject<StaticMobilityModel> ();
-  Ptr<PropagationLossModel> model = PropagationLossModel::CreateDefault ();
+  Ptr<LogDistancePropagationLossModel> log = CreateObjectWith<LogDistancePropagationLossModel> ();
+  log->SetReferenceModel (CreateObjectWith<FriisPropagationLossModel> ());
+
+  Ptr<PropagationLossModel> model = log;
 
   a->SetPosition (Vector (0.0, 0.0, 0.0));
   for (double x = min; x < max; x+= step)
--- a/src/devices/wifi/propagation-delay-model.cc	Mon Mar 03 05:11:11 2008 +0100
+++ b/src/devices/wifi/propagation-delay-model.cc	Mon Mar 03 18:30:29 2008 +0100
@@ -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<enum ModelType> g_modelType
-("PropagationDelayModelType",
- "The type of propagation delay model to use.",
- CONSTANT_SPEED, "ConstantSpeed",
- RANDOM, "Random",
- 0, (void*)0);
-
-static NumericDefaultValue<double> 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> 
-PropagationDelayModel::CreateDefault (void)
+
+TypeId 
+RandomPropagationDelayModel::GetTypeId (void)
 {
-  switch (g_modelType.GetValue ()) {
-  case CONSTANT_SPEED:
-    return CreateObject<ConstantSpeedPropagationDelayModel> (g_speed.GetValue ());
-    break;
-  case RANDOM:
-    return CreateObject<RandomPropagationDelayModel> ();
-    break;
-  default:
-    NS_ASSERT (false);
-    return 0;
-    break;
-  }
+  static TypeId tid = TypeId ("RandomPropagationDelayModel")
+    .SetParent<PropagationDelayModel> ()
+    .AddConstructor<RandomPropagationDelayModel> ()
+    .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 @@
   return Seconds (m_variable.GetValue ());
 }
 
-ConstantSpeedPropagationDelayModel::ConstantSpeedPropagationDelayModel (double speed)
-  : m_speed (speed)
+TypeId
+ConstantSpeedPropagationDelayModel::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ConstantSpeedPropagationDelayModel")
+    .SetParent<ConstantSpeedPropagationDelayModel> ()
+    .AddAttribute ("Speed", "The speed (m/s)",
+                   Double (300000000.0),
+                   MakeDoubleAccessor (&ConstantSpeedPropagationDelayModel::m_speed),
+                   MakeDoubleChecker<double> ())
+    ;
+  return tid;
+}
+
+ConstantSpeedPropagationDelayModel::ConstantSpeedPropagationDelayModel ()
 {}
 Time 
 ConstantSpeedPropagationDelayModel::GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
--- a/src/devices/wifi/propagation-delay-model.h	Mon Mar 03 05:11:11 2008 +0100
+++ b/src/devices/wifi/propagation-delay-model.h	Mon Mar 03 18:30:29 2008 +0100
@@ -45,11 +45,6 @@
    * source and destination.
    */
   virtual Time GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const = 0;
-  /**
-   * \returns the default propagation loss model as specified
-   * by the PropagationDelayModelType ns3::DefaultValue.
-   */
-  static Ptr<PropagationDelayModel> CreateDefault (void);
 };
 
 /**
@@ -58,15 +53,12 @@
 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<MobilityModel> a, Ptr<MobilityModel> b) const;
 private:
@@ -79,15 +71,12 @@
 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<MobilityModel> a, Ptr<MobilityModel> b) const;
   /**
    * \param speed the new speed (m/s)
--- a/src/devices/wifi/propagation-loss-model.cc	Mon Mar 03 05:11:11 2008 +0100
+++ b/src/devices/wifi/propagation-loss-model.cc	Mon Mar 03 18:30:29 2008 +0100
@@ -18,98 +18,38 @@
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
 #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 <math.h>
 
 NS_LOG_COMPONENT_DEFINE ("PropagationLossModel");
 
 namespace ns3 {
 
-enum ModelType {
-  FRIIS,
-  RANDOM,
-  LOG_DISTANCE
-};
-
-static EnumDefaultValue<enum ModelType> g_modelType
-("PropagationLossModelType",
- "The type of propagation loss model.",
- LOG_DISTANCE, "LogDistance",
- FRIIS, "Friis",
- RANDOM, "Random",
- 0, (void *)0);
-
-static NumericDefaultValue<double> 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<double> g_friisSystemLoss
-("FriisPropagationLossSystemLoss",
- "The system loss to use by default for every FriisPropagationLossModel",
- 1.0);
-static NumericDefaultValue<double> 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<double> g_logDistanceExponent
-("LogDistancePropagationLossExponent",
- "The exponent of the Path Loss propagation model",
- 3.0);
-
-static NumericDefaultValue<double> g_logDistanceReferenceDistance
-("LogDistancePropagationLossReferenceDistance",
- "The distance at which the reference loss is calculated (m)",
- 1.0);
-
-static EnumDefaultValue<enum ModelType> 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> 
-PropagationLossModel::CreateDefault (void)
+TypeId 
+RandomPropagationLossModel::GetTypeId (void)
 {
-  switch (g_modelType.GetValue ()) {
-  case FRIIS:
-    return CreateObject<FriisPropagationLossModel> ();
-    break;
-  case RANDOM:
-    return CreateObject<RandomPropagationLossModel> ();
-    break;
-  case LOG_DISTANCE:
-    return CreateObject<LogDistancePropagationLossModel> ();
-    break;
-  default:
-    NS_ASSERT (false);
-    return 0;
-    break;
-  }
+  static TypeId tid = TypeId ("RandomPropagationLossModel")
+    .SetParent<PropagationLossModel> ()
+    .AddConstructor<RandomPropagationLossModel> ()
+    .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 @@
   return rxPower;
 }
 
+TypeId 
+FriisPropagationLossModel::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("FriisPropagationLossModel")
+    .SetParent<PropagationLossModel> ()
+    .AddConstructor<FriisPropagationLossModel> ()
+    .AddAttribute ("Lambda", 
+                   "The wavelength  (default is 5.15 GHz at 300 000 km/s).",
+                   Double (300000000.0 / 5.150e9),
+                   MakeDoubleAccessor (&FriisPropagationLossModel::m_lambda),
+                   MakeDoubleChecker<double> ())
+    .AddAttribute ("SystemLoss", "The system loss",
+                   Double (1.0),
+                   MakeDoubleAccessor (&FriisPropagationLossModel::m_systemLoss),
+                   MakeDoubleChecker<double> ())
+    .AddAttribute ("MinDistance", 
+                   "The distance under which the propagation model refuses to give results (m)",
+                   Double (0.5),
+                   MakeDoubleAccessor (&FriisPropagationLossModel::m_minDistance),
+                   MakeDoubleChecker<double> ())
+    ;
+  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 @@
   return rxPowerDbm;
 }
 
+TypeId
+LogDistancePropagationLossModel::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("LogDistancePropagationLossModel")
+    .SetParent<PropagationLossModel> ()
+    .AddConstructor<LogDistancePropagationLossModel> ()
+    .AddAttribute ("Exponent",
+                   "The exponent of the Path Loss propagation model",
+                   Double (3.0),
+                   MakeDoubleAccessor (&LogDistancePropagationLossModel::m_exponent),
+                   MakeDoubleChecker<double> ())
+    .AddAttribute ("ReferenceDistance",
+                   "The distance at which the reference loss is calculated (m)",
+                   Double (1.0),
+                   MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceDistance),
+                   MakeDoubleChecker<double> ())
+    .AddAttribute ("ReferenceModel",
+                   "The reference model at the reference distance.",
+                   Ptr<PropagationLossModel> (0),
+                   MakePtrAccessor (&LogDistancePropagationLossModel::m_reference),
+                   MakePtrChecker<PropagationLossModel> ())
+    ;
+  return tid;
+                   
+}
 
 LogDistancePropagationLossModel::LogDistancePropagationLossModel ()
-  : m_exponent (g_logDistanceExponent.GetValue ()),
-    m_referenceDistance (g_logDistanceReferenceDistance.GetValue ()),
-    m_reference (CreateDefaultReference ())
 {}
 
 void 
@@ -243,24 +226,6 @@
 {
   return m_exponent;
 }
-
-Ptr<PropagationLossModel>
-LogDistancePropagationLossModel::CreateDefaultReference (void)
-{
-  switch (g_logDistanceReferenceType.GetValue ()) {
-  case RANDOM:
-    return CreateObject<RandomPropagationLossModel> ();
-    break;
-  case FRIIS:
-    return CreateObject<FriisPropagationLossModel> ();
-    break;
-  case LOG_DISTANCE:
-  default:
-    NS_ASSERT (false);
-    return 0;
-    break;
-  }
-}
   
 double 
 LogDistancePropagationLossModel::GetRxPower (double txPowerDbm,
--- a/src/devices/wifi/propagation-loss-model.h	Mon Mar 03 05:11:11 2008 +0100
+++ b/src/devices/wifi/propagation-loss-model.h	Mon Mar 03 18:30:29 2008 +0100
@@ -46,12 +46,6 @@
   virtual double GetRxPower (double txPowerDbm,
 			     Ptr<MobilityModel> a,
 			     Ptr<MobilityModel> b) const = 0;
-
-  /**
-   * \returns the default propagation loss model as specified
-   * by \valueref{PropagationLossModelType}.
-   */
-  static Ptr<PropagationLossModel> CreateDefault (void);
 };
 
 /**
@@ -60,15 +54,12 @@
 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 @@
 class FriisPropagationLossModel : public PropagationLossModel
 {
 public:
+  static TypeId GetTypeId (void);
   /**
    * Use the default parameters from \valueref{FriisPropagationLossLambda},
    * \valueref{FriisPropagationLossSystemLoss}, and,
@@ -193,6 +185,7 @@
 class LogDistancePropagationLossModel : public PropagationLossModel
 {
 public:
+  static TypeId GetTypeId (void);
   /**
    * Use the default parameters from
    * \valueref{LogDistancePropagationLossExponent}, and,
--- a/src/devices/wifi/wifi-channel.cc	Mon Mar 03 05:11:11 2008 +0100
+++ b/src/devices/wifi/wifi-channel.cc	Mon Mar 03 18:30:29 2008 +0100
@@ -31,9 +31,25 @@
 
 namespace ns3 {
 
+TypeId 
+WifiChannel::GetTypdId (void)
+{
+  static TypeId tid = TypeId ("WifiChannel")
+    .SetParent<WifiChannel> ()
+    .AddConstructor<WifiChannel> ()
+    .AddAttribute ("PropagationLossModel", "XXX",
+                   Ptr<PropagationLossModel> (0),
+                   MakePtrAccessor (&WifiChannel::m_loss),
+                   MakePtrChecker<PropagationLossModel> ())
+    .AddAttribute ("PropagationDelayModel", "XXX",
+                   Ptr<PropagationDelayModel> (0),
+                   MakePtrAccessor (&WifiChannel::m_delay),
+                   MakePtrChecker<PropagationDelayModel> ())
+    ;
+  return tid;
+}
+
 WifiChannel::WifiChannel ()
-  : m_loss (PropagationLossModel::CreateDefault ()),
-    m_delay (PropagationDelayModel::CreateDefault ())
 {}
 WifiChannel::~WifiChannel ()
 {
--- a/src/devices/wifi/wifi-channel.h	Mon Mar 03 05:11:11 2008 +0100
+++ b/src/devices/wifi/wifi-channel.h	Mon Mar 03 18:30:29 2008 +0100
@@ -48,6 +48,8 @@
 class WifiChannel : public Channel
 {
 public:
+  static TypeId GetTypdId (void);
+
   /**
    * arg1: the packet to receive
    * arg2: the rx power of the packet to receive (dbm)
--- a/src/devices/wifi/wifi-helper.cc	Mon Mar 03 05:11:11 2008 +0100
+++ b/src/devices/wifi/wifi-helper.cc	Mon Mar 03 18:30:29 2008 +0100
@@ -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 @@
 WifiHelper::Build (NodeContainer c) const
 {
   Ptr<WifiChannel> channel = CreateObjectWith<WifiChannel> ();
+  channel->SetPropagationDelayModel (CreateObjectWith<ConstantSpeedPropagationDelayModel> ());
+  Ptr<LogDistancePropagationLossModel> log = CreateObjectWith<LogDistancePropagationLossModel> ();
+  log->SetReferenceModel (CreateObjectWith<FriisPropagationLossModel> ());
+  channel->SetPropagationLossModel (log);
   return Build (c, channel);
 }
 NetDeviceContainer