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