2 * mgcp-statistics for Wireshark
3 * Copyright 2003 Lars Roland
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>
43 #include "../register.h"
44 #include "../epan/dissectors/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"
56 #ifdef NEED_G_ASCII_STRCASECMP_H
57 #include "../epan/g_ascii_strcasecmp.h"
61 #define NUM_TIMESTATS 10
63 /* used to keep track of the statistics for an entire program interface */
64 typedef struct _mgcpstat_t {
68 GtkWidget *scrolled_window;
70 timestat_t rtd[NUM_TIMESTATS];
77 static const value_string mgcp_mesage_type[] = {
91 mgcpstat_reset(void *pms)
93 mgcpstat_t *ms=(mgcpstat_t *)pms;
96 for(i=0;i<NUM_TIMESTATS;i++) {
100 ms->rtd[i].min.secs=0;
101 ms->rtd[i].min.nsecs=0;
102 ms->rtd[i].max.secs=0;
103 ms->rtd[i].max.nsecs=0;
104 ms->rtd[i].tot.secs=0;
105 ms->rtd[i].tot.nsecs=0;
116 mgcpstat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pmi)
118 mgcpstat_t *ms=(mgcpstat_t *)pms;
119 const mgcp_info_t *mi=pmi;
122 switch (mi->mgcp_type) {
125 if(mi->is_duplicate){
126 /* Duplicate is ignored */
137 if(mi->is_duplicate){
138 /* Duplicate is ignored */
142 else if (!mi->request_available) {
143 /* no request was seen */
149 /* calculate time delta between request and response */
150 nstime_delta(&delta, &pinfo->fd->abs_ts, &mi->req_time);
152 if (g_ascii_strncasecmp(mi->code, "EPCF", 4) == 0 ) {
153 time_stat_update(&(ms->rtd[0]),&delta, pinfo);
155 else if (g_ascii_strncasecmp(mi->code, "CRCX", 4) == 0 ) {
156 time_stat_update(&(ms->rtd[1]),&delta, pinfo);
158 else if (g_ascii_strncasecmp(mi->code, "MDCX", 4) == 0 ) {
159 time_stat_update(&(ms->rtd[2]),&delta, pinfo);
161 else if (g_ascii_strncasecmp(mi->code, "DLCX", 4) == 0 ) {
162 time_stat_update(&(ms->rtd[3]),&delta, pinfo);
164 else if (g_ascii_strncasecmp(mi->code, "RQNT", 4) == 0 ) {
165 time_stat_update(&(ms->rtd[4]),&delta, pinfo);
167 else if (g_ascii_strncasecmp(mi->code, "NTFY", 4) == 0 ) {
168 time_stat_update(&(ms->rtd[5]),&delta, pinfo);
170 else if (g_ascii_strncasecmp(mi->code, "AUEP", 4) == 0 ) {
171 time_stat_update(&(ms->rtd[6]),&delta, pinfo);
173 else if (g_ascii_strncasecmp(mi->code, "AUCX", 4) == 0 ) {
174 time_stat_update(&(ms->rtd[7]),&delta, pinfo);
176 else if (g_ascii_strncasecmp(mi->code, "RSIP", 4) == 0 ) {
177 time_stat_update(&(ms->rtd[8]),&delta, pinfo);
180 time_stat_update(&(ms->rtd[9]),&delta, pinfo);
194 mgcpstat_draw(void *pms)
196 mgcpstat_t *ms=(mgcpstat_t *)pms;
198 /* gtk1 using a scrollable clist*/
202 str[i]=g_malloc(sizeof(char[256]));
205 /* clear list before printing */
206 gtk_clist_clear(ms->table);
208 for(i=0;i<NUM_TIMESTATS;i++) {
209 /* nothing seen, nothing to do */
210 if(ms->rtd[i].num==0){
214 g_snprintf(str[0], 256, "%s", val_to_str(i,mgcp_mesage_type,"Other"));
215 g_snprintf(str[1], 256, "%d", ms->rtd[i].num);
216 g_snprintf(str[2], 256, "%8.2f msec", nstime_to_msec(&(ms->rtd[i].min)));
217 g_snprintf(str[3], 256, "%8.2f msec", nstime_to_msec(&(ms->rtd[i].max)));
218 g_snprintf(str[4], 256, "%8.2f msec", get_average(&(ms->rtd[i].tot), ms->rtd[i].num));
219 g_snprintf(str[5], 256, "%6u", ms->rtd[i].min_num);
220 g_snprintf(str[6], 256, "%6u", ms->rtd[i].max_num);
221 gtk_clist_append(ms->table, str);
224 gtk_widget_show(GTK_WIDGET(ms->table));
230 void protect_thread_critical_region(void);
231 void unprotect_thread_critical_region(void);
233 win_destroy_cb(GtkWindow *win _U_, gpointer data)
235 mgcpstat_t *ms=(mgcpstat_t *)data;
237 protect_thread_critical_region();
238 remove_tap_listener(ms);
239 unprotect_thread_critical_region();
248 static const gchar *titles[]={
258 gtk_mgcpstat_init(const char *optarg, void *userdata _U_)
261 const char *filter=NULL;
262 GString *error_string;
266 if(strncmp(optarg,"mgcp,srt,",9) == 0){
272 ms=g_malloc(sizeof(mgcpstat_t));
273 ms->filter=g_strdup(filter);
277 ms->win=window_new(GTK_WINDOW_TOPLEVEL, "MGCP SRT");
278 gtk_window_set_default_size(GTK_WINDOW(ms->win), 550, 150);
280 ms->vbox=gtk_vbox_new(FALSE, 3);
282 init_main_stat_window(ms->win, ms->vbox, "MGCP Service Response Time (SRT) Statistics", filter);
284 /* GTK1 using a scrollable clist*/
285 /* init a scrolled window*/
286 ms->scrolled_window = scrolled_window_new(NULL, NULL);
288 ms->table = create_stat_table(ms->scrolled_window, ms->vbox, 7, titles);
290 error_string=register_tap_listener("mgcp", ms, filter, mgcpstat_reset, mgcpstat_packet, mgcpstat_draw);
292 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
293 g_string_free(error_string, TRUE);
300 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
301 gtk_box_pack_start(GTK_BOX(ms->vbox), bbox, FALSE, FALSE, 0);
303 bt_close = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
304 window_set_cancel_button(ms->win, bt_close, window_cancel_button_cb);
306 SIGNAL_CONNECT(ms->win, "delete_event", window_delete_event_cb, NULL);
307 SIGNAL_CONNECT(ms->win, "destroy", win_destroy_cb, ms);
309 gtk_widget_show_all(ms->win);
310 window_present(ms->win);
312 cf_retap_packets(&cfile, FALSE);
315 static tap_dfilter_dlg mgcp_srt_dlg = {
316 "MGCP Service Response Time (SRT) Statistics",
323 register_tap_listener_gtkmgcpstat(void)
325 /* We don't register this tap, if we don't have the mgcp plugin loaded.*/
326 if (find_tap_id("mgcp")) {
327 register_dfilter_stat(&mgcp_srt_dlg, "MGCP",
328 REGISTER_STAT_GROUP_RESPONSE_TIME);