Major rewrite of the protocol framework - changes not yet complete
Common ------ - Change in OstProto - Individual protocols are now extensions of (new) message 'Protocol' instead of 'Stream' - Stream now contains a repeated Protocol which also determines the ordered set of currently selected protocols; StreamCore.frame_proto which was doing this earlier has been removed - Change in AbstractProtocol Interface - Parent changed to StreamBase - Corresponding change in constructor and factory func - createInstance() - new method protocolNumber() - returns unique id for each protocol - protoDataCopyInto/From() now copies into OstProto::Protocol instead of OstProto::Stream - Change in all subclasses of AbstractProtocol to match new interface - For all protocols, configFrom is no longer static, but each protocol has its own configForm - configForm creation is lazy - configForm is still a child of the protocol i.e. it will be destroyed alongwith the protocol - TODO: convert configWidget() to a pure factory function i.e. the protocol does not own the configForm - this requires us to pass the widget into load/storeConfigWidget() methods - ProtocolCollection class removed alongwith its .h and .cpp - ProtocolList class redefined to serve the purpose of ProtocolCollection - New class ProtocolListIterator defined to iterate ProtocolList - AbstractProtocol methods now use the ProtocolListIterator - Factory function createProtocol() added to ProtocolManager - OstProto::StreamCore accessor functions moved from Stream to StreamBase Server ------ - MyService uses the newly moved accessors to StreamBase for OstProto::StreamCore members - StreamInfo now uses the protocols to create the packet Client ------ - StreamConfigDialog now uses ProtocolListIterator - So does PacketModel
This commit is contained in:
parent
0103696016
commit
1357f495ac
@ -1,18 +1,24 @@
|
||||
#include <QHostAddress>
|
||||
#include "packetmodel.h"
|
||||
|
||||
PacketModel::PacketModel(const QList<AbstractProtocol*> &selectedProtocols,
|
||||
QObject *parent)
|
||||
#include "packetmodel.h"
|
||||
#include "../common/protocollistiterator.h"
|
||||
#include "../common/abstractprotocol.h"
|
||||
|
||||
PacketModel::PacketModel(QObject *parent)
|
||||
{
|
||||
mSelectedProtocols = selectedProtocols;
|
||||
}
|
||||
|
||||
void PacketModel::setSelectedProtocols(
|
||||
const QList<AbstractProtocol*> &selectedProtocols)
|
||||
void PacketModel::setSelectedProtocols(ProtocolListIterator &iter)
|
||||
{
|
||||
if (mSelectedProtocols != selectedProtocols)
|
||||
QList<const AbstractProtocol*> currentProtocols;
|
||||
|
||||
iter.toFront();
|
||||
while (iter.hasNext())
|
||||
currentProtocols.append(iter.next());
|
||||
|
||||
if (mSelectedProtocols != currentProtocols)
|
||||
{
|
||||
mSelectedProtocols = selectedProtocols;
|
||||
mSelectedProtocols = currentProtocols;
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,16 @@
|
||||
#define _PACKET_MODEL_H
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include "abstractprotocol.h"
|
||||
|
||||
class ProtocolListIterator;
|
||||
class AbstractProtocol;
|
||||
|
||||
class PacketModel: public QAbstractItemModel
|
||||
{
|
||||
|
||||
public:
|
||||
PacketModel(const QList<AbstractProtocol*> &selectedProtocols,
|
||||
QObject *parent = 0);
|
||||
void setSelectedProtocols(
|
||||
const QList<AbstractProtocol*> &selectedProtocols);
|
||||
PacketModel(QObject *parent = 0);
|
||||
void setSelectedProtocols(ProtocolListIterator &iter);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
@ -34,7 +34,7 @@ private:
|
||||
} ws;
|
||||
} IndexId;
|
||||
|
||||
QList<AbstractProtocol*> mSelectedProtocols;
|
||||
QList<const AbstractProtocol*> mSelectedProtocols;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -2,16 +2,14 @@
|
||||
#include <QHostAddress>
|
||||
|
||||
#include "stream.h"
|
||||
//#include "../common/protocollist.h"
|
||||
#include "../common/protocollistiterator.h"
|
||||
#include "../common/abstractprotocol.h"
|
||||
|
||||
Stream::Stream()
|
||||
{
|
||||
//mId = 0xFFFFFFFF;
|
||||
mCore->set_is_enabled(true);
|
||||
|
||||
QList<int> protoList;
|
||||
protoList.append(51);
|
||||
protoList.append(52);
|
||||
setFrameProtocol(protoList);
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
Stream::~Stream()
|
||||
@ -20,10 +18,43 @@ Stream::~Stream()
|
||||
|
||||
void Stream::loadProtocolWidgets()
|
||||
{
|
||||
protocols.loadConfigWidgets();
|
||||
#if 0
|
||||
//protocols.loadConfigWidgets();
|
||||
foreach(AbstractProtocol* proto, *currentFrameProtocols)
|
||||
{
|
||||
proto->loadConfigWidget();
|
||||
}
|
||||
#else
|
||||
ProtocolListIterator *iter;
|
||||
|
||||
iter = createProtocolListIterator();
|
||||
while (iter->hasNext())
|
||||
{
|
||||
AbstractProtocol* p = iter->next();
|
||||
p->loadConfigWidget();
|
||||
}
|
||||
delete iter;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Stream::storeProtocolWidgets()
|
||||
{
|
||||
protocols.storeConfigWidgets();
|
||||
#if 0
|
||||
//protocols.storeConfigWidgets();
|
||||
foreach(const AbstractProtocol* proto, frameProtocol())
|
||||
{
|
||||
proto->storeConfigWidget();
|
||||
_iter->toFront();
|
||||
}
|
||||
#else
|
||||
ProtocolListIterator *iter;
|
||||
|
||||
iter = createProtocolListIterator();
|
||||
while (iter->hasNext())
|
||||
{
|
||||
AbstractProtocol* p = iter->next();
|
||||
p->storeConfigWidget();
|
||||
}
|
||||
delete iter;
|
||||
#endif
|
||||
}
|
||||
|
128
client/stream.h
128
client/stream.h
@ -13,135 +13,11 @@ class Stream : public StreamBase {
|
||||
//quint32 mId;
|
||||
|
||||
public:
|
||||
void loadProtocolWidgets();
|
||||
void storeProtocolWidgets();
|
||||
|
||||
public:
|
||||
enum FrameLengthMode {
|
||||
e_fl_fixed,
|
||||
e_fl_inc,
|
||||
e_fl_dec,
|
||||
e_fl_random
|
||||
};
|
||||
|
||||
enum SendUnit {
|
||||
e_su_packets,
|
||||
e_su_bursts
|
||||
};
|
||||
|
||||
enum SendMode {
|
||||
e_sm_fixed,
|
||||
e_sm_continuous
|
||||
};
|
||||
|
||||
enum NextWhat {
|
||||
e_nw_stop,
|
||||
e_nw_goto_next,
|
||||
e_nw_goto_id
|
||||
};
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Methods
|
||||
// -------------------------------------------------------
|
||||
Stream();
|
||||
~Stream();
|
||||
|
||||
// TODO: Below methods move to StreamBase???
|
||||
|
||||
bool operator < (const Stream &s) const
|
||||
{ return(mCore->ordinal() < s.mCore->ordinal()); }
|
||||
|
||||
quint32 id()
|
||||
{ return mStreamId->id();}
|
||||
bool setId(quint32 id)
|
||||
{ mStreamId->set_id(id); return true;}
|
||||
|
||||
#if 0 // FIXME(HI): needed?
|
||||
quint32 portId()
|
||||
{ return mCore->port_id();}
|
||||
bool setPortId(quint32 id)
|
||||
{ mCore->set_port_id(id); return true;}
|
||||
#endif
|
||||
|
||||
quint32 ordinal()
|
||||
{ return mCore->ordinal();}
|
||||
bool setOrdinal(quint32 ordinal)
|
||||
{ mCore->set_ordinal(ordinal); return true; }
|
||||
|
||||
bool isEnabled() const
|
||||
{ return mCore->is_enabled(); }
|
||||
bool setIsEnabled(bool flag)
|
||||
{ mCore->set_is_enabled(flag); return true; }
|
||||
|
||||
const QString name() const
|
||||
{ return QString().fromStdString(mCore->name()); }
|
||||
bool setName(QString name)
|
||||
{ mCore->set_name(name.toStdString()); return true; }
|
||||
|
||||
// Frame Length (includes FCS)
|
||||
FrameLengthMode lenMode()
|
||||
{ return (FrameLengthMode) mCore->len_mode(); }
|
||||
bool setLenMode(FrameLengthMode lenMode)
|
||||
{ mCore->set_len_mode(
|
||||
(OstProto::StreamCore::FrameLengthMode) lenMode); return true; }
|
||||
|
||||
quint16 frameLen()
|
||||
{ return mCore->frame_len(); }
|
||||
bool setFrameLen(quint16 frameLen)
|
||||
{ mCore->set_frame_len(frameLen); return true; }
|
||||
|
||||
quint16 frameLenMin()
|
||||
{ return mCore->frame_len_min(); }
|
||||
bool setFrameLenMin(quint16 frameLenMin)
|
||||
{ mCore->set_frame_len_min(frameLenMin); return true; }
|
||||
|
||||
quint16 frameLenMax()
|
||||
{ return mCore->frame_len_max(); }
|
||||
bool setFrameLenMax(quint16 frameLenMax)
|
||||
{ mCore->set_frame_len_max(frameLenMax); return true; }
|
||||
|
||||
SendUnit sendUnit()
|
||||
{ return (SendUnit) mControl->unit(); }
|
||||
bool setSendUnit(SendUnit sendUnit)
|
||||
{ mControl->set_unit(
|
||||
(OstProto::StreamControl::SendUnit) sendUnit); return true; }
|
||||
|
||||
SendMode sendMode()
|
||||
{ return (SendMode) mControl->mode(); }
|
||||
bool setSendMode(SendMode sendMode)
|
||||
{ mControl->set_mode(
|
||||
(OstProto::StreamControl::SendMode) sendMode); return true; }
|
||||
|
||||
NextWhat nextWhat()
|
||||
{ return (NextWhat) mControl->next(); }
|
||||
bool setNextWhat(NextWhat nextWhat)
|
||||
{ mControl->set_next(
|
||||
(OstProto::StreamControl::NextWhat) nextWhat); return true; }
|
||||
|
||||
quint32 numPackets()
|
||||
{ return (quint32) mControl->num_packets(); }
|
||||
bool setNumPackets(quint32 numPackets)
|
||||
{ mControl->set_num_packets(numPackets); return true; }
|
||||
|
||||
quint32 numBursts()
|
||||
{ return (quint32) mControl->num_bursts(); }
|
||||
bool setNumBursts(quint32 numBursts)
|
||||
{ mControl->set_num_bursts(numBursts); return true; }
|
||||
|
||||
quint32 burstSize()
|
||||
{ return (quint32) mControl->packets_per_burst(); }
|
||||
bool setBurstSize(quint32 packetsPerBurst)
|
||||
{ mControl->set_packets_per_burst(packetsPerBurst); return true; }
|
||||
|
||||
quint32 packetRate()
|
||||
{ return (quint32) mControl->packets_per_sec(); }
|
||||
bool setPacketRate(quint32 packetsPerSec)
|
||||
{ mControl->set_packets_per_sec(packetsPerSec); return true; }
|
||||
|
||||
quint32 burstRate()
|
||||
{ return (quint32) mControl->bursts_per_sec(); }
|
||||
bool setBurstRate(quint32 burstsPerSec)
|
||||
{ mControl->set_bursts_per_sec(burstsPerSec); return true; }
|
||||
void loadProtocolWidgets();
|
||||
void storeProtocolWidgets();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,9 +1,16 @@
|
||||
#include <QHostAddress>
|
||||
|
||||
#include "streamconfigdialog.h"
|
||||
#include "stream.h"
|
||||
#include "abstractprotocol.h"
|
||||
#include "protocollistiterator.h"
|
||||
|
||||
#include "modeltest.h"
|
||||
|
||||
// FIXME(HI) - remove
|
||||
#include "../common/protocolmanager.h"
|
||||
extern ProtocolManager OstProtocolManager;
|
||||
|
||||
int StreamConfigDialog::lastTopLevelTabIndex = 0;
|
||||
int StreamConfigDialog::lastProtoTabIndex = 0;
|
||||
|
||||
@ -15,6 +22,7 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
|
||||
mpStream = new Stream;
|
||||
mPort.streamByIndex(mCurrentStreamIndex)->protoDataCopyInto(s);
|
||||
mpStream->protoDataCopyFrom(s);
|
||||
_iter = mpStream->createProtocolListIterator();
|
||||
|
||||
setupUi(this);
|
||||
setupUiExtra();
|
||||
@ -97,8 +105,12 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
|
||||
// Force L4 Protocol = None if L3 Protocol is set to ARP
|
||||
connect(rbL3Arp, SIGNAL(toggled(bool)), rbL4None, SLOT(setChecked(bool)));
|
||||
|
||||
mpAvailableProtocolsModel = new QStringListModel(
|
||||
OstProtocolManager.protocolDatabase(), this);
|
||||
lvAllProtocols->setModel(mpAvailableProtocolsModel);
|
||||
|
||||
LoadCurrentStream();
|
||||
mpPacketModel = new PacketModel(QList<AbstractProtocol*>(), this);
|
||||
mpPacketModel = new PacketModel(this);
|
||||
tvPacketTree->setModel(mpPacketModel);
|
||||
mpPacketModelTester = new ModelTest(mpPacketModel);
|
||||
tvPacketTree->header()->hide();
|
||||
@ -134,6 +146,7 @@ void StreamConfigDialog::setupUiExtra()
|
||||
QRegExp reHex4B("[0-9,a-f,A-F]{1,8}");
|
||||
QRegExp reMac("([0-9,a-f,A-F]{2,2}[:-]){5,5}[0-9,a-f,A-F]{2,2}");
|
||||
|
||||
#if 0 // MPS - temp mask
|
||||
// Add the Payload widget to the dialog
|
||||
{
|
||||
QGridLayout *layout;
|
||||
@ -143,6 +156,7 @@ void StreamConfigDialog::setupUiExtra()
|
||||
layout->addWidget(mpStream->protocol(52)->configWidget(), 0, 1);
|
||||
qDebug("setupUi wgt = %p", mpStream->protocol(52)->configWidget());
|
||||
}
|
||||
#endif
|
||||
|
||||
// ---- Setup default stuff that cannot be done in designer ----
|
||||
gbVlan->setDisabled(true);
|
||||
@ -199,6 +213,7 @@ StreamConfigDialog::~StreamConfigDialog()
|
||||
delete mpPacketModelTester;
|
||||
delete mpPacketModel;
|
||||
|
||||
#if 0 // MPS - temp mask
|
||||
// Remove payload data widget so that it is not deleted when this object
|
||||
// is destroyed
|
||||
{
|
||||
@ -209,6 +224,7 @@ StreamConfigDialog::~StreamConfigDialog()
|
||||
mpStream->protocol(52)->configWidget()->setParent(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Remove any existing widget on the L2-L4 Tabs lest they are deleted
|
||||
// when this object is destoryed
|
||||
@ -232,53 +248,95 @@ StreamConfigDialog::~StreamConfigDialog()
|
||||
delete bgL3Proto;
|
||||
delete bgL4Proto;
|
||||
|
||||
delete _iter;
|
||||
delete mpStream;
|
||||
}
|
||||
|
||||
void StreamConfigDialog::updateSelectedProtocols()
|
||||
{
|
||||
mSelectedProtocols.clear();
|
||||
#define CHKINS(p) \
|
||||
{ \
|
||||
if (_iter->hasNext() && (_iter->peekNext()->protocolNumber() == OstProto::Protocol::k##p##FieldNumber)) \
|
||||
_iter->next(); \
|
||||
else \
|
||||
_iter->insert(OstProtocolManager.createProtocol(OstProto::Protocol::k##p##FieldNumber, mpStream)); \
|
||||
}
|
||||
|
||||
// FIXME: Hardcoded numbers!
|
||||
_iter->toFront();
|
||||
#if 1
|
||||
qDebug("Before Update");
|
||||
while (_iter->hasNext())
|
||||
{
|
||||
AbstractProtocol* p;
|
||||
|
||||
p = _iter->next();
|
||||
qDebug("%p:[%d]", p, p->protocolNumber());
|
||||
}
|
||||
|
||||
_iter->toFront();
|
||||
#endif
|
||||
|
||||
// Mac
|
||||
mSelectedProtocols.append(51);
|
||||
CHKINS(Mac)
|
||||
|
||||
if (cbCVlan->isEnabled() && cbCVlan->isChecked())
|
||||
mSelectedProtocols.append(126);
|
||||
CHKINS(Vlan);
|
||||
|
||||
if (rbFtEthernet2->isChecked())
|
||||
mSelectedProtocols.append(121);
|
||||
CHKINS(Eth2)
|
||||
else if (rbFt802Dot3Raw->isChecked())
|
||||
mSelectedProtocols.append(122);
|
||||
CHKINS(Dot3)
|
||||
else if (rbFt802Dot3Llc->isChecked())
|
||||
{
|
||||
mSelectedProtocols.append(122);
|
||||
mSelectedProtocols.append(123);
|
||||
CHKINS(Dot3);
|
||||
CHKINS(Llc);
|
||||
}
|
||||
else if (rbFtLlcSnap->isChecked())
|
||||
{
|
||||
mSelectedProtocols.append(122);
|
||||
mSelectedProtocols.append(123);
|
||||
mSelectedProtocols.append(124);
|
||||
CHKINS(Dot3);
|
||||
CHKINS(Llc);
|
||||
CHKINS(Snap);
|
||||
}
|
||||
|
||||
if (rbL3Ipv4->isChecked())
|
||||
mSelectedProtocols.append(130);
|
||||
CHKINS(Ip4)
|
||||
else if (rbL3Arp->isChecked())
|
||||
mSelectedProtocols.append(131);
|
||||
CHKINS(Arp)
|
||||
|
||||
if (rbL4Tcp->isChecked())
|
||||
mSelectedProtocols.append(140);
|
||||
CHKINS(Tcp)
|
||||
else if (rbL4Udp->isChecked())
|
||||
mSelectedProtocols.append(141);
|
||||
CHKINS(Udp)
|
||||
else if (rbL4Icmp->isChecked())
|
||||
mSelectedProtocols.append(142);
|
||||
CHKINS(Icmp)
|
||||
else if (rbL4Igmp->isChecked())
|
||||
mSelectedProtocols.append(143);
|
||||
CHKINS(Igmp)
|
||||
|
||||
// Payload
|
||||
mSelectedProtocols.append(52);
|
||||
CHKINS(Payload)
|
||||
|
||||
// Remove all protocols, if any, beyond payload
|
||||
while (_iter->hasNext())
|
||||
{
|
||||
_iter->next();
|
||||
_iter->remove();
|
||||
}
|
||||
|
||||
|
||||
#if 1
|
||||
qDebug("After Update");
|
||||
_iter->toFront();
|
||||
while (_iter->hasNext())
|
||||
{
|
||||
AbstractProtocol* p;
|
||||
|
||||
p = _iter->next();
|
||||
qDebug("%p:[%d]", p, p->protocolNumber());
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef CHKINS
|
||||
|
||||
}
|
||||
|
||||
void StreamConfigDialog::updateContents()
|
||||
@ -345,22 +403,17 @@ void StreamConfigDialog::on_pbNext_clicked()
|
||||
|
||||
void StreamConfigDialog::on_twTopLevel_currentChanged(int index)
|
||||
{
|
||||
QList<AbstractProtocol*> protoList;
|
||||
|
||||
// We only process the "Packet View" tab
|
||||
if (index != 2)
|
||||
return;
|
||||
|
||||
updateContents();
|
||||
foreach(int i, mSelectedProtocols)
|
||||
if (mpStream->protocol(i))
|
||||
protoList.append(mpStream->protocol(i));
|
||||
|
||||
mpPacketModel->setSelectedProtocols(protoList);
|
||||
mpPacketModel->setSelectedProtocols(*_iter);
|
||||
}
|
||||
|
||||
void StreamConfigDialog::on_twProto_currentChanged(int index)
|
||||
{
|
||||
#if 0 // MPS - temp mask
|
||||
QLayout *layout;
|
||||
QList<QWidget*> wl;
|
||||
|
||||
@ -461,6 +514,39 @@ void StreamConfigDialog::on_twProto_currentChanged(int index)
|
||||
}
|
||||
break;
|
||||
}
|
||||
#else
|
||||
int selTab;
|
||||
|
||||
qDebug("In %s (tab index = %d)", __FUNCTION__, index);
|
||||
// We need to process only index 4 i.e. the Protocol Data tab
|
||||
if (index != 4)
|
||||
return;
|
||||
|
||||
// Hide the ToolBox before modifying it - otherwise we have a crash !!!
|
||||
tbProtocolData->hide();
|
||||
|
||||
selTab = tbProtocolData->currentIndex();
|
||||
|
||||
// Remove any existing widget on the activated tab
|
||||
while (tbProtocolData->count() > 0)
|
||||
{
|
||||
QWidget* w = tbProtocolData->widget(0);
|
||||
tbProtocolData->removeItem(0);
|
||||
w->setParent(0);
|
||||
}
|
||||
|
||||
_iter->toFront();
|
||||
while (_iter->hasNext())
|
||||
{
|
||||
AbstractProtocol* p = _iter->next();
|
||||
tbProtocolData->addItem(p->configWidget(), p->name());
|
||||
}
|
||||
|
||||
if (selTab < tbProtocolData->count())
|
||||
tbProtocolData->setCurrentIndex(selTab);
|
||||
|
||||
tbProtocolData->show();
|
||||
#endif
|
||||
}
|
||||
|
||||
void StreamConfigDialog::update_NumPacketsAndNumBursts()
|
||||
@ -504,6 +590,7 @@ void StreamConfigDialog::LoadCurrentStream()
|
||||
lePktLenMax->setText(str.setNum(mpStream->frameLenMax()));
|
||||
}
|
||||
|
||||
#if 0 // MPS - temp mask
|
||||
// Protocols
|
||||
{
|
||||
int i;
|
||||
@ -620,9 +707,130 @@ void StreamConfigDialog::LoadCurrentStream()
|
||||
|
||||
_proto_parse_done:
|
||||
Q_ASSERT(i == mSelectedProtocols.size());
|
||||
|
||||
mpStream->loadProtocolWidgets();
|
||||
}
|
||||
#else
|
||||
// Protocols
|
||||
{
|
||||
qDebug("Loading - current list");
|
||||
_iter->toFront();
|
||||
while(_iter->hasNext())
|
||||
{
|
||||
AbstractProtocol* p = _iter->next();
|
||||
qDebug("%p -- %d", p, p->protocolNumber());
|
||||
}
|
||||
_iter->toFront();
|
||||
|
||||
#define CHK(p) (_iter->hasNext() && _iter->peekNext()->protocolNumber() == p)
|
||||
|
||||
Q_ASSERT(CHK(51)); // Mac
|
||||
_iter->next();
|
||||
|
||||
// VLAN
|
||||
if (CHK(126)) // VLAN
|
||||
{
|
||||
cbCVlan->setChecked(true);
|
||||
_iter->next();
|
||||
}
|
||||
|
||||
if (CHK(52)) // Payload
|
||||
{
|
||||
_iter->next();
|
||||
goto _proto_parse_done;
|
||||
}
|
||||
else if (CHK(121)) // Eth2
|
||||
{
|
||||
rbFtEthernet2->setChecked(true);
|
||||
_iter->next();
|
||||
}
|
||||
else if (CHK(122)) // 802.3 RAW
|
||||
{
|
||||
_iter->next();
|
||||
if (CHK(123)) // 802.3 LLC
|
||||
{
|
||||
_iter->next();
|
||||
if (CHK(124)) // SNAP
|
||||
{
|
||||
rbFtLlcSnap->setChecked(true);
|
||||
_iter->next();
|
||||
}
|
||||
else
|
||||
{
|
||||
rbFt802Dot3Llc->setChecked(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rbFt802Dot3Raw->setChecked(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
rbFtNone->setChecked(true);
|
||||
|
||||
|
||||
// L3
|
||||
if (CHK(52)) // Payload
|
||||
{
|
||||
_iter->next();
|
||||
goto _proto_parse_done;
|
||||
}
|
||||
else if (CHK(130)) // IP4
|
||||
{
|
||||
rbL3Ipv4->setChecked(true);
|
||||
_iter->next();
|
||||
}
|
||||
else if (CHK(131)) // ARP
|
||||
{
|
||||
rbL3Arp->setChecked(true);
|
||||
_iter->next();
|
||||
}
|
||||
else
|
||||
rbL3None->setChecked(true);
|
||||
|
||||
if (!_iter->hasNext())
|
||||
goto _proto_parse_done;
|
||||
|
||||
// L4
|
||||
if (CHK(52)) // Payload
|
||||
{
|
||||
_iter->next();
|
||||
goto _proto_parse_done;
|
||||
}
|
||||
else if (CHK(140)) // TCP
|
||||
{
|
||||
rbL4Tcp->setChecked(true);
|
||||
_iter->next();
|
||||
}
|
||||
else if (CHK(141)) // UDP
|
||||
{
|
||||
rbL4Udp->setChecked(true);
|
||||
_iter->next();
|
||||
}
|
||||
else if (CHK(142)) // ICMP
|
||||
{
|
||||
rbL4Icmp->setChecked(true);
|
||||
_iter->next();
|
||||
}
|
||||
else if (CHK(143)) // IGMP
|
||||
{
|
||||
rbL4Igmp->setChecked(true);
|
||||
_iter->next();
|
||||
}
|
||||
else
|
||||
rbL4None->setChecked(true);
|
||||
|
||||
Q_ASSERT(CHK(52)); // Payload
|
||||
_iter->next();
|
||||
|
||||
_proto_parse_done:
|
||||
Q_ASSERT(!_iter->hasNext());
|
||||
mpStream->loadProtocolWidgets();
|
||||
|
||||
#undef CHK
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
// Stream Control
|
||||
{
|
||||
@ -673,6 +881,7 @@ _proto_parse_done:
|
||||
// TODO(MED): Change this when we support goto to specific stream
|
||||
leStreamId->setText(QString("0"));
|
||||
}
|
||||
qDebug("loading stream done");
|
||||
}
|
||||
|
||||
void StreamConfigDialog::StoreCurrentStream()
|
||||
@ -692,7 +901,7 @@ void StreamConfigDialog::StoreCurrentStream()
|
||||
// Protocols
|
||||
{
|
||||
updateSelectedProtocols();
|
||||
pStream->setFrameProtocol(mSelectedProtocols);
|
||||
//pStream->setFrameProtocol(mSelectedProtocols);
|
||||
pStream->storeProtocolWidgets();
|
||||
}
|
||||
|
||||
|
@ -27,21 +27,22 @@ public:
|
||||
~StreamConfigDialog();
|
||||
|
||||
private:
|
||||
//QList<Stream> *mpStreamList;
|
||||
|
||||
QButtonGroup *bgFrameType;
|
||||
QButtonGroup *bgL3Proto;
|
||||
QButtonGroup *bgL4Proto;
|
||||
|
||||
QStringListModel *mpAvailableProtocolsModel;
|
||||
|
||||
Port& mPort;
|
||||
uint mCurrentStreamIndex;
|
||||
|
||||
Stream *mpStream;
|
||||
QList<int> mSelectedProtocols;
|
||||
ProtocolListIterator *_iter;
|
||||
|
||||
PacketModel *mpPacketModel;
|
||||
ModelTest *mpPacketModelTester;
|
||||
|
||||
|
||||
// The following static variables are used to track the "selected" tab
|
||||
// for the various tab widgets so that it can be restored when the dialog
|
||||
// is opened the next time
|
||||
|
@ -12,6 +12,12 @@
|
||||
<height>589</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>Edit Stream</string>
|
||||
</property>
|
||||
@ -56,7 +62,7 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="2" >
|
||||
<item row="0" column="1" >
|
||||
<widget class="QGroupBox" name="gbFrameLength" >
|
||||
<property name="title" >
|
||||
<string>Frame Length (including FCS)</string>
|
||||
@ -157,10 +163,10 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3" >
|
||||
<item row="1" column="0" colspan="2" >
|
||||
<widget class="QTabWidget" name="twProto" >
|
||||
<property name="currentIndex" >
|
||||
<number>0</number>
|
||||
<number>4</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_7" >
|
||||
<attribute name="title" >
|
||||
@ -516,6 +522,20 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" />
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab" >
|
||||
<attribute name="title" >
|
||||
<string>Protocol Data</string>
|
||||
</attribute>
|
||||
<layout class="QHBoxLayout" >
|
||||
<item>
|
||||
<widget class="QToolBox" name="tbProtocolData" >
|
||||
<property name="currentIndex" >
|
||||
<number>-1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -136,7 +136,7 @@ bool StreamModel::setData(const QModelIndex &index, const QVariant &value, int r
|
||||
return true;
|
||||
|
||||
case StreamStatus:
|
||||
mCurrentPort->streamByIndex(index.row())->setIsEnabled(value.toBool());
|
||||
mCurrentPort->streamByIndex(index.row())->setEnabled(value.toBool());
|
||||
emit(dataChanged(index, index));
|
||||
return true;
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
#include <qendian.h>
|
||||
|
||||
#include "abstractprotocol.h"
|
||||
#include "streambase.h"
|
||||
#include "protocollistiterator.h"
|
||||
|
||||
/*!
|
||||
\class AbstractProtocol
|
||||
@ -19,13 +22,9 @@
|
||||
- metaFieldCount()
|
||||
- isMetaField()
|
||||
*/
|
||||
AbstractProtocol::AbstractProtocol(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent)
|
||||
: frameProtocols(frameProtoList)
|
||||
AbstractProtocol::AbstractProtocol(StreamBase *stream)
|
||||
{
|
||||
qDebug("%s: &frameproto = %p/%p (sz:%d)", __FUNCTION__, &frameProtocols, &frameProtoList, frameProtocols.size());
|
||||
stream = parent;
|
||||
mpStream = stream;
|
||||
metaCount = -1;
|
||||
protoSize = -1;
|
||||
}
|
||||
@ -34,13 +33,17 @@ AbstractProtocol::~AbstractProtocol()
|
||||
{
|
||||
}
|
||||
|
||||
AbstractProtocol* AbstractProtocol::createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore)
|
||||
AbstractProtocol* AbstractProtocol::createInstance(StreamBase *stream)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
quint32 AbstractProtocol::protocolNumber() const
|
||||
{
|
||||
qDebug("Something wrong!!!");
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn virtual void protoDataCopyInto(OstProto::OstProto::StreamCore &stream) = 0;
|
||||
|
||||
@ -182,13 +185,14 @@ quint32 AbstractProtocol::protocolId(ProtocolIdType type) const
|
||||
quint32 AbstractProtocol::payloadProtocolId(ProtocolIdType type) const
|
||||
{
|
||||
quint32 id = 0xFFFFFFFF;
|
||||
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols);
|
||||
ProtocolListIterator *iter = mpStream->createProtocolListIterator();
|
||||
|
||||
if (iter.findNext(this))
|
||||
if (iter->findNext(this))
|
||||
{
|
||||
if (iter.hasNext())
|
||||
id = iter.next()->protocolId(type);
|
||||
if (iter->hasNext())
|
||||
id = iter->next()->protocolId(type);
|
||||
}
|
||||
delete iter;
|
||||
|
||||
qDebug("%s: payloadProtocolId = %u", __FUNCTION__, id);
|
||||
return id;
|
||||
@ -215,16 +219,17 @@ int AbstractProtocol::protocolFrameSize() const
|
||||
int AbstractProtocol::protocolFrameOffset() const
|
||||
{
|
||||
int size = 0;
|
||||
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols);
|
||||
ProtocolListIterator *iter = mpStream->createProtocolListIterator();
|
||||
|
||||
if (iter.findNext(this))
|
||||
if (iter->findNext(this))
|
||||
{
|
||||
iter.previous();
|
||||
while (iter.hasPrevious())
|
||||
size += iter.previous()->protocolFrameSize();
|
||||
iter->previous();
|
||||
while (iter->hasPrevious())
|
||||
size += iter->previous()->protocolFrameSize();
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
delete iter;
|
||||
|
||||
qDebug("%s: ofs = %d", __FUNCTION__, size);
|
||||
return size;
|
||||
@ -234,15 +239,16 @@ int AbstractProtocol::protocolFramePayloadSize() const
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols);
|
||||
ProtocolListIterator *iter = mpStream->createProtocolListIterator();
|
||||
|
||||
if (iter.findNext(this))
|
||||
if (iter->findNext(this))
|
||||
{
|
||||
while (iter.hasNext())
|
||||
size += iter.next()->protocolFrameSize();
|
||||
while (iter->hasNext())
|
||||
size += iter->next()->protocolFrameSize();
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
delete iter;
|
||||
|
||||
qDebug("%s: payloadSize = %d", __FUNCTION__, size);
|
||||
return size;
|
||||
@ -421,17 +427,18 @@ quint32 AbstractProtocol::protocolFrameHeaderCksum(int streamIndex,
|
||||
CksumType cksumType) const
|
||||
{
|
||||
quint32 sum = 0xFFFF;
|
||||
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols);
|
||||
ProtocolListIterator *iter = mpStream->createProtocolListIterator();
|
||||
|
||||
Q_ASSERT(cksumType == CksumIpPseudo);
|
||||
|
||||
if (iter.findNext(this))
|
||||
if (iter->findNext(this))
|
||||
{
|
||||
iter.previous();
|
||||
if (iter.hasPrevious())
|
||||
sum = iter.previous()->protocolFrameCksum(streamIndex,
|
||||
iter->previous();
|
||||
if (iter->hasPrevious())
|
||||
sum = iter->previous()->protocolFrameCksum(streamIndex,
|
||||
CksumIpPseudo);
|
||||
}
|
||||
delete iter;
|
||||
|
||||
while(sum>>16)
|
||||
sum = (sum & 0xFFFF) + (sum >> 16);
|
||||
@ -444,20 +451,21 @@ quint32 AbstractProtocol::protocolFramePayloadCksum(int streamIndex,
|
||||
{
|
||||
quint32 sum = 0;
|
||||
quint16 cksum;
|
||||
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols);
|
||||
ProtocolListIterator *iter = mpStream->createProtocolListIterator();
|
||||
|
||||
Q_ASSERT(cksumType == CksumIp);
|
||||
|
||||
if (iter.findNext(this))
|
||||
if (iter->findNext(this))
|
||||
{
|
||||
while (iter.hasNext())
|
||||
while (iter->hasNext())
|
||||
{
|
||||
cksum = iter.next()->protocolFrameCksum(streamIndex, CksumIp);
|
||||
cksum = iter->next()->protocolFrameCksum(streamIndex, CksumIp);
|
||||
sum += (quint16) ~cksum;
|
||||
}
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
delete iter;
|
||||
|
||||
while(sum>>16)
|
||||
sum = (sum & 0xFFFF) + (sum >> 16);
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <QFlags>
|
||||
|
||||
//#include "../rpc/pbhelper.h"
|
||||
#include "../common/protocol.pb.h"
|
||||
#include "protocol.pb.h"
|
||||
|
||||
#define BASE_BIN (2)
|
||||
#define BASE_OCT (8)
|
||||
@ -19,10 +19,7 @@
|
||||
#define uintToHexStr(num, bytes) \
|
||||
QString("%1").arg(num, bytes*2, BASE_HEX, QChar('0'))
|
||||
|
||||
class OstProto::StreamCore;
|
||||
class AbstractProtocol;
|
||||
|
||||
typedef QLinkedList<const AbstractProtocol*> ProtocolList;
|
||||
class StreamBase;
|
||||
|
||||
class AbstractProtocol
|
||||
{
|
||||
@ -32,8 +29,7 @@ private:
|
||||
mutable QString protoAbbr;
|
||||
|
||||
protected:
|
||||
OstProto::StreamCore *stream;
|
||||
ProtocolList &frameProtocols;
|
||||
StreamBase *mpStream;
|
||||
|
||||
public:
|
||||
enum FieldFlag {
|
||||
@ -65,16 +61,14 @@ public:
|
||||
CksumMax
|
||||
};
|
||||
|
||||
AbstractProtocol(ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent = 0);
|
||||
AbstractProtocol(StreamBase *stream);
|
||||
virtual ~AbstractProtocol();
|
||||
|
||||
static AbstractProtocol* createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore = 0);
|
||||
static AbstractProtocol* createInstance(StreamBase *stream);
|
||||
virtual quint32 protocolNumber() const;
|
||||
|
||||
virtual void protoDataCopyInto(OstProto::Stream &stream) = 0;
|
||||
virtual void protoDataCopyFrom(const OstProto::Stream &stream) = 0;
|
||||
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const = 0;
|
||||
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol) = 0;
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
@ -109,7 +103,6 @@ public:
|
||||
virtual void loadConfigWidget() = 0;
|
||||
virtual void storeConfigWidget() = 0;
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractProtocol::FieldFlags);
|
||||
|
||||
#endif
|
||||
|
@ -1,49 +1,49 @@
|
||||
#include <qendian.h>
|
||||
#include <QHostAddress>
|
||||
|
||||
#include "Dot3.h"
|
||||
#include "dot3.h"
|
||||
#include "streambase.h"
|
||||
|
||||
#define SZ_FCS 4
|
||||
|
||||
Dot3ConfigForm *Dot3Protocol::configForm = NULL;
|
||||
|
||||
Dot3ConfigForm::Dot3ConfigForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
Dot3Protocol::Dot3Protocol(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent)
|
||||
: AbstractProtocol(frameProtoList, parent)
|
||||
Dot3Protocol::Dot3Protocol(StreamBase *stream)
|
||||
: AbstractProtocol(stream)
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new Dot3ConfigForm;
|
||||
configForm = NULL;
|
||||
}
|
||||
|
||||
Dot3Protocol::~Dot3Protocol()
|
||||
{
|
||||
delete configForm;
|
||||
}
|
||||
|
||||
AbstractProtocol* Dot3Protocol::createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore)
|
||||
AbstractProtocol* Dot3Protocol::createInstance(StreamBase *stream)
|
||||
{
|
||||
return new Dot3Protocol(frameProtoList, streamCore);
|
||||
return new Dot3Protocol(stream);
|
||||
}
|
||||
|
||||
void Dot3Protocol::protoDataCopyInto(OstProto::Stream &stream)
|
||||
quint32 Dot3Protocol::protocolNumber() const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
stream.MutableExtension(OstProto::dot3)->CopyFrom(data);
|
||||
return OstProto::Protocol::kDot3FieldNumber;
|
||||
}
|
||||
|
||||
void Dot3Protocol::protoDataCopyFrom(const OstProto::Stream &stream)
|
||||
void Dot3Protocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
if (stream.HasExtension(OstProto::dot3))
|
||||
data.MergeFrom(stream.GetExtension(OstProto::dot3));
|
||||
protocol.MutableExtension(OstProto::dot3)->CopyFrom(data);
|
||||
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
||||
}
|
||||
|
||||
void Dot3Protocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
||||
{
|
||||
if (protocol.protocol_id().id() == protocolNumber() &&
|
||||
protocol.HasExtension(OstProto::dot3))
|
||||
data.MergeFrom(protocol.GetExtension(OstProto::dot3));
|
||||
}
|
||||
|
||||
QString Dot3Protocol::name() const
|
||||
@ -75,14 +75,14 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
|
||||
{
|
||||
quint16 len;
|
||||
|
||||
len = stream->frame_len() - SZ_FCS;
|
||||
len = mpStream->frameLen() - SZ_FCS;
|
||||
return len;
|
||||
}
|
||||
case FieldTextValue:
|
||||
{
|
||||
quint16 len;
|
||||
|
||||
len = stream->frame_len() - SZ_FCS;
|
||||
len = mpStream->frameLen() - SZ_FCS;
|
||||
return QString("%1").arg(len);
|
||||
}
|
||||
case FieldFrameValue:
|
||||
@ -90,7 +90,7 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
|
||||
quint16 len;
|
||||
QByteArray fv;
|
||||
|
||||
len = stream->frame_len() - SZ_FCS;
|
||||
len = mpStream->frameLen() - SZ_FCS;
|
||||
fv.resize(2);
|
||||
qToBigEndian(len, (uchar*) fv.data());
|
||||
return fv;
|
||||
@ -117,11 +117,15 @@ bool Dot3Protocol::setFieldData(int index, const QVariant &value,
|
||||
|
||||
QWidget* Dot3Protocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new Dot3ConfigForm;
|
||||
return configForm;
|
||||
}
|
||||
|
||||
void Dot3Protocol::loadConfigWidget()
|
||||
{
|
||||
configWidget();
|
||||
|
||||
configForm->leLength->setText(
|
||||
fieldData(dot3_length, FieldValue).toString());
|
||||
}
|
||||
@ -130,6 +134,8 @@ void Dot3Protocol::storeConfigWidget()
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
configWidget();
|
||||
|
||||
data.set_length(configForm->leLength->text().toULong(&isOk));
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ class Dot3Protocol : public AbstractProtocol
|
||||
{
|
||||
private:
|
||||
OstProto::Dot3 data;
|
||||
static Dot3ConfigForm *configForm;
|
||||
Dot3ConfigForm *configForm;
|
||||
enum Dot3field
|
||||
{
|
||||
dot3_length,
|
||||
@ -26,16 +26,14 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
Dot3Protocol(ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent = 0);
|
||||
Dot3Protocol(StreamBase *stream);
|
||||
virtual ~Dot3Protocol();
|
||||
|
||||
static AbstractProtocol* createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore = 0);
|
||||
static AbstractProtocol* createInstance(StreamBase *stream);
|
||||
virtual quint32 protocolNumber() const;
|
||||
|
||||
virtual void protoDataCopyInto(OstProto::Stream &stream);
|
||||
virtual void protoDataCopyFrom(const OstProto::Stream &stream);
|
||||
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
|
||||
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
@ -7,6 +7,6 @@ message Dot3 {
|
||||
optional uint32 length = 1;
|
||||
}
|
||||
|
||||
extend Stream {
|
||||
extend Protocol {
|
||||
optional Dot3 dot3 = 122;
|
||||
}
|
||||
|
@ -3,45 +3,44 @@
|
||||
|
||||
#include "eth2.h"
|
||||
|
||||
Eth2ConfigForm *Eth2Protocol::configForm = NULL;
|
||||
|
||||
Eth2ConfigForm::Eth2ConfigForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
Eth2Protocol::Eth2Protocol(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent)
|
||||
: AbstractProtocol(frameProtoList, parent)
|
||||
Eth2Protocol::Eth2Protocol(StreamBase *stream)
|
||||
: AbstractProtocol(stream)
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new Eth2ConfigForm;
|
||||
configForm = NULL;
|
||||
}
|
||||
|
||||
Eth2Protocol::~Eth2Protocol()
|
||||
{
|
||||
delete configForm;
|
||||
}
|
||||
|
||||
AbstractProtocol* Eth2Protocol::createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore)
|
||||
AbstractProtocol* Eth2Protocol::createInstance(StreamBase *stream)
|
||||
{
|
||||
return new Eth2Protocol(frameProtoList, streamCore);
|
||||
return new Eth2Protocol(stream);
|
||||
}
|
||||
|
||||
void Eth2Protocol::protoDataCopyInto(OstProto::Stream &stream)
|
||||
quint32 Eth2Protocol::protocolNumber() const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
stream.MutableExtension(OstProto::eth2)->CopyFrom(data);
|
||||
return OstProto::Protocol::kEth2FieldNumber;
|
||||
}
|
||||
|
||||
void Eth2Protocol::protoDataCopyFrom(const OstProto::Stream &stream)
|
||||
void Eth2Protocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
if (stream.HasExtension(OstProto::eth2))
|
||||
data.MergeFrom(stream.GetExtension(OstProto::eth2));
|
||||
protocol.MutableExtension(OstProto::eth2)->CopyFrom(data);
|
||||
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
||||
}
|
||||
|
||||
void Eth2Protocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
||||
{
|
||||
if (protocol.protocol_id().id() == protocolNumber() &&
|
||||
protocol.HasExtension(OstProto::eth2))
|
||||
data.MergeFrom(protocol.GetExtension(OstProto::eth2));
|
||||
}
|
||||
|
||||
QString Eth2Protocol::name() const
|
||||
@ -121,11 +120,15 @@ bool Eth2Protocol::setFieldData(int index, const QVariant &value,
|
||||
|
||||
QWidget* Eth2Protocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new Eth2ConfigForm;
|
||||
return configForm;
|
||||
}
|
||||
|
||||
void Eth2Protocol::loadConfigWidget()
|
||||
{
|
||||
configWidget();
|
||||
|
||||
configForm->leType->setText(uintToHexStr(
|
||||
fieldData(eth2_type, FieldValue).toUInt(), 2));
|
||||
}
|
||||
@ -134,6 +137,8 @@ void Eth2Protocol::storeConfigWidget()
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
configWidget();
|
||||
|
||||
data.set_type(configForm->leType->text().remove(QChar(' ')).toULong(&isOk, 16));
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ class Eth2Protocol : public AbstractProtocol
|
||||
{
|
||||
private:
|
||||
OstProto::Eth2 data;
|
||||
static Eth2ConfigForm *configForm;
|
||||
Eth2ConfigForm *configForm;
|
||||
enum eth2field
|
||||
{
|
||||
eth2_type = 0,
|
||||
@ -26,16 +26,14 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
Eth2Protocol(ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent = 0);
|
||||
Eth2Protocol(StreamBase *stream);
|
||||
virtual ~Eth2Protocol();
|
||||
|
||||
static AbstractProtocol* createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore = 0);
|
||||
static AbstractProtocol* createInstance(StreamBase *stream);
|
||||
virtual quint32 protocolNumber() const;
|
||||
|
||||
virtual void protoDataCopyInto(OstProto::Stream &stream);
|
||||
virtual void protoDataCopyFrom(const OstProto::Stream &stream);
|
||||
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
|
||||
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
@ -7,6 +7,6 @@ message Eth2 {
|
||||
optional uint32 type = 1;
|
||||
}
|
||||
|
||||
extend Stream {
|
||||
extend Protocol {
|
||||
optional Eth2 eth2 = 121;
|
||||
}
|
||||
|
@ -5,21 +5,15 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>166</width>
|
||||
<height>72</height>
|
||||
<width>267</width>
|
||||
<height>64</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" >
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox" >
|
||||
<property name="title" >
|
||||
<string>Ethernet II</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" >
|
||||
<item>
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" >
|
||||
<widget class="QLabel" name="lblType" >
|
||||
<property name="text" >
|
||||
<string>Ethernet Type</string>
|
||||
@ -29,7 +23,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="0" column="1" >
|
||||
<widget class="QLineEdit" name="leType" >
|
||||
<property name="enabled" >
|
||||
<bool>false</bool>
|
||||
@ -39,10 +33,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item row="0" column="2" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -55,6 +46,19 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
#include "ip4.h"
|
||||
|
||||
Ip4ConfigForm *Ip4Protocol::configForm = NULL;
|
||||
|
||||
Ip4ConfigForm::Ip4ConfigForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
@ -18,6 +16,11 @@ Ip4ConfigForm::Ip4ConfigForm(QWidget *parent)
|
||||
this, SLOT(on_cmbIpDstAddrMode_currentIndexChanged(int)));
|
||||
}
|
||||
|
||||
Ip4ConfigForm::~Ip4ConfigForm()
|
||||
{
|
||||
qDebug("IPv4 Config Form destructor called");
|
||||
}
|
||||
|
||||
void Ip4ConfigForm::on_cmbIpSrcAddrMode_currentIndexChanged(int index)
|
||||
{
|
||||
if (index == OstProto::Ip4::e_im_fixed)
|
||||
@ -46,42 +49,38 @@ void Ip4ConfigForm::on_cmbIpDstAddrMode_currentIndexChanged(int index)
|
||||
}
|
||||
}
|
||||
|
||||
Ip4Protocol::Ip4Protocol(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent)
|
||||
: AbstractProtocol(frameProtoList, parent)
|
||||
Ip4Protocol::Ip4Protocol(StreamBase *stream)
|
||||
: AbstractProtocol(stream)
|
||||
{
|
||||
#if 0
|
||||
PbHelper pbh;
|
||||
|
||||
pbh.ForceSetSingularDefault(&data);
|
||||
#endif
|
||||
if (configForm == NULL)
|
||||
configForm = new Ip4ConfigForm;
|
||||
configForm = NULL;
|
||||
}
|
||||
|
||||
Ip4Protocol::~Ip4Protocol()
|
||||
{
|
||||
delete configForm;
|
||||
}
|
||||
|
||||
AbstractProtocol* Ip4Protocol::createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore)
|
||||
AbstractProtocol* Ip4Protocol::createInstance(StreamBase *stream)
|
||||
{
|
||||
return new Ip4Protocol(frameProtoList, streamCore);
|
||||
return new Ip4Protocol(stream);
|
||||
}
|
||||
|
||||
void Ip4Protocol::protoDataCopyInto(OstProto::Stream &stream)
|
||||
quint32 Ip4Protocol::protocolNumber() const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
stream.MutableExtension(OstProto::ip4)->CopyFrom(data);
|
||||
return OstProto::Protocol::kIp4FieldNumber;
|
||||
}
|
||||
|
||||
void Ip4Protocol::protoDataCopyFrom(const OstProto::Stream &stream)
|
||||
void Ip4Protocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
if (stream.HasExtension(OstProto::ip4))
|
||||
data.MergeFrom(stream.GetExtension(OstProto::ip4));
|
||||
protocol.MutableExtension(OstProto::ip4)->CopyFrom(data);
|
||||
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
||||
}
|
||||
|
||||
void Ip4Protocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
||||
{
|
||||
if (protocol.protocol_id().id() == protocolNumber() &&
|
||||
protocol.HasExtension(OstProto::ip4))
|
||||
data.MergeFrom(protocol.GetExtension(OstProto::ip4));
|
||||
}
|
||||
|
||||
QString Ip4Protocol::name() const
|
||||
@ -604,11 +603,15 @@ quint32 Ip4Protocol::protocolFrameCksum(int streamIndex,
|
||||
|
||||
QWidget* Ip4Protocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new Ip4ConfigForm;
|
||||
return configForm;
|
||||
}
|
||||
|
||||
void Ip4Protocol::loadConfigWidget()
|
||||
{
|
||||
configWidget();
|
||||
|
||||
configForm->cbIpVersionOverride->setChecked(data.is_override_ver());
|
||||
configForm->leIpVersion->setText(fieldData(ip4_ver, FieldValue).toString());
|
||||
|
||||
@ -649,6 +652,8 @@ void Ip4Protocol::storeConfigWidget()
|
||||
uint ff = 0;
|
||||
bool isOk;
|
||||
|
||||
configWidget();
|
||||
|
||||
data.set_is_override_ver(configForm->cbIpVersionOverride->isChecked());
|
||||
data.set_ver_hdrlen(((configForm->leIpVersion->text().toULong(&isOk) & 0x0F) << 4) |
|
||||
(configForm->leIpHdrLen->text().toULong(&isOk) & 0x0F));
|
||||
|
15
common/ip4.h
15
common/ip4.h
@ -16,6 +16,7 @@ class Ip4ConfigForm : public QWidget, public Ui::ip4
|
||||
Q_OBJECT
|
||||
public:
|
||||
Ip4ConfigForm(QWidget *parent = 0);
|
||||
~Ip4ConfigForm();
|
||||
private slots:
|
||||
void on_cmbIpSrcAddrMode_currentIndexChanged(int index);
|
||||
void on_cmbIpDstAddrMode_currentIndexChanged(int index);
|
||||
@ -25,7 +26,7 @@ class Ip4Protocol : public AbstractProtocol
|
||||
{
|
||||
private:
|
||||
OstProto::Ip4 data;
|
||||
static Ip4ConfigForm *configForm;
|
||||
Ip4ConfigForm *configForm;
|
||||
enum ip4field
|
||||
{
|
||||
ip4_ver = 0,
|
||||
@ -58,16 +59,14 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
Ip4Protocol(ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent = 0);
|
||||
Ip4Protocol(StreamBase *stream);
|
||||
virtual ~Ip4Protocol();
|
||||
|
||||
static AbstractProtocol* createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore = 0);
|
||||
static AbstractProtocol* createInstance(StreamBase *stream);
|
||||
virtual quint32 protocolNumber() const;
|
||||
|
||||
virtual void protoDataCopyInto(OstProto::Stream &stream);
|
||||
virtual void protoDataCopyFrom(const OstProto::Stream &stream);
|
||||
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
|
||||
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
@ -42,6 +42,6 @@ message Ip4 {
|
||||
// TODO: Options
|
||||
}
|
||||
|
||||
extend Stream {
|
||||
extend Protocol {
|
||||
optional Ip4 ip4 = 130;
|
||||
}
|
||||
|
@ -3,45 +3,44 @@
|
||||
|
||||
#include "llc.h"
|
||||
|
||||
LlcConfigForm *LlcProtocol::configForm = NULL;
|
||||
|
||||
LlcConfigForm::LlcConfigForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
LlcProtocol::LlcProtocol(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent)
|
||||
: AbstractProtocol(frameProtoList, parent)
|
||||
LlcProtocol::LlcProtocol(StreamBase *stream)
|
||||
: AbstractProtocol(stream)
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new LlcConfigForm;
|
||||
configForm = NULL;
|
||||
}
|
||||
|
||||
LlcProtocol::~LlcProtocol()
|
||||
{
|
||||
delete configForm;
|
||||
}
|
||||
|
||||
AbstractProtocol* LlcProtocol::createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore)
|
||||
AbstractProtocol* LlcProtocol::createInstance(StreamBase *stream)
|
||||
{
|
||||
return new LlcProtocol(frameProtoList, streamCore);
|
||||
return new LlcProtocol(stream);
|
||||
}
|
||||
|
||||
void LlcProtocol::protoDataCopyInto(OstProto::Stream &stream)
|
||||
quint32 LlcProtocol::protocolNumber() const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
stream.MutableExtension(OstProto::llc)->CopyFrom(data);
|
||||
return OstProto::Protocol::kLlcFieldNumber;
|
||||
}
|
||||
|
||||
void LlcProtocol::protoDataCopyFrom(const OstProto::Stream &stream)
|
||||
void LlcProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
if (stream.HasExtension(OstProto::llc))
|
||||
data.MergeFrom(stream.GetExtension(OstProto::llc));
|
||||
protocol.MutableExtension(OstProto::llc)->CopyFrom(data);
|
||||
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
||||
}
|
||||
|
||||
void LlcProtocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
||||
{
|
||||
if (protocol.protocol_id().id() == protocolNumber() &&
|
||||
protocol.HasExtension(OstProto::llc))
|
||||
data.MergeFrom(protocol.GetExtension(OstProto::llc));
|
||||
}
|
||||
|
||||
QString LlcProtocol::name() const
|
||||
@ -135,6 +134,8 @@ bool LlcProtocol::setFieldData(int index, const QVariant &value,
|
||||
|
||||
QWidget* LlcProtocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new LlcConfigForm;
|
||||
return configForm;
|
||||
}
|
||||
|
||||
@ -143,6 +144,8 @@ void LlcProtocol::loadConfigWidget()
|
||||
#define uintToHexStr(num, bytes) \
|
||||
QString("%1").arg(num, bytes*2, BASE_HEX, QChar('0'))
|
||||
|
||||
configWidget();
|
||||
|
||||
configForm->leDsap->setText(uintToHexStr(
|
||||
fieldData(llc_dsap, FieldValue).toUInt(), 1));
|
||||
configForm->leSsap->setText(uintToHexStr(
|
||||
@ -156,6 +159,8 @@ void LlcProtocol::storeConfigWidget()
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
configWidget();
|
||||
|
||||
data.set_dsap(configForm->leDsap->text().toULong(&isOk, BASE_HEX));
|
||||
data.set_ssap(configForm->leSsap->text().toULong(&isOk, BASE_HEX));
|
||||
data.set_ctl(configForm->leControl->text().toULong(&isOk, BASE_HEX));
|
||||
|
14
common/llc.h
14
common/llc.h
@ -20,7 +20,7 @@ class LlcProtocol : public AbstractProtocol
|
||||
{
|
||||
private:
|
||||
OstProto::Llc data;
|
||||
static LlcConfigForm *configForm;
|
||||
LlcConfigForm *configForm;
|
||||
enum llcfield
|
||||
{
|
||||
llc_dsap = 0,
|
||||
@ -31,16 +31,14 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
LlcProtocol(ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent = 0);
|
||||
LlcProtocol(StreamBase *stream);
|
||||
virtual ~LlcProtocol();
|
||||
|
||||
static AbstractProtocol* createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore = 0);
|
||||
static AbstractProtocol* createInstance(StreamBase *stream);
|
||||
virtual quint32 protocolNumber() const;
|
||||
|
||||
virtual void protoDataCopyInto(OstProto::Stream &stream);
|
||||
virtual void protoDataCopyFrom(const OstProto::Stream &stream);
|
||||
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
|
||||
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
@ -8,6 +8,6 @@ message Llc {
|
||||
optional uint32 ctl = 3;
|
||||
}
|
||||
|
||||
extend Stream {
|
||||
extend Protocol {
|
||||
optional Llc llc = 123;
|
||||
}
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
#include "mac.h"
|
||||
|
||||
MacConfigForm *MacProtocol::configForm = NULL;
|
||||
|
||||
MacConfigForm::MacConfigForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
@ -17,6 +15,11 @@ MacConfigForm::MacConfigForm(QWidget *parent)
|
||||
leSrcMacCount->setValidator(new QIntValidator(1, MAX_MAC_ITER_COUNT, this));
|
||||
}
|
||||
|
||||
MacConfigForm::~MacConfigForm()
|
||||
{
|
||||
qDebug("In MacConfigForm destructor");
|
||||
}
|
||||
|
||||
void MacConfigForm::on_cmbDstMacMode_currentIndexChanged(int index)
|
||||
{
|
||||
if (index == OstProto::Mac::e_mm_fixed)
|
||||
@ -46,37 +49,38 @@ void MacConfigForm::on_cmbSrcMacMode_currentIndexChanged(int index)
|
||||
}
|
||||
|
||||
|
||||
MacProtocol::MacProtocol(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent)
|
||||
: AbstractProtocol(frameProtoList, parent)
|
||||
MacProtocol::MacProtocol(StreamBase *stream)
|
||||
: AbstractProtocol(stream)
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new MacConfigForm;
|
||||
configForm = NULL;
|
||||
}
|
||||
|
||||
MacProtocol::~MacProtocol()
|
||||
{
|
||||
delete configForm;
|
||||
}
|
||||
|
||||
AbstractProtocol* MacProtocol::createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore)
|
||||
AbstractProtocol* MacProtocol::createInstance(StreamBase *stream)
|
||||
{
|
||||
return new MacProtocol(frameProtoList, streamCore);
|
||||
return new MacProtocol(stream);
|
||||
}
|
||||
|
||||
void MacProtocol::protoDataCopyInto(OstProto::Stream &stream)
|
||||
quint32 MacProtocol::protocolNumber() const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
stream.MutableExtension(OstProto::mac)->CopyFrom(data);
|
||||
return OstProto::Protocol::kMacFieldNumber;
|
||||
}
|
||||
|
||||
void MacProtocol::protoDataCopyFrom(const OstProto::Stream &stream)
|
||||
void MacProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
if (stream.HasExtension(OstProto::mac))
|
||||
data.MergeFrom(stream.GetExtension(OstProto::mac));
|
||||
protocol.MutableExtension(OstProto::mac)->CopyFrom(data);
|
||||
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
||||
}
|
||||
|
||||
void MacProtocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
||||
{
|
||||
if (protocol.protocol_id().id() == protocolNumber() &&
|
||||
protocol.HasExtension(OstProto::mac))
|
||||
data.MergeFrom(protocol.GetExtension(OstProto::mac));
|
||||
}
|
||||
|
||||
QString MacProtocol::name() const
|
||||
@ -238,11 +242,15 @@ bool MacProtocol::setFieldData(int index, const QVariant &value,
|
||||
|
||||
QWidget* MacProtocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new MacConfigForm;
|
||||
return configForm;
|
||||
}
|
||||
|
||||
void MacProtocol::loadConfigWidget()
|
||||
{
|
||||
configWidget();
|
||||
|
||||
configForm->leDstMac->setText(uintToHexStr(data.dst_mac(), 6));
|
||||
configForm->cmbDstMacMode->setCurrentIndex(data.dst_mac_mode());
|
||||
configForm->leDstMacCount->setText(QString().setNum(data.dst_mac_count()));
|
||||
@ -258,6 +266,8 @@ void MacProtocol::storeConfigWidget()
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
configWidget();
|
||||
|
||||
data.set_dst_mac(configForm->leDstMac->text().remove(QChar(' ')).
|
||||
toULongLong(&isOk, 16));
|
||||
data.set_dst_mac_mode((OstProto::Mac::MacAddrMode) configForm->
|
||||
|
15
common/mac.h
15
common/mac.h
@ -13,6 +13,7 @@ class MacConfigForm : public QWidget, public Ui::mac
|
||||
Q_OBJECT
|
||||
public:
|
||||
MacConfigForm(QWidget *parent = 0);
|
||||
virtual ~MacConfigForm();
|
||||
private slots:
|
||||
void on_cmbDstMacMode_currentIndexChanged(int index);
|
||||
void on_cmbSrcMacMode_currentIndexChanged(int index);
|
||||
@ -22,7 +23,7 @@ class MacProtocol : public AbstractProtocol
|
||||
{
|
||||
private:
|
||||
OstProto::Mac data;
|
||||
static MacConfigForm *configForm;
|
||||
MacConfigForm *configForm;
|
||||
enum macfield
|
||||
{
|
||||
mac_dstAddr = 0,
|
||||
@ -39,16 +40,14 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
MacProtocol(ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent = 0);
|
||||
MacProtocol(StreamBase *stream);
|
||||
virtual ~MacProtocol();
|
||||
|
||||
static AbstractProtocol* createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore = 0);
|
||||
static AbstractProtocol* createInstance(StreamBase *stream);
|
||||
virtual quint32 protocolNumber() const;
|
||||
|
||||
virtual void protoDataCopyInto(OstProto::Stream &stream);
|
||||
virtual void protoDataCopyFrom(const OstProto::Stream &stream);
|
||||
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
|
||||
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
@ -24,6 +24,6 @@ message Mac {
|
||||
optional uint32 src_mac_step = 8 [default = 1];
|
||||
}
|
||||
|
||||
extend Stream {
|
||||
extend Protocol {
|
||||
optional Mac mac = 51;
|
||||
}
|
||||
|
@ -6,13 +6,13 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>512</width>
|
||||
<height>98</height>
|
||||
<height>104</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" >
|
||||
<layout class="QVBoxLayout" >
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox" >
|
||||
<property name="title" >
|
||||
@ -81,10 +81,10 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>1</string>
|
||||
<string/>
|
||||
</property>
|
||||
<property name="cursorPosition" >
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -101,10 +101,10 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>1</string>
|
||||
<string/>
|
||||
</property>
|
||||
<property name="cursorPosition" >
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -164,7 +164,7 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>1</string>
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -181,16 +181,29 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>1</string>
|
||||
<string/>
|
||||
</property>
|
||||
<property name="cursorPosition" >
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
@ -29,7 +29,8 @@ PROTOS += \
|
||||
HEADERS += \
|
||||
abstractprotocol.h \
|
||||
protocolmanager.h \
|
||||
protocolcollection.h \
|
||||
protocollist.h \
|
||||
protocollistiterator.h \
|
||||
streambase.h \
|
||||
mac.h \
|
||||
payload.h \
|
||||
@ -44,7 +45,8 @@ HEADERS += \
|
||||
SOURCES += \
|
||||
abstractprotocol.cpp \
|
||||
protocolmanager.cpp \
|
||||
protocolcollection.cpp \
|
||||
protocollist.cpp \
|
||||
protocollistiterator.cpp \
|
||||
streambase.cpp \
|
||||
mac.cpp \
|
||||
payload.cpp \
|
||||
|
@ -3,11 +3,10 @@
|
||||
|
||||
//#include "../client/stream.h"
|
||||
#include "payload.h"
|
||||
#include "streambase.h"
|
||||
|
||||
#define SZ_FCS 4
|
||||
|
||||
PayloadConfigForm *PayloadProtocol::configForm = NULL;
|
||||
|
||||
PayloadConfigForm::PayloadConfigForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
@ -31,37 +30,38 @@ void PayloadConfigForm::on_cmbPatternMode_currentIndexChanged(int index)
|
||||
}
|
||||
}
|
||||
|
||||
PayloadProtocol::PayloadProtocol(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent)
|
||||
: AbstractProtocol(frameProtoList, parent)
|
||||
PayloadProtocol::PayloadProtocol(StreamBase *stream)
|
||||
: AbstractProtocol(stream)
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new PayloadConfigForm;
|
||||
configForm = NULL;
|
||||
}
|
||||
|
||||
PayloadProtocol::~PayloadProtocol()
|
||||
{
|
||||
delete configForm;
|
||||
}
|
||||
|
||||
AbstractProtocol* PayloadProtocol::createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore)
|
||||
AbstractProtocol* PayloadProtocol::createInstance(StreamBase *stream)
|
||||
{
|
||||
return new PayloadProtocol(frameProtoList, streamCore);
|
||||
return new PayloadProtocol(stream);
|
||||
}
|
||||
|
||||
void PayloadProtocol::protoDataCopyInto(OstProto::Stream &stream)
|
||||
quint32 PayloadProtocol::protocolNumber() const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
stream.MutableExtension(OstProto::payload)->CopyFrom(data);
|
||||
return OstProto::Protocol::kPayloadFieldNumber;
|
||||
}
|
||||
|
||||
void PayloadProtocol::protoDataCopyFrom(const OstProto::Stream &stream)
|
||||
void PayloadProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
if (stream.HasExtension(OstProto::payload))
|
||||
data.MergeFrom(stream.GetExtension(OstProto::payload));
|
||||
protocol.MutableExtension(OstProto::payload)->CopyFrom(data);
|
||||
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
||||
}
|
||||
|
||||
void PayloadProtocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
||||
{
|
||||
if (protocol.protocol_id().id() == protocolNumber() &&
|
||||
protocol.HasExtension(OstProto::payload))
|
||||
data.MergeFrom(protocol.GetExtension(OstProto::payload));
|
||||
}
|
||||
|
||||
QString PayloadProtocol::name() const
|
||||
@ -76,7 +76,7 @@ QString PayloadProtocol::shortName() const
|
||||
|
||||
int PayloadProtocol::protocolFrameSize() const
|
||||
{
|
||||
return (stream->frame_len() - protocolFrameOffset() - SZ_FCS);
|
||||
return (mpStream->frameLen() - protocolFrameOffset() - SZ_FCS);
|
||||
}
|
||||
|
||||
int PayloadProtocol::fieldCount() const
|
||||
@ -124,7 +124,7 @@ QVariant PayloadProtocol::fieldData(int index, FieldAttrib attrib,
|
||||
QByteArray fv;
|
||||
int dataLen;
|
||||
|
||||
dataLen = stream->frame_len() - protocolFrameOffset();
|
||||
dataLen = mpStream->frameLen() - protocolFrameOffset();
|
||||
dataLen -= SZ_FCS;
|
||||
fv.resize(dataLen+4);
|
||||
switch(data.pattern_mode())
|
||||
@ -179,12 +179,15 @@ bool PayloadProtocol::setFieldData(int index, const QVariant &value,
|
||||
|
||||
QWidget* PayloadProtocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new PayloadConfigForm;
|
||||
return configForm;
|
||||
//return new PayloadConfigForm;
|
||||
}
|
||||
|
||||
void PayloadProtocol::loadConfigWidget()
|
||||
{
|
||||
configWidget();
|
||||
|
||||
configForm->cmbPatternMode->setCurrentIndex(data.pattern_mode());
|
||||
configForm->lePattern->setText(uintToHexStr(data.pattern(), 4));
|
||||
}
|
||||
@ -193,6 +196,8 @@ void PayloadProtocol::storeConfigWidget()
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
configWidget();
|
||||
|
||||
data.set_pattern_mode((OstProto::Payload::DataPatternMode)
|
||||
configForm->cmbPatternMode->currentIndex());
|
||||
data.set_pattern(configForm->lePattern->text().remove(QChar(' ')).toULong(&isOk, 16));
|
||||
|
@ -19,7 +19,7 @@ class PayloadProtocol : public AbstractProtocol
|
||||
{
|
||||
private:
|
||||
OstProto::Payload data;
|
||||
static PayloadConfigForm *configForm;
|
||||
PayloadConfigForm *configForm;
|
||||
enum payloadfield
|
||||
{
|
||||
payload_dataPattern,
|
||||
@ -31,16 +31,14 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
PayloadProtocol(ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent = 0);
|
||||
PayloadProtocol(StreamBase *stream);
|
||||
virtual ~PayloadProtocol();
|
||||
|
||||
static AbstractProtocol* createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore = 0);
|
||||
static AbstractProtocol* createInstance(StreamBase *stream);
|
||||
virtual quint32 protocolNumber() const;
|
||||
|
||||
virtual void protoDataCopyInto(OstProto::Stream &stream);
|
||||
virtual void protoDataCopyFrom(const OstProto::Stream &stream);
|
||||
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
|
||||
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
@ -17,6 +17,6 @@ message Payload {
|
||||
//optional uint32 data_start_ofs = 13;
|
||||
}
|
||||
|
||||
extend Stream {
|
||||
extend Protocol {
|
||||
optional Payload payload = 52;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ message StreamCore {
|
||||
optional uint32 frame_len_max = 17 [default = 1518];
|
||||
|
||||
// Currently Selected Protocols
|
||||
repeated uint32 frame_proto = 20;
|
||||
//repeated uint32 frame_proto = 20;
|
||||
}
|
||||
|
||||
message StreamControl {
|
||||
@ -61,14 +61,45 @@ message StreamControl {
|
||||
|
||||
}
|
||||
|
||||
message ProtocolId {
|
||||
required uint32 id = 1;
|
||||
}
|
||||
|
||||
message Protocol {
|
||||
|
||||
required ProtocolId protocol_id = 1;
|
||||
|
||||
extensions 51 to 100; // Reserved for Ostinato Use
|
||||
extensions 101 to 200; // Available for use by protocols
|
||||
|
||||
enum k {
|
||||
kMacFieldNumber = 51;
|
||||
kPayloadFieldNumber = 52;
|
||||
|
||||
kEth2FieldNumber = 121;
|
||||
kDot3FieldNumber = 122;
|
||||
kLlcFieldNumber = 123;
|
||||
kSnapFieldNumber = 124;
|
||||
|
||||
kVlanFieldNumber = 126;
|
||||
|
||||
kIp4FieldNumber = 130;
|
||||
kArpFieldNumber = 131;
|
||||
|
||||
kTcpFieldNumber = 140;
|
||||
kUdpFieldNumber = 141;
|
||||
kIcmpFieldNumber = 142;
|
||||
kIgmpFieldNumber = 143;
|
||||
}
|
||||
}
|
||||
|
||||
message Stream {
|
||||
|
||||
required StreamId stream_id = 1;
|
||||
optional StreamCore core = 2;
|
||||
optional StreamControl control = 3;
|
||||
|
||||
extensions 51 to 100; // Reserved for Ostinato Use
|
||||
extensions 101 to 200; // Available for use by protocols
|
||||
repeated Protocol protocol = 4;
|
||||
}
|
||||
|
||||
message Void {
|
||||
|
@ -1,106 +0,0 @@
|
||||
#include "protocolcollection.h"
|
||||
|
||||
extern ProtocolManager OstProtocolManager;
|
||||
|
||||
ProtocolCollection::ProtocolCollection(ProtocolList &streamProtocols,
|
||||
OstProto::StreamCore *streamCore)
|
||||
: protoManager(OstProtocolManager)
|
||||
{
|
||||
// Create an instance of each registered protocol
|
||||
|
||||
QMapIterator<int, void*> iter(protoManager.factory);
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
AbstractProtocol* (*p)(ProtocolList&, OstProto::StreamCore*);
|
||||
AbstractProtocol* q;
|
||||
|
||||
iter.next();
|
||||
p = (AbstractProtocol* (*)(ProtocolList&, OstProto::StreamCore*))
|
||||
iter.value();
|
||||
q = (*p)(streamProtocols, streamCore);
|
||||
|
||||
protocols.insert(iter.key(), q);
|
||||
}
|
||||
}
|
||||
|
||||
ProtocolCollection::~ProtocolCollection()
|
||||
{
|
||||
QMutableMapIterator<int,AbstractProtocol*> iter(protocols);
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
iter.next();
|
||||
if (iter.value())
|
||||
{
|
||||
delete iter.value();
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProtocolCollection::protoDataCopyFrom(const OstProto::Stream &stream) const
|
||||
{
|
||||
QMapIterator<int,AbstractProtocol*> iter(protocols);
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
iter.next();
|
||||
if (iter.value())
|
||||
{
|
||||
iter.value()->protoDataCopyFrom(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProtocolCollection::protoDataCopyInto(OstProto::Stream &stream) const
|
||||
{
|
||||
QMapIterator<int,AbstractProtocol*> iter(protocols);
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
iter.next();
|
||||
if (iter.value())
|
||||
{
|
||||
iter.value()->protoDataCopyInto(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProtocolCollection::loadConfigWidgets() const
|
||||
{
|
||||
QMapIterator<int,AbstractProtocol*> iter(protocols);
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
iter.next();
|
||||
if (iter.value())
|
||||
{
|
||||
iter.value()->loadConfigWidget();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProtocolCollection::storeConfigWidgets() const
|
||||
{
|
||||
QMapIterator<int,AbstractProtocol*> iter(protocols);
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
iter.next();
|
||||
if (iter.value())
|
||||
{
|
||||
iter.value()->storeConfigWidget();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AbstractProtocol* ProtocolCollection::protocol(int protoNum)
|
||||
{
|
||||
return protocols.value(protoNum);
|
||||
}
|
||||
|
||||
AbstractProtocol* ProtocolCollection::protocol(QString protoName)
|
||||
{
|
||||
return protocols.value(protoManager.nameToNumberMap.value(protoName));
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
#ifndef _PROTOCOL_COLLECTION_H
|
||||
#define _PROTOCOL_COLLECTION_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QLinkedList>
|
||||
|
||||
#include "abstractprotocol.h"
|
||||
#include "protocolmanager.h"
|
||||
|
||||
class ProtocolCollection {
|
||||
|
||||
ProtocolManager &protoManager;
|
||||
QMap<int, AbstractProtocol*> protocols;
|
||||
|
||||
public:
|
||||
ProtocolCollection(ProtocolList &streamProtocols,
|
||||
OstProto::StreamCore *streamCore);
|
||||
ProtocolCollection::~ProtocolCollection();
|
||||
|
||||
void protoDataCopyFrom(const OstProto::Stream &stream) const;
|
||||
void protoDataCopyInto(OstProto::Stream &stream) const;
|
||||
|
||||
void loadConfigWidgets() const;
|
||||
void storeConfigWidgets() const;
|
||||
|
||||
AbstractProtocol* protocol(int protoNum);
|
||||
AbstractProtocol* protocol(QString protoName);
|
||||
};
|
||||
|
||||
#endif
|
8
common/protocollist.cpp
Normal file
8
common/protocollist.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "protocollist.h"
|
||||
#include "abstractprotocol.h"
|
||||
|
||||
void ProtocolList::destroy()
|
||||
{
|
||||
while (!isEmpty())
|
||||
delete takeFirst();
|
||||
}
|
9
common/protocollist.h
Normal file
9
common/protocollist.h
Normal file
@ -0,0 +1,9 @@
|
||||
#include <QLinkedList>
|
||||
|
||||
class AbstractProtocol;
|
||||
|
||||
class ProtocolList : public QLinkedList<AbstractProtocol*>
|
||||
{
|
||||
public:
|
||||
void destroy();
|
||||
};
|
87
common/protocollistiterator.cpp
Normal file
87
common/protocollistiterator.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
#include "protocollistiterator.h"
|
||||
#include "protocollist.h"
|
||||
|
||||
ProtocolListIterator::ProtocolListIterator(ProtocolList &list)
|
||||
{
|
||||
_iter = new QMutableLinkedListIterator<AbstractProtocol*>(list);
|
||||
}
|
||||
|
||||
ProtocolListIterator::~ProtocolListIterator()
|
||||
{
|
||||
delete _iter;
|
||||
}
|
||||
|
||||
bool ProtocolListIterator::findNext(const AbstractProtocol* value) const
|
||||
{
|
||||
return _iter->findNext((AbstractProtocol*)((uint)value));
|
||||
}
|
||||
|
||||
bool ProtocolListIterator::findPrevious(const AbstractProtocol* value)
|
||||
{
|
||||
return _iter->findPrevious((AbstractProtocol*)((uint)value));
|
||||
}
|
||||
|
||||
bool ProtocolListIterator::hasNext() const
|
||||
{
|
||||
return _iter->hasNext();
|
||||
}
|
||||
|
||||
bool ProtocolListIterator::hasPrevious() const
|
||||
{
|
||||
return _iter->hasPrevious();
|
||||
}
|
||||
|
||||
void ProtocolListIterator::insert(const AbstractProtocol* value)
|
||||
{
|
||||
_iter->insert((AbstractProtocol*)((uint)value));
|
||||
}
|
||||
|
||||
AbstractProtocol* ProtocolListIterator::next()
|
||||
{
|
||||
return _iter->next();
|
||||
}
|
||||
|
||||
AbstractProtocol* ProtocolListIterator::peekNext() const
|
||||
{
|
||||
return _iter->peekNext();
|
||||
}
|
||||
|
||||
AbstractProtocol* ProtocolListIterator::peekPrevious() const
|
||||
{
|
||||
return _iter->peekPrevious();
|
||||
}
|
||||
|
||||
AbstractProtocol* ProtocolListIterator::previous()
|
||||
{
|
||||
return _iter->previous();
|
||||
}
|
||||
|
||||
void ProtocolListIterator::remove()
|
||||
{
|
||||
_iter->remove();
|
||||
}
|
||||
|
||||
void ProtocolListIterator::setValue(const AbstractProtocol* value) const
|
||||
{
|
||||
_iter->setValue((AbstractProtocol*)((uint)value));
|
||||
}
|
||||
|
||||
void ProtocolListIterator::toBack()
|
||||
{
|
||||
_iter->toBack();
|
||||
}
|
||||
|
||||
void ProtocolListIterator::toFront()
|
||||
{
|
||||
_iter->toFront();
|
||||
}
|
||||
|
||||
const AbstractProtocol* ProtocolListIterator::value() const
|
||||
{
|
||||
return _iter->value();
|
||||
}
|
||||
|
||||
AbstractProtocol* ProtocolListIterator::value()
|
||||
{
|
||||
return _iter->value();
|
||||
}
|
29
common/protocollistiterator.h
Normal file
29
common/protocollistiterator.h
Normal file
@ -0,0 +1,29 @@
|
||||
#include <QMutableLinkedListIterator>
|
||||
|
||||
class AbstractProtocol;
|
||||
class ProtocolList;
|
||||
|
||||
class ProtocolListIterator
|
||||
{
|
||||
private:
|
||||
QMutableLinkedListIterator<AbstractProtocol*> *_iter;
|
||||
|
||||
public:
|
||||
ProtocolListIterator(ProtocolList &list);
|
||||
~ProtocolListIterator();
|
||||
bool findNext(const AbstractProtocol* value) const;
|
||||
bool findPrevious(const AbstractProtocol* value);
|
||||
bool hasNext() const;
|
||||
bool hasPrevious() const;
|
||||
void insert(const AbstractProtocol* value);
|
||||
AbstractProtocol* next();
|
||||
AbstractProtocol* peekNext() const;
|
||||
AbstractProtocol* peekPrevious() const;
|
||||
AbstractProtocol* previous();
|
||||
void remove();
|
||||
void setValue(const AbstractProtocol* value) const;
|
||||
void toBack();
|
||||
void toFront();
|
||||
const AbstractProtocol* value() const;
|
||||
AbstractProtocol* value();
|
||||
};
|
@ -1,5 +1,9 @@
|
||||
#include "protocolmanager.h"
|
||||
|
||||
// FIXME(HI): remove
|
||||
#include "protocol.pb.h"
|
||||
#include "abstractprotocol.h"
|
||||
|
||||
#include "mac.h"
|
||||
#include "payload.h"
|
||||
|
||||
@ -12,9 +16,6 @@
|
||||
#include "tcp.h"
|
||||
#include "udp.h"
|
||||
|
||||
QMap<int, void*> ProtocolManager::factory;
|
||||
QMap<QString, int> ProtocolManager::nameToNumberMap;
|
||||
|
||||
ProtocolManager OstProtocolManager;
|
||||
|
||||
ProtocolManager::ProtocolManager()
|
||||
@ -36,5 +37,33 @@ void ProtocolManager::registerProtocol(int protoNumber, QString protoName,
|
||||
{
|
||||
// TODO: validate incoming params for duplicates with existing
|
||||
nameToNumberMap.insert(protoName, protoNumber);
|
||||
numberToNameMap.insert(protoNumber, protoName);
|
||||
factory.insert(protoNumber, protoInstanceCreator);
|
||||
}
|
||||
|
||||
AbstractProtocol* ProtocolManager::createProtocol(int protoNumber,
|
||||
StreamBase *stream)
|
||||
{
|
||||
AbstractProtocol* (*pc)(StreamBase*);
|
||||
AbstractProtocol* p;
|
||||
|
||||
pc = (AbstractProtocol* (*)(StreamBase*))
|
||||
factory.value(protoNumber);
|
||||
|
||||
Q_ASSERT(pc != NULL);
|
||||
|
||||
p = (*pc)(stream);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
AbstractProtocol* ProtocolManager::createProtocol(QString protoName,
|
||||
StreamBase *stream)
|
||||
{
|
||||
return createProtocol(nameToNumberMap.value(protoName), stream);
|
||||
}
|
||||
|
||||
QStringList ProtocolManager::protocolDatabase()
|
||||
{
|
||||
return numberToNameMap.values();
|
||||
}
|
||||
|
@ -2,18 +2,27 @@
|
||||
#define _PROTOCOL_MANAGER_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
|
||||
class AbstractProtocol;
|
||||
class StreamBase;
|
||||
|
||||
class ProtocolManager
|
||||
{
|
||||
public:
|
||||
//! \todo Make these data structures private/protected
|
||||
static QMap<QString, int> nameToNumberMap;
|
||||
static QMap<int, void*> factory;
|
||||
QMap<int, QString> numberToNameMap;
|
||||
QMap<QString, int> nameToNumberMap;
|
||||
QMap<int, void*> factory;
|
||||
|
||||
public:
|
||||
ProtocolManager();
|
||||
|
||||
void registerProtocol(int protoNumber, QString protoName,
|
||||
void *protoCreator);
|
||||
|
||||
AbstractProtocol* createProtocol(int protoNumber, StreamBase *stream);
|
||||
AbstractProtocol* createProtocol(QString protoName, StreamBase *stream);
|
||||
|
||||
QStringList protocolDatabase();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -3,46 +3,44 @@
|
||||
|
||||
#include "sample.h"
|
||||
|
||||
SampleConfigForm *SampleProtocol::configForm = NULL;
|
||||
|
||||
SampleConfigForm::SampleConfigForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
}
|
||||
|
||||
SampleProtocol::SampleProtocol(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent)
|
||||
: AbstractProtocol(frameProtoList, parent)
|
||||
SampleProtocol::SampleProtocol(StreamBase *stream);
|
||||
: AbstractProtocol(stream)
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new SampleConfigForm;
|
||||
configForm = NULL;
|
||||
}
|
||||
|
||||
SampleProtocol::~SampleProtocol()
|
||||
{
|
||||
delete configForm;
|
||||
}
|
||||
|
||||
AbstractProtocol* SampleProtocol::createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore)
|
||||
AbstractProtocol* SampleProtocol::createInstance(StreamBase *stream)
|
||||
{
|
||||
return new SampleProtocol(frameProtoList, streamCore);
|
||||
}
|
||||
|
||||
void SampleProtocol::protoDataCopyInto(OstProto::Stream &stream)
|
||||
quint32 SampleProtocol::protocolNumber() const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
stream.MutableExtension(OstProto::sample)->CopyFrom(data);
|
||||
return OstProto::Protocol::kSampleFieldNumber;
|
||||
}
|
||||
|
||||
void SampleProtocol::protoDataCopyFrom(const OstProto::Stream &stream)
|
||||
void SampleProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
if (stream.HasExtension(OstProto::sample))
|
||||
data.MergeFrom(stream.GetExtension(OstProto::sample));
|
||||
protocol.MutableExtension(OstProto::sample)->CopyFrom(data);
|
||||
protocol.mutable_protocol_id()->set_id(protocolNumber())
|
||||
}
|
||||
|
||||
void SampleProtocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
||||
{
|
||||
if (protocol.protocol_id()->id() == protocolNumber() &&
|
||||
protocol.HasExtension(OstProto::sample))
|
||||
data.MergeFrom(protocol.GetExtension(OstProto::sample));
|
||||
}
|
||||
|
||||
QString SampleProtocol::name() const
|
||||
@ -156,15 +154,21 @@ bool SampleProtocol::setFieldData(int index, const QVariant &value,
|
||||
|
||||
QWidget* SampleProtocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configFrom = new SampleConfigForm;
|
||||
|
||||
return configForm;
|
||||
}
|
||||
|
||||
void SampleProtocol::loadConfigWidget()
|
||||
{
|
||||
configWidget();
|
||||
}
|
||||
|
||||
void SampleProtocol::storeConfigWidget()
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
configWidget();
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ class SampleProtocol : public AbstractProtocol
|
||||
{
|
||||
private:
|
||||
OstProto::Sample data;
|
||||
static SampleConfigForm *configForm;
|
||||
SampleConfigForm *configForm;
|
||||
enum samplefield
|
||||
{
|
||||
|
||||
@ -26,16 +26,14 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
SampleProtocol(ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent = 0);
|
||||
SampleProtocol(StreamBase *stream);
|
||||
virtual ~SampleProtocol();
|
||||
|
||||
static AbstractProtocol* createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore = 0);
|
||||
static AbstractProtocol* createInstance(StreamBase *stream);
|
||||
virtual quint32 protocolNumber() const;
|
||||
|
||||
virtual void protoDataCopyInto(OstProto::Stream &stream);
|
||||
virtual void protoDataCopyFrom(const OstProto::Stream &stream);
|
||||
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
|
||||
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
@ -3,45 +3,44 @@
|
||||
|
||||
#include "snap.h"
|
||||
|
||||
SnapConfigForm *SnapProtocol::configForm = NULL;
|
||||
|
||||
SnapConfigForm::SnapConfigForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
SnapProtocol::SnapProtocol(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent)
|
||||
: AbstractProtocol(frameProtoList, parent)
|
||||
SnapProtocol::SnapProtocol(StreamBase *stream)
|
||||
: AbstractProtocol(stream)
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new SnapConfigForm;
|
||||
configForm = NULL;
|
||||
}
|
||||
|
||||
SnapProtocol::~SnapProtocol()
|
||||
{
|
||||
delete configForm;
|
||||
}
|
||||
|
||||
AbstractProtocol* SnapProtocol::createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore)
|
||||
AbstractProtocol* SnapProtocol::createInstance(StreamBase *stream)
|
||||
{
|
||||
return new SnapProtocol(frameProtoList, streamCore);
|
||||
return new SnapProtocol(stream);
|
||||
}
|
||||
|
||||
void SnapProtocol::protoDataCopyInto(OstProto::Stream &stream)
|
||||
quint32 SnapProtocol::protocolNumber() const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
stream.MutableExtension(OstProto::snap)->CopyFrom(data);
|
||||
return OstProto::Protocol::kSnapFieldNumber;
|
||||
}
|
||||
|
||||
void SnapProtocol::protoDataCopyFrom(const OstProto::Stream &stream)
|
||||
void SnapProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
if (stream.HasExtension(OstProto::snap))
|
||||
data.MergeFrom(stream.GetExtension(OstProto::snap));
|
||||
protocol.MutableExtension(OstProto::snap)->CopyFrom(data);
|
||||
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
||||
}
|
||||
|
||||
void SnapProtocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
||||
{
|
||||
if (protocol.protocol_id().id() == protocolNumber() &&
|
||||
protocol.HasExtension(OstProto::snap))
|
||||
data.MergeFrom(protocol.GetExtension(OstProto::snap));
|
||||
}
|
||||
|
||||
QString SnapProtocol::name() const
|
||||
@ -140,11 +139,15 @@ bool SnapProtocol::setFieldData(int index, const QVariant &value,
|
||||
|
||||
QWidget* SnapProtocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new SnapConfigForm;
|
||||
return configForm;
|
||||
}
|
||||
|
||||
void SnapProtocol::loadConfigWidget()
|
||||
{
|
||||
configWidget();
|
||||
|
||||
configForm->leOui->setText(uintToHexStr(
|
||||
fieldData(snap_oui, FieldValue).toUInt(), 3));
|
||||
configForm->leType->setText(uintToHexStr(
|
||||
@ -155,6 +158,8 @@ void SnapProtocol::storeConfigWidget()
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
configWidget();
|
||||
|
||||
data.set_oui(configForm->leOui->text().toULong(&isOk, BASE_HEX));
|
||||
data.set_type(configForm->leType->text().toULong(&isOk, BASE_HEX));
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class SnapProtocol : public AbstractProtocol
|
||||
{
|
||||
private:
|
||||
OstProto::Snap data;
|
||||
static SnapConfigForm *configForm;
|
||||
SnapConfigForm *configForm;
|
||||
enum snapfield
|
||||
{
|
||||
snap_oui = 0,
|
||||
@ -27,16 +27,14 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
SnapProtocol(ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent = 0);
|
||||
SnapProtocol(StreamBase *stream);
|
||||
virtual ~SnapProtocol();
|
||||
|
||||
static AbstractProtocol* createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore = 0);
|
||||
static AbstractProtocol* createInstance(StreamBase *stream);
|
||||
virtual quint32 protocolNumber() const;
|
||||
|
||||
virtual void protoDataCopyInto(OstProto::Stream &stream);
|
||||
virtual void protoDataCopyFrom(const OstProto::Stream &stream);
|
||||
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
|
||||
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
@ -7,6 +7,6 @@ message Snap {
|
||||
optional uint32 type = 2;
|
||||
}
|
||||
|
||||
extend Stream {
|
||||
extend Protocol {
|
||||
optional Snap snap = 124;
|
||||
}
|
||||
|
@ -1,12 +1,47 @@
|
||||
#include "streambase.h"
|
||||
#include "abstractprotocol.h"
|
||||
#include "protocollist.h"
|
||||
#include "protocollistiterator.h"
|
||||
#include "protocolmanager.h"
|
||||
|
||||
extern ProtocolManager OstProtocolManager;
|
||||
|
||||
StreamBase::StreamBase() :
|
||||
mStreamId(new OstProto::StreamId),
|
||||
mCore(new OstProto::StreamCore),
|
||||
mControl(new OstProto::StreamControl),
|
||||
protocols(currentFrameProtocols, mCore)
|
||||
mControl(new OstProto::StreamControl)
|
||||
{
|
||||
AbstractProtocol *proto;
|
||||
|
||||
mStreamId->set_id(0xFFFFFFFF);
|
||||
|
||||
currentFrameProtocols = new ProtocolList;
|
||||
|
||||
// By default newly created streams have the mac and payload protocols
|
||||
proto = OstProtocolManager.createProtocol("mac", this);
|
||||
currentFrameProtocols->append(proto);
|
||||
qDebug("stream: mac = %p", proto);
|
||||
|
||||
proto = OstProtocolManager.createProtocol("payload", this);
|
||||
currentFrameProtocols->append(proto);
|
||||
qDebug("stream: payload = %p", proto);
|
||||
|
||||
{
|
||||
ProtocolListIterator *iter = createProtocolListIterator();
|
||||
iter->toFront();
|
||||
while (iter->hasNext())
|
||||
{
|
||||
qDebug("{{%p}}", iter->next());
|
||||
// qDebug("{{%p}: %d}", iter->peekNext(), iter->next()->protocolNumber());
|
||||
}
|
||||
iter->toFront();
|
||||
while (iter->hasNext())
|
||||
{
|
||||
qDebug("{[%d]}", iter->next()->protocolNumber());
|
||||
// qDebug("{{%p}: %d}", iter->peekNext(), iter->next()->protocolNumber());
|
||||
}
|
||||
delete iter;
|
||||
}
|
||||
}
|
||||
|
||||
StreamBase::~StreamBase()
|
||||
@ -18,12 +53,20 @@ StreamBase::~StreamBase()
|
||||
|
||||
void StreamBase::protoDataCopyFrom(const OstProto::Stream &stream)
|
||||
{
|
||||
AbstractProtocol *proto;
|
||||
|
||||
mStreamId->CopyFrom(stream.stream_id());
|
||||
mCore->CopyFrom(stream.core());
|
||||
mControl->CopyFrom(stream.control());
|
||||
|
||||
protocols.protoDataCopyFrom(stream);
|
||||
setFrameProtocol(frameProtocol());
|
||||
currentFrameProtocols->destroy();
|
||||
for (int i=0; i < stream.protocol_size(); i++)
|
||||
{
|
||||
proto = OstProtocolManager.createProtocol(
|
||||
stream.protocol(i).protocol_id().id(), this);
|
||||
proto->protoDataCopyFrom(stream.protocol(i));
|
||||
currentFrameProtocols->append(proto);
|
||||
}
|
||||
}
|
||||
|
||||
void StreamBase::protoDataCopyInto(OstProto::Stream &stream) const
|
||||
@ -32,38 +75,211 @@ void StreamBase::protoDataCopyInto(OstProto::Stream &stream) const
|
||||
stream.mutable_core()->CopyFrom(*mCore);
|
||||
stream.mutable_control()->CopyFrom(*mControl);
|
||||
|
||||
protocols.protoDataCopyInto(stream);
|
||||
}
|
||||
|
||||
QList<int> StreamBase::frameProtocol()
|
||||
stream.clear_protocol();
|
||||
foreach (const AbstractProtocol* proto, *currentFrameProtocols)
|
||||
{
|
||||
QList<int> protocolList;
|
||||
OstProto::Protocol *p;
|
||||
|
||||
for (int i = 0; i < mCore->frame_proto_size(); i++)
|
||||
protocolList.append(mCore->frame_proto(i));
|
||||
|
||||
return protocolList;
|
||||
p = stream.add_protocol();
|
||||
proto->protoDataCopyInto(*p);
|
||||
}
|
||||
}
|
||||
|
||||
void StreamBase::setFrameProtocol(QList<int> protocolList)
|
||||
#if 0
|
||||
ProtocolList StreamBase::frameProtocol()
|
||||
{
|
||||
mCore->clear_frame_proto();
|
||||
currentFrameProtocols.clear();
|
||||
return currentFrameProtocols;
|
||||
}
|
||||
|
||||
for (int i = 0; i < protocolList.size(); i++)
|
||||
void StreamBase::setFrameProtocol(ProtocolList protocolList)
|
||||
{
|
||||
mCore->add_frame_proto(protocolList.at(i));
|
||||
currentFrameProtocols.append(protocols.protocol(protocolList.at(i)));
|
||||
}
|
||||
//currentFrameProtocols.destroy();
|
||||
currentFrameProtocols = protocolList;
|
||||
}
|
||||
#endif
|
||||
|
||||
AbstractProtocol* StreamBase::protocol(int protoNum)
|
||||
ProtocolListIterator* StreamBase::createProtocolListIterator()
|
||||
{
|
||||
return protocols.protocol(protoNum);
|
||||
return new ProtocolListIterator(*currentFrameProtocols);
|
||||
}
|
||||
|
||||
AbstractProtocol* StreamBase::protocol(QString protoName)
|
||||
bool StreamBase::operator < (const StreamBase &s) const
|
||||
{
|
||||
return protocols.protocol(protoName);
|
||||
return(mCore->ordinal() < s.mCore->ordinal());
|
||||
}
|
||||
|
||||
quint32 StreamBase::id()
|
||||
{
|
||||
return mStreamId->id();
|
||||
}
|
||||
|
||||
bool StreamBase::setId(quint32 id)
|
||||
{
|
||||
mStreamId->set_id(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
quint32 StreamBase::ordinal()
|
||||
{
|
||||
return mCore->ordinal();
|
||||
}
|
||||
|
||||
bool StreamBase::setOrdinal(quint32 ordinal)
|
||||
{
|
||||
mCore->set_ordinal(ordinal);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StreamBase::isEnabled() const
|
||||
{
|
||||
return mCore->is_enabled();
|
||||
}
|
||||
|
||||
bool StreamBase::setEnabled(bool flag)
|
||||
{
|
||||
mCore->set_is_enabled(flag);
|
||||
return true;
|
||||
}
|
||||
|
||||
const QString StreamBase::name() const
|
||||
{
|
||||
return QString().fromStdString(mCore->name());
|
||||
}
|
||||
|
||||
bool StreamBase::setName(QString name)
|
||||
{
|
||||
mCore->set_name(name.toStdString());
|
||||
return true;
|
||||
}
|
||||
|
||||
StreamBase::FrameLengthMode StreamBase::lenMode()
|
||||
{
|
||||
return (StreamBase::FrameLengthMode) mCore->len_mode();
|
||||
}
|
||||
|
||||
bool StreamBase::setLenMode(FrameLengthMode lenMode)
|
||||
{
|
||||
mCore->set_len_mode((OstProto::StreamCore::FrameLengthMode) lenMode);
|
||||
return true;
|
||||
}
|
||||
|
||||
quint16 StreamBase::frameLen()
|
||||
{
|
||||
return mCore->frame_len();
|
||||
}
|
||||
|
||||
bool StreamBase::setFrameLen(quint16 frameLen)
|
||||
{
|
||||
mCore->set_frame_len(frameLen);
|
||||
return true;
|
||||
}
|
||||
|
||||
quint16 StreamBase::frameLenMin()
|
||||
{
|
||||
return mCore->frame_len_min();
|
||||
}
|
||||
|
||||
bool StreamBase::setFrameLenMin(quint16 frameLenMin)
|
||||
{
|
||||
mCore->set_frame_len_min(frameLenMin);
|
||||
return true;
|
||||
}
|
||||
|
||||
quint16 StreamBase::frameLenMax()
|
||||
{
|
||||
return mCore->frame_len_max();
|
||||
}
|
||||
|
||||
bool StreamBase::setFrameLenMax(quint16 frameLenMax)
|
||||
{
|
||||
mCore->set_frame_len_max(frameLenMax);
|
||||
return true;
|
||||
}
|
||||
|
||||
StreamBase::SendUnit StreamBase::sendUnit()
|
||||
{
|
||||
return (StreamBase::SendUnit) mControl->unit();
|
||||
}
|
||||
bool StreamBase::setSendUnit(SendUnit sendUnit)
|
||||
{
|
||||
mControl->set_unit((OstProto::StreamControl::SendUnit) sendUnit);
|
||||
return true;
|
||||
}
|
||||
|
||||
StreamBase::SendMode StreamBase::sendMode()
|
||||
{
|
||||
return (StreamBase::SendMode) mControl->mode();
|
||||
}
|
||||
|
||||
bool StreamBase::setSendMode(SendMode sendMode)
|
||||
{
|
||||
mControl->set_mode(
|
||||
(OstProto::StreamControl::SendMode) sendMode);
|
||||
return true;
|
||||
}
|
||||
|
||||
StreamBase::NextWhat StreamBase::nextWhat()
|
||||
{
|
||||
return (StreamBase::NextWhat) mControl->next();
|
||||
}
|
||||
|
||||
bool StreamBase::setNextWhat(NextWhat nextWhat)
|
||||
{
|
||||
mControl->set_next((OstProto::StreamControl::NextWhat) nextWhat);
|
||||
return true;
|
||||
}
|
||||
|
||||
quint32 StreamBase::numPackets()
|
||||
{
|
||||
return (quint32) mControl->num_packets();
|
||||
}
|
||||
|
||||
bool StreamBase::setNumPackets(quint32 numPackets)
|
||||
{
|
||||
mControl->set_num_packets(numPackets);
|
||||
return true;
|
||||
}
|
||||
|
||||
quint32 StreamBase::numBursts()
|
||||
{
|
||||
return (quint32) mControl->num_bursts();
|
||||
}
|
||||
|
||||
bool StreamBase::setNumBursts(quint32 numBursts)
|
||||
{
|
||||
mControl->set_num_bursts(numBursts);
|
||||
return true;
|
||||
}
|
||||
|
||||
quint32 StreamBase::burstSize()
|
||||
{
|
||||
return (quint32) mControl->packets_per_burst();
|
||||
}
|
||||
|
||||
bool StreamBase::setBurstSize(quint32 packetsPerBurst)
|
||||
{
|
||||
mControl->set_packets_per_burst(packetsPerBurst);
|
||||
return true;
|
||||
}
|
||||
|
||||
quint32 StreamBase::packetRate()
|
||||
{
|
||||
return (quint32) mControl->packets_per_sec();
|
||||
}
|
||||
|
||||
bool StreamBase::setPacketRate(quint32 packetsPerSec)
|
||||
{
|
||||
mControl->set_packets_per_sec(packetsPerSec);
|
||||
return true;
|
||||
}
|
||||
|
||||
quint32 StreamBase::burstRate()
|
||||
{
|
||||
return (quint32) mControl->bursts_per_sec();
|
||||
}
|
||||
|
||||
bool StreamBase::setBurstRate(quint32 burstsPerSec)
|
||||
{
|
||||
mControl->set_bursts_per_sec(burstsPerSec);
|
||||
return true;
|
||||
}
|
||||
|
@ -1,21 +1,25 @@
|
||||
#ifndef _STREAM_BASE_H
|
||||
#define _STREAM_BASE_H
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QLinkedList>
|
||||
|
||||
#include "protocolcollection.h"
|
||||
#include "protocol.pb.h"
|
||||
|
||||
class AbstractProtocol;
|
||||
class ProtocolList;
|
||||
class ProtocolListIterator;
|
||||
|
||||
class StreamBase
|
||||
{
|
||||
protected: // TODO: temp - make private
|
||||
private:
|
||||
OstProto::StreamId *mStreamId;
|
||||
OstProto::StreamCore *mCore;
|
||||
OstProto::StreamControl *mControl;
|
||||
|
||||
private:
|
||||
ProtocolList currentFrameProtocols;
|
||||
protected:
|
||||
ProtocolCollection protocols;
|
||||
//! \todo TODO: Make ProtocolList a private member of StreamBase?
|
||||
ProtocolList *currentFrameProtocols;
|
||||
|
||||
public:
|
||||
StreamBase();
|
||||
@ -24,13 +28,91 @@ public:
|
||||
void protoDataCopyFrom(const OstProto::Stream &stream);
|
||||
void protoDataCopyInto(OstProto::Stream &stream) const;
|
||||
|
||||
QList<int> frameProtocol();
|
||||
void setFrameProtocol(QList<int> protocolList);
|
||||
|
||||
AbstractProtocol* protocol(int protoNum);
|
||||
AbstractProtocol* protocol(QString protoName);
|
||||
ProtocolListIterator* createProtocolListIterator();
|
||||
|
||||
// TODO: make a copy constructor
|
||||
|
||||
public:
|
||||
enum FrameLengthMode {
|
||||
e_fl_fixed,
|
||||
e_fl_inc,
|
||||
e_fl_dec,
|
||||
e_fl_random
|
||||
};
|
||||
|
||||
enum SendUnit {
|
||||
e_su_packets,
|
||||
e_su_bursts
|
||||
};
|
||||
|
||||
enum SendMode {
|
||||
e_sm_fixed,
|
||||
e_sm_continuous
|
||||
};
|
||||
|
||||
enum NextWhat {
|
||||
e_nw_stop,
|
||||
e_nw_goto_next,
|
||||
e_nw_goto_id
|
||||
};
|
||||
|
||||
bool operator < (const StreamBase &s) const;
|
||||
|
||||
quint32 id();
|
||||
bool setId(quint32 id);
|
||||
|
||||
#if 0 // FIXME(HI): needed?
|
||||
quint32 portId()
|
||||
{ return mCore->port_id();}
|
||||
bool setPortId(quint32 id)
|
||||
{ mCore->set_port_id(id); return true;}
|
||||
#endif
|
||||
|
||||
quint32 ordinal();
|
||||
bool setOrdinal(quint32 ordinal);
|
||||
|
||||
bool isEnabled() const;
|
||||
bool setEnabled(bool flag);
|
||||
|
||||
const QString name() const ;
|
||||
bool setName(QString name) ;
|
||||
|
||||
// Frame Length (includes FCS);
|
||||
FrameLengthMode lenMode();
|
||||
bool setLenMode(FrameLengthMode lenMode);
|
||||
|
||||
quint16 frameLen();
|
||||
bool setFrameLen(quint16 frameLen);
|
||||
|
||||
quint16 frameLenMin();
|
||||
bool setFrameLenMin(quint16 frameLenMin);
|
||||
|
||||
quint16 frameLenMax();
|
||||
bool setFrameLenMax(quint16 frameLenMax);
|
||||
|
||||
SendUnit sendUnit();
|
||||
bool setSendUnit(SendUnit sendUnit);
|
||||
|
||||
SendMode sendMode();
|
||||
bool setSendMode(SendMode sendMode);
|
||||
|
||||
NextWhat nextWhat();
|
||||
bool setNextWhat(NextWhat nextWhat);
|
||||
|
||||
quint32 numPackets();
|
||||
bool setNumPackets(quint32 numPackets);
|
||||
|
||||
quint32 numBursts();
|
||||
bool setNumBursts(quint32 numBursts);
|
||||
|
||||
quint32 burstSize();
|
||||
bool setBurstSize(quint32 packetsPerBurst);
|
||||
|
||||
quint32 packetRate();
|
||||
bool setPacketRate(quint32 packetsPerSec);
|
||||
|
||||
quint32 burstRate();
|
||||
bool setBurstRate(quint32 burstsPerSec);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -3,45 +3,44 @@
|
||||
|
||||
#include "tcp.h"
|
||||
|
||||
TcpConfigForm *TcpProtocol::configForm = NULL;
|
||||
|
||||
TcpConfigForm::TcpConfigForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
TcpProtocol::TcpProtocol(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent)
|
||||
: AbstractProtocol(frameProtoList, parent)
|
||||
TcpProtocol::TcpProtocol(StreamBase *stream)
|
||||
: AbstractProtocol(stream)
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new TcpConfigForm;
|
||||
configForm = NULL;
|
||||
}
|
||||
|
||||
TcpProtocol::~TcpProtocol()
|
||||
{
|
||||
delete configForm;
|
||||
}
|
||||
|
||||
AbstractProtocol* TcpProtocol::createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore)
|
||||
AbstractProtocol* TcpProtocol::createInstance(StreamBase *stream)
|
||||
{
|
||||
return new TcpProtocol(frameProtoList, streamCore);
|
||||
return new TcpProtocol(stream);
|
||||
}
|
||||
|
||||
void TcpProtocol::protoDataCopyInto(OstProto::Stream &stream)
|
||||
quint32 TcpProtocol::protocolNumber() const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
stream.MutableExtension(OstProto::tcp)->CopyFrom(data);
|
||||
return OstProto::Protocol::kTcpFieldNumber;
|
||||
}
|
||||
|
||||
void TcpProtocol::protoDataCopyFrom(const OstProto::Stream &stream)
|
||||
void TcpProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
if (stream.HasExtension(OstProto::tcp))
|
||||
data.MergeFrom(stream.GetExtension(OstProto::tcp));
|
||||
protocol.MutableExtension(OstProto::tcp)->CopyFrom(data);
|
||||
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
||||
}
|
||||
|
||||
void TcpProtocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
||||
{
|
||||
if (protocol.protocol_id().id() == protocolNumber() &&
|
||||
protocol.HasExtension(OstProto::tcp))
|
||||
data.MergeFrom(protocol.GetExtension(OstProto::tcp));
|
||||
}
|
||||
|
||||
QString TcpProtocol::name() const
|
||||
@ -384,11 +383,15 @@ bool TcpProtocol::setFieldData(int index, const QVariant &value,
|
||||
|
||||
QWidget* TcpProtocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new TcpConfigForm;
|
||||
return configForm;
|
||||
}
|
||||
|
||||
void TcpProtocol::loadConfigWidget()
|
||||
{
|
||||
configWidget();
|
||||
|
||||
configForm->leTcpSrcPort->setText(QString().setNum(data.src_port()));
|
||||
configForm->leTcpDstPort->setText(QString().setNum(data.dst_port()));
|
||||
|
||||
@ -419,6 +422,8 @@ void TcpProtocol::storeConfigWidget()
|
||||
bool isOk;
|
||||
int ff = 0;
|
||||
|
||||
configWidget();
|
||||
|
||||
data.set_src_port(configForm->leTcpSrcPort->text().toULong(&isOk));
|
||||
data.set_dst_port(configForm->leTcpDstPort->text().toULong(&isOk));
|
||||
|
||||
|
14
common/tcp.h
14
common/tcp.h
@ -24,7 +24,7 @@ class TcpProtocol : public AbstractProtocol
|
||||
{
|
||||
private:
|
||||
OstProto::Tcp data;
|
||||
static TcpConfigForm *configForm;
|
||||
TcpConfigForm *configForm;
|
||||
enum tcpfield
|
||||
{
|
||||
tcp_src_port = 0,
|
||||
@ -45,16 +45,14 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
TcpProtocol(ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent = 0);
|
||||
TcpProtocol(StreamBase *stream);
|
||||
virtual ~TcpProtocol();
|
||||
|
||||
static AbstractProtocol* createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore = 0);
|
||||
static AbstractProtocol* createInstance(StreamBase *stream);
|
||||
virtual quint32 protocolNumber() const;
|
||||
|
||||
virtual void protoDataCopyInto(OstProto::Stream &stream);
|
||||
virtual void protoDataCopyFrom(const OstProto::Stream &stream);
|
||||
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
|
||||
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
@ -21,7 +21,7 @@ message Tcp {
|
||||
optional uint32 urg_ptr = 11;
|
||||
}
|
||||
|
||||
extend Stream {
|
||||
extend Protocol {
|
||||
optional Tcp tcp = 140;
|
||||
}
|
||||
|
||||
|
@ -3,45 +3,44 @@
|
||||
|
||||
#include "udp.h"
|
||||
|
||||
UdpConfigForm *UdpProtocol::configForm = NULL;
|
||||
|
||||
UdpConfigForm::UdpConfigForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
UdpProtocol::UdpProtocol(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent)
|
||||
: AbstractProtocol(frameProtoList, parent)
|
||||
UdpProtocol::UdpProtocol(StreamBase *stream)
|
||||
: AbstractProtocol(stream)
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new UdpConfigForm;
|
||||
configForm = NULL;
|
||||
}
|
||||
|
||||
UdpProtocol::~UdpProtocol()
|
||||
{
|
||||
delete configForm;
|
||||
}
|
||||
|
||||
AbstractProtocol* UdpProtocol::createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore)
|
||||
AbstractProtocol* UdpProtocol::createInstance(StreamBase *stream)
|
||||
{
|
||||
return new UdpProtocol(frameProtoList, streamCore);
|
||||
return new UdpProtocol(stream);
|
||||
}
|
||||
|
||||
void UdpProtocol::protoDataCopyInto(OstProto::Stream &stream)
|
||||
quint32 UdpProtocol::protocolNumber() const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
stream.MutableExtension(OstProto::udp)->CopyFrom(data);
|
||||
return OstProto::Protocol::kUdpFieldNumber;
|
||||
}
|
||||
|
||||
void UdpProtocol::protoDataCopyFrom(const OstProto::Stream &stream)
|
||||
void UdpProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
if (stream.HasExtension(OstProto::udp))
|
||||
data.MergeFrom(stream.GetExtension(OstProto::udp));
|
||||
protocol.MutableExtension(OstProto::udp)->CopyFrom(data);
|
||||
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
||||
}
|
||||
|
||||
void UdpProtocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
||||
{
|
||||
if (protocol.protocol_id().id() == protocolNumber() &&
|
||||
protocol.HasExtension(OstProto::udp))
|
||||
data.MergeFrom(protocol.GetExtension(OstProto::udp));
|
||||
}
|
||||
|
||||
QString UdpProtocol::name() const
|
||||
@ -261,11 +260,15 @@ bool UdpProtocol::setFieldData(int index, const QVariant &value,
|
||||
|
||||
QWidget* UdpProtocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new UdpConfigForm;
|
||||
return configForm;
|
||||
}
|
||||
|
||||
void UdpProtocol::loadConfigWidget()
|
||||
{
|
||||
configWidget();
|
||||
|
||||
configForm->leUdpSrcPort->setText(fieldData(udp_srcPort, FieldValue).toString());
|
||||
configForm->leUdpDstPort->setText(fieldData(udp_dstPort, FieldValue).toString());
|
||||
|
||||
@ -281,6 +284,8 @@ void UdpProtocol::storeConfigWidget()
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
configWidget();
|
||||
|
||||
data.set_src_port(configForm->leUdpSrcPort->text().toULong(&isOk));
|
||||
data.set_dst_port(configForm->leUdpDstPort->text().toULong(&isOk));
|
||||
|
||||
|
14
common/udp.h
14
common/udp.h
@ -17,7 +17,7 @@ class UdpProtocol : public AbstractProtocol
|
||||
{
|
||||
private:
|
||||
OstProto::Udp data;
|
||||
static UdpConfigForm *configForm;
|
||||
UdpConfigForm *configForm;
|
||||
enum udpfield
|
||||
{
|
||||
udp_srcPort = 0,
|
||||
@ -32,16 +32,14 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
UdpProtocol(ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent = 0);
|
||||
UdpProtocol(StreamBase *stream);
|
||||
virtual ~UdpProtocol();
|
||||
|
||||
static AbstractProtocol* createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore = 0);
|
||||
static AbstractProtocol* createInstance(StreamBase *stream);
|
||||
virtual quint32 protocolNumber() const;
|
||||
|
||||
virtual void protoDataCopyInto(OstProto::Stream &stream);
|
||||
virtual void protoDataCopyFrom(const OstProto::Stream &stream);
|
||||
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
|
||||
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
@ -13,6 +13,6 @@ message Udp {
|
||||
optional uint32 cksum = 6;
|
||||
}
|
||||
|
||||
extend Stream {
|
||||
extend Protocol {
|
||||
optional Udp udp = 141;
|
||||
}
|
||||
|
@ -2,45 +2,44 @@
|
||||
|
||||
#include "vlan.h"
|
||||
|
||||
VlanConfigForm *VlanProtocol::configForm = NULL;
|
||||
|
||||
VlanConfigForm::VlanConfigForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
}
|
||||
|
||||
VlanProtocol::VlanProtocol(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent)
|
||||
: AbstractProtocol(frameProtoList, parent)
|
||||
VlanProtocol::VlanProtocol(StreamBase *stream)
|
||||
: AbstractProtocol(stream)
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new VlanConfigForm;
|
||||
configForm = NULL;
|
||||
}
|
||||
|
||||
VlanProtocol::~VlanProtocol()
|
||||
{
|
||||
delete configForm;
|
||||
}
|
||||
|
||||
AbstractProtocol* VlanProtocol::createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore)
|
||||
AbstractProtocol* VlanProtocol::createInstance(StreamBase *stream)
|
||||
{
|
||||
return new VlanProtocol(frameProtoList, streamCore);
|
||||
return new VlanProtocol(stream);
|
||||
}
|
||||
|
||||
void VlanProtocol::protoDataCopyInto(OstProto::Stream &stream)
|
||||
quint32 VlanProtocol::protocolNumber() const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
stream.MutableExtension(OstProto::vlan)->CopyFrom(data);
|
||||
return OstProto::Protocol::kVlanFieldNumber;
|
||||
}
|
||||
|
||||
void VlanProtocol::protoDataCopyFrom(const OstProto::Stream &stream)
|
||||
void VlanProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
||||
{
|
||||
// FIXME: multiple headers
|
||||
if (stream.HasExtension(OstProto::vlan))
|
||||
data.MergeFrom(stream.GetExtension(OstProto::vlan));
|
||||
protocol.MutableExtension(OstProto::vlan)->CopyFrom(data);
|
||||
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
||||
}
|
||||
|
||||
void VlanProtocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
||||
{
|
||||
if (protocol.protocol_id().id() == protocolNumber() &&
|
||||
protocol.HasExtension(OstProto::vlan))
|
||||
data.MergeFrom(protocol.GetExtension(OstProto::vlan));
|
||||
}
|
||||
|
||||
QString VlanProtocol::name() const
|
||||
@ -203,22 +202,27 @@ bool VlanProtocol::setFieldData(int index, const QVariant &value,
|
||||
|
||||
QWidget* VlanProtocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
configForm = new VlanConfigForm;
|
||||
return configForm;
|
||||
}
|
||||
|
||||
void VlanProtocol::loadConfigWidget()
|
||||
{
|
||||
configWidget();
|
||||
|
||||
configForm->leTpid->setText(uintToHexStr(fieldData(vlan_tpid, FieldValue).toUInt(), 2));
|
||||
configForm->cmbPrio->setCurrentIndex(fieldData(vlan_prio, FieldValue).toUInt());
|
||||
configForm->cmbCfiDei->setCurrentIndex(fieldData(vlan_cfiDei, FieldValue).toUInt());
|
||||
configForm->leVlanId->setText(fieldData(vlan_vlanId, FieldValue).toString());
|
||||
|
||||
}
|
||||
|
||||
void VlanProtocol::storeConfigWidget()
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
configWidget();
|
||||
|
||||
data.set_is_override_tpid(configForm->cbTpidOverride->isChecked());
|
||||
data.set_tpid(configForm->leTpid->text().remove(QChar(' ')).toULong(&isOk, BASE_HEX));
|
||||
data.set_vlan_tag(
|
||||
|
@ -17,7 +17,7 @@ class VlanProtocol : public AbstractProtocol
|
||||
{
|
||||
private:
|
||||
OstProto::Vlan data;
|
||||
static VlanConfigForm *configForm;
|
||||
VlanConfigForm *configForm;
|
||||
enum Vlanfield
|
||||
{
|
||||
vlan_tpid,
|
||||
@ -32,16 +32,14 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
VlanProtocol(ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *parent = 0);
|
||||
VlanProtocol(StreamBase *stream);
|
||||
virtual ~VlanProtocol();
|
||||
|
||||
static AbstractProtocol* createInstance(
|
||||
ProtocolList &frameProtoList,
|
||||
OstProto::StreamCore *streamCore = 0);
|
||||
static AbstractProtocol* createInstance(StreamBase *stream);
|
||||
virtual quint32 protocolNumber() const;
|
||||
|
||||
virtual void protoDataCopyInto(OstProto::Stream &stream);
|
||||
virtual void protoDataCopyFrom(const OstProto::Stream &stream);
|
||||
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
|
||||
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
@ -10,6 +10,6 @@ message Vlan {
|
||||
optional uint32 vlan_tag = 3; // includes prio, cfi and vlanid
|
||||
}
|
||||
|
||||
extend Stream {
|
||||
extend Protocol {
|
||||
optional Vlan vlan = 126;
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
#include "myservice.h"
|
||||
#include "qdebug.h"
|
||||
|
||||
#include <qglobal.h>
|
||||
#include <qendian.h>
|
||||
#include "qdebug.h"
|
||||
|
||||
#include "myservice.h"
|
||||
#include "../common/protocollist.h"
|
||||
#include "../common/abstractprotocol.h"
|
||||
|
||||
|
||||
#if 0
|
||||
#include <pcap-int.h>
|
||||
@ -26,50 +30,31 @@ StreamInfo::~StreamInfo()
|
||||
{
|
||||
}
|
||||
|
||||
#if 0
|
||||
quint32 StreamInfo::pseudoHdrCksumPartial(quint32 srcIp, quint32 dstIp,
|
||||
quint8 protocol, quint16 len)
|
||||
{
|
||||
quint32 sum;
|
||||
|
||||
sum = srcIp >> 16;
|
||||
sum += srcIp & 0xFFFF;
|
||||
sum += dstIp >> 16;
|
||||
sum += dstIp & 0xFFFF;
|
||||
sum += (quint16) (protocol);
|
||||
sum += len;
|
||||
|
||||
// Above calculation done assuming 'big endian' - so convert to host order
|
||||
return qFromBigEndian(sum);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int StreamInfo::makePacket(uchar *buf, int bufMaxSize, int n)
|
||||
{
|
||||
int pktLen, len = 0;
|
||||
|
||||
// Decide a frame length based on length mode
|
||||
switch(mCore->len_mode())
|
||||
switch(lenMode())
|
||||
{
|
||||
case OstProto::StreamCore::e_fl_fixed:
|
||||
pktLen = mCore->frame_len();
|
||||
pktLen = frameLen();
|
||||
break;
|
||||
case OstProto::StreamCore::e_fl_inc:
|
||||
pktLen = mCore->frame_len_min() + (n %
|
||||
(mCore->frame_len_max() - mCore->frame_len_min() + 1));
|
||||
pktLen = frameLenMin() + (n %
|
||||
(frameLenMax() - frameLenMin() + 1));
|
||||
break;
|
||||
case OstProto::StreamCore::e_fl_dec:
|
||||
pktLen = mCore->frame_len_max() - (n %
|
||||
(mCore->frame_len_max() - mCore->frame_len_min() + 1));
|
||||
pktLen = frameLenMax() - (n %
|
||||
(frameLenMax() - frameLenMin() + 1));
|
||||
break;
|
||||
case OstProto::StreamCore::e_fl_random:
|
||||
pktLen = mCore->frame_len_min() + (qrand() %
|
||||
(mCore->frame_len_max() - mCore->frame_len_min() + 1));
|
||||
pktLen = frameLenMin() + (qrand() %
|
||||
(frameLenMax() - frameLenMin() + 1));
|
||||
break;
|
||||
default:
|
||||
qWarning("Unhandled len mode %d. Using default 64",
|
||||
mCore->len_mode());
|
||||
lenMode());
|
||||
pktLen = 64;
|
||||
break;
|
||||
}
|
||||
@ -81,11 +66,11 @@ int StreamInfo::makePacket(uchar *buf, int bufMaxSize, int n)
|
||||
return 0;
|
||||
|
||||
// FIXME: Calculated pktLen is an input to Payload Protocol
|
||||
for (int i = 0; i < mCore->frame_proto_size(); i++)
|
||||
foreach(const AbstractProtocol* proto, *currentFrameProtocols)
|
||||
{
|
||||
QByteArray ba;
|
||||
|
||||
ba = protocol(mCore->frame_proto(i))->protocolFrameValue(n);
|
||||
ba = proto->protocolFrameValue(n);
|
||||
if (len + ba.size() < bufMaxSize)
|
||||
{
|
||||
memcpy(buf+len, ba.constData(), ba.size());
|
||||
@ -94,379 +79,6 @@ int StreamInfo::makePacket(uchar *buf, int bufMaxSize, int n)
|
||||
}
|
||||
|
||||
return pktLen;
|
||||
|
||||
#if 0 // Proto FW
|
||||
int u, pktLen, dataLen, len = 0;
|
||||
quint32 srcIp, dstIp; // need it later for TCP/UDP cksum calculation
|
||||
quint32 cumCksum = 0; // cumulative cksum used to combine partial cksums
|
||||
int tcpOfs, udpOfs; // needed to fill in cksum later
|
||||
uchar scratch[8];
|
||||
|
||||
// We always have a Mac Header!
|
||||
switch (d.mac().dst_mac_mode())
|
||||
{
|
||||
case OstProto::Mac::e_mm_fixed:
|
||||
qToBigEndian((quint64) d.mac().dst_mac(), scratch);
|
||||
break;
|
||||
case OstProto::Mac::e_mm_inc:
|
||||
u = (n % d.mac().dst_mac_count()) * d.mac().dst_mac_step();
|
||||
qToBigEndian((quint64) d.mac().dst_mac() + u, scratch);
|
||||
break;
|
||||
case OstProto::Mac::e_mm_dec:
|
||||
u = (n % d.mac().dst_mac_count()) * d.mac().dst_mac_step();
|
||||
qToBigEndian((quint64) d.mac().dst_mac() - u, scratch);
|
||||
break;
|
||||
default:
|
||||
qWarning("Unhandled dstMac_mode %d", d.mac().dst_mac_mode());
|
||||
}
|
||||
memcpy((buf + len), scratch + 2, 6);
|
||||
len += 6;
|
||||
|
||||
switch (d.mac().src_mac_mode())
|
||||
{
|
||||
case OstProto::Mac::e_mm_fixed:
|
||||
qToBigEndian((quint64) d.mac().src_mac(), scratch);
|
||||
break;
|
||||
case OstProto::Mac::e_mm_inc:
|
||||
u = (n % d.mac().src_mac_count()) * d.mac().src_mac_step();
|
||||
qToBigEndian((quint64) d.mac().src_mac() + u, scratch);
|
||||
break;
|
||||
case OstProto::Mac::e_mm_dec:
|
||||
u = (n % d.mac().src_mac_count()) * d.mac().src_mac_step();
|
||||
qToBigEndian((quint64) d.mac().src_mac() - u, scratch);
|
||||
break;
|
||||
default:
|
||||
qWarning("Unhandled srcMac_mode %d", d.mac().src_mac_mode());
|
||||
}
|
||||
memcpy((buf + len), scratch + 2, 6);
|
||||
len += 6;
|
||||
|
||||
|
||||
// Frame Type - Part 1 (pre VLAN info)
|
||||
switch(d.core().ft())
|
||||
{
|
||||
case OstProto::StreamCore::e_ft_none:
|
||||
case OstProto::StreamCore::e_ft_eth_2:
|
||||
break;
|
||||
case OstProto::StreamCore::e_ft_802_3_raw:
|
||||
qToBigEndian((quint16) pktLen, buf+len);
|
||||
len += 2;
|
||||
break;
|
||||
case OstProto::StreamCore::e_ft_802_3_llc:
|
||||
qToBigEndian((quint16) pktLen, buf+len);
|
||||
len += 2;
|
||||
buf[len+0] = (quint8) d.llc().dsap();
|
||||
buf[len+1] = (quint8) d.llc().ssap();
|
||||
buf[len+2] = (quint8) d.llc().ctl();
|
||||
len +=3;
|
||||
break;
|
||||
case OstProto::StreamCore::e_ft_snap:
|
||||
qToBigEndian((quint16) pktLen, buf+len);
|
||||
len += 2;
|
||||
buf[len+0] = (quint8) d.llc().dsap();
|
||||
buf[len+1] = (quint8) d.llc().ssap();
|
||||
buf[len+2] = (quint8) d.llc().ctl();
|
||||
len +=3;
|
||||
qToBigEndian((quint32) d.snap().oui(), scratch);
|
||||
memcpy((buf + len), scratch + 2, 3);
|
||||
len += 3;
|
||||
break;
|
||||
default:
|
||||
qWarning("Unhandled frame type %d\n", d.core().ft());
|
||||
}
|
||||
|
||||
// VLAN
|
||||
if (d.vlan().is_svlan_tagged())
|
||||
{
|
||||
if (d.vlan().is_stpid_override())
|
||||
qToBigEndian((quint16) d.vlan().stpid(), buf+len);
|
||||
else
|
||||
qToBigEndian((quint16) 0x88a8, buf+len);
|
||||
len += 2 ;
|
||||
|
||||
qToBigEndian((quint16) d.vlan().svlan_tag(), buf+len);
|
||||
len += 2 ;
|
||||
}
|
||||
|
||||
if (d.vlan().is_cvlan_tagged())
|
||||
{
|
||||
if (d.vlan().is_ctpid_override())
|
||||
qToBigEndian((quint16) d.vlan().ctpid(), buf+len);
|
||||
else
|
||||
qToBigEndian((quint16) 0x8100, buf+len);
|
||||
len += 2 ;
|
||||
|
||||
qToBigEndian((quint16) d.vlan().cvlan_tag(), buf+len);
|
||||
len += 2 ;
|
||||
}
|
||||
|
||||
// Frame Type - Part 2 (post VLAN info)
|
||||
switch(d.core().ft())
|
||||
{
|
||||
case OstProto::StreamCore::e_ft_none:
|
||||
break;
|
||||
case OstProto::StreamCore::e_ft_eth_2:
|
||||
qToBigEndian((quint16) d.eth2().type(), buf+len);
|
||||
len += 2;
|
||||
break;
|
||||
case OstProto::StreamCore::e_ft_802_3_raw:
|
||||
case OstProto::StreamCore::e_ft_802_3_llc:
|
||||
break;
|
||||
case OstProto::StreamCore::e_ft_snap:
|
||||
qToBigEndian((quint16) d.eth2().type(), buf+len);
|
||||
len += 2;
|
||||
break;
|
||||
default:
|
||||
qWarning("Unhandled frame type %d\n", d.core().ft());
|
||||
}
|
||||
|
||||
// L3
|
||||
switch (d.core().l3_proto())
|
||||
{
|
||||
case OstProto::StreamCore::e_l3_none:
|
||||
break;
|
||||
case OstProto::StreamCore::e_l3_ip:
|
||||
{
|
||||
quint32 subnet, host;
|
||||
int ipOfs = len;
|
||||
|
||||
buf[len+0] = (quint8) (d.ip().ver_hdrlen());
|
||||
buf[len+1] = (quint8) (d.ip().tos());
|
||||
len += 2;
|
||||
|
||||
if (d.ip().is_override_totlen())
|
||||
qToBigEndian((quint16) d.ip().tot_len(), buf+len);
|
||||
else
|
||||
qToBigEndian((quint16) (pktLen - ipOfs), buf+len);
|
||||
len += 2;
|
||||
|
||||
qToBigEndian((quint16) d.ip().id(), buf+len);
|
||||
len += 2;
|
||||
|
||||
qToBigEndian((quint16) (( (d.ip().flags() & 0x3) << 13) |
|
||||
(d.ip().frag_ofs() & 0x1FFF)), buf+len);
|
||||
len += 2;
|
||||
|
||||
buf[len+0] = (quint8) (d.ip().ttl());
|
||||
buf[len+1] = (quint8) (d.ip().proto());
|
||||
len += 2;
|
||||
|
||||
// cksum calculated after filling in the rest
|
||||
qToBigEndian((quint16) 0, buf+len);
|
||||
len += 2;
|
||||
|
||||
// Get Src/Dst IP for this packet using respective IpMode
|
||||
switch(d.ip().src_ip_mode())
|
||||
{
|
||||
case OstProto::Ip::e_im_fixed:
|
||||
srcIp = (quint32) d.ip().src_ip();
|
||||
qToBigEndian(srcIp, buf+len);
|
||||
break;
|
||||
case OstProto::Ip::e_im_inc_host:
|
||||
u = n % d.ip().src_ip_count();
|
||||
subnet = d.ip().src_ip() & d.ip().src_ip_mask();
|
||||
host = (((d.ip().src_ip() & ~d.ip().src_ip_mask()) + u) &
|
||||
~d.ip().src_ip_mask());
|
||||
srcIp = (quint32) (subnet | host);
|
||||
qToBigEndian(srcIp, buf+len);
|
||||
break;
|
||||
case OstProto::Ip::e_im_dec_host:
|
||||
u = n % d.ip().src_ip_count();
|
||||
subnet = d.ip().src_ip() & d.ip().src_ip_mask();
|
||||
host = (((d.ip().src_ip() & ~d.ip().src_ip_mask()) - u) &
|
||||
~d.ip().src_ip_mask());
|
||||
srcIp = (quint32) (subnet | host);
|
||||
qToBigEndian(srcIp, buf+len);
|
||||
break;
|
||||
case OstProto::Ip::e_im_random_host:
|
||||
subnet = d.ip().src_ip() & d.ip().src_ip_mask();
|
||||
host = (qrand() & ~d.ip().src_ip_mask());
|
||||
srcIp = (quint32) (subnet | host);
|
||||
qToBigEndian(srcIp, buf+len);
|
||||
break;
|
||||
default:
|
||||
qWarning("Unhandled src_ip_mode = %d", d.ip().src_ip_mode());
|
||||
}
|
||||
len +=4;
|
||||
|
||||
switch(d.ip().dst_ip_mode())
|
||||
{
|
||||
case OstProto::Ip::e_im_fixed:
|
||||
dstIp = (quint32) d.ip().dst_ip();
|
||||
qToBigEndian(dstIp, buf+len);
|
||||
break;
|
||||
case OstProto::Ip::e_im_inc_host:
|
||||
u = n % d.ip().dst_ip_count();
|
||||
subnet = d.ip().dst_ip() & d.ip().dst_ip_mask();
|
||||
host = (((d.ip().dst_ip() & ~d.ip().dst_ip_mask()) + u) &
|
||||
~d.ip().dst_ip_mask());
|
||||
dstIp = (quint32) (subnet | host);
|
||||
qToBigEndian(dstIp, buf+len);
|
||||
break;
|
||||
case OstProto::Ip::e_im_dec_host:
|
||||
u = n % d.ip().dst_ip_count();
|
||||
subnet = d.ip().dst_ip() & d.ip().dst_ip_mask();
|
||||
host = (((d.ip().dst_ip() & ~d.ip().dst_ip_mask()) - u) &
|
||||
~d.ip().dst_ip_mask());
|
||||
dstIp = (quint32) (subnet | host);
|
||||
qToBigEndian(dstIp, buf+len);
|
||||
break;
|
||||
case OstProto::Ip::e_im_random_host:
|
||||
subnet = d.ip().dst_ip() & d.ip().dst_ip_mask();
|
||||
host = (qrand() & ~d.ip().dst_ip_mask());
|
||||
dstIp = (quint32) (subnet | host);
|
||||
qToBigEndian(dstIp, buf+len);
|
||||
break;
|
||||
default:
|
||||
qWarning("Unhandled dst_ip_mode = %d", d.ip().dst_ip_mode());
|
||||
}
|
||||
len +=4;
|
||||
|
||||
// Calculate and fill in cksum (unless overridden)
|
||||
if (d.ip().is_override_cksum())
|
||||
qToBigEndian((quint16) d.ip().cksum(), buf+ipOfs+10);
|
||||
else
|
||||
*((quint16*)(buf + ipOfs + 10)) = ipv4Cksum(buf + ipOfs, len-ipOfs);
|
||||
break;
|
||||
|
||||
}
|
||||
case OstProto::StreamCore::e_l3_arp:
|
||||
// TODO(LOW)
|
||||
break;
|
||||
default:
|
||||
qWarning("Unhandled l3 proto %d\n", d.core().l3_proto());
|
||||
}
|
||||
|
||||
switch (d.core().l4_proto())
|
||||
{
|
||||
case OstProto::StreamCore::e_l4_none:
|
||||
break;
|
||||
case OstProto::StreamCore::e_l4_tcp:
|
||||
{
|
||||
tcpOfs = len;
|
||||
|
||||
cumCksum = pseudoHdrCksumPartial(srcIp, dstIp, 6, pktLen - len);
|
||||
|
||||
qToBigEndian((quint16) d.tcp().src_port(), buf+len);
|
||||
len += 2;
|
||||
qToBigEndian((quint16) d.tcp().dst_port(), buf+len);
|
||||
len += 2;
|
||||
|
||||
qToBigEndian((quint32) d.tcp().seq_num(), buf+len);
|
||||
len += 4;
|
||||
qToBigEndian((quint32) d.tcp().ack_num(), buf+len);
|
||||
len += 4;
|
||||
|
||||
if (d.tcp().is_override_hdrlen())
|
||||
buf[len+0] = (quint8) d.tcp().hdrlen_rsvd();
|
||||
else
|
||||
buf[len+0] = (quint8) 0x50; // FIXME(LOW): Hardcoding
|
||||
buf[len+1] = (quint8) d.tcp().flags();
|
||||
len += 2;
|
||||
|
||||
qToBigEndian((quint16) d.tcp().window(), buf+len);
|
||||
len +=2;
|
||||
|
||||
// Fill in cksum as 0 for cksum calculation, actual cksum filled later
|
||||
qToBigEndian((quint16) 0, buf+len);
|
||||
len +=2;
|
||||
|
||||
qToBigEndian((quint16) d.tcp().urg_ptr(), buf+len);
|
||||
len +=2;
|
||||
|
||||
// Accumulate cumulative cksum
|
||||
cumCksum += ipv4CksumPartial(buf + tcpOfs, len - tcpOfs);
|
||||
|
||||
break;
|
||||
}
|
||||
case OstProto::StreamCore::e_l4_udp:
|
||||
{
|
||||
udpOfs = len;
|
||||
|
||||
cumCksum = pseudoHdrCksumPartial(srcIp, dstIp, 17, pktLen - len);
|
||||
|
||||
qToBigEndian((quint16) d.udp().src_port(), buf+len);
|
||||
len += 2;
|
||||
qToBigEndian((quint16) d.udp().dst_port(), buf+len);
|
||||
len += 2;
|
||||
|
||||
if (d.udp().is_override_totlen())
|
||||
qToBigEndian((quint16) d.udp().totlen(), buf+len);
|
||||
else
|
||||
qToBigEndian((quint16) (pktLen - udpOfs), buf+len);
|
||||
len +=2;
|
||||
|
||||
// Fill in cksum as 0 for cksum calculation, actual cksum filled later
|
||||
qToBigEndian((quint16) 0, buf+len);
|
||||
len +=2;
|
||||
|
||||
// Accumulate cumulative cksum
|
||||
cumCksum += ipv4CksumPartial(buf + udpOfs, len - udpOfs);
|
||||
|
||||
break;
|
||||
}
|
||||
case OstProto::StreamCore::e_l4_icmp:
|
||||
// TODO(LOW)
|
||||
break;
|
||||
case OstProto::StreamCore::e_l4_igmp:
|
||||
// TODO(LOW)
|
||||
break;
|
||||
default:
|
||||
qWarning("Unhandled l4 proto %d\n", d.core().l4_proto());
|
||||
}
|
||||
|
||||
// Fill-in the data pattern
|
||||
dataLen = pktLen - len;
|
||||
switch(d.core().pattern_mode())
|
||||
{
|
||||
case OstProto::StreamCore::e_dp_fixed_word:
|
||||
for (int i = 0; i < (dataLen/4)+1; i++)
|
||||
qToBigEndian((quint32) d.core().pattern(), buf+len+(i*4));
|
||||
break;
|
||||
case OstProto::StreamCore::e_dp_inc_byte:
|
||||
for (int i = 0; i < dataLen; i++)
|
||||
buf[len + i] = i % (0xFF + 1);
|
||||
break;
|
||||
case OstProto::StreamCore::e_dp_dec_byte:
|
||||
for (int i = 0; i < dataLen; i++)
|
||||
buf[len + i] = 0xFF - (i % (0xFF + 1));
|
||||
break;
|
||||
case OstProto::StreamCore::e_dp_random:
|
||||
for (int i = 0; i < dataLen; i++)
|
||||
buf[len + i] = qrand() % (0xFF + 1);
|
||||
break;
|
||||
default:
|
||||
qWarning("Unhandled data pattern %d", d.core().pattern_mode());
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0 // Proto FW
|
||||
// Calculate TCP/UDP checksum over the data pattern/payload and fill in
|
||||
switch (d.core().l4_proto())
|
||||
{
|
||||
case OstProto::StreamCore::e_l4_tcp:
|
||||
if (d.tcp().is_override_cksum())
|
||||
qToBigEndian((quint16) d.tcp().cksum(), buf + tcpOfs + 16);
|
||||
else
|
||||
*((quint16*)(buf + tcpOfs + 16)) =
|
||||
ipv4Cksum(buf + len, dataLen, cumCksum);
|
||||
break;
|
||||
case OstProto::StreamCore::e_l4_udp:
|
||||
if (d.udp().is_override_cksum())
|
||||
qToBigEndian((quint16) d.udp().cksum(), buf + udpOfs + 6);
|
||||
else
|
||||
*((quint16*)(buf + udpOfs + 6)) =
|
||||
ipv4Cksum(buf + len, dataLen, cumCksum);
|
||||
break;
|
||||
case OstProto::StreamCore::e_l4_none:
|
||||
case OstProto::StreamCore::e_l4_icmp:
|
||||
case OstProto::StreamCore::e_l4_igmp:
|
||||
// No cksum processing required
|
||||
break;
|
||||
}
|
||||
return pktLen;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -589,28 +201,28 @@ void PortInfo::update()
|
||||
for (int i = 0; i < streamList.size(); i++)
|
||||
{
|
||||
//_restart:
|
||||
if (streamList[i]->mCore->is_enabled())
|
||||
if (streamList[i]->isEnabled())
|
||||
{
|
||||
long numPackets, numBursts;
|
||||
long ibg, ipg;
|
||||
|
||||
switch (streamList[i]->mControl->unit())
|
||||
switch (streamList[i]->sendUnit())
|
||||
{
|
||||
case OstProto::StreamControl::e_su_bursts:
|
||||
numBursts = streamList[i]->mControl->num_bursts();
|
||||
numPackets = streamList[i]->mControl->packets_per_burst();
|
||||
ibg = 1000000/streamList[i]->mControl->bursts_per_sec();
|
||||
numBursts = streamList[i]->numBursts();
|
||||
numPackets = streamList[i]->burstSize();
|
||||
ibg = 1000000/streamList[i]->burstRate();
|
||||
ipg = 0;
|
||||
break;
|
||||
case OstProto::StreamControl::e_su_packets:
|
||||
numBursts = 1;
|
||||
numPackets = streamList[i]->mControl->num_packets();
|
||||
numPackets = streamList[i]->numPackets();
|
||||
ibg = 0;
|
||||
ipg = 1000000/streamList[i]->mControl->packets_per_sec();
|
||||
ipg = 1000000/streamList[i]->packetRate();
|
||||
break;
|
||||
default:
|
||||
qWarning("Unhandled stream control unit %d",
|
||||
streamList[i]->mControl->unit());
|
||||
streamList[i]->sendUnit());
|
||||
continue;
|
||||
}
|
||||
qDebug("numBursts = %ld, numPackets = %ld\n",
|
||||
@ -672,7 +284,7 @@ void PortInfo::update()
|
||||
}
|
||||
} // for (numBursts)
|
||||
|
||||
switch(streamList[i]->mControl->next())
|
||||
switch(streamList[i]->nextWhat())
|
||||
{
|
||||
case ::OstProto::StreamControl::e_nw_stop:
|
||||
goto _stop_no_more_pkts;
|
||||
@ -697,7 +309,7 @@ void PortInfo::update()
|
||||
|
||||
default:
|
||||
qFatal("---------- %s: Unhandled case (%d) -----------",
|
||||
__FUNCTION__, streamList[i]->mControl->next() );
|
||||
__FUNCTION__, streamList[i]->nextWhat() );
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user