33 static TypeId tid =
TypeId(
"ns3::ClassAEndDeviceLorawanMac")
35 .SetGroupName(
"lorawan")
83 params.crcEnabled =
true;
115 <<
", replyDataRate: " <<
unsigned(replyDataRate) <<
".");
133 packetCopy->RemoveHeader(mHdr);
145 packetCopy->RemoveHeader(fHdr);
164 packet->PeekPacketTag(tag);
178 NS_LOG_DEBUG(
"The message is intended for another recipient.");
196 NS_LOG_DEBUG(
"Failure: no more retransmissions left. Used "
197 <<
unsigned(txs) <<
" transmissions.");
206 <<
" retransmissions left: rescheduling transmission.");
213 NS_LOG_INFO(
"The packet we are receiving is in uplink.");
218 <<
" retransmissions left: rescheduling transmission.");
224 NS_LOG_DEBUG(
"Failure: no more retransmissions left. Used " <<
unsigned(txs)
225 <<
" transmissions.");
249 <<
" retransmissions left: rescheduling transmission.");
255 NS_LOG_DEBUG(
"Failure: no more retransmissions left. Used " <<
unsigned(txs)
256 <<
" transmissions.");
321 switch (phy->GetState())
324 NS_ABORT_MSG(
"PHY was in TX mode when attempting to close a receive window.");
333 phy->SwitchToSleep();
347 NS_LOG_INFO(
"Won't open second receive window since we are in RX mode.");
388 switch (phy->GetState())
395 NS_LOG_DEBUG(
"PHY is receiving: Receive will handle the result.");
399 phy->SwitchToSleep();
405 NS_LOG_DEBUG(
"No reception initiated by PHY: rescheduling transmission.");
409 <<
" retransmissions left: rescheduling transmission.");
418 NS_LOG_DEBUG(
"Failure: no more retransmissions left. Used " <<
unsigned(txs)
419 <<
" transmissions.");
427 NS_ABORT_MSG(
"The number of retransmissions left is negative ! ");
436 <<
" transmissions left. We were not transmitting confirmed messages.");
460 "Attempting to send when there are receive windows: Transmission postponed.");
468 NS_LOG_DEBUG(
"Duration until endSecondRxWindow for new transmission:"
470 waitTime =
Max(waitTime, endSecondRxWindow -
Now());
480 Time retransmitWaitTime =
484 <<
" retransmitWaitTime:" << retransmitWaitTime.
As(
Time::S));
485 waitTime =
Max(waitTime, retransmitWaitTime);
536 bool rx1DrOffsetAck =
true;
537 bool rx2DataRateAck =
true;
538 bool channelAck =
true;
543 rx1DrOffsetAck =
false;
549 rx2DataRateAck =
false;
558 if (rx1DrOffsetAck && rx2DataRateAck && channelAck)
An identifier for simulation events.
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.
@ TX
The PHY layer is sending a packet.
@ SLEEP
The PHY layer is sleeping.
@ STANDBY
The PHY layer is in STANDBY.
@ RX
The PHY layer is receiving a packet.
Ptr< LogicalLoraChannel > GetRandomChannelForTx()
Find a suitable channel for transmission.
virtual void ResetRetransmissionParameters()
Reset retransmission parameters contained in the structure LoraRetxParams.
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.
uint8_t m_codingRate
The coding rate used by this device.
Ptr< UniformRandomVariable > m_uniformRV
An uniform random variable, used to randomly pick from the channel list.
uint16_t m_adrAckCnt
ADRACKCnt counter of the number of consecutive uplinks without downlink reply from the server.
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.
EndDeviceLorawanMac()
Default constructor.
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.
void Send()
Send a packet.
Structure to collect all parameters that are used to compute the duration of a packet (excluding payl...