From 9777b825a89f21adacf5b5601226431f70879c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Sat, 1 Apr 2023 14:46:12 +0200 Subject: [PATCH] wifi: Do not compute bands stored in interference helper if the spectrum PHY interface is operating on the same channel --- src/wifi/model/spectrum-wifi-phy.cc | 38 ++++++++++++++++++++--------- src/wifi/model/spectrum-wifi-phy.h | 5 ++-- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/wifi/model/spectrum-wifi-phy.cc b/src/wifi/model/spectrum-wifi-phy.cc index c175e8ffa..71f4243e0 100644 --- a/src/wifi/model/spectrum-wifi-phy.cc +++ b/src/wifi/model/spectrum-wifi-phy.cc @@ -205,13 +205,36 @@ SpectrumWifiPhy::AddChannel(const Ptr channel, const FrequencyR } void -SpectrumWifiPhy::ResetSpectrumModel() +SpectrumWifiPhy::ResetSpectrumModelIfNeeded() { NS_LOG_FUNCTION(this); - // Replace existing spectrum model with new one + // We have to reset the spectrum model because we changed RF channel. Consequently, + // we also have to add the spectrum interface to the spectrum channel again because + // MultiModelSpectrumChannel keeps spectrum interfaces in a map indexed by the RX + // spectrum model UID (which has changed after channel switching). + // Both SingleModelSpectrumChannel and MultiModelSpectrumChannel ensure not to keep + // duplicated spectrum interfaces (the latter removes the spectrum interface and adds + // it again in the entry associated with the new RX spectrum model UID) + const auto channelWidth = GetChannelWidth(); - m_currentSpectrumPhyInterface->SetRxSpectrumModel(GetFrequency(), + const auto centerFrequency = GetFrequency(); + if (m_currentSpectrumPhyInterface->GetCenterFrequency() == centerFrequency) + { + // Center frequency has not changed for that interface, hence we do not need to + // reset the spectrum model nor update any band stored in the interference helper + if (!m_trackSignalsInactiveInterfaces) + { + // If we are not tracking signals from inactive interface, + // this means the spectrum interface has been disconnected + // from the spectrum channel and has to be connected back + m_currentSpectrumPhyInterface->GetChannel()->AddRx(m_currentSpectrumPhyInterface); + } + return; + } + + // Replace existing spectrum model with new one + m_currentSpectrumPhyInterface->SetRxSpectrumModel(centerFrequency, channelWidth, GetSubcarrierSpacing(), GetGuardBandwidth(channelWidth)); @@ -258,15 +281,8 @@ SpectrumWifiPhy::DoChannelSwitch() } } - // We have to reset the spectrum model because we changed RF channel. Consequently, - // we also have to add the spectrum interface to the spectrum channel again because - // MultiModelSpectrumChannel keeps spectrum interfaces in a map indexed by the RX - // spectrum model UID (which has changed after channel switching). - // Both SingleModelSpectrumChannel and MultiModelSpectrumChannel ensure not to keep - // duplicated spectrum interfaces (the latter removes the spectrum interface and adds - // it again in the entry associated with the new RX spectrum model UID) m_currentSpectrumPhyInterface = newSpectrumPhyInterface; - ResetSpectrumModel(); + ResetSpectrumModelIfNeeded(); if (IsInitialized()) { diff --git a/src/wifi/model/spectrum-wifi-phy.h b/src/wifi/model/spectrum-wifi-phy.h index 587764222..62b711a25 100644 --- a/src/wifi/model/spectrum-wifi-phy.h +++ b/src/wifi/model/spectrum-wifi-phy.h @@ -171,9 +171,10 @@ class SpectrumWifiPhy : public WifiPhy private: /** - * Perform run-time spectrum model change + * Perform run-time spectrum model change if the one used by the current Spectrum PHY interface + * has changed */ - void ResetSpectrumModel(); + void ResetSpectrumModelIfNeeded(); /** * This function is called to update the bands handled by the InterferenceHelper.