12#include "ns3/simulator.h"
31 .SetGroupName(
"lorawan")
32 .AddTraceSource(
"StartSending",
33 "Trace source indicating the PHY layer"
34 "has begun the sending process for a packet",
36 "ns3::Packet::TracedCallback")
37 .AddTraceSource(
"PhyRxBegin",
38 "Trace source indicating a packet "
39 "is now being received from the channel medium "
42 "ns3::Packet::TracedCallback")
43 .AddTraceSource(
"PhyRxEnd",
44 "Trace source indicating the PHY has finished "
45 "the reception process for a packet",
47 "ns3::Packet::TracedCallback")
48 .AddTraceSource(
"ReceivedPacket",
49 "Trace source indicating a packet "
50 "was correctly received",
52 "ns3::Packet::TracedCallback")
53 .AddTraceSource(
"LostPacketBecauseInterference",
54 "Trace source indicating a packet "
55 "could not be correctly decoded because of interfering"
58 "ns3::Packet::TracedCallback")
59 .AddTraceSource(
"LostPacketBecauseUnderSensitivity",
60 "Trace source indicating a packet "
61 "could not be correctly received because"
62 "its received power is below the sensitivity of the receiver",
64 "ns3::Packet::TracedCallback");
182 double num = 8 * pl - 4 * txParams.
sf + 28 + 16 * crc - 20 * h;
183 double den = 4 * (txParams.
sf - 2 * de);
184 double payloadSymbNb =
185 8 + std::max(std::ceil(num / den) * (txParams.
codingRate + 4),
double(0));
188 double tPayload = payloadSymbNb * tSym;
190 NS_LOG_DEBUG(
"Time computation: num = " << num <<
", den = " << den <<
", payloadSymbNb = "
191 << payloadSymbNb <<
", tSym = " << tSym);
197 return Seconds(tPreamble + tPayload);
203 os <<
"SF: " << unsigned(params.sf) <<
", headerDisabled: " << params.headerDisabled
204 <<
", codingRate: " << unsigned(params.codingRate) <<
", bandwidthHz: " << params.bandwidthHz
205 <<
", nPreamble: " << params.nPreamble <<
", crcEnabled: " << params.crcEnabled
206 <<
", lowDataRateOptimizationEnabled: " << params.lowDataRateOptimizationEnabled <<
")";
Keep track of the current position and velocity of an object.
A base class which provides memory management and object aggregation.
Smart pointer class similar to boost::intrusive_ptr.
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.
Ptr< LoraChannel > GetChannel() const
Get the channel instance associated to this PHY.
~LoraPhy() override
Destructor.
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet reception ends.
void SetReceiveOkCallback(RxOkCallback callback)
Set the callback to call upon successful reception of a packet.
static Time GetOnAirTime(Ptr< Packet > packet, LoraTxParameters txParams)
Compute the time that a packet with certain characteristics will take to be transmitted.
TracedCallback< Ptr< const Packet >, uint32_t > m_interferedPacket
The trace source fired when a packet cannot be correctly received because of interference.
RxFailedCallback m_rxFailedCallback
The callback to perform upon failed reception of a packet we were locked on.
static Time GetTSym(LoraTxParameters txParams)
Compute the symbol time from spreading factor and bandwidth.
TxFinishedCallback m_txFinishedCallback
The callback to perform upon the end of a transmission.
void SetMobility(Ptr< MobilityModel > mobility)
Set the mobility model associated to this PHY.
void SetReceiveFailedCallback(RxFailedCallback callback)
Set the callback to call upon failed reception of a packet we were previously locked on.
void SetDevice(Ptr< NetDevice > device)
Set the NetDevice that owns this PHY.
TracedCallback< Ptr< const Packet >, uint32_t > m_successfullyReceivedPacket
The trace source fired when a packet was correctly received.
TracedCallback< Ptr< const Packet >, uint32_t > m_startSending
The trace source fired when a packet is sent.
Ptr< NetDevice > GetDevice() const
Get the NetDevice associated to this PHY.
static TypeId GetTypeId()
Register this type.
TracedCallback< Ptr< const Packet >, uint32_t > m_underSensitivity
The trace source fired when a packet cannot be received because its power is below the sensitivity th...
Ptr< MobilityModel > m_mobility
The mobility model associated to this PHY.
void SetChannel(Ptr< LoraChannel > channel)
Set the LoraChannel instance PHY transmits on.
Ptr< NetDevice > m_device
The net device this PHY is attached to.
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
Ptr< MobilityModel > GetMobility()
Get the mobility model associated to this PHY.
LoraPhy()
Default constructor.
void SetTxFinishedCallback(TxFinishedCallback callback)
Set the callback to call after transmission of a packet.
Ptr< LoraChannel > m_channel
The channel this PHY transmits on.
RxOkCallback m_rxOkCallback
The callback to perform upon correct reception of a packet.
#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_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
std::ostream & operator<<(std::ostream &os, const EndDeviceStatus &status)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Structure to collect all parameters that are used to compute the duration of a packet (excluding payl...
uint8_t codingRate
Code rate (obtained as 4/(codingRate+4))
uint32_t nPreamble
Number of preamble symbols.
bool headerDisabled
Whether to use implicit header mode.
double bandwidthHz
Bandwidth in Hz.
bool lowDataRateOptimizationEnabled
Whether low data rate optimization is enabled.
bool crcEnabled
Whether Cyclic Redundancy Check (CRC) is enabled.
uint8_t sf
Spreading Factor.