Moving the propagation models of wifi from src/devices/wifi to src/common. The idea is to share them with the other wireless devices.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/common/jakes-propagation-loss-model.cc Tue Feb 02 11:44:02 2010 +0100
@@ -0,0 +1,259 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006,2007 INRIA
+ *
+ * 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: Federico Maguolo <maguolof@dei.unipd.it>
+ */
+
+#include "ns3/simulator.h"
+#include "ns3/uinteger.h"
+#include "ns3/double.h"
+#include "ns3/random-variable.h"
+#include "ns3/mobility-model.h"
+#include "ns3/log.h"
+#include "jakes-propagation-loss-model.h"
+#include <math.h>
+
+NS_LOG_COMPONENT_DEFINE ("Jakes");
+
+namespace ns3 {
+
+class JakesPropagationLossModel::PathCoefficients
+{
+public:
+ PathCoefficients (Ptr<const JakesPropagationLossModel> jakes,
+ Ptr<MobilityModel> receiver,
+ uint8_t nRays,
+ uint8_t nOscillators);
+ ~PathCoefficients ();
+ double GetLoss (void);
+ Ptr<MobilityModel> GetReceiver (void);
+private:
+ void DoConstruct (void);
+ Ptr<MobilityModel> m_receiver;
+ uint8_t m_nOscillators;
+ uint8_t m_nRays;
+ double **m_phases;
+ Time m_lastUpdate;
+ Ptr<const JakesPropagationLossModel> m_jakes;
+};
+
+
+JakesPropagationLossModel::PathCoefficients::PathCoefficients (Ptr<const JakesPropagationLossModel> jakes,
+ Ptr<MobilityModel> receiver,
+ uint8_t nRays,
+ uint8_t nOscillators)
+ : m_receiver (receiver),
+ m_nOscillators (nOscillators),
+ m_nRays (nRays),
+ m_jakes(jakes)
+{
+ DoConstruct ();
+}
+
+JakesPropagationLossModel::PathCoefficients::~PathCoefficients ()
+{
+ for (uint8_t i = 0; i < m_nRays; i++)
+ {
+ delete [] m_phases[i];
+ }
+ delete [] m_phases;
+}
+
+void
+JakesPropagationLossModel::PathCoefficients::DoConstruct ()
+{
+ m_phases = new double*[m_nRays];
+ for (uint8_t i = 0; i < m_nRays; i++)
+ {
+ m_phases[i] = new double[m_nOscillators + 1];
+ for (uint8_t j = 0; j <= m_nOscillators; j++)
+ {
+ m_phases[i][j] = 2.0 * JakesPropagationLossModel::PI * m_jakes->m_variable.GetValue ();
+ }
+ }
+ m_lastUpdate = Simulator::Now ();
+}
+
+Ptr<MobilityModel>
+JakesPropagationLossModel::PathCoefficients::GetReceiver ()
+{
+ return m_receiver;
+}
+
+double
+JakesPropagationLossModel::PathCoefficients::GetLoss (void)
+{
+ uint16_t N = 4 * m_nOscillators + 2;
+ Time interval = Simulator::Now () - m_lastUpdate;
+ ComplexNumber coef= {0.0, 0.0};
+ ComplexNumber fading;
+ double norm = 0.0;
+ for (uint8_t i = 0; i < m_nRays; i++)
+ {
+ fading.real = 0.0;
+ fading.imag = 0.0;
+ for (uint8_t j = 0; j <= m_nOscillators; j++)
+ {
+ m_phases[i][j] += 2.0 * JakesPropagationLossModel::PI *
+ cos (2.0 * JakesPropagationLossModel::PI * j / N) * m_jakes->m_fd * interval.GetSeconds ();
+ m_phases[i][j] -= 2.0 * JakesPropagationLossModel::PI *
+ floor (m_phases[i][j] / 2.0 / JakesPropagationLossModel::PI);
+ fading.real += m_jakes->m_amp[j].real * cos (m_phases[i][j]);
+ fading.imag += m_jakes->m_amp[j].imag * cos (m_phases[i][j]);
+ norm += sqrt(pow (m_jakes->m_amp[j].real, 2) + pow(m_jakes->m_amp[j].imag, 2));
+ }
+ coef.real += fading.real;
+ coef.imag += fading.imag;
+ }
+ m_lastUpdate = Simulator::Now ();
+ double k = sqrt (pow (coef.real, 2) + pow (coef.imag, 2)) / norm;
+ NS_LOG_DEBUG ("Jakes coef "<< k << " (" << 10 * log10 (k) << "dB)");
+ return 10 * log10 (k);
+}
+
+NS_OBJECT_ENSURE_REGISTERED (JakesPropagationLossModel);
+
+const double JakesPropagationLossModel::PI = 3.14159265358979323846;
+
+TypeId
+JakesPropagationLossModel::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::JakesPropagationLossModel")
+ .SetParent<PropagationLossModel> ()
+ .AddConstructor<JakesPropagationLossModel> ()
+ .AddAttribute ("NumberOfRaysPerPath",
+ "The number of rays to use by default for compute the fading coeficent for a given path (default is 1)",
+ UintegerValue (1),
+ MakeUintegerAccessor (&JakesPropagationLossModel::SetNRays,
+ &JakesPropagationLossModel::GetNRays),
+ MakeUintegerChecker<uint8_t> ())
+ .AddAttribute ("NumberOfOscillatorsPerRay",
+ "The number of oscillators to use by default for compute the coeficent for a given ray of a given "
+ "path (default is 4)",
+ UintegerValue (4),
+ MakeUintegerAccessor (&JakesPropagationLossModel::SetNOscillators,
+ &JakesPropagationLossModel::GetNOscillators),
+ MakeUintegerChecker<uint8_t> ())
+ .AddAttribute ("DopplerFreq",
+ "The doppler frequency in Hz (f_d = v / lambda = v * f / c), the default is 0)",
+ DoubleValue (0.0),
+ MakeDoubleAccessor (&JakesPropagationLossModel::m_fd),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("Distribution",
+ "The distribution to choose the initial phases.",
+ RandomVariableValue (ConstantVariable (1.0)),
+ MakeRandomVariableAccessor (&JakesPropagationLossModel::m_variable),
+ MakeRandomVariableChecker ())
+ ;
+ return tid;
+}
+
+JakesPropagationLossModel::JakesPropagationLossModel ()
+ : m_amp (0),
+ m_nRays (0),
+ m_nOscillators (0)
+{}
+
+JakesPropagationLossModel::~JakesPropagationLossModel ()
+{
+ delete [] m_amp;
+ for (PathsList::iterator i = m_paths.end (); i != m_paths.begin (); i--)
+ {
+ PathsSet *ps = *i;
+ for (DestinationList::iterator r = ps->receivers.begin (); r != ps->receivers.end (); r++)
+ {
+ PathCoefficients *pc = *r;
+ delete pc;
+ }
+ delete ps;
+ }
+}
+
+void
+JakesPropagationLossModel::SetNRays (uint8_t nRays)
+{
+ m_nRays = nRays;
+}
+
+void
+JakesPropagationLossModel::SetNOscillators (uint8_t nOscillators)
+{
+ m_nOscillators = nOscillators;
+ delete [] m_amp;
+ uint16_t N = 4 * m_nOscillators + 2;
+ m_amp = new ComplexNumber[m_nOscillators + 1];
+ m_amp[0].real = 2.0 * sqrt(2.0 / N) * cos (PI / 4.0);
+ m_amp[0].imag = 2.0 * sqrt(2.0 / N) * sin (PI / 4.0);
+ for (uint8_t i = 1; i <= m_nOscillators; i++)
+ {
+ double beta = PI * (double)i / m_nOscillators;
+ m_amp[i].real = 4.0 * cos (beta) / sqrt(N);
+ m_amp[i].imag = 4.0 * sin (beta) / sqrt(N);
+ }
+}
+
+uint8_t
+JakesPropagationLossModel::GetNRays (void) const
+{
+ return m_nRays;
+}
+uint8_t
+JakesPropagationLossModel::GetNOscillators (void) const
+{
+ return m_nOscillators;
+}
+
+
+double
+JakesPropagationLossModel::DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const
+{
+ PathsList::iterator i = m_paths.end ();
+ while (i != m_paths.begin ())
+ {
+ i--;
+ PathsSet *ps = *i;
+ if (ps->sender == a)
+ {
+ m_paths.erase (i);
+ m_paths.push_back (ps);
+ for (DestinationList::iterator r = ps->receivers.begin (); r != ps->receivers.end (); r++)
+ {
+ PathCoefficients *pc = *r;
+ if (pc->GetReceiver () == b)
+ {
+ ps->receivers.erase (r);
+ ps->receivers.push_back (pc);
+ return txPowerDbm + pc->GetLoss ();
+ }
+ }
+ PathCoefficients *pc = new PathCoefficients (this, b, m_nRays, m_nOscillators);
+ ps->receivers.push_back (pc);
+ return txPowerDbm + pc->GetLoss ();
+ }
+ }
+ PathsSet *ps = new PathsSet;
+ ps->sender = a;
+ PathCoefficients *pc = new PathCoefficients (this, b, m_nRays, m_nOscillators);
+ ps->receivers.push_back (pc);
+ m_paths.push_back (ps);
+ return txPowerDbm + pc->GetLoss ();
+}
+
+} // namespace ns3
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/common/jakes-propagation-loss-model.h Tue Feb 02 11:44:02 2010 +0100
@@ -0,0 +1,137 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006,2007 INRIA
+ *
+ * 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: Federico Maguolo <maguolof@dei.unipd.it>
+ */
+#ifndef PROPAGATION_JAKES_MODEL_H
+#define PROPAGATION_JAKES_MODEL_H
+
+#include "ns3/nstime.h"
+#include "propagation-loss-model.h"
+
+namespace ns3 {
+
+
+/**
+ * \brief a Jakes propagation loss model
+ *
+ * The Jakes propagation loss model implemented here is
+ * described in [1].
+ *
+ *
+ * We call path the set of rays that depart from a given
+ * transmitter and arrive to a given receiver. For each ray
+ * The complex coefficient is compute as follow:
+ * \f[ u(t)=u_c(t) + j u_s(t)\f]
+ * \f[ u_c(t) = \frac{2}{\sqrt{N}}\sum_{n=0}^{M}a_n\cos(\omega_n t+\phi_n)\f]
+ * \f[ u_s(t) = \frac{2}{\sqrt{N}}\sum_{n=0}^{M}b_n\cos(\omega_n t+\phi_n)\f]
+ * where
+ * \f[ a_n=\left \{ \begin{array}{ll}
+ * \sqrt{2}\cos\beta_0 & n=0 \\
+ * 2\cos\beta_n & n=1,2,\ldots,M
+ * \end{array}
+ * \right .\f]
+ * \f[ b_n=\left \{ \begin{array}{ll}
+ * \sqrt{2}\sin\beta_0 & n=0 \\
+ * 2\sin\beta_n & n=1,2,\ldots,M
+ * \end{array}
+ * \right .\f]
+ * \f[ \beta_n=\left \{ \begin{array}{ll}
+ * \frac{\pi}{4} & n=0 \\
+ * \frac{\pi n}{M} & n=1,2,\ldots,M
+ * \end{array}
+ * \right .\f]
+ * \f[ \omega_n=\left \{ \begin{array}{ll}
+ * 2\pi f_d & n=0 \\
+ * 2\pi f_d \cos\frac{2\pi n}{N} & n=1,2,\ldots,M
+ * \end{array}
+ * \right .\f]
+ *
+ * The parameter \f$f_d\f$ is the doppler frequency and \f$N=4M+2\f$ where
+ * \f$M\f$ is the number of oscillators per ray.
+ *
+ * The attenuation coefficent of the path is the magnitude of the sum of
+ * all the ray coefficients. This attenuation coefficient could be greater than
+ * \f$1\f$, hence it is divide by \f$ \frac{2N_r}{\sqrt{N}} \sum_{n+0}^{M}\sqrt{a_n^2 +b_n^2}\f$
+ * where \f$N_r\f$ is the number of rays.
+ *
+ * The initail phases \f$\phi_i\f$ are random and they are choosen according
+ * to a given distribution.
+ *
+ * [1] Y. R. Zheng and C. Xiao, "Simulation Models With Correct
+ * Statistical Properties for Rayleigh Fading Channel", IEEE
+ * Trans. on Communications, Vol. 51, pp 920-928, June 2003
+ */
+class JakesPropagationLossModel : public PropagationLossModel
+{
+public:
+ static TypeId GetTypeId (void);
+ JakesPropagationLossModel ();
+ virtual ~JakesPropagationLossModel ();
+
+ /**
+ * \param nRays Number of rays per path
+ *
+ * Set the number of rays for each path
+ */
+ void SetNRays (uint8_t nRays);
+ /**
+ * \param nOscillators Number of oscillators
+ *
+ * Set the number of oscillators to use to compute the ray coefficient
+ */
+ void SetNOscillators (uint8_t nOscillators);
+
+ uint8_t GetNRays (void) const;
+ uint8_t GetNOscillators (void) const;
+
+private:
+ JakesPropagationLossModel (const JakesPropagationLossModel &o);
+ JakesPropagationLossModel & operator = (const JakesPropagationLossModel &o);
+ void DoConstruct (void);
+ virtual double DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const;
+
+ class PathCoefficients;
+ struct ComplexNumber {
+ double real;
+ double imag;
+ };
+ friend class PathCoefficents;
+ typedef std::vector<PathCoefficients *> DestinationList;
+ struct PathsSet {
+ Ptr<MobilityModel> sender;
+ DestinationList receivers;
+ };
+ typedef std::vector<PathsSet *> PathsList;
+
+
+ static const double PI;
+ ComplexNumber* m_amp;
+ RandomVariable m_variable;
+ double m_fd;
+ mutable PathsList m_paths;
+ uint8_t m_nRays;
+ uint8_t m_nOscillators;
+};
+
+} // namespace ns3
+
+#endif /* PROPAGATION_JAKES_MODEL_H */
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/common/propagation-delay-model.cc Tue Feb 02 11:44:02 2010 +0100
@@ -0,0 +1,104 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006,2007 INRIA
+ *
+ * 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>
+ */
+#include "propagation-delay-model.h"
+#include "ns3/random-variable.h"
+#include "ns3/mobility-model.h"
+#include "ns3/double.h"
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED (PropagationDelayModel);
+
+TypeId
+PropagationDelayModel::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::PropagationDelayModel")
+ .SetParent<Object> ()
+ ;
+ return tid;
+}
+
+PropagationDelayModel::~PropagationDelayModel ()
+{}
+
+NS_OBJECT_ENSURE_REGISTERED (RandomPropagationDelayModel);
+
+TypeId
+RandomPropagationDelayModel::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::RandomPropagationDelayModel")
+ .SetParent<PropagationDelayModel> ()
+ .AddConstructor<RandomPropagationDelayModel> ()
+ .AddAttribute ("Variable",
+ "The random variable which generates random delays (s).",
+ RandomVariableValue (UniformVariable (0.0, 1.0)),
+ MakeRandomVariableAccessor (&RandomPropagationDelayModel::m_variable),
+ MakeRandomVariableChecker ())
+ ;
+ return tid;
+}
+
+RandomPropagationDelayModel::RandomPropagationDelayModel ()
+{}
+RandomPropagationDelayModel::~RandomPropagationDelayModel ()
+{}
+Time
+RandomPropagationDelayModel::GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
+{
+ return Seconds (m_variable.GetValue ());
+}
+
+NS_OBJECT_ENSURE_REGISTERED (ConstantSpeedPropagationDelayModel);
+
+TypeId
+ConstantSpeedPropagationDelayModel::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::ConstantSpeedPropagationDelayModel")
+ .SetParent<PropagationDelayModel> ()
+ .AddConstructor<ConstantSpeedPropagationDelayModel> ()
+ .AddAttribute ("Speed", "The speed (m/s)",
+ DoubleValue (300000000.0),
+ MakeDoubleAccessor (&ConstantSpeedPropagationDelayModel::m_speed),
+ MakeDoubleChecker<double> ())
+ ;
+ return tid;
+}
+
+ConstantSpeedPropagationDelayModel::ConstantSpeedPropagationDelayModel ()
+{}
+Time
+ConstantSpeedPropagationDelayModel::GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
+{
+ double distance = a->GetDistanceFrom (b);
+ double seconds = distance / m_speed;
+ return Seconds (seconds);
+}
+void
+ConstantSpeedPropagationDelayModel::SetSpeed (double speed)
+{
+ m_speed = speed;
+}
+double
+ConstantSpeedPropagationDelayModel::GetSpeed (void) const
+{
+ return m_speed;
+}
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/common/propagation-delay-model.h Tue Feb 02 11:44:02 2010 +0100
@@ -0,0 +1,96 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006,2007 INRIA
+ *
+ * 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 PROPAGATION_DELAY_MODEL_H
+#define PROPAGATION_DELAY_MODEL_H
+
+#include "ns3/ptr.h"
+#include "ns3/object.h"
+#include "ns3/nstime.h"
+#include "ns3/random-variable.h"
+
+namespace ns3 {
+
+class MobilityModel;
+
+/**
+ * \brief calculate a propagation delay.
+ */
+class PropagationDelayModel : public Object
+{
+public:
+ static TypeId GetTypeId (void);
+ virtual ~PropagationDelayModel ();
+ /**
+ * \param a the source
+ * \param b the destination
+ * \returns the calculated propagation delay
+ *
+ * Calculate the propagation delay between the specified
+ * source and destination.
+ */
+ virtual Time GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const = 0;
+};
+
+/**
+ * \brief the propagation delay is random
+ */
+class RandomPropagationDelayModel : public PropagationDelayModel
+{
+public:
+ static TypeId GetTypeId (void);
+
+ /**
+ * Use the default parameters from PropagationDelayRandomDistribution.
+ */
+ RandomPropagationDelayModel ();
+ virtual ~RandomPropagationDelayModel ();
+ virtual Time GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const;
+private:
+ RandomVariable m_variable;
+};
+
+/**
+ * \brief the propagation speed is constant
+ */
+class ConstantSpeedPropagationDelayModel : public PropagationDelayModel
+{
+public:
+ static TypeId GetTypeId (void);
+
+ /**
+ * Use the default parameters from PropagationDelayConstantSpeed.
+ */
+ ConstantSpeedPropagationDelayModel ();
+ virtual Time GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const;
+ /**
+ * \param speed the new speed (m/s)
+ */
+ void SetSpeed (double speed);
+ /**
+ * \returns the current propagation speed (m/s).
+ */
+ double GetSpeed (void) const;
+private:
+ double m_speed;
+};
+
+} // namespace ns3
+
+#endif /* PROPAGATION_DELAY_MODEL_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/common/propagation-loss-model-test-suite.cc Tue Feb 02 11:44:02 2010 +0100
@@ -0,0 +1,250 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 The Boeing Company
+ *
+ * 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
+ */
+
+#include "ns3/log.h"
+#include "ns3/abort.h"
+#include "ns3/test.h"
+#include "ns3/pcap-file.h"
+#include "ns3/config.h"
+#include "ns3/string.h"
+#include "ns3/uinteger.h"
+#include "ns3/data-rate.h"
+#include "ns3/inet-socket-address.h"
+#include "ns3/internet-stack-helper.h"
+#include "ns3/ipv4-address-helper.h"
+#include "ns3/tcp-socket-factory.h"
+#include "ns3/yans-wifi-helper.h"
+#include "ns3/propagation-loss-model.h"
+#include "ns3/propagation-delay-model.h"
+#include "ns3/yans-wifi-channel.h"
+#include "ns3/yans-wifi-phy.h"
+#include "ns3/wifi-net-device.h"
+#include "ns3/mobility-helper.h"
+#include "ns3/constant-position-mobility-model.h"
+#include "ns3/nqos-wifi-mac-helper.h"
+#include "ns3/simulator.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("PropagationLossModelsTest");
+
+// ===========================================================================
+// This is a simple test to validate propagation loss models of ns-3 wifi.
+// See the chapter in the ns-3 testing and validation guide for more detail
+// ===========================================================================
+//
+class FriisPropagationLossModelTestCase : public TestCase
+{
+public:
+ FriisPropagationLossModelTestCase ();
+ virtual ~FriisPropagationLossModelTestCase ();
+
+private:
+ virtual bool DoRun (void);
+
+ typedef struct {
+ Vector m_position;
+ double m_pt; // dBm
+ double m_pr; // W
+ double m_tolerance;
+ } TestVector;
+
+ TestVectors<TestVector> m_testVectors;
+};
+
+FriisPropagationLossModelTestCase::FriisPropagationLossModelTestCase ()
+ : TestCase ("Check to see that the ns-3 Friis propagation loss model provides correct received power"), m_testVectors ()
+{
+}
+
+FriisPropagationLossModelTestCase::~FriisPropagationLossModelTestCase ()
+{
+}
+
+bool
+FriisPropagationLossModelTestCase::DoRun (void)
+{
+ // The ns-3 testing manual gives more background on the values selected
+ // for this test. First, set a few defaults.
+
+ // wavelength at 2.4 GHz is 0.125m
+ Config::SetDefault ("ns3::FriisPropagationLossModel::Lambda", DoubleValue (0.125));
+ Config::SetDefault ("ns3::FriisPropagationLossModel::SystemLoss", DoubleValue (1.0));
+
+ // Select a reference transmit power
+ // Pt = 10^(17.0206/10)/10^3 = .05035702 W
+ double txPowerW = 0.05035702;
+ double txPowerdBm = 10 * log10 (txPowerW) + 30;
+
+ //
+ // We want to test the propagation loss model calculations at a few chosen
+ // distances and compare the results to those we have manually calculated
+ // according to the model documentation. The model reference specifies,
+ // for instance, that the received power at 100m according to the provided
+ // input power will be 4.98265e-10 W. Since this value specifies the power
+ // to 1e-15 significance, we test the ns-3 calculated value for agreement
+ // within 5e-16.
+ //
+ TestVector testVector;
+
+ testVector.m_position = Vector (100, 0, 0);
+ testVector.m_pt = txPowerdBm;
+ testVector.m_pr = 4.98265e-10;
+ testVector.m_tolerance = 5e-16;
+ m_testVectors.Add (testVector);
+
+ testVector.m_position = Vector (500, 0, 0);
+ testVector.m_pt = txPowerdBm;
+ testVector.m_pr = 1.99306e-11;
+ testVector.m_tolerance = 5e-17;
+ m_testVectors.Add (testVector);
+
+ testVector.m_position = Vector (1000, 0, 0);
+ testVector.m_pt = txPowerdBm;
+ testVector.m_pr = 4.98265e-12;
+ testVector.m_tolerance = 5e-18;
+ m_testVectors.Add (testVector);
+
+ testVector.m_position = Vector (2000, 0, 0);
+ testVector.m_pt = txPowerdBm;
+ testVector.m_pr = 1.24566e-12;
+ testVector.m_tolerance = 5e-18;
+ m_testVectors.Add (testVector);
+
+ // Now, check that the received power values are expected
+
+ Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
+ a->SetPosition (Vector (0,0,0));
+ Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
+
+ Ptr<FriisPropagationLossModel> lossModel = CreateObject<FriisPropagationLossModel> ();
+ for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
+ {
+ testVector = m_testVectors.Get (i);
+ b->SetPosition (testVector.m_position);
+ double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
+ double resultW = pow (10.0, resultdBm/10.0)/1000;
+ NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance, "Got unexpected rcv power");
+ }
+
+ return GetErrorStatus ();
+}
+
+class LogDistancePropagationLossModelTestCase : public TestCase
+{
+public:
+ LogDistancePropagationLossModelTestCase ();
+ virtual ~LogDistancePropagationLossModelTestCase ();
+
+private:
+ virtual bool DoRun (void);
+
+ typedef struct {
+ Vector m_position;
+ double m_pt; // dBm
+ double m_pr; // W
+ double m_tolerance;
+ } TestVector;
+
+ TestVectors<TestVector> m_testVectors;
+};
+
+LogDistancePropagationLossModelTestCase::LogDistancePropagationLossModelTestCase ()
+ : TestCase ("Check to see that the ns-3 Log Distance propagation loss model provides correct received power"), m_testVectors ()
+{
+}
+
+LogDistancePropagationLossModelTestCase::~LogDistancePropagationLossModelTestCase ()
+{
+}
+
+bool
+LogDistancePropagationLossModelTestCase::DoRun (void)
+{
+ // reference loss at 2.4 GHz is 40.045997
+ Config::SetDefault ("ns3::LogDistancePropagationLossModel::ReferenceLoss", DoubleValue (40.045997));
+ Config::SetDefault ("ns3::LogDistancePropagationLossModel::Exponent", DoubleValue (3));
+
+ // Select a reference transmit power
+ // Pt = 10^(17.0206/10)/10^3 = .05035702 W
+ double txPowerW = 0.05035702;
+ double txPowerdBm = 10 * log10 (txPowerW) + 30;
+
+ //
+ // We want to test the propagation loss model calculations at a few chosen
+ // distances and compare the results to those we have manually calculated
+ // according to the model documentation. The following "TestVector" objects
+ // will drive the test.
+ //
+ TestVector testVector;
+
+ testVector.m_position = Vector (10, 0, 0);
+ testVector.m_pt = txPowerdBm;
+ testVector.m_pr = 4.98265e-9;
+ testVector.m_tolerance = 5e-15;
+ m_testVectors.Add (testVector);
+
+ testVector.m_position = Vector (20, 0, 0);
+ testVector.m_pt = txPowerdBm;
+ testVector.m_pr = 6.22831e-10;
+ testVector.m_tolerance = 5e-16;
+ m_testVectors.Add (testVector);
+
+ testVector.m_position = Vector (40, 0, 0);
+ testVector.m_pt = txPowerdBm;
+ testVector.m_pr = 7.78539e-11;
+ testVector.m_tolerance = 5e-17;
+ m_testVectors.Add (testVector);
+
+ testVector.m_position = Vector (80, 0, 0);
+ testVector.m_pt = txPowerdBm;
+ testVector.m_pr = 9.73173e-12;
+ testVector.m_tolerance = 5e-17;
+ m_testVectors.Add (testVector);
+
+ Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
+ a->SetPosition (Vector (0,0,0));
+ Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
+
+ Ptr<LogDistancePropagationLossModel> lossModel = CreateObject<LogDistancePropagationLossModel> ();
+ for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
+ {
+ testVector = m_testVectors.Get (i);
+ b->SetPosition (testVector.m_position);
+ double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
+ double resultW = pow (10.0, resultdBm/10.0)/1000;
+ NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance, "Got unexpected rcv power");
+ }
+
+ return GetErrorStatus ();
+}
+
+class PropagationLossModelsTestSuite : public TestSuite
+{
+public:
+ PropagationLossModelsTestSuite ();
+};
+
+PropagationLossModelsTestSuite::PropagationLossModelsTestSuite ()
+ : TestSuite ("propagation-loss-model", UNIT)
+{
+ AddTestCase (new FriisPropagationLossModelTestCase);
+ AddTestCase (new LogDistancePropagationLossModelTestCase);
+}
+
+PropagationLossModelsTestSuite WifiPropagationLossModelsTestSuite;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/common/propagation-loss-model.cc Tue Feb 02 11:44:02 2010 +0100
@@ -0,0 +1,546 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006,2007 INRIA
+ *
+ * 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>
+ * Contributions: Timo Bingmann <timo.bingmann@student.kit.edu>
+ */
+
+#include "propagation-loss-model.h"
+#include "ns3/log.h"
+#include "ns3/mobility-model.h"
+#include "ns3/boolean.h"
+#include "ns3/double.h"
+#include <math.h>
+
+NS_LOG_COMPONENT_DEFINE ("PropagationLossModel");
+
+namespace ns3 {
+
+// ------------------------------------------------------------------------- //
+
+NS_OBJECT_ENSURE_REGISTERED (PropagationLossModel);
+
+TypeId
+PropagationLossModel::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::PropagationLossModel")
+ .SetParent<Object> ()
+ ;
+ return tid;
+}
+
+PropagationLossModel::PropagationLossModel ()
+ : m_next (0)
+{}
+
+PropagationLossModel::~PropagationLossModel ()
+{}
+
+void
+PropagationLossModel::SetNext (Ptr<PropagationLossModel> next)
+{
+ m_next = next;
+}
+
+double
+PropagationLossModel::CalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const
+{
+ double self = DoCalcRxPower (txPowerDbm, a, b);
+ if (m_next != 0)
+ {
+ self = m_next->CalcRxPower (self, a, b);
+ }
+ return self;
+}
+
+// ------------------------------------------------------------------------- //
+
+NS_OBJECT_ENSURE_REGISTERED (RandomPropagationLossModel);
+
+TypeId
+RandomPropagationLossModel::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::RandomPropagationLossModel")
+ .SetParent<PropagationLossModel> ()
+ .AddConstructor<RandomPropagationLossModel> ()
+ .AddAttribute ("Variable", "The random variable used to pick a loss everytime CalcRxPower is invoked.",
+ RandomVariableValue (ConstantVariable (1.0)),
+ MakeRandomVariableAccessor (&RandomPropagationLossModel::m_variable),
+ MakeRandomVariableChecker ())
+ ;
+ return tid;
+}
+RandomPropagationLossModel::RandomPropagationLossModel ()
+ : PropagationLossModel ()
+{}
+
+RandomPropagationLossModel::~RandomPropagationLossModel ()
+{}
+
+double
+RandomPropagationLossModel::DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const
+{
+ double rxc = -m_variable.GetValue ();
+ NS_LOG_DEBUG ("attenuation coefficent="<<rxc<<"Db");
+ return txPowerDbm + rxc;
+}
+
+// ------------------------------------------------------------------------- //
+
+NS_OBJECT_ENSURE_REGISTERED (FriisPropagationLossModel);
+
+const double FriisPropagationLossModel::PI = 3.14159265358979323846;
+
+TypeId
+FriisPropagationLossModel::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::FriisPropagationLossModel")
+ .SetParent<PropagationLossModel> ()
+ .AddConstructor<FriisPropagationLossModel> ()
+ .AddAttribute ("Lambda",
+ "The wavelength (default is 5.15 GHz at 300 000 km/s).",
+ DoubleValue (300000000.0 / 5.150e9),
+ MakeDoubleAccessor (&FriisPropagationLossModel::m_lambda),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("SystemLoss", "The system loss",
+ DoubleValue (1.0),
+ MakeDoubleAccessor (&FriisPropagationLossModel::m_systemLoss),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("MinDistance",
+ "The distance under which the propagation model refuses to give results (m)",
+ DoubleValue (0.5),
+ MakeDoubleAccessor (&FriisPropagationLossModel::SetMinDistance,
+ &FriisPropagationLossModel::GetMinDistance),
+ MakeDoubleChecker<double> ())
+ ;
+ return tid;
+}
+
+FriisPropagationLossModel::FriisPropagationLossModel ()
+{}
+void
+FriisPropagationLossModel::SetSystemLoss (double systemLoss)
+{
+ m_systemLoss = systemLoss;
+}
+double
+FriisPropagationLossModel::GetSystemLoss (void) const
+{
+ return m_systemLoss;
+}
+void
+FriisPropagationLossModel::SetMinDistance (double minDistance)
+{
+ m_minDistance = minDistance;
+}
+double
+FriisPropagationLossModel::GetMinDistance (void) const
+{
+ return m_minDistance;
+}
+void
+FriisPropagationLossModel::SetLambda (double frequency, double speed)
+{
+ m_lambda = speed / frequency;
+}
+void
+FriisPropagationLossModel::SetLambda (double lambda)
+{
+ m_lambda = lambda;
+}
+double
+FriisPropagationLossModel::GetLambda (void) const
+{
+ return m_lambda;
+}
+
+double
+FriisPropagationLossModel::DbmToW (double dbm) const
+{
+ double mw = pow(10.0,dbm/10.0);
+ return mw / 1000.0;
+}
+
+double
+FriisPropagationLossModel::DbmFromW (double w) const
+{
+ double dbm = log10 (w * 1000.0) * 10.0;
+ return dbm;
+}
+
+double
+FriisPropagationLossModel::DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const
+{
+ /*
+ * Friis free space equation:
+ * where Pt, Gr, Gr and P are in Watt units
+ * L is in meter units.
+ *
+ * P Gt * Gr * (lambda^2)
+ * --- = ---------------------
+ * Pt (4 * pi * d)^2 * L
+ *
+ * Gt: tx gain (unit-less)
+ * Gr: rx gain (unit-less)
+ * Pt: tx power (W)
+ * d: distance (m)
+ * L: system loss
+ * lambda: wavelength (m)
+ *
+ * Here, we ignore tx and rx gain and the input and output values
+ * are in dB or dBm:
+ *
+ * lambda^2
+ * rx = tx + 10 log10 (-------------------)
+ * (4 * pi * d)^2 * L
+ *
+ * rx: rx power (dB)
+ * tx: tx power (dB)
+ * d: distance (m)
+ * L: system loss (unit-less)
+ * lambda: wavelength (m)
+ */
+ double distance = a->GetDistanceFrom (b);
+ if (distance <= m_minDistance)
+ {
+ return txPowerDbm;
+ }
+ double numerator = m_lambda * m_lambda;
+ double denominator = 16 * PI * PI * distance * distance * m_systemLoss;
+ double pr = 10 * log10 (numerator / denominator);
+ NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<pr<<"dB");
+ return txPowerDbm + pr;
+}
+
+// ------------------------------------------------------------------------- //
+
+NS_OBJECT_ENSURE_REGISTERED (LogDistancePropagationLossModel);
+
+TypeId
+LogDistancePropagationLossModel::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::LogDistancePropagationLossModel")
+ .SetParent<PropagationLossModel> ()
+ .AddConstructor<LogDistancePropagationLossModel> ()
+ .AddAttribute ("Exponent",
+ "The exponent of the Path Loss propagation model",
+ DoubleValue (3.0),
+ MakeDoubleAccessor (&LogDistancePropagationLossModel::m_exponent),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("ReferenceDistance",
+ "The distance at which the reference loss is calculated (m)",
+ DoubleValue (1.0),
+ MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceDistance),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("ReferenceLoss",
+ "The reference loss at reference distance (dB). (Default is Friis at 1m with 5.15 GHz)",
+ DoubleValue (46.6777),
+ MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceLoss),
+ MakeDoubleChecker<double> ())
+ ;
+ return tid;
+
+}
+
+LogDistancePropagationLossModel::LogDistancePropagationLossModel ()
+{}
+
+void
+LogDistancePropagationLossModel::SetPathLossExponent (double n)
+{
+ m_exponent = n;
+}
+void
+LogDistancePropagationLossModel::SetReference (double referenceDistance, double referenceLoss)
+{
+ m_referenceDistance = referenceDistance;
+ m_referenceLoss = referenceLoss;
+}
+double
+LogDistancePropagationLossModel::GetPathLossExponent (void) const
+{
+ return m_exponent;
+}
+
+double
+LogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const
+{
+ double distance = a->GetDistanceFrom (b);
+ if (distance <= m_referenceDistance)
+ {
+ return txPowerDbm;
+ }
+ /**
+ * The formula is:
+ * rx = 10 * log (Pr0(tx)) - n * 10 * log (d/d0)
+ *
+ * Pr0: rx power at reference distance d0 (W)
+ * d0: reference distance: 1.0 (m)
+ * d: distance (m)
+ * tx: tx power (dB)
+ * rx: dB
+ *
+ * Which, in our case is:
+ *
+ * rx = rx0(tx) - 10 * n * log (d/d0)
+ */
+ double pathLossDb = 10 * m_exponent * log10 (distance / m_referenceDistance);
+ double rxc = -m_referenceLoss - pathLossDb;
+ NS_LOG_DEBUG ("distance="<<distance<<"m, reference-attenuation="<<-m_referenceLoss<<"dB, "<<
+ "attenuation coefficient="<<rxc<<"db");
+ return txPowerDbm + rxc;
+}
+
+// ------------------------------------------------------------------------- //
+
+NS_OBJECT_ENSURE_REGISTERED (ThreeLogDistancePropagationLossModel);
+
+TypeId
+ThreeLogDistancePropagationLossModel::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::ThreeLogDistancePropagationLossModel")
+ .SetParent<PropagationLossModel> ()
+ .AddConstructor<ThreeLogDistancePropagationLossModel> ()
+ .AddAttribute ("Distance0",
+ "Beginning of the first (near) distance field",
+ DoubleValue (1.0),
+ MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance0),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("Distance1",
+ "Beginning of the second (middle) distance field.",
+ DoubleValue (200.0),
+ MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance1),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("Distance2",
+ "Beginning of the third (far) distance field.",
+ DoubleValue (500.0),
+ MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance2),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("Exponent0",
+ "The exponent for the first field.",
+ DoubleValue (1.9),
+ MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent0),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("Exponent1",
+ "The exponent for the second field.",
+ DoubleValue (3.8),
+ MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent1),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("Exponent2",
+ "The exponent for the third field.",
+ DoubleValue (3.8),
+ MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent2),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("ReferenceLoss",
+ "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)",
+ DoubleValue (46.6777),
+ MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_referenceLoss),
+ MakeDoubleChecker<double> ())
+ ;
+ return tid;
+
+}
+
+ThreeLogDistancePropagationLossModel::ThreeLogDistancePropagationLossModel ()
+{
+}
+
+double
+ThreeLogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const
+{
+ double distance = a->GetDistanceFrom (b);
+ NS_ASSERT(distance >= 0);
+
+ // See doxygen comments for the formula and explanation
+
+ double pathLossDb;
+
+ if (distance < m_distance0)
+ {
+ pathLossDb = 0;
+ }
+ else if (distance < m_distance1)
+ {
+ pathLossDb = m_referenceLoss
+ + 10 * m_exponent0 * log10(distance / m_distance0);
+ }
+ else if (distance < m_distance2)
+ {
+ pathLossDb = m_referenceLoss
+ + 10 * m_exponent0 * log10(m_distance1 / m_distance0)
+ + 10 * m_exponent1 * log10(distance / m_distance1);
+ }
+ else
+ {
+ pathLossDb = m_referenceLoss
+ + 10 * m_exponent0 * log10(m_distance1 / m_distance0)
+ + 10 * m_exponent1 * log10(m_distance2 / m_distance1)
+ + 10 * m_exponent2 * log10(distance / m_distance2);
+ }
+
+ NS_LOG_DEBUG ("ThreeLogDistance distance=" << distance << "m, " <<
+ "attenuation=" << pathLossDb << "dB");
+
+ return txPowerDbm - pathLossDb;
+}
+
+// ------------------------------------------------------------------------- //
+
+NS_OBJECT_ENSURE_REGISTERED (NakagamiPropagationLossModel);
+
+TypeId
+NakagamiPropagationLossModel::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::NakagamiPropagationLossModel")
+ .SetParent<PropagationLossModel> ()
+ .AddConstructor<NakagamiPropagationLossModel> ()
+ .AddAttribute ("Distance1",
+ "Beginning of the second distance field. Default is 80m.",
+ DoubleValue (80.0),
+ MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance1),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("Distance2",
+ "Beginning of the third distance field. Default is 200m.",
+ DoubleValue (200.0),
+ MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance2),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("m0",
+ "m0 for distances smaller than Distance1. Default is 1.5.",
+ DoubleValue (1.5),
+ MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m0),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("m1",
+ "m1 for distances smaller than Distance2. Default is 0.75.",
+ DoubleValue (0.75),
+ MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m1),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("m2",
+ "m2 for distances greater than Distance2. Default is 0.75.",
+ DoubleValue (0.75),
+ MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m2),
+ MakeDoubleChecker<double> ())
+ ;
+ return tid;
+
+}
+
+NakagamiPropagationLossModel::NakagamiPropagationLossModel ()
+{}
+
+double
+NakagamiPropagationLossModel::DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const
+{
+ // select m parameter
+
+ double distance = a->GetDistanceFrom (b);
+ NS_ASSERT(distance >= 0);
+
+ double m;
+ if (distance < m_distance1)
+ {
+ m = m_m0;
+ }
+ else if (distance < m_distance2)
+ {
+ m = m_m1;
+ }
+ else
+ {
+ m = m_m2;
+ }
+
+ // the current power unit is dBm, but Watt is put into the Nakagami /
+ // Rayleigh distribution.
+ double powerW = pow(10, (txPowerDbm - 30) / 10);
+
+ double resultPowerW;
+
+ // switch between Erlang- and Gamma distributions: this is only for
+ // speed. (Gamma is equal to Erlang for any positive integer m.)
+ unsigned int int_m = static_cast<unsigned int>(floor(m));
+
+ if (int_m == m)
+ {
+ resultPowerW = m_erlangRandomVariable.GetValue(int_m, powerW / m);
+ }
+ else
+ {
+ resultPowerW = m_gammaRandomVariable.GetValue(m, powerW / m);
+ }
+
+ double resultPowerDbm = 10 * log10(resultPowerW) + 30;
+
+ NS_LOG_DEBUG ("Nakagami distance=" << distance << "m, " <<
+ "power=" << powerW <<"W, " <<
+ "resultPower=" << resultPowerW << "W=" << resultPowerDbm << "dBm");
+
+ return resultPowerDbm;
+}
+
+// ------------------------------------------------------------------------- //
+
+NS_OBJECT_ENSURE_REGISTERED (FixedRssLossModel);
+
+TypeId
+FixedRssLossModel::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::FixedRssLossModel")
+ .SetParent<PropagationLossModel> ()
+ .AddConstructor<FixedRssLossModel> ()
+ .AddAttribute ("Rss", "The fixed receiver Rss.",
+ DoubleValue (-150.0),
+ MakeDoubleAccessor (&FixedRssLossModel::m_rss),
+ MakeDoubleChecker<double> ())
+ ;
+ return tid;
+}
+FixedRssLossModel::FixedRssLossModel ()
+ : PropagationLossModel ()
+{}
+
+FixedRssLossModel::~FixedRssLossModel ()
+{}
+
+void
+FixedRssLossModel::SetRss (double rss)
+{
+ m_rss = rss;
+}
+
+double
+FixedRssLossModel::DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const
+{
+ return m_rss;
+}
+
+// ------------------------------------------------------------------------- //
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/common/propagation-loss-model.h Tue Feb 02 11:44:02 2010 +0100
@@ -0,0 +1,375 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006,2007 INRIA
+ *
+ * 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>
+ * Contributions: Timo Bingmann <timo.bingmann@student.kit.edu>
+ * Contributions: Gary Pei <guangyu.pei@boeing.com> for fixed RSS
+ */
+
+#ifndef PROPAGATION_LOSS_MODEL_H
+#define PROPAGATION_LOSS_MODEL_H
+
+#include "ns3/object.h"
+#include "ns3/random-variable.h"
+
+namespace ns3 {
+
+class MobilityModel;
+
+/**
+ * \brief Modelize the propagation loss through a transmission medium
+ *
+ * Calculate the receive power (dbm) from a transmit power (dbm)
+ * and a mobility model for the source and destination positions.
+ */
+class PropagationLossModel : public Object
+{
+public:
+ static TypeId GetTypeId (void);
+
+ PropagationLossModel ();
+ virtual ~PropagationLossModel ();
+
+ void SetNext (Ptr<PropagationLossModel> next);
+
+ /**
+ * \param txPowerDbm current transmission power (in dBm)
+ * \param a the mobility model of the source
+ * \param b the mobility model of the destination
+ * \returns the reception power after adding/multiplying propagation loss (in dBm)
+ */
+ double CalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const;
+private:
+ PropagationLossModel (const PropagationLossModel &o);
+ PropagationLossModel &operator = (const PropagationLossModel &o);
+ virtual double DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const = 0;
+
+ Ptr<PropagationLossModel> m_next;
+};
+
+/**
+ * \brief The propagation loss follows a random distribution.
+ */
+class RandomPropagationLossModel : public PropagationLossModel
+{
+public:
+ static TypeId GetTypeId (void);
+
+ RandomPropagationLossModel ();
+ virtual ~RandomPropagationLossModel ();
+
+private:
+ RandomPropagationLossModel (const RandomPropagationLossModel &o);
+ RandomPropagationLossModel & operator = (const RandomPropagationLossModel &o);
+ virtual double DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const;
+ RandomVariable m_variable;
+};
+
+/**
+ * \brief a Friis propagation loss model
+ *
+ * The Friis propagation loss model was first described in
+ * "A Note on a Simple Transmission Formula", by
+ * "Harald T. Friis".
+ *
+ * The original equation was described as:
+ * \f$ \frac{P_r}{P_t} = \frac{A_r A_t}{d^2\lambda^2} \f$
+ * with the following equation for the case of an
+ * isotropic antenna with no heat loss:
+ * \f$ A_{isotr.} = \frac{\lambda^2}{4\pi} \f$
+ *
+ * The final equation becomes:
+ * \f$ \frac{P_r}{P_t} = \frac{\lambda^2}{(4 \pi d)^2} \f$
+ *
+ * Modern extensions to this original equation are:
+ * \f$ P_r = \frac{P_t G_t G_r \lambda^2}{(4 \pi d)^2 L}\f$
+ *
+ * With:
+ * - \f$ P_r \f$ : reception power (W)
+ * - \f$ P_t \f$ : transmission power (W)
+ * - \f$ G_t \f$ : transmission gain (unit-less)
+ * - \f$ G_r \f$ : reception gain (unit-less)
+ * - \f$ \lambda \f$ : wavelength (m)
+ * - \f$ d \f$ : distance (m)
+ * - \f$ L \f$ : system loss (unit-less)
+ *
+ *
+ * This model is invalid for small distance values.
+ * The current implementation returns the txpower as the rxpower
+ * for any distance smaller than MinDistance.
+ */
+class FriisPropagationLossModel : public PropagationLossModel
+{
+public:
+ static TypeId GetTypeId (void);
+ FriisPropagationLossModel ();
+ /**
+ * \param frequency (Hz)
+ * \param speed (m/s)
+ *
+ * Set the main wavelength used in the Friis model
+ * calculation.
+ */
+ void SetLambda (double frequency, double speed);
+ /**
+ * \param lambda (m) the wavelength
+ *
+ * Set the main wavelength used in the Friis model
+ * calculation.
+ */
+ void SetLambda (double lambda);
+ /**
+ * \param systemLoss (dimension-less)
+ *
+ * Set the system loss used by the Friis propagation model.
+ */
+ void SetSystemLoss (double systemLoss);
+
+ /**
+ * \param minDistance the minimum distance
+ *
+ * Below this distance, the txpower is returned
+ * unmodified as the rxpower.
+ */
+ void SetMinDistance (double minDistance);
+
+ /**
+ * \returns the minimum distance.
+ */
+ double GetMinDistance (void) const;
+
+ /**
+ * \returns the current wavelength (m)
+ */
+ double GetLambda (void) const;
+ /**
+ * \returns the current system loss (dimention-less)
+ */
+ double GetSystemLoss (void) const;
+
+private:
+ FriisPropagationLossModel (const FriisPropagationLossModel &o);
+ FriisPropagationLossModel & operator = (const FriisPropagationLossModel &o);
+ virtual double DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const;
+ double DbmToW (double dbm) const;
+ double DbmFromW (double w) const;
+
+ static const double PI;
+ double m_lambda;
+ double m_systemLoss;
+ double m_minDistance;
+};
+
+/**
+ * \brief a log distance propagation model.
+ *
+ * This model calculates the reception power with a so-called
+ * log-distance propagation model:
+ * \f$ L = L_0 + 10 n log_{10}(\frac{d}{d_0})\f$
+ *
+ * where:
+ * - \f$ n \f$ : the path loss distance exponent
+ * - \f$ d_0 \f$ : reference distance (m)
+ * - \f$ L_0 \f$ : path loss at reference distance (dB)
+ * - \f$ d \f$ : distance (m)
+ * - \f$ L \f$ : path loss (dB)
+ *
+ * When the path loss is requested at a distance smaller than
+ * the reference distance, the tx power is returned.
+ *
+ */
+class LogDistancePropagationLossModel : public PropagationLossModel
+{
+public:
+ static TypeId GetTypeId (void);
+ LogDistancePropagationLossModel ();
+
+ /**
+ * \param n the path loss exponent.
+ * Set the path loss exponent.
+ */
+ void SetPathLossExponent (double n);
+ /**
+ * \returns the current path loss exponent.
+ */
+ double GetPathLossExponent (void) const;
+
+ void SetReference (double referenceDistance, double referenceLoss);
+
+private:
+ LogDistancePropagationLossModel (const LogDistancePropagationLossModel &o);
+ LogDistancePropagationLossModel & operator = (const LogDistancePropagationLossModel &o);
+ virtual double DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const;
+ static Ptr<PropagationLossModel> CreateDefaultReference (void);
+
+ double m_exponent;
+ double m_referenceDistance;
+ double m_referenceLoss;
+};
+
+/**
+ * \brief A log distance path loss propagation model with three distance
+ * fields. This model is the same as ns3::LogDistancePropagationLossModel
+ * except that it has three distance fields: near, middle and far with
+ * different exponents.
+ *
+ * Within each field the reception power is calculated using the log-distance
+ * propagation equation:
+ * \f[ L = L_0 + 10 \cdot n_0 log_{10}(\frac{d}{d_0})\f]
+ * Each field begins where the previous ends and all together form a continuous function.
+ *
+ * There are three valid distance fields: near, middle, far. Actually four: the
+ * first from 0 to the reference distance is invalid and returns txPowerDbm.
+ *
+ * \f[ \underbrace{0 \cdots\cdots}_{=0} \underbrace{d_0 \cdots\cdots}_{n_0} \underbrace{d_1 \cdots\cdots}_{n_1} \underbrace{d_2 \cdots\cdots}_{n_2} \infty \f]
+ *
+ * Complete formula for the path loss in dB:
+ *
+ * \f[\displaystyle L =
+\begin{cases}
+0 & d < d_0 \\
+L_0 + 10 \cdot n_0 \log_{10}(\frac{d}{d_0}) & d_0 \leq d < d_1 \\
+L_0 + 10 \cdot n_0 \log_{10}(\frac{d_1}{d_0}) + 10 \cdot n_1 \log_{10}(\frac{d}{d_1}) & d_1 \leq d < d_2 \\
+L_0 + 10 \cdot n_0 \log_{10}(\frac{d_1}{d_0}) + 10 \cdot n_1 \log_{10}(\frac{d_2}{d_1}) + 10 \cdot n_2 \log_{10}(\frac{d}{d_2})& d_2 \leq d
+\end{cases}\f]
+ *
+ * where:
+ * - \f$ L \f$ : resulting path loss (dB)
+ * - \f$ d \f$ : distance (m)
+ * - \f$ d_0, d_1, d_2 \f$ : three distance fields (m)
+ * - \f$ n_0, n_1, n_2 \f$ : path loss distance exponent for each field (unitless)
+ * - \f$ L_0 \f$ : path loss at reference distance (dB)
+ *
+ * When the path loss is requested at a distance smaller than the reference
+ * distance \f$ d_0 \f$, the tx power (with no path loss) is returned. The
+ * reference distance defaults to 1m and reference loss defaults to
+ * ns3::FriisPropagationLossModel with 5.15 GHz and is thus \f$ L_0 \f$ = 46.67 dB.
+ */
+
+class ThreeLogDistancePropagationLossModel : public PropagationLossModel
+{
+public:
+ static TypeId GetTypeId (void);
+ ThreeLogDistancePropagationLossModel ();
+
+ // Parameters are all accessible via attributes.
+
+private:
+ ThreeLogDistancePropagationLossModel (const ThreeLogDistancePropagationLossModel& o);
+ ThreeLogDistancePropagationLossModel& operator= (const ThreeLogDistancePropagationLossModel& o);
+
+ virtual double DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const;
+
+ double m_distance0;
+ double m_distance1;
+ double m_distance2;
+
+ double m_exponent0;
+ double m_exponent1;
+ double m_exponent2;
+
+ double m_referenceLoss;
+};
+
+/**
+ * \brief Nakagami-m fast fading propagation loss model.
+ *
+ * The Nakagami-m distribution is applied to the power level. The probability
+ * density function is defined as
+ * \f[ p(x; m, \omega) = \frac{2 m^m}{\Gamma(m) \omega^m} x^{2m - 1} e^{-\frac{m}{\omega} x^2} = 2 x \cdot p_{\text{Gamma}}(x^2, m, \frac{m}{\omega}) \f]
+ * with \f$ m \f$ the fading depth parameter and \f$ \omega \f$ the average received power.
+ *
+ * It is implemented by either a ns3::GammaVariable or a ns3::ErlangVariable
+ * random variable.
+ *
+ * Like in ns3::ThreeLogDistancePropagationLossModel, the m parameter is varied
+ * over three distance fields:
+ * \f[ \underbrace{0 \cdots\cdots}_{m_0} \underbrace{d_1 \cdots\cdots}_{m_1} \underbrace{d_2 \cdots\cdots}_{m_2} \infty \f]
+ *
+ * For m = 1 the Nakagami-m distribution equals the Rayleigh distribution. Thus
+ * this model also implements Rayleigh distribution based fast fading.
+ */
+
+class NakagamiPropagationLossModel : public PropagationLossModel
+{
+public:
+ static TypeId GetTypeId (void);
+
+ NakagamiPropagationLossModel ();
+
+ // Parameters are all accessible via attributes.
+
+private:
+ NakagamiPropagationLossModel (const NakagamiPropagationLossModel& o);
+ NakagamiPropagationLossModel& operator= (const NakagamiPropagationLossModel& o);
+
+ virtual double DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const;
+
+ double m_distance1;
+ double m_distance2;
+
+ double m_m0;
+ double m_m1;
+ double m_m2;
+
+ ErlangVariable m_erlangRandomVariable;
+ GammaVariable m_gammaRandomVariable;
+};
+
+/**
+ * \brief The propagation loss is fixed. The user can set received power level.
+ */
+class FixedRssLossModel : public PropagationLossModel
+{
+public:
+ static TypeId GetTypeId (void);
+
+ FixedRssLossModel ();
+ virtual ~FixedRssLossModel ();
+ /**
+ * \param rss (dBm) the received signal strength
+ *
+ * Set the RSS.
+ */
+ void SetRss (double rss);
+
+private:
+ FixedRssLossModel (const FixedRssLossModel &o);
+ FixedRssLossModel & operator = (const FixedRssLossModel &o);
+ virtual double DoCalcRxPower (double txPowerDbm,
+ Ptr<MobilityModel> a,
+ Ptr<MobilityModel> b) const;
+ double m_rss;
+};
+
+} // namespace ns3
+
+#endif /* PROPAGATION_LOSS_MODEL_H */
--- a/src/common/wscript Mon Feb 01 15:24:40 2010 +0000
+++ b/src/common/wscript Tue Feb 02 11:44:02 2010 +0100
@@ -21,6 +21,10 @@
'ascii-writer.cc',
'pcap-file.cc',
'pcap-file-test-suite.cc',
+ 'propagation-delay-model.cc',
+ 'propagation-loss-model.cc',
+ 'propagation-loss-model-test-suite.cc',
+ 'jakes-propagation-loss-model.cc',
]
headers = bld.new_task_gen('ns3header')
@@ -43,4 +47,7 @@
'ascii-writer.h',
'sgi-hashmap.h',
'pcap-file.h',
+ 'propagation-delay-model.h',
+ 'propagation-loss-model.h',
+ 'jakes-propagation-loss-model.h',
]
--- a/src/devices/wifi/jakes-propagation-loss-model.cc Mon Feb 01 15:24:40 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,259 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006,2007 INRIA
- *
- * 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: Federico Maguolo <maguolof@dei.unipd.it>
- */
-
-#include "ns3/simulator.h"
-#include "ns3/uinteger.h"
-#include "ns3/double.h"
-#include "ns3/random-variable.h"
-#include "ns3/mobility-model.h"
-#include "ns3/log.h"
-#include "jakes-propagation-loss-model.h"
-#include <math.h>
-
-NS_LOG_COMPONENT_DEFINE ("Jakes");
-
-namespace ns3 {
-
-class JakesPropagationLossModel::PathCoefficients
-{
-public:
- PathCoefficients (Ptr<const JakesPropagationLossModel> jakes,
- Ptr<MobilityModel> receiver,
- uint8_t nRays,
- uint8_t nOscillators);
- ~PathCoefficients ();
- double GetLoss (void);
- Ptr<MobilityModel> GetReceiver (void);
-private:
- void DoConstruct (void);
- Ptr<MobilityModel> m_receiver;
- uint8_t m_nOscillators;
- uint8_t m_nRays;
- double **m_phases;
- Time m_lastUpdate;
- Ptr<const JakesPropagationLossModel> m_jakes;
-};
-
-
-JakesPropagationLossModel::PathCoefficients::PathCoefficients (Ptr<const JakesPropagationLossModel> jakes,
- Ptr<MobilityModel> receiver,
- uint8_t nRays,
- uint8_t nOscillators)
- : m_receiver (receiver),
- m_nOscillators (nOscillators),
- m_nRays (nRays),
- m_jakes(jakes)
-{
- DoConstruct ();
-}
-
-JakesPropagationLossModel::PathCoefficients::~PathCoefficients ()
-{
- for (uint8_t i = 0; i < m_nRays; i++)
- {
- delete [] m_phases[i];
- }
- delete [] m_phases;
-}
-
-void
-JakesPropagationLossModel::PathCoefficients::DoConstruct ()
-{
- m_phases = new double*[m_nRays];
- for (uint8_t i = 0; i < m_nRays; i++)
- {
- m_phases[i] = new double[m_nOscillators + 1];
- for (uint8_t j = 0; j <= m_nOscillators; j++)
- {
- m_phases[i][j] = 2.0 * JakesPropagationLossModel::PI * m_jakes->m_variable.GetValue ();
- }
- }
- m_lastUpdate = Simulator::Now ();
-}
-
-Ptr<MobilityModel>
-JakesPropagationLossModel::PathCoefficients::GetReceiver ()
-{
- return m_receiver;
-}
-
-double
-JakesPropagationLossModel::PathCoefficients::GetLoss (void)
-{
- uint16_t N = 4 * m_nOscillators + 2;
- Time interval = Simulator::Now () - m_lastUpdate;
- ComplexNumber coef= {0.0, 0.0};
- ComplexNumber fading;
- double norm = 0.0;
- for (uint8_t i = 0; i < m_nRays; i++)
- {
- fading.real = 0.0;
- fading.imag = 0.0;
- for (uint8_t j = 0; j <= m_nOscillators; j++)
- {
- m_phases[i][j] += 2.0 * JakesPropagationLossModel::PI *
- cos (2.0 * JakesPropagationLossModel::PI * j / N) * m_jakes->m_fd * interval.GetSeconds ();
- m_phases[i][j] -= 2.0 * JakesPropagationLossModel::PI *
- floor (m_phases[i][j] / 2.0 / JakesPropagationLossModel::PI);
- fading.real += m_jakes->m_amp[j].real * cos (m_phases[i][j]);
- fading.imag += m_jakes->m_amp[j].imag * cos (m_phases[i][j]);
- norm += sqrt(pow (m_jakes->m_amp[j].real, 2) + pow(m_jakes->m_amp[j].imag, 2));
- }
- coef.real += fading.real;
- coef.imag += fading.imag;
- }
- m_lastUpdate = Simulator::Now ();
- double k = sqrt (pow (coef.real, 2) + pow (coef.imag, 2)) / norm;
- NS_LOG_DEBUG ("Jakes coef "<< k << " (" << 10 * log10 (k) << "dB)");
- return 10 * log10 (k);
-}
-
-NS_OBJECT_ENSURE_REGISTERED (JakesPropagationLossModel);
-
-const double JakesPropagationLossModel::PI = 3.14159265358979323846;
-
-TypeId
-JakesPropagationLossModel::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::JakesPropagationLossModel")
- .SetParent<PropagationLossModel> ()
- .AddConstructor<JakesPropagationLossModel> ()
- .AddAttribute ("NumberOfRaysPerPath",
- "The number of rays to use by default for compute the fading coeficent for a given path (default is 1)",
- UintegerValue (1),
- MakeUintegerAccessor (&JakesPropagationLossModel::SetNRays,
- &JakesPropagationLossModel::GetNRays),
- MakeUintegerChecker<uint8_t> ())
- .AddAttribute ("NumberOfOscillatorsPerRay",
- "The number of oscillators to use by default for compute the coeficent for a given ray of a given "
- "path (default is 4)",
- UintegerValue (4),
- MakeUintegerAccessor (&JakesPropagationLossModel::SetNOscillators,
- &JakesPropagationLossModel::GetNOscillators),
- MakeUintegerChecker<uint8_t> ())
- .AddAttribute ("DopplerFreq",
- "The doppler frequency in Hz (f_d = v / lambda = v * f / c), the default is 0)",
- DoubleValue (0.0),
- MakeDoubleAccessor (&JakesPropagationLossModel::m_fd),
- MakeDoubleChecker<double> ())
- .AddAttribute ("Distribution",
- "The distribution to choose the initial phases.",
- RandomVariableValue (ConstantVariable (1.0)),
- MakeRandomVariableAccessor (&JakesPropagationLossModel::m_variable),
- MakeRandomVariableChecker ())
- ;
- return tid;
-}
-
-JakesPropagationLossModel::JakesPropagationLossModel ()
- : m_amp (0),
- m_nRays (0),
- m_nOscillators (0)
-{}
-
-JakesPropagationLossModel::~JakesPropagationLossModel ()
-{
- delete [] m_amp;
- for (PathsList::iterator i = m_paths.end (); i != m_paths.begin (); i--)
- {
- PathsSet *ps = *i;
- for (DestinationList::iterator r = ps->receivers.begin (); r != ps->receivers.end (); r++)
- {
- PathCoefficients *pc = *r;
- delete pc;
- }
- delete ps;
- }
-}
-
-void
-JakesPropagationLossModel::SetNRays (uint8_t nRays)
-{
- m_nRays = nRays;
-}
-
-void
-JakesPropagationLossModel::SetNOscillators (uint8_t nOscillators)
-{
- m_nOscillators = nOscillators;
- delete [] m_amp;
- uint16_t N = 4 * m_nOscillators + 2;
- m_amp = new ComplexNumber[m_nOscillators + 1];
- m_amp[0].real = 2.0 * sqrt(2.0 / N) * cos (PI / 4.0);
- m_amp[0].imag = 2.0 * sqrt(2.0 / N) * sin (PI / 4.0);
- for (uint8_t i = 1; i <= m_nOscillators; i++)
- {
- double beta = PI * (double)i / m_nOscillators;
- m_amp[i].real = 4.0 * cos (beta) / sqrt(N);
- m_amp[i].imag = 4.0 * sin (beta) / sqrt(N);
- }
-}
-
-uint8_t
-JakesPropagationLossModel::GetNRays (void) const
-{
- return m_nRays;
-}
-uint8_t
-JakesPropagationLossModel::GetNOscillators (void) const
-{
- return m_nOscillators;
-}
-
-
-double
-JakesPropagationLossModel::DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const
-{
- PathsList::iterator i = m_paths.end ();
- while (i != m_paths.begin ())
- {
- i--;
- PathsSet *ps = *i;
- if (ps->sender == a)
- {
- m_paths.erase (i);
- m_paths.push_back (ps);
- for (DestinationList::iterator r = ps->receivers.begin (); r != ps->receivers.end (); r++)
- {
- PathCoefficients *pc = *r;
- if (pc->GetReceiver () == b)
- {
- ps->receivers.erase (r);
- ps->receivers.push_back (pc);
- return txPowerDbm + pc->GetLoss ();
- }
- }
- PathCoefficients *pc = new PathCoefficients (this, b, m_nRays, m_nOscillators);
- ps->receivers.push_back (pc);
- return txPowerDbm + pc->GetLoss ();
- }
- }
- PathsSet *ps = new PathsSet;
- ps->sender = a;
- PathCoefficients *pc = new PathCoefficients (this, b, m_nRays, m_nOscillators);
- ps->receivers.push_back (pc);
- m_paths.push_back (ps);
- return txPowerDbm + pc->GetLoss ();
-}
-
-} // namespace ns3
-
--- a/src/devices/wifi/jakes-propagation-loss-model.h Mon Feb 01 15:24:40 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,137 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006,2007 INRIA
- *
- * 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: Federico Maguolo <maguolof@dei.unipd.it>
- */
-#ifndef PROPAGATION_JAKES_MODEL_H
-#define PROPAGATION_JAKES_MODEL_H
-
-#include "ns3/nstime.h"
-#include "propagation-loss-model.h"
-
-namespace ns3 {
-
-
-/**
- * \brief a Jakes propagation loss model
- *
- * The Jakes propagation loss model implemented here is
- * described in [1].
- *
- *
- * We call path the set of rays that depart from a given
- * transmitter and arrive to a given receiver. For each ray
- * The complex coefficient is compute as follow:
- * \f[ u(t)=u_c(t) + j u_s(t)\f]
- * \f[ u_c(t) = \frac{2}{\sqrt{N}}\sum_{n=0}^{M}a_n\cos(\omega_n t+\phi_n)\f]
- * \f[ u_s(t) = \frac{2}{\sqrt{N}}\sum_{n=0}^{M}b_n\cos(\omega_n t+\phi_n)\f]
- * where
- * \f[ a_n=\left \{ \begin{array}{ll}
- * \sqrt{2}\cos\beta_0 & n=0 \\
- * 2\cos\beta_n & n=1,2,\ldots,M
- * \end{array}
- * \right .\f]
- * \f[ b_n=\left \{ \begin{array}{ll}
- * \sqrt{2}\sin\beta_0 & n=0 \\
- * 2\sin\beta_n & n=1,2,\ldots,M
- * \end{array}
- * \right .\f]
- * \f[ \beta_n=\left \{ \begin{array}{ll}
- * \frac{\pi}{4} & n=0 \\
- * \frac{\pi n}{M} & n=1,2,\ldots,M
- * \end{array}
- * \right .\f]
- * \f[ \omega_n=\left \{ \begin{array}{ll}
- * 2\pi f_d & n=0 \\
- * 2\pi f_d \cos\frac{2\pi n}{N} & n=1,2,\ldots,M
- * \end{array}
- * \right .\f]
- *
- * The parameter \f$f_d\f$ is the doppler frequency and \f$N=4M+2\f$ where
- * \f$M\f$ is the number of oscillators per ray.
- *
- * The attenuation coefficent of the path is the magnitude of the sum of
- * all the ray coefficients. This attenuation coefficient could be greater than
- * \f$1\f$, hence it is divide by \f$ \frac{2N_r}{\sqrt{N}} \sum_{n+0}^{M}\sqrt{a_n^2 +b_n^2}\f$
- * where \f$N_r\f$ is the number of rays.
- *
- * The initail phases \f$\phi_i\f$ are random and they are choosen according
- * to a given distribution.
- *
- * [1] Y. R. Zheng and C. Xiao, "Simulation Models With Correct
- * Statistical Properties for Rayleigh Fading Channel", IEEE
- * Trans. on Communications, Vol. 51, pp 920-928, June 2003
- */
-class JakesPropagationLossModel : public PropagationLossModel
-{
-public:
- static TypeId GetTypeId (void);
- JakesPropagationLossModel ();
- virtual ~JakesPropagationLossModel ();
-
- /**
- * \param nRays Number of rays per path
- *
- * Set the number of rays for each path
- */
- void SetNRays (uint8_t nRays);
- /**
- * \param nOscillators Number of oscillators
- *
- * Set the number of oscillators to use to compute the ray coefficient
- */
- void SetNOscillators (uint8_t nOscillators);
-
- uint8_t GetNRays (void) const;
- uint8_t GetNOscillators (void) const;
-
-private:
- JakesPropagationLossModel (const JakesPropagationLossModel &o);
- JakesPropagationLossModel & operator = (const JakesPropagationLossModel &o);
- void DoConstruct (void);
- virtual double DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const;
-
- class PathCoefficients;
- struct ComplexNumber {
- double real;
- double imag;
- };
- friend class PathCoefficents;
- typedef std::vector<PathCoefficients *> DestinationList;
- struct PathsSet {
- Ptr<MobilityModel> sender;
- DestinationList receivers;
- };
- typedef std::vector<PathsSet *> PathsList;
-
-
- static const double PI;
- ComplexNumber* m_amp;
- RandomVariable m_variable;
- double m_fd;
- mutable PathsList m_paths;
- uint8_t m_nRays;
- uint8_t m_nOscillators;
-};
-
-} // namespace ns3
-
-#endif /* PROPAGATION_JAKES_MODEL_H */
-
-
--- a/src/devices/wifi/propagation-delay-model.cc Mon Feb 01 15:24:40 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,104 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006,2007 INRIA
- *
- * 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>
- */
-#include "propagation-delay-model.h"
-#include "ns3/random-variable.h"
-#include "ns3/mobility-model.h"
-#include "ns3/double.h"
-
-namespace ns3 {
-
-NS_OBJECT_ENSURE_REGISTERED (PropagationDelayModel);
-
-TypeId
-PropagationDelayModel::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::PropagationDelayModel")
- .SetParent<Object> ()
- ;
- return tid;
-}
-
-PropagationDelayModel::~PropagationDelayModel ()
-{}
-
-NS_OBJECT_ENSURE_REGISTERED (RandomPropagationDelayModel);
-
-TypeId
-RandomPropagationDelayModel::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::RandomPropagationDelayModel")
- .SetParent<PropagationDelayModel> ()
- .AddConstructor<RandomPropagationDelayModel> ()
- .AddAttribute ("Variable",
- "The random variable which generates random delays (s).",
- RandomVariableValue (UniformVariable (0.0, 1.0)),
- MakeRandomVariableAccessor (&RandomPropagationDelayModel::m_variable),
- MakeRandomVariableChecker ())
- ;
- return tid;
-}
-
-RandomPropagationDelayModel::RandomPropagationDelayModel ()
-{}
-RandomPropagationDelayModel::~RandomPropagationDelayModel ()
-{}
-Time
-RandomPropagationDelayModel::GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
-{
- return Seconds (m_variable.GetValue ());
-}
-
-NS_OBJECT_ENSURE_REGISTERED (ConstantSpeedPropagationDelayModel);
-
-TypeId
-ConstantSpeedPropagationDelayModel::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::ConstantSpeedPropagationDelayModel")
- .SetParent<PropagationDelayModel> ()
- .AddConstructor<ConstantSpeedPropagationDelayModel> ()
- .AddAttribute ("Speed", "The speed (m/s)",
- DoubleValue (300000000.0),
- MakeDoubleAccessor (&ConstantSpeedPropagationDelayModel::m_speed),
- MakeDoubleChecker<double> ())
- ;
- return tid;
-}
-
-ConstantSpeedPropagationDelayModel::ConstantSpeedPropagationDelayModel ()
-{}
-Time
-ConstantSpeedPropagationDelayModel::GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const
-{
- double distance = a->GetDistanceFrom (b);
- double seconds = distance / m_speed;
- return Seconds (seconds);
-}
-void
-ConstantSpeedPropagationDelayModel::SetSpeed (double speed)
-{
- m_speed = speed;
-}
-double
-ConstantSpeedPropagationDelayModel::GetSpeed (void) const
-{
- return m_speed;
-}
-
-} // namespace ns3
--- a/src/devices/wifi/propagation-delay-model.h Mon Feb 01 15:24:40 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,96 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006,2007 INRIA
- *
- * 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 PROPAGATION_DELAY_MODEL_H
-#define PROPAGATION_DELAY_MODEL_H
-
-#include "ns3/ptr.h"
-#include "ns3/object.h"
-#include "ns3/nstime.h"
-#include "ns3/random-variable.h"
-
-namespace ns3 {
-
-class MobilityModel;
-
-/**
- * \brief calculate a propagation delay.
- */
-class PropagationDelayModel : public Object
-{
-public:
- static TypeId GetTypeId (void);
- virtual ~PropagationDelayModel ();
- /**
- * \param a the source
- * \param b the destination
- * \returns the calculated propagation delay
- *
- * Calculate the propagation delay between the specified
- * source and destination.
- */
- virtual Time GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const = 0;
-};
-
-/**
- * \brief the propagation delay is random
- */
-class RandomPropagationDelayModel : public PropagationDelayModel
-{
-public:
- static TypeId GetTypeId (void);
-
- /**
- * Use the default parameters from PropagationDelayRandomDistribution.
- */
- RandomPropagationDelayModel ();
- virtual ~RandomPropagationDelayModel ();
- virtual Time GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const;
-private:
- RandomVariable m_variable;
-};
-
-/**
- * \brief the propagation speed is constant
- */
-class ConstantSpeedPropagationDelayModel : public PropagationDelayModel
-{
-public:
- static TypeId GetTypeId (void);
-
- /**
- * Use the default parameters from PropagationDelayConstantSpeed.
- */
- ConstantSpeedPropagationDelayModel ();
- virtual Time GetDelay (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const;
- /**
- * \param speed the new speed (m/s)
- */
- void SetSpeed (double speed);
- /**
- * \returns the current propagation speed (m/s).
- */
- double GetSpeed (void) const;
-private:
- double m_speed;
-};
-
-} // namespace ns3
-
-#endif /* PROPAGATION_DELAY_MODEL_H */
--- a/src/devices/wifi/propagation-loss-model-test-suite.cc Mon Feb 01 15:24:40 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,250 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 The Boeing Company
- *
- * 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
- */
-
-#include "ns3/log.h"
-#include "ns3/abort.h"
-#include "ns3/test.h"
-#include "ns3/pcap-file.h"
-#include "ns3/config.h"
-#include "ns3/string.h"
-#include "ns3/uinteger.h"
-#include "ns3/data-rate.h"
-#include "ns3/inet-socket-address.h"
-#include "ns3/internet-stack-helper.h"
-#include "ns3/ipv4-address-helper.h"
-#include "ns3/tcp-socket-factory.h"
-#include "ns3/yans-wifi-helper.h"
-#include "ns3/propagation-loss-model.h"
-#include "ns3/propagation-delay-model.h"
-#include "ns3/yans-wifi-channel.h"
-#include "ns3/yans-wifi-phy.h"
-#include "ns3/wifi-net-device.h"
-#include "ns3/mobility-helper.h"
-#include "ns3/constant-position-mobility-model.h"
-#include "ns3/nqos-wifi-mac-helper.h"
-#include "ns3/simulator.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("PropagationLossModelsTest");
-
-// ===========================================================================
-// This is a simple test to validate propagation loss models of ns-3 wifi.
-// See the chapter in the ns-3 testing and validation guide for more detail
-// ===========================================================================
-//
-class FriisPropagationLossModelTestCase : public TestCase
-{
-public:
- FriisPropagationLossModelTestCase ();
- virtual ~FriisPropagationLossModelTestCase ();
-
-private:
- virtual bool DoRun (void);
-
- typedef struct {
- Vector m_position;
- double m_pt; // dBm
- double m_pr; // W
- double m_tolerance;
- } TestVector;
-
- TestVectors<TestVector> m_testVectors;
-};
-
-FriisPropagationLossModelTestCase::FriisPropagationLossModelTestCase ()
- : TestCase ("Check to see that the ns-3 Friis propagation loss model provides correct received power"), m_testVectors ()
-{
-}
-
-FriisPropagationLossModelTestCase::~FriisPropagationLossModelTestCase ()
-{
-}
-
-bool
-FriisPropagationLossModelTestCase::DoRun (void)
-{
- // The ns-3 testing manual gives more background on the values selected
- // for this test. First, set a few defaults.
-
- // wavelength at 2.4 GHz is 0.125m
- Config::SetDefault ("ns3::FriisPropagationLossModel::Lambda", DoubleValue (0.125));
- Config::SetDefault ("ns3::FriisPropagationLossModel::SystemLoss", DoubleValue (1.0));
-
- // Select a reference transmit power
- // Pt = 10^(17.0206/10)/10^3 = .05035702 W
- double txPowerW = 0.05035702;
- double txPowerdBm = 10 * log10 (txPowerW) + 30;
-
- //
- // We want to test the propagation loss model calculations at a few chosen
- // distances and compare the results to those we have manually calculated
- // according to the model documentation. The model reference specifies,
- // for instance, that the received power at 100m according to the provided
- // input power will be 4.98265e-10 W. Since this value specifies the power
- // to 1e-15 significance, we test the ns-3 calculated value for agreement
- // within 5e-16.
- //
- TestVector testVector;
-
- testVector.m_position = Vector (100, 0, 0);
- testVector.m_pt = txPowerdBm;
- testVector.m_pr = 4.98265e-10;
- testVector.m_tolerance = 5e-16;
- m_testVectors.Add (testVector);
-
- testVector.m_position = Vector (500, 0, 0);
- testVector.m_pt = txPowerdBm;
- testVector.m_pr = 1.99306e-11;
- testVector.m_tolerance = 5e-17;
- m_testVectors.Add (testVector);
-
- testVector.m_position = Vector (1000, 0, 0);
- testVector.m_pt = txPowerdBm;
- testVector.m_pr = 4.98265e-12;
- testVector.m_tolerance = 5e-18;
- m_testVectors.Add (testVector);
-
- testVector.m_position = Vector (2000, 0, 0);
- testVector.m_pt = txPowerdBm;
- testVector.m_pr = 1.24566e-12;
- testVector.m_tolerance = 5e-18;
- m_testVectors.Add (testVector);
-
- // Now, check that the received power values are expected
-
- Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
- a->SetPosition (Vector (0,0,0));
- Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
-
- Ptr<FriisPropagationLossModel> lossModel = CreateObject<FriisPropagationLossModel> ();
- for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
- {
- testVector = m_testVectors.Get (i);
- b->SetPosition (testVector.m_position);
- double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
- double resultW = pow (10.0, resultdBm/10.0)/1000;
- NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance, "Got unexpected rcv power");
- }
-
- return GetErrorStatus ();
-}
-
-class LogDistancePropagationLossModelTestCase : public TestCase
-{
-public:
- LogDistancePropagationLossModelTestCase ();
- virtual ~LogDistancePropagationLossModelTestCase ();
-
-private:
- virtual bool DoRun (void);
-
- typedef struct {
- Vector m_position;
- double m_pt; // dBm
- double m_pr; // W
- double m_tolerance;
- } TestVector;
-
- TestVectors<TestVector> m_testVectors;
-};
-
-LogDistancePropagationLossModelTestCase::LogDistancePropagationLossModelTestCase ()
- : TestCase ("Check to see that the ns-3 Log Distance propagation loss model provides correct received power"), m_testVectors ()
-{
-}
-
-LogDistancePropagationLossModelTestCase::~LogDistancePropagationLossModelTestCase ()
-{
-}
-
-bool
-LogDistancePropagationLossModelTestCase::DoRun (void)
-{
- // reference loss at 2.4 GHz is 40.045997
- Config::SetDefault ("ns3::LogDistancePropagationLossModel::ReferenceLoss", DoubleValue (40.045997));
- Config::SetDefault ("ns3::LogDistancePropagationLossModel::Exponent", DoubleValue (3));
-
- // Select a reference transmit power
- // Pt = 10^(17.0206/10)/10^3 = .05035702 W
- double txPowerW = 0.05035702;
- double txPowerdBm = 10 * log10 (txPowerW) + 30;
-
- //
- // We want to test the propagation loss model calculations at a few chosen
- // distances and compare the results to those we have manually calculated
- // according to the model documentation. The following "TestVector" objects
- // will drive the test.
- //
- TestVector testVector;
-
- testVector.m_position = Vector (10, 0, 0);
- testVector.m_pt = txPowerdBm;
- testVector.m_pr = 4.98265e-9;
- testVector.m_tolerance = 5e-15;
- m_testVectors.Add (testVector);
-
- testVector.m_position = Vector (20, 0, 0);
- testVector.m_pt = txPowerdBm;
- testVector.m_pr = 6.22831e-10;
- testVector.m_tolerance = 5e-16;
- m_testVectors.Add (testVector);
-
- testVector.m_position = Vector (40, 0, 0);
- testVector.m_pt = txPowerdBm;
- testVector.m_pr = 7.78539e-11;
- testVector.m_tolerance = 5e-17;
- m_testVectors.Add (testVector);
-
- testVector.m_position = Vector (80, 0, 0);
- testVector.m_pt = txPowerdBm;
- testVector.m_pr = 9.73173e-12;
- testVector.m_tolerance = 5e-17;
- m_testVectors.Add (testVector);
-
- Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
- a->SetPosition (Vector (0,0,0));
- Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
-
- Ptr<LogDistancePropagationLossModel> lossModel = CreateObject<LogDistancePropagationLossModel> ();
- for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
- {
- testVector = m_testVectors.Get (i);
- b->SetPosition (testVector.m_position);
- double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
- double resultW = pow (10.0, resultdBm/10.0)/1000;
- NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance, "Got unexpected rcv power");
- }
-
- return GetErrorStatus ();
-}
-
-class PropagationLossModelsTestSuite : public TestSuite
-{
-public:
- PropagationLossModelsTestSuite ();
-};
-
-PropagationLossModelsTestSuite::PropagationLossModelsTestSuite ()
- : TestSuite ("propagation-loss-model", UNIT)
-{
- AddTestCase (new FriisPropagationLossModelTestCase);
- AddTestCase (new LogDistancePropagationLossModelTestCase);
-}
-
-PropagationLossModelsTestSuite WifiPropagationLossModelsTestSuite;
--- a/src/devices/wifi/propagation-loss-model.cc Mon Feb 01 15:24:40 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,546 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006,2007 INRIA
- *
- * 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>
- * Contributions: Timo Bingmann <timo.bingmann@student.kit.edu>
- */
-
-#include "propagation-loss-model.h"
-#include "ns3/log.h"
-#include "ns3/mobility-model.h"
-#include "ns3/boolean.h"
-#include "ns3/double.h"
-#include <math.h>
-
-NS_LOG_COMPONENT_DEFINE ("PropagationLossModel");
-
-namespace ns3 {
-
-// ------------------------------------------------------------------------- //
-
-NS_OBJECT_ENSURE_REGISTERED (PropagationLossModel);
-
-TypeId
-PropagationLossModel::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::PropagationLossModel")
- .SetParent<Object> ()
- ;
- return tid;
-}
-
-PropagationLossModel::PropagationLossModel ()
- : m_next (0)
-{}
-
-PropagationLossModel::~PropagationLossModel ()
-{}
-
-void
-PropagationLossModel::SetNext (Ptr<PropagationLossModel> next)
-{
- m_next = next;
-}
-
-double
-PropagationLossModel::CalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const
-{
- double self = DoCalcRxPower (txPowerDbm, a, b);
- if (m_next != 0)
- {
- self = m_next->CalcRxPower (self, a, b);
- }
- return self;
-}
-
-// ------------------------------------------------------------------------- //
-
-NS_OBJECT_ENSURE_REGISTERED (RandomPropagationLossModel);
-
-TypeId
-RandomPropagationLossModel::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::RandomPropagationLossModel")
- .SetParent<PropagationLossModel> ()
- .AddConstructor<RandomPropagationLossModel> ()
- .AddAttribute ("Variable", "The random variable used to pick a loss everytime CalcRxPower is invoked.",
- RandomVariableValue (ConstantVariable (1.0)),
- MakeRandomVariableAccessor (&RandomPropagationLossModel::m_variable),
- MakeRandomVariableChecker ())
- ;
- return tid;
-}
-RandomPropagationLossModel::RandomPropagationLossModel ()
- : PropagationLossModel ()
-{}
-
-RandomPropagationLossModel::~RandomPropagationLossModel ()
-{}
-
-double
-RandomPropagationLossModel::DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const
-{
- double rxc = -m_variable.GetValue ();
- NS_LOG_DEBUG ("attenuation coefficent="<<rxc<<"Db");
- return txPowerDbm + rxc;
-}
-
-// ------------------------------------------------------------------------- //
-
-NS_OBJECT_ENSURE_REGISTERED (FriisPropagationLossModel);
-
-const double FriisPropagationLossModel::PI = 3.14159265358979323846;
-
-TypeId
-FriisPropagationLossModel::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::FriisPropagationLossModel")
- .SetParent<PropagationLossModel> ()
- .AddConstructor<FriisPropagationLossModel> ()
- .AddAttribute ("Lambda",
- "The wavelength (default is 5.15 GHz at 300 000 km/s).",
- DoubleValue (300000000.0 / 5.150e9),
- MakeDoubleAccessor (&FriisPropagationLossModel::m_lambda),
- MakeDoubleChecker<double> ())
- .AddAttribute ("SystemLoss", "The system loss",
- DoubleValue (1.0),
- MakeDoubleAccessor (&FriisPropagationLossModel::m_systemLoss),
- MakeDoubleChecker<double> ())
- .AddAttribute ("MinDistance",
- "The distance under which the propagation model refuses to give results (m)",
- DoubleValue (0.5),
- MakeDoubleAccessor (&FriisPropagationLossModel::SetMinDistance,
- &FriisPropagationLossModel::GetMinDistance),
- MakeDoubleChecker<double> ())
- ;
- return tid;
-}
-
-FriisPropagationLossModel::FriisPropagationLossModel ()
-{}
-void
-FriisPropagationLossModel::SetSystemLoss (double systemLoss)
-{
- m_systemLoss = systemLoss;
-}
-double
-FriisPropagationLossModel::GetSystemLoss (void) const
-{
- return m_systemLoss;
-}
-void
-FriisPropagationLossModel::SetMinDistance (double minDistance)
-{
- m_minDistance = minDistance;
-}
-double
-FriisPropagationLossModel::GetMinDistance (void) const
-{
- return m_minDistance;
-}
-void
-FriisPropagationLossModel::SetLambda (double frequency, double speed)
-{
- m_lambda = speed / frequency;
-}
-void
-FriisPropagationLossModel::SetLambda (double lambda)
-{
- m_lambda = lambda;
-}
-double
-FriisPropagationLossModel::GetLambda (void) const
-{
- return m_lambda;
-}
-
-double
-FriisPropagationLossModel::DbmToW (double dbm) const
-{
- double mw = pow(10.0,dbm/10.0);
- return mw / 1000.0;
-}
-
-double
-FriisPropagationLossModel::DbmFromW (double w) const
-{
- double dbm = log10 (w * 1000.0) * 10.0;
- return dbm;
-}
-
-double
-FriisPropagationLossModel::DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const
-{
- /*
- * Friis free space equation:
- * where Pt, Gr, Gr and P are in Watt units
- * L is in meter units.
- *
- * P Gt * Gr * (lambda^2)
- * --- = ---------------------
- * Pt (4 * pi * d)^2 * L
- *
- * Gt: tx gain (unit-less)
- * Gr: rx gain (unit-less)
- * Pt: tx power (W)
- * d: distance (m)
- * L: system loss
- * lambda: wavelength (m)
- *
- * Here, we ignore tx and rx gain and the input and output values
- * are in dB or dBm:
- *
- * lambda^2
- * rx = tx + 10 log10 (-------------------)
- * (4 * pi * d)^2 * L
- *
- * rx: rx power (dB)
- * tx: tx power (dB)
- * d: distance (m)
- * L: system loss (unit-less)
- * lambda: wavelength (m)
- */
- double distance = a->GetDistanceFrom (b);
- if (distance <= m_minDistance)
- {
- return txPowerDbm;
- }
- double numerator = m_lambda * m_lambda;
- double denominator = 16 * PI * PI * distance * distance * m_systemLoss;
- double pr = 10 * log10 (numerator / denominator);
- NS_LOG_DEBUG ("distance="<<distance<<"m, attenuation coefficient="<<pr<<"dB");
- return txPowerDbm + pr;
-}
-
-// ------------------------------------------------------------------------- //
-
-NS_OBJECT_ENSURE_REGISTERED (LogDistancePropagationLossModel);
-
-TypeId
-LogDistancePropagationLossModel::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::LogDistancePropagationLossModel")
- .SetParent<PropagationLossModel> ()
- .AddConstructor<LogDistancePropagationLossModel> ()
- .AddAttribute ("Exponent",
- "The exponent of the Path Loss propagation model",
- DoubleValue (3.0),
- MakeDoubleAccessor (&LogDistancePropagationLossModel::m_exponent),
- MakeDoubleChecker<double> ())
- .AddAttribute ("ReferenceDistance",
- "The distance at which the reference loss is calculated (m)",
- DoubleValue (1.0),
- MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceDistance),
- MakeDoubleChecker<double> ())
- .AddAttribute ("ReferenceLoss",
- "The reference loss at reference distance (dB). (Default is Friis at 1m with 5.15 GHz)",
- DoubleValue (46.6777),
- MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceLoss),
- MakeDoubleChecker<double> ())
- ;
- return tid;
-
-}
-
-LogDistancePropagationLossModel::LogDistancePropagationLossModel ()
-{}
-
-void
-LogDistancePropagationLossModel::SetPathLossExponent (double n)
-{
- m_exponent = n;
-}
-void
-LogDistancePropagationLossModel::SetReference (double referenceDistance, double referenceLoss)
-{
- m_referenceDistance = referenceDistance;
- m_referenceLoss = referenceLoss;
-}
-double
-LogDistancePropagationLossModel::GetPathLossExponent (void) const
-{
- return m_exponent;
-}
-
-double
-LogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const
-{
- double distance = a->GetDistanceFrom (b);
- if (distance <= m_referenceDistance)
- {
- return txPowerDbm;
- }
- /**
- * The formula is:
- * rx = 10 * log (Pr0(tx)) - n * 10 * log (d/d0)
- *
- * Pr0: rx power at reference distance d0 (W)
- * d0: reference distance: 1.0 (m)
- * d: distance (m)
- * tx: tx power (dB)
- * rx: dB
- *
- * Which, in our case is:
- *
- * rx = rx0(tx) - 10 * n * log (d/d0)
- */
- double pathLossDb = 10 * m_exponent * log10 (distance / m_referenceDistance);
- double rxc = -m_referenceLoss - pathLossDb;
- NS_LOG_DEBUG ("distance="<<distance<<"m, reference-attenuation="<<-m_referenceLoss<<"dB, "<<
- "attenuation coefficient="<<rxc<<"db");
- return txPowerDbm + rxc;
-}
-
-// ------------------------------------------------------------------------- //
-
-NS_OBJECT_ENSURE_REGISTERED (ThreeLogDistancePropagationLossModel);
-
-TypeId
-ThreeLogDistancePropagationLossModel::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::ThreeLogDistancePropagationLossModel")
- .SetParent<PropagationLossModel> ()
- .AddConstructor<ThreeLogDistancePropagationLossModel> ()
- .AddAttribute ("Distance0",
- "Beginning of the first (near) distance field",
- DoubleValue (1.0),
- MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance0),
- MakeDoubleChecker<double> ())
- .AddAttribute ("Distance1",
- "Beginning of the second (middle) distance field.",
- DoubleValue (200.0),
- MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance1),
- MakeDoubleChecker<double> ())
- .AddAttribute ("Distance2",
- "Beginning of the third (far) distance field.",
- DoubleValue (500.0),
- MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance2),
- MakeDoubleChecker<double> ())
- .AddAttribute ("Exponent0",
- "The exponent for the first field.",
- DoubleValue (1.9),
- MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent0),
- MakeDoubleChecker<double> ())
- .AddAttribute ("Exponent1",
- "The exponent for the second field.",
- DoubleValue (3.8),
- MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent1),
- MakeDoubleChecker<double> ())
- .AddAttribute ("Exponent2",
- "The exponent for the third field.",
- DoubleValue (3.8),
- MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent2),
- MakeDoubleChecker<double> ())
- .AddAttribute ("ReferenceLoss",
- "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)",
- DoubleValue (46.6777),
- MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_referenceLoss),
- MakeDoubleChecker<double> ())
- ;
- return tid;
-
-}
-
-ThreeLogDistancePropagationLossModel::ThreeLogDistancePropagationLossModel ()
-{
-}
-
-double
-ThreeLogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const
-{
- double distance = a->GetDistanceFrom (b);
- NS_ASSERT(distance >= 0);
-
- // See doxygen comments for the formula and explanation
-
- double pathLossDb;
-
- if (distance < m_distance0)
- {
- pathLossDb = 0;
- }
- else if (distance < m_distance1)
- {
- pathLossDb = m_referenceLoss
- + 10 * m_exponent0 * log10(distance / m_distance0);
- }
- else if (distance < m_distance2)
- {
- pathLossDb = m_referenceLoss
- + 10 * m_exponent0 * log10(m_distance1 / m_distance0)
- + 10 * m_exponent1 * log10(distance / m_distance1);
- }
- else
- {
- pathLossDb = m_referenceLoss
- + 10 * m_exponent0 * log10(m_distance1 / m_distance0)
- + 10 * m_exponent1 * log10(m_distance2 / m_distance1)
- + 10 * m_exponent2 * log10(distance / m_distance2);
- }
-
- NS_LOG_DEBUG ("ThreeLogDistance distance=" << distance << "m, " <<
- "attenuation=" << pathLossDb << "dB");
-
- return txPowerDbm - pathLossDb;
-}
-
-// ------------------------------------------------------------------------- //
-
-NS_OBJECT_ENSURE_REGISTERED (NakagamiPropagationLossModel);
-
-TypeId
-NakagamiPropagationLossModel::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::NakagamiPropagationLossModel")
- .SetParent<PropagationLossModel> ()
- .AddConstructor<NakagamiPropagationLossModel> ()
- .AddAttribute ("Distance1",
- "Beginning of the second distance field. Default is 80m.",
- DoubleValue (80.0),
- MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance1),
- MakeDoubleChecker<double> ())
- .AddAttribute ("Distance2",
- "Beginning of the third distance field. Default is 200m.",
- DoubleValue (200.0),
- MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance2),
- MakeDoubleChecker<double> ())
- .AddAttribute ("m0",
- "m0 for distances smaller than Distance1. Default is 1.5.",
- DoubleValue (1.5),
- MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m0),
- MakeDoubleChecker<double> ())
- .AddAttribute ("m1",
- "m1 for distances smaller than Distance2. Default is 0.75.",
- DoubleValue (0.75),
- MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m1),
- MakeDoubleChecker<double> ())
- .AddAttribute ("m2",
- "m2 for distances greater than Distance2. Default is 0.75.",
- DoubleValue (0.75),
- MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m2),
- MakeDoubleChecker<double> ())
- ;
- return tid;
-
-}
-
-NakagamiPropagationLossModel::NakagamiPropagationLossModel ()
-{}
-
-double
-NakagamiPropagationLossModel::DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const
-{
- // select m parameter
-
- double distance = a->GetDistanceFrom (b);
- NS_ASSERT(distance >= 0);
-
- double m;
- if (distance < m_distance1)
- {
- m = m_m0;
- }
- else if (distance < m_distance2)
- {
- m = m_m1;
- }
- else
- {
- m = m_m2;
- }
-
- // the current power unit is dBm, but Watt is put into the Nakagami /
- // Rayleigh distribution.
- double powerW = pow(10, (txPowerDbm - 30) / 10);
-
- double resultPowerW;
-
- // switch between Erlang- and Gamma distributions: this is only for
- // speed. (Gamma is equal to Erlang for any positive integer m.)
- unsigned int int_m = static_cast<unsigned int>(floor(m));
-
- if (int_m == m)
- {
- resultPowerW = m_erlangRandomVariable.GetValue(int_m, powerW / m);
- }
- else
- {
- resultPowerW = m_gammaRandomVariable.GetValue(m, powerW / m);
- }
-
- double resultPowerDbm = 10 * log10(resultPowerW) + 30;
-
- NS_LOG_DEBUG ("Nakagami distance=" << distance << "m, " <<
- "power=" << powerW <<"W, " <<
- "resultPower=" << resultPowerW << "W=" << resultPowerDbm << "dBm");
-
- return resultPowerDbm;
-}
-
-// ------------------------------------------------------------------------- //
-
-NS_OBJECT_ENSURE_REGISTERED (FixedRssLossModel);
-
-TypeId
-FixedRssLossModel::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::FixedRssLossModel")
- .SetParent<PropagationLossModel> ()
- .AddConstructor<FixedRssLossModel> ()
- .AddAttribute ("Rss", "The fixed receiver Rss.",
- DoubleValue (-150.0),
- MakeDoubleAccessor (&FixedRssLossModel::m_rss),
- MakeDoubleChecker<double> ())
- ;
- return tid;
-}
-FixedRssLossModel::FixedRssLossModel ()
- : PropagationLossModel ()
-{}
-
-FixedRssLossModel::~FixedRssLossModel ()
-{}
-
-void
-FixedRssLossModel::SetRss (double rss)
-{
- m_rss = rss;
-}
-
-double
-FixedRssLossModel::DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const
-{
- return m_rss;
-}
-
-// ------------------------------------------------------------------------- //
-
-} // namespace ns3
--- a/src/devices/wifi/propagation-loss-model.h Mon Feb 01 15:24:40 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,375 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006,2007 INRIA
- *
- * 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>
- * Contributions: Timo Bingmann <timo.bingmann@student.kit.edu>
- * Contributions: Gary Pei <guangyu.pei@boeing.com> for fixed RSS
- */
-
-#ifndef PROPAGATION_LOSS_MODEL_H
-#define PROPAGATION_LOSS_MODEL_H
-
-#include "ns3/object.h"
-#include "ns3/random-variable.h"
-
-namespace ns3 {
-
-class MobilityModel;
-
-/**
- * \brief Modelize the propagation loss through a transmission medium
- *
- * Calculate the receive power (dbm) from a transmit power (dbm)
- * and a mobility model for the source and destination positions.
- */
-class PropagationLossModel : public Object
-{
-public:
- static TypeId GetTypeId (void);
-
- PropagationLossModel ();
- virtual ~PropagationLossModel ();
-
- void SetNext (Ptr<PropagationLossModel> next);
-
- /**
- * \param txPowerDbm current transmission power (in dBm)
- * \param a the mobility model of the source
- * \param b the mobility model of the destination
- * \returns the reception power after adding/multiplying propagation loss (in dBm)
- */
- double CalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const;
-private:
- PropagationLossModel (const PropagationLossModel &o);
- PropagationLossModel &operator = (const PropagationLossModel &o);
- virtual double DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const = 0;
-
- Ptr<PropagationLossModel> m_next;
-};
-
-/**
- * \brief The propagation loss follows a random distribution.
- */
-class RandomPropagationLossModel : public PropagationLossModel
-{
-public:
- static TypeId GetTypeId (void);
-
- RandomPropagationLossModel ();
- virtual ~RandomPropagationLossModel ();
-
-private:
- RandomPropagationLossModel (const RandomPropagationLossModel &o);
- RandomPropagationLossModel & operator = (const RandomPropagationLossModel &o);
- virtual double DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const;
- RandomVariable m_variable;
-};
-
-/**
- * \brief a Friis propagation loss model
- *
- * The Friis propagation loss model was first described in
- * "A Note on a Simple Transmission Formula", by
- * "Harald T. Friis".
- *
- * The original equation was described as:
- * \f$ \frac{P_r}{P_t} = \frac{A_r A_t}{d^2\lambda^2} \f$
- * with the following equation for the case of an
- * isotropic antenna with no heat loss:
- * \f$ A_{isotr.} = \frac{\lambda^2}{4\pi} \f$
- *
- * The final equation becomes:
- * \f$ \frac{P_r}{P_t} = \frac{\lambda^2}{(4 \pi d)^2} \f$
- *
- * Modern extensions to this original equation are:
- * \f$ P_r = \frac{P_t G_t G_r \lambda^2}{(4 \pi d)^2 L}\f$
- *
- * With:
- * - \f$ P_r \f$ : reception power (W)
- * - \f$ P_t \f$ : transmission power (W)
- * - \f$ G_t \f$ : transmission gain (unit-less)
- * - \f$ G_r \f$ : reception gain (unit-less)
- * - \f$ \lambda \f$ : wavelength (m)
- * - \f$ d \f$ : distance (m)
- * - \f$ L \f$ : system loss (unit-less)
- *
- *
- * This model is invalid for small distance values.
- * The current implementation returns the txpower as the rxpower
- * for any distance smaller than MinDistance.
- */
-class FriisPropagationLossModel : public PropagationLossModel
-{
-public:
- static TypeId GetTypeId (void);
- FriisPropagationLossModel ();
- /**
- * \param frequency (Hz)
- * \param speed (m/s)
- *
- * Set the main wavelength used in the Friis model
- * calculation.
- */
- void SetLambda (double frequency, double speed);
- /**
- * \param lambda (m) the wavelength
- *
- * Set the main wavelength used in the Friis model
- * calculation.
- */
- void SetLambda (double lambda);
- /**
- * \param systemLoss (dimension-less)
- *
- * Set the system loss used by the Friis propagation model.
- */
- void SetSystemLoss (double systemLoss);
-
- /**
- * \param minDistance the minimum distance
- *
- * Below this distance, the txpower is returned
- * unmodified as the rxpower.
- */
- void SetMinDistance (double minDistance);
-
- /**
- * \returns the minimum distance.
- */
- double GetMinDistance (void) const;
-
- /**
- * \returns the current wavelength (m)
- */
- double GetLambda (void) const;
- /**
- * \returns the current system loss (dimention-less)
- */
- double GetSystemLoss (void) const;
-
-private:
- FriisPropagationLossModel (const FriisPropagationLossModel &o);
- FriisPropagationLossModel & operator = (const FriisPropagationLossModel &o);
- virtual double DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const;
- double DbmToW (double dbm) const;
- double DbmFromW (double w) const;
-
- static const double PI;
- double m_lambda;
- double m_systemLoss;
- double m_minDistance;
-};
-
-/**
- * \brief a log distance propagation model.
- *
- * This model calculates the reception power with a so-called
- * log-distance propagation model:
- * \f$ L = L_0 + 10 n log_{10}(\frac{d}{d_0})\f$
- *
- * where:
- * - \f$ n \f$ : the path loss distance exponent
- * - \f$ d_0 \f$ : reference distance (m)
- * - \f$ L_0 \f$ : path loss at reference distance (dB)
- * - \f$ d \f$ : distance (m)
- * - \f$ L \f$ : path loss (dB)
- *
- * When the path loss is requested at a distance smaller than
- * the reference distance, the tx power is returned.
- *
- */
-class LogDistancePropagationLossModel : public PropagationLossModel
-{
-public:
- static TypeId GetTypeId (void);
- LogDistancePropagationLossModel ();
-
- /**
- * \param n the path loss exponent.
- * Set the path loss exponent.
- */
- void SetPathLossExponent (double n);
- /**
- * \returns the current path loss exponent.
- */
- double GetPathLossExponent (void) const;
-
- void SetReference (double referenceDistance, double referenceLoss);
-
-private:
- LogDistancePropagationLossModel (const LogDistancePropagationLossModel &o);
- LogDistancePropagationLossModel & operator = (const LogDistancePropagationLossModel &o);
- virtual double DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const;
- static Ptr<PropagationLossModel> CreateDefaultReference (void);
-
- double m_exponent;
- double m_referenceDistance;
- double m_referenceLoss;
-};
-
-/**
- * \brief A log distance path loss propagation model with three distance
- * fields. This model is the same as ns3::LogDistancePropagationLossModel
- * except that it has three distance fields: near, middle and far with
- * different exponents.
- *
- * Within each field the reception power is calculated using the log-distance
- * propagation equation:
- * \f[ L = L_0 + 10 \cdot n_0 log_{10}(\frac{d}{d_0})\f]
- * Each field begins where the previous ends and all together form a continuous function.
- *
- * There are three valid distance fields: near, middle, far. Actually four: the
- * first from 0 to the reference distance is invalid and returns txPowerDbm.
- *
- * \f[ \underbrace{0 \cdots\cdots}_{=0} \underbrace{d_0 \cdots\cdots}_{n_0} \underbrace{d_1 \cdots\cdots}_{n_1} \underbrace{d_2 \cdots\cdots}_{n_2} \infty \f]
- *
- * Complete formula for the path loss in dB:
- *
- * \f[\displaystyle L =
-\begin{cases}
-0 & d < d_0 \\
-L_0 + 10 \cdot n_0 \log_{10}(\frac{d}{d_0}) & d_0 \leq d < d_1 \\
-L_0 + 10 \cdot n_0 \log_{10}(\frac{d_1}{d_0}) + 10 \cdot n_1 \log_{10}(\frac{d}{d_1}) & d_1 \leq d < d_2 \\
-L_0 + 10 \cdot n_0 \log_{10}(\frac{d_1}{d_0}) + 10 \cdot n_1 \log_{10}(\frac{d_2}{d_1}) + 10 \cdot n_2 \log_{10}(\frac{d}{d_2})& d_2 \leq d
-\end{cases}\f]
- *
- * where:
- * - \f$ L \f$ : resulting path loss (dB)
- * - \f$ d \f$ : distance (m)
- * - \f$ d_0, d_1, d_2 \f$ : three distance fields (m)
- * - \f$ n_0, n_1, n_2 \f$ : path loss distance exponent for each field (unitless)
- * - \f$ L_0 \f$ : path loss at reference distance (dB)
- *
- * When the path loss is requested at a distance smaller than the reference
- * distance \f$ d_0 \f$, the tx power (with no path loss) is returned. The
- * reference distance defaults to 1m and reference loss defaults to
- * ns3::FriisPropagationLossModel with 5.15 GHz and is thus \f$ L_0 \f$ = 46.67 dB.
- */
-
-class ThreeLogDistancePropagationLossModel : public PropagationLossModel
-{
-public:
- static TypeId GetTypeId (void);
- ThreeLogDistancePropagationLossModel ();
-
- // Parameters are all accessible via attributes.
-
-private:
- ThreeLogDistancePropagationLossModel (const ThreeLogDistancePropagationLossModel& o);
- ThreeLogDistancePropagationLossModel& operator= (const ThreeLogDistancePropagationLossModel& o);
-
- virtual double DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const;
-
- double m_distance0;
- double m_distance1;
- double m_distance2;
-
- double m_exponent0;
- double m_exponent1;
- double m_exponent2;
-
- double m_referenceLoss;
-};
-
-/**
- * \brief Nakagami-m fast fading propagation loss model.
- *
- * The Nakagami-m distribution is applied to the power level. The probability
- * density function is defined as
- * \f[ p(x; m, \omega) = \frac{2 m^m}{\Gamma(m) \omega^m} x^{2m - 1} e^{-\frac{m}{\omega} x^2} = 2 x \cdot p_{\text{Gamma}}(x^2, m, \frac{m}{\omega}) \f]
- * with \f$ m \f$ the fading depth parameter and \f$ \omega \f$ the average received power.
- *
- * It is implemented by either a ns3::GammaVariable or a ns3::ErlangVariable
- * random variable.
- *
- * Like in ns3::ThreeLogDistancePropagationLossModel, the m parameter is varied
- * over three distance fields:
- * \f[ \underbrace{0 \cdots\cdots}_{m_0} \underbrace{d_1 \cdots\cdots}_{m_1} \underbrace{d_2 \cdots\cdots}_{m_2} \infty \f]
- *
- * For m = 1 the Nakagami-m distribution equals the Rayleigh distribution. Thus
- * this model also implements Rayleigh distribution based fast fading.
- */
-
-class NakagamiPropagationLossModel : public PropagationLossModel
-{
-public:
- static TypeId GetTypeId (void);
-
- NakagamiPropagationLossModel ();
-
- // Parameters are all accessible via attributes.
-
-private:
- NakagamiPropagationLossModel (const NakagamiPropagationLossModel& o);
- NakagamiPropagationLossModel& operator= (const NakagamiPropagationLossModel& o);
-
- virtual double DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const;
-
- double m_distance1;
- double m_distance2;
-
- double m_m0;
- double m_m1;
- double m_m2;
-
- ErlangVariable m_erlangRandomVariable;
- GammaVariable m_gammaRandomVariable;
-};
-
-/**
- * \brief The propagation loss is fixed. The user can set received power level.
- */
-class FixedRssLossModel : public PropagationLossModel
-{
-public:
- static TypeId GetTypeId (void);
-
- FixedRssLossModel ();
- virtual ~FixedRssLossModel ();
- /**
- * \param rss (dBm) the received signal strength
- *
- * Set the RSS.
- */
- void SetRss (double rss);
-
-private:
- FixedRssLossModel (const FixedRssLossModel &o);
- FixedRssLossModel & operator = (const FixedRssLossModel &o);
- virtual double DoCalcRxPower (double txPowerDbm,
- Ptr<MobilityModel> a,
- Ptr<MobilityModel> b) const;
- double m_rss;
-};
-
-} // namespace ns3
-
-#endif /* PROPAGATION_LOSS_MODEL_H */
--- a/src/devices/wifi/wifi-channel.cc Mon Feb 01 15:24:40 2010 +0000
+++ b/src/devices/wifi/wifi-channel.cc Tue Feb 02 11:44:02 2010 +0100
@@ -28,8 +28,8 @@
#include "wifi-channel.h"
#include "wifi-net-device.h"
#include "yans-wifi-phy.h"
-#include "propagation-loss-model.h"
-#include "propagation-delay-model.h"
+#include "ns3/propagation-loss-model.h"
+#include "ns3/propagation-delay-model.h"
NS_LOG_COMPONENT_DEFINE ("WifiChannel");
--- a/src/devices/wifi/wifi-phy-test.cc Mon Feb 01 15:24:40 2010 +0000
+++ b/src/devices/wifi/wifi-phy-test.cc Tue Feb 02 11:44:02 2010 +0100
@@ -20,8 +20,8 @@
#include "wifi-net-device.h"
#include "yans-wifi-channel.h"
#include "yans-wifi-phy.h"
-#include "propagation-loss-model.h"
-#include "propagation-delay-model.h"
+#include "ns3/propagation-loss-model.h"
+#include "ns3/propagation-delay-model.h"
#include "error-rate-model.h"
#include "yans-error-rate-model.h"
#include "ns3/ptr.h"
--- a/src/devices/wifi/wifi-test.cc Mon Feb 01 15:24:40 2010 +0000
+++ b/src/devices/wifi/wifi-test.cc Tue Feb 02 11:44:02 2010 +0100
@@ -23,8 +23,8 @@
#include "adhoc-wifi-mac.h"
#include "yans-wifi-phy.h"
#include "arf-wifi-manager.h"
-#include "propagation-delay-model.h"
-#include "propagation-loss-model.h"
+#include "ns3/propagation-delay-model.h"
+#include "ns3/propagation-loss-model.h"
#include "error-rate-model.h"
#include "yans-error-rate-model.h"
#include "ns3/constant-position-mobility-model.h"
--- a/src/devices/wifi/wscript Mon Feb 01 15:24:40 2010 +0000
+++ b/src/devices/wifi/wscript Tue Feb 02 11:44:02 2010 +0100
@@ -3,10 +3,6 @@
def build(bld):
obj = bld.create_ns3_module('wifi', ['node'])
obj.source = [
- 'propagation-delay-model.cc',
- 'propagation-loss-model.cc',
- 'propagation-loss-model-test-suite.cc',
- 'jakes-propagation-loss-model.cc',
'wifi-channel.cc',
'wifi-mode.cc',
'ssid.cc',
@@ -63,9 +59,6 @@
headers = bld.new_task_gen('ns3header')
headers.module = 'wifi'
headers.source = [
- 'propagation-delay-model.h',
- 'propagation-loss-model.h',
- 'jakes-propagation-loss-model.h',
'wifi-net-device.h',
'wifi-channel.h',
'wifi-mode.h',
--- a/src/devices/wifi/yans-wifi-channel.cc Mon Feb 01 15:24:40 2010 +0000
+++ b/src/devices/wifi/yans-wifi-channel.cc Tue Feb 02 11:44:02 2010 +0100
@@ -27,8 +27,8 @@
#include "ns3/object-factory.h"
#include "yans-wifi-channel.h"
#include "yans-wifi-phy.h"
-#include "propagation-loss-model.h"
-#include "propagation-delay-model.h"
+#include "ns3/propagation-loss-model.h"
+#include "ns3/propagation-delay-model.h"
NS_LOG_COMPONENT_DEFINE ("YansWifiChannel");