From c622338aaa8493d098efb4c7d4f3b5f85fcbeae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Tue, 24 Jan 2023 22:27:06 +0100 Subject: [PATCH] wifi: Add function to retrieve frequency range of the currently active spectrum PHY interface --- src/wifi/model/phy-entity.cc | 32 +++++++++++++++++------------ src/wifi/model/spectrum-wifi-phy.cc | 21 ++++++++++++------- src/wifi/model/spectrum-wifi-phy.h | 1 + src/wifi/model/wifi-phy.cc | 10 ++++++--- src/wifi/model/wifi-phy.h | 7 +++++++ src/wifi/model/yans-wifi-phy.cc | 8 +++++++- src/wifi/model/yans-wifi-phy.h | 1 + 7 files changed, 56 insertions(+), 24 deletions(-) diff --git a/src/wifi/model/phy-entity.cc b/src/wifi/model/phy-entity.cc index 76410f6cb..b2442cb8b 100644 --- a/src/wifi/model/phy-entity.cc +++ b/src/wifi/model/phy-entity.cc @@ -273,7 +273,7 @@ PhyEntity::GetPhyHeaderSnrPer(WifiPpduField field, Ptr event) const event, measurementChannelWidth, GetPrimaryBand(measurementChannelWidth), - WHOLE_WIFI_SPECTRUM, + m_wifiPhy->GetCurrentFrequencyRange(), field); } @@ -715,7 +715,7 @@ PhyEntity::EndReceivePayload(Ptr event) channelWidthAndBand.first, txVector.GetNss(staId), channelWidthAndBand.second, - WHOLE_WIFI_SPECTRUM); + m_wifiPhy->GetCurrentFrequencyRange()); Ptr psdu = GetAddressedPsduInPpdu(ppdu); m_wifiPhy->NotifyRxEnd(psdu); @@ -796,7 +796,7 @@ PhyEntity::GetReceptionStatus(Ptr psdu, event, channelWidthAndBand.first, channelWidthAndBand.second, - WHOLE_WIFI_SPECTRUM, + m_wifiPhy->GetCurrentFrequencyRange(), staId, std::make_pair(relativeMpduStart, relativeMpduStart + mpduDuration)); @@ -872,20 +872,24 @@ PhyEntity::CreateInterferenceEvent(Ptr ppdu, RxPowerWattPerChannelBand& rxPower, bool isStartOfdmaRxing /* = false */) { - return m_wifiPhy->m_interference - ->Add(ppdu, txVector, duration, rxPower, WHOLE_WIFI_SPECTRUM, isStartOfdmaRxing); + return m_wifiPhy->m_interference->Add(ppdu, + txVector, + duration, + rxPower, + m_wifiPhy->GetCurrentFrequencyRange(), + isStartOfdmaRxing); } void PhyEntity::UpdateInterferenceEvent(Ptr event, const RxPowerWattPerChannelBand& rxPower) { - m_wifiPhy->m_interference->UpdateEvent(event, rxPower, WHOLE_WIFI_SPECTRUM); + m_wifiPhy->m_interference->UpdateEvent(event, rxPower, m_wifiPhy->GetCurrentFrequencyRange()); } void PhyEntity::NotifyInterferenceRxEndAndClear(bool reset) { - m_wifiPhy->m_interference->NotifyRxEnd(Simulator::Now(), WHOLE_WIFI_SPECTRUM); + m_wifiPhy->m_interference->NotifyRxEnd(Simulator::Now(), m_wifiPhy->GetCurrentFrequencyRange()); m_signalNoiseMap.clear(); m_statusPerMpduMap.clear(); for (const auto& endOfMpduEvent : m_endOfMpduEvents) @@ -961,7 +965,8 @@ PhyEntity::EndPreambleDetectionPeriod(Ptr event) m_wifiPhy->m_currentPreambleEvents.erase(it); // This is needed to cleanup the m_firstPowerPerBand so that the first power corresponds to // the power at the start of the PPDU - m_wifiPhy->m_interference->NotifyRxEnd(maxEvent->GetStartTime(), WHOLE_WIFI_SPECTRUM); + m_wifiPhy->m_interference->NotifyRxEnd(maxEvent->GetStartTime(), + m_wifiPhy->GetCurrentFrequencyRange()); // Make sure InterferenceHelper keeps recording events m_wifiPhy->m_interference->NotifyRxStart(); return; @@ -973,7 +978,7 @@ PhyEntity::EndPreambleDetectionPeriod(Ptr event) measurementChannelWidth, 1, measurementBand, - WHOLE_WIFI_SPECTRUM); + m_wifiPhy->GetCurrentFrequencyRange()); NS_LOG_DEBUG("SNR(dB)=" << RatioToDb(snr) << " at end of preamble detection period"); if ((!m_wifiPhy->m_preambleDetectionModel && maxRxPowerW > 0.0) || @@ -1005,7 +1010,7 @@ PhyEntity::EndPreambleDetectionPeriod(Ptr event) // corresponds to the power at the start of the PPDU m_wifiPhy->m_interference->NotifyRxEnd( m_wifiPhy->m_currentEvent->GetStartTime(), - WHOLE_WIFI_SPECTRUM); + m_wifiPhy->GetCurrentFrequencyRange()); } else { @@ -1049,7 +1054,8 @@ PhyEntity::EndPreambleDetectionPeriod(Ptr event) if (m_wifiPhy->m_currentPreambleEvents.empty()) { // Do not erase events if there are still pending preamble events to be processed - m_wifiPhy->m_interference->NotifyRxEnd(Simulator::Now(), WHOLE_WIFI_SPECTRUM); + m_wifiPhy->m_interference->NotifyRxEnd(Simulator::Now(), + m_wifiPhy->GetCurrentFrequencyRange()); } m_wifiPhy->m_currentEvent = nullptr; // Cancel preamble reception @@ -1142,7 +1148,7 @@ PhyEntity::ResetReceive(Ptr event) NS_LOG_FUNCTION(this << *event); DoResetReceive(event); NS_ASSERT(!m_wifiPhy->IsStateRx()); - m_wifiPhy->m_interference->NotifyRxEnd(Simulator::Now(), WHOLE_WIFI_SPECTRUM); + m_wifiPhy->m_interference->NotifyRxEnd(Simulator::Now(), m_wifiPhy->GetCurrentFrequencyRange()); NS_ASSERT(m_endRxPayloadEvents.size() == 1 && m_endRxPayloadEvents.front().IsExpired()); m_endRxPayloadEvents.clear(); m_wifiPhy->m_currentEvent = nullptr; @@ -1212,7 +1218,7 @@ PhyEntity::GetDelayUntilCcaEnd(double thresholdDbm, WifiSpectrumBand band) { return m_wifiPhy->m_interference->GetEnergyDuration(DbmToW(thresholdDbm), band, - WHOLE_WIFI_SPECTRUM); + m_wifiPhy->GetCurrentFrequencyRange()); } void diff --git a/src/wifi/model/spectrum-wifi-phy.cc b/src/wifi/model/spectrum-wifi-phy.cc index 390ad1e07..eab812778 100644 --- a/src/wifi/model/spectrum-wifi-phy.cc +++ b/src/wifi/model/spectrum-wifi-phy.cc @@ -188,16 +188,16 @@ SpectrumWifiPhy::UpdateInterferenceHelperBands() } } const auto bandsChanged = std::any_of(bands.cbegin(), bands.cend(), [&](const auto& band) { - return !m_interference->HasBand(band, WHOLE_WIFI_SPECTRUM); + return !m_interference->HasBand(band, GetCurrentFrequencyRange()); }); if (!bandsChanged) { return; } - m_interference->RemoveBands(WHOLE_WIFI_SPECTRUM); + m_interference->RemoveBands(GetCurrentFrequencyRange()); for (const auto& band : bands) { - m_interference->AddBand(band, WHOLE_WIFI_SPECTRUM); + m_interference->AddBand(band, GetCurrentFrequencyRange()); } } @@ -407,14 +407,14 @@ SpectrumWifiPhy::StartRx(Ptr rxParams) if (!wifiRxParams) { NS_LOG_INFO("Received non Wi-Fi signal"); - m_interference->AddForeignSignal(rxDuration, rxPowerW, WHOLE_WIFI_SPECTRUM); + m_interference->AddForeignSignal(rxDuration, rxPowerW, GetCurrentFrequencyRange()); SwitchMaybeToCcaBusy(nullptr); return; } if (wifiRxParams && m_disableWifiReception) { NS_LOG_INFO("Received Wi-Fi signal but blocked from syncing"); - m_interference->AddForeignSignal(rxDuration, rxPowerW, WHOLE_WIFI_SPECTRUM); + m_interference->AddForeignSignal(rxDuration, rxPowerW, GetCurrentFrequencyRange()); SwitchMaybeToCcaBusy(nullptr); return; } @@ -427,7 +427,7 @@ SpectrumWifiPhy::StartRx(Ptr rxParams) if (totalRxPowerW < DbmToW(GetRxSensitivity()) * (txWidth / 20.0)) { NS_LOG_INFO("Received signal too weak to process: " << WToDbm(totalRxPowerW) << " dBm"); - m_interference->Add(ppdu, txVector, rxDuration, rxPowerW, WHOLE_WIFI_SPECTRUM); + m_interference->Add(ppdu, txVector, rxDuration, rxPowerW, GetCurrentFrequencyRange()); SwitchMaybeToCcaBusy(nullptr); return; } @@ -437,7 +437,7 @@ SpectrumWifiPhy::StartRx(Ptr rxParams) if (!CanStartRx(ppdu, txWidth)) { NS_LOG_INFO("Cannot start reception of the PPDU, consider it as interference"); - m_interference->Add(ppdu, txVector, rxDuration, rxPowerW, WHOLE_WIFI_SPECTRUM); + m_interference->Add(ppdu, txVector, rxDuration, rxPowerW, GetCurrentFrequencyRange()); SwitchMaybeToCcaBusy(ppdu); return; } @@ -624,6 +624,13 @@ SpectrumWifiPhy::GetTxMaskRejectionParams() const m_txMaskOuterBandMaximumRejection); } +FrequencyRange +SpectrumWifiPhy::GetCurrentFrequencyRange() const +{ + NS_ABORT_IF(!m_currentSpectrumPhyInterface); + return m_currentSpectrumPhyInterface->GetFrequencyRange(); +} + Ptr SpectrumWifiPhy::GetInterfaceCoveringChannelBand(uint16_t frequency, uint16_t width) const { diff --git a/src/wifi/model/spectrum-wifi-phy.h b/src/wifi/model/spectrum-wifi-phy.h index df9fd23ee..6f0a66a0f 100644 --- a/src/wifi/model/spectrum-wifi-phy.h +++ b/src/wifi/model/spectrum-wifi-phy.h @@ -75,6 +75,7 @@ class SpectrumWifiPhy : public WifiPhy uint16_t GetGuardBandwidth(uint16_t currentChannelWidth) const override; std::tuple GetTxMaskRejectionParams() const override; WifiSpectrumBand GetBand(uint16_t bandWidth, uint8_t bandIndex = 0) override; + FrequencyRange GetCurrentFrequencyRange() const override; /** * Attach a SpectrumChannel to use for a given frequency range. diff --git a/src/wifi/model/wifi-phy.cc b/src/wifi/model/wifi-phy.cc index 56d669321..5b441ef75 100644 --- a/src/wifi/model/wifi-phy.cc +++ b/src/wifi/model/wifi-phy.cc @@ -1222,7 +1222,7 @@ WifiPhy::DoChannelSwitch() { // notify channel switching m_state->SwitchToChannelSwitching(GetChannelSwitchDelay()); - m_interference->EraseEvents(WHOLE_WIFI_SPECTRUM); + m_interference->EraseEvents(GetCurrentFrequencyRange()); /* * Needed here to be able to correctly sensed the medium for the first * time after the switching. The actual switching is not performed until @@ -1834,7 +1834,11 @@ WifiPhy::StartReceivePreamble(Ptr ppdu, // TODO find a fallback PHY for receiving the PPDU (e.g. 11a for 11ax due to preamble // structure) NS_LOG_DEBUG("Unsupported modulation received (" << modulation << "), consider as noise"); - m_interference->Add(ppdu, ppdu->GetTxVector(), rxDuration, rxPowersW, WHOLE_WIFI_SPECTRUM); + m_interference->Add(ppdu, + ppdu->GetTxVector(), + rxDuration, + rxPowersW, + GetCurrentFrequencyRange()); SwitchMaybeToCcaBusy(nullptr); } } @@ -2087,7 +2091,7 @@ WifiPhy::AbortCurrentReception(WifiPhyRxfailureReason reason) { m_endPhyRxEvent.Cancel(); } - m_interference->NotifyRxEnd(Simulator::Now(), WHOLE_WIFI_SPECTRUM); + m_interference->NotifyRxEnd(Simulator::Now(), GetCurrentFrequencyRange()); if (!m_currentEvent) { return; diff --git a/src/wifi/model/wifi-phy.h b/src/wifi/model/wifi-phy.h index 875021983..b1ae4f9f5 100644 --- a/src/wifi/model/wifi-phy.h +++ b/src/wifi/model/wifi-phy.h @@ -1157,6 +1157,13 @@ class WifiPhy : public Object */ virtual WifiSpectrumBand GetBand(uint16_t bandWidth, uint8_t bandIndex = 0) = 0; + /** + * Get the frequency range of the current RF interface. + * + * \return the frequency range of the current RF interface + */ + virtual FrequencyRange GetCurrentFrequencyRange() const = 0; + protected: void DoInitialize() override; void DoDispose() override; diff --git a/src/wifi/model/yans-wifi-phy.cc b/src/wifi/model/yans-wifi-phy.cc index 1782b2b8b..de547d989 100644 --- a/src/wifi/model/yans-wifi-phy.cc +++ b/src/wifi/model/yans-wifi-phy.cc @@ -56,7 +56,7 @@ YansWifiPhy::SetInterferenceHelper(const Ptr helper) WifiSpectrumBand band; band.first = 0; band.second = 0; - m_interference->AddBand(band, WHOLE_WIFI_SPECTRUM); + m_interference->AddBand(band, GetCurrentFrequencyRange()); } YansWifiPhy::~YansWifiPhy() @@ -118,4 +118,10 @@ YansWifiPhy::GetBand(uint16_t /*bandWidth*/, uint8_t /*bandIndex*/) return band; } +FrequencyRange +YansWifiPhy::GetCurrentFrequencyRange() const +{ + return WHOLE_WIFI_SPECTRUM; +} + } // namespace ns3 diff --git a/src/wifi/model/yans-wifi-phy.h b/src/wifi/model/yans-wifi-phy.h index f51004a22..4bfc8e849 100644 --- a/src/wifi/model/yans-wifi-phy.h +++ b/src/wifi/model/yans-wifi-phy.h @@ -62,6 +62,7 @@ class YansWifiPhy : public WifiPhy uint16_t GetGuardBandwidth(uint16_t currentChannelWidth) const override; std::tuple GetTxMaskRejectionParams() const override; WifiSpectrumBand GetBand(uint16_t bandWidth, uint8_t bandIndex = 0) override; + FrequencyRange GetCurrentFrequencyRange() const override; /** * Set the YansWifiChannel this YansWifiPhy is to be connected to.