Reoganize code using subrepo for Ostinato (part 2)

This commit includes all the new and modified files
This commit is contained in:
Srivats P 2021-02-20 20:40:37 +05:30
parent 5edf9a75e5
commit 843733567a
13 changed files with 103 additions and 14 deletions

View File

@ -26,6 +26,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include <qendian.h> #include <qendian.h>
#if 0
#ifdef qDebug
#undef qDebug
#define qDebug(...)
#endif
#endif
/*! /*!
\class AbstractProtocol \class AbstractProtocol

View File

@ -27,6 +27,7 @@ struct FrameValueAttrib
enum ErrorFlag { enum ErrorFlag {
UnresolvedSrcMacError = 0x1, UnresolvedSrcMacError = 0x1,
UnresolvedDstMacError = 0x2, UnresolvedDstMacError = 0x2,
OutOfMemoryError = 0x4,
}; };
Q_DECLARE_FLAGS(ErrorFlags, ErrorFlag); Q_DECLARE_FLAGS(ErrorFlags, ErrorFlag);
ErrorFlags errorFlags{0}; ErrorFlags errorFlags{0};

View File

@ -1,3 +1,3 @@
QMAKE_CXXFLAGS += -isystem $$[QT_INSTALL_HEADERS] -std=c++11 QMAKE_CXXFLAGS += -isystem $$[QT_INSTALL_HEADERS] -std=c++11
CONFIG(debug, debug|release): QMAKE_CXXFLAGS_WARN_ON += -Wall -W -Wextra -Werror CONFIG(debug, debug|release): QMAKE_CXXFLAGS_WARN_ON += -Wall -W -Wextra -Werror -Wno-error
CONFIG(debug, debug|release): QMAKE_CXXFLAGS_WARN_ON += -Wno-deprecated-declarations CONFIG(debug, debug|release): QMAKE_CXXFLAGS_WARN_ON += -Wno-deprecated-declarations

View File

@ -33,6 +33,8 @@ RpcServer::RpcServer(bool perConnLogs)
RpcServer::~RpcServer() RpcServer::~RpcServer()
{ {
close();
emit closed();
} }
bool RpcServer::registerService(::google::protobuf::Service *service, bool RpcServer::registerService(::google::protobuf::Service *service,
@ -73,6 +75,7 @@ void RpcServer::incomingConnection(qintptr socketDescriptor)
connect(this, SIGNAL(notifyClients(int, SharedProtobufMessage)), connect(this, SIGNAL(notifyClients(int, SharedProtobufMessage)),
conn, SLOT(sendNotification(int, SharedProtobufMessage))); conn, SLOT(sendNotification(int, SharedProtobufMessage)));
connect(this, SIGNAL(closed()), thread, SLOT(quit()));
thread->start(); thread->start();
} }

View File

@ -44,6 +44,7 @@ public:
QHostAddress address, quint16 tcpPortNum); QHostAddress address, quint16 tcpPortNum);
signals: signals:
void closed();
void notifyClients(int notifType, SharedProtobufMessage notifData); void notifyClients(int notifType, SharedProtobufMessage notifData);
protected: protected:

View File

@ -315,8 +315,10 @@ int AbstractPort::updatePacketListSequential()
qDebug("npx2 = %llu", npx2); qDebug("npx2 = %llu", npx2);
qDebug("npy2 = %llu\n", npy2); qDebug("npy2 = %llu\n", npy2);
if (n > 1) if (n >= 1) {
loopNextPacketSet(x, n, 0, loopDelay); loopNextPacketSet(x, n, 0, loopDelay);
qDebug("PacketSet: n = %lu, x = %lu", n, x);
}
else if (n == 0) else if (n == 0)
x = 0; x = 0;
@ -333,10 +335,20 @@ int AbstractPort::updatePacketListSequential()
if (len <= 0) if (len <= 0)
continue; continue;
// Create a packet set for 'y' with repeat = 1
if (j == x) {
loopNextPacketSet(y, 1, 0, loopDelay);
qDebug("PacketSet: n = 1, y = %lu", y);
}
qDebug("q(%d, %d) sec = %lu nsec = %lu", qDebug("q(%d, %d) sec = %lu nsec = %lu",
i, j, sec, nsec); i, j, sec, nsec);
appendToPacketList(sec, nsec, pktBuf_, len); if (!appendToPacketList(sec, nsec, pktBuf_, len)) {
clearPacketList(); // don't leave it half baked/inconsitent
packetListAttrib.errorFlags |= FrameValueAttrib::OutOfMemoryError;
goto _out_of_memory;
}
if ((j > 0) && (((j+1) % burstSize) == 0)) if ((j > 0) && (((j+1) % burstSize) == 0))
{ {
@ -397,6 +409,7 @@ int AbstractPort::updatePacketListSequential()
} // if (stream is enabled) } // if (stream is enabled)
} // for (numStreams) } // for (numStreams)
_out_of_memory:
_stop_no_more_pkts: _stop_no_more_pkts:
isSendQueueDirty_ = false; isSendQueueDirty_ = false;
@ -410,7 +423,7 @@ int AbstractPort::updatePacketListInterleaved()
FrameValueAttrib packetListAttrib; FrameValueAttrib packetListAttrib;
int numStreams = 0; int numStreams = 0;
quint64 minGap = ULLONG_MAX; quint64 minGap = ULLONG_MAX;
quint64 duration = quint64(1e9); quint64 duration = quint64(1e3);
QList<quint64> ibg1, ibg2; QList<quint64> ibg1, ibg2;
QList<quint64> nb1, nb2; QList<quint64> nb1, nb2;
QList<quint64> ipg1, ipg2; QList<quint64> ipg1, ipg2;
@ -568,6 +581,11 @@ int AbstractPort::updatePacketListInterleaved()
qDebug("minGap = %llu", minGap); qDebug("minGap = %llu", minGap);
qDebug("duration = %llu", duration); qDebug("duration = %llu", duration);
if (duration < minGap*100) {
duration = minGap*100;
qDebug("increase duration to %llu for better accuracy", duration);
}
uchar* buf; uchar* buf;
int len; int len;
quint64 durSec = duration/ulong(1e9); quint64 durSec = duration/ulong(1e9);
@ -604,7 +622,11 @@ int AbstractPort::updatePacketListInterleaved()
continue; continue;
qDebug("q(%d) sec = %llu nsec = %llu", i, sec, nsec); qDebug("q(%d) sec = %llu nsec = %llu", i, sec, nsec);
appendToPacketList(sec, nsec, buf, len); if (!appendToPacketList(sec, nsec, buf, len)) {
clearPacketList(); // don't leave it half baked/inconsitent
packetListAttrib.errorFlags |= FrameValueAttrib::OutOfMemoryError;
goto _out_of_memory;
}
lastPktTxSec = sec; lastPktTxSec = sec;
lastPktTxNsec = nsec; lastPktTxNsec = nsec;
@ -636,15 +658,19 @@ int AbstractPort::updatePacketListInterleaved()
} }
} while ((sec < durSec) || (nsec < durNsec)); } while ((sec < durSec) || (nsec < durNsec));
qint64 delaySec = durSec - lastPktTxSec;
qint64 delayNsec = durNsec - lastPktTxNsec;
while (delayNsec < 0)
{ {
delayNsec += long(1e9); qint64 delaySec = durSec - lastPktTxSec;
delaySec--; qint64 delayNsec = durNsec - lastPktTxNsec;
while (delayNsec < 0)
{
delayNsec += long(1e9);
delaySec--;
}
qDebug("loop Delay = %lld/%lld", delaySec, delayNsec);
setPacketListLoopMode(true, delaySec, delayNsec);
} }
qDebug("loop Delay = %lld/%lld", delaySec, delayNsec);
setPacketListLoopMode(true, delaySec, delayNsec); _out_of_memory:
isSendQueueDirty_ = false; isSendQueueDirty_ = false;
qDebug("PacketListAttrib = %x", qDebug("PacketListAttrib = %x",
@ -688,6 +714,9 @@ void AbstractPort::stats(PortStats *stats)
void AbstractPort::streamStats(uint guid, OstProto::StreamStatsList *stats) void AbstractPort::streamStats(uint guid, OstProto::StreamStatsList *stats)
{ {
// In case stats are being maintained elsewhere
updateStreamStats();
if (streamStats_.contains(guid)) if (streamStats_.contains(guid))
{ {
StreamStatsTuple sst = streamStats_.value(guid); StreamStatsTuple sst = streamStats_.value(guid);
@ -705,6 +734,9 @@ void AbstractPort::streamStats(uint guid, OstProto::StreamStatsList *stats)
void AbstractPort::streamStatsAll(OstProto::StreamStatsList *stats) void AbstractPort::streamStatsAll(OstProto::StreamStatsList *stats)
{ {
// In case stats are being maintained elsewhere
updateStreamStats();
// FIXME: change input param to a non-OstProto type and/or have // FIXME: change input param to a non-OstProto type and/or have
// a getFirst/Next like API? // a getFirst/Next like API?
StreamStatsIterator i(streamStats_); StreamStatsIterator i(streamStats_);

View File

@ -124,6 +124,9 @@ public:
void streamStatsAll(OstProto::StreamStatsList *stats); void streamStatsAll(OstProto::StreamStatsList *stats);
void resetStreamStats(uint guid); void resetStreamStats(uint guid);
void resetStreamStatsAll(); void resetStreamStatsAll();
virtual void updateStreamStats() {
// subclasses may implement - if required
}
DeviceManager* deviceManager(); DeviceManager* deviceManager();
virtual void startDeviceEmulation() = 0; virtual void startDeviceEmulation() = 0;

View File

@ -1,5 +1,6 @@
TEMPLATE = app TEMPLATE = app
CONFIG += qt ver_info c++11 CONFIG += qt ver_info c++11
addon: CONFIG -= ver_info
QT += network script xml QT += network script xml
QT -= gui QT -= gui
linux*:system(grep -q IFLA_STATS64 /usr/include/linux/if_link.h): \ linux*:system(grep -q IFLA_STATS64 /usr/include/linux/if_link.h): \

View File

@ -30,7 +30,7 @@ class LinuxPort : public PcapPort
{ {
public: public:
LinuxPort(int id, const char *device); LinuxPort(int id, const char *device);
~LinuxPort(); virtual ~LinuxPort();
void init(); void init();

View File

@ -1249,6 +1249,9 @@ QString MyService::frameValueErrorNotes(int portId, int error)
QString pfx = QString("Port %1: ").arg(portId); QString pfx = QString("Port %1: ").arg(portId);
auto errorFlags = static_cast<FrameValueAttrib::ErrorFlags>(error); auto errorFlags = static_cast<FrameValueAttrib::ErrorFlags>(error);
if (errorFlags & FrameValueAttrib::OutOfMemoryError)
return pfx + "Error building packet buffers - out of buffer memory\n";
// If smac resolve fails, dmac will always fail - so check that first // If smac resolve fails, dmac will always fail - so check that first
// and report only that so as not to confuse users (they may not realize // and report only that so as not to confuse users (they may not realize
// that without a source device, we have no ARP table to lookup for dmac) // that without a source device, we have no ARP table to lookup for dmac)

View File

@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/> along with this program. If not, see <http://www.gnu.org/licenses/>
*/ */
#include "pcaptransmitter.h" #include "pcaptxthread.h"
#include "statstuple.h" #include "statstuple.h"
#include "timestamp.h" #include "timestamp.h"
@ -109,6 +109,11 @@ void PcapTxThread::clearPacketList()
void PcapTxThread::loopNextPacketSet(qint64 size, qint64 repeats, void PcapTxThread::loopNextPacketSet(qint64 size, qint64 repeats,
long repeatDelaySec, long repeatDelayNsec) long repeatDelaySec, long repeatDelayNsec)
{ {
// Since we create implicit packetset for this case, skip
// This case => Packet set for y when x = 0 or n==1 in n*x+y
if (repeats == 1)
return;
currentPacketSequence_ = new PacketSequence(trackStreamStats_); currentPacketSequence_ = new PacketSequence(trackStreamStats_);
currentPacketSequence_->repeatCount_ = repeats; currentPacketSequence_->repeatCount_ = repeats;
currentPacketSequence_->usecDelay_ = repeatDelaySec * long(1e6) currentPacketSequence_->usecDelay_ = repeatDelaySec * long(1e6)

View File

@ -17,6 +17,10 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/> along with this program. If not, see <http://www.gnu.org/licenses/>
*/ */
#ifdef TURBO
#include "xdpport.h" // MUST be included first - see why in xdpport.h
#endif
#include "portmanager.h" #include "portmanager.h"
#include "bsdport.h" #include "bsdport.h"
@ -93,7 +97,11 @@ PortManager::PortManager()
#if defined(Q_OS_WIN32) #if defined(Q_OS_WIN32)
port = new WinPcapPort(i, device->name, device->description); port = new WinPcapPort(i, device->name, device->description);
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
#ifdef TURBO
port = new XdpPort(i, device->name);
#else
port = new LinuxPort(i, device->name); port = new LinuxPort(i, device->name);
#endif
#elif defined(Q_OS_BSD4) #elif defined(Q_OS_BSD4)
port = new BsdPort(i, device->name); port = new BsdPort(i, device->name);
#else #else

View File

@ -20,9 +20,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#ifndef _TIMESTAMP_H #ifndef _TIMESTAMP_H
#define _TIMESTAMP_H #define _TIMESTAMP_H
#include "timespecops.h"
#include <QtGlobal> #include <QtGlobal>
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX)
#include <sys/time.h>
#ifdef USE_NSEC_TIMESTAMP
typedef struct timespec TimeStamp;
static void inline getTimeStamp(TimeStamp *stamp)
{
clock_gettime(CLOCK_MONOTONIC, stamp);
}
// Returns time diff in nsecs between end and start
static long inline ndiffTimeStamp(const TimeStamp *start, const TimeStamp *end)
{
struct timespec diff;
timespecsub(end, start, &diff);
long nsecs = diff.tv_nsec;
if (diff.tv_sec)
nsecs += diff.tv_sec*1e9;
return nsecs;
}
#else
typedef struct timeval TimeStamp; typedef struct timeval TimeStamp;
static void inline getTimeStamp(TimeStamp *stamp) static void inline getTimeStamp(TimeStamp *stamp)
{ {
@ -43,6 +66,8 @@ static long inline udiffTimeStamp(const TimeStamp *start, const TimeStamp *end)
return usecs; return usecs;
} }
#endif
#elif defined(Q_OS_WIN32) #elif defined(Q_OS_WIN32)
static quint64 gTicksFreq; static quint64 gTicksFreq;
typedef LARGE_INTEGER TimeStamp; typedef LARGE_INTEGER TimeStamp;