31 return (os <<
"UNKNOWN");
50 return (os <<
"UNKNOWN");
63 else if (value ==
"4/6")
67 else if (value ==
"4/7")
71 else if (value ==
"4/8")
77 is.setstate(std::ios_base::failbit);
86 os <<
"LoraTxParameters("
87 <<
"spreadingFactor=" << unsigned(params.spreadingFactor) <<
", "
88 <<
"bandwidthHz=" << params.bandwidthHz <<
", "
89 <<
"codingRate=" << params.codingRate <<
", "
90 <<
"lowDataRateOptimize=" << params.lowDataRateOptimize <<
", "
91 <<
"preambleLenSymb: " << params.preambleLenSymb <<
", "
92 <<
"implicitHeader=" << params.implicitHeader <<
", "
93 <<
"crcEnabled=" << params.crcEnabled <<
")";
104 auto sf =
static_cast<double>(spreadingFactor);
105 auto bw =
static_cast<double>(bandwidthHz);
106 return Seconds(pow(2, sf) / bw);
122 double tPreamble = (nPreamble + 4.25) * tSym;
125 NS_LOG_DEBUG(
"PHY Packet of size " << phyPayloadLen <<
" bytes");
128 auto pl =
static_cast<double>(phyPayloadLen);
130 auto cr =
static_cast<double>(txParams.
codingRate);
139 double num = 8.0 * pl - 4.0 * sf + 28.0 + 16.0 * crc - 20.0 * h;
140 double den = 4.0 * (sf - 2.0 * de);
141 double payloadSymbNb = 8.0 + std::max(std::ceil(num / den) * (cr + 4.0), 0.0);
144 double tPayload = payloadSymbNb * tSym;
146 NS_LOG_DEBUG(
"Time computation: num = " << num <<
", den = " << den <<
", payloadSymbNb = "
147 << payloadSymbNb <<
", tSym = " << tSym);
153 return Seconds(tPreamble + tPayload);
162 .SetGroupName(
"lorawan")
163 .AddTraceSource(
"StartSending",
164 "Trace source indicating the PHY layer"
165 "has begun the sending process for a packet",
167 "ns3::Packet::TracedCallback")
168 .AddTraceSource(
"PhyRxBegin",
169 "Trace source indicating a packet "
170 "is now being received from the channel medium "
173 "ns3::Packet::TracedCallback")
174 .AddTraceSource(
"PhyRxEnd",
175 "Trace source indicating the PHY has finished "
176 "the reception process for a packet",
178 "ns3::Packet::TracedCallback")
179 .AddTraceSource(
"ReceivedPacket",
180 "Trace source indicating a packet "
181 "was correctly received",
183 "ns3::Packet::TracedCallback")
184 .AddTraceSource(
"LostPacketBecauseInterference",
185 "Trace source indicating a packet "
186 "could not be correctly decoded because of interfering"
189 "ns3::Packet::TracedCallback")
190 .AddTraceSource(
"LostPacketBecauseUnderSensitivity",
191 "Trace source indicating a packet "
192 "could not be correctly received because"
193 "its received power is below the sensitivity of the receiver",
195 "ns3::Packet::TracedCallback");
Keep track of the current position and velocity of an object.
Object()
Caller graph was not generated because of its size.
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.
Callback< void, Ptr< const Packet > > RxFailedCallback
Type definition for a callback for when a packet reception fails.
void SetReceiveOkCallback(RxOkCallback callback)
Set the callback to call upon successful reception of a packet.
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.
Callback< void, Ptr< const Packet > > TxFinishedCallback
Type definition for a callback to call when a packet has finished sending.
static Time GetTimeOnAir(uint32_t phyPayloadLen, const LoraTxParameters &txParams)
Compute the total transmission time for a physical packet based on modulation parameters.
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 Time GetTSym(uint8_t spreadingFactor, uint32_t bandwidthHz)
Compute the symbol time from spreading factor and bandwidth.
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.
Callback< void, Ptr< const Packet > > RxOkCallback
Type definition for a callback for when a packet is correctly received.
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_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, 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 ",...
CodingRate
Enumeration of the LoRa supported coding rates.
IQPolarity
I/Q Polarity of LoRa transmission symbols.
@ DOWN
Downlink / Downchirp / Inverted polarity.
@ UP
Uplink / Upchirp / Normal polarity.
#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 EndDeviceLoraPhy::State &state)
Overloaded operator to print the value of a EndDeviceLoraPhy::State.
std::istream & operator>>(std::istream &is, CodingRate &codingRate)
Allow parsing of CodingRate from CommandLine.
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...
CodingRate codingRate
Transmission coding rate.
uint32_t bandwidthHz
Transmission bandwidth in Hz.
bool implicitHeader
Whether to use implicit header mode.
uint8_t spreadingFactor
Symbol Spreading Factor (SF).
bool crcEnabled
Whether Cyclic Redundancy Check (CRC) is enabled.
bool lowDataRateOptimize
Low Data Rate Optimization (mandated for SF11 and SF12).
uint16_t preambleLenSymb
Number of symbols in the packet preamble.