30 NS_LOG_COMPONENT_DEFINE(
"LorawanMac");
32 NS_OBJECT_ENSURE_REGISTERED(LorawanMac);
38 TypeId(
"ns3::LorawanMac")
40 .AddTraceSource(
"SentNewPacket",
41 "Trace source indicating a new packet "
42 "arrived at the MAC layer",
44 "ns3::Packet::TracedCallback")
45 .AddTraceSource(
"ReceivedPacket",
46 "Trace source indicating a packet "
47 "was correctly received at the MAC layer",
49 "ns3::Packet::TracedCallback")
50 .AddTraceSource(
"CannotSendBecauseDutyCycle",
51 "Trace source indicating a packet "
52 "could not be sent immediately because of duty cycle limitations",
54 "ns3::Packet::TracedCallback");
59 : m_isRegenerative(false)
61 NS_FATAL_ERROR(
"Default constructor not in use");
67 m_isRegenerative(false)
69 NS_LOG_FUNCTION(
this);
74 NS_LOG_FUNCTION(
this);
106 DynamicCast<SatLoraPhyTx>(
m_phy->GetPhyTx())
125 NS_LOG_FUNCTION(
this <<
unsigned(dataRate));
139 NS_LOG_FUNCTION(
this <<
unsigned(dataRate));
153 NS_LOG_FUNCTION(
this <<
unsigned(txPower));
166 NS_LOG_FUNCTION(packet);
173 double tSym = pow(2,
int(txParams.
sf)) / (txParams.
bandwidthHz);
176 double tPreamble = (double(txParams.
nPreamble) + 4.25) * tSym;
179 uint32_t pl = packet->GetSize();
180 NS_LOG_DEBUG(
"Packet of size " << pl <<
" bytes");
190 double num = 8 * pl - 4 * txParams.
sf + 28 + 16 * crc - 20 * h;
191 double den = (txParams.
sf - 2 * de) * txParams.
codingRate;
192 double payloadSymbNb = 8 + std::max(std::ceil(num / den), double(0));
195 double tPayload = payloadSymbNb * tSym;
197 NS_LOG_DEBUG(
"Time computation: num = " << num <<
", den = " << den <<
", payloadSymbNb = "
198 << payloadSymbNb <<
", tSym = " << tSym);
199 NS_LOG_DEBUG(
"tPreamble = " << tPreamble);
200 NS_LOG_DEBUG(
"tPayload = " << tPayload);
201 NS_LOG_DEBUG(
"Total time = " << tPreamble + tPayload);
204 return Seconds(tPreamble + tPayload);
246 NS_LOG_FUNCTION(
this << isRegenerative);
This class supports LorawanMac instances by managing a list of the logical channels that the device i...
TracedCallback< Ptr< const Packet > > m_receivedPacket
Trace source that is fired when a packet reaches the MAC layer.
ReplyDataRateMatrix m_replyDataRateMatrix
The matrix that decides the DR the GW will use in a reply based on the ED's sending DR and on the val...
void SetReplyDataRateMatrix(ReplyDataRateMatrix replyDataRateMatrix)
Set the matrix to use when deciding with which DataRate to respond.
std::vector< uint32_t > m_maxAppPayloadForDataRate
A vector holding the maximum app payload size that corresponds to a certain DataRate.
std::vector< double > m_bandwidthForDataRate
A vector holding the bandwidth each Data Rate corresponds to.
int m_nPreambleSymbols
The number of symbols to use in the PHY preamble.
int GetNPreambleSymbols(void)
Get the number of PHY preamble symbols this MAC is set to use.
void SetTxDbmForTxPower(std::vector< double > txDbmForTxPower)
Set the vector to use to check up which transmission power in Dbm corresponds to a certain TxPower va...
Time GetOnAirTime(Ptr< Packet > packet, LoraTxParameters txParams)
Compute the time that a packet with certain characteristics will take to be transmitted.
Ptr< SatPhy > GetPhy(void)
Get the underlying PHY layer.
TracedCallback< Ptr< const Packet > > m_cannotSendBecauseDutyCycle
The trace source that is fired when a packet cannot be sent because of duty cycle limitations.
bool m_isRegenerative
Indicates if satellite is regenerative on the link where this layer is sending packets.
Ptr< SatPhy > m_phy
The PHY instance that sits under this MAC layer.
virtual void Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Send a packet.
void SetBandwidthForDataRate(std::vector< double > bandwidthForDataRate)
Set the vector to use to check up correspondence between bandwidth and DataRate.
static TypeId GetTypeId(void)
TracedCallback< Ptr< const Packet > > m_sentNewPacket
Trace source that is fired when a new APP layer packet arrives at the MAC layer.
void SetSfForDataRate(std::vector< uint8_t > sfForDataRate)
Set the vector to use to check up correspondence between SF and DataRate.
void SetMaxAppPayloadForDataRate(std::vector< uint32_t > maxAppPayloadForDataRate)
Set the maximum App layer payload for a set DataRate.
uint8_t GetSfFromDataRate(uint8_t dataRate)
Get the SF corresponding to a data rate, based on this MAC's region.
Ptr< NetDevice > GetDevice(void)
Get the device this MAC layer is installed on.
Ptr< NetDevice > m_device
The device this MAC layer is installed on.
LoraLogicalChannelHelper GetLoraLogicalChannelHelper(void)
Get the logical lora channel helper associated with this MAC.
std::vector< double > m_txDbmForTxPower
A vector holding the power that corresponds to a certain TxPower value.
double GetDbmForTxPower(uint8_t txPower)
Get the transmission power in dBm that corresponds, in this region, to the encoded 8-bit txPower.
void SetNPreambleSymbols(int nPreambleSymbols)
Set the number of PHY preamble symbols this MAC is set to use.
void SetLoraLogicalChannelHelper(LoraLogicalChannelHelper helper)
Set the LoraLogicalChannelHelper this MAC instance will use.
void SetPhy(Ptr< SatPhy > phy)
Set the underlying PHY layer.
void SetDevice(Ptr< NetDevice > device)
Set the device this MAC layer is installed on.
LoraLogicalChannelHelper m_channelHelper
The LoraLogicalChannelHelper instance that is assigned to this MAC.
void setRegenerative(bool isRegenerative)
Indicates if the satellite is regenerative on the link this layer is sending packets.
std::vector< uint8_t > m_sfForDataRate
A vector holding the SF each Data Rate corresponds to.
virtual void TxFinished()=0
Perform actions after sending a packet.
double GetBandwidthFromDataRate(uint8_t dataRate)
Get the BW corresponding to a data rate, based on this MAC's region.
std::array< std::array< uint8_t, 6 >, 8 > ReplyDataRateMatrix
SatEnums class is for simplifying the use of enumerators in the satellite module.
Base MAC class for SatNetDevices.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Structure to collect all parameters that are used to compute the duration of a packet (excluding payl...
bool lowDataRateOptimizationEnabled
Whether Low Data Rate Optimization is enabled.
uint32_t nPreamble
Number of preamble symbols.
bool headerDisabled
Whether to use implicit header mode.
uint8_t sf
Spreading Factor.
double bandwidthHz
Bandwidth in Hz.
double codingRate
Code rate.
bool crcEnabled
Whether Cyclic Redundancy Check is enabled.