A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
peer-link-frame.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Kirill Andreev <andreev@iitp.ru>
7 */
8
9#include "peer-link-frame.h"
10
12
13#include "ns3/mesh-wifi-interface-mac.h"
14#include "ns3/packet.h"
15#include "ns3/test.h"
16
17namespace ns3
18{
19namespace dot11s
20{
21NS_OBJECT_ENSURE_REGISTERED(PeerLinkOpenStart);
22
24 : m_capability(0),
25 m_rates(SupportedRates()),
26 m_extendedRates(ExtendedSupportedRatesIE()),
27 m_meshId(),
28 m_config(IeConfiguration())
29{
30}
31
32void
41
44{
46 /// \todo protocol version:
47 retval.capability = m_capability;
48 retval.rates = m_rates;
50 retval.meshId = m_meshId;
51 retval.config = m_config;
52
53 return retval;
54}
55
58{
59 static TypeId tid = TypeId("ns3::dot11s::PeerLinkOpenStart")
61 .SetGroupName("Mesh")
62 .AddConstructor<PeerLinkOpenStart>();
63 return tid;
64}
65
71
72void
73PeerLinkOpenStart::Print(std::ostream& os) const
74{
75 os << "capability=" << m_capability << ", rates=" << m_rates;
76 os << ", ";
77 m_meshId.Print(os);
78 os << ", ";
79 m_config.Print(os);
80}
81
84{
85 uint32_t size = 0; // Peering protocol
86 size += 2; // capability
87 size += m_rates.GetSerializedSize();
89 {
90 size += m_extendedRates->GetSerializedSize();
91 }
94 return size;
95}
96
97void
99{
100 Buffer::Iterator i = start;
101
103 i = m_rates.Serialize(i);
104 if (m_extendedRates)
105 {
106 i = m_extendedRates->Serialize(i);
107 }
108 i = m_meshId.Serialize(i);
109 i = m_config.Serialize(i);
110}
111
114{
115 Buffer::Iterator i = start;
116
118 i = m_rates.Deserialize(i);
119 m_extendedRates.emplace();
120 auto tmp = m_extendedRates->DeserializeIfPresent(i);
121 if (tmp.GetDistanceFrom(i) == 0)
122 {
123 m_extendedRates.reset();
124 }
125 i = tmp;
126 uint8_t id = i.ReadU8();
127 uint8_t length = i.ReadU8();
130 (m_meshId.GetInformationFieldSize() != length))
131 {
132 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
133 }
135 id = i.ReadU8();
136 length = i.ReadU8();
139 (m_config.GetInformationFieldSize() != length))
140 {
141 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
142 }
144
145 return i.GetDistanceFrom(start);
146}
147
148bool
150{
151 return ((a.m_capability == b.m_capability) && (a.m_meshId.IsEqual(b.m_meshId)) &&
152 (a.m_config == b.m_config));
153}
154
156
158 : m_meshId()
159{
160}
161
162void
167
170{
172 /// \todo protocol version:
173 retval.meshId = m_meshId;
174
175 return retval;
176}
177
178TypeId
180{
181 static TypeId tid = TypeId("ns3::dot11s::PeerLinkCloseStart")
182 .SetParent<Header>()
183 .SetGroupName("Mesh")
184 .AddConstructor<PeerLinkCloseStart>();
185 return tid;
186}
187
188TypeId
190{
191 return GetTypeId();
192}
193
194void
195PeerLinkCloseStart::Print(std::ostream& os) const
196{
197 m_meshId.Print(os);
198}
199
202{
203 uint32_t size = 0; // Peering protocol
204 size += m_meshId.GetInformationFieldSize() + 2;
205 return size;
206}
207
208void
210{
211 Buffer::Iterator i = start;
212 i = m_meshId.Serialize(i);
213}
214
217{
218 Buffer::Iterator i = start;
219
220 uint8_t id = i.ReadU8();
221 uint8_t length = i.ReadU8();
224 (m_meshId.GetInformationFieldSize() != length))
225 {
226 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
227 }
229 return i.GetDistanceFrom(start);
230}
231
232bool
234{
235 return (a.m_meshId.IsEqual(b.m_meshId));
236}
237
239
241 : m_capability(0),
242 m_aid(0),
243 m_rates(SupportedRates()),
244 m_config(IeConfiguration())
245{
246}
247
248void
256
259{
261 /// \todo protocol version:
262 retval.capability = m_capability;
263 retval.aid = m_aid;
264 retval.rates = m_rates;
265 retval.config = m_config;
266
267 return retval;
268}
269
270TypeId
272{
273 static TypeId tid = TypeId("ns3::dot11s::PeerLinkConfirmStart")
274 .SetParent<Header>()
275 .SetGroupName("Mesh")
276 .AddConstructor<PeerLinkConfirmStart>();
277 return tid;
278}
279
280TypeId
285
286void
287PeerLinkConfirmStart::Print(std::ostream& os) const
288{
289 os << "capability=" << m_capability << ", rates=" << m_rates;
290 os << ", ";
291 m_config.Print(os);
292}
293
296{
297 uint32_t size = 0; // Peering protocol
298 size += 2; // capability
299 size += 2; // AID of remote peer
300 size += m_rates.GetSerializedSize();
301 if (m_extendedRates)
302 {
303 size += m_extendedRates->GetSerializedSize();
304 }
305 size += m_config.GetInformationFieldSize() + 2;
306 return size;
307}
308
309void
311{
312 Buffer::Iterator i = start;
313
316 i = m_rates.Serialize(i);
317 if (m_extendedRates)
318 {
319 i = m_extendedRates->Serialize(i);
320 }
321 i = m_config.Serialize(i);
322}
323
326{
327 Buffer::Iterator i = start;
328
330 m_aid = i.ReadLsbtohU16();
331 i = m_rates.Deserialize(i);
332 m_extendedRates.emplace();
333 auto tmp = m_extendedRates->DeserializeIfPresent(i);
334 if (tmp.GetDistanceFrom(i) == 0)
335 {
336 m_extendedRates.reset();
337 }
338 i = tmp;
339 uint8_t id = i.ReadU8();
340 uint8_t length = i.ReadU8();
343 (m_config.GetInformationFieldSize() != length))
344 {
345 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
346 }
348 return i.GetDistanceFrom(start);
349}
350
351bool
353{
354 return ((a.m_capability == b.m_capability) && (a.m_aid == b.m_aid) &&
355 (a.m_config == b.m_config));
356}
357} // namespace dot11s
358} // 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
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
void Next()
go forward by one byte
Definition buffer.h:842
The Extended Supported Rates Information Element.
Protocol header serialization and deserialization.
Definition header.h:33
The Supported Rates Information Element.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
uint16_t GetSerializedSize() const
Get the size of the serialized IE including Element ID and length fields (for every element this IE i...
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize entire IE (which may possibly be fragmented into multiple elements), which must be presen...
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize entire IE including Element ID and length fields.
Describes Mesh Configuration Element see 7.3.2.86 of 802.11s draft 3.0.
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
uint16_t DeserializeInformationField(Buffer::Iterator i, uint16_t length) override
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
void Print(std::ostream &os) const override
Generate human-readable form of IE.
uint16_t GetInformationFieldSize() const override
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
uint16_t GetInformationFieldSize() const override
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
void Print(std::ostream &os) const override
Generate human-readable form of IE.
bool IsEqual(const IeMeshId &o) const
Equality test.
uint16_t DeserializeInformationField(Buffer::Iterator start, uint16_t length) override
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
bool operator==(const MeshHeader &a, const MeshHeader &b)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.