2 * gtp_stat 2008 Kari Tiirikainen
3 * Largely based on ldap_stat by Ronnie Sahlberg, all mistakes added by KTi
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
38 #include <epan/packet_info.h>
39 #include <epan/epan.h>
40 #include <epan/value_string.h>
42 #include <epan/dissectors/packet-gtp.h>
44 #include "../timestats.h"
45 #include "../simple_dialog.h"
47 #include "../stat_menu.h"
49 #include "ui/gtk/gui_utils.h"
50 #include "ui/gtk/dlg_utils.h"
51 #include "ui/gtk/service_response_time_table.h"
52 #include "ui/gtk/tap_param_dlg.h"
53 #include "ui/gtk/gtkglobals.h"
54 #include "ui/gtk/main.h"
56 #include "ui/gtk/old-gtk-compat.h"
58 /* used to keep track of the statistics for an entire program interface */
59 typedef struct _gtpstat_t {
61 srt_stat_table gtp_srt_table;
65 gtpstat_set_title(gtpstat_t *gtp)
69 title = g_strdup_printf("GTP Control Plane Response Time statistics: %s",
70 cf_get_display_name(&cfile));
71 gtk_window_set_title(GTK_WINDOW(gtp->win), title);
76 gtpstat_reset(void *pgtp)
78 gtpstat_t *gtp=(gtpstat_t *)pgtp;
80 reset_srt_table_data(>p->gtp_srt_table);
81 gtpstat_set_title(gtp);
85 gtpstat_packet(void *pgtp, packet_info *pinfo, epan_dissect_t *edt _U_, const void *psi)
87 const gtp_msg_hash_t *gtp=psi;
88 gtpstat_t *fs=(gtpstat_t *)pgtp;
91 /* we are only interested in reply packets */
95 /* if we have not seen the request, just ignore it */
100 /* Only use the commands we know how to handle, this is not a comprehensive list */
101 /* Redoing the message indexing is bit reduntant, */
102 /* but using message type as such would yield a long gtp_srt_table. */
103 /* Only a fraction of the messages are matchable req/resp pairs, */
104 /* it just doesn't feel feasible. */
106 switch(gtp->msgtype){
107 case GTP_MSG_ECHO_REQ: idx=0;
109 case GTP_MSG_CREATE_PDP_REQ: idx=1;
111 case GTP_MSG_UPDATE_PDP_REQ: idx=2;
113 case GTP_MSG_DELETE_PDP_REQ: idx=3;
119 add_srt_table_data(&fs->gtp_srt_table, idx, >p->req_time, pinfo);
127 gtpstat_draw(void *pgtp)
129 gtpstat_t *gtp=(gtpstat_t *)pgtp;
131 draw_srt_table_data(>p->gtp_srt_table);
136 win_destroy_cb(GtkWindow *win _U_, gpointer data)
138 gtpstat_t *gtp=(gtpstat_t *)data;
140 protect_thread_critical_region();
141 remove_tap_listener(gtp);
142 unprotect_thread_critical_region();
144 free_srt_table_data(>p->gtp_srt_table);
150 gtk_gtpstat_init(const char *optarg, void *userdata _U_)
153 const char *filter=NULL;
156 GString *error_string;
161 if(!strncmp(optarg,"gtp,",4)){
164 filter="gtp"; /*NULL doesn't work here like in LDAP. Too little time/lazy to find out why ?*/
167 gtp=g_malloc(sizeof(gtpstat_t));
169 gtp->win = dlg_window_new("gtp-stat"); /* transient_for top_level */
170 gtk_window_set_destroy_with_parent (GTK_WINDOW(gtp->win), TRUE);
172 gtk_window_set_default_size(GTK_WINDOW(gtp->win), 550, 400);
173 gtpstat_set_title(gtp);
175 vbox=gtk_vbox_new(FALSE, 3);
176 gtk_container_add(GTK_CONTAINER(gtp->win), vbox);
177 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
179 label=gtk_label_new("GTP Service Response Time statistics");
180 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
182 filter_string = g_strdup_printf("Filter: %s", filter ? filter : "");
183 label=gtk_label_new(filter_string);
184 g_free(filter_string);
185 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
186 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
188 label=gtk_label_new("GTP Requests");
189 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
191 /* We must display TOP LEVEL Widget before calling init_srt_table() */
192 gtk_widget_show_all(gtp->win);
194 init_srt_table(>p->gtp_srt_table, 4, vbox, NULL);
195 init_srt_table_row(>p->gtp_srt_table, 0, "Echo");
196 init_srt_table_row(>p->gtp_srt_table, 1, "Create PDP context");
197 init_srt_table_row(>p->gtp_srt_table, 2, "Update PDP context");
198 init_srt_table_row(>p->gtp_srt_table, 3, "Delete PDP context");
200 error_string=register_tap_listener("gtp", gtp, filter, 0, gtpstat_reset, gtpstat_packet, gtpstat_draw);
202 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
203 g_string_free(error_string, TRUE);
209 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
210 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
212 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
213 window_set_cancel_button(gtp->win, close_bt, window_cancel_button_cb);
215 g_signal_connect(gtp->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
216 g_signal_connect(gtp->win, "destroy", G_CALLBACK(win_destroy_cb), gtp);
218 gtk_widget_show_all(gtp->win);
219 window_present(gtp->win);
221 cf_retap_packets(&cfile);
222 gdk_window_raise(gtk_widget_get_window(gtp->win));
225 static tap_param gtp_stat_params[] = {
226 { PARAM_FILTER, "Filter", NULL }
229 static tap_param_dlg gtp_stat_dlg = {
230 "GTP Control Plane Response Time Statistics",
234 G_N_ELEMENTS(gtp_stat_params),
239 register_tap_listener_gtkgtpstat(void)
241 register_dfilter_stat(>p_stat_dlg, "GTP",
242 REGISTER_STAT_GROUP_RESPONSE_TIME);
245 void gtp_srt_cb(GtkAction *action, gpointer user_data _U_)
247 tap_param_dlg_cb(action, >p_stat_dlg);