Added a preflight check method to class StreamBase - this is used by StreamConfigDialog to notify the user of potential problems such as truncated frames

This commit is contained in:
Srivats P. 2010-05-02 15:37:46 +05:30
parent e681e1e226
commit d0cddbafb8
6 changed files with 120 additions and 48 deletions

View File

@ -926,11 +926,20 @@ void StreamConfigDialog::StoreCurrentStream()
void StreamConfigDialog::on_pbOk_clicked()
{
OstProto::Stream s;
QString log;
OstProto::Stream s;
// Store dialog contents into stream
StoreCurrentStream();
if (!mpStream->preflightCheck(log))
{
if (QMessageBox::warning(this, "Preflight Check", log + "\nContinue?",
QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
== QMessageBox::No)
return;
}
// Copy the data from the "local working copy of stream" to "actual stream"
mpStream->protoDataCopyInto(s);
mPort.streamByIndex(mCurrentStreamIndex)->protoDataCopyFrom(s);
@ -938,5 +947,7 @@ void StreamConfigDialog::on_pbOk_clicked()
qDebug("stream stored");
lastTopLevelTabIndex = twTopLevel->currentIndex();
accept();
}

View File

@ -1198,22 +1198,6 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
<include location="ostinato.qrc" />
</resources>
<connections>
<connection>
<sender>pbOk</sender>
<signal>clicked()</signal>
<receiver>StreamConfigDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>496</x>
<y>552</y>
</hint>
<hint type="destinationlabel" >
<x>533</x>
<y>433</y>
</hint>
</hints>
</connection>
<connection>
<sender>pbCancel</sender>
<signal>clicked()</signal>
@ -1221,8 +1205,8 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>579</x>
<y>552</y>
<x>558</x>
<y>453</y>
</hint>
<hint type="destinationlabel" >
<x>533</x>
@ -1237,12 +1221,12 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>158</x>
<y>149</y>
<x>169</x>
<y>207</y>
</hint>
<hint type="destinationlabel" >
<x>158</x>
<y>149</y>
<x>169</x>
<y>207</y>
</hint>
</hints>
</connection>
@ -1253,12 +1237,12 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>59</x>
<y>120</y>
<x>125</x>
<y>207</y>
</hint>
<hint type="destinationlabel" >
<x>59</x>
<y>149</y>
<x>125</x>
<y>207</y>
</hint>
</hints>
</connection>
@ -1269,12 +1253,12 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>59</x>
<y>123</y>
<x>125</x>
<y>207</y>
</hint>
<hint type="destinationlabel" >
<x>59</x>
<y>149</y>
<x>125</x>
<y>207</y>
</hint>
</hints>
</connection>
@ -1285,12 +1269,12 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>59</x>
<y>123</y>
<x>125</x>
<y>207</y>
</hint>
<hint type="destinationlabel" >
<x>145</x>
<y>149</y>
<x>156</x>
<y>207</y>
</hint>
</hints>
</connection>

View File

@ -23,7 +23,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "dot3.h"
#include "streambase.h"
#define SZ_FCS 4
Dot3ConfigForm::Dot3ConfigForm(QWidget *parent)
: QWidget(parent)
@ -95,7 +94,6 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
{
quint16 len;
//len = mpStream->frameLen() - SZ_FCS;
len = protocolFramePayloadSize(streamIndex);
return len;
}
@ -103,7 +101,6 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
{
quint16 len;
//len = mpStream->frameLen() - SZ_FCS;
len = protocolFramePayloadSize(streamIndex);
return QString("%1").arg(len);
}
@ -112,7 +109,6 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
quint16 len;
QByteArray fv;
//len = mpStream->frameLen() - SZ_FCS;
len = protocolFramePayloadSize(streamIndex);
fv.resize(2);
qToBigEndian(len, (uchar*) fv.data());

View File

@ -24,7 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "payload.h"
#include "streambase.h"
#define SZ_FCS 4
PayloadConfigForm::PayloadConfigForm(QWidget *parent)
: QWidget(parent)
@ -94,19 +93,22 @@ QString PayloadProtocol::shortName() const
return QString("DATA");
}
int PayloadProtocol::protocolFrameSize(int streamIndex) const
int PayloadProtocol::protocolFrameSize(int streamIndex) const
{
int len;
len = mpStream->frameLen(streamIndex) - protocolFrameOffset(streamIndex)
- SZ_FCS;
- kFcsSize;
if (len < 0)
len = 0;
qDebug("%s: this = %p, streamIndex = %d, len = %d", __FUNCTION__, this,
streamIndex, len);
return len;
}
int PayloadProtocol::fieldCount() const
int PayloadProtocol::fieldCount() const
{
return payload_fieldCount;
}

