diff options
author | Gerald Combs <gerald@wireshark.org> | 2015-08-31 16:06:33 -0700 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2015-09-01 01:01:32 +0000 |
commit | 54d2ff1c3e74e57a59a57b9b3fdeb50e64cceb0f (patch) | |
tree | 7ed6e6d0b300803378f549d3e310d4aec49ed08c /epan/dissectors | |
parent | 377d215e0fd1022a093fa44b32f396948e70c119 (diff) |
Convert the WSP stats to generic stat API.
Add support for multiple tables to SimpleStatisticsDialog.
Change-Id: I843d901db092d2f2856d3d1a16f29f85fb41374b
Reviewed-on: https://code.wireshark.org/review/10339
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'epan/dissectors')
-rw-r--r-- | epan/dissectors/packet-wsp.c | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/epan/dissectors/packet-wsp.c b/epan/dissectors/packet-wsp.c index 179feccd7c..64de613a9a 100644 --- a/epan/dissectors/packet-wsp.c +++ b/epan/dissectors/packet-wsp.c @@ -51,6 +51,7 @@ #include "packet-wsp.h" /* Statistics (see doc/README.tapping) */ +#include <epan/stat_tap_ui.h> #include <epan/tap.h> void proto_register_wsp(void); @@ -5539,6 +5540,138 @@ add_multipart_data (proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo) } } +/* TAP STAT INFO */ +typedef enum +{ + MESSAGE_TYPE_COLUMN = 0, + PACKET_COLUMN +} wsp_stat_columns; + +static stat_tap_table_item wsp_stat_fields[] = { + {TABLE_ITEM_STRING, TAP_ALIGN_LEFT, "Type / Code", "%-25s"}, + {TABLE_ITEM_UINT, TAP_ALIGN_RIGHT, "Packets", "%d"} + }; + +static int unknown_pt_idx; +static int unknown_sc_idx; + +static void wsp_stat_init(new_stat_tap_ui* new_stat, new_stat_tap_gui_init_cb gui_callback, void* gui_data) +{ + int num_fields = sizeof(wsp_stat_fields)/sizeof(stat_tap_table_item); + new_stat_tap_table* pt_table = new_stat_tap_init_table("PDU Types", num_fields, 0, NULL, gui_callback, gui_data); + stat_tap_table_item_type pt_items[sizeof(wsp_stat_fields)/sizeof(stat_tap_table_item)]; + new_stat_tap_table* sc_table = new_stat_tap_init_table("Status Codes", num_fields, 0, NULL, gui_callback, gui_data); + stat_tap_table_item_type sc_items[sizeof(wsp_stat_fields)/sizeof(stat_tap_table_item)]; + int table_idx; + + new_stat_tap_add_table(new_stat, pt_table); + new_stat_tap_add_table(new_stat, sc_table); + + /* Add a row for each PDU type and status code */ + table_idx = 0; + memset(pt_items, 0, sizeof(pt_items)); + pt_items[MESSAGE_TYPE_COLUMN].type = TABLE_ITEM_STRING; + pt_items[PACKET_COLUMN].type = TABLE_ITEM_UINT; + while (wsp_vals_pdu_type[table_idx].strptr) + { + pt_items[MESSAGE_TYPE_COLUMN].value.string_value = g_strdup(wsp_vals_pdu_type[table_idx].strptr); + pt_items[MESSAGE_TYPE_COLUMN].user_data.uint_value = wsp_vals_pdu_type[table_idx].value; + + new_stat_tap_init_table_row(pt_table, table_idx, num_fields, pt_items); + table_idx++; + } + pt_items[MESSAGE_TYPE_COLUMN].value.string_value = g_strdup("Unknown PDU type"); + pt_items[MESSAGE_TYPE_COLUMN].user_data.uint_value = 0; + new_stat_tap_init_table_row(pt_table, table_idx, num_fields, pt_items); + unknown_pt_idx = table_idx; + + table_idx = 0; + memset(sc_items, 0, sizeof(sc_items)); + sc_items[MESSAGE_TYPE_COLUMN].type = TABLE_ITEM_STRING; + sc_items[PACKET_COLUMN].type = TABLE_ITEM_UINT; + while (wsp_vals_status[table_idx].strptr) + { + sc_items[MESSAGE_TYPE_COLUMN].value.string_value = g_strdup(wsp_vals_status[table_idx].strptr); + sc_items[MESSAGE_TYPE_COLUMN].user_data.uint_value = wsp_vals_status[table_idx].value; + + new_stat_tap_init_table_row(sc_table, table_idx, num_fields, sc_items); + table_idx++; + } + sc_items[MESSAGE_TYPE_COLUMN].value.string_value = g_strdup("Unknown status code"); + sc_items[MESSAGE_TYPE_COLUMN].user_data.uint_value = 0; + new_stat_tap_init_table_row(sc_table, table_idx, num_fields, sc_items); + unknown_sc_idx = table_idx; +} + +static gboolean +wsp_stat_packet(void *tapdata, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *wiv_ptr) +{ + new_stat_data_t* stat_data = (new_stat_data_t*)tapdata; + const wsp_info_value_t *value = (const wsp_info_value_t *)wiv_ptr; + new_stat_tap_table *pt_table, *sc_table; + guint element; + stat_tap_table_item_type* item_data; + gboolean found; + + pt_table = g_array_index(stat_data->new_stat_tap_data->tables, new_stat_tap_table*, 0); + sc_table = g_array_index(stat_data->new_stat_tap_data->tables, new_stat_tap_table*, 1); + + found = FALSE; + for (element = 0; element < pt_table->num_elements; element++) { + item_data = new_stat_tap_get_field_data(pt_table, element, MESSAGE_TYPE_COLUMN); + if (value->pdut == item_data->user_data.uint_value) { + found = TRUE; + break; + } + } + if (!found) { + element = unknown_pt_idx; + } + item_data = new_stat_tap_get_field_data(pt_table, element, PACKET_COLUMN); + item_data->value.uint_value++; + new_stat_tap_set_field_data(pt_table, element, PACKET_COLUMN, item_data); + + if (value->status_code != 0) { + found = FALSE; + for (element = 0; element < sc_table->num_elements; element++) { + item_data = new_stat_tap_get_field_data(sc_table, element, MESSAGE_TYPE_COLUMN); + if (value->status_code == (int) item_data->user_data.uint_value) { + found = TRUE; + break; + } + } + if (!found) { + element = unknown_sc_idx; + } + item_data = new_stat_tap_get_field_data(sc_table, element, PACKET_COLUMN); + item_data->value.uint_value++; + new_stat_tap_set_field_data(sc_table, element, PACKET_COLUMN, item_data); + } + + return TRUE; +} + +static void +wsp_stat_reset(new_stat_tap_table* table) +{ + guint element; + stat_tap_table_item_type* item_data; + + for (element = 0; element < table->num_elements; element++) + { + item_data = new_stat_tap_get_field_data(table, element, PACKET_COLUMN); + item_data->value.uint_value = 0; + new_stat_tap_set_field_data(table, element, PACKET_COLUMN, item_data); + } +} + +static void +wsp_stat_free_table_item(new_stat_tap_table* table _U_, guint row _U_, guint column, stat_tap_table_item_type* field_data) +{ + if (column != MESSAGE_TYPE_COLUMN) return; + g_free((char*)field_data->value.string_value); + field_data->value.string_value = NULL; +} /* Register the protocol with Wireshark */ void @@ -7174,6 +7307,26 @@ proto_register_sir(void) &ett_sir /* Session Initiation Request */ }; + static tap_param wsp_stat_params[] = { + { PARAM_FILTER, "filter", "Filter", NULL, TRUE } + }; + + static new_stat_tap_ui wsp_stat_table = { + REGISTER_STAT_GROUP_TELEPHONY, + "WAP-WSP Packet Counter", + "wsp", + "wsp,stat", + wsp_stat_init, + wsp_stat_packet, + wsp_stat_reset, + wsp_stat_free_table_item, + NULL, + sizeof(wsp_stat_fields)/sizeof(stat_tap_table_item), wsp_stat_fields, + sizeof(wsp_stat_params)/sizeof(tap_param), wsp_stat_params, + NULL + }; + + /* Register the dissector */ proto_sir = proto_register_protocol( "WAP Session Initiation Request", /* protocol name for use by wireshark */ @@ -7187,6 +7340,9 @@ proto_register_sir(void) /* Register header fields and protocol subtrees */ proto_register_field_array(proto_sir, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett)); + + register_new_stat_tap_ui(&wsp_stat_table); + } void |