2015-04-16 11:50:07 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2012 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_ABSTRACT_PORT_H
|
|
|
|
#define _SERVER_ABSTRACT_PORT_H
|
|
|
|
|
2016-11-11 09:52:07 -06:00
|
|
|
#include "streamstats.h"
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
#include <QList>
|
|
|
|
#include <QtGlobal>
|
|
|
|
|
|
|
|
#include "../common/protocol.pb.h"
|
|
|
|
|
2015-09-14 07:49:52 -05:00
|
|
|
class DeviceManager;
|
2015-04-16 11:50:07 -05:00
|
|
|
class StreamBase;
|
2015-09-14 07:49:52 -05:00
|
|
|
class PacketBuffer;
|
2015-04-16 11:50:07 -05:00
|
|
|
class QIODevice;
|
|
|
|
|
2015-11-14 05:36:43 -06:00
|
|
|
// TODO: send notification back to client(s)
|
|
|
|
#define notify qWarning
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
class AbstractPort
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct PortStats
|
|
|
|
{
|
|
|
|
quint64 rxPkts;
|
|
|
|
quint64 rxBytes;
|
|
|
|
quint64 rxPps;
|
|
|
|
quint64 rxBps;
|
|
|
|
|
|
|
|
quint64 rxDrops;
|
|
|
|
quint64 rxErrors;
|
|
|
|
quint64 rxFifoErrors;
|
|
|
|
quint64 rxFrameErrors;
|
|
|
|
|
|
|
|
quint64 txPkts;
|
|
|
|
quint64 txBytes;
|
|
|
|
quint64 txPps;
|
|
|
|
quint64 txBps;
|
|
|
|
};
|
|
|
|
|
2015-10-12 07:41:30 -05:00
|
|
|
enum Accuracy
|
|
|
|
{
|
|
|
|
kHighAccuracy,
|
|
|
|
kMediumAccuracy,
|
|
|
|
kLowAccuracy,
|
|
|
|
};
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
AbstractPort(int id, const char *device);
|
|
|
|
virtual ~AbstractPort();
|
|
|
|
|
|
|
|
bool isUsable() { return isUsable_; }
|
|
|
|
|
|
|
|
virtual void init();
|
|
|
|
|
|
|
|
int id() { return data_.port_id().id(); }
|
|
|
|
const char* name() { return data_.name().c_str(); }
|
|
|
|
void protoDataCopyInto(OstProto::Port *port) { port->CopyFrom(data_); }
|
|
|
|
|
2016-10-27 11:14:08 -05:00
|
|
|
bool canModify(const OstProto::Port &port, bool *dirty);
|
2015-04-16 11:50:07 -05:00
|
|
|
bool modify(const OstProto::Port &port);
|
|
|
|
|
|
|
|
virtual OstProto::LinkState linkState() { return linkState_; }
|
|
|
|
virtual bool hasExclusiveControl() = 0;
|
|
|
|
virtual bool setExclusiveControl(bool exclusive) = 0;
|
|
|
|
|
|
|
|
int streamCount() { return streamList_.size(); }
|
|
|
|
StreamBase* streamAtIndex(int index);
|
|
|
|
StreamBase* stream(int streamId);
|
|
|
|
bool addStream(StreamBase *stream);
|
|
|
|
bool deleteStream(int streamId);
|
|
|
|
|
|
|
|
bool isDirty() { return isSendQueueDirty_; }
|
|
|
|
void setDirty() { isSendQueueDirty_ = true; }
|
|
|
|
|
2016-11-21 07:09:55 -06:00
|
|
|
virtual bool setTrackStreamStats(bool enable);
|
|
|
|
|
2015-10-12 07:41:30 -05:00
|
|
|
Accuracy rateAccuracy();
|
|
|
|
virtual bool setRateAccuracy(Accuracy accuracy);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
virtual void clearPacketList() = 0;
|
|
|
|
virtual void loopNextPacketSet(qint64 size, qint64 repeats,
|
|
|
|
long repeatDelaySec, long repeatDelayNsec) = 0;
|
|
|
|
virtual bool appendToPacketList(long sec, long nsec, const uchar *packet,
|
|
|
|
int length) = 0;
|
|
|
|
virtual void setPacketListLoopMode(bool loop,
|
|
|
|
quint64 secDelay, quint64 nsecDelay) = 0;
|
|
|
|
void updatePacketList();
|
|
|
|
|
|
|
|
virtual void startTransmit() = 0;
|
|
|
|
virtual void stopTransmit() = 0;
|
|
|
|
virtual bool isTransmitOn() = 0;
|
|
|
|
|
|
|
|
virtual void startCapture() = 0;
|
|
|
|
virtual void stopCapture() = 0;
|
|
|
|
virtual bool isCaptureOn() = 0;
|
|
|
|
virtual QIODevice* captureData() = 0;
|
|
|
|
|
2015-11-10 08:10:32 -06:00
|
|
|
void stats(PortStats *stats);
|
|
|
|
void resetStats() { epochStats_ = stats_; }
|
|
|
|
|
2016-11-17 10:14:34 -06:00
|
|
|
virtual bool startStreamStatsTracking() = 0;
|
|
|
|
virtual bool stopStreamStatsTracking() = 0;
|
2016-11-10 06:48:27 -06:00
|
|
|
// FIXME: combine single and All calls?
|
|
|
|
void streamStats(uint guid, OstProto::StreamStatsList *stats);
|
|
|
|
void streamStatsAll(OstProto::StreamStatsList *stats);
|
|
|
|
void resetStreamStats(uint guid);
|
|
|
|
void resetStreamStatsAll();
|
|
|
|
|
2015-09-14 07:49:52 -05:00
|
|
|
DeviceManager* deviceManager();
|
|
|
|
virtual void startDeviceEmulation() = 0;
|
|
|
|
virtual void stopDeviceEmulation() = 0;
|
|
|
|
virtual int sendEmulationPacket(PacketBuffer *pktBuf) = 0;
|
|
|
|
|
2015-11-04 07:20:08 -06:00
|
|
|
void clearDeviceNeighbors();
|
|
|
|
void resolveDeviceNeighbors();
|
|
|
|
|
2015-11-10 08:10:32 -06:00
|
|
|
quint64 deviceMacAddress(int streamId, int frameIndex);
|
|
|
|
quint64 neighborMacAddress(int streamId, int frameIndex);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
protected:
|
2016-11-10 06:48:27 -06:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
void addNote(QString note);
|
|
|
|
|
|
|
|
void updatePacketListSequential();
|
|
|
|
void updatePacketListInterleaved();
|
|
|
|
|
|
|
|
bool isUsable_;
|
|
|
|
OstProto::Port data_;
|
|
|
|
OstProto::LinkState linkState_;
|
|
|
|
ulong minPacketSetSize_;
|
2015-10-12 07:41:30 -05:00
|
|
|
Accuracy rateAccuracy_;
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
quint64 maxStatsValue_;
|
|
|
|
struct PortStats stats_;
|
2016-11-11 09:52:07 -06:00
|
|
|
StreamStats streamStats_;
|
2015-04-16 11:50:07 -05:00
|
|
|
//! \todo Need lock for stats access/update
|
|
|
|
|
2015-09-14 07:49:52 -05:00
|
|
|
DeviceManager *deviceManager_;
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
private:
|
|
|
|
bool isSendQueueDirty_;
|
|
|
|
|
|
|
|
static const int kMaxPktSize = 16384;
|
|
|
|
uchar pktBuf_[kMaxPktSize];
|
|
|
|
|
2015-11-10 08:10:32 -06:00
|
|
|
// When finding a corresponding device for a packet, we need to inspect
|
|
|
|
// only uptil the L3 header; in the worst case this would be -
|
|
|
|
// mac (12) + 4 x vlan (16) + ethType (2) + ipv6 (40) = 74 bytes
|
|
|
|
// let's round it up to 80 bytes
|
|
|
|
static const int kMaxL3PktSize = 80;
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
/*! \note StreamBase::id() and index into streamList[] are NOT same! */
|
|
|
|
QList<StreamBase*> streamList_;
|
|
|
|
|
|
|
|
struct PortStats epochStats_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|