From 15d068c016f329ef02af6429f1defa919404f61a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Sat, 25 Feb 2023 13:59:05 +0100 Subject: [PATCH] wifi: Move some more 802.11ax specific to HE PHY --- src/wifi/model/he/he-phy.cc | 41 ++++++++++++++++ src/wifi/model/he/he-phy.h | 15 ++++++ src/wifi/model/spectrum-wifi-phy.cc | 49 +------------------ src/wifi/model/wifi-spectrum-phy-interface.cc | 4 +- src/wifi/model/wifi-spectrum-phy-interface.h | 10 ++-- 5 files changed, 63 insertions(+), 56 deletions(-) diff --git a/src/wifi/model/he/he-phy.cc b/src/wifi/model/he/he-phy.cc index 926c67ea8..fd927ca84 100644 --- a/src/wifi/model/he/he-phy.cc +++ b/src/wifi/model/he/he-phy.cc @@ -1873,6 +1873,47 @@ HePhy::ConvertHeRuSubcarriers(uint16_t bandWidth, return convertedSubcarriers; } +HePhy::RuBands +HePhy::GetRuBands(Ptr phy, uint16_t channelWidth, uint16_t guardBandwidth) +{ + HePhy::RuBands ruBands{}; + for (uint16_t bw = 160; bw >= 20; bw = bw / 2) + { + for (uint32_t i = 0; i < (channelWidth / bw); ++i) + { + for (uint32_t type = 0; type < 7; type++) + { + HeRu::RuType ruType = static_cast(type); + std::size_t nRus = HeRu::GetNRus(bw, ruType); + for (std::size_t phyIndex = 1; phyIndex <= nRus; phyIndex++) + { + HeRu::SubcarrierGroup group = HeRu::GetSubcarrierGroup(bw, ruType, phyIndex); + HeRu::SubcarrierRange subcarrierRange = + std::make_pair(group.front().first, group.back().second); + const auto bandIndices = ConvertHeRuSubcarriers(bw, + guardBandwidth, + phy->GetSubcarrierSpacing(), + subcarrierRange, + i); + const auto bandFrequencies = phy->ConvertIndicesToFrequencies(bandIndices); + WifiSpectrumBandInfo band = {bandIndices, bandFrequencies}; + std::size_t index = + (bw == 160 && phyIndex > nRus / 2 ? phyIndex - nRus / 2 : phyIndex); + const auto p20Index = phy->GetOperatingChannel().GetPrimaryChannelIndex(20); + bool primary80IsLower80 = (p20Index < bw / 40); + bool primary80 = (bw < 160 || ruType == HeRu::RU_2x996_TONE || + (primary80IsLower80 && phyIndex <= nRus / 2) || + (!primary80IsLower80 && phyIndex > nRus / 2)); + HeRu::RuSpec ru(ruType, index, primary80); + NS_ABORT_IF(ru.GetPhyIndex(bw, p20Index) != phyIndex); + ruBands.insert({band.indices, ru}); + } + } + } + } + return ruBands; +} + } // namespace ns3 namespace diff --git a/src/wifi/model/he/he-phy.h b/src/wifi/model/he/he-phy.h index e49866562..49c0118d3 100644 --- a/src/wifi/model/he/he-phy.h +++ b/src/wifi/model/he/he-phy.h @@ -451,6 +451,21 @@ class HePhy : public VhtPhy HeRu::SubcarrierRange subcarrierRange, uint8_t bandIndex = 0); + /// Map a spectrum band associated with an RU to the RU specification + using RuBands = std::map; + + /** + * Static function to compute the RU bands that belong to a given channel width. + * + * \param phy the PHY that issued the function call + * \param channelWidth the channelWidth the channel width in MHz + * \param guardBandwidth width of the guard band in MHz + * \returns the computed RU bands that belong to the channel width + */ + static RuBands GetRuBands(Ptr phy, + uint16_t channelWidth, + uint16_t guardBandwidth); + protected: PhyFieldRxStatus ProcessSig(Ptr event, PhyFieldRxStatus status, diff --git a/src/wifi/model/spectrum-wifi-phy.cc b/src/wifi/model/spectrum-wifi-phy.cc index 5912a5f3f..0b972cdf6 100644 --- a/src/wifi/model/spectrum-wifi-phy.cc +++ b/src/wifi/model/spectrum-wifi-phy.cc @@ -145,54 +145,7 @@ SpectrumWifiPhy::UpdateInterferenceHelperBands(std::optional indicesOff } if (GetStandard() >= WIFI_STANDARD_80211ax) { - // For a given RU type, some RUs over a channel occupy the same tones as - // the corresponding RUs over a subchannel, while some others not. For instance, - // the first nine 26-tone RUs over an 80 MHz channel occupy the same tones as - // the first nine 26-tone RUs over the lowest 40 MHz subchannel. Therefore, we - // need to store all the bands in a set (which removes duplicates) and then - // pass the elements in the set to AddBand (to which we cannot pass duplicates) - WifiSpectrumPhyInterface::RuBands ruBandsMap{}; - for (uint16_t bw = 160; bw >= 20; bw = bw / 2) - { - for (uint32_t i = 0; i < (channelWidth / bw); ++i) - { - for (uint32_t type = 0; type < 7; type++) - { - HeRu::RuType ruType = static_cast(type); - std::size_t nRus = HeRu::GetNRus(bw, ruType); - for (std::size_t phyIndex = 1; phyIndex <= nRus; phyIndex++) - { - HeRu::RuType ruType = static_cast(type); - std::size_t nRus = HeRu::GetNRus(bw, ruType); - for (std::size_t phyIndex = 1; phyIndex <= nRus; phyIndex++) - { - HeRu::SubcarrierGroup group = - HeRu::GetSubcarrierGroup(bw, ruType, phyIndex); - HeRu::SubcarrierRange subcarrierRange = - std::make_pair(group.front().first, group.back().second); - const auto band = - HePhy::ConvertHeRuSubcarriers(bw, - GetGuardBandwidth(channelWidth), - GetSubcarrierSpacing(), - subcarrierRange, - i); - std::size_t index = - (bw == 160 && phyIndex > nRus / 2 ? phyIndex - nRus / 2 : phyIndex); - bool primary80IsLower80 = - (GetOperatingChannel().GetPrimaryChannelIndex(20) < bw / 40); - bool primary80 = (bw < 160 || ruType == HeRu::RU_2x996_TONE || - (primary80IsLower80 && phyIndex <= nRus / 2) || - (!primary80IsLower80 && phyIndex > nRus / 2)); - HeRu::RuSpec ru(ruType, index, primary80); - NS_ABORT_IF(ru.GetPhyIndex(bw, - GetOperatingChannel().GetPrimaryChannelIndex( - 20)) != phyIndex); - ruBandsMap.insert({band, ru}); - } - } - } - } - } + auto&& ruBandsMap = HePhy::GetRuBands(this, channelWidth, GetGuardBandwidth(channelWidth)); for (const auto& bandRuPair : ruBandsMap) { ruBands.push_back(bandRuPair.first); diff --git a/src/wifi/model/wifi-spectrum-phy-interface.cc b/src/wifi/model/wifi-spectrum-phy-interface.cc index 8db4def47..8ee0b907c 100644 --- a/src/wifi/model/wifi-spectrum-phy-interface.cc +++ b/src/wifi/model/wifi-spectrum-phy-interface.cc @@ -156,12 +156,12 @@ WifiSpectrumPhyInterface::GetChannelWidth() const } void -WifiSpectrumPhyInterface::SetRuBands(WifiSpectrumPhyInterface::RuBands&& ruBands) +WifiSpectrumPhyInterface::SetRuBands(HePhy::RuBands&& ruBands) { m_ruBands = std::move(ruBands); } -const WifiSpectrumPhyInterface::RuBands& +const HePhy::RuBands& WifiSpectrumPhyInterface::GetRuBands() const { return m_ruBands; diff --git a/src/wifi/model/wifi-spectrum-phy-interface.h b/src/wifi/model/wifi-spectrum-phy-interface.h index 2e388dde1..e967ca470 100644 --- a/src/wifi/model/wifi-spectrum-phy-interface.h +++ b/src/wifi/model/wifi-spectrum-phy-interface.h @@ -22,6 +22,7 @@ #include "spectrum-wifi-phy.h" +#include "ns3/he-phy.h" #include "ns3/spectrum-phy.h" namespace ns3 @@ -125,21 +126,18 @@ class WifiSpectrumPhyInterface : public SpectrumPhy uint32_t bandBandwidth, uint16_t guardBandwidth); - /// Map a spectrum band associated with an RU to the RU specification - using RuBands = std::map; - /** * Set the HE RU spectrum bands handled by this interface (if any) * * \param ruBands the HE RU spectrum bands */ - void SetRuBands(RuBands&& ruBands); + void SetRuBands(HePhy::RuBands&& ruBands); /** * Get the HE RU spectrum bands handled by this interface * * \return the HE RU spectrum bands */ - const RuBands& GetRuBands() const; + const HePhy::RuBands& GetRuBands() const; private: void DoDispose() override; @@ -152,7 +150,7 @@ class WifiSpectrumPhyInterface : public SpectrumPhy uint16_t m_channelWidth; ///< channel width in MHz Ptr m_rxSpectrumModel; ///< receive spectrum model - RuBands m_ruBands; /**< Store all the distinct spectrum bands associated with every RU */ + HePhy::RuBands m_ruBands; /**< Store all the distinct spectrum bands associated with every RU */ }; } // namespace ns3