A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-fields.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Ritsumeikan University, Shiga, Japan.
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Alberto Gallegos Ramonet <ramonet@fc.ritsumei.ac.jp>
7 */
8
9#include "lr-wpan-fields.h"
10
11#include <ns3/address-utils.h>
12#include <ns3/log.h>
13
14namespace ns3
15{
16namespace lrwpan
17{
18
28
30{
31 SetSuperframe(bitmap);
32}
33
34void
35SuperframeField::SetSuperframe(uint16_t superFrmSpec)
36{
37 m_sspecBcnOrder = (superFrmSpec) & (0x0F); // Bits 0-3
38 m_sspecSprFrmOrder = (superFrmSpec >> 4) & (0x0F); // Bits 4-7
39 m_sspecFnlCapSlot = (superFrmSpec >> 8) & (0x0F); // Bits 8-11
40 m_sspecBatLifeExt = (superFrmSpec >> 12) & (0x01); // Bit 12
41 // Bit 13 (Reserved)
42 m_sspecPanCoor = (superFrmSpec >> 14) & (0x01); // Bit 14
43 m_sspecAssocPermit = (superFrmSpec >> 15) & (0x01); // Bit 15
44}
45
46void
48{
49 if (bcnOrder > 15)
50 {
51 NS_ABORT_MSG("SuperframeField Beacon Order value must be 15 or less");
52 }
53 else
54 {
55 m_sspecBcnOrder = bcnOrder;
56 }
57}
58
59void
61{
62 if (frmOrder > 15)
63 {
64 NS_ABORT_MSG("SuperframeField Frame Order value must be 15 or less");
65 }
66 else
67 {
68 m_sspecSprFrmOrder = frmOrder;
69 }
70}
71
72void
74{
75 if (capSlot > 15)
76 {
77 NS_ABORT_MSG("The final slot cannot be greater than the slots in a CAP (15)");
78 }
79 else
80 {
81 m_sspecFnlCapSlot = capSlot;
82 }
83}
84
85void
87{
88 m_sspecBatLifeExt = battLifeExt;
89}
90
91void
93{
94 m_sspecPanCoor = panCoor;
95}
96
97void
99{
100 m_sspecAssocPermit = assocPermit;
101}
102
103uint8_t
108
109uint8_t
114
115uint8_t
120
121bool
126
127bool
129{
130 return m_sspecPanCoor;
131}
132
133bool
138
139uint16_t
141{
142 uint16_t superframe;
143
144 superframe = m_sspecBcnOrder & (0x0F); // Bits 0-3
145 superframe |= (m_sspecSprFrmOrder << 4) & (0x0F << 4); // Bits 4-7
146 superframe |= (m_sspecFnlCapSlot << 8) & (0x0F << 8); // Bits 8-11
147 superframe |= (m_sspecBatLifeExt << 12) & (0x01 << 12); // Bit 12
148 // Bit 13 (Reserved)
149 superframe |= (m_sspecPanCoor << 14) & (0x01 << 14); // Bit 14
150 superframe |= (m_sspecAssocPermit << 15) & (0x01 << 15); // Bit 15
151
152 return superframe;
153}
154
155std::ostream&
156operator<<(std::ostream& os, const SuperframeField& superframeField)
157{
158 os << " Beacon Order = " << uint32_t(superframeField.GetBeaconOrder())
159 << ", Frame Order = " << uint32_t(superframeField.GetFrameOrder())
160 << ", Final CAP slot = " << uint32_t(superframeField.GetFinalCapSlot())
161 << ", Battery Life Ext = " << bool(superframeField.IsBattLifeExt())
162 << ", PAN Coordinator = " << bool(superframeField.IsPanCoor())
163 << ", Association Permit = " << bool(superframeField.IsAssocPermit());
164 return os;
165}
166
167/***********************************************************
168 * Guaranteed Time Slots (GTS) Fields
169 ***********************************************************/
170
172{
173 // GTS Specification Field
175 m_gtsSpecPermit = 0;
176 // GTS Direction Field
177 m_gtsDirMask = 0;
178}
179
180uint8_t
182{
183 uint8_t gtsSpecField;
184
185 gtsSpecField = m_gtsSpecDescCount & (0x07); // Bits 0-2
186 // Bits 3-6 (Reserved)
187 gtsSpecField |= (m_gtsSpecPermit << 7) & (0x01 << 7); // Bit 7
188
189 return gtsSpecField;
190}
191
192uint8_t
194{
195 uint8_t gtsDirectionField;
196
197 gtsDirectionField = m_gtsDirMask & (0x7F); // Bit 0-6
198 // Bit 7 (Reserved)
199 return gtsDirectionField;
200}
201
202void
204{
205 m_gtsSpecDescCount = (gtsSpec) & (0x07); // Bits 0-2
206 // Bits 3-6 (Reserved)
207 m_gtsSpecPermit = (gtsSpec >> 7) & (0x01); // Bit 7
208}
209
210void
212{
213 m_gtsDirMask = (gtsDir) & (0x7F); // Bits 0-6
214 // Bit 7 (Reserved)
215}
216
217bool
219{
220 return m_gtsSpecPermit;
221}
222
225{
226 uint32_t size;
227
228 size = 1; // 1 octet GTS Specification Field
229 if (m_gtsSpecDescCount > 0)
230 {
231 size += 1; // 1 octet GTS Direction Field
232 size += (m_gtsSpecDescCount * 3); // 3 octets per GTS descriptor
233 }
234
235 return size;
236}
237
240{
242
243 if (m_gtsSpecDescCount > 0)
244 {
245 uint8_t gtsDescStartAndLength;
247
248 for (int j = 0; j < m_gtsSpecDescCount; j++)
249 {
250 WriteTo(i, m_gtsList[j].m_gtsDescDevShortAddr);
251
252 gtsDescStartAndLength =
253 (m_gtsList[j].m_gtsDescStartSlot & 0x0F) | // GTS descriptor bits 16-19
254 (m_gtsList[j].m_gtsDescLength & 0xF0); // GTS descriptor bits 20-23
255
256 i.WriteU8(gtsDescStartAndLength);
257 }
258 }
259 return i;
260}
261
264{
265 uint8_t gtsSpecField = i.ReadU8();
266 SetGtsSpecField(gtsSpecField);
267
268 if (m_gtsSpecDescCount > 0)
269 {
270 uint8_t gtsDirectionField = i.ReadU8();
271 SetGtsDirectionField(gtsDirectionField);
272
273 uint8_t gtsDescStartAndLength;
274 for (int j = 0; j < m_gtsSpecDescCount; j++)
275 {
276 ReadFrom(i, m_gtsList[j].m_gtsDescDevShortAddr);
277
278 gtsDescStartAndLength = i.ReadU8();
279 m_gtsList[j].m_gtsDescStartSlot = (gtsDescStartAndLength) & (0x0F);
280 m_gtsList[j].m_gtsDescLength = (gtsDescStartAndLength >> 4) & (0x0F);
281 }
282 }
283 return i;
284}
285
286std::ostream&
287operator<<(std::ostream& os, const GtsFields& gtsFields)
288{
289 os << " GTS specification = " << uint32_t(gtsFields.GetGtsSpecField())
290 << ", GTS direction = " << uint32_t(gtsFields.GetGtsDirectionField());
291 return os;
292}
293
294/***********************************************************
295 * Pending Address Fields
296 ***********************************************************/
297
303
304uint8_t
309
310uint8_t
315
316uint8_t
318{
319 uint8_t pndAddrSpecField;
320
321 pndAddrSpecField = m_pndAddrSpecNumShortAddr & (0x07); // Bits 0-2
322 // Bit 3 (Reserved)
323 pndAddrSpecField |= (m_pndAddrSpecNumExtAddr << 4) & (0x07 << 4); // Bits 4-6
324 // Bit 7 (Reserved)
325
326 return pndAddrSpecField;
327}
328
329void
331{
332 uint8_t totalPendAddr = m_pndAddrSpecNumShortAddr + m_pndAddrSpecNumExtAddr;
333
334 if (totalPendAddr == 7)
335 {
336 return;
337 }
338 else
339 {
342 }
343}
344
345void
347{
348 uint8_t totalPendAddr = m_pndAddrSpecNumShortAddr + m_pndAddrSpecNumExtAddr;
349
350 if (totalPendAddr == 7)
351 {
352 return;
353 }
354 else
355 {
358 }
359}
360
361bool
363{
364 for (int j = 0; j <= m_pndAddrSpecNumShortAddr; j++)
365 {
366 if (shortAddr == m_shortAddrList[j])
367 {
368 return true;
369 }
370 }
371
372 return false;
373}
374
375bool
377{
378 for (int j = 0; j <= m_pndAddrSpecNumExtAddr; j++)
379 {
380 if (extAddr == m_extAddrList[j])
381 {
382 return true;
383 }
384 }
385
386 return false;
387}
388
389void
391{
392 m_pndAddrSpecNumShortAddr = (pndAddrSpecField) & (0x07); // Bit 0-2
393 // Bit 3
394 m_pndAddrSpecNumExtAddr = (pndAddrSpecField >> 4) & (0x07); // Bit 4-6
395 // Bit 7
396}
397
400{
401 uint32_t size;
402
403 size = 1; // 1 octet (Pending Address Specification Field)
404 size = size + (m_pndAddrSpecNumShortAddr * 2); // X octets (Short Pending Address List)
405 size = size + (m_pndAddrSpecNumExtAddr * 8); // X octets (Extended Pending Address List)
406
407 return size;
408}
409
412{
414
415 for (int j = 0; j < m_pndAddrSpecNumShortAddr; j++)
416 {
418 }
419
420 for (int k = 0; k < m_pndAddrSpecNumExtAddr; k++)
421 {
422 WriteTo(i, m_extAddrList[k]);
423 }
424
425 return i;
426}
427
430{
431 uint8_t pndAddrSpecField = i.ReadU8();
432
433 SetPndAddrSpecField(pndAddrSpecField);
434
435 for (int j = 0; j < m_pndAddrSpecNumShortAddr; j++)
436 {
438 }
439
440 for (int k = 0; k < m_pndAddrSpecNumExtAddr; k++)
441 {
442 ReadFrom(i, m_extAddrList[k]);
443 }
444
445 return i;
446}
447
448std::ostream&
449operator<<(std::ostream& os, const PendingAddrFields& pendingAddrFields)
450{
451 os << " Num. Short Addr = " << uint32_t(pendingAddrFields.GetNumShortAddr())
452 << ", Num. Ext Addr = " << uint32_t(pendingAddrFields.GetNumExtAddr());
453 return os;
454}
455
456/***********************************************************
457 * Capability Information Field
458 ***********************************************************/
459
461{
462 m_deviceType = true;
463 m_powerSource = false;
465 m_securityCap = false;
466 m_allocAddr = true;
467}
468
470{
471 SetCapability(bitmap);
472}
473
474uint8_t
476{
477 uint8_t capability;
478
479 capability = (m_reservedBit0) & (0x01); //!< Bit 0 (reserved)
480 capability |= (m_deviceType << 1) & (0x01 << 1); //!< Bit 1
481 capability |= (m_powerSource << 2) & (0x01 << 2); //!< Bit 2
482 capability |= (m_receiverOnWhenIdle << 3) & (0x01 << 3); //!< Bit 3
483 capability |= (m_reservedBit45 << 4) & (0x03 << 4); //!< Bit 4-5 (reserved)
484 capability |= (m_securityCap << 6) & (0x01 << 6); //!< Bit 6
485 capability |= (m_allocAddr << 7) & (0x01 << 7); //!< Bit 7
486
487 return capability;
488}
489
490void
492{
493 m_reservedBit0 = (bitmap) & (0x01); //!< Bit 0 (reserved)
494 m_deviceType = (bitmap >> 1) & (0x01); //!< Bit 1
495 m_powerSource = (bitmap >> 2) & (0x01); //!< Bit 2
496 m_receiverOnWhenIdle = (bitmap >> 3) & (0x01); //!< Bit 3
497 m_reservedBit45 = (bitmap >> 4) & (0x03); //!< Bit 4-5 (reserved)
498 m_securityCap = (bitmap >> 6) & (0x01); //!< Bit 6
499 m_allocAddr = (bitmap >> 7) & (0x01); //!< Bit 7
500}
501
502bool
504{
505 return m_deviceType;
506}
507
508bool
513
514bool
519
520bool
525
526bool
531
532void
534{
535 m_deviceType = devType;
536}
537
538void
543
544void
546{
547 m_receiverOnWhenIdle = rxIdle;
548}
549
550void
552{
553 m_securityCap = sec;
554}
555
556void
558{
559 m_allocAddr = addrAlloc;
560}
561
562/**
563 * output stream output operator
564 *
565 * \param os output stream
566 * \param capabilityField the Capability Information Field
567 *
568 * \returns output stream
569 */
570std::ostream&
571operator<<(std::ostream& os, const CapabilityField& capabilityField)
572{
573 os << " FFD device capable = " << bool(capabilityField.IsDeviceTypeFfd())
574 << ", Alternate Power Current Available = " << bool(capabilityField.IsPowSrcAvailable())
575 << ", Receiver On When Idle = " << bool(capabilityField.IsReceiverOnWhenIdle())
576 << ", Security Capable = " << bool(capabilityField.IsSecurityCapability())
577 << ", Coordinator Allocate Short Address = " << bool(capabilityField.IsShortAddrAllocOn());
578 return os;
579}
580
581} // namespace lrwpan
582} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
This class can contain 16 bit addresses.
an EUI-64 address
Represent the Capability Information Field.
bool m_powerSource
Capability Information Field, Power Source (bit 2)
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 m_allocAddr
Capability Information Field, Allocate Address (bit 7)
uint8_t GetCapability() const
Get the bitmap representing the device capability.
void SetCapability(uint8_t bitmap)
Set the bitmap representing the device capability.
bool IsDeviceTypeFfd() const
True if the device type is a Full Functional Device (FFD) false if is a Reduced Functional Device (RF...
void SetShortAddrAllocOn(bool addrAlloc)
Set the Short Address Flag in the Capability Information Field.
bool m_securityCap
Capability Information Field, Security Capability (bit 6)
bool m_reservedBit0
Capability Information Field, Reserved (bit 0)
uint8_t m_reservedBit45
Capability Information Field, Reserved (bit 4 & 5)
bool m_deviceType
Capability Information Field, Device Type (bit 1)
void SetPowSrcAvailable(bool pow)
Set the Power Source available flag in the Capability Information Field.
void SetRxOnWhenIdle(bool rxIdle)
Indicate if the receiver is On on Idle.
void SetSecurityCap(bool sec)
Set the Security Capability flag in the Capability Information Field.
void SetFfdDevice(bool devType)
Set the Device type in the Capability Information Field.
bool m_receiverOnWhenIdle
Capability Information Field, Receiver On When Idle (bit 3)
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.
Represent the GTS information fields.
GtsDescriptor m_gtsList[7]
GTS List field (maximum descriptors stored == 7)
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 m_gtsDirMask
GTS Direction field Directions Mask (Bit 0-6)
void SetGtsSpecField(uint8_t gtsSpec)
Set the GTS Specification Field to the GTS Fields.
uint8_t m_gtsSpecDescCount
GTS specification field Descriptor Count (Bit 0-2)
uint8_t GetGtsDirectionField() const
Get the GTS Direction Field from the GTS Fields.
void SetGtsDirectionField(uint8_t gtsDir)
Set the GTS direction field to the GTS Fields.
bool GetGtsPermit() const
Get the GTS Specification Permit.
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.
uint8_t m_gtsSpecPermit
GTS specification field GTS Permit (Bit 7)
Represent the Pending Address Specification field.
void SetPndAddrSpecField(uint8_t pndAddrSpecField)
Set the whole Pending Address Specification field.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire Pending Address Fields.
std::array< Mac16Address, 7 > m_shortAddrList
Pending Short Address List.
uint8_t GetPndAddrSpecField() const
Get the whole Pending Address Specification Field from the Pending Address Fields.
uint8_t GetNumExtAddr() const
Get the number of Extended Pending Address indicated in the Pending Address Specification Field.
uint8_t m_pndAddrSpecNumShortAddr
Pending Address Specification field Number of Short Address (Bits 0-2) Pending Address Specification ...
bool SearchAddress(Mac16Address shortAddr)
Search for the short Pending Address in the Address List.
void AddAddress(Mac16Address shortAddr)
Add a short Pending Address to the Address List.
uint32_t GetSerializedSize() const
Get the size of the serialized Pending Address Fields.
uint8_t GetNumShortAddr() const
Get the number of Short Pending Address indicated in the Pending Address Specification Field.
uint8_t m_pndAddrSpecNumExtAddr
Pending Address Specification field Number of Extended Address (Bits 4-6) Pending Address Specificati...
std::array< Mac64Address, 7 > m_extAddrList
Pending Extended Address List.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the all the Pending Address Fields.
Represent the Superframe Specification information field.
void SetPanCoor(bool panCoor)
Set the Superframe Specification PAN coordinator field.
bool m_sspecBatLifeExt
Superframe Specification field Battery Life Extension (Bit 12)
uint8_t GetFinalCapSlot() const
Get the the Final CAP Slot.
bool IsPanCoor() const
Check if the PAN Coordinator bit is enabled.
void SetAssocPermit(bool assocPermit)
Set the Superframe Specification Association Permit field.
bool m_sspecAssocPermit
Superframe Specification field Association Permit (Bit 15)
void SetBattLifeExt(bool battLifeExt)
Set the Superframe Specification Battery Life Extension (BLE).
bool IsBattLifeExt() const
Check if the Battery Life Extension bit is enabled.
bool m_sspecPanCoor
Superframe Specification field PAN Coordinator (Bit 14)
void SetSuperframe(uint16_t superFrm)
Set the whole Superframe Specification Information field.
uint8_t GetBeaconOrder() const
Get the Superframe Specification Beacon Order field.
uint8_t GetFrameOrder() const
Get the Superframe Specification Frame Order field.
bool IsAssocPermit() const
Check if the Association Permit bit is enabled.
uint16_t GetSuperframe() const
Get the Superframe specification information field.
uint8_t m_sspecSprFrmOrder
Superframe Specification field Superframe Order (Bit 4-7)
void SetFinalCapSlot(uint8_t capSlot)
Set the superframe specification Final CAP slot field.
uint8_t m_sspecBcnOrder
Superframe Specification field Beacon Order (Bit 0-3)
void SetBeaconOrder(uint8_t bcnOrder)
Set the superframe specification Beacon Order field.
uint8_t m_sspecFnlCapSlot
Superframe Specification field Final CAP slot (Bit 8-11)
void SetSuperframeOrder(uint8_t frmOrder)
Set the superframe specification Superframe Order field.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
std::ostream & operator<<(std::ostream &os, const SuperframeField &superframeField)
Stream insertion operator.
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.
uint8_t m_gtsDescLength
GTS Descriptor GTS Length (Bit 20-23)
uint8_t m_gtsDescStartSlot
GTS Descriptor GTS Starting Slot(Bit 16-19)