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() void StreamConfigDialog::on_pbOk_clicked()
{ {
OstProto::Stream s; QString log;
OstProto::Stream s;
// Store dialog contents into stream // Store dialog contents into stream
StoreCurrentStream(); 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" // Copy the data from the "local working copy of stream" to "actual stream"
mpStream->protoDataCopyInto(s); mpStream->protoDataCopyInto(s);
mPort.streamByIndex(mCurrentStreamIndex)->protoDataCopyFrom(s); mPort.streamByIndex(mCurrentStreamIndex)->protoDataCopyFrom(s);
@ -938,5 +947,7 @@ void StreamConfigDialog::on_pbOk_clicked()
qDebug("stream stored"); qDebug("stream stored");
lastTopLevelTabIndex = twTopLevel->currentIndex(); 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" /> <include location="ostinato.qrc" />
</resources> </resources>
<connections> <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> <connection>
<sender>pbCancel</sender> <sender>pbCancel</sender>
<signal>clicked()</signal> <signal>clicked()</signal>
@ -1221,8 +1205,8 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
<slot>reject()</slot> <slot>reject()</slot>
<hints> <hints>
<hint type="sourcelabel" > <hint type="sourcelabel" >
<x>579</x> <x>558</x>
<y>552</y> <y>453</y>
</hint> </hint>
<hint type="destinationlabel" > <hint type="destinationlabel" >
<x>533</x> <x>533</x>
@ -1237,12 +1221,12 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel" > <hint type="sourcelabel" >
<x>158</x> <x>169</x>
<y>149</y> <y>207</y>
</hint> </hint>
<hint type="destinationlabel" > <hint type="destinationlabel" >
<x>158</x> <x>169</x>
<y>149</y> <y>207</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@ -1253,12 +1237,12 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel" > <hint type="sourcelabel" >
<x>59</x> <x>125</x>
<y>120</y> <y>207</y>
</hint> </hint>
<hint type="destinationlabel" > <hint type="destinationlabel" >
<x>59</x> <x>125</x>
<y>149</y> <y>207</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@ -1269,12 +1253,12 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel" > <hint type="sourcelabel" >
<x>59</x> <x>125</x>
<y>123</y> <y>207</y>
</hint> </hint>
<hint type="destinationlabel" > <hint type="destinationlabel" >
<x>59</x> <x>125</x>
<y>149</y> <y>207</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@ -1285,12 +1269,12 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel" > <hint type="sourcelabel" >
<x>59</x> <x>125</x>
<y>123</y> <y>207</y>
</hint> </hint>
<hint type="destinationlabel" > <hint type="destinationlabel" >
<x>145</x> <x>156</x>
<y>149</y> <y>207</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>

View File

@ -23,7 +23,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "dot3.h" #include "dot3.h"
#include "streambase.h" #include "streambase.h"
#define SZ_FCS 4
Dot3ConfigForm::Dot3ConfigForm(QWidget *parent) Dot3ConfigForm::Dot3ConfigForm(QWidget *parent)
: QWidget(parent) : QWidget(parent)
@ -95,7 +94,6 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
{ {
quint16 len; quint16 len;
//len = mpStream->frameLen() - SZ_FCS;
len = protocolFramePayloadSize(streamIndex); len = protocolFramePayloadSize(streamIndex);
return len; return len;
} }
@ -103,7 +101,6 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
{ {
quint16 len; quint16 len;
//len = mpStream->frameLen() - SZ_FCS;
len = protocolFramePayloadSize(streamIndex); len = protocolFramePayloadSize(streamIndex);
return QString("%1").arg(len); return QString("%1").arg(len);
} }
@ -112,7 +109,6 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
quint16 len; quint16 len;
QByteArray fv; QByteArray fv;
//len = mpStream->frameLen() - SZ_FCS;
len = protocolFramePayloadSize(streamIndex); len = protocolFramePayloadSize(streamIndex);
fv.resize(2); fv.resize(2);
qToBigEndian(len, (uchar*) fv.data()); 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 "payload.h"
#include "streambase.h" #include "streambase.h"
#define SZ_FCS 4
PayloadConfigForm::PayloadConfigForm(QWidget *parent) PayloadConfigForm::PayloadConfigForm(QWidget *parent)
: QWidget(parent) : QWidget(parent)
@ -94,19 +93,22 @@ QString PayloadProtocol::shortName() const
return QString("DATA"); return QString("DATA");
} }
int PayloadProtocol::protocolFrameSize(int streamIndex) const int PayloadProtocol::protocolFrameSize(int streamIndex) const
{ {
int len; int len;
len = mpStream->frameLen(streamIndex) - protocolFrameOffset(streamIndex) len = mpStream->frameLen(streamIndex) - protocolFrameOffset(streamIndex)
- SZ_FCS; - kFcsSize;
if (len < 0)
len = 0;
qDebug("%s: this = %p, streamIndex = %d, len = %d", __FUNCTION__, this, qDebug("%s: this = %p, streamIndex = %d, len = %d", __FUNCTION__, this,
streamIndex, len); streamIndex, len);
return len; return len;
} }
int PayloadProtocol::fieldCount() const int PayloadProtocol::fieldCount() const
{ {
return payload_fieldCount; return payload_fieldCount;
} }

View File

@ -362,14 +362,67 @@ _exit:
return true; 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; int pktLen, len = 0;
pktLen = frameLen(n); pktLen = frameLen(frameIndex);
// pktLen is adjusted for CRC/FCS which will be added by the NIC // pktLen is adjusted for CRC/FCS which will be added by the NIC
pktLen -= 4; pktLen -= kFcsSize;
if ((pktLen < 0) || (pktLen > bufMaxSize)) if ((pktLen < 0) || (pktLen > bufMaxSize))
return 0; return 0;
@ -383,7 +436,7 @@ int StreamBase::frameValue(uchar *buf, int bufMaxSize, int n) const
QByteArray ba; QByteArray ba;
proto = iter->next(); proto = iter->next();
ba = proto->protocolFrameValue(n); ba = proto->protocolFrameValue(frameIndex);
if (len + ba.size() < bufMaxSize) if (len + ba.size() < bufMaxSize)
memcpy(buf+len, ba.constData(), ba.size()); memcpy(buf+len, ba.constData(), ba.size());
@ -394,6 +447,26 @@ int StreamBase::frameValue(uchar *buf, int bufMaxSize, int n) const
return pktLen; 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) bool StreamBase::StreamLessThan(StreamBase* stream1, StreamBase* stream2)
{ {
return stream1->ordinal() < stream2->ordinal() ? true : false; 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" #include "protocol.pb.h"
const int kFcsSize = 4;
class AbstractProtocol; class AbstractProtocol;
class ProtocolList; class ProtocolList;
class ProtocolListIterator; class ProtocolListIterator;
@ -130,7 +132,11 @@ public:
bool setBurstRate(quint32 burstsPerSec); bool setBurstRate(quint32 burstsPerSec);
bool isFrameVariable() const; 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); static bool StreamLessThan(StreamBase* stream1, StreamBase* stream2);
}; };