A Discrete-Event Network Simulator
API
lr-wpan-fields.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2019 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
22
23#include "lr-wpan-fields.h"
24#include <ns3/log.h>
25#include <ns3/address-utils.h>
26
27namespace ns3 {
28
30{
31 SetBeaconOrder (15);
34 SetBattLifeExt (false);
35 SetPanCoor (false);
36 SetAssocPermit (false);
37}
38
39void
40SuperframeField::SetSuperframe (uint16_t superFrmSpec)
41{
42 m_sspecBcnOrder = (superFrmSpec) & (0x0F); //Bits 0-3
43 m_sspecSprFrmOrder = (superFrmSpec >> 4) & (0x0F); //Bits 4-7
44 m_sspecFnlCapSlot = (superFrmSpec >> 8) & (0x0F); //Bits 8-11
45 m_sspecBatLifeExt = (superFrmSpec >> 12) & (0x01); //Bit 12
46 //Bit 13 (Reserved)
47 m_sspecPanCoor = (superFrmSpec >> 14) & (0x01); //Bit 14
48 m_sspecAssocPermit = (superFrmSpec >> 15) & (0x01); //Bit 15
49}
50
51void
53{
54 if (bcnOrder > 15)
55 {
56 std::cout << "SuperframeField Beacon Order value must be 15 or less\n";
57 }
58 else
59 {
60 m_sspecBcnOrder = bcnOrder;
61 }
62}
63
64void
66{
67 if (frmOrder > 15)
68 {
69 std::cout << "SuperframeField Frame Order value must be 15 or less\n";
70 }
71 else
72 {
73 m_sspecSprFrmOrder = frmOrder;
74 }
75}
76
77void
79{
80 if (capSlot > 15)
81 {
82 std::cout << "The final slot cannot greater than the slots in a CAP (15)\n";
83 }
84 else
85 {
86 m_sspecFnlCapSlot = capSlot;
87 }
88}
89
90void
92{
93 m_sspecBatLifeExt = battLifeExt;
94}
95
96void
98{
99 m_sspecPanCoor = panCoor;
100}
101
102void
104{
105 m_sspecAssocPermit = assocPermit;
106}
107
108uint8_t
110{
111 return m_sspecBcnOrder;
112}
113
114uint8_t
116{
117 return m_sspecSprFrmOrder;
118}
119
120uint8_t
122{
123 return m_sspecFnlCapSlot;
124}
125
126bool
128{
129 return m_sspecBatLifeExt;
130}
131
132bool
134{
135 return m_sspecPanCoor;
136}
137
138bool
140{
141 return m_sspecAssocPermit;
142}
143
144uint16_t
146{
147 uint16_t superframe;
148
149 superframe = m_sspecBcnOrder & (0x0F); // Bits 0-3
150 superframe |= (m_sspecSprFrmOrder << 4) & (0x0F << 4); // Bits 4-7
151 superframe |= (m_sspecFnlCapSlot << 8) & (0x0F << 8); // Bits 8-11
152 superframe |= (m_sspecBatLifeExt << 12) & (0x01 << 12); // Bit 12
153 // Bit 13 (Reserved)
154 superframe |= (m_sspecPanCoor << 14) & (0x01 << 14); // Bit 14
155 superframe |= (m_sspecAssocPermit << 15) & (0x01 << 15); // Bit 15
156
157 return superframe;
158}
159
162{
163 return 2; // 2 Octets (superframeSpec)
164}
165
168{
170 return i;
171}
172
175{
176 uint16_t superframe = i.ReadLsbtohU16 ();
177 SetSuperframe (superframe);
178
179 return i;
180}
181
182std::ostream &
183operator << (std::ostream &os, const SuperframeField &superframeField)
184{
185 os << " Beacon Order = " << uint32_t (superframeField.GetBeaconOrder ())
186 << ", Frame Order = " << uint32_t (superframeField.GetFrameOrder ())
187 << ", Final CAP slot = " << uint32_t (superframeField.GetFinalCapSlot ())
188 << ", Battery Life Ext = " << bool (superframeField.IsBattLifeExt ())
189 << ", PAN Coordinator = " << bool (superframeField.IsPanCoor ())
190 << ", Association Permit = " << bool (superframeField.IsAssocPermit ());
191 return os;
192}
193
194/***********************************************************
195 * Guaranteed Time Slots (GTS) Fields
196 ***********************************************************/
197
199{
200 // GTS Specification Field
202 m_gtsSpecPermit = 0;
203 // GTS Direction Field
204 m_gtsDirMask = 0;
205}
206
207uint8_t
209{
210 uint8_t gtsSpecField;
211
212 gtsSpecField = m_gtsSpecDescCount & (0x07); // Bits 0-2
213 // Bits 3-6 (Reserved)
214 gtsSpecField |= (m_gtsSpecPermit << 7) & (0x01 << 7); // Bit 7
215
216 return gtsSpecField;
217}
218
219uint8_t
221{
222 uint8_t gtsDirectionField;
223
224 gtsDirectionField = m_gtsDirMask & (0x7F); // Bit 0-6
225 // Bit 7 (Reserved)
226 return gtsDirectionField;
227}
228
229void
231{
232 m_gtsSpecDescCount = (gtsSpec) & (0x07); // Bits 0-2
233 // Bits 3-6 (Reserved)
234 m_gtsSpecPermit = (gtsSpec >> 7) & (0x01); // Bit 7
235}
236
237void
239{
240 m_gtsDirMask = (gtsDir) & (0x7F); // Bits 0-6
241 // Bit 7 (Reserved)
242}
243
246{
247 uint32_t size;
248
249 size = 1; // 1 octet GTS Specification Field
250 if (m_gtsSpecDescCount > 0)
251 {
252 size += 1; // 1 octet GTS Direction Field
253 size += (m_gtsSpecDescCount * 3); // 3 octets per GTS descriptor
254 }
255
256 return size;
257}
258
261{
263
264 if (m_gtsSpecDescCount > 0)
265 {
266 uint8_t gtsDescStartAndLenght;
268
269 for (int j = 0; j < m_gtsSpecDescCount; j++)
270 {
271 WriteTo (i,m_gtsList[j].m_gtsDescDevShortAddr);
272
273 gtsDescStartAndLenght = m_gtsList[j].m_gtsDescStartSlot & (0x0F);
274 gtsDescStartAndLenght = (m_gtsList[j].m_gtsDescLength << 4) & (0x0F);
275
276 i.WriteU8 (gtsDescStartAndLenght);
277 }
278 }
279 return i;
280}
281
284{
285
286 uint8_t gtsSpecField = i.ReadU8 ();
287 SetGtsSpecField (gtsSpecField);
288
289 if (m_gtsSpecDescCount > 0)
290 {
291 uint8_t gtsDirectionField = i.ReadU8 ();
292 SetGtsDirectionField (gtsDirectionField);
293
294 uint8_t gtsDescStartAndLenght;
295 for (int j = 0; j < m_gtsSpecDescCount; j++)
296 {
297 ReadFrom (i, m_gtsList[j].m_gtsDescDevShortAddr);
298
299 gtsDescStartAndLenght = i.ReadU8 ();
300 m_gtsList[j].m_gtsDescStartSlot = (gtsDescStartAndLenght) & (0x0F);
301 m_gtsList[j].m_gtsDescLength = (gtsDescStartAndLenght >> 4) & (0x0F);
302 }
303 }
304 return i;
305}
306
307std::ostream &
308operator << (std::ostream &os, const GtsFields &gtsFields)
309{
310 os << " GTS specification = " << uint32_t (gtsFields.GetGtsSpecField ())
311 << ", GTS direction = " << uint32_t (gtsFields.GetGtsDirectionField ());
312 return os;
313}
314
315/***********************************************************
316 * Pending Address Fields
317 ***********************************************************/
318
320{
323}
324
325
326uint8_t
328{
330}
331
332
333uint8_t
335{
337}
338
339uint8_t
341{
342 uint8_t pndAddrSpecField;
343
344 pndAddrSpecField = m_pndAddrSpecNumShortAddr & (0x07); // Bits 0-2
345 // Bit 3 (Reserved)
346 pndAddrSpecField |= (m_pndAddrSpecNumExtAddr << 4) & (0x07 << 4); // Bits 4-6
347 // Bit 7 (Reserved)
348
349 return pndAddrSpecField;
350}
351
352void
354{
355 uint8_t totalPendAddr = m_pndAddrSpecNumShortAddr + m_pndAddrSpecNumExtAddr;
356
357 if (totalPendAddr == 7)
358 {
359 return;
360 }
361 else
362 {
365 }
366}
367
368void
370{
371 uint8_t totalPendAddr = m_pndAddrSpecNumShortAddr + m_pndAddrSpecNumExtAddr;
372
373 if (totalPendAddr == 7)
374 {
375 return;
376 }
377 else
378 {
381 }
382}
383
384bool
386{
387 for (int j = 0; j <= m_pndAddrSpecNumShortAddr; j++)
388 {
389 if (shortAddr == m_shortAddrList[j])
390 {
391 return true;
392 }
393 }
394
395 return false;
396}
397
398
399bool
401{
402 for (int j = 0; j <= m_pndAddrSpecNumExtAddr; j++)
403 {
404 if (extAddr == m_extAddrList[j])
405 {
406 return true;
407 }
408 }
409
410 return false;
411}
412
413
414void
416{
417 m_pndAddrSpecNumShortAddr = (pndAddrSpecField) & (0x07); // Bit 0-2
418 // Bit 3
419 m_pndAddrSpecNumExtAddr = (pndAddrSpecField >> 4) & (0x07); // Bit 4-6
420 // Bit 7
421}
422
423
426{
427 uint32_t size;
428
429 size = 1; // 1 octet (Pending Address Specification Field)
430 size = size + (m_pndAddrSpecNumShortAddr * 2); // X octets (Short Pending Address List)
431 size = size + (m_pndAddrSpecNumExtAddr * 8); // X octets (Extended Pending Address List)
432
433 return size;
434}
435
438{
440
441 for (int j = 0; j < m_pndAddrSpecNumShortAddr; j++)
442 {
444 }
445
446 for (int k = 0; k < m_pndAddrSpecNumExtAddr; k++ )
447 {
449 }
450
451 return i;
452}
453
456{
457 uint8_t pndAddrSpecField = i.ReadU8 ();
458
459 SetPndAddrSpecField (pndAddrSpecField);
460
461 for (int j = 0; j < m_pndAddrSpecNumShortAddr; j++)
462 {
464 }
465
466 for (int k = 0; k < m_pndAddrSpecNumExtAddr; k++)
467 {
469 }
470
471 return i;
472}
473
474std::ostream &
475operator << (std::ostream &os, const PendingAddrFields &pendingAddrFields)
476{
477 os << " Num. Short Addr = " << uint32_t (pendingAddrFields.GetNumShortAddr ())
478 << ", Num. Ext Addr = " << uint32_t (pendingAddrFields.GetNumExtAddr ());
479 return os;
480}
481
482} // ns-3 namespace
iterator in a Buffer instance
Definition: buffer.h:99
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:911
void WriteU8(uint8_t data)
Definition: buffer.h:869
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint16_t ReadLsbtohU16(void)
Definition: buffer.cc:1066
Represent the GTS information fields.
void SetGtsSpecField(uint8_t gtsSpec)
Set the GTS Specification Field to the GTS Fields.
uint8_t GetGtsSpecField(void) const
Get the GTS Specification Field from the GTS Fields.
void SetGtsDirectionField(uint8_t gtsDir)
Set the GTS direction field to the GTS Fields.
gtsDescriptor m_gtsList[7]
GTS List field (maximum descriptors stored == 7)
uint32_t GetSerializedSize(void) const
Get the size of the serialized GTS fields.
uint8_t GetGtsDirectionField(void) const
Get the GTS Direction Field from the GTS Fields.
uint8_t m_gtsSpecPermit
GTS specification field GTS Permit (Bit 7)
uint8_t m_gtsSpecDescCount
GTS specification field Descriptor Count (Bit 0-2)
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire 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)
This class can contain 16 bit addresses.
Definition: mac16-address.h:42
an EUI-64 address
Definition: mac64-address.h:44
Represent the Pending Address Specification field.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the all the Pending Address Fields.
std::array< Mac16Address, 7 > m_shortAddrList
Pending Short Address List.
uint8_t GetNumExtAddr(void) const
Get the number of Extended Pending Address indicated in the Pending Address Specification Field.
std::array< Mac64Address, 7 > m_extAddrList
Pending Extended Address List.
uint32_t GetSerializedSize(void) const
Get the size of the serialized Pending Address Fields.
uint8_t m_pndAddrSpecNumShortAddr
Pending Address Specification field Number of Short Address (Bits 0-2) Pending Address Specification ...
uint8_t m_pndAddrSpecNumExtAddr
Pending Address Specification field Number of Extended Address (Bits 4-6) Pending Address Specificati...
bool SearchAddress(Mac16Address shortAddr)
Search for the short Pending Address in the Address List.
uint8_t GetNumShortAddr(void) const
Get the number of Short Pending Address indicated in the Pending Address Specification Field.
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.
void AddAddress(Mac16Address shortAddr)
Add a short Pending Address to the Address List.
void SetPndAddrSpecField(uint8_t pndAddrSpecField)
Set the whole Pending Address Specification field.
Represent the Superframe Specification information field.
bool m_sspecBatLifeExt
Superframe Specification field Battery Life Extension (Bit 12) Superframe Specification field Reserve...
bool m_sspecAssocPermit
Superframe Specification field Association Permit (Bit 15)
bool IsBattLifeExt(void) const
Check if the Battery Life Extension bit is enabled.
bool m_sspecPanCoor
Superframe Specification field PAN Coordinator (Bit 14)
uint8_t m_sspecFnlCapSlot
Superframe Specification field Final CAP slot (Bit 8-11)
void SetAssocPermit(bool assocPermit)
Set the Superframe Specification Association Permit field.
uint8_t m_sspecBcnOrder
Superframe Specification field Beacon Order (Bit 0-3)
void SetBattLifeExt(bool battLifeExt)
Set the Superframe Specification Battery Life Extension (BLE).
uint8_t GetFinalCapSlot(void) const
Get the the Final CAP Slot.
uint8_t m_sspecSprFrmOrder
Superframe Specification field Superframe Order (Bit 4-7)
uint32_t GetSerializedSize(void) const
Get the size of the serialized Superframe specification information field.
void SetFinalCapSlot(uint8_t capSlot)
Set the superframe specification Final CAP slot field.
void SetSuperframeOrder(uint8_t frmOrder)
Set the superframe specification Superframe Order field.
void SetPanCoor(bool panCoor)
Set the Superframe Specification PAN coordinator field.
uint16_t GetSuperframe(void) const
Get the Superframe specification information field.
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize the entire superframe specification field.
void SetBeaconOrder(uint8_t bcnOrder)
Set the superframe specification Beacon Order field.
bool IsAssocPermit(void) const
Check if the Association Permit bit is enabled.
uint8_t GetBeaconOrder(void) const
Get the Superframe Specification Beacon Order field.
Buffer::Iterator Deserialize(Buffer::Iterator i)
Deserialize the entire superframe specification field.
uint8_t GetFrameOrder(void) const
Get the Superframe Specification Frame Order field.
void SetSuperframe(uint16_t superFrm)
Set the whole Superframe Specification Information field.
bool IsPanCoor(void) const
Check if the PAN Coordinator bit is enabled.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:139
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)