View File

@ -362,14 +362,67 @@ _exit:
return true;
}
int StreamBase::frameValue(uchar *buf, int bufMaxSize, int n) const
bool StreamBase::isFrameSizeVariable() const
{
ProtocolListIterator *iter;
iter = createProtocolListIterator();
while (iter->hasNext())
{
AbstractProtocol *proto;
proto = iter->next();
if (proto->isProtocolFrameSizeVariable())
goto _exit;
}
delete iter;
return false;
_exit:
delete iter;
return true;
}
// frameProtocolLength() returns the sum of all the individual protocol sizes
// which may be different from frameLen()
int StreamBase::frameProtocolLength(int frameIndex) const
{
int len = 0;
ProtocolListIterator *iter = createProtocolListIterator();
while (iter->hasNext())
{
AbstractProtocol *proto = iter->next();
len += proto->protocolFrameSize(frameIndex);
}
delete iter;
return len;
}
int StreamBase::frameCount() const
{
int count;
switch (sendUnit())
{
case e_su_packets: count = numPackets(); break;
case e_su_bursts: count = numBursts() * burstSize(); break;
default: Q_ASSERT(false); // unreachable
}
return count;
}
int StreamBase::frameValue(uchar *buf, int bufMaxSize, int frameIndex) const
{
int pktLen, len = 0;
pktLen = frameLen(n);
pktLen = frameLen(frameIndex);
// pktLen is adjusted for CRC/FCS which will be added by the NIC
pktLen -= 4;
pktLen -= kFcsSize;
if ((pktLen < 0) || (pktLen > bufMaxSize))
return 0;
@ -383,7 +436,7 @@ int StreamBase::frameValue(uchar *buf, int bufMaxSize, int n) const
QByteArray ba;
proto = iter->next();
ba = proto->protocolFrameValue(n);
ba = proto->protocolFrameValue(frameIndex);
if (len + ba.size() < bufMaxSize)
memcpy(buf+len, ba.constData(), ba.size());
@ -394,6 +447,26 @@ int StreamBase::frameValue(uchar *buf, int bufMaxSize, int n) const
return pktLen;
}
bool StreamBase::preflightCheck(QString &result) const
{
int count = isFrameSizeVariable() ? frameCount() : 1;
for (int i = 0; i < count; i++)
{
if (frameLen(i) < (frameProtocolLength(i) + kFcsSize))
{
result += QString("One or more frames may be truncated - "
"frame length should be at least %1.\n")
.arg(frameProtocolLength(i) + kFcsSize);
goto _fail;
}
}
return true;
_fail:
return false;
}
bool StreamBase::StreamLessThan(StreamBase* stream1, StreamBase* stream2)
{
return stream1->ordinal() < stream2->ordinal() ? true : false;

View File

@ -25,6 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "protocol.pb.h"
const int kFcsSize = 4;
class AbstractProtocol;
class ProtocolList;
class ProtocolListIterator;
@ -130,7 +132,11 @@ public:
bool setBurstRate(quint32 burstsPerSec);
bool isFrameVariable() const;
int frameValue(uchar *buf, int bufMaxSize, int n) const;
bool isFrameSizeVariable() const;
int frameProtocolLength(int frameIndex) const;
int frameCount() const;
int frameValue(uchar *buf, int bufMaxSize, int frameIndex) const;
bool preflightCheck(QString &result) const;
static bool StreamLessThan(StreamBase* stream1, StreamBase* stream2);
};