Fix https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8105 :
[metze/wireshark/wip.git] / ui / 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28  */
29
30 #include "config.h"
31
32 #include <gtk/gtk.h>
33
34 #include <wiretap/wtap.h>
35
36 #include <epan/epan.h>
37 #include <epan/packet.h>
38 #include <epan/packet_info.h>
39 #include <epan/value_string.h>
40 #include <epan/tap.h>
41 #include <epan/asn1.h>
42 #include <epan/dissectors/packet-gsm_map.h>
43
44 #include "../stat_menu.h"
45 #include "../globals.h"
46 #include "../file.h"
47 #include "../summary.h"
48
49 #include "ui/gtk/gui_stat_menu.h"
50 #include "ui/gtk/dlg_utils.h"
51 #include "ui/gtk/gui_utils.h"
52 #include "ui/gtk/gsm_map_stat.h"
53
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.0f, 0.5f);
64   gtk_box_pack_start(GTK_BOX(box), lb,FALSE,FALSE, 0);
65   gtk_widget_show(lb);
66 }
67
68 void gsm_map_stat_gtk_sum_cb(GtkAction *action _U_, gpointer user_data _U_)
69 {
70   summary_tally summary;
71   GtkWidget     *sum_open_w,
72                 *main_vb, *file_fr, *data_fr, *file_box,
73                 *data_box, *bbox, *close_bt,
74                 *invoke_fr, *invoke_box,
75                 *rr_fr, *rr_box,
76                 *tot_fr, *tot_box;
77
78   gchar         string_buff[SUM_STR_MAX];
79   double        seconds;
80   int           i;
81   int           tot_invokes, tot_rr;
82   double        tot_invokes_size, tot_rr_size;
83
84   /* initialize the tally */
85   summary_fill_in(&cfile, &summary);
86
87   /* initial computations */
88   seconds = summary.stop_time - summary.start_time;
89
90   sum_open_w = dlg_window_new("GSM MAP Statistics: Summary");  /* transient_for top_level */
91   gtk_window_set_destroy_with_parent (GTK_WINDOW(sum_open_w), TRUE);
92
93   /* Container for each row of widgets */
94   main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
95   gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
96   gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
97   gtk_widget_show(main_vb);
98
99   /* File frame */
100   file_fr = gtk_frame_new("File");
101   gtk_box_pack_start(GTK_BOX (main_vb), file_fr, TRUE, TRUE, 0);
102   gtk_widget_show(file_fr);
103
104   file_box = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
105   gtk_container_add(GTK_CONTAINER(file_fr), file_box);
106   gtk_widget_show(file_box);
107
108   /* filename */
109   g_snprintf(string_buff, SUM_STR_MAX, "Name: %s", ((summary.filename) ? summary.filename : "None"));
110   add_string_to_box(string_buff, file_box);
111
112   /* length */
113   g_snprintf(string_buff, SUM_STR_MAX, "Length: %" G_GINT64_MODIFIER "d", summary.file_length);
114   add_string_to_box(string_buff, file_box);
115
116   /* format */
117   g_snprintf(string_buff, SUM_STR_MAX, "Format: %s", wtap_file_type_string(summary.file_type));
118   add_string_to_box(string_buff, file_box);
119
120   if (summary.has_snap) {
121     /* snapshot length */
122     g_snprintf(string_buff, SUM_STR_MAX, "Snapshot length: %u", summary.snap);
123     add_string_to_box(string_buff, file_box);
124   }
125
126   /* Data frame */
127   data_fr = gtk_frame_new("Data");
128   gtk_box_pack_start(GTK_BOX (main_vb), data_fr, TRUE, TRUE, 0);
129   gtk_widget_show(data_fr);
130
131   data_box = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
132   gtk_container_add(GTK_CONTAINER(data_fr), data_box);
133   gtk_widget_show(data_box);
134
135   /*
136    * We must have no un-time-stamped packets (i.e., the number of
137    * time-stamped packets must be the same as the number of packets),
138    * and at least two time-stamped packets, in order for the elapsed
139    * time to be valid.
140    */
141   if (summary.packet_count_ts == summary.packet_count &&
142       summary.packet_count_ts >= 2) {
143     /* seconds */
144     g_snprintf(string_buff, SUM_STR_MAX, "Elapsed time: %.3f seconds", summary.elapsed_time);
145     add_string_to_box(string_buff, data_box);
146
147     g_snprintf(string_buff, SUM_STR_MAX, "Between first and last packet: %.3f seconds", seconds);
148     add_string_to_box(string_buff, data_box);
149   }
150
151   /* Packet count */
152   g_snprintf(string_buff, SUM_STR_MAX, "Packet count: %i", summary.packet_count);
153   add_string_to_box(string_buff, data_box);
154
155   tot_invokes = 0;
156   tot_invokes_size = 0;
157   for (i=0; i < GSM_MAP_MAX_NUM_OPR_CODES; i++)
158   {
159     tot_invokes += gsm_map_stat.opr_code[i];
160     tot_invokes_size += gsm_map_stat.size[i];
161   }
162
163   tot_rr = 0;
164   tot_rr_size = 0;
165   for (i=0; i < GSM_MAP_MAX_NUM_OPR_CODES; i++)
166   {
167     tot_rr += gsm_map_stat.opr_code_rr[i];
168     tot_rr_size += gsm_map_stat.size_rr[i];
169   }
170
171   /* Invoke frame */
172   invoke_fr = gtk_frame_new("Invokes");
173   gtk_box_pack_start(GTK_BOX (main_vb), invoke_fr, TRUE, TRUE, 0);
174   gtk_widget_show(invoke_fr);
175
176   invoke_box = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
177   gtk_container_add(GTK_CONTAINER(invoke_fr), invoke_box);
178   gtk_widget_show(invoke_box);
179
180   /* Total number of invokes */
181   g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes: %u", tot_invokes);
182   add_string_to_box(string_buff, invoke_box);
183
184   /*
185    * We must have no un-time-stamped packets (i.e., the number of
186    * time-stamped packets must be the same as the number of packets),
187    * and at least two time-stamped packets, in order for the elapsed
188    * time to be valid.
189    */
190   if (summary.packet_count_ts == summary.packet_count &&
191       summary.packet_count_ts >= 2) {
192     /* Total number of invokes per second */
193     if (seconds)
194       g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes per second: %.2f", tot_invokes/seconds);
195     else
196       g_snprintf(string_buff, SUM_STR_MAX, "Total number of Invokes per second: N/A");
197     add_string_to_box(string_buff, invoke_box);
198   }
199
200   /* Total size of invokes */
201   g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for Invokes: %.0f", tot_invokes_size);
202   add_string_to_box(string_buff, invoke_box);
203
204   /* Average size of invokes */
205   if (tot_invokes)
206     g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Invoke: %.2f", tot_invokes_size/tot_invokes);
207   else
208     g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Invoke: N/A");
209   add_string_to_box(string_buff, invoke_box);
210
211   /*
212    * We must have no un-time-stamped packets (i.e., the number of
213    * time-stamped packets must be the same as the number of packets),
214    * and at least two time-stamped packets, in order for the elapsed
215    * time to be valid.
216    */
217   if (summary.packet_count_ts == summary.packet_count &&
218       summary.packet_count_ts >= 2) {
219     /* Average size of invokes per second */
220     if (seconds)
221       g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: %.2f", tot_invokes_size/seconds);
222     else
223       g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: N/A");
224     add_string_to_box(string_buff, invoke_box);
225   }
226
227   /* Return Results frame */
228   rr_fr = gtk_frame_new("Return Results");
229   gtk_box_pack_start(GTK_BOX (main_vb), rr_fr, TRUE, TRUE, 0);
230   gtk_widget_show(rr_fr);
231
232   rr_box = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
233   gtk_container_add(GTK_CONTAINER(rr_fr), rr_box);
234   gtk_widget_show(rr_box);
235
236   /* Total number of return results */
237   g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results: %u", tot_rr);
238   add_string_to_box(string_buff, rr_box);
239
240   /*
241    * We must have no un-time-stamped packets (i.e., the number of
242    * time-stamped packets must be the same as the number of packets),
243    * and at least two time-stamped packets, in order for the elapsed
244    * time to be valid.
245    */
246   if (summary.packet_count_ts == summary.packet_count &&
247       summary.packet_count_ts >= 2) {
248     /* Total number of return results per second */
249     if (seconds)
250       g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results per second: %.2f", tot_rr/seconds);
251     else
252       g_snprintf(string_buff, SUM_STR_MAX, "Total number of Return Results per second: N/A");
253     add_string_to_box(string_buff, rr_box);
254   }
255
256   /* Total size of return results */
257   g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for Return Results: %.0f", tot_rr_size);
258   add_string_to_box(string_buff, rr_box);
259
260   /* Average size of return results */
261   if (tot_rr)
262     g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Return Result: %.2f", tot_rr_size/tot_rr);
263   else
264     g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per Return Result: N/A");
265   add_string_to_box(string_buff, rr_box);
266
267   /*
268    * We must have no un-time-stamped packets (i.e., the number of
269    * time-stamped packets must be the same as the number of packets),
270    * and at least two time-stamped packets, in order for the elapsed
271    * time to be valid.
272    */
273   if (summary.packet_count_ts == summary.packet_count &&
274       summary.packet_count_ts >= 2) {
275     /* Average size of return results per second */
276     if (seconds)
277       g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: %.2f", tot_rr_size/seconds);
278     else
279       g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per second: N/A");
280     add_string_to_box(string_buff, rr_box);
281   }
282
283   /* Totals frame */
284   tot_fr = gtk_frame_new("Totals");
285   gtk_box_pack_start(GTK_BOX (main_vb), tot_fr, TRUE, TRUE, 0);
286   gtk_widget_show(tot_fr);
287
288   tot_box = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
289   gtk_container_add(GTK_CONTAINER(tot_fr), tot_box);
290   gtk_widget_show(tot_box);
291
292   /* Total number of return results */
293   g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages: %u", tot_invokes + tot_rr);
294   add_string_to_box(string_buff, tot_box);
295
296   /*
297    * We must have no un-time-stamped packets (i.e., the number of
298    * time-stamped packets must be the same as the number of packets),
299    * and at least two time-stamped packets, in order for the elapsed
300    * time to be valid.
301    */
302   if (summary.packet_count_ts == summary.packet_count &&
303       summary.packet_count_ts >= 2) {
304     if (seconds)
305       g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages per second: %.2f",
306                  (tot_invokes + tot_rr)/seconds);
307     else
308       g_snprintf(string_buff, SUM_STR_MAX, "Total number of GSM MAP messages per second: N/A");
309     add_string_to_box(string_buff, tot_box);
310   }
311
312   g_snprintf(string_buff, SUM_STR_MAX, "Total number of bytes for GSM MAP messages: %.0f", tot_invokes_size + tot_rr_size);
313   add_string_to_box(string_buff, tot_box);
314
315   if (tot_invokes + tot_rr)
316     g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per GSM MAP messages: %.2f",
317                (tot_invokes_size + tot_rr_size)/(tot_invokes + tot_rr));
318   else
319     g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes per GSM MAP messages: N/A");
320   add_string_to_box(string_buff, tot_box);
321
322   /*
323    * We must have no un-time-stamped packets (i.e., the number of
324    * time-stamped packets must be the same as the number of packets),
325    * and at least two time-stamped packets, in order for the elapsed
326    * time to be valid.
327    */
328   if (summary.packet_count_ts == summary.packet_count &&
329       summary.packet_count_ts >= 2) {
330     if (seconds)
331       g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes second: %.2f",
332                  (tot_invokes_size + tot_rr_size)/seconds);
333     else
334       g_snprintf(string_buff, SUM_STR_MAX, "Average number of bytes second: N/A");
335     add_string_to_box(string_buff, tot_box);
336   }
337
338   /* Button row. */
339   bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
340   gtk_box_pack_start(GTK_BOX(main_vb), bbox, TRUE, TRUE, 0);
341   gtk_widget_show(bbox);
342
343   close_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLOSE);
344   window_set_cancel_button(sum_open_w, close_bt, window_cancel_button_cb);
345
346   g_signal_connect(sum_open_w, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
347
348   gtk_widget_show(sum_open_w);
349   window_present(sum_open_w);
350 }
351
352
353 void
354 register_tap_listener_gtkgsm_map_summary(void)
355 {
356 }