From ac1356ed5381d6f7cfc7aa4b843942b924187b04 Mon Sep 17 00:00:00 2001 From: Srivats P Date: Fri, 9 Dec 2016 18:48:08 +0530 Subject: [PATCH] Optimize stream preflight check for performance Loop only once for all packets of the stream --- common/streambase.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/common/streambase.cpp b/common/streambase.cpp index 622e3d5..56d6d4a 100644 --- a/common/streambase.cpp +++ b/common/streambase.cpp @@ -581,32 +581,46 @@ quint64 StreamBase::neighborMacAddress(int frameIndex) const return getNeighborMacAddress(portId_, int(mStreamId->id()), frameIndex); } +/*! + Checks for any potential errors with the packets generated by this + stream. Returns true if no problems are found, false otherwise. Details + of the error(s) are available in the INOUT param result + + All errors found are returned. However, each type of error is reported + only once, even if multiple packets may have that error. +*/ bool StreamBase::preflightCheck(QString &result) const { bool pass = true; + bool chkTrunc = true; + bool chkJumbo = true; int count = isFrameSizeVariable() ? frameCount() : 1; for (int i = 0; i < count; i++) { - if (frameLen(i) < (frameProtocolLength(i) + kFcsSize)) + int pktLen = frameLen(i); + + if (chkTrunc && (pktLen < (frameProtocolLength(i) + kFcsSize))) { result += QString("One or more frames may be truncated - " "frame length should be at least %1.\n") .arg(frameProtocolLength(i) + kFcsSize); + chkTrunc = false; pass = false; - break; } - } - for (int i = 0; i < count; i++) - { - if (frameLen(i) > 1522) + if (chkJumbo && (pktLen > 1522)) { result += QString("Jumbo frames may be truncated or dropped " - "if not supported by the hardware\n"); + "if not supported by the hardware.\n"); + chkJumbo = false; pass = false; - break; } + + // Break out of loop if we've seen at least one instance of all + // the above errors + if (!chkTrunc && !chkJumbo) + break; } return pass;