A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
he-ru.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Stefano Avallone <stavallo@unina.it>
18 */
19
20#include "he-ru.h"
21
22#include "ns3/abort.h"
23#include "ns3/assert.h"
24
25#include <optional>
26
27namespace ns3
28{
29
31 // RUs in a 20 MHz HE PPDU (Table 28-6)
32 {{20, HeRu::RU_26_TONE},
33 {/* 1 */ {{-121, -96}},
34 /* 2 */ {{-95, -70}},
35 /* 3 */ {{-68, -43}},
36 /* 4 */ {{-42, -17}},
37 /* 5 */ {{-16, -4}, {4, 16}},
38 /* 6 */ {{17, 42}},
39 /* 7 */ {{43, 68}},
40 /* 8 */ {{70, 95}},
41 /* 9 */ {{96, 121}}}},
42 {{20, HeRu::RU_52_TONE},
43 {/* 1 */ {{-121, -70}},
44 /* 2 */ {{-68, -17}},
45 /* 3 */ {{17, 68}},
46 /* 4 */ {{70, 121}}}},
47 {{20, HeRu::RU_106_TONE},
48 {/* 1 */ {{-122, -17}},
49 /* 2 */ {{17, 122}}}},
50 {{20, HeRu::RU_242_TONE}, {/* 1 */ {{-122, -2}, {2, 122}}}},
51 // RUs in a 40 MHz HE PPDU (Table 28-7)
52 {{40, HeRu::RU_26_TONE},
53 {/* 1 */ {{-243, -218}},
54 /* 2 */ {{-217, -192}},
55 /* 3 */ {{-189, -164}},
56 /* 4 */ {{-163, -138}},
57 /* 5 */ {{-136, -111}},
58 /* 6 */ {{-109, -84}},
59 /* 7 */ {{-83, -58}},
60 /* 8 */ {{-55, -30}},
61 /* 9 */ {{-29, -4}},
62 /* 10 */ {{4, 29}},
63 /* 11 */ {{30, 55}},
64 /* 12 */ {{58, 83}},
65 /* 13 */ {{84, 109}},
66 /* 14 */ {{111, 136}},
67 /* 15 */ {{138, 163}},
68 /* 16 */ {{164, 189}},
69 /* 17 */ {{192, 217}},
70 /* 18 */ {{218, 243}}}},
71 {{40, HeRu::RU_52_TONE},
72 {/* 1 */ {{-243, -192}},
73 /* 2 */ {{-189, -138}},
74 /* 3 */ {{-109, -58}},
75 /* 4 */ {{-55, -4}},
76 /* 5 */ {{4, 55}},
77 /* 6 */ {{58, 109}},
78 /* 7 */ {{138, 189}},
79 /* 8 */ {{192, 243}}}},
80 {{40, HeRu::RU_106_TONE},
81 {/* 1 */ {{-243, -138}},
82 /* 2 */ {{-109, -4}},
83 /* 3 */ {{4, 109}},
84 /* 4 */ {{138, 243}}}},
85 {{40, HeRu::RU_242_TONE},
86 {/* 1 */ {{-244, -3}},
87 /* 2 */ {{3, 244}}}},
88 {{40, HeRu::RU_484_TONE}, {/* 1 */ {{-244, -3}, {3, 244}}}},
89 // RUs in an 80 MHz HE PPDU (Table 28-8)
90 {{80, HeRu::RU_26_TONE},
91 {/* 1 */ {{-499, -474}},
92 /* 2 */ {{-473, -448}},
93 /* 3 */ {{-445, -420}},
94 /* 4 */ {{-419, -394}},
95 /* 5 */ {{-392, -367}},
96 /* 6 */ {{-365, -340}},
97 /* 7 */ {{-339, -314}},
98 /* 8 */ {{-311, -286}},
99 /* 9 */ {{-285, -260}},
100 /* 10 */ {{-257, -232}},
101 /* 11 */ {{-231, -206}},
102 /* 12 */ {{-203, -178}},
103 /* 13 */ {{-177, -152}},
104 /* 14 */ {{-150, -125}},
105 /* 15 */ {{-123, -98}},
106 /* 16 */ {{-97, -72}},
107 /* 17 */ {{-69, -44}},
108 /* 18 */ {{-43, -18}},
109 /* 19 */ {{-16, -4}, {4, 16}},
110 /* 20 */ {{18, 43}},
111 /* 21 */ {{44, 69}},
112 /* 22 */ {{72, 97}},
113 /* 23 */ {{98, 123}},
114 /* 24 */ {{125, 150}},
115 /* 25 */ {{152, 177}},
116 /* 26 */ {{178, 203}},
117 /* 27 */ {{206, 231}},
118 /* 28 */ {{232, 257}},
119 /* 29 */ {{260, 285}},
120 /* 30 */ {{286, 311}},
121 /* 31 */ {{314, 339}},
122 /* 32 */ {{340, 365}},
123 /* 33 */ {{367, 392}},
124 /* 34 */ {{394, 419}},
125 /* 35 */ {{420, 445}},
126 /* 36 */ {{448, 473}},
127 /* 37 */ {{474, 499}}}},
128 {{80, HeRu::RU_52_TONE},
129 {/* 1 */ {{-499, -448}},
130 /* 2 */ {{-445, -394}},
131 /* 3 */ {{-365, -314}},
132 /* 4 */ {{-311, -260}},
133 /* 5 */ {{-257, -206}},
134 /* 6 */ {{-203, -152}},
135 /* 7 */ {{-123, -72}},
136 /* 8 */ {{-69, -18}},
137 /* 9 */ {{18, 69}},
138 /* 10 */ {{72, 123}},
139 /* 11 */ {{152, 203}},
140 /* 12 */ {{206, 257}},
141 /* 13 */ {{260, 311}},
142 /* 14 */ {{314, 365}},
143 /* 15 */ {{394, 445}},
144 /* 16 */ {{448, 499}}}},
145 {{80, HeRu::RU_106_TONE},
146 {/* 1 */ {{-499, -394}},
147 /* 2 */ {{-365, -260}},
148 /* 3 */ {{-257, -152}},
149 /* 4 */ {{-123, -18}},
150 /* 5 */ {{18, 123}},
151 /* 6 */ {{152, 257}},
152 /* 7 */ {{260, 365}},
153 /* 8 */ {{394, 499}}}},
154 {{80, HeRu::RU_242_TONE},
155 {/* 1 */ {{-500, -259}},
156 /* 2 */ {{-258, -17}},
157 /* 3 */ {{17, 258}},
158 /* 4 */ {{259, 500}}}},
159 {{80, HeRu::RU_484_TONE},
160 {/* 1 */ {{-500, -17}},
161 /* 2 */ {{17, 500}}}},
162 {{80, HeRu::RU_996_TONE}, {/* 1 */ {{-500, -3}, {3, 500}}}},
163};
164
165// Table 27-26 IEEE802.11ax-2021
167 // clang-format off
168 {0,
169 {HeRu::RuSpec{HeRu::RU_26_TONE, 1, true},
170 HeRu::RuSpec{HeRu::RU_26_TONE, 2, true},
171 HeRu::RuSpec{HeRu::RU_26_TONE, 3, true},
172 HeRu::RuSpec{HeRu::RU_26_TONE, 4, true},
173 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
174 HeRu::RuSpec{HeRu::RU_26_TONE, 6, true},
175 HeRu::RuSpec{HeRu::RU_26_TONE, 7, true},
176 HeRu::RuSpec{HeRu::RU_26_TONE, 8, true},
177 HeRu::RuSpec{HeRu::RU_26_TONE, 9, true}}},
178 {1,
179 {HeRu::RuSpec{HeRu::RU_26_TONE, 1, true},
180 HeRu::RuSpec{HeRu::RU_26_TONE, 2, true},
181 HeRu::RuSpec{HeRu::RU_26_TONE, 3, true},
182 HeRu::RuSpec{HeRu::RU_26_TONE, 4, true},
183 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
184 HeRu::RuSpec{HeRu::RU_26_TONE, 6, true},
185 HeRu::RuSpec{HeRu::RU_26_TONE, 7, true},
186 HeRu::RuSpec{HeRu::RU_52_TONE, 4, true}}},
187 {2,
188 {HeRu::RuSpec{HeRu::RU_26_TONE, 1, true},
189 HeRu::RuSpec{HeRu::RU_26_TONE, 2, true},
190 HeRu::RuSpec{HeRu::RU_26_TONE, 3, true},
191 HeRu::RuSpec{HeRu::RU_26_TONE, 4, true},
192 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
193 HeRu::RuSpec{HeRu::RU_52_TONE, 3, true},
194 HeRu::RuSpec{HeRu::RU_26_TONE, 8, true},
195 HeRu::RuSpec{HeRu::RU_26_TONE, 9, true}}},
196 {3,
197 {HeRu::RuSpec{HeRu::RU_26_TONE, 1, true},
198 HeRu::RuSpec{HeRu::RU_26_TONE, 2, true},
199 HeRu::RuSpec{HeRu::RU_26_TONE, 3, true},
200 HeRu::RuSpec{HeRu::RU_26_TONE, 4, true},
201 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
202 HeRu::RuSpec{HeRu::RU_52_TONE, 3, true},
203 HeRu::RuSpec{HeRu::RU_52_TONE, 4, true}}},
204 {4,
205 {HeRu::RuSpec{HeRu::RU_26_TONE, 1, true},
206 HeRu::RuSpec{HeRu::RU_26_TONE, 2, true},
207 HeRu::RuSpec{HeRu::RU_52_TONE, 2, true},
208 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
209 HeRu::RuSpec{HeRu::RU_26_TONE, 6, true},
210 HeRu::RuSpec{HeRu::RU_26_TONE, 7, true},
211 HeRu::RuSpec{HeRu::RU_26_TONE, 8, true},
212 HeRu::RuSpec{HeRu::RU_26_TONE, 9, true}}},
213 {5,
214 {HeRu::RuSpec{HeRu::RU_26_TONE, 1, true},
215 HeRu::RuSpec{HeRu::RU_26_TONE, 2, true},
216 HeRu::RuSpec{HeRu::RU_52_TONE, 2, true},
217 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
218 HeRu::RuSpec{HeRu::RU_26_TONE, 6, true},
219 HeRu::RuSpec{HeRu::RU_26_TONE, 7, true},
220 HeRu::RuSpec{HeRu::RU_52_TONE, 4, true}}},
221 {6,
222 {HeRu::RuSpec{HeRu::RU_26_TONE, 1, true},
223 HeRu::RuSpec{HeRu::RU_26_TONE, 2, true},
224 HeRu::RuSpec{HeRu::RU_52_TONE, 2, true},
225 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
226 HeRu::RuSpec{HeRu::RU_52_TONE, 3, true},
227 HeRu::RuSpec{HeRu::RU_26_TONE, 8, true},
228 HeRu::RuSpec{HeRu::RU_26_TONE, 9, true}}},
229 {7,
230 {HeRu::RuSpec{HeRu::RU_26_TONE, 1, true},
231 HeRu::RuSpec{HeRu::RU_26_TONE, 2, true},
232 HeRu::RuSpec{HeRu::RU_52_TONE, 2, true},
233 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
234 HeRu::RuSpec{HeRu::RU_52_TONE, 3, true},
235 HeRu::RuSpec{HeRu::RU_52_TONE, 4, true}}},
236 {8,
237 {HeRu::RuSpec{HeRu::RU_52_TONE, 1, true},
238 HeRu::RuSpec{HeRu::RU_26_TONE, 3, true},
239 HeRu::RuSpec{HeRu::RU_26_TONE, 4, true},
240 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
241 HeRu::RuSpec{HeRu::RU_26_TONE, 6, true},
242 HeRu::RuSpec{HeRu::RU_26_TONE, 7, true},
243 HeRu::RuSpec{HeRu::RU_26_TONE, 8, true},
244 HeRu::RuSpec{HeRu::RU_26_TONE, 9, true}}},
245 {9,
246 {HeRu::RuSpec{HeRu::RU_52_TONE, 1, true},
247 HeRu::RuSpec{HeRu::RU_26_TONE, 3, true},
248 HeRu::RuSpec{HeRu::RU_26_TONE, 4, true},
249 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
250 HeRu::RuSpec{HeRu::RU_26_TONE, 6, true},
251 HeRu::RuSpec{HeRu::RU_26_TONE, 7, true},
252 HeRu::RuSpec{HeRu::RU_52_TONE, 4, true}}},
253 {10,
254 {HeRu::RuSpec{HeRu::RU_52_TONE, 1, true},
255 HeRu::RuSpec{HeRu::RU_26_TONE, 3, true},
256 HeRu::RuSpec{HeRu::RU_26_TONE, 4, true},
257 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
258 HeRu::RuSpec{HeRu::RU_52_TONE, 3, true},
259 HeRu::RuSpec{HeRu::RU_26_TONE, 8, true},
260 HeRu::RuSpec{HeRu::RU_26_TONE, 9, true}}},
261 {11,
262 {HeRu::RuSpec{HeRu::RU_52_TONE, 1, true},
263 HeRu::RuSpec{HeRu::RU_26_TONE, 3, true},
264 HeRu::RuSpec{HeRu::RU_26_TONE, 4, true},
265 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
266 HeRu::RuSpec{HeRu::RU_52_TONE, 3, true},
267 HeRu::RuSpec{HeRu::RU_52_TONE, 4, true}}},
268 {12,
269 {HeRu::RuSpec{HeRu::RU_52_TONE, 1, true},
270 HeRu::RuSpec{HeRu::RU_52_TONE, 2, true},
271 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
272 HeRu::RuSpec{HeRu::RU_26_TONE, 6, true},
273 HeRu::RuSpec{HeRu::RU_26_TONE, 7, true},
274 HeRu::RuSpec{HeRu::RU_26_TONE, 8, true},
275 HeRu::RuSpec{HeRu::RU_26_TONE, 9, true}}},
276 {13,
277 {HeRu::RuSpec{HeRu::RU_52_TONE, 1, true},
278 HeRu::RuSpec{HeRu::RU_52_TONE, 2, true},
279 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
280 HeRu::RuSpec{HeRu::RU_26_TONE, 6, true},
281 HeRu::RuSpec{HeRu::RU_26_TONE, 7, true},
282 HeRu::RuSpec{HeRu::RU_52_TONE, 4, true}}},
283 {14,
284 {HeRu::RuSpec{HeRu::RU_52_TONE, 1, true},
285 HeRu::RuSpec{HeRu::RU_52_TONE, 2, true},
286 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
287 HeRu::RuSpec{HeRu::RU_52_TONE, 3, true},
288 HeRu::RuSpec{HeRu::RU_26_TONE, 8, true},
289 HeRu::RuSpec{HeRu::RU_26_TONE, 9, true}}},
290 {15,
291 {HeRu::RuSpec{HeRu::RU_52_TONE, 1, true},
292 HeRu::RuSpec{HeRu::RU_52_TONE, 2, true},
293 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
294 HeRu::RuSpec{HeRu::RU_52_TONE, 3, true},
295 HeRu::RuSpec{HeRu::RU_52_TONE, 4, true}}},
296 {16,
297 {HeRu::RuSpec{HeRu::RU_52_TONE, 1, true},
298 HeRu::RuSpec{HeRu::RU_52_TONE, 2, true},
299 HeRu::RuSpec{HeRu::RU_106_TONE, 2, true}}},
300 {24,
301 {HeRu::RuSpec{HeRu::RU_106_TONE, 1, true},
302 HeRu::RuSpec{HeRu::RU_52_TONE, 3, true},
303 HeRu::RuSpec{HeRu::RU_52_TONE, 4, true}}},
304 {32,
305 {HeRu::RuSpec{HeRu::RU_26_TONE, 1, true},
306 HeRu::RuSpec{HeRu::RU_26_TONE, 2, true},
307 HeRu::RuSpec{HeRu::RU_26_TONE, 3, true},
308 HeRu::RuSpec{HeRu::RU_26_TONE, 4, true},
309 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
310 HeRu::RuSpec{HeRu::RU_106_TONE, 2, true}}},
311 {40,
312 {HeRu::RuSpec{HeRu::RU_26_TONE, 1, true},
313 HeRu::RuSpec{HeRu::RU_26_TONE, 2, true},
314 HeRu::RuSpec{HeRu::RU_52_TONE, 2, true},
315 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
316 HeRu::RuSpec{HeRu::RU_106_TONE, 2, true}}},
317 {48,
318 {HeRu::RuSpec{HeRu::RU_52_TONE, 1, true},
319 HeRu::RuSpec{HeRu::RU_26_TONE, 3, true},
320 HeRu::RuSpec{HeRu::RU_26_TONE, 4, true},
321 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
322 HeRu::RuSpec{HeRu::RU_106_TONE, 2, true}}},
323 {56,
324 {HeRu::RuSpec{HeRu::RU_52_TONE, 1, true},
325 HeRu::RuSpec{HeRu::RU_52_TONE, 2, true},
326 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
327 HeRu::RuSpec{HeRu::RU_106_TONE, 2, true}}},
328 {64,
329 {HeRu::RuSpec{HeRu::RU_106_TONE, 1, true},
330 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
331 HeRu::RuSpec{HeRu::RU_26_TONE, 6, true},
332 HeRu::RuSpec{HeRu::RU_26_TONE, 7, true},
333 HeRu::RuSpec{HeRu::RU_26_TONE, 8, true},
334 HeRu::RuSpec{HeRu::RU_26_TONE, 9, true}}},
335 {72,
336 {HeRu::RuSpec{HeRu::RU_106_TONE, 1, true},
337 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
338 HeRu::RuSpec{HeRu::RU_26_TONE, 6, true},
339 HeRu::RuSpec{HeRu::RU_26_TONE, 7, true},
340 HeRu::RuSpec{HeRu::RU_52_TONE, 4, true}}},
341 {80,
342 {HeRu::RuSpec{HeRu::RU_106_TONE, 1, true},
343 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
344 HeRu::RuSpec{HeRu::RU_52_TONE, 3, true},
345 HeRu::RuSpec{HeRu::RU_26_TONE, 8, true},
346 HeRu::RuSpec{HeRu::RU_26_TONE, 9, true}}},
347 {88,
348 {HeRu::RuSpec{HeRu::RU_106_TONE, 1, true},
349 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
350 HeRu::RuSpec{HeRu::RU_52_TONE, 3, true},
351 HeRu::RuSpec{HeRu::RU_52_TONE, 4, true}}},
352 {96,
353 {HeRu::RuSpec{HeRu::RU_106_TONE, 1, true},
354 HeRu::RuSpec{HeRu::RU_106_TONE, 2, true}}},
355 {112,
356 {HeRu::RuSpec{HeRu::RU_52_TONE, 1, true},
357 HeRu::RuSpec{HeRu::RU_52_TONE, 2, true},
358 HeRu::RuSpec{HeRu::RU_52_TONE, 3, true},
359 HeRu::RuSpec{HeRu::RU_52_TONE, 4, true}}},
360 {128,
361 {HeRu::RuSpec{HeRu::RU_106_TONE, 1, true},
362 HeRu::RuSpec{HeRu::RU_26_TONE, 5, true},
363 HeRu::RuSpec{HeRu::RU_106_TONE, 2, true}}},
364 {192,
365 {HeRu::RuSpec{HeRu::RU_242_TONE, 1, true}}},
366 {200,
367 {HeRu::RuSpec{HeRu::RU_484_TONE, 1, true}}},
368 {208,
369 {HeRu::RuSpec{HeRu::RU_996_TONE, 1, true}}},
370 // clang-format on
371};
372
373HeRu::RuSpecCompare::RuSpecCompare(uint16_t channelWidth, uint8_t p20Index)
374 : m_channelWidth(channelWidth),
375 m_p20Index(p20Index)
376{
377}
378
379bool
381{
382 const auto lhsIndex = lhs.GetPhyIndex(m_channelWidth, m_p20Index);
383 const auto rhsIndex = rhs.GetPhyIndex(m_channelWidth, m_p20Index);
384 const auto lhsStartTone =
385 HeRu::GetSubcarrierGroup(m_channelWidth, lhs.GetRuType(), lhsIndex).front().first;
386 const auto rhsStartTone =
387 HeRu::GetSubcarrierGroup(m_channelWidth, rhs.GetRuType(), rhsIndex).front().first;
388 return lhsStartTone < rhsStartTone;
389}
390
391std::vector<HeRu::RuSpec>
392HeRu::GetRuSpecs(uint8_t ruAllocation)
393{
394 std::optional<std::size_t> idx;
395 switch (ruAllocation)
396 {
397 case 0 ... 15:
398 case 112:
399 idx = ruAllocation;
400 break;
401 case 16 ... 95:
402 case 192 ... 215:
403 idx = ruAllocation & 0xF8;
404 break;
405 case 96 ... 111:
406 idx = ruAllocation & 0xF0;
407 break;
408 case 113 ... 115:
409 break;
410 case 128 ... 191:
411 idx = ruAllocation & 0xC0;
412 break;
413 default:
414 NS_FATAL_ERROR("Reserved RU allocation " << +ruAllocation);
415 }
416 return idx.has_value() ? m_heRuAllocations.at(idx.value()) : std::vector<HeRu::RuSpec>{};
417}
418
419uint8_t
421{
422 switch (ruType)
423 {
424 case HeRu::RU_26_TONE:
425 return 0;
426 case HeRu::RU_52_TONE:
427 return isOdd ? 15 : 112;
429 return isOdd ? 128 : 96;
431 return 192;
433 return 200;
434 default:
435 return 208;
436 }
437}
438
440 : m_index(0) // indicates undefined RU
441{
442}
443
444HeRu::RuSpec::RuSpec(RuType ruType, std::size_t index, bool primary80MHz)
445 : m_ruType(ruType),
446 m_index(index),
447 m_primary80MHz(primary80MHz)
448{
449 NS_ABORT_MSG_IF(index == 0, "Index cannot be zero");
450}
451
454{
455 NS_ABORT_MSG_IF(m_index == 0, "Undefined RU");
456 return m_ruType;
457}
458
459std::size_t
461{
462 NS_ABORT_MSG_IF(m_index == 0, "Undefined RU");
463 return m_index;
464}
465
466bool
468{
469 NS_ABORT_MSG_IF(m_index == 0, "Undefined RU");
470 return m_primary80MHz;
471}
472
473std::size_t
474HeRu::RuSpec::GetPhyIndex(uint16_t bw, uint8_t p20Index) const
475{
476 bool primary80IsLower80 = (p20Index < bw / 40);
477
478 if (bw < 160 || m_ruType == HeRu::RU_2x996_TONE || (primary80IsLower80 && m_primary80MHz) ||
479 (!primary80IsLower80 && !m_primary80MHz))
480 {
481 return m_index;
482 }
483 else
484 {
485 return m_index + GetNRus(bw, m_ruType) / 2;
486 }
487}
488
489std::size_t
490HeRu::GetNRus(uint16_t bw, RuType ruType)
491{
492 if (bw == 160 && ruType == RU_2x996_TONE)
493 {
494 return 1;
495 }
496
497 // if the bandwidth is 160MHz, search for the number of RUs available
498 // in 80MHz and double the result.
499 auto it = m_heRuSubcarrierGroups.find({(bw == 160 ? 80 : bw), ruType});
500
501 if (it == m_heRuSubcarrierGroups.end())
502 {
503 return 0;
504 }
505
506 return (bw == 160 ? 2 : 1) * it->second.size();
507}
508
509std::vector<HeRu::RuSpec>
511{
512 if (ruType == HeRu::RU_2x996_TONE)
513 {
514 NS_ASSERT(bw >= 160);
515 return {{ruType, 1, true}};
516 }
517
518 std::vector<HeRu::RuSpec> ret;
519 std::vector<bool> primary80MHzSet{true};
520
521 if (bw == 160)
522 {
523 primary80MHzSet.push_back(false);
524 bw = 80;
525 }
526
527 for (auto primary80MHz : primary80MHzSet)
528 {
529 for (std::size_t ruIndex = 1;
530 ruIndex <= HeRu::m_heRuSubcarrierGroups.at({bw, ruType}).size();
531 ruIndex++)
532 {
533 ret.emplace_back(ruType, ruIndex, primary80MHz);
534 }
535 }
536 return ret;
537}
538
539std::vector<HeRu::RuSpec>
541{
542 std::vector<std::size_t> indices;
543
544 if (ruType == HeRu::RU_52_TONE || ruType == HeRu::RU_106_TONE)
545 {
546 if (bw == 20)
547 {
548 indices.push_back(5);
549 }
550 else if (bw == 40)
551 {
552 indices.insert(indices.end(), {5, 14});
553 }
554 else if (bw >= 80)
555 {
556 indices.insert(indices.end(), {5, 14, 19, 24, 33});
557 }
558 }
559 else if (ruType == HeRu::RU_242_TONE || ruType == HeRu::RU_484_TONE)
560 {
561 if (bw >= 80)
562 {
563 indices.push_back(19);
564 }
565 }
566
567 std::vector<HeRu::RuSpec> ret;
568 std::vector<bool> primary80MHzSet{true};
569
570 if (bw == 160)
571 {
572 primary80MHzSet.push_back(false);
573 }
574
575 for (auto primary80MHz : primary80MHzSet)
576 {
577 for (const auto& index : indices)
578 {
579 ret.emplace_back(HeRu::RU_26_TONE, index, primary80MHz);
580 }
581 }
582 return ret;
583}
584
586HeRu::GetSubcarrierGroup(uint16_t bw, RuType ruType, std::size_t phyIndex)
587{
588 if (ruType == HeRu::RU_2x996_TONE) // handle special case of RU covering 160 MHz channel
589 {
590 NS_ABORT_MSG_IF(bw != 160, "2x996 tone RU can only be used on 160 MHz band");
591 return {{-1012, -3}, {3, 1012}};
592 }
593
594 // Determine the shift to apply to tone indices for 160 MHz channel (i.e. -1012 to 1012), since
595 // m_heRuSubcarrierGroups contains indices for lower 80 MHz subchannel (i.e. from -500 to 500).
596 // The phyIndex is used to that aim.
597 std::size_t indexInLower80MHz = phyIndex;
598 std::size_t numRus = GetNRus(bw, ruType);
599 int16_t shift = (bw == 160) ? -512 : 0;
600 if (bw == 160 && phyIndex > (numRus / 2))
601 {
602 // The provided index is that of the upper 80 MHz subchannel
603 indexInLower80MHz = phyIndex - (numRus / 2);
604 shift = 512;
605 }
606
607 auto it = m_heRuSubcarrierGroups.find({(bw == 160 ? 80 : bw), ruType});
608
609 NS_ABORT_MSG_IF(it == m_heRuSubcarrierGroups.end(), "RU not found");
610 NS_ABORT_MSG_IF(indexInLower80MHz > it->second.size(), "RU index not available");
611
612 SubcarrierGroup group = it->second.at(indexInLower80MHz - 1);
613 if (bw == 160)
614 {
615 for (auto& range : group)
616 {
617 range.first += shift;
618 range.second += shift;
619 }
620 }
621 return group;
622}
623
624bool
625HeRu::DoesOverlap(uint16_t bw, RuSpec ru, const std::vector<RuSpec>& v)
626{
627 // A 2x996-tone RU spans 160 MHz, hence it overlaps with any other RU
628 if (bw == 160 && ru.GetRuType() == RU_2x996_TONE && !v.empty())
629 {
630 return true;
631 }
632
633 // This function may be called by the MAC layer, hence the PHY index may have
634 // not been set yet. Hence, we pass the "MAC" index to GetSubcarrierGroup instead
635 // of the PHY index. This is fine because we compare the primary 80 MHz bands of
636 // the two RUs below.
637 SubcarrierGroup rangesRu = GetSubcarrierGroup(bw, ru.GetRuType(), ru.GetIndex());
638 for (auto& p : v)
639 {
640 if (ru.GetPrimary80MHz() != p.GetPrimary80MHz())
641 {
642 // the two RUs are located in distinct 80MHz bands
643 continue;
644 }
645 for (const auto& rangeRu : rangesRu)
646 {
647 SubcarrierGroup rangesP = GetSubcarrierGroup(bw, p.GetRuType(), p.GetIndex());
648 for (auto& rangeP : rangesP)
649 {
650 if (rangeP.second >= rangeRu.first && rangeRu.second >= rangeP.first)
651 {
652 return true;
653 }
654 }
655 }
656 }
657 return false;
658}
659
660bool
661HeRu::DoesOverlap(uint16_t bw, RuSpec ru, const SubcarrierGroup& toneRanges, uint8_t p20Index)
662{
663 for (const auto& range : toneRanges)
664 {
665 if (bw == 160 && ru.GetRuType() == RU_2x996_TONE)
666 {
667 return true;
668 }
669
670 SubcarrierGroup rangesRu =
671 GetSubcarrierGroup(bw, ru.GetRuType(), ru.GetPhyIndex(bw, p20Index));
672 for (auto& r : rangesRu)
673 {
674 if (range.second >= r.first && r.second >= range.first)
675 {
676 return true;
677 }
678 }
679 }
680 return false;
681}
682
684HeRu::FindOverlappingRu(uint16_t bw, RuSpec referenceRu, RuType searchedRuType)
685{
686 std::size_t numRus = HeRu::GetNRus(bw, searchedRuType);
687
688 std::size_t numRusPer80Mhz;
689 std::vector<bool> primary80MhzFlags;
690 if (bw == 160)
691 {
692 primary80MhzFlags.push_back(true);
693 primary80MhzFlags.push_back(false);
694 numRusPer80Mhz = (searchedRuType == HeRu::RU_2x996_TONE ? 1 : numRus / 2);
695 }
696 else
697 {
698 primary80MhzFlags.push_back(referenceRu.GetPrimary80MHz());
699 numRusPer80Mhz = numRus;
700 }
701
702 for (const auto primary80MHz : primary80MhzFlags)
703 {
704 std::size_t index = 1;
705 for (std::size_t indexPer80Mhz = 1; indexPer80Mhz <= numRusPer80Mhz;
706 ++indexPer80Mhz, ++index)
707 {
708 RuSpec searchedRu(searchedRuType, index, primary80MHz);
709 if (DoesOverlap(bw, referenceRu, {searchedRu}))
710 {
711 return searchedRu;
712 }
713 }
714 }
715 NS_ABORT_MSG("The searched RU type " << searchedRuType << " was not found for bw=" << bw
716 << " and referenceRu=" << referenceRu);
717 return HeRu::RuSpec();
718}
719
720std::ostream&
721operator<<(std::ostream& os, const HeRu::RuType& ruType)
722{
723 switch (ruType)
724 {
725 case HeRu::RU_26_TONE:
726 os << "26-tones";
727 break;
728 case HeRu::RU_52_TONE:
729 os << "52-tones";
730 break;
732 os << "106-tones";
733 break;
735 os << "242-tones";
736 break;
738 os << "484-tones";
739 break;
741 os << "996-tones";
742 break;
744 os << "2x996-tones";
745 break;
746 default:
747 NS_FATAL_ERROR("Unknown RU type");
748 }
749 return os;
750}
751
752std::ostream&
753operator<<(std::ostream& os, const HeRu::RuSpec& ru)
754{
755 os << "RU{" << ru.GetRuType() << "/" << ru.GetIndex() << "/"
756 << (ru.GetPrimary80MHz() ? "primary80MHz" : "secondary80MHz");
757 os << "}";
758 return os;
759}
760
761uint16_t
763{
764 switch (ruType)
765 {
766 case RU_26_TONE:
767 return 2;
768 case RU_52_TONE:
769 return 4;
770 case RU_106_TONE:
771 return 8;
772 case RU_242_TONE:
773 return 20;
774 case RU_484_TONE:
775 return 40;
776 case RU_996_TONE:
777 return 80;
778 case RU_2x996_TONE:
779 return 160;
780 default:
781 NS_ABORT_MSG("RU type " << ruType << " not found");
782 return 0;
783 }
784}
785
787HeRu::GetRuType(uint16_t bandwidth)
788{
789 switch (bandwidth)
790 {
791 case 2:
792 return RU_26_TONE;
793 case 4:
794 return RU_52_TONE;
795 case 8:
796 return RU_106_TONE;
797 case 20:
798 return RU_242_TONE;
799 case 40:
800 return RU_484_TONE;
801 case 80:
802 return RU_996_TONE;
803 case 160:
804 return RU_2x996_TONE;
805 default:
806 NS_ABORT_MSG(bandwidth << " MHz bandwidth not found");
807 return RU_242_TONE;
808 }
809}
810
813 std::size_t& nStations,
814 std::size_t& nCentral26TonesRus)
815{
816 RuType ruType;
817 uint8_t nRusAssigned = 0;
818
819 // iterate over all the available RU types
820 for (auto& ru : m_heRuSubcarrierGroups)
821 {
822 if (ru.first.first == bandwidth && ru.second.size() <= nStations)
823 {
824 ruType = ru.first.second;
825 nRusAssigned = ru.second.size();
826 break;
827 }
828 else if (bandwidth == 160 && ru.first.first == 80 && (2 * ru.second.size() <= nStations))
829 {
830 ruType = ru.first.second;
831 nRusAssigned = 2 * ru.second.size();
832 break;
833 }
834 }
835 if (nRusAssigned == 0)
836 {
837 NS_ABORT_IF(bandwidth != 160 || nStations != 1);
838 nRusAssigned = 1;
839 ruType = RU_2x996_TONE;
840 }
841
842 nStations = nRusAssigned;
843
844 switch (ruType)
845 {
846 case RU_52_TONE:
847 case RU_106_TONE:
848 if (bandwidth == 20)
849 {
850 nCentral26TonesRus = 1;
851 }
852 else if (bandwidth == 40)
853 {
854 nCentral26TonesRus = 2;
855 }
856 else
857 {
858 nCentral26TonesRus = 5;
859 }
860 break;
861 case RU_242_TONE:
862 case RU_484_TONE:
863 nCentral26TonesRus = (bandwidth >= 80 ? 1 : 0);
864 break;
865 default:
866 nCentral26TonesRus = 0;
867 }
868
869 if (bandwidth == 160)
870 {
871 nCentral26TonesRus *= 2;
872 }
873
874 return ruType;
875}
876
877bool
879{
880 // we do not compare the RU PHY indices because they may be uninitialized for
881 // one of the compared RUs. This event should not cause the comparison to evaluate
882 // to false
883 return m_ruType == other.m_ruType && m_index == other.m_index &&
884 m_primary80MHz == other.m_primary80MHz;
885}
886
887bool
889{
890 return !(*this == other);
891}
892
893} // namespace ns3
RU Specification.
Definition: he-ru.h:66
std::size_t GetIndex() const
Get the RU index.
Definition: he-ru.cc:460
std::size_t m_index
RU index (starting at 1) as defined by Tables 27-7 to 27-9 of 802.11ax D8.0.
Definition: he-ru.h:125
RuType GetRuType() const
Get the RU type.
Definition: he-ru.cc:453
RuSpec()
Default constructor.
Definition: he-ru.cc:439
bool m_primary80MHz
true if the RU is allocated in the primary 80MHz channel
Definition: he-ru.h:127
std::size_t GetPhyIndex(uint16_t bw, uint8_t p20Index) const
Get the RU PHY index.
Definition: he-ru.cc:474
RuType m_ruType
RU type.
Definition: he-ru.h:124
bool operator==(const RuSpec &other) const
Compare this RU to the given RU.
Definition: he-ru.cc:878
bool GetPrimary80MHz() const
Get the primary 80 MHz flag.
Definition: he-ru.cc:467
bool operator!=(const RuSpec &other) const
Compare this RU to the given RU.
Definition: he-ru.cc:888
static RuSpec FindOverlappingRu(uint16_t bw, RuSpec referenceRu, RuType searchedRuType)
Find the RU allocation of the given RU type overlapping the given reference RU allocation.
Definition: he-ru.cc:684
static bool DoesOverlap(uint16_t bw, RuSpec ru, const std::vector< RuSpec > &v)
Check whether the given RU overlaps with the given set of RUs.
Definition: he-ru.cc:625
static std::vector< RuSpec > GetRuSpecs(uint8_t ruAllocation)
Get the RU specs based on RU_ALLOCATION.
Definition: he-ru.cc:392
static uint16_t GetBandwidth(RuType ruType)
Get the approximate bandwidth occupied by a RU.
Definition: he-ru.cc:762
static SubcarrierGroup GetSubcarrierGroup(uint16_t 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:586
static std::size_t GetNRus(uint16_t 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:490
static std::vector< HeRu::RuSpec > GetRusOfType(uint16_t bw, HeRu::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:510
std::vector< SubcarrierRange > SubcarrierGroup
a vector of subcarrier ranges defining a subcarrier group
Definition: he-ru.h:55
std::map< uint8_t, std::vector< RuSpec > > RuAllocationMap
RU allocation map.
Definition: he-ru.h:287
static std::vector< HeRu::RuSpec > GetCentral26TonesRus(uint16_t bw, HeRu::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:540
static const SubcarrierGroups m_heRuSubcarrierGroups
Subcarrier groups for all RUs (with indices being applicable to primary 80 MHz channel)
Definition: he-ru.h:284
static uint8_t GetEqualizedRuAllocation(RuType ruType, bool isOdd)
Get the RU_ALLOCATION value for equal size RUs.
Definition: he-ru.cc:420
RuType
The different HE Resource Unit (RU) types.
Definition: he-ru.h:41
@ RU_26_TONE
Definition: he-ru.h:42
@ RU_484_TONE
Definition: he-ru.h:46
@ RU_996_TONE
Definition: he-ru.h:47
@ RU_106_TONE
Definition: he-ru.h:44
@ RU_52_TONE
Definition: he-ru.h:43
@ RU_242_TONE
Definition: he-ru.h:45
@ RU_2x996_TONE
Definition: he-ru.h:48
static RuType GetEqualSizedRusForStations(uint16_t 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:812
static RuType GetRuType(uint16_t bandwidth)
Get the RU corresponding to the approximate bandwidth.
Definition: he-ru.cc:787
static const RuAllocationMap m_heRuAllocations
Table 27-26 of IEEE 802.11ax-2021.
Definition: he-ru.h:290
std::map< BwTonesPair, std::vector< SubcarrierGroup > > SubcarrierGroups
map (bandwidth, number of tones) pairs to the group of subcarrier ranges
Definition: he-ru.h:281
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Definition: abort.h:76
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:129
RuSpecCompare(uint16_t channelWidth, uint8_t p20Index)
Constructor.
Definition: he-ru.cc:373
bool operator()(const RuSpec &lhs, const RuSpec &rhs) const
Function call operator.
Definition: he-ru.cc:380