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