1 /* mtp3_summary_dialog.cpp
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
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.
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.
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.
26 #include "mtp3_summary_dialog.h"
27 #include <ui_mtp3_summary_dialog.h>
38 #include <epan/dissectors/packet-mtp3.h>
40 #include "wsutil/utf8_entities.h"
42 #include "ui/capture_globals.h"
43 #include "ui/simple_dialog.h"
45 #include "qt_ui_utils.h"
47 #include <QTextStream>
49 typedef struct _mtp3_stat_si_code_t {
52 } mtp3_stat_si_code_t;
54 typedef struct _mtp3_stat_t {
55 mtp3_addr_pc_t addr_opc;
56 mtp3_addr_pc_t addr_dpc;
57 mtp3_stat_si_code_t mtp3_si_code[MTP3_NUM_SI_CODE];
60 #define MTP3_MAX_NUM_OPC_DPC 50
62 static mtp3_stat_t mtp3_stat[MTP3_MAX_NUM_OPC_DPC];
63 static size_t mtp3_num_used;
65 Mtp3SummaryDialog::Mtp3SummaryDialog(QWidget &parent, CaptureFile &capture_file) :
66 WiresharkDialog(parent, capture_file),
67 ui(new Ui::Mtp3SummaryDialog)
71 setWindowSubtitle(tr("MTP3 Summary"));
75 Mtp3SummaryDialog::~Mtp3SummaryDialog()
80 QString Mtp3SummaryDialog::summaryToHtml()
82 summary_tally summary;
83 memset(&summary, 0, sizeof(summary_tally));
86 QString table_begin, table_end;
87 QString table_row_begin, table_ul_row_begin, table_row_end;
88 QString table_vheader_tmpl, table_hheader15_tmpl, table_hheader25_tmpl;
89 QString table_data_tmpl;
91 section_tmpl = "<p><strong>%1</strong></p>\n";
92 table_begin = "<p><table>\n";
93 table_end = "</table></p>\n";
94 table_row_begin = "<tr>\n";
95 table_ul_row_begin = "<tr style=\"border-bottom: 1px solid gray;\">\n";
96 table_row_end = "</tr>\n";
97 table_vheader_tmpl = "<td width=\"50%\">%1:</td>"; // <th align="left"> looked odd
98 table_hheader15_tmpl = "<td width=\"15%\"><u>%1</u></td>";
99 table_hheader25_tmpl = "<td width=\"25%\"><u>%1</u></td>";
100 table_data_tmpl = "<td>%1</td>";
102 if (cap_file_.isValid()) {
103 /* initial computations */
104 summary_fill_in(cap_file_.capFile(), &summary);
106 summary_fill_in_capture(cap_file_.capFile(), &global_capture_opts, &summary);
111 QTextStream out(&summary_str);
114 out << section_tmpl.arg(tr("File"));
117 out << table_row_begin
118 << table_vheader_tmpl.arg(tr("Name"))
119 << table_data_tmpl.arg(summary.filename)
122 out << table_row_begin
123 << table_vheader_tmpl.arg(tr("Length"))
124 << table_data_tmpl.arg(file_size_to_qstring(summary.file_length))
127 QString format_str = wtap_file_type_subtype_string(summary.file_type);
128 if (summary.iscompressed) {
129 format_str.append(tr(" (gzip compressed)"));
131 out << table_row_begin
132 << table_vheader_tmpl.arg(tr("Format"))
133 << table_data_tmpl.arg(format_str)
136 if (summary.has_snap) {
137 out << table_row_begin
138 << table_vheader_tmpl.arg(tr("Snapshot length"))
139 << table_data_tmpl.arg(summary.snap)
146 out << section_tmpl.arg(tr("Data"));
149 if (summary.packet_count_ts == summary.packet_count &&
150 summary.packet_count >= 1)
153 out << table_row_begin
154 << table_vheader_tmpl.arg(tr("First packet"))
155 << table_data_tmpl.arg(time_t_to_qstring((time_t)summary.start_time))
159 out << table_row_begin
160 << table_vheader_tmpl.arg(tr("Last packet"))
161 << table_data_tmpl.arg(time_t_to_qstring((time_t)summary.stop_time))
164 // elapsed seconds (capture duration)
165 if (summary.packet_count_ts > 1)
167 /* elapsed seconds */
169 unsigned int elapsed_time = (unsigned int)summary.elapsed_time;
170 if (elapsed_time/86400)
172 elapsed_str = QString("%1 days ").arg(elapsed_time / 86400);
175 elapsed_str += QString("%1:%2:%3")
176 .arg(elapsed_time % 86400 / 3600, 2, 10, QChar('0'))
177 .arg(elapsed_time % 3600 / 60, 2, 10, QChar('0'))
178 .arg(elapsed_time % 60, 2, 10, QChar('0'));
179 out << table_row_begin
180 << table_vheader_tmpl.arg(tr("Elapsed"))
181 << table_data_tmpl.arg(elapsed_str)
187 out << table_row_begin
188 << table_vheader_tmpl.arg(tr("Packets"))
189 << table_data_tmpl.arg(summary.packet_count)
194 QString n_a = UTF8_EM_DASH;
197 double seconds = summary.stop_time - summary.start_time;
200 out << section_tmpl.arg(tr("Service Indicator (SI) Totals"));
203 out << table_row_begin
204 << table_hheader25_tmpl.arg(tr("SI"))
205 << table_hheader15_tmpl.arg(tr("MSUs"))
206 << table_hheader15_tmpl.arg(tr("MSUs/s"))
207 << table_hheader15_tmpl.arg(tr("Bytes"))
208 << table_hheader15_tmpl.arg(tr("Bytes/MSU"))
209 << table_hheader15_tmpl.arg(tr("Bytes/s"))
212 for (size_t ws_si_code = 0; ws_si_code < MTP3_NUM_SI_CODE; ws_si_code++) {
215 QString msus_s_str = n_a;
216 QString bytes_msu_str = n_a;
217 QString bytes_s_str = n_a;
219 for (size_t stat_idx = 0; stat_idx < mtp3_num_used; stat_idx++) {
220 si_msus += mtp3_stat[stat_idx].mtp3_si_code[ws_si_code].num_msus;
221 si_bytes += mtp3_stat[stat_idx].mtp3_si_code[ws_si_code].size;
223 total_msus += si_msus;
224 total_bytes += si_bytes;
227 msus_s_str = QString("%1").arg(si_msus / seconds, 1, 'f', 1);
228 bytes_s_str = QString("%1").arg(si_bytes / seconds, 1, 'f', 1);
232 bytes_msu_str = QString("%1").arg((double) si_bytes / si_msus, 1, 'f', 1);
235 out << table_row_begin
236 << table_data_tmpl.arg(mtp3_service_indicator_code_short_vals[ws_si_code].strptr)
237 << table_data_tmpl.arg(si_msus)
238 << table_data_tmpl.arg(msus_s_str)
239 << table_data_tmpl.arg(si_bytes)
240 << table_data_tmpl.arg(bytes_msu_str)
241 << table_data_tmpl.arg(bytes_s_str)
249 QString total_msus_s_str = n_a;
250 QString total_bytes_msu_str = n_a;
251 QString total_bytes_s_str = n_a;
254 total_msus_s_str = QString("%1").arg(total_msus / seconds, 1, 'f', 1);
255 total_bytes_s_str = QString("%1").arg(total_bytes / seconds, 1, 'f', 1);
257 if (total_msus > 0) {
258 total_bytes_msu_str = QString("%1").arg((double) total_bytes / total_msus, 1, 'f', 1);
261 out << section_tmpl.arg(tr("Totals"));
264 out << table_row_begin
265 << table_vheader_tmpl.arg(tr("Total MSUs"))
266 << table_data_tmpl.arg(total_msus)
269 out << table_row_begin
270 << table_vheader_tmpl.arg(tr("MSUs/s"))
271 << table_data_tmpl.arg(total_msus_s_str)
274 out << table_row_begin
275 << table_vheader_tmpl.arg(tr("Total Bytes"))
276 << table_data_tmpl.arg(total_bytes)
279 out << table_row_begin
280 << table_vheader_tmpl.arg(tr("Average Bytes/MSU"))
281 << table_data_tmpl.arg(total_bytes_msu_str)
284 out << table_row_begin
285 << table_vheader_tmpl.arg(tr("Average Bytes/s"))
286 << table_data_tmpl.arg(total_bytes_s_str)
294 void Mtp3SummaryDialog::updateWidgets()
296 ui->summaryTextEdit->setHtml(summaryToHtml());
298 WiresharkDialog::updateWidgets();
307 mtp3_stat_t (*stat_p)[MTP3_MAX_NUM_OPC_DPC] = (mtp3_stat_t(*)[MTP3_MAX_NUM_OPC_DPC])tapdata;
310 memset(stat_p, 0, MTP3_MAX_NUM_OPC_DPC * sizeof(mtp3_stat_t));
321 mtp3_stat_t (*stat_p)[MTP3_MAX_NUM_OPC_DPC] = (mtp3_stat_t(*)[MTP3_MAX_NUM_OPC_DPC])tapdata;
322 const mtp3_tap_rec_t *data_p = (const mtp3_tap_rec_t *)data;
325 if (data_p->mtp3_si_code >= MTP3_NUM_SI_CODE)
328 * we thought this si_code was not used ?
329 * is MTP3_NUM_SI_CODE out of date ?
335 * look for opc/dpc pair
338 while (i < mtp3_num_used)
340 if (memcmp(&data_p->addr_opc, &(*stat_p)[i].addr_opc, sizeof(mtp3_addr_pc_t)) == 0)
342 if (memcmp(&data_p->addr_dpc, &(*stat_p)[i].addr_dpc, sizeof(mtp3_addr_pc_t)) == 0)
351 if (i == mtp3_num_used)
353 if (mtp3_num_used == MTP3_MAX_NUM_OPC_DPC)
364 (*stat_p)[i].addr_opc = data_p->addr_opc;
365 (*stat_p)[i].addr_dpc = data_p->addr_dpc;
366 (*stat_p)[i].mtp3_si_code[data_p->mtp3_si_code].num_msus++;
367 (*stat_p)[i].mtp3_si_code[data_p->mtp3_si_code].size += data_p->size;
373 register_tap_listener_qt_mtp3_summary(void)
377 memset((void *) &mtp3_stat, 0, sizeof(mtp3_stat));
380 register_tap_listener("mtp3", &mtp3_stat, NULL, 0,
387 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_p->str);
388 g_string_free(err_p, TRUE);
402 * indent-tabs-mode: nil
405 * ex: set shiftwidth=4 tabstop=8 expandtab:
406 * :indentSize=4:tabSize=8:noTabs=true: