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{
27
28/***********************************************************
29 * Beacon MAC Payload
30 ***********************************************************/
31
33{
34}
35
37
40{
41 static TypeId tid = TypeId("ns3::BeaconPayloadHeader")
43 .SetGroupName("LrWpan")
44 .AddConstructor<BeaconPayloadHeader>();
45 return tid;
46}
47
50{
51 return GetTypeId();
52}
53
56{
57 uint32_t size = 0;
61
62 return size;
63}
64
65void
67{
68 Buffer::Iterator i = start;
72}
73
76{
77 Buffer::Iterator i = start;
81
82 return i.GetDistanceFrom(start);
83}
84
85void
86BeaconPayloadHeader::Print(std::ostream& os) const
87{
88 os << "| Superframe Spec Field | = " << m_superframeField
89 << "| GTS Spec Field | = " << m_gtsFields.GetGtsSpecField()
90 << "| Pending Spec Field| =" << m_pndAddrFields.GetPndAddrSpecField();
91}
92
93void
95{
97}
98
99void
101{
102 m_gtsFields = gtsFields;
103}
104
105void
107{
108 m_pndAddrFields = pndAddrFields;
109}
110
113{
114 return m_superframeField;
115}
116
119{
120 return m_gtsFields;
121}
122
125{
126 return m_pndAddrFields;
127}
128
129/***********************************************************
130 * Command MAC Payload
131 ***********************************************************/
132
134{
136}
137
139{
140 SetCommandFrameType(macCmd);
141}
142
144
145TypeId
147{
148 static TypeId tid = TypeId("ns3::CommandPayloadHeader")
149 .SetParent<Header>()
150 .SetGroupName("LrWpan")
151 .AddConstructor<CommandPayloadHeader>();
152 return tid;
153}
154
155TypeId
157{
158 return GetTypeId();
159}
160
163{
164 uint32_t size = 1;
165 // TODO: add missing serialize commands size when other commands are added.
166 switch (m_cmdFrameId)
167 {
168 case ASSOCIATION_REQ:
170 break;
171 case ASSOCIATION_RESP:
172 size += 3; // (short address + Association Status)
173 break;
175 break;
176 case DATA_REQ:
177 break;
178 case PANID_CONFLICT:
179 break;
180 case ORPHAN_NOTIF:
181 break;
182 case BEACON_REQ:
183 break;
184 case COOR_REALIGN:
185 size += 8;
186 break;
187 case GTS_REQ:
188 break;
189 case CMD_RESERVED:
190 break;
191 }
192 return size;
193}
194
195void
197{
198 Buffer::Iterator i = start;
200 // TODO: add missing serialize commands when other commands are added.
201 switch (m_cmdFrameId)
202 {
203 case ASSOCIATION_REQ:
205 break;
206 case ASSOCIATION_RESP:
209 break;
211 break;
212 case DATA_REQ:
213 break;
214 case PANID_CONFLICT:
215 break;
216 case ORPHAN_NOTIF:
217 break;
218 case BEACON_REQ:
219 break;
220 case COOR_REALIGN:
221 i.WriteU16(m_panid);
223 i.WriteU8(m_logCh);
226 break;
227 case GTS_REQ:
228 break;
229 case CMD_RESERVED:
230 break;
231 }
232}
233
236{
237 Buffer::Iterator i = start;
238 m_cmdFrameId = static_cast<MacCommand>(i.ReadU8());
239 // TODO: add missing deserialize commands when other commands are added.
240 switch (m_cmdFrameId)
241 {
242 case ASSOCIATION_REQ:
244 break;
245 case ASSOCIATION_RESP:
247 m_assocStatus = static_cast<AssocStatus>(i.ReadU8());
248 break;
250 break;
251 case DATA_REQ:
252 break;
253 case PANID_CONFLICT:
254 break;
255 case ORPHAN_NOTIF:
256 break;
257 case BEACON_REQ:
258 break;
259 case COOR_REALIGN:
260 m_panid = i.ReadU16();
262 m_logCh = i.ReadU8();
264 m_logChPage = i.ReadU8();
265 break;
266 case GTS_REQ:
267 break;
268 case CMD_RESERVED:
269 break;
270 }
271
272 return i.GetDistanceFrom(start);
273}
274
275void
276CommandPayloadHeader::Print(std::ostream& os) const
277{
278 os << "| MAC Command Frame ID | = " << static_cast<uint32_t>(m_cmdFrameId);
279 switch (m_cmdFrameId)
280 {
281 case ASSOCIATION_REQ:
282 os << "| Device Type FFD | = " << m_capabilityInfo.IsDeviceTypeFfd()
283 << "| Alternative Power Source available | = " << m_capabilityInfo.IsPowSrcAvailable()
284 << "| Receiver on when Idle | = " << m_capabilityInfo.IsReceiverOnWhenIdle()
285 << "| Security capable | = " << m_capabilityInfo.IsSecurityCapability()
286 << "| Allocate address on | = " << m_capabilityInfo.IsShortAddrAllocOn();
287 break;
288 case ASSOCIATION_RESP:
289 os << "| Assigned Short Address | = " << m_shortAddr
290 << "| Status Response | = " << m_assocStatus;
291 break;
293 break;
294 case DATA_REQ:
295 break;
296 case PANID_CONFLICT:
297 break;
298 case ORPHAN_NOTIF:
299 break;
300 case BEACON_REQ:
301 break;
302 case COOR_REALIGN:
303 os << "| PAN identifier| = " << m_panid
304 << "| PAN Coord Short address| = " << m_coordShortAddr
305 << "| Channel Num.| = " << static_cast<uint32_t>(m_logCh)
306 << "| Short address| = " << m_shortAddr
307 << "| Page Num.| = " << static_cast<uint32_t>(m_logChPage);
308 break;
309 case GTS_REQ:
310 break;
311 case CMD_RESERVED:
312 break;
313 }
314}
315
316void
318{
319 m_cmdFrameId = macCommand;
320}
321
322void
324{
326 m_capabilityInfo = cap;
327}
328
329void
331{
333 m_coordShortAddr = addr;
334}
335
336void
338{
340 m_logCh = channel;
341}
342
343void
345{
347 m_logChPage = page;
348}
349
350void
352{
354 m_panid = id;
355}
356
359{
360 switch (m_cmdFrameId)
361 {
362 case 0x01:
363 return ASSOCIATION_REQ;
364 case 0x02:
365 return ASSOCIATION_RESP;
366 case 0x03:
368 case 0x04:
369 return DATA_REQ;
370 case 0x05:
371 return PANID_CONFLICT;
372 case 0x06:
373 return ORPHAN_NOTIF;
374 case 0x07:
375 return BEACON_REQ;
376 case 0x08:
377 return COOR_REALIGN;
378 case 0x09:
379 return GTS_REQ;
380 default:
381 return CMD_RESERVED;
382 }
383}
384
385void
387{
389 m_shortAddr = shortAddr;
390}
391
392void
394{
396 m_assocStatus = status;
397}
398
401{
402 return m_shortAddr;
403}
404
407{
409 return m_assocStatus;
410}
411
414{
416 return m_capabilityInfo;
417}
418
421{
423 return m_coordShortAddr;
424}
425
426uint8_t
428{
430 return m_logCh;
431}
432
433uint8_t
435{
437 return m_logChPage;
438}
439
440uint16_t
442{
444 return m_panid;
445}
446
447} // namespace ns3
Implements the header for the MAC payload beacon frame according to the IEEE 802.15....
GtsFields GetGtsFields() const
Get the Guaranteed Time Slots (GTS) fields from the beacon payload header.
GtsFields m_gtsFields
GTS Fields.
PendingAddrFields m_pndAddrFields
Pending Address Fields.
PendingAddrFields GetPndAddrFields() const
Get the pending address fields from the beacon payload header.
SuperframeField m_superframeField
Superframe Specification Field.
void Print(std::ostream &os) const override
uint32_t Deserialize(Buffer::Iterator start) override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
static TypeId GetTypeId()
Get the type ID.
void Serialize(Buffer::Iterator start) const override
void SetSuperframeSpecField(SuperframeField sfrmField)
Set the superframe specification field to 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.
SuperframeField GetSuperframeSpecField() const
Get the superframe specification field from the beacon payload header.
void SetPndAddrFields(PendingAddrFields pndAddrFields)
Set the superframe Pending Address fields to the beacon payload header.
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:865
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:786
uint16_t ReadU16()
Definition: buffer.h:1035
Represent the Capability Information Field.
bool IsDeviceTypeFfd() const
True if the device type is a Full Functional Device (FFD) false if is a Reduced Functional Device (RF...
bool IsSecurityCapability() const
True if the device is capable of sending and receiving cryptographically protected MAC frames.
bool IsPowSrcAvailable() const
True if the device is receiving power from alternating current mains.
bool IsReceiverOnWhenIdle() const
True if the device does not disable its receiver to conserve power during idle periods.
bool IsShortAddrAllocOn() const
True if the device wishes the coordinator to allocate a short address as result of the association pr...
uint32_t GetSerializedSize() const
Get the size of the serialized Capability Information Field.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire Capability Information Field.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire Capability Information Field.
Implements the header for the MAC payload command frame according to the IEEE 802....
void SetPage(uint8_t page)
Set the logical channel page number.
AssocStatus
Association Status Field values.
CapabilityField GetCapabilityField() const
Get the Capability Information Field from the command payload header.
void SetPanId(uint16_t id)
Get the PAN identifier.
Mac16Address GetShortAddr() const
Get the Short address assigned by the coordinator (Association Response and Coordinator Realigment co...
void SetCapabilityField(CapabilityField cap)
Set the Capability Information Field to the command payload header (Association Request Command).
uint8_t GetChannel() const
Get the logical channel number.
uint16_t m_panid
The PAN identifier (Coordinator realigment command)
AssocStatus GetAssociationStatus() const
Get the status resulting from an association request (Association Response Command).
CapabilityField m_capabilityInfo
Capability Information Field (Association Request Command)
MacCommand m_cmdFrameId
The command Frame Identifier (Used by all commands)
void SetAssociationStatus(AssocStatus status)
Set status resulting from the association attempt (Association Response Command).
MacCommand GetCommandFrameType() const
Get the command frame type ID.
MacCommand
The MAC command frames.
@ ASSOCIATION_RESP
Association response (RFD true: Rx)
@ BEACON_REQ
Beacon Request (RFD true: none )
@ DATA_REQ
Data Request (RFD true: Tx)
@ ORPHAN_NOTIF
Orphan Notification (RFD true: Tx)
@ ASSOCIATION_REQ
Association request (RFD true: Tx)
@ DISASSOCIATION_NOTIF
Disassociation notification (RFD true: TX, Rx)
@ COOR_REALIGN
Coordinator Realignment (RFD true: Rx)
@ PANID_CONFLICT
Pan ID conflict notification (RFD true: Tx)
@ GTS_REQ
GTS Request (RFD true: none)
Mac16Address GetCoordShortAddr() const
Get the coordinator short address.
void Serialize(Buffer::Iterator start) const override
uint16_t GetPanId() const
Get the PAN identifier.
void SetCommandFrameType(MacCommand macCmd)
Set the command frame type.
void SetCoordShortAddr(Mac16Address addr)
Set the coordinator short address (16 bit address).
static TypeId GetTypeId()
Get the type ID.
Mac16Address m_coordShortAddr
The coordinator short address (Coordinator realigment command)
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint8_t m_logCh
The channel number (Coordinator realigment command)
uint8_t m_logChPage
The channel page number (Coordinator realigment command)
Mac16Address m_shortAddr
Contains the short address assigned by the coordinator.
AssocStatus m_assocStatus
Association Status (Association Response Command)
void SetShortAddr(Mac16Address shortAddr)
Set the Short Address Assigned by the coordinator (Association Response and Coordinator Realigment Co...
uint32_t GetSerializedSize() const override
void Print(std::ostream &os) const override
void SetChannel(uint8_t channel)
Set the logical channel number.
uint8_t GetPage() const
Get the logical channel page number.
uint32_t Deserialize(Buffer::Iterator start) override
Represent the GTS information fields.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire GTS 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.
Protocol header serialization and deserialization.
Definition: header.h:44
This class can contain 16 bit addresses.
Definition: mac16-address.h:44
Represent the Pending Address Specification field.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the all the Pending Address Fields.
uint32_t GetSerializedSize() const
Get the size of the serialized Pending Address Fields.
uint8_t GetPndAddrSpecField() const
Get the whole Pending Address Specification Field from the Pending Address Fields.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire Pending Address Fields.
Represent the Superframe Specification information field.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire superframe specification field.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire superframe specification field.
uint32_t GetSerializedSize() const
Get the size of the serialized Superframe specification information field.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
#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.