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
22#include <ns3/simulator.h>
23#include <ns3/address-utils.h>
24
25namespace ns3 {
26
27/***********************************************************
28 * Beacon MAC Payload
29 ***********************************************************/
30
32{}
33
35
38{
39 static TypeId tid = TypeId ("ns3::BeaconPayloadHeader")
40 .SetParent<Header> ()
41 .SetGroupName ("LrWpan")
42 .AddConstructor<BeaconPayloadHeader> ()
43 ;
44 return tid;
45}
46
49{
50 return GetTypeId ();
51}
52
55{
56 uint32_t size = 0;
60
61 return size;
62}
63
64void
66{
69 i = m_gtsFields.Serialize (i);
71}
72
75{
80
81 return i.GetDistanceFrom (start);
82}
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
93
94void
96{
98}
99
100void
102{
103 m_gtsFields = gtsFields;
104}
105
106void
108{
109 m_pndAddrFields = pndAddrFields;
110}
111
114{
115 return m_superframeField;
116}
117
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
141{
142 SetCommandFrameType (macCmd);
143}
144
146
147TypeId
149{
150 static TypeId tid = TypeId ("ns3::CommandPayloadHeader")
151 .SetParent<Header> ()
152 .SetGroupName ("LrWpan")
153 .AddConstructor<CommandPayloadHeader> ()
154 ;
155 return tid;
156}
157
158TypeId
160{
161 return GetTypeId ();
162}
163
166{
167 uint32_t size = 1;
168 // TODO: add missing serialize commands size when other commands are added.
169 switch (m_cmdFrameId)
170 {
171 case ASSOCIATION_REQ:
173 break;
174 case ASSOCIATION_RESP:
175 size += 3; // (short address + Association Status)
176 break;
178 break;
179 case DATA_REQ:
180 break;
181 case PANID_CONFLICT:
182 break;
183 case ORPHAN_NOTIF:
184 break;
185 case BEACON_REQ:
186 break;
187 case COOR_REALIGN:
188 break;
189 case GTS_REQ:
190 break;
191 case CMD_RESERVED:
192 break;
193 }
194 return size;
195}
196
197void
199{
202 // TODO: add missing serialize commands when other commands are added.
203 switch (m_cmdFrameId)
204 {
205 case ASSOCIATION_REQ:
207 break;
208 case ASSOCIATION_RESP:
211 break;
213 break;
214 case DATA_REQ:
215 break;
216 case PANID_CONFLICT:
217 break;
218 case ORPHAN_NOTIF:
219 break;
220 case BEACON_REQ:
221 break;
222 case COOR_REALIGN:
223 break;
224 case GTS_REQ:
225 break;
226 case CMD_RESERVED:
227 break;
228 }
229}
230
233{
235 m_cmdFrameId = static_cast <MacCommand> (i.ReadU8 ());
236 // TODO: add missing deserialize commands when other commands are added.
237 switch (m_cmdFrameId)
238 {
239 case ASSOCIATION_REQ:
241 break;
242 case ASSOCIATION_RESP:
244 m_assocStatus = static_cast <AssocStatus> (i.ReadU8 ());
245 break;
247 break;
248 case DATA_REQ:
249 break;
250 case PANID_CONFLICT:
251 break;
252 case ORPHAN_NOTIF:
253 break;
254 case BEACON_REQ:
255 break;
256 case COOR_REALIGN:
257 break;
258 case GTS_REQ:
259 break;
260 case CMD_RESERVED:
261 break;
262 }
263
264 return i.GetDistanceFrom (start);
265}
266
267void
268CommandPayloadHeader::Print (std::ostream &os) const
269{
270 os << "| MAC Command Frame ID | = " << (uint32_t) m_cmdFrameId;
271 switch (m_cmdFrameId)
272 {
273 case ASSOCIATION_REQ:
274 os << "| Device Type FFD | = " << m_capabilityInfo.IsDeviceTypeFfd ()
275 << "| Alternative Power Source available | = " << m_capabilityInfo.IsPowSrcAvailable ()
276 << "| Receiver on when Idle | = " << m_capabilityInfo.IsReceiverOnWhenIdle ()
277 << "| Security capable | = " << m_capabilityInfo.IsSecurityCapability ()
278 << "| Allocate address on | = " << m_capabilityInfo.IsShortAddrAllocOn ();
279 break;
280 case ASSOCIATION_RESP:
281 os << "| Assigned Short Address | = " << m_shortAddr
282 << "| Status Response | = " << m_assocStatus;
283 break;
285 break;
286 case DATA_REQ:
287 break;
288 case PANID_CONFLICT:
289 break;
290 case ORPHAN_NOTIF:
291 break;
292 case BEACON_REQ:
293 break;
294 case COOR_REALIGN:
295 break;
296 case GTS_REQ:
297 break;
298 case CMD_RESERVED:
299 break;
300 }
301}
302
303void
305{
306 m_cmdFrameId = macCommand;
307}
308
309void
311{
313 m_capabilityInfo = cap;
314}
315
318{
319 switch (m_cmdFrameId)
320 {
321 case 0x01:
322 return ASSOCIATION_REQ;
323 break;
324 case 0x02:
325 return ASSOCIATION_RESP;
326 break;
327 case 0x03:
329 break;
330 case 0x04:
331 return DATA_REQ;
332 break;
333 case 0x05:
334 return PANID_CONFLICT;
335 break;
336 case 0x06:
337 return ORPHAN_NOTIF;
338 break;
339 case 0x07:
340 return BEACON_REQ;
341 break;
342 case 0x08:
343 return COOR_REALIGN;
344 break;
345 case 0x09:
346 return GTS_REQ;
347 break;
348 default:
349 return CMD_RESERVED;
350 }
351}
352
353void
355{
357 m_shortAddr = shortAddr;
358}
359
360void
362{
364 m_assocStatus = status;
365}
366
369{
371 return m_shortAddr;
372}
373
376{
378 return m_assocStatus;
379}
380
383{
385 return m_capabilityInfo;
386}
387
388
389} // ns3 namespace
Implements the header for the MAC payload beacon frame according to the IEEE 802.15....
virtual void Serialize(Buffer::Iterator start) const
static TypeId GetTypeId(void)
Get the type ID.
GtsFields m_gtsFields
GTS Fields.
PendingAddrFields m_pndAddrFields
Pending Address Fields.
uint32_t Deserialize(Buffer::Iterator start)
GtsFields GetGtsFields(void) const
Get the Guaranteed Time Slots (GTS) fields from the beacon payload header.
SuperframeField m_superframeField
Superframe Specification Field.
SuperframeField GetSuperframeSpecField(void) const
Get the superframe specification field from the beacon payload header.
TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
void Print(std::ostream &os) const
void SetSuperframeSpecField(SuperframeField sfrmField)
Set the superframe specification field to the beacon payload header.
void SetGtsFields(GtsFields gtsFields)
Set the superframe Guaranteed Time Slot (GTS) fields to the beacon payload header.
PendingAddrFields GetPndAddrFields(void) const
Get the pending address fields from the beacon payload header.
void SetPndAddrFields(PendingAddrFields pndAddrFields)
Set the superframe Pending Address fields to the beacon payload header.
uint32_t GetSerializedSize(void) const
iterator in a Buffer instance
Definition: buffer.h:99
void WriteU8(uint8_t data)
Definition: buffer.h:869
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:788
Represent the Capability Information Field.
bool IsDeviceTypeFfd(void) const
True if the device type is a Full Functional Device (FFD) false if is a Reduced Functional Device (RF...
uint32_t GetSerializedSize(void) const
Get the size of the serialized Capability Information Field.
bool IsSecurityCapability(void) const
True if the device is capable of sending and receiving cryptographically protected MAC frames.
bool IsShortAddrAllocOn(void) const
True if the device wishes the coordinator to allocate a short address as result of the association pr...
bool IsPowSrcAvailable(void) const
True if the device is receiving power from alternating current mains.
bool IsReceiverOnWhenIdle(void) const
True if the device does not disable its receiver to conserve power during idle periods.
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.
void SetCapabilityField(CapabilityField cap)
Set the Capability Information Field to the command payload header (Association Request Command).
TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
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).
uint32_t GetSerializedSize(void) const
virtual void Serialize(Buffer::Iterator start) const
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 SetCommandFrameType(MacCommand macCmd)
Set the command frame type.
uint32_t Deserialize(Buffer::Iterator start)
void Print(std::ostream &os) const
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)
MacCommand GetCommandFrameType(void) const
Get the command frame type ID.
static TypeId GetTypeId(void)
Get the type ID.
void SetShortAddr(Mac16Address shortAddr)
Set the Short Address Assigned by the coordinator (Association Response Command).
CapabilityField GetCapabilityField(void) const
Get the Capability Information Field from the command payload header.
AssocStatus GetAssociationStatus(void) const
Get the status resulting from an association request (Association Response Command).
Mac16Address GetShortAddr(void) const
Get the Short address assigned by the coordinator (Association Response Command).
Represent the GTS information fields.
uint8_t GetGtsSpecField(void) const
Get the GTS Specification Field from the GTS Fields.
uint32_t GetSerializedSize(void) const
Get the size of the serialized GTS fields.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire GTS fields.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire GTS fields.
Protocol header serialization and deserialization.
Definition: header.h:43
This class can contain 16 bit addresses.
Definition: mac16-address.h:42
Represent the Pending Address Specification field.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the all the Pending Address Fields.
uint32_t GetSerializedSize(void) const
Get the size of the serialized Pending Address Fields.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire Pending Address Fields.
uint8_t GetPndAddrSpecField(void) const
Get the whole Pending Address Specification Field from the Pending Address Fields.
Represent the Superframe Specification information field.
uint32_t GetSerializedSize(void) const
Get the size of the serialized 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.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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.
def start()
Definition: core.py:1852