Implemented new method protocolFrameVariableCount() and associated code for all the protocols that require it. With this commit, the set of changes required to reduce the time taken to prebuild the packets for transmit is done.
Fixes issue 35 Fixes issue 49
This commit is contained in:
parent
0223f39994
commit
210bdf11a9
@ -57,6 +57,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
- protocolFrameSize()
|
||||
- isProtocolFrameValueVariable()
|
||||
- isProtocolFrameSizeVariable()
|
||||
- protocolFrameVariableCount()
|
||||
|
||||
See the description of the methods for more information.
|
||||
|
||||
@ -554,7 +555,7 @@ QByteArray AbstractProtocol::protocolFrameValue(int streamIndex, bool forCksum)
|
||||
*/
|
||||
bool AbstractProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
return false;
|
||||
return (protocolFrameVariableCount() > 1);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -633,6 +634,32 @@ bool AbstractProtocol::isProtocolFramePayloadSizeVariable() const
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns true if the payload size for a protocol varies at run-time,
|
||||
false otherwise
|
||||
|
||||
This is useful for subclasses which have fields dependent on payload size
|
||||
(e.g. UDP has a checksum field that varies if the payload varies)
|
||||
*/
|
||||
int AbstractProtocol::protocolFramePayloadVariableCount() const
|
||||
{
|
||||
int count = 1;
|
||||
AbstractProtocol *p = next;
|
||||
|
||||
while (p)
|
||||
{
|
||||
if (p->isProtocolFrameValueVariable()
|
||||
|| p->isProtocolFrameSizeVariable())
|
||||
count = lcm(count, p->protocolFrameVariableCount());
|
||||
p = p->next;
|
||||
}
|
||||
if (parent && (parent->isProtocolFramePayloadValueVariable()
|
||||
|| parent->isProtocolFramePayloadSizeVariable()))
|
||||
count = lcm(count, parent->protocolFramePayloadVariableCount());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns true if the protocol typically contains a payload or other protocols
|
||||
following it e.g. TCP, UDP have payloads, while ARP, IGMP do not
|
||||
|
@ -142,6 +142,7 @@ public:
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
bool isProtocolFramePayloadValueVariable() const;
|
||||
bool isProtocolFramePayloadSizeVariable() const;
|
||||
int protocolFramePayloadVariableCount() const;
|
||||
|
||||
bool protocolHasPayload() const;
|
||||
|
||||
|
@ -835,15 +835,54 @@ _exit:
|
||||
return isOk;
|
||||
}
|
||||
|
||||
/*!
|
||||
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 ArpProtocol::isProtocolFrameValueVariable() const
|
||||
{
|
||||
return true;
|
||||
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;
|
||||
|
||||
if (fieldData(arp_senderHwAddrMode, FieldValue).toUInt()
|
||||
!= uint(OstProto::Arp::kFixed))
|
||||
{
|
||||
count = AbstractProtocol::lcm(count,
|
||||
fieldData(arp_senderHwAddrCount, FieldValue).toUInt());
|
||||
}
|
||||
|
||||
if (fieldData(arp_senderProtoAddrMode, FieldValue).toUInt()
|
||||
!= uint(OstProto::Arp::kFixed))
|
||||
{
|
||||
count = AbstractProtocol::lcm(count,
|
||||
fieldData(arp_senderProtoAddrCount, FieldValue).toUInt());
|
||||
}
|
||||
|
||||
if (fieldData(arp_targetHwAddrMode, FieldValue).toUInt()
|
||||
!= uint(OstProto::Arp::kFixed))
|
||||
{
|
||||
count = AbstractProtocol::lcm(count,
|
||||
fieldData(arp_targetHwAddrCount, FieldValue).toUInt());
|
||||
}
|
||||
|
||||
if (fieldData(arp_targetProtoAddrMode, FieldValue).toUInt()
|
||||
!= uint(OstProto::Arp::kFixed))
|
||||
{
|
||||
count = AbstractProtocol::lcm(count,
|
||||
fieldData(arp_targetProtoAddrCount, FieldValue).toUInt());
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
QWidget* ArpProtocol::configWidget()
|
||||
|
@ -111,6 +111,7 @@ public:
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
|
@ -169,6 +169,12 @@ public:
|
||||
return (protoA->isProtocolFrameSizeVariable()
|
||||
|| protoB->isProtocolFrameSizeVariable());
|
||||
}
|
||||
virtual int protocolFrameVariableCount() const
|
||||
{
|
||||
return AbstractProtocol::lcm(
|
||||
protoA->protocolFrameVariableCount(),
|
||||
protoB->protocolFrameVariableCount());
|
||||
}
|
||||
|
||||
virtual quint32 protocolFrameCksum(int streamIndex = 0,
|
||||
CksumType cksumType = CksumIp) const
|
||||
|
@ -203,6 +203,11 @@ bool Dot3Protocol::isProtocolFrameValueVariable() const
|
||||
return isProtocolFramePayloadSizeVariable();
|
||||
}
|
||||
|
||||
int Dot3Protocol::protocolFrameVariableCount() const
|
||||
{
|
||||
return protocolFramePayloadVariableCount();
|
||||
}
|
||||
|
||||
QWidget* Dot3Protocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
|
@ -70,6 +70,7 @@ public:
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
|
@ -925,6 +925,25 @@ bool GmpProtocol::isProtocolFrameValueVariable() const
|
||||
return false;
|
||||
}
|
||||
|
||||
int GmpProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
int count = 1;
|
||||
|
||||
// No fields vary for Ssm Query and Report
|
||||
if (isSsmReport() || isSsmQuery())
|
||||
return count;
|
||||
|
||||
// For all other msg types, check the group mode
|
||||
if (fieldData(kGroupMode, FieldValue).toUInt()
|
||||
!= uint(OstProto::Gmp::kFixed))
|
||||
{
|
||||
count = AbstractProtocol::lcm(count,
|
||||
fieldData(kGroupCount, FieldValue).toUInt());
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void GmpProtocol::loadConfigWidget()
|
||||
{
|
||||
configWidget();
|
||||
|
@ -80,6 +80,7 @@ public:
|
||||
virtual int protocolFrameSize(int streamIndex = 0) const;
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
virtual void loadConfigWidget();
|
||||
virtual void storeConfigWidget();
|
||||
|
@ -808,6 +808,19 @@ bool Ip6Protocol::isProtocolFrameValueVariable() const
|
||||
return false;
|
||||
}
|
||||
|
||||
int Ip6Protocol::protocolFrameVariableCount() const
|
||||
{
|
||||
int count = 1;
|
||||
|
||||
if (data.src_addr_mode() != OstProto::Ip6::kFixed)
|
||||
count = AbstractProtocol::lcm(count, data.src_addr_count());
|
||||
|
||||
if (data.dst_addr_mode() != OstProto::Ip6::kFixed)
|
||||
count = AbstractProtocol::lcm(count, data.dst_addr_count());
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
quint32 Ip6Protocol::protocolFrameCksum(int streamIndex,
|
||||
CksumType cksumType) const
|
||||
{
|
||||
|
@ -118,6 +118,7 @@ public:
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
virtual quint32 protocolFrameCksum(int streamIndex = 0,
|
||||
CksumType cksumType = CksumIp) const;
|
||||
|
@ -268,6 +268,18 @@ bool MacProtocol::isProtocolFrameValueVariable() const
|
||||
return false;
|
||||
}
|
||||
|
||||
int MacProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
int count = 1;
|
||||
|
||||
if (data.dst_mac_mode() != OstProto::Mac::e_mm_fixed)
|
||||
count = AbstractProtocol::lcm(count, data.dst_mac_count());
|
||||
|
||||
if (data.src_mac_mode() != OstProto::Mac::e_mm_fixed)
|
||||
count = AbstractProtocol::lcm(count, data.src_mac_count());
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
QWidget* MacProtocol::configWidget()
|
||||
{
|
||||
|
@ -81,6 +81,7 @@ public:
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
|
@ -226,6 +226,32 @@ bool PayloadProtocol::isProtocolFrameSizeVariable() const
|
||||
return true;
|
||||
}
|
||||
|
||||
int PayloadProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
int count = 1;
|
||||
|
||||
if (data.pattern_mode() == OstProto::Payload::e_dp_random)
|
||||
{
|
||||
switch(mpStream->sendUnit())
|
||||
{
|
||||
case OstProto::StreamControl::e_su_packets:
|
||||
return mpStream->numPackets();
|
||||
|
||||
case OstProto::StreamControl::e_su_bursts:
|
||||
return int(mpStream->numBursts()
|
||||
* mpStream->burstSize()
|
||||
* mpStream->burstRate());
|
||||
}
|
||||
}
|
||||
|
||||
if (mpStream->lenMode() != StreamBase::e_fl_fixed)
|
||||
{
|
||||
count = AbstractProtocol::lcm(count,
|
||||
mpStream->frameLenMax() - mpStream->frameLenMin() + 1);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
QWidget* PayloadProtocol::configWidget()
|
||||
{
|
||||
|
@ -75,6 +75,7 @@ public:
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual bool isProtocolFrameSizeVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
|
@ -473,6 +473,18 @@ bool SampleProtocol::isProtocolFrameSizeVariable() const
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
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
|
||||
*/
|
||||
int SampleProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QWidget* SampleProtocol::configWidget()
|
||||
{
|
||||
/* Lazy creation of the configWidget */
|
||||
|
@ -93,6 +93,7 @@ public:
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual bool isProtocolFrameSizeVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
|
@ -606,6 +606,14 @@ bool TcpProtocol::isProtocolFrameValueVariable() const
|
||||
return isProtocolFramePayloadValueVariable();
|
||||
}
|
||||
|
||||
int TcpProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
if (data.is_override_cksum())
|
||||
return 1;
|
||||
|
||||
return protocolFramePayloadVariableCount();
|
||||
}
|
||||
|
||||
QWidget* TcpProtocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
|
@ -91,6 +91,7 @@ public:
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
|
@ -433,6 +433,14 @@ bool UdpProtocol::isProtocolFrameValueVariable() const
|
||||
return isProtocolFramePayloadValueVariable();
|
||||
}
|
||||
|
||||
int UdpProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
if (data.is_override_totlen() && data.is_override_cksum())
|
||||
return 1;
|
||||
|
||||
return protocolFramePayloadVariableCount();
|
||||
}
|
||||
|
||||
QWidget* UdpProtocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
|
@ -78,6 +78,7 @@ public:
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
|
@ -271,6 +271,11 @@ bool UserScriptProtocol::isProtocolFrameSizeVariable() const
|
||||
return userProtocol_.isProtocolFrameSizeVariable();
|
||||
}
|
||||
|
||||
int UserScriptProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
return userProtocol_.protocolFrameVariableCount();
|
||||
}
|
||||
|
||||
quint32 UserScriptProtocol::protocolFrameCksum(int streamIndex,
|
||||
CksumType cksumType) const
|
||||
{
|
||||
@ -532,6 +537,7 @@ void UserProtocol::reset()
|
||||
name_ = QString();
|
||||
protocolFrameValueVariable_ = false;
|
||||
protocolFrameSizeVariable_ = false;
|
||||
protocolFrameVariableCount_ = 1;
|
||||
}
|
||||
|
||||
QString UserProtocol::name() const
|
||||
@ -564,6 +570,16 @@ void UserProtocol::setProtocolFrameSizeVariable(bool variable)
|
||||
protocolFrameSizeVariable_ = variable;
|
||||
}
|
||||
|
||||
int UserProtocol::protocolFrameVariableCount() const
|
||||
{
|
||||
return protocolFrameVariableCount_;
|
||||
}
|
||||
|
||||
void UserProtocol::setProtocolFrameVariableCount(int count)
|
||||
{
|
||||
protocolFrameVariableCount_ = count;
|
||||
}
|
||||
|
||||
quint32 UserProtocol::payloadProtocolId(UserProtocol::ProtocolIdType type) const
|
||||
{
|
||||
return parent_->payloadProtocolId(
|
||||
@ -590,6 +606,11 @@ bool UserProtocol::isProtocolFramePayloadSizeVariable() const
|
||||
return parent_->isProtocolFramePayloadSizeVariable();
|
||||
}
|
||||
|
||||
int UserProtocol::protocolFramePayloadVariableCount() const
|
||||
{
|
||||
return parent_->protocolFramePayloadVariableCount();
|
||||
}
|
||||
|
||||
quint32 UserProtocol::protocolFrameHeaderCksum(int streamIndex,
|
||||
AbstractProtocol::CksumType cksumType) const
|
||||
{
|
||||
|
@ -42,13 +42,17 @@ class UserProtocol : public QObject
|
||||
Q_PROPERTY(bool protocolFrameSizeVariable
|
||||
READ isProtocolFrameSizeVariable
|
||||
WRITE setProtocolFrameSizeVariable);
|
||||
Q_PROPERTY(int protocolFrameVariableCount
|
||||
READ protocolFrameVariableCount
|
||||
WRITE setProtocolFrameVariableCount);
|
||||
|
||||
public:
|
||||
enum ProtocolIdType
|
||||
{
|
||||
ProtocolIdLlc = AbstractProtocol::ProtocolIdLlc,
|
||||
ProtocolIdEth = AbstractProtocol::ProtocolIdEth,
|
||||
ProtocolIdIp = AbstractProtocol::ProtocolIdIp
|
||||
ProtocolIdIp = AbstractProtocol::ProtocolIdIp,
|
||||
ProtocolIdTcpUdp = AbstractProtocol::ProtocolIdTcpUdp
|
||||
};
|
||||
|
||||
enum CksumType
|
||||
@ -70,6 +74,8 @@ public slots:
|
||||
void setProtocolFrameValueVariable(bool variable);
|
||||
bool isProtocolFrameSizeVariable() const;
|
||||
void setProtocolFrameSizeVariable(bool variable);
|
||||
int protocolFrameVariableCount() const;
|
||||
void setProtocolFrameVariableCount(int count);
|
||||
|
||||
quint32 payloadProtocolId(UserProtocol::ProtocolIdType type) const;
|
||||
int protocolFrameOffset(int streamIndex = 0) const;
|
||||
@ -77,6 +83,7 @@ public slots:
|
||||
|
||||
bool isProtocolFramePayloadValueVariable() const;
|
||||
bool isProtocolFramePayloadSizeVariable() const;
|
||||
int protocolFramePayloadVariableCount() const;
|
||||
|
||||
quint32 protocolFrameHeaderCksum(int streamIndex = 0,
|
||||
AbstractProtocol::CksumType cksumType = AbstractProtocol::CksumIp) const;
|
||||
@ -87,8 +94,9 @@ private:
|
||||
AbstractProtocol *parent_;
|
||||
|
||||
QString name_;
|
||||
bool protocolFrameValueVariable_;
|
||||
bool protocolFrameSizeVariable_;
|
||||
bool protocolFrameValueVariable_;
|
||||
bool protocolFrameSizeVariable_;
|
||||
int protocolFrameVariableCount_;
|
||||
};
|
||||
|
||||
|
||||
@ -141,6 +149,7 @@ public:
|
||||
|
||||
virtual bool isProtocolFrameValueVariable() const;
|
||||
virtual bool isProtocolFrameSizeVariable() const;
|
||||
virtual int protocolFrameVariableCount() const;
|
||||
|
||||
virtual quint32 protocolFrameCksum(int streamIndex = 0,
|
||||
CksumType cksumType = CksumIp) const;
|
||||
|
@ -298,6 +298,8 @@ void PcapPort::PortTransmitter::clearPacketList()
|
||||
repeatSize_ = 0;
|
||||
packetCount_ = 0;
|
||||
|
||||
returnToQIdx_ = -1;
|
||||
|
||||
setPacketListLoopMode(false, 0, 0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user