A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lora-phy.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 University of Padova
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Davide Magrin <magrinda@dei.unipd.it>
7 */
8
9#ifndef LORA_PHY_H
10#define LORA_PHY_H
11
13
14#include "ns3/mobility-model.h"
15#include "ns3/net-device.h"
16
17namespace ns3
18{
19namespace lorawan
20{
21
22class LoraChannel;
23
24/**
25 * @ingroup lorawan
26 *
27 * Enumeration of the LoRa supported coding rates
28 */
29enum class CodingRate : uint8_t
30{
31 CR_4_5 = 1, //!< Coding rate 4/5
32 CR_4_6, //!< Coding rate 4/6
33 CR_4_7, //!< Coding rate 4/7
34 CR_4_8, //!< Coding rate 4/8
35};
36
37/**
38 * Allow logging of CodingRate like any other data type.
39 */
40std::ostream& operator<<(std::ostream& os, const CodingRate& codingRate);
41
42/**
43 * Allow parsing of CodingRate from CommandLine.
44 */
45std::istream& operator>>(std::istream& is, CodingRate& codingRate);
46
47/**
48 * @ingroup lorawan
49 *
50 * Structure to collect all parameters that are used to compute the duration of
51 * a packet (excluding payload length).
52 */
54{
55 uint8_t sf = 7; //!< Spreading Factor
56 bool headerDisabled = false; //!< Whether to use implicit header mode
57 CodingRate codingRate = CodingRate::CR_4_5; //!< Code rate (obtained as 4/(codingRate+4))
58 uint32_t bandwidthHz = 125000; //!< Bandwidth in Hz
59 uint32_t nPreamble = 8; //!< Number of preamble symbols
60 bool crcEnabled = true; //!< Whether Cyclic Redundancy Check (CRC) is enabled
61 bool lowDataRateOptimizationEnabled = false; //!< Whether low data rate optimization is enabled
62};
63
64/**
65 * Allow logging of LoraTxParameters like with any other data type.
66 */
67std::ostream& operator<<(std::ostream& os, const LoraTxParameters& params);
68
69/**
70 * @ingroup lorawan
71 *
72 * Base class for PHY layers implementing the LoRa modulation scheme.
73 *
74 * This class features common callbacks and defines the interfaces that are used
75 * to send and receive packets at the PHY layer. Furthermore, it features an
76 * implementation of the GetOnAirTime function, used to compute the actual
77 * duration of a packet based on a series of parameters that are collected in
78 * LoraTxParameters objects.
79 */
80class LoraPhy : public Object
81{
82 public:
83 /**
84 * Register this type.
85 * @return The object TypeId.
86 */
87 static TypeId GetTypeId();
88
89 LoraPhy(); //!< Default constructor
90 ~LoraPhy() override; //!< Destructor
91
92 /**
93 * Type definition for a callback for when a packet is correctly received.
94 *
95 * This callback can be set by an upper layer that wishes to be informed of
96 * correct reception events.
97 */
99
100 /**
101 * Type definition for a callback for when a packet reception fails.
102 *
103 * This callback can be set by an upper layer that wishes to be informed of
104 * failed reception events.
105 */
107
108 /**
109 * Type definition for a callback to call when a packet has finished sending.
110 *
111 * This callback is used by the MAC layer, to determine when to open a receive
112 * window.
113 */
115
116 /**
117 * Start receiving a packet.
118 *
119 * This method is typically called by LoraChannel.
120 *
121 * @param packet The packet that is arriving at this PHY layer.
122 * @param rxPowerDbm The power of the arriving packet (assumed to be constant for the whole
123 * reception).
124 * @param sf The Spreading Factor of the arriving packet.
125 * @param duration The on air time of this packet.
126 * @param frequencyHz The frequency this packet is being transmitted on.
127 */
128 virtual void StartReceive(Ptr<Packet> packet,
129 double rxPowerDbm,
130 uint8_t sf,
131 Time duration,
132 uint32_t frequencyHz) = 0;
133
134 /**
135 * Finish reception of a packet.
136 *
137 * This method is scheduled by StartReceive, based on the packet duration. By
138 * passing a LoraInterferenceHelper Event to this method, the class will be
139 * able to identify the packet that is being received among all those that
140 * were registered as interference by StartReceive.
141 *
142 * @param packet The received packet.
143 * @param event The event that is tied to this packet in the
144 * LoraInterferenceHelper.
145 */
147
148 /**
149 * Instruct the PHY to send a packet according to some parameters.
150 *
151 * @param packet The packet to send.
152 * @param txParams The desired transmission parameters.
153 * @param frequencyHz The frequency on which to transmit.
154 * @param txPowerDbm The power in dBm with which to transmit the packet.
155 */
156 virtual void Send(Ptr<Packet> packet,
157 LoraTxParameters txParams,
158 uint32_t frequencyHz,
159 double txPowerDbm) = 0;
160
161 /**
162 * Whether this device is transmitting or not.
163 *
164 * @return True if the device is currently transmitting a packet, false
165 * otherwise.
166 */
167 virtual bool IsTransmitting() = 0;
168
169 /**
170 * Whether this device is listening on the specified frequency or not.
171 *
172 * @param frequencyHz The frequency [Hz] to query.
173 * @return True if the device is listening on that frequency, false
174 * otherwise.
175 */
176 virtual bool IsOnFrequency(uint32_t frequencyHz) = 0;
177
178 /**
179 * Set the callback to call upon successful reception of a packet.
180 *
181 * This method is typically called by an upper MAC layer that wants to be
182 * notified after the successful reception of a packet.
183 *
184 * @param callback The RxOkCallback instance.
185 */
186 void SetReceiveOkCallback(RxOkCallback callback);
187
188 /**
189 * Set the callback to call upon failed reception of a packet we were
190 * previously locked on.
191 *
192 * This method is typically called by an upper MAC layer that wants to be
193 * notified after the failed reception of a packet.
194 *
195 * @param callback The RxFailedCallback instance.
196 */
198
199 /**
200 * Set the callback to call after transmission of a packet.
201 *
202 * This method is typically called by an upper MAC layer that wants to be
203 * notified after the transmission of a packet.
204 *
205 * @param callback The TxFinishedCallback instance.
206 */
208
209 /**
210 * Get the mobility model associated to this PHY.
211 *
212 * @return The MobilityModel associated to this PHY.
213 */
215
216 /**
217 * Set the mobility model associated to this PHY.
218 *
219 * @param mobility The mobility model to associate to this PHY.
220 */
221 void SetMobility(Ptr<MobilityModel> mobility);
222
223 /**
224 * Set the LoraChannel instance PHY transmits on.
225 *
226 * Typically, there is only one instance per simulation.
227 *
228 * @param channel The LoraChannel instance this PHY will transmit on.
229 */
230 void SetChannel(Ptr<LoraChannel> channel);
231
232 /**
233 * Get the channel instance associated to this PHY.
234 *
235 * @return The LoraChannel instance this PHY transmits on.
236 */
238
239 /**
240 * Get the NetDevice associated to this PHY.
241 *
242 * @return The NetDevice associated to this PHY.
243 */
245
246 /**
247 * Set the NetDevice that owns this PHY.
248 *
249 * @param device The NetDevice this PHY will reference as its owner.
250 */
251 void SetDevice(Ptr<NetDevice> device);
252
253 /**
254 * Compute the symbol time from spreading factor and bandwidth.
255 *
256 * @param txParams The parameters for transmission.
257 * @return TSym, the time required to send a LoRa modulation symbol.
258 */
259 static Time GetTSym(LoraTxParameters txParams);
260
261 /**
262 * Compute the time that a packet with certain characteristics will take to be
263 * transmitted.
264 *
265 * Besides from the ones saved in LoraTxParameters, the packet's payload
266 * (obtained through a GetSize () call to account for the presence of Headers
267 * and Trailers, too) also influences the packet transmit time.
268 *
269 * @param packet The packet that needs to be transmitted.
270 * @param txParams The set of parameters that will be used for transmission.
271 * @return The time necessary to transmit the packet.
272 */
273 static Time GetOnAirTime(Ptr<Packet> packet, LoraTxParameters txParams);
274
275 private:
276 /**
277 * Internal call when transmission of a packet finishes.
278 *
279 * Calls to this function are typically scheduled by the Send function.
280 *
281 * @param packet A pointer to the packet that has been transmitted.
282 */
283 virtual void TxFinished(Ptr<const Packet> packet) = 0;
284
285 Ptr<MobilityModel> m_mobility; //!< The mobility model associated to this PHY.
286
287 protected:
288 // Member objects
289
290 Ptr<NetDevice> m_device; //!< The net device this PHY is attached to.
291
292 Ptr<LoraChannel> m_channel; //!< The channel this PHY transmits on.
293
294 LoraInterferenceHelper m_interference; //!< The LoraInterferenceHelper associated to this PHY.
295
296 // Trace sources
297
298 /**
299 * The trace source fired when a packet is sent.
300 */
302
303 /**
304 * The trace source fired when a packet begins the reception process from the
305 * medium.
306 */
308
309 /**
310 * The trace source fired when a packet reception ends.
311 */
313
314 /**
315 * The trace source fired when a packet was correctly received.
316 */
318
319 /**
320 * The trace source fired when a packet cannot be received because its power
321 * is below the sensitivity threshold.
322 */
324
325 /**
326 * The trace source fired when a packet cannot be correctly received because
327 * of interference.
328 */
330
331 // Callbacks
332
333 /**
334 * The callback to perform upon correct reception of a packet.
335 */
337
338 /**
339 * The callback to perform upon failed reception of a packet we were locked on.
340 */
342
343 /**
344 * The callback to perform upon the end of a transmission.
345 */
347};
348
349} // namespace lorawan
350} // namespace ns3
351
352#endif /* LORA_PHY_H */
Callback template class.
Definition callback.h:428
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:50
The class that delivers packets among PHY layers.
Helper for LoraPhy that manages interference calculations.
Ptr< LoraChannel > GetChannel() const
Get the channel instance associated to this PHY.
Definition lora-phy.cc:90
~LoraPhy() override
Destructor.
Definition lora-phy.cc:71
virtual void Send(Ptr< Packet > packet, LoraTxParameters txParams, uint32_t frequencyHz, double txPowerDbm)=0
Instruct the PHY to send a packet according to some parameters.
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet reception ends.
Definition lora-phy.h:312
LoraInterferenceHelper m_interference
The LoraInterferenceHelper associated to this PHY.
Definition lora-phy.h:294
Callback< void, Ptr< const Packet > > RxFailedCallback
Type definition for a callback for when a packet reception fails.
Definition lora-phy.h:106
void SetReceiveOkCallback(RxOkCallback callback)
Set the callback to call upon successful reception of a packet.
Definition lora-phy.cc:131
static Time GetOnAirTime(Ptr< Packet > packet, LoraTxParameters txParams)
Compute the time that a packet with certain characteristics will take to be transmitted.
Definition lora-phy.cc:155
TracedCallback< Ptr< const Packet >, uint32_t > m_interferedPacket
The trace source fired when a packet cannot be correctly received because of interference.
Definition lora-phy.h:329
RxFailedCallback m_rxFailedCallback
The callback to perform upon failed reception of a packet we were locked on.
Definition lora-phy.h:341
Callback< void, Ptr< const Packet > > TxFinishedCallback
Type definition for a callback to call when a packet has finished sending.
Definition lora-phy.h:114
static Time GetTSym(LoraTxParameters txParams)
Compute the symbol time from spreading factor and bandwidth.
Definition lora-phy.cc:149
virtual void TxFinished(Ptr< const Packet > packet)=0
Internal call when transmission of a packet finishes.
virtual bool IsOnFrequency(uint32_t frequencyHz)=0
Whether this device is listening on the specified frequency or not.
TxFinishedCallback m_txFinishedCallback
The callback to perform upon the end of a transmission.
Definition lora-phy.h:346
virtual void EndReceive(Ptr< Packet > packet, Ptr< LoraInterferenceHelper::Event > event)=0
Finish reception of a packet.
void SetMobility(Ptr< MobilityModel > mobility)
Set the mobility model associated to this PHY.
Definition lora-phy.cc:115
void SetReceiveFailedCallback(RxFailedCallback callback)
Set the callback to call upon failed reception of a packet we were previously locked on.
Definition lora-phy.cc:137
void SetDevice(Ptr< NetDevice > device)
Set the NetDevice that owns this PHY.
Definition lora-phy.cc:82
TracedCallback< Ptr< const Packet >, uint32_t > m_successfullyReceivedPacket
The trace source fired when a packet was correctly received.
Definition lora-phy.h:317
TracedCallback< Ptr< const Packet >, uint32_t > m_startSending
The trace source fired when a packet is sent.
Definition lora-phy.h:301
virtual bool IsTransmitting()=0
Whether this device is transmitting or not.
virtual void StartReceive(Ptr< Packet > packet, double rxPowerDbm, uint8_t sf, Time duration, uint32_t frequencyHz)=0
Start receiving a packet.
Ptr< NetDevice > GetDevice() const
Get the NetDevice associated to this PHY.
Definition lora-phy.cc:76
static TypeId GetTypeId()
Register this type.
Definition lora-phy.cc:25
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...
Definition lora-phy.h:323
Ptr< MobilityModel > m_mobility
The mobility model associated to this PHY.
Definition lora-phy.h:285
void SetChannel(Ptr< LoraChannel > channel)
Set the LoraChannel instance PHY transmits on.
Definition lora-phy.cc:123
Ptr< NetDevice > m_device
The net device this PHY is attached to.
Definition lora-phy.h:290
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
Definition lora-phy.h:307
Ptr< MobilityModel > GetMobility()
Get the mobility model associated to this PHY.
Definition lora-phy.cc:98
LoraPhy()
Default constructor.
Definition lora-phy.cc:67
Callback< void, Ptr< const Packet > > RxOkCallback
Type definition for a callback for when a packet is correctly received.
Definition lora-phy.h:98
void SetTxFinishedCallback(TxFinishedCallback callback)
Set the callback to call after transmission of a packet.
Definition lora-phy.cc:143
Ptr< LoraChannel > m_channel
The channel this PHY transmits on.
Definition lora-phy.h:292
RxOkCallback m_rxOkCallback
The callback to perform upon correct reception of a packet.
Definition lora-phy.h:336
CodingRate
Enumeration of the LoRa supported coding rates.
Definition lora-phy.h:30
@ CR_4_5
Coding rate 4/5.
Definition lora-phy.h:31
@ CR_4_7
Coding rate 4/7.
Definition lora-phy.h:33
@ CR_4_8
Coding rate 4/8.
Definition lora-phy.h:34
@ CR_4_6
Coding rate 4/6.
Definition lora-phy.h:32
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.
Definition lora-phy.cc:223
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...
Definition lora-phy.h:54
uint32_t nPreamble
Number of preamble symbols.
Definition lora-phy.h:59
CodingRate codingRate
Code rate (obtained as 4/(codingRate+4)).
Definition lora-phy.h:57
uint32_t bandwidthHz
Bandwidth in Hz.
Definition lora-phy.h:58
bool headerDisabled
Whether to use implicit header mode.
Definition lora-phy.h:56
bool lowDataRateOptimizationEnabled
Whether low data rate optimization is enabled.
Definition lora-phy.h:61
bool crcEnabled
Whether Cyclic Redundancy Check (CRC) is enabled.
Definition lora-phy.h:60
uint8_t sf
Spreading Factor.
Definition lora-phy.h:55