Have the time field in the Graph Analyzis windos use the same time format as used...
[metze/wireshark/wip.git] / ui / gtk / h225_ras_srt.c
1 /* h225_ras_srt.c
2  * H.225 RAS Service Response Time statistics for Wireshar
3  * Copyright 2003 Lars Roland
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
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.
15  *
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.
20  *
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.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
32 #endif
33
34 #include <string.h>
35
36 #include <gtk/gtk.h>
37
38 #include <epan/packet.h>
39 #include <epan/packet_info.h>
40 #include <epan/epan.h>
41 #include <epan/value_string.h>
42 #include <epan/tap.h>
43 #include <epan/dissectors/packet-h225.h>
44
45 #include "../timestats.h"
46 #include "../simple_dialog.h"
47 #include "../file.h"
48 #include "../stat_menu.h"
49
50 #include "ui/gtk/gui_stat_util.h"
51 #include "ui/gtk/dlg_utils.h"
52 #include "ui/gtk/tap_param_dlg.h"
53 #include "ui/gtk/gui_utils.h"
54 #include "ui/gtk/main.h"
55
56 #include "ui/gtk/old-gtk-compat.h"
57
58 static void gtk_h225rassrt_init(const char *optarg, void *userdata);
59
60 static tap_param h225_rassrt_params[] = {
61         { PARAM_FILTER, "Filter", NULL }
62 };
63
64 static tap_param_dlg h225_rassrt_dlg = {
65         "H.225 RAS Service Response Time",
66         "h225,srt",
67         gtk_h225rassrt_init,
68         -1,
69         G_N_ELEMENTS(h225_rassrt_params),
70         h225_rassrt_params
71 };
72
73 /* following values represent the size of their valuestring arrays */
74 #define NUM_RAS_STATS 7
75
76 static const value_string ras_message_category[] = {
77   {  0, "Gatekeeper    "},
78   {  1, "Registration  "},
79   {  2, "UnRegistration"},
80   {  3, "Admission     "},
81   {  4, "Bandwidth     "},
82   {  5, "Disengage     "},
83   {  6, "Location      "},
84   {  0, NULL }
85 };
86
87 typedef enum _ras_type {
88         RAS_REQUEST,
89         RAS_CONFIRM,
90         RAS_REJECT,
91         RAS_OTHER
92 }ras_type;
93
94 typedef enum _ras_category {
95         RAS_GATEKEEPER,
96         RAS_REGISTRATION,
97         RAS_UNREGISTRATION,
98         RAS_ADMISSION,
99         RAS_BANDWIDTH,
100         RAS_DISENGAGE,
101         RAS_LOCATION,
102         RAS_OTHERS
103 }ras_category;
104
105 /* Summary of response-time calculations*/
106 typedef struct _h225_rtd_t {
107         guint32 open_req_num;
108         guint32 disc_rsp_num;
109         guint32 req_dup_num;
110         guint32 rsp_dup_num;
111         timestat_t stats;
112 } h225_rtd_t;
113
114 /* used to keep track of the statistics for an entire program interface */
115 typedef struct _h225rassrt_t {
116         GtkWidget *win;
117         GtkWidget *vbox;
118         char *filter;
119         GtkWidget *scrolled_window;
120         GtkTreeView *table;
121         h225_rtd_t ras_rtd[NUM_RAS_STATS];
122 } h225rassrt_t;
123
124
125 static void
126 h225rassrt_reset(void *phs)
127 {
128         h225rassrt_t *hs=(h225rassrt_t *)phs;
129         int i;
130
131         for(i=0;i<NUM_RAS_STATS;i++) {
132                 hs->ras_rtd[i].stats.num = 0;
133                 hs->ras_rtd[i].stats.min_num = 0;
134                 hs->ras_rtd[i].stats.max_num = 0;
135                 hs->ras_rtd[i].stats.min.secs = 0;
136                 hs->ras_rtd[i].stats.min.nsecs = 0;
137                 hs->ras_rtd[i].stats.max.secs = 0;
138                 hs->ras_rtd[i].stats.max.nsecs = 0;
139                 hs->ras_rtd[i].stats.tot.secs = 0;
140                 hs->ras_rtd[i].stats.tot.nsecs = 0;
141                 hs->ras_rtd[i].open_req_num = 0;
142                 hs->ras_rtd[i].disc_rsp_num = 0;
143                 hs->ras_rtd[i].req_dup_num = 0;
144                 hs->ras_rtd[i].rsp_dup_num = 0;
145         }
146
147 }
148
149
150 static int
151 h225rassrt_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *phi)
152 {
153         h225rassrt_t *hs=(h225rassrt_t *)phs;
154         const h225_packet_info *pi=phi;
155
156         ras_type rasmsg_type = RAS_OTHER;
157         ras_category rascategory = RAS_OTHERS;
158
159         if (pi->msg_type != H225_RAS || pi->msg_tag == -1) {
160                 /* No RAS Message or uninitialized msg_tag -> return */
161                 return 0;
162         }
163
164         if (pi->msg_tag < 21) {
165                 /* */
166                 rascategory = pi->msg_tag / 3;
167                 rasmsg_type = pi->msg_tag % 3;
168         }
169         else {
170                 /* No SRT yet (ToDo) */
171                 return 0;
172         }
173
174         switch(rasmsg_type) {
175
176         case RAS_REQUEST:
177                 if(pi->is_duplicate){
178                         hs->ras_rtd[rascategory].req_dup_num++;
179                 }
180                 else {
181                         hs->ras_rtd[rascategory].open_req_num++;
182                 }
183                 break;
184
185         case RAS_CONFIRM:
186                 /* no break - delay stats are identical for Confirm and Reject  */
187         case RAS_REJECT:
188                 if(pi->is_duplicate){
189                         /* Duplicate is ignored */
190                         hs->ras_rtd[rascategory].rsp_dup_num++;
191                 }
192                 else if (!pi->request_available) {
193                         /* no request was seen, ignore response  */
194                         hs->ras_rtd[rascategory].disc_rsp_num++;
195                 }
196                 else {
197                         hs->ras_rtd[rascategory].open_req_num--;
198                         time_stat_update(&(hs->ras_rtd[rascategory].stats),&(pi->delta_time), pinfo);
199                 }
200                 break;
201
202         default:
203                 return 0;
204         }
205         return 1;
206 }
207
208 static void
209 h225rassrt_draw(void *phs)
210 {
211         h225rassrt_t *hs=(h225rassrt_t *)phs;
212         int i;
213         char str[3][256];
214         GtkListStore *store;
215         GtkTreeIter iter;
216
217         /* Now print Message and Reason Counter Table */
218         /* clear list before printing */
219         store = GTK_LIST_STORE(gtk_tree_view_get_model(hs->table));
220         gtk_list_store_clear(store);
221
222         for(i=0;i<NUM_RAS_STATS;i++) {
223                 /* nothing seen, nothing to do */
224                 if(hs->ras_rtd[i].stats.num==0){
225                         continue;
226                 }
227                 g_snprintf(str[0], sizeof(char[256]),
228                                 "%8.2f msec", nstime_to_msec(&(hs->ras_rtd[i].stats.min)));
229                 g_snprintf(str[1], sizeof(char[256]),
230                                 "%8.2f msec", nstime_to_msec(&(hs->ras_rtd[i].stats.max)));
231                 g_snprintf(str[2], sizeof(char[256]),
232                                 "%8.2f msec", get_average(&(hs->ras_rtd[i].stats.tot), hs->ras_rtd[i].stats.num));
233
234                 gtk_list_store_append(store, &iter);
235                 gtk_list_store_set(store, &iter,
236                         0, val_to_str(i,ras_message_category,"Other"),
237                         1, hs->ras_rtd[i].stats.num,
238                         2, str[0],
239                         3, str[1],
240                         4, str[2],
241                         5, hs->ras_rtd[i].stats.min_num,
242                         6, hs->ras_rtd[i].stats.max_num,
243                         7, hs->ras_rtd[i].open_req_num,
244                         8, hs->ras_rtd[i].disc_rsp_num,
245                         9, hs->ras_rtd[i].req_dup_num,
246                         10, hs->ras_rtd[i].rsp_dup_num,
247                         -1);
248         }
249 }
250
251 static void
252 win_destroy_cb(GtkWindow *win _U_, gpointer data)
253 {
254         h225rassrt_t *hs=(h225rassrt_t *)data;
255
256         protect_thread_critical_region();
257         remove_tap_listener(hs);
258         unprotect_thread_critical_region();
259
260         if(hs->filter){
261                 g_free(hs->filter);
262                 hs->filter=NULL;
263         }
264         g_free(hs);
265 }
266
267
268 static const stat_column titles[]={
269         {G_TYPE_STRING, LEFT, "RAS-Type" },
270         {G_TYPE_UINT, RIGHT,   "Measurements" },
271         {G_TYPE_STRING, RIGHT, "Min RTT" },
272         {G_TYPE_STRING, RIGHT, "Max RTT" },
273         {G_TYPE_STRING, RIGHT, "Avg RTT" },
274         {G_TYPE_UINT, RIGHT,  "Min in Frame" },
275         {G_TYPE_UINT, RIGHT,  "Max in Frame" },
276         {G_TYPE_UINT, RIGHT,  "Open Requests" },
277         {G_TYPE_UINT, RIGHT,  "Discarded Responses" },
278         {G_TYPE_UINT, RIGHT,  "Repeated Requests" },
279         {G_TYPE_UINT, RIGHT,  "Repeated Responses"}
280 };
281
282 static void
283 gtk_h225rassrt_init(const char *optarg, void *userdata _U_)
284 {
285         h225rassrt_t *hs;
286         GString *error_string;
287         GtkWidget *bbox;
288         GtkWidget *close_bt;
289
290         hs=g_malloc(sizeof(h225rassrt_t));
291
292         if(strncmp(optarg,"h225,srt,",9) == 0){
293                 hs->filter=g_strdup(optarg+9);
294         } else {
295                 hs->filter=NULL;
296         }
297
298         h225rassrt_reset(hs);
299
300         hs->win = dlg_window_new("h225-ras-srt");  /* transient_for top_level */
301         gtk_window_set_destroy_with_parent (GTK_WINDOW(hs->win), TRUE);
302         gtk_window_set_default_size(GTK_WINDOW(hs->win), 600, 300);
303
304         hs->vbox=gtk_vbox_new(FALSE, 3);
305         gtk_container_set_border_width(GTK_CONTAINER(hs->vbox), 12);
306
307         init_main_stat_window(hs->win, hs->vbox, "H.225 RAS Service Response Time", hs->filter);
308
309         /* init a scrolled window*/
310         hs->scrolled_window = scrolled_window_new(NULL, NULL);
311
312         hs->table = create_stat_table(hs->scrolled_window, hs->vbox, 11, titles);
313
314         error_string=register_tap_listener("h225", hs, hs->filter, 0, h225rassrt_reset, h225rassrt_packet, h225rassrt_draw);
315         if(error_string){
316                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error_string->str);
317                 g_string_free(error_string, TRUE);
318                 g_free(hs->filter);
319                 g_free(hs);
320                 return;
321         }
322
323         /* Button row. */
324         bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
325         gtk_box_pack_end(GTK_BOX(hs->vbox), bbox, FALSE, FALSE, 0);
326
327         close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
328         window_set_cancel_button(hs->win, close_bt, window_cancel_button_cb);
329
330         g_signal_connect(hs->win, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
331         g_signal_connect(hs->win, "destroy", G_CALLBACK(win_destroy_cb), hs);
332
333         gtk_widget_show_all(hs->win);
334         window_present(hs->win);
335
336         cf_retap_packets(&cfile);
337         gdk_window_raise(gtk_widget_get_window(hs->win));
338 }
339
340 void
341 register_tap_listener_gtk_h225rassrt(void)
342 {
343         register_dfilter_stat(&h225_rassrt_dlg, "H.225 RAS",
344             REGISTER_STAT_GROUP_RESPONSE_TIME);
345 }
346
347 void h225_srt_cb(GtkAction *action, gpointer user_data _U_)
348 {
349         tap_param_dlg_cb(action, &h225_rassrt_dlg);
350 }
351