A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lora-channel.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 * The structure of this class is inspired by the YansWifiChannel
9 * contained in the WiFi module.
10 */
11
12#ifndef LORA_CHANNEL_H
13#define LORA_CHANNEL_H
14
15#include "ns3/channel.h"
16#include "ns3/packet.h"
17#include "ns3/propagation-delay-model.h"
18#include "ns3/propagation-loss-model.h"
19#include "ns3/traced-callback.h"
20
21namespace ns3
22{
23namespace lorawan
24{
25
26class LoraPhy;
27enum class IQPolarity;
28struct LoraTxParameters;
29
30/**
31 * @ingroup lorawan
32 *
33 * The class that delivers packets among PHY layers.
34 *
35 * This class is tasked with taking packets that PHY layers want to send and,
36 * based on some factors like the transmission power and the node positions,
37 * computing the power at every receiver using a PropagationLossModel and
38 * notifying them of the reception event after a delay based on some
39 * PropagationDelayModel.
40 */
41class LoraChannel : public Channel
42{
43 public:
44 /**
45 * Register this type.
46 * @return The object TypeId.
47 */
48 static TypeId GetTypeId();
49
50 LoraChannel(); //!< Default constructor
51 ~LoraChannel() override; //!< Destructor
52
53 // Inherited from Channel.
54 std::size_t GetNDevices() const override;
55 Ptr<NetDevice> GetDevice(std::size_t i) const override;
56
57 /**
58 * Construct a LoraChannel with a loss and delay model.
59 *
60 * @param loss The loss model to associate to this channel.
61 * @param delay The delay model to associate to this channel.
62 */
64
65 /**
66 * Connect a LoraPhy object to the LoraChannel.
67 *
68 * This method is needed so that the channel knows it has to notify this PHY
69 * of incoming transmissions.
70 *
71 * @param phy The physical layer to add.
72 */
73 void Add(Ptr<LoraPhy> phy);
74
75 /**
76 * Remove a physical layer from the LoraChannel.
77 *
78 * This method removes a phy from the list of devices we have to notify.
79 * Removing unused PHY layers from the channel can improve performance, since
80 * it is not necessary to notify them about each transmission.
81 *
82 * @param phy The physical layer to remove.
83 */
84 void Remove(Ptr<LoraPhy> phy);
85
86 /**
87 * Send a packet in the channel.
88 *
89 * This method is typically invoked by a PHY that needs to send a packet.
90 * Every connected Phy will be notified of this packet send through a call to
91 * their StartReceive methods after a delay based on the channel's
92 * PropagationDelayModel.
93 *
94 * @param sender The PHY device that is sending this packet.
95 * @param packet The PHY packet that is being sent over the channel.
96 * @param frequencyHz The frequency this transmission will happen at.
97 * @param iqPolarity The transmission's I/Q polarity (uplink or downlink).
98 * @param txParams The set of parameters that are used by the transmitter.
99 * @param txPowerDbm The power of the transmission.
100 * @param duration The on-air duration of this packet.
101 *
102 * @internal When this method is called, the channel schedules an internal Receive call
103 * that performs the actual call to the PHY's StartReceive function.
104 */
105 void Send(Ptr<LoraPhy> sender,
106 Ptr<Packet> packet,
107 uint32_t frequencyHz,
108 IQPolarity iqPolarity,
109 const LoraTxParameters& txParams,
110 double txPowerDbm,
111 Time duration) const;
112
113 /**
114 * Compute the received power when transmitting from a point to another one.
115 *
116 * This method can be used by external object to see the receive power of a
117 * transmission from one point to another using this Channel's
118 * PropagationLossModel.
119 *
120 * @param txPowerDbm The power the transmitter is using, in dBm.
121 * @param senderMobility The mobility model of the sender.
122 * @param receiverMobility The mobility model of the receiver.
123 * @return The received power in dBm.
124 */
125 double GetRxPower(double txPowerDbm,
126 Ptr<MobilityModel> senderMobility,
127 Ptr<MobilityModel> receiverMobility) const;
128
129 private:
130 /**
131 * A struct that holds meaningful parameters for transmission on a LoraChannel.
132 */
134 {
135 uint32_t frequencyHz; //!< The frequency [Hz] of this transmission.
136 IQPolarity iqPolarity; //!< The transmission's I/Q polarity (uplink or downlink).
137 uint8_t spreadingFactor; //!< The Spreading Factor of this transmission.
138 double rxPowerDbm; //!< The average reception power.
139 Time duration; //!< The duration of the transmission.
140 };
141
142 /**
143 * Private method that is scheduled by LoraChannel's Send method to happen
144 * after the channel delay, for each of the connected PHY layers.
145 *
146 * It's here that the Receive method of the PHY is called to initiate packet
147 * reception at the PHY.
148 *
149 * @param receiver The phy to start reception on.
150 * @param packet The packet the phy will receive.
151 * @param parameters The parameters that characterize this transmission.
152 */
153 void Receive(Ptr<LoraPhy> receiver,
154 Ptr<Packet> packet,
155 const LoraChannelParameters& parameters) const;
156
157 /**
158 * Allow logging of LoraChannelParameters like with any other data type.
159 */
160 friend std::ostream& operator<<(std::ostream& os, const LoraChannelParameters& params);
161
162 /**
163 * The vector containing the PHYs that are currently connected to the
164 * channel.
165 */
166 std::vector<Ptr<LoraPhy>> m_phyList;
167
168 /**
169 * Pointer to the loss model.
170 *
171 * This loss model can be a concatenation of multiple loss models, obtained
172 * via PropagationLossModel's SetNext method.
173 */
175
176 /**
177 * Pointer to the delay model.
178 */
180
181 /**
182 * Callback for when a packet is being sent on the channel.
183 */
185};
186
187} // namespace lorawan
188} // namespace ns3
189
190#endif /* LORA_CHANNEL_H */
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
void Send(Ptr< LoraPhy > sender, Ptr< Packet > packet, uint32_t frequencyHz, IQPolarity iqPolarity, const LoraTxParameters &txParams, double txPowerDbm, Time duration) const
Send a packet in the channel.
std::size_t GetNDevices() const override
~LoraChannel() override
Destructor.
std::vector< Ptr< LoraPhy > > m_phyList
The vector containing the PHYs that are currently connected to the channel.
friend std::ostream & operator<<(std::ostream &os, const LoraChannelParameters &params)
Allow logging of LoraChannelParameters like with any other data type.
void Remove(Ptr< LoraPhy > phy)
Remove a physical layer from the LoraChannel.
double GetRxPower(double txPowerDbm, Ptr< MobilityModel > senderMobility, Ptr< MobilityModel > receiverMobility) const
Compute the received power when transmitting from a point to another one.
Ptr< PropagationDelayModel > m_delay
Pointer to the delay model.
LoraChannel()
Default constructor.
TracedCallback< Ptr< const Packet > > m_packetSent
Callback for when a packet is being sent on the channel.
Ptr< NetDevice > GetDevice(std::size_t i) const override
void Add(Ptr< LoraPhy > phy)
Connect a LoraPhy object to the LoraChannel.
void Receive(Ptr< LoraPhy > receiver, Ptr< Packet > packet, const LoraChannelParameters &parameters) const
Private method that is scheduled by LoraChannel's Send method to happen after the channel delay,...
Ptr< PropagationLossModel > m_loss
Pointer to the loss model.
static TypeId GetTypeId()
Register this type.
Base class for PHY layers implementing the LoRa modulation scheme.
Definition lora-phy.h:102
IQPolarity
I/Q Polarity of LoRa transmission symbols.
Definition lora-phy.h:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.
A struct that holds meaningful parameters for transmission on a LoraChannel.
uint32_t frequencyHz
The frequency [Hz] of this transmission.
uint8_t spreadingFactor
The Spreading Factor of this transmission.
IQPolarity iqPolarity
The transmission's I/Q polarity (uplink or downlink).
Time duration
The duration of the transmission.
double rxPowerDbm
The average reception power.
Structure to collect all parameters that are used to compute the duration of a packet (excluding payl...
Definition lora-phy.h:73