2 * Copyright 2011 Martin Mathieson
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifdef HAVE_SYS_TYPES_H
33 #include <sys/types.h>
37 #include <epan/packet.h>
38 #include <epan/packet_info.h>
40 #include <epan/stat_cmd_args.h>
41 #include <epan/dissectors/packet-mac-lte.h>
43 /**********************************************/
44 /* Table column identifiers and title strings */
53 UL_PADDING_PERCENT_COLUMN,
54 UL_RETX_FRAMES_COLUMN,
59 DL_CRC_HIGH_CODE_RATE_COLUMN,
60 DL_CRC_PDSCH_LOST_COLUMN,
61 DL_CRC_DUPLICATE_NONZERO_RV_COLUMN,
62 DL_RETX_FRAMES_COLUMN,
67 static const gchar *ue_titles[] = { " RNTI", " Type", "UEId",
68 "UL Frames", "UL Bytes", "UL Mb/sec", " UL Pad %", "UL ReTX",
69 "DL Frames", "DL Bytes", "DL Mb/sec", "DL CRC Fail", "DL CRC HCR", "DL CRC PDSCH Lost", "DL CRC DupNonZeroRV", "DL ReTX"};
72 /* Stats for one UE */
73 typedef struct mac_lte_row_data {
74 /* Key for matching this row */
79 gboolean is_predefined_data;
82 guint32 UL_raw_bytes; /* all bytes */
83 guint32 UL_total_bytes; /* payload */
84 nstime_t UL_time_start;
85 nstime_t UL_time_stop;
86 guint32 UL_padding_bytes;
87 guint32 UL_CRC_errors;
88 guint32 UL_retx_frames;
91 guint32 DL_total_bytes;
92 nstime_t DL_time_start;
93 nstime_t DL_time_stop;
94 guint32 DL_CRC_failures;
95 guint32 DL_CRC_high_code_rate;
96 guint32 DL_CRC_PDSCH_lost;
97 guint32 DL_CRC_Duplicate_NonZero_RV;
98 guint32 DL_retx_frames;
103 /* One row/UE in the UE table */
104 typedef struct mac_lte_ep {
105 struct mac_lte_ep* next;
106 struct mac_lte_row_data stats;
110 /* Common channel stats */
111 typedef struct mac_lte_common_stats {
120 guint16 max_ul_ues_in_tti;
121 guint16 max_dl_ues_in_tti;
122 } mac_lte_common_stats;
125 /* Top-level struct for MAC LTE statistics */
126 typedef struct mac_lte_stat_t {
128 mac_lte_common_stats common_stats;
130 /* Keep track of unique rntis & ueids */
131 guint8 used_ueids[65535];
132 guint8 used_rntis[65535];
133 guint16 number_of_ueids;
134 guint16 number_of_rntis;
136 mac_lte_ep_t *ep_list;
140 /* Reset the statistics window */
142 mac_lte_stat_reset(void *phs)
144 mac_lte_stat_t* mac_lte_stat = (mac_lte_stat_t *)phs;
145 mac_lte_ep_t* list = mac_lte_stat->ep_list;
147 /* Reset counts of unique ueids & rntis */
148 memset(mac_lte_stat->used_ueids, 0, 65535);
149 mac_lte_stat->number_of_ueids = 0;
150 memset(mac_lte_stat->used_rntis, 0, 65535);
151 mac_lte_stat->number_of_rntis = 0;
153 /* Zero common stats */
154 memset(&(mac_lte_stat->common_stats), 0, sizeof(mac_lte_common_stats));
160 mac_lte_stat->ep_list = NULL;
164 /* Allocate a mac_lte_ep_t struct to store info for new UE */
165 static mac_lte_ep_t* alloc_mac_lte_ep(struct mac_lte_tap_info *si, packet_info *pinfo _U_)
173 if (!(ep = g_malloc(sizeof(mac_lte_ep_t)))) {
177 /* Copy SI data into ep->stats */
178 ep->stats.rnti = si->rnti;
179 ep->stats.rnti_type = si->rntiType;
180 ep->stats.ueid = si->ueid;
182 /* Counts for new UE are all 0 */
183 ep->stats.UL_frames = 0;
184 ep->stats.DL_frames = 0;
185 ep->stats.UL_total_bytes = 0;
186 ep->stats.UL_raw_bytes = 0;
187 ep->stats.UL_padding_bytes = 0;
188 ep->stats.DL_total_bytes = 0;
189 ep->stats.UL_CRC_errors = 0;
190 ep->stats.DL_CRC_failures = 0;
191 ep->stats.DL_CRC_high_code_rate = 0;
192 ep->stats.DL_CRC_PDSCH_lost = 0;
193 ep->stats.DL_CRC_Duplicate_NonZero_RV = 0;
194 ep->stats.UL_retx_frames = 0;
195 ep->stats.DL_retx_frames = 0;
203 /* Update counts of unique rntis & ueids */
204 static void update_ueid_rnti_counts(guint16 rnti, guint16 ueid, mac_lte_stat_t *hs)
206 if (!hs->used_ueids[ueid]) {
207 hs->used_ueids[ueid] = TRUE;
208 hs->number_of_ueids++;
210 if (!hs->used_rntis[rnti]) {
211 hs->used_rntis[rnti] = TRUE;
212 hs->number_of_rntis++;
217 /* Process stat struct for a MAC LTE frame */
219 mac_lte_stat_packet(void *phs, packet_info *pinfo, epan_dissect_t *edt _U_,
222 /* Get reference to stat window instance */
223 mac_lte_stat_t *hs = (mac_lte_stat_t *)phs;
224 mac_lte_ep_t *tmp = NULL, *te = NULL;
226 /* Cast tap info struct */
227 struct mac_lte_tap_info *si = (struct mac_lte_tap_info *)phi;
233 hs->common_stats.all_frames++;
235 /* For common channels, just update global counters */
236 switch (si->rntiType) {
238 hs->common_stats.pch_frames++;
239 hs->common_stats.pch_bytes += si->single_number_of_bytes;
243 hs->common_stats.bch_frames++;
244 hs->common_stats.bch_bytes += si->single_number_of_bytes;
247 hs->common_stats.rar_frames++;
248 hs->common_stats.rar_entries += si->number_of_rars;
252 /* Drop through for per-UE update */
260 /* Check max UEs/tti counter */
261 switch (si->direction) {
262 case DIRECTION_UPLINK:
263 hs->common_stats.max_ul_ues_in_tti =
264 MAX(hs->common_stats.max_ul_ues_in_tti, si->ueInTTI);
266 case DIRECTION_DOWNLINK:
267 hs->common_stats.max_dl_ues_in_tti =
268 MAX(hs->common_stats.max_dl_ues_in_tti, si->ueInTTI);
272 /* For per-UE data, must create a new row if none already existing */
274 /* Allocate new list */
275 hs->ep_list = alloc_mac_lte_ep(si, pinfo);
276 /* Make it the first/only entry */
279 /* Update counts of unique ueids & rntis */
280 update_ueid_rnti_counts(si->rnti, si->ueid, hs);
282 /* Look among existing rows for this RNTI */
283 for (tmp = hs->ep_list;(tmp != NULL); tmp = tmp->next) {
284 /* Match only by RNTI and UEId together */
285 if ((tmp->stats.rnti == si->rnti) &&
286 (tmp->stats.ueid == si->ueid)){
292 /* Not found among existing, so create a new one anyway */
294 if ((te = alloc_mac_lte_ep(si, pinfo))) {
295 /* Add new item to end of list */
296 mac_lte_ep_t *p = hs->ep_list;
303 /* Update counts of unique ueids & rntis */
304 update_ueid_rnti_counts(si->rnti, si->ueid, hs);
309 /* Really should have a row pointer by now */
314 /* Update entry with details from si */
315 te->stats.rnti = si->rnti;
316 te->stats.is_predefined_data = si->isPredefinedData;
319 if (si->direction == DIRECTION_UPLINK) {
321 te->stats.UL_retx_frames++;
325 if (si->crcStatusValid && (si->crcStatus != crc_success)) {
326 te->stats.UL_CRC_errors++;
330 /* Update time range */
331 if (te->stats.UL_frames == 0) {
332 te->stats.UL_time_start = si->time;
334 te->stats.UL_time_stop = si->time;
336 te->stats.UL_frames++;
338 te->stats.UL_raw_bytes += si->raw_length;
339 te->stats.UL_padding_bytes += si->padding_bytes;
341 if (si->isPredefinedData) {
342 te->stats.UL_total_bytes += si->single_number_of_bytes;
345 te->stats.UL_total_bytes += si->single_number_of_bytes;
352 te->stats.DL_retx_frames++;
356 if (si->crcStatusValid && (si->crcStatus != crc_success)) {
357 switch (si->crcStatus) {
359 te->stats.DL_CRC_failures++;
361 case crc_high_code_rate:
362 te->stats.DL_CRC_high_code_rate++;
365 te->stats.DL_CRC_PDSCH_lost++;
367 case crc_duplicate_nonzero_rv:
368 te->stats.DL_CRC_Duplicate_NonZero_RV++;
372 /* Something went wrong! */
378 /* Update time range */
379 if (te->stats.DL_frames == 0) {
380 te->stats.DL_time_start = si->time;
382 te->stats.DL_time_stop = si->time;
384 te->stats.DL_frames++;
386 if (si->isPredefinedData) {
387 te->stats.DL_total_bytes += si->single_number_of_bytes;
390 te->stats.DL_total_bytes += si->single_number_of_bytes;
399 /* Calculate and return a bandwidth figure, in Mbs */
400 static float calculate_bw(nstime_t *start_time, nstime_t *stop_time, guint32 bytes)
402 if (memcmp(start_time, stop_time, sizeof(nstime_t)) != 0) {
403 float elapsed_ms = (((float)stop_time->secs - (float)start_time->secs) * 1000) +
404 (((float)stop_time->nsecs - (float)start_time->nsecs) / 1000000);
405 return ((bytes * 8) / elapsed_ms) / 1000;
413 /* Output the accumulated stats */
415 mac_lte_stat_draw(void *phs)
418 guint16 number_of_ues = 0;
420 /* Deref the struct */
421 mac_lte_stat_t *hs = (mac_lte_stat_t *)phs;
422 mac_lte_ep_t* list = hs->ep_list, *tmp = 0;
425 printf("System data:\n");
426 printf("============\n");
427 printf("Max UL UEs/TTI: %u Max DL UEs/TTI: %u\n\n",
428 hs->common_stats.max_ul_ues_in_tti, hs->common_stats.max_dl_ues_in_tti);
430 /* Common channel data */
431 printf("Common channel data:\n");
432 printf("====================\n");
433 printf("BCH Frames: %u ", hs->common_stats.bch_frames);
434 printf("BCH Bytes: %u ", hs->common_stats.bch_bytes);
435 printf("PCH Frames: %u ", hs->common_stats.pch_frames);
436 printf("PCH Bytes: %u ", hs->common_stats.pch_bytes);
437 printf("RAR Frames: %u ", hs->common_stats.rar_frames);
438 printf("RAR Entries: %u\n\n", hs->common_stats.rar_entries);
441 /* Per-UE table entries */
443 /* Set title to show how many UEs in table */
444 for (tmp = list; (tmp!=NULL); tmp=tmp->next, number_of_ues++);
445 printf("UL/DL-SCH data (%u entries - %u unique RNTIs, %u unique UEIds):\n",
446 number_of_ues, hs->number_of_rntis, hs->number_of_ueids);
447 printf("==================================================================\n");
449 /* Show column titles */
450 for (i=0; i < NUM_UE_COLUMNS; i++) {
451 printf("%s ", ue_titles[i]);
455 /* Write a row for each UE */
456 for (tmp = list; tmp; tmp=tmp->next) {
457 /* Calculate bandwidth */
458 float UL_bw = calculate_bw(&tmp->stats.UL_time_start,
459 &tmp->stats.UL_time_stop,
460 tmp->stats.UL_total_bytes);
461 float DL_bw = calculate_bw(&tmp->stats.DL_time_start,
462 &tmp->stats.DL_time_stop,
463 tmp->stats.DL_total_bytes);
465 printf("%5u %7s %5u %10u %9u %10f %10f %8u %10u %9u %10f %12u %11u %18u %20u %8u\n",
467 (tmp->stats.rnti_type == C_RNTI) ? "C-RNTI" : "SPS-RNTI",
469 tmp->stats.UL_frames,
470 tmp->stats.UL_total_bytes,
472 tmp->stats.UL_total_bytes ?
473 (((float)tmp->stats.UL_padding_bytes / (float)tmp->stats.UL_raw_bytes) * 100.0) :
475 tmp->stats.UL_retx_frames,
476 tmp->stats.DL_frames,
477 tmp->stats.DL_total_bytes,
479 tmp->stats.DL_CRC_failures,
480 tmp->stats.DL_CRC_high_code_rate,
481 tmp->stats.DL_CRC_PDSCH_lost,
482 tmp->stats.DL_CRC_Duplicate_NonZero_RV,
483 tmp->stats.DL_retx_frames);
487 /* Create a new MAC LTE stats struct */
488 static void mac_lte_stat_init(const char *optarg, void *userdata _U_)
491 const char *filter = NULL;
492 GString *error_string;
494 /* Check for a filter string */
495 if (strncmp(optarg, "mac-lte,stat,", 13) == 0) {
496 /* Skip those characters from filter to display */
497 filter = optarg + 13;
505 hs = g_malloc(sizeof(mac_lte_stat_t));
508 error_string = register_tap_listener("mac-lte", hs,
514 g_string_free(error_string, TRUE);
521 /* Register this tap listener (need void on own so line register function found) */
523 register_tap_listener_mac_lte_stat(void)
525 register_stat_cmd_arg("mac-lte,stat", mac_lte_stat_init, NULL);