1 /* sctp_graph_byte_dialog.cpp
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #include "sctp_graph_byte_dialog.h"
11 #include <ui_sctp_graph_byte_dialog.h>
15 #include <epan/dissectors/packet-sctp.h>
16 #include "epan/packet.h"
18 #include "ui/tap-sctp-analysis.h"
20 #include <ui/qt/utils/qt_ui_utils.h>
21 #include <ui/qt/widgets/qcustomplot.h>
22 #include "sctp_graph_dialog.h"
23 #include "sctp_assoc_analyse_dialog.h"
25 SCTPGraphByteDialog::SCTPGraphByteDialog(QWidget
*parent
, const sctp_assoc_info_t
*assoc
,
26 capture_file
*cf
, int dir
) :
28 ui(new Ui::SCTPGraphByteDialog
),
34 selected_assoc_id
= assoc
->assoc_id
;
37 Qt::WindowFlags flags
= Qt::Window
| Qt::WindowSystemMenuHint
38 | Qt::WindowMinimizeButtonHint
39 | Qt::WindowMaximizeButtonHint
40 | Qt::WindowCloseButtonHint
;
41 this->setWindowFlags(flags
);
42 this->setWindowTitle(tr("SCTP Data and Adv. Rec. Window over Time: %1 Port1 %2 Port2 %3")
43 .arg(gchar_free_to_qstring(cf_get_display_name(cap_file_
))).arg(assoc
->port1
).arg(assoc
->port2
));
44 if ((direction
== 1 && assoc
->n_array_tsn1
== 0) || (direction
== 2 && assoc
->n_array_tsn2
== 0)) {
46 msgBox
.setText(tr("No Data Chunks sent"));
54 SCTPGraphByteDialog::~SCTPGraphByteDialog()
60 void SCTPGraphByteDialog::drawBytesGraph(const sctp_assoc_info_t
*selected_assoc
)
62 GList
*listTSN
= Q_NULLPTR
, *tlist
= Q_NULLPTR
;
63 tsn_t
*tsn
= Q_NULLPTR
;
66 uint64_t sumBytes
= 0;
69 maxBytes
= selected_assoc
->n_data_bytes_ep1
;
70 listTSN
= g_list_last(selected_assoc
->tsn1
);
72 maxBytes
= selected_assoc
->n_data_bytes_ep2
;
73 listTSN
= g_list_last(selected_assoc
->tsn2
);
78 tsn
= gxx_list_data(tsn_t
*, listTSN
);
79 tlist
= g_list_first(tsn
->tsns
);
83 type
= gxx_list_data(struct chunk_header
*, tlist
)->type
;
84 if (type
== SCTP_DATA_CHUNK_ID
|| type
== SCTP_I_DATA_CHUNK_ID
) {
85 length
= g_ntohs(gxx_list_data(struct data_chunk_header
*, tlist
)->length
);
86 if (type
== SCTP_DATA_CHUNK_ID
)
87 length
-= DATA_CHUNK_HEADER_LENGTH
;
89 length
-= I_DATA_CHUNK_HEADER_LENGTH
;
92 xb
.append(tsn
->secs
+ tsn
->usecs
/1000000.0);
93 fb
.append(tsn
->frame_number
);
95 tlist
= gxx_list_next(tlist
);
97 listTSN
= gxx_list_previous(listTSN
);
101 QCPScatterStyle myScatter
;
102 myScatter
.setShape(QCPScatterStyle::ssCircle
);
103 myScatter
.setSize(3);
105 // create graph and assign data to it:
109 QCPGraph
*gr
= ui
->sctpPlot
->addGraph(ui
->sctpPlot
->xAxis
, ui
->sctpPlot
->yAxis
);
110 gr
->setName(tr("Bytes"));
111 myScatter
.setPen(QPen(Qt::red
));
112 myScatter
.setBrush(Qt::red
);
113 ui
->sctpPlot
->graph(0)->setScatterStyle(myScatter
);
114 ui
->sctpPlot
->graph(0)->setLineStyle(QCPGraph::lsNone
);
115 ui
->sctpPlot
->graph(0)->setData(xb
, yb
);
117 ui
->sctpPlot
->xAxis
->setLabel(tr("time [secs]"));
118 ui
->sctpPlot
->yAxis
->setLabel(tr("Received Bytes"));
120 // set axes ranges, so we see all data:
121 QCPRange
myXByteRange(0, (selected_assoc
->max_secs
+1));
122 QCPRange
myYByteRange(0, maxBytes
);
123 ui
->sctpPlot
->xAxis
->setRange(myXByteRange
);
124 ui
->sctpPlot
->yAxis
->setRange(myYByteRange
);
128 void SCTPGraphByteDialog::drawGraph()
130 const sctp_assoc_info_t
* selected_assoc
= SCTPAssocAnalyseDialog::findAssoc(this, selected_assoc_id
);
131 if (!selected_assoc
) return;
133 ui
->sctpPlot
->clearGraphs();
134 drawBytesGraph(selected_assoc
);
135 ui
->sctpPlot
->setInteractions(QCP::iRangeZoom
| QCP::iRangeDrag
| QCP::iSelectPlottables
);
136 connect(ui
->sctpPlot
, &QCustomPlot::plottableClick
, this, &SCTPGraphByteDialog::graphClicked
);
137 ui
->sctpPlot
->replot();
141 void SCTPGraphByteDialog::on_pushButton_4_clicked()
143 const sctp_assoc_info_t
* selected_assoc
= SCTPAssocAnalyseDialog::findAssoc(this, selected_assoc_id
);
144 if (!selected_assoc
) return;
146 ui
->sctpPlot
->xAxis
->setRange(selected_assoc
->min_secs
+selected_assoc
->min_usecs
/1000000.0, selected_assoc
->max_secs
+selected_assoc
->max_usecs
/1000000.0);
147 if (direction
== 1) {
148 ui
->sctpPlot
->yAxis
->setRange(0, selected_assoc
->n_data_bytes_ep1
);
150 ui
->sctpPlot
->yAxis
->setRange(0, selected_assoc
->n_data_bytes_ep2
);
152 ui
->sctpPlot
->replot();
155 void SCTPGraphByteDialog::graphClicked(QCPAbstractPlottable
* plottable
, int, QMouseEvent
* event
)
157 if (plottable
->name().contains(tr("Bytes"), Qt::CaseInsensitive
)) {
158 double bytes
= ui
->sctpPlot
->yAxis
->pixelToCoord(event
->pos().y());
160 for (i
= 0; i
< yb
.size(); i
++) {
161 if (bytes
<= yb
.value(i
)) {
162 frame_num
= fb
.at(i
);
166 if (cap_file_
&& frame_num
> 0) {
167 cf_goto_frame(cap_file_
, frame_num
, false);
170 ui
->hintLabel
->setText(tr("<small><i>Graph %1: Received bytes=%2 Time=%3 secs </i></small>")
171 .arg(plottable
->name())
178 void SCTPGraphByteDialog::on_saveButton_clicked()
180 SCTPGraphDialog::save_graph(this, ui
->sctpPlot
);