12#include "ns3/lorawan-mac-header.h"
13#include "ns3/simulator.h"
43 NS_LOG_INFO(
"A new packet was sent by the MAC layer");
61 NS_LOG_INFO(
"Finished retransmission attempts for a packet");
62 NS_LOG_DEBUG(
"Packet: " << packet <<
"ReqTx " <<
unsigned(reqTx) <<
", succ: " << success
63 <<
", firstAttempt: " << firstAttempt.
GetSeconds());
79 NS_LOG_INFO(
"A packet was successfully received at the MAC layer of gateway "
86 (*it).second.receptionTimes.insert(
105 NS_LOG_INFO(
"PHY packet " << packet <<
" was transmitted by device " << edId);
122 NS_LOG_INFO(
"PHY packet " << packet <<
" was successfully received at gateway " << gwId);
125 (*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome>(gwId,
RECEIVED));
134 NS_LOG_INFO(
"PHY packet " << packet <<
" was interfered at gateway " << gwId);
137 (*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome>(gwId,
INTERFERED));
146 NS_LOG_INFO(
"PHY packet " << packet <<
" was lost because no more receivers at gateway "
149 (*it).second.outcomes.insert(
159 NS_LOG_INFO(
"PHY packet " << packet <<
" was lost because under sensitivity at gateway "
163 (*it).second.outcomes.insert(
174 "PHY packet " << packet
175 <<
" was lost because of concurrent downlink transmission at gateway "
179 (*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome>(gwId,
LOST_BECAUSE_TX));
190 copy->RemoveHeader(mHdr);
205 std::vector<int> packetCounts(6, 0);
209 if ((*itPhy).second.sendTime >= startTime && (*itPhy).second.sendTime <=
stopTime)
211 packetCounts.at(0)++;
213 NS_LOG_DEBUG(
"Dealing with packet " << (*itPhy).second.packet);
214 NS_LOG_DEBUG(
"This packet was received by " << (*itPhy).second.outcomes.size()
217 if ((*itPhy).second.outcomes.count(gwId) > 0)
219 switch ((*itPhy).second.outcomes.at(gwId))
222 packetCounts.at(1)++;
226 packetCounts.at(2)++;
230 packetCounts.at(3)++;
234 packetCounts.at(4)++;
238 packetCounts.at(5)++;
259 std::vector<int> packetCounts(6, 0);
263 if ((*itPhy).second.sendTime >= startTime && (*itPhy).second.sendTime <=
stopTime)
265 packetCounts.at(0)++;
267 NS_LOG_DEBUG(
"Dealing with packet " << (*itPhy).second.packet);
268 NS_LOG_DEBUG(
"This packet was received by " << (*itPhy).second.outcomes.size()
271 if ((*itPhy).second.outcomes.count(gwId) > 0)
273 switch ((*itPhy).second.outcomes.at(gwId))
276 packetCounts.at(1)++;
280 packetCounts.at(2)++;
284 packetCounts.at(3)++;
288 packetCounts.at(4)++;
292 packetCounts.at(5)++;
303 std::string output(
"");
304 for (
int i = 0; i < 6; ++i)
306 output += std::to_string(packetCounts.at(i)) +
" ";
321 if ((*it).second.sendTime >= startTime && (*it).second.sendTime <=
stopTime)
324 if (!(*it).second.receptionTimes.empty())
331 return std::to_string(sent) +
" " + std::to_string(received);
343 if ((*it).second.firstAttempt >= startTime && (*it).second.firstAttempt <=
stopTime)
347 NS_LOG_DEBUG(
"Number of attempts: " <<
unsigned(it->second.reTxAttempts)
348 <<
", successful: " << it->second.successful);
349 if (it->second.successful)
356 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.