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 "../register.h"
45 #include "../timestats.h"
46 #include "../simple_dialog.h"
48 #include "../globals.h"
49 #include "../stat_menu.h"
51 #include "gtk/gui_utils.h"
52 #include "gtk/dlg_utils.h"
53 #include "gtk/filter_dlg.h"
54 #include "gtk/service_response_time_table.h"
55 #include "gtk/tap_dfilter_dlg.h"
56 #include "gtk/gtkglobals.h"
59 /* used to keep track of the statistics for an entire program interface */
60 typedef struct _gtpstat_t {
62 srt_stat_table gtp_srt_table;
66 gtpstat_set_title(gtpstat_t *gtp)
70 title = g_strdup_printf("GTP Control Plane Response Time statistics: %s",
71 cf_get_display_name(&cfile));
72 gtk_window_set_title(GTK_WINDOW(gtp->win), title);
77 gtpstat_reset(void *pgtp)
79 gtpstat_t *gtp=(gtpstat_t *)pgtp;
81 reset_srt_table_data(>p->gtp_srt_table);
82 gtpstat_set_title(gtp);
86 gtpstat_packet(void *pgtp, packet_info *pinfo, epan_dissect_t *edt _U_, const void *psi)
88 const gtp_msg_hash_t *gtp=psi;
89 gtpstat_t *fs=(gtpstat_t *)pgtp;
92 /* we are only interested in reply packets */
96 /* if we have not seen the request, just ignore it */
101 /* Only use the commands we know how to handle, this is not a comprehensive list */
102 /* Redoing the message indexing is bit reduntant,*/
103 /* but using message type as such would yield a long gtp_srt_table.*/
104 /* Only a fragtion of the messages are matchable req/resp pairs,*/
105 /* it's just doesn't feel feasible*/
107 switch(gtp->msgtype){
108 case GTP_MSG_ECHO_REQ: index=0;
110 case GTP_MSG_CREATE_PDP_REQ: index=1;
112 case GTP_MSG_UPDATE_PDP_REQ: index=2;
114 case GTP_MSG_DELETE_PDP_REQ: index=3;
120 add_srt_table_data(&fs->gtp_srt_table, index, >p->req_time, pinfo);
128 gtpstat_draw(void *pgtp)
130 gtpstat_t *gtp=(gtpstat_t *)pgtp;
132 draw_srt_table_data(>p->gtp_srt_table);
137 win_destroy_cb(GtkWindow *win _U_, gpointer data)
139 gtpstat_t *gtp=(gtpstat_t *)data;
141 protect_thread_critical_region();
142 remove_tap_listener(gtp);
143 unprotect_thread_critical_region();
145 free_srt_table_data(>p->gtp_srt_table);
151 gtk_gtpstat_init(const char *optarg, void *userdata _U_)
154 const char *filter=NULL;
157 GString *error_string;
162 if(!strncmp(optarg,"gtp,",4)){
165 filter="gtp"; /*NULL doesn't work here like in LDAP. Too little time/lazy to find out why ?*/
168 gtp=g_malloc(sizeof(gtpstat_t));
170 gtp->win=window_new(GTK_WINDOW_TOPLEVEL, "gtp-stat");
171 gtk_window_set_default_size(GTK_WINDOW(gtp->win), 550, 400);
172 gtpstat_set_title(gtp);
174 vbox=gtk_vbox_new(FALSE, 3);
175 gtk_container_add(GTK_CONTAINER(gtp->win), vbox);
176 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
178 label=gtk_label_new("GTP Service Response Time statistics");
179 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
181 filter_string = g_strdup_printf("Filter: %s", filter ? filter : "");
182 label=gtk_label_new(filter_string);
183 g_free(filter_string);
184 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
185 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
187 label=gtk_label_new("GTP Requests");
188 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
190 /* We must display TOP LEVEL Widget before calling init_srt_table() */
191 gtk_widget_show_all(gtp->win);
193 init_srt_table(>p->gtp_srt_table, 4, vbox, NULL);
194 init_srt_table_row(>p->gtp_srt_table, 0, "Echo");
195 init_srt_table_row(>p->gtp_srt_table, 1, "Create PDP context");
196 init_srt_table_row(>p->gtp_srt_table, 2, "Update PDP context");
197 init_srt_table_row(>p->gtp_srt_table, 3, "Delete PDP context");
199 error_string=register_tap_listener("gtp", gtp, filter, gtpstat_reset, gtpstat_packet, gtpstat_draw);
201 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
202 g_string_free(error_string, TRUE);
208 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
209 gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
211 close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
212 window_set_cancel_button(gtp->win, close_bt, window_cancel_button_cb);
214 g_signal_connect(gtp->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
215 g_signal_connect(gtp->win, "destroy", G_CALLBACK(win_destroy_cb), gtp);
217 gtk_widget_show_all(gtp->win);
218 window_present(gtp->win);
220 cf_retap_packets(&cfile, FALSE);
221 gdk_window_raise(gtp->win->window);
224 static tap_dfilter_dlg gtp_stat_dlg = {
225 "GTP Control Plane Response Time Statistics",
232 register_tap_listener_gtkgtpstat(void)
234 register_dfilter_stat(>p_stat_dlg, "GTP",
235 REGISTER_STAT_GROUP_RESPONSE_TIME);