A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
lora-frame-header.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2017 University of Padova
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: Davide Magrin <magrinda@dei.unipd.it>
18
*/
19
20
#ifndef LORA_FRAME_HEADER_H
21
#define LORA_FRAME_HEADER_H
22
23
#include "
lora-device-address.h
"
24
#include "
mac-command.h
"
25
26
#include "ns3/header.h"
27
28
namespace
ns3
29
{
30
namespace
lorawan
31
{
32
33
/**
34
* \ingroup lorawan
35
*
36
* This class represents the Frame header (FHDR) used in a LoraWAN network.
37
*
38
* Although the specification divides the FHDR from the FPort field, this
39
* implementation considers them as a unique entity (i.e., FPort is treated as
40
* if it were a part of FHDR).
41
*
42
* \remark Prior to using it, this class needs to be informed of whether the
43
* header is for an uplink or downlink message. This is necessary due to the
44
* fact that UL and DL messages have subtly different structure and, hence,
45
* serialization and deserialization schemes.
46
*/
47
class
LoraFrameHeader
:
public
Header
48
{
49
public
:
50
LoraFrameHeader
();
//!< Default constructor
51
~LoraFrameHeader
()
override
;
//!< Destructor
52
53
// Methods inherited from Header
54
55
/**
56
* Register this type.
57
* \return The object TypeId.
58
*/
59
static
TypeId
GetTypeId
();
60
TypeId
GetInstanceTypeId
()
const override
;
61
62
/**
63
* Return the size required for serialization of this header.
64
*
65
* \return The serialized size in bytes.
66
*/
67
uint32_t
GetSerializedSize
()
const override
;
68
69
/**
70
* Serialize the header.
71
*
72
* See Page 15 of LoraWAN specification for a representation of fields.
73
*
74
* \param start A pointer to the buffer that will be filled with the
75
* serialization.
76
*/
77
void
Serialize
(
Buffer::Iterator
start)
const override
;
78
79
/**
80
* Deserialize the contents of the buffer into a LoraFrameHeader object.
81
*
82
* \param start A pointer to the buffer we need to deserialize.
83
* \return The number of consumed bytes.
84
*/
85
uint32_t
Deserialize
(
Buffer::Iterator
start)
override
;
86
87
/**
88
* Print the header in a human-readable format.
89
*
90
* \param os The std::ostream on which to print the header.
91
*/
92
void
Print
(std::ostream& os)
const override
;
93
94
/**
95
* State that this is an uplink message.
96
*
97
* This method needs to be called at least once before any serialization or
98
* deserialization.
99
*/
100
void
SetAsUplink
();
101
102
/**
103
* State that this is a downlink message.
104
*
105
* This method needs to be called at least once before any serialization or
106
* deserialization.
107
*/
108
void
SetAsDownlink
();
109
110
/**
111
* Set the FPort value.
112
*
113
* \param fPort The FPort to set.
114
*/
115
void
SetFPort
(uint8_t fPort);
116
117
/**
118
* Get the FPort value.
119
*
120
* \return The FPort value.
121
*/
122
uint8_t
GetFPort
()
const
;
123
124
/**
125
* Set the address.
126
*
127
* \param address The LoraDeviceAddress to set.
128
*/
129
void
SetAddress
(
LoraDeviceAddress
address);
130
131
/**
132
* Get this header's device address value.
133
*
134
* \return The address value stored in this header.
135
*/
136
LoraDeviceAddress
GetAddress
()
const
;
137
138
/**
139
* Set the value of the ADR bit field.
140
*
141
* \param adr Whether or not to set the ADR bit field.
142
*/
143
void
SetAdr
(
bool
adr);
144
145
/**
146
* Get the value of the ADR bit field.
147
*
148
* \return True if the ADR bit is set, false otherwise.
149
*/
150
bool
GetAdr
()
const
;
151
152
/**
153
* Set the value of the ADRACKReq bit field.
154
*
155
* \param adrAckReq Whether or not to set the ADRACKReq bit field.
156
*/
157
void
SetAdrAckReq
(
bool
adrAckReq);
158
159
/**
160
* Get the value of the ADRACKReq bit field.
161
*
162
* \return True if the ADRACKReq bit is set, false otherwise.
163
*/
164
bool
GetAdrAckReq
()
const
;
165
166
/**
167
* Set the value of the ACK bit field.
168
*
169
* \param ack Whether or not to set the ACK bit.
170
*/
171
void
SetAck
(
bool
ack);
172
173
/**
174
* Get the value of the ACK bit field.
175
*
176
* \return True if the ACK bit is set, false otherwise.
177
*/
178
bool
GetAck
()
const
;
179
180
/**
181
* Set the value of the FPending bit field.
182
*
183
* \param fPending Whether or not to set the FPending bit.
184
*/
185
void
SetFPending
(
bool
fPending);
186
187
/**
188
* Get the value of the FPending bit field.
189
*
190
* \return True if the FPending bit is set, false otherwise.
191
*/
192
bool
GetFPending
()
const
;
193
194
/**
195
* Get the FOptsLen value.
196
*
197
* \remark This value cannot be set since it's directly extracted from the
198
* number and kind of MAC commands.
199
*
200
* \return The FOptsLen value.
201
*/
202
uint8_t
GetFOptsLen
()
const
;
203
204
/**
205
* Set the FCnt value.
206
*
207
* \param fCnt The FCnt to set.
208
*/
209
void
SetFCnt
(uint16_t fCnt);
210
/**
211
* Get the FCnt value.
212
*
213
* \return The FCnt value.
214
*/
215
uint16_t
GetFCnt
()
const
;
216
217
/**
218
* Return a pointer to the first MacCommand of type T, or 0 if no such MacCommand exists
219
* in this header.
220
*
221
* \return A pointer to a MacCommand of type T.
222
*/
223
template
<
typename
T>
224
inline
Ptr<T>
GetMacCommand
();
225
226
/**
227
* Add a LinkCheckReq command.
228
*/
229
void
AddLinkCheckReq
();
230
231
/**
232
* Add a LinkCheckAns command.
233
*
234
* \param margin The demodulation margin the LinkCheckReq packet was received with.
235
* \param gwCnt The number of gateways the LinkCheckReq packet was received by.
236
*/
237
void
AddLinkCheckAns
(uint8_t margin, uint8_t gwCnt);
238
239
/**
240
* Add a LinkAdrReq command.
241
*
242
* \param dataRate The data rate at which the receiver should transmit.
243
* \param txPower The power at which the receiver should transmit, encoded according to the
244
* LoRaWAN specification of the region. \param enabledChannels A list containing the indices of
245
* channels enabled by this command. \param repetitions The number of repetitions the receiver
246
* should send when transmitting.
247
*/
248
void
AddLinkAdrReq
(uint8_t dataRate,
249
uint8_t txPower,
250
std::list<int> enabledChannels,
251
int
repetitions);
252
253
/**
254
* Add a LinkAdrAns command.
255
*
256
* \param powerAck Whether the power can be set or not.
257
* \param dataRateAck Whether the data rate can be set or not.
258
* \param channelMaskAck Whether the channel mask is coherent with the device's current state or
259
* not.
260
*/
261
void
AddLinkAdrAns
(
bool
powerAck,
bool
dataRateAck,
bool
channelMaskAck);
262
263
/**
264
* Add a DutyCycleReq command.
265
*
266
* This command accepts an 8-bit integer as dutyCycle. The actual dutyCycle
267
* that will be implemented in the end-device will then be, in fraction form,
268
* 1/2^(dutyCycle).
269
*
270
* \param dutyCycle The dutyCycle in 8-bit form.
271
*/
272
void
AddDutyCycleReq
(uint8_t dutyCycle);
273
274
/**
275
* Add a DutyCycleAns command.
276
*/
277
void
AddDutyCycleAns
();
278
279
/**
280
* Add a RxParamSetupReq command.
281
*
282
* \param rx1DrOffset The requested data rate offset for the first receive window.
283
* \param rx2DataRate The requested data rate for the second receive window.
284
* \param frequency The frequency at which to listen for the second receive window.
285
*/
286
void
AddRxParamSetupReq
(uint8_t rx1DrOffset, uint8_t rx2DataRate,
double
frequency);
287
288
/**
289
* Add a RxParamSetupAns command.
290
*/
291
void
AddRxParamSetupAns
();
292
293
/**
294
* Add a DevStatusReq command.
295
*/
296
void
AddDevStatusReq
();
297
298
/**
299
* Add a NewChannelReq command with provided fields.
300
*
301
* \param chIndex The ChIndex field.
302
* \param frequency The Frequency field.
303
* \param minDataRate The MinDR field.
304
* \param maxDataRate The MaxDR field.
305
*/
306
void
AddNewChannelReq
(uint8_t chIndex,
307
double
frequency,
308
uint8_t minDataRate,
309
uint8_t maxDataRate);
310
311
/**
312
* Return a list of pointers to all the MAC commands saved in this header.
313
*
314
* \return The list of pointers to MacCommand objects.
315
*/
316
std::list<Ptr<MacCommand>>
GetCommands
();
317
318
/**
319
* Add a predefined command to the list in this frame header.
320
*
321
* \param macCommand A pointer to the MacCommand object to add.
322
*/
323
void
AddCommand
(
Ptr<MacCommand>
macCommand);
324
325
private
:
326
uint8_t
m_fPort
;
//!< The FPort field
327
328
LoraDeviceAddress
m_address
;
//!< The DevAddr field
329
330
bool
m_adr
;
//!< The ADR field of the FCtrl
331
bool
m_adrAckReq
;
//!< The ADRACKReq field of the FCtrl
332
bool
m_ack
;
//!< The ACK field of the FCtrl
333
bool
m_fPending
;
//!< The FPending/ClassB field of the FCtrl
334
uint8_t
m_fOptsLen
;
//!< The FOptsLen field of the FCtrl
335
336
uint16_t
m_fCnt
;
//!< The FCnt field
337
338
Buffer
m_fOpts
;
//!< The FOpts field
339
std::list<Ptr<MacCommand>>
m_macCommands
;
//!< List containing all the MacCommand instances that
340
//!< are contained in this LoraFrameHeader
341
342
bool
m_isUplink
;
//!< Whether this frame header is uplink or not
343
};
344
345
template
<
typename
T>
346
Ptr<T>
347
LoraFrameHeader::GetMacCommand
()
348
{
349
// Iterate on MAC commands and try casting
350
std::list<Ptr<MacCommand>>::const_iterator it;
351
for
(it =
m_macCommands
.begin(); it !=
m_macCommands
.end(); ++it)
352
{
353
if
((*it)->GetObject<T>())
354
{
355
return
(*it)->GetObject<T>();
356
}
357
}
358
359
// If no command was found, return 0
360
return
nullptr
;
361
}
362
}
// namespace lorawan
363
364
}
// namespace ns3
365
#endif
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:100
ns3::Buffer
automatically resized byte buffer
Definition:
buffer.h:94
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:44
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:77
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::lorawan::LoraDeviceAddress
This class represents the device address of a LoraWAN end device.
Definition:
lora-device-address.h:117
ns3::lorawan::LoraFrameHeader
This class represents the Frame header (FHDR) used in a LoraWAN network.
Definition:
lora-frame-header.h:48
ns3::lorawan::LoraFrameHeader::m_ack
bool m_ack
The ACK field of the FCtrl.
Definition:
lora-frame-header.h:332
ns3::lorawan::LoraFrameHeader::AddDutyCycleReq
void AddDutyCycleReq(uint8_t dutyCycle)
Add a DutyCycleReq command.
Definition:
lora-frame-header.cc:507
ns3::lorawan::LoraFrameHeader::GetAck
bool GetAck() const
Get the value of the ACK bit field.
Definition:
lora-frame-header.cc:403
ns3::lorawan::LoraFrameHeader::GetFPort
uint8_t GetFPort() const
Get the FPort value.
Definition:
lora-frame-header.cc:353
ns3::lorawan::LoraFrameHeader::AddLinkCheckReq
void AddLinkCheckReq()
Add a LinkCheckReq command.
Definition:
lora-frame-header.cc:446
ns3::lorawan::LoraFrameHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the contents of the buffer into a LoraFrameHeader object.
Definition:
lora-frame-header.cc:122
ns3::lorawan::LoraFrameHeader::AddCommand
void AddCommand(Ptr< MacCommand > macCommand)
Add a predefined command to the list in this frame header.
Definition:
lora-frame-header.cc:594
ns3::lorawan::LoraFrameHeader::SetFCnt
void SetFCnt(uint16_t fCnt)
Set the FCnt value.
Definition:
lora-frame-header.cc:434
ns3::lorawan::LoraFrameHeader::GetAdr
bool GetAdr() const
Get the value of the ADR bit field.
Definition:
lora-frame-header.cc:378
ns3::lorawan::LoraFrameHeader::GetMacCommand
Ptr< T > GetMacCommand()
Return a pointer to the first MacCommand of type T, or 0 if no such MacCommand exists in this header.
Definition:
lora-frame-header.h:347
ns3::lorawan::LoraFrameHeader::AddNewChannelReq
void AddNewChannelReq(uint8_t chIndex, double frequency, uint8_t minDataRate, uint8_t maxDataRate)
Add a NewChannelReq command with provided fields.
Definition:
lora-frame-header.cc:570
ns3::lorawan::LoraFrameHeader::AddDutyCycleAns
void AddDutyCycleAns()
Add a DutyCycleAns command.
Definition:
lora-frame-header.cc:519
ns3::lorawan::LoraFrameHeader::m_fPending
bool m_fPending
The FPending/ClassB field of the FCtrl.
Definition:
lora-frame-header.h:333
ns3::lorawan::LoraFrameHeader::AddRxParamSetupAns
void AddRxParamSetupAns()
Add a RxParamSetupAns command.
Definition:
lora-frame-header.cc:546
ns3::lorawan::LoraFrameHeader::SetAck
void SetAck(bool ack)
Set the value of the ACK bit field.
Definition:
lora-frame-header.cc:396
ns3::lorawan::LoraFrameHeader::m_adr
bool m_adr
The ADR field of the FCtrl.
Definition:
lora-frame-header.h:330
ns3::lorawan::LoraFrameHeader::m_fCnt
uint16_t m_fCnt
The FCnt field.
Definition:
lora-frame-header.h:336
ns3::lorawan::LoraFrameHeader::SetAdr
void SetAdr(bool adr)
Set the value of the ADR bit field.
Definition:
lora-frame-header.cc:371
ns3::lorawan::LoraFrameHeader::m_fOptsLen
uint8_t m_fOptsLen
The FOptsLen field of the FCtrl.
Definition:
lora-frame-header.h:334
ns3::lorawan::LoraFrameHeader::AddDevStatusReq
void AddDevStatusReq()
Add a DevStatusReq command.
Definition:
lora-frame-header.cc:558
ns3::lorawan::LoraFrameHeader::GetFPending
bool GetFPending() const
Get the value of the FPending bit field.
Definition:
lora-frame-header.cc:415
ns3::lorawan::LoraFrameHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Return the size required for serialization of this header.
Definition:
lora-frame-header.cc:65
ns3::lorawan::LoraFrameHeader::SetAddress
void SetAddress(LoraDeviceAddress address)
Set the address.
Definition:
lora-frame-header.cc:359
ns3::lorawan::LoraFrameHeader::GetFCnt
uint16_t GetFCnt() const
Get the FCnt value.
Definition:
lora-frame-header.cc:440
ns3::lorawan::LoraFrameHeader::Print
void Print(std::ostream &os) const override
Print the header in a human-readable format.
Definition:
lora-frame-header.cc:310
ns3::lorawan::LoraFrameHeader::GetAdrAckReq
bool GetAdrAckReq() const
Get the value of the ADRACKReq bit field.
Definition:
lora-frame-header.cc:390
ns3::lorawan::LoraFrameHeader::m_macCommands
std::list< Ptr< MacCommand > > m_macCommands
List containing all the MacCommand instances that are contained in this LoraFrameHeader.
Definition:
lora-frame-header.h:339
ns3::lorawan::LoraFrameHeader::SetAsUplink
void SetAsUplink()
State that this is an uplink message.
Definition:
lora-frame-header.cc:331
ns3::lorawan::LoraFrameHeader::m_address
LoraDeviceAddress m_address
The DevAddr field.
Definition:
lora-frame-header.h:328
ns3::lorawan::LoraFrameHeader::m_fOpts
Buffer m_fOpts
The FOpts field.
Definition:
lora-frame-header.h:338
ns3::lorawan::LoraFrameHeader::GetAddress
LoraDeviceAddress GetAddress() const
Get this header's device address value.
Definition:
lora-frame-header.cc:365
ns3::lorawan::LoraFrameHeader::SetAdrAckReq
void SetAdrAckReq(bool adrAckReq)
Set the value of the ADRACKReq bit field.
Definition:
lora-frame-header.cc:384
ns3::lorawan::LoraFrameHeader::~LoraFrameHeader
~LoraFrameHeader() override
Destructor.
Definition:
lora-frame-header.cc:46
ns3::lorawan::LoraFrameHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Serialize the header.
Definition:
lora-frame-header.cc:79
ns3::lorawan::LoraFrameHeader::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition:
lora-frame-header.cc:51
ns3::lorawan::LoraFrameHeader::m_adrAckReq
bool m_adrAckReq
The ADRACKReq field of the FCtrl.
Definition:
lora-frame-header.h:331
ns3::lorawan::LoraFrameHeader::SetFPending
void SetFPending(bool fPending)
Set the value of the FPending bit field.
Definition:
lora-frame-header.cc:409
ns3::lorawan::LoraFrameHeader::AddLinkCheckAns
void AddLinkCheckAns(uint8_t margin, uint8_t gwCnt)
Add a LinkCheckAns command.
Definition:
lora-frame-header.cc:458
ns3::lorawan::LoraFrameHeader::AddLinkAdrAns
void AddLinkAdrAns(bool powerAck, bool dataRateAck, bool channelMaskAck)
Add a LinkAdrAns command.
Definition:
lora-frame-header.cc:496
ns3::lorawan::LoraFrameHeader::m_isUplink
bool m_isUplink
Whether this frame header is uplink or not.
Definition:
lora-frame-header.h:342
ns3::lorawan::LoraFrameHeader::AddLinkAdrReq
void AddLinkAdrReq(uint8_t dataRate, uint8_t txPower, std::list< int > enabledChannels, int repetitions)
Add a LinkAdrReq command.
Definition:
lora-frame-header.cc:469
ns3::lorawan::LoraFrameHeader::m_fPort
uint8_t m_fPort
The FPort field.
Definition:
lora-frame-header.h:326
ns3::lorawan::LoraFrameHeader::LoraFrameHeader
LoraFrameHeader()
Default constructor.
Definition:
lora-frame-header.cc:34
ns3::lorawan::LoraFrameHeader::GetCommands
std::list< Ptr< MacCommand > > GetCommands()
Return a list of pointers to all the MAC commands saved in this header.
Definition:
lora-frame-header.cc:586
ns3::lorawan::LoraFrameHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition:
lora-frame-header.cc:59
ns3::lorawan::LoraFrameHeader::SetAsDownlink
void SetAsDownlink()
State that this is a downlink message.
Definition:
lora-frame-header.cc:339
ns3::lorawan::LoraFrameHeader::SetFPort
void SetFPort(uint8_t fPort)
Set the FPort value.
Definition:
lora-frame-header.cc:347
ns3::lorawan::LoraFrameHeader::AddRxParamSetupReq
void AddRxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, double frequency)
Add a RxParamSetupReq command.
Definition:
lora-frame-header.cc:531
ns3::lorawan::LoraFrameHeader::GetFOptsLen
uint8_t GetFOptsLen() const
Get the FOptsLen value.
Definition:
lora-frame-header.cc:421
uint32_t
lora-device-address.h
mac-command.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
lorawan
model
lora-frame-header.h
Generated on Mon Aug 12 2024 11:16:15 for ns-3 by
1.9.6