A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
radio-bearer-stats-calculator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Jaume Nin <jnin@cttc.es>
7 * Nicola Baldo <nbaldo@cttc.es>
8 */
9
10#ifndef RADIO_BEARER_STATS_CALCULATOR_H_
11#define RADIO_BEARER_STATS_CALCULATOR_H_
12
14
15#include "ns3/basic-data-calculators.h"
16#include "ns3/lte-common.h"
17#include "ns3/object.h"
18#include "ns3/uinteger.h"
19
20#include <fstream>
21#include <map>
22#include <string>
23
24namespace ns3
25{
26/// Container: (IMSI, LCID) pair, uint32_t
27typedef std::map<ImsiLcidPair_t, uint32_t> Uint32Map;
28/// Container: (IMSI, LCID) pair, uint64_t
29typedef std::map<ImsiLcidPair_t, uint64_t> Uint64Map;
30/// Container: (IMSI, LCID) pair, uint32_t calculator
31typedef std::map<ImsiLcidPair_t, Ptr<MinMaxAvgTotalCalculator<uint32_t>>> Uint32StatsMap;
32/// Container: (IMSI, LCID) pair, uint64_t calculator
33typedef std::map<ImsiLcidPair_t, Ptr<MinMaxAvgTotalCalculator<uint64_t>>> Uint64StatsMap;
34/// Container: (IMSI, LCID) pair, double
35typedef std::map<ImsiLcidPair_t, double> DoubleMap;
36/// Container: (IMSI, LCID) pair, LteFlowId_t
37typedef std::map<ImsiLcidPair_t, LteFlowId_t> FlowIdMap;
38
39/**
40 * @ingroup lte
41 *
42 * This class is an ns-3 trace sink that performs the calculation of
43 * PDU statistics for uplink and downlink. Statistics are generated
44 * on a per radio bearer basis. This class can be used for
45 * RLC PDU stats or PDCP PDU stats by connecting to the appropriate
46 * trace sources at the RLC or PDCP layer.
47 *
48 * The statistics are calculated at consecutive time windows and
49 * periodically written to a file. The calculated statistics are:
50 *
51 * - Number of transmitted PDUs
52 * - Number of received PDUs
53 * - Number of transmitted bytes
54 * - Number of received bytes
55 * - Average, min, max and standard deviation of PDU delay (delay is
56 * calculated from the generation of the PDU to its reception)
57 * - Average, min, max and standard deviation of PDU size
58 */
60{
61 public:
62 /**
63 * Class constructor
64 */
66
67 /**
68 * Class constructor
69 * @param protocolType the name of the protocol type
70 */
71 RadioBearerStatsCalculator(std::string protocolType);
72
73 /**
74 * Class destructor
75 */
76
78
79 // Inherited from ns3::Object
80 /**
81 * Register this type.
82 * @return The object TypeId.
83 */
84 static TypeId GetTypeId();
85 void DoDispose() override;
86
87 /**
88 * Get the name of the file where the uplink statistics will be stored.
89 * @return the name of the file where the uplink statistics will be stored
90 */
91 std::string GetUlOutputFilename();
92
93 /**
94 * Get the name of the file where the downlink statistics will be stored.
95 * @return the name of the file where the downlink statistics will be stored
96 */
97 std::string GetDlOutputFilename();
98
99 /**
100 * Set the name of the file where the uplink PDCP statistics will be stored.
101 *
102 * @param outputFilename string with the name of the file
103 */
104 void SetUlPdcpOutputFilename(std::string outputFilename);
105
106 /**
107 * Get the name of the file where the uplink PDCP statistics will be stored.
108 * @return the name of the file where the uplink PDCP statistics will be stored
109 */
110 std::string GetUlPdcpOutputFilename();
111
112 /**
113 * Set the name of the file where the downlink PDCP statistics will be stored.
114 *
115 * @param outputFilename string with the name of the file
116 */
117 void SetDlPdcpOutputFilename(std::string outputFilename);
118
119 /**
120 * Get the name of the file where the downlink PDCP statistics will be stored.
121 * @return the name of the file where the downlink PDCP statistics will be stored
122 */
123 std::string GetDlPdcpOutputFilename();
124
125 /**
126 *
127 * @param t the value of the StartTime attribute
128 */
129 void SetStartTime(Time t);
130
131 /**
132 *
133 * @return the value of the StartTime attribute
134 */
135 Time GetStartTime() const;
136
137 /**
138 *
139 * @param e the epoch duration
140 */
141 void SetEpoch(Time e);
142
143 /**
144 *
145 * @return the epoch duration
146 */
147 Time GetEpoch() const;
148
149 /**
150 * Notifies the stats calculator that an uplink transmission has occurred.
151 * @param cellId CellId of the attached Enb
152 * @param imsi IMSI of the UE who transmitted the PDU
153 * @param rnti C-RNTI of the UE who transmitted the PDU
154 * @param lcid LCID through which the PDU has been transmitted
155 * @param packetSize size of the PDU in bytes
156 */
157 void UlTxPdu(uint16_t cellId, uint64_t imsi, uint16_t rnti, uint8_t lcid, uint32_t packetSize);
158
159 /**
160 * Notifies the stats calculator that an uplink reception has occurred.
161 * @param cellId CellId of the attached Enb
162 * @param imsi IMSI of the UE who received the PDU
163 * @param rnti C-RNTI of the UE who received the PDU
164 * @param lcid LCID through which the PDU has been received
165 * @param packetSize size of the PDU in bytes
166 * @param delay RLC to RLC delay in nanoseconds
167 */
168 void UlRxPdu(uint16_t cellId,
169 uint64_t imsi,
170 uint16_t rnti,
171 uint8_t lcid,
173 uint64_t delay);
174
175 /**
176 * Notifies the stats calculator that an downlink transmission has occurred.
177 * @param cellId CellId of the attached Enb
178 * @param imsi IMSI of the UE who is receiving the PDU
179 * @param rnti C-RNTI of the UE who is receiving the PDU
180 * @param lcid LCID through which the PDU has been transmitted
181 * @param packetSize size of the PDU in bytes
182 */
183 void DlTxPdu(uint16_t cellId, uint64_t imsi, uint16_t rnti, uint8_t lcid, uint32_t packetSize);
184
185 /**
186 * Notifies the stats calculator that an downlink reception has occurred.
187 * @param cellId CellId of the attached Enb
188 * @param imsi IMSI of the UE who received the PDU
189 * @param rnti C-RNTI of the UE who received the PDU
190 * @param lcid LCID through which the PDU has been transmitted
191 * @param packetSize size of the PDU in bytes
192 * @param delay RLC to RLC delay in nanoseconds
193 */
194 void DlRxPdu(uint16_t cellId,
195 uint64_t imsi,
196 uint16_t rnti,
197 uint8_t lcid,
199 uint64_t delay);
200
201 /**
202 * Gets the number of transmitted uplink packets.
203 * @param imsi IMSI of the UE
204 * @param lcid LCID
205 * @return number of transmitted uplink packets
206 */
207 uint32_t GetUlTxPackets(uint64_t imsi, uint8_t lcid);
208
209 /**
210 * Gets the number of received uplink packets.
211 * @param imsi IMSI of the UE
212 * @param lcid LCID
213 * @return number of received uplink packets
214 */
215 uint32_t GetUlRxPackets(uint64_t imsi, uint8_t lcid);
216
217 /**
218 * Gets the number of transmitted uplink data bytes.
219 * @param imsi IMSI of the UE
220 * @param lcid LCID
221 * @return number of transmitted data bytes
222 */
223 uint64_t GetUlTxData(uint64_t imsi, uint8_t lcid);
224
225 /**
226 * Gets the number of received uplink data bytes.
227 * @param imsi IMSI of the UE
228 * @param lcid LCID
229 * @return number of received data bytes
230 */
231 uint64_t GetUlRxData(uint64_t imsi, uint8_t lcid);
232
233 /**
234 * Gets the attached Enb cellId.
235 * @param imsi IMSI of the UE
236 * @param lcid LCID
237 * @return Enb cellId
238 */
239 uint32_t GetUlCellId(uint64_t imsi, uint8_t lcid);
240
241 /**
242 * Gets the uplink RLC to RLC delay
243 * @param imsi IMSI of the UE
244 * @param lcid LCID
245 * @return RLC to RLC delay in seconds
246 */
247 double GetUlDelay(uint64_t imsi, uint8_t lcid);
248
249 /**
250 * Gets the uplink RLC to RLC statistics: average, min, max and standard deviation.
251 * @param imsi IMSI of the UE
252 * @param lcid LCID
253 * @return RLC to RLC delay statistics average, min, max and standard deviation in seconds
254 */
255 std::vector<double> GetUlDelayStats(uint64_t imsi, uint8_t lcid);
256
257 /**
258 * Gets the uplink PDU size statistics: average, min, max and standard deviation.
259 * @param imsi IMSI of the UE
260 * @param lcid LCID
261 * @return PDU size statistics average, min, max and standard deviation in seconds
262 */
263 std::vector<double> GetUlPduSizeStats(uint64_t imsi, uint8_t lcid);
264
265 /**
266 * Gets the number of transmitted downlink data bytes.
267 * @param imsi IMSI of the UE
268 * @param lcid LCID
269 * @return number of transmitted data bytes
270 */
271 uint32_t GetDlTxPackets(uint64_t imsi, uint8_t lcid);
272
273 /**
274 * Gets the number of received downlink data bytes.
275 * @param imsi IMSI of the UE
276 * @param lcid LCID
277 * @return number of received data bytes
278 */
279 uint32_t GetDlRxPackets(uint64_t imsi, uint8_t lcid);
280
281 /**
282 * Gets the number of transmitted downlink data bytes.
283 * @param imsi IMSI of the UE
284 * @param lcid LCID
285 * @return number of transmitted data bytes
286 */
287 uint64_t GetDlTxData(uint64_t imsi, uint8_t lcid);
288
289 /**
290 * Gets the number of received downlink data bytes.
291 * @param imsi IMSI of the UE
292 * @param lcid LCID
293 * @return number of received data bytes
294 */
295 uint64_t GetDlRxData(uint64_t imsi, uint8_t lcid);
296
297 /**
298 * Gets the attached Enb cellId.
299 * @param imsi IMSI of the UE
300 * @param lcid LCID
301 * @return Enb cellId
302 */
303 uint32_t GetDlCellId(uint64_t imsi, uint8_t lcid);
304
305 /**
306 * Gets the downlink RLC to RLC delay
307 * @param imsi IMSI of the UE
308 * @param lcid LCID
309 * @return RLC to RLC delay in seconds
310 */
311 double GetDlDelay(uint64_t imsi, uint8_t lcid);
312
313 /**
314 * Gets the downlink RLC to RLC statistics: average, min, max and standard deviation.
315 * @param imsi IMSI of the UE
316 * @param lcid LCID
317 * @return RLC to RLC delay statistics average, min, max and standard deviation in seconds
318 */
319 std::vector<double> GetDlDelayStats(uint64_t imsi, uint8_t lcid);
320
321 /**
322 * Gets the downlink PDU size statistics: average, min, max and standard deviation.
323 * @param imsi IMSI of the UE
324 * @param lcid LCID
325 * @return PDU size statistics average, min, max and standard deviation in seconds
326 */
327 std::vector<double> GetDlPduSizeStats(uint64_t imsi, uint8_t lcid);
328
329 private:
330 /**
331 * Called after each epoch to write collected
332 * statistics to output files. During first call
333 * it opens output files and write columns descriptions.
334 * During next calls it opens output files in append mode.
335 */
336 void ShowResults();
337
338 /**
339 * Writes collected statistics to UL output file and
340 * closes UL output file.
341 * @param outFile ofstream for UL statistics
342 */
343 void WriteUlResults(std::ofstream& outFile);
344
345 /**
346 * Writes collected statistics to DL output file and
347 * closes DL output file.
348 * @param outFile ofstream for DL statistics
349 */
350 void WriteDlResults(std::ofstream& outFile);
351
352 /**
353 * Erases collected statistics
354 */
355 void ResetResults();
356
357 /**
358 * Reschedules EndEpoch event. Usually used after
359 * execution of SetStartTime() or SetEpoch()
360 */
361 void RescheduleEndEpoch();
362
363 /**
364 * Function called in every endEpochEvent. It calls
365 * ShowResults() to write statistics to output files
366 * and ResetResults() to clear collected statistics.
367 */
368 void EndEpoch();
369
370 EventId m_endEpochEvent; //!< Event id for next end epoch event
371
372 FlowIdMap m_flowId; //!< List of FlowIds, ie. (RNTI, LCID) by (IMSI, LCID) pair
373
374 Uint32Map m_dlCellId; //!< List of DL CellIds by (IMSI, LCID) pair
375 Uint32Map m_dlTxPackets; //!< Number of DL TX Packets by (IMSI, LCID) pair
376 Uint32Map m_dlRxPackets; //!< Number of DL RX Packets by (IMSI, LCID) pair
377 Uint64Map m_dlTxData; //!< Amount of DL TX Data by (IMSI, LCID) pair
378 Uint64Map m_dlRxData; //!< Amount of DL RX Data by (IMSI, LCID) pair
379 Uint64StatsMap m_dlDelay; //!< DL delay by (IMSI, LCID) pair
380 Uint32StatsMap m_dlPduSize; //!< DL PDU Size by (IMSI, LCID) pair
381
382 Uint32Map m_ulCellId; //!< List of UL CellIds by (IMSI, LCID) pair
383 Uint32Map m_ulTxPackets; //!< Number of UL TX Packets by (IMSI, LCID) pair
384 Uint32Map m_ulRxPackets; //!< Number of UL RX Packets by (IMSI, LCID) pair
385 Uint64Map m_ulTxData; //!< Amount of UL TX Data by (IMSI, LCID) pair
386 Uint64Map m_ulRxData; //!< Amount of UL RX Data by (IMSI, LCID) pair
387 Uint64StatsMap m_ulDelay; //!< UL delay by (IMSI, LCID) pair
388 Uint32StatsMap m_ulPduSize; //!< UL PDU Size by (IMSI, LCID) pair
389
390 /**
391 * Start time of the on going epoch
392 */
394
395 /**
396 * Epoch duration
397 */
399
400 /**
401 * true if output files have not been opened yet
402 */
404
405 /**
406 * true if any output is pending
407 */
409
410 /**
411 * Protocol type, by default RLC
412 */
413 std::string m_protocolType;
414
415 /**
416 * Name of the file where the downlink PDCP statistics will be saved
417 */
419
420 /**
421 * Name of the file where the uplink PDCP statistics will be saved
422 */
424};
425
426} // namespace ns3
427
428#endif /* RADIO_BEARER_STATS_CALCULATOR_H_ */
An identifier for simulation events.
Definition event-id.h:45
Base class for ***StatsCalculator classes.
This class is an ns-3 trace sink that performs the calculation of PDU statistics for uplink and downl...
Uint32Map m_ulTxPackets
Number of UL TX Packets by (IMSI, LCID) pair.
Uint64StatsMap m_dlDelay
DL delay by (IMSI, LCID) pair.
std::vector< double > GetDlDelayStats(uint64_t imsi, uint8_t lcid)
Gets the downlink RLC to RLC statistics: average, min, max and standard deviation.
std::string m_protocolType
Protocol type, by default RLC.
Uint64Map m_dlRxData
Amount of DL RX Data by (IMSI, LCID) pair.
uint64_t GetDlTxData(uint64_t imsi, uint8_t lcid)
Gets the number of transmitted downlink data bytes.
uint32_t GetUlRxPackets(uint64_t imsi, uint8_t lcid)
Gets the number of received uplink packets.
~RadioBearerStatsCalculator() override
Class destructor.
uint32_t GetDlRxPackets(uint64_t imsi, uint8_t lcid)
Gets the number of received downlink data bytes.
std::vector< double > GetDlPduSizeStats(uint64_t imsi, uint8_t lcid)
Gets the downlink PDU size statistics: average, min, max and standard deviation.
void RescheduleEndEpoch()
Reschedules EndEpoch event.
Uint64StatsMap m_ulDelay
UL delay by (IMSI, LCID) pair.
uint32_t GetUlCellId(uint64_t imsi, uint8_t lcid)
Gets the attached Enb cellId.
Uint64Map m_ulRxData
Amount of UL RX Data by (IMSI, LCID) pair.
void EndEpoch()
Function called in every endEpochEvent.
Time m_startTime
Start time of the on going epoch.
std::vector< double > GetUlPduSizeStats(uint64_t imsi, uint8_t lcid)
Gets the uplink PDU size statistics: average, min, max and standard deviation.
Uint64Map m_ulTxData
Amount of UL TX Data by (IMSI, LCID) pair.
std::string GetUlPdcpOutputFilename()
Get the name of the file where the uplink PDCP statistics will be stored.
void ShowResults()
Called after each epoch to write collected statistics to output files.
uint32_t GetDlTxPackets(uint64_t imsi, uint8_t lcid)
Gets the number of transmitted downlink data bytes.
Uint32StatsMap m_ulPduSize
UL PDU Size by (IMSI, LCID) pair.
EventId m_endEpochEvent
Event id for next end epoch event.
void DoDispose() override
Destructor implementation.
void UlRxPdu(uint16_t cellId, uint64_t imsi, uint16_t rnti, uint8_t lcid, uint32_t packetSize, uint64_t delay)
Notifies the stats calculator that an uplink reception has occurred.
uint64_t GetUlRxData(uint64_t imsi, uint8_t lcid)
Gets the number of received uplink data bytes.
std::string m_dlPdcpOutputFilename
Name of the file where the downlink PDCP statistics will be saved.
void UlTxPdu(uint16_t cellId, uint64_t imsi, uint16_t rnti, uint8_t lcid, uint32_t packetSize)
Notifies the stats calculator that an uplink transmission has occurred.
uint64_t GetDlRxData(uint64_t imsi, uint8_t lcid)
Gets the number of received downlink data bytes.
Uint32Map m_dlRxPackets
Number of DL RX Packets by (IMSI, LCID) pair.
std::string GetUlOutputFilename()
Get the name of the file where the uplink statistics will be stored.
void DlTxPdu(uint16_t cellId, uint64_t imsi, uint16_t rnti, uint8_t lcid, uint32_t packetSize)
Notifies the stats calculator that an downlink transmission has occurred.
uint64_t GetUlTxData(uint64_t imsi, uint8_t lcid)
Gets the number of transmitted uplink data bytes.
std::string GetDlOutputFilename()
Get the name of the file where the downlink statistics will be stored.
std::string m_ulPdcpOutputFilename
Name of the file where the uplink PDCP statistics will be saved.
void DlRxPdu(uint16_t cellId, uint64_t imsi, uint16_t rnti, uint8_t lcid, uint32_t packetSize, uint64_t delay)
Notifies the stats calculator that an downlink reception has occurred.
void ResetResults()
Erases collected statistics.
void WriteDlResults(std::ofstream &outFile)
Writes collected statistics to DL output file and closes DL output file.
Uint32StatsMap m_dlPduSize
DL PDU Size by (IMSI, LCID) pair.
Uint32Map m_ulRxPackets
Number of UL RX Packets by (IMSI, LCID) pair.
bool m_firstWrite
true if output files have not been opened yet
std::string GetDlPdcpOutputFilename()
Get the name of the file where the downlink PDCP statistics will be stored.
uint32_t GetDlCellId(uint64_t imsi, uint8_t lcid)
Gets the attached Enb cellId.
double GetDlDelay(uint64_t imsi, uint8_t lcid)
Gets the downlink RLC to RLC delay.
void WriteUlResults(std::ofstream &outFile)
Writes collected statistics to UL output file and closes UL output file.
double GetUlDelay(uint64_t imsi, uint8_t lcid)
Gets the uplink RLC to RLC delay.
void SetUlPdcpOutputFilename(std::string outputFilename)
Set the name of the file where the uplink PDCP statistics will be stored.
Uint32Map m_ulCellId
List of UL CellIds by (IMSI, LCID) pair.
uint32_t GetUlTxPackets(uint64_t imsi, uint8_t lcid)
Gets the number of transmitted uplink packets.
Uint32Map m_dlCellId
List of DL CellIds by (IMSI, LCID) pair.
std::vector< double > GetUlDelayStats(uint64_t imsi, uint8_t lcid)
Gets the uplink RLC to RLC statistics: average, min, max and standard deviation.
Uint32Map m_dlTxPackets
Number of DL TX Packets by (IMSI, LCID) pair.
bool m_pendingOutput
true if any output is pending
static TypeId GetTypeId()
Register this type.
Uint64Map m_dlTxData
Amount of DL TX Data by (IMSI, LCID) pair.
void SetDlPdcpOutputFilename(std::string outputFilename)
Set the name of the file where the downlink PDCP statistics will be stored.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::map< ImsiLcidPair_t, double > DoubleMap
Container: (IMSI, LCID) pair, double.
std::map< ImsiLcidPair_t, LteFlowId_t > FlowIdMap
Container: (IMSI, LCID) pair, LteFlowId_t.
std::map< ImsiLcidPair_t, uint32_t > Uint32Map
Container: (IMSI, LCID) pair, uint32_t.
std::map< ImsiLcidPair_t, uint64_t > Uint64Map
Container: (IMSI, LCID) pair, uint64_t.
std::map< ImsiLcidPair_t, Ptr< MinMaxAvgTotalCalculator< uint64_t > > > Uint64StatsMap
Container: (IMSI, LCID) pair, uint64_t calculator.
std::map< ImsiLcidPair_t, Ptr< MinMaxAvgTotalCalculator< uint32_t > > > Uint32StatsMap
Container: (IMSI, LCID) pair, uint32_t calculator.
static const uint32_t packetSize
Packet size generated at the AP.