From 2d15c8d4d8044c6f660579e843655bd143522729 Mon Sep 17 00:00:00 2001 From: Rediet Date: Mon, 6 Jul 2020 16:08:05 +0200 Subject: [PATCH] wifi: Add methods to HeRu Also switch to uint16_t for bandwidth in HeRu --- src/wifi/model/he-ru.cc | 92 +++++++++++++++++++++++++++-------------- src/wifi/model/he-ru.h | 33 +++++++++------ 2 files changed, 81 insertions(+), 44 deletions(-) diff --git a/src/wifi/model/he-ru.cc b/src/wifi/model/he-ru.cc index 20ca15996..4d96244e7 100644 --- a/src/wifi/model/he-ru.cc +++ b/src/wifi/model/he-ru.cc @@ -149,7 +149,7 @@ const HeRu::SubcarrierGroups HeRu::m_heRuSubcarrierGroups = std::size_t -HeRu::GetNRus (uint8_t bw, RuType ruType) +HeRu::GetNRus (uint16_t bw, RuType ruType) { if (bw == 160 && ruType == RU_2x996_TONE) { @@ -169,7 +169,7 @@ HeRu::GetNRus (uint8_t bw, RuType ruType) } HeRu::SubcarrierGroup -HeRu::GetSubcarrierGroup (uint8_t bw, RuType ruType, std::size_t index) +HeRu::GetSubcarrierGroup (uint16_t bw, RuType ruType, std::size_t index) { if (ruType == HeRu::RU_2x996_TONE) //handle special case of RU covering 160 MHz channel { @@ -208,7 +208,7 @@ HeRu::GetSubcarrierGroup (uint8_t bw, RuType ruType, std::size_t index) } bool -HeRu::DoesOverlap (uint8_t bw, RuSpec ru, const std::vector &v) +HeRu::DoesOverlap (uint16_t bw, RuSpec ru, const std::vector &v) { // A 2x996-tone RU spans 160 MHz, hence it overlaps with any other RU if (bw == 160 && ru.ruType == RU_2x996_TONE && !v.empty ()) @@ -233,7 +233,7 @@ HeRu::DoesOverlap (uint8_t bw, RuSpec ru, const std::vector &v) } bool -HeRu::DoesOverlap (uint8_t bw, RuSpec ru, const SubcarrierGroup &toneRanges) +HeRu::DoesOverlap (uint16_t bw, RuSpec ru, const SubcarrierGroup &toneRanges) { for (const auto & range : toneRanges) { @@ -254,6 +254,44 @@ HeRu::DoesOverlap (uint8_t bw, RuSpec ru, const SubcarrierGroup &toneRanges) return false; } +HeRu::RuSpec +HeRu::FindOverlappingRu (uint16_t bw, RuSpec referenceRu, RuType searchedRuType) +{ + RuSpec searchedRu; + searchedRu.ruType = searchedRuType; + std::size_t numRus = HeRu::GetNRus (bw, searchedRuType); + + std::size_t numRusPer80Mhz; + std::vector primary80MhzFlags; + if (bw == 160) + { + primary80MhzFlags.push_back (true); + primary80MhzFlags.push_back (false); + numRusPer80Mhz = numRus / 2; + } + else + { + primary80MhzFlags.push_back (referenceRu.primary80MHz); + numRusPer80Mhz = numRus; + } + + std::size_t index = 1; + for (const auto primary80Mhz : primary80MhzFlags) + { + searchedRu.primary80MHz = primary80Mhz; + for (std::size_t indexPer80Mhz = 1; indexPer80Mhz <= numRusPer80Mhz; ++indexPer80Mhz, ++index) + { + searchedRu.index = index; + if (DoesOverlap (bw, referenceRu, {searchedRu})) + { + return searchedRu; + } + } + } + NS_ABORT_MSG ("The searched RU type " << searchedRuType << " was not found for bw=" << bw << " and referenceRu=" << referenceRu); + return searchedRu; +} + std::ostream& operator<< (std::ostream& os, const HeRu::RuType &ruType) { switch (ruType) @@ -317,36 +355,28 @@ HeRu::GetBandwidth (RuType ruType) } HeRu::RuType -HeRu::GetEqualSizedRusForStations (uint16_t bandwidth, std::size_t& nStations) +HeRu::GetRuType (uint16_t bandwidth) { - RuType ruType; - uint8_t nRusAssigned = 0; - - // iterate over all the available RU types - for (auto& ru : m_heRuSubcarrierGroups) + switch (bandwidth) { - if (ru.first.first == bandwidth && ru.second.size () <= nStations) - { - ruType = ru.first.second; - nRusAssigned = ru.second.size (); - break; - } - else if (bandwidth == 160 && ru.first.first == 80 && (2 * ru.second.size () <= nStations)) - { - ruType = ru.first.second; - nRusAssigned = 2 * ru.second.size (); - break; - } + case 2: + return RU_26_TONE; + case 4: + return RU_52_TONE; + case 8: + return RU_106_TONE; + case 20: + return RU_242_TONE; + case 40: + return RU_484_TONE; + case 80: + return RU_996_TONE; + case 160: + return RU_2x996_TONE; + default: + NS_ABORT_MSG (bandwidth << " MHz bandwidth not found"); + return RU_242_TONE; } - if (nRusAssigned == 0) - { - NS_ABORT_IF (bandwidth != 160 || nStations != 1); - nRusAssigned = 1; - ruType = RU_2x996_TONE; - } - - nStations = nRusAssigned; - return ruType; } } //namespace ns3 diff --git a/src/wifi/model/he-ru.h b/src/wifi/model/he-ru.h index e2cd2dd2f..26254f85b 100644 --- a/src/wifi/model/he-ru.h +++ b/src/wifi/model/he-ru.h @@ -23,9 +23,9 @@ #include #include - #include #include + namespace ns3 { @@ -77,7 +77,7 @@ public: * \param ruType the RU type (number of tones) * \return the number of distinct RUs available */ - static std::size_t GetNRus (uint8_t bw, RuType ruType); + static std::size_t GetNRus (uint16_t bw, RuType ruType); /** * Get the subcarrier group of the RU having the given index among all the @@ -93,7 +93,7 @@ public: * \param index the index (starting at 1) of the RU * \return the subcarrier range of the specified RU */ - static SubcarrierGroup GetSubcarrierGroup (uint8_t bw, RuType ruType, std::size_t index); + static SubcarrierGroup GetSubcarrierGroup (uint16_t bw, RuType ruType, std::size_t index); /** * Check whether the given RU overlaps with the given set of RUs. @@ -105,7 +105,7 @@ public: * \param v the given set of RUs * \return true if the given RU overlaps with the given set of RUs. */ - static bool DoesOverlap (uint8_t bw, RuSpec ru, const std::vector &v); + static bool DoesOverlap (uint16_t bw, RuSpec ru, const std::vector &v); /** * Check whether the given RU overlaps with the given tone ranges. @@ -117,7 +117,19 @@ public: * \param toneRanges the given set of tone ranges * \return true if the given RU overlaps with the given set of tone ranges. */ - static bool DoesOverlap (uint8_t bw, RuSpec ru, const SubcarrierGroup &toneRanges); + static bool DoesOverlap (uint16_t bw, RuSpec ru, const SubcarrierGroup &toneRanges); + + /** + * Find the RU allocation of the given RU type overlapping the given + * reference RU allocation. + * Note that an assert is generated if the RU allocation is not found. + * + * \param bw the bandwidth (MHz) of the HE PPDU (20, 40, 80, 160) + * \param referenceRu the reference RU allocation + * \param searchedRuType the searched RU type + * \return the searched RU allocation. + */ + static RuSpec FindOverlappingRu (uint16_t bw, RuSpec referenceRu, RuType searchedRuType); /** * Get the approximate bandwidth occupied by a RU. @@ -128,17 +140,12 @@ public: static uint16_t GetBandwidth (RuType ruType); /** - * Given the channel bandwidth and the number of stations candidate for being - * assigned an RU, maximize the number of candidate stations that can be assigned - * an RU subject to the constraint that all the stations must be assigned an RU - * of the same size (in terms of number of tones). + * Get the RU corresponding to the approximate bandwidth. * - * \param bandwidth the channel bandwidth in MHz - * \param nStations the number of candidate stations. On return, it is set to - * the number of stations that are assigned an RU + * \param bandwidth the approximate bandwidth (in MHz) occupied by the RU * \return the RU type */ - static RuType GetEqualSizedRusForStations (uint16_t bandwidth, std::size_t& nStations); + static RuType GetRuType (uint16_t bandwidth); /// (bandwidth, number of tones) pair typedef std::pair BwTonesPair;