From e990fc0d1edd4c041d2859dd8af8e1f9dbb18db4 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Fri, 19 Apr 2024 16:42:43 +0200 Subject: [PATCH] wifi: Do not reset end busy times in case of EMLSR link switch --- src/wifi/model/channel-access-manager.cc | 75 ++++++++++++++++++------ src/wifi/model/channel-access-manager.h | 10 +++- 2 files changed, 65 insertions(+), 20 deletions(-) diff --git a/src/wifi/model/channel-access-manager.cc b/src/wifi/model/channel-access-manager.cc index 6f515bc359..bb2a026b36 100644 --- a/src/wifi/model/channel-access-manager.cc +++ b/src/wifi/model/channel-access-manager.cc @@ -270,7 +270,7 @@ ChannelAccessManager::SetupPhyListener(Ptr phy) DeactivatePhyListener(m_phy); } m_phy = phy; // this is the new active PHY - InitLastBusyStructs(); + ResizeLastBusyStructs(); phy->RegisterListener(phyListener); if (phy->IsStateSwitching()) { @@ -362,43 +362,82 @@ ChannelAccessManager::Add(Ptr txop) } void -ChannelAccessManager::InitLastBusyStructs() +ChannelAccessManager::ResizeLastBusyStructs() { NS_LOG_FUNCTION(this); - Time now = Simulator::Now(); - m_lastBusyEnd.clear(); - m_lastPer20MHzBusyEnd.clear(); - m_lastIdle.clear(); - m_lastBusyEnd[WIFI_CHANLIST_PRIMARY] = now; - m_lastIdle[WIFI_CHANLIST_PRIMARY] = {now, now}; + const auto now = Simulator::Now(); + + m_lastBusyEnd.emplace(WIFI_CHANLIST_PRIMARY, now); + m_lastIdle.emplace(WIFI_CHANLIST_PRIMARY, Timespan{now, now}); + + const auto width = m_phy ? m_phy->GetChannelWidth() : 0; + std::size_t size = + (width > 20 && m_phy->GetStandard() >= WIFI_STANDARD_80211ax) ? width / 20 : 0; + m_lastPer20MHzBusyEnd.resize(size, now); if (!m_phy || !m_phy->GetOperatingChannel().IsOfdm()) { return; } - const auto width = m_phy->GetChannelWidth(); - if (width >= 40) { - m_lastBusyEnd[WIFI_CHANLIST_SECONDARY] = now; - m_lastIdle[WIFI_CHANLIST_SECONDARY] = {now, now}; + m_lastBusyEnd.emplace(WIFI_CHANLIST_SECONDARY, now); + m_lastIdle.emplace(WIFI_CHANLIST_SECONDARY, Timespan{now, now}); } + else + { + m_lastBusyEnd.erase(WIFI_CHANLIST_SECONDARY); + m_lastIdle.erase(WIFI_CHANLIST_SECONDARY); + } + if (width >= 80) { - m_lastBusyEnd[WIFI_CHANLIST_SECONDARY40] = now; - m_lastIdle[WIFI_CHANLIST_SECONDARY40] = {now, now}; + m_lastBusyEnd.emplace(WIFI_CHANLIST_SECONDARY40, now); + m_lastIdle.emplace(WIFI_CHANLIST_SECONDARY40, Timespan{now, now}); + } + else + { + m_lastBusyEnd.erase(WIFI_CHANLIST_SECONDARY40); + m_lastIdle.erase(WIFI_CHANLIST_SECONDARY40); } + if (width >= 160) { - m_lastBusyEnd[WIFI_CHANLIST_SECONDARY80] = now; - m_lastIdle[WIFI_CHANLIST_SECONDARY80] = {now, now}; + m_lastBusyEnd.emplace(WIFI_CHANLIST_SECONDARY80, now); + m_lastIdle.emplace(WIFI_CHANLIST_SECONDARY80, Timespan{now, now}); } + else + { + m_lastBusyEnd.erase(WIFI_CHANLIST_SECONDARY80); + m_lastIdle.erase(WIFI_CHANLIST_SECONDARY80); + } + // TODO Add conditions for new channel widths as they get supported +} + +void +ChannelAccessManager::InitLastBusyStructs() +{ + NS_LOG_FUNCTION(this); + Time now = Simulator::Now(); + + ResizeLastBusyStructs(); + + // reset all values + for (auto& [chType, time] : m_lastBusyEnd) + { + time = now; + } + + for (auto& [chType, timeSpan] : m_lastIdle) + { + timeSpan = Timespan{now, now}; + } - if (m_phy->GetStandard() >= WIFI_STANDARD_80211ax && width > 20) + for (auto& time : m_lastPer20MHzBusyEnd) { - m_lastPer20MHzBusyEnd.assign(width / 20, now); + time = now; } } diff --git a/src/wifi/model/channel-access-manager.h b/src/wifi/model/channel-access-manager.h index 5cbc57347c..ef5bccd044 100644 --- a/src/wifi/model/channel-access-manager.h +++ b/src/wifi/model/channel-access-manager.h @@ -362,11 +362,17 @@ class ChannelAccessManager : public Object std::shared_ptr GetPhyListener(Ptr phy) const; /** - * Initialize the structures holding busy end times per channel type (primary, - * secondary, etc.) and per 20 MHz channel. + * Initialize the structures holding busy end times per channel type (primary, secondary, etc.) + * and per 20 MHz channel. All values are set to the current time. */ void InitLastBusyStructs(); + /** + * Resize the structures holding busy end times per channel type (primary, secondary, etc.) + * and per 20 MHz channel. If a value (e.g., the busy end time for secondary40 channel) already + * exists, it is not changed; otherwise, it is set to the current time. + */ + void ResizeLastBusyStructs(); /** * Update backoff slots for all Txops. */