A Discrete-Event Network Simulator
API
lr-wpan-mac-pl-headers.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 Ritsumeikan University, Shiga, Japan.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Alberto Gallegos Ramonet <ramonet@fc.ritsumei.ac.jp>
19  */
20 
21 #include "lr-wpan-mac-pl-headers.h"
22 #include <ns3/simulator.h>
23 
24 namespace ns3 {
25 
26 /***********************************************************
27  * Beacon MAC Payload
28  ***********************************************************/
29 
31 {
32 }
33 
35 
36 TypeId
38 {
39  static TypeId tid = TypeId ("ns3::BeaconPayloadHeader")
40  .SetParent<Header> ()
41  .SetGroupName ("LrWpan")
42  .AddConstructor<BeaconPayloadHeader> ()
43  ;
44  return tid;
45 }
46 
47 TypeId
49 {
50  return GetTypeId ();
51 }
52 
53 uint32_t
55 {
56  uint32_t size = 0;
58  size += m_gtsFields.GetSerializedSize ();
60 
61  return size;
62 }
63 
64 void
66 {
69  i = m_gtsFields.Serialize (i);
70  i = m_pndAddrFields.Serialize (i);
71 }
72 
73 uint32_t
75 {
78  i = m_gtsFields.Deserialize (i);
80 
81  return i.GetDistanceFrom (start);
82 }
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 
94 void
96 {
97  m_superframeField = sf;
98 }
99 
100 void
102 {
103  m_gtsFields = gtsFields;
104 }
105 
106 void
108 {
109  m_pndAddrFields = pndAddrFields;
110 }
111 
114 {
115  return m_superframeField;
116 }
117 
118 GtsFields
120 {
121  return m_gtsFields;
122 }
123 
126 {
127  return m_pndAddrFields;
128 }
129 
130 
131 /***********************************************************
132  * Command MAC Payload
133  ***********************************************************/
134 
136 {
138 }
139 
140 
142 {
143  SetCommandFrameType (macCmd);
144 }
145 
147 
148 TypeId
150 {
151  static TypeId tid = TypeId ("ns3::CommandPayloadHeader")
152  .SetParent<Header> ()
153  .SetGroupName ("LrWpan")
154  .AddConstructor<CommandPayloadHeader> ()
155  ;
156  return tid;
157 }
158 
159 TypeId
161 {
162  return GetTypeId ();
163 }
164 
165 uint32_t
167 {
168  uint32_t size = 1;
169 
170  return size;
171 }
172 
173 void
175 {
177  i.WriteU8 (m_cmdFrameId);
178 }
179 
180 uint32_t
182 {
184  m_cmdFrameId = i.ReadU8 ();
185 
186  return i.GetDistanceFrom (start);
187 }
188 
189 void
190 CommandPayloadHeader::Print (std::ostream &os) const
191 {
192  os << "| MAC Command Frame ID | = " << (uint32_t) m_cmdFrameId;
193 }
194 
195 void
197 {
198  m_cmdFrameId = macCommand;
199 }
200 
201 
204 {
205  switch (m_cmdFrameId)
206  {
207  case 0x01:
208  return ASSOCIATION_REQ;
209  break;
210  case 0x02:
211  return ASSOCIATION_RESP;
212  break;
213  case 0x03:
214  return DISASSOCIATION_NOTIF;
215  break;
216  case 0x04:
217  return DATA_REQ;
218  break;
219  case 0x05:
220  return PANID_CONFLICT;
221  break;
222  case 0x06:
223  return ORPHAN_NOTIF;
224  break;
225  case 0x07:
226  return BEACON_REQ;
227  break;
228  case 0x08:
229  return COOR_REALIGN;
230  break;
231  case 0x09:
232  return GTS_REQ;
233  break;
234  default:
235  return CMD_RESERVED;
236  }
237 }
238 
239 
240 } // ns3 namespace
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire GTS fields.
Protocol header serialization and deserialization.
Definition: header.h:42
void SetCommandFrameType(MacCommand macCmd)
Set the command frame type.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the all the Pending Address Fields.
SuperframeField m_superframeField
Superframe Specification Field.
Association response (RFD true: Rx)
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire Pending Address Fields.
Association request (RFD true: Tx)
uint32_t GetSerializedSize(void) const
Get the size of the serialized GTS fields.
virtual void Serialize(Buffer::Iterator start) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
PendingAddrFields GetPndAddrFields(void) const
Coordinator Realignment (RFD true: Rx)
def start()
Definition: core.py:1855
PendingAddrFields m_pndAddrFields
Pending Address Fields.
uint8_t m_cmdFrameId
The command Frame Identifier.
static TypeId GetTypeId(void)
Get the type ID.
MacCommand
The MAC command frames.
static TypeId GetTypeId(void)
Get the type ID.
iterator in a Buffer instance
Definition: buffer.h:98
uint32_t GetSerializedSize(void) const
void SetSuperframeSpecField(SuperframeField sfrmField)
Set the superframe specification field to the beacon payload header.
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:783
TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Beacon Request (RFD true: none )
virtual void Serialize(Buffer::Iterator start) const
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire superframe specification field.
uint32_t GetSerializedSize(void) const
Get the size of the serialized Superframe specification information field.
uint8_t GetGtsSpecField(void) const
Get the GTS Specification Field from the GTS Fields.
TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
void Print(std::ostream &os) const
Pan ID conflict notification (RFD true: Tx)
SuperframeField GetSuperframeSpecField(void) const
Get the superframe specification field from the beacon payload header.
Implements the header for the MAC payload beacon frame according to the IEEE 802.15.4-2011 Std.
uint32_t Deserialize(Buffer::Iterator start)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t Deserialize(Buffer::Iterator start)
Represent the Superframe Specification information field.
GtsFields m_gtsFields
GTS Fields.
uint32_t GetSerializedSize(void) const
void Print(std::ostream &os) const
void SetGtsFields(GtsFields gtsFields)
Set the superframe Guaranteed Time Slot (GTS) fields to the beacon payload header.
uint8_t GetPndAddrSpecField(void) const
Get the whole Pending Address Specification Field from the Pending Address Fields.
Implements the header for the MAC payload command frame according to the IEEE 802.15.4-2011 Std.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire superframe specification field.
void WriteU8(uint8_t data)
Definition: buffer.h:869
MacCommand GetCommandFrameType(void) const
Get the command frame type.
void SetPndAddrFields(PendingAddrFields pndAddrFields)
Set the superframe Pending Address fields to the beacon payload header.
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint32_t GetSerializedSize(void) const
Get the size of the serialized Pending Address Fields.
Represent the Pending Address Specification field.
Represent the GTS information fields.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire GTS fields.
Orphan Notification (RFD true: Tx)
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
GtsFields GetGtsFields(void) const
Get the Guaranteed Time Slots (GTS) fields from the beacon payload header.
Disassociation notification (RFD true: TX, Rx)