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 SetMleContainingFrame();
97
98 uint32_t size = 8 /* timestamp */ + 2 /* beacon interval */;
101 return size;
102}
103
104void
106{
107 SetMleContainingFrame();
108
109 Buffer::Iterator i = start;
110 i.WriteHtolsbU64(Simulator::Now().GetMicroSeconds());
111 i.WriteHtolsbU16(static_cast<uint16_t>(m_beaconInterval / 1024));
112 i = m_capability.Serialize(i);
114}
115
118{
119 Buffer::Iterator i = start;
122 m_beaconInterval *= 1024;
124 auto distance = i.GetDistanceFrom(start);
126 if (auto& mle = Get<MultiLinkElement>())
127 {
128 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); ++id)
129 {
130 auto& perStaProfile = mle->GetPerStaProfile(id);
131 if (perStaProfile.HasProbeResponse())
132 {
133 auto& frameInPerStaProfile = perStaProfile.GetProbeResponse();
134 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
135 }
136 }
137 }
138 return distance;
139}
140
141/***********************************************************
142 * Beacons
143 ***********************************************************/
144
146
147/* static */
148TypeId
150{
151 static TypeId tid = TypeId("ns3::MgtBeaconHeader")
153 .SetGroupName("Wifi")
154 .AddConstructor<MgtBeaconHeader>();
155 return tid;
156}
157
158/***********************************************************
159 * Assoc Request
160 ***********************************************************/
161
163
164TypeId
166{
167 static TypeId tid = TypeId("ns3::MgtAssocRequestHeader")
168 .SetParent<Header>()
169 .SetGroupName("Wifi")
170 .AddConstructor<MgtAssocRequestHeader>();
171 return tid;
172}
173
174TypeId
179
180uint16_t
185
186void
188{
189 m_listenInterval = interval;
190}
191
197
203
206{
207 SetMleContainingFrame();
208
209 uint32_t size = 0;
211 size += 2; // listen interval
213 return size;
214}
215
227
228void
238
239void
248
251{
252 Buffer::Iterator i = start;
255 auto distance = i.GetDistanceFrom(start) +
257 if (auto& mle = Get<MultiLinkElement>())
258 {
259 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); id++)
260 {
261 auto& perStaProfile = mle->GetPerStaProfile(id);
262 if (perStaProfile.HasAssocRequest())
263 {
264 auto& frameInPerStaProfile =
265 std::get<std::reference_wrapper<MgtAssocRequestHeader>>(
266 perStaProfile.GetAssocRequest())
267 .get();
268 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
269 }
270 }
271 }
272 return distance;
273}
274
277 uint16_t length,
278 const MgtAssocRequestHeader& frame)
279{
280 Buffer::Iterator i = start;
283 auto distance = i.GetDistanceFrom(start);
284 NS_ASSERT_MSG(distance <= length,
285 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
287 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
288}
289
301
302void
311
314 uint16_t length,
315 const MgtProbeResponseHeader& frame)
316{
317 auto i = start;
318 m_timestamp = frame.GetTimestamp();
321 auto distance = i.GetDistanceFrom(start);
322 NS_ASSERT_MSG(distance <= length,
323 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
325 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
326}
327
328/***********************************************************
329 * Ressoc Request
330 ***********************************************************/
331
333
334TypeId
336{
337 static TypeId tid = TypeId("ns3::MgtReassocRequestHeader")
338 .SetParent<Header>()
339 .SetGroupName("Wifi")
340 .AddConstructor<MgtReassocRequestHeader>();
341 return tid;
342}
343
344TypeId
349
350uint16_t
355
356void
358{
359 m_listenInterval = interval;
360}
361
367
373
374void
379
382{
383 SetMleContainingFrame();
384
385 uint32_t size = 0;
387 size += 2; // listen interval
388 size += 6; // current AP address
390 return size;
391}
392
404
405void
407{
408 os << "current AP address=" << m_currentApAddr << ", ";
410}
411
412void
423
424void
433
436{
437 Buffer::Iterator i = start;
441 auto distance = i.GetDistanceFrom(start) +
443 if (auto& mle = Get<MultiLinkElement>())
444 {
445 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); id++)
446 {
447 auto& perStaProfile = mle->GetPerStaProfile(id);
448 if (perStaProfile.HasReassocRequest())
449 {
450 auto& frameInPerStaProfile =
451 std::get<std::reference_wrapper<MgtReassocRequestHeader>>(
452 perStaProfile.GetAssocRequest())
453 .get();
454 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
455 }
456 }
457 }
458 return distance;
459}
460
463 uint16_t length,
464 const MgtReassocRequestHeader& frame)
465{
466 Buffer::Iterator i = start;
470 auto distance = i.GetDistanceFrom(start);
471 NS_ASSERT_MSG(distance <= length,
472 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
474 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
475}
476
477/***********************************************************
478 * Assoc/Reassoc Response
479 ***********************************************************/
480
482
483TypeId
485{
486 static TypeId tid = TypeId("ns3::MgtAssocResponseHeader")
487 .SetParent<Header>()
488 .SetGroupName("Wifi")
489 .AddConstructor<MgtAssocResponseHeader>();
490 return tid;
491}
492
493TypeId
498
504
505void
510
516
522
523void
525{
526 m_aid = aid;
527}
528
529uint16_t
534
537{
538 SetMleContainingFrame();
539
540 uint32_t size = 0;
542 size += m_code.GetSerializedSize();
543 size += 2; // aid
545 return size;
546}
547
560
561void
563{
564 os << "status code=" << m_code << ", "
565 << "aid=" << m_aid << ", ";
567}
568
569void
580
581void
591
594{
595 Buffer::Iterator i = start;
597 i = m_code.Deserialize(i);
598 m_aid = i.ReadLsbtohU16();
599 auto distance = i.GetDistanceFrom(start) +
601 if (auto& mle = Get<MultiLinkElement>())
602 {
603 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); id++)
604 {
605 auto& perStaProfile = mle->GetPerStaProfile(id);
606 if (perStaProfile.HasAssocResponse())
607 {
608 auto& frameInPerStaProfile = perStaProfile.GetAssocResponse();
609 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
610 }
611 }
612 }
613 return distance;
614}
615
618 uint16_t length,
619 const MgtAssocResponseHeader& frame)
620{
621 Buffer::Iterator i = start;
623 i = m_code.Deserialize(i);
624 m_aid = frame.m_aid;
625 auto distance = i.GetDistanceFrom(start);
626 NS_ASSERT_MSG(distance <= length,
627 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
629 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
630}
631
632} // 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
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 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.
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.
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:49
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.
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.
Definition mgt-headers.h:95
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.