12#ifndef END_DEVICE_LORAWAN_MAC_H
13#define END_DEVICE_LORAWAN_MAC_H
19#include "ns3/random-variable-stream.h"
20#include "ns3/traced-value.h"
355 double txPowerDbm)
const;
456 double frequencyHz) = 0;
474 uint8_t maxDataRate);
An identifier for simulation events.
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Forward calls to a chain of Callback.
Trace classes with value semantics.
a unique identifier for an interface.
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.
~EndDeviceLorawanMac() override
Destructor.
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...
EndDeviceLorawanMac()
Default constructor.
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.
LorawanMac()
Default constructor.
CodingRate
Enumeration of the LoRa supported coding rates.
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.