") : mpStream->name()));
// Meta Data
{
name->setText(mpStream->name());
enabled->setChecked(mpStream->isEnabled());
cmbPktLenMode->setCurrentIndex(mpStream->lenMode());
lePktLen->setText(str.setNum(mpStream->frameLen()));
lePktLenMin->setText(str.setNum(mpStream->frameLenMin()));
lePktLenMax->setText(str.setNum(mpStream->frameLenMax()));
}
// Protocols
{
updateSelectProtocolsSimpleWidget();
updateSelectProtocolsAdvancedWidget();
loadProtocolWidgets();
}
// Variable Fields
{
variableFieldsWidget->clear();
variableFieldsWidget->load();
}
// Stream Control
{
switch (mpStream->sendUnit())
{
case Stream::e_su_packets:
rbSendPackets->setChecked(true);
break;
case Stream::e_su_bursts:
rbSendBursts->setChecked(true);
break;
default:
qWarning("Unhandled sendUnit = %d\n", mpStream->sendUnit());
}
switch (mpStream->sendMode())
{
case Stream::e_sm_fixed:
rbModeFixed->setChecked(true);
break;
case Stream::e_sm_continuous:
rbModeContinuous->setChecked(true);
break;
default:
qWarning("Unhandled sendMode = %d\n", mpStream->sendMode());
}
switch(mpStream->nextWhat())
{
case Stream::e_nw_stop:
rbActionStop->setChecked(true);
break;
case Stream::e_nw_goto_next:
rbActionGotoNext->setChecked(true);
break;
case Stream::e_nw_goto_id:
rbActionGotoStream->setChecked(true);
break;
default:
qWarning("Unhandled nextAction = %d\n", mpStream->nextWhat());
}
leNumPackets->setText(QString().setNum(mpStream->numPackets()));
leNumBursts->setText(QString().setNum(mpStream->numBursts()));
lePacketsPerBurst->setText(QString().setNum(mpStream->burstSize()));
lePacketsPerSec->setText(
QString("%L1").arg(mpStream->packetRate(), 0, 'f', 4));
leBurstsPerSec->setText(
QString("%L1").arg(mpStream->burstRate(), 0, 'f', 4));
// TODO(MED): Change this when we support goto to specific stream
leStreamId->setText(QString("0"));
leGapIsg->setText("0.0");
}
qDebug("loading stream done");
}
void StreamConfigDialog::StoreCurrentStream()
{
QString str;
bool isOk;
Stream *pStream = mpStream;
qDebug("storing pStream %p", pStream);
// Meta Data
pStream->setName(name->text());
pStream->setEnabled(enabled->isChecked());
pStream->setLenMode((Stream::FrameLengthMode) cmbPktLenMode->currentIndex());
pStream->setFrameLen(lePktLen->text().toULong(&isOk));
pStream->setFrameLenMin(lePktLenMin->text().toULong(&isOk));
pStream->setFrameLenMax(lePktLenMax->text().toULong(&isOk));
// Protocols
{
storeProtocolWidgets();
}
// Variable Fields
{
variableFieldsWidget->store();
}
// Stream Control
{
if (rbSendPackets->isChecked())
pStream->setSendUnit(Stream::e_su_packets);
if (rbSendBursts->isChecked())
pStream->setSendUnit(Stream::e_su_bursts);
if (rbModeFixed->isChecked())
pStream->setSendMode(Stream::e_sm_fixed);
if (rbModeContinuous->isChecked())
pStream->setSendMode(Stream::e_sm_continuous);
if (rbActionStop->isChecked())
pStream->setNextWhat(Stream::e_nw_stop);
if (rbActionGotoNext->isChecked())
pStream->setNextWhat(Stream::e_nw_goto_next);
if (rbActionGotoStream->isChecked())
pStream->setNextWhat(Stream::e_nw_goto_id);
pStream->setNumPackets(leNumPackets->text().toULong(&isOk));
pStream->setNumBursts(leNumBursts->text().toULong(&isOk));
pStream->setBurstSize(lePacketsPerBurst->text().toULong(&isOk));
pStream->setPacketRate(
XLocale().toDouble(lePacketsPerSec->text(), &isOk));
pStream->setBurstRate(
XLocale().toDouble(leBurstsPerSec->text(), &isOk));
}
}
void StreamConfigDialog::on_tbProtocolData_currentChanged(int /*index*/)
{
// Refresh protocol widgets in case there is any dependent data between
// protocols e.g. TCP/UDP port numbers are dependent on Port/Protocol
// selection in TextProtocol
#if 0 // FIXME: temp mask to avoid crash till we fix it
storeProtocolWidgets();
loadProtocolWidgets();
#endif
}
void StreamConfigDialog::on_rbPacketsPerSec_toggled(bool checked)
{
if (checked)
on_lePacketsPerSec_textChanged(lePacketsPerSec->text());
}
void StreamConfigDialog::on_rbBurstsPerSec_toggled(bool checked)
{
if (checked)
on_leBurstsPerSec_textChanged(leBurstsPerSec->text());
}
void StreamConfigDialog::on_lePacketsPerBurst_textChanged(const QString &/*text*/)
{
if (rbSendBursts->isChecked())
on_leBurstsPerSec_textChanged(leBurstsPerSec->text());
}
void StreamConfigDialog::on_lePacketsPerSec_textChanged(const QString &text)
{
bool isOk;
Stream *pStream = mpStream;
uint frameLen = pStream->frameLenAvg();
if (rbSendPackets->isChecked())
{
double pktsPerSec = XLocale().toDouble(text, &isOk);
double bitsPerSec = pktsPerSec * double((frameLen+kEthFrameOverHead)*8);
if (rbPacketsPerSec->isChecked())
leBitsPerSec->setText(QString("%L1").arg(bitsPerSec, 0, 'f', 0));
leGapIbg->setText(QString("0.0"));
leGapIpg->setText(QString("%L1").arg(1/double(pktsPerSec), 0, 'f', 9));
}
}
void StreamConfigDialog::on_leBurstsPerSec_textChanged(const QString &text)
{
bool isOk;
Stream *pStream = mpStream;
uint burstSize = lePacketsPerBurst->text().toULong(&isOk);
uint frameLen = pStream->frameLenAvg();
qDebug("start of %s(%s)", __FUNCTION__, qPrintable(text));
if (rbSendBursts->isChecked())
{
double burstsPerSec = XLocale().toDouble(text, &isOk);
double bitsPerSec = burstsPerSec *
double(burstSize * (frameLen + kEthFrameOverHead) * 8);
if (rbBurstsPerSec->isChecked())
leBitsPerSec->setText(QString("%L1").arg(bitsPerSec, 0, 'f', 0));
leGapIbg->setText(QString("%L1").arg(1/double(burstsPerSec), 0, 'f',9));
leGapIpg->setText(QString("0.0"));
}
qDebug("end of %s", __FUNCTION__);
}
void StreamConfigDialog::on_leBitsPerSec_textEdited(const QString &text)
{
bool isOk;
Stream *pStream = mpStream;
uint burstSize = lePacketsPerBurst->text().toULong(&isOk);
uint frameLen = pStream->frameLenAvg();
if (rbSendPackets->isChecked())
{
double pktsPerSec = XLocale().toDouble(text, &isOk)/
double((frameLen+kEthFrameOverHead)*8);
lePacketsPerSec->setText(QString("%L1").arg(pktsPerSec, 0, 'f', 4));
}
else if (rbSendBursts->isChecked())
{
double burstsPerSec = XLocale().toDouble(text, &isOk)/
double(burstSize * (frameLen + kEthFrameOverHead) * 8);
leBurstsPerSec->setText(QString("%L1").arg(burstsPerSec, 0, 'f', 4));
}
}
bool StreamConfigDialog::isCurrentStreamValid()
{
QStringList log;
if ((mPort.transmitMode() == OstProto::kInterleavedTransmit)
&& (mpStream->isFrameVariable()))
{
log << tr("In 'Interleaved Streams' transmit mode, the count for "
"varying fields at transmit time may not be same as configured");
}
if (!mPort.trackStreamStats()
&& mpStream->hasProtocol(OstProto::Protocol::kSignFieldNumber))
{
log << tr("Stream contains special signature, but per stream statistics "
"will not be available till it is enabled on the port");
}
mpStream->preflightCheck(log);
if (log.size())
{
if (QMessageBox::warning(this, "Preflight Check",
tr("We found possible problems with this stream -
")
+ ""
+ log.replaceInStrings(QRegExp("(.*)"), "- \\1
")
.join("\n")
+ "
"
+ tr("Ignore?
"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
== QMessageBox::No)
return false;
}
return true;
}
void StreamConfigDialog::on_pbPrev_clicked()
{
Q_ASSERT(mCurrentStreamIndex > 0);
StoreCurrentStream();
if (!isCurrentStreamValid())
return;
delete _iter;
mpStream = _streamList.at(--mCurrentStreamIndex);
_iter = mpStream->createProtocolListIterator();
LoadCurrentStream();
on_twTopLevel_currentChanged(twTopLevel->currentIndex());
pbPrev->setDisabled(mCurrentStreamIndex == 0);
pbNext->setDisabled(int(mCurrentStreamIndex) == (_streamList.size()-1));
}
void StreamConfigDialog::on_pbNext_clicked()
{
Q_ASSERT(int(mCurrentStreamIndex) < (_streamList.size()-1));
StoreCurrentStream();
if (!isCurrentStreamValid())
return;
delete _iter;
mpStream = _streamList.at(++mCurrentStreamIndex);
_iter = mpStream->createProtocolListIterator();
LoadCurrentStream();
on_twTopLevel_currentChanged(twTopLevel->currentIndex());
pbPrev->setDisabled(mCurrentStreamIndex == 0);
pbNext->setDisabled(int(mCurrentStreamIndex) == (_streamList.size()-1));
}
void StreamConfigDialog::on_pbOk_clicked()
{
// Store dialog contents into current stream
StoreCurrentStream();
if (!isCurrentStreamValid())
return;
// Copy the working copy of streams to user provided streams
Q_ASSERT(_userStreamList.size() == _streamList.size());
for (int i = 0; i < _streamList.size(); i++) {
OstProto::Stream s;
_streamList.at(i)->protoDataCopyInto(s);
_userStreamList[i]->protoDataCopyFrom(s);
}
qDebug("stream stored");
lastGeometry = geometry();
lastTopLevelTabIndex = twTopLevel->currentIndex();
lastProtocolDataIndex = tbProtocolData->currentIndex();
accept();
}