From 670920afa6d27d01c448926d36f1f1a2ec7044b4 Mon Sep 17 00:00:00 2001 From: "Srivats P." Date: Sat, 9 Jul 2011 20:40:42 +0530 Subject: [PATCH] Enable inter-packet gap to be more than one second Fixes issue 42 --- client/streamconfigdialog.cpp | 4 ++-- common/fileformat.cpp | 39 ++++++++++++++++++++++++++++++++++- common/fileformat.h | 4 +++- common/protocol.proto | 6 ++++-- common/streambase.cpp | 12 +++++------ common/streambase.h | 8 +++---- server/abstractport.cpp | 4 ++-- server/pcapport.cpp | 6 ++++++ 8 files changed, 65 insertions(+), 18 deletions(-) diff --git a/client/streamconfigdialog.cpp b/client/streamconfigdialog.cpp index cb7579b..c98cd52 100644 --- a/client/streamconfigdialog.cpp +++ b/client/streamconfigdialog.cpp @@ -964,8 +964,8 @@ void StreamConfigDialog::StoreCurrentStream() pStream->setNumPackets(leNumPackets->text().toULong(&isOk)); pStream->setNumBursts(leNumBursts->text().toULong(&isOk)); pStream->setBurstSize(lePacketsPerBurst->text().toULong(&isOk)); - pStream->setPacketRate(lePacketsPerSec->text().toULong(&isOk)); - pStream->setBurstRate(leBurstsPerSec->text().toULong(&isOk)); + pStream->setPacketRate(lePacketsPerSec->text().toDouble(&isOk)); + pStream->setBurstRate(leBurstsPerSec->text().toDouble(&isOk)); } } diff --git a/common/fileformat.cpp b/common/fileformat.cpp index aada8b1..4edd980 100644 --- a/common/fileformat.cpp +++ b/common/fileformat.cpp @@ -161,7 +161,6 @@ bool FileFormat::openStreams(const QString fileName, } Q_ASSERT(meta.data().format_version_major() == kFileFormatVersionMajor); - Q_ASSERT(meta.data().format_version_minor() == kFileFormatVersionMinor); // ByteSize() does not include the Tag/Key, so we add 2 for that contentOffset = kFileMetaDataOffset + meta.data().ByteSize() + 2; @@ -178,6 +177,8 @@ bool FileFormat::openStreams(const QString fileName, if (!content.matter().has_streams()) goto _missing_streams; + postParseFixup(meta.data(), content); + streams.CopyFrom(content.matter().streams()); return true; @@ -444,3 +445,39 @@ void FileFormat::initFileMetaData(OstProto::FileMetaData &metaData) qApp->property("revision").toString().toUtf8().constData()); } +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +/*! Fixup content to what is expected in the native version */ +void FileFormat::postParseFixup(OstProto::FileMetaData metaData, + OstProto::FileContent &content) +{ + Q_ASSERT(metaData.format_version_major() == kFileFormatVersionMajor); + + // Do fixups from oldest to newest versions + switch (metaData.format_version_minor()) + { + case 1: + { + int n = content.matter().streams().stream_size(); + for (int i = 0; i < n; i++) + { + OstProto::StreamControl *sctl = + content.mutable_matter()->mutable_streams()->mutable_stream(i)->mutable_control(); + sctl->set_packets_per_sec(sctl->obsolete_packets_per_sec()); + sctl->set_bursts_per_sec(sctl->obsolete_bursts_per_sec()); + } + + // fall-through to next higher version until native version + } + case kFileFormatVersionMinor: // native version + break; + + case 0: + default: + qWarning("%s: minor version %u unhandled", __FUNCTION__, + metaData.format_version_minor()); + Q_ASSERT_X(false, "postParseFixup", "unhandled minor version"); + } + +} +#pragma GCC diagnostic warning "-Wdeprecated-declarations" + diff --git a/common/fileformat.h b/common/fileformat.h index 0204906..409b8a8 100644 --- a/common/fileformat.h +++ b/common/fileformat.h @@ -39,6 +39,8 @@ public: private: void initFileMetaData(OstProto::FileMetaData &metaData); + void postParseFixup(OstProto::FileMetaData metaData, + OstProto::FileContent &content); static const int kFileMagicSize = 12; static const int kFileChecksumSize = 5; @@ -51,7 +53,7 @@ private: // Native file format version static const uint kFileFormatVersionMajor = 0; - static const uint kFileFormatVersionMinor = 1; + static const uint kFileFormatVersionMinor = 2; static const uint kFileFormatVersionRevision = 3; }; diff --git a/common/protocol.proto b/common/protocol.proto index 1c9aaa3..9ac1c9a 100644 --- a/common/protocol.proto +++ b/common/protocol.proto @@ -67,8 +67,10 @@ message StreamControl { optional uint32 num_bursts = 4 [default = 1]; optional uint32 packets_per_burst = 5 [default = 10]; optional NextWhat next = 6 [default = e_nw_goto_next]; - optional uint32 packets_per_sec = 7 [default = 1]; - optional uint32 bursts_per_sec = 8 [default = 1]; + optional uint32 OBSOLETE_packets_per_sec = 7 [default = 1, deprecated=true]; + optional uint32 OBSOLETE_bursts_per_sec = 8 [default = 1, deprecated=true]; + optional double packets_per_sec = 9 [default = 1]; + optional double bursts_per_sec = 10 [default = 1]; } message ProtocolId { diff --git a/common/streambase.cpp b/common/streambase.cpp index b9dea25..720b801 100644 --- a/common/streambase.cpp +++ b/common/streambase.cpp @@ -325,23 +325,23 @@ bool StreamBase::setBurstSize(quint32 packetsPerBurst) return true; } -quint32 StreamBase::packetRate() const +double StreamBase::packetRate() const { - return (quint32) mControl->packets_per_sec(); + return (double) mControl->packets_per_sec(); } -bool StreamBase::setPacketRate(quint32 packetsPerSec) +bool StreamBase::setPacketRate(double packetsPerSec) { mControl->set_packets_per_sec(packetsPerSec); return true; } -quint32 StreamBase::burstRate() const +double StreamBase::burstRate() const { - return (quint32) mControl->bursts_per_sec(); + return (double) mControl->bursts_per_sec(); } -bool StreamBase::setBurstRate(quint32 burstsPerSec) +bool StreamBase::setBurstRate(double burstsPerSec) { mControl->set_bursts_per_sec(burstsPerSec); return true; diff --git a/common/streambase.h b/common/streambase.h index 7afbbd9..0d1e53b 100644 --- a/common/streambase.h +++ b/common/streambase.h @@ -125,11 +125,11 @@ public: quint32 burstSize() const; bool setBurstSize(quint32 packetsPerBurst); - quint32 packetRate() const; - bool setPacketRate(quint32 packetsPerSec); + double packetRate() const; + bool setPacketRate(double packetsPerSec); - quint32 burstRate() const; - bool setBurstRate(quint32 burstsPerSec); + double burstRate() const; + bool setBurstRate(double burstsPerSec); bool isFrameVariable() const; bool isFrameSizeVariable() const; diff --git a/server/abstractport.cpp b/server/abstractport.cpp index 028ca15..252f4b5 100644 --- a/server/abstractport.cpp +++ b/server/abstractport.cpp @@ -204,7 +204,7 @@ void AbstractPort::updatePacketList() appendToPacketList(sec, usec, pktBuf_, len); usec += (k < np1) ? ipg1 : ipg2; - if (usec > 1000000) + while (usec >= 1000000) { sec++; usec -= 1000000; @@ -212,7 +212,7 @@ void AbstractPort::updatePacketList() } // for (numPackets) usec += (j < nb1) ? ibg1 : ibg2; - if (usec > 1000000) + while (usec >= 1000000) { sec++; usec -= 1000000; diff --git a/server/pcapport.cpp b/server/pcapport.cpp index 7aa63b5..c92eae8 100644 --- a/server/pcapport.cpp +++ b/server/pcapport.cpp @@ -492,6 +492,12 @@ void PcapPort::PortTransmitter::udelay(long usec) delay.tv_sec = 0; delay.tv_usec = usec; + while (delay.tv_usec >= 1000000) + { + delay.tv_sec++; + delay.tv_usec -= 1000000; + } + gettimeofday(&now, NULL); timeradd(&now, &delay, &target);