Warningfix:
[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 #ifdef HAVE_SYS_TYPES_H
35 #include <sys/types.h>
36 #endif
37
38 #include <gtk/gtk.h>
39
40 #include <wiretap/wtap.h>
41
42 #include <epan/epan.h>
43 #include <epan/packet.h>
44 #include <epan/packet_info.h>
45 #include <epan/value_string.h>
46 #include <epan/tap.h>
47 #include <epan/asn1.h>
48 #include <epan/dissectors/packet-gsm_map.h>
49
50 #include "../stat_menu.h"
51 #include "../globals.h"
52 #include "../file.h"
53 #include "../summary.h"
54
55 #include "gtk/gui_stat_menu.h"
56 #include "gtk/dlg_utils.h"
57 #include "gtk/gui_utils.h"
58 #include "gtk/gsm_map_stat.h"
59
60
61 #define SUM_STR_MAX 1024
62
63
64 static void
65 add_string_to_box(gchar *str, GtkWidget *box)
66 {
67   GtkWidget *lb;
68   lb = gtk_label_new(str);
69   gtk_misc_set_alignment(GTK_MISC(lb), 0.0f, 0.5f);
70   gtk_box_pack_start(GTK_BOX(box), lb,FALSE,FALSE, 0);
71   gtk_widget_show(lb);
72 }
73
74
75 static void
76 gsm_map_stat_gtk_sum_cb(GtkWidget *w _U_, gpointer d _U_)
77 {
78   summary_tally summary;
79   GtkWidget     *sum_open_w,
80                 *main_vb, *file_fr, *data_fr, *file_box,
81                 *data_box, *bbox, *close_bt,
82                 *invoke_fr, *invoke_box,
83                 *rr_fr, *rr_box,
84                 *tot_fr, *tot_box;
85
86   gchar         string_buff[SUM_STR_MAX];
87   double        seconds;
88   int           i;
89   int           tot_invokes, tot_rr;
90   double        tot_invokes_size, tot_rr_size;
91
92   /* initialize the tally */
93   summary_fill_in(&cfile, &summary);
94
95   /* initial compututations */
96   seconds = summary.stop_time - summary.start_time;
97
98   sum_open_w = window_new(GTK_WINDOW_TOPLEVEL, "GSM MAP Statistics: Summary");
99
100   /* Container for each row of widgets */
101   main_vb = gtk_vbox_new(FALSE, 3);
102   gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
103   gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
104   gtk_widget_show(main_vb);
105
106   /* File frame */
107   file_fr = gtk_frame_new("File");
108   gtk_container_add(GTK_CONTAINER(main_vb), file_fr);
109   gtk_widget_show(file_fr);
110
111   file_box = gtk_vbox_new(FALSE, 3);
112   gtk_container_add(GTK_CONTAINER(file_fr), file_box);
113   gtk_widget_show(file_box);
114
115   /* filename */
116   g_snprintf(string_buff, SUM_STR_MAX, "Name: %s", ((summary.filename) ? summary.filename : "None"));
117   add_string_to_box(string_buff, file_box);
118
119   /* length */
120   g_snprintf(string_buff, SUM_STR_MAX, "Length: %" G_GINT64_MODIFIER "d", summary.file_length);
121   add_string_to_box(string_buff, file_box);
122
123   /* format */
124   g_snprintf(string_buff, SUM_STR_MAX, "Format: %s", wtap_file_type_string(summary.file_type));
125   add_string_to_box(string_buff, file_box);
126
127   if (summary.has_snap) {
128     /* snapshot length */
129     g_snprintf(string_buff, SUM_STR_MAX, "Snapshot length: %u", summary.snap);
130     add_string_to_box(string_buff, file_box);
131   }
132
133   /* Data frame */
134   data_fr = gtk_frame_new("Data");
135   gtk_container_add(GTK_CONTAINER(main_vb), data_fr);
136   gtk_widget_show(data_fr);
137
138   data_box = gtk_vbox_new(FALSE, 3);
139   gtk_container_add(GTK_CONTAINER(data_fr), data_box);
140   gtk_widget_show(data_box);
141
142   /* seconds */
143   g_snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time);
144   add_string_to_box(string_buff, data_box);
145
146   g_snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
147   add_string_to_box(string_buff, data_box);
148
149   /* Packet count */
150   g_snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.packet_count);
151   add_string_to_box(string_buff, data_box);
152
153   tot_invokes = 0;
154   tot_invokes_size = 0;
155   for (i=0; i < GSM_MAP_MAX_NUM_OPR_CODES; i++)
156   {
157     tot_invokes += gsm_map_stat.opr_code[i];
158     tot_invokes_size += gsm_map_stat.size[i];
159   }
160
161   tot_rr = 0;
162   tot_rr_size = 0;
163   for (i=0; i < GSM_MAP_MAX_NUM_OPR_CODES; i++)
164   {
165     tot_rr += gsm_map_stat.opr_code_rr[i];
166     tot_rr_size += gsm_map_stat.size_rr[i];
167   }
168
169   /* Invoke frame */
170   invoke_fr = gtk_frame_new("Invokes");
171   gtk_container_add(GTK_CONTAINER(main_vb), invoke_fr);
172   gtk_widget_show(invoke_fr);
173
174   invoke_box = gtk_vbox_new(FALSE, 3);
175   gtk_container_add(GTK_CONTAINER(invoke_fr), invoke_box);
176   gtk_widget_show(invoke_box);
177
178   /* Total number of invokes */
179   g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes: %u", tot_invokes);
180   add_string_to_box(string_buff, invoke_box);
181
182   /* Total number of invokes per second */
183   if (seconds)
184         g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes per second: %.2f", tot_invokes/seconds);
185   else
186         g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes per second: N/A");
187   add_string_to_box(string_buff, invoke_box);
188
189   /* Total size of invokes */
190   g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for Invokes: %.0f", tot_invokes_size);
191   add_string_to_box(string_buff, invoke_box);
192
193   /* Average size of invokes */
194   if (tot_invokes)
195         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Invoke: %.2f", tot_invokes_size/tot_invokes);
196   else
197         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Invoke: N/A");
198   add_string_to_box(string_buff, invoke_box);
199
200   /* Average size of invokes per second */
201   if (seconds)
202         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: %.2f", tot_invokes_size/seconds);
203   else
204         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: N/A");
205   add_string_to_box(string_buff, invoke_box);
206
207   /* Return Results frame */
208   rr_fr = gtk_frame_new("Return Results");
209   gtk_container_add(GTK_CONTAINER(main_vb), rr_fr);
210   gtk_widget_show(rr_fr);
211
212   rr_box = gtk_vbox_new(FALSE, 3);
213   gtk_container_add(GTK_CONTAINER(rr_fr), rr_box);
214   gtk_widget_show(rr_box);
215
216   /* Total number of return results */
217   g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results: %u", tot_rr);
218   add_string_to_box(string_buff, rr_box);
219
220   /* Total number of return results per second */
221   if (seconds)
222         g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results per second: %.2f", tot_rr/seconds);
223   else
224         g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results per second: N/A");
225   add_string_to_box(string_buff, rr_box);
226
227   /* Total size of return results */
228   g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for Return Results: %.0f", tot_rr_size);
229   add_string_to_box(string_buff, rr_box);
230
231   /* Average size of return results */
232   if (tot_rr)
233         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Return Result: %.2f", tot_rr_size/tot_rr);
234   else
235         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Return Result: N/A");
236   add_string_to_box(string_buff, rr_box);
237
238   /* Average size of return results per second */
239   if (seconds)
240         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: %.2f", tot_rr_size/seconds);
241   else
242         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: N/A");
243   add_string_to_box(string_buff, rr_box);
244
245   /* Totals frame */
246   tot_fr = gtk_frame_new("Totals");
247   gtk_container_add(GTK_CONTAINER(main_vb), tot_fr);
248   gtk_widget_show(tot_fr);
249
250   tot_box = gtk_vbox_new(FALSE, 3);
251   gtk_container_add(GTK_CONTAINER(tot_fr), tot_box);
252   gtk_widget_show(tot_box);
253
254   /* Total number of return results */
255   g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages: %u", tot_invokes + tot_rr);
256   add_string_to_box(string_buff, tot_box);
257
258   if (seconds)
259         g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages per second: %.2f",
260                 (tot_invokes + tot_rr)/seconds);
261   else
262         g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages per second: N/A");
263   add_string_to_box(string_buff, tot_box);
264
265   g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for GSM MAP messages: %.0f", tot_invokes_size + tot_rr_size);
266   add_string_to_box(string_buff, tot_box);
267
268   if (tot_invokes + tot_rr)
269         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per GSM MAP messages: %.2f",
270                 (tot_invokes_size + tot_rr_size)/(tot_invokes + tot_rr));
271   else
272         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per GSM MAP messages: N/A");
273   add_string_to_box(string_buff, tot_box);
274
275   if (seconds)
276         g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes second: %.2f",
277                 (tot_invokes_size + tot_rr_size)/seconds);
278   else
279           g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes second: N/A");
280   add_string_to_box(string_buff, tot_box);
281
282
283   /* Button row. */
284   bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
285   gtk_container_add(GTK_CONTAINER(main_vb), bbox);
286   gtk_widget_show(bbox);
287
288   close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
289   window_set_cancel_button(sum_open_w, close_bt, window_cancel_button_cb);
290
291   g_signal_connect(sum_open_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
292
293   gtk_widget_show(sum_open_w);
294   window_present(sum_open_w);
295 }
296
297
298 void
299 register_tap_listener_gtkgsm_map_summary(void)
300 {
301     register_stat_menu_item("GSM/MAP Summary",  REGISTER_STAT_GROUP_TELEPHONY,
302         gsm_map_stat_gtk_sum_cb, NULL, NULL, NULL);
303 }