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