From dd7f4a6fd07fad515f873f33b3ae50668e928c22 Mon Sep 17 00:00:00 2001 From: Srivats P Date: Sun, 7 Nov 2021 19:05:11 +0530 Subject: [PATCH] Add load % as an input for port rate --- client/port.cpp | 6 +++ client/port.h | 5 +++ client/portwidget.cpp | 22 +++++++++++ client/portwidget.h | 1 + client/portwidget.ui | 83 +++++++++++++++++++++++++++++++++++++----- server/winpcapport.cpp | 2 +- 6 files changed, 108 insertions(+), 11 deletions(-) diff --git a/client/port.cpp b/client/port.cpp index 651714e..3a3aad3 100644 --- a/client/port.cpp +++ b/client/port.cpp @@ -317,6 +317,12 @@ void Port::setAverageBitRate(double bitsPerSec) emit portRateChanged(mPortGroupId, mPortId); } +void Port::setAverageLoadRate(double load) +{ + Q_ASSERT(d.speed() > 0); + setAverageBitRate(load*d.speed()*1e6); +} + bool Port::newStreamAt(int index, OstProto::Stream const *stream) { Stream *s = new Stream; diff --git a/client/port.h b/client/port.h index 9a7d7e6..431791e 100644 --- a/client/port.h +++ b/client/port.h @@ -102,6 +102,10 @@ public: { return d.transmit_mode(); } bool trackStreamStats() const { return d.is_tracking_stream_stats(); } + double speed() const + { return d.speed(); } + double averageLoadRate() const + { return d.speed() ? avgBitsPerSec_/(d.speed()*1e6) : 0; } double averagePacketRate() const { return avgPacketsPerSec_; } double averageBitRate() const @@ -183,6 +187,7 @@ public: void setAveragePacketRate(double packetsPerSec); void setAverageBitRate(double bitsPerSec); + void setAverageLoadRate(double loadPercent); // FIXME(MED): Bad Hack! port should not need an external trigger to // recalculate - refactor client side domain objects and model objects void recalculateAverageRates(); diff --git a/client/portwidget.cpp b/client/portwidget.cpp index f285a13..23e44cf 100644 --- a/client/portwidget.cpp +++ b/client/portwidget.cpp @@ -22,10 +22,13 @@ along with this program. If not, see #include "portgrouplist.h" #include "xqlocale.h" +#include + PortWidget::PortWidget(QWidget *parent) : QWidget(parent) { setupUi(this); + averageLoadPercent->setMaximum(DBL_MAX); } void PortWidget::setPortGroupList(PortGroupList *portGroups) @@ -71,6 +74,14 @@ void PortWidget::setCurrentPortIndex(const QModelIndex &portIndex) SIGNAL(portRateChanged(int, int)), this, SLOT(updatePortRates())); + double speed = plm->port(currentPortIndex_).speed(); + portSpeed->setText(QString("Max %L1 Mbps").arg(speed)); + + rbLoad->setVisible(speed > 0); + averageLoadPercent->setVisible(speed > 0); + speedSep->setVisible(speed > 0); + portSpeed->setVisible(speed > 0); + updatePortRates(); updatePortActions(); } @@ -99,6 +110,15 @@ void PortWidget::on_stopTx_clicked() plm->portGroup(curPortGroup).stopTx(&portList); } +void PortWidget::on_averageLoadPercent_editingFinished() +{ + Q_ASSERT(plm->isPort(currentPortIndex_)); + + plm->port(currentPortIndex_).setAverageLoadRate( + averageLoadPercent->value()/100); +} + + void PortWidget::on_averagePacketsPerSec_editingFinished() { Q_ASSERT(plm->isPort(currentPortIndex_)); @@ -127,6 +147,8 @@ void PortWidget::updatePortRates() if (!plm->isPort(currentPortIndex_)) return; + averageLoadPercent->setValue( + plm->port(currentPortIndex_).averageLoadRate()*100); averagePacketsPerSec->setText(QString("%L1") .arg(plm->port(currentPortIndex_).averagePacketRate(), 0, 'f', 4)); averageBitsPerSec->setText(QString("%L1") diff --git a/client/portwidget.h b/client/portwidget.h index 2863e7f..d914da7 100644 --- a/client/portwidget.h +++ b/client/portwidget.h @@ -43,6 +43,7 @@ private slots: void on_startTx_clicked(); void on_stopTx_clicked(); + void on_averageLoadPercent_editingFinished(); void on_averagePacketsPerSec_editingFinished(); void on_averageBitsPerSec_editingFinished(); diff --git a/client/portwidget.ui b/client/portwidget.ui index d54b972..b5f7e74 100644 --- a/client/portwidget.ui +++ b/client/portwidget.ui @@ -6,8 +6,8 @@ 0 0 - 532 - 42 + 806 + 73 @@ -75,6 +75,13 @@ + + + + Qt::Vertical + + + @@ -102,6 +109,46 @@ + + + + Load + + + + + + + false + + + % + + + 4 + + + + + + + Qt::Vertical + + + + + + + Port Speed + + + + + + Max speed + + + @@ -117,12 +164,12 @@ setEnabled(bool) - 326 - 80 + 450 + 44 - 454 - 79 + 593 + 45 @@ -133,12 +180,28 @@ setEnabled(bool) - 523 - 80 + 661 + 44 - 651 - 88 + 804 + 45 + + + + + rbLoad + toggled(bool) + averageLoadPercent + setEnabled(bool) + + + 281 + 43 + + + 308 + 45 diff --git a/server/winpcapport.cpp b/server/winpcapport.cpp index 4179604..9cde438 100644 --- a/server/winpcapport.cpp +++ b/server/winpcapport.cpp @@ -263,7 +263,7 @@ void WinPcapPort::populateInterfaceInfo() interfaceInfo_ = new InterfaceInfo; interfaceInfo_->speed = adapter->TransmitLinkSpeed != quint64(-1) ? - adapter->TransmitLinkSpeed/ulong(1e6) : 0; + adapter->TransmitLinkSpeed/1e6 : 0; interfaceInfo_->mtu = adapter->Mtu; if (adapter->PhysicalAddressLength == 6) {