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