From 5439c98fe5a6998ebe0186cfcd167b710667486b Mon Sep 17 00:00:00 2001 From: Sharan Naribole Date: Mon, 7 Aug 2023 20:13:21 +0200 Subject: [PATCH] wifi: Extend helper to configure mapping between spectrum PHY interfaces and PHY instances --- src/wifi/helper/spectrum-wifi-helper.cc | 40 +++++++++++++++++++++---- src/wifi/helper/spectrum-wifi-helper.h | 27 +++++++++++++++++ 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/wifi/helper/spectrum-wifi-helper.cc b/src/wifi/helper/spectrum-wifi-helper.cc index 56b3aa266..6a6d7ff03 100644 --- a/src/wifi/helper/spectrum-wifi-helper.cc +++ b/src/wifi/helper/spectrum-wifi-helper.cc @@ -104,6 +104,19 @@ SpectrumWifiPhyHelper::AddWifiBandwidthFilter(Ptr channel) } } +void +SpectrumWifiPhyHelper::AddPhyToFreqRangeMapping(uint8_t linkId, const FrequencyRange& freqRange) +{ + if (auto it = m_interfacesMap.find(linkId); it == m_interfacesMap.end()) + { + m_interfacesMap.insert({linkId, {freqRange}}); + } + else + { + it->second.emplace(freqRange); + } +} + std::vector> SpectrumWifiPhyHelper::Create(Ptr node, Ptr device) const { @@ -114,7 +127,7 @@ SpectrumWifiPhyHelper::Create(Ptr node, Ptr device) const auto phy = m_phys.at(i).Create(); auto interference = m_interferenceHelper.Create(); phy->SetInterferenceHelper(interference); - Ptr error = m_errorRateModel.at(i).Create(); + auto error = m_errorRateModel.at(i).Create(); phy->SetErrorRateModel(error); if (m_frameCaptureModel.at(i).IsTypeIdSet()) { @@ -127,10 +140,7 @@ SpectrumWifiPhyHelper::Create(Ptr node, Ptr device) const m_preambleDetectionModel.at(i).Create(); phy->SetPreambleDetectionModel(preambleDetection); } - for (const auto& [freqRange, channel] : m_channels) - { - phy->AddChannel(channel, freqRange); - } + InstallPhyInterfaces(i, phy); phy->SetDevice(device); phy->SetMobility(node->GetObject()); ret.emplace_back(phy); @@ -139,4 +149,24 @@ SpectrumWifiPhyHelper::Create(Ptr node, Ptr device) const return ret; } +void +SpectrumWifiPhyHelper::InstallPhyInterfaces(uint8_t linkId, Ptr phy) const +{ + if (m_interfacesMap.count(linkId) == 0) + { + // default setup: set all interfaces to this link + for (const auto& [freqRange, channel] : m_channels) + { + phy->AddChannel(channel, freqRange); + } + } + else + { + for (const auto& freqRange : m_interfacesMap.at(linkId)) + { + phy->AddChannel(m_channels.at(freqRange), freqRange); + } + } +} + } // namespace ns3 diff --git a/src/wifi/helper/spectrum-wifi-helper.h b/src/wifi/helper/spectrum-wifi-helper.h index a58cfeed7..fd628b803 100644 --- a/src/wifi/helper/spectrum-wifi-helper.h +++ b/src/wifi/helper/spectrum-wifi-helper.h @@ -22,10 +22,14 @@ #include "wifi-helper.h" +#include +#include + namespace ns3 { class SpectrumChannel; +class SpectrumWifiPhy; /** * \brief Make it easy to create and manage PHY objects for the spectrum model. @@ -81,6 +85,16 @@ class SpectrumWifiPhyHelper : public WifiPhyHelper void AddChannel(const std::string& channelName, const FrequencyRange& freqRange = WHOLE_WIFI_SPECTRUM); + /** + * Add a given spectrum PHY interface to the PHY instance corresponding of a given link. + * If no mapping has been specified for a given link, all spectrum PHY interfaces will + * be added to the PHY instance of that link. + * + * \param linkId ID of the link to setup + * \param freqRange frequency range handled by of the spectrum PHY interface + */ + void AddPhyToFreqRangeMapping(uint8_t linkId, const FrequencyRange& freqRange); + private: /** * \param node the node on which we wish to create a wifi PHY @@ -90,6 +104,16 @@ class SpectrumWifiPhyHelper : public WifiPhyHelper * This method implements the pure virtual method defined in \ref ns3::WifiPhyHelper. */ std::vector> Create(Ptr node, Ptr device) const override; + + /** + * \brief Install PHY interfaces to the PHY instance of a given link + * based on the currently configured mapping (\see AddPhyInterface). + * + * \param linkId ID of the link to setup + * \param phy spectrum PHY instance of the link + */ + void InstallPhyInterfaces(uint8_t linkId, Ptr phy) const; + /** * \param channel The channel to inspect to possibly add a WifiBandwidthFilter * @@ -99,6 +123,9 @@ class SpectrumWifiPhyHelper : public WifiPhyHelper void AddWifiBandwidthFilter(Ptr channel); std::map> m_channels; ///< the spectrum channels + std::map> + m_interfacesMap; ///< map of the spectrum PHY interfaces to be added to the PHY instance + ///< corresponding to a given link ID }; } // namespace ns3