A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
end-device-lorawan-mac.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 University of Padova
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Davide Magrin <magrinda@dei.unipd.it>
7 * Martina Capuzzo <capuzzom@dei.unipd.it>
8 *
9 * Modified by: Peggy Anderson <peggy.anderson@usask.ca>
10 */
11
12#ifndef END_DEVICE_LORAWAN_MAC_H
13#define END_DEVICE_LORAWAN_MAC_H
14
15#include "lora-frame-header.h"
16#include "lorawan-mac-header.h"
17#include "lorawan-mac.h"
18
19#include "ns3/random-variable-stream.h"
20#include "ns3/traced-value.h"
21
22namespace ns3
23{
24namespace lorawan
25{
26
27enum class CodingRate : uint8_t;
28
29/**
30 * @ingroup lorawan
31 *
32 * Class representing the MAC layer of a LoRaWAN device.
33 */
35{
36 public:
37 /**
38 * Register this type.
39 * @return The object TypeId.
40 */
41 static TypeId GetTypeId();
42
43 EndDeviceLorawanMac(); //!< Default constructor
44 ~EndDeviceLorawanMac() override; //!< Destructor
45
46 static constexpr uint16_t ADR_ACK_LIMIT = 64; //!< ADRACKCnt threshold for setting ADRACKReq
47 static constexpr uint16_t ADR_ACK_DELAY = 32; //!< ADRACKCnt threshold for ADR backoff action
48
49 /**
50 * Send a packet.
51 *
52 * The MAC layer of the end device will take care of using the right parameters. This function
53 * may return immediately if the packet cannot be sent with the current MAC parameters, or it
54 * may automatically reschedule itself later on if the device has exhausted it duty cycle budget
55 * or if it is currently busy on another task.
56 *
57 * @param packet The packet to send.
58 */
59 void Send(Ptr<Packet> packet) override;
60
61 /**
62 * Evaluate whether this packet can be sent in the current device state
63 *
64 * @param [in] packet The packet to be evaluated
65 * @param [out] nextTxDelay Minimum delay for sending the packet
66 * @return Whether the packet can be sent in the current device state
67 */
68 bool ValidatePacketForSend(Ptr<const Packet> packet, Time& nextTxDelay) const;
69
70 /**
71 * Add a MAC command to the list of those that will be sent out in the next packet.
72 *
73 * @param macCommand A pointer to the MAC command.
74 */
75 void AddMacCommand(Ptr<MacCommand> macCommand);
76
77 /**
78 * Signals to the network server that this device will or may not comply with LinkADRReq
79 * settings (data rate, transmission power and number of retransmissions) received in downlink.
80 * This also controls whether the local ADR backoff procedure can reset configurations in case
81 * of connectivity loss. A false value effectively allows for a fully static transmission
82 * parameters configuration.
83 *
84 * @note Setting this to false does not prevent the device from setting the ADRACKReq bit
85 * in its FHDR to request a keepalive downlink message from the server.
86 *
87 * @param adr The ADR bit.
88 */
89 void SetUplinkAdrBit(bool adr);
90
91 /**
92 * Get the current value of the device's uplink ADR bit of the LoRaWAN FHDR.
93 *
94 * @return true The device will comply with data rate, transmission power and number of
95 * retransmissions settings received from the network server via LinkADRReq.
96 * @return false Signals to the network server that the device may not comply with the data
97 * rate, transmission power and number of retransmissions settings received via LikADRReq.
98 */
99 bool GetUplinkAdrBit() const;
100
101 /**
102 * Set the max number of unacknowledged redundant transmissions of each packet. If,
103 * after a transmission, any acknowledgement is received, no more are sent for that packet.
104 *
105 * @param nbTrans The number of transmissions.
106 */
107 void SetMaxNumberOfTransmissions(uint8_t nbTrans);
108
109 /**
110 * Get the max number of unacknowledged redundant transmissions of each packet. If,
111 * after a transmission, any acknowledgement is received, no more are sent for that packet.
112 *
113 * @return The number of transmissions as uint8_t.
114 */
116
117 /**
118 * Set the data rate this end device will use when transmitting. For End
119 * Devices, this value is assumed to be fixed, and can be modified via MAC
120 * commands issued by the gateway.
121 *
122 * @param dataRate The dataRate to use when transmitting.
123 */
124 void SetDataRate(uint8_t dataRate);
125
126 /**
127 * Get the data rate this end device is set to use.
128 *
129 * @return The data rate this device uses when transmitting.
130 */
131 uint8_t GetDataRate();
132
133 /**
134 * Get the transmission power this end device is set to use.
135 *
136 * @return The transmission ERP [dBm] this device uses when transmitting.
137 */
139
140 /**
141 * Set the transmission power of this end device.
142 *
143 * @param txPowerDbm The transmission ERP [dBm] value.
144 */
145 void SetTransmissionPowerDbm(double txPowerDbm);
146
147 /**
148 * Set the network address of this device.
149 *
150 * @param address The address to set.
151 */
153
154 /**
155 * Get the network address of this device.
156 *
157 * @return This device's address.
158 */
160
161 /**
162 * Get the last known link margin from the demodulation floor.
163 *
164 * This is intended for asynchronous polling by the Application layer of the device. For
165 * synchronous behavior provide a callback using the trace system.
166 *
167 * @return The last known link margin [dB]
168 */
169 uint8_t GetLastKnownLinkMarginDb() const;
170
171 /**
172 * Get the last known number of gateways concurrently receiving transmissions from the device.
173 *
174 * This is intended for asynchronous polling by the Application layer of the device. For
175 * synchronous behavior provide a callback using the trace system.
176 *
177 * @return The last known number of receiver gateways.
178 */
179 uint8_t GetLastKnownGatewayCount() const;
180
181 /**
182 * Get the aggregated duty cycle.
183 *
184 * @return A time instance containing the aggregated duty cycle in fractional form.
185 */
186 double GetAggregatedDutyCycle();
187
188 /**
189 * Set the frame type to send when the Send method is called.
190 *
191 * @param fType The frame type.
192 */
194
195 /**
196 * Get the frame type to send when the Send method is called.
197 *
198 * @return The frame type.
199 */
201
202 /**
203 * Get the current value of the LoRaWAN uplink frame counter (FCnt) of this device
204 *
205 * @return This device's current uplink frame counter (FCnt)
206 */
207 uint16_t GetUplinkFrameCounter() const;
208
209 protected:
210 /**
211 * Current packet transmission context tracking transmissions attempts mandated by the protocol
212 */
214 {
215 Ptr<Packet> packet = nullptr; //!< A pointer to the packet being transmitted
216 Time firstAttempt = Time(); //!< Timestamp of the first transmission of the packet
217 bool needsAck = false; //!< Whether the packet requires explicit acknowledgment
218 int8_t nbTxLeft = 0; //!< Number of transmission attempts left for this packet
219 };
220
221 /**
222 * Postpone transmission to the specified time.
223 *
224 * @param nextTxDelay Delay at which the transmission will be performed.
225 * @param packet The packet to delay the transmission of.
226 */
227 void PostponeTransmission(Time nextTxDelay, Ptr<Packet> packet);
228
229 /**
230 * Find a suitable channel for transmission. The channel is chosen randomly among the
231 * ones that are available in the end device, based on their duty cycle limitations.
232 *
233 * @return A pointer to the channel.
234 */
236
237 /**
238 * Take action on the commands contained on this FrameHeader.
239 *
240 * @param frameHeader The frame header.
241 */
242 void ApplyMACCommands(LoraFrameHeader frameHeader);
243
244 /**
245 * TracedCallback signature for the (re)transmission and acknowledgement process outcome of
246 * confirmed uplink packets.
247 *
248 * @param [in] txCount Number of transmissions attempted during the process.
249 * @param [in] ack Whether the transmission process led to network acknowledgement.
250 * @param [in] firstAttempt Timestamp of the initial transmission attempt.
251 * @param [in] packet The packet being transmitted.
252 */
253 typedef void (*ConfirmedTxOutcomeCallback)(uint8_t txCount,
254 bool ack,
255 Time firstAttempt,
256 Ptr<Packet> packet);
257
258 /// Traced Callback: confirmed transmission process outcome event.
260
261 PacketTxContext m_txContext; //!< Structure containing the transmission context for the last
262 //!< packet sent by this device, used to track retransmissions.
263 /**
264 * @brief The event of transmitting a packet at a later moment.
265 *
266 * A packet transmission is scheduled for the future in the following cases:
267 * - Duty cycle restrictions apply (either legal or imposed by the network)
268 * - The application layer wants to send but the device is currently busy
269 * - A packet needs to be retransmitted later by the LoRaWAN MAC protocol
270 *
271 * This Event is used to cancel postponed transmissions in case the application layer wants to
272 * send a new packet, overwriting the one currently scheduled. Notice that this can be used to
273 * interrupt an ongoing retransmission process. It somewhat acts as a size-1 queue of packets
274 * to be sent.
275 */
277
279 m_uniformRV; //!< An uniform random variable, used to randomly pick from the channel list
280 //!< and to sample random retransmission scheduling backoff.
281
282 LoraDeviceAddress m_address; //!< The LoRaWAN address of this device.
283 std::list<Ptr<MacCommand>> m_macCommandList; //!< List of the MAC commands that need to be
284 //!< applied to the next UL packet.
285
286 uint16_t m_fCnt; //!< Current value of the uplink frame counter
287 uint16_t m_adrAckCnt; //!< ADRACKCnt counter of the number of consecutive uplinks without
288 //!< downlink reply from the server. Reset upon reception of any Class A
289 //!< downlink destined to the device.
290
291 TracedValue<uint8_t> m_dataRate; //!< The data rate this device is using to transmit.
293 m_txPowerDbm; //!< The transmission ERP [dBm] this device is currently using.
294 uint8_t m_nbTrans; //!< Default number of repeated transmissions of each packet.
295
296 CodingRate m_codingRate; //!< The coding rate used by this device.
297 bool m_headerDisabled; //!< Whether or not the LoRa PHY header is disabled for communications by
298 //!< this device.
299
300 /**
301 * @brief The duration of reception windows in number of symbols. This is converted to time by
302 * the PHY layer based or the reception parameters used.
303 *
304 * The downlink preamble transmitted by the gateways contains 8 symbols. The receiver requires 5
305 * symbols to detect the preamble and synchronize. Therefore there must be a 5 symbols overlap
306 * between the receive window and the transmitted preamble. (Ref: Recommended SX1272/76 Settings
307 * for EU868 LoRaWAN Network Operation )
308 */
310
311 double m_lastRxSnr; //!< Record latest reception SNR measurement to provide via DevStatusAns
312
313 private:
314 /**
315 * Apply ADR backoff as in LoRaWAN specification, V1.0.4 (2020) on the provided input
316 * parameters passed by reference. This is useful for testing whether a packet could be sent
317 * without changing the device state or interrupting any ongoing retransmission process.
318 *
319 * @param [in,out] txPowerDbm Output transmission power [dBm]
320 * @param [in,out] dataRate LoRaWAN MAC data rate
321 * @param [in,out] nbTrans Number of redundant packet transmissions
322 * @param [in,out] txChannelArray Array of channels for uplink transmission
323 */
324 static void DoExecuteADRBackoff(double& txPowerDbm,
325 uint8_t& dataRate,
326 uint8_t& nbTrans,
327 const std::vector<Ptr<LogicalLoraChannel>>& txChannelArray);
328
329 /**
330 * Check whether the size of the application payload is under the maximum allowed.
331 *
332 * From LoRaWAN L2 1.0.4 Specification (TS001-1.0.4), Section 4.3.2: "N is the number of octets
333 * of the application payload and SHALL be equal to or less than N ≤ M − 1 − (length of FHDR in
334 * octets), where M is the maximum MACPayload length. The valid ranges of both N and M are
335 * region-specific and defined in the "LoRaWAN Regional Parameters" [RP002] document."
336 *
337 * @param appPayloadSize Number of bytes of the application payload.
338 * @param dataRate Data rate to evaluate the max MACPayload for.
339 * @return Whether the payload size is valid.
340 */
341 bool IsPayloadSizeValid(uint32_t appPayloadSize, uint8_t dataRate) const;
342
343 /**
344 * Get the set of active transmission channels among the provided array which are compatible
345 * with the a certain data rate and transmission power.
346 *
347 * @param txChannelArray Set of transmission channels to evaluate
348 * @param dataRate Data rate that the channels need to be compatible with
349 * @param txPowerDbm Transmission power [dBm] that the channels need to be compatible with
350 * @return A (possibly empty) vector of compatible transmission channels.
351 */
352 std::vector<Ptr<LogicalLoraChannel>> GetCompatibleTxChannels(
353 const std::vector<Ptr<LogicalLoraChannel>>& txChannelArray,
354 uint8_t dataRate,
355 double txPowerDbm) const;
356
357 /**
358 * Find the base minimum wait time before the next possible transmission based on channels legal
359 * duty cycle, server-imposed aggregated duty-cycle, and device class operation.
360 *
361 * @warning This function does not check whether the input channels are compatible with other
362 * device transmission parameters (data rate, output power), filtering is left to the caller
363 *
364 * @param [in] txChannelArray Array of channels to use for duty cycle evaluation
365 *
366 * @return The base minimum wait time.
367 */
368 Time GetNextTransmissionDelay(const std::vector<Ptr<LogicalLoraChannel>>& txChannelArray) const;
369
370 /**
371 * Find the minimum wait time before the next possible transmission based
372 * on end device's Class Type scheduled operations.
373 *
374 * @return The wait Time before the next MAC send.
375 */
377
378 /**
379 * Perform operations to update the MAC layer with the new packet context and call SendToPhy
380 * function. This function does not fail, only call it after doing the appropriate checks.
381 *
382 * @param packet The packet to send.
383 */
384 virtual void DoSend(Ptr<Packet> packet);
385
386 /**
387 * Execute ADR backoff as in LoRaWAN specification, V1.0.4 (2020) on this device
388 */
389 void ExecuteADRBackoff();
390
391 /**
392 * Add the necessary options and MAC commands to the LoraFrameHeader.
393 *
394 * @param frameHeader The frame header on which to apply the options.
395 */
396 void ApplyNecessaryOptions(LoraFrameHeader& frameHeader);
397
398 /**
399 * Add the necessary options and MAC commands to the LorawanMacHeader.
400 *
401 * @param macHeader The mac header on which to apply the options.
402 */
404
405 /**
406 * Gather PHY transmission parameters and send a packet through the LoRa physical layer.
407 *
408 * @param packet The packet to send.
409 */
410 virtual void SendToPhy(Ptr<Packet> packet) = 0;
411
412 void TxFinished(Ptr<const Packet> packet) override = 0;
413 void Receive(Ptr<const Packet> packet) override = 0;
414 void FailedReception(Ptr<const Packet> packet) override = 0;
415
416 /**
417 * Perform the actions that need to be taken when receiving a LinkCheckAns command.
418 *
419 * @param margin The margin value of the command.
420 * @param gwCnt The gateway count value of the command.
421 */
422 void OnLinkCheckAns(uint8_t margin, uint8_t gwCnt);
423
424 /**
425 * Perform the actions that need to be taken when receiving a LinkAdrReq command.
426 *
427 * @param dataRate The data rate value of the command.
428 * @param txPower The transmission power value of the command.
429 * @param chMask Mask of enabled channels of the command.
430 * @param chMaskCntl Indicator of the 16 channel bank to apply the chMask to.
431 * @param nbTrans The number of repetitions prescribed by the command.
432 */
433 void OnLinkAdrReq(uint8_t dataRate,
434 uint8_t txPower,
435 uint16_t chMask,
436 uint8_t chMaskCntl,
437 uint8_t nbTrans);
438
439 /**
440 * Perform the actions that need to be taken when receiving a DutyCycleReq command.
441 *
442 * @param maxDutyCycle The aggregate duty cycle encoded by the command.
443 */
444 void OnDutyCycleReq(uint8_t maxDutyCycle);
445
446 /**
447 * Perform the actions that need to be taken when receiving a RxParamSetupReq
448 * command based on the Device's Class Type.
449 *
450 * @param rx1DrOffset The first reception window data rate offset to set.
451 * @param rx2DataRate The data rate to use for the second receive window.
452 * @param frequencyHz The frequency [Hz] to use for the second receive window.
453 */
454 virtual void OnRxParamSetupReq(uint8_t rx1DrOffset,
455 uint8_t rx2DataRate,
456 double frequencyHz) = 0;
457
458 /**
459 * Perform the actions that need to be taken when receiving a DevStatusReq command.
460 */
461 void OnDevStatusReq();
462
463 /**
464 * Perform the actions that need to be taken when receiving a NewChannelReq command.
465 *
466 * @param chIndex The ChIndex field of the received NewChannelReq command.
467 * @param frequencyHz The Frequency [Hz] field of the received NewChannelReq command.
468 * @param minDataRate The MinDR field of the received NewChannelReq command.
469 * @param maxDataRate The MaxDR field of the received NewChannelReq command.
470 */
471 void OnNewChannelReq(uint8_t chIndex,
472 uint32_t frequencyHz,
473 uint8_t minDataRate,
474 uint8_t maxDataRate);
475
477 m_fType; //!< The frame type to apply to packets sent with the Send method.
478
479 bool m_adr; //!< Uplink ADR bit contained in the FCtrl field of the LoRaWAN FHDR.
480 //!< Controlled by the device, if set to false signals the network server
481 //!< that the device may not accept attempts to control the number of
482 //!< retransmissions, the data rate, or the TX power with downlink
483 //!< LinkADRReq commands. This also allows the device's local ADR backoff
484 //!< procedure to reset configurations in case of connectivity loss.
485
486 TracedValue<double> m_aggregatedDutyCycle; //!< The aggregated duty cycle this device needs to
487 //!< respect across all sub-bands.
488
489 TracedValue<uint8_t> m_lastKnownLinkMarginDb; //!< Last known best link margin [dB] from the
490 //!< demodulation floor, obtained via LinkCheckReq
491 TracedValue<uint8_t> m_lastKnownGatewayCount; //!< Last known number of gateways in range of
492 //!< this end device, obtained via LinkCheckReq
493
494 bool m_adrAckReq; //!< ADRACKReq bit, set to 1 after ADR_ACK_LIMIT consecutive uplinks without
495 //!< downlink messages received from the server. It requests the server to
496 //!< send a downlink for keepalive purposes.
497};
498
499} // namespace lorawan
500} // namespace ns3
501
502#endif /* END_DEVICE_LORAWAN_MAC_H */
An identifier for simulation events.
Definition event-id.h:45
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
Forward calls to a chain of Callback.
Trace classes with value semantics.
a unique identifier for an interface.
Definition type-id.h:50
virtual void SendToPhy(Ptr< Packet > packet)=0
Gather PHY transmission parameters and send a packet through the LoRa physical layer.
bool IsPayloadSizeValid(uint32_t appPayloadSize, uint8_t dataRate) const
Check whether the size of the application payload is under the maximum allowed.
Time GetNextTransmissionDelay(const std::vector< Ptr< LogicalLoraChannel > > &txChannelArray) const
Find the base minimum wait time before the next possible transmission based on channels legal duty cy...
Ptr< LogicalLoraChannel > GetRandomChannelForTx()
Find a suitable channel for transmission.
bool m_headerDisabled
Whether or not the LoRa PHY header is disabled for communications by this device.
void OnLinkAdrReq(uint8_t dataRate, uint8_t txPower, uint16_t chMask, uint8_t chMaskCntl, uint8_t nbTrans)
Perform the actions that need to be taken when receiving a LinkAdrReq command.
void OnDutyCycleReq(uint8_t maxDutyCycle)
Perform the actions that need to be taken when receiving a DutyCycleReq command.
TracedValue< double > m_txPowerDbm
The transmission ERP [dBm] this device is currently using.
void PostponeTransmission(Time nextTxDelay, Ptr< Packet > packet)
Postpone transmission to the specified time.
void TxFinished(Ptr< const Packet > packet) override=0
Perform actions after sending a packet.
void Receive(Ptr< const Packet > packet) override=0
Receive a packet from the lower layer.
double GetTransmissionPowerDbm()
Get the transmission power this end device is set to use.
uint16_t GetUplinkFrameCounter() const
Get the current value of the LoRaWAN uplink frame counter (FCnt) of this device.
bool m_adr
Uplink ADR bit contained in the FCtrl field of the LoRaWAN FHDR.
void SetUplinkAdrBit(bool adr)
Signals to the network server that this device will or may not comply with LinkADRReq settings (data ...
TracedCallback< uint8_t, bool, Time, Ptr< Packet > > m_confirmedTxOutcomeCallback
Traced Callback: confirmed transmission process outcome event.
bool m_adrAckReq
ADRACKReq bit, set to 1 after ADR_ACK_LIMIT consecutive uplinks without downlink messages received fr...
Ptr< UniformRandomVariable > m_uniformRV
An uniform random variable, used to randomly pick from the channel list and to sample random retransm...
static constexpr uint16_t ADR_ACK_DELAY
ADRACKCnt threshold for ADR backoff action.
static TypeId GetTypeId()
Register this type.
void FailedReception(Ptr< const Packet > packet) override=0
Inform this layer that reception of a packet we were locked on failed.
uint8_t GetLastKnownLinkMarginDb() const
Get the last known link margin from the demodulation floor.
TracedValue< double > m_aggregatedDutyCycle
The aggregated duty cycle this device needs to respect across all sub-bands.
LorawanMacHeader::FType GetFType()
Get the frame type to send when the Send method is called.
double GetAggregatedDutyCycle()
Get the aggregated duty cycle.
uint16_t m_adrAckCnt
ADRACKCnt counter of the number of consecutive uplinks without downlink reply from the server.
void ApplyMACCommands(LoraFrameHeader frameHeader)
Take action on the commands contained on this FrameHeader.
static void DoExecuteADRBackoff(double &txPowerDbm, uint8_t &dataRate, uint8_t &nbTrans, const std::vector< Ptr< LogicalLoraChannel > > &txChannelArray)
Apply ADR backoff as in LoRaWAN specification, V1.0.4 (2020) on the provided input parameters passed ...
virtual Time GetNextClassTransmissionDelay() const =0
Find the minimum wait time before the next possible transmission based on end device's Class Type sch...
void SetFType(LorawanMacHeader::FType fType)
Set the frame type to send when the Send method is called.
virtual void OnRxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, double frequencyHz)=0
Perform the actions that need to be taken when receiving a RxParamSetupReq command based on the Devic...
std::vector< Ptr< LogicalLoraChannel > > GetCompatibleTxChannels(const std::vector< Ptr< LogicalLoraChannel > > &txChannelArray, uint8_t dataRate, double txPowerDbm) const
Get the set of active transmission channels among the provided array which are compatible with the a ...
CodingRate m_codingRate
The coding rate used by this device.
void OnNewChannelReq(uint8_t chIndex, uint32_t frequencyHz, uint8_t minDataRate, uint8_t maxDataRate)
Perform the actions that need to be taken when receiving a NewChannelReq command.
void ApplyNecessaryOptions(LoraFrameHeader &frameHeader)
Add the necessary options and MAC commands to the LoraFrameHeader.
uint8_t GetMaxNumberOfTransmissions()
Get the max number of unacknowledged redundant transmissions of each packet.
void OnLinkCheckAns(uint8_t margin, uint8_t gwCnt)
Perform the actions that need to be taken when receiving a LinkCheckAns command.
EventId m_nextTx
The event of transmitting a packet at a later moment.
void SetMaxNumberOfTransmissions(uint8_t nbTrans)
Set the max number of unacknowledged redundant transmissions of each packet.
std::list< Ptr< MacCommand > > m_macCommandList
List of the MAC commands that need to be applied to the next UL packet.
TracedValue< uint8_t > m_dataRate
The data rate this device is using to transmit.
LoraDeviceAddress m_address
The LoRaWAN address of this device.
bool GetUplinkAdrBit() const
Get the current value of the device's uplink ADR bit of the LoRaWAN FHDR.
PacketTxContext m_txContext
Structure containing the transmission context for the last packet sent by this device,...
void Send(Ptr< Packet > packet) override
Send a packet.
void(* ConfirmedTxOutcomeCallback)(uint8_t txCount, bool ack, Time firstAttempt, Ptr< Packet > packet)
TracedCallback signature for the (re)transmission and acknowledgement process outcome of confirmed up...
uint8_t GetLastKnownGatewayCount() const
Get the last known number of gateways concurrently receiving transmissions from the device.
void AddMacCommand(Ptr< MacCommand > macCommand)
Add a MAC command to the list of those that will be sent out in the next packet.
static constexpr uint16_t ADR_ACK_LIMIT
ADRACKCnt threshold for setting ADRACKReq.
virtual void DoSend(Ptr< Packet > packet)
Perform operations to update the MAC layer with the new packet context and call SendToPhy function.
void OnDevStatusReq()
Perform the actions that need to be taken when receiving a DevStatusReq command.
LoraDeviceAddress GetDeviceAddress()
Get the network address of this device.
double m_lastRxSnr
Record latest reception SNR measurement to provide via DevStatusAns.
TracedValue< uint8_t > m_lastKnownGatewayCount
Last known number of gateways in range of this end device, obtained via LinkCheckReq.
uint8_t m_nbTrans
Default number of repeated transmissions of each packet.
void SetDataRate(uint8_t dataRate)
Set the data rate this end device will use when transmitting.
uint8_t m_receiveWindowDurationInSymbols
The duration of reception windows in number of symbols.
TracedValue< uint8_t > m_lastKnownLinkMarginDb
Last known best link margin [dB] from the demodulation floor, obtained via LinkCheckReq.
LorawanMacHeader::FType m_fType
The frame type to apply to packets sent with the Send method.
void SetTransmissionPowerDbm(double txPowerDbm)
Set the transmission power of this end device.
uint8_t GetDataRate()
Get the data rate this end device is set to use.
bool ValidatePacketForSend(Ptr< const Packet > packet, Time &nextTxDelay) const
Evaluate whether this packet can be sent in the current device state.
void ExecuteADRBackoff()
Execute ADR backoff as in LoRaWAN specification, V1.0.4 (2020) on this device.
void SetDeviceAddress(LoraDeviceAddress address)
Set the network address of this device.
uint16_t m_fCnt
Current value of the uplink frame counter.
This class represents the device address of a LoraWAN end device.
This class represents the Frame header (FHDR) used in a LoraWAN network.
This class represents the Mac header of a LoRaWAN packet.
LorawanMac()
Default constructor.
CodingRate
Enumeration of the LoRa supported coding rates.
Definition lora-phy.h:49
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Current packet transmission context tracking transmissions attempts mandated by the protocol.
Ptr< Packet > packet
A pointer to the packet being transmitted.
Time firstAttempt
Timestamp of the first transmission of the packet.
int8_t nbTxLeft
Number of transmission attempts left for this packet.
bool needsAck
Whether the packet requires explicit acknowledgment.