Witness: enum witness_notifyResponse_type
[wireshark-wip.git] / ui / gtk / gtp_stat.c
blob17e6a15cc950e9863e9601fecf7f774d6d07e638
1 /* gtp_stat.c
2 * gtp_stat 2008 Kari Tiirikainen
3 * Largely based on ldap_stat by Ronnie Sahlberg, all mistakes added by KTi
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "config.h"
28 #include <string.h>
30 #include <gtk/gtk.h>
32 #include <epan/packet_info.h>
33 #include <epan/epan.h>
34 #include <epan/value_string.h>
35 #include <epan/tap.h>
36 #include <epan/dissectors/packet-gtp.h>
38 #include "ui/simple_dialog.h"
39 #include "../file.h"
40 #include "../stat_menu.h"
42 #include "ui/gtk/gui_utils.h"
43 #include "ui/gtk/dlg_utils.h"
44 #include "ui/gtk/service_response_time_table.h"
45 #include "ui/gtk/tap_param_dlg.h"
46 #include "ui/gtk/gtkglobals.h"
47 #include "ui/gtk/main.h"
49 #include "ui/gtk/old-gtk-compat.h"
51 /* used to keep track of the statistics for an entire program interface */
52 typedef struct _gtpstat_t {
53 GtkWidget *win;
54 srt_stat_table gtp_srt_table;
55 } gtpstat_t;
57 static void
58 gtpstat_set_title(gtpstat_t *gtp)
60 set_window_title(gtp->win, "GTP Control Plane Response Time statistics");
63 static void
64 gtpstat_reset(void *pgtp)
66 gtpstat_t *gtp=(gtpstat_t *)pgtp;
68 reset_srt_table_data(&gtp->gtp_srt_table);
69 gtpstat_set_title(gtp);
72 static int
73 gtpstat_packet(void *pgtp, packet_info *pinfo, epan_dissect_t *edt _U_, const void *psi)
75 const gtp_msg_hash_t *gtp=(gtp_msg_hash_t *)psi;
76 gtpstat_t *fs=(gtpstat_t *)pgtp;
77 int idx=0;
79 /* we are only interested in reply packets */
80 if(gtp->is_request){
81 return 0;
83 /* if we have not seen the request, just ignore it */
84 if(!gtp->req_frame){
85 return 0;
88 /* Only use the commands we know how to handle, this is not a comprehensive list */
89 /* Redoing the message indexing is bit reduntant, */
90 /* but using message type as such would yield a long gtp_srt_table. */
91 /* Only a fraction of the messages are matchable req/resp pairs, */
92 /* it just doesn't feel feasible. */
94 switch(gtp->msgtype){
95 case GTP_MSG_ECHO_REQ: idx=0;
96 break;
97 case GTP_MSG_CREATE_PDP_REQ: idx=1;
98 break;
99 case GTP_MSG_UPDATE_PDP_REQ: idx=2;
100 break;
101 case GTP_MSG_DELETE_PDP_REQ: idx=3;
102 break;
103 default:
104 return 0;
107 add_srt_table_data(&fs->gtp_srt_table, idx, &gtp->req_time, pinfo);
109 return 1;
114 static void
115 gtpstat_draw(void *pgtp)
117 gtpstat_t *gtp=(gtpstat_t *)pgtp;
119 draw_srt_table_data(&gtp->gtp_srt_table);
123 static void
124 win_destroy_cb(GtkWindow *win _U_, gpointer data)
126 gtpstat_t *gtp=(gtpstat_t *)data;
128 remove_tap_listener(gtp);
130 free_srt_table_data(&gtp->gtp_srt_table);
131 g_free(gtp);
135 static void
136 gtk_gtpstat_init(const char *opt_arg, void *userdata _U_)
138 gtpstat_t *gtp;
139 const char *filter=NULL;
140 GtkWidget *label;
141 char *filter_string;
142 GString *error_string;
143 GtkWidget *vbox;
144 GtkWidget *bbox;
145 GtkWidget *close_bt;
147 if(!strncmp(opt_arg,"gtp,",4)){
148 filter=opt_arg+4;
149 } else {
150 filter="gtp"; /*NULL doesn't work here like in LDAP. Too little time/lazy to find out why ?*/
153 gtp=(gtpstat_t *)g_malloc(sizeof(gtpstat_t));
155 gtp->win = dlg_window_new("gtp-stat"); /* transient_for top_level */
156 gtk_window_set_destroy_with_parent (GTK_WINDOW(gtp->win), TRUE);
158 gtk_window_set_default_size(GTK_WINDOW(gtp->win), 550, 400);
159 gtpstat_set_title(gtp);
161 vbox=ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
162 gtk_container_add(GTK_CONTAINER(gtp->win), vbox);
163 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
165 label=gtk_label_new("GTP Service Response Time statistics");
166 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
168 filter_string = g_strdup_printf("Filter: %s", filter ? filter : "");
169 label=gtk_label_new(filter_string);
170 g_free(filter_string);
171 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
172 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
174 label=gtk_label_new("GTP Requests");
175 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
177 /* We must display TOP LEVEL Widget before calling init_srt_table() */
178 gtk_widget_show_all(gtp->win);
180 init_srt_table(&gtp->gtp_srt_table, 4, vbox, NULL);
181 init_srt_table_row(&gtp->gtp_srt_table, 0, "Echo");
182 init_srt_table_row(&gtp->gtp_srt_table, 1, "Create PDP context");
183 init_srt_table_row(&gtp->gtp_srt_table, 2, "Update PDP context");
184 init_srt_table_row(&gtp->gtp_srt_table, 3, "Delete PDP context");
186 error_string=register_tap_listener("gtp", gtp, filter, 0, gtpstat_reset, gtpstat_packet, gtpstat_draw);
187 if(error_string){
188 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
189 g_string_free(error_string, TRUE);
190 g_free(gtp);
191 return;
194 /* Button row. */
195 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
196 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
198 close_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
199 window_set_cancel_button(gtp->win, close_bt, window_cancel_button_cb);
201 g_signal_connect(gtp->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
202 g_signal_connect(gtp->win, "destroy", G_CALLBACK(win_destroy_cb), gtp);
204 gtk_widget_show_all(gtp->win);
205 window_present(gtp->win);
207 cf_retap_packets(&cfile);
208 gdk_window_raise(gtk_widget_get_window(gtp->win));
211 static tap_param gtp_stat_params[] = {
212 { PARAM_FILTER, "Filter", NULL }
215 static tap_param_dlg gtp_stat_dlg = {
216 "GTP Control Plane Response Time Statistics",
217 "gtp",
218 gtk_gtpstat_init,
220 G_N_ELEMENTS(gtp_stat_params),
221 gtp_stat_params
224 void
225 register_tap_listener_gtkgtpstat(void)
227 register_param_stat(&gtp_stat_dlg, "GTP",
228 REGISTER_STAT_GROUP_RESPONSE_TIME);