A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-ru.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
7 */
8
9#include "wifi-ru.h"
10
11#include <algorithm>
12
13namespace ns3
14{
15
16WifiRu::RuSpecCompare::RuSpecCompare(MHz_u channelWidth, uint8_t p20Index)
17 : m_channelWidth(channelWidth),
18 m_p20Index(p20Index)
19{
20}
21
22bool
23WifiRu::RuSpecCompare::operator()(const RuSpec& lhs, const RuSpec& rhs) const
24{
25 const auto lhsIndex = WifiRu::GetPhyIndex(lhs, m_channelWidth, m_p20Index);
26 const auto rhsIndex = WifiRu::GetPhyIndex(rhs, m_channelWidth, m_p20Index);
27 const auto lhsStartTone =
28 WifiRu::GetSubcarrierGroup(m_channelWidth,
30 lhsIndex,
32 .front()
33 .first;
34 const auto rhsStartTone =
35 WifiRu::GetSubcarrierGroup(m_channelWidth,
37 rhsIndex,
39 .front()
40 .first;
41 return lhsStartTone < rhsStartTone;
42}
43
46{
47 return std::visit([&](auto&& ru) { return ru.GetRuType(); }, ruVariant);
48}
49
50std::size_t
52{
53 return std::visit([&](auto&& ru) { return ru.GetIndex(); }, ruVariant);
54}
55
56std::size_t
57WifiRu::GetPhyIndex(RuSpec ruVariant, MHz_u bw, uint8_t p20Index)
58{
59 return std::visit([&](auto&& ru) { return ru.GetPhyIndex(bw, p20Index); }, ruVariant);
60}
61
64{
65 switch (mc)
66 {
71 default:
72 NS_ABORT_MSG("Unknown modulation class: " << mc);
74 }
75}
76
79{
80 switch (ruType)
81 {
83 return MHz_u{2};
85 return MHz_u{4};
87 return MHz_u{8};
89 return MHz_u{20};
91 return MHz_u{40};
93 return MHz_u{80};
95 return MHz_u{160};
97 return MHz_u{320};
98 default:
99 NS_ABORT_MSG("RU type " << ruType << " not found");
100 return MHz_u{0};
101 }
102}
103
104RuType
106{
107 switch (static_cast<uint16_t>(bandwidth))
108 {
109 case 2:
110 return RuType::RU_26_TONE;
111 case 4:
112 return RuType::RU_52_TONE;
113 case 8:
114 return RuType::RU_106_TONE;
115 case 20:
116 return RuType::RU_242_TONE;
117 case 40:
118 return RuType::RU_484_TONE;
119 case 80:
120 return RuType::RU_996_TONE;
121 case 160:
123 case 320:
125 default:
126 NS_ABORT_MSG(bandwidth << " bandwidth not found");
127 return RuType::RU_TYPE_MAX;
128 }
129}
130
131std::size_t
133{
134 if (ruType > GetMaxRuType(mc))
135 {
136 return 0;
137 }
138 return (mc == WIFI_MOD_CLASS_HE) ? HeRu::GetNRus(bw, ruType) : EhtRu::GetNRus(bw, ruType);
139}
140
142WifiRu::GetSubcarrierGroup(MHz_u bw, RuType ruType, std::size_t phyIndex, WifiModulationClass mc)
143{
144 return (mc == WIFI_MOD_CLASS_HE) ? HeRu::GetSubcarrierGroup(bw, ruType, phyIndex)
145 : EhtRu::GetSubcarrierGroup(bw, ruType, phyIndex);
146}
147
148uint16_t
149WifiRu::GetEqualizedRuAllocation(RuType ruType, bool isOdd, bool hasUsers, WifiModulationClass mc)
150{
151 return (mc == WIFI_MOD_CLASS_HE) ? HeRu::GetEqualizedRuAllocation(ruType, isOdd, hasUsers)
152 : EhtRu::GetEqualizedRuAllocation(ruType, isOdd, hasUsers);
153}
154
155std::vector<WifiRu::RuSpec>
156WifiRu::GetRuSpecs(uint16_t ruAllocation, WifiModulationClass mc)
157{
158 std::vector<RuSpec> ruSpecs;
159 if (mc == WIFI_MOD_CLASS_HE)
160 {
161 auto heRuSpecs = HeRu::GetRuSpecs(ruAllocation);
162 std::copy(heRuSpecs.begin(), heRuSpecs.end(), std::back_inserter(ruSpecs));
163 }
164 else
165 {
166 auto ehtRuSpecs = EhtRu::GetRuSpecs(ruAllocation);
167 std::copy(ehtRuSpecs.begin(), ehtRuSpecs.end(), std::back_inserter(ruSpecs));
168 }
169 return ruSpecs;
170}
171
172std::vector<WifiRu::RuSpec>
174{
175 std::vector<RuSpec> rus;
176 if (mc == WIFI_MOD_CLASS_HE)
177 {
178 auto heRuSpecs = HeRu::GetRusOfType(bw, ruType);
179 std::copy(heRuSpecs.begin(), heRuSpecs.end(), std::back_inserter(rus));
180 }
181 else
182 {
183 auto ehtRuSpecs = EhtRu::GetRusOfType(bw, ruType);
184 std::copy(ehtRuSpecs.begin(), ehtRuSpecs.end(), std::back_inserter(rus));
185 }
186 return rus;
187}
188
189std::vector<WifiRu::RuSpec>
191{
192 std::vector<RuSpec> central26TonesRus;
193 if (mc == WIFI_MOD_CLASS_HE)
194 {
195 auto heRuSpecs = HeRu::GetCentral26TonesRus(bw, ruType);
196 std::copy(heRuSpecs.begin(), heRuSpecs.end(), std::back_inserter(central26TonesRus));
197 }
198 else
199 {
200 auto ehtRuSpecs = EhtRu::GetCentral26TonesRus(bw, ruType);
201 std::copy(ehtRuSpecs.begin(), ehtRuSpecs.end(), std::back_inserter(central26TonesRus));
202 }
203 return central26TonesRus;
204}
205
206bool
207WifiRu::DoesOverlap(MHz_u bw, RuSpec ru, const std::vector<RuSpec>& v)
208{
209 if (IsHe(ru))
210 {
211 std::vector<HeRu::RuSpec> heRus;
212 std::transform(v.cbegin(), v.cend(), std::back_inserter(heRus), [](const auto& heRu) {
213 return std::get<HeRu::RuSpec>(heRu);
214 });
215 return HeRu::DoesOverlap(bw, std::get<HeRu::RuSpec>(ru), heRus);
216 }
217
218 std::vector<EhtRu::RuSpec> ehtRus;
219 std::transform(v.cbegin(), v.cend(), std::back_inserter(ehtRus), [](const auto& ehtRu) {
220 return std::get<EhtRu::RuSpec>(ehtRu);
221 });
222 return EhtRu::DoesOverlap(bw, std::get<EhtRu::RuSpec>(ru), ehtRus);
223}
224
226WifiRu::FindOverlappingRu(MHz_u bw, RuSpec referenceRu, RuType searchedRuType)
227{
228 return IsHe(referenceRu) ? RuSpec{HeRu::FindOverlappingRu(bw,
229 std::get<HeRu::RuSpec>(referenceRu),
230 searchedRuType)}
232 std::get<EhtRu::RuSpec>(referenceRu),
233 searchedRuType)};
234}
235
236RuType
238 std::size_t& nStations,
239 std::size_t& nCentral26TonesRus,
241{
242 return (mc == WIFI_MOD_CLASS_HE)
243 ? HeRu::GetEqualSizedRusForStations(bandwidth, nStations, nCentral26TonesRus)
244 : EhtRu::GetEqualSizedRusForStations(bandwidth, nStations, nCentral26TonesRus);
245}
246
247bool
249{
250 return std::holds_alternative<HeRu::RuSpec>(ru);
251}
252
253bool
255{
256 return std::holds_alternative<EhtRu::RuSpec>(ru);
257}
258
259std::ostream&
260operator<<(std::ostream& os, const WifiRu::RuSpec& ruVariant)
261{
262 std::visit([&os](auto&& arg) { os << arg; }, ruVariant);
263 return os;
264}
265
266} // namespace ns3
static bool DoesOverlap(MHz_u bw, RuSpec ru, const std::vector< RuSpec > &v)
Check whether the given RU overlaps with the given set of RUs.
Definition eht-ru.cc:1072
static uint16_t GetEqualizedRuAllocation(RuType ruType, bool isOdd, bool hasUsers)
Get the RU_ALLOCATION value for equal size RUs.
Definition eht-ru.cc:821
static std::vector< RuSpec > GetRusOfType(MHz_u bw, RuType ruType)
Get the set of distinct RUs of the given type (number of tones) available in an PPDU of the given ban...
Definition eht-ru.cc:988
static std::vector< RuSpec > GetRuSpecs(uint16_t ruAllocation)
Get the RU specs based on RU_ALLOCATION.
Definition eht-ru.cc:798
static SubcarrierGroup GetSubcarrierGroup(MHz_u bw, RuType ruType, std::size_t phyIndex)
Get the subcarrier group of the RU having the given PHY index among all the RUs of the given type (nu...
Definition eht-ru.cc:1064
static std::vector< RuSpec > GetCentral26TonesRus(MHz_u bw, RuType ruType)
Get the set of 26-tone RUs that can be additionally allocated if the given bandwidth is split in RUs ...
Definition eht-ru.cc:1027
static RuSpec FindOverlappingRu(MHz_u bw, RuSpec referenceRu, RuType searchedRuType)
Find the RU allocation of the given RU type overlapping the given reference RU allocation.
Definition eht-ru.cc:1121
static RuType GetEqualSizedRusForStations(MHz_u bandwidth, std::size_t &nStations, std::size_t &nCentral26TonesRus)
Given the channel bandwidth and the number of stations candidate for being assigned an RU,...
Definition eht-ru.cc:1143
static std::size_t GetNRus(MHz_u bw, RuType ruType, bool includeUndefinedRus=false)
Get the number of distinct RUs of the given type (number of tones) available in a PPDU of the given b...
Definition eht-ru.cc:963
static std::vector< RuSpec > GetRuSpecs(uint16_t ruAllocation)
Get the RU specs based on RU_ALLOCATION.
Definition he-ru.cc:365
static bool DoesOverlap(MHz_u bw, RuSpec ru, const std::vector< RuSpec > &v)
Check whether the given RU overlaps with the given set of RUs.
Definition he-ru.cc:631
static std::vector< RuSpec > GetRusOfType(MHz_u bw, RuType ruType)
Get the set of distinct RUs of the given type (number of tones) available in a HE PPDU of the given b...
Definition he-ru.cc:511
static SubcarrierGroup GetSubcarrierGroup(MHz_u bw, RuType ruType, std::size_t phyIndex)
Get the subcarrier group of the RU having the given PHY index among all the RUs of the given type (nu...
Definition he-ru.cc:592
static RuSpec FindOverlappingRu(MHz_u bw, RuSpec referenceRu, RuType searchedRuType)
Find the RU allocation of the given RU type overlapping the given reference RU allocation.
Definition he-ru.cc:673
static std::size_t GetNRus(MHz_u bw, RuType ruType)
Get the number of distinct RUs of the given type (number of tones) available in a HE PPDU of the give...
Definition he-ru.cc:491
static RuType GetEqualSizedRusForStations(MHz_u bandwidth, std::size_t &nStations, std::size_t &nCentral26TonesRus)
Given the channel bandwidth and the number of stations candidate for being assigned an RU,...
Definition he-ru.cc:719
static std::vector< RuSpec > GetCentral26TonesRus(MHz_u bw, RuType ruType)
Get the set of 26-tone RUs that can be additionally allocated if the given bandwidth is split in RUs ...
Definition he-ru.cc:546
static uint16_t GetEqualizedRuAllocation(RuType ruType, bool isOdd, bool hasUsers)
Get the RU_ALLOCATION value for equal size RUs.
Definition he-ru.cc:397
static std::vector< RuSpec > GetRuSpecs(uint16_t ruAllocation, WifiModulationClass mc)
Get the RU specs based on RU_ALLOCATION.
Definition wifi-ru.cc:156
static std::size_t GetNRus(MHz_u bw, RuType ruType, WifiModulationClass mc)
Get the number of distinct RUs of the given type (number of tones) available in a PPDU of the given b...
Definition wifi-ru.cc:132
std::variant< HeRu::RuSpec, EhtRu::RuSpec > RuSpec
variant of the RU specification
Definition wifi-ru.h:27
static std::vector< RuSpec > GetRusOfType(MHz_u bw, RuType ruType, WifiModulationClass mc)
Get the set of distinct RUs of the given type (number of tones) available in an MU PPDU of the given ...
Definition wifi-ru.cc:173
static bool IsHe(RuSpec ru)
Get whether a given RU variant is a HE RU.
Definition wifi-ru.cc:248
static RuSpec FindOverlappingRu(MHz_u bw, RuSpec referenceRu, RuType searchedRuType)
Find the RU allocation of the given RU type overlapping the given reference RU allocation.
Definition wifi-ru.cc:226
static MHz_u GetBandwidth(RuType ruType)
Get the approximate bandwidth occupied by a RU.
Definition wifi-ru.cc:78
static RuType GetEqualSizedRusForStations(MHz_u bandwidth, std::size_t &nStations, std::size_t &nCentral26TonesRus, WifiModulationClass mc)
Given the channel bandwidth and the number of stations candidate for being assigned an RU,...
Definition wifi-ru.cc:237
static RuType GetRuType(RuSpec ru)
Get the type of a given RU.
Definition wifi-ru.cc:45
static SubcarrierGroup GetSubcarrierGroup(MHz_u bw, RuType ruType, std::size_t phyIndex, WifiModulationClass mc)
Get the subcarrier group of the RU having the given PHY index among all the RUs of the given type (nu...
Definition wifi-ru.cc:142
static std::vector< RuSpec > GetCentral26TonesRus(MHz_u bw, RuType ruType, WifiModulationClass mc)
Get the set of 26-tone RUs that can be additionally allocated if the given bandwidth is split in RUs ...
Definition wifi-ru.cc:190
static bool DoesOverlap(MHz_u bw, RuSpec ru, const std::vector< RuSpec > &v)
Check whether the given RU overlaps with the given set of RUs.
Definition wifi-ru.cc:207
static uint16_t GetEqualizedRuAllocation(RuType ruType, bool isOdd, bool hasUsers, WifiModulationClass mc)
Get the RU_ALLOCATION value for equal size RUs.
Definition wifi-ru.cc:149
static std::size_t GetPhyIndex(RuSpec ru, MHz_u bw, uint8_t p20Index)
Get the RU PHY index.
Definition wifi-ru.cc:57
static std::size_t GetIndex(RuSpec ru)
Get the index of a given RU.
Definition wifi-ru.cc:51
static bool IsEht(RuSpec ru)
Get whether a given RU variant is a EHT RU.
Definition wifi-ru.cc:254
static RuType GetMaxRuType(WifiModulationClass mc)
Get the maximum RU type supported by a given modulation class.
Definition wifi-ru.cc:63
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
@ WIFI_MOD_CLASS_EHT
EHT (Clause 36)
@ WIFI_MOD_CLASS_HE
HE (Clause 27)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
RuType
The different Resource Unit (RU) types.
Definition wifi-types.h:98
std::vector< SubcarrierRange > SubcarrierGroup
a vector of subcarrier ranges defining a subcarrier group
Definition wifi-types.h:156
double MHz_u
MHz weak type.
Definition wifi-units.h:31
RuSpecCompare(MHz_u channelWidth, uint8_t p20Index)
Constructor.
Definition wifi-ru.cc:16
bool operator()(const RuSpec &lhs, const RuSpec &rhs) const
Function call operator.
Definition wifi-ru.cc:23