Feature (contd.): Variable Fields - removed protocol subclass implementations of isProtocolFrameValueVariable() since the updated implementation in the base abstract class is now sufficient. Updated subclass implementations of protocolFrameValueVariableCount() to query the base class and use the return value in its calculation
This commit is contained in:
parent
df24cf8b15
commit
7a1f791a37
@ -675,14 +675,9 @@ QByteArray AbstractProtocol::protocolFrameValue(int streamIndex, bool forCksum)
|
||||
/*!
|
||||
Returns true if the protocol varies one or more of its fields at run-time,
|
||||
false otherwise
|
||||
|
||||
The default implementation returns false. A subclass should reimplement
|
||||
if it has varying fields e.g. an IP protocol that increments/decrements
|
||||
the IP address with every packet
|
||||
*/
|
||||
bool AbstractProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
// TODO: change subclass to call base class function?
|
||||
return (protocolFrameVariableCount() > 1);
|
||||
}
|
||||
|
||||
@ -715,7 +710,6 @@ bool AbstractProtocol::isProtocolFrameSizeVariable() const
|
||||
*/
|
||||
int AbstractProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
// TODO: change subclass to call base class function?
|
||||
int count = 1;
|
||||
|
||||
for (int i = 0; i < _data.variable_fields_size(); i++)
|
||||
@ -734,6 +728,10 @@ int AbstractProtocol::protocolFrameVariableCount() const
|
||||
*/
|
||||
bool AbstractProtocol::isProtocolFramePayloadValueVariable() const
|
||||
{
|
||||
// TODO: it is simpler to do the following -
|
||||
// return (protocolFramePayloadVariableCount() > 1)
|
||||
// However, it may be inefficient till the time we cache the
|
||||
// variable count
|
||||
AbstractProtocol *p = next;
|
||||
|
||||
while (p)
|
||||
@ -1038,6 +1036,7 @@ void AbstractProtocol::varyProtocolFrameValue(QByteArray &buf, int frameIndex,
|
||||
{
|
||||
int x = frameIndex % varField.count();
|
||||
|
||||
// FIXME: use vf.step()!!!!
|
||||
// FIXME: use templates for duplicating code for quint8, quint16, quint32
|
||||
switch (varField.type()) {
|
||||
case OstProto::VariableField::kCounter8: {
|
||||
|
@ -774,24 +774,9 @@ _exit:
|
||||
return isOk;
|
||||
}
|
||||
|
||||
bool ArpProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
if (fieldData(arp_senderHwAddrMode, FieldValue).toUInt()
|
||||
!= uint(OstProto::Arp::kFixed)
|
||||
|| fieldData(arp_senderProtoAddrMode, FieldValue).toUInt()
|
||||
!= uint(OstProto::Arp::kFixed)
|
||||
|| fieldData(arp_targetHwAddrMode, FieldValue).toUInt()
|
||||
!= uint(OstProto::Arp::kFixed)
|
||||
|| fieldData(arp_targetProtoAddrMode, FieldValue).toUInt()
|
||||
!= uint(OstProto::Arp::kFixed))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int ArpProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
int count = 1;
|
||||
int count = AbstractProtocol::protocolFrameVariableCount();
|
||||
|
||||
if (fieldData(arp_senderHwAddrMode, FieldValue).toUInt()
|
||||
!= uint(OstProto::Arp::kFixed))
|
||||
|
@ -93,7 +93,6 @@ public:
|
||||
virtual bool setFieldData(int index, const QVariant &value,
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
private:
|
||||
|
@ -150,12 +150,6 @@ public:
|
||||
int protocolFramePayloadSize() const;
|
||||
#endif
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const
|
||||
{
|
||||
return (protoA->isProtocolFrameValueVariable()
|
||||
|| protoB->isProtocolFrameValueVariable());
|
||||
}
|
||||
|
||||
virtual bool isProtocolFrameSizeVariable() const
|
||||
{
|
||||
return (protoA->isProtocolFrameSizeVariable()
|
||||
@ -163,9 +157,14 @@ public:
|
||||
}
|
||||
virtual int protocolFrameVariableCount() const
|
||||
{
|
||||
return AbstractProtocol::lcm(
|
||||
protoA->protocolFrameVariableCount(),
|
||||
int count = AbstractProtocol::protocolFrameVariableCount();
|
||||
count = AbstractProtocol::lcm(
|
||||
count,
|
||||
protoA->protocolFrameVariableCount());
|
||||
count = AbstractProtocol::lcm(
|
||||
count,
|
||||
protoB->protocolFrameVariableCount());
|
||||
return count;
|
||||
}
|
||||
|
||||
virtual quint32 protocolFrameCksum(int streamIndex = 0,
|
||||
|
@ -185,12 +185,9 @@ bool Dot3Protocol::setFieldData(int index, const QVariant &value,
|
||||
return isOk;
|
||||
}
|
||||
|
||||
bool Dot3Protocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
return isProtocolFramePayloadSizeVariable();
|
||||
}
|
||||
|
||||
int Dot3Protocol::protocolFrameVariableCount() const
|
||||
{
|
||||
return protocolFramePayloadVariableCount();
|
||||
return AbstractProtocol::lcm(
|
||||
AbstractProtocol::protocolFrameVariableCount(),
|
||||
protocolFramePayloadVariableCount());
|
||||
}
|
||||
|
@ -57,7 +57,6 @@ public:
|
||||
virtual bool setFieldData(int index, const QVariant &value,
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
private:
|
||||
|
@ -735,23 +735,9 @@ int GmpProtocol::protocolFrameSize(int streamIndex) const
|
||||
return AbstractProtocol::protocolFrameValue(streamIndex, true).size();
|
||||
}
|
||||
|
||||
bool GmpProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
// No fields vary for Ssm Report
|
||||
if (isSsmReport())
|
||||
return false;
|
||||
|
||||
// For all other msg types, check the group mode
|
||||
if (fieldData(kGroupMode, FieldValue).toUInt()
|
||||
!= uint(OstProto::Gmp::kFixed))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int GmpProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
int count = 1;
|
||||
int count = AbstractProtocol::protocolFrameVariableCount();
|
||||
|
||||
// No fields vary for Ssm Report
|
||||
if (isSsmReport())
|
||||
|
@ -96,7 +96,6 @@ public:
|
||||
|
||||
virtual int protocolFrameSize(int streamIndex = 0) const;
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
protected:
|
||||
|
@ -756,18 +756,9 @@ _exit:
|
||||
return isOk;
|
||||
}
|
||||
|
||||
bool Ip6Protocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
if ((data.src_addr_mode() != OstProto::Ip6::kFixed)
|
||||
|| (data.dst_addr_mode() != OstProto::Ip6::kFixed))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
int Ip6Protocol::protocolFrameVariableCount() const
|
||||
{
|
||||
int count = 1;
|
||||
int count = AbstractProtocol::protocolFrameVariableCount();
|
||||
|
||||
if (data.src_addr_mode() != OstProto::Ip6::kFixed)
|
||||
count = AbstractProtocol::lcm(count, data.src_addr_count());
|
||||
|
@ -100,7 +100,6 @@ public:
|
||||
virtual bool setFieldData(int index, const QVariant &value,
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
virtual quint32 protocolFrameCksum(int streamIndex = 0,
|
||||
|
@ -327,18 +327,9 @@ _exit:
|
||||
return isOk;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int MacProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
int count = 1;
|
||||
int count = AbstractProtocol::protocolFrameVariableCount();
|
||||
|
||||
if (data.dst_mac_mode() != OstProto::Mac::e_mm_fixed)
|
||||
count = AbstractProtocol::lcm(count, data.dst_mac_count());
|
||||
|
@ -63,7 +63,6 @@ public:
|
||||
virtual bool setFieldData(int index, const QVariant &value,
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
private:
|
||||
|
@ -215,11 +215,8 @@ bool PayloadProtocol::setFieldData(int index, const QVariant &value,
|
||||
|
||||
bool PayloadProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
if (isProtocolFrameSizeVariable()
|
||||
|| data.pattern_mode() == OstProto::Payload::e_dp_random)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return (AbstractProtocol::isProtocolFrameSizeVariable()
|
||||
|| isProtocolFrameSizeVariable());
|
||||
}
|
||||
|
||||
bool PayloadProtocol::isProtocolFrameSizeVariable() const
|
||||
@ -232,7 +229,7 @@ bool PayloadProtocol::isProtocolFrameSizeVariable() const
|
||||
|
||||
int PayloadProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
int count = 1;
|
||||
int count = AbstractProtocol::protocolFrameVariableCount();
|
||||
|
||||
if (data.pattern_mode() == OstProto::Payload::e_dp_random)
|
||||
{
|
||||
|
@ -441,17 +441,6 @@ int SampleProtocol::protocolFrameSize(int streamIndex) const
|
||||
return AbstractProtocol::protocolFrameSize(streamIndex);
|
||||
}
|
||||
|
||||
/*!
|
||||
TODO: If your protocol has any variable fields, return true \n
|
||||
|
||||
Otherwise you don't need to reimplement this method - the base class always
|
||||
returns false
|
||||
*/
|
||||
bool SampleProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
TODO: If your protocol frame size can vary across pkts of the same stream,
|
||||
return true \n
|
||||
@ -468,10 +457,9 @@ bool SampleProtocol::isProtocolFrameSizeVariable() const
|
||||
TODO: If your protocol frame has any variable fields or has a variable
|
||||
size, return the minimum number of frames required to vary the fields \n
|
||||
|
||||
Otherwise you don't need to reimplement this method - the base class always
|
||||
returns 1
|
||||
See AbstractProtocol::protocolFrameVariableCount() for more info
|
||||
*/
|
||||
int SampleProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
return 1;
|
||||
return AbstractProtocol::protocolFrameVariableCount();
|
||||
}
|
||||
|
@ -78,7 +78,6 @@ public:
|
||||
|
||||
virtual int protocolFrameSize(int streamIndex = 0) const;
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual bool isProtocolFrameSizeVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
|
@ -588,19 +588,13 @@ _exit:
|
||||
return isOk;
|
||||
}
|
||||
|
||||
bool TcpProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
if (data.is_override_cksum())
|
||||
return false;
|
||||
else
|
||||
return isProtocolFramePayloadValueVariable();
|
||||
}
|
||||
|
||||
int TcpProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
if (data.is_override_cksum())
|
||||
return 1;
|
||||
int count = AbstractProtocol::protocolFrameVariableCount();
|
||||
|
||||
return protocolFramePayloadVariableCount();
|
||||
if (!data.is_override_cksum())
|
||||
count = AbstractProtocol::lcm(count,
|
||||
protocolFramePayloadVariableCount());
|
||||
return count;
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,6 @@ public:
|
||||
virtual bool setFieldData(int index, const QVariant &value,
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
private:
|
||||
|
@ -414,18 +414,16 @@ _exit:
|
||||
return isOk;
|
||||
}
|
||||
|
||||
bool UdpProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
if (data.is_override_totlen() && data.is_override_cksum())
|
||||
return false;
|
||||
else
|
||||
return isProtocolFramePayloadValueVariable();
|
||||
}
|
||||
|
||||
int UdpProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
if (data.is_override_totlen() && data.is_override_cksum())
|
||||
return 1;
|
||||
int count;
|
||||
|
||||
return protocolFramePayloadVariableCount();
|
||||
if (data.is_override_totlen() && data.is_override_cksum())
|
||||
count = AbstractProtocol::protocolFrameVariableCount();
|
||||
else
|
||||
count = AbstractProtocol::lcm(
|
||||
AbstractProtocol::protocolFrameVariableCount(),
|
||||
protocolFramePayloadVariableCount());
|
||||
|
||||
return count;
|
||||
}
|
||||
|
@ -65,7 +65,6 @@ public:
|
||||
virtual bool setFieldData(int index, const QVariant &value,
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
private:
|
||||
|
@ -212,11 +212,6 @@ int UserScriptProtocol::protocolFrameSize(int streamIndex) const
|
||||
return userValue.toInt32();
|
||||
}
|
||||
|
||||
bool UserScriptProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
return userProtocol_.isProtocolFrameValueVariable();
|
||||
}
|
||||
|
||||
bool UserScriptProtocol::isProtocolFrameSizeVariable() const
|
||||
{
|
||||
return userProtocol_.isProtocolFrameSizeVariable();
|
||||
@ -224,7 +219,9 @@ bool UserScriptProtocol::isProtocolFrameSizeVariable() const
|
||||
|
||||
int UserScriptProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
return userProtocol_.protocolFrameVariableCount();
|
||||
return AbstractProtocol::lcm(
|
||||
AbstractProtocol::protocolFrameVariableCount(),
|
||||
userProtocol_.protocolFrameVariableCount());
|
||||
}
|
||||
|
||||
quint32 UserScriptProtocol::protocolFrameCksum(int streamIndex,
|
||||
@ -460,7 +457,6 @@ UserProtocol::UserProtocol(AbstractProtocol *parent)
|
||||
void UserProtocol::reset()
|
||||
{
|
||||
name_ = QString();
|
||||
protocolFrameValueVariable_ = false;
|
||||
protocolFrameSizeVariable_ = false;
|
||||
protocolFrameVariableCount_ = 1;
|
||||
}
|
||||
@ -475,16 +471,6 @@ void UserProtocol::setName(QString &name)
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
bool UserProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
return protocolFrameValueVariable_;
|
||||
}
|
||||
|
||||
void UserProtocol::setProtocolFrameValueVariable(bool variable)
|
||||
{
|
||||
protocolFrameValueVariable_ = variable;
|
||||
}
|
||||
|
||||
bool UserProtocol::isProtocolFrameSizeVariable() const
|
||||
{
|
||||
return protocolFrameSizeVariable_;
|
||||
|
@ -35,9 +35,6 @@ class UserProtocol : public QObject
|
||||
Q_ENUMS(CksumType);
|
||||
|
||||
Q_PROPERTY(QString name READ name WRITE setName);
|
||||
Q_PROPERTY(bool protocolFrameValueVariable
|
||||
READ isProtocolFrameValueVariable
|
||||
WRITE setProtocolFrameValueVariable);
|
||||
Q_PROPERTY(bool protocolFrameSizeVariable
|
||||
READ isProtocolFrameSizeVariable
|
||||
WRITE setProtocolFrameSizeVariable);
|
||||
@ -69,8 +66,6 @@ public slots:
|
||||
QString name() const;
|
||||
void setName(QString &name);
|
||||
|
||||
bool isProtocolFrameValueVariable() const;
|
||||
void setProtocolFrameValueVariable(bool variable);
|
||||
bool isProtocolFrameSizeVariable() const;
|
||||
void setProtocolFrameSizeVariable(bool variable);
|
||||
int protocolFrameVariableCount() const;
|
||||
@ -93,7 +88,6 @@ private:
|
||||
AbstractProtocol *parent_;
|
||||
|
||||
QString name_;
|
||||
bool protocolFrameValueVariable_;
|
||||
bool protocolFrameSizeVariable_;
|
||||
int protocolFrameVariableCount_;
|
||||
};
|
||||
@ -133,7 +127,6 @@ public:
|
||||
|
||||
virtual int protocolFrameSize(int streamIndex = 0) const;
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual bool isProtocolFrameSizeVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user