13#include "ns3/simulator.h"
29 uint8_t spreadingFactor,
34 m_sf(spreadingFactor),
111double inf = std::numeric_limits<double>::max();
128 {6, -16, -18, -19, -19, -20},
129 {-24, 6, -20, -22, -22, -22},
130 {-27, -27, 6, -23, -25, -25},
131 {-30, -30, -30, 6, -26, -28},
132 {-33, -33, -33, -33, 6, -29},
133 {-36, -36, -36, -36, -36, 6}
174 uint8_t spreadingFactor,
220std::list<Ptr<LoraInterferenceHelper::Event>>
231 stream <<
"Currently registered events:" << std::endl;
235 (*it)->Print(stream);
252 double rxPowerDbm =
event->GetRxPowerdBm();
253 uint8_t sf =
event->GetSpreadingFactor();
254 uint32_t frequencyHz =
event->GetFrequency();
258 Time duration =
event->GetDuration();
259 Time packetStartTime = now - duration;
262 std::list<Ptr<LoraInterferenceHelper::Event>>::iterator it;
265 std::vector<double> cumulativeInterferenceEnergy(6, 0);
276 if (!(interferer->GetFrequency() == frequencyHz) || interferer == event)
286 uint8_t interfererSf = interferer->GetSpreadingFactor();
287 double interfererPower = interferer->GetRxPowerdBm();
288 Time interfererStartTime = interferer->GetStartTime();
289 Time interfererEndTime = interferer->GetEndTime();
291 NS_LOG_INFO(
"Found an interferer: sf = " <<
unsigned(interfererSf)
292 <<
", power = " << interfererPower
293 <<
", start time = " << interfererStartTime
294 <<
", end time = " << interfererEndTime);
301 double interfererPowerW =
DbmToW(interfererPower);
303 double interferenceEnergy = overlap.
GetSeconds() * interfererPowerW;
304 cumulativeInterferenceEnergy.at(
unsigned(interfererSf) - 7) += interferenceEnergy;
305 NS_LOG_DEBUG(
"Interferer power in W: " << interfererPowerW);
306 NS_LOG_DEBUG(
"Interference energy: " << interferenceEnergy);
311 for (
auto currentSf = uint8_t(7); currentSf <= uint8_t(12); currentSf++)
314 << cumulativeInterferenceEnergy.at(
unsigned(currentSf) - 7));
318 double signalPowerW =
DbmToW(rxPowerDbm);
319 double signalEnergy = duration.
GetSeconds() * signalPowerW;
324 double snirIsolation =
m_collisionSnir[unsigned(sf) - 7][unsigned(currentSf) - 7];
325 NS_LOG_DEBUG(
"The needed isolation to survive is " << snirIsolation <<
" dB");
327 10 * log10(signalEnergy / cumulativeInterferenceEnergy.at(
unsigned(currentSf) - 7));
330 if (snir >= snirIsolation)
333 NS_LOG_DEBUG(
"Packet survived interference with SF " << currentSf);
337 NS_LOG_DEBUG(
"Packet destroyed by interference with SF" <<
unsigned(currentSf));
367 Time s1 = event1->GetStartTime();
368 Time s2 = event2->GetStartTime();
369 Time e1 = event1->GetEndTime();
370 Time e2 = event2->GetEndTime();
373 if (e1 <= s2 || e2 <= s1)
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
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.
virtual ~LoraInterferenceHelper()
Destructor.
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.
LoraInterferenceHelper()
Default constructor.
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.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Time Seconds(double value)
Construct a Time in the indicated unit.
std::ostream & operator<<(std::ostream &os, const EndDeviceLoraPhy::State &state)
Overloaded operator to print the value of a EndDeviceLoraPhy::State.
double DbmToW(double dBm)
Convert from dBm to Watts.
Every class exported by the ns3 library is enclosed in the ns3 namespace.