From 5c8ce8a6f6661c8bef8b5de1c67bcf2bf2e7ab06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Thu, 16 May 2024 21:24:24 +0200 Subject: [PATCH] wifi: Add 80+80MHz support for SpectrumWifiPhy::GetBand --- src/wifi/model/spectrum-wifi-phy.cc | 32 +++++++++++++++++++++++++++-- src/wifi/model/spectrum-wifi-phy.h | 12 +++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/wifi/model/spectrum-wifi-phy.cc b/src/wifi/model/spectrum-wifi-phy.cc index 16a6c14d8..acd3b2ac2 100644 --- a/src/wifi/model/spectrum-wifi-phy.cc +++ b/src/wifi/model/spectrum-wifi-phy.cc @@ -647,6 +647,26 @@ SpectrumWifiPhy::GetGuardBandwidth(ChannelWidthMhz currentChannelWidth) const return guardBandwidth; } +uint32_t +SpectrumWifiPhy::GetNumBandsBetweenSegments(const WifiPhyOperatingChannel& channel, + uint32_t subcarrierSpacing) +{ + NS_ABORT_MSG_IF(channel.GetNSegments() > 2, + "Only 2 non-contiguous frequency segments are supported"); + if (channel.GetNSegments() < 2) + { + return 0; + } + const auto frequencies = channel.GetFrequencies(); + const auto lowFrequency = *frequencies.cbegin(); + const auto highFrequency = *frequencies.crbegin(); + NS_ASSERT(lowFrequency != highFrequency); + // all segments have the same width + const auto segmentsWidth = channel.GetWidth(0); + const auto widthBetweenSegments = highFrequency - lowFrequency - segmentsWidth; + return (widthBetweenSegments * 1e6) / subcarrierSpacing; +} + WifiSpectrumBandInfo SpectrumWifiPhy::GetBandForInterface(Ptr spectrumPhyInterface, ChannelWidthMhz bandWidth, @@ -656,6 +676,7 @@ SpectrumWifiPhy::GetBandForInterface(Ptr spectrumPhyIn const auto channelWidth = spectrumPhyInterface->GetChannelWidth(); const auto numBandsInBand = static_cast(bandWidth * 1e6 / subcarrierSpacing); auto numBandsInChannel = static_cast(channelWidth * 1e6 / subcarrierSpacing); + const auto numBands = channelWidth / bandWidth; if (numBandsInBand % 2 == 0) { numBandsInChannel += 1; // symmetry around center frequency @@ -664,9 +685,16 @@ SpectrumWifiPhy::GetBandForInterface(Ptr spectrumPhyIn size_t totalNumBands = rxSpectrumModel->GetNumBands(); NS_ASSERT_MSG((numBandsInChannel % 2 == 1) && (totalNumBands % 2 == 1), "Should have odd number of bands"); - NS_ASSERT_MSG((bandIndex * bandWidth) < channelWidth, "Band index is out of bound"); + NS_ASSERT_MSG(bandIndex < numBands, "Band index is out of bound"); NS_ASSERT(totalNumBands >= numBandsInChannel); - auto startIndex = ((totalNumBands - numBandsInChannel) / 2) + (bandIndex * numBandsInBand); + const auto numBandsBetweenSegments = + GetNumBandsBetweenSegments(GetOperatingChannel(), GetSubcarrierSpacing()); + auto startIndex = ((totalNumBands - numBandsInChannel - numBandsBetweenSegments) / 2) + + (bandIndex * numBandsInBand); + if (bandIndex >= (numBands / 2)) + { + startIndex += numBandsBetweenSegments; + } auto stopIndex = startIndex + numBandsInBand - 1; auto frequencies = ConvertIndicesToFrequenciesForInterface(spectrumPhyInterface, {startIndex, stopIndex}); diff --git a/src/wifi/model/spectrum-wifi-phy.h b/src/wifi/model/spectrum-wifi-phy.h index 799e33f1d..46919d1e1 100644 --- a/src/wifi/model/spectrum-wifi-phy.h +++ b/src/wifi/model/spectrum-wifi-phy.h @@ -176,6 +176,18 @@ class SpectrumWifiPhy : public WifiPhy */ const std::map>& GetSpectrumPhyInterfaces() const; + /** + * Determine the number of bands between the two segments if the operating channel is made of + * non-contiguous segments, otherwise the function returns zero. + * + * \param channel the operating channel + * \param subcarrierSpacing the subcarrier spacing + * \return the number of bands between the two segments if the operating channel is made of + * non-contiguous segments, zero otherwise + */ + static uint32_t GetNumBandsBetweenSegments(const WifiPhyOperatingChannel& channel, + uint32_t subcarrierSpacing); + /** * \param callback the callback to invoke when operating channel has switched. */