A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
21
22#include <ns3/address-utils.h>
23#include <ns3/simulator.h>
24
25namespace ns3
26{
27namespace lrwpan
28{
29
30/***********************************************************
31 * Beacon MAC Payload
32 ***********************************************************/
33
35{
36}
37
39
42{
43 static TypeId tid = TypeId("ns3::BeaconPayloadHeader")
45 .SetGroupName("LrWpan")
46 .AddConstructor<BeaconPayloadHeader>();
47 return tid;
48}
49
52{
53 return GetTypeId();
54}
55
58{
59 uint32_t size = 0;
60 size += sizeof(m_superframeField);
63
64 return size;
65}
66
67void
69{
70 Buffer::Iterator i = start;
74}
75
78{
79 Buffer::Iterator i = start;
83
84 return i.GetDistanceFrom(start);
85}
86
87void
88BeaconPayloadHeader::Print(std::ostream& os) const
89{
90 os << "| Superframe Spec Field | = " << m_superframeField
91 << "| GTS Spec Field | = " << m_gtsFields.GetGtsSpecField()
92 << "| Pending Spec Field| =" << m_pndAddrFields.GetPndAddrSpecField();
93}
94
95void
97{
99}
100
101void
103{
104 m_gtsFields = gtsFields;
105}
106
107void
109{
110 m_pndAddrFields = pndAddrFields;
111}
112
113uint16_t
115{
116 return m_superframeField;
117}
118
121{
122 return m_gtsFields;
123}
124
127{
128 return m_pndAddrFields;
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 return tid;
155}
156
157TypeId
159{
160 return GetTypeId();
161}
162
165{
166 uint32_t size = 1;
167 // TODO: add missing serialize commands size when other commands are added.
168 switch (m_cmdFrameId)
169 {
170 case ASSOCIATION_REQ:
171 size += 1; // (Capability field)
172 break;
173 case ASSOCIATION_RESP:
174 size += 3; // (short address + Association Status)
175 break;
177 break;
178 case DATA_REQ:
179 break;
180 case PANID_CONFLICT:
181 break;
182 case ORPHAN_NOTIF:
183 break;
184 case BEACON_REQ:
185 break;
186 case COOR_REALIGN:
187 size += 8;
188 break;
189 case GTS_REQ:
190 break;
191 case CMD_RESERVED:
192 break;
193 }
194 return size;
195}
196
197void
199{
200 Buffer::Iterator i = start;
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 i.WriteU16(m_panid);
225 i.WriteU8(m_logCh);
228 break;
229 case GTS_REQ:
230 break;
231 case CMD_RESERVED:
232 break;
233 }
234}
235
238{
239 Buffer::Iterator i = start;
240 m_cmdFrameId = static_cast<MacCommand>(i.ReadU8());
241 // TODO: add missing deserialize commands when other commands are added.
242 switch (m_cmdFrameId)
243 {
244 case ASSOCIATION_REQ:
246 break;
247 case ASSOCIATION_RESP:
249 m_assocStatus = i.ReadU8();
250 break;
252 break;
253 case DATA_REQ:
254 break;
255 case PANID_CONFLICT:
256 break;
257 case ORPHAN_NOTIF:
258 break;
259 case BEACON_REQ:
260 break;
261 case COOR_REALIGN:
262 m_panid = i.ReadU16();
264 m_logCh = i.ReadU8();
266 m_logChPage = i.ReadU8();
267 break;
268 case GTS_REQ:
269 break;
270 case CMD_RESERVED:
271 break;
272 }
273
274 return i.GetDistanceFrom(start);
275}
276
277void
278CommandPayloadHeader::Print(std::ostream& os) const
279{
280 os << "| MAC Command Frame ID | = " << static_cast<uint32_t>(m_cmdFrameId);
281 switch (m_cmdFrameId)
282 {
283 case ASSOCIATION_REQ: {
285 os << "| Device Type FFD | = " << capability.IsDeviceTypeFfd()
286 << "| Alternative Power Source available | = " << capability.IsPowSrcAvailable()
287 << "| Receiver on when Idle | = " << capability.IsReceiverOnWhenIdle()
288 << "| Security capable | = " << capability.IsSecurityCapability()
289 << "| Allocate address on | = " << capability.IsShortAddrAllocOn();
290 break;
291 }
292 case ASSOCIATION_RESP:
293 os << "| Assigned Short Address | = " << m_shortAddr
294 << "| Status Response | = " << m_assocStatus;
295 break;
297 break;
298 case DATA_REQ:
299 break;
300 case PANID_CONFLICT:
301 break;
302 case ORPHAN_NOTIF:
303 break;
304 case BEACON_REQ:
305 break;
306 case COOR_REALIGN:
307 os << "| PAN identifier| = " << m_panid
308 << "| PAN Coord Short address| = " << m_coordShortAddr
309 << "| Channel Num.| = " << static_cast<uint32_t>(m_logCh)
310 << "| Short address| = " << m_shortAddr
311 << "| Page Num.| = " << static_cast<uint32_t>(m_logChPage);
312 break;
313 case GTS_REQ:
314 break;
315 case CMD_RESERVED:
316 break;
317 default:
318 break;
319 }
320}
321
322void
324{
325 m_cmdFrameId = macCommand;
326}
327
328void
330{
332 m_capabilityInfo = cap;
333}
334
335void
337{
339 m_coordShortAddr = addr;
340}
341
342void
344{
346 m_logCh = channel;
347}
348
349void
351{
353 m_logChPage = page;
354}
355
356void
358{
360 m_panid = id;
361}
362
365{
366 switch (m_cmdFrameId)
367 {
368 case 0x01:
369 return ASSOCIATION_REQ;
370 case 0x02:
371 return ASSOCIATION_RESP;
372 case 0x03:
374 case 0x04:
375 return DATA_REQ;
376 case 0x05:
377 return PANID_CONFLICT;
378 case 0x06:
379 return ORPHAN_NOTIF;
380 case 0x07:
381 return BEACON_REQ;
382 case 0x08:
383 return COOR_REALIGN;
384 case 0x09:
385 return GTS_REQ;
386 default:
387 return CMD_RESERVED;
388 }
389}
390
391void
393{
395 m_shortAddr = shortAddr;
396}
397
398void
400{
402 m_assocStatus = status;
403}
404
407{
408 return m_shortAddr;
409}
410
411uint8_t
413{
415 return m_assocStatus;
416}
417
418uint8_t
420{
422 return m_capabilityInfo;
423}
424
427{
429 return m_coordShortAddr;
430}
431
432uint8_t
434{
436 return m_logCh;
437}
438
439uint8_t
441{
443 return m_logChPage;
444}
445
446uint16_t
448{
450 return m_panid;
451}
452
453} // namespace lrwpan
454} // namespace ns3
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
Protocol header serialization and deserialization.
Definition: header.h:44
This class can contain 16 bit addresses.
Definition: mac16-address.h:44
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Implements the header for the MAC payload beacon frame according to the IEEE 802.15....
static TypeId GetTypeId()
Get the type ID.
void SetSuperframeSpecField(uint16_t sfrmField)
Set the superframe specification field to the beacon payload header.
uint16_t GetSuperframeSpecField() const
Get the superframe specification field from the beacon payload header.
GtsFields GetGtsFields() const
Get the Guaranteed Time Slots (GTS) fields from 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.
PendingAddrFields GetPndAddrFields() const
Get the pending address fields from the beacon payload header.
uint16_t m_superframeField
Superframe Specification Field.
void Serialize(Buffer::Iterator start) const override
void Print(std::ostream &os) const override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint32_t Deserialize(Buffer::Iterator start) override
PendingAddrFields m_pndAddrFields
Pending Address Fields.
void SetPndAddrFields(PendingAddrFields pndAddrFields)
Set the superframe Pending Address fields to the beacon payload header.
Represent the Capability Information Field.
bool IsShortAddrAllocOn() const
True if the device wishes the coordinator to allocate a short address as result of the association pr...
bool IsSecurityCapability() const
True if the device is capable of sending and receiving cryptographically protected MAC frames.
bool IsDeviceTypeFfd() const
True if the device type is a Full Functional Device (FFD) false if is a Reduced Functional Device (RF...
bool IsReceiverOnWhenIdle() const
True if the device does not disable its receiver to conserve power during idle periods.
bool IsPowSrcAvailable() const
True if the device is receiving power from alternating current mains.
Implements the header for the MAC payload command frame according to the IEEE 802....
uint16_t m_panid
The PAN identifier (Coordinator realigment command)
MacCommand GetCommandFrameType() const
Get the command frame type ID.
Mac16Address GetShortAddr() const
Get the Short address assigned by the coordinator (Association Response and Coordinator Realigment co...
void Print(std::ostream &os) const override
uint8_t GetChannel() const
Get the logical channel number.
Mac16Address m_coordShortAddr
The coordinator short address (Coordinator realigment command)
uint16_t GetPanId() const
Get the PAN identifier.
void SetPage(uint8_t page)
Set the logical channel page number.
void SetShortAddr(Mac16Address shortAddr)
Set the Short Address Assigned by the coordinator (Association Response and Coordinator Realigment Co...
uint8_t GetCapabilityField() const
Get the Capability Information Field from the command payload header.
void SetCommandFrameType(MacCommand macCmd)
Set the command frame type.
Mac16Address GetCoordShortAddr() const
Get the coordinator short address.
MacCommand m_cmdFrameId
The command Frame Identifier (Used by all commands)
void SetCapabilityField(uint8_t cap)
Set the Capability Information Field to the command payload header (Association Request Command).
void SetCoordShortAddr(Mac16Address addr)
Set the coordinator short address (16 bit address).
void Serialize(Buffer::Iterator start) const override
uint8_t m_logChPage
The channel page number (Coordinator realigment command)
uint32_t GetSerializedSize() const override
uint32_t Deserialize(Buffer::Iterator start) override
uint8_t GetPage() const
Get the logical channel page number.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
@ ASSOCIATION_RESP
Association response (RFD true: Rx)
@ PANID_CONFLICT
Pan ID conflict notification (RFD true: Tx)
@ DISASSOCIATION_NOTIF
Disassociation notification (RFD true: TX, Rx)
@ DATA_REQ
Data Request (RFD true: Tx)
@ COOR_REALIGN
Coordinator Realignment (RFD true: Rx)
@ GTS_REQ
GTS Request (RFD true: none)
@ ORPHAN_NOTIF
Orphan Notification (RFD true: Tx)
@ ASSOCIATION_REQ
Association request (RFD true: Tx)
@ BEACON_REQ
Beacon Request (RFD true: none )
Mac16Address m_shortAddr
Contains the short address assigned by the coordinator (Association Response and Coordinator Realiagm...
void SetAssociationStatus(uint8_t status)
Set status resulting from the association attempt (Association Response Command).
uint8_t GetAssociationStatus() const
Get the status resulting from an association request (Association Response Command).
void SetPanId(uint16_t id)
Get the PAN identifier.
void SetChannel(uint8_t channel)
Set the logical channel number.
uint8_t m_capabilityInfo
Capability Information Field (Association Request Command)
uint8_t m_logCh
The channel number (Coordinator realigment command)
static TypeId GetTypeId()
Get the type ID.
uint8_t m_assocStatus
Association Status (Association Response Command)
Represent the GTS information 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.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire GTS fields.
Represent the Pending Address Specification field.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire Pending Address Fields.
uint8_t GetPndAddrSpecField() const
Get the whole Pending Address Specification Field from the Pending Address Fields.
uint32_t GetSerializedSize() const
Get the size of the serialized Pending Address Fields.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the all the Pending Address Fields.
#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.