From ac99256d5077d87ac0c0cd754b30434021bd6ed3 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Thu, 28 Apr 2022 15:24:58 +0200 Subject: [PATCH] wifi: Add a ChannelAccessManager method to compute the largest available primary channel --- src/wifi/model/channel-access-manager.cc | 34 ++++++++++++++++++++++++ src/wifi/model/channel-access-manager.h | 13 +++++++++ 2 files changed, 47 insertions(+) diff --git a/src/wifi/model/channel-access-manager.cc b/src/wifi/model/channel-access-manager.cc index 6bb8a0a80..6aceb5deb 100644 --- a/src/wifi/model/channel-access-manager.cc +++ b/src/wifi/model/channel-access-manager.cc @@ -565,6 +565,40 @@ ChannelAccessManager::DoRestartAccessTimeoutIfNeeded (void) } } +uint16_t +ChannelAccessManager::GetLargestIdlePrimaryChannel (Time interval, Time end) +{ + NS_LOG_FUNCTION (this << interval.As (Time::US) << end.As (Time::S)); + + // If the medium is busy or it just became idle, UpdateLastIdlePeriod does + // nothing. This allows us to call this method, e.g., at the end of a frame + // reception and check the busy/idle status of the channel before the start + // of the frame reception (last idle period was last updated at the start of + // the frame reception). + // If the medium has been idle for some time, UpdateLastIdlePeriod updates + // the last idle period. This is normally what we want because this method may + // also be called before starting a TXOP gained through EDCA. + UpdateLastIdlePeriod (); + + uint16_t width = 0; + + // we iterate over the different types of channels in the same order as they + // are listed in WifiChannelListType + for (const auto& lastIdle : m_lastIdle) + { + if (lastIdle.second.start <= end -interval && lastIdle.second.end >= end) + { + // channel idle, update width + width = (width == 0) ? 20 : (2 * width); + } + else + { + break; + } + } + return width; +} + void ChannelAccessManager::DisableEdcaFor (Ptr qosTxop, Time duration) { diff --git a/src/wifi/model/channel-access-manager.h b/src/wifi/model/channel-access-manager.h index 74a7e10ef..1c4061ad6 100644 --- a/src/wifi/model/channel-access-manager.h +++ b/src/wifi/model/channel-access-manager.h @@ -127,6 +127,19 @@ public: */ void DisableEdcaFor (Ptr qosTxop, Time duration); + /** + * Return the width of the largest primary channel that has been idle for the + * given time interval before the given time, if any primary channel has been + * idle, or zero, otherwise. + * + * \param interval the given time interval + * \param end the given end time + * \return the width of the largest primary channel that has been idle for the + * given time interval before the given time, if any primary channel has + * been idle, or zero, otherwise + */ + uint16_t GetLargestIdlePrimaryChannel (Time interval, Time end); + /** * \param duration expected duration of reception *