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 * 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
20#include "lr-wpan-fields.h"
21
22#include <ns3/address-utils.h>
23#include <ns3/log.h>
24
25namespace ns3
26{
27namespace lrwpan
28{
29
31{
35 SetBattLifeExt(false);
36 SetPanCoor(false);
37 SetAssocPermit(false);
38}
39
41{
42 SetSuperframe(bitmap);
43}
44
45void
46SuperframeField::SetSuperframe(uint16_t superFrmSpec)
47{
48 m_sspecBcnOrder = (superFrmSpec) & (0x0F); // Bits 0-3
49 m_sspecSprFrmOrder = (superFrmSpec >> 4) & (0x0F); // Bits 4-7
50 m_sspecFnlCapSlot = (superFrmSpec >> 8) & (0x0F); // Bits 8-11
51 m_sspecBatLifeExt = (superFrmSpec >> 12) & (0x01); // Bit 12
52 // Bit 13 (Reserved)
53 m_sspecPanCoor = (superFrmSpec >> 14) & (0x01); // Bit 14
54 m_sspecAssocPermit = (superFrmSpec >> 15) & (0x01); // Bit 15
55}
56
57void
59{
60 if (bcnOrder > 15)
61 {
62 NS_ABORT_MSG("SuperframeField Beacon Order value must be 15 or less");
63 }
64 else
65 {
66 m_sspecBcnOrder = bcnOrder;
67 }
68}
69
70void
72{
73 if (frmOrder > 15)
74 {
75 NS_ABORT_MSG("SuperframeField Frame Order value must be 15 or less");
76 }
77 else
78 {
79 m_sspecSprFrmOrder = frmOrder;
80 }
81}
82
83void
85{
86 if (capSlot > 15)
87 {
88 NS_ABORT_MSG("The final slot cannot be greater than the slots in a CAP (15)");
89 }
90 else
91 {
92 m_sspecFnlCapSlot = capSlot;
93 }
94}
95
96void
98{
99 m_sspecBatLifeExt = battLifeExt;
100}
101
102void
104{
105 m_sspecPanCoor = panCoor;
106}
107
108void
110{
111 m_sspecAssocPermit = assocPermit;
112}
113
114uint8_t
116{
117 return m_sspecBcnOrder;
118}
119
120uint8_t
122{
123 return m_sspecSprFrmOrder;
124}
125
126uint8_t
128{
129 return m_sspecFnlCapSlot;
130}
131
132bool
134{
135 return m_sspecBatLifeExt;
136}
137
138bool
140{
141 return m_sspecPanCoor;
142}
143
144bool
146{
147 return m_sspecAssocPermit;
148}
149
150uint16_t
152{
153 uint16_t superframe;
154
155 superframe = m_sspecBcnOrder & (0x0F); // Bits 0-3
156 superframe |= (m_sspecSprFrmOrder << 4) & (0x0F << 4); // Bits 4-7
157 superframe |= (m_sspecFnlCapSlot << 8) & (0x0F << 8); // Bits 8-11
158 superframe |= (m_sspecBatLifeExt << 12) & (0x01 << 12); // Bit 12
159 // Bit 13 (Reserved)
160 superframe |= (m_sspecPanCoor << 14) & (0x01 << 14); // Bit 14
161 superframe |= (m_sspecAssocPermit << 15) & (0x01 << 15); // Bit 15
162
163 return superframe;
164}
165
166std::ostream&
167operator<<(std::ostream& os, const SuperframeField& superframeField)
168{
169 os << " Beacon Order = " << uint32_t(superframeField.GetBeaconOrder())
170 << ", Frame Order = " << uint32_t(superframeField.GetFrameOrder())
171 << ", Final CAP slot = " << uint32_t(superframeField.GetFinalCapSlot())
172 << ", Battery Life Ext = " << bool(superframeField.IsBattLifeExt())
173 << ", PAN Coordinator = " << bool(superframeField.IsPanCoor())
174 << ", Association Permit = " << bool(superframeField.IsAssocPermit());
175 return os;
176}
177
178/***********************************************************
179 * Guaranteed Time Slots (GTS) Fields
180 ***********************************************************/
181
183{
184 // GTS Specification Field
186 m_gtsSpecPermit = 0;
187 // GTS Direction Field
188 m_gtsDirMask = 0;
189}
190
191uint8_t
193{
194 uint8_t gtsSpecField;
195
196 gtsSpecField = m_gtsSpecDescCount & (0x07); // Bits 0-2
197 // Bits 3-6 (Reserved)
198 gtsSpecField |= (m_gtsSpecPermit << 7) & (0x01 << 7); // Bit 7
199
200 return gtsSpecField;
201}
202
203uint8_t
205{
206 uint8_t gtsDirectionField;
207
208 gtsDirectionField = m_gtsDirMask & (0x7F); // Bit 0-6
209 // Bit 7 (Reserved)
210 return gtsDirectionField;
211}
212
213void
215{
216 m_gtsSpecDescCount = (gtsSpec) & (0x07); // Bits 0-2
217 // Bits 3-6 (Reserved)
218 m_gtsSpecPermit = (gtsSpec >> 7) & (0x01); // Bit 7
219}
220
221void
223{
224 m_gtsDirMask = (gtsDir) & (0x7F); // Bits 0-6
225 // Bit 7 (Reserved)
226}
227
228bool
230{
231 return m_gtsSpecPermit;
232}
233
236{
237 uint32_t size;
238
239 size = 1; // 1 octet GTS Specification Field
240 if (m_gtsSpecDescCount > 0)
241 {
242 size += 1; // 1 octet GTS Direction Field
243 size += (m_gtsSpecDescCount * 3); // 3 octets per GTS descriptor
244 }
245
246 return size;
247}
248
251{
253
254 if (m_gtsSpecDescCount > 0)
255 {
256 uint8_t gtsDescStartAndLength;
258
259 for (int j = 0; j < m_gtsSpecDescCount; j++)
260 {
261 WriteTo(i, m_gtsList[j].m_gtsDescDevShortAddr);
262
263 gtsDescStartAndLength =
264 (m_gtsList[j].m_gtsDescStartSlot & 0x0F) | // GTS descriptor bits 16-19
265 (m_gtsList[j].m_gtsDescLength & 0xF0); // GTS descriptor bits 20-23
266
267 i.WriteU8(gtsDescStartAndLength);
268 }
269 }
270 return i;
271}
272
275{
276 uint8_t gtsSpecField = i.ReadU8();
277 SetGtsSpecField(gtsSpecField);
278
279 if (m_gtsSpecDescCount > 0)
280 {
281 uint8_t gtsDirectionField = i.ReadU8();
282 SetGtsDirectionField(gtsDirectionField);
283
284 uint8_t gtsDescStartAndLength;
285 for (int j = 0; j < m_gtsSpecDescCount; j++)
286 {
287 ReadFrom(i, m_gtsList[j].m_gtsDescDevShortAddr);
288
289 gtsDescStartAndLength = i.ReadU8();
290 m_gtsList[j].m_gtsDescStartSlot = (gtsDescStartAndLength) & (0x0F);
291 m_gtsList[j].m_gtsDescLength = (gtsDescStartAndLength >> 4) & (0x0F);
292 }
293 }
294 return i;
295}
296
297std::ostream&
298operator<<(std::ostream& os, const GtsFields& gtsFields)
299{
300 os << " GTS specification = " << uint32_t(gtsFields.GetGtsSpecField())
301 << ", GTS direction = " << uint32_t(gtsFields.GetGtsDirectionField());
302 return os;
303}
304
305/***********************************************************
306 * Pending Address Fields
307 ***********************************************************/
308
310{
313}
314
315uint8_t
317{
319}
320
321uint8_t
323{
325}
326
327uint8_t
329{
330 uint8_t pndAddrSpecField;
331
332 pndAddrSpecField = m_pndAddrSpecNumShortAddr & (0x07); // Bits 0-2
333 // Bit 3 (Reserved)
334 pndAddrSpecField |= (m_pndAddrSpecNumExtAddr << 4) & (0x07 << 4); // Bits 4-6
335 // Bit 7 (Reserved)
336
337 return pndAddrSpecField;
338}
339
340void
342{
343 uint8_t totalPendAddr = m_pndAddrSpecNumShortAddr + m_pndAddrSpecNumExtAddr;
344
345 if (totalPendAddr == 7)
346 {
347 return;
348 }
349 else
350 {
353 }
354}
355
356void
358{
359 uint8_t totalPendAddr = m_pndAddrSpecNumShortAddr + m_pndAddrSpecNumExtAddr;
360
361 if (totalPendAddr == 7)
362 {
363 return;
364 }
365 else
366 {
369 }
370}
371
372bool
374{
375 for (int j = 0; j <= m_pndAddrSpecNumShortAddr; j++)
376 {
377 if (shortAddr == m_shortAddrList[j])
378 {
379 return true;
380 }
381 }
382
383 return false;
384}
385
386bool
388{
389 for (int j = 0; j <= m_pndAddrSpecNumExtAddr; j++)
390 {
391 if (extAddr == m_extAddrList[j])
392 {
393 return true;
394 }
395 }
396
397 return false;
398}
399
400void
402{
403 m_pndAddrSpecNumShortAddr = (pndAddrSpecField) & (0x07); // Bit 0-2
404 // Bit 3
405 m_pndAddrSpecNumExtAddr = (pndAddrSpecField >> 4) & (0x07); // Bit 4-6
406 // Bit 7
407}
408
411{
412 uint32_t size;
413
414 size = 1; // 1 octet (Pending Address Specification Field)
415 size = size + (m_pndAddrSpecNumShortAddr * 2); // X octets (Short Pending Address List)
416 size = size + (m_pndAddrSpecNumExtAddr * 8); // X octets (Extended Pending Address List)
417
418 return size;
419}
420
423{
425
426 for (int j = 0; j < m_pndAddrSpecNumShortAddr; j++)
427 {
429 }
430
431 for (int k = 0; k < m_pndAddrSpecNumExtAddr; k++)
432 {
433 WriteTo(i, m_extAddrList[k]);
434 }
435
436 return i;
437}
438
441{
442 uint8_t pndAddrSpecField = i.ReadU8();
443
444 SetPndAddrSpecField(pndAddrSpecField);
445
446 for (int j = 0; j < m_pndAddrSpecNumShortAddr; j++)
447 {
449 }
450
451 for (int k = 0; k < m_pndAddrSpecNumExtAddr; k++)
452 {
453 ReadFrom(i, m_extAddrList[k]);
454 }
455
456 return i;
457}
458
459std::ostream&
460operator<<(std::ostream& os, const PendingAddrFields& pendingAddrFields)
461{
462 os << " Num. Short Addr = " << uint32_t(pendingAddrFields.GetNumShortAddr())
463 << ", Num. Ext Addr = " << uint32_t(pendingAddrFields.GetNumExtAddr());
464 return os;
465}
466
467/***********************************************************
468 * Capability Information Field
469 ***********************************************************/
470
472{
473 m_deviceType = true;
474 m_powerSource = false;
476 m_securityCap = false;
477 m_allocAddr = true;
478}
479
481{
482 SetCapability(bitmap);
483}
484
485uint8_t
487{
488 uint8_t capability;
489
490 capability = (m_reservedBit0) & (0x01); //!< Bit 0 (reserved)
491 capability |= (m_deviceType << 1) & (0x01 << 1); //!< Bit 1
492 capability |= (m_powerSource << 2) & (0x01 << 2); //!< Bit 2
493 capability |= (m_receiverOnWhenIdle << 3) & (0x01 << 3); //!< Bit 3
494 capability |= (m_reservedBit45 << 4) & (0x03 << 4); //!< Bit 4-5 (reserved)
495 capability |= (m_securityCap << 6) & (0x01 << 6); //!< Bit 6
496 capability |= (m_allocAddr << 7) & (0x01 << 7); //!< Bit 7
497
498 return capability;
499}
500
501void
503{
504 m_reservedBit0 = (bitmap) & (0x01); //!< Bit 0 (reserved)
505 m_deviceType = (bitmap >> 1) & (0x01); //!< Bit 1
506 m_powerSource = (bitmap >> 2) & (0x01); //!< Bit 2
507 m_receiverOnWhenIdle = (bitmap >> 3) & (0x01); //!< Bit 3
508 m_reservedBit45 = (bitmap >> 4) & (0x03); //!< Bit 4-5 (reserved)
509 m_securityCap = (bitmap >> 6) & (0x01); //!< Bit 6
510 m_allocAddr = (bitmap >> 7) & (0x01); //!< Bit 7
511}
512
513bool
515{
516 return m_deviceType;
517}
518
519bool
521{
522 return m_powerSource;
523}
524
525bool
527{
529}
530
531bool
533{
534 return m_securityCap;
535}
536
537bool
539{
540 return m_allocAddr;
541}
542
543void
545{
546 m_deviceType = devType;
547}
548
549void
551{
552 m_powerSource = pow;
553}
554
555void
557{
558 m_receiverOnWhenIdle = rxIdle;
559}
560
561void
563{
564 m_securityCap = sec;
565}
566
567void
569{
570 m_allocAddr = addrAlloc;
571}
572
573/**
574 * output stream output operator
575 *
576 * \param os output stream
577 * \param capabilityField the Capability Information Field
578 *
579 * \returns output stream
580 */
581std::ostream&
582operator<<(std::ostream& os, const CapabilityField& capabilityField)
583{
584 os << " FFD device capable = " << bool(capabilityField.IsDeviceTypeFfd())
585 << ", Alternate Power Current Available = " << bool(capabilityField.IsPowSrcAvailable())
586 << ", Receiver On When Idle = " << bool(capabilityField.IsReceiverOnWhenIdle())
587 << ", Security Capable = " << bool(capabilityField.IsSecurityCapability())
588 << ", Coordinator Allocate Short Address = " << bool(capabilityField.IsShortAddrAllocOn());
589 return os;
590}
591
592} // namespace lrwpan
593} // 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
This class can contain 16 bit addresses.
Definition: mac16-address.h:44
an EUI-64 address
Definition: mac64-address.h:46
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:49
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)