A Discrete-Event Network Simulator
API
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_meshId(),
38 m_config(IeConfiguration())
39{
40}
41
42void
44{
45 m_capability = fields.capability;
46 m_rates = fields.rates;
47 m_meshId = fields.meshId;
48 m_config = fields.config;
49}
50
53{
56 retval.capability = m_capability;
57 retval.rates = m_rates;
58 retval.meshId = m_meshId;
59 retval.config = m_config;
60
61 return retval;
62}
63
66{
67 static TypeId tid = TypeId("ns3::dot11s::PeerLinkOpenStart")
69 .SetGroupName("Mesh")
70 .AddConstructor<PeerLinkOpenStart>();
71 return tid;
72}
73
76{
77 return GetTypeId();
78}
79
80void
81PeerLinkOpenStart::Print(std::ostream& os) const
82{
83 os << "capability=" << m_capability << ", rates=" << m_rates;
84 os << ", ";
85 m_meshId.Print(os);
86 os << ", ";
87 m_config.Print(os);
88}
89
92{
93 uint32_t size = 0; // Peering protocol
94 size += 2; // capability
95 size += m_rates.GetSerializedSize();
96 if (m_rates.GetNRates() > 8)
97 {
98 size += m_rates.extended->GetSerializedSize();
99 }
100 size += m_meshId.GetInformationFieldSize() + 2;
101 size += m_config.GetInformationFieldSize() + 2;
102 return size;
103}
104
105void
107{
109
111 i = m_rates.Serialize(i);
112 if (m_rates.GetNRates() > 8)
113 {
114 i = m_rates.extended->Serialize(i);
115 }
116 i = m_meshId.Serialize(i);
117 i = m_config.Serialize(i);
118}
119
122{
124
126 i = m_rates.Deserialize(i);
128 uint8_t id = i.ReadU8();
129 uint8_t length = i.ReadU8();
132 (m_meshId.GetInformationFieldSize() != length))
133 {
134 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
135 }
137 id = i.ReadU8();
138 length = i.ReadU8();
141 (m_config.GetInformationFieldSize() != length))
142 {
143 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
144 }
146
147 return i.GetDistanceFrom(start);
148}
149
150bool
152{
153 return ((a.m_capability == b.m_capability) && (a.m_meshId.IsEqual(b.m_meshId)) &&
154 (a.m_config == b.m_config));
155}
156
158
160 : m_meshId()
161{
162}
163
164void
166{
167 m_meshId = fields.meshId;
168}
169
172{
175 retval.meshId = m_meshId;
176
177 return retval;
178}
179
180TypeId
182{
183 static TypeId tid = TypeId("ns3::dot11s::PeerLinkCloseStart")
184 .SetParent<Header>()
185 .SetGroupName("Mesh")
186 .AddConstructor<PeerLinkCloseStart>();
187 return tid;
188}
189
190TypeId
192{
193 return GetTypeId();
194}
195
196void
197PeerLinkCloseStart::Print(std::ostream& os) const
198{
199 m_meshId.Print(os);
200}
201
204{
205 uint32_t size = 0; // Peering protocol
206 size += m_meshId.GetInformationFieldSize() + 2;
207 return size;
208}
209
210void
212{
214 i = m_meshId.Serialize(i);
215}
216
219{
221
222 uint8_t id = i.ReadU8();
223 uint8_t length = i.ReadU8();
226 (m_meshId.GetInformationFieldSize() != length))
227 {
228 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
229 }
231 return i.GetDistanceFrom(start);
232}
233
234bool
236{
237 return ((a.m_meshId.IsEqual(b.m_meshId)));
238}
239
241
243 : m_capability(0),
244 m_aid(0),
245 m_rates(SupportedRates()),
246 m_config(IeConfiguration())
247{
248}
249
250void
252{
253 m_capability = fields.capability;
254 m_aid = fields.aid;
255 m_rates = fields.rates;
256 m_config = fields.config;
257}
258
261{
264 retval.capability = m_capability;
265 retval.aid = m_aid;
266 retval.rates = m_rates;
267 retval.config = m_config;
268
269 return retval;
270}
271
272TypeId
274{
275 static TypeId tid = TypeId("ns3::dot11s::PeerLinkConfirmStart")
276 .SetParent<Header>()
277 .SetGroupName("Mesh")
278 .AddConstructor<PeerLinkConfirmStart>();
279 return tid;
280}
281
282TypeId
284{
285 return GetTypeId();
286}
287
288void
289PeerLinkConfirmStart::Print(std::ostream& os) const
290{
291 os << "capability=" << m_capability << ", rates=" << m_rates;
292 os << ", ";
293 m_config.Print(os);
294}
295
298{
299 uint32_t size = 0; // Peering protocol
300 size += 2; // capability
301 size += 2; // AID of remote peer
302 size += m_rates.GetSerializedSize();
303 if (m_rates.GetNRates() > 8)
304 {
305 size += m_rates.extended->GetSerializedSize();
306 }
307 size += m_config.GetInformationFieldSize() + 2;
308 return size;
309}
310
311void
313{
315
318 i = m_rates.Serialize(i);
319 if (m_rates.GetNRates() > 8)
320 {
321 i = m_rates.extended->Serialize(i);
322 }
323 i = m_config.Serialize(i);
324}
325
328{
330
332 m_aid = i.ReadLsbtohU16();
333 i = m_rates.Deserialize(i);
335 uint8_t id = i.ReadU8();
336 uint8_t length = i.ReadU8();
339 (m_config.GetInformationFieldSize() != length))
340 {
341 NS_FATAL_ERROR("Broken frame: Element ID does not match IE itself!");
342 }
344 return i.GetDistanceFrom(start);
345}
346
347bool
349{
350 return ((a.m_capability == b.m_capability) && (a.m_aid == b.m_aid) &&
351 (a.m_config == b.m_config));
352}
353} // namespace dot11s
354} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:905
uint8_t ReadU8()
Definition: buffer.h:1027
uint16_t ReadLsbtohU16()
Definition: buffer.cc:1067
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:783
void Next()
go forward by one byte
Definition: buffer.h:853
Protocol header serialization and deserialization.
Definition: header.h:44
The Supported Rates Information Element.
uint8_t GetNRates() const
Return the number of supported rates.
std::optional< ExtendedSupportedRatesIE > extended
extended supported rates info element
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
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...
static Buffer::Iterator DeserializeIfPresent(std::optional< IE > &optElem, Buffer::Iterator i, Args &&... args)
Deserialize an entire IE (which may possibly be fragmented into multiple elements) that is optionally...
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:94
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.