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{
22
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 }
92 size += m_meshId.GetInformationFieldSize() + 2;
93 size += m_config.GetInformationFieldSize() + 2;
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();
128 m_meshId.DeserializeInformationField(i, length);
129 if ((m_meshId.ElementId() != (WifiInformationElementId)id) ||
130 (m_meshId.GetInformationFieldSize() != length))
131 {
132 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
133 }
134 i.Next(m_meshId.GetInformationFieldSize());
135 id = i.ReadU8();
136 length = i.ReadU8();
137 m_config.DeserializeInformationField(i, length);
138 if ((m_config.ElementId() != (WifiInformationElementId)id) ||
139 (m_config.GetInformationFieldSize() != length))
140 {
141 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
142 }
143 i.Next(m_config.GetInformationFieldSize());
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
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();
222 m_meshId.DeserializeInformationField(i, length);
223 if ((m_meshId.ElementId() != (WifiInformationElementId)id) ||
224 (m_meshId.GetInformationFieldSize() != length))
225 {
226 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
227 }
228 i.Next(m_meshId.GetInformationFieldSize());
229 return i.GetDistanceFrom(start);
230}
231
232bool
234{
235 return (a.m_meshId.IsEqual(b.m_meshId));
236}
237
239
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();
341 m_config.DeserializeInformationField(i, length);
342 if ((m_config.ElementId() != (WifiInformationElementId)id) ||
343 (m_config.GetInformationFieldSize() != length))
344 {
345 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
346 }
347 i.Next(m_config.GetInformationFieldSize());
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:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Describes Mesh Configuration Element see 7.3.2.86 of 802.11s draft 3.0.
bool IsEqual(const IeMeshId &o) const
Equality test.
#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.