A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
mgt-headers.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 INRIA
3 * Copyright (c) 2009 MIRKO BANCHI
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8 * Mirko Banchi <mk.banchi@gmail.com>
9 */
10
11#include "mgt-headers.h"
12
13#include "ns3/address-utils.h"
14#include "ns3/simulator.h"
15
16namespace ns3
17{
18
19/***********************************************************
20 * Probe Request
21 ***********************************************************/
22
24
27{
28 static TypeId tid = TypeId("ns3::MgtProbeRequestHeader")
30 .SetGroupName("Wifi")
31 .AddConstructor<MgtProbeRequestHeader>();
32 return tid;
33}
34
40
41/***********************************************************
42 * Probe Response
43 ***********************************************************/
44
46
49{
50 static TypeId tid = TypeId("ns3::MgtProbeResponseHeader")
52 .SetGroupName("Wifi")
53 .AddConstructor<MgtProbeResponseHeader>();
54 return tid;
55}
56
62
63uint64_t
68
71{
72 SetMleContainingFrame();
73
74 uint32_t size = 8 /* timestamp */ + 2 /* beacon interval */;
75 size += m_capability.GetSerializedSize();
77 return size;
78}
79
80void
82{
83 SetMleContainingFrame();
84
85 Buffer::Iterator i = start;
86 i.WriteU64(Simulator::Now().GetMicroSeconds());
87 i.WriteU16(static_cast<uint16_t>(m_beaconInterval / 1024));
88 i = m_capability.Serialize(i);
90}
91
94{
95 Buffer::Iterator i = start;
96 m_timestamp = i.ReadU64();
98 m_beaconInterval *= 1024;
99 i = m_capability.Deserialize(i);
100 auto distance = i.GetDistanceFrom(start);
102 if (auto& mle = Get<MultiLinkElement>())
103 {
104 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); ++id)
105 {
106 auto& perStaProfile = mle->GetPerStaProfile(id);
107 if (perStaProfile.HasProbeResponse())
108 {
109 auto& frameInPerStaProfile = perStaProfile.GetProbeResponse();
110 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
111 }
112 }
113 }
114 return distance;
115}
116
117/***********************************************************
118 * Beacons
119 ***********************************************************/
120
122
123/* static */
124TypeId
126{
127 static TypeId tid = TypeId("ns3::MgtBeaconHeader")
129 .SetGroupName("Wifi")
130 .AddConstructor<MgtBeaconHeader>();
131 return tid;
132}
133
134TypeId
136{
137 return GetTypeId();
138}
139
140uint64_t
142{
143 return m_timestamp;
144}
145
148{
149 uint32_t size = 8 /* timestamp */ + 2 /* beacon interval */;
150 size += m_capability.GetSerializedSize();
152 return size;
153}
154
155void
157{
158 Buffer::Iterator i = start;
159 i.WriteU64(Simulator::Now().GetMicroSeconds());
160 i.WriteU16(static_cast<uint16_t>(m_beaconInterval / 1024));
161 i = m_capability.Serialize(i);
163}
164
167{
168 Buffer::Iterator i = start;
169 m_timestamp = i.ReadU64();
171 m_beaconInterval *= 1024;
172 i = m_capability.Deserialize(i);
173 auto distance = i.GetDistanceFrom(start);
175}
176
177/***********************************************************
178 * Assoc Request
179 ***********************************************************/
180
182
183TypeId
185{
186 static TypeId tid = TypeId("ns3::MgtAssocRequestHeader")
187 .SetParent<Header>()
188 .SetGroupName("Wifi")
189 .AddConstructor<MgtAssocRequestHeader>();
190 return tid;
191}
192
193TypeId
198
201{
202 SetMleContainingFrame();
203
204 uint32_t size = 0;
205 size += m_capability.GetSerializedSize();
206 size += 2; // listen interval
208 return size;
209}
210
213 const MgtAssocRequestHeader& frame) const
214{
215 uint32_t size = 0;
216 size += m_capability.GetSerializedSize();
217 size +=
220 return size;
221}
222
223void
233
234void
243
246{
247 Buffer::Iterator i = start;
248 i = m_capability.Deserialize(i);
250 auto distance = i.GetDistanceFrom(start) +
252 if (auto& mle = Get<MultiLinkElement>())
253 {
254 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); id++)
255 {
256 auto& perStaProfile = mle->GetPerStaProfile(id);
257 if (perStaProfile.HasAssocRequest())
258 {
259 auto& frameInPerStaProfile =
260 std::get<std::reference_wrapper<MgtAssocRequestHeader>>(
261 perStaProfile.GetAssocRequest())
262 .get();
263 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
264 }
265 }
266 }
267 return distance;
268}
269
272 uint16_t length,
273 const MgtAssocRequestHeader& frame)
274{
275 Buffer::Iterator i = start;
276 i = m_capability.Deserialize(i);
278 auto distance = i.GetDistanceFrom(start);
279 NS_ASSERT_MSG(distance <= length,
280 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
282 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
283}
284
296
297void
306
309 uint16_t length,
310 const MgtProbeResponseHeader& frame)
311{
312 auto i = start;
313 m_timestamp = frame.GetTimestamp();
315 i = m_capability.Deserialize(i);
316 auto distance = i.GetDistanceFrom(start);
317 NS_ASSERT_MSG(distance <= length,
318 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
320 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
321}
322
323/***********************************************************
324 * Ressoc Request
325 ***********************************************************/
326
328
329TypeId
331{
332 static TypeId tid = TypeId("ns3::MgtReassocRequestHeader")
333 .SetParent<Header>()
334 .SetGroupName("Wifi")
335 .AddConstructor<MgtReassocRequestHeader>();
336 return tid;
337}
338
339TypeId
344
347{
348 SetMleContainingFrame();
349
350 uint32_t size = 0;
351 size += m_capability.GetSerializedSize();
352 size += 2; // listen interval
353 size += 6; // current AP address
355 return size;
356}
357
369
370void
372{
373 os << "current AP address=" << m_currentApAddr << ", ";
375}
376
377void
388
389void
398
401{
402 Buffer::Iterator i = start;
403 i = m_capability.Deserialize(i);
406 auto distance = i.GetDistanceFrom(start) +
408 if (auto& mle = Get<MultiLinkElement>())
409 {
410 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); id++)
411 {
412 auto& perStaProfile = mle->GetPerStaProfile(id);
413 if (perStaProfile.HasReassocRequest())
414 {
415 auto& frameInPerStaProfile =
416 std::get<std::reference_wrapper<MgtReassocRequestHeader>>(
417 perStaProfile.GetAssocRequest())
418 .get();
419 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
420 }
421 }
422 }
423 return distance;
424}
425
428 uint16_t length,
429 const MgtReassocRequestHeader& frame)
430{
431 Buffer::Iterator i = start;
432 i = m_capability.Deserialize(i);
435 auto distance = i.GetDistanceFrom(start);
436 NS_ASSERT_MSG(distance <= length,
437 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
439 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
440}
441
442/***********************************************************
443 * Assoc/Reassoc Response
444 ***********************************************************/
445
447
448TypeId
450{
451 static TypeId tid = TypeId("ns3::MgtAssocResponseHeader")
452 .SetParent<Header>()
453 .SetGroupName("Wifi")
454 .AddConstructor<MgtAssocResponseHeader>();
455 return tid;
456}
457
458TypeId
463
466{
467 SetMleContainingFrame();
468
469 uint32_t size = 0;
470 size += m_capability.GetSerializedSize();
471 size += m_statusCode.GetSerializedSize();
472 size += 2; // aid
474 return size;
475}
476
479 const MgtAssocResponseHeader& frame) const
480{
481 uint32_t size = 0;
482 size += m_capability.GetSerializedSize();
483 size += m_statusCode.GetSerializedSize();
484 size +=
487 return size;
488}
489
490void
492{
493 os << "status code=" << m_statusCode << ", "
494 << "aid=" << m_aid << ", ";
496}
497
498void
500{
501 SetMleContainingFrame();
502
503 Buffer::Iterator i = start;
504 i = m_capability.Serialize(i);
505 i = m_statusCode.Serialize(i);
506 i.WriteU16(m_aid);
508}
509
510void
520
523{
524 Buffer::Iterator i = start;
525 i = m_capability.Deserialize(i);
526 i = m_statusCode.Deserialize(i);
527 m_aid = i.ReadU16();
528 auto distance = i.GetDistanceFrom(start) +
530 if (auto& mle = Get<MultiLinkElement>())
531 {
532 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); id++)
533 {
534 auto& perStaProfile = mle->GetPerStaProfile(id);
535 if (perStaProfile.HasAssocResponse())
536 {
537 auto& frameInPerStaProfile = perStaProfile.GetAssocResponse();
538 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
539 }
540 }
541 }
542 return distance;
543}
544
547 uint16_t length,
548 const MgtAssocResponseHeader& frame)
549{
550 Buffer::Iterator i = start;
551 i = m_capability.Deserialize(i);
552 i = m_statusCode.Deserialize(i);
553 m_aid = frame.m_aid;
554 auto distance = i.GetDistanceFrom(start);
555 NS_ASSERT_MSG(distance <= length,
556 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
558 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
559}
560
561} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:98
void WriteU64(uint64_t data)
Definition buffer.cc:870
uint64_t ReadU64()
Definition buffer.cc:973
void WriteU16(uint16_t data)
Definition buffer.cc:848
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
uint16_t ReadU16()
Definition buffer.h:1051
Protocol header serialization and deserialization.
Definition header.h:36
Implement the header for management frames of type association request.
uint32_t GetSerializedSizeImpl() const
uint32_t DeserializeImpl(Buffer::Iterator start)
uint32_t DeserializeFromPerStaProfileImpl(Buffer::Iterator start, uint16_t length, const MgtAssocRequestHeader &frame)
Deserialize this header from a Per-STA Profile subelement of a Multi-Link Element.
void SerializeImpl(Buffer::Iterator start) const
CapabilityInformation m_capability
Capability information.
void SerializeInPerStaProfileImpl(Buffer::Iterator start, const MgtAssocRequestHeader &frame) const
Serialize this header into a Per-STA Profile subelement of a Multi-Link Element.
uint16_t m_listenInterval
listen interval (in units of beacon interval)
uint32_t GetSerializedSizeInPerStaProfileImpl(const MgtAssocRequestHeader &frame) const
static TypeId GetTypeId()
Register this type.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Implement the header for management frames of type association and reassociation response.
static TypeId GetTypeId()
Register this type.
StatusCode m_statusCode
Status code.
uint32_t GetSerializedSizeImpl() const
uint32_t DeserializeFromPerStaProfileImpl(Buffer::Iterator start, uint16_t length, const MgtAssocResponseHeader &frame)
Deserialize this header from a Per-STA Profile subelement of a Multi-Link Element.
uint32_t DeserializeImpl(Buffer::Iterator start)
uint32_t GetSerializedSizeInPerStaProfileImpl(const MgtAssocResponseHeader &frame) const
CapabilityInformation m_capability
Capability information.
void SerializeImpl(Buffer::Iterator start) const
void PrintImpl(std::ostream &os) const
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SerializeInPerStaProfileImpl(Buffer::Iterator start, const MgtAssocResponseHeader &frame) const
Serialize this header into a Per-STA Profile subelement of a Multi-Link Element.
Implement the header for management frames of type beacon.
static TypeId GetTypeId()
Register this type.
uint32_t DeserializeImpl(Buffer::Iterator start)
uint64_t m_beaconInterval
Beacon interval (microseconds).
uint64_t m_timestamp
Timestamp (microseconds).
uint32_t GetSerializedSizeImpl() const
void SerializeImpl(Buffer::Iterator start) const
uint64_t GetTimestamp() const
CapabilityInformation m_capability
Capability information.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Implement the header for management frames that can be included in a Per-STA Profile subelement of a ...
Implement the header for management frames of type probe request.
static TypeId GetTypeId()
Register this type.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Implement the header for management frames of type probe response.
uint64_t GetTimestamp() const
Return the time stamp.
uint64_t m_beaconInterval
Beacon interval.
uint32_t GetSerializedSizeImpl() const
uint32_t DeserializeFromPerStaProfileImpl(Buffer::Iterator start, uint16_t length, const MgtProbeResponseHeader &frame)
Deserialize this header from a Per-STA Profile subelement of a Multi-Link Element.
uint32_t GetSerializedSizeInPerStaProfileImpl(const MgtProbeResponseHeader &frame) const
static TypeId GetTypeId()
Register this type.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint32_t DeserializeImpl(Buffer::Iterator start)
void SerializeImpl(Buffer::Iterator start) const
CapabilityInformation m_capability
Capability information.
void SerializeInPerStaProfileImpl(Buffer::Iterator start, const MgtProbeResponseHeader &frame) const
Serialize this header into a Per-STA Profile subelement of a Multi-Link Element.
uint64_t m_timestamp
Timestamp (microseconds).
Implement the header for management frames of type reassociation request.
Mac48Address m_currentApAddr
Address of the current access point.
uint16_t m_listenInterval
listen interval (in units of beacon interval)
static TypeId GetTypeId()
Register this type.
void PrintImpl(std::ostream &os) const
void SerializeInPerStaProfileImpl(Buffer::Iterator start, const MgtReassocRequestHeader &frame) const
Serialize this header into a Per-STA Profile subelement of a Multi-Link Element.
uint32_t DeserializeImpl(Buffer::Iterator start)
void SerializeImpl(Buffer::Iterator start) const
CapabilityInformation m_capability
Capability information.
uint32_t GetSerializedSizeInPerStaProfileImpl(const MgtReassocRequestHeader &frame) const
uint32_t DeserializeFromPerStaProfileImpl(Buffer::Iterator start, uint16_t length, const MgtReassocRequestHeader &frame)
Deserialize this header from a Per-STA Profile subelement of a Multi-Link Element.
uint32_t GetSerializedSizeImpl() const
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
Implement the header for management frames.
#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_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::tuple< Ssid, SupportedRates, std::optional< ExtendedSupportedRatesIE >, std::optional< HtCapabilities >, std::optional< ExtendedCapabilities >, std::optional< VhtCapabilities >, std::optional< HeCapabilities >, std::optional< He6GhzBandCapabilities >, std::optional< MultiLinkElement >, std::optional< EhtCapabilities >, std::vector< TidToLinkMapping > > AssocRequestElems
List of Information Elements included in Association Request frames.
std::tuple< Ssid, SupportedRates, std::optional< DsssParameterSet >, std::optional< ErpInformation >, std::optional< ExtendedSupportedRatesIE >, std::optional< EdcaParameterSet >, std::optional< HtCapabilities >, std::optional< HtOperation >, std::optional< ExtendedCapabilities >, std::optional< VhtCapabilities >, std::optional< VhtOperation >, std::optional< ReducedNeighborReport >, std::optional< HeCapabilities >, std::optional< HeOperation >, std::optional< MuEdcaParameterSet >, std::optional< He6GhzBandCapabilities >, std::optional< MultiLinkElement >, std::optional< EhtCapabilities >, std::optional< EhtOperation >, std::vector< TidToLinkMapping > > ProbeResponseElems
List of Information Elements included in Probe Response frames.
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
std::tuple< SupportedRates, std::optional< ExtendedSupportedRatesIE >, std::optional< EdcaParameterSet >, std::optional< HtCapabilities >, std::optional< HtOperation >, std::optional< ExtendedCapabilities >, std::optional< VhtCapabilities >, std::optional< VhtOperation >, std::optional< HeCapabilities >, std::optional< HeOperation >, std::optional< MuEdcaParameterSet >, std::optional< He6GhzBandCapabilities >, std::optional< MultiLinkElement >, std::optional< EhtCapabilities >, std::optional< EhtOperation >, std::vector< TidToLinkMapping > > AssocResponseElems
List of Information Elements included in Association Response frames.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.