A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lora-packet-tracker.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 University of Padova
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Davide Magrin <magrinda@dei.unipd.it>
18 */
19
20#ifndef LORA_PACKET_TRACKER_H
21#define LORA_PACKET_TRACKER_H
22
23#include "ns3/nstime.h"
24#include "ns3/packet.h"
25
26#include <map>
27#include <string>
28
29namespace ns3
30{
31namespace lorawan
32{
33
35{
41 UNSET
42};
43
44/**
45 * \ingroup lorawan
46 *
47 * Stores PHY-layer uplink packet metrics of sender/receivers.
48 */
50{
51 Ptr<const Packet> packet; //!< Packet being tracked
52 uint32_t senderId; //!< Node id of the packet sender
53 Time sendTime; //!< Timestamp of pkt radio tx start
54 std::map<int, enum PhyPacketOutcome> outcomes; //!< Reception outcome of this pkt at the end of
55 //!< the tx, mapped by gateway's node id
56};
57
58/**
59 * \ingroup lorawan
60 *
61 * Stores MAC-layer packet metrics of sender/receivers.
62 *
63 * \remark Can be used for both uplink and downlink packets.
64 */
66{
67 Ptr<const Packet> packet; //!< Packet being tracked
68 uint32_t senderId; //!< Node id of the packet sender
69 Time sendTime; //!< Timestamp of the pkt leaving MAC layer to go down the stack of sender
70 Time receivedTime; //!< Time of first reception (placeholder field)
71 //!< \todo Field set to max and not used
72 std::map<int, Time> receptionTimes; //!< Timestamp of the pkt leaving MAC layer to go up the
73 //!< stack, mapped by receiver's node id
74};
75
76/**
77 * \ingroup lorawan
78 *
79 * Stores (optionally enabled) MAC layer packet retransmission process metrics of end devices.
80 */
82{
83 Time firstAttempt; //!< Timestamp of the first transmission attempt
84 Time finishTime; //!< Timestamp of the conclusion of the retransmission process
85 uint8_t reTxAttempts; //!< Number of transmissions attempted during the process
86 bool successful; //!< Whether the retransmission procedure was successful
87};
88
89typedef std::map<Ptr<const Packet>, MacPacketStatus> MacPacketData;
90typedef std::map<Ptr<const Packet>, PacketStatus> PhyPacketData;
91typedef std::map<Ptr<const Packet>, RetransmissionStatus> RetransmissionData;
92
93/**
94 * \ingroup lorawan
95 *
96 * Tracks and stores packets sent in the simulation and provides aggregation functionality
97 */
99{
100 public:
101 LoraPacketTracker(); //!< Default constructor
102 ~LoraPacketTracker(); //!< Destructor
103
104 ///////////////////////////
105 // PHY layer trace sinks //
106 ///////////////////////////
107
108 // Packet transmission by end devices
109
110 /**
111 * Trace a packet TX start by the PHY layer of an end device.
112 *
113 * \param packet The packet being transmitted.
114 * \param systemId Id of end device transmitting the packet.
115 */
116 void TransmissionCallback(Ptr<const Packet> packet, uint32_t systemId);
117
118 // Packet reception outcome at gateways
119
120 /**
121 * Trace a correct packet RX by the PHY layer of a gateway.
122 *
123 * \param packet The packet being received.
124 * \param systemId Id of the gateway receiving the packet.
125 */
127 /**
128 * Trace a gateway packet loss caused by interference.
129 *
130 * \param packet The packet being lost.
131 * \param systemId Id of the gateway losing the packet.
132 */
133 void InterferenceCallback(Ptr<const Packet> packet, uint32_t systemId);
134 /**
135 * Trace a gateway packet loss caused by lack of free reception paths.
136 *
137 * \param packet The packet being lost.
138 * \param systemId Id of the gateway losing the packet.
139 */
141 /**
142 * Trace a gateway packet loss caused by signal strength under sensitivity.
143 *
144 * \param packet The packet being lost.
145 * \param systemId Id of the gateway losing the packet.
146 */
148 /**
149 * Trace a gateway packet loss caused by concurrent downlink transmission.
150 *
151 * \param packet The packet being lost.
152 * \param systemId Id of the gateway losing the packet.
153 */
154 void LostBecauseTxCallback(Ptr<const Packet> packet, uint32_t systemId);
155
156 ///////////////////////////
157 // MAC layer trace sinks //
158 ///////////////////////////
159
160 // Packet send
161
162 /**
163 * Trace a packet leaving a node's MAC layer to go down the stack and be sent by the PHY layer.
164 *
165 * \remark This trace sink is normally connected to both end devices and gateways.
166 *
167 * \param packet The packet being sent.
168 */
170 /**
171 * Trace the exit status of a MAC layer packet retransmission process of an end device.
172 *
173 * \param reqTx Number of transmissions attempted during the process.
174 * \param success Whether the retransmission procedure was successful.
175 * \param firstAttempt Timestamp of the initial transmission attempt.
176 * \param packet The packet being retransmitted.
177 */
178 void RequiredTransmissionsCallback(uint8_t reqTx,
179 bool success,
180 Time firstAttempt,
181 Ptr<Packet> packet);
182
183 // Packet reception by gateways
184
185 /**
186 * Trace a packet leaving a gateway's MAC layer to go up the stack and be delivered to the
187 * node's application.
188 *
189 * \param packet The packet being received.
190 */
192
193 ///////////////////////////////
194 // Packet counting functions //
195 ///////////////////////////////
196
197 /**
198 * Check whether a packet is uplink.
199 *
200 * \param packet The packet to be checked.
201 * \return True if the packet is uplink, false otherwise.
202 */
203 bool IsUplink(Ptr<const Packet> packet);
204
205 // void CountRetransmissions (Time transient, Time simulationTime, MacPacketData
206 // macPacketTracker, RetransmissionData reTransmissionTracker,
207 // PhyPacketData packetTracker);
208
209 /**
210 * Count packets in a time interval to evaluate the performance at PHY level of a specific
211 * gateway. It counts the total number of uplink packets sent over the radio medium, and - from
212 * the perspective of the specified gateway - the number of such packets correctly received,
213 * lost to interference, lost to unavailability of the gateway's reception paths, lost for being
214 * under the RSSI sensitivity threshold, and lost due to concurrent downlink transmission of the
215 * gateway.
216 *
217 * \param startTime Timestamp of the start of the measurement.
218 * \param stopTime Timestamp of the end of the measurement.
219 * \param systemId Node id of the gateway.
220 * \return A vector comprised of the following fields: [totPacketsSent, receivedPackets,
221 * interferedPackets, noMoreGwPackets, underSensitivityPackets, lostBecauseTxPackets].
222 */
223 std::vector<int> CountPhyPacketsPerGw(Time startTime, Time stopTime, int systemId);
224 /**
225 * \copydoc ns3::lorawan::LoraPacketTracker::CountPhyPacketsPerGw
226 * \return Values in the output vector are formatted into a space-separated string.
227 */
228 std::string PrintPhyPacketsPerGw(Time startTime, Time stopTime, int systemId);
229
230 /**
231 * Count packets in a time interval to evaluate the performance at MAC level of a specific
232 * gateway.
233 *
234 * \param startTime Timestamp of the start of the measurement.
235 * \param stopTime Timestamp of the end of the measurement.
236 * \param systemId Node id of the gateway.
237 * \return String of output values.
238 *
239 * \todo Not implemented, this is a placeholder for future implementation.
240 */
241 std::string CountMacPacketsPerGw(Time startTime, Time stopTime, int systemId);
242 /** \copydoc ns3::lorawan::LoraPacketTracker::CountMacPacketsPerGw */
243 std::string PrintMacPacketsPerGw(Time startTime, Time stopTime, int systemId);
244
245 /**
246 * In a time interval, count the number of retransmissions that were needed to correctly deliver
247 * a packet and receive the corresponding acknowledgment.
248 *
249 * \param startTime Timestamp of the start of the measurement.
250 * \param stopTime Timestamp of the end of the measurement.
251 * \return String of output values.
252 *
253 * \todo Not implemented, this is a placeholder for future implementation.
254 */
255 std::string CountRetransmissions(Time startTime, Time stopTime);
256
257 /**
258 * In a time interval, count packets to evaluate the global performance at MAC level of the
259 * whole network. In this case, a MAC layer packet is labeled as successful if it was successful
260 * at at least one of the available gateways.
261 *
262 * \param startTime Timestamp of the start of the measurement.
263 * \param stopTime Timestamp of the end of the measurement.
264 * \return Space-separated string containing two metrics: the number of sent packets and the
265 * number of packets that were received by at least one gateway.
266 */
267 std::string CountMacPacketsGlobally(Time startTime, Time stopTime);
268
269 /**
270 * In a time interval, count packets to evaluate the performance at MAC level of the whole
271 * network. In this case, a MAC layer packet is labeled as successful if it was successful at at
272 * least one of the available gateways, and if the corresponding acknowledgment was correctly
273 * delivered at the device.
274 *
275 * \param startTime Timestamp of the start of the measurement.
276 * \param stopTime Timestamp of the end of the measurement.
277 * \return Space-separated string containing two metrics: the number of sent packets and the
278 * number of packets that generated a successful acknowledgment.
279 */
280 std::string CountMacPacketsGloballyCpsr(Time startTime, Time stopTime);
281
282 private:
283 PhyPacketData m_packetTracker; //!< Packet map of PHY layer metrics
284 MacPacketData m_macPacketTracker; //!< Packet map of MAC layer metrics
285 RetransmissionData m_reTransmissionTracker; //!< Packet map of retransmission process metrics
286};
287} // namespace lorawan
288} // namespace ns3
289#endif
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Tracks and stores packets sent in the simulation and provides aggregation functionality.
void NoMoreReceiversCallback(Ptr< const Packet > packet, uint32_t systemId)
Trace a gateway packet loss caused by lack of free reception paths.
std::string CountRetransmissions(Time startTime, Time stopTime)
In a time interval, count the number of retransmissions that were needed to correctly deliver a packe...
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.
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::string CountMacPacketsPerGw(Time startTime, Time stopTime, int systemId)
Count packets in a time interval to evaluate the performance at MAC level of a specific gateway.
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 PrintMacPacketsPerGw(Time startTime, Time stopTime, int systemId)
Count packets in a time interval to evaluate the performance at MAC level of a specific gateway.
std::string CountMacPacketsGloballyCpsr(Time startTime, Time stopTime)
In a time interval, count packets to evaluate the performance at MAC level of the whole network.
Time stopTime
std::map< Ptr< const Packet >, MacPacketStatus > MacPacketData
std::map< Ptr< const Packet >, PacketStatus > PhyPacketData
std::map< Ptr< const Packet >, RetransmissionStatus > RetransmissionData
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.
std::map< int, Time > receptionTimes
Timestamp of the pkt leaving MAC layer to go up the stack, mapped by receiver's node id.
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.
std::map< int, enum PhyPacketOutcome > outcomes
Reception outcome of this pkt at the end of the tx, mapped by gateway's node id.
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.