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
23NS_OBJECT_ENSURE_REGISTERED(MgtProbeRequestHeader);
24
25TypeId
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
69void
74
80
86
87uint64_t
92
95{
96 uint32_t size = 8 /* timestamp */ + 2 /* beacon interval */;
99 return size;
100}
101
102void
111
123
124/***********************************************************
125 * Beacons
126 ***********************************************************/
127
129
130/* static */
131TypeId
133{
134 static TypeId tid = TypeId("ns3::MgtBeaconHeader")
136 .SetGroupName("Wifi")
137 .AddConstructor<MgtBeaconHeader>();
138 return tid;
139}
140
141/***********************************************************
142 * Assoc Request
143 ***********************************************************/
144
146
147TypeId
149{
150 static TypeId tid = TypeId("ns3::MgtAssocRequestHeader")
151 .SetParent<Header>()
152 .SetGroupName("Wifi")
153 .AddConstructor<MgtAssocRequestHeader>();
154 return tid;
155}
156
157TypeId
162
163uint16_t
168
169void
171{
172 m_listenInterval = interval;
173}
174
180
186
189{
190 SetMleContainingFrame();
191
192 uint32_t size = 0;
194 size += 2; // listen interval
196 return size;
197}
198
210
211void
221
222void
231
234{
235 Buffer::Iterator i = start;
238 auto distance = i.GetDistanceFrom(start) +
240 if (auto& mle = Get<MultiLinkElement>())
241 {
242 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); id++)
243 {
244 auto& perStaProfile = mle->GetPerStaProfile(id);
245 if (perStaProfile.HasAssocRequest())
246 {
247 auto& frameInPerStaProfile =
248 std::get<std::reference_wrapper<MgtAssocRequestHeader>>(
249 perStaProfile.GetAssocRequest())
250 .get();
251 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
252 }
253 }
254 }
255 return distance;
256}
257
260 uint16_t length,
261 const MgtAssocRequestHeader& frame)
262{
263 Buffer::Iterator i = start;
266 auto distance = i.GetDistanceFrom(start);
267 NS_ASSERT_MSG(distance <= length,
268 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
270 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
271}
272
273/***********************************************************
274 * Ressoc Request
275 ***********************************************************/
276
278
279TypeId
281{
282 static TypeId tid = TypeId("ns3::MgtReassocRequestHeader")
283 .SetParent<Header>()
284 .SetGroupName("Wifi")
285 .AddConstructor<MgtReassocRequestHeader>();
286 return tid;
287}
288
289TypeId
294
295uint16_t
300
301void
303{
304 m_listenInterval = interval;
305}
306
312
318
319void
324
327{
328 SetMleContainingFrame();
329
330 uint32_t size = 0;
332 size += 2; // listen interval
333 size += 6; // current AP address
335 return size;
336}
337
349
350void
352{
353 os << "current AP address=" << m_currentApAddr << ", ";
355}
356
357void
368
369void
378
381{
382 Buffer::Iterator i = start;
386 auto distance = i.GetDistanceFrom(start) +
388 if (auto& mle = Get<MultiLinkElement>())
389 {
390 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); id++)
391 {
392 auto& perStaProfile = mle->GetPerStaProfile(id);
393 if (perStaProfile.HasReassocRequest())
394 {
395 auto& frameInPerStaProfile =
396 std::get<std::reference_wrapper<MgtReassocRequestHeader>>(
397 perStaProfile.GetAssocRequest())
398 .get();
399 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
400 }
401 }
402 }
403 return distance;
404}
405
408 uint16_t length,
409 const MgtReassocRequestHeader& frame)
410{
411 Buffer::Iterator i = start;
415 auto distance = i.GetDistanceFrom(start);
416 NS_ASSERT_MSG(distance <= length,
417 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
419 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
420}
421
422/***********************************************************
423 * Assoc/Reassoc Response
424 ***********************************************************/
425
427
428TypeId
430{
431 static TypeId tid = TypeId("ns3::MgtAssocResponseHeader")
432 .SetParent<Header>()
433 .SetGroupName("Wifi")
434 .AddConstructor<MgtAssocResponseHeader>();
435 return tid;
436}
437
438TypeId
443
449
450void
455
461
467
468void
470{
471 m_aid = aid;
472}
473
474uint16_t
479
482{
483 SetMleContainingFrame();
484
485 uint32_t size = 0;
487 size += m_code.GetSerializedSize();
488 size += 2; // aid
490 return size;
491}
492
505
506void
508{
509 os << "status code=" << m_code << ", "
510 << "aid=" << m_aid << ", ";
512}
513
514void
525
526void
536
539{
540 Buffer::Iterator i = start;
542 i = m_code.Deserialize(i);
543 m_aid = i.ReadLsbtohU16();
544 auto distance = i.GetDistanceFrom(start) +
546 if (auto& mle = Get<MultiLinkElement>())
547 {
548 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); id++)
549 {
550 auto& perStaProfile = mle->GetPerStaProfile(id);
551 if (perStaProfile.HasAssocResponse())
552 {
553 auto& frameInPerStaProfile = perStaProfile.GetAssocResponse();
554 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
555 }
556 }
557 }
558 return distance;
559}
560
563 uint16_t length,
564 const MgtAssocResponseHeader& frame)
565{
566 Buffer::Iterator i = start;
568 i = m_code.Deserialize(i);
569 m_aid = frame.m_aid;
570 auto distance = i.GetDistanceFrom(start);
571 NS_ASSERT_MSG(distance <= length,
572 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
574 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
575}
576
577} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteHtolsbU16(uint16_t data)
Definition buffer.cc:891
uint16_t ReadLsbtohU16()
Definition buffer.cc:1053
uint64_t ReadLsbtohU64()
Definition buffer.cc:1083
void WriteHtolsbU64(uint64_t data)
Definition buffer.cc:909
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
uint32_t GetSerializedSize() const
Return the serialized size of capability information.
Buffer::Iterator Serialize(Buffer::Iterator start) const
Serialize capability information to the given buffer.
Buffer::Iterator Deserialize(Buffer::Iterator start)
Deserialize capability information from the given buffer.
Protocol header serialization and deserialization.
Definition header.h:33
an EUI-48 address
Implement the header for management frames of type association request.
uint32_t GetSerializedSizeImpl() const
uint32_t DeserializeImpl(Buffer::Iterator start)
CapabilityInformation & Capabilities()
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.
void SetListenInterval(uint16_t interval)
Set the listen interval.
uint16_t GetListenInterval() const
Return the listen interval.
uint16_t m_listenInterval
listen 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.
CapabilityInformation & Capabilities()
static TypeId GetTypeId()
Register this type.
StatusCode GetStatusCode()
Return the 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)
void SetStatusCode(StatusCode code)
Set the status code.
uint32_t GetSerializedSizeInPerStaProfileImpl(const MgtAssocResponseHeader &frame) const
void SetAssociationId(uint16_t aid)
Set the association ID.
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.
uint16_t GetAssociationId() const
Return the association ID.
StatusCode m_code
Status code.
Implement the header for management frames of type beacon.
static TypeId GetTypeId()
Register this type.
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
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 SetBeaconIntervalUs(uint64_t us)
Set the beacon interval in microseconds unit.
uint64_t GetBeaconIntervalUs() const
Return the beacon interval in microseconds unit.
void SerializeImpl(Buffer::Iterator start) const
CapabilityInformation m_capability
Capability information.
uint64_t m_timestamp
Timestamp.
CapabilityInformation & Capabilities()
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
uint16_t GetListenInterval() const
Return the listen interval.
static TypeId GetTypeId()
Register this type.
CapabilityInformation & Capabilities()
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
void SetListenInterval(uint16_t interval)
Set the listen interval.
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
void SetCurrentApAddress(Mac48Address currentApAddr)
Set the address of the current access point.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Status code for association response.
Definition status-code.h:21
Buffer::Iterator Serialize(Buffer::Iterator start) const
Buffer::Iterator Deserialize(Buffer::Iterator start)
uint32_t GetSerializedSize() const
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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.
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.