11#include "ns3/lorawan-mac-header.h"
12#include "ns3/simulator.h"
39 NS_LOG_INFO(
"A new packet was sent by the MAC layer");
57 NS_LOG_INFO(
"Finished retransmission attempts for a packet");
58 NS_LOG_DEBUG(
"Packet: " << packet <<
"ReqTx " <<
unsigned(reqTx) <<
", succ: " << success
59 <<
", firstAttempt: " << firstAttempt.
As(
Time::S));
75 NS_LOG_INFO(
"A packet was successfully received at the MAC layer of gateway "
82 (*it).second.receptionTimes.insert(
101 NS_LOG_INFO(
"PHY packet " << packet <<
" was transmitted by device " << edId);
118 NS_LOG_INFO(
"PHY packet " << packet <<
" was successfully received at gateway " << gwId);
121 (*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome>(gwId,
RECEIVED));
130 NS_LOG_INFO(
"PHY packet " << packet <<
" was interfered at gateway " << gwId);
133 (*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome>(gwId,
INTERFERED));
142 NS_LOG_INFO(
"PHY packet " << packet <<
" was lost because no more receivers at gateway "
145 (*it).second.outcomes.insert(
155 NS_LOG_INFO(
"PHY packet " << packet <<
" was lost because under sensitivity at gateway "
159 (*it).second.outcomes.insert(
170 "PHY packet " << packet
171 <<
" was lost because of concurrent downlink transmission at gateway "
175 (*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome>(gwId,
LOST_BECAUSE_TX));
186 copy->RemoveHeader(mHdr);
201 std::vector<int> packetCounts(6, 0);
205 if ((*itPhy).second.sendTime >= startTime && (*itPhy).second.sendTime <=
stopTime)
207 packetCounts.at(0)++;
209 NS_LOG_DEBUG(
"Dealing with packet " << (*itPhy).second.packet);
210 NS_LOG_DEBUG(
"This packet was received by " << (*itPhy).second.outcomes.size()
213 if ((*itPhy).second.outcomes.count(gwId) > 0)
215 switch ((*itPhy).second.outcomes.at(gwId))
218 packetCounts.at(1)++;
222 packetCounts.at(2)++;
226 packetCounts.at(3)++;
230 packetCounts.at(4)++;
234 packetCounts.at(5)++;
255 std::vector<int> packetCounts(6, 0);
259 if ((*itPhy).second.sendTime >= startTime && (*itPhy).second.sendTime <=
stopTime)
261 packetCounts.at(0)++;
263 NS_LOG_DEBUG(
"Dealing with packet " << (*itPhy).second.packet);
264 NS_LOG_DEBUG(
"This packet was received by " << (*itPhy).second.outcomes.size()
267 if ((*itPhy).second.outcomes.count(gwId) > 0)
269 switch ((*itPhy).second.outcomes.at(gwId))
272 packetCounts.at(1)++;
276 packetCounts.at(2)++;
280 packetCounts.at(3)++;
284 packetCounts.at(4)++;
288 packetCounts.at(5)++;
299 std::string output(
"");
300 for (
int i = 0; i < 6; ++i)
302 output += std::to_string(packetCounts.at(i)) +
" ";
317 if ((*it).second.sendTime >= startTime && (*it).second.sendTime <=
stopTime)
320 if (!(*it).second.receptionTimes.empty())
327 return std::to_string(sent) +
" " + std::to_string(received);
339 if ((*it).second.firstAttempt >= startTime && (*it).second.firstAttempt <=
stopTime)
343 NS_LOG_DEBUG(
"Number of attempts: " <<
unsigned(it->second.reTxAttempts)
344 <<
", successful: " << it->second.successful);
345 if (it->second.successful)
352 return std::to_string(sent) +
" " + std::to_string(received);
Smart pointer class similar to boost::intrusive_ptr.
static uint32_t GetContext()
Get the current simulation context.
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.
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.
Time Now()
create an ns3::Time instance which contains the current simulation time.
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.