ostinato/common/abstractprotocol.h
Srivats P. 17792b8253 Refactoring, optimization et. al.
---------------------------------
	- StreamConfigDialog: Valid subsequent protocol choices for a particular protocol in the simple protocol selection widget is no longer hardcoded - ProtocolManager is queried for validitity of each pair of possible protocols; signal-slot connections are made accordingly. This refactoring makes it easier to add a protocol to the simple protocol selection widget
	- ProtocolManager: populates and maintains a database of valid 'neighbour protocols' and implements a method - isValidNeighbour() to query the same for a pair of protocols
	- AbstractProtocol: new method protocolIdType() introduced to build the above database (in conjunction with the existing method protocolId(ProtocolIdType)); default implementation returns ProtocolIdNone
	- Protocols which include a valid/supported ProtocolIdType (eth/llc/ip) reimplement protocolIdType() to return the apporpirate ProtocolIdType. These are viz.
		- combo
		- eth
		- llc
		- snap
		- ip
	- Speed optimization while populating streamqueues if the protocolFrameValue/Size() does not vary across packets
	- AbstractProtocol: new methods to support the above optimization
		- isProtocolFrameValueVariable()
		- isProtocolFrameSizeVariable()
		- isProtocolFramePayloadValueVariable()
		- isProtocolFramePayloadSizeVariable()
		(each of the default implementations returns false indicating that the protocol frame value or frame size is fixed and not variable)
	- Protocols which support variable values/size (list follows) reimplement the above methods appropriately
		- combo
		- mac
		- dot3
		- ip4
		- tcp
		- udp
		- payload
	- StreamInfo::makePacket() moved to base class as StreamBase::frameValue()
	- StreamBase: all 'get' accessor functions made 'const'
	- class ProtocolManager: while registering a protocol, no need to pass the protocol name; ProtocolManager finds it out internally by using the protocol's shortName() method



Fixes
-----
	- Fixed issue with port capture not starting the first time 'start capture' was clicked
2009-11-13 16:00:57 +00:00

125 lines
3.2 KiB
C++

#ifndef _ABSTRACT_PROTOCOL_H
#define _ABSTRACT_PROTOCOL_H
#include <QString>
#include <QVariant>
#include <QByteArray>
#include <QWidget>
#include <QLinkedList>
#include <QFlags>
//#include "../rpc/pbhelper.h"
#include "protocol.pb.h"
#define BASE_BIN (2)
#define BASE_OCT (8)
#define BASE_DEC (10)
#define BASE_HEX (16)
#define uintToHexStr(num, bytes) \
QString("%1").arg(num, bytes*2, BASE_HEX, QChar('0'))
class StreamBase;
class ProtocolListIterator;
class AbstractProtocol
{
template <int protoNumber, class ProtoA, class ProtoB>
friend class ComboProtocol;
friend class ProtocolListIterator;
private:
mutable int metaCount;
mutable int protoSize;
mutable QString protoAbbr;
protected:
StreamBase *mpStream;
AbstractProtocol *parent;
AbstractProtocol *prev;
AbstractProtocol *next;
public:
enum FieldFlag {
FieldIsNormal = 0x0,
FieldIsMeta = 0x1,
FieldIsCksum = 0x2
};
Q_DECLARE_FLAGS(FieldFlags, FieldFlag);
enum FieldAttrib {
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
};
enum ProtocolIdType {
ProtocolIdNone,
ProtocolIdLlc,
ProtocolIdEth,
ProtocolIdIp,
};
enum CksumType {
CksumIp,
CksumIpPseudo,
CksumTcpUdp,
CksumMax
};
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;
virtual 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;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractProtocol::FieldFlags);
#endif