Change T-Tag on the fly

This commit is contained in:
Srivats P 2023-03-17 12:45:59 +05:30
parent 2104936b69
commit 5d4a19174e
4 changed files with 33 additions and 10 deletions

View File

@ -86,13 +86,14 @@ public:
static quint32 magic(); static quint32 magic();
static bool packetGuid(const uchar *pkt, int pktLen, uint *guid); static bool packetGuid(const uchar *pkt, int pktLen, uint *guid);
static const quint32 kMaxGuid = 0x00ffffff; static const quint32 kMaxGuid = 0x00ffffff;
static const quint8 kTypeLenTtagPlaceholder = 0x22;
static const quint8 kTypeLenTtag = 0x23;
private: private:
static const quint32 kSignMagic = 0x1d10c0da; // coda! (unicode - 0x1d10c) static const quint32 kSignMagic = 0x1d10c0da; // coda! (unicode - 0x1d10c)
static const quint8 kTypeLenEnd = 0x00; static const quint8 kTypeLenEnd = 0x00;
static const quint8 kTypeLenGuid = 0x61; static const quint8 kTypeLenGuid = 0x61;
static const quint8 kTypeLenTtagPlaceholder = 0x22;
static const quint8 kTypeLenTtag = 0x23;
OstProto::Sign data; OstProto::Sign data;
}; };

View File

@ -79,6 +79,7 @@ public:
int repeatCount_; int repeatCount_;
int repeatSize_; int repeatSize_;
long usecDelay_; long usecDelay_;
qulonglong ttagPktInterval_{0}; // ttag pkt once every X packets
StreamStats streamStatsMeta_; StreamStats streamStatsMeta_;
private: private:

View File

@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "pcaptxthread.h" #include "pcaptxthread.h"
#include "sign.h"
#include "statstuple.h" #include "statstuple.h"
#include "timestamp.h" #include "timestamp.h"
@ -132,6 +133,8 @@ void PcapTxThread::loopNextPacketSet(qint64 size, qint64 repeats,
currentPacketSequence_->repeatCount_ = repeats; currentPacketSequence_->repeatCount_ = repeats;
currentPacketSequence_->usecDelay_ = repeatDelaySec * long(1e6) currentPacketSequence_->usecDelay_ = repeatDelaySec * long(1e6)
+ repeatDelayNsec/1000; + repeatDelayNsec/1000;
currentPacketSequence_->ttagPktInterval_ =
kTtagPktInterval*1e6/currentPacketSequence_->usecDelay_;
repeatSequenceStart_ = packetSequenceList_.size(); repeatSequenceStart_ = packetSequenceList_.size();
repeatSize_ = size; repeatSize_ = size;
@ -195,6 +198,8 @@ bool PcapTxThread::appendToPacketList(long sec, long nsec,
start->usecDelay_ = 0; start->usecDelay_ = 0;
start->repeatSize_ = start->repeatSize_ =
packetSequenceList_.size() - repeatSequenceStart_; packetSequenceList_.size() - repeatSequenceStart_;
start->ttagPktInterval_ = kTtagPktInterval*1e6
/currentPacketSequence_->usecDelay_;
} }
repeatSize_ = 0; repeatSize_ = 0;
@ -270,9 +275,10 @@ void PcapTxThread::run()
packetSequenceList_.at(i)->repeatCount_, packetSequenceList_.at(i)->repeatCount_,
packetSequenceList_.at(i)->repeatSize_, packetSequenceList_.at(i)->repeatSize_,
packetSequenceList_.at(i)->usecDelay_); packetSequenceList_.at(i)->usecDelay_);
qDebug("sendQ[%d]: pkts = %ld, usecDuration = %ld", i, qDebug("sendQ[%d]: pkts = %ld, usecDuration = %ld, ttagPktIntvl = %llu", i,
packetSequenceList_.at(i)->packets_, packetSequenceList_.at(i)->packets_,
packetSequenceList_.at(i)->usecDuration_); packetSequenceList_.at(i)->usecDuration_,
packetSequenceList_.at(i)->ttagPktInterval_);
} }
lastStats_ = *stats_; // used for stream stats lastStats_ = *stats_; // used for stream stats
@ -309,11 +315,11 @@ _restart:
ret = -2; ret = -2;
} else { } else {
ret = sendQueueTransmit(handle_, seq->sendQueue_, ret = sendQueueTransmit(handle_, seq->sendQueue_,
overHead, kSyncTransmit); seq->ttagPktInterval_, overHead, kSyncTransmit);
} }
#else #else
ret = sendQueueTransmit(handle_, seq->sendQueue_, ret = sendQueueTransmit(handle_, seq->sendQueue_,
overHead, kSyncTransmit); seq->ttagPktInterval_, overHead, kSyncTransmit);
#endif #endif
if (ret >= 0) { if (ret >= 0) {
@ -402,8 +408,8 @@ double PcapTxThread::lastTxDuration()
return lastTxDuration_; return lastTxDuration_;
} }
int PcapTxThread::sendQueueTransmit(pcap_t *p, int PcapTxThread::sendQueueTransmit(pcap_t *p, pcap_send_queue *queue,
pcap_send_queue *queue, long &overHead, int sync) quint64 ttagPktInterval, long &overHead, int sync)
{ {
TimeStamp ovrStart, ovrEnd; TimeStamp ovrStart, ovrEnd;
struct timeval ts; struct timeval ts;
@ -415,6 +421,14 @@ int PcapTxThread::sendQueueTransmit(pcap_t *p,
while((char*) hdr < end) { while((char*) hdr < end) {
uchar *pkt = (uchar*)hdr + sizeof(*hdr); uchar *pkt = (uchar*)hdr + sizeof(*hdr);
int pktLen = hdr->caplen; int pktLen = hdr->caplen;
bool ttagPkt = false;
// Time for a T-Tag packet?
if (ttagPktInterval && ((stats_->pkts % ttagPktInterval) == 0)) {
ttagPkt = true;
// FIXME: fixup cksum(s)
*(pkt+pktLen-5) = SignProtocol::kTypeLenTtag;
}
if (sync) { if (sync) {
long usec = (hdr->ts.tv_sec - ts.tv_sec) * 1000000 + long usec = (hdr->ts.tv_sec - ts.tv_sec) * 1000000 +
@ -440,6 +454,11 @@ int PcapTxThread::sendQueueTransmit(pcap_t *p,
stats_->pkts++; stats_->pkts++;
stats_->bytes += pktLen; stats_->bytes += pktLen;
// Revert T-Tag packet changes
if (ttagPkt) {
*(pkt+pktLen-5) = SignProtocol::kTypeLenTtagPlaceholder;
}
// Step to the next packet in the buffer // Step to the next packet in the buffer
hdr = (struct pcap_pkthdr*) (pkt + pktLen); hdr = (struct pcap_pkthdr*) (pkt + pktLen);
pkt = (uchar*) ((uchar*)hdr + sizeof(*hdr)); // FIXME: superfluous? pkt = (uchar*) ((uchar*)hdr + sizeof(*hdr)); // FIXME: superfluous?

View File

@ -66,8 +66,8 @@ private:
}; };
static void udelay(unsigned long usec); static void udelay(unsigned long usec);
int sendQueueTransmit(pcap_t *p, pcap_send_queue *queue, long &overHead, int sendQueueTransmit(pcap_t *p, pcap_send_queue *queue,
int sync); quint64 ttagPktInterval, long &overHead, int sync);
void updateTxStreamStats(); void updateTxStreamStats();
// Intermediate state variables used while building the packet list // Intermediate state variables used while building the packet list
@ -95,6 +95,8 @@ private:
StreamStats streamStats_; StreamStats streamStats_;
double lastTxDuration_{0.0}; // in secs double lastTxDuration_{0.0}; // in secs
const ulong kTtagPktInterval{5}; // T-Tag pkt once every X sec
}; };
#endif #endif