From 30ec962813e39c13d66419c4b89a9fa1ff57fe91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Wed, 1 Feb 2023 12:24:16 +0100 Subject: [PATCH] wifi: Add function to SpectrumWifiPhy to get the band corresponding to a given width in a selected range --- src/wifi/model/spectrum-wifi-phy.cc | 16 ++++++++++++---- src/wifi/model/spectrum-wifi-phy.h | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/wifi/model/spectrum-wifi-phy.cc b/src/wifi/model/spectrum-wifi-phy.cc index eab812778..8eb0a16b5 100644 --- a/src/wifi/model/spectrum-wifi-phy.cc +++ b/src/wifi/model/spectrum-wifi-phy.cc @@ -553,9 +553,17 @@ SpectrumWifiPhy::GetGuardBandwidth(uint16_t currentChannelWidth) const } WifiSpectrumBand -SpectrumWifiPhy::GetBand(uint16_t bandWidth, uint8_t bandIndex) +SpectrumWifiPhy::GetBand(uint16_t bandWidth, uint8_t bandIndex /* = 0 */) +{ + return GetBandForInterface(bandWidth, bandIndex, GetCurrentFrequencyRange(), GetChannelWidth()); +} + +WifiSpectrumBand +SpectrumWifiPhy::GetBandForInterface(uint16_t bandWidth, + uint8_t bandIndex, + FrequencyRange range, + uint16_t channelWidth) { - uint16_t channelWidth = GetChannelWidth(); uint32_t bandBandwidth = GetBandBandwidth(); size_t numBandsInChannel = static_cast(channelWidth * 1e6 / bandBandwidth); size_t numBandsInBand = static_cast(bandWidth * 1e6 / bandBandwidth); @@ -563,12 +571,12 @@ SpectrumWifiPhy::GetBand(uint16_t bandWidth, uint8_t bandIndex) { numBandsInChannel += 1; // symmetry around center frequency } - NS_ABORT_IF(!m_currentSpectrumPhyInterface); - size_t totalNumBands = m_currentSpectrumPhyInterface->GetRxSpectrumModel()->GetNumBands(); + size_t totalNumBands = m_spectrumPhyInterfaces.at(range)->GetRxSpectrumModel()->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"); WifiSpectrumBand band; + NS_ASSERT(totalNumBands >= numBandsInChannel); band.first = ((totalNumBands - numBandsInChannel) / 2) + (bandIndex * numBandsInBand); band.second = band.first + numBandsInBand - 1; if (band.first >= totalNumBands / 2) diff --git a/src/wifi/model/spectrum-wifi-phy.h b/src/wifi/model/spectrum-wifi-phy.h index 6f0a66a0f..596620f1e 100644 --- a/src/wifi/model/spectrum-wifi-phy.h +++ b/src/wifi/model/spectrum-wifi-phy.h @@ -118,6 +118,22 @@ class SpectrumWifiPhy : public WifiPhy */ uint32_t GetBandBandwidth() const; + /** + * Get the start band index and the stop band index for a given band and a given spectrum PHY + * interface + * + * \param bandWidth the width of the band to be returned (MHz) + * \param bandIndex the index of the band to be returned + * \param range the frequency range identifying the spectrum PHY interface + * \param channelWidth the channel width currently used by the spectrum PHY interface + * + * \return a pair of start and stop indexes that defines the band + */ + WifiSpectrumBand GetBandForInterface(uint16_t bandWidth, + uint8_t bandIndex, + FrequencyRange range, + uint16_t channelWidth); + /** * Callback invoked when the PHY model starts to process a signal *