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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Alberto Gallegos Ramonet <ramonet@fc.ritsumei.ac.jp>
7 */
8
10
11#include <ns3/address-utils.h>
12#include <ns3/simulator.h>
13
14namespace ns3
15{
16namespace lrwpan
17{
18
19/***********************************************************
20 * Beacon MAC Payload
21 ***********************************************************/
22
26
28
31{
32 static TypeId tid = TypeId("ns3::lrwpan::BeaconPayloadHeader")
33 .AddDeprecatedName("ns3::BeaconPayloadHeader")
35 .SetGroupName("LrWpan")
36 .AddConstructor<BeaconPayloadHeader>();
37 return tid;
38}
39
45
48{
49 uint32_t size = 0;
50 size += sizeof(m_superframeField);
53
54 return size;
55}
56
57void
65
76
77void
78BeaconPayloadHeader::Print(std::ostream& os) const
79{
80 os << "| Superframe Spec Field | = " << m_superframeField
81 << "| GTS Spec Field | = " << m_gtsFields.GetGtsSpecField()
82 << "| Pending Spec Field| =" << m_pndAddrFields.GetPndAddrSpecField();
83}
84
85void
90
91void
93{
94 m_gtsFields = gtsFields;
95}
96
97void
99{
100 m_pndAddrFields = pndAddrFields;
101}
102
103uint16_t
108
111{
112 return m_gtsFields;
113}
114
120
121/***********************************************************
122 * Command MAC Payload
123 ***********************************************************/
124
129
134
136
137TypeId
139{
140 static TypeId tid = TypeId("ns3::CommandPayloadHeader")
141 .SetParent<Header>()
142 .SetGroupName("LrWpan")
143 .AddConstructor<CommandPayloadHeader>();
144 return tid;
145}
146
147TypeId
152
155{
156 uint32_t size = 1;
157 // TODO: add missing serialize commands size when other commands are added.
158 switch (m_cmdFrameId)
159 {
160 case ASSOCIATION_REQ:
161 size += 1; // (Capability field)
162 break;
163 case ASSOCIATION_RESP:
164 size += 3; // (short address + Association Status)
165 break;
167 case DATA_REQ:
168 case PANID_CONFLICT:
169 case ORPHAN_NOTIF:
170 case BEACON_REQ:
171 break;
172 case COOR_REALIGN:
173 size += 8;
174 break;
175 case GTS_REQ:
176 case CMD_RESERVED:
177 break;
178 }
179 return size;
180}
181
182void
184{
185 Buffer::Iterator i = start;
187 // TODO: add missing serialize commands when other commands are added.
188 switch (m_cmdFrameId)
189 {
190 case ASSOCIATION_REQ:
192 break;
193 case ASSOCIATION_RESP:
196 break;
198 case DATA_REQ:
199 case PANID_CONFLICT:
200 case ORPHAN_NOTIF:
201 case BEACON_REQ:
202 break;
203 case COOR_REALIGN:
204 i.WriteU16(m_panid);
206 i.WriteU8(m_logCh);
209 break;
210 case GTS_REQ:
211 case CMD_RESERVED:
212 break;
213 }
214}
215
218{
219 Buffer::Iterator i = start;
220 m_cmdFrameId = static_cast<MacCommand>(i.ReadU8());
221 // TODO: add missing deserialize commands when other commands are added.
222 switch (m_cmdFrameId)
223 {
224 case ASSOCIATION_REQ:
226 break;
227 case ASSOCIATION_RESP:
229 m_assocStatus = i.ReadU8();
230 break;
232 case DATA_REQ:
233 case PANID_CONFLICT:
234 case ORPHAN_NOTIF:
235 case BEACON_REQ:
236 break;
237 case COOR_REALIGN:
238 m_panid = i.ReadU16();
240 m_logCh = i.ReadU8();
242 m_logChPage = i.ReadU8();
243 break;
244 case GTS_REQ:
245 case CMD_RESERVED:
246 break;
247 }
248
249 return i.GetDistanceFrom(start);
250}
251
252void
253CommandPayloadHeader::Print(std::ostream& os) const
254{
255 os << "| MAC Command Frame ID | = " << static_cast<uint32_t>(m_cmdFrameId);
256 switch (m_cmdFrameId)
257 {
258 case ASSOCIATION_REQ: {
260 os << "| Device Type FFD | = " << capability.IsDeviceTypeFfd()
261 << "| Alternative Power Source available | = " << capability.IsPowSrcAvailable()
262 << "| Receiver on when Idle | = " << capability.IsReceiverOnWhenIdle()
263 << "| Security capable | = " << capability.IsSecurityCapability()
264 << "| Allocate address on | = " << capability.IsShortAddrAllocOn();
265 break;
266 }
267 case ASSOCIATION_RESP:
268 os << "| Assigned Short Address | = " << m_shortAddr
269 << "| Status Response | = " << m_assocStatus;
270 break;
272 case DATA_REQ:
273 case PANID_CONFLICT:
274 case ORPHAN_NOTIF:
275 case BEACON_REQ:
276 break;
277 case COOR_REALIGN:
278 os << "| PAN identifier| = " << m_panid
279 << "| PAN Coord Short address| = " << m_coordShortAddr
280 << "| Channel Num.| = " << static_cast<uint32_t>(m_logCh)
281 << "| Short address| = " << m_shortAddr
282 << "| Page Num.| = " << static_cast<uint32_t>(m_logChPage);
283 break;
284 case GTS_REQ:
285 case CMD_RESERVED:
286 default:
287 break;
288 }
289}
290
291void
296
297void
303
304void
310
311void
313{
315 m_logCh = channel;
316}
317
318void
324
325void
331
334{
335 switch (m_cmdFrameId)
336 {
337 case 0x01:
338 return ASSOCIATION_REQ;
339 case 0x02:
340 return ASSOCIATION_RESP;
341 case 0x03:
343 case 0x04:
344 return DATA_REQ;
345 case 0x05:
346 return PANID_CONFLICT;
347 case 0x06:
348 return ORPHAN_NOTIF;
349 case 0x07:
350 return BEACON_REQ;
351 case 0x08:
352 return COOR_REALIGN;
353 case 0x09:
354 return GTS_REQ;
355 default:
356 return CMD_RESERVED;
357 }
358}
359
360void
366
367void
373
379
380uint8_t
386
387uint8_t
393
400
401uint8_t
407
408uint8_t
414
415uint16_t
421
422} // namespace lrwpan
423} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
void WriteU16(uint16_t data)
Definition buffer.cc:848
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
uint16_t ReadU16()
Definition buffer.h:1024
Protocol header serialization and deserialization.
Definition header.h:33
This class can contain 16 bit addresses.
a unique identifier for an interface.
Definition type-id.h:48
TypeId AddDeprecatedName(const std::string &name)
Add an deprecated name for a TypeId.
Definition type-id.cc:862
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:55
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
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.