sign: signed tx stats infra; actual tx signing pending

This commit is contained in:
Srivats P 2016-10-23 17:24:23 +05:30
parent 31c2cd2dcb
commit a79bbb1fcd
14 changed files with 108 additions and 1 deletions

View File

@ -98,6 +98,8 @@ public:
{ return d.is_exclusive_control(); }
OstProto::TransmitMode transmitMode()
{ return d.transmit_mode(); }
OstProto::StreamType streamsType()
{ return d.streams_type(); }
double averagePacketRate()
{ return avgPacketsPerSec_; }
double averageBitRate()

View File

@ -64,6 +64,19 @@ PortConfigDialog::PortConfigDialog(OstProto::Port &portConfig, QWidget *parent)
qDebug("reservedBy_ = %d", reservedBy_);
exclusiveControlButton->setChecked(portConfig_.is_exclusive_control());
switch(portConfig_.streams_type())
{
case OstProto::kUnsignedStream:
signedStreamsButton->setChecked(false);
break;
case OstProto::kSignedStream:
signedStreamsButton->setChecked(true);
break;
default:
Q_ASSERT(false); // Unreachable!!!
break;
}
}
void PortConfigDialog::accept()
@ -96,6 +109,11 @@ void PortConfigDialog::accept()
pc.set_is_exclusive_control(exclusiveControlButton->isChecked());
if (signedStreamsButton->isChecked())
pc.set_streams_type(OstProto::kSignedStream);
else
pc.set_streams_type(OstProto::kUnsignedStream);
// Update fields that have changed, clear the rest
if (pc.transmit_mode() != portConfig_.transmit_mode())
portConfig_.set_transmit_mode(pc.transmit_mode());
@ -112,5 +130,10 @@ void PortConfigDialog::accept()
else
portConfig_.clear_is_exclusive_control();
if (pc.streams_type() != portConfig_.streams_type())
portConfig_.set_streams_type(pc.streams_type());
else
portConfig_.clear_streams_type();
QDialog::accept();
}

View File

@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>244</width>
<height>233</height>
<height>257</height>
</rect>
</property>
<property name="windowTitle" >
@ -69,6 +69,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="signedStreamsButton" >
<property name="text" >
<string>Signed Streams</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >

View File

@ -719,7 +719,13 @@ void PortsWindow::on_actionPort_Configuration_triggered()
return;
OstProto::Port config;
// XXX: we don't call Port::protoDataCopyInto() to get config b'coz
// we want only the modifiable fields populated to send to Drone
// TODO: extend Port::protoDataCopyInto() to accept an optional param
// which says copy only modifiable fields
plm->port(current).protoDataCopyInto(&config);
config.set_transmit_mode(plm->port(current).transmitMode());
config.set_streams_type(plm->port(current).streamsType());
config.set_is_exclusive_control(plm->port(current).hasExclusiveControl());
config.set_user_name(plm->port(current).userName().toStdString());

View File

@ -195,6 +195,11 @@ enum TransmitMode {
kInterleavedTransmit = 1;
}
enum StreamType {
kUnsignedStream = 0; // FIXME: rename? convert to flags?
kSignedStream = 1;
}
message Port {
required PortId port_id = 1;
optional string name = 2;
@ -204,6 +209,7 @@ message Port {
optional bool is_exclusive_control = 6;
optional TransmitMode transmit_mode = 7 [default = kSequentialTransmit];
optional string user_name = 8;
optional StreamType streams_type = 9 [default = kUnsignedStream];
}
message PortConfigList {

View File

@ -82,6 +82,9 @@ bool AbstractPort::modify(const OstProto::Port &port)
if (port.has_transmit_mode())
data_.set_transmit_mode(port.transmit_mode());
if (port.has_streams_type())
setStreamsType(port.streams_type());
if (port.has_user_name()) {
data_.set_user_name(port.user_name());
}
@ -155,6 +158,11 @@ void AbstractPort::addNote(QString note)
data_.set_notes(notes.toStdString());
}
bool AbstractPort::setStreamsType(OstProto::StreamType type)
{
data_.set_streams_type(type);
}
AbstractPort::Accuracy AbstractPort::rateAccuracy()
{
return rateAccuracy_;

View File

@ -102,6 +102,8 @@ public:
bool isDirty() { return isSendQueueDirty_; }
void setDirty() { isSendQueueDirty_ = true; }
virtual bool setStreamsType(OstProto::StreamType type);
Accuracy rateAccuracy();
virtual bool setRateAccuracy(Accuracy accuracy);

View File

@ -133,6 +133,9 @@ void MyService::modifyPort(::google::protobuf::RpcController* /*controller*/,
id = port.port_id().id();
if (id < portInfo.size())
{
// FIXME: return error for any change in transmitMode/streamsType
// while transmit is on
portLock[id]->lockForWrite();
portInfo[id]->modify(port);
portLock[id]->unlock();
@ -148,6 +151,8 @@ void MyService::modifyPort(::google::protobuf::RpcController* /*controller*/,
notif->set_notif_type(OstProto::portConfigChanged);
emit notification(notif->notif_type(), SharedProtobufMessage(notif));
}
// FIXME: potential memory leak of notif
}
void MyService::getStreamIdList(::google::protobuf::RpcController* controller,

View File

@ -117,6 +117,26 @@ void PcapPort::updateNotes()
arg(notes).toStdString());
}
bool PcapPort::setStreamsType(OstProto::StreamType type)
{
AbstractPort::setStreamsType(type);
transmitter_->useSignedStreams(type == OstProto::kSignedStream);
// XXX: Because of the way we implement signed tx stats, changing
// streamsType requires us to set sign tx stats equal to tx stats
// followed by clear stats; see note in PcapTxStats::run() for details
// FIXME: can we get away with clearing only sign stats?
// FIXME: Ideally PcapPort should *NOT* know how PcapTxStats implements
// sign stats
stats_.sign.txPkts = stats_.txPkts;
stats_.sign.txBytes = stats_.txBytes;
stats_.sign.rxPkts = stats_.rxPkts;
stats_.sign.rxBytes = stats_.rxBytes;
resetStats();
return true;
}
bool PcapPort::setRateAccuracy(AbstractPort::Accuracy accuracy)
{
if (transmitter_->setRateAccuracy(accuracy)) {

View File

@ -39,6 +39,8 @@ public:
virtual bool hasExclusiveControl() { return false; }
virtual bool setExclusiveControl(bool /*exclusive*/) { return false; }
virtual bool setStreamsType(OstProto::StreamType type);
virtual bool setRateAccuracy(AbstractPort::Accuracy accuracy);
virtual void clearPacketList() {

View File

@ -78,6 +78,11 @@ void PcapTransmitter::useExternalStats(AbstractPort::PortStats *stats)
txStats_.useExternalStats(stats);
}
void PcapTransmitter::useSignedStreams(bool enable)
{
txStats_.useSignedStreams(enable);
}
void PcapTransmitter::start()
{
txThread_.start();

View File

@ -43,6 +43,8 @@ public:
void setHandle(pcap_t *handle);
void useExternalStats(AbstractPort::PortStats *stats);
void useSignedStreams(bool enable);
void start();
void stop();
bool isRunning();

View File

@ -28,6 +28,8 @@ PcapTxStats::PcapTxStats()
stats_ = new AbstractPort::PortStats;
usingInternalStats_ = true;
usingSignedStreams_ = false;
stop_ = false;
}
@ -50,6 +52,11 @@ void PcapTxStats::useExternalStats(AbstractPort::PortStats *stats)
usingInternalStats_ = false;
}
void PcapTxStats::useSignedStreams(bool enable)
{
usingSignedStreams_ = enable;
}
void PcapTxStats::start()
{
QThread::start();
@ -76,6 +83,15 @@ void PcapTxStats::run()
stats_->txPkts = txThreadStats_->pkts;
stats_->txBytes = txThreadStats_->bytes;
// XXX: If port uses signed streams, we assume that all packets
// sent by txThread are signed packets => this requires us to
// set sign tx stats equal to tx stats followed by a clear stats
// whenever this setting changes
if (usingSignedStreams_) {
stats_->sign.txPkts = txThreadStats_->pkts;
stats_->sign.txBytes = txThreadStats_->bytes;
}
if (stop_)
break;
QThread::msleep(1000);

View File

@ -36,6 +36,8 @@ public:
void useExternalStats(AbstractPort::PortStats *stats);
void useSignedStreams(bool enable);
void start();
void stop();
private:
@ -46,6 +48,7 @@ private:
bool usingInternalStats_;
AbstractPort::PortStats *stats_;
volatile bool usingSignedStreams_;
volatile bool stop_;
};