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;
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 
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:
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  break;
186  case GTS_REQ:
187  break;
188  case CMD_RESERVED:
189  break;
190  }
191  return size;
192 }
193 
194 void
196 {
199  // TODO: add missing serialize commands when other commands are added.
200  switch (m_cmdFrameId)
201  {
202  case ASSOCIATION_REQ:
204  break;
205  case ASSOCIATION_RESP:
206  WriteTo(i, m_shortAddr);
208  break;
210  break;
211  case DATA_REQ:
212  break;
213  case PANID_CONFLICT:
214  break;
215  case ORPHAN_NOTIF:
216  break;
217  case BEACON_REQ:
218  break;
219  case COOR_REALIGN:
220  break;
221  case GTS_REQ:
222  break;
223  case CMD_RESERVED:
224  break;
225  }
226 }
227 
228 uint32_t
230 {
232  m_cmdFrameId = static_cast<MacCommand>(i.ReadU8());
233  // TODO: add missing deserialize commands when other commands are added.
234  switch (m_cmdFrameId)
235  {
236  case ASSOCIATION_REQ:
238  break;
239  case ASSOCIATION_RESP:
240  ReadFrom(i, m_shortAddr);
241  m_assocStatus = static_cast<AssocStatus>(i.ReadU8());
242  break;
244  break;
245  case DATA_REQ:
246  break;
247  case PANID_CONFLICT:
248  break;
249  case ORPHAN_NOTIF:
250  break;
251  case BEACON_REQ:
252  break;
253  case COOR_REALIGN:
254  break;
255  case GTS_REQ:
256  break;
257  case CMD_RESERVED:
258  break;
259  }
260 
261  return i.GetDistanceFrom(start);
262 }
263 
264 void
265 CommandPayloadHeader::Print(std::ostream& os) const
266 {
267  os << "| MAC Command Frame ID | = " << (uint32_t)m_cmdFrameId;
268  switch (m_cmdFrameId)
269  {
270  case ASSOCIATION_REQ:
271  os << "| Device Type FFD | = " << m_capabilityInfo.IsDeviceTypeFfd()
272  << "| Alternative Power Source available | = " << m_capabilityInfo.IsPowSrcAvailable()
273  << "| Receiver on when Idle | = " << m_capabilityInfo.IsReceiverOnWhenIdle()
274  << "| Security capable | = " << m_capabilityInfo.IsSecurityCapability()
275  << "| Allocate address on | = " << m_capabilityInfo.IsShortAddrAllocOn();
276  break;
277  case ASSOCIATION_RESP:
278  os << "| Assigned Short Address | = " << m_shortAddr
279  << "| Status Response | = " << m_assocStatus;
280  break;
282  break;
283  case DATA_REQ:
284  break;
285  case PANID_CONFLICT:
286  break;
287  case ORPHAN_NOTIF:
288  break;
289  case BEACON_REQ:
290  break;
291  case COOR_REALIGN:
292  break;
293  case GTS_REQ:
294  break;
295  case CMD_RESERVED:
296  break;
297  }
298 }
299 
300 void
302 {
303  m_cmdFrameId = macCommand;
304 }
305 
306 void
308 {
310  m_capabilityInfo = cap;
311 }
312 
315 {
316  switch (m_cmdFrameId)
317  {
318  case 0x01:
319  return ASSOCIATION_REQ;
320  break;
321  case 0x02:
322  return ASSOCIATION_RESP;
323  break;
324  case 0x03:
325  return DISASSOCIATION_NOTIF;
326  break;
327  case 0x04:
328  return DATA_REQ;
329  break;
330  case 0x05:
331  return PANID_CONFLICT;
332  break;
333  case 0x06:
334  return ORPHAN_NOTIF;
335  break;
336  case 0x07:
337  return BEACON_REQ;
338  break;
339  case 0x08:
340  return COOR_REALIGN;
341  break;
342  case 0x09:
343  return GTS_REQ;
344  break;
345  default:
346  return CMD_RESERVED;
347  }
348 }
349 
350 void
352 {
354  m_shortAddr = shortAddr;
355 }
356 
357 void
359 {
361  m_assocStatus = status;
362 }
363 
366 {
368  return m_shortAddr;
369 }
370 
373 {
375  return m_assocStatus;
376 }
377 
380 {
382  return m_capabilityInfo;
383 }
384 
385 } // 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
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
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:783
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....
AssocStatus
Association Status Field values.
CapabilityField GetCapabilityField() const
Get the Capability Information Field from the command payload header.
Mac16Address GetShortAddr() const
Get the Short address assigned by the coordinator (Association Response Command).
void SetCapabilityField(CapabilityField cap)
Set the Capability Information Field to the command payload header (Association Request 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.
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)
void Serialize(Buffer::Iterator start) const override
void SetCommandFrameType(MacCommand macCmd)
Set the command frame type.
static TypeId GetTypeId()
Get the type ID.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Mac16Address m_shortAddr
Contains the short address assigned by the coordinator (Association Response Command) See IEEE 802....
AssocStatus m_assocStatus
Association Status (Association Response Command)
void SetShortAddr(Mac16Address shortAddr)
Set the Short Address Assigned by the coordinator (Association Response Command).
uint32_t GetSerializedSize() const override
void Print(std::ostream &os) const 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
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.
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:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
#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.