diff --git a/server/packetsequence.h b/server/packetsequence.h index 402faca..903fc1e 100644 --- a/server/packetsequence.h +++ b/server/packetsequence.h @@ -27,7 +27,8 @@ along with this program. If not, see class PacketSequence { public: - PacketSequence() { + PacketSequence(bool trackGuidStats) { + trackGuidStats_ = trackGuidStats; sendQueue_ = pcap_sendqueue_alloc(1*1024*1024); lastPacket_ = NULL; packets_ = 0; @@ -61,7 +62,7 @@ public: lastPacket_ = (struct pcap_pkthdr *) (sendQueue_->buffer + sendQueue_->len); ret = pcap_sendqueue_queue(sendQueue_, pktHeader, pktData); - if (ret >= 0) { + if (trackGuidStats_ && (ret >= 0)) { uint guid; if (SignProtocol::packetGuid(pktData, pktHeader->caplen, &guid)) { streamStatsMeta_[guid].tx_pkts++; @@ -79,6 +80,9 @@ public: int repeatSize_; long usecDelay_; StreamStats streamStatsMeta_; + +private: + bool trackGuidStats_; }; #endif diff --git a/server/pcapport.cpp b/server/pcapport.cpp index fc6aa13..7f2e398 100644 --- a/server/pcapport.cpp +++ b/server/pcapport.cpp @@ -132,12 +132,32 @@ bool PcapPort::setRateAccuracy(AbstractPort::Accuracy accuracy) bool PcapPort::startStreamStatsTracking() { - return rxStatsPoller_->start(); + if (!transmitter_->setStreamStatsTracking(true)) + goto _tx_fail; + if (!rxStatsPoller_->start()) + goto _rx_fail; + return true; + +_rx_fail: + transmitter_->setStreamStatsTracking(false); +_tx_fail: + qWarning("failed to start stream stats tracking"); + return false; } bool PcapPort::stopStreamStatsTracking() { - return rxStatsPoller_->stop(); + if (!transmitter_->setStreamStatsTracking(false)) + goto _tx_fail; + if (!rxStatsPoller_->stop()) + goto _rx_fail; + return true; + +_rx_fail: + transmitter_->setStreamStatsTracking(true); +_tx_fail: + qWarning("failed to stop stream stats tracking"); + return false; } void PcapPort::startDeviceEmulation() diff --git a/server/pcaptransmitter.cpp b/server/pcaptransmitter.cpp index d7eae96..e6a2c89 100644 --- a/server/pcaptransmitter.cpp +++ b/server/pcaptransmitter.cpp @@ -43,6 +43,11 @@ bool PcapTransmitter::setRateAccuracy( return txThread_.setRateAccuracy(accuracy); } +bool PcapTransmitter::setStreamStatsTracking(bool enable) +{ + return txThread_.setStreamStatsTracking(enable); +} + void PcapTransmitter::clearPacketList() { txThread_.clearPacketList(); diff --git a/server/pcaptransmitter.h b/server/pcaptransmitter.h index 75964bc..a232194 100644 --- a/server/pcaptransmitter.h +++ b/server/pcaptransmitter.h @@ -33,6 +33,7 @@ public: ~PcapTransmitter(); bool setRateAccuracy(AbstractPort::Accuracy accuracy); + bool setStreamStatsTracking(bool enable); void clearPacketList(); void loopNextPacketSet(qint64 size, qint64 repeats, diff --git a/server/pcaptxthread.cpp b/server/pcaptxthread.cpp index 1bd5d97..8e18a58 100644 --- a/server/pcaptxthread.cpp +++ b/server/pcaptxthread.cpp @@ -39,6 +39,7 @@ PcapTxThread::PcapTxThread(const char *device) #endif state_ = kNotStarted; stop_ = false; + trackStreamStats_ = false; clearPacketList(); handle_ = pcap_open_live(device, 64 /* FIXME */, 0, 1000 /* ms */, errbuf); @@ -82,6 +83,12 @@ bool PcapTxThread::setRateAccuracy( return true; } +bool PcapTxThread::setStreamStatsTracking(bool enable) +{ + trackStreamStats_ = enable; + return true; +} + void PcapTxThread::clearPacketList() { Q_ASSERT(!isRunning()); @@ -103,7 +110,7 @@ void PcapTxThread::clearPacketList() void PcapTxThread::loopNextPacketSet(qint64 size, qint64 repeats, long repeatDelaySec, long repeatDelayNsec) { - currentPacketSequence_ = new PacketSequence; + currentPacketSequence_ = new PacketSequence(trackStreamStats_); currentPacketSequence_->repeatCount_ = repeats; currentPacketSequence_->usecDelay_ = repeatDelaySec * long(1e6) + repeatDelayNsec/1000; @@ -141,7 +148,7 @@ bool PcapTxThread::appendToPacketList(long sec, long nsec, } //! \todo (LOW): calculate sendqueue size - currentPacketSequence_ = new PacketSequence; + currentPacketSequence_ = new PacketSequence(trackStreamStats_); packetSequenceList_.append(currentPacketSequence_); @@ -342,7 +349,8 @@ _restart: } _exit: - updateStreamStats(); + if (trackStreamStats_) + updateStreamStats(); state_ = kFinished; } diff --git a/server/pcaptxthread.h b/server/pcaptxthread.h index 29ea0fa..5b94ccb 100644 --- a/server/pcaptxthread.h +++ b/server/pcaptxthread.h @@ -34,6 +34,7 @@ public: ~PcapTxThread(); bool setRateAccuracy(AbstractPort::Accuracy accuracy); + bool setStreamStatsTracking(bool enable); void clearPacketList(); void loopNextPacketSet(qint64 size, qint64 repeats, @@ -87,6 +88,7 @@ private: volatile bool stop_; volatile State state_; + bool trackStreamStats_; StatsTuple *stats_; StatsTuple lastStats_; StreamStats streamStats_;