Add load % as an input for port rate

This commit is contained in:
Srivats P 2021-11-07 19:05:11 +05:30
parent 925edb8507
commit dd7f4a6fd0
6 changed files with 108 additions and 11 deletions

View File

@ -317,6 +317,12 @@ void Port::setAverageBitRate(double bitsPerSec)
emit portRateChanged(mPortGroupId, mPortId); 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) bool Port::newStreamAt(int index, OstProto::Stream const *stream)
{ {
Stream *s = new Stream; Stream *s = new Stream;

View File

@ -102,6 +102,10 @@ public:
{ return d.transmit_mode(); } { return d.transmit_mode(); }
bool trackStreamStats() const bool trackStreamStats() const
{ return d.is_tracking_stream_stats(); } { 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 double averagePacketRate() const
{ return avgPacketsPerSec_; } { return avgPacketsPerSec_; }
double averageBitRate() const double averageBitRate() const
@ -183,6 +187,7 @@ public:
void setAveragePacketRate(double packetsPerSec); void setAveragePacketRate(double packetsPerSec);
void setAverageBitRate(double bitsPerSec); void setAverageBitRate(double bitsPerSec);
void setAverageLoadRate(double loadPercent);
// FIXME(MED): Bad Hack! port should not need an external trigger to // FIXME(MED): Bad Hack! port should not need an external trigger to
// recalculate - refactor client side domain objects and model objects // recalculate - refactor client side domain objects and model objects
void recalculateAverageRates(); void recalculateAverageRates();

View File

@ -22,10 +22,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "portgrouplist.h" #include "portgrouplist.h"
#include "xqlocale.h" #include "xqlocale.h"
#include <cfloat>
PortWidget::PortWidget(QWidget *parent) PortWidget::PortWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
setupUi(this); setupUi(this);
averageLoadPercent->setMaximum(DBL_MAX);
} }
void PortWidget::setPortGroupList(PortGroupList *portGroups) void PortWidget::setPortGroupList(PortGroupList *portGroups)
@ -71,6 +74,14 @@ void PortWidget::setCurrentPortIndex(const QModelIndex &portIndex)
SIGNAL(portRateChanged(int, int)), SIGNAL(portRateChanged(int, int)),
this, SLOT(updatePortRates())); 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(); updatePortRates();
updatePortActions(); updatePortActions();
} }
@ -99,6 +110,15 @@ void PortWidget::on_stopTx_clicked()
plm->portGroup(curPortGroup).stopTx(&portList); 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() void PortWidget::on_averagePacketsPerSec_editingFinished()
{ {
Q_ASSERT(plm->isPort(currentPortIndex_)); Q_ASSERT(plm->isPort(currentPortIndex_));
@ -127,6 +147,8 @@ void PortWidget::updatePortRates()
if (!plm->isPort(currentPortIndex_)) if (!plm->isPort(currentPortIndex_))
return; return;
averageLoadPercent->setValue(
plm->port(currentPortIndex_).averageLoadRate()*100);
averagePacketsPerSec->setText(QString("%L1") averagePacketsPerSec->setText(QString("%L1")
.arg(plm->port(currentPortIndex_).averagePacketRate(), 0, 'f', 4)); .arg(plm->port(currentPortIndex_).averagePacketRate(), 0, 'f', 4));
averageBitsPerSec->setText(QString("%L1") averageBitsPerSec->setText(QString("%L1")

View File

@ -43,6 +43,7 @@ private slots:
void on_startTx_clicked(); void on_startTx_clicked();
void on_stopTx_clicked(); void on_stopTx_clicked();
void on_averageLoadPercent_editingFinished();
void on_averagePacketsPerSec_editingFinished(); void on_averagePacketsPerSec_editingFinished();
void on_averageBitsPerSec_editingFinished(); void on_averageBitsPerSec_editingFinished();

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>532</width> <width>806</width>
<height>42</height> <height>73</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -75,6 +75,13 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="Line" name="rateSep">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item> <item>
<widget class="QRadioButton" name="radioButton"> <widget class="QRadioButton" name="radioButton">
<property name="text"> <property name="text">
@ -102,6 +109,46 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QRadioButton" name="rbLoad">
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="averageLoadPercent">
<property name="enabled">
<bool>false</bool>
</property>
<property name="suffix">
<string>%</string>
</property>
<property name="decimals">
<number>4</number>
</property>
</widget>
</item>
<item>
<widget class="Line" name="speedSep">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="portSpeed">
<property name="toolTip">
<string>Port Speed</string>
</property>
<property name="statusTip">
<string/>
</property>
<property name="text">
<string>Max speed</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@ -117,12 +164,12 @@
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>326</x> <x>450</x>
<y>80</y> <y>44</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>454</x> <x>593</x>
<y>79</y> <y>45</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@ -133,12 +180,28 @@
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>523</x> <x>661</x>
<y>80</y> <y>44</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>651</x> <x>804</x>
<y>88</y> <y>45</y>
</hint>
</hints>
</connection>
<connection>
<sender>rbLoad</sender>
<signal>toggled(bool)</signal>
<receiver>averageLoadPercent</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>281</x>
<y>43</y>
</hint>
<hint type="destinationlabel">
<x>308</x>
<y>45</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>

View File

@ -263,7 +263,7 @@ void WinPcapPort::populateInterfaceInfo()
interfaceInfo_ = new InterfaceInfo; interfaceInfo_ = new InterfaceInfo;
interfaceInfo_->speed = adapter->TransmitLinkSpeed != quint64(-1) ? interfaceInfo_->speed = adapter->TransmitLinkSpeed != quint64(-1) ?
adapter->TransmitLinkSpeed/ulong(1e6) : 0; adapter->TransmitLinkSpeed/1e6 : 0;
interfaceInfo_->mtu = adapter->Mtu; interfaceInfo_->mtu = adapter->Mtu;
if (adapter->PhysicalAddressLength == 6) { if (adapter->PhysicalAddressLength == 6) {