23#include "ns3/lorawan-mac-header.h"
24#include "ns3/simulator.h"
54 NS_LOG_INFO(
"A new packet was sent by the MAC layer");
72 NS_LOG_INFO(
"Finished retransmission attempts for a packet");
73 NS_LOG_DEBUG(
"Packet: " << packet <<
"ReqTx " <<
unsigned(reqTx) <<
", succ: " << success
74 <<
", firstAttempt: " << firstAttempt.
GetSeconds());
97 (*it).second.receptionTimes.insert(
116 NS_LOG_INFO(
"PHY packet " << packet <<
" was transmitted by device " << edId);
133 NS_LOG_INFO(
"PHY packet " << packet <<
" was successfully received at gateway " << gwId);
136 (*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome>(gwId,
RECEIVED));
145 NS_LOG_INFO(
"PHY packet " << packet <<
" was interfered at gateway " << gwId);
148 (*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome>(gwId,
INTERFERED));
157 NS_LOG_INFO(
"PHY packet " << packet <<
" was lost because no more receivers at gateway "
160 (*it).second.outcomes.insert(
170 NS_LOG_INFO(
"PHY packet " << packet <<
" was lost because under sensitivity at gateway "
174 (*it).second.outcomes.insert(
185 "PHY packet " << packet
186 <<
" was lost because of concurrent downlink transmission at gateway "
190 (*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome>(gwId,
LOST_BECAUSE_TX));
201 copy->RemoveHeader(mHdr);
216 std::vector<int> packetCounts(6, 0);
220 if ((*itPhy).second.sendTime >= startTime && (*itPhy).second.sendTime <=
stopTime)
222 packetCounts.at(0)++;
224 NS_LOG_DEBUG(
"Dealing with packet " << (*itPhy).second.packet);
225 NS_LOG_DEBUG(
"This packet was received by " << (*itPhy).second.outcomes.size()
228 if ((*itPhy).second.outcomes.count(gwId) > 0)
230 switch ((*itPhy).second.outcomes.at(gwId))
233 packetCounts.at(1)++;
237 packetCounts.at(2)++;
241 packetCounts.at(3)++;
245 packetCounts.at(4)++;
249 packetCounts.at(5)++;
270 std::vector<int> packetCounts(6, 0);
274 if ((*itPhy).second.sendTime >= startTime && (*itPhy).second.sendTime <=
stopTime)
276 packetCounts.at(0)++;
278 NS_LOG_DEBUG(
"Dealing with packet " << (*itPhy).second.packet);
279 NS_LOG_DEBUG(
"This packet was received by " << (*itPhy).second.outcomes.size()
282 if ((*itPhy).second.outcomes.count(gwId) > 0)
284 switch ((*itPhy).second.outcomes.at(gwId))
287 packetCounts.at(1)++;
291 packetCounts.at(2)++;
295 packetCounts.at(3)++;
299 packetCounts.at(4)++;
303 packetCounts.at(5)++;
314 std::string output(
"");
315 for (
int i = 0; i < 6; ++i)
317 output += std::to_string(packetCounts.at(i)) +
" ";
332 if ((*it).second.sendTime >= startTime && (*it).second.sendTime <=
stopTime)
335 if (!(*it).second.receptionTimes.empty())
342 return std::to_string(sent) +
" " + std::to_string(received);
354 if ((*it).second.firstAttempt >= startTime && (*it).second.firstAttempt <=
stopTime)
358 NS_LOG_DEBUG(
"Number of attempts: " <<
unsigned(it->second.reTxAttempts)
359 <<
", successful: " << it->second.successful);
360 if (it->second.successful)
367 return std::to_string(sent) +
" " + std::to_string(received);
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
static uint32_t GetContext()
Get the current simulation context.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
static Time Max()
Maximum representable Time Not to be confused with Max(Time,Time).
void NoMoreReceiversCallback(Ptr< const Packet > packet, uint32_t systemId)
Trace a gateway packet loss caused by lack of free reception paths.
void MacTransmissionCallback(Ptr< const Packet > packet)
Trace a packet leaving a node's MAC layer to go down the stack and be sent by the PHY layer.
PhyPacketData m_packetTracker
Packet map of PHY layer metrics.
~LoraPacketTracker()
Destructor.
void RequiredTransmissionsCallback(uint8_t reqTx, bool success, Time firstAttempt, Ptr< Packet > packet)
Trace the exit status of a MAC layer packet retransmission process of an end device.
void UnderSensitivityCallback(Ptr< const Packet > packet, uint32_t systemId)
Trace a gateway packet loss caused by signal strength under sensitivity.
void LostBecauseTxCallback(Ptr< const Packet > packet, uint32_t systemId)
Trace a gateway packet loss caused by concurrent downlink transmission.
std::vector< int > CountPhyPacketsPerGw(Time startTime, Time stopTime, int systemId)
Count packets in a time interval to evaluate the performance at PHY level of a specific gateway.
std::string PrintPhyPacketsPerGw(Time startTime, Time stopTime, int systemId)
Count packets in a time interval to evaluate the performance at PHY level of a specific gateway.
void MacGwReceptionCallback(Ptr< const Packet > packet)
Trace a packet leaving a gateway's MAC layer to go up the stack and be delivered to the node's applic...
LoraPacketTracker()
Default constructor.
void PacketReceptionCallback(Ptr< const Packet > packet, uint32_t systemId)
Trace a correct packet RX by the PHY layer of a gateway.
MacPacketData m_macPacketTracker
Packet map of MAC layer metrics.
std::string CountMacPacketsGlobally(Time startTime, Time stopTime)
In a time interval, count packets to evaluate the global performance at MAC level of the whole networ...
bool IsUplink(Ptr< const Packet > packet)
Check whether a packet is uplink.
void InterferenceCallback(Ptr< const Packet > packet, uint32_t systemId)
Trace a gateway packet loss caused by interference.
void TransmissionCallback(Ptr< const Packet > packet, uint32_t systemId)
Trace a packet TX start by the PHY layer of an end device.
RetransmissionData m_reTransmissionTracker
Packet map of retransmission process metrics.
std::string CountMacPacketsGloballyCpsr(Time startTime, Time stopTime)
In a time interval, count packets to evaluate the performance at MAC level of the whole network.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#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(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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Stores MAC-layer packet metrics of sender/receivers.
Ptr< const Packet > packet
Packet being tracked.
Time receivedTime
Time of first reception (placeholder field)
Time sendTime
Timestamp of the pkt leaving MAC layer to go down the stack of sender.
uint32_t senderId
Node id of the packet sender.
Stores PHY-layer uplink packet metrics of sender/receivers.
uint32_t senderId
Node id of the packet sender.
Time sendTime
Timestamp of pkt radio tx start.
Ptr< const Packet > packet
Packet being tracked.
Stores (optionally enabled) MAC layer packet retransmission process metrics of end devices.
Time finishTime
Timestamp of the conclusion of the retransmission process.
Time firstAttempt
Timestamp of the first transmission attempt.
bool successful
Whether the retransmission procedure was successful.
uint8_t reTxAttempts
Number of transmissions attempted during the process.