34 NS_LOG_COMPONENT_DEFINE(
"LorawanMac");
36 NS_OBJECT_ENSURE_REGISTERED(LorawanMac);
42 TypeId(
"ns3::LorawanMac")
44 .AddTraceSource(
"SentNewPacket",
45 "Trace source indicating a new packet "
46 "arrived at the MAC layer",
48 "ns3::Packet::TracedCallback")
49 .AddTraceSource(
"ReceivedPacket",
50 "Trace source indicating a packet "
51 "was correctly received at the MAC layer",
53 "ns3::Packet::TracedCallback")
54 .AddTraceSource(
"CannotSendBecauseDutyCycle",
55 "Trace source indicating a packet "
56 "could not be sent immediately because of duty cycle limitations",
58 "ns3::Packet::TracedCallback");
63 : m_isRegenerative(false)
65 NS_FATAL_ERROR(
"Default constructor not in use");
71 m_isRegenerative(false)
73 NS_LOG_FUNCTION(
this);
78 NS_LOG_FUNCTION(
this);
110 Ptr<SatLoraPhyTx> phyLoraTx = DynamicCast<SatLoraPhyTx>(
m_phy->GetPhyTx());
111 NS_ASSERT_MSG(phyLoraTx !=
nullptr,
"Lorawan MAC does not have a SatLoraPhyTx instance");
130 NS_LOG_FUNCTION(
this <<
unsigned(dataRate));
144 NS_LOG_FUNCTION(
this <<
unsigned(dataRate));
158 NS_LOG_FUNCTION(
this <<
unsigned(txPower));
171 NS_LOG_FUNCTION(packet);
178 double tSym = pow(2,
int(txParams.
sf)) / (txParams.
bandwidthHz);
181 double tPreamble = (double(txParams.
nPreamble) + 4.25) * tSym;
184 uint32_t pl = packet->GetSize();
185 NS_LOG_DEBUG(
"Packet of size " << pl <<
" bytes");
195 double num = 8 * pl - 4 * txParams.
sf + 28 + 16 * crc - 20 * h;
196 double den = (txParams.
sf - 2 * de) * txParams.
codingRate;
197 double payloadSymbNb = 8 + std::max(std::ceil(num / den), double(0));
200 double tPayload = payloadSymbNb * tSym;
202 NS_LOG_DEBUG(
"Time computation: num = " << num <<
", den = " << den <<
", payloadSymbNb = "
203 << payloadSymbNb <<
", tSym = " << tSym);
204 NS_LOG_DEBUG(
"tPreamble = " << tPreamble);
205 NS_LOG_DEBUG(
"tPayload = " << tPayload);
206 NS_LOG_DEBUG(
"Total time = " << tPreamble + tPayload);
209 return Seconds(tPreamble + tPayload);
251 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
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.