From 8246114a8d746ff64f400796be63f66389663cd7 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 28 Oct 2008 13:17:17 +0100 Subject: [PATCH] add composite capability to PropagationLossModel base class. --- bindings/python/ns3_module_wifi.py | 74 +++++++----------- .../wifi/composite-propagation-loss-model.cc | 78 ------------------- .../wifi/composite-propagation-loss-model.h | 63 --------------- .../wifi/jakes-propagation-loss-model.cc | 5 +- .../wifi/jakes-propagation-loss-model.h | 20 ++--- src/devices/wifi/propagation-loss-model.cc | 22 +++++- src/devices/wifi/propagation-loss-model.h | 27 +++++-- src/devices/wifi/wscript | 2 - 8 files changed, 77 insertions(+), 214 deletions(-) delete mode 100644 src/devices/wifi/composite-propagation-loss-model.cc delete mode 100644 src/devices/wifi/composite-propagation-loss-model.h diff --git a/bindings/python/ns3_module_wifi.py b/bindings/python/ns3_module_wifi.py index b5350b533..29dc22b03 100644 --- a/bindings/python/ns3_module_wifi.py +++ b/bindings/python/ns3_module_wifi.py @@ -73,8 +73,6 @@ def register_types(module): module.add_class('AmrrWifiManager', parent=root_module['ns3::WifiRemoteStationManager']) ## arf-wifi-manager.h: ns3::ArfWifiManager [class] module.add_class('ArfWifiManager', parent=root_module['ns3::WifiRemoteStationManager']) - ## composite-propagation-loss-model.h: ns3::CompositePropagationLossModel [class] - module.add_class('CompositePropagationLossModel', parent=root_module['ns3::PropagationLossModel']) ## constant-rate-wifi-manager.h: ns3::ConstantRateWifiManager [class] module.add_class('ConstantRateWifiManager', parent=root_module['ns3::WifiRemoteStationManager']) ## propagation-delay-model.h: ns3::ConstantSpeedPropagationDelayModel [class] @@ -176,7 +174,6 @@ def register_methods(root_module): register_Ns3AdhocWifiMac_methods(root_module, root_module['ns3::AdhocWifiMac']) register_Ns3AmrrWifiManager_methods(root_module, root_module['ns3::AmrrWifiManager']) register_Ns3ArfWifiManager_methods(root_module, root_module['ns3::ArfWifiManager']) - register_Ns3CompositePropagationLossModel_methods(root_module, root_module['ns3::CompositePropagationLossModel']) register_Ns3ConstantRateWifiManager_methods(root_module, root_module['ns3::ConstantRateWifiManager']) register_Ns3ConstantSpeedPropagationDelayModel_methods(root_module, root_module['ns3::ConstantSpeedPropagationDelayModel']) register_Ns3FriisPropagationLossModel_methods(root_module, root_module['ns3::FriisPropagationLossModel']) @@ -1004,20 +1001,27 @@ def register_Ns3PropagationDelayModel_methods(root_module, cls): return def register_Ns3PropagationLossModel_methods(root_module, cls): - ## propagation-loss-model.h: ns3::PropagationLossModel::PropagationLossModel(ns3::PropagationLossModel const & arg0) [copy constructor] - cls.add_constructor([param('ns3::PropagationLossModel const &', 'arg0')]) - ## propagation-loss-model.h: ns3::PropagationLossModel::PropagationLossModel() [constructor] - cls.add_constructor([]) ## propagation-loss-model.h: static ns3::TypeId ns3::PropagationLossModel::GetTypeId() [member function] cls.add_method('GetTypeId', 'ns3::TypeId', [], is_static=True) + ## propagation-loss-model.h: ns3::PropagationLossModel::PropagationLossModel() [constructor] + cls.add_constructor([]) + ## propagation-loss-model.h: void ns3::PropagationLossModel::SetNext(ns3::Ptr next) [member function] + cls.add_method('SetNext', + 'void', + [param('ns3::Ptr< ns3::PropagationLossModel >', 'next')]) ## propagation-loss-model.h: double ns3::PropagationLossModel::GetLoss(ns3::Ptr a, ns3::Ptr b) const [member function] cls.add_method('GetLoss', 'double', [param('ns3::Ptr< ns3::MobilityModel >', 'a'), param('ns3::Ptr< ns3::MobilityModel >', 'b')], - is_pure_virtual=True, is_const=True, is_virtual=True) + is_const=True) + ## propagation-loss-model.h: double ns3::PropagationLossModel::DoGetLoss(ns3::Ptr a, ns3::Ptr b) const [member function] + cls.add_method('DoGetLoss', + 'double', + [param('ns3::Ptr< ns3::MobilityModel >', 'a'), param('ns3::Ptr< ns3::MobilityModel >', 'b')], + is_pure_virtual=True, is_const=True, visibility='private', is_virtual=True) return def register_Ns3RandomPropagationDelayModel_methods(root_module, cls): @@ -1047,11 +1051,11 @@ def register_Ns3RandomPropagationLossModel_methods(root_module, cls): is_static=True) ## propagation-loss-model.h: ns3::RandomPropagationLossModel::RandomPropagationLossModel() [constructor] cls.add_constructor([]) - ## propagation-loss-model.h: double ns3::RandomPropagationLossModel::GetLoss(ns3::Ptr a, ns3::Ptr b) const [member function] - cls.add_method('GetLoss', + ## propagation-loss-model.h: double ns3::RandomPropagationLossModel::DoGetLoss(ns3::Ptr a, ns3::Ptr b) const [member function] + cls.add_method('DoGetLoss', 'double', [param('ns3::Ptr< ns3::MobilityModel >', 'a'), param('ns3::Ptr< ns3::MobilityModel >', 'b')], - is_const=True, is_virtual=True) + is_const=True, visibility='private', is_virtual=True) return def register_Ns3RraaWifiRemoteStation_methods(root_module, cls): @@ -1973,32 +1977,6 @@ def register_Ns3ArfWifiManager_methods(root_module, cls): visibility='private', is_virtual=True) return -def register_Ns3CompositePropagationLossModel_methods(root_module, cls): - ## composite-propagation-loss-model.h: ns3::CompositePropagationLossModel::CompositePropagationLossModel(ns3::CompositePropagationLossModel const & arg0) [copy constructor] - cls.add_constructor([param('ns3::CompositePropagationLossModel const &', 'arg0')]) - ## composite-propagation-loss-model.h: static ns3::TypeId ns3::CompositePropagationLossModel::GetTypeId() [member function] - cls.add_method('GetTypeId', - 'ns3::TypeId', - [], - is_static=True) - ## composite-propagation-loss-model.h: ns3::CompositePropagationLossModel::CompositePropagationLossModel() [constructor] - cls.add_constructor([]) - ## composite-propagation-loss-model.h: double ns3::CompositePropagationLossModel::GetLoss(ns3::Ptr a, ns3::Ptr b) const [member function] - cls.add_method('GetLoss', - 'double', - [param('ns3::Ptr< ns3::MobilityModel >', 'a'), param('ns3::Ptr< ns3::MobilityModel >', 'b')], - is_const=True, is_virtual=True) - ## composite-propagation-loss-model.h: void ns3::CompositePropagationLossModel::AddPropagationLossModel(ns3::Ptr pl) [member function] - cls.add_method('AddPropagationLossModel', - 'void', - [param('ns3::Ptr< ns3::PropagationLossModel >', 'pl')]) - ## composite-propagation-loss-model.h: void ns3::CompositePropagationLossModel::AddDefaults() [member function] - cls.add_method('AddDefaults', - 'void', - [], - visibility='protected', is_virtual=True) - return - def register_Ns3ConstantRateWifiManager_methods(root_module, cls): ## constant-rate-wifi-manager.h: ns3::ConstantRateWifiManager::ConstantRateWifiManager(ns3::ConstantRateWifiManager const & arg0) [copy constructor] cls.add_constructor([param('ns3::ConstantRateWifiManager const &', 'arg0')]) @@ -2093,11 +2071,11 @@ def register_Ns3FriisPropagationLossModel_methods(root_module, cls): 'double', [], is_const=True) - ## propagation-loss-model.h: double ns3::FriisPropagationLossModel::GetLoss(ns3::Ptr a, ns3::Ptr b) const [member function] - cls.add_method('GetLoss', + ## propagation-loss-model.h: double ns3::FriisPropagationLossModel::DoGetLoss(ns3::Ptr a, ns3::Ptr b) const [member function] + cls.add_method('DoGetLoss', 'double', [param('ns3::Ptr< ns3::MobilityModel >', 'a'), param('ns3::Ptr< ns3::MobilityModel >', 'b')], - is_const=True, is_virtual=True) + is_const=True, visibility='private', is_virtual=True) return def register_Ns3IdealWifiManager_methods(root_module, cls): @@ -2141,11 +2119,6 @@ def register_Ns3JakesPropagationLossModel_methods(root_module, cls): is_static=True) ## jakes-propagation-loss-model.h: ns3::JakesPropagationLossModel::JakesPropagationLossModel() [constructor] cls.add_constructor([]) - ## jakes-propagation-loss-model.h: double ns3::JakesPropagationLossModel::GetLoss(ns3::Ptr a, ns3::Ptr b) const [member function] - cls.add_method('GetLoss', - 'double', - [param('ns3::Ptr< ns3::MobilityModel >', 'a'), param('ns3::Ptr< ns3::MobilityModel >', 'b')], - is_const=True, is_virtual=True) ## jakes-propagation-loss-model.h: void ns3::JakesPropagationLossModel::SetNRays(uint8_t nRays) [member function] cls.add_method('SetNRays', 'void', @@ -2154,6 +2127,11 @@ def register_Ns3JakesPropagationLossModel_methods(root_module, cls): cls.add_method('SetNOscillators', 'void', [param('uint8_t', 'nOscillators')]) + ## jakes-propagation-loss-model.h: double ns3::JakesPropagationLossModel::DoGetLoss(ns3::Ptr a, ns3::Ptr b) const [member function] + cls.add_method('DoGetLoss', + 'double', + [param('ns3::Ptr< ns3::MobilityModel >', 'a'), param('ns3::Ptr< ns3::MobilityModel >', 'b')], + is_const=True, visibility='private', is_virtual=True) return def register_Ns3LogDistancePropagationLossModel_methods(root_module, cls): @@ -2183,11 +2161,11 @@ def register_Ns3LogDistancePropagationLossModel_methods(root_module, cls): cls.add_method('SetReferenceDistance', 'void', [param('double', 'referenceDistance')]) - ## propagation-loss-model.h: double ns3::LogDistancePropagationLossModel::GetLoss(ns3::Ptr a, ns3::Ptr b) const [member function] - cls.add_method('GetLoss', + ## propagation-loss-model.h: double ns3::LogDistancePropagationLossModel::DoGetLoss(ns3::Ptr a, ns3::Ptr b) const [member function] + cls.add_method('DoGetLoss', 'double', [param('ns3::Ptr< ns3::MobilityModel >', 'a'), param('ns3::Ptr< ns3::MobilityModel >', 'b')], - is_const=True, is_virtual=True) + is_const=True, visibility='private', is_virtual=True) return def register_Ns3NqapWifiMac_methods(root_module, cls): diff --git a/src/devices/wifi/composite-propagation-loss-model.cc b/src/devices/wifi/composite-propagation-loss-model.cc deleted file mode 100644 index 4820472a8..000000000 --- a/src/devices/wifi/composite-propagation-loss-model.cc +++ /dev/null @@ -1,78 +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 - */ - -#include "ns3/simulator.h" -#include "ns3/uinteger.h" -#include "ns3/double.h" -#include "ns3/random-variable.h" -#include "ns3/mobility-model.h" -#include "composite-propagation-loss-model.h" -#include - -namespace ns3 { - - - -NS_OBJECT_ENSURE_REGISTERED (CompositePropagationLossModel); - -TypeId -CompositePropagationLossModel::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::CompositePropagationLossModel") - .SetParent () - .AddConstructor () - ; - return tid; -} - -CompositePropagationLossModel::CompositePropagationLossModel () -{ - AddDefaults (); -} - -CompositePropagationLossModel::~CompositePropagationLossModel () -{} - -void -CompositePropagationLossModel::AddDefaults () -{} - -void -CompositePropagationLossModel::AddPropagationLossModel (Ptr pl) -{ - m_propagationModels.push_back (pl); -} - -double -CompositePropagationLossModel::GetLoss (Ptr a, - Ptr b) const -{ - double rxc = 0.0; - for(PropagationModelList::const_iterator i = m_propagationModels.begin (); - i != m_propagationModels.end (); - i++) { - rxc += (*i)->GetLoss (a, b); - } - - return rxc; -} - -} // namespace ns3 - diff --git a/src/devices/wifi/composite-propagation-loss-model.h b/src/devices/wifi/composite-propagation-loss-model.h deleted file mode 100644 index 497ea93e3..000000000 --- a/src/devices/wifi/composite-propagation-loss-model.h +++ /dev/null @@ -1,63 +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 - */ -#ifndef PROPAGATION_COMP_MODEL_H -#define PROPAGATION_COMP_MODEL_H - -#include "ns3/nstime.h" -#include "propagation-loss-model.h" - -namespace ns3 { - -/** - * \brief a Composite propagation loss model - * - * This model is use to compute the receivng power - * using more than one propagation loss model (e.g. distance loss - * and jakes). - * - * The received power is computed considering the cascade of the models - */ -class CompositePropagationLossModel : public PropagationLossModel { -public: - static TypeId GetTypeId (void); - CompositePropagationLossModel (); - virtual ~CompositePropagationLossModel (); - - virtual double GetLoss (Ptr a, - Ptr b) const; - /** - * \param pl the propagation loss model to add - * - * Insert a propagation loss model to the composite. - */ - void AddPropagationLossModel (Ptr pl); -protected: - virtual void AddDefaults (void); -private: - typedef std::vector > PropagationModelList; - PropagationModelList m_propagationModels; -}; - - -} // namespace ns3 - -#endif /* PROPAGATION_COMP_MODEL_H */ - - diff --git a/src/devices/wifi/jakes-propagation-loss-model.cc b/src/devices/wifi/jakes-propagation-loss-model.cc index 12d549fe2..78c84deb2 100644 --- a/src/devices/wifi/jakes-propagation-loss-model.cc +++ b/src/devices/wifi/jakes-propagation-loss-model.cc @@ -33,7 +33,8 @@ namespace ns3 { -class JakesPropagationLossModel::PathCoefficients { +class JakesPropagationLossModel::PathCoefficients +{ public: PathCoefficients (Ptr jakes, Ptr receiver, @@ -198,7 +199,7 @@ JakesPropagationLossModel::SetNOscillators (uint8_t nOscillators) } double -JakesPropagationLossModel::GetLoss (Ptr a, +JakesPropagationLossModel::DoGetLoss (Ptr a, Ptr b) const { PathsList::iterator i = m_paths.end (); diff --git a/src/devices/wifi/jakes-propagation-loss-model.h b/src/devices/wifi/jakes-propagation-loss-model.h index bf7c76b50..ee46d0620 100644 --- a/src/devices/wifi/jakes-propagation-loss-model.h +++ b/src/devices/wifi/jakes-propagation-loss-model.h @@ -83,8 +83,6 @@ public: JakesPropagationLossModel (); virtual ~JakesPropagationLossModel (); - virtual double GetLoss (Ptr a, - Ptr b) const; /** * \param nRays Number of rays per path * @@ -99,27 +97,29 @@ public: void SetNOscillators (uint8_t nOscillators); private: + void DoConstruct (void); + virtual double DoGetLoss (Ptr a, + Ptr b) const; + + class PathCoefficients; struct ComplexNumber { double real; double imag; }; friend class PathCoefficents; - - static const double PI; - ComplexNumber* m_amp; - RandomVariable m_variable; - double m_fd; - typedef std::vector DestinationList; struct PathsSet { Ptr sender; DestinationList receivers; }; typedef std::vector PathsList; - - void DoConstruct (void); + + 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; diff --git a/src/devices/wifi/propagation-loss-model.cc b/src/devices/wifi/propagation-loss-model.cc index b54e90a0b..7069d4970 100644 --- a/src/devices/wifi/propagation-loss-model.cc +++ b/src/devices/wifi/propagation-loss-model.cc @@ -43,10 +43,26 @@ PropagationLossModel::GetTypeId (void) return tid; } +PropagationLossModel::PropagationLossModel () + : m_next (0) +{} PropagationLossModel::~PropagationLossModel () {} +double +PropagationLossModel::GetLoss (Ptr a, + Ptr b) const +{ + double self = DoGetLoss (a, b); + if (m_next != 0) + { + self += m_next->GetLoss (a, b); + } + return self; +} + + NS_OBJECT_ENSURE_REGISTERED (RandomPropagationLossModel); TypeId @@ -69,7 +85,7 @@ RandomPropagationLossModel::~RandomPropagationLossModel () {} double -RandomPropagationLossModel::GetLoss (Ptr a, +RandomPropagationLossModel::DoGetLoss (Ptr a, Ptr b) const { double rxc = -m_variable.GetValue (); @@ -158,7 +174,7 @@ FriisPropagationLossModel::DbmFromW (double w) const double -FriisPropagationLossModel::GetLoss (Ptr a, +FriisPropagationLossModel::DoGetLoss (Ptr a, Ptr b) const { /* @@ -255,7 +271,7 @@ LogDistancePropagationLossModel::GetPathLossExponent (void) const } double -LogDistancePropagationLossModel::GetLoss (Ptr a, +LogDistancePropagationLossModel::DoGetLoss (Ptr a, Ptr b) const { double distance = a->GetDistanceFrom (b); diff --git a/src/devices/wifi/propagation-loss-model.h b/src/devices/wifi/propagation-loss-model.h index 4ae46aa22..67c9989a1 100644 --- a/src/devices/wifi/propagation-loss-model.h +++ b/src/devices/wifi/propagation-loss-model.h @@ -38,14 +38,25 @@ class PropagationLossModel : public Object public: static TypeId GetTypeId (void); + PropagationLossModel (); virtual ~PropagationLossModel (); + + void SetNext (Ptr next); + /** * \param a the mobility model of the source * \param b the mobility model of the destination * \returns the attenuation coefficient (dB) */ - virtual double GetLoss (Ptr a, - Ptr b) const = 0; + double GetLoss (Ptr a, + Ptr b) const; +private: + PropagationLossModel (const PropagationLossModel &o); + PropagationLossModel &operator = (const PropagationLossModel &o); + virtual double DoGetLoss (Ptr a, + Ptr b) const = 0; + + Ptr m_next; }; /** @@ -59,9 +70,9 @@ public: RandomPropagationLossModel (); virtual ~RandomPropagationLossModel (); - virtual double GetLoss (Ptr a, - Ptr b) const; private: + virtual double DoGetLoss (Ptr a, + Ptr b) const; RandomVariable m_variable; }; @@ -147,9 +158,9 @@ public: */ double GetSystemLoss (void) const; - virtual double GetLoss (Ptr a, - Ptr b) const; private: + virtual double DoGetLoss (Ptr a, + Ptr b) const; double DbmToW (double dbm) const; double DbmFromW (double w) const; @@ -200,9 +211,9 @@ public: void SetReferenceDistance (double referenceDistance); - virtual double GetLoss (Ptr a, - Ptr b) const; private: + virtual double DoGetLoss (Ptr a, + Ptr b) const; static Ptr CreateDefaultReference (void); double m_exponent; diff --git a/src/devices/wifi/wscript b/src/devices/wifi/wscript index 1c0a3e2d5..94cdd75b4 100644 --- a/src/devices/wifi/wscript +++ b/src/devices/wifi/wscript @@ -5,7 +5,6 @@ def build(bld): obj.source = [ 'propagation-delay-model.cc', 'propagation-loss-model.cc', - 'composite-propagation-loss-model.cc', 'jakes-propagation-loss-model.cc', 'wifi-channel.cc', 'wifi-mode.cc', @@ -50,7 +49,6 @@ def build(bld): headers.source = [ 'propagation-delay-model.h', 'propagation-loss-model.h', - 'composite-propagation-loss-model.h', 'jakes-propagation-loss-model.h', 'wifi-net-device.h', 'wifi-channel.h',