diff --git a/src/wifi/model/spectrum-wifi-phy.cc b/src/wifi/model/spectrum-wifi-phy.cc index 668380c36..0af1fe9fe 100644 --- a/src/wifi/model/spectrum-wifi-phy.cc +++ b/src/wifi/model/spectrum-wifi-phy.cc @@ -586,27 +586,50 @@ SpectrumWifiPhy::GetBandForInterface(uint16_t bandWidth, FrequencyRange freqRange, uint16_t channelWidth) { - uint32_t subcarrierSpacing = GetSubcarrierSpacing(); - size_t numBandsInChannel = static_cast(channelWidth * 1e6 / subcarrierSpacing); - size_t numBandsInBand = static_cast(bandWidth * 1e6 / subcarrierSpacing); + auto subcarrierSpacing = GetSubcarrierSpacing(); + auto numBandsInChannel = static_cast(channelWidth * 1e6 / subcarrierSpacing); + auto numBandsInBand = static_cast(bandWidth * 1e6 / subcarrierSpacing); if (numBandsInBand % 2 == 0) { numBandsInChannel += 1; // symmetry around center frequency } - size_t totalNumBands = - m_spectrumPhyInterfaces.at(freqRange)->GetRxSpectrumModel()->GetNumBands(); + auto rxSpectrumModel = m_spectrumPhyInterfaces.at(freqRange)->GetRxSpectrumModel(); + 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(totalNumBands >= numBandsInChannel); auto startIndex = ((totalNumBands - numBandsInChannel) / 2) + (bandIndex * numBandsInBand); auto stopIndex = startIndex + numBandsInBand - 1; + auto frequencies = ConvertIndicesForInterface({startIndex, stopIndex}, freqRange); + NS_ASSERT(frequencies.first >= (freqRange.minFrequency * 1e6)); + NS_ASSERT(frequencies.second <= (freqRange.maxFrequency * 1e6)); + NS_ASSERT((frequencies.second - frequencies.first) == (bandWidth * 1e6)); if (startIndex >= totalNumBands / 2) { // step past DC startIndex += 1; } - return {{startIndex, stopIndex}, {0, 0}}; + return {{startIndex, stopIndex}, frequencies}; +} + +WifiSpectrumBandFrequencies +SpectrumWifiPhy::ConvertIndicesToFrequencies(const WifiSpectrumBandIndices& indices) const +{ + return ConvertIndicesForInterface(indices, GetCurrentFrequencyRange()); +} + +WifiSpectrumBandFrequencies +SpectrumWifiPhy::ConvertIndicesForInterface(const WifiSpectrumBandIndices& indices, + const FrequencyRange& freqRange) const +{ + auto rxSpectrumModel = m_spectrumPhyInterfaces.at(freqRange)->GetRxSpectrumModel(); + auto startGuardBand = rxSpectrumModel->Begin(); + auto startChannel = std::next(startGuardBand, indices.first); + auto endChannel = std::next(startGuardBand, indices.second + 1); + auto lowFreq = static_cast(startChannel->fc); + auto highFreq = static_cast(endChannel->fc); + return {lowFreq, highFreq}; } std::tuple diff --git a/src/wifi/model/spectrum-wifi-phy.h b/src/wifi/model/spectrum-wifi-phy.h index f9abc1bd3..fb23d1ff8 100644 --- a/src/wifi/model/spectrum-wifi-phy.h +++ b/src/wifi/model/spectrum-wifi-phy.h @@ -77,6 +77,8 @@ class SpectrumWifiPhy : public WifiPhy std::tuple GetTxMaskRejectionParams() const override; WifiSpectrumBandInfo GetBand(uint16_t bandWidth, uint8_t bandIndex = 0) override; FrequencyRange GetCurrentFrequencyRange() const override; + WifiSpectrumBandFrequencies ConvertIndicesToFrequencies( + const WifiSpectrumBandIndices& indices) const override; /** * Attach a SpectrumChannel to use for a given frequency range. @@ -183,6 +185,9 @@ class SpectrumWifiPhy : public WifiPhy //!< reasons) private: + WifiSpectrumBandFrequencies ConvertIndicesForInterface(const WifiSpectrumBandIndices& indices, + const FrequencyRange& freqRange) const; + /** * Perform run-time spectrum model change */ diff --git a/src/wifi/model/wifi-phy.h b/src/wifi/model/wifi-phy.h index 633aa58d6..c5ae2f21b 100644 --- a/src/wifi/model/wifi-phy.h +++ b/src/wifi/model/wifi-phy.h @@ -1053,6 +1053,15 @@ class WifiPhy : public Object */ void NotifyChannelAccessRequested(); + /** + * This is a helper function to convert start and stop indices to start and stop frequencies. + * + * \param indices the start/stop indices to convert + * \return the converted frequencies + */ + virtual WifiSpectrumBandFrequencies ConvertIndicesToFrequencies( + const WifiSpectrumBandIndices& indices) const = 0; + /** * Add the PHY entity to the map of __implemented__ PHY entities for the * given modulation class. diff --git a/src/wifi/model/yans-wifi-phy.cc b/src/wifi/model/yans-wifi-phy.cc index 6eb3cbc73..2e56c92dc 100644 --- a/src/wifi/model/yans-wifi-phy.cc +++ b/src/wifi/model/yans-wifi-phy.cc @@ -118,4 +118,10 @@ YansWifiPhy::GetCurrentFrequencyRange() const return WHOLE_WIFI_SPECTRUM; } +WifiSpectrumBandFrequencies +YansWifiPhy::ConvertIndicesToFrequencies(const WifiSpectrumBandIndices& /*indices*/) const +{ + return {0, 0}; +} + } // namespace ns3 diff --git a/src/wifi/model/yans-wifi-phy.h b/src/wifi/model/yans-wifi-phy.h index fb69283c7..7bbac571f 100644 --- a/src/wifi/model/yans-wifi-phy.h +++ b/src/wifi/model/yans-wifi-phy.h @@ -63,6 +63,8 @@ class YansWifiPhy : public WifiPhy std::tuple GetTxMaskRejectionParams() const override; WifiSpectrumBandInfo GetBand(uint16_t bandWidth, uint8_t bandIndex = 0) override; FrequencyRange GetCurrentFrequencyRange() const override; + WifiSpectrumBandFrequencies ConvertIndicesToFrequencies( + const WifiSpectrumBandIndices& indices) const override; /** * Set the YansWifiChannel this YansWifiPhy is to be connected to.