A Discrete-Event Network Simulator
API
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 
20 #include "lr-wpan-mac-pl-headers.h"
21 
22 #include <ns3/address-utils.h>
23 #include <ns3/simulator.h>
24 
25 namespace ns3
26 {
27 
28 /***********************************************************
29  * Beacon MAC Payload
30  ***********************************************************/
31 
33 {
34 }
35 
37 
38 TypeId
40 {
41  static TypeId tid = TypeId("ns3::BeaconPayloadHeader")
42  .SetParent<Header>()
43  .SetGroupName("LrWpan")
44  .AddConstructor<BeaconPayloadHeader>();
45  return tid;
46 }
47 
48 TypeId
50 {
51  return GetTypeId();
52 }
53 
54 uint32_t
56 {
57  uint32_t size = 0;
58  size += sizeof(m_superframeField);
61 
62  return size;
63 }
64 
65 void
67 {
70  i = m_gtsFields.Serialize(i);
72 }
73 
74 uint32_t
76 {
79  i = m_gtsFields.Deserialize(i);
81 
82  return i.GetDistanceFrom(start);
83 }
84 
85 void
86 BeaconPayloadHeader::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 
93 void
95 {
96  m_superframeField = sf;
97 }
98 
99 void
101 {
102  m_gtsFields = gtsFields;
103 }
104 
105 void
107 {
108  m_pndAddrFields = pndAddrFields;
109 }
110 
111 uint16_t
113 {
114  return m_superframeField;
115 }
116 
117 GtsFields
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 
145 TypeId
147 {
148  static TypeId tid = TypeId("ns3::CommandPayloadHeader")
149  .SetParent<Header>()
150  .SetGroupName("LrWpan")
151  .AddConstructor<CommandPayloadHeader>();
152  return tid;
153 }
154 
155 TypeId
157 {
158  return GetTypeId();
159 }
160 
161 uint32_t
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:
169  size += 1; // (Capability field)
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 
195 void
197 {
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:
207  WriteTo(i, m_shortAddr);
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);
224  WriteTo(i, m_shortAddr);
225  i.WriteU8(m_logChPage);
226  break;
227  case GTS_REQ:
228  break;
229  case CMD_RESERVED:
230  break;
231  }
232 }
233 
234 uint32_t
236 {
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:
243  m_capabilityInfo = i.ReadU8();
244  break;
245  case ASSOCIATION_RESP:
246  ReadFrom(i, m_shortAddr);
247  m_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();
263  ReadFrom(i, m_shortAddr);
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 
275 void
276 CommandPayloadHeader::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  CapabilityField capability(m_capabilityInfo);
283  os << "| Device Type FFD | = " << capability.IsDeviceTypeFfd()
284  << "| Alternative Power Source available | = " << capability.IsPowSrcAvailable()
285  << "| Receiver on when Idle | = " << capability.IsReceiverOnWhenIdle()
286  << "| Security capable | = " << capability.IsSecurityCapability()
287  << "| Allocate address on | = " << capability.IsShortAddrAllocOn();
288  break;
289  }
290  case ASSOCIATION_RESP:
291  os << "| Assigned Short Address | = " << m_shortAddr
292  << "| Status Response | = " << m_assocStatus;
293  break;
295  break;
296  case DATA_REQ:
297  break;
298  case PANID_CONFLICT:
299  break;
300  case ORPHAN_NOTIF:
301  break;
302  case BEACON_REQ:
303  break;
304  case COOR_REALIGN:
305  os << "| PAN identifier| = " << m_panid
306  << "| PAN Coord Short address| = " << m_coordShortAddr
307  << "| Channel Num.| = " << static_cast<uint32_t>(m_logCh)
308  << "| Short address| = " << m_shortAddr
309  << "| Page Num.| = " << static_cast<uint32_t>(m_logChPage);
310  break;
311  case GTS_REQ:
312  break;
313  case CMD_RESERVED:
314  break;
315  default:
316  break;
317  }
318 }
319 
320 void
322 {
323  m_cmdFrameId = macCommand;
324 }
325 
326 void
328 {
330  m_capabilityInfo = cap;
331 }
332 
333 void
335 {
337  m_coordShortAddr = addr;
338 }
339 
340 void
342 {
344  m_logCh = channel;
345 }
346 
347 void
349 {
351  m_logChPage = page;
352 }
353 
354 void
356 {
358  m_panid = id;
359 }
360 
363 {
364  switch (m_cmdFrameId)
365  {
366  case 0x01:
367  return ASSOCIATION_REQ;
368  case 0x02:
369  return ASSOCIATION_RESP;
370  case 0x03:
371  return DISASSOCIATION_NOTIF;
372  case 0x04:
373  return DATA_REQ;
374  case 0x05:
375  return PANID_CONFLICT;
376  case 0x06:
377  return ORPHAN_NOTIF;
378  case 0x07:
379  return BEACON_REQ;
380  case 0x08:
381  return COOR_REALIGN;
382  case 0x09:
383  return GTS_REQ;
384  default:
385  return CMD_RESERVED;
386  }
387 }
388 
389 void
391 {
393  m_shortAddr = shortAddr;
394 }
395 
396 void
398 {
400  m_assocStatus = status;
401 }
402 
405 {
406  return m_shortAddr;
407 }
408 
409 uint8_t
411 {
413  return m_assocStatus;
414 }
415 
416 uint8_t
418 {
420  return m_capabilityInfo;
421 }
422 
425 {
427  return m_coordShortAddr;
428 }
429 
430 uint8_t
432 {
434  return m_logCh;
435 }
436 
437 uint8_t
439 {
441  return m_logChPage;
442 }
443 
444 uint16_t
446 {
448  return m_panid;
449 }
450 
451 } // 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.
uint16_t GetSuperframeSpecField() const
Get the superframe specification field from the beacon payload header.
void SetSuperframeSpecField(uint16_t sfrmField)
Set the superframe specification field to the beacon payload header.
uint16_t m_superframeField
Superframe Specification Field.
void Print(std::ostream &os) const 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
uint32_t GetSerializedSize() const override
void SetGtsFields(GtsFields gtsFields)
Set the superframe Guaranteed Time Slot (GTS) fields to 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:859
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:780
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...
Implements the header for the MAC payload command frame according to the IEEE 802....
uint8_t m_assocStatus
Association Status (Association Response Command)
void SetPage(uint8_t page)
Set the logical channel page number.
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...
uint8_t GetChannel() const
Get the logical channel number.
uint16_t m_panid
The PAN identifier (Coordinator realigment command)
MacCommand m_cmdFrameId
The command Frame Identifier (Used by all commands)
uint8_t m_capabilityInfo
Capability Information Field (Association Request 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).
uint8_t GetCapabilityField() const
Get the Capability Information Field from the command payload header.
static TypeId GetTypeId()
Get the type ID.
void SetAssociationStatus(uint8_t status)
Set status resulting from the association attempt (Association Response Command).
Mac16Address m_coordShortAddr
The coordinator short address (Coordinator realigment command)
void SetCapabilityField(uint8_t cap)
Set the Capability Information Field to the command payload header (Association Request 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 GetAssociationStatus() const
Get the status resulting from an association request (Association Response Command).
uint8_t m_logChPage
The channel page number (Coordinator realigment command)
Mac16Address m_shortAddr
Contains the short address assigned by the coordinator (Association Response and Coordinator Realiagm...
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.
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
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
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.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#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.
channel
Definition: third.py:88