Second step in introducing asn context to BER dissectors just like in PER.
[obnox/wireshark/wip.git] / gtk / gsm_map_summary.c
1 /* gsm_map_summary.c
2  * Routines for GSM MAP Statictics summary window
3  *
4  * Copyright 2004, Michael Lum <mlum [AT] telostech.com>
5  * In association with Telos Technology Inc.
6  *
7  * Modified from summary_dlg.c
8  *
9  * $Id$
10  *
11  * Wireshark - Network traffic analyzer
12  * By Gerald Combs <gerald@wireshark.org>
13  * Copyright 1998 Gerald Combs
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <gtk/gtk.h>
35
36 #include <wtap.h>
37
38 #include "epan/packet_info.h"
39 #include "epan/epan.h"
40 #include "epan/value_string.h"
41 #include "../stat_menu.h"
42 #include "gui_stat_menu.h"
43 #include "globals.h"
44 #include "file.h"
45 #include "summary.h"
46 #include "dlg_utils.h"
47 #include "gui_utils.h"
48 #include "compat_macros.h"
49 #include <epan/tap.h>
50
51 #include <epan/asn1.h>
52 #include <epan/dissectors/packet-gsm_map.h>
53 #include "gsm_map_stat.h"
54
55 #define SUM_STR_MAX 1024
56
57
58 static void
59 add_string_to_box(gchar *str, GtkWidget *box)
60 {
61   GtkWidget *lb;
62   lb = gtk_label_new(str);
63   gtk_misc_set_alignment(GTK_MISC(lb), 0.0, 0.5);
64   gtk_box_pack_start(GTK_BOX(box), lb,FALSE,FALSE, 0);
65   gtk_widget_show(lb);
66 }
67
68
69 static void
70 gsm_map_stat_gtk_sum_cb(GtkWidget *w _U_, gpointer d _U_)
71 {
72   summary_tally summary;
73   GtkWidget     *sum_open_w,
74                 *main_vb, *file_fr, *data_fr, *file_box,
75                 *data_box, *bbox, *close_bt,
76                 *invoke_fr, *invoke_box,
77                 *rr_fr, *rr_box,
78                 *tot_fr, *tot_box;
79
80   gchar         string_buff[SUM_STR_MAX];
81   double        seconds;
82   int           i;
83   int           tot_invokes, tot_rr;
84   double        tot_invokes_size, tot_rr_size;
85
86   /* initialize the tally */
87   summary_fill_in(&cfile, &summary);
88
89   /* initial compututations */
90   seconds = summary.stop_time - summary.start_time;
91
92   sum_open_w = window_new(GTK_WINDOW_TOPLEVEL, "GSM MAP Statistics: Summary");
93
94   /* Container for each row of widgets */
95   main_vb = gtk_vbox_new(FALSE, 3);
96   gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
97   gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
98   gtk_widget_show(main_vb);
99
100   /* File frame */
101   file_fr = gtk_frame_new("File");
102   gtk_container_add(GTK_CONTAINER(main_vb), file_fr);
103   gtk_widget_show(file_fr);
104
105   file_box = gtk_vbox_new(FALSE, 3);
106   gtk_container_add(GTK_CONTAINER(file_fr), file_box);
107   gtk_widget_show(file_box);
108
109   /* filename */
110   g_snprintf(string_buff, SUM_STR_MAX, "Name: %s", ((summary.filename) ? summary.filename : "None"));
111   add_string_to_box(string_buff, file_box);
112
113   /* length */
114   g_snprintf(string_buff, SUM_STR_MAX, "Length: %lld", summary.file_length);
115   add_string_to_box(string_buff, file_box);
116
117   /* format */
118   g_snprintf(string_buff, SUM_STR_MAX, "Format: %s", wtap_file_type_string(summary.encap_type));
119   add_string_to_box(string_buff, file_box);
120
121   if (summary.has_snap) {
122     /* snapshot length */
123     g_snprintf(string_buff, SUM_STR_MAX, "Snapshot length: %u", summary.snap);
124     add_string_to_box(string_buff, file_box);
125   }
126
127   /* Data frame */
128   data_fr = gtk_frame_new("Data");
129   gtk_container_add(GTK_CONTAINER(main_vb), data_fr);
130   gtk_widget_show(data_fr);
131
132   data_box = gtk_vbox_new(FALSE, 3);
133   gtk_container_add(GTK_CONTAINER(data_fr), data_box);
134   gtk_widget_show(data_box);
135
136   /* seconds */
137   g_snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time);
138   add_string_to_box(string_buff, data_box);
139
140   g_snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
141   add_string_to_box(string_buff, data_box);
142
143   /* Packet count */
144   g_snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.packet_count);
145   add_string_to_box(string_buff, data_box);
146
147   tot_invokes = 0;
148   tot_invokes_size = 0;
149   for (i=0; i < GSM_MAP_MAX_NUM_OPR_CODES; i++)
150   {
151     tot_invokes += gsm_map_stat.opr_code[i];
152     tot_invokes_size += gsm_map_stat.size[i];
153   }
154
155   tot_rr = 0;
156   tot_rr_size = 0;
157   for (i=0; i < GSM_MAP_MAX_NUM_OPR_CODES; i++)
158   {
159     tot_rr += gsm_map_stat.opr_code_rr[i];
160     tot_rr_size += gsm_map_stat.size_rr[i];
161   }
162
163   /* Invoke frame */
164   invoke_fr = gtk_frame_new("Invokes");
165   gtk_container_add(GTK_CONTAINER(main_vb), invoke_fr);
166   gtk_widget_show(invoke_fr);
167
168   invoke_box = gtk_vbox_new(FALSE, 3);
169   gtk_container_add(GTK_CONTAINER(invoke_fr), invoke_box);
170   gtk_widget_show(invoke_box);
171
172   /* Total number of invokes */
173   g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes: %u", tot_invokes);
174   add_string_to_box(string_buff, invoke_box);
175
176   /* Total number of invokes per second */
177   if (seconds)
178         g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes per second: %.2f", tot_invokes/seconds);
179   else
180         g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes per second: N/A");
181   add_string_to_box(string_buff, invoke_box);
182
183   /* Total size of invokes */
184   g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for Invokes: %.0f", tot_invokes_size);
185   add_string_to_box(string_buff, invoke_box);
186
187   /* Average size of invokes */
188   if (tot_invokes)
189         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Invoke: %.2f", tot_invokes_size/tot_invokes);
190   else
191         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Invoke: N/A");
192   add_string_to_box(string_buff, invoke_box);
193
194   /* Average size of invokes per second */
195   if (seconds)
196         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: %.2f", tot_invokes_size/seconds);
197   else
198         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: N/A");
199   add_string_to_box(string_buff, invoke_box);
200
201   /* Return Results frame */
202   rr_fr = gtk_frame_new("Return Results");
203   gtk_container_add(GTK_CONTAINER(main_vb), rr_fr);
204   gtk_widget_show(rr_fr);
205
206   rr_box = gtk_vbox_new(FALSE, 3);
207   gtk_container_add(GTK_CONTAINER(rr_fr), rr_box);
208   gtk_widget_show(rr_box);
209
210   /* Total number of return results */
211   g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results: %u", tot_rr);
212   add_string_to_box(string_buff, rr_box);
213
214   /* Total number of return results per second */
215   if (seconds)
216         g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results per second: %.2f", tot_rr/seconds);
217   else
218         g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results per second: N/A");
219   add_string_to_box(string_buff, rr_box);
220
221   /* Total size of return results */
222   g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for Return Results: %.0f", tot_rr_size);
223   add_string_to_box(string_buff, rr_box);
224
225   /* Average size of return results */
226   if (tot_rr)
227         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Return Result: %.2f", tot_rr_size/tot_rr);
228   else
229         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Return Result: N/A");
230   add_string_to_box(string_buff, rr_box);
231
232   /* Average size of return results per second */
233   if (seconds)
234         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: %.2f", tot_rr_size/seconds);
235   else
236         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: N/A");
237   add_string_to_box(string_buff, rr_box);
238
239   /* Totals frame */
240   tot_fr = gtk_frame_new("Totals");
241   gtk_container_add(GTK_CONTAINER(main_vb), tot_fr);
242   gtk_widget_show(tot_fr);
243
244   tot_box = gtk_vbox_new(FALSE, 3);
245   gtk_container_add(GTK_CONTAINER(tot_fr), tot_box);
246   gtk_widget_show(tot_box);
247
248   /* Total number of return results */
249   g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages: %u", tot_invokes + tot_rr);
250   add_string_to_box(string_buff, tot_box);
251
252   if (seconds)
253         g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages per second: %.2f",
254                 (tot_invokes + tot_rr)/seconds);
255   else
256         g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages per second: N/A");
257   add_string_to_box(string_buff, tot_box);
258
259   g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for GSM MAP messages: %.0f", tot_invokes_size + tot_rr_size);
260   add_string_to_box(string_buff, tot_box);
261
262   if (tot_invokes + tot_rr)
263         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per GSM MAP messages: %.2f",
264                 (tot_invokes_size + tot_rr_size)/(tot_invokes + tot_rr));
265   else
266         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per GSM MAP messages: N/A");
267   add_string_to_box(string_buff, tot_box);
268
269   if (seconds)
270         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes second: %.2f",
271                 (tot_invokes_size + tot_rr_size)/seconds);
272   else
273           g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes second: N/A");
274   add_string_to_box(string_buff, tot_box);
275
276
277   /* Button row. */
278   bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
279   gtk_container_add(GTK_CONTAINER(main_vb), bbox);
280   gtk_widget_show(bbox);
281
282   close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
283   window_set_cancel_button(sum_open_w, close_bt, window_cancel_button_cb);
284
285   SIGNAL_CONNECT(sum_open_w, "delete_event", window_delete_event_cb, NULL);
286
287   gtk_widget_show(sum_open_w);
288   window_present(sum_open_w);
289 }
290
291
292 void
293 register_tap_listener_gtkgsm_map_summary(void)
294 {
295     register_stat_menu_item("GSM/MAP Summary",  REGISTER_STAT_GROUP_TELEPHONY,
296         gsm_map_stat_gtk_sum_cb, NULL, NULL, NULL);
297 }