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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Kirill Andreev <andreev@iitp.ru>
18 */
19
20#include "peer-link-frame.h"
21
23
24#include "ns3/mesh-wifi-interface-mac.h"
25#include "ns3/packet.h"
26#include "ns3/test.h"
27
28namespace ns3
29{
30namespace dot11s
31{
32NS_OBJECT_ENSURE_REGISTERED(PeerLinkOpenStart);
33
35 : m_capability(0),
36 m_rates(SupportedRates()),
37 m_extendedRates(ExtendedSupportedRatesIE()),
38 m_meshId(),
39 m_config(IeConfiguration())
40{
41}
42
43void
45{
46 m_capability = fields.capability;
47 m_rates = fields.rates;
49 m_meshId = fields.meshId;
50 m_config = fields.config;
51}
52
55{
57 /// \todo protocol version:
58 retval.capability = m_capability;
59 retval.rates = m_rates;
61 retval.meshId = m_meshId;
62 retval.config = m_config;
63
64 return retval;
65}
66
69{
70 static TypeId tid = TypeId("ns3::dot11s::PeerLinkOpenStart")
72 .SetGroupName("Mesh")
73 .AddConstructor<PeerLinkOpenStart>();
74 return tid;
75}
76
79{
80 return GetTypeId();
81}
82
83void
84PeerLinkOpenStart::Print(std::ostream& os) const
85{
86 os << "capability=" << m_capability << ", rates=" << m_rates;
87 os << ", ";
88 m_meshId.Print(os);
89 os << ", ";
90 m_config.Print(os);
91}
92
95{
96 uint32_t size = 0; // Peering protocol
97 size += 2; // capability
98 size += m_rates.GetSerializedSize();
100 {
101 size += m_extendedRates->GetSerializedSize();
102 }
103 size += m_meshId.GetInformationFieldSize() + 2;
104 size += m_config.GetInformationFieldSize() + 2;
105 return size;
106}
107
108void
110{
111 Buffer::Iterator i = start;
112
114 i = m_rates.Serialize(i);
115 if (m_extendedRates)
116 {
117 i = m_extendedRates->Serialize(i);
118 }
119 i = m_meshId.Serialize(i);
120 i = m_config.Serialize(i);
121}
122
125{
126 Buffer::Iterator i = start;
127
129 i = m_rates.Deserialize(i);
130 m_extendedRates.emplace();
131 auto tmp = m_extendedRates->DeserializeIfPresent(i);
132 if (tmp.GetDistanceFrom(i) == 0)
133 {
134 m_extendedRates.reset();
135 }
136 i = tmp;
137 uint8_t id = i.ReadU8();
138 uint8_t length = i.ReadU8();
141 (m_meshId.GetInformationFieldSize() != length))
142 {
143 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
144 }
146 id = i.ReadU8();
147 length = i.ReadU8();
150 (m_config.GetInformationFieldSize() != length))
151 {
152 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
153 }
155
156 return i.GetDistanceFrom(start);
157}
158
159bool
161{
162 return ((a.m_capability == b.m_capability) && (a.m_meshId.IsEqual(b.m_meshId)) &&
163 (a.m_config == b.m_config));
164}
165
167
169 : m_meshId()
170{
171}
172
173void
175{
176 m_meshId = fields.meshId;
177}
178
181{
183 /// \todo protocol version:
184 retval.meshId = m_meshId;
185
186 return retval;
187}
188
189TypeId
191{
192 static TypeId tid = TypeId("ns3::dot11s::PeerLinkCloseStart")
193 .SetParent<Header>()
194 .SetGroupName("Mesh")
195 .AddConstructor<PeerLinkCloseStart>();
196 return tid;
197}
198
199TypeId
201{
202 return GetTypeId();
203}
204
205void
206PeerLinkCloseStart::Print(std::ostream& os) const
207{
208 m_meshId.Print(os);
209}
210
213{
214 uint32_t size = 0; // Peering protocol
215 size += m_meshId.GetInformationFieldSize() + 2;
216 return size;
217}
218
219void
221{
222 Buffer::Iterator i = start;
223 i = m_meshId.Serialize(i);
224}
225
228{
229 Buffer::Iterator i = start;
230
231 uint8_t id = i.ReadU8();
232 uint8_t length = i.ReadU8();
235 (m_meshId.GetInformationFieldSize() != length))
236 {
237 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
238 }
240 return i.GetDistanceFrom(start);
241}
242
243bool
245{
246 return (a.m_meshId.IsEqual(b.m_meshId));
247}
248
250
252 : m_capability(0),
253 m_aid(0),
254 m_rates(SupportedRates()),
255 m_config(IeConfiguration())
256{
257}
258
259void
261{
262 m_capability = fields.capability;
263 m_aid = fields.aid;
264 m_rates = fields.rates;
265 m_config = fields.config;
266}
267
270{
272 /// \todo protocol version:
273 retval.capability = m_capability;
274 retval.aid = m_aid;
275 retval.rates = m_rates;
276 retval.config = m_config;
277
278 return retval;
279}
280
281TypeId
283{
284 static TypeId tid = TypeId("ns3::dot11s::PeerLinkConfirmStart")
285 .SetParent<Header>()
286 .SetGroupName("Mesh")
287 .AddConstructor<PeerLinkConfirmStart>();
288 return tid;
289}
290
291TypeId
293{
294 return GetTypeId();
295}
296
297void
298PeerLinkConfirmStart::Print(std::ostream& os) const
299{
300 os << "capability=" << m_capability << ", rates=" << m_rates;
301 os << ", ";
302 m_config.Print(os);
303}
304
307{
308 uint32_t size = 0; // Peering protocol
309 size += 2; // capability
310 size += 2; // AID of remote peer
311 size += m_rates.GetSerializedSize();
312 if (m_extendedRates)
313 {
314 size += m_extendedRates->GetSerializedSize();
315 }
316 size += m_config.GetInformationFieldSize() + 2;
317 return size;
318}
319
320void
322{
323 Buffer::Iterator i = start;
324
327 i = m_rates.Serialize(i);
328 if (m_extendedRates)
329 {
330 i = m_extendedRates->Serialize(i);
331 }
332 i = m_config.Serialize(i);
333}
334
337{
338 Buffer::Iterator i = start;
339
341 m_aid = i.ReadLsbtohU16();
342 i = m_rates.Deserialize(i);
343 m_extendedRates.emplace();
344 auto tmp = m_extendedRates->DeserializeIfPresent(i);
345 if (tmp.GetDistanceFrom(i) == 0)
346 {
347 m_extendedRates.reset();
348 }
349 i = tmp;
350 uint8_t id = i.ReadU8();
351 uint8_t length = i.ReadU8();
354 (m_config.GetInformationFieldSize() != length))
355 {
356 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
357 }
359 return i.GetDistanceFrom(start);
360}
361
362bool
364{
365 return ((a.m_capability == b.m_capability) && (a.m_aid == b.m_aid) &&
366 (a.m_config == b.m_config));
367}
368} // namespace dot11s
369} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:902
uint8_t ReadU8()
Definition: buffer.h:1027
uint16_t ReadLsbtohU16()
Definition: buffer.cc:1064
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:780
void Next()
go forward by one byte
Definition: buffer.h:853
The Extended Supported Rates Information Element.
Protocol header serialization and deserialization.
Definition: header.h:44
The Supported Rates Information Element.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
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.
Definition: ie-dot11s-id.cc:57
uint16_t GetInformationFieldSize() const override
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
Definition: ie-dot11s-id.cc:86
void Print(std::ostream &os) const override
Generate human-readable form of IE.
bool IsEqual(const IeMeshId &o) const
Equality test.
Definition: ie-dot11s-id.cc:63
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.
Definition: fatal-error.h:179
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
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.