2008-08-08 22:22:13 -05:00
|
|
|
#ifndef _MY_SERVICE_H
|
|
|
|
#define _MY_SERVICE_H
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#include <google/protobuf/message.h>
|
|
|
|
#include <google/protobuf/service.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../common/protocol.pb.h"
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
#include "../common/streambase.h"
|
2008-08-08 22:22:13 -05:00
|
|
|
#include "abstracthost.h"
|
|
|
|
#include <pcap.h>
|
2008-09-14 07:03:53 -05:00
|
|
|
#include <QtGlobal>
|
2008-08-08 22:22:13 -05:00
|
|
|
#include <QList>
|
2008-09-14 07:03:53 -05:00
|
|
|
#include <QThread>
|
2009-10-14 10:16:56 -05:00
|
|
|
#include <QTemporaryFile>
|
2008-08-08 22:22:13 -05:00
|
|
|
|
2008-08-23 23:39:08 -05:00
|
|
|
#include "../rpc/pbhelper.h"
|
2009-01-17 04:13:46 -06:00
|
|
|
#include "pcapextra.h"
|
|
|
|
|
2008-09-28 13:01:52 -05:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
#include <packet32.h>
|
|
|
|
#endif
|
|
|
|
|
2008-08-08 22:22:13 -05:00
|
|
|
#define MAX_PKT_HDR_SIZE 1536
|
|
|
|
#define MAX_STREAM_NAME_SIZE 64
|
|
|
|
|
2008-09-28 13:01:52 -05:00
|
|
|
//! 7 byte Preamble + 1 byte SFD + 4 byte FCS
|
|
|
|
#define ETH_FRAME_HDR_SIZE 12
|
|
|
|
|
2008-08-08 22:22:13 -05:00
|
|
|
class MyService;
|
|
|
|
|
Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
o ProtocolManager - singleton with which all protocols register
o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
o createInstance()
o protocolFrameSize()
o protocolFrameOffset(), protocolFramePayloadSize()
o protocolId(), payloadProtocolId()
o protocolFrameCksum(), protocolFramePayloadCksum()
0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 01:27:17 -05:00
|
|
|
class StreamInfo : public StreamBase
|
2008-08-08 22:22:13 -05:00
|
|
|
{
|
|
|
|
friend class MyService;
|
2008-09-14 07:03:53 -05:00
|
|
|
friend class PortInfo;
|
2008-08-08 22:22:13 -05:00
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
OstProto::StreamId mStreamId;
|
2008-09-28 13:01:52 -05:00
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
public:
|
|
|
|
StreamInfo();
|
|
|
|
~StreamInfo();
|
|
|
|
|
|
|
|
private:
|
2009-01-17 04:13:46 -06:00
|
|
|
int makePacket(uchar *buf, int bufMaxSize, int n);
|
2008-08-08 22:22:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class PortInfo
|
|
|
|
{
|
|
|
|
friend class MyService;
|
|
|
|
|
2009-02-02 04:08:57 -06:00
|
|
|
class PortMonitorRx: public QThread
|
2008-09-14 07:03:53 -05:00
|
|
|
{
|
|
|
|
friend class PortInfo;
|
|
|
|
|
2008-09-28 13:01:52 -05:00
|
|
|
PortInfo *port;
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
PPACKET_OID_DATA oidData;
|
|
|
|
#endif
|
2008-09-14 07:03:53 -05:00
|
|
|
public:
|
2009-02-02 04:08:57 -06:00
|
|
|
PortMonitorRx(PortInfo *port);
|
|
|
|
static void callbackRx(u_char *state,
|
|
|
|
const struct pcap_pkthdr *header, const u_char *pkt_data);
|
|
|
|
void run();
|
|
|
|
};
|
|
|
|
|
|
|
|
class PortMonitorTx: public QThread
|
|
|
|
{
|
|
|
|
friend class PortInfo;
|
|
|
|
|
|
|
|
PortInfo *port;
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
PPACKET_OID_DATA oidData;
|
|
|
|
#endif
|
|
|
|
public:
|
|
|
|
PortMonitorTx(PortInfo *port);
|
|
|
|
static void callbackTx(u_char *state,
|
2008-09-14 07:03:53 -05:00
|
|
|
const struct pcap_pkthdr *header, const u_char *pkt_data);
|
|
|
|
void run();
|
|
|
|
};
|
2009-02-12 11:07:19 -06:00
|
|
|
|
|
|
|
class PortTransmitter: public QThread
|
|
|
|
{
|
|
|
|
friend class PortInfo;
|
|
|
|
|
2009-02-22 01:53:14 -06:00
|
|
|
PortInfo *port;
|
|
|
|
int m_stop;
|
2009-02-12 11:07:19 -06:00
|
|
|
|
|
|
|
public:
|
|
|
|
PortTransmitter(PortInfo *port);
|
|
|
|
void run();
|
2009-02-22 01:53:14 -06:00
|
|
|
void stop();
|
2009-02-12 11:07:19 -06:00
|
|
|
};
|
2009-10-14 10:16:56 -05:00
|
|
|
|
|
|
|
class PortCapture: public QThread
|
|
|
|
{
|
|
|
|
friend class PortInfo;
|
|
|
|
|
|
|
|
PortInfo *port;
|
|
|
|
pcap_t *capHandle;
|
|
|
|
pcap_dumper_t *dumpHandle;
|
|
|
|
QTemporaryFile capFile;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PortCapture(PortInfo *port);
|
2009-11-03 08:02:09 -06:00
|
|
|
~PortCapture();
|
2009-10-14 10:16:56 -05:00
|
|
|
void run();
|
|
|
|
void stop();
|
2009-11-03 08:02:09 -06:00
|
|
|
QFile* captureFile();
|
2009-10-14 10:16:56 -05:00
|
|
|
};
|
2008-09-14 07:03:53 -05:00
|
|
|
|
2008-08-23 23:39:08 -05:00
|
|
|
OstProto::Port d;
|
2008-09-14 07:03:53 -05:00
|
|
|
|
|
|
|
struct PortStats
|
|
|
|
{
|
|
|
|
quint64 rxPkts;
|
|
|
|
quint64 rxBytes;
|
2008-09-28 13:01:52 -05:00
|
|
|
quint64 rxPktsNic;
|
|
|
|
quint64 rxBytesNic;
|
2008-09-14 07:03:53 -05:00
|
|
|
quint64 rxPps;
|
|
|
|
quint64 rxBps;
|
|
|
|
|
|
|
|
quint64 txPkts;
|
|
|
|
quint64 txBytes;
|
2008-09-28 13:01:52 -05:00
|
|
|
quint64 txPktsNic;
|
|
|
|
quint64 txBytesNic;
|
2008-09-14 07:03:53 -05:00
|
|
|
quint64 txPps;
|
|
|
|
quint64 txBps;
|
|
|
|
};
|
|
|
|
|
2008-09-28 13:01:52 -05:00
|
|
|
//! \todo Need lock for stats access/update
|
2009-02-22 01:53:14 -06:00
|
|
|
|
2008-09-28 13:01:52 -05:00
|
|
|
|
|
|
|
//! Stuff we need to maintain since PCAP doesn't as of now. As and when
|
|
|
|
// PCAP supports it, we'll remove from here
|
|
|
|
struct PcapExtra
|
|
|
|
{
|
|
|
|
|
|
|
|
//! PCAP doesn't do any tx stats
|
|
|
|
quint64 txPkts;
|
|
|
|
quint64 txBytes;
|
2009-02-22 01:53:14 -06:00
|
|
|
|
2008-09-28 13:01:52 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
pcap_if_t *dev;
|
2009-02-02 04:08:57 -06:00
|
|
|
pcap_t *devHandleRx;
|
|
|
|
pcap_t *devHandleTx;
|
2009-02-22 01:53:14 -06:00
|
|
|
QList<ost_pcap_send_queue> sendQueueList;
|
2009-03-10 11:48:03 -05:00
|
|
|
int returnToQIdx; // FIXME(MED): combine with sendQList
|
2008-09-28 13:01:52 -05:00
|
|
|
bool isSendQueueDirty;
|
|
|
|
PcapExtra pcapExtra;
|
2009-02-02 04:08:57 -06:00
|
|
|
PortMonitorRx monitorRx;
|
|
|
|
PortMonitorTx monitorTx;
|
2009-02-12 11:07:19 -06:00
|
|
|
PortTransmitter transmitter;
|
2009-10-14 10:16:56 -05:00
|
|
|
PortCapture capturer;
|
2008-09-28 13:01:52 -05:00
|
|
|
|
|
|
|
struct PortStats epochStats;
|
2008-09-14 07:03:53 -05:00
|
|
|
struct PortStats stats;
|
2009-02-02 04:08:57 -06:00
|
|
|
struct timeval lastTsRx; //! used for Rate Stats calculations
|
|
|
|
struct timeval lastTsTx; //! used for Rate Stats calculations
|
2008-08-08 22:22:13 -05:00
|
|
|
|
2008-08-23 23:39:08 -05:00
|
|
|
/*! StreamInfo::d::stream_id and index into streamList[] are NOT same! */
|
2009-04-27 11:51:44 -05:00
|
|
|
QList<StreamInfo*> streamList;
|
2008-08-08 22:22:13 -05:00
|
|
|
|
|
|
|
public:
|
2009-01-17 04:13:46 -06:00
|
|
|
PortInfo(uint id, pcap_if_t *dev);
|
2008-09-14 07:03:53 -05:00
|
|
|
uint id() { return d.port_id().id(); }
|
|
|
|
bool isDirty() { return isSendQueueDirty; }
|
|
|
|
void setDirty(bool dirty) { isSendQueueDirty = dirty; }
|
|
|
|
void update();
|
|
|
|
void startTransmit();
|
|
|
|
void stopTransmit();
|
2009-10-14 10:16:56 -05:00
|
|
|
void startCapture();
|
|
|
|
void stopCapture();
|
2009-11-03 08:02:09 -06:00
|
|
|
QFile* captureFile();
|
2008-09-14 07:03:53 -05:00
|
|
|
void resetStats();
|
2008-08-08 22:22:13 -05:00
|
|
|
};
|
|
|
|
|
2008-09-14 07:03:53 -05:00
|
|
|
|
2008-08-08 22:22:13 -05:00
|
|
|
class MyService: public OstProto::OstService
|
|
|
|
{
|
|
|
|
AbstractHost *host;
|
|
|
|
char logStr[1024];
|
|
|
|
|
2008-08-23 23:39:08 -05:00
|
|
|
uint numPorts;
|
2008-09-14 07:03:53 -05:00
|
|
|
|
2008-08-23 23:39:08 -05:00
|
|
|
/*! PortInfo::d::port_id and index into portInfo[] are same! */
|
2008-09-14 07:03:53 -05:00
|
|
|
QList<PortInfo*> portInfo;
|
2008-08-08 22:22:13 -05:00
|
|
|
pcap_if_t *alldevs;
|
|
|
|
|
2008-08-23 23:39:08 -05:00
|
|
|
int getStreamIndex(unsigned int portIdx,unsigned int streamId);
|
|
|
|
|
2008-08-08 22:22:13 -05:00
|
|
|
public:
|
|
|
|
MyService(AbstractHost* host);
|
|
|
|
virtual ~MyService();
|
|
|
|
|
2008-08-23 23:39:08 -05:00
|
|
|
/* Methods provided by the service */
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void getPortIdList(::google::protobuf::RpcController* controller,
|
2008-08-23 23:39:08 -05:00
|
|
|
const ::OstProto::Void* request,
|
|
|
|
::OstProto::PortIdList* response,
|
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void getPortConfig(::google::protobuf::RpcController* controller,
|
2008-08-23 23:39:08 -05:00
|
|
|
const ::OstProto::PortIdList* request,
|
|
|
|
::OstProto::PortConfigList* response,
|
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void getStreamIdList(::google::protobuf::RpcController* controller,
|
2008-08-23 23:39:08 -05:00
|
|
|
const ::OstProto::PortId* request,
|
|
|
|
::OstProto::StreamIdList* response,
|
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void getStreamConfig(::google::protobuf::RpcController* controller,
|
2008-08-23 23:39:08 -05:00
|
|
|
const ::OstProto::StreamIdList* request,
|
|
|
|
::OstProto::StreamConfigList* response,
|
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void addStream(::google::protobuf::RpcController* controller,
|
2008-08-23 23:39:08 -05:00
|
|
|
const ::OstProto::StreamIdList* request,
|
|
|
|
::OstProto::Ack* response,
|
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void deleteStream(::google::protobuf::RpcController* controller,
|
2008-08-23 23:39:08 -05:00
|
|
|
const ::OstProto::StreamIdList* request,
|
|
|
|
::OstProto::Ack* response,
|
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void modifyStream(::google::protobuf::RpcController* controller,
|
2008-08-23 23:39:08 -05:00
|
|
|
const ::OstProto::StreamConfigList* request,
|
|
|
|
::OstProto::Ack* response,
|
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void startTx(::google::protobuf::RpcController* controller,
|
2008-08-23 23:39:08 -05:00
|
|
|
const ::OstProto::PortIdList* request,
|
|
|
|
::OstProto::Ack* response,
|
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void stopTx(::google::protobuf::RpcController* controller,
|
2008-08-23 23:39:08 -05:00
|
|
|
const ::OstProto::PortIdList* request,
|
|
|
|
::OstProto::Ack* response,
|
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void startCapture(::google::protobuf::RpcController* controller,
|
2008-08-23 23:39:08 -05:00
|
|
|
const ::OstProto::PortIdList* request,
|
|
|
|
::OstProto::Ack* response,
|
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void stopCapture(::google::protobuf::RpcController* controller,
|
2008-08-23 23:39:08 -05:00
|
|
|
const ::OstProto::PortIdList* request,
|
|
|
|
::OstProto::Ack* response,
|
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void getCaptureBuffer(::google::protobuf::RpcController* controller,
|
2009-11-03 08:02:09 -06:00
|
|
|
const ::OstProto::PortId* request,
|
|
|
|
::OstProto::CaptureBuffer* response,
|
2008-08-23 23:39:08 -05:00
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void getStats(::google::protobuf::RpcController* controller,
|
2008-08-23 23:39:08 -05:00
|
|
|
const ::OstProto::PortIdList* request,
|
|
|
|
::OstProto::PortStatsList* response,
|
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
virtual void clearStats(::google::protobuf::RpcController* controller,
|
2008-08-23 23:39:08 -05:00
|
|
|
const ::OstProto::PortIdList* request,
|
|
|
|
::OstProto::Ack* response,
|
|
|
|
::google::protobuf::Closure* done);
|
2008-08-08 22:22:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|