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