From 5ed4fe74c76d34a604b3a2ebda41a14fb0f2686e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Sat, 25 Feb 2023 14:06:56 +0100 Subject: [PATCH] spectrum: Split out WifiSpectrumValue5MhzFactory since it is not used by wifi --- src/spectrum/CMakeLists.txt | 2 + ...ideal-phy-matrix-propagation-loss-model.cc | 4 +- ...hoc-aloha-ideal-phy-with-microwave-oven.cc | 4 +- .../examples/adhoc-aloha-ideal-phy.cc | 4 +- .../model/ism-spectrum-value-helper.cc | 97 +++++++++++++++++++ .../model/ism-spectrum-value-helper.h | 76 +++++++++++++++ .../model/wifi-spectrum-value-helper.cc | 72 -------------- .../model/wifi-spectrum-value-helper.h | 46 +-------- src/spectrum/test/spectrum-ideal-phy-test.cc | 4 +- .../test/three-gpp-channel-test-suite.cc | 4 +- 10 files changed, 186 insertions(+), 127 deletions(-) create mode 100644 src/spectrum/model/ism-spectrum-value-helper.cc create mode 100644 src/spectrum/model/ism-spectrum-value-helper.h diff --git a/src/spectrum/CMakeLists.txt b/src/spectrum/CMakeLists.txt index 404f31a16..42970eb2a 100644 --- a/src/spectrum/CMakeLists.txt +++ b/src/spectrum/CMakeLists.txt @@ -10,6 +10,7 @@ set(source_files model/friis-spectrum-propagation-loss.cc model/half-duplex-ideal-phy-signal-parameters.cc model/half-duplex-ideal-phy.cc + model/ism-spectrum-value-helper.cc model/matrix-based-channel-model.cc model/microwave-oven-spectrum-value-helper.cc model/two-ray-spectrum-propagation-loss-model.cc @@ -50,6 +51,7 @@ set(header_files model/friis-spectrum-propagation-loss.h model/half-duplex-ideal-phy-signal-parameters.h model/half-duplex-ideal-phy.h + model/ism-spectrum-value-helper.h model/matrix-based-channel-model.h model/microwave-oven-spectrum-value-helper.h model/two-ray-spectrum-propagation-loss-model.h diff --git a/src/spectrum/examples/adhoc-aloha-ideal-phy-matrix-propagation-loss-model.cc b/src/spectrum/examples/adhoc-aloha-ideal-phy-matrix-propagation-loss-model.cc index d051fc6d9..22ac384a2 100644 --- a/src/spectrum/examples/adhoc-aloha-ideal-phy-matrix-propagation-loss-model.cc +++ b/src/spectrum/examples/adhoc-aloha-ideal-phy-matrix-propagation-loss-model.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -31,7 +32,6 @@ #include #include #include -#include #include #include @@ -163,7 +163,7 @@ main(int argc, char** argv) channelHelper.AddPropagationLoss(propLoss); Ptr channel = channelHelper.Create(); - WifiSpectrumValue5MhzFactory sf; + SpectrumValue5MhzFactory sf; uint32_t channelNumber = 1; Ptr txPsd = sf.CreateTxPowerSpectralDensity(txPowerW, channelNumber); diff --git a/src/spectrum/examples/adhoc-aloha-ideal-phy-with-microwave-oven.cc b/src/spectrum/examples/adhoc-aloha-ideal-phy-with-microwave-oven.cc index e61eb799d..6c67ca467 100644 --- a/src/spectrum/examples/adhoc-aloha-ideal-phy-with-microwave-oven.cc +++ b/src/spectrum/examples/adhoc-aloha-ideal-phy-with-microwave-oven.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -35,7 +36,6 @@ #include #include #include -#include #include #include @@ -196,7 +196,7 @@ main(int argc, char** argv) // Configure ofdm nodes //////////////////////// - WifiSpectrumValue5MhzFactory sf; + SpectrumValue5MhzFactory sf; double txPower = 0.1; // Watts uint32_t channelNumber = 4; diff --git a/src/spectrum/examples/adhoc-aloha-ideal-phy.cc b/src/spectrum/examples/adhoc-aloha-ideal-phy.cc index da7907578..a68706085 100644 --- a/src/spectrum/examples/adhoc-aloha-ideal-phy.cc +++ b/src/spectrum/examples/adhoc-aloha-ideal-phy.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -31,7 +32,6 @@ #include #include #include -#include #include #include @@ -176,7 +176,7 @@ main(int argc, char** argv) SpectrumChannelHelper channelHelper = SpectrumChannelHelper::Default(); Ptr channel = channelHelper.Create(); - WifiSpectrumValue5MhzFactory sf; + SpectrumValue5MhzFactory sf; double txPower = 0.1; // Watts uint32_t channelNumber = 1; diff --git a/src/spectrum/model/ism-spectrum-value-helper.cc b/src/spectrum/model/ism-spectrum-value-helper.cc new file mode 100644 index 000000000..4d60a8b55 --- /dev/null +++ b/src/spectrum/model/ism-spectrum-value-helper.cc @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2009 CTTC + * Copyright (c) 2010 TELEMATICS LAB, DEE - Politecnico di Bari + * Copyright (c) 2017 Orange Labs + * + * 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 + * + * Authors: Nicola Baldo + * Giuseppe Piro + */ + +#include "ism-spectrum-value-helper.h" + +#include "ns3/assert.h" +#include "ns3/log.h" + +namespace ns3 +{ + +NS_LOG_COMPONENT_DEFINE("IsmSpectrumValueHelper"); + +static Ptr g_WifiSpectrumModel5Mhz; ///< static initializer for the class + +/** + * Static class to initialize the values for the 2.4 GHz Wi-Fi spectrum model + */ +static class WifiSpectrumModel5MhzInitializer +{ + public: + WifiSpectrumModel5MhzInitializer() + { + Bands bands; + for (int i = -4; i < 13 + 7; i++) + { + BandInfo bi; + bi.fl = 2407.0e6 + i * 5.0e6; + bi.fh = 2407.0e6 + (i + 1) * 5.0e6; + bi.fc = (bi.fl + bi.fh) / 2; + bands.push_back(bi); + } + g_WifiSpectrumModel5Mhz = Create(bands); + } +} g_WifiSpectrumModel5MhzInitializerInstance; //!< initialization instance for WifiSpectrumModel5Mhz + +Ptr +SpectrumValue5MhzFactory::CreateConstant(double v) +{ + Ptr c = Create(g_WifiSpectrumModel5Mhz); + (*c) = v; + return c; +} + +Ptr +SpectrumValue5MhzFactory::CreateTxPowerSpectralDensity(double txPower, uint8_t channel) +{ + Ptr txPsd = Create(g_WifiSpectrumModel5Mhz); + + // since the spectrum model has a resolution of 5 MHz, we model + // the transmitted signal with a constant density over a 20MHz + // bandwidth centered on the center frequency of the channel. The + // transmission power outside the transmission power density is + // calculated considering the transmit spectrum mask, see IEEE + // Std. 802.11-2007, Annex I + + double txPowerDensity = txPower / 20e6; + + NS_ASSERT(channel >= 1); + NS_ASSERT(channel <= 13); + + (*txPsd)[channel - 1] = txPowerDensity * 1e-4; // -40dB + (*txPsd)[channel] = txPowerDensity * 1e-4; // -40dB + (*txPsd)[channel + 1] = txPowerDensity * 0.0015849; // -28dB + (*txPsd)[channel + 2] = txPowerDensity * 0.0015849; // -28dB + (*txPsd)[channel + 3] = txPowerDensity; + (*txPsd)[channel + 4] = txPowerDensity; + (*txPsd)[channel + 5] = txPowerDensity; + (*txPsd)[channel + 6] = txPowerDensity; + (*txPsd)[channel + 7] = txPowerDensity * 0.0015849; // -28dB + (*txPsd)[channel + 8] = txPowerDensity * 0.0015849; // -28dB + (*txPsd)[channel + 9] = txPowerDensity * 1e-4; // -40dB + (*txPsd)[channel + 10] = txPowerDensity * 1e-4; // -40dB + + return txPsd; +} + +} // namespace ns3 diff --git a/src/spectrum/model/ism-spectrum-value-helper.h b/src/spectrum/model/ism-spectrum-value-helper.h new file mode 100644 index 000000000..9937ea650 --- /dev/null +++ b/src/spectrum/model/ism-spectrum-value-helper.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2009 CTTC + * Copyright (c) 2017 Orange Labs + * + * 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 + * + * Authors: Nicola Baldo + * Giuseppe Piro + */ + +#ifndef ISM_SPECTRUM_VALUE_HELPER_H +#define ISM_SPECTRUM_VALUE_HELPER_H + +#include + +namespace ns3 +{ + +/** + * \ingroup spectrum + * + * Implements Wifi SpectrumValue for the 2.4 GHz ISM band only, with a + * 5 MHz spectrum resolution. + * + */ +class SpectrumValue5MhzFactory +{ + public: + /** + * Destructor + */ + virtual ~SpectrumValue5MhzFactory() = default; + /** + * Creates a SpectrumValue instance with a constant value for all frequencies + * + * @param psd the constant value + * + * @return a Ptr to a newly created SpectrumValue + */ + virtual Ptr CreateConstant(double psd); + /** + * Creates a SpectrumValue instance that represents the TX Power Spectral + * Density of a wifi device corresponding to the provided parameters + * + * Since the spectrum model has a resolution of 5 MHz, we model + * the transmitted signal with a constant density over a 20MHz + * bandwidth centered on the center frequency of the channel. The + * transmission power outside the transmission power density is + * calculated considering the transmit spectrum mask, see IEEE + * Std. 802.11-2007, Annex I. The two bands just outside of the main + * 20 MHz are allocated power at -28 dB down from the center 20 MHz, + * and the two bands outside of this are allocated power at -40 dB down + * (with a total bandwidth of 60 MHz containing non-zero power allocation). + * + * @param txPower the total TX power in W + * @param channel the number of the channel (1 <= channel <= 13) + * + * @return a Ptr to a newly created SpectrumValue + */ + virtual Ptr CreateTxPowerSpectralDensity(double txPower, uint8_t channel); +}; + +} // namespace ns3 + +#endif /* ISM_SPECTRUM_VALUE_HELPER_H */ diff --git a/src/spectrum/model/wifi-spectrum-value-helper.cc b/src/spectrum/model/wifi-spectrum-value-helper.cc index cef38923b..2174a651c 100644 --- a/src/spectrum/model/wifi-spectrum-value-helper.cc +++ b/src/spectrum/model/wifi-spectrum-value-helper.cc @@ -819,78 +819,6 @@ WifiSpectrumValueHelper::GetBandPowerW(Ptr psd, const WifiSpectru return powerWattPerHertz * (bandIt->fh - bandIt->fl); } -static Ptr g_WifiSpectrumModel5Mhz; ///< static initializer for the class - -WifiSpectrumValueHelper::~WifiSpectrumValueHelper() -{ -} - -WifiSpectrumValue5MhzFactory::~WifiSpectrumValue5MhzFactory() -{ -} - -/** - * Static class to initialize the values for the 2.4 GHz Wi-Fi spectrum model - */ -static class WifiSpectrumModel5MhzInitializer -{ - public: - WifiSpectrumModel5MhzInitializer() - { - Bands bands; - for (int i = -4; i < 13 + 7; i++) - { - BandInfo bi; - bi.fl = 2407.0e6 + i * 5.0e6; - bi.fh = 2407.0e6 + (i + 1) * 5.0e6; - bi.fc = (bi.fl + bi.fh) / 2; - bands.push_back(bi); - } - g_WifiSpectrumModel5Mhz = Create(bands); - } -} g_WifiSpectrumModel5MhzInitializerInstance; //!< initialization instance for WifiSpectrumModel5Mhz - -Ptr -WifiSpectrumValue5MhzFactory::CreateConstant(double v) -{ - Ptr c = Create(g_WifiSpectrumModel5Mhz); - (*c) = v; - return c; -} - -Ptr -WifiSpectrumValue5MhzFactory::CreateTxPowerSpectralDensity(double txPower, uint8_t channel) -{ - Ptr txPsd = Create(g_WifiSpectrumModel5Mhz); - - // since the spectrum model has a resolution of 5 MHz, we model - // the transmitted signal with a constant density over a 20MHz - // bandwidth centered on the center frequency of the channel. The - // transmission power outside the transmission power density is - // calculated considering the transmit spectrum mask, see IEEE - // Std. 802.11-2007, Annex I - - double txPowerDensity = txPower / 20e6; - - NS_ASSERT(channel >= 1); - NS_ASSERT(channel <= 13); - - (*txPsd)[channel - 1] = txPowerDensity * 1e-4; // -40dB - (*txPsd)[channel] = txPowerDensity * 1e-4; // -40dB - (*txPsd)[channel + 1] = txPowerDensity * 0.0015849; // -28dB - (*txPsd)[channel + 2] = txPowerDensity * 0.0015849; // -28dB - (*txPsd)[channel + 3] = txPowerDensity; - (*txPsd)[channel + 4] = txPowerDensity; - (*txPsd)[channel + 5] = txPowerDensity; - (*txPsd)[channel + 6] = txPowerDensity; - (*txPsd)[channel + 7] = txPowerDensity * 0.0015849; // -28dB - (*txPsd)[channel + 8] = txPowerDensity * 0.0015849; // -28dB - (*txPsd)[channel + 9] = txPowerDensity * 1e-4; // -40dB - (*txPsd)[channel + 10] = txPowerDensity * 1e-4; // -40dB - - return txPsd; -} - bool operator<(const FrequencyRange& left, const FrequencyRange& right) { diff --git a/src/spectrum/model/wifi-spectrum-value-helper.h b/src/spectrum/model/wifi-spectrum-value-helper.h index ad56981ca..b78de184f 100644 --- a/src/spectrum/model/wifi-spectrum-value-helper.h +++ b/src/spectrum/model/wifi-spectrum-value-helper.h @@ -45,7 +45,7 @@ class WifiSpectrumValueHelper /** * Destructor */ - virtual ~WifiSpectrumValueHelper(); + virtual ~WifiSpectrumValueHelper() = default; /** * Return a SpectrumModel instance corresponding to the center frequency @@ -323,50 +323,6 @@ class WifiSpectrumValueHelper static double GetBandPowerW(Ptr psd, const WifiSpectrumBand& band); }; -/** - * \ingroup spectrum - * - * Implements Wifi SpectrumValue for the 2.4 GHz ISM band only, with a - * 5 MHz spectrum resolution. - * - */ -class WifiSpectrumValue5MhzFactory -{ - public: - /** - * Destructor - */ - virtual ~WifiSpectrumValue5MhzFactory(); - /** - * Creates a SpectrumValue instance with a constant value for all frequencies - * - * @param psd the constant value - * - * @return a Ptr to a newly created SpectrumValue - */ - virtual Ptr CreateConstant(double psd); - /** - * Creates a SpectrumValue instance that represents the TX Power Spectral - * Density of a wifi device corresponding to the provided parameters - * - * Since the spectrum model has a resolution of 5 MHz, we model - * the transmitted signal with a constant density over a 20MHz - * bandwidth centered on the center frequency of the channel. The - * transmission power outside the transmission power density is - * calculated considering the transmit spectrum mask, see IEEE - * Std. 802.11-2007, Annex I. The two bands just outside of the main - * 20 MHz are allocated power at -28 dB down from the center 20 MHz, - * and the two bands outside of this are allocated power at -40 dB down - * (with a total bandwidth of 60 MHz containing non-zero power allocation). - * - * @param txPower the total TX power in W - * @param channel the number of the channel (1 <= channel <= 13) - * - * @return a Ptr to a newly created SpectrumValue - */ - virtual Ptr CreateTxPowerSpectralDensity(double txPower, uint8_t channel); -}; - /** * \ingroup spectrum * Struct defining a frequency range between minFrequency (MHz) and maxFrequency (MHz). diff --git a/src/spectrum/test/spectrum-ideal-phy-test.cc b/src/spectrum/test/spectrum-ideal-phy-test.cc index 588a38c56..4da692f61 100644 --- a/src/spectrum/test/spectrum-ideal-phy-test.cc +++ b/src/spectrum/test/spectrum-ideal-phy-test.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,6 @@ #include #include #include -#include #include #include @@ -170,7 +170,7 @@ SpectrumIdealPhyTestCase::DoRun() channelHelper.AddPropagationLoss(propLoss); Ptr channel = channelHelper.Create(); - WifiSpectrumValue5MhzFactory sf; + SpectrumValue5MhzFactory sf; uint32_t channelNumber = 1; Ptr txPsd = sf.CreateTxPowerSpectralDensity(txPowerW, channelNumber); diff --git a/src/spectrum/test/three-gpp-channel-test-suite.cc b/src/spectrum/test/three-gpp-channel-test-suite.cc index e49a4f8f6..3ad2a1570 100644 --- a/src/spectrum/test/three-gpp-channel-test-suite.cc +++ b/src/spectrum/test/three-gpp-channel-test-suite.cc @@ -21,6 +21,7 @@ #include "ns3/config.h" #include "ns3/constant-position-mobility-model.h" #include "ns3/double.h" +#include "ns3/ism-spectrum-value-helper.h" #include "ns3/isotropic-antenna-model.h" #include "ns3/log.h" #include "ns3/node-container.h" @@ -34,7 +35,6 @@ #include "ns3/three-gpp-spectrum-propagation-loss-model.h" #include "ns3/uinteger.h" #include "ns3/uniform-planar-array.h" -#include "ns3/wifi-spectrum-value-helper.h" using namespace ns3; @@ -636,7 +636,7 @@ ThreeGppSpectrumPropagationLossModelTest::DoRun() DoBeamforming(rxDev, rxAntenna, txDev, txAntenna); // create the tx psd - WifiSpectrumValue5MhzFactory sf; + SpectrumValue5MhzFactory sf; double txPower = 0.1; // Watts uint32_t channelNumber = 1; Ptr txPsd = sf.CreateTxPowerSpectralDensity(txPower, channelNumber);