34 static TypeId tid =
TypeId(
"ns3::ClassAEndDeviceLorawanMac")
36 .SetGroupName(
"lorawan")
92 params.crcEnabled =
true;
100 m_phy->Send(packetToSend, params, txChannel->GetFrequency(),
m_txPower);
124 <<
", replyDataRate: " <<
unsigned(replyDataRate) <<
".");
142 packetCopy->RemoveHeader(mHdr);
154 packetCopy->RemoveHeader(fHdr);
179 NS_LOG_DEBUG(
"The message is intended for another recipient.");
195 NS_LOG_DEBUG(
"Failure: no more retransmissions left. Used "
196 <<
unsigned(txs) <<
" transmissions.");
205 <<
" retransmissions left: rescheduling transmission.");
212 NS_LOG_INFO(
"The packet we are receiving is in uplink.");
217 <<
" retransmissions left: rescheduling transmission.");
223 NS_LOG_DEBUG(
"Failure: no more retransmissions left. Used " <<
unsigned(txs)
224 <<
" transmissions.");
248 <<
" retransmissions left: rescheduling transmission.");
254 NS_LOG_DEBUG(
"Failure: no more retransmissions left. Used " <<
unsigned(txs)
255 <<
" transmissions.");
320 switch (phy->GetState())
323 NS_ABORT_MSG(
"PHY was in TX mode when attempting to close a receive window.");
332 phy->SwitchToSleep();
346 NS_LOG_INFO(
"Won't open second receive window since we are in RX mode.");
387 switch (phy->GetState())
394 NS_LOG_DEBUG(
"PHY is receiving: Receive will handle the result.");
398 phy->SwitchToSleep();
404 NS_LOG_DEBUG(
"No reception initiated by PHY: rescheduling transmission.");
408 <<
" retransmissions left: rescheduling transmission.");
417 NS_LOG_DEBUG(
"Failure: no more retransmissions left. Used " <<
unsigned(txs)
418 <<
" transmissions.");
426 NS_ABORT_MSG(
"The number of retransmissions left is negative ! ");
435 <<
" transmissions left. We were not transmitting confirmed messages.");
459 "Attempting to send when there are receive windows: Transmission postponed.");
467 NS_LOG_DEBUG(
"Duration until endSecondRxWindow for new transmission:"
469 waitingTime = std::max(waitingTime, endSecondRxWindow -
Simulator::Now());
479 Time retransmitWaitingTime =
482 NS_LOG_DEBUG(
"ack_timeout:" << ack_timeout <<
" retransmitWaitingTime:"
484 waitingTime = std::max(waitingTime, retransmitWaitingTime);
529 bool offsetOk =
true;
530 bool dataRateOk =
true;
532 uint8_t rx1DrOffset = rxParamSetupReq->GetRx1DrOffset();
533 uint8_t rx2DataRate = rxParamSetupReq->GetRx2DataRate();
534 double frequency = rxParamSetupReq->GetFrequency();
536 NS_LOG_FUNCTION(
this <<
unsigned(rx1DrOffset) <<
unsigned(rx2DataRate) << frequency);
539 if (!(0 <= rx1DrOffset && rx1DrOffset <= 5))
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...
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated 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...
double GetSecondReceiveWindowFrequency() const
Get the frequency that is used for the second receive window.
double m_secondReceiveWindowFrequency
The frequency to listen on for the second receive window.
EventId m_closeFirstWindow
The event of the closing the first 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 waitingTime) override
Find the minimum waiting time before the next possible transmission based on end device's Class Type.
void OnRxClassParamSetupReq(Ptr< RxParamSetupReq > rxParamSetupReq) override
Perform the actions that need to be taken when receiving a RxParamSetupReq command based on the Devic...
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.
void TxFinished(Ptr< const Packet > packet) override
Perform actions after sending a packet.
void CloseSecondReceiveWindow()
Perform operations needed to close the second receive window.
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.
void SetSecondReceiveWindowFrequency(double frequencyMHz)
Set the frequency that will be used for the second receive window.
~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.
uint8_t m_maxNumbTx
Default number of unacknowledged redundant transmissions of each packet.
bool m_headerDisabled
Whether or not the LoRa PHY header is disabled for communications by this device.
Ptr< LogicalLoraChannel > GetChannelForTx()
Find a suitable channel for transmission.
TracedValue< double > m_txPower
The transmission power this device is using to transmit.
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 by the Shuffle method to randomly reorder 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.
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.
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.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
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...