A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
common-info-basic-mle.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Universita' degli Studi di Napoli Federico II
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8
10
11#include "ns3/address-utils.h"
12
13namespace ns3
14{
15
16uint16_t
18{
19 // see Sec. 9.4.2.312.2.1 of 802.11be D1.5
20 return (m_linkIdInfo.has_value() ? 0x0001 : 0x0) |
21 (m_bssParamsChangeCount.has_value() ? 0x0002 : 0x0) |
22 (m_mediumSyncDelayInfo.has_value() ? 0x0004 : 0x0) |
23 (m_emlCapabilities.has_value() ? 0x0008 : 0x0) |
24 (m_mldCapabilities.has_value() ? 0x0010 : 0x0) | (m_apMldId.has_value() ? 0x0020 : 0x0) |
25 (m_extMldCapabilities.has_value() ? 0x0040 : 0x0);
26}
27
28uint8_t
30{
31 uint8_t ret = 7; // Common Info Length (1) + MLD MAC Address (6)
32 ret += (m_linkIdInfo.has_value() ? 1 : 0);
33 ret += (m_bssParamsChangeCount.has_value() ? 1 : 0);
34 ret += (m_mediumSyncDelayInfo.has_value() ? 2 : 0);
35 ret += (m_emlCapabilities.has_value() ? 2 : 0);
36 ret += (m_mldCapabilities.has_value() ? 2 : 0);
37 ret += (m_apMldId.has_value() ? 1 : 0);
38 ret += (m_extMldCapabilities.has_value() ? 2 : 0);
39 return ret;
40}
41
42void
44{
45 start.WriteU8(GetSize()); // Common Info Length
47 if (m_linkIdInfo.has_value())
48 {
49 start.WriteU8(*m_linkIdInfo & 0x0f);
50 }
51 if (m_bssParamsChangeCount.has_value())
52 {
53 start.WriteU8(*m_bssParamsChangeCount);
54 }
55 if (m_mediumSyncDelayInfo.has_value())
56 {
57 start.WriteU8(m_mediumSyncDelayInfo->mediumSyncDuration);
58 uint8_t val = m_mediumSyncDelayInfo->mediumSyncOfdmEdThreshold |
59 (m_mediumSyncDelayInfo->mediumSyncMaxNTxops << 4);
60 start.WriteU8(val);
61 }
62 if (m_emlCapabilities.has_value())
63 {
64 uint16_t val =
65 m_emlCapabilities->emlsrSupport | (m_emlCapabilities->emlsrPaddingDelay << 1) |
66 (m_emlCapabilities->emlsrTransitionDelay << 4) |
67 (m_emlCapabilities->emlmrSupport << 7) | (m_emlCapabilities->emlmrDelay << 8) |
68 (m_emlCapabilities->transitionTimeout << 11);
69 start.WriteHtolsbU16(val);
70 }
71 if (m_mldCapabilities.has_value())
72 {
73 uint16_t val =
74 m_mldCapabilities->maxNSimultaneousLinks | (m_mldCapabilities->srsSupport << 4) |
75 (m_mldCapabilities->tidToLinkMappingSupport << 5) |
76 (m_mldCapabilities->freqSepForStrApMld << 7) | (m_mldCapabilities->aarSupport << 12);
77 start.WriteHtolsbU16(val);
78 }
79 if (m_apMldId.has_value())
80 {
81 start.WriteU8(*m_apMldId);
82 }
83 if (m_extMldCapabilities.has_value())
84 {
85 uint16_t val = m_extMldCapabilities->opParamUpdateSupp |
86 (m_extMldCapabilities->recommMaxSimulLinks << 1) |
87 (m_extMldCapabilities->nstrStatusUpdateSupp << 5);
88 start.WriteHtolsbU16(val);
89 }
90}
91
92uint8_t
94{
95 Buffer::Iterator i = start;
96
97 uint8_t length = i.ReadU8();
99 uint8_t count = 7;
100
101 if ((presence & 0x0001) != 0)
102 {
103 m_linkIdInfo = i.ReadU8() & 0x0f;
104 count++;
105 }
106 if ((presence & 0x0002) != 0)
107 {
109 count++;
110 }
111 if ((presence & 0x0004) != 0)
112 {
114 m_mediumSyncDelayInfo->mediumSyncDuration = i.ReadU8();
115 uint8_t val = i.ReadU8();
116 m_mediumSyncDelayInfo->mediumSyncOfdmEdThreshold = val & 0x0f;
117 m_mediumSyncDelayInfo->mediumSyncMaxNTxops = (val >> 4) & 0x0f;
118 count += 2;
119 }
120 if ((presence & 0x0008) != 0)
121 {
123 uint16_t val = i.ReadLsbtohU16();
124 m_emlCapabilities->emlsrSupport = val & 0x0001;
125 m_emlCapabilities->emlsrPaddingDelay = (val >> 1) & 0x0007;
126 m_emlCapabilities->emlsrTransitionDelay = (val >> 4) & 0x0007;
127 m_emlCapabilities->emlmrSupport = (val >> 7) & 0x0001;
128 m_emlCapabilities->emlmrDelay = (val >> 8) & 0x0007;
129 m_emlCapabilities->transitionTimeout = (val >> 11) & 0x000f;
130 count += 2;
131 }
132 if ((presence & 0x0010) != 0)
133 {
135 uint16_t val = i.ReadLsbtohU16();
136 m_mldCapabilities->maxNSimultaneousLinks = val & 0x000f;
137 m_mldCapabilities->srsSupport = (val >> 4) & 0x0001;
138 m_mldCapabilities->tidToLinkMappingSupport = (val >> 5) & 0x0003;
139 m_mldCapabilities->freqSepForStrApMld = (val >> 7) & 0x001f;
140 m_mldCapabilities->aarSupport = (val >> 12) & 0x0001;
141 count += 2;
142 }
143 if ((presence & 0x0020) != 0)
144 {
145 m_apMldId = i.ReadU8();
146 count++;
147 }
148 if ((presence & 0x0040) != 0)
149 {
151 auto val = i.ReadLsbtohU16();
152 m_extMldCapabilities->opParamUpdateSupp = val & 0x0001;
153 m_extMldCapabilities->recommMaxSimulLinks = (val >> 1) & 0x000f;
154 m_extMldCapabilities->nstrStatusUpdateSupp = (val >> 5) & 0x0001;
155 count += 2;
156 }
157
158 NS_ABORT_MSG_IF(count != length,
159 "Common Info Length (" << +length
160 << ") differs "
161 "from actual number of bytes read ("
162 << +count << ")");
163 return count;
164}
165
166uint8_t
168{
169 auto delayUs = delay.GetMicroSeconds();
170
171 if (delayUs == 0)
172 {
173 return 0;
174 }
175
176 for (uint8_t i = 1; i <= 4; i++)
177 {
178 if (1 << (i + 4) == delayUs)
179 {
180 return i;
181 }
182 }
183
184 NS_ABORT_MSG("Value not allowed (" << delay.As(Time::US) << ")");
185 return 0;
186}
187
188Time
190{
191 NS_ABORT_MSG_IF(value > 4, "Value not allowed (" << +value << ")");
192 if (value == 0)
193 {
194 return MicroSeconds(0);
195 }
196 return MicroSeconds(1 << (4 + value));
197}
198
199uint8_t
201{
202 auto delayUs = delay.GetMicroSeconds();
203
204 if (delayUs == 0)
205 {
206 return 0;
207 }
208
209 for (uint8_t i = 1; i <= 5; i++)
210 {
211 if (1 << (i + 3) == delayUs)
212 {
213 return i;
214 }
215 }
216
217 NS_ABORT_MSG("Value not allowed (" << delay.As(Time::US) << ")");
218 return 0;
219}
220
221Time
223{
224 NS_ABORT_MSG_IF(value > 5, "Value not allowed (" << +value << ")");
225 if (value == 0)
226 {
227 return MicroSeconds(0);
228 }
229 return MicroSeconds(1 << (3 + value));
230}
231
232void
234{
235 int64_t delayUs = delay.GetMicroSeconds();
236 NS_ABORT_MSG_IF(delayUs % 32 != 0, "Delay must be a multiple of 32 microseconds");
237 delayUs /= 32;
238
239 if (!m_mediumSyncDelayInfo.has_value())
240 {
242 }
243 m_mediumSyncDelayInfo->mediumSyncDuration = (delayUs & 0xff);
244}
245
246Time
252
253void
255{
256 NS_ABORT_MSG_IF(threshold < -72 || threshold > -62, "Threshold may range from -72 to -62 dBm");
257 uint8_t value = 72 + threshold;
258
259 if (!m_mediumSyncDelayInfo.has_value())
260 {
262 }
264}
265
266int8_t
268{
270 return (m_mediumSyncDelayInfo->mediumSyncOfdmEdThreshold) - 72;
271}
272
273void
275{
276 NS_ASSERT_MSG(nTxops < 16, "Value " << +nTxops << "cannot be encoded in 4 bits");
277
278 if (!m_mediumSyncDelayInfo.has_value())
279 {
281 }
282
283 if (nTxops == 0)
284 {
285 // no limit on max number of TXOPs
287 return;
288 }
289
290 m_mediumSyncDelayInfo->mediumSyncMaxNTxops = --nTxops;
291}
292
293std::optional<uint8_t>
295{
297 uint8_t nTxops = m_mediumSyncDelayInfo->mediumSyncMaxNTxops;
298 if (nTxops == 15)
299 {
300 return std::nullopt;
301 }
302 return nTxops + 1;
303}
304
305} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
uint16_t ReadLsbtohU16()
Definition buffer.cc:1053
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:404
@ US
microsecond
Definition nstime.h:107
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:402
#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(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1368
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
Extended MLD Capabilities and Operations subfield.
Medium Synchronization Delay Information subfield.
uint8_t mediumSyncOfdmEdThreshold
Medium Synchronization OFDM ED Threshold.
uint8_t mediumSyncDuration
Medium Synchronization Duration.
uint8_t mediumSyncMaxNTxops
Medium Synchronization MAximum Number of TXOPs.
uint16_t GetPresenceBitmap() const
Get the Presence Bitmap subfield of the Common Info field.
uint8_t GetSize() const
Get the size of the serialized Common Info field.
static uint8_t EncodeEmlsrTransitionDelay(Time delay)
static Time DecodeEmlsrTransitionDelay(uint8_t value)
std::optional< EmlCapabilities > m_emlCapabilities
EML Capabilities.
std::optional< ExtMldCapabilities > m_extMldCapabilities
Extended MLD Capabilities.
uint8_t Deserialize(Buffer::Iterator start, uint16_t presence)
Deserialize the Common Info field.
std::optional< uint8_t > GetMediumSyncMaxNTxops() const
Get the maximum number of TXOPs a non-AP STA is allowed to attempt to initiate while the MediumSyncDe...
int8_t GetMediumSyncOfdmEdThreshold() const
Get the Medium Synchronization OFDM ED Threshold in dBm.
std::optional< MldCapabilities > m_mldCapabilities
MLD Capabilities.
void SetMediumSyncOfdmEdThreshold(int8_t threshold)
Set the Medium Synchronization OFDM ED Threshold subfield of the Medium Synchronization Delay Informa...
static Time DecodeEmlsrPaddingDelay(uint8_t value)
void Serialize(Buffer::Iterator &start) const
Serialize the Common Info field.
std::optional< MediumSyncDelayInfo > m_mediumSyncDelayInfo
Medium Synchronization Delay Information.
void SetMediumSyncDelayTimer(Time delay)
Set the Medium Synchronization Duration subfield of the Medium Synchronization Delay Information in t...
Time GetMediumSyncDelayTimer() const
Get the Medium Synchronization Duration subfield of the Medium Synchronization Delay Information in t...
Mac48Address m_mldMacAddress
Subfields.
std::optional< uint8_t > m_bssParamsChangeCount
BSS Parameters Change Count.
void SetMediumSyncMaxNTxops(uint8_t nTxops)
Set the Medium Synchronization Maximum Number of TXOPs subfield of the Medium Synchronization Delay I...
std::optional< uint8_t > m_linkIdInfo
Link ID Info.
static uint8_t EncodeEmlsrPaddingDelay(Time delay)
std::optional< uint8_t > m_apMldId
AP MLD ID.