aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/camel_srt.c
blob: fed4a8b1e055c326a117245b1244336ab4d3fddd (plain)
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
241
242
243
244
245
246
247
248
/* camel_srt.c
 * camel Service Response Time statistics for Wireshark
 * Copyright 2006 Florent Drouin (based on h225_ras_srt.c from Lars Roland)
 *
 * 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 "register.h"
#include "timestats.h"
#include "simple_dialog.h"
#include "file.h"
#include "globals.h"
#include "stat_menu.h"
#include "tap_dfilter_dlg.h"

#include "gtk/main.h"
#include "gtk/dlg_utils.h"
#include "gtk/gui_utils.h"
#include "gtk/gui_stat_util.h"
#include "gtk/compat_macros.h"
#include "gtk/service_response_time_table.h"

#include "epan/camel-persistentdata.h"

/* used to keep track of the statistics for an entire program interface */
struct camelsrt_t {
  GtkWidget *win;
  srt_stat_table camel_srt_table;
};

static void camelsrt_set_title(struct camelsrt_t * p_camelsrt);
static void camelsrt_reset(void *phs);
static int camelsrt_packet(void *phs, 
			   packet_info *pinfo _U_, 
			   epan_dissect_t *edt _U_,
			   const void *phi);

static void camelsrt_draw(void *phs);
static void win_destroy_cb(GtkWindow *win _U_, gpointer data);
static void gtk_camelsrt_init(const char *optarg, void *userdata _U_);
void register_tap_listener_gtk_camelsrt(void);

/*
 *
 */
static void camelsrt_set_title(struct camelsrt_t * p_camelsrt)
{
  char * title;
  title = g_strdup_printf("CAMEL Service Response Time statistics: %s",
			  cf_get_display_name(&cfile));
  gtk_window_set_title(GTK_WINDOW(p_camelsrt->win), title);
  g_free(title);
}

static void camelsrt_reset(void *phs)
{
  struct camelsrt_t *hs=(struct camelsrt_t *)phs;
  reset_srt_table_data(&hs->camel_srt_table);
  camelsrt_set_title(hs); 
}

/*
 * Count the delta time between Request and Response
 * As we can make several measurement per message, we use a boolean array for the category
 * Then, if the measurement is provided, check if it is valid, and update the table 
 */
static int camelsrt_packet(void *phs, 
			   packet_info *pinfo _U_, 
			   epan_dissect_t *edt _U_,
			   const void *phi)
{
  struct camelsrt_t *hs=(struct camelsrt_t *)phs;
  const struct camelsrt_info_t * pi=phi;
  int i;

  for (i=1; i<NB_CAMELSRT_CATEGORY; i++) {
    if ( pi->bool_msginfo[i] &&
	 pi->msginfo[i].is_delta_time 
	 && pi->msginfo[i].request_available
	 && !pi->msginfo[i].is_duplicate ) {
      
      add_srt_table_data(&hs->camel_srt_table, i, &pi->msginfo[i].req_time, pinfo);
      
    }
  } /* category */
  return 1;
}


static void camelsrt_draw(void *phs)
{
  struct camelsrt_t *hs=(struct camelsrt_t *)phs;
  draw_srt_table_data(&hs->camel_srt_table);
}

/*
 * Routine for Display
 */
static void win_destroy_cb(GtkWindow *win _U_, gpointer data)
{
  struct camelsrt_t *hs=(struct camelsrt_t *)data;
  
  protect_thread_critical_region();
  remove_tap_listener(hs);
  unprotect_thread_critical_region();
   
  free_srt_table_data(&hs->camel_srt_table);
  g_free(hs);
}

static void gtk_camelsrt_init(const char *optarg, void *userdata _U_)
{
  struct camelsrt_t * p_camelsrt;
  const char *filter=NULL; 
  const char *emptyfilter="";

  GtkWidget *cmd_label;
  GtkWidget *main_label;
  GtkWidget *filter_label;
  char filter_string[256];
  GString *error_string;
  GtkWidget *vbox;
  GtkWidget *bbox;
  GtkWidget *close_bt;
  int i;

  if(strncmp(optarg,"camel,srt,",10) == 0){
    filter=optarg+10;
  } else {
    filter=NULL;
  }
  
  p_camelsrt=g_malloc(sizeof(struct camelsrt_t)); 

  p_camelsrt->win=window_new(GTK_WINDOW_TOPLEVEL, "camel-srt");
  gtk_window_set_default_size(GTK_WINDOW(p_camelsrt->win), 550, 400);
  camelsrt_set_title(p_camelsrt);

  vbox=gtk_vbox_new(FALSE, 3);
  gtk_container_add(GTK_CONTAINER(p_camelsrt->win), vbox);
  gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
  
  main_label=gtk_label_new("CAMEL Service Response Time statistics");
  gtk_box_pack_start(GTK_BOX(vbox), main_label, FALSE, FALSE, 0);
  gtk_widget_show(main_label);

  g_snprintf(filter_string,255,"Filter:%s",filter?filter:"");
  filter_label=gtk_label_new(filter_string);
  gtk_box_pack_start(GTK_BOX(vbox), filter_label, FALSE, FALSE, 0);
  gtk_widget_show(filter_label);

  cmd_label=gtk_label_new("CAMEL Commands");
  gtk_box_pack_start(GTK_BOX(vbox), cmd_label, FALSE, FALSE, 0);
  gtk_widget_show(cmd_label);

  /* We must display TOP LEVEL Widget before calling init_srt_table() */
  gtk_widget_show_all(p_camelsrt->win);
  
  init_srt_table(&p_camelsrt->camel_srt_table, NB_CAMELSRT_CATEGORY, vbox, NULL); 
  for(i=0 ;i<NB_CAMELSRT_CATEGORY; i++) {
    init_srt_table_row(&p_camelsrt->camel_srt_table, i,
		       val_to_str(i,camelSRTtype_naming,"Unknown"));
  }

  if (filter) {
    error_string=register_tap_listener("CAMEL", 
				       p_camelsrt,
				       filter,
				       camelsrt_reset,
				       camelsrt_packet, 
				       camelsrt_draw);
  } else {
    error_string=register_tap_listener("CAMEL", 
				       p_camelsrt,
				       emptyfilter,
				       camelsrt_reset,
				       camelsrt_packet, 
				       camelsrt_draw);
  }
  
    if(error_string){
      simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, error_string->str);
      g_string_free(error_string, TRUE);
    g_free(p_camelsrt);
    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 = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
  window_set_cancel_button(p_camelsrt->win, close_bt, window_cancel_button_cb);
  
  SIGNAL_CONNECT(p_camelsrt->win, "delete_event", window_delete_event_cb, NULL);
  SIGNAL_CONNECT(p_camelsrt->win, "destroy", win_destroy_cb, p_camelsrt);

  gtk_widget_show_all(p_camelsrt->win);
  window_present(p_camelsrt->win);
  cf_retap_packets(&cfile, FALSE); 

}

static tap_dfilter_dlg camel_srt_dlg = {
  "CAMEL Service Response Time",
  "camel,srt",
  gtk_camelsrt_init,
  -1
};

void /* Next line mandatory */
register_tap_listener_gtk_camelsrt(void)
{
  register_dfilter_stat(&camel_srt_dlg, "CAMEL",
			REGISTER_STAT_GROUP_RESPONSE_TIME);
}