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>
42 #include <epan/stat.h>
43 #include "stat_menu.h"
45 #include "../register.h"
46 #include "../plugins/mgcp/packet-mgcp.h"
47 #include "../timestats.h"
48 #include "gtk_stat_util.h"
49 #include "compat_macros.h"
50 #include "../simple_dialog.h"
51 #include "dlg_utils.h"
53 #include "../globals.h"
54 #include "../tap_dfilter_dlg.h"
55 #include "tap_dfilter_dlg.h"
56 #include "gui_utils.h"
59 #define NUM_TIMESTATS 10
61 /* used to keep track of the statistics for an entire program interface */
62 typedef struct _mgcpstat_t {
66 GtkWidget *scrolled_window;
68 timestat_t rtd[NUM_TIMESTATS];
75 static const value_string mgcp_mesage_type[] = {
89 mgcpstat_reset(void *pms)
91 mgcpstat_t *ms=(mgcpstat_t *)pms;
94 for(i=0;i<NUM_TIMESTATS;i++) {
98 ms->rtd[i].min.secs=0;
99 ms->rtd[i].min.nsecs=0;
100 ms->rtd[i].max.secs=0;
101 ms->rtd[i].max.nsecs=0;
102 ms->rtd[i].tot.secs=0;
103 ms->rtd[i].tot.nsecs=0;
114 mgcpstat_packet(void *pms, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pmi)
116 mgcpstat_t *ms=(mgcpstat_t *)pms;
117 const mgcp_info_t *mi=pmi;
120 switch (mi->mgcp_type) {
123 if(mi->is_duplicate){
124 /* Duplicate is ignored */
135 if(mi->is_duplicate){
136 /* Duplicate is ignored */
140 else if (!mi->request_available) {
141 /* no request was seen */
147 /* calculate time delta between request and response */
148 delta.secs=pinfo->fd->abs_secs-mi->req_time.secs;
149 delta.nsecs=pinfo->fd->abs_usecs*1000-mi->req_time.nsecs;
151 delta.nsecs+=1000000000;
155 if (strncasecmp(mi->code, "EPCF", 4) == 0 ) {
156 time_stat_update(&(ms->rtd[0]),&delta, pinfo);
158 else if (strncasecmp(mi->code, "CRCX", 4) == 0 ) {
159 time_stat_update(&(ms->rtd[1]),&delta, pinfo);
161 else if (strncasecmp(mi->code, "MDCX", 4) == 0 ) {
162 time_stat_update(&(ms->rtd[2]),&delta, pinfo);
164 else if (strncasecmp(mi->code, "DLCX", 4) == 0 ) {
165 time_stat_update(&(ms->rtd[3]),&delta, pinfo);
167 else if (strncasecmp(mi->code, "RQNT", 4) == 0 ) {
168 time_stat_update(&(ms->rtd[4]),&delta, pinfo);
170 else if (strncasecmp(mi->code, "NTFY", 4) == 0 ) {
171 time_stat_update(&(ms->rtd[5]),&delta, pinfo);
173 else if (strncasecmp(mi->code, "AUEP", 4) == 0 ) {
174 time_stat_update(&(ms->rtd[6]),&delta, pinfo);
176 else if (strncasecmp(mi->code, "AUCX", 4) == 0 ) {
177 time_stat_update(&(ms->rtd[7]),&delta, pinfo);
179 else if (strncasecmp(mi->code, "RSIP", 4) == 0 ) {
180 time_stat_update(&(ms->rtd[8]),&delta, pinfo);
183 time_stat_update(&(ms->rtd[9]),&delta, pinfo);
197 mgcpstat_draw(void *pms)
199 mgcpstat_t *ms=(mgcpstat_t *)pms;
201 /* gtk1 using a scrollable clist*/
205 str[i]=g_malloc(sizeof(char[256]));
208 /* clear list before printing */
209 gtk_clist_clear(ms->table);
211 for(i=0;i<NUM_TIMESTATS;i++) {
212 /* nothing seen, nothing to do */
213 if(ms->rtd[i].num==0){
217 g_snprintf(str[0], 256, "%s", val_to_str(i,mgcp_mesage_type,"Other"));
218 g_snprintf(str[1], 256, "%d", ms->rtd[i].num);
219 g_snprintf(str[2], 256, "%8.2f msec", nstime_to_msec(&(ms->rtd[i].min)));
220 g_snprintf(str[3], 256, "%8.2f msec", nstime_to_msec(&(ms->rtd[i].max)));
221 g_snprintf(str[4], 256, "%8.2f msec", get_average(&(ms->rtd[i].tot), ms->rtd[i].num));
222 g_snprintf(str[5], 256, "%6u", ms->rtd[i].min_num);
223 g_snprintf(str[6], 256, "%6u", ms->rtd[i].max_num);
224 gtk_clist_append(ms->table, str);
227 gtk_widget_show(GTK_WIDGET(ms->table));
233 void protect_thread_critical_region(void);
234 void unprotect_thread_critical_region(void);
236 win_destroy_cb(GtkWindow *win _U_, gpointer data)
238 mgcpstat_t *ms=(mgcpstat_t *)data;
240 protect_thread_critical_region();
241 remove_tap_listener(ms);
242 unprotect_thread_critical_region();
251 static const gchar *titles[]={
261 gtk_mgcpstat_init(const char *optarg)
264 const char *filter=NULL;
265 GString *error_string;
269 if(strncmp(optarg,"mgcp,srt,",9) == 0){
275 ms=g_malloc(sizeof(mgcpstat_t));
276 ms->filter=g_strdup(filter);
280 ms->win=window_new(GTK_WINDOW_TOPLEVEL, "MGCP SRT");
281 gtk_window_set_default_size(GTK_WINDOW(ms->win), 550, 150);
283 ms->vbox=gtk_vbox_new(FALSE, 3);
285 init_main_stat_window(ms->win, ms->vbox, "MGCP Service Response Time (SRT) Statistics", filter);
287 /* GTK1 using a scrollable clist*/
288 /* init a scrolled window*/
289 ms->scrolled_window = scrolled_window_new(NULL, NULL);
291 ms->table = create_stat_table(ms->scrolled_window, ms->vbox, 7, titles);
293 error_string=register_tap_listener("mgcp", ms, filter, mgcpstat_reset, mgcpstat_packet, mgcpstat_draw);
295 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
296 g_string_free(error_string, TRUE);
303 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
304 gtk_box_pack_start(GTK_BOX(ms->vbox), bbox, FALSE, FALSE, 0);
306 bt_close = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
307 window_set_cancel_button(ms->win, bt_close, window_cancel_button_cb);
309 SIGNAL_CONNECT(ms->win, "delete_event", window_delete_event_cb, NULL);
310 SIGNAL_CONNECT(ms->win, "destroy", win_destroy_cb, ms);
312 gtk_widget_show_all(ms->win);
313 window_present(ms->win);
315 cf_retap_packets(&cfile);
318 static tap_dfilter_dlg mgcp_srt_dlg = {
319 "MGCP Service Response Time (SRT) Statistics",
326 register_tap_listener_gtkmgcpstat(void)
328 /* We don't register this tap, if we don't have the mgcp plugin loaded.*/
329 if (find_tap_id("mgcp")) {
330 register_stat_cmd_arg("mgcp,srt", gtk_mgcpstat_init);
332 register_stat_menu_item("MGCP...", REGISTER_STAT_GROUP_RESPONSE_TIME,
333 gtk_tap_dfilter_dlg_cb, NULL, NULL, &(mgcp_srt_dlg));