A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
eht-operation.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sharan Naribole <sharan.naribole@gmail.com>
7 */
8
9#include "eht-operation.h"
10
11#include <ns3/assert.h>
12
13#include <algorithm>
14
15namespace ns3
16{
17
18void
19EhtOperation::Print(std::ostream& os) const
20{
21 os << "EHT Operation=" << +m_params.opInfoPresent << "|" << +m_params.disabledSubchBmPresent
22 << "|" << +m_params.defaultPeDur << "|" << +m_params.grpBuIndLimit << "|"
23 << +m_params.grpBuExp << "|[";
24 for (const auto& maxRxNss : m_mcsNssSet.maxRxNss)
25 {
26 os << +maxRxNss << "|";
27 }
28 os << "]|[";
29 for (const auto& maxTxNss : m_mcsNssSet.maxTxNss)
30 {
31 os << +maxTxNss << "|";
32 }
33 os << "]";
34 if (m_opInfo.has_value())
35 {
36 os << "|" << +m_opInfo->control.channelWidth << "|" << +m_opInfo->ccfs0 << "|"
37 << +m_opInfo->ccfs1;
38 if (m_opInfo->disabledSubchBm.has_value())
39 {
40 os << "|" << m_opInfo->disabledSubchBm.value();
41 }
42 }
43}
44
45void
47{
48 uint8_t val = opInfoPresent | (disabledSubchBmPresent << 1) | (defaultPeDur << 2) |
49 (grpBuIndLimit << 3) | (grpBuExp << 4);
50 start.WriteU8(val);
51}
52
53uint16_t
55{
56 auto params = start.ReadU8();
57 opInfoPresent = params & 0x01;
58 disabledSubchBmPresent = (params >> 1) & 0x01;
59 defaultPeDur = (params >> 2) & 0x01;
60 grpBuIndLimit = (params >> 3) & 0x01;
61 grpBuExp = (params >> 4) & 0x03;
63}
64
65/**
66 * set the max Tx/Rx NSS for input MCS index range
67 * \param vec vector of max NSS per MCS
68 * \param maxNss max NSS for input MCS range
69 * \param mcsStart MCS index start
70 * \param mcsEnd MCS index end
71 */
72void
73SetMaxNss(std::vector<uint8_t>& vec, uint8_t maxNss, uint8_t mcsStart, uint8_t mcsEnd)
74{
75 NS_ASSERT(mcsStart <= mcsEnd);
76 NS_ASSERT((mcsStart >= 0) && (mcsEnd <= WIFI_EHT_MAX_MCS_INDEX));
77 NS_ASSERT((maxNss >= 1) && (maxNss <= WIFI_EHT_MAX_NSS_CONFIGURABLE));
78 for (auto index = mcsStart; index <= mcsEnd; index++)
79 {
80 vec[index] = maxNss;
81 }
82}
83
84/**
85 * Get the max Tx/Rx NSS for input MCS index range
86 * \param vec vector of max NSS per MCS
87 * \param mcsStart MCS index start
88 * \param mcsEnd MCS index end
89 * \return max Rx NSS
90 */
92GetMaxNss(const std::vector<uint8_t>& vec, uint8_t mcsStart, uint8_t mcsEnd)
93{
94 NS_ASSERT(mcsStart <= mcsEnd);
95 NS_ASSERT((mcsStart >= 0) && (mcsEnd <= WIFI_EHT_MAX_MCS_INDEX));
96 auto minMaxNss = WIFI_EHT_MAX_NSS_CONFIGURABLE;
97 for (auto index = mcsStart; index <= mcsEnd; index++)
98 {
99 if (vec[index] < minMaxNss)
100 {
101 minMaxNss = vec[index];
102 }
103 }
104 return minMaxNss;
105}
106
107void
109{
110 uint32_t val = GetMaxNss(maxRxNss, 0, 7) | (GetMaxNss(maxTxNss, 0, 7) << 4) |
111 (GetMaxNss(maxRxNss, 8, 9) << 8) | (GetMaxNss(maxTxNss, 8, 9) << 12) |
112 (GetMaxNss(maxRxNss, 10, 11) << 16) | (GetMaxNss(maxTxNss, 10, 11) << 20) |
113 (GetMaxNss(maxRxNss, 12, 13) << 24) | (GetMaxNss(maxTxNss, 12, 13) << 28);
114 start.WriteHtolsbU32(val);
115}
116
117uint16_t
119{
120 auto subfield = start.ReadLsbtohU32();
121 auto rxNssMcs0_7 = subfield & 0xf; // Max Rx NSS MCS 0-7
122 SetMaxNss(maxRxNss, rxNssMcs0_7, 0, 7);
123 auto txNssMcs0_7 = (subfield >> 4) & 0xf; // Max Tx NSS MCS 0-7
124 SetMaxNss(maxTxNss, txNssMcs0_7, 0, 7);
125 auto rxNssMcs8_9 = (subfield >> 8) & 0xf; // Max Rx NSS MCS 8-9
126 SetMaxNss(maxRxNss, rxNssMcs8_9, 8, 9);
127 auto txNssMcs8_9 = (subfield >> 12) & 0xf; // Max Tx NSS MCS 8-9
128 SetMaxNss(maxTxNss, txNssMcs8_9, 8, 9);
129 auto rxNssMcs10_11 = (subfield >> 16) & 0xf; // Max Rx NSS MCS 10-11
130 SetMaxNss(maxRxNss, rxNssMcs10_11, 10, 11);
131 auto txNssMcs10_11 = (subfield >> 20) & 0xf; // Max Tx NSS MCS 10-11
132 SetMaxNss(maxTxNss, txNssMcs10_11, 10, 11);
133 auto rxNssMcs12_13 = (subfield >> 24) & 0xf; // Max Rx NSS MCS 12-13
134 SetMaxNss(maxRxNss, rxNssMcs12_13, 12, 13);
135 auto txNssMcs12_13 = (subfield >> 28) & 0xf; // Max Tx NSS MCS 12-13
136 SetMaxNss(maxTxNss, txNssMcs12_13, 12, 13);
138}
139
140void
142{
143 start.WriteU8(control.channelWidth); // Control
144 start.WriteU8(ccfs0); // CCFS 0
145 start.WriteU8(ccfs1); // CCFS 1
146 if (disabledSubchBm.has_value())
147 {
148 start.WriteU16(disabledSubchBm.value());
149 }
150}
151
152uint16_t
154{
155 auto i = start;
156 uint16_t count = 0;
157 auto controlSubfield = i.ReadU8();
158 count++;
159 control.channelWidth = controlSubfield & 0x7;
160 ccfs0 = i.ReadU8();
161 count++;
162 ccfs1 = i.ReadU8();
163 count++;
165 "Incorrect EHT Operation Info deserialize");
166 if (!disabledSubchBmPresent)
167 {
168 return count;
169 }
170 disabledSubchBm = i.ReadU16();
171 count += 2;
173 "Incorrect EHT Operation Info deserialize");
174 return count;
175}
176
182
185{
186 return IE_EXTENSION;
187}
188
194
195uint16_t
197{
198 // IEEE 802.11be D2.0 9.4.2.311
199 auto ret =
202 {
203 return ret;
204 }
207 {
208 return ret;
209 }
211}
212
213void
214EhtOperation::SetMaxRxNss(uint8_t maxNss, uint8_t mcsStart, uint8_t mcsEnd)
215{
216 NS_ASSERT(mcsStart <= mcsEnd);
217 NS_ASSERT((mcsStart >= 0) && (mcsEnd <= WIFI_EHT_MAX_MCS_INDEX));
218 NS_ASSERT((maxNss >= 1) && (maxNss <= WIFI_EHT_MAX_NSS_CONFIGURABLE));
219 SetMaxNss(m_mcsNssSet.maxRxNss, maxNss, mcsStart, mcsEnd);
220}
221
222void
223EhtOperation::SetMaxTxNss(uint8_t maxNss, uint8_t mcsStart, uint8_t mcsEnd)
224{
225 NS_ASSERT(mcsStart <= mcsEnd);
226 NS_ASSERT((mcsStart >= 0) && (mcsEnd <= WIFI_EHT_MAX_MCS_INDEX));
227 NS_ASSERT((maxNss >= 1) && (maxNss <= WIFI_EHT_MAX_NSS_CONFIGURABLE));
228 SetMaxNss(m_mcsNssSet.maxTxNss, maxNss, mcsStart, mcsEnd);
229}
230
231void
233{
234 m_params.Serialize(start);
235 m_mcsNssSet.Serialize(start);
237 "Incorrect setting of EHT Operation Information Present bit");
238
240 { // EHT Operation Information Present not set
241 return;
242 }
243
244 auto disabledSubchBmPresent = m_params.disabledSubchBmPresent > 0;
245 NS_ASSERT_MSG(disabledSubchBmPresent == m_opInfo->disabledSubchBm.has_value(),
246 "Incorrect setting of Disabled Subchannel Bitmap Present bit");
247 m_opInfo->Serialize(start);
248}
249
250uint16_t
252{
253 auto i = start;
254 i.Next(m_params.Deserialize(i));
255 i.Next(m_mcsNssSet.Deserialize(i));
256 uint16_t count = i.GetDistanceFrom(start);
257
259 {
260 NS_ASSERT_MSG(count == length, "Unexpected EHT Operation size");
261 }
262
263 if (m_params.opInfoPresent > 0)
264 {
265 auto disabledSubchBmPresent = m_params.disabledSubchBmPresent > 0;
267 i.Next(m_opInfo->Deserialize(i, disabledSubchBmPresent));
268 count = i.GetDistanceFrom(start);
269 }
270
271 NS_ABORT_MSG_IF(count != length,
272 "EHT Operation Length (" << +length
273 << ") differs "
274 "from actual number of bytes read ("
275 << +count << ")");
276 return length;
277}
278} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void SetMaxTxNss(uint8_t maxNss, uint8_t mcsStart, uint8_t mcsEnd)
Set the max Tx NSS for input MCS index range.
void SetMaxRxNss(uint8_t maxNss, uint8_t mcsStart, uint8_t mcsEnd)
Set the max Rx NSS for input MCS index range.
EhtOpParams m_params
EHT Operation Parameters.
EhtBasicMcsNssSet m_mcsNssSet
Basic EHT-MCS and NSS set.
uint16_t DeserializeInformationField(Buffer::Iterator start, uint16_t length) override
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
WifiInformationElementId ElementIdExt() const override
Get the wifi information element ID extension.
void Print(std::ostream &os) const override
Generate human-readable form of IE.
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
uint16_t GetInformationFieldSize() const override
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
std::optional< EhtOpInfo > m_opInfo
EHT Operation Information.
void SerializeInformationField(Buffer::Iterator start) const override
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
Every class exported by the ns3 library is enclosed in the ns3 namespace.
constexpr uint16_t WIFI_EHT_OP_INFO_BASIC_SIZE_B
IEEE 802.11be D2.0 Figure 9-1002c.
constexpr uint16_t WIFI_EHT_DISABLED_SUBCH_BM_SIZE_B
IEEE 802.11be D2.0 Figure 9-1002c.
constexpr uint8_t WIFI_DEFAULT_EHT_MAX_NSS
Default max Tx/Rx NSS.
constexpr uint8_t WIFI_EHT_MAX_MCS_INDEX
IEEE 802.11be D2.0 Figure 9-1002ai.
constexpr uint8_t WIFI_IE_ELEMENT_ID_EXT_SIZE
Size in bytes of the Element ID Extension field (IEEE 802.11-2020 9.4.2.1 General)
constexpr uint16_t WIFI_EHT_BASIC_MCS_NSS_SET_SIZE_B
IEEE 802.11be D2.0 Figure 9-1002ai.
void SetMaxNss(std::vector< uint8_t > &vec, uint8_t maxNss, uint8_t mcsStart, uint8_t mcsEnd)
set the max Tx/Rx NSS for input MCS index range
constexpr uint8_t WIFI_EHT_MAX_NSS_CONFIGURABLE
Max NSS configurable, 802.11be D2.0 Table 9-401m.
constexpr uint16_t WIFI_EHT_OP_PARAMS_SIZE_B
IEEE 802.11be D2.0 Figure 9-1002b.
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
uint32_t GetMaxNss(const std::vector< uint8_t > &vec, uint8_t mcsStart, uint8_t mcsEnd)
Get the max Tx/Rx NSS for input MCS index range.
void Serialize(Buffer::Iterator &start) const
Serialize the Basic EHT-MCS and NSS Set subfield.
std::vector< uint8_t > maxRxNss
Max Rx NSS per MCS.
std::vector< uint8_t > maxTxNss
Max Tx NSS per MCS.
uint16_t Deserialize(Buffer::Iterator start)
Deserialize the Basic EHT-MCS and NSS Set subfield.
EHT Operation Information subfield IEEE 802.11be D2.0 Figure 9-1002c.
void Serialize(Buffer::Iterator &start) const
Serialize the EHT Operation Information subfield.
uint16_t Deserialize(Buffer::Iterator start, bool disabledSubchBmPresent)
Deserialize the EHT Operation Information subfield.
uint8_t defaultPeDur
EHT Default PE Duration.
void Serialize(Buffer::Iterator &start) const
Serialize the EHT Operation Parameters subfield.
uint8_t grpBuExp
Group Addressed BU Indication Exponent.
uint16_t Deserialize(Buffer::Iterator start)
Deserialize the EHT Operation Parameters subfield.
uint8_t opInfoPresent
EHT Operation Information Present.
uint8_t disabledSubchBmPresent
Disabled Subchannel Bitmap Present.
uint8_t grpBuIndLimit
Group Addressed BU Indication Limit.
#define IE_EXTENSION
#define IE_EXT_EHT_OPERATION