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