From a79bbb1fcd6adae024ed3daa340cec2c6163cc24 Mon Sep 17 00:00:00 2001 From: Srivats P Date: Sun, 23 Oct 2016 17:24:23 +0530 Subject: [PATCH] sign: signed tx stats infra; actual tx signing pending --- client/port.h | 2 ++ client/portconfigdialog.cpp | 23 +++++++++++++++++++++++ client/portconfigdialog.ui | 9 ++++++++- client/portswindow.cpp | 6 ++++++ common/protocol.proto | 6 ++++++ server/abstractport.cpp | 8 ++++++++ server/abstractport.h | 2 ++ server/myservice.cpp | 5 +++++ server/pcapport.cpp | 20 ++++++++++++++++++++ server/pcapport.h | 2 ++ server/pcaptransmitter.cpp | 5 +++++ server/pcaptransmitter.h | 2 ++ server/pcaptxstats.cpp | 16 ++++++++++++++++ server/pcaptxstats.h | 3 +++ 14 files changed, 108 insertions(+), 1 deletion(-) diff --git a/client/port.h b/client/port.h index 281a61a..77ae2d5 100644 --- a/client/port.h +++ b/client/port.h @@ -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() diff --git a/client/portconfigdialog.cpp b/client/portconfigdialog.cpp index c7df99a..83f1d7e 100644 --- a/client/portconfigdialog.cpp +++ b/client/portconfigdialog.cpp @@ -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(); } diff --git a/client/portconfigdialog.ui b/client/portconfigdialog.ui index 1bdc143..711cd3d 100644 --- a/client/portconfigdialog.ui +++ b/client/portconfigdialog.ui @@ -6,7 +6,7 @@ 0 0 244 - 233 + 257 @@ -69,6 +69,13 @@ + + + + Signed Streams + + + diff --git a/client/portswindow.cpp b/client/portswindow.cpp index 76f7ee7..f142953 100644 --- a/client/portswindow.cpp +++ b/client/portswindow.cpp @@ -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()); diff --git a/common/protocol.proto b/common/protocol.proto index 6e25f5a..e1505ef 100644 --- a/common/protocol.proto +++ b/common/protocol.proto @@ -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 { diff --git a/server/abstractport.cpp b/server/abstractport.cpp index 899f530..b43a312 100644 --- a/server/abstractport.cpp +++ b/server/abstractport.cpp @@ -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_; diff --git a/server/abstractport.h b/server/abstractport.h index 0ecea70..426c475 100644 --- a/server/abstractport.h +++ b/server/abstractport.h @@ -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); diff --git a/server/myservice.cpp b/server/myservice.cpp index a2b9eda..88c627b 100644 --- a/server/myservice.cpp +++ b/server/myservice.cpp @@ -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, diff --git a/server/pcapport.cpp b/server/pcapport.cpp index 700358f..b297d50 100644 --- a/server/pcapport.cpp +++ b/server/pcapport.cpp @@ -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)) { diff --git a/server/pcapport.h b/server/pcapport.h index 04e8269..bedeeee 100644 --- a/server/pcapport.h +++ b/server/pcapport.h @@ -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() { diff --git a/server/pcaptransmitter.cpp b/server/pcaptransmitter.cpp index a81ede9..12df97d 100644 --- a/server/pcaptransmitter.cpp +++ b/server/pcaptransmitter.cpp @@ -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(); diff --git a/server/pcaptransmitter.h b/server/pcaptransmitter.h index 3dc8eb9..83fd57f 100644 --- a/server/pcaptransmitter.h +++ b/server/pcaptransmitter.h @@ -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(); diff --git a/server/pcaptxstats.cpp b/server/pcaptxstats.cpp index 353ea9d..102df54 100644 --- a/server/pcaptxstats.cpp +++ b/server/pcaptxstats.cpp @@ -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); diff --git a/server/pcaptxstats.h b/server/pcaptxstats.h index ed134bb..4025d57 100644 --- a/server/pcaptxstats.h +++ b/server/pcaptxstats.h @@ -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_; };