A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lora-interference-helper.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_INTERFERENCE_HELPER_H
21#define LORA_INTERFERENCE_HELPER_H
22
24
25#include "ns3/callback.h"
26#include "ns3/nstime.h"
27#include "ns3/object.h"
28#include "ns3/packet.h"
29#include "ns3/simulator.h"
30#include "ns3/traced-callback.h"
31
32#include <list>
33
34namespace ns3
35{
36namespace lorawan
37{
38
39/**
40 * \ingroup lorawan
41 *
42 * Helper for LoraPhy that manages interference calculations.
43 *
44 * This class keeps a list of signals that are impinging on the antenna of the
45 * device, in order to compute which ones can be correctly received and which
46 * ones are lost due to interference.
47 */
49{
50 public:
51 /**
52 * A class representing a signal in time.
53 *
54 * Used in LoraInterferenceHelper to keep track of which signals overlap and
55 * cause destructive interference.
56 */
57 class Event : public SimpleRefCount<LoraInterferenceHelper::Event>
58 {
59 public:
60 /**
61 * Construct a new interference signal Event object
62 *
63 * \param duration The duration in time.
64 * \param rxPowerdBm The power of the signal.
65 * \param spreadingFactor The modulation spreading factor.
66 * \param packet The packet transmitted.
67 * \param frequencyMHz The carrier frequency of the signal.
68 */
69 Event(Time duration,
70 double rxPowerdBm,
71 uint8_t spreadingFactor,
72 Ptr<Packet> packet,
73 double frequencyMHz);
74
75 ~Event(); //!< Destructor
76
77 /**
78 * Get the duration of the event.
79 *
80 * \return The duration in time.
81 */
82 Time GetDuration() const;
83
84 /**
85 * Get the starting time of the event.
86 *
87 * \return The starting time.
88 */
89 Time GetStartTime() const;
90
91 /**
92 * Get the ending time of the event.
93 *
94 * \return The end time.
95 */
96 Time GetEndTime() const;
97
98 /**
99 * Get the power of the event.
100 *
101 * \return The power in dBm as a double.
102 */
103 double GetRxPowerdBm() const;
104
105 /**
106 * Get the spreading factor used by this signal.
107 *
108 * \return The spreading factor value.
109 */
110 uint8_t GetSpreadingFactor() const;
111
112 /**
113 * Get the packet this event was generated for.
114 *
115 * \return A pointer to the packet.
116 */
117 Ptr<Packet> GetPacket() const;
118
119 /**
120 * Get the frequency this event was on.
121 *
122 * \return The carrier frequency as a double.
123 */
124 double GetFrequency() const;
125
126 /**
127 * Print the current event in a human readable form.
128 *
129 * \param stream The output stream to use.
130 */
131 void Print(std::ostream& stream) const;
132
133 private:
134 Time m_startTime; //!< The time this signal begins (at the device).
135 Time m_endTime; //!< The time this signal ends (at the device).
136 uint8_t m_sf; //!< The spreading factor of this signal.
137 double m_rxPowerdBm; //!< The power of this event in dBm (at the device).
138 Ptr<Packet> m_packet; //!< The packet this event was generated for.
139 double m_frequencyMHz; //!< The frequency this event was on.
140 };
141
142 /**
143 * Enumeration of types of collision matrices.
144 */
146 {
149 };
150
151 /**
152 * Register this type.
153 * \return The object TypeId.
154 */
155 static TypeId GetTypeId();
156
157 LoraInterferenceHelper(); //!< Default constructor
158 virtual ~LoraInterferenceHelper(); //!< Destructor
159
160 /**
161 * Add an event to the InterferenceHelper.
162 *
163 * \param duration The duration of the packet.
164 * \param rxPower The received power in dBm.
165 * \param spreadingFactor The spreading factor used by the transmission.
166 * \param packet The packet carried by this transmission.
167 * \param frequencyMHz The frequency this event was sent at.
168 *
169 * \return The newly created event.
170 */
172 double rxPower,
173 uint8_t spreadingFactor,
174 Ptr<Packet> packet,
175 double frequencyMHz);
176
177 /**
178 * Get a list of the interferers currently registered at this InterferenceHelper.
179 *
180 * \return The list of pointers to interference Event objects.
181 */
182 std::list<Ptr<LoraInterferenceHelper::Event>> GetInterferers();
183
184 /**
185 * Print the events that are saved in this helper in a human readable format.
186 *
187 * \param stream The output stream.
188 */
189 void PrintEvents(std::ostream& stream);
190
191 /**
192 * Determine whether the event was destroyed by interference or not. This is
193 * the method where the SNIR tables come into play and the computations
194 * regarding power are performed.
195
196 * \param event The event for which to check the outcome.
197 * \return The sf of the packets that caused the loss, or 0 if there was no
198 * loss.
199 */
201
202 /**
203 * Compute the time duration in which two given events are overlapping.
204 *
205 * \param event1 The first event.
206 * \param event2 The second event.
207 *
208 * \return The overlap time.
209 */
212
213 /**
214 * Delete all events in the LoraInterferenceHelper.
215 */
216 void ClearAllEvents();
217
218 /**
219 * Delete old events in this LoraInterferenceHelper.
220 */
221 void CleanOldEvents();
222
223 static CollisionMatrix collisionMatrix; //!< Collision matrix type set by the constructor
224
225 static std::vector<std::vector<double>> collisionSnirAloha; //!< ALOHA collision matrix
226 static std::vector<std::vector<double>> collisionSnirGoursaud; //!< GOURSAUD collision matrix
227
228 private:
229 /**
230 * Set the collision matrix.
231 *
232 * \param collisionMatrix The type of collision matrix to set.
233 *
234 * \todo Redundant, only used by constructor which also sets the matrix directly. To be removed.
235 */
237
238 std::vector<std::vector<double>> m_collisionSnir; //!< The matrix containing information about
239 //!< how packets survive interference
240 std::list<Ptr<LoraInterferenceHelper::Event>>
241 m_events; //!< List of the events this LoraInterferenceHelper is keeping track of
242 static Time oldEventThreshold; //!< The threshold after which an event is considered old and
243 //!< removed from the list
244};
245
246/**
247 * Allow easy logging of LoraInterferenceHelper Events
248 *
249 * \param os The output stream for logging
250 * \param event The event to be logged
251 */
252std::ostream& operator<<(std::ostream& os, const LoraInterferenceHelper::Event& event);
253} // namespace lorawan
254
255} // namespace ns3
256#endif /* LORA_INTERFERENCE_HELPER_H */
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
A template-based reference counting class.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
A class representing a signal in time.
double GetRxPowerdBm() const
Get the power of the event.
Time m_startTime
The time this signal begins (at the device).
Time GetStartTime() const
Get the starting time of the event.
double GetFrequency() const
Get the frequency this event was on.
Time GetEndTime() const
Get the ending time of the event.
uint8_t GetSpreadingFactor() const
Get the spreading factor used by this signal.
Time GetDuration() const
Get the duration of the event.
Time m_endTime
The time this signal ends (at the device).
uint8_t m_sf
The spreading factor of this signal.
Ptr< Packet > GetPacket() const
Get the packet this event was generated for.
void Print(std::ostream &stream) const
Print the current event in a human readable form.
Ptr< Packet > m_packet
The packet this event was generated for.
double m_rxPowerdBm
The power of this event in dBm (at the device).
double m_frequencyMHz
The frequency this event was on.
Helper for LoraPhy that manages interference calculations.
Ptr< LoraInterferenceHelper::Event > Add(Time duration, double rxPower, uint8_t spreadingFactor, Ptr< Packet > packet, double frequencyMHz)
Add an event to the InterferenceHelper.
static std::vector< std::vector< double > > collisionSnirGoursaud
GOURSAUD collision matrix.
static Time oldEventThreshold
The threshold after which an event is considered old and removed from the list.
Time GetOverlapTime(Ptr< LoraInterferenceHelper::Event > event1, Ptr< LoraInterferenceHelper::Event > event2)
Compute the time duration in which two given events are overlapping.
CollisionMatrix
Enumeration of types of collision matrices.
void CleanOldEvents()
Delete old events in this LoraInterferenceHelper.
void ClearAllEvents()
Delete all events in the LoraInterferenceHelper.
static CollisionMatrix collisionMatrix
Collision matrix type set by the constructor.
static std::vector< std::vector< double > > collisionSnirAloha
ALOHA collision matrix.
static TypeId GetTypeId()
Register this type.
std::vector< std::vector< double > > m_collisionSnir
The matrix containing information about how packets survive interference.
void SetCollisionMatrix(enum CollisionMatrix collisionMatrix)
Set the collision matrix.
uint8_t IsDestroyedByInterference(Ptr< LoraInterferenceHelper::Event > event)
Determine whether the event was destroyed by interference or not.
void PrintEvents(std::ostream &stream)
Print the events that are saved in this helper in a human readable format.
std::list< Ptr< LoraInterferenceHelper::Event > > GetInterferers()
Get a list of the interferers currently registered at this InterferenceHelper.
std::list< Ptr< LoraInterferenceHelper::Event > > m_events
List of the events this LoraInterferenceHelper is keeping track of.
std::ostream & operator<<(std::ostream &os, const EndDeviceStatus &status)
Every class exported by the ns3 library is enclosed in the ns3 namespace.