2015-04-16 11:50:07 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 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 _SERVER_PCAP_PORT_H
|
|
|
|
#define _SERVER_PCAP_PORT_H
|
|
|
|
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QThread>
|
|
|
|
#include <pcap.h>
|
|
|
|
|
|
|
|
#include "abstractport.h"
|
|
|
|
#include "pcapextra.h"
|
2016-11-17 10:14:34 -06:00
|
|
|
#include "pcaprxstats.h"
|
2019-08-10 02:46:18 -05:00
|
|
|
#include "pcapsession.h"
|
2016-09-06 08:20:08 -05:00
|
|
|
#include "pcaptransmitter.h"
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
class PcapPort : public AbstractPort
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PcapPort(int id, const char *device);
|
|
|
|
~PcapPort();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
|
|
|
virtual bool hasExclusiveControl() { return false; }
|
|
|
|
virtual bool setExclusiveControl(bool /*exclusive*/) { return false; }
|
|
|
|
|
2016-12-07 06:49:09 -06:00
|
|
|
virtual bool setTrackStreamStats(bool enable);
|
2015-10-12 07:41:30 -05:00
|
|
|
virtual bool setRateAccuracy(AbstractPort::Accuracy accuracy);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
virtual void clearPacketList() {
|
|
|
|
transmitter_->clearPacketList();
|
|
|
|
setPacketListLoopMode(false, 0, 0);
|
|
|
|
}
|
|
|
|
virtual void loopNextPacketSet(qint64 size, qint64 repeats,
|
|
|
|
long repeatDelaySec, long repeatDelayNsec) {
|
|
|
|
transmitter_->loopNextPacketSet(size, repeats,
|
|
|
|
repeatDelaySec, repeatDelayNsec);
|
|
|
|
}
|
|
|
|
virtual bool appendToPacketList(long sec, long nsec, const uchar *packet,
|
|
|
|
int length) {
|
|
|
|
return transmitter_->appendToPacketList(sec, nsec, packet, length);
|
|
|
|
}
|
|
|
|
virtual void setPacketListLoopMode(bool loop, quint64 secDelay, quint64 nsecDelay)
|
|
|
|
{
|
|
|
|
transmitter_->setPacketListLoopMode(loop, secDelay, nsecDelay);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void startTransmit() {
|
|
|
|
Q_ASSERT(!isDirty());
|
|
|
|
transmitter_->start();
|
|
|
|
}
|
|
|
|
virtual void stopTransmit() { transmitter_->stop(); }
|
|
|
|
virtual bool isTransmitOn() { return transmitter_->isRunning(); }
|
2022-02-21 10:50:59 -06:00
|
|
|
virtual double lastTransmitDuration() {
|
|
|
|
return transmitter_->lastTxDuration();
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
virtual void startCapture() { capturer_->start(); }
|
|
|
|
virtual void stopCapture() { capturer_->stop(); }
|
|
|
|
virtual bool isCaptureOn() { return capturer_->isRunning(); }
|
|
|
|
virtual QIODevice* captureData() { return capturer_->captureFile(); }
|
|
|
|
|
2015-09-14 07:49:52 -05:00
|
|
|
virtual void startDeviceEmulation();
|
|
|
|
virtual void stopDeviceEmulation();
|
|
|
|
virtual int sendEmulationPacket(PacketBuffer *pktBuf);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
protected:
|
|
|
|
enum Direction
|
|
|
|
{
|
|
|
|
kDirectionRx,
|
|
|
|
kDirectionTx
|
|
|
|
};
|
|
|
|
|
2019-08-10 02:46:18 -05:00
|
|
|
class PortMonitor: public QThread // TODO: inherit from PcapSession (only if required)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
PortMonitor(const char *device, Direction direction,
|
|
|
|
AbstractPort::PortStats *stats);
|
|
|
|
~PortMonitor();
|
|
|
|
void run();
|
|
|
|
void stop();
|
|
|
|
pcap_t* handle() { return handle_; }
|
|
|
|
Direction direction() { return direction_; }
|
|
|
|
bool isDirectional() { return isDirectional_; }
|
|
|
|
bool isPromiscuous() { return isPromisc_; }
|
|
|
|
protected:
|
|
|
|
AbstractPort::PortStats *stats_;
|
|
|
|
bool stop_;
|
|
|
|
private:
|
|
|
|
pcap_t *handle_;
|
|
|
|
Direction direction_;
|
|
|
|
bool isDirectional_;
|
|
|
|
bool isPromisc_;
|
|
|
|
};
|
|
|
|
|
2019-08-10 02:46:18 -05:00
|
|
|
class PortCapturer: public PcapSession
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
PortCapturer(const char *device);
|
|
|
|
~PortCapturer();
|
|
|
|
void run();
|
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
bool isRunning();
|
|
|
|
QFile* captureFile();
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum State
|
|
|
|
{
|
|
|
|
kNotStarted,
|
|
|
|
kRunning,
|
|
|
|
kFinished
|
|
|
|
};
|
|
|
|
|
|
|
|
QString device_;
|
|
|
|
volatile bool stop_;
|
|
|
|
QTemporaryFile capFile_;
|
|
|
|
pcap_t *handle_;
|
|
|
|
pcap_dumper_t *dumpHandle_;
|
|
|
|
volatile State state_;
|
|
|
|
};
|
|
|
|
|
2019-08-10 02:46:18 -05:00
|
|
|
class EmulationTransceiver: public PcapSession
|
2015-09-14 07:49:52 -05:00
|
|
|
{
|
|
|
|
public:
|
2015-11-14 05:36:43 -06:00
|
|
|
EmulationTransceiver(const char *device, DeviceManager *deviceManager);
|
|
|
|
~EmulationTransceiver();
|
2015-09-14 07:49:52 -05:00
|
|
|
void run();
|
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
bool isRunning();
|
|
|
|
int transmitPacket(PacketBuffer *pktBuf);
|
|
|
|
|
|
|
|
private:
|
2015-11-14 05:36:43 -06:00
|
|
|
enum State
|
2015-09-14 07:49:52 -05:00
|
|
|
{
|
|
|
|
kNotStarted,
|
|
|
|
kRunning,
|
|
|
|
kFinished
|
|
|
|
};
|
|
|
|
|
|
|
|
QString device_;
|
|
|
|
DeviceManager *deviceManager_;
|
|
|
|
volatile bool stop_;
|
|
|
|
pcap_t *handle_;
|
|
|
|
volatile State state_;
|
|
|
|
};
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
PortMonitor *monitorRx_;
|
|
|
|
PortMonitor *monitorTx_;
|
|
|
|
|
|
|
|
void updateNotes();
|
|
|
|
|
|
|
|
private:
|
2016-12-07 06:49:09 -06:00
|
|
|
bool startStreamStatsTracking();
|
|
|
|
bool stopStreamStatsTracking();
|
|
|
|
|
2016-09-13 08:35:24 -05:00
|
|
|
PcapTransmitter *transmitter_;
|
2015-04-16 11:50:07 -05:00
|
|
|
PortCapturer *capturer_;
|
2015-11-14 05:36:43 -06:00
|
|
|
EmulationTransceiver *emulXcvr_;
|
2016-11-17 10:14:34 -06:00
|
|
|
PcapRxStats *rxStatsPoller_;
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
static pcap_if_t *deviceList_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|