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