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