ostinato/common/comboprotocol.h

211 lines
5.9 KiB
C
Raw Normal View History

/*
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 _COMBO_PROTOCOL_H
#define _COMBO_PROTOCOL_H
#include "abstractprotocol.h"
Protocol Framework related -------------------------- - AbstractProtocol Constructor and Factory function now take an optional (default NULL) "parent" abstract protocol in addition to the stream; this "parent" protocol is non-NULL for protocols which are aggregated in a ComboProtocol - All subclasses of AbstractProtocol modified as per the above interface change - ProtocolManager also modifed as per the above interface change - new data members in AbstractProtocol - prev, next; the AbstractProtocol implementation now uses these members to traverse protocols on the list instead of ProtocolListIterator; this change required for ComboProtocol - ProtocolListIterator updates these new members - prev/next on insert/remove/replace - ComboProtocol and ProtocolListIterator classes made friends of AbstractProtocol - ComboProtocol implemented as a template class (completed) - Dot2LLc implemented as a combo of Dot3Raw and LLC - Dot2Snap implemented as a combo of Dot2Llc and SNAP - VlanStack implemented as a combo of VLAN + VLAN - ProtocolManager now uses the ProtocolId enums rather than hardcoded values Stream Config Dialog -------------------- - "None" radio button added to all protocol levels - Protocol Level 1 added with 'mac' as the only valid protocol in the "simple" mode widget - With Dot2Llc, Dot2Snap and VlanStack implemented as "combo" protocols, the protocol choice radiobuttons in the "simple" mode are now 1:1 with a protocol; this has the following implications/advantages: - Updates of the "simple" mode widget from/to stream's protocolList is simpler; this code has now been rewritten to take advantage of 1:1 - This paves the way for exporting tunneled protocols 4over4, 4over6, 6over4 etc. in the "simple" mode - This should also (hopefully) require less changes when adding a new protocol; more work needs to be done to reach this goal Fixes ----- - Dot3Protocol now derives "length" correctly for VLAN tagged packets - StreamBase now uses the ProtocolListIterator to append the default protocols in a stream instead of directly manipulating ProtocolList; also in protoDataCopyFrom() Others (Client/Server) ---------------------- - Port Packet Capture implemented; "view capture" is pending (hack put in place now for testing)
2009-10-14 10:16:56 -05:00
template <int protoNumber, class ProtoA, class ProtoB>
class ComboProtocol : public AbstractProtocol
{
private:
ProtoA *protoA;
ProtoB *protoB;
QWidget *configForm;
public:
ComboProtocol(StreamBase *stream, AbstractProtocol *parent = 0)
: AbstractProtocol(stream, parent)
{
protoA = new ProtoA(stream, this);
protoB = new ProtoB(stream, this);
protoA->next = protoB;
protoB->prev = protoA;
configForm = NULL;
qDebug("%s: protoNumber = %d, %p <--> %p", __FUNCTION__,
protoNumber, protoA, protoB);
}
virtual ~ComboProtocol()
{
if (configForm)
{
protoA->configWidget()->setParent(0);
protoB->configWidget()->setParent(0);
delete configForm;
}
delete protoA;
delete protoB;
}
static ComboProtocol* createInstance(StreamBase *stream,
AbstractProtocol *parent)
{
return new ComboProtocol<protoNumber, ProtoA, ProtoB>(stream, parent);
}
virtual quint32 protocolNumber() const
{
return protoNumber;
}
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const
{
protoA->protoDataCopyInto(protocol);
protoB->protoDataCopyInto(protocol);
protocol.mutable_protocol_id()->set_id(protocolNumber());
}
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol)
{
if (protocol.protocol_id().id() == protocolNumber())
{
OstProto::Protocol proto;
// NOTE: To use protoX->protoDataCopyFrom() we need to arrange
// so that it sees its own protocolNumber() - but since the
// input param 'protocol' is 'const', we make a copy first
proto.CopyFrom(protocol);
proto.mutable_protocol_id()->set_id(protoA->protocolNumber());
protoA->protoDataCopyFrom(proto);
proto.mutable_protocol_id()->set_id(protoB->protocolNumber());
protoB->protoDataCopyFrom(proto);
}
}
virtual QString name() const
{
return protoA->name() + "/" + protoB->name();
}
virtual QString shortName() const
{
return protoA->shortName() + "/" + protoB->shortName();
}
virtual ProtocolIdType protocolIdType() const
{
return protoB->protocolIdType();
}
virtual quint32 protocolId(ProtocolIdType type) const
{
return protoA->protocolId(type);
}
//quint32 payloadProtocolId(ProtocolIdType type) const;
virtual int fieldCount() const
{
return protoA->fieldCount() + protoB->fieldCount();
}
//virtual int metaFieldCount() const;
//int frameFieldCount() const;
virtual FieldFlags fieldFlags(int index) const
{
int cnt = protoA->fieldCount();
if (index < cnt)
return protoA->fieldFlags(index);
else
return protoB->fieldFlags(index - cnt);
}
virtual QVariant fieldData(int index, FieldAttrib attrib,
int streamIndex = 0) const
{
int cnt = protoA->fieldCount();
if (index < cnt)
return protoA->fieldData(index, attrib, streamIndex);
else
return protoB->fieldData(index - cnt, attrib, streamIndex);
}
virtual bool setFieldData(int index, const QVariant &value,
FieldAttrib attrib = FieldValue)
{
int cnt = protoA->fieldCount();
if (index < cnt)
return protoA->setFieldData(index, value, attrib);
else
return protoB->setFieldData(index - cnt, value, attrib);
}
#if 0
QByteArray protocolFrameValue(int streamIndex = 0,
bool forCksum = false) const;
virtual int protocolFrameSize() const;
int protocolFrameOffset() const;
int protocolFramePayloadSize() const;
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 10:00:57 -06:00
#endif
virtual bool isProtocolFrameValueVariable() const
{
return (protoA->isProtocolFrameValueVariable()
|| protoB->isProtocolFrameValueVariable());
}
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 10:00:57 -06:00
virtual bool isProtocolFrameSizeVariable() const
{
return (protoA->isProtocolFrameSizeVariable()
|| protoB->isProtocolFrameSizeVariable());
}
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 10:00:57 -06:00
#if 0
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;
#endif
virtual QWidget* configWidget()
{
if (configForm == NULL)
{
QVBoxLayout *layout = new QVBoxLayout;
configForm = new QWidget;
layout->addWidget(protoA->configWidget());
layout->addWidget(protoB->configWidget());
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
configForm->setLayout(layout);
}
return configForm;
}
virtual void loadConfigWidget()
{
protoA->loadConfigWidget();
protoB->loadConfigWidget();
}
virtual void storeConfigWidget()
{
protoA->storeConfigWidget();
protoB->storeConfigWidget();
}
};
#endif