2010-03-27 13:38:57 -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/>
|
|
|
|
*/
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
#ifndef _ABSTRACT_PROTOCOL_H
|
|
|
|
#define _ABSTRACT_PROTOCOL_H
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QWidget>
|
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 <QLinkedList>
|
2009-05-24 09:54:11 -05:00
|
|
|
#include <QFlags>
|
2009-04-27 11:51:44 -05:00
|
|
|
|
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 "../rpc/pbhelper.h"
|
2009-08-02 09:52:34 -05:00
|
|
|
#include "protocol.pb.h"
|
2009-04-27 11:51:44 -05:00
|
|
|
|
|
|
|
#define BASE_BIN (2)
|
|
|
|
#define BASE_OCT (8)
|
|
|
|
#define BASE_DEC (10)
|
|
|
|
#define BASE_HEX (16)
|
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
#define uintToHexStr(num, bytes) \
|
|
|
|
QString("%1").arg(num, bytes*2, BASE_HEX, QChar('0'))
|
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
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
class StreamBase;
|
2009-10-14 10:16:56 -05:00
|
|
|
class ProtocolListIterator;
|
2009-04-27 11:51:44 -05:00
|
|
|
|
|
|
|
class AbstractProtocol
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
template <int protoNumber, class ProtoA, class ProtoB>
|
|
|
|
friend class ComboProtocol;
|
|
|
|
friend class ProtocolListIterator;
|
2009-10-14 10:16:56 -05:00
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
private:
|
2010-04-18 11:20:35 -05:00
|
|
|
mutable int metaCount;
|
|
|
|
mutable int protoSize;
|
2009-12-28 02:31:28 -06:00
|
|
|
mutable QString protoAbbr;
|
2009-04-27 11:51:44 -05:00
|
|
|
|
|
|
|
protected:
|
2010-04-18 11:20:35 -05:00
|
|
|
StreamBase *mpStream; //!< Stream that this protocol belongs to
|
|
|
|
AbstractProtocol *parent; //!< Parent protocol, if any
|
|
|
|
AbstractProtocol *prev; //!< Protocol preceding this protocol
|
|
|
|
AbstractProtocol *next; //!< Protocol succeeding this protocol
|
2009-04-27 11:51:44 -05:00
|
|
|
|
|
|
|
public:
|
2010-04-18 11:20:35 -05:00
|
|
|
//! Properties of a field, can be OR'd
|
2009-12-28 02:31:28 -06:00
|
|
|
enum FieldFlag {
|
2010-04-18 11:20:35 -05:00
|
|
|
FieldIsNormal = 0x0, //!< field appears in frame content
|
|
|
|
FieldIsMeta = 0x1, //!< field does not appear in frame, is meta data
|
|
|
|
FieldIsCksum = 0x2 //!< field is a checksum, appears in frame content
|
2009-12-28 02:31:28 -06:00
|
|
|
};
|
2010-04-18 11:20:35 -05:00
|
|
|
Q_DECLARE_FLAGS(FieldFlags, FieldFlag); //!< \private abcd
|
2009-12-28 02:31:28 -06:00
|
|
|
|
2010-04-18 11:20:35 -05:00
|
|
|
//! Various attributes of a field
|
2009-12-28 02:31:28 -06:00
|
|
|
enum FieldAttrib {
|
2010-04-18 11:20:35 -05:00
|
|
|
FieldName, //!< name
|
|
|
|
FieldValue, //!< value in host byte order (user editable)
|
|
|
|
FieldTextValue, //!< value as text
|
|
|
|
FieldFrameValue, //!< frame encoded value in network byte order
|
|
|
|
FieldBitSize, //!< size in bits
|
2009-12-28 02:31:28 -06:00
|
|
|
};
|
|
|
|
|
2010-04-18 11:20:35 -05:00
|
|
|
//! Supported Protocol Id types
|
2009-12-28 02:31:28 -06:00
|
|
|
enum ProtocolIdType {
|
2010-04-18 11:20:35 -05:00
|
|
|
ProtocolIdNone, //!< Marker representing non-existent protocol id
|
|
|
|
ProtocolIdLlc, //!< LLC (802.2)
|
|
|
|
ProtocolIdEth, //!< Ethernet II
|
|
|
|
ProtocolIdIp, //!< IP
|
2009-12-28 02:31:28 -06:00
|
|
|
};
|
|
|
|
|
2010-04-18 11:20:35 -05:00
|
|
|
//! Supported checksum types
|
2009-12-28 02:31:28 -06:00
|
|
|
enum CksumType {
|
2010-04-18 11:20:35 -05:00
|
|
|
CksumIp, //!< Standard IP Checksum
|
|
|
|
CksumIpPseudo, //!< Standard checksum for Pseudo-IP header
|
|
|
|
CksumTcpUdp, //!< Standard TCP/UDP checksum including pseudo-IP
|
2009-12-28 02:31:28 -06:00
|
|
|
|
2010-04-18 11:20:35 -05:00
|
|
|
CksumMax //!< Marker for number of cksum types
|
2009-12-28 02:31:28 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
AbstractProtocol(StreamBase *stream, AbstractProtocol *parent = 0);
|
|
|
|
virtual ~AbstractProtocol();
|
|
|
|
|
|
|
|
static AbstractProtocol* createInstance(StreamBase *stream,
|
|
|
|
AbstractProtocol *parent = 0);
|
|
|
|
virtual quint32 protocolNumber() const;
|
|
|
|
|
|
|
|
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const = 0;
|
|
|
|
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol) = 0;
|
|
|
|
|
|
|
|
virtual QString name() const;
|
|
|
|
virtual QString shortName() const;
|
|
|
|
|
|
|
|
virtual ProtocolIdType protocolIdType() const;
|
|
|
|
virtual quint32 protocolId(ProtocolIdType type) const;
|
|
|
|
quint32 payloadProtocolId(ProtocolIdType type) const;
|
|
|
|
|
|
|
|
virtual int fieldCount() const;
|
|
|
|
int metaFieldCount() const;
|
|
|
|
int frameFieldCount() const;
|
|
|
|
|
|
|
|
virtual FieldFlags fieldFlags(int index) const;
|
|
|
|
virtual QVariant fieldData(int index, FieldAttrib attrib,
|
|
|
|
int streamIndex = 0) const;
|
|
|
|
virtual bool setFieldData(int index, const QVariant &value,
|
|
|
|
FieldAttrib attrib = FieldValue);
|
|
|
|
|
|
|
|
QByteArray protocolFrameValue(int streamIndex = 0,
|
|
|
|
bool forCksum = false) const;
|
|
|
|
virtual int protocolFrameSize(int streamIndex = 0) const;
|
|
|
|
int protocolFrameOffset(int streamIndex = 0) const;
|
|
|
|
int protocolFramePayloadSize(int streamIndex = 0) const;
|
|
|
|
|
|
|
|
virtual bool isProtocolFrameValueVariable() const;
|
|
|
|
virtual bool isProtocolFrameSizeVariable() const;
|
|
|
|
bool isProtocolFramePayloadValueVariable() const;
|
|
|
|
bool isProtocolFramePayloadSizeVariable() const;
|
|
|
|
|
|
|
|
virtual quint32 protocolFrameCksum(int streamIndex = 0,
|
|
|
|
CksumType cksumType = CksumIp) const;
|
|
|
|
quint32 protocolFrameHeaderCksum(int streamIndex = 0,
|
|
|
|
CksumType cksumType = CksumIp) const;
|
|
|
|
quint32 protocolFramePayloadCksum(int streamIndex = 0,
|
|
|
|
CksumType cksumType = CksumIp) const;
|
|
|
|
|
|
|
|
virtual QWidget* configWidget() = 0;
|
|
|
|
virtual void loadConfigWidget() = 0;
|
|
|
|
virtual void storeConfigWidget() = 0;
|
2009-04-27 11:51:44 -05:00
|
|
|
};
|
2009-05-24 09:54:11 -05:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractProtocol::FieldFlags);
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
#endif
|