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 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 * Mirko Banchi <mk.banchi@gmail.com>
20 */
21
22#include "mgt-headers.h"
23
24#include "ns3/address-utils.h"
25#include "ns3/simulator.h"
26
27namespace ns3
28{
29
30/***********************************************************
31 * Probe Request
32 ***********************************************************/
33
34NS_OBJECT_ENSURE_REGISTERED(MgtProbeRequestHeader);
35
36TypeId
38{
39 static TypeId tid = TypeId("ns3::MgtProbeRequestHeader")
41 .SetGroupName("Wifi")
42 .AddConstructor<MgtProbeRequestHeader>();
43 return tid;
44}
45
48{
49 return GetTypeId();
50}
51
52/***********************************************************
53 * Probe Response
54 ***********************************************************/
55
57
60{
61 static TypeId tid = TypeId("ns3::MgtProbeResponseHeader")
63 .SetGroupName("Wifi")
64 .AddConstructor<MgtProbeResponseHeader>();
65 return tid;
66}
67
70{
71 return GetTypeId();
72}
73
74uint64_t
76{
77 return m_beaconInterval;
78}
79
80void
82{
84}
85
88{
89 return m_capability;
90}
91
94{
95 return m_capability;
96}
97
98uint64_t
100{
101 return m_timestamp;
102}
103
106{
107 uint32_t size = 8 /* timestamp */ + 2 /* beacon interval */;
110 return size;
111}
112
113void
115{
116 Buffer::Iterator i = start;
117 i.WriteHtolsbU64(Simulator::Now().GetMicroSeconds());
118 i.WriteHtolsbU16(static_cast<uint16_t>(m_beaconInterval / 1024));
119 i = m_capability.Serialize(i);
121}
122
125{
126 Buffer::Iterator i = start;
129 m_beaconInterval *= 1024;
131 auto distance = i.GetDistanceFrom(start);
133}
134
135/***********************************************************
136 * Beacons
137 ***********************************************************/
138
140
141/* static */
142TypeId
144{
145 static TypeId tid = TypeId("ns3::MgtBeaconHeader")
147 .SetGroupName("Wifi")
148 .AddConstructor<MgtBeaconHeader>();
149 return tid;
150}
151
152/***********************************************************
153 * Assoc Request
154 ***********************************************************/
155
157
158TypeId
160{
161 static TypeId tid = TypeId("ns3::MgtAssocRequestHeader")
162 .SetParent<Header>()
163 .SetGroupName("Wifi")
164 .AddConstructor<MgtAssocRequestHeader>();
165 return tid;
166}
167
168TypeId
170{
171 return GetTypeId();
172}
173
174uint16_t
176{
177 return m_listenInterval;
178}
179
180void
182{
183 m_listenInterval = interval;
184}
185
188{
189 return m_capability;
190}
191
194{
195 return m_capability;
196}
197
200{
201 SetMleContainingFrame();
202
203 uint32_t size = 0;
205 size += 2; // listen interval
207 return size;
208}
209
212 const MgtAssocRequestHeader& frame) const
213{
214 uint32_t size = 0;
216 size +=
219 return size;
220}
221
222void
224{
225 SetMleContainingFrame();
226
227 Buffer::Iterator i = start;
228 i = m_capability.Serialize(i);
231}
232
233void
235 const MgtAssocRequestHeader& frame) const
236{
237 Buffer::Iterator i = start;
238 i = m_capability.Serialize(i);
241}
242
245{
246 Buffer::Iterator i = start;
249 auto distance = i.GetDistanceFrom(start) +
251 if (auto& mle = Get<MultiLinkElement>())
252 {
253 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); id++)
254 {
255 auto& perStaProfile = mle->GetPerStaProfile(id);
256 if (perStaProfile.HasAssocRequest())
257 {
258 auto& frameInPerStaProfile =
259 std::get<std::reference_wrapper<MgtAssocRequestHeader>>(
260 perStaProfile.GetAssocRequest())
261 .get();
262 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
263 }
264 }
265 }
266 return distance;
267}
268
271 uint16_t length,
272 const MgtAssocRequestHeader& frame)
273{
274 Buffer::Iterator i = start;
277 auto distance = i.GetDistanceFrom(start);
278 NS_ASSERT_MSG(distance <= length,
279 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
281 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
282}
283
284/***********************************************************
285 * Ressoc Request
286 ***********************************************************/
287
289
290TypeId
292{
293 static TypeId tid = TypeId("ns3::MgtReassocRequestHeader")
294 .SetParent<Header>()
295 .SetGroupName("Wifi")
296 .AddConstructor<MgtReassocRequestHeader>();
297 return tid;
298}
299
300TypeId
302{
303 return GetTypeId();
304}
305
306uint16_t
308{
309 return m_listenInterval;
310}
311
312void
314{
315 m_listenInterval = interval;
316}
317
320{
321 return m_capability;
322}
323
326{
327 return m_capability;
328}
329
330void
332{
333 m_currentApAddr = currentApAddr;
334}
335
338{
339 SetMleContainingFrame();
340
341 uint32_t size = 0;
343 size += 2; // listen interval
344 size += 6; // current AP address
346 return size;
347}
348
351 const MgtReassocRequestHeader& frame) const
352{
353 uint32_t size = 0;
355 size +=
358 return size;
359}
360
361void
363{
364 os << "current AP address=" << m_currentApAddr << ", ";
366}
367
368void
370{
371 SetMleContainingFrame();
372
373 Buffer::Iterator i = start;
374 i = m_capability.Serialize(i);
378}
379
380void
382 const MgtReassocRequestHeader& frame) const
383{
384 Buffer::Iterator i = start;
385 i = m_capability.Serialize(i);
388}
389
392{
393 Buffer::Iterator i = start;
397 auto distance = i.GetDistanceFrom(start) +
399 if (auto& mle = Get<MultiLinkElement>())
400 {
401 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); id++)
402 {
403 auto& perStaProfile = mle->GetPerStaProfile(id);
404 if (perStaProfile.HasReassocRequest())
405 {
406 auto& frameInPerStaProfile =
407 std::get<std::reference_wrapper<MgtReassocRequestHeader>>(
408 perStaProfile.GetAssocRequest())
409 .get();
410 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
411 }
412 }
413 }
414 return distance;
415}
416
419 uint16_t length,
420 const MgtReassocRequestHeader& frame)
421{
422 Buffer::Iterator i = start;
426 auto distance = i.GetDistanceFrom(start);
427 NS_ASSERT_MSG(distance <= length,
428 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
430 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
431}
432
433/***********************************************************
434 * Assoc/Reassoc Response
435 ***********************************************************/
436
438
439TypeId
441{
442 static TypeId tid = TypeId("ns3::MgtAssocResponseHeader")
443 .SetParent<Header>()
444 .SetGroupName("Wifi")
445 .AddConstructor<MgtAssocResponseHeader>();
446 return tid;
447}
448
449TypeId
451{
452 return GetTypeId();
453}
454
457{
458 return m_code;
459}
460
461void
463{
464 m_code = code;
465}
466
469{
470 return m_capability;
471}
472
475{
476 return m_capability;
477}
478
479void
481{
482 m_aid = aid;
483}
484
485uint16_t
487{
488 return m_aid;
489}
490
493{
494 SetMleContainingFrame();
495
496 uint32_t size = 0;
498 size += m_code.GetSerializedSize();
499 size += 2; // aid
501 return size;
502}
503
506 const MgtAssocResponseHeader& frame) const
507{
508 uint32_t size = 0;
510 size += m_code.GetSerializedSize();
511 size +=
514 return size;
515}
516
517void
519{
520 os << "status code=" << m_code << ", "
521 << "aid=" << m_aid << ", ";
523}
524
525void
527{
528 SetMleContainingFrame();
529
530 Buffer::Iterator i = start;
531 i = m_capability.Serialize(i);
532 i = m_code.Serialize(i);
535}
536
537void
539 const MgtAssocResponseHeader& frame) const
540{
541 Buffer::Iterator i = start;
542 i = m_capability.Serialize(i);
543 i = m_code.Serialize(i);
546}
547
550{
551 Buffer::Iterator i = start;
553 i = m_code.Deserialize(i);
554 m_aid = i.ReadLsbtohU16();
555 auto distance = i.GetDistanceFrom(start) +
557 if (auto& mle = Get<MultiLinkElement>())
558 {
559 for (std::size_t id = 0; id < mle->GetNPerStaProfileSubelements(); id++)
560 {
561 auto& perStaProfile = mle->GetPerStaProfile(id);
562 if (perStaProfile.HasAssocResponse())
563 {
564 auto& frameInPerStaProfile = perStaProfile.GetAssocResponse();
565 frameInPerStaProfile.CopyIesFromContainingFrame(*this);
566 }
567 }
568 }
569 return distance;
570}
571
574 uint16_t length,
575 const MgtAssocResponseHeader& frame)
576{
577 Buffer::Iterator i = start;
579 i = m_code.Deserialize(i);
580 m_aid = frame.m_aid;
581 auto distance = i.GetDistanceFrom(start);
582 NS_ASSERT_MSG(distance <= length,
583 "Bytes read (" << distance << ") exceed expected number (" << length << ")");
585 DeserializeFromPerStaProfileImpl(i, length - distance, frame);
586}
587
588} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:902
uint16_t ReadLsbtohU16()
Definition: buffer.cc:1064
uint64_t ReadLsbtohU64()
Definition: buffer.cc:1094
void WriteHtolsbU64(uint64_t data)
Definition: buffer.cc:920
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:780
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:44
an EUI-48 address
Definition: mac48-address.h:46
Implement the header for management frames of type association request.
Definition: mgt-headers.h:157
uint32_t GetSerializedSizeImpl() const
Definition: mgt-headers.cc:199
uint32_t DeserializeImpl(Buffer::Iterator start)
Definition: mgt-headers.cc:244
CapabilityInformation & Capabilities()
Definition: mgt-headers.cc:193
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.
Definition: mgt-headers.cc:270
void SerializeImpl(Buffer::Iterator start) const
Definition: mgt-headers.cc:223
CapabilityInformation m_capability
Capability information.
Definition: mgt-headers.h:231
void SerializeInPerStaProfileImpl(Buffer::Iterator start, const MgtAssocRequestHeader &frame) const
Serialize this header into a Per-STA Profile subelement of a Multi-Link Element.
Definition: mgt-headers.cc:234
void SetListenInterval(uint16_t interval)
Set the listen interval.
Definition: mgt-headers.cc:181
uint16_t GetListenInterval() const
Return the listen interval.
Definition: mgt-headers.cc:175
uint16_t m_listenInterval
listen interval
Definition: mgt-headers.h:232
uint32_t GetSerializedSizeInPerStaProfileImpl(const MgtAssocRequestHeader &frame) const
Definition: mgt-headers.cc:211
static TypeId GetTypeId()
Register this type.
Definition: mgt-headers.cc:159
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: mgt-headers.cc:169
Implement the header for management frames of type association and reassociation response.
Definition: mgt-headers.h:334
CapabilityInformation & Capabilities()
Definition: mgt-headers.cc:474
static TypeId GetTypeId()
Register this type.
Definition: mgt-headers.cc:440
StatusCode GetStatusCode()
Return the status code.
Definition: mgt-headers.cc:456
uint32_t GetSerializedSizeImpl() const
Definition: mgt-headers.cc:492
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.
Definition: mgt-headers.cc:573
uint32_t DeserializeImpl(Buffer::Iterator start)
Definition: mgt-headers.cc:549
void SetStatusCode(StatusCode code)
Set the status code.
Definition: mgt-headers.cc:462
uint32_t GetSerializedSizeInPerStaProfileImpl(const MgtAssocResponseHeader &frame) const
Definition: mgt-headers.cc:505
void SetAssociationId(uint16_t aid)
Set the association ID.
Definition: mgt-headers.cc:480
CapabilityInformation m_capability
Capability information.
Definition: mgt-headers.h:422
void SerializeImpl(Buffer::Iterator start) const
Definition: mgt-headers.cc:526
void PrintImpl(std::ostream &os) const
Definition: mgt-headers.cc:518
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: mgt-headers.cc:450
void SerializeInPerStaProfileImpl(Buffer::Iterator start, const MgtAssocResponseHeader &frame) const
Serialize this header into a Per-STA Profile subelement of a Multi-Link Element.
Definition: mgt-headers.cc:538
uint16_t GetAssociationId() const
Return the association ID.
Definition: mgt-headers.cc:486
StatusCode m_code
Status code.
Definition: mgt-headers.h:423
Implement the header for management frames of type beacon.
Definition: mgt-headers.h:512
static TypeId GetTypeId()
Register this type.
Definition: mgt-headers.cc:143
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.
Definition: mgt-headers.h:432
static TypeId GetTypeId()
Register this type.
Definition: mgt-headers.cc:37
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: mgt-headers.cc:47
Implement the header for management frames of type probe response.
Definition: mgt-headers.h:451
uint64_t GetTimestamp() const
Return the time stamp.
Definition: mgt-headers.cc:99
uint64_t m_beaconInterval
Beacon interval.
Definition: mgt-headers.h:503
uint32_t GetSerializedSizeImpl() const
Definition: mgt-headers.cc:105
static TypeId GetTypeId()
Register this type.
Definition: mgt-headers.cc:59
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: mgt-headers.cc:69
uint32_t DeserializeImpl(Buffer::Iterator start)
Definition: mgt-headers.cc:124
void SetBeaconIntervalUs(uint64_t us)
Set the beacon interval in microseconds unit.
Definition: mgt-headers.cc:81
uint64_t GetBeaconIntervalUs() const
Return the beacon interval in microseconds unit.
Definition: mgt-headers.cc:75
void SerializeImpl(Buffer::Iterator start) const
Definition: mgt-headers.cc:114
CapabilityInformation m_capability
Capability information.
Definition: mgt-headers.h:504
uint64_t m_timestamp
Timestamp.
Definition: mgt-headers.h:502
CapabilityInformation & Capabilities()
Definition: mgt-headers.cc:93
Implement the header for management frames of type reassociation request.
Definition: mgt-headers.h:241
Mac48Address m_currentApAddr
Address of the current access point.
Definition: mgt-headers.h:323
uint16_t m_listenInterval
listen interval
Definition: mgt-headers.h:325
uint16_t GetListenInterval() const
Return the listen interval.
Definition: mgt-headers.cc:307
static TypeId GetTypeId()
Register this type.
Definition: mgt-headers.cc:291
CapabilityInformation & Capabilities()
Definition: mgt-headers.cc:325
void PrintImpl(std::ostream &os) const
Definition: mgt-headers.cc:362
void SerializeInPerStaProfileImpl(Buffer::Iterator start, const MgtReassocRequestHeader &frame) const
Serialize this header into a Per-STA Profile subelement of a Multi-Link Element.
Definition: mgt-headers.cc:381
uint32_t DeserializeImpl(Buffer::Iterator start)
Definition: mgt-headers.cc:391
void SerializeImpl(Buffer::Iterator start) const
Definition: mgt-headers.cc:369
void SetListenInterval(uint16_t interval)
Set the listen interval.
Definition: mgt-headers.cc:313
CapabilityInformation m_capability
Capability information.
Definition: mgt-headers.h:324
uint32_t GetSerializedSizeInPerStaProfileImpl(const MgtReassocRequestHeader &frame) const
Definition: mgt-headers.cc:350
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.
Definition: mgt-headers.cc:418
uint32_t GetSerializedSizeImpl() const
Definition: mgt-headers.cc:337
void SetCurrentApAddress(Mac48Address currentApAddr)
Set the address of the current access point.
Definition: mgt-headers.cc:331
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: mgt-headers.cc:301
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Status code for association response.
Definition: status-code.h:32
Buffer::Iterator Serialize(Buffer::Iterator start) const
Definition: status-code.cc:54
Buffer::Iterator Deserialize(Buffer::Iterator start)
Definition: status-code.cc:61
uint32_t GetSerializedSize() const
Definition: status-code.cc:48
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
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:86
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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< MultiLinkElement >, std::optional< EhtCapabilities >, std::optional< EhtOperation >, std::vector< TidToLinkMapping > > AssocResponseElems
List of Information Elements included in Association Response frames.
Definition: mgt-headers.h:149
std::tuple< Ssid, SupportedRates, std::optional< ExtendedSupportedRatesIE >, std::optional< HtCapabilities >, std::optional< ExtendedCapabilities >, std::optional< VhtCapabilities >, std::optional< HeCapabilities >, std::optional< MultiLinkElement >, std::optional< EhtCapabilities >, std::vector< TidToLinkMapping > > AssocRequestElems
List of Information Elements included in Association Request frames.
Definition: mgt-headers.h:132
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.