2008-12-31 15:26:48 +00:00
/* megaco_stat.c
* megaco - statistics for Wireshark
* Copyright 2003 Lars Roland
2008-12-31 17:47:36 +00:00
* Copyright 2008 , Ericsson AB
* By Balint Reczey < balint . reczey @ ericsson . com >
2008-12-31 15:26:48 +00:00
*
* $ Id $
*
* 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
# ifdef HAVE_SYS_TYPES_H
# include <sys / types.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/gcp.h"
2009-01-06 14:42:20 +00:00
# include <epan/prefs-int.h>
2008-12-31 15:26:48 +00:00
# include "../timestats.h"
2012-01-16 01:07:52 +00:00
# include "ui/simple_dialog.h"
2008-12-31 15:26:48 +00:00
# include "../file.h"
# include "../stat_menu.h"
2012-01-15 21:59:11 +00:00
# include "ui/gtk/gui_stat_util.h"
# include "ui/gtk/dlg_utils.h"
# include "ui/gtk/tap_param_dlg.h"
# include "ui/gtk/gui_utils.h"
# include "ui/gtk/main.h"
2008-12-31 15:26:48 +00:00
2008-12-31 17:47:36 +00:00
# include "tap-megaco-common.h"
2008-12-31 15:26:48 +00:00
2012-01-15 21:59:11 +00:00
# include "ui/gtk/old-gtk-compat.h"
2008-12-31 15:26:48 +00:00
static void
megacostat_reset ( void * pms )
{
megacostat_t * ms = ( megacostat_t * ) pms ;
int i ;
for ( i = 0 ; i < NUM_TIMESTATS ; i + + ) {
ms - > rtd [ i ] . num = 0 ;
ms - > rtd [ i ] . min_num = 0 ;
ms - > rtd [ i ] . max_num = 0 ;
ms - > rtd [ i ] . min . secs = 0 ;
ms - > rtd [ i ] . min . nsecs = 0 ;
ms - > rtd [ i ] . max . secs = 0 ;
ms - > rtd [ i ] . max . nsecs = 0 ;
ms - > rtd [ i ] . tot . secs = 0 ;
ms - > rtd [ i ] . tot . nsecs = 0 ;
}
ms - > open_req_num = 0 ;
ms - > disc_rsp_num = 0 ;
ms - > req_dup_num = 0 ;
ms - > rsp_dup_num = 0 ;
}
static void
megacostat_draw ( void * pms )
{
megacostat_t * ms = ( megacostat_t * ) pms ;
int i ;
2009-10-07 10:00:26 +00:00
char str [ 3 ] [ 256 ] ;
GtkListStore * store ;
GtkTreeIter iter ;
2008-12-31 15:26:48 +00:00
/* clear list before printing */
2009-10-07 10:00:26 +00:00
store = GTK_LIST_STORE ( gtk_tree_view_get_model ( ms - > table ) ) ;
gtk_list_store_clear ( store ) ;
2008-12-31 15:26:48 +00:00
2009-01-01 15:49:20 +00:00
for ( i = 0 ; i < NUM_TIMESTATS ; i + + ) {
2008-12-31 15:26:48 +00:00
/* nothing seen, nothing to do */
if ( ms - > rtd [ i ] . num = = 0 ) {
continue ;
}
2009-10-07 10:00:26 +00:00
g_snprintf ( str [ 0 ] , sizeof ( char [ 256 ] ) , " %8.2f msec " , nstime_to_msec ( & ( ms - > rtd [ i ] . min ) ) ) ;
g_snprintf ( str [ 1 ] , sizeof ( char [ 256 ] ) , " %8.2f msec " , nstime_to_msec ( & ( ms - > rtd [ i ] . max ) ) ) ;
g_snprintf ( str [ 2 ] , sizeof ( char [ 256 ] ) , " %8.2f msec " , get_average ( & ( ms - > rtd [ i ] . tot ) , ms - > rtd [ i ] . num ) ) ;
gtk_list_store_append ( store , & iter ) ;
gtk_list_store_set ( store , & iter ,
0 , val_to_str ( i , megaco_message_type , " Other " ) ,
1 , ms - > rtd [ i ] . num ,
2 , str [ 0 ] ,
3 , str [ 1 ] ,
4 , str [ 2 ] ,
5 , ms - > rtd [ i ] . min_num ,
6 , ms - > rtd [ i ] . max_num ,
- 1 ) ;
2008-12-31 15:26:48 +00:00
}
}
static void
win_destroy_cb ( GtkWindow * win _U_ , gpointer data )
{
megacostat_t * ms = ( megacostat_t * ) data ;
protect_thread_critical_region ( ) ;
remove_tap_listener ( ms ) ;
unprotect_thread_critical_region ( ) ;
if ( ms - > filter ) {
g_free ( ms - > filter ) ;
ms - > filter = NULL ;
}
g_free ( ms ) ;
}
2009-10-07 10:00:26 +00:00
static const stat_column titles [ ] = {
{ G_TYPE_STRING , LEFT , " Type " } ,
{ G_TYPE_UINT , RIGHT , " Messages " } ,
{ G_TYPE_STRING , RIGHT , " Min SRT " } ,
{ G_TYPE_STRING , RIGHT , " Max SRT " } ,
{ G_TYPE_STRING , RIGHT , " Avg SRT " } ,
{ G_TYPE_UINT , RIGHT , " Min in Frame " } ,
2010-08-30 16:10:01 +00:00
{ G_TYPE_UINT , RIGHT , " Max in Frame " }
2009-10-07 10:00:26 +00:00
} ;
2008-12-31 15:26:48 +00:00
static void
gtk_megacostat_init ( const char * optarg , void * userdata _U_ )
{
megacostat_t * ms ;
GString * error_string ;
GtkWidget * bt_close ;
GtkWidget * bbox ;
2009-01-06 14:42:20 +00:00
pref_t * megaco_ctx_track , * h248_ctx_track ;
megaco_ctx_track = prefs_find_preference ( prefs_find_module ( " megaco " ) , " ctx_info " ) ;
h248_ctx_track = prefs_find_preference ( prefs_find_module ( " h248 " ) , " ctx_info " ) ;
2010-08-30 16:10:01 +00:00
2011-03-26 15:53:55 +00:00
if ( ! megaco_ctx_track | | ! h248_ctx_track ) {
/* No such preferences */
return ;
}
2009-01-06 14:42:20 +00:00
if ( ! * megaco_ctx_track - > varp . boolp | | ! * h248_ctx_track - > varp . boolp ) {
2012-03-18 22:24:24 +00:00
simple_dialog ( ESD_TYPE_ERROR , ESD_BTN_OK , " %s " , " Track Context option at Protocols -> MEGACO and Protocols -> H248 preferences has to be set to true to enable measurement of service response times. " ) ;
2009-01-06 14:42:20 +00:00
return ;
}
2010-08-30 16:10:01 +00:00
2009-06-05 22:42:47 +00:00
ms = g_malloc ( sizeof ( megacostat_t ) ) ;
2008-12-31 15:26:48 +00:00
if ( strncmp ( optarg , " megaco,srt, " , 11 ) = = 0 ) {
2009-06-05 22:42:47 +00:00
ms - > filter = g_strdup ( optarg + 11 ) ;
2008-12-31 15:26:48 +00:00
} else {
2009-06-05 22:42:47 +00:00
ms - > filter = NULL ;
2008-12-31 15:26:48 +00:00
}
megacostat_reset ( ms ) ;
2009-06-21 20:42:07 +00:00
ms - > win = dlg_window_new ( " MEGACO SRT " ) ; /* transient_for top_level */
gtk_window_set_destroy_with_parent ( GTK_WINDOW ( ms - > win ) , TRUE ) ;
2008-12-31 15:26:48 +00:00
gtk_window_set_default_size ( GTK_WINDOW ( ms - > win ) , 550 , 150 ) ;
ms - > vbox = gtk_vbox_new ( FALSE , 3 ) ;
2009-06-05 22:42:47 +00:00
init_main_stat_window ( ms - > win , ms - > vbox , " MEGACO Service Response Time (SRT) Statistics " , ms - > filter ) ;
2008-12-31 15:26:48 +00:00
/* init a scrolled window*/
ms - > scrolled_window = scrolled_window_new ( NULL , NULL ) ;
ms - > table = create_stat_table ( ms - > scrolled_window , ms - > vbox , 7 , titles ) ;
2009-06-05 22:42:47 +00:00
error_string = register_tap_listener ( " megaco " , ms , ms - > filter , 0 , megacostat_reset , megacostat_packet , megacostat_draw ) ;
2008-12-31 15:26:48 +00:00
if ( error_string ) {
simple_dialog ( ESD_TYPE_ERROR , ESD_BTN_OK , " %s " , error_string - > str ) ;
g_string_free ( error_string , TRUE ) ;
g_free ( ms - > filter ) ;
g_free ( ms ) ;
return ;
}
/* Button row. */
bbox = dlg_button_row_new ( GTK_STOCK_CLOSE , NULL ) ;
gtk_box_pack_start ( GTK_BOX ( ms - > vbox ) , bbox , FALSE , FALSE , 0 ) ;
bt_close = g_object_get_data ( G_OBJECT ( bbox ) , GTK_STOCK_CLOSE ) ;
window_set_cancel_button ( ms - > win , bt_close , window_cancel_button_cb ) ;
g_signal_connect ( ms - > win , " delete_event " , G_CALLBACK ( window_delete_event_cb ) , NULL ) ;
g_signal_connect ( ms - > win , " destroy " , G_CALLBACK ( win_destroy_cb ) , ms ) ;
gtk_widget_show_all ( ms - > win ) ;
window_present ( ms - > win ) ;
2009-06-05 22:42:47 +00:00
cf_retap_packets ( & cfile ) ;
2011-07-21 20:12:08 +00:00
gdk_window_raise ( gtk_widget_get_window ( ms - > win ) ) ;
2008-12-31 15:26:48 +00:00
}
2011-06-05 22:39:23 +00:00
static tap_param megaco_srt_params [ ] = {
{ PARAM_FILTER , " Filter " , NULL }
} ;
static tap_param_dlg megaco_srt_dlg = {
2008-12-31 15:26:48 +00:00
" MEGACO Service Response Time (SRT) Statistics " ,
" megaco,srt " ,
gtk_megacostat_init ,
2011-06-05 22:39:23 +00:00
- 1 ,
G_N_ELEMENTS ( megaco_srt_params ) ,
megaco_srt_params
2008-12-31 15:26:48 +00:00
} ;
void
register_tap_listener_gtkmegacostat ( void )
{
2011-08-20 09:55:32 +00:00
register_dfilter_stat ( & megaco_srt_dlg , " MEGACO " ,
REGISTER_STAT_GROUP_RESPONSE_TIME ) ;
}
void megaco_srt_cb ( GtkAction * action , gpointer user_data _U_ )
{
tap_param_dlg_cb ( action , & megaco_srt_dlg ) ;
2008-12-31 15:26:48 +00:00
}
2011-09-25 21:19:45 +00:00