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
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::CommandPayloadHeader::DISASSOCIATION_NOTIF
@ DISASSOCIATION_NOTIF
Disassociation notification (RFD true: TX, Rx)
Definition: lr-wpan-mac-pl-headers.h:119
ns3::PendingAddrFields::GetPndAddrSpecField
uint8_t GetPndAddrSpecField(void) const
Get the whole Pending Address Specification Field from the Pending Address Fields.
Definition: lr-wpan-fields.cc:340
ns3::BeaconPayloadHeader::GetSerializedSize
uint32_t GetSerializedSize(void) const
Definition: lr-wpan-mac-pl-headers.cc:54
ns3::CommandPayloadHeader::ASSOCIATION_RESP
@ ASSOCIATION_RESP
Association response (RFD true: Rx)
Definition: lr-wpan-mac-pl-headers.h:118
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::CommandPayloadHeader::GTS_REQ
@ GTS_REQ
GTS Request (RFD true: none)
Definition: lr-wpan-mac-pl-headers.h:125
ns3::Buffer::Iterator::GetDistanceFrom
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
ns3::PendingAddrFields
Represent the Pending Address Specification field.
Definition: lr-wpan-fields.h:258
ns3::CommandPayloadHeader::GetInstanceTypeId
TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: lr-wpan-mac-pl-headers.cc:160
ns3::BeaconPayloadHeader
Implements the header for the MAC payload beacon frame according to the IEEE 802.15....
Definition: lr-wpan-mac-pl-headers.h:40
ns3::BeaconPayloadHeader::GetSuperframeSpecField
SuperframeField GetSuperframeSpecField(void) const
Get the superframe specification field from the beacon payload header.
Definition: lr-wpan-mac-pl-headers.cc:113
ns3::CommandPayloadHeader::GetCommandFrameType
MacCommand GetCommandFrameType(void) const
Get the command frame type.
Definition: lr-wpan-mac-pl-headers.cc:203
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8(void)
Definition: buffer.h:1021
ns3::BeaconPayloadHeader::GetInstanceTypeId
TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: lr-wpan-mac-pl-headers.cc:48
lr-wpan-mac-pl-headers.h
ns3::CommandPayloadHeader::ORPHAN_NOTIF
@ ORPHAN_NOTIF
Orphan Notification (RFD true: Tx)
Definition: lr-wpan-mac-pl-headers.h:122
ns3::CommandPayloadHeader::SetCommandFrameType
void SetCommandFrameType(MacCommand macCmd)
Set the command frame type.
Definition: lr-wpan-mac-pl-headers.cc:196
ns3::BeaconPayloadHeader::BeaconPayloadHeader
BeaconPayloadHeader()
Definition: lr-wpan-mac-pl-headers.cc:30
ns3::BeaconPayloadHeader::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: lr-wpan-mac-pl-headers.cc:37
ns3::Buffer::Iterator::WriteU8
void WriteU8(uint8_t data)
Definition: buffer.h:869
ns3::SuperframeField
Represent the Superframe Specification information field.
Definition: lr-wpan-fields.h:55
ns3::CommandPayloadHeader::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: lr-wpan-mac-pl-headers.cc:149
ns3::CommandPayloadHeader::COOR_REALIGN
@ COOR_REALIGN
Coordinator Realignment (RFD true: Rx)
Definition: lr-wpan-mac-pl-headers.h:124
ns3::CommandPayloadHeader::CommandPayloadHeader
CommandPayloadHeader(void)
Definition: lr-wpan-mac-pl-headers.cc:135
ns3::SuperframeField::GetSerializedSize
uint32_t GetSerializedSize(void) const
Get the size of the serialized Superframe specification information field.
Definition: lr-wpan-fields.cc:161
ns3::CommandPayloadHeader::MacCommand
MacCommand
The MAC command frames.
Definition: lr-wpan-mac-pl-headers.h:116
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::CommandPayloadHeader::BEACON_REQ
@ BEACON_REQ
Beacon Request (RFD true: none )
Definition: lr-wpan-mac-pl-headers.h:123
ns3::BeaconPayloadHeader::SetSuperframeSpecField
void SetSuperframeSpecField(SuperframeField sfrmField)
Set the superframe specification field to the beacon payload header.
Definition: lr-wpan-mac-pl-headers.cc:95
ns3::PendingAddrFields::Serialize
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire Pending Address Fields.
Definition: lr-wpan-fields.cc:437
ns3::BeaconPayloadHeader::m_pndAddrFields
PendingAddrFields m_pndAddrFields
Pending Address Fields.
Definition: lr-wpan-mac-pl-headers.h:97
ns3::PendingAddrFields::Deserialize
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the all the Pending Address Fields.
Definition: lr-wpan-fields.cc:455
ns3::CommandPayloadHeader::m_cmdFrameId
uint8_t m_cmdFrameId
The command Frame Identifier.
Definition: lr-wpan-mac-pl-headers.h:161
visualizer.core.start
def start()
Definition: core.py:1855
ns3::BeaconPayloadHeader::Print
void Print(std::ostream &os) const
Definition: lr-wpan-mac-pl-headers.cc:86
ns3::BeaconPayloadHeader::Serialize
virtual void Serialize(Buffer::Iterator start) const
Definition: lr-wpan-mac-pl-headers.cc:65
ns3::BeaconPayloadHeader::GetPndAddrFields
PendingAddrFields GetPndAddrFields(void) const
Get the pending address fields from the beacon payload header.
Definition: lr-wpan-mac-pl-headers.cc:125
ns3::CommandPayloadHeader::GetSerializedSize
uint32_t GetSerializedSize(void) const
Definition: lr-wpan-mac-pl-headers.cc:166
ns3::CommandPayloadHeader::Serialize
virtual void Serialize(Buffer::Iterator start) const
Definition: lr-wpan-mac-pl-headers.cc:174
ns3::GtsFields::Deserialize
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire GTS fields.
Definition: lr-wpan-fields.cc:283
ns3::CommandPayloadHeader::ASSOCIATION_REQ
@ ASSOCIATION_REQ
Association request (RFD true: Tx)
Definition: lr-wpan-mac-pl-headers.h:117
ns3::Header
Protocol header serialization and deserialization.
Definition: header.h:43
ns3::GtsFields
Represent the GTS information fields.
Definition: lr-wpan-fields.h:176
ns3::CommandPayloadHeader::DATA_REQ
@ DATA_REQ
Data Request (RFD true: Tx)
Definition: lr-wpan-mac-pl-headers.h:120
ns3::SuperframeField::Serialize
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire superframe specification field.
Definition: lr-wpan-fields.cc:167
ns3::PendingAddrFields::GetSerializedSize
uint32_t GetSerializedSize(void) const
Get the size of the serialized Pending Address Fields.
Definition: lr-wpan-fields.cc:425
ns3::Header::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition: buffer.h:99
ns3::CommandPayloadHeader
Implements the header for the MAC payload command frame according to the IEEE 802....
Definition: lr-wpan-mac-pl-headers.h:108
ns3::BeaconPayloadHeader::SetGtsFields
void SetGtsFields(GtsFields gtsFields)
Set the superframe Guaranteed Time Slot (GTS) fields to the beacon payload header.
Definition: lr-wpan-mac-pl-headers.cc:101
ns3::CommandPayloadHeader::CMD_RESERVED
@ CMD_RESERVED
Reserved.
Definition: lr-wpan-mac-pl-headers.h:126
ns3::GtsFields::Serialize
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire GTS fields.
Definition: lr-wpan-fields.cc:260
ns3::SuperframeField::Deserialize
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire superframe specification field.
Definition: lr-wpan-fields.cc:174
ns3::BeaconPayloadHeader::SetPndAddrFields
void SetPndAddrFields(PendingAddrFields pndAddrFields)
Set the superframe Pending Address fields to the beacon payload header.
Definition: lr-wpan-mac-pl-headers.cc:107
ns3::CommandPayloadHeader::Print
void Print(std::ostream &os) const
Definition: lr-wpan-mac-pl-headers.cc:190
ns3::BeaconPayloadHeader::m_gtsFields
GtsFields m_gtsFields
GTS Fields.
Definition: lr-wpan-mac-pl-headers.h:93
ns3::BeaconPayloadHeader::GetGtsFields
GtsFields GetGtsFields(void) const
Get the Guaranteed Time Slots (GTS) fields from the beacon payload header.
Definition: lr-wpan-mac-pl-headers.cc:119
ns3::GtsFields::GetGtsSpecField
uint8_t GetGtsSpecField(void) const
Get the GTS Specification Field from the GTS Fields.
Definition: lr-wpan-fields.cc:208
ns3::GtsFields::GetSerializedSize
uint32_t GetSerializedSize(void) const
Get the size of the serialized GTS fields.
Definition: lr-wpan-fields.cc:245
ns3::BeaconPayloadHeader::m_superframeField
SuperframeField m_superframeField
Superframe Specification Field.
Definition: lr-wpan-mac-pl-headers.h:89
ns3::CommandPayloadHeader::PANID_CONFLICT
@ PANID_CONFLICT
Pan ID conflict notification (RFD true: Tx)
Definition: lr-wpan-mac-pl-headers.h:121