2016-09-13 08:35:24 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2016 Srivats P.
|
|
|
|
|
|
|
|
This file is part of "Ostinato"
|
|
|
|
|
|
|
|
This is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PCAP_TX_THREAD_H
|
|
|
|
#define _PCAP_TX_THREAD_H
|
|
|
|
|
|
|
|
#include "abstractport.h"
|
|
|
|
#include "packetsequence.h"
|
2016-11-13 07:41:24 -06:00
|
|
|
#include "statstuple.h"
|
2016-09-13 08:35:24 -05:00
|
|
|
|
|
|
|
#include <QThread>
|
|
|
|
#include <pcap.h>
|
|
|
|
|
|
|
|
class PcapTxThread: public QThread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PcapTxThread(const char *device);
|
|
|
|
~PcapTxThread();
|
|
|
|
|
|
|
|
bool setRateAccuracy(AbstractPort::Accuracy accuracy);
|
2016-12-06 10:11:47 -06:00
|
|
|
bool setStreamStatsTracking(bool enable);
|
2016-09-13 08:35:24 -05:00
|
|
|
|
|
|
|
void clearPacketList();
|
|
|
|
void loopNextPacketSet(qint64 size, qint64 repeats,
|
|
|
|
long repeatDelaySec, long repeatDelayNsec);
|
|
|
|
bool appendToPacketList(long sec, long usec, const uchar *packet,
|
|
|
|
int length);
|
|
|
|
void setPacketListLoopMode(bool loop, quint64 secDelay, quint64 nsecDelay);
|
|
|
|
|
|
|
|
void setHandle(pcap_t *handle);
|
2016-10-19 08:22:35 -05:00
|
|
|
|
|
|
|
void setStats(StatsTuple *stats);
|
2016-09-13 08:35:24 -05:00
|
|
|
|
2016-11-11 09:52:07 -06:00
|
|
|
const StreamStats& streamStats();
|
|
|
|
void clearStreamStats();
|
|
|
|
|
2016-09-13 08:35:24 -05:00
|
|
|
void run();
|
|
|
|
|
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
bool isRunning();
|
2016-10-19 08:22:35 -05:00
|
|
|
|
2016-09-13 08:35:24 -05:00
|
|
|
private:
|
|
|
|
enum State
|
|
|
|
{
|
|
|
|
kNotStarted,
|
|
|
|
kRunning,
|
|
|
|
kFinished
|
|
|
|
};
|
|
|
|
|
|
|
|
static void udelay(unsigned long usec);
|
|
|
|
int sendQueueTransmit(pcap_t *p, pcap_send_queue *queue, long &overHead,
|
|
|
|
int sync);
|
2016-11-13 07:41:24 -06:00
|
|
|
void updateStreamStats();
|
2016-09-13 08:35:24 -05:00
|
|
|
|
2016-11-15 10:53:55 -06:00
|
|
|
// Intermediate state variables used while building the packet list
|
2016-09-13 08:35:24 -05:00
|
|
|
PacketSequence *currentPacketSequence_;
|
|
|
|
int repeatSequenceStart_;
|
|
|
|
quint64 repeatSize_;
|
|
|
|
quint64 packetCount_;
|
|
|
|
|
2016-11-15 10:53:55 -06:00
|
|
|
QList<PacketSequence*> packetSequenceList_;
|
|
|
|
quint64 packetListSize_; // count of pkts in packet List including repeats
|
|
|
|
|
2016-09-13 08:35:24 -05:00
|
|
|
int returnToQIdx_;
|
|
|
|
quint64 loopDelay_;
|
|
|
|
|
|
|
|
void (*udelayFn_)(unsigned long);
|
|
|
|
|
|
|
|
bool usingInternalHandle_;
|
|
|
|
pcap_t *handle_;
|
|
|
|
volatile bool stop_;
|
|
|
|
volatile State state_;
|
2016-10-19 08:22:35 -05:00
|
|
|
|
2016-12-06 10:11:47 -06:00
|
|
|
bool trackStreamStats_;
|
2016-10-19 08:22:35 -05:00
|
|
|
StatsTuple *stats_;
|
2016-11-13 07:41:24 -06:00
|
|
|
StatsTuple lastStats_;
|
2016-11-11 09:52:07 -06:00
|
|
|
StreamStats streamStats_;
|
2016-09-13 08:35:24 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|