33 static TypeId tid =
TypeId(
"ns3::ClassAEndDeviceLorawanMac")
35 .SetGroupName(
"lorawan")
91 params.crcEnabled =
true;
123 <<
", replyDataRate: " <<
unsigned(replyDataRate) <<
".");
141 packetCopy->RemoveHeader(mHdr);
153 packetCopy->RemoveHeader(fHdr);
169 packet->PeekPacketTag(tag);
183 NS_LOG_DEBUG(
"The message is intended for another recipient.");
199 NS_LOG_DEBUG(
"Failure: no more retransmissions left. Used "
200 <<
unsigned(txs) <<
" transmissions.");
209 <<
" retransmissions left: rescheduling transmission.");
216 NS_LOG_INFO(
"The packet we are receiving is in uplink.");
221 <<
" retransmissions left: rescheduling transmission.");
227 NS_LOG_DEBUG(
"Failure: no more retransmissions left. Used " <<
unsigned(txs)
228 <<
" transmissions.");
252 <<
" retransmissions left: rescheduling transmission.");
258 NS_LOG_DEBUG(
"Failure: no more retransmissions left. Used " <<
unsigned(txs)
259 <<
" transmissions.");
324 switch (phy->GetState())
327 NS_ABORT_MSG(
"PHY was in TX mode when attempting to close a receive window.");
336 phy->SwitchToSleep();
350 NS_LOG_INFO(
"Won't open second receive window since we are in RX mode.");
391 switch (phy->GetState())
398 NS_LOG_DEBUG(
"PHY is receiving: Receive will handle the result.");
402 phy->SwitchToSleep();
408 NS_LOG_DEBUG(
"No reception initiated by PHY: rescheduling transmission.");
412 <<
" retransmissions left: rescheduling transmission.");
421 NS_LOG_DEBUG(
"Failure: no more retransmissions left. Used " <<
unsigned(txs)
422 <<
" transmissions.");
430 NS_ABORT_MSG(
"The number of retransmissions left is negative ! ");
439 <<
" transmissions left. We were not transmitting confirmed messages.");
463 "Attempting to send when there are receive windows: Transmission postponed.");
471 NS_LOG_DEBUG(
"Duration until endSecondRxWindow for new transmission:"
473 waitTime =
Max(waitTime, endSecondRxWindow -
Now());
483 Time retransmitWaitTime =
487 <<
" retransmitWaitTime:" << retransmitWaitTime.
As(
Time::S));
488 waitTime =
Max(waitTime, retransmitWaitTime);
539 bool rx1DrOffsetAck =
true;
540 bool rx2DataRateAck =
true;
541 bool channelAck =
true;
546 rx1DrOffsetAck =
false;
552 rx2DataRateAck =
false;
561 if (rx1DrOffsetAck && rx2DataRateAck && channelAck)
An identifier for simulation events.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
bool IsExpired() const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Class representing the MAC layer of a Class A LoRaWAN device.
uint8_t m_rx1DrOffset
The RX1DROffset parameter value.
void OpenSecondReceiveWindow()
Perform operations needed to open the second receive window.
uint8_t GetSecondReceiveWindowDataRate() const
Get the data rate that will be used in the second receive window.
Time m_receiveDelay2
The interval between when a packet is done sending and when the second receive window is opened.
ClassAEndDeviceLorawanMac()
Default constructor.
static TypeId GetTypeId()
Register this type.
void FailedReception(Ptr< const Packet > packet) override
Function called by lower layers to inform this layer that reception of a packet we were locked on fai...
uint32_t GetSecondReceiveWindowFrequency() const
Get the frequency that is used for the second receive window.
EventId m_closeFirstWindow
The event of the closing the first receive window.
void SetSecondReceiveWindowFrequency(uint32_t frequencyHz)
Set the frequency that will be used for the second receive window.
uint8_t m_secondReceiveWindowDataRate
The data rate to listen for during the second downlink transmission.
Time m_receiveDelay1
The interval between when a packet is done sending and when the first receive window is opened.
Time GetNextClassTransmissionDelay(Time waitTime) override
Find the minimum wait time before the next possible transmission based on end device's Class Type.
void CloseFirstReceiveWindow()
Perform operations needed to close the first receive window.
void SendToPhy(Ptr< Packet > packet) override
Add headers and send a packet with the sending function of the physical layer.
uint32_t m_secondReceiveWindowFrequencyHz
The frequency [Hz] to listen on for the second receive window.
void TxFinished(Ptr< const Packet > packet) override
Perform the actions that are required after a packet send.
void CloseSecondReceiveWindow()
Perform operations needed to close the second receive window.
void OnRxParamSetupReq(uint8_t rx1DrOffset, uint8_t rx2DataRate, double frequencyHz) override
Perform the actions that need to be taken when receiving a RxParamSetupReq command based on the Devic...
uint8_t GetFirstReceiveWindowDataRate()
Get the data rate that will be used in the first receive window.
EventId m_closeSecondWindow
The event of the closing the second receive window.
EventId m_secondReceiveWindow
The event of the second receive window opening.
void SetSecondReceiveWindowDataRate(uint8_t dataRate)
Set the data rate to be used in the second receive window.
void Receive(Ptr< const Packet > packet) override
Receive a packet.
~ClassAEndDeviceLorawanMac() override
Destructor.
void OpenFirstReceiveWindow()
Perform operations needed to open the first receive window.
@ RX
The PHY layer is receiving a packet.
@ TX
The PHY layer is sending a packet.
@ SLEEP
The PHY layer is sleeping.
@ STANDBY
The PHY layer is in STANDBY.
Class representing the MAC layer of a LoRaWAN device.
bool m_headerDisabled
Whether or not the LoRa PHY header is disabled for communications by this device.
TracedValue< double > m_txPowerDbm
The transmission ERP [dBm] this device is currently using.
Ptr< LogicalLoraChannel > GetChannelForTx()
Find a suitable channel for transmission.
uint8_t m_codingRate
The coding rate used by this device.
bool m_enableDRAdapt
Enable data rate adaptation (ADR) during the retransmission procedure.
Ptr< UniformRandomVariable > m_uniformRV
An uniform random variable, used to randomly pick from the channel list.
virtual void resetRetransmissionParameters()
Reset retransmission parameters contained in the structure LoraRetxParams.
void ParseCommands(LoraFrameHeader frameHeader)
Parse and take action on the commands contained on this FrameHeader.
TracedCallback< uint8_t, bool, Time, Ptr< Packet > > m_requiredTxCallback
The trace source fired when the transmission procedure is finished.
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 address of this device.
void Send(Ptr< Packet > packet) override
Send a packet.
double m_lastRxSnr
Used to record the last reception SNR measurement to be included in the DevStatusAns.
uint8_t m_nbTrans
Default number of unacknowledged redundant transmissions of each packet.
uint8_t m_receiveWindowDurationInSymbols
The duration of a receive window in number of symbols.
struct LoraRetxParameters m_retxParams
Structure containing the retransmission parameters for this device.
static Time GetOnAirTime(Ptr< Packet > packet, LoraTxParameters txParams)
Compute the time that a packet with certain characteristics will take to be transmitted.
static Time GetTSym(LoraTxParameters txParams)
Compute the symbol time from spreading factor and bandwidth.
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
double GetReceivePower() const
Read the power this packet arrived with.
TracedCallback< Ptr< const Packet > > m_receivedPacket
Trace source that is fired when a packet reaches the MAC layer.
uint8_t GetSfFromDataRate(uint8_t dataRate)
Get the spreading factor corresponding to a data rate, based on this MAC's region.
double GetBandwidthFromDataRate(uint8_t dataRate)
Get the bandwidth corresponding to a data rate, based on this MAC's region.
ReplyDataRateMatrix m_replyDataRateMatrix
The matrix that decides the data rate the gateway will use in a reply based on the end device's sendi...
Ptr< LogicalLoraChannelHelper > m_channelHelper
The LogicalLoraChannelHelper instance that is assigned to this MAC.
Ptr< LoraPhy > m_phy
The PHY instance that sits under this MAC layer.
int m_nPreambleSymbols
The number of symbols to use in the PHY preamble.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
bool waitingAck
Whether the packet requires explicit acknowledgment.
uint8_t retxLeft
Number of retransmission attempts left.
Time firstAttempt
Timestamp of the first transmission of the packet.
Ptr< Packet > packet
A pointer to the packet being retransmitted.
Structure to collect all parameters that are used to compute the duration of a packet (excluding payl...