From e23f26a8f381c5145f96807b58cf7aa85ca7ca32 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Fri, 24 Aug 2007 15:12:12 +0200 Subject: [PATCH] start of work towards port of wifi code --- samples/wscript | 4 + src/devices/wifi/propagation-delay-model.cc | 45 ++++++++ src/devices/wifi/propagation-delay-model.h | 43 +++++++ src/devices/wifi/propagation-loss-model.cc | 121 ++++++++++++++++++++ src/devices/wifi/propagation-loss-model.h | 59 ++++++++++ src/wscript | 1 + 6 files changed, 273 insertions(+) create mode 100644 src/devices/wifi/propagation-delay-model.cc create mode 100644 src/devices/wifi/propagation-delay-model.h create mode 100644 src/devices/wifi/propagation-loss-model.cc create mode 100644 src/devices/wifi/propagation-loss-model.h diff --git a/samples/wscript b/samples/wscript index d8733131a..998ab464f 100644 --- a/samples/wscript +++ b/samples/wscript @@ -41,3 +41,7 @@ def build(bld): ['core', 'simulator', 'mobility']) obj.source = 'main-random-topology.cc' + obj = bld.create_ns3_program('main-adhoc-wifi', + ['core', 'simulator', 'mobility', 'wifi']) + obj.source = 'main-adhoc-wifi.cc' + diff --git a/src/devices/wifi/propagation-delay-model.cc b/src/devices/wifi/propagation-delay-model.cc new file mode 100644 index 000000000..7f03a5f65 --- /dev/null +++ b/src/devices/wifi/propagation-delay-model.cc @@ -0,0 +1,45 @@ +#include "propagation-delay-model.h" +#include "ns3/random-variable.h" + +namespace ns3 { + +PropagationDelayModel::~PropagationDelayModel () +{} + +RandomPropagationDelayModel::RandomPropagationDelayModel (const RandomVariable &variable) + : m_variable (variable.Copy ()) +{} +RandomPropagationDelayModel::~RandomPropagationDelayModel () +{ + delete m_variable; +} +Time +RandomPropagationDelayModel::GetDelay (double distance) const +{ + return Seconds (m_variable->GetValue ()); +} + +ConstantSpeedPropagationDelayModel::ConstantSpeedPropagationDelayModel () + : m_speed (300000000.0) +{} +ConstantSpeedPropagationDelayModel::ConstantSpeedPropagationDelayModel (double speed) + : m_speed (speed) +{} +Time +ConstantSpeedPropagationDelayModel::GetDelay (double distance) const +{ + 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 diff --git a/src/devices/wifi/propagation-delay-model.h b/src/devices/wifi/propagation-delay-model.h new file mode 100644 index 000000000..7b23b58b4 --- /dev/null +++ b/src/devices/wifi/propagation-delay-model.h @@ -0,0 +1,43 @@ +#ifndef PROPAGATION_DELAY_MODEL_H +#define PROPAGATION_DELAY_MODEL_H + +#include "ns3/ptr.h" +#include "ns3/object.h" +#include "ns3/nstime.h" + +namespace ns3 { + +class RandomVariable; + +class PropagationDelayModel : public Object +{ +public: + virtual ~PropagationDelayModel (); + virtual Time GetDelay (double distance) const = 0; +}; + +class RandomPropagationDelayModel : public PropagationDelayModel +{ +public: + RandomPropagationDelayModel (const RandomVariable &variable); + virtual ~RandomPropagationDelayModel (); + virtual Time GetDelay (double distance) const; +private: + RandomVariable *m_variable; +}; + +class ConstantSpeedPropagationDelayModel : public PropagationDelayModel +{ +public: + ConstantSpeedPropagationDelayModel (); + ConstantSpeedPropagationDelayModel (double speed); + virtual Time GetDelay (double distance) const; + void SetSpeed (double speed); + double GetSpeed (void) const; +private: + double m_speed; +}; + +} // namespace ns3 + +#endif /* PROPAGATION_DELAY_MODEL_H */ diff --git a/src/devices/wifi/propagation-loss-model.cc b/src/devices/wifi/propagation-loss-model.cc new file mode 100644 index 000000000..ea7ba30fe --- /dev/null +++ b/src/devices/wifi/propagation-loss-model.cc @@ -0,0 +1,121 @@ +#include "propagation-loss-model.h" +#include + +namespace ns3 { + +const double FriisPropagationLossModel::PI = 3.1415; + +PropagationLossModel::~PropagationLossModel () +{} + +FriisPropagationLossModel::FriisPropagationLossModel () + : m_lambda (), + m_systemLoss (1.0) +{} +void +FriisPropagationLossModel::SetSystemLoss (double systemLoss) +{ + m_systemLoss = systemLoss; +} +double +FriisPropagationLossModel::GetSystemLoss (void) const +{ + return m_systemLoss; +} +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::GetRxPower (double txPowerDbm, + double distance) const +{ + /* + * Friis free space equation: + * where Pt, Gr, Gr and P are in Watt units + * L is in meter units. + * + * Pt * Gt * Gr * (lambda^2) + * P = -------------------------- + * (4 * pi * d)^2 * L + * + * Gt: tx gain (W) + * Gr: rx gain (W) + * Pt: tx power (W) + * d: distance (m) + * L: system loss + * lambda: wavelength (m) + * + * Here, we ignore tx and rx gain. + */ + double numerator = DbmToW (txPowerDbm) * m_lambda * m_lambda; + double denominator = 16 * PI * PI * distance * distance * m_systemLoss; + double pr = numerator / denominator; + return DbmFromW (pr); +} + + +PathLossPropagationLossModel::PathLossPropagationLossModel () +{} + +void +PathLossPropagationLossModel::SetPathLossExponent (double n) +{ + m_exponent = n; +} +double +PathLossPropagationLossModel::GetPathLossExponent (void) const +{ + return m_exponent; +} + +double +PathLossPropagationLossModel::DbToW (double db) const +{ + return pow(10.0,db/10.0); +} + + +double +PathLossPropagationLossModel::GetRxPower (double txPowerDbm, + double distance) const +{ + if (distance <= 1.0) + { + return txPowerDbm; + } + double prd0 = m_reference->GetRxPower (txPowerDbm, 1.0); + double pr = 10*log10(prd0) - m_exponent * 10.0 * log10(distance); + return DbToW (pr); + +} + + +} // namespace ns3 diff --git a/src/devices/wifi/propagation-loss-model.h b/src/devices/wifi/propagation-loss-model.h new file mode 100644 index 000000000..65e1a568f --- /dev/null +++ b/src/devices/wifi/propagation-loss-model.h @@ -0,0 +1,59 @@ +#ifndef PROPAGATION_LOSS_MODEL_H +#define PROPAGATION_LOSS_MODEL_H + +#include "ns3/object.h" + +namespace ns3 { + +class PropagationLossModel : public Object +{ +public: + virtual ~PropagationLossModel (); + virtual double GetRxPower (double txPowerDbm, + double distance) const = 0; +}; + +class FriisPropagationLossModel : public PropagationLossModel +{ +public: + FriisPropagationLossModel (); + void SetLambda (double frequency, double speed); + void SetLambda (double lambda); + void SetSystemLoss (double systemLoss); + double GetLambda (void) const; + double GetSystemLoss (void) const; + + virtual double GetRxPower (double txPowerDbm, + double distance) const; +private: + double DbmToW (double dbm) const; + double DbmFromW (double w) const; + + static const double PI; + double m_lambda; + double m_systemLoss; +}; + +class PathLossPropagationLossModel : public PropagationLossModel +{ +public: + PathLossPropagationLossModel (); + + void SetPathLossExponent (double n); + double GetPathLossExponent (void) const; + + void SetReferenceModel (Ptr model); + + virtual double GetRxPower (double txPowerDbm, + double distance) const; +private: + double DbToW (double db) const; + + double m_lambda; + double m_exponent; + Ptr m_reference; +}; + +} // namespace ns3 + +#endif /* PROPAGATION_LOSS_MODEL_H */ diff --git a/src/wscript b/src/wscript index 1e20fb75c..7e7642c6e 100644 --- a/src/wscript +++ b/src/wscript @@ -21,6 +21,7 @@ all_modules = ( 'applications', 'routing/global-routing', 'mobility', + 'devices/wifi', ) def set_options(opt):