A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-mac-pl-headers.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Ritsumeikan University, Shiga, Japan.
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 * Author: Alberto Gallegos Ramonet <ramonet@fc.ritsumei.ac.jp>
18 */
19
21
22#include <ns3/address-utils.h>
23#include <ns3/simulator.h>
24
25namespace ns3
26{
27namespace lrwpan
28{
29
30/***********************************************************
31 * Beacon MAC Payload
32 ***********************************************************/
33
35{
36}
37
39
42{
43 static TypeId tid = TypeId("ns3::BeaconPayloadHeader")
45 .SetGroupName("LrWpan")
46 .AddConstructor<BeaconPayloadHeader>();
47 return tid;
48}
49
52{
53 return GetTypeId();
54}
55
58{
59 uint32_t size = 0;
60 size += sizeof(m_superframeField);
63
64 return size;
65}
66
67void
69{
70 Buffer::Iterator i = start;
74}
75
78{
79 Buffer::Iterator i = start;
83
84 return i.GetDistanceFrom(start);
85}
86
87void
88BeaconPayloadHeader::Print(std::ostream& os) const
89{
90 os << "| Superframe Spec Field | = " << m_superframeField
91 << "| GTS Spec Field | = " << m_gtsFields.GetGtsSpecField()
92 << "| Pending Spec Field| =" << m_pndAddrFields.GetPndAddrSpecField();
93}
94
95void
97{
99}
100
101void
103{
104 m_gtsFields = gtsFields;
105}
106
107void
109{
110 m_pndAddrFields = pndAddrFields;
111}
112
113uint16_t
115{
116 return m_superframeField;
117}
118
121{
122 return m_gtsFields;
123}
124
127{
128 return m_pndAddrFields;
129}
130
131/***********************************************************
132 * Command MAC Payload
133 ***********************************************************/
134
136{
138}
139
141{
142 SetCommandFrameType(macCmd);
143}
144
146
147TypeId
149{
150 static TypeId tid = TypeId("ns3::CommandPayloadHeader")
151 .SetParent<Header>()
152 .SetGroupName("LrWpan")
153 .AddConstructor<CommandPayloadHeader>();
154 return tid;
155}
156
157TypeId
159{
160 return GetTypeId();
161}
162
165{
166 uint32_t size = 1;
167 // TODO: add missing serialize commands size when other commands are added.
168 switch (m_cmdFrameId)
169 {
170 case ASSOCIATION_REQ:
171 size += 1; // (Capability field)
172 break;
173 case ASSOCIATION_RESP:
174 size += 3; // (short address + Association Status)
175 break;
177 case DATA_REQ:
178 case PANID_CONFLICT:
179 case ORPHAN_NOTIF:
180 case BEACON_REQ:
181 break;
182 case COOR_REALIGN:
183 size += 8;
184 break;
185 case GTS_REQ:
186 case CMD_RESERVED:
187 break;
188 }
189 return size;
190}
191
192void
194{
195 Buffer::Iterator i = start;
197 // TODO: add missing serialize commands when other commands are added.
198 switch (m_cmdFrameId)
199 {
200 case ASSOCIATION_REQ:
202 break;
203 case ASSOCIATION_RESP:
206 break;
208 case DATA_REQ:
209 case PANID_CONFLICT:
210 case ORPHAN_NOTIF:
211 case BEACON_REQ:
212 break;
213 case COOR_REALIGN:
214 i.WriteU16(m_panid);
216 i.WriteU8(m_logCh);
219 break;
220 case GTS_REQ:
221 case CMD_RESERVED:
222 break;
223 }
224}
225
228{
229 Buffer::Iterator i = start;
230 m_cmdFrameId = static_cast<MacCommand>(i.ReadU8());
231 // TODO: add missing deserialize commands when other commands are added.
232 switch (m_cmdFrameId)
233 {
234 case ASSOCIATION_REQ:
236 break;
237 case ASSOCIATION_RESP:
239 m_assocStatus = i.ReadU8();
240 break;
242 case DATA_REQ:
243 case PANID_CONFLICT:
244 case ORPHAN_NOTIF:
245 case BEACON_REQ:
246 break;
247 case COOR_REALIGN:
248 m_panid = i.ReadU16();
250 m_logCh = i.ReadU8();
252 m_logChPage = i.ReadU8();
253 break;
254 case GTS_REQ:
255 case CMD_RESERVED:
256 break;
257 }
258
259 return i.GetDistanceFrom(start);
260}
261
262void
263CommandPayloadHeader::Print(std::ostream& os) const
264{
265 os << "| MAC Command Frame ID | = " << static_cast<uint32_t>(m_cmdFrameId);
266 switch (m_cmdFrameId)
267 {
268 case ASSOCIATION_REQ: {
270 os << "| Device Type FFD | = " << capability.IsDeviceTypeFfd()
271 << "| Alternative Power Source available | = " << capability.IsPowSrcAvailable()
272 << "| Receiver on when Idle | = " << capability.IsReceiverOnWhenIdle()
273 << "| Security capable | = " << capability.IsSecurityCapability()
274 << "| Allocate address on | = " << capability.IsShortAddrAllocOn();
275 break;
276 }
277 case ASSOCIATION_RESP:
278 os << "| Assigned Short Address | = " << m_shortAddr
279 << "| Status Response | = " << m_assocStatus;
280 break;
282 case DATA_REQ:
283 case PANID_CONFLICT:
284 case ORPHAN_NOTIF:
285 case BEACON_REQ:
286 break;
287 case COOR_REALIGN:
288 os << "| PAN identifier| = " << m_panid
289 << "| PAN Coord Short address| = " << m_coordShortAddr
290 << "| Channel Num.| = " << static_cast<uint32_t>(m_logCh)
291 << "| Short address| = " << m_shortAddr
292 << "| Page Num.| = " << static_cast<uint32_t>(m_logChPage);
293 break;
294 case GTS_REQ:
295 case CMD_RESERVED:
296 default:
297 break;
298 }
299}
300
301void
303{
304 m_cmdFrameId = macCommand;
305}
306
307void
309{
311 m_capabilityInfo = cap;
312}
313
314void
316{
318 m_coordShortAddr = addr;
319}
320
321void
323{
325 m_logCh = channel;
326}
327
328void
330{
332 m_logChPage = page;
333}
334
335void
337{
339 m_panid = id;
340}
341
344{
345 switch (m_cmdFrameId)
346 {
347 case 0x01:
348 return ASSOCIATION_REQ;
349 case 0x02:
350 return ASSOCIATION_RESP;
351 case 0x03:
353 case 0x04:
354 return DATA_REQ;
355 case 0x05:
356 return PANID_CONFLICT;
357 case 0x06:
358 return ORPHAN_NOTIF;
359 case 0x07:
360 return BEACON_REQ;
361 case 0x08:
362 return COOR_REALIGN;
363 case 0x09:
364 return GTS_REQ;
365 default:
366 return CMD_RESERVED;
367 }
368}
369
370void
372{
374 m_shortAddr = shortAddr;
375}
376
377void
379{
381 m_assocStatus = status;
382}
383
386{
387 return m_shortAddr;
388}
389
390uint8_t
392{
394 return m_assocStatus;
395}
396
397uint8_t
399{
401 return m_capabilityInfo;
402}
403
406{
408 return m_coordShortAddr;
409}
410
411uint8_t
413{
415 return m_logCh;
416}
417
418uint8_t
420{
422 return m_logChPage;
423}
424
425uint16_t
427{
429 return m_panid;
430}
431
432} // namespace lrwpan
433} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
uint8_t ReadU8()
Definition: buffer.h:1027
void WriteU8(uint8_t data)
Definition: buffer.h:881
void WriteU16(uint16_t data)
Definition: buffer.cc:859
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:780
uint16_t ReadU16()
Definition: buffer.h:1035
Protocol header serialization and deserialization.
Definition: header.h:44
This class can contain 16 bit addresses.
Definition: mac16-address.h:44
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Implements the header for the MAC payload beacon frame according to the IEEE 802.15....
static TypeId GetTypeId()
Get the type ID.
void SetSuperframeSpecField(uint16_t sfrmField)
Set the superframe specification field to the beacon payload header.
uint16_t GetSuperframeSpecField() const
Get the superframe specification field from the beacon payload header.
GtsFields GetGtsFields() const
Get the Guaranteed Time Slots (GTS) fields from the beacon payload header.
uint32_t GetSerializedSize() const override
void SetGtsFields(GtsFields gtsFields)
Set the superframe Guaranteed Time Slot (GTS) fields to the beacon payload header.
PendingAddrFields GetPndAddrFields() const
Get the pending address fields from the beacon payload header.
uint16_t m_superframeField
Superframe Specification Field.
void Serialize(Buffer::Iterator start) const override
void Print(std::ostream &os) const override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint32_t Deserialize(Buffer::Iterator start) override
PendingAddrFields m_pndAddrFields
Pending Address Fields.
void SetPndAddrFields(PendingAddrFields pndAddrFields)
Set the superframe Pending Address fields to the beacon payload header.
Represent the Capability Information Field.
bool IsShortAddrAllocOn() const
True if the device wishes the coordinator to allocate a short address as result of the association pr...
bool IsSecurityCapability() const
True if the device is capable of sending and receiving cryptographically protected MAC frames.
bool IsDeviceTypeFfd() const
True if the device type is a Full Functional Device (FFD) false if is a Reduced Functional Device (RF...
bool IsReceiverOnWhenIdle() const
True if the device does not disable its receiver to conserve power during idle periods.
bool IsPowSrcAvailable() const
True if the device is receiving power from alternating current mains.
Implements the header for the MAC payload command frame according to the IEEE 802....
uint16_t m_panid
The PAN identifier (Coordinator realigment command)
MacCommand GetCommandFrameType() const
Get the command frame type ID.
Mac16Address GetShortAddr() const
Get the Short address assigned by the coordinator (Association Response and Coordinator Realigment co...
void Print(std::ostream &os) const override
uint8_t GetChannel() const
Get the logical channel number.
Mac16Address m_coordShortAddr
The coordinator short address (Coordinator realigment command)
uint16_t GetPanId() const
Get the PAN identifier.
void SetPage(uint8_t page)
Set the logical channel page number.
void SetShortAddr(Mac16Address shortAddr)
Set the Short Address Assigned by the coordinator (Association Response and Coordinator Realigment Co...
uint8_t GetCapabilityField() const
Get the Capability Information Field from the command payload header.
void SetCommandFrameType(MacCommand macCmd)
Set the command frame type.
Mac16Address GetCoordShortAddr() const
Get the coordinator short address.
MacCommand m_cmdFrameId
The command Frame Identifier (Used by all commands)
void SetCapabilityField(uint8_t cap)
Set the Capability Information Field to the command payload header (Association Request Command).
void SetCoordShortAddr(Mac16Address addr)
Set the coordinator short address (16 bit address).
void Serialize(Buffer::Iterator start) const override
uint8_t m_logChPage
The channel page number (Coordinator realigment command)
uint32_t GetSerializedSize() const override
uint32_t Deserialize(Buffer::Iterator start) override
uint8_t GetPage() const
Get the logical channel page number.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
@ ASSOCIATION_RESP
Association response (RFD true: Rx)
@ PANID_CONFLICT
Pan ID conflict notification (RFD true: Tx)
@ DISASSOCIATION_NOTIF
Disassociation notification (RFD true: TX, Rx)
@ DATA_REQ
Data Request (RFD true: Tx)
@ COOR_REALIGN
Coordinator Realignment (RFD true: Rx)
@ GTS_REQ
GTS Request (RFD true: none)
@ ORPHAN_NOTIF
Orphan Notification (RFD true: Tx)
@ ASSOCIATION_REQ
Association request (RFD true: Tx)
@ BEACON_REQ
Beacon Request (RFD true: none )
Mac16Address m_shortAddr
Contains the short address assigned by the coordinator (Association Response and Coordinator Realiagm...
void SetAssociationStatus(uint8_t status)
Set status resulting from the association attempt (Association Response Command).
uint8_t GetAssociationStatus() const
Get the status resulting from an association request (Association Response Command).
void SetPanId(uint16_t id)
Get the PAN identifier.
void SetChannel(uint8_t channel)
Set the logical channel number.
uint8_t m_capabilityInfo
Capability Information Field (Association Request Command)
uint8_t m_logCh
The channel number (Coordinator realigment command)
static TypeId GetTypeId()
Get the type ID.
uint8_t m_assocStatus
Association Status (Association Response Command)
Represent the GTS information fields.
uint32_t GetSerializedSize() const
Get the size of the serialized GTS fields.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire GTS fields.
uint8_t GetGtsSpecField() const
Get the GTS Specification Field from the GTS Fields.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire GTS fields.
Represent the Pending Address Specification field.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire Pending Address Fields.
uint8_t GetPndAddrSpecField() const
Get the whole Pending Address Specification Field from the Pending Address Fields.
uint32_t GetSerializedSize() const
Get the size of the serialized Pending Address Fields.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the all the Pending Address Fields.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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.
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.