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=[";
22 if (m_opInfo.has_value())
23 {
24 os << "Channel Width: " << +m_opInfo->control.channelWidth;
25 }
26 os << "]";
27}
28
29void
31{
32 uint8_t val = opInfoPresent | (disabledSubchBmPresent << 1) | (defaultPeDur << 2) |
33 (grpBuIndLimit << 3) | (grpBuExp << 4);
34 start.WriteU8(val);
35}
36
37uint16_t
39{
40 auto params = start.ReadU8();
41 opInfoPresent = params & 0x01;
42 disabledSubchBmPresent = (params >> 1) & 0x01;
43 defaultPeDur = (params >> 2) & 0x01;
44 grpBuIndLimit = (params >> 3) & 0x01;
45 grpBuExp = (params >> 4) & 0x03;
47}
48
49/**
50 * set the max Tx/Rx NSS for input MCS index range
51 * @param vec vector of max NSS per MCS
52 * @param maxNss max NSS for input MCS range
53 * @param mcsStart MCS index start
54 * @param mcsEnd MCS index end
55 */
56void
57SetMaxNss(std::vector<uint8_t>& vec, uint8_t maxNss, uint8_t mcsStart, uint8_t mcsEnd)
58{
59 NS_ASSERT(mcsStart <= mcsEnd);
60 NS_ASSERT((mcsStart >= 0) && (mcsEnd <= WIFI_EHT_MAX_MCS_INDEX));
61 NS_ASSERT((maxNss >= 1) && (maxNss <= WIFI_EHT_MAX_NSS_CONFIGURABLE));
62 for (auto index = mcsStart; index <= mcsEnd; index++)
63 {
64 vec[index] = maxNss;
65 }
66}
67
68/**
69 * Get the max Tx/Rx NSS for input MCS index range
70 * @param vec vector of max NSS per MCS
71 * @param mcsStart MCS index start
72 * @param mcsEnd MCS index end
73 * @return max Rx NSS
74 */
76GetMaxNss(const std::vector<uint8_t>& vec, uint8_t mcsStart, uint8_t mcsEnd)
77{
78 NS_ASSERT(mcsStart <= mcsEnd);
79 NS_ASSERT((mcsStart >= 0) && (mcsEnd <= WIFI_EHT_MAX_MCS_INDEX));
80 auto minMaxNss = WIFI_EHT_MAX_NSS_CONFIGURABLE;
81 for (auto index = mcsStart; index <= mcsEnd; index++)
82 {
83 if (vec[index] < minMaxNss)
84 {
85 minMaxNss = vec[index];
86 }
87 }
88 return minMaxNss;
89}
90
91void
93{
94 uint32_t val = GetMaxNss(maxRxNss, 0, 7) | (GetMaxNss(maxTxNss, 0, 7) << 4) |
95 (GetMaxNss(maxRxNss, 8, 9) << 8) | (GetMaxNss(maxTxNss, 8, 9) << 12) |
96 (GetMaxNss(maxRxNss, 10, 11) << 16) | (GetMaxNss(maxTxNss, 10, 11) << 20) |
97 (GetMaxNss(maxRxNss, 12, 13) << 24) | (GetMaxNss(maxTxNss, 12, 13) << 28);
98 start.WriteHtolsbU32(val);
99}
100
101uint16_t
103{
104 auto subfield = start.ReadLsbtohU32();
105 auto rxNssMcs0_7 = subfield & 0xf; // Max Rx NSS MCS 0-7
106 SetMaxNss(maxRxNss, rxNssMcs0_7, 0, 7);
107 auto txNssMcs0_7 = (subfield >> 4) & 0xf; // Max Tx NSS MCS 0-7
108 SetMaxNss(maxTxNss, txNssMcs0_7, 0, 7);
109 auto rxNssMcs8_9 = (subfield >> 8) & 0xf; // Max Rx NSS MCS 8-9
110 SetMaxNss(maxRxNss, rxNssMcs8_9, 8, 9);
111 auto txNssMcs8_9 = (subfield >> 12) & 0xf; // Max Tx NSS MCS 8-9
112 SetMaxNss(maxTxNss, txNssMcs8_9, 8, 9);
113 auto rxNssMcs10_11 = (subfield >> 16) & 0xf; // Max Rx NSS MCS 10-11
114 SetMaxNss(maxRxNss, rxNssMcs10_11, 10, 11);
115 auto txNssMcs10_11 = (subfield >> 20) & 0xf; // Max Tx NSS MCS 10-11
116 SetMaxNss(maxTxNss, txNssMcs10_11, 10, 11);
117 auto rxNssMcs12_13 = (subfield >> 24) & 0xf; // Max Rx NSS MCS 12-13
118 SetMaxNss(maxRxNss, rxNssMcs12_13, 12, 13);
119 auto txNssMcs12_13 = (subfield >> 28) & 0xf; // Max Tx NSS MCS 12-13
120 SetMaxNss(maxTxNss, txNssMcs12_13, 12, 13);
122}
123
124void
126{
127 start.WriteU8(control.channelWidth); // Control
128 start.WriteU8(ccfs0); // CCFS 0
129 start.WriteU8(ccfs1); // CCFS 1
130 if (disabledSubchBm.has_value())
131 {
132 start.WriteU16(disabledSubchBm.value());
133 }
134}
135
136uint16_t
138{
139 auto i = start;
140 uint16_t count = 0;
141 auto controlSubfield = i.ReadU8();
142 count++;
143 control.channelWidth = controlSubfield & 0x7;
144 ccfs0 = i.ReadU8();
145 count++;
146 ccfs1 = i.ReadU8();
147 count++;
149 "Incorrect EHT Operation Info deserialize");
150 if (!disabledSubchBmPresent)
151 {
152 return count;
153 }
154 disabledSubchBm = i.ReadU16();
155 count += 2;
157 "Incorrect EHT Operation Info deserialize");
158 return count;
159}
160
166
169{
170 return IE_EXTENSION;
171}
172
178
179uint16_t
181{
182 // IEEE 802.11be D2.0 9.4.2.311
183 auto ret =
186 {
187 return ret;
188 }
191 {
192 return ret;
193 }
195}
196
197void
198EhtOperation::SetMaxRxNss(uint8_t maxNss, uint8_t mcsStart, uint8_t mcsEnd)
199{
200 NS_ASSERT(mcsStart <= mcsEnd);
201 NS_ASSERT((mcsStart >= 0) && (mcsEnd <= WIFI_EHT_MAX_MCS_INDEX));
202 NS_ASSERT((maxNss >= 1) && (maxNss <= WIFI_EHT_MAX_NSS_CONFIGURABLE));
203 SetMaxNss(m_mcsNssSet.maxRxNss, maxNss, mcsStart, mcsEnd);
204}
205
206void
207EhtOperation::SetMaxTxNss(uint8_t maxNss, uint8_t mcsStart, uint8_t mcsEnd)
208{
209 NS_ASSERT(mcsStart <= mcsEnd);
210 NS_ASSERT((mcsStart >= 0) && (mcsEnd <= WIFI_EHT_MAX_MCS_INDEX));
211 NS_ASSERT((maxNss >= 1) && (maxNss <= WIFI_EHT_MAX_NSS_CONFIGURABLE));
212 SetMaxNss(m_mcsNssSet.maxTxNss, maxNss, mcsStart, mcsEnd);
213}
214
215void
217{
218 m_params.Serialize(start);
219 m_mcsNssSet.Serialize(start);
221 "Incorrect setting of EHT Operation Information Present bit");
222
224 { // EHT Operation Information Present not set
225 return;
226 }
227
228 auto disabledSubchBmPresent = m_params.disabledSubchBmPresent > 0;
229 NS_ASSERT_MSG(disabledSubchBmPresent == m_opInfo->disabledSubchBm.has_value(),
230 "Incorrect setting of Disabled Subchannel Bitmap Present bit");
231 m_opInfo->Serialize(start);
232}
233
234uint16_t
236{
237 auto i = start;
238 i.Next(m_params.Deserialize(i));
239 i.Next(m_mcsNssSet.Deserialize(i));
240 uint16_t count = i.GetDistanceFrom(start);
241
243 {
244 NS_ASSERT_MSG(count == length, "Unexpected EHT Operation size");
245 }
246
247 if (m_params.opInfoPresent > 0)
248 {
249 auto disabledSubchBmPresent = m_params.disabledSubchBmPresent > 0;
251 i.Next(m_opInfo->Deserialize(i, disabledSubchBmPresent));
252 count = i.GetDistanceFrom(start);
253 }
254
255 NS_ABORT_MSG_IF(count != length,
256 "EHT Operation Length (" << +length
257 << ") differs "
258 "from actual number of bytes read ("
259 << +count << ")");
260 return length;
261}
262} // 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