2 * mgcp-statistics for ethereal
3 * Copyright 2003 Lars Roland
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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>
43 #include "../register.h"
44 #include "../plugins/mgcp/packet-mgcp.h"
45 #include "../timestats.h"
46 #include "gui_stat_util.h"
47 #include "compat_macros.h"
48 #include "../simple_dialog.h"
49 #include "dlg_utils.h"
51 #include "../globals.h"
52 #include "../stat_menu.h"
53 #include "../tap_dfilter_dlg.h"
54 #include "gui_utils.h"
57 #define NUM_TIMESTATS 10
59 /* used to keep track of the statistics for an entire program interface */
60 typedef struct _mgcpstat_t {
64 GtkWidget *scrolled_window;
66 timestat_t rtd[NUM_TIMESTATS];
73 static const value_string mgcp_mesage_type[] = {
87 mgcpstat_reset(void *pms)
89 mgcpstat_t *ms=(mgcpstat_t *)pms;
92 for(i=0;i<NUM_TIMESTATS;i++) {
96 ms->rtd[i].min.secs=0;
97 ms->rtd[i].min.nsecs=0;
98 ms->rtd[i].max.secs=0;
99 ms->rtd[i].max.nsecs=0;
100 ms->rtd[i].tot.secs=0;
101 ms->rtd[i].tot.nsecs=0;
112 mgcpstat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pmi)
114 mgcpstat_t *ms=(mgcpstat_t *)pms;
115 const mgcp_info_t *mi=pmi;
118 switch (mi->mgcp_type) {
121 if(mi->is_duplicate){
122 /* Duplicate is ignored */
133 if(mi->is_duplicate){
134 /* Duplicate is ignored */
138 else if (!mi->request_available) {
139 /* no request was seen */
145 /* calculate time delta between request and response */
146 nstime_delta(&delta, &pinfo->fd->abs_ts, &mi->req_time);
148 if (strncasecmp(mi->code, "EPCF", 4) == 0 ) {
149 time_stat_update(&(ms->rtd[0]),&delta, pinfo);
151 else if (strncasecmp(mi->code, "CRCX", 4) == 0 ) {
152 time_stat_update(&(ms->rtd[1]),&delta, pinfo);
154 else if (strncasecmp(mi->code, "MDCX", 4) == 0 ) {
155 time_stat_update(&(ms->rtd[2]),&delta, pinfo);
157 else if (strncasecmp(mi->code, "DLCX", 4) == 0 ) {
158 time_stat_update(&(ms->rtd[3]),&delta, pinfo);
160 else if (strncasecmp(mi->code, "RQNT", 4) == 0 ) {
161 time_stat_update(&(ms->rtd[4]),&delta, pinfo);
163 else if (strncasecmp(mi->code, "NTFY", 4) == 0 ) {
164 time_stat_update(&(ms->rtd[5]),&delta, pinfo);
166 else if (strncasecmp(mi->code, "AUEP", 4) == 0 ) {
167 time_stat_update(&(ms->rtd[6]),&delta, pinfo);
169 else if (strncasecmp(mi->code, "AUCX", 4) == 0 ) {
170 time_stat_update(&(ms->rtd[7]),&delta, pinfo);
172 else if (strncasecmp(mi->code, "RSIP", 4) == 0 ) {
173 time_stat_update(&(ms->rtd[8]),&delta, pinfo);
176 time_stat_update(&(ms->rtd[9]),&delta, pinfo);
190 mgcpstat_draw(void *pms)
192 mgcpstat_t *ms=(mgcpstat_t *)pms;
194 /* gtk1 using a scrollable clist*/
198 str[i]=g_malloc(sizeof(char[256]));
201 /* clear list before printing */
202 gtk_clist_clear(ms->table);
204 for(i=0;i<NUM_TIMESTATS;i++) {
205 /* nothing seen, nothing to do */
206 if(ms->rtd[i].num==0){
210 g_snprintf(str[0], 256, "%s", val_to_str(i,mgcp_mesage_type,"Other"));
211 g_snprintf(str[1], 256, "%d", ms->rtd[i].num);
212 g_snprintf(str[2], 256, "%8.2f msec", nstime_to_msec(&(ms->rtd[i].min)));
213 g_snprintf(str[3], 256, "%8.2f msec", nstime_to_msec(&(ms->rtd[i].max)));
214 g_snprintf(str[4], 256, "%8.2f msec", get_average(&(ms->rtd[i].tot), ms->rtd[i].num));
215 g_snprintf(str[5], 256, "%6u", ms->rtd[i].min_num);
216 g_snprintf(str[6], 256, "%6u", ms->rtd[i].max_num);
217 gtk_clist_append(ms->table, str);
220 gtk_widget_show(GTK_WIDGET(ms->table));
226 void protect_thread_critical_region(void);
227 void unprotect_thread_critical_region(void);
229 win_destroy_cb(GtkWindow *win _U_, gpointer data)
231 mgcpstat_t *ms=(mgcpstat_t *)data;
233 protect_thread_critical_region();
234 remove_tap_listener(ms);
235 unprotect_thread_critical_region();
244 static const gchar *titles[]={
254 gtk_mgcpstat_init(const char *optarg)
257 const char *filter=NULL;
258 GString *error_string;
262 if(strncmp(optarg,"mgcp,srt,",9) == 0){
268 ms=g_malloc(sizeof(mgcpstat_t));
269 ms->filter=g_strdup(filter);
273 ms->win=window_new(GTK_WINDOW_TOPLEVEL, "MGCP SRT");
274 gtk_window_set_default_size(GTK_WINDOW(ms->win), 550, 150);
276 ms->vbox=gtk_vbox_new(FALSE, 3);
278 init_main_stat_window(ms->win, ms->vbox, "MGCP Service Response Time (SRT) Statistics", filter);
280 /* GTK1 using a scrollable clist*/
281 /* init a scrolled window*/
282 ms->scrolled_window = scrolled_window_new(NULL, NULL);
284 ms->table = create_stat_table(ms->scrolled_window, ms->vbox, 7, titles);
286 error_string=register_tap_listener("mgcp", ms, filter, mgcpstat_reset, mgcpstat_packet, mgcpstat_draw);
288 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
289 g_string_free(error_string, TRUE);
296 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
297 gtk_box_pack_start(GTK_BOX(ms->vbox), bbox, FALSE, FALSE, 0);
299 bt_close = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
300 window_set_cancel_button(ms->win, bt_close, window_cancel_button_cb);
302 SIGNAL_CONNECT(ms->win, "delete_event", window_delete_event_cb, NULL);
303 SIGNAL_CONNECT(ms->win, "destroy", win_destroy_cb, ms);
305 gtk_widget_show_all(ms->win);
306 window_present(ms->win);
308 cf_retap_packets(&cfile, FALSE);
311 static tap_dfilter_dlg mgcp_srt_dlg = {
312 "MGCP Service Response Time (SRT) Statistics",
319 register_tap_listener_gtkmgcpstat(void)
321 /* We don't register this tap, if we don't have the mgcp plugin loaded.*/
322 if (find_tap_id("mgcp")) {
323 register_dfilter_stat(&mgcp_srt_dlg, "MGCP",
324 REGISTER_STAT_GROUP_RESPONSE_TIME);