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
This commit is contained in:
parent
ade8c119d9
commit
17792b8253
@ -43,60 +43,60 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
|
||||
|
||||
// Time to play match the signals and slots!
|
||||
|
||||
// If L1/FT = None, force subsequent protocol level(s) also to None
|
||||
connect(rbL1None, SIGNAL(toggled(bool)), this, SLOT(forceProtocolNone(bool)));
|
||||
connect(rbFtNone, SIGNAL(toggled(bool)), this, SLOT(forceProtocolNone(bool)));
|
||||
// If L1/L2(FT)/L3 = None, force subsequent protocol level(s) also to None
|
||||
connect(rbL1None, SIGNAL(toggled(bool)), SLOT(forceProtocolNone(bool)));
|
||||
connect(rbFtNone, SIGNAL(toggled(bool)), SLOT(forceProtocolNone(bool)));
|
||||
connect(rbL3None, SIGNAL(toggled(bool)), SLOT(forceProtocolNone(bool)));
|
||||
|
||||
// Enable/Disable L3 Protocol Choices for FT Ethernet2
|
||||
connect(rbFtEthernet2, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setEnabled(bool)));
|
||||
connect(rbFtEthernet2, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setEnabled(bool)));
|
||||
|
||||
// Force L3 = None if FT = 802.3 Raw
|
||||
connect(rbFt802Dot3Raw, SIGNAL(clicked(bool)), rbL3None, SLOT(click()));
|
||||
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setDisabled(bool)));
|
||||
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setDisabled(bool)));
|
||||
|
||||
// Force L3 = None if FT = 802.3 LLC (to ensure a valid L3 is selected)
|
||||
connect(rbFt802Dot3Llc, SIGNAL(clicked(bool)), rbL3None, SLOT(click()));
|
||||
|
||||
// Enable/Disable L3 Protocol Choices for FT 802Dot3Llc
|
||||
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setEnabled(bool)));
|
||||
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setDisabled(bool)));
|
||||
|
||||
// Enable/Disable L3 Protocol Choices for FT 802.3 LLC SNAP
|
||||
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setEnabled(bool)));
|
||||
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setEnabled(bool)));
|
||||
|
||||
// Force L3 = Other if FT = Other
|
||||
// If L1/L2(FT)/L3/L4 = Other, force subsequent protocol to Other and
|
||||
// disable the subsequent protocol group as well
|
||||
connect(rbL1Other, SIGNAL(toggled(bool)), rbFtOther, SLOT(setChecked(bool)));
|
||||
connect(rbL1Other, SIGNAL(toggled(bool)), gbFrameType, SLOT(setDisabled(bool)));
|
||||
connect(rbFtOther, SIGNAL(toggled(bool)), rbL3Other, SLOT(setChecked(bool)));
|
||||
connect(rbFtOther, SIGNAL(toggled(bool)), gbL3Proto, SLOT(setDisabled(bool)));
|
||||
|
||||
// If L3 = None, force subsequent protocol level also to None
|
||||
connect(rbL3None, SIGNAL(toggled(bool)), this, SLOT(forceProtocolNone(bool)));
|
||||
|
||||
// Enable/Disable L4 Protocol Choices for L3 Protocol IPv4
|
||||
connect(rbL3Ipv4, SIGNAL(toggled(bool)), rbL4Icmp, SLOT(setEnabled(bool)));
|
||||
connect(rbL3Ipv4, SIGNAL(toggled(bool)), rbL4Igmp, SLOT(setEnabled(bool)));
|
||||
connect(rbL3Ipv4, SIGNAL(toggled(bool)), rbL4Tcp, SLOT(setEnabled(bool)));
|
||||
connect(rbL3Ipv4, SIGNAL(toggled(bool)), rbL4Udp, SLOT(setEnabled(bool)));
|
||||
|
||||
// Enable/Disable L4 Protocol Choices for L3 Protocol ARP
|
||||
connect(rbL3Arp, SIGNAL(toggled(bool)), rbL4Icmp, SLOT(setDisabled(bool)));
|
||||
connect(rbL3Arp, SIGNAL(toggled(bool)), rbL4Igmp, SLOT(setDisabled(bool)));
|
||||
connect(rbL3Arp, SIGNAL(toggled(bool)), rbL4Tcp, SLOT(setDisabled(bool)));
|
||||
connect(rbL3Arp, SIGNAL(toggled(bool)), rbL4Udp, SLOT(setDisabled(bool)));
|
||||
|
||||
// Force L4 Protocol = None if L3 Protocol is set to ARP
|
||||
connect(rbL3Arp, SIGNAL(clicked(bool)), rbL4None, SLOT(click()));
|
||||
|
||||
// Force L4 = Other if L3 = Other
|
||||
connect(rbL3Other, SIGNAL(toggled(bool)), rbL4Other, SLOT(setChecked(bool)));
|
||||
connect(rbL3Other, SIGNAL(toggled(bool)), gbL4Proto, SLOT(setDisabled(bool)));
|
||||
|
||||
// Force Payload = Other if L4 = Other
|
||||
connect(rbL4Other, SIGNAL(toggled(bool)), rbPayloadOther, SLOT(setChecked(bool)));
|
||||
connect(rbL4Other, SIGNAL(toggled(bool)), gbPayloadProto, SLOT(setDisabled(bool)));
|
||||
|
||||
// Setup valid subsequent protocols for L2 and L3 protocols
|
||||
for (int i = ProtoL2; i <= ProtoL3; i++)
|
||||
{
|
||||
foreach(QAbstractButton *btn1, bgProto[i]->buttons())
|
||||
{
|
||||
int id1 = bgProto[i]->id(btn1);
|
||||
|
||||
if (id1 != ButtonIdNone && id1 != ButtonIdOther)
|
||||
{
|
||||
int validProtocolCount = 0;
|
||||
|
||||
foreach(QAbstractButton *btn2, bgProto[i+1]->buttons())
|
||||
{
|
||||
int id2 = bgProto[i+1]->id(btn2);
|
||||
|
||||
if (id2 != ButtonIdNone && id2 != ButtonIdOther)
|
||||
{
|
||||
if (OstProtocolManager.isValidNeighbour(id1, id2))
|
||||
{
|
||||
connect(btn1, SIGNAL(toggled(bool)),
|
||||
btn2, SLOT(setEnabled(bool)));
|
||||
validProtocolCount++;
|
||||
}
|
||||
else
|
||||
connect(btn1, SIGNAL(toggled(bool)),
|
||||
btn2, SLOT(setDisabled(bool)));
|
||||
}
|
||||
}
|
||||
|
||||
// If btn1 has no subsequent valid protocols,
|
||||
// force subsequent Protocol to 'None'
|
||||
if (validProtocolCount == 0)
|
||||
connect(btn1, SIGNAL(clicked(bool)),
|
||||
bgProto[i+1]->button(ButtonIdNone), SLOT(click()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mpAvailableProtocolsModel = new QStringListModel(
|
||||
OstProtocolManager.protocolDatabase(), this);
|
||||
lvAllProtocols->setModel(mpAvailableProtocolsModel);
|
||||
@ -729,9 +729,17 @@ void StreamConfigDialog::updateSelectProtocolsSimpleWidget()
|
||||
id = _iter->next()->protocolNumber();
|
||||
btn = bgProto[i]->button(id);
|
||||
|
||||
if (btn && btn->isEnabled())
|
||||
if (btn)
|
||||
{
|
||||
if (btn->isEnabled())
|
||||
btn->click();
|
||||
else
|
||||
{
|
||||
btn->setChecked(true);
|
||||
__updateProtocol(i, id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ AbstractProtocol* AbstractProtocol::createInstance(StreamBase *stream,
|
||||
|
||||
quint32 AbstractProtocol::protocolNumber() const
|
||||
{
|
||||
qDebug("Something wrong!!!");
|
||||
qFatal("Something wrong!!!");
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
@ -193,6 +193,11 @@ bool AbstractProtocol::setFieldData(int index, const QVariant &value,
|
||||
return false;
|
||||
}
|
||||
|
||||
AbstractProtocol::ProtocolIdType AbstractProtocol::protocolIdType() const
|
||||
{
|
||||
return ProtocolIdNone;
|
||||
}
|
||||
|
||||
quint32 AbstractProtocol::protocolId(ProtocolIdType type) const
|
||||
{
|
||||
return 0;
|
||||
@ -360,6 +365,49 @@ QByteArray AbstractProtocol::protocolFrameValue(int streamIndex, bool forCksum)
|
||||
return proto;
|
||||
}
|
||||
|
||||
bool AbstractProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AbstractProtocol::isProtocolFrameSizeVariable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AbstractProtocol::isProtocolFramePayloadValueVariable() const
|
||||
{
|
||||
AbstractProtocol *p = next;
|
||||
|
||||
while (p)
|
||||
{
|
||||
if (p->isProtocolFrameValueVariable())
|
||||
return true;
|
||||
p = p->next;
|
||||
}
|
||||
if (parent && parent->isProtocolFramePayloadValueVariable())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AbstractProtocol::isProtocolFramePayloadSizeVariable() const
|
||||
{
|
||||
AbstractProtocol *p = next;
|
||||
|
||||
while (p)
|
||||
{
|
||||
if (p->isProtocolFrameSizeVariable())
|
||||
return true;
|
||||
p = p->next;
|
||||
}
|
||||
if (parent && parent->isProtocolFramePayloadSizeVariable())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\note If a subclass uses protocolFrameCksum() from within fieldData() to
|
||||
derive a cksum field, it MUST handle and return the 'FieldBitSize'
|
||||
|
@ -56,6 +56,7 @@ public:
|
||||
};
|
||||
|
||||
enum ProtocolIdType {
|
||||
ProtocolIdNone,
|
||||
ProtocolIdLlc,
|
||||
ProtocolIdEth,
|
||||
ProtocolIdIp,
|
||||
@ -82,6 +83,7 @@ public:
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
||||
virtual ProtocolIdType protocolIdType() const;
|
||||
virtual quint32 protocolId(ProtocolIdType type) const;
|
||||
quint32 payloadProtocolId(ProtocolIdType type) const;
|
||||
|
||||
@ -101,6 +103,11 @@ public:
|
||||
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,
|
||||
|
@ -84,6 +84,11 @@ public:
|
||||
return protoA->shortName() + "/" + protoB->shortName();
|
||||
}
|
||||
|
||||
virtual ProtocolIdType protocolIdType() const
|
||||
{
|
||||
return protoB->protocolIdType();
|
||||
}
|
||||
|
||||
virtual quint32 protocolId(ProtocolIdType type) const
|
||||
{
|
||||
return protoA->protocolId(type);
|
||||
@ -133,7 +138,21 @@ public:
|
||||
virtual int protocolFrameSize() const;
|
||||
int protocolFrameOffset() const;
|
||||
int protocolFramePayloadSize() const;
|
||||
#endif
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const
|
||||
{
|
||||
return (protoA->isProtocolFrameValueVariable()
|
||||
|| protoB->isProtocolFrameValueVariable());
|
||||
}
|
||||
|
||||
virtual bool isProtocolFrameSizeVariable() const
|
||||
{
|
||||
return (protoA->isProtocolFrameSizeVariable()
|
||||
|| protoB->isProtocolFrameSizeVariable());
|
||||
}
|
||||
|
||||
#if 0
|
||||
virtual quint32 protocolFrameCksum(int streamIndex = 0,
|
||||
CksumType cksumType = CksumIp) const;
|
||||
quint32 protocolFrameHeaderCksum(int streamIndex = 0,
|
||||
|
@ -119,6 +119,10 @@ bool Dot3Protocol::setFieldData(int index, const QVariant &value,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Dot3Protocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
return isProtocolFramePayloadSizeVariable();
|
||||
}
|
||||
|
||||
QWidget* Dot3Protocol::configWidget()
|
||||
{
|
||||
|
@ -46,6 +46,8 @@ public:
|
||||
virtual bool setFieldData(int index, const QVariant &value,
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
virtual void storeConfigWidget();
|
||||
|
@ -54,6 +54,11 @@ QString Eth2Protocol::shortName() const
|
||||
return QString("Eth II");
|
||||
}
|
||||
|
||||
AbstractProtocol::ProtocolIdType Eth2Protocol::protocolIdType() const
|
||||
{
|
||||
return ProtocolIdEth;
|
||||
}
|
||||
|
||||
int Eth2Protocol::fieldCount() const
|
||||
{
|
||||
return eth2_fieldCount;
|
||||
|
@ -39,6 +39,8 @@ public:
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
||||
virtual ProtocolIdType protocolIdType() const;
|
||||
|
||||
virtual int fieldCount() const;
|
||||
|
||||
virtual QVariant fieldData(int index, FieldAttrib attrib,
|
||||
|
@ -94,6 +94,11 @@ QString Ip4Protocol::shortName() const
|
||||
return QString("IPv4");
|
||||
}
|
||||
|
||||
AbstractProtocol::ProtocolIdType Ip4Protocol::protocolIdType() const
|
||||
{
|
||||
return ProtocolIdIp;
|
||||
}
|
||||
|
||||
quint32 Ip4Protocol::protocolId(ProtocolIdType type) const
|
||||
{
|
||||
switch(type)
|
||||
@ -572,6 +577,15 @@ bool Ip4Protocol::setFieldData(int index, const QVariant &value,
|
||||
return isOk;
|
||||
}
|
||||
|
||||
bool Ip4Protocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
if ((data.src_ip_mode() != OstProto::Ip4::e_im_fixed)
|
||||
|| (data.dst_ip_mode() != OstProto::Ip4::e_im_fixed))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
quint32 Ip4Protocol::protocolFrameCksum(int streamIndex,
|
||||
CksumType cksumType) const
|
||||
{
|
||||
|
@ -71,6 +71,7 @@ public:
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
virtual ProtocolIdType protocolIdType() const;
|
||||
virtual quint32 protocolId(ProtocolIdType type) const;
|
||||
virtual int fieldCount() const;
|
||||
|
||||
@ -82,6 +83,8 @@ public:
|
||||
virtual quint32 protocolFrameCksum(int streamIndex = 0,
|
||||
CksumType cksumType = CksumIp) const;
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
virtual void storeConfigWidget();
|
||||
|
@ -54,6 +54,11 @@ QString LlcProtocol::shortName() const
|
||||
return QString("LLC");
|
||||
}
|
||||
|
||||
AbstractProtocol::ProtocolIdType LlcProtocol::protocolIdType() const
|
||||
{
|
||||
return ProtocolIdLlc;
|
||||
}
|
||||
|
||||
int LlcProtocol::fieldCount() const
|
||||
{
|
||||
return llc_fieldCount;
|
||||
|
@ -44,6 +44,8 @@ public:
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
||||
virtual ProtocolIdType protocolIdType() const;
|
||||
|
||||
virtual int fieldCount() const;
|
||||
|
||||
virtual QVariant fieldData(int index, FieldAttrib attrib,
|
||||
|
@ -239,6 +239,15 @@ bool MacProtocol::setFieldData(int index, const QVariant &value,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MacProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
if ((data.dst_mac_mode() != OstProto::Mac::e_mm_fixed) ||
|
||||
(data.src_mac_mode() != OstProto::Mac::e_mm_fixed))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
QWidget* MacProtocol::configWidget()
|
||||
{
|
||||
|
@ -61,6 +61,8 @@ public:
|
||||
virtual bool setFieldData(int index, const QVariant &value,
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
virtual void storeConfigWidget();
|
||||
|
@ -187,6 +187,23 @@ bool PayloadProtocol::setFieldData(int index, const QVariant &value,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PayloadProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
if (isProtocolFrameSizeVariable()
|
||||
|| data.pattern_mode() == OstProto::Payload::e_dp_random)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PayloadProtocol::isProtocolFrameSizeVariable() const
|
||||
{
|
||||
if (mpStream->lenMode() == StreamBase::e_fl_fixed)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QWidget* PayloadProtocol::configWidget()
|
||||
{
|
||||
|
@ -54,6 +54,9 @@ public:
|
||||
virtual bool setFieldData(int index, const QVariant &value,
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual bool isProtocolFrameSizeVariable() const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
virtual void storeConfigWidget();
|
||||
|
@ -24,42 +24,69 @@ ProtocolManager::ProtocolManager()
|
||||
themselves (once this is done remove the #includes for all the protocols)
|
||||
*/
|
||||
registerProtocol(OstProto::Protocol::kMacFieldNumber,
|
||||
QString("mac"), (void*) MacProtocol::createInstance);
|
||||
(void*) MacProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kPayloadFieldNumber,
|
||||
QString("payload"), (void*) PayloadProtocol::createInstance);
|
||||
(void*) PayloadProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kEth2FieldNumber,
|
||||
QString("eth2"), (void*) Eth2Protocol::createInstance);
|
||||
(void*) Eth2Protocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kDot3FieldNumber,
|
||||
QString("dot3"), (void*) Dot3Protocol::createInstance);
|
||||
(void*) Dot3Protocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kLlcFieldNumber,
|
||||
QString("llc"), (void*) LlcProtocol::createInstance);
|
||||
(void*) LlcProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kSnapFieldNumber,
|
||||
QString("snap"), (void*) SnapProtocol::createInstance);
|
||||
(void*) SnapProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kDot2LlcFieldNumber,
|
||||
QString("dot2Llc"), (void*) Dot2LlcProtocol::createInstance);
|
||||
(void*) Dot2LlcProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kDot2SnapFieldNumber,
|
||||
QString("dot2Snap"), (void*) Dot2SnapProtocol::createInstance);
|
||||
(void*) Dot2SnapProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kSvlanFieldNumber,
|
||||
QString("svlan"), (void*) VlanProtocol::createInstance);
|
||||
(void*) SVlanProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kVlanFieldNumber,
|
||||
QString("vlan"), (void*) VlanProtocol::createInstance);
|
||||
(void*) VlanProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kVlanStackFieldNumber,
|
||||
QString("vlanstack"), (void*) VlanStackProtocol::createInstance);
|
||||
(void*) VlanStackProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kIp4FieldNumber,
|
||||
QString("ip4"), (void*) Ip4Protocol::createInstance);
|
||||
(void*) Ip4Protocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kTcpFieldNumber,
|
||||
QString("tcp"), (void*) TcpProtocol::createInstance);
|
||||
(void*) TcpProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kUdpFieldNumber,
|
||||
QString("udp"), (void*) UdpProtocol::createInstance);
|
||||
(void*) UdpProtocol::createInstance);
|
||||
|
||||
populateNeighbourProtocols();
|
||||
}
|
||||
|
||||
void ProtocolManager::registerProtocol(int protoNumber, QString protoName,
|
||||
void ProtocolManager::registerProtocol(int protoNumber,
|
||||
void *protoInstanceCreator)
|
||||
{
|
||||
AbstractProtocol *p;
|
||||
|
||||
//! \todo (MED) validate incoming params for duplicates with existing
|
||||
nameToNumberMap.insert(protoName, protoNumber);
|
||||
numberToNameMap.insert(protoNumber, protoName);
|
||||
|
||||
factory.insert(protoNumber, protoInstanceCreator);
|
||||
|
||||
p = createProtocol(protoNumber, NULL);
|
||||
protocolList.append(p);
|
||||
|
||||
numberToNameMap.insert(protoNumber, p->shortName());
|
||||
nameToNumberMap.insert(p->shortName(), protoNumber);
|
||||
}
|
||||
|
||||
void ProtocolManager::populateNeighbourProtocols()
|
||||
{
|
||||
neighbourProtocols.clear();
|
||||
|
||||
foreach(AbstractProtocol *p, protocolList)
|
||||
{
|
||||
if (p->protocolIdType() != AbstractProtocol::ProtocolIdNone)
|
||||
{
|
||||
foreach(AbstractProtocol *q, protocolList)
|
||||
{
|
||||
if (q->protocolId(p->protocolIdType()))
|
||||
neighbourProtocols.insert(
|
||||
p->protocolNumber(), q->protocolNumber());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AbstractProtocol* ProtocolManager::createProtocol(int protoNumber,
|
||||
@ -84,6 +111,14 @@ AbstractProtocol* ProtocolManager::createProtocol(QString protoName,
|
||||
return createProtocol(nameToNumberMap.value(protoName), stream, parent);
|
||||
}
|
||||
|
||||
bool ProtocolManager::isValidNeighbour(int protoPrefix, int protoSuffix)
|
||||
{
|
||||
if (neighbourProtocols.contains(protoPrefix, protoSuffix))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList ProtocolManager::protocolDatabase()
|
||||
{
|
||||
return numberToNameMap.values();
|
||||
|
@ -11,19 +11,24 @@ class ProtocolManager
|
||||
{
|
||||
QMap<int, QString> numberToNameMap;
|
||||
QMap<QString, int> nameToNumberMap;
|
||||
QMultiMap<int, int> neighbourProtocols;
|
||||
QMap<int, void*> factory;
|
||||
QList<AbstractProtocol*> protocolList;
|
||||
|
||||
void populateNeighbourProtocols();
|
||||
|
||||
public:
|
||||
ProtocolManager();
|
||||
|
||||
void registerProtocol(int protoNumber, QString protoName,
|
||||
void *protoCreator);
|
||||
void registerProtocol(int protoNumber, void *protoInstanceCreator);
|
||||
|
||||
AbstractProtocol* createProtocol(int protoNumber, StreamBase *stream,
|
||||
AbstractProtocol *parent = 0);
|
||||
AbstractProtocol* createProtocol(QString protoName, StreamBase *stream,
|
||||
AbstractProtocol *parent = 0);
|
||||
|
||||
bool isValidNeighbour(int protoPrefix, int protoSuffix);
|
||||
|
||||
QStringList protocolDatabase();
|
||||
};
|
||||
|
||||
|
@ -54,6 +54,11 @@ QString SnapProtocol::shortName() const
|
||||
return QString("SNAP");
|
||||
}
|
||||
|
||||
AbstractProtocol::ProtocolIdType SnapProtocol::protocolIdType() const
|
||||
{
|
||||
return ProtocolIdEth;
|
||||
}
|
||||
|
||||
quint32 SnapProtocol::protocolId(ProtocolIdType type) const
|
||||
{
|
||||
switch(type)
|
||||
|
@ -39,6 +39,8 @@ public:
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
||||
virtual ProtocolIdType protocolIdType() const;
|
||||
virtual quint32 protocolId(ProtocolIdType type) const;
|
||||
|
||||
virtual int fieldCount() const;
|
||||
|
@ -20,11 +20,13 @@ StreamBase::StreamBase() :
|
||||
|
||||
iter = createProtocolListIterator();
|
||||
// By default newly created streams have the mac and payload protocols
|
||||
proto = OstProtocolManager.createProtocol("mac", this);
|
||||
proto = OstProtocolManager.createProtocol(
|
||||
OstProto::Protocol::kMacFieldNumber, this);
|
||||
iter->insert(proto);
|
||||
qDebug("stream: mac = %p", proto);
|
||||
|
||||
proto = OstProtocolManager.createProtocol("payload", this);
|
||||
proto = OstProtocolManager.createProtocol(
|
||||
OstProto::Protocol::kPayloadFieldNumber, this);
|
||||
iter->insert(proto);
|
||||
qDebug("stream: payload = %p", proto);
|
||||
|
||||
@ -104,7 +106,7 @@ void StreamBase::setFrameProtocol(ProtocolList protocolList)
|
||||
}
|
||||
#endif
|
||||
|
||||
ProtocolListIterator* StreamBase::createProtocolListIterator()
|
||||
ProtocolListIterator* StreamBase::createProtocolListIterator() const
|
||||
{
|
||||
return new ProtocolListIterator(*currentFrameProtocols);
|
||||
}
|
||||
@ -158,7 +160,7 @@ bool StreamBase::setName(QString name)
|
||||
return true;
|
||||
}
|
||||
|
||||
StreamBase::FrameLengthMode StreamBase::lenMode()
|
||||
StreamBase::FrameLengthMode StreamBase::lenMode() const
|
||||
{
|
||||
return (StreamBase::FrameLengthMode) mCore->len_mode();
|
||||
}
|
||||
@ -169,7 +171,7 @@ bool StreamBase::setLenMode(FrameLengthMode lenMode)
|
||||
return true;
|
||||
}
|
||||
|
||||
quint16 StreamBase::frameLen(int streamIndex)
|
||||
quint16 StreamBase::frameLen(int streamIndex) const
|
||||
{
|
||||
int pktLen;
|
||||
|
||||
@ -211,7 +213,7 @@ bool StreamBase::setFrameLen(quint16 frameLen)
|
||||
return true;
|
||||
}
|
||||
|
||||
quint16 StreamBase::frameLenMin()
|
||||
quint16 StreamBase::frameLenMin() const
|
||||
{
|
||||
return mCore->frame_len_min();
|
||||
}
|
||||
@ -222,7 +224,7 @@ bool StreamBase::setFrameLenMin(quint16 frameLenMin)
|
||||
return true;
|
||||
}
|
||||
|
||||
quint16 StreamBase::frameLenMax()
|
||||
quint16 StreamBase::frameLenMax() const
|
||||
{
|
||||
return mCore->frame_len_max();
|
||||
}
|
||||
@ -233,17 +235,18 @@ bool StreamBase::setFrameLenMax(quint16 frameLenMax)
|
||||
return true;
|
||||
}
|
||||
|
||||
StreamBase::SendUnit StreamBase::sendUnit()
|
||||
StreamBase::SendUnit StreamBase::sendUnit() const
|
||||
{
|
||||
return (StreamBase::SendUnit) mControl->unit();
|
||||
}
|
||||
|
||||
bool StreamBase::setSendUnit(SendUnit sendUnit)
|
||||
{
|
||||
mControl->set_unit((OstProto::StreamControl::SendUnit) sendUnit);
|
||||
return true;
|
||||
}
|
||||
|
||||
StreamBase::SendMode StreamBase::sendMode()
|
||||
StreamBase::SendMode StreamBase::sendMode() const
|
||||
{
|
||||
return (StreamBase::SendMode) mControl->mode();
|
||||
}
|
||||
@ -255,7 +258,7 @@ bool StreamBase::setSendMode(SendMode sendMode)
|
||||
return true;
|
||||
}
|
||||
|
||||
StreamBase::NextWhat StreamBase::nextWhat()
|
||||
StreamBase::NextWhat StreamBase::nextWhat() const
|
||||
{
|
||||
return (StreamBase::NextWhat) mControl->next();
|
||||
}
|
||||
@ -266,7 +269,7 @@ bool StreamBase::setNextWhat(NextWhat nextWhat)
|
||||
return true;
|
||||
}
|
||||
|
||||
quint32 StreamBase::numPackets()
|
||||
quint32 StreamBase::numPackets() const
|
||||
{
|
||||
return (quint32) mControl->num_packets();
|
||||
}
|
||||
@ -277,7 +280,7 @@ bool StreamBase::setNumPackets(quint32 numPackets)
|
||||
return true;
|
||||
}
|
||||
|
||||
quint32 StreamBase::numBursts()
|
||||
quint32 StreamBase::numBursts() const
|
||||
{
|
||||
return (quint32) mControl->num_bursts();
|
||||
}
|
||||
@ -288,7 +291,7 @@ bool StreamBase::setNumBursts(quint32 numBursts)
|
||||
return true;
|
||||
}
|
||||
|
||||
quint32 StreamBase::burstSize()
|
||||
quint32 StreamBase::burstSize() const
|
||||
{
|
||||
return (quint32) mControl->packets_per_burst();
|
||||
}
|
||||
@ -299,7 +302,7 @@ bool StreamBase::setBurstSize(quint32 packetsPerBurst)
|
||||
return true;
|
||||
}
|
||||
|
||||
quint32 StreamBase::packetRate()
|
||||
quint32 StreamBase::packetRate() const
|
||||
{
|
||||
return (quint32) mControl->packets_per_sec();
|
||||
}
|
||||
@ -310,7 +313,7 @@ bool StreamBase::setPacketRate(quint32 packetsPerSec)
|
||||
return true;
|
||||
}
|
||||
|
||||
quint32 StreamBase::burstRate()
|
||||
quint32 StreamBase::burstRate() const
|
||||
{
|
||||
return (quint32) mControl->bursts_per_sec();
|
||||
}
|
||||
@ -320,3 +323,57 @@ bool StreamBase::setBurstRate(quint32 burstsPerSec)
|
||||
mControl->set_bursts_per_sec(burstsPerSec);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StreamBase::isFrameVariable() const
|
||||
{
|
||||
ProtocolListIterator *iter;
|
||||
|
||||
iter = createProtocolListIterator();
|
||||
while (iter->hasNext())
|
||||
{
|
||||
AbstractProtocol *proto;
|
||||
|
||||
proto = iter->next();
|
||||
if (proto->isProtocolFrameValueVariable())
|
||||
goto _exit;
|
||||
}
|
||||
delete iter;
|
||||
return false;
|
||||
|
||||
_exit:
|
||||
delete iter;
|
||||
return true;
|
||||
}
|
||||
|
||||
int StreamBase::frameValue(uchar *buf, int bufMaxSize, int n) const
|
||||
{
|
||||
int pktLen, len = 0;
|
||||
|
||||
pktLen = frameLen(n);
|
||||
|
||||
// pktLen is adjusted for CRC/FCS which will be added by the NIC
|
||||
pktLen -= 4;
|
||||
|
||||
if ((pktLen < 0) || (pktLen > bufMaxSize))
|
||||
return 0;
|
||||
|
||||
ProtocolListIterator *iter;
|
||||
|
||||
iter = createProtocolListIterator();
|
||||
while (iter->hasNext())
|
||||
{
|
||||
AbstractProtocol *proto;
|
||||
QByteArray ba;
|
||||
|
||||
proto = iter->next();
|
||||
ba = proto->protocolFrameValue(n);
|
||||
|
||||
if (len + ba.size() < bufMaxSize)
|
||||
memcpy(buf+len, ba.constData(), ba.size());
|
||||
len += ba.size();
|
||||
}
|
||||
delete iter;
|
||||
|
||||
return pktLen;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
void protoDataCopyFrom(const OstProto::Stream &stream);
|
||||
void protoDataCopyInto(OstProto::Stream &stream) const;
|
||||
|
||||
ProtocolListIterator* createProtocolListIterator();
|
||||
ProtocolListIterator* createProtocolListIterator() const;
|
||||
|
||||
//! \todo (LOW) should we have a copy constructor??
|
||||
|
||||
@ -76,41 +76,44 @@ public:
|
||||
bool setName(QString name) ;
|
||||
|
||||
// Frame Length (includes FCS);
|
||||
FrameLengthMode lenMode();
|
||||
FrameLengthMode lenMode() const;
|
||||
bool setLenMode(FrameLengthMode lenMode);
|
||||
|
||||
quint16 frameLen(int streamIndex = 0);
|
||||
quint16 frameLen(int streamIndex = 0) const;
|
||||
bool setFrameLen(quint16 frameLen);
|
||||
|
||||
quint16 frameLenMin();
|
||||
quint16 frameLenMin() const;
|
||||
bool setFrameLenMin(quint16 frameLenMin);
|
||||
|
||||
quint16 frameLenMax();
|
||||
quint16 frameLenMax() const;
|
||||
bool setFrameLenMax(quint16 frameLenMax);
|
||||
|
||||
SendUnit sendUnit();
|
||||
SendUnit sendUnit() const;
|
||||
bool setSendUnit(SendUnit sendUnit);
|
||||
|
||||
SendMode sendMode();
|
||||
SendMode sendMode() const;
|
||||
bool setSendMode(SendMode sendMode);
|
||||
|
||||
NextWhat nextWhat();
|
||||
NextWhat nextWhat() const;
|
||||
bool setNextWhat(NextWhat nextWhat);
|
||||
|
||||
quint32 numPackets();
|
||||
quint32 numPackets() const;
|
||||
bool setNumPackets(quint32 numPackets);
|
||||
|
||||
quint32 numBursts();
|
||||
quint32 numBursts() const;
|
||||
bool setNumBursts(quint32 numBursts);
|
||||
|
||||
quint32 burstSize();
|
||||
quint32 burstSize() const;
|
||||
bool setBurstSize(quint32 packetsPerBurst);
|
||||
|
||||
quint32 packetRate();
|
||||
quint32 packetRate() const;
|
||||
bool setPacketRate(quint32 packetsPerSec);
|
||||
|
||||
quint32 burstRate();
|
||||
quint32 burstRate() const;
|
||||
bool setBurstRate(quint32 burstsPerSec);
|
||||
|
||||
bool isFrameVariable() const;
|
||||
int frameValue(uchar *buf, int bufMaxSize, int n) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -380,6 +380,13 @@ bool TcpProtocol::setFieldData(int index, const QVariant &value,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TcpProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
if (data.is_override_cksum())
|
||||
return false;
|
||||
else
|
||||
return isProtocolFramePayloadValueVariable();
|
||||
}
|
||||
|
||||
QWidget* TcpProtocol::configWidget()
|
||||
{
|
||||
|
@ -67,6 +67,8 @@ public:
|
||||
virtual bool setFieldData(int index, const QVariant &value,
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
virtual void storeConfigWidget();
|
||||
|
@ -258,6 +258,13 @@ bool UdpProtocol::setFieldData(int index, const QVariant &value,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UdpProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
if (data.is_override_totlen() && data.is_override_cksum())
|
||||
return false;
|
||||
else
|
||||
return isProtocolFramePayloadValueVariable();
|
||||
}
|
||||
|
||||
QWidget* UdpProtocol::configWidget()
|
||||
{
|
||||
|
@ -54,6 +54,8 @@ public:
|
||||
virtual bool setFieldData(int index, const QVariant &value,
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
virtual void storeConfigWidget();
|
||||
|
@ -25,39 +25,6 @@ StreamInfo::~StreamInfo()
|
||||
{
|
||||
}
|
||||
|
||||
int StreamInfo::makePacket(uchar *buf, int bufMaxSize, int n)
|
||||
{
|
||||
int pktLen, len = 0;
|
||||
|
||||
pktLen = frameLen(n);
|
||||
|
||||
// pktLen is adjusted for CRC/FCS which will be added by the NIC
|
||||
pktLen -= 4;
|
||||
|
||||
if ((pktLen < 0) || (pktLen > bufMaxSize))
|
||||
return 0;
|
||||
|
||||
ProtocolListIterator *iter;
|
||||
|
||||
iter = createProtocolListIterator();
|
||||
while (iter->hasNext())
|
||||
{
|
||||
AbstractProtocol *proto;
|
||||
QByteArray ba;
|
||||
|
||||
proto = iter->next();
|
||||
ba = proto->protocolFrameValue(n);
|
||||
|
||||
if (len + ba.size() < bufMaxSize)
|
||||
memcpy(buf+len, ba.constData(), ba.size());
|
||||
len += ba.size();
|
||||
}
|
||||
delete iter;
|
||||
|
||||
return pktLen;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// ------------------ PortInfo --------------------
|
||||
//
|
||||
@ -195,6 +162,8 @@ void PortInfo::updateLinkState()
|
||||
|
||||
void PortInfo::update()
|
||||
{
|
||||
int len;
|
||||
bool isVariable;
|
||||
uchar pktBuf[2000];
|
||||
pcap_pkthdr pktHdr;
|
||||
ost_pcap_send_queue sendQ;
|
||||
@ -249,17 +218,25 @@ void PortInfo::update()
|
||||
numBursts, numPackets);
|
||||
qDebug("ibg = %ld, ipg = %ld\n", ibg, ipg);
|
||||
|
||||
if (streamList[i]->isFrameVariable())
|
||||
{
|
||||
isVariable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
isVariable = false;
|
||||
len = streamList[i]->frameValue(pktBuf, sizeof(pktBuf), 0);
|
||||
}
|
||||
|
||||
for (int j = 0; j < numBursts; j++)
|
||||
{
|
||||
for (int k = 0; k < numPackets; k++)
|
||||
{
|
||||
int len;
|
||||
|
||||
/*! \todo (HIGH) if pkt contents do not change across
|
||||
pkts then don't call makePacket(), rather reuse the
|
||||
previous */
|
||||
len = streamList[i]->makePacket(pktBuf, sizeof(pktBuf),
|
||||
if (isVariable)
|
||||
{
|
||||
len = streamList[i]->frameValue(pktBuf, sizeof(pktBuf),
|
||||
j * numPackets + k);
|
||||
}
|
||||
if (len > 0)
|
||||
{
|
||||
pktHdr.caplen = pktHdr.len = len;
|
||||
@ -784,7 +761,6 @@ void PortInfo::PortCapture::run()
|
||||
{
|
||||
if (!capFile.open())
|
||||
qFatal("Unable to open temp cap file");
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug("cap file = %s", capFile.fileName().toAscii().constData());
|
||||
|
@ -46,9 +46,6 @@ class StreamInfo : public StreamBase
|
||||
public:
|
||||
StreamInfo();
|
||||
~StreamInfo();
|
||||
|
||||
private:
|
||||
int makePacket(uchar *buf, int bufMaxSize, int n);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user