aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2015-06-23 08:53:17 -0400
committerMichael Mann <mmann78@netscape.net>2015-07-03 23:08:28 +0000
commita8ff1e2778b22ca55db752264eaf864d720ca8dc (patch)
tree1b7182449a95437aa6a0419519c92fcc08ca3aa0 /epan/dissectors
parent09ea473cee9ef37335f2ef8247da94bc71d12bba (diff)
Create very basic "generic" stat tap API to create a "GUI" independent table.
A few sample tap/dissectors (ANSI/A, ANSI MAP) are also included to test the API. The "GUI output" is a bit raw and could use some "prettying up", but all the basic hooks are there. Telephony "stat grouping" needs to be better alphabetized to properly populate menu (on GTK, probably Qt) Change-Id: I98514171f69c4ab3a304dccb26c71d629703c9ab Reviewed-on: https://code.wireshark.org/review/9110 Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/dissectors')
-rw-r--r--epan/dissectors/packet-ansi_a.c163
-rw-r--r--epan/dissectors/packet-ansi_map.c126
2 files changed, 284 insertions, 5 deletions
diff --git a/epan/dissectors/packet-ansi_a.c b/epan/dissectors/packet-ansi_a.c
index 7f68df2002..f402ab05de 100644
--- a/epan/dissectors/packet-ansi_a.c
+++ b/epan/dissectors/packet-ansi_a.c
@@ -44,6 +44,7 @@
#include <epan/exceptions.h>
#include <epan/prefs.h>
#include <epan/tap.h>
+#include <epan/stat_tap_ui.h>
#include <epan/strutil.h>
#include <epan/expert.h>
#include <epan/to_str.h>
@@ -10746,6 +10747,135 @@ dissect_sip_dtap_bsmap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
}
+/* TAP STAT INFO */
+typedef enum
+{
+ IEI_COLUMN = 0,
+ MESSAGE_NAME_COLUMN,
+ COUNT_COLUMN
+} ansi_a_stat_columns;
+
+static stat_tap_table_item dtap_stat_fields[] = {{TABLE_ITEM_UINT, TAP_ALIGN_RIGHT, "IEI", "0x%02x "}, {TABLE_ITEM_STRING, TAP_ALIGN_LEFT, "Message Name", "%-50s"},
+ {TABLE_ITEM_UINT, TAP_ALIGN_RIGHT, "Count", "%d"}};
+
+void ansi_a_dtap_stat_init(new_stat_tap_ui* new_stat, new_stat_tap_gui_init_cb gui_callback, void* gui_data)
+{
+ int num_fields = sizeof(dtap_stat_fields)/sizeof(stat_tap_table_item);
+ new_stat_tap_table* table = new_stat_tap_init_table("ANSI A-I/F DTAP Statistics", num_fields, 0, NULL, gui_callback, gui_data);
+ int i = 0;
+ stat_tap_table_item_type items[sizeof(dtap_stat_fields)/sizeof(stat_tap_table_item)];
+
+ new_stat_tap_add_table(new_stat, table);
+
+ /* Add a fow for each value type */
+ while (ansi_a_dtap_strings[i].strptr)
+ {
+ items[IEI_COLUMN].type = TABLE_ITEM_UINT;
+ items[IEI_COLUMN].value.uint_value = ansi_a_dtap_strings[i].value;
+ items[MESSAGE_NAME_COLUMN].type = TABLE_ITEM_STRING;
+ items[MESSAGE_NAME_COLUMN].value.string_value = ansi_a_dtap_strings[i].strptr;
+ items[COUNT_COLUMN].type = TABLE_ITEM_UINT;
+ items[COUNT_COLUMN].value.uint_value = 0;
+
+ new_stat_tap_init_table_row(table, i, num_fields, items);
+ i++;
+ }
+}
+
+static gboolean
+ansi_a_dtap_stat_packet(void *tapdata, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *data)
+{
+ new_stat_data_t* stat_data = (new_stat_data_t*)tapdata;
+ const ansi_a_tap_rec_t *data_p = (const ansi_a_tap_rec_t *)data;
+ stat_tap_table_item_type* dtap_data;
+ new_stat_tap_table* table;
+ guint i = 0, idx;
+
+ if (data_p->pdu_type == BSSAP_PDU_TYPE_DTAP)
+ {
+ if (my_try_val_to_str_idx(data_p->message_type, ansi_a_dtap_strings, &idx) == NULL)
+ return FALSE;
+
+ table = g_array_index(stat_data->new_stat_tap_data->tables, new_stat_tap_table*, i);
+
+ dtap_data = new_stat_tap_get_field_data(table, data_p->message_type, COUNT_COLUMN);
+ dtap_data->value.uint_value++;
+ new_stat_tap_set_field_data(table, data_p->message_type, COUNT_COLUMN, dtap_data);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+ansi_a_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, COUNT_COLUMN);
+ item_data->value.uint_value = 0;
+ new_stat_tap_set_field_data(table, element, COUNT_COLUMN, item_data);
+ }
+
+}
+
+static stat_tap_table_item bsmap_stat_fields[] = {{TABLE_ITEM_UINT, TAP_ALIGN_RIGHT, "IEI", "0x%02x "}, {TABLE_ITEM_STRING, TAP_ALIGN_LEFT, "Message Name", "%-50s"},
+ {TABLE_ITEM_UINT, TAP_ALIGN_RIGHT, "Count", "%d"}};
+
+void ansi_a_bsmap_stat_init(new_stat_tap_ui* new_stat, new_stat_tap_gui_init_cb gui_callback, void* gui_data)
+{
+ int num_fields = sizeof(bsmap_stat_fields)/sizeof(stat_tap_table_item);
+ new_stat_tap_table* table = new_stat_tap_init_table("ANSI A-I/F BSMAP Statistics", num_fields, 0, NULL, gui_callback, gui_data);
+ int i = 0;
+ stat_tap_table_item_type items[sizeof(bsmap_stat_fields)/sizeof(stat_tap_table_item)];
+
+ new_stat_tap_add_table(new_stat, table);
+
+ /* Add a fow for each value type */
+ while (ansi_a_bsmap_strings[i].strptr)
+ {
+ items[IEI_COLUMN].type = TABLE_ITEM_UINT;
+ items[IEI_COLUMN].value.uint_value = ansi_a_bsmap_strings[i].value;
+ items[MESSAGE_NAME_COLUMN].type = TABLE_ITEM_STRING;
+ items[MESSAGE_NAME_COLUMN].value.string_value = ansi_a_bsmap_strings[i].strptr;
+ items[COUNT_COLUMN].type = TABLE_ITEM_UINT;
+ items[COUNT_COLUMN].value.uint_value = 0;
+
+ new_stat_tap_init_table_row(table, i, num_fields, items);
+ i++;
+ }
+}
+
+static gboolean
+ansi_a_bsmap_stat_packet(void *tapdata, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *data)
+{
+ new_stat_data_t* stat_data = (new_stat_data_t*)tapdata;
+ const ansi_a_tap_rec_t *data_p = (const ansi_a_tap_rec_t *)data;
+ stat_tap_table_item_type* dtap_data;
+ new_stat_tap_table* table;
+ guint i = 0, idx;
+
+ if (data_p->pdu_type == BSSAP_PDU_TYPE_BSMAP)
+ {
+ if (my_try_val_to_str_idx(data_p->message_type, ansi_a_bsmap_strings, &idx) == NULL)
+ return FALSE;
+
+ table = g_array_index(stat_data->new_stat_tap_data->tables, new_stat_tap_table*, i);
+
+ dtap_data = new_stat_tap_get_field_data(table, data_p->message_type, COUNT_COLUMN);
+ dtap_data->value.uint_value++;
+ new_stat_tap_set_field_data(table, data_p->message_type, COUNT_COLUMN, dtap_data);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/* Register the protocol with Wireshark */
void
proto_register_ansi_a(void)
@@ -12729,6 +12859,36 @@ proto_register_ansi_a(void)
gint **ett;
gint ett_len = (NUM_INDIVIDUAL_ELEMS+MAX_NUM_DTAP_MSG+MAX_NUM_BSMAP_MSG+MAX_NUM_ELEM_1+NUM_FWD_MS_INFO_REC+NUM_REV_MS_INFO_REC) * sizeof(gint *);
+ static new_stat_tap_ui dtap_stat_table = {
+ REGISTER_STAT_GROUP_TELEPHONY,
+ "ANSI A-I/F DTAP Statistics",
+ "ansi_a",
+ "ansi_a,dtap",
+ ansi_a_dtap_stat_init,
+ ansi_a_dtap_stat_packet,
+ ansi_a_stat_reset,
+ NULL,
+ NULL,
+ sizeof(dtap_stat_fields)/sizeof(stat_tap_table_item), dtap_stat_fields,
+ 0, NULL,
+ NULL
+ };
+
+ static new_stat_tap_ui bsmap_stat_table = {
+ REGISTER_STAT_GROUP_TELEPHONY,
+ "ANSI A-I/F BSMAP Statistics",
+ "ansi_a",
+ "ansi_a,bsmap",
+ ansi_a_bsmap_stat_init,
+ ansi_a_bsmap_stat_packet,
+ ansi_a_stat_reset,
+ NULL,
+ NULL,
+ sizeof(bsmap_stat_fields)/sizeof(stat_tap_table_item), bsmap_stat_fields,
+ 0, NULL,
+ NULL
+ };
+
/*
* XXX - at least one version of the HP C compiler apparently doesn't
* recognize constant expressions using the "?" operator as being
@@ -12845,6 +13005,9 @@ proto_register_ansi_a(void)
&global_a_info_display);
g_free(ett);
+
+ register_new_stat_tap_ui(&dtap_stat_table);
+ register_new_stat_tap_ui(&bsmap_stat_table);
}
diff --git a/epan/dissectors/packet-ansi_map.c b/epan/dissectors/packet-ansi_map.c
index f06e116f0d..0dfb67e371 100644
--- a/epan/dissectors/packet-ansi_map.c
+++ b/epan/dissectors/packet-ansi_map.c
@@ -96,6 +96,7 @@
#include <epan/prefs.h>
#include <epan/expert.h>
#include <epan/tap.h>
+#include <epan/stat_tap_ui.h>
#include <epan/asn1.h>
#include "packet-ber.h"
@@ -883,7 +884,7 @@ static int hf_ansi_map_interSystemSMSDeliveryPointToPointRes = -1; /* InterSyst
static int hf_ansi_map_qualificationRequest2Res = -1; /* QualificationRequest2Res */
/*--- End of included file: packet-ansi_map-hf.c ---*/
-#line 327 "../../asn1/ansi_map/packet-ansi_map-template.c"
+#line 328 "../../asn1/ansi_map/packet-ansi_map-template.c"
/* Initialize the subtree pointers */
static gint ett_ansi_map = -1;
@@ -1143,7 +1144,7 @@ static gint ett_ansi_map_InvokeData = -1;
static gint ett_ansi_map_ReturnData = -1;
/*--- End of included file: packet-ansi_map-ett.c ---*/
-#line 359 "../../asn1/ansi_map/packet-ansi_map-template.c"
+#line 360 "../../asn1/ansi_map/packet-ansi_map-template.c"
static expert_field ei_ansi_map_nr_not_used = EI_INIT;
static expert_field ei_ansi_map_unknown_invokeData_blob = EI_INIT;
@@ -15279,7 +15280,7 @@ dissect_ansi_map_QualificationRequest2Res(gboolean implicit_tag _U_, tvbuff_t *t
/*--- End of included file: packet-ansi_map-fn.c ---*/
-#line 3634 "../../asn1/ansi_map/packet-ansi_map-template.c"
+#line 3635 "../../asn1/ansi_map/packet-ansi_map-template.c"
/*
* 6.5.2.dk N.S0013-0 v 1.0,X.S0004-550-E v1.0 2.301
@@ -16097,6 +16098,104 @@ static void range_add_callback(guint32 ssn)
}
}
+/* TAP STAT INFO */
+typedef enum
+{
+ OPCODE_COLUMN = 0,
+ OPERATION_COLUMN,
+ COUNT_COLUMN,
+ TOTAL_BYTES_COLUMN,
+ AVG_BYTES_COLUMN
+} ansi_map_stat_columns;
+
+static stat_tap_table_item stat_fields[] = {{TABLE_ITEM_UINT, TAP_ALIGN_RIGHT, "OpCode", "0x%02x"}, {TABLE_ITEM_STRING, TAP_ALIGN_LEFT, "Operation Name", "%-50s"},
+ {TABLE_ITEM_UINT, TAP_ALIGN_RIGHT, "Count", " %d "}, {TABLE_ITEM_UINT, TAP_ALIGN_RIGHT, "Total Bytes", " %d "},
+ {TABLE_ITEM_FLOAT, TAP_ALIGN_RIGHT, "Avg Bytes", " %8.2f "}};
+
+void ansi_map_stat_init(new_stat_tap_ui* new_stat, new_stat_tap_gui_init_cb gui_callback, void* gui_data)
+{
+ int num_fields = sizeof(stat_fields)/sizeof(stat_tap_table_item);
+ new_stat_tap_table* table = new_stat_tap_init_table("ANSI MAP Operation Statistics", num_fields, 0, "ansi_map.op_code", gui_callback, gui_data);
+ int i = 0;
+ stat_tap_table_item_type items[sizeof(stat_fields)/sizeof(stat_tap_table_item)];
+
+ new_stat_tap_add_table(new_stat, table);
+
+ /* Add a fow for each value type */
+ while (ansi_map_opr_code_strings[i].strptr)
+ {
+ items[OPCODE_COLUMN].type = TABLE_ITEM_UINT;
+ items[OPCODE_COLUMN].value.uint_value = ansi_map_opr_code_strings[i].value;
+ items[OPERATION_COLUMN].type = TABLE_ITEM_STRING;
+ items[OPERATION_COLUMN].value.string_value = ansi_map_opr_code_strings[i].strptr;
+ items[COUNT_COLUMN].type = TABLE_ITEM_UINT;
+ items[COUNT_COLUMN].value.uint_value = 0;
+ items[TOTAL_BYTES_COLUMN].type = TABLE_ITEM_UINT;
+ items[TOTAL_BYTES_COLUMN].value.uint_value = 0;
+ items[AVG_BYTES_COLUMN].type = TABLE_ITEM_FLOAT;
+ items[AVG_BYTES_COLUMN].value.float_value = 0.0;
+
+ new_stat_tap_init_table_row(table, ansi_map_opr_code_strings[i].value, num_fields, items);
+ i++;
+ }
+}
+
+
+static gboolean
+ansi_map_stat_packet(void *tapdata, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *data)
+{
+ new_stat_data_t* stat_data = (new_stat_data_t*)tapdata;
+ const ansi_map_tap_rec_t *data_p = (const ansi_map_tap_rec_t *)data;
+ new_stat_tap_table* table;
+ stat_tap_table_item_type* item_data;
+ guint i = 0, count, total_bytes;
+
+ /* Only tracking field values we know */
+ if (try_val_to_str(data_p->message_type, ansi_map_opr_code_strings) == NULL)
+ return FALSE;
+
+ table = g_array_index(stat_data->new_stat_tap_data->tables, new_stat_tap_table*, i);
+
+ item_data = new_stat_tap_get_field_data(table, data_p->message_type, COUNT_COLUMN);
+ item_data->value.uint_value++;
+ count = item_data->value.uint_value;
+ new_stat_tap_set_field_data(table, data_p->message_type, COUNT_COLUMN, item_data);
+
+ item_data = new_stat_tap_get_field_data(table, data_p->message_type, TOTAL_BYTES_COLUMN);
+ item_data->value.uint_value += data_p->size;
+ total_bytes = item_data->value.uint_value;
+ new_stat_tap_set_field_data(table, data_p->message_type, TOTAL_BYTES_COLUMN, item_data);
+
+ item_data = new_stat_tap_get_field_data(table, data_p->message_type, AVG_BYTES_COLUMN);
+ item_data->value.float_value = (float)total_bytes/(float)count;
+ new_stat_tap_set_field_data(table, data_p->message_type, AVG_BYTES_COLUMN, item_data);
+
+ return TRUE;
+}
+
+static void
+ansi_map_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, COUNT_COLUMN);
+ item_data->value.uint_value = 0;
+ new_stat_tap_set_field_data(table, element, COUNT_COLUMN, item_data);
+
+ item_data = new_stat_tap_get_field_data(table, element, TOTAL_BYTES_COLUMN);
+ item_data->value.uint_value = 0;
+ new_stat_tap_set_field_data(table, element, TOTAL_BYTES_COLUMN, item_data);
+
+ item_data = new_stat_tap_get_field_data(table, element, AVG_BYTES_COLUMN);
+ item_data->value.float_value = 0.0;
+ new_stat_tap_set_field_data(table, element, AVG_BYTES_COLUMN, item_data);
+ }
+
+}
+
void
proto_reg_handoff_ansi_map(void)
{
@@ -19129,7 +19228,7 @@ void proto_register_ansi_map(void) {
NULL, HFILL }},
/*--- End of included file: packet-ansi_map-hfarr.c ---*/
-#line 5291 "../../asn1/ansi_map/packet-ansi_map-template.c"
+#line 5390 "../../asn1/ansi_map/packet-ansi_map-template.c"
};
/* List of subtrees */
@@ -19390,7 +19489,7 @@ void proto_register_ansi_map(void) {
&ett_ansi_map_ReturnData,
/*--- End of included file: packet-ansi_map-ettarr.c ---*/
-#line 5324 "../../asn1/ansi_map/packet-ansi_map-template.c"
+#line 5423 "../../asn1/ansi_map/packet-ansi_map-template.c"
};
static ei_register_info ei[] = {
@@ -19408,6 +19507,22 @@ void proto_register_ansi_map(void) {
{NULL, NULL, -1}
};
+ /* TAP STAT INFO */
+ static new_stat_tap_ui stat_table = {
+ REGISTER_STAT_GROUP_TELEPHONY,
+ "ANSI Map Operation Statistics",
+ "ansi_map",
+ "ansi_map",
+ ansi_map_stat_init,
+ ansi_map_stat_packet,
+ ansi_map_stat_reset,
+ NULL,
+ NULL,
+ sizeof(stat_fields)/sizeof(stat_tap_table_item), stat_fields,
+ 0, NULL,
+ NULL
+ };
+
/* Register protocol */
proto_ansi_map = proto_register_protocol(PNAME, PSNAME, PFNAME);
/* Register fields and subtrees */
@@ -19448,4 +19563,5 @@ void proto_register_ansi_map(void) {
&ansi_map_response_matching_type, ansi_map_response_matching_type_values, FALSE);
register_init_routine(&ansi_map_init_protocol);
+ register_new_stat_tap_ui(&stat_table);
}