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:
Srivats P. 2009-08-02 14:52:34 +00:00
parent 0103696016
commit 1357f495ac
57 changed files with 1370 additions and 1192 deletions

View File

@ -1,18 +1,24 @@
#include <QHostAddress> #include <QHostAddress>
#include "packetmodel.h"
PacketModel::PacketModel(const QList<AbstractProtocol*> &selectedProtocols, #include "packetmodel.h"
QObject *parent) #include "../common/protocollistiterator.h"
#include "../common/abstractprotocol.h"
PacketModel::PacketModel(QObject *parent)
{ {
mSelectedProtocols = selectedProtocols;
} }
void PacketModel::setSelectedProtocols( void PacketModel::setSelectedProtocols(ProtocolListIterator &iter)
const QList<AbstractProtocol*> &selectedProtocols)
{ {
if (mSelectedProtocols != selectedProtocols) QList<const AbstractProtocol*> currentProtocols;
iter.toFront();
while (iter.hasNext())
currentProtocols.append(iter.next());
if (mSelectedProtocols != currentProtocols)
{ {
mSelectedProtocols = selectedProtocols; mSelectedProtocols = currentProtocols;
reset(); reset();
} }
} }

View File

@ -2,16 +2,16 @@
#define _PACKET_MODEL_H #define _PACKET_MODEL_H
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include "abstractprotocol.h"
class ProtocolListIterator;
class AbstractProtocol;
class PacketModel: public QAbstractItemModel class PacketModel: public QAbstractItemModel
{ {
public: public:
PacketModel(const QList<AbstractProtocol*> &selectedProtocols, PacketModel(QObject *parent = 0);
QObject *parent = 0); void setSelectedProtocols(ProtocolListIterator &iter);
void setSelectedProtocols(
const QList<AbstractProtocol*> &selectedProtocols);
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const;
@ -34,7 +34,7 @@ private:
} ws; } ws;
} IndexId; } IndexId;
QList<AbstractProtocol*> mSelectedProtocols; QList<const AbstractProtocol*> mSelectedProtocols;
}; };
#endif #endif

View File

@ -2,16 +2,14 @@
#include <QHostAddress> #include <QHostAddress>
#include "stream.h" #include "stream.h"
//#include "../common/protocollist.h"
#include "../common/protocollistiterator.h"
#include "../common/abstractprotocol.h"
Stream::Stream() Stream::Stream()
{ {
//mId = 0xFFFFFFFF; //mId = 0xFFFFFFFF;
mCore->set_is_enabled(true); setEnabled(true);
QList<int> protoList;
protoList.append(51);
protoList.append(52);
setFrameProtocol(protoList);
} }
Stream::~Stream() Stream::~Stream()
@ -20,10 +18,43 @@ Stream::~Stream()
void Stream::loadProtocolWidgets() 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() 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
} }

View File

@ -13,135 +13,11 @@ class Stream : public StreamBase {
//quint32 mId; //quint32 mId;
public: 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();
~Stream(); ~Stream();
// TODO: Below methods move to StreamBase??? void loadProtocolWidgets();
void storeProtocolWidgets();
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; }
}; };
#endif #endif

View File

@ -1,9 +1,16 @@
#include <QHostAddress> #include <QHostAddress>
#include "streamconfigdialog.h" #include "streamconfigdialog.h"
#include "stream.h" #include "stream.h"
#include "abstractprotocol.h"
#include "protocollistiterator.h"
#include "modeltest.h" #include "modeltest.h"
// FIXME(HI) - remove
#include "../common/protocolmanager.h"
extern ProtocolManager OstProtocolManager;
int StreamConfigDialog::lastTopLevelTabIndex = 0; int StreamConfigDialog::lastTopLevelTabIndex = 0;
int StreamConfigDialog::lastProtoTabIndex = 0; int StreamConfigDialog::lastProtoTabIndex = 0;
@ -15,6 +22,7 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
mpStream = new Stream; mpStream = new Stream;
mPort.streamByIndex(mCurrentStreamIndex)->protoDataCopyInto(s); mPort.streamByIndex(mCurrentStreamIndex)->protoDataCopyInto(s);
mpStream->protoDataCopyFrom(s); mpStream->protoDataCopyFrom(s);
_iter = mpStream->createProtocolListIterator();
setupUi(this); setupUi(this);
setupUiExtra(); setupUiExtra();
@ -97,8 +105,12 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
// Force L4 Protocol = None if L3 Protocol is set to ARP // Force L4 Protocol = None if L3 Protocol is set to ARP
connect(rbL3Arp, SIGNAL(toggled(bool)), rbL4None, SLOT(setChecked(bool))); connect(rbL3Arp, SIGNAL(toggled(bool)), rbL4None, SLOT(setChecked(bool)));
mpAvailableProtocolsModel = new QStringListModel(
OstProtocolManager.protocolDatabase(), this);
lvAllProtocols->setModel(mpAvailableProtocolsModel);
LoadCurrentStream(); LoadCurrentStream();
mpPacketModel = new PacketModel(QList<AbstractProtocol*>(), this); mpPacketModel = new PacketModel(this);
tvPacketTree->setModel(mpPacketModel); tvPacketTree->setModel(mpPacketModel);
mpPacketModelTester = new ModelTest(mpPacketModel); mpPacketModelTester = new ModelTest(mpPacketModel);
tvPacketTree->header()->hide(); tvPacketTree->header()->hide();
@ -134,6 +146,7 @@ void StreamConfigDialog::setupUiExtra()
QRegExp reHex4B("[0-9,a-f,A-F]{1,8}"); 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}"); 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 // Add the Payload widget to the dialog
{ {
QGridLayout *layout; QGridLayout *layout;
@ -143,6 +156,7 @@ void StreamConfigDialog::setupUiExtra()
layout->addWidget(mpStream->protocol(52)->configWidget(), 0, 1); layout->addWidget(mpStream->protocol(52)->configWidget(), 0, 1);
qDebug("setupUi wgt = %p", mpStream->protocol(52)->configWidget()); qDebug("setupUi wgt = %p", mpStream->protocol(52)->configWidget());
} }
#endif
// ---- Setup default stuff that cannot be done in designer ---- // ---- Setup default stuff that cannot be done in designer ----
gbVlan->setDisabled(true); gbVlan->setDisabled(true);
@ -199,6 +213,7 @@ StreamConfigDialog::~StreamConfigDialog()
delete mpPacketModelTester; delete mpPacketModelTester;
delete mpPacketModel; delete mpPacketModel;
#if 0 // MPS - temp mask
// Remove payload data widget so that it is not deleted when this object // Remove payload data widget so that it is not deleted when this object
// is destroyed // is destroyed
{ {
@ -209,6 +224,7 @@ StreamConfigDialog::~StreamConfigDialog()
mpStream->protocol(52)->configWidget()->setParent(0); mpStream->protocol(52)->configWidget()->setParent(0);
} }
} }
#endif
// Remove any existing widget on the L2-L4 Tabs lest they are deleted // Remove any existing widget on the L2-L4 Tabs lest they are deleted
// when this object is destoryed // when this object is destoryed
@ -232,53 +248,95 @@ StreamConfigDialog::~StreamConfigDialog()
delete bgL3Proto; delete bgL3Proto;
delete bgL4Proto; delete bgL4Proto;
delete _iter;
delete mpStream; delete mpStream;
} }
void StreamConfigDialog::updateSelectedProtocols() 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 // Mac
mSelectedProtocols.append(51); CHKINS(Mac)
if (cbCVlan->isEnabled() && cbCVlan->isChecked()) if (cbCVlan->isEnabled() && cbCVlan->isChecked())
mSelectedProtocols.append(126); CHKINS(Vlan);
if (rbFtEthernet2->isChecked()) if (rbFtEthernet2->isChecked())
mSelectedProtocols.append(121); CHKINS(Eth2)
else if (rbFt802Dot3Raw->isChecked()) else if (rbFt802Dot3Raw->isChecked())
mSelectedProtocols.append(122); CHKINS(Dot3)
else if (rbFt802Dot3Llc->isChecked()) else if (rbFt802Dot3Llc->isChecked())
{ {
mSelectedProtocols.append(122); CHKINS(Dot3);
mSelectedProtocols.append(123); CHKINS(Llc);
} }
else if (rbFtLlcSnap->isChecked()) else if (rbFtLlcSnap->isChecked())
{ {
mSelectedProtocols.append(122); CHKINS(Dot3);
mSelectedProtocols.append(123); CHKINS(Llc);
mSelectedProtocols.append(124); CHKINS(Snap);
} }
if (rbL3Ipv4->isChecked()) if (rbL3Ipv4->isChecked())
mSelectedProtocols.append(130); CHKINS(Ip4)
else if (rbL3Arp->isChecked()) else if (rbL3Arp->isChecked())
mSelectedProtocols.append(131); CHKINS(Arp)
if (rbL4Tcp->isChecked()) if (rbL4Tcp->isChecked())
mSelectedProtocols.append(140); CHKINS(Tcp)
else if (rbL4Udp->isChecked()) else if (rbL4Udp->isChecked())
mSelectedProtocols.append(141); CHKINS(Udp)
else if (rbL4Icmp->isChecked()) else if (rbL4Icmp->isChecked())
mSelectedProtocols.append(142); CHKINS(Icmp)
else if (rbL4Igmp->isChecked()) else if (rbL4Igmp->isChecked())
mSelectedProtocols.append(143); CHKINS(Igmp)
// Payload // 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() void StreamConfigDialog::updateContents()
@ -345,22 +403,17 @@ void StreamConfigDialog::on_pbNext_clicked()
void StreamConfigDialog::on_twTopLevel_currentChanged(int index) void StreamConfigDialog::on_twTopLevel_currentChanged(int index)
{ {
QList<AbstractProtocol*> protoList;
// We only process the "Packet View" tab // We only process the "Packet View" tab
if (index != 2) if (index != 2)
return; return;
updateContents(); updateContents();
foreach(int i, mSelectedProtocols) mpPacketModel->setSelectedProtocols(*_iter);
if (mpStream->protocol(i))
protoList.append(mpStream->protocol(i));
mpPacketModel->setSelectedProtocols(protoList);
} }
void StreamConfigDialog::on_twProto_currentChanged(int index) void StreamConfigDialog::on_twProto_currentChanged(int index)
{ {
#if 0 // MPS - temp mask
QLayout *layout; QLayout *layout;
QList<QWidget*> wl; QList<QWidget*> wl;
@ -461,6 +514,39 @@ void StreamConfigDialog::on_twProto_currentChanged(int index)
} }
break; 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() void StreamConfigDialog::update_NumPacketsAndNumBursts()
@ -504,6 +590,7 @@ void StreamConfigDialog::LoadCurrentStream()
lePktLenMax->setText(str.setNum(mpStream->frameLenMax())); lePktLenMax->setText(str.setNum(mpStream->frameLenMax()));
} }
#if 0 // MPS - temp mask
// Protocols // Protocols
{ {
int i; int i;
@ -620,9 +707,130 @@ void StreamConfigDialog::LoadCurrentStream()
_proto_parse_done: _proto_parse_done:
Q_ASSERT(i == mSelectedProtocols.size()); Q_ASSERT(i == mSelectedProtocols.size());
mpStream->loadProtocolWidgets(); 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 // Stream Control
{ {
@ -673,6 +881,7 @@ _proto_parse_done:
// TODO(MED): Change this when we support goto to specific stream // TODO(MED): Change this when we support goto to specific stream
leStreamId->setText(QString("0")); leStreamId->setText(QString("0"));
} }
qDebug("loading stream done");
} }
void StreamConfigDialog::StoreCurrentStream() void StreamConfigDialog::StoreCurrentStream()
@ -692,7 +901,7 @@ void StreamConfigDialog::StoreCurrentStream()
// Protocols // Protocols
{ {
updateSelectedProtocols(); updateSelectedProtocols();
pStream->setFrameProtocol(mSelectedProtocols); //pStream->setFrameProtocol(mSelectedProtocols);
pStream->storeProtocolWidgets(); pStream->storeProtocolWidgets();
} }

View File

@ -27,21 +27,22 @@ public:
~StreamConfigDialog(); ~StreamConfigDialog();
private: private:
//QList<Stream> *mpStreamList;
QButtonGroup *bgFrameType; QButtonGroup *bgFrameType;
QButtonGroup *bgL3Proto; QButtonGroup *bgL3Proto;
QButtonGroup *bgL4Proto; QButtonGroup *bgL4Proto;
QStringListModel *mpAvailableProtocolsModel;
Port& mPort; Port& mPort;
uint mCurrentStreamIndex; uint mCurrentStreamIndex;
Stream *mpStream;
QList<int> mSelectedProtocols; Stream *mpStream;
ProtocolListIterator *_iter;
PacketModel *mpPacketModel; PacketModel *mpPacketModel;
ModelTest *mpPacketModelTester; ModelTest *mpPacketModelTester;
// The following static variables are used to track the "selected" tab // 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 // for the various tab widgets so that it can be restored when the dialog
// is opened the next time // is opened the next time

View File

@ -12,6 +12,12 @@
<height>589</height> <height>589</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle" > <property name="windowTitle" >
<string>Edit Stream</string> <string>Edit Stream</string>
</property> </property>
@ -56,7 +62,7 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="2" > <item row="0" column="1" >
<widget class="QGroupBox" name="gbFrameLength" > <widget class="QGroupBox" name="gbFrameLength" >
<property name="title" > <property name="title" >
<string>Frame Length (including FCS)</string> <string>Frame Length (including FCS)</string>
@ -157,10 +163,10 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="3" > <item row="1" column="0" colspan="2" >
<widget class="QTabWidget" name="twProto" > <widget class="QTabWidget" name="twProto" >
<property name="currentIndex" > <property name="currentIndex" >
<number>0</number> <number>4</number>
</property> </property>
<widget class="QWidget" name="tab_7" > <widget class="QWidget" name="tab_7" >
<attribute name="title" > <attribute name="title" >
@ -516,6 +522,20 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
</attribute> </attribute>
<layout class="QHBoxLayout" /> <layout class="QHBoxLayout" />
</widget> </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> </widget>
</item> </item>
</layout> </layout>

View File

@ -136,7 +136,7 @@ bool StreamModel::setData(const QModelIndex &index, const QVariant &value, int r
return true; return true;
case StreamStatus: case StreamStatus:
mCurrentPort->streamByIndex(index.row())->setIsEnabled(value.toBool()); mCurrentPort->streamByIndex(index.row())->setEnabled(value.toBool());
emit(dataChanged(index, index)); emit(dataChanged(index, index));
return true; return true;

View File

@ -1,5 +1,8 @@
#include <qendian.h> #include <qendian.h>
#include "abstractprotocol.h" #include "abstractprotocol.h"
#include "streambase.h"
#include "protocollistiterator.h"
/*! /*!
\class AbstractProtocol \class AbstractProtocol
@ -19,13 +22,9 @@
- metaFieldCount() - metaFieldCount()
- isMetaField() - isMetaField()
*/ */
AbstractProtocol::AbstractProtocol( AbstractProtocol::AbstractProtocol(StreamBase *stream)
ProtocolList &frameProtoList,
OstProto::StreamCore *parent)
: frameProtocols(frameProtoList)
{ {
qDebug("%s: &frameproto = %p/%p (sz:%d)", __FUNCTION__, &frameProtocols, &frameProtoList, frameProtocols.size()); mpStream = stream;
stream = parent;
metaCount = -1; metaCount = -1;
protoSize = -1; protoSize = -1;
} }
@ -34,13 +33,17 @@ AbstractProtocol::~AbstractProtocol()
{ {
} }
AbstractProtocol* AbstractProtocol::createInstance( AbstractProtocol* AbstractProtocol::createInstance(StreamBase *stream)
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{ {
return NULL; return NULL;
} }
quint32 AbstractProtocol::protocolNumber() const
{
qDebug("Something wrong!!!");
return 0xFFFFFFFF;
}
/*! /*!
\fn virtual void protoDataCopyInto(OstProto::OstProto::StreamCore &stream) = 0; \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 AbstractProtocol::payloadProtocolId(ProtocolIdType type) const
{ {
quint32 id = 0xFFFFFFFF; quint32 id = 0xFFFFFFFF;
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols); ProtocolListIterator *iter = mpStream->createProtocolListIterator();
if (iter.findNext(this)) if (iter->findNext(this))
{ {
if (iter.hasNext()) if (iter->hasNext())
id = iter.next()->protocolId(type); id = iter->next()->protocolId(type);
} }
delete iter;
qDebug("%s: payloadProtocolId = %u", __FUNCTION__, id); qDebug("%s: payloadProtocolId = %u", __FUNCTION__, id);
return id; return id;
@ -215,16 +219,17 @@ int AbstractProtocol::protocolFrameSize() const
int AbstractProtocol::protocolFrameOffset() const int AbstractProtocol::protocolFrameOffset() const
{ {
int size = 0; int size = 0;
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols); ProtocolListIterator *iter = mpStream->createProtocolListIterator();
if (iter.findNext(this)) if (iter->findNext(this))
{ {
iter.previous(); iter->previous();
while (iter.hasPrevious()) while (iter->hasPrevious())
size += iter.previous()->protocolFrameSize(); size += iter->previous()->protocolFrameSize();
} }
else else
return -1; return -1;
delete iter;
qDebug("%s: ofs = %d", __FUNCTION__, size); qDebug("%s: ofs = %d", __FUNCTION__, size);
return size; return size;
@ -234,15 +239,16 @@ int AbstractProtocol::protocolFramePayloadSize() const
{ {
int size = 0; int size = 0;
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols); ProtocolListIterator *iter = mpStream->createProtocolListIterator();
if (iter.findNext(this)) if (iter->findNext(this))
{ {
while (iter.hasNext()) while (iter->hasNext())
size += iter.next()->protocolFrameSize(); size += iter->next()->protocolFrameSize();
} }
else else
return -1; return -1;
delete iter;
qDebug("%s: payloadSize = %d", __FUNCTION__, size); qDebug("%s: payloadSize = %d", __FUNCTION__, size);
return size; return size;
@ -421,17 +427,18 @@ quint32 AbstractProtocol::protocolFrameHeaderCksum(int streamIndex,
CksumType cksumType) const CksumType cksumType) const
{ {
quint32 sum = 0xFFFF; quint32 sum = 0xFFFF;
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols); ProtocolListIterator *iter = mpStream->createProtocolListIterator();
Q_ASSERT(cksumType == CksumIpPseudo); Q_ASSERT(cksumType == CksumIpPseudo);
if (iter.findNext(this)) if (iter->findNext(this))
{ {
iter.previous(); iter->previous();
if (iter.hasPrevious()) if (iter->hasPrevious())
sum = iter.previous()->protocolFrameCksum(streamIndex, sum = iter->previous()->protocolFrameCksum(streamIndex,
CksumIpPseudo); CksumIpPseudo);
} }
delete iter;
while(sum>>16) while(sum>>16)
sum = (sum & 0xFFFF) + (sum >> 16); sum = (sum & 0xFFFF) + (sum >> 16);
@ -444,20 +451,21 @@ quint32 AbstractProtocol::protocolFramePayloadCksum(int streamIndex,
{ {
quint32 sum = 0; quint32 sum = 0;
quint16 cksum; quint16 cksum;
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols); ProtocolListIterator *iter = mpStream->createProtocolListIterator();
Q_ASSERT(cksumType == CksumIp); 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; sum += (quint16) ~cksum;
} }
} }
else else
return 0; return 0;
delete iter;
while(sum>>16) while(sum>>16)
sum = (sum & 0xFFFF) + (sum >> 16); sum = (sum & 0xFFFF) + (sum >> 16);

View File

@ -9,7 +9,7 @@
#include <QFlags> #include <QFlags>
//#include "../rpc/pbhelper.h" //#include "../rpc/pbhelper.h"
#include "../common/protocol.pb.h" #include "protocol.pb.h"
#define BASE_BIN (2) #define BASE_BIN (2)
#define BASE_OCT (8) #define BASE_OCT (8)
@ -19,10 +19,7 @@
#define uintToHexStr(num, bytes) \ #define uintToHexStr(num, bytes) \
QString("%1").arg(num, bytes*2, BASE_HEX, QChar('0')) QString("%1").arg(num, bytes*2, BASE_HEX, QChar('0'))
class OstProto::StreamCore; class StreamBase;
class AbstractProtocol;
typedef QLinkedList<const AbstractProtocol*> ProtocolList;
class AbstractProtocol class AbstractProtocol
{ {
@ -32,8 +29,7 @@ private:
mutable QString protoAbbr; mutable QString protoAbbr;
protected: protected:
OstProto::StreamCore *stream; StreamBase *mpStream;
ProtocolList &frameProtocols;
public: public:
enum FieldFlag { enum FieldFlag {
@ -65,16 +61,14 @@ public:
CksumMax CksumMax
}; };
AbstractProtocol(ProtocolList &frameProtoList, AbstractProtocol(StreamBase *stream);
OstProto::StreamCore *parent = 0);
virtual ~AbstractProtocol(); virtual ~AbstractProtocol();
static AbstractProtocol* createInstance( static AbstractProtocol* createInstance(StreamBase *stream);
ProtocolList &frameProtoList, virtual quint32 protocolNumber() const;
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream) = 0; virtual void protoDataCopyInto(OstProto::Protocol &protocol) const = 0;
virtual void protoDataCopyFrom(const OstProto::Stream &stream) = 0; virtual void protoDataCopyFrom(const OstProto::Protocol &protocol) = 0;
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;
@ -109,7 +103,6 @@ public:
virtual void loadConfigWidget() = 0; virtual void loadConfigWidget() = 0;
virtual void storeConfigWidget() = 0; virtual void storeConfigWidget() = 0;
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractProtocol::FieldFlags); Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractProtocol::FieldFlags);
#endif #endif

View File

@ -1,49 +1,49 @@
#include <qendian.h> #include <qendian.h>
#include <QHostAddress> #include <QHostAddress>
#include "Dot3.h" #include "dot3.h"
#include "streambase.h"
#define SZ_FCS 4 #define SZ_FCS 4
Dot3ConfigForm *Dot3Protocol::configForm = NULL;
Dot3ConfigForm::Dot3ConfigForm(QWidget *parent) Dot3ConfigForm::Dot3ConfigForm(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
setupUi(this); setupUi(this);
} }
Dot3Protocol::Dot3Protocol( Dot3Protocol::Dot3Protocol(StreamBase *stream)
ProtocolList &frameProtoList, : AbstractProtocol(stream)
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) configForm = NULL;
configForm = new Dot3ConfigForm;
} }
Dot3Protocol::~Dot3Protocol() Dot3Protocol::~Dot3Protocol()
{ {
delete configForm;
} }
AbstractProtocol* Dot3Protocol::createInstance( AbstractProtocol* Dot3Protocol::createInstance(StreamBase *stream)
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{ {
return new Dot3Protocol(frameProtoList, streamCore); return new Dot3Protocol(stream);
} }
void Dot3Protocol::protoDataCopyInto(OstProto::Stream &stream) quint32 Dot3Protocol::protocolNumber() const
{ {
// FIXME: multiple headers return OstProto::Protocol::kDot3FieldNumber;
stream.MutableExtension(OstProto::dot3)->CopyFrom(data);
} }
void Dot3Protocol::protoDataCopyFrom(const OstProto::Stream &stream) void Dot3Protocol::protoDataCopyInto(OstProto::Protocol &protocol) const
{ {
// FIXME: multiple headers protocol.MutableExtension(OstProto::dot3)->CopyFrom(data);
if (stream.HasExtension(OstProto::dot3)) protocol.mutable_protocol_id()->set_id(protocolNumber());
data.MergeFrom(stream.GetExtension(OstProto::dot3)); }
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 QString Dot3Protocol::name() const
@ -75,14 +75,14 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
{ {
quint16 len; quint16 len;
len = stream->frame_len() - SZ_FCS; len = mpStream->frameLen() - SZ_FCS;
return len; return len;
} }
case FieldTextValue: case FieldTextValue:
{ {
quint16 len; quint16 len;
len = stream->frame_len() - SZ_FCS; len = mpStream->frameLen() - SZ_FCS;
return QString("%1").arg(len); return QString("%1").arg(len);
} }
case FieldFrameValue: case FieldFrameValue:
@ -90,7 +90,7 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
quint16 len; quint16 len;
QByteArray fv; QByteArray fv;
len = stream->frame_len() - SZ_FCS; len = mpStream->frameLen() - SZ_FCS;
fv.resize(2); fv.resize(2);
qToBigEndian(len, (uchar*) fv.data()); qToBigEndian(len, (uchar*) fv.data());
return fv; return fv;
@ -117,11 +117,15 @@ bool Dot3Protocol::setFieldData(int index, const QVariant &value,
QWidget* Dot3Protocol::configWidget() QWidget* Dot3Protocol::configWidget()
{ {
if (configForm == NULL)
configForm = new Dot3ConfigForm;
return configForm; return configForm;
} }
void Dot3Protocol::loadConfigWidget() void Dot3Protocol::loadConfigWidget()
{ {
configWidget();
configForm->leLength->setText( configForm->leLength->setText(
fieldData(dot3_length, FieldValue).toString()); fieldData(dot3_length, FieldValue).toString());
} }
@ -130,6 +134,8 @@ void Dot3Protocol::storeConfigWidget()
{ {
bool isOk; bool isOk;
configWidget();
data.set_length(configForm->leLength->text().toULong(&isOk)); data.set_length(configForm->leLength->text().toULong(&isOk));
} }

View File

@ -17,7 +17,7 @@ class Dot3Protocol : public AbstractProtocol
{ {
private: private:
OstProto::Dot3 data; OstProto::Dot3 data;
static Dot3ConfigForm *configForm; Dot3ConfigForm *configForm;
enum Dot3field enum Dot3field
{ {
dot3_length, dot3_length,
@ -26,16 +26,14 @@ private:
}; };
public: public:
Dot3Protocol(ProtocolList &frameProtoList, Dot3Protocol(StreamBase *stream);
OstProto::StreamCore *parent = 0);
virtual ~Dot3Protocol(); virtual ~Dot3Protocol();
static AbstractProtocol* createInstance( static AbstractProtocol* createInstance(StreamBase *stream);
ProtocolList &frameProtoList, virtual quint32 protocolNumber() const;
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;

View File

@ -7,6 +7,6 @@ message Dot3 {
optional uint32 length = 1; optional uint32 length = 1;
} }
extend Stream { extend Protocol {
optional Dot3 dot3 = 122; optional Dot3 dot3 = 122;
} }

View File

@ -3,45 +3,44 @@
#include "eth2.h" #include "eth2.h"
Eth2ConfigForm *Eth2Protocol::configForm = NULL;
Eth2ConfigForm::Eth2ConfigForm(QWidget *parent) Eth2ConfigForm::Eth2ConfigForm(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
setupUi(this); setupUi(this);
} }
Eth2Protocol::Eth2Protocol( Eth2Protocol::Eth2Protocol(StreamBase *stream)
ProtocolList &frameProtoList, : AbstractProtocol(stream)
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) configForm = NULL;
configForm = new Eth2ConfigForm;
} }
Eth2Protocol::~Eth2Protocol() Eth2Protocol::~Eth2Protocol()
{ {
delete configForm;
} }
AbstractProtocol* Eth2Protocol::createInstance( AbstractProtocol* Eth2Protocol::createInstance(StreamBase *stream)
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{ {
return new Eth2Protocol(frameProtoList, streamCore); return new Eth2Protocol(stream);
} }
void Eth2Protocol::protoDataCopyInto(OstProto::Stream &stream) quint32 Eth2Protocol::protocolNumber() const
{ {
// FIXME: multiple headers return OstProto::Protocol::kEth2FieldNumber;
stream.MutableExtension(OstProto::eth2)->CopyFrom(data);
} }
void Eth2Protocol::protoDataCopyFrom(const OstProto::Stream &stream) void Eth2Protocol::protoDataCopyInto(OstProto::Protocol &protocol) const
{ {
// FIXME: multiple headers protocol.MutableExtension(OstProto::eth2)->CopyFrom(data);
if (stream.HasExtension(OstProto::eth2)) protocol.mutable_protocol_id()->set_id(protocolNumber());
data.MergeFrom(stream.GetExtension(OstProto::eth2)); }
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 QString Eth2Protocol::name() const
@ -121,11 +120,15 @@ bool Eth2Protocol::setFieldData(int index, const QVariant &value,
QWidget* Eth2Protocol::configWidget() QWidget* Eth2Protocol::configWidget()
{ {
if (configForm == NULL)
configForm = new Eth2ConfigForm;
return configForm; return configForm;
} }
void Eth2Protocol::loadConfigWidget() void Eth2Protocol::loadConfigWidget()
{ {
configWidget();
configForm->leType->setText(uintToHexStr( configForm->leType->setText(uintToHexStr(
fieldData(eth2_type, FieldValue).toUInt(), 2)); fieldData(eth2_type, FieldValue).toUInt(), 2));
} }
@ -134,6 +137,8 @@ void Eth2Protocol::storeConfigWidget()
{ {
bool isOk; bool isOk;
configWidget();
data.set_type(configForm->leType->text().remove(QChar(' ')).toULong(&isOk, 16)); data.set_type(configForm->leType->text().remove(QChar(' ')).toULong(&isOk, 16));
} }

View File

@ -17,7 +17,7 @@ class Eth2Protocol : public AbstractProtocol
{ {
private: private:
OstProto::Eth2 data; OstProto::Eth2 data;
static Eth2ConfigForm *configForm; Eth2ConfigForm *configForm;
enum eth2field enum eth2field
{ {
eth2_type = 0, eth2_type = 0,
@ -26,16 +26,14 @@ private:
}; };
public: public:
Eth2Protocol(ProtocolList &frameProtoList, Eth2Protocol(StreamBase *stream);
OstProto::StreamCore *parent = 0);
virtual ~Eth2Protocol(); virtual ~Eth2Protocol();
static AbstractProtocol* createInstance( static AbstractProtocol* createInstance(StreamBase *stream);
ProtocolList &frameProtoList, virtual quint32 protocolNumber() const;
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;

View File

@ -7,6 +7,6 @@ message Eth2 {
optional uint32 type = 1; optional uint32 type = 1;
} }
extend Stream { extend Protocol {
optional Eth2 eth2 = 121; optional Eth2 eth2 = 121;
} }

View File

@ -5,44 +5,35 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>166</width> <width>267</width>
<height>72</height> <height>64</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle" >
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QHBoxLayout" > <layout class="QGridLayout" >
<item> <item row="0" column="0" >
<widget class="QGroupBox" name="groupBox" > <widget class="QLabel" name="lblType" >
<property name="title" > <property name="text" >
<string>Ethernet II</string> <string>Ethernet Type</string>
</property>
<property name="buddy" >
<cstring>leType</cstring>
</property> </property>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="lblType" >
<property name="text" >
<string>Ethernet Type</string>
</property>
<property name="buddy" >
<cstring>leType</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leType" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="inputMask" >
<string>>HH HH; </string>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item row="0" column="1" >
<widget class="QLineEdit" name="leType" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="inputMask" >
<string>>HH HH; </string>
</property>
</widget>
</item>
<item row="0" column="2" >
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -55,6 +46,19 @@
</property> </property>
</spacer> </spacer>
</item> </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> </layout>
</widget> </widget>
<resources/> <resources/>

View File

@ -3,8 +3,6 @@
#include "ip4.h" #include "ip4.h"
Ip4ConfigForm *Ip4Protocol::configForm = NULL;
Ip4ConfigForm::Ip4ConfigForm(QWidget *parent) Ip4ConfigForm::Ip4ConfigForm(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
@ -18,6 +16,11 @@ Ip4ConfigForm::Ip4ConfigForm(QWidget *parent)
this, SLOT(on_cmbIpDstAddrMode_currentIndexChanged(int))); this, SLOT(on_cmbIpDstAddrMode_currentIndexChanged(int)));
} }
Ip4ConfigForm::~Ip4ConfigForm()
{
qDebug("IPv4 Config Form destructor called");
}
void Ip4ConfigForm::on_cmbIpSrcAddrMode_currentIndexChanged(int index) void Ip4ConfigForm::on_cmbIpSrcAddrMode_currentIndexChanged(int index)
{ {
if (index == OstProto::Ip4::e_im_fixed) if (index == OstProto::Ip4::e_im_fixed)
@ -46,42 +49,38 @@ void Ip4ConfigForm::on_cmbIpDstAddrMode_currentIndexChanged(int index)
} }
} }
Ip4Protocol::Ip4Protocol( Ip4Protocol::Ip4Protocol(StreamBase *stream)
ProtocolList &frameProtoList, : AbstractProtocol(stream)
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
#if 0 configForm = NULL;
PbHelper pbh;
pbh.ForceSetSingularDefault(&data);
#endif
if (configForm == NULL)
configForm = new Ip4ConfigForm;
} }
Ip4Protocol::~Ip4Protocol() Ip4Protocol::~Ip4Protocol()
{ {
delete configForm;
} }
AbstractProtocol* Ip4Protocol::createInstance( AbstractProtocol* Ip4Protocol::createInstance(StreamBase *stream)
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{ {
return new Ip4Protocol(frameProtoList, streamCore); return new Ip4Protocol(stream);
} }
void Ip4Protocol::protoDataCopyInto(OstProto::Stream &stream) quint32 Ip4Protocol::protocolNumber() const
{ {
// FIXME: multiple headers return OstProto::Protocol::kIp4FieldNumber;
stream.MutableExtension(OstProto::ip4)->CopyFrom(data);
} }
void Ip4Protocol::protoDataCopyFrom(const OstProto::Stream &stream) void Ip4Protocol::protoDataCopyInto(OstProto::Protocol &protocol) const
{ {
// FIXME: multiple headers protocol.MutableExtension(OstProto::ip4)->CopyFrom(data);
if (stream.HasExtension(OstProto::ip4)) protocol.mutable_protocol_id()->set_id(protocolNumber());
data.MergeFrom(stream.GetExtension(OstProto::ip4)); }
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 QString Ip4Protocol::name() const
@ -604,11 +603,15 @@ quint32 Ip4Protocol::protocolFrameCksum(int streamIndex,
QWidget* Ip4Protocol::configWidget() QWidget* Ip4Protocol::configWidget()
{ {
if (configForm == NULL)
configForm = new Ip4ConfigForm;
return configForm; return configForm;
} }
void Ip4Protocol::loadConfigWidget() void Ip4Protocol::loadConfigWidget()
{ {
configWidget();
configForm->cbIpVersionOverride->setChecked(data.is_override_ver()); configForm->cbIpVersionOverride->setChecked(data.is_override_ver());
configForm->leIpVersion->setText(fieldData(ip4_ver, FieldValue).toString()); configForm->leIpVersion->setText(fieldData(ip4_ver, FieldValue).toString());
@ -649,6 +652,8 @@ void Ip4Protocol::storeConfigWidget()
uint ff = 0; uint ff = 0;
bool isOk; bool isOk;
configWidget();
data.set_is_override_ver(configForm->cbIpVersionOverride->isChecked()); data.set_is_override_ver(configForm->cbIpVersionOverride->isChecked());
data.set_ver_hdrlen(((configForm->leIpVersion->text().toULong(&isOk) & 0x0F) << 4) | data.set_ver_hdrlen(((configForm->leIpVersion->text().toULong(&isOk) & 0x0F) << 4) |
(configForm->leIpHdrLen->text().toULong(&isOk) & 0x0F)); (configForm->leIpHdrLen->text().toULong(&isOk) & 0x0F));

View File

@ -16,6 +16,7 @@ class Ip4ConfigForm : public QWidget, public Ui::ip4
Q_OBJECT Q_OBJECT
public: public:
Ip4ConfigForm(QWidget *parent = 0); Ip4ConfigForm(QWidget *parent = 0);
~Ip4ConfigForm();
private slots: private slots:
void on_cmbIpSrcAddrMode_currentIndexChanged(int index); void on_cmbIpSrcAddrMode_currentIndexChanged(int index);
void on_cmbIpDstAddrMode_currentIndexChanged(int index); void on_cmbIpDstAddrMode_currentIndexChanged(int index);
@ -25,7 +26,7 @@ class Ip4Protocol : public AbstractProtocol
{ {
private: private:
OstProto::Ip4 data; OstProto::Ip4 data;
static Ip4ConfigForm *configForm; Ip4ConfigForm *configForm;
enum ip4field enum ip4field
{ {
ip4_ver = 0, ip4_ver = 0,
@ -58,16 +59,14 @@ private:
}; };
public: public:
Ip4Protocol(ProtocolList &frameProtoList, Ip4Protocol(StreamBase *stream);
OstProto::StreamCore *parent = 0);
virtual ~Ip4Protocol(); virtual ~Ip4Protocol();
static AbstractProtocol* createInstance( static AbstractProtocol* createInstance(StreamBase *stream);
ProtocolList &frameProtoList, virtual quint32 protocolNumber() const;
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;

View File

@ -42,6 +42,6 @@ message Ip4 {
// TODO: Options // TODO: Options
} }
extend Stream { extend Protocol {
optional Ip4 ip4 = 130; optional Ip4 ip4 = 130;
} }

View File

@ -3,45 +3,44 @@
#include "llc.h" #include "llc.h"
LlcConfigForm *LlcProtocol::configForm = NULL;
LlcConfigForm::LlcConfigForm(QWidget *parent) LlcConfigForm::LlcConfigForm(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
setupUi(this); setupUi(this);
} }
LlcProtocol::LlcProtocol( LlcProtocol::LlcProtocol(StreamBase *stream)
ProtocolList &frameProtoList, : AbstractProtocol(stream)
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) configForm = NULL;
configForm = new LlcConfigForm;
} }
LlcProtocol::~LlcProtocol() LlcProtocol::~LlcProtocol()
{ {
delete configForm;
} }
AbstractProtocol* LlcProtocol::createInstance( AbstractProtocol* LlcProtocol::createInstance(StreamBase *stream)
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{ {
return new LlcProtocol(frameProtoList, streamCore); return new LlcProtocol(stream);
} }
void LlcProtocol::protoDataCopyInto(OstProto::Stream &stream) quint32 LlcProtocol::protocolNumber() const
{ {
// FIXME: multiple headers return OstProto::Protocol::kLlcFieldNumber;
stream.MutableExtension(OstProto::llc)->CopyFrom(data);
} }
void LlcProtocol::protoDataCopyFrom(const OstProto::Stream &stream) void LlcProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
{ {
// FIXME: multiple headers protocol.MutableExtension(OstProto::llc)->CopyFrom(data);
if (stream.HasExtension(OstProto::llc)) protocol.mutable_protocol_id()->set_id(protocolNumber());
data.MergeFrom(stream.GetExtension(OstProto::llc)); }
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 QString LlcProtocol::name() const
@ -135,6 +134,8 @@ bool LlcProtocol::setFieldData(int index, const QVariant &value,
QWidget* LlcProtocol::configWidget() QWidget* LlcProtocol::configWidget()
{ {
if (configForm == NULL)
configForm = new LlcConfigForm;
return configForm; return configForm;
} }
@ -143,6 +144,8 @@ void LlcProtocol::loadConfigWidget()
#define uintToHexStr(num, bytes) \ #define uintToHexStr(num, bytes) \
QString("%1").arg(num, bytes*2, BASE_HEX, QChar('0')) QString("%1").arg(num, bytes*2, BASE_HEX, QChar('0'))
configWidget();
configForm->leDsap->setText(uintToHexStr( configForm->leDsap->setText(uintToHexStr(
fieldData(llc_dsap, FieldValue).toUInt(), 1)); fieldData(llc_dsap, FieldValue).toUInt(), 1));
configForm->leSsap->setText(uintToHexStr( configForm->leSsap->setText(uintToHexStr(
@ -156,6 +159,8 @@ void LlcProtocol::storeConfigWidget()
{ {
bool isOk; bool isOk;
configWidget();
data.set_dsap(configForm->leDsap->text().toULong(&isOk, BASE_HEX)); data.set_dsap(configForm->leDsap->text().toULong(&isOk, BASE_HEX));
data.set_ssap(configForm->leSsap->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)); data.set_ctl(configForm->leControl->text().toULong(&isOk, BASE_HEX));

View File

@ -20,7 +20,7 @@ class LlcProtocol : public AbstractProtocol
{ {
private: private:
OstProto::Llc data; OstProto::Llc data;
static LlcConfigForm *configForm; LlcConfigForm *configForm;
enum llcfield enum llcfield
{ {
llc_dsap = 0, llc_dsap = 0,
@ -31,16 +31,14 @@ private:
}; };
public: public:
LlcProtocol(ProtocolList &frameProtoList, LlcProtocol(StreamBase *stream);
OstProto::StreamCore *parent = 0);
virtual ~LlcProtocol(); virtual ~LlcProtocol();
static AbstractProtocol* createInstance( static AbstractProtocol* createInstance(StreamBase *stream);
ProtocolList &frameProtoList, virtual quint32 protocolNumber() const;
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;

View File

@ -8,6 +8,6 @@ message Llc {
optional uint32 ctl = 3; optional uint32 ctl = 3;
} }
extend Stream { extend Protocol {
optional Llc llc = 123; optional Llc llc = 123;
} }

View File

@ -3,8 +3,6 @@
#include "mac.h" #include "mac.h"
MacConfigForm *MacProtocol::configForm = NULL;
MacConfigForm::MacConfigForm(QWidget *parent) MacConfigForm::MacConfigForm(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
@ -17,6 +15,11 @@ MacConfigForm::MacConfigForm(QWidget *parent)
leSrcMacCount->setValidator(new QIntValidator(1, MAX_MAC_ITER_COUNT, this)); leSrcMacCount->setValidator(new QIntValidator(1, MAX_MAC_ITER_COUNT, this));
} }
MacConfigForm::~MacConfigForm()
{
qDebug("In MacConfigForm destructor");
}
void MacConfigForm::on_cmbDstMacMode_currentIndexChanged(int index) void MacConfigForm::on_cmbDstMacMode_currentIndexChanged(int index)
{ {
if (index == OstProto::Mac::e_mm_fixed) if (index == OstProto::Mac::e_mm_fixed)
@ -46,37 +49,38 @@ void MacConfigForm::on_cmbSrcMacMode_currentIndexChanged(int index)
} }
MacProtocol::MacProtocol( MacProtocol::MacProtocol(StreamBase *stream)
ProtocolList &frameProtoList, : AbstractProtocol(stream)
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) configForm = NULL;
configForm = new MacConfigForm;
} }
MacProtocol::~MacProtocol() MacProtocol::~MacProtocol()
{ {
delete configForm;
} }
AbstractProtocol* MacProtocol::createInstance( AbstractProtocol* MacProtocol::createInstance(StreamBase *stream)
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{ {
return new MacProtocol(frameProtoList, streamCore); return new MacProtocol(stream);
} }
void MacProtocol::protoDataCopyInto(OstProto::Stream &stream) quint32 MacProtocol::protocolNumber() const
{ {
// FIXME: multiple headers return OstProto::Protocol::kMacFieldNumber;
stream.MutableExtension(OstProto::mac)->CopyFrom(data);
} }
void MacProtocol::protoDataCopyFrom(const OstProto::Stream &stream) void MacProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
{ {
// FIXME: multiple headers protocol.MutableExtension(OstProto::mac)->CopyFrom(data);
if (stream.HasExtension(OstProto::mac)) protocol.mutable_protocol_id()->set_id(protocolNumber());
data.MergeFrom(stream.GetExtension(OstProto::mac)); }
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 QString MacProtocol::name() const
@ -238,11 +242,15 @@ bool MacProtocol::setFieldData(int index, const QVariant &value,
QWidget* MacProtocol::configWidget() QWidget* MacProtocol::configWidget()
{ {
if (configForm == NULL)
configForm = new MacConfigForm;
return configForm; return configForm;
} }
void MacProtocol::loadConfigWidget() void MacProtocol::loadConfigWidget()
{ {
configWidget();
configForm->leDstMac->setText(uintToHexStr(data.dst_mac(), 6)); configForm->leDstMac->setText(uintToHexStr(data.dst_mac(), 6));
configForm->cmbDstMacMode->setCurrentIndex(data.dst_mac_mode()); configForm->cmbDstMacMode->setCurrentIndex(data.dst_mac_mode());
configForm->leDstMacCount->setText(QString().setNum(data.dst_mac_count())); configForm->leDstMacCount->setText(QString().setNum(data.dst_mac_count()));
@ -258,6 +266,8 @@ void MacProtocol::storeConfigWidget()
{ {
bool isOk; bool isOk;
configWidget();
data.set_dst_mac(configForm->leDstMac->text().remove(QChar(' ')). data.set_dst_mac(configForm->leDstMac->text().remove(QChar(' ')).
toULongLong(&isOk, 16)); toULongLong(&isOk, 16));
data.set_dst_mac_mode((OstProto::Mac::MacAddrMode) configForm-> data.set_dst_mac_mode((OstProto::Mac::MacAddrMode) configForm->

View File

@ -13,6 +13,7 @@ class MacConfigForm : public QWidget, public Ui::mac
Q_OBJECT Q_OBJECT
public: public:
MacConfigForm(QWidget *parent = 0); MacConfigForm(QWidget *parent = 0);
virtual ~MacConfigForm();
private slots: private slots:
void on_cmbDstMacMode_currentIndexChanged(int index); void on_cmbDstMacMode_currentIndexChanged(int index);
void on_cmbSrcMacMode_currentIndexChanged(int index); void on_cmbSrcMacMode_currentIndexChanged(int index);
@ -22,7 +23,7 @@ class MacProtocol : public AbstractProtocol
{ {
private: private:
OstProto::Mac data; OstProto::Mac data;
static MacConfigForm *configForm; MacConfigForm *configForm;
enum macfield enum macfield
{ {
mac_dstAddr = 0, mac_dstAddr = 0,
@ -39,16 +40,14 @@ private:
}; };
public: public:
MacProtocol(ProtocolList &frameProtoList, MacProtocol(StreamBase *stream);
OstProto::StreamCore *parent = 0);
virtual ~MacProtocol(); virtual ~MacProtocol();
static AbstractProtocol* createInstance( static AbstractProtocol* createInstance(StreamBase *stream);
ProtocolList &frameProtoList, virtual quint32 protocolNumber() const;
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;

View File

@ -24,6 +24,6 @@ message Mac {
optional uint32 src_mac_step = 8 [default = 1]; optional uint32 src_mac_step = 8 [default = 1];
} }
extend Stream { extend Protocol {
optional Mac mac = 51; optional Mac mac = 51;
} }

View File

@ -6,13 +6,13 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>512</width> <width>512</width>
<height>98</height> <height>104</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle" >
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QHBoxLayout" > <layout class="QVBoxLayout" >
<item> <item>
<widget class="QGroupBox" name="groupBox" > <widget class="QGroupBox" name="groupBox" >
<property name="title" > <property name="title" >
@ -81,10 +81,10 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text" > <property name="text" >
<string>1</string> <string/>
</property> </property>
<property name="cursorPosition" > <property name="cursorPosition" >
<number>1</number> <number>0</number>
</property> </property>
</widget> </widget>
</item> </item>
@ -101,10 +101,10 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text" > <property name="text" >
<string>1</string> <string/>
</property> </property>
<property name="cursorPosition" > <property name="cursorPosition" >
<number>1</number> <number>0</number>
</property> </property>
</widget> </widget>
</item> </item>
@ -164,7 +164,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text" > <property name="text" >
<string>1</string> <string/>
</property> </property>
</widget> </widget>
</item> </item>
@ -181,16 +181,29 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text" > <property name="text" >
<string>1</string> <string/>
</property> </property>
<property name="cursorPosition" > <property name="cursorPosition" >
<number>1</number> <number>0</number>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
<resources/> <resources/>

View File

@ -29,7 +29,8 @@ PROTOS += \
HEADERS += \ HEADERS += \
abstractprotocol.h \ abstractprotocol.h \
protocolmanager.h \ protocolmanager.h \
protocolcollection.h \ protocollist.h \
protocollistiterator.h \
streambase.h \ streambase.h \
mac.h \ mac.h \
payload.h \ payload.h \
@ -44,7 +45,8 @@ HEADERS += \
SOURCES += \ SOURCES += \
abstractprotocol.cpp \ abstractprotocol.cpp \
protocolmanager.cpp \ protocolmanager.cpp \
protocolcollection.cpp \ protocollist.cpp \
protocollistiterator.cpp \
streambase.cpp \ streambase.cpp \
mac.cpp \ mac.cpp \
payload.cpp \ payload.cpp \

View File

@ -3,11 +3,10 @@
//#include "../client/stream.h" //#include "../client/stream.h"
#include "payload.h" #include "payload.h"
#include "streambase.h"
#define SZ_FCS 4 #define SZ_FCS 4
PayloadConfigForm *PayloadProtocol::configForm = NULL;
PayloadConfigForm::PayloadConfigForm(QWidget *parent) PayloadConfigForm::PayloadConfigForm(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
@ -31,37 +30,38 @@ void PayloadConfigForm::on_cmbPatternMode_currentIndexChanged(int index)
} }
} }
PayloadProtocol::PayloadProtocol( PayloadProtocol::PayloadProtocol(StreamBase *stream)
ProtocolList &frameProtoList, : AbstractProtocol(stream)
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) configForm = NULL;
configForm = new PayloadConfigForm;
} }
PayloadProtocol::~PayloadProtocol() PayloadProtocol::~PayloadProtocol()
{ {
delete configForm;
} }
AbstractProtocol* PayloadProtocol::createInstance( AbstractProtocol* PayloadProtocol::createInstance(StreamBase *stream)
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{ {
return new PayloadProtocol(frameProtoList, streamCore); return new PayloadProtocol(stream);
} }
void PayloadProtocol::protoDataCopyInto(OstProto::Stream &stream) quint32 PayloadProtocol::protocolNumber() const
{ {
// FIXME: multiple headers return OstProto::Protocol::kPayloadFieldNumber;
stream.MutableExtension(OstProto::payload)->CopyFrom(data);
} }
void PayloadProtocol::protoDataCopyFrom(const OstProto::Stream &stream) void PayloadProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
{ {
// FIXME: multiple headers protocol.MutableExtension(OstProto::payload)->CopyFrom(data);
if (stream.HasExtension(OstProto::payload)) protocol.mutable_protocol_id()->set_id(protocolNumber());
data.MergeFrom(stream.GetExtension(OstProto::payload)); }
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 QString PayloadProtocol::name() const
@ -76,7 +76,7 @@ QString PayloadProtocol::shortName() const
int PayloadProtocol::protocolFrameSize() const int PayloadProtocol::protocolFrameSize() const
{ {
return (stream->frame_len() - protocolFrameOffset() - SZ_FCS); return (mpStream->frameLen() - protocolFrameOffset() - SZ_FCS);
} }
int PayloadProtocol::fieldCount() const int PayloadProtocol::fieldCount() const
@ -124,7 +124,7 @@ QVariant PayloadProtocol::fieldData(int index, FieldAttrib attrib,
QByteArray fv; QByteArray fv;
int dataLen; int dataLen;
dataLen = stream->frame_len() - protocolFrameOffset(); dataLen = mpStream->frameLen() - protocolFrameOffset();
dataLen -= SZ_FCS; dataLen -= SZ_FCS;
fv.resize(dataLen+4); fv.resize(dataLen+4);
switch(data.pattern_mode()) switch(data.pattern_mode())
@ -179,12 +179,15 @@ bool PayloadProtocol::setFieldData(int index, const QVariant &value,
QWidget* PayloadProtocol::configWidget() QWidget* PayloadProtocol::configWidget()
{ {
if (configForm == NULL)
configForm = new PayloadConfigForm;
return configForm; return configForm;
//return new PayloadConfigForm;
} }
void PayloadProtocol::loadConfigWidget() void PayloadProtocol::loadConfigWidget()
{ {
configWidget();
configForm->cmbPatternMode->setCurrentIndex(data.pattern_mode()); configForm->cmbPatternMode->setCurrentIndex(data.pattern_mode());
configForm->lePattern->setText(uintToHexStr(data.pattern(), 4)); configForm->lePattern->setText(uintToHexStr(data.pattern(), 4));
} }
@ -193,6 +196,8 @@ void PayloadProtocol::storeConfigWidget()
{ {
bool isOk; bool isOk;
configWidget();
data.set_pattern_mode((OstProto::Payload::DataPatternMode) data.set_pattern_mode((OstProto::Payload::DataPatternMode)
configForm->cmbPatternMode->currentIndex()); configForm->cmbPatternMode->currentIndex());
data.set_pattern(configForm->lePattern->text().remove(QChar(' ')).toULong(&isOk, 16)); data.set_pattern(configForm->lePattern->text().remove(QChar(' ')).toULong(&isOk, 16));

View File

@ -19,7 +19,7 @@ class PayloadProtocol : public AbstractProtocol
{ {
private: private:
OstProto::Payload data; OstProto::Payload data;
static PayloadConfigForm *configForm; PayloadConfigForm *configForm;
enum payloadfield enum payloadfield
{ {
payload_dataPattern, payload_dataPattern,
@ -31,16 +31,14 @@ private:
}; };
public: public:
PayloadProtocol(ProtocolList &frameProtoList, PayloadProtocol(StreamBase *stream);
OstProto::StreamCore *parent = 0);
virtual ~PayloadProtocol(); virtual ~PayloadProtocol();
static AbstractProtocol* createInstance( static AbstractProtocol* createInstance(StreamBase *stream);
ProtocolList &frameProtoList, virtual quint32 protocolNumber() const;
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;

View File

@ -17,6 +17,6 @@ message Payload {
//optional uint32 data_start_ofs = 13; //optional uint32 data_start_ofs = 13;
} }
extend Stream { extend Protocol {
optional Payload payload = 52; optional Payload payload = 52;
} }

View File

@ -28,7 +28,7 @@ message StreamCore {
optional uint32 frame_len_max = 17 [default = 1518]; optional uint32 frame_len_max = 17 [default = 1518];
// Currently Selected Protocols // Currently Selected Protocols
repeated uint32 frame_proto = 20; //repeated uint32 frame_proto = 20;
} }
message StreamControl { 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 { message Stream {
required StreamId stream_id = 1; required StreamId stream_id = 1;
optional StreamCore core = 2; optional StreamCore core = 2;
optional StreamControl control = 3; optional StreamControl control = 3;
extensions 51 to 100; // Reserved for Ostinato Use repeated Protocol protocol = 4;
extensions 101 to 200; // Available for use by protocols
} }
message Void { message Void {

View File

@ -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));
}

View File

@ -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
View File

@ -0,0 +1,8 @@
#include "protocollist.h"
#include "abstractprotocol.h"
void ProtocolList::destroy()
{
while (!isEmpty())
delete takeFirst();
}

9
common/protocollist.h Normal file
View File

@ -0,0 +1,9 @@
#include <QLinkedList>
class AbstractProtocol;
class ProtocolList : public QLinkedList<AbstractProtocol*>
{
public:
void destroy();
};

View 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();
}

View 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();
};

View File

@ -1,5 +1,9 @@
#include "protocolmanager.h" #include "protocolmanager.h"
// FIXME(HI): remove
#include "protocol.pb.h"
#include "abstractprotocol.h"
#include "mac.h" #include "mac.h"
#include "payload.h" #include "payload.h"
@ -12,9 +16,6 @@
#include "tcp.h" #include "tcp.h"
#include "udp.h" #include "udp.h"
QMap<int, void*> ProtocolManager::factory;
QMap<QString, int> ProtocolManager::nameToNumberMap;
ProtocolManager OstProtocolManager; ProtocolManager OstProtocolManager;
ProtocolManager::ProtocolManager() ProtocolManager::ProtocolManager()
@ -36,5 +37,33 @@ void ProtocolManager::registerProtocol(int protoNumber, QString protoName,
{ {
// TODO: validate incoming params for duplicates with existing // TODO: validate incoming params for duplicates with existing
nameToNumberMap.insert(protoName, protoNumber); nameToNumberMap.insert(protoName, protoNumber);
numberToNameMap.insert(protoNumber, protoName);
factory.insert(protoNumber, protoInstanceCreator); 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();
}

View File

@ -2,18 +2,27 @@
#define _PROTOCOL_MANAGER_H #define _PROTOCOL_MANAGER_H
#include <QMap> #include <QMap>
#include <QStringList>
class AbstractProtocol;
class StreamBase;
class ProtocolManager class ProtocolManager
{ {
public: QMap<int, QString> numberToNameMap;
//! \todo Make these data structures private/protected QMap<QString, int> nameToNumberMap;
static QMap<QString, int> nameToNumberMap; QMap<int, void*> factory;
static QMap<int, void*> factory;
public: public:
ProtocolManager(); ProtocolManager();
void registerProtocol(int protoNumber, QString protoName, void registerProtocol(int protoNumber, QString protoName,
void *protoCreator); void *protoCreator);
AbstractProtocol* createProtocol(int protoNumber, StreamBase *stream);
AbstractProtocol* createProtocol(QString protoName, StreamBase *stream);
QStringList protocolDatabase();
}; };
#endif #endif

View File

@ -3,46 +3,44 @@
#include "sample.h" #include "sample.h"
SampleConfigForm *SampleProtocol::configForm = NULL;
SampleConfigForm::SampleConfigForm(QWidget *parent) SampleConfigForm::SampleConfigForm(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
setupUi(this); setupUi(this);
} }
SampleProtocol::SampleProtocol( SampleProtocol::SampleProtocol(StreamBase *stream);
ProtocolList &frameProtoList, : AbstractProtocol(stream)
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) configForm = NULL;
configForm = new SampleConfigForm;
} }
SampleProtocol::~SampleProtocol() SampleProtocol::~SampleProtocol()
{ {
delete configForm;
} }
AbstractProtocol* SampleProtocol::createInstance( AbstractProtocol* SampleProtocol::createInstance(StreamBase *stream)
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{ {
return new SampleProtocol(frameProtoList, streamCore); return new SampleProtocol(frameProtoList, streamCore);
} }
void SampleProtocol::protoDataCopyInto(OstProto::Stream &stream) quint32 SampleProtocol::protocolNumber() const
{ {
// FIXME: multiple headers return OstProto::Protocol::kSampleFieldNumber;
stream.MutableExtension(OstProto::sample)->CopyFrom(data);
} }
void SampleProtocol::protoDataCopyFrom(const OstProto::Stream &stream) void SampleProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
{ {
// FIXME: multiple headers protocol.MutableExtension(OstProto::sample)->CopyFrom(data);
if (stream.HasExtension(OstProto::sample)) protocol.mutable_protocol_id()->set_id(protocolNumber())
data.MergeFrom(stream.GetExtension(OstProto::sample)); }
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 QString SampleProtocol::name() const
@ -156,15 +154,21 @@ bool SampleProtocol::setFieldData(int index, const QVariant &value,
QWidget* SampleProtocol::configWidget() QWidget* SampleProtocol::configWidget()
{ {
if (configForm == NULL)
configFrom = new SampleConfigForm;
return configForm; return configForm;
} }
void SampleProtocol::loadConfigWidget() void SampleProtocol::loadConfigWidget()
{ {
configWidget();
} }
void SampleProtocol::storeConfigWidget() void SampleProtocol::storeConfigWidget()
{ {
bool isOk; bool isOk;
configWidget();
} }

View File

@ -18,7 +18,7 @@ class SampleProtocol : public AbstractProtocol
{ {
private: private:
OstProto::Sample data; OstProto::Sample data;
static SampleConfigForm *configForm; SampleConfigForm *configForm;
enum samplefield enum samplefield
{ {
@ -26,16 +26,14 @@ private:
}; };
public: public:
SampleProtocol(ProtocolList &frameProtoList, SampleProtocol(StreamBase *stream);
OstProto::StreamCore *parent = 0);
virtual ~SampleProtocol(); virtual ~SampleProtocol();
static AbstractProtocol* createInstance( static AbstractProtocol* createInstance(StreamBase *stream);
ProtocolList &frameProtoList, virtual quint32 protocolNumber() const;
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;

View File

@ -3,45 +3,44 @@
#include "snap.h" #include "snap.h"
SnapConfigForm *SnapProtocol::configForm = NULL;
SnapConfigForm::SnapConfigForm(QWidget *parent) SnapConfigForm::SnapConfigForm(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
setupUi(this); setupUi(this);
} }
SnapProtocol::SnapProtocol( SnapProtocol::SnapProtocol(StreamBase *stream)
ProtocolList &frameProtoList, : AbstractProtocol(stream)
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) configForm = NULL;
configForm = new SnapConfigForm;
} }
SnapProtocol::~SnapProtocol() SnapProtocol::~SnapProtocol()
{ {
delete configForm;
} }
AbstractProtocol* SnapProtocol::createInstance( AbstractProtocol* SnapProtocol::createInstance(StreamBase *stream)
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{ {
return new SnapProtocol(frameProtoList, streamCore); return new SnapProtocol(stream);
} }
void SnapProtocol::protoDataCopyInto(OstProto::Stream &stream) quint32 SnapProtocol::protocolNumber() const
{ {
// FIXME: multiple headers return OstProto::Protocol::kSnapFieldNumber;
stream.MutableExtension(OstProto::snap)->CopyFrom(data);
} }
void SnapProtocol::protoDataCopyFrom(const OstProto::Stream &stream) void SnapProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
{ {
// FIXME: multiple headers protocol.MutableExtension(OstProto::snap)->CopyFrom(data);
if (stream.HasExtension(OstProto::snap)) protocol.mutable_protocol_id()->set_id(protocolNumber());
data.MergeFrom(stream.GetExtension(OstProto::snap)); }
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 QString SnapProtocol::name() const
@ -140,11 +139,15 @@ bool SnapProtocol::setFieldData(int index, const QVariant &value,
QWidget* SnapProtocol::configWidget() QWidget* SnapProtocol::configWidget()
{ {
if (configForm == NULL)
configForm = new SnapConfigForm;
return configForm; return configForm;
} }
void SnapProtocol::loadConfigWidget() void SnapProtocol::loadConfigWidget()
{ {
configWidget();
configForm->leOui->setText(uintToHexStr( configForm->leOui->setText(uintToHexStr(
fieldData(snap_oui, FieldValue).toUInt(), 3)); fieldData(snap_oui, FieldValue).toUInt(), 3));
configForm->leType->setText(uintToHexStr( configForm->leType->setText(uintToHexStr(
@ -155,6 +158,8 @@ void SnapProtocol::storeConfigWidget()
{ {
bool isOk; bool isOk;
configWidget();
data.set_oui(configForm->leOui->text().toULong(&isOk, BASE_HEX)); data.set_oui(configForm->leOui->text().toULong(&isOk, BASE_HEX));
data.set_type(configForm->leType->text().toULong(&isOk, BASE_HEX)); data.set_type(configForm->leType->text().toULong(&isOk, BASE_HEX));
} }

View File

@ -17,7 +17,7 @@ class SnapProtocol : public AbstractProtocol
{ {
private: private:
OstProto::Snap data; OstProto::Snap data;
static SnapConfigForm *configForm; SnapConfigForm *configForm;
enum snapfield enum snapfield
{ {
snap_oui = 0, snap_oui = 0,
@ -27,16 +27,14 @@ private:
}; };
public: public:
SnapProtocol(ProtocolList &frameProtoList, SnapProtocol(StreamBase *stream);
OstProto::StreamCore *parent = 0);
virtual ~SnapProtocol(); virtual ~SnapProtocol();
static AbstractProtocol* createInstance( static AbstractProtocol* createInstance(StreamBase *stream);
ProtocolList &frameProtoList, virtual quint32 protocolNumber() const;
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;

View File

@ -7,6 +7,6 @@ message Snap {
optional uint32 type = 2; optional uint32 type = 2;
} }
extend Stream { extend Protocol {
optional Snap snap = 124; optional Snap snap = 124;
} }

View File

@ -1,12 +1,47 @@
#include "streambase.h" #include "streambase.h"
#include "abstractprotocol.h"
#include "protocollist.h"
#include "protocollistiterator.h"
#include "protocolmanager.h"
extern ProtocolManager OstProtocolManager;
StreamBase::StreamBase() : StreamBase::StreamBase() :
mStreamId(new OstProto::StreamId), mStreamId(new OstProto::StreamId),
mCore(new OstProto::StreamCore), mCore(new OstProto::StreamCore),
mControl(new OstProto::StreamControl), mControl(new OstProto::StreamControl)
protocols(currentFrameProtocols, mCore)
{ {
AbstractProtocol *proto;
mStreamId->set_id(0xFFFFFFFF); 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() StreamBase::~StreamBase()
@ -18,12 +53,20 @@ StreamBase::~StreamBase()
void StreamBase::protoDataCopyFrom(const OstProto::Stream &stream) void StreamBase::protoDataCopyFrom(const OstProto::Stream &stream)
{ {
AbstractProtocol *proto;
mStreamId->CopyFrom(stream.stream_id()); mStreamId->CopyFrom(stream.stream_id());
mCore->CopyFrom(stream.core()); mCore->CopyFrom(stream.core());
mControl->CopyFrom(stream.control()); mControl->CopyFrom(stream.control());
protocols.protoDataCopyFrom(stream); currentFrameProtocols->destroy();
setFrameProtocol(frameProtocol()); 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 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_core()->CopyFrom(*mCore);
stream.mutable_control()->CopyFrom(*mControl); stream.mutable_control()->CopyFrom(*mControl);
protocols.protoDataCopyInto(stream); stream.clear_protocol();
} foreach (const AbstractProtocol* proto, *currentFrameProtocols)
QList<int> StreamBase::frameProtocol()
{
QList<int> protocolList;
for (int i = 0; i < mCore->frame_proto_size(); i++)
protocolList.append(mCore->frame_proto(i));
return protocolList;
}
void StreamBase::setFrameProtocol(QList<int> protocolList)
{
mCore->clear_frame_proto();
currentFrameProtocols.clear();
for (int i = 0; i < protocolList.size(); i++)
{ {
mCore->add_frame_proto(protocolList.at(i)); OstProto::Protocol *p;
currentFrameProtocols.append(protocols.protocol(protocolList.at(i)));
p = stream.add_protocol();
proto->protoDataCopyInto(*p);
} }
} }
AbstractProtocol* StreamBase::protocol(int protoNum) #if 0
ProtocolList StreamBase::frameProtocol()
{ {
return protocols.protocol(protoNum); return currentFrameProtocols;
} }
AbstractProtocol* StreamBase::protocol(QString protoName) void StreamBase::setFrameProtocol(ProtocolList protocolList)
{ {
return protocols.protocol(protoName); //currentFrameProtocols.destroy();
currentFrameProtocols = protocolList;
}
#endif
ProtocolListIterator* StreamBase::createProtocolListIterator()
{
return new ProtocolListIterator(*currentFrameProtocols);
} }
bool StreamBase::operator < (const StreamBase &s) const
{
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;
}

View File

@ -1,21 +1,25 @@
#ifndef _STREAM_BASE_H #ifndef _STREAM_BASE_H
#define _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 class StreamBase
{ {
protected: // TODO: temp - make private private:
OstProto::StreamId *mStreamId; OstProto::StreamId *mStreamId;
OstProto::StreamCore *mCore; OstProto::StreamCore *mCore;
OstProto::StreamControl *mControl; OstProto::StreamControl *mControl;
private:
ProtocolList currentFrameProtocols;
protected: protected:
ProtocolCollection protocols; //! \todo TODO: Make ProtocolList a private member of StreamBase?
ProtocolList *currentFrameProtocols;
public: public:
StreamBase(); StreamBase();
@ -24,13 +28,91 @@ public:
void protoDataCopyFrom(const OstProto::Stream &stream); void protoDataCopyFrom(const OstProto::Stream &stream);
void protoDataCopyInto(OstProto::Stream &stream) const; void protoDataCopyInto(OstProto::Stream &stream) const;
QList<int> frameProtocol(); ProtocolListIterator* createProtocolListIterator();
void setFrameProtocol(QList<int> protocolList);
AbstractProtocol* protocol(int protoNum);
AbstractProtocol* protocol(QString protoName);
// TODO: make a copy constructor // 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 #endif

View File

@ -3,45 +3,44 @@
#include "tcp.h" #include "tcp.h"
TcpConfigForm *TcpProtocol::configForm = NULL;
TcpConfigForm::TcpConfigForm(QWidget *parent) TcpConfigForm::TcpConfigForm(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
setupUi(this); setupUi(this);
} }
TcpProtocol::TcpProtocol( TcpProtocol::TcpProtocol(StreamBase *stream)
ProtocolList &frameProtoList, : AbstractProtocol(stream)
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) configForm = NULL;
configForm = new TcpConfigForm;
} }
TcpProtocol::~TcpProtocol() TcpProtocol::~TcpProtocol()
{ {
delete configForm;
} }
AbstractProtocol* TcpProtocol::createInstance( AbstractProtocol* TcpProtocol::createInstance(StreamBase *stream)
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{ {
return new TcpProtocol(frameProtoList, streamCore); return new TcpProtocol(stream);
} }
void TcpProtocol::protoDataCopyInto(OstProto::Stream &stream) quint32 TcpProtocol::protocolNumber() const
{ {
// FIXME: multiple headers return OstProto::Protocol::kTcpFieldNumber;
stream.MutableExtension(OstProto::tcp)->CopyFrom(data);
} }
void TcpProtocol::protoDataCopyFrom(const OstProto::Stream &stream) void TcpProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
{ {
// FIXME: multiple headers protocol.MutableExtension(OstProto::tcp)->CopyFrom(data);
if (stream.HasExtension(OstProto::tcp)) protocol.mutable_protocol_id()->set_id(protocolNumber());
data.MergeFrom(stream.GetExtension(OstProto::tcp)); }
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 QString TcpProtocol::name() const
@ -384,11 +383,15 @@ bool TcpProtocol::setFieldData(int index, const QVariant &value,
QWidget* TcpProtocol::configWidget() QWidget* TcpProtocol::configWidget()
{ {
if (configForm == NULL)
configForm = new TcpConfigForm;
return configForm; return configForm;
} }
void TcpProtocol::loadConfigWidget() void TcpProtocol::loadConfigWidget()
{ {
configWidget();
configForm->leTcpSrcPort->setText(QString().setNum(data.src_port())); configForm->leTcpSrcPort->setText(QString().setNum(data.src_port()));
configForm->leTcpDstPort->setText(QString().setNum(data.dst_port())); configForm->leTcpDstPort->setText(QString().setNum(data.dst_port()));
@ -419,6 +422,8 @@ void TcpProtocol::storeConfigWidget()
bool isOk; bool isOk;
int ff = 0; int ff = 0;
configWidget();
data.set_src_port(configForm->leTcpSrcPort->text().toULong(&isOk)); data.set_src_port(configForm->leTcpSrcPort->text().toULong(&isOk));
data.set_dst_port(configForm->leTcpDstPort->text().toULong(&isOk)); data.set_dst_port(configForm->leTcpDstPort->text().toULong(&isOk));

View File

@ -24,7 +24,7 @@ class TcpProtocol : public AbstractProtocol
{ {
private: private:
OstProto::Tcp data; OstProto::Tcp data;
static TcpConfigForm *configForm; TcpConfigForm *configForm;
enum tcpfield enum tcpfield
{ {
tcp_src_port = 0, tcp_src_port = 0,
@ -45,16 +45,14 @@ private:
}; };
public: public:
TcpProtocol(ProtocolList &frameProtoList, TcpProtocol(StreamBase *stream);
OstProto::StreamCore *parent = 0);
virtual ~TcpProtocol(); virtual ~TcpProtocol();
static AbstractProtocol* createInstance( static AbstractProtocol* createInstance(StreamBase *stream);
ProtocolList &frameProtoList, virtual quint32 protocolNumber() const;
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;

View File

@ -21,7 +21,7 @@ message Tcp {
optional uint32 urg_ptr = 11; optional uint32 urg_ptr = 11;
} }
extend Stream { extend Protocol {
optional Tcp tcp = 140; optional Tcp tcp = 140;
} }

View File

@ -3,45 +3,44 @@
#include "udp.h" #include "udp.h"
UdpConfigForm *UdpProtocol::configForm = NULL;
UdpConfigForm::UdpConfigForm(QWidget *parent) UdpConfigForm::UdpConfigForm(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
setupUi(this); setupUi(this);
} }
UdpProtocol::UdpProtocol( UdpProtocol::UdpProtocol(StreamBase *stream)
ProtocolList &frameProtoList, : AbstractProtocol(stream)
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) configForm = NULL;
configForm = new UdpConfigForm;
} }
UdpProtocol::~UdpProtocol() UdpProtocol::~UdpProtocol()
{ {
delete configForm;
} }
AbstractProtocol* UdpProtocol::createInstance( AbstractProtocol* UdpProtocol::createInstance(StreamBase *stream)
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{ {
return new UdpProtocol(frameProtoList, streamCore); return new UdpProtocol(stream);
} }
void UdpProtocol::protoDataCopyInto(OstProto::Stream &stream) quint32 UdpProtocol::protocolNumber() const
{ {
// FIXME: multiple headers return OstProto::Protocol::kUdpFieldNumber;
stream.MutableExtension(OstProto::udp)->CopyFrom(data);
} }
void UdpProtocol::protoDataCopyFrom(const OstProto::Stream &stream) void UdpProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
{ {
// FIXME: multiple headers protocol.MutableExtension(OstProto::udp)->CopyFrom(data);
if (stream.HasExtension(OstProto::udp)) protocol.mutable_protocol_id()->set_id(protocolNumber());
data.MergeFrom(stream.GetExtension(OstProto::udp)); }
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 QString UdpProtocol::name() const
@ -261,11 +260,15 @@ bool UdpProtocol::setFieldData(int index, const QVariant &value,
QWidget* UdpProtocol::configWidget() QWidget* UdpProtocol::configWidget()
{ {
if (configForm == NULL)
configForm = new UdpConfigForm;
return configForm; return configForm;
} }
void UdpProtocol::loadConfigWidget() void UdpProtocol::loadConfigWidget()
{ {
configWidget();
configForm->leUdpSrcPort->setText(fieldData(udp_srcPort, FieldValue).toString()); configForm->leUdpSrcPort->setText(fieldData(udp_srcPort, FieldValue).toString());
configForm->leUdpDstPort->setText(fieldData(udp_dstPort, FieldValue).toString()); configForm->leUdpDstPort->setText(fieldData(udp_dstPort, FieldValue).toString());
@ -281,6 +284,8 @@ void UdpProtocol::storeConfigWidget()
{ {
bool isOk; bool isOk;
configWidget();
data.set_src_port(configForm->leUdpSrcPort->text().toULong(&isOk)); data.set_src_port(configForm->leUdpSrcPort->text().toULong(&isOk));
data.set_dst_port(configForm->leUdpDstPort->text().toULong(&isOk)); data.set_dst_port(configForm->leUdpDstPort->text().toULong(&isOk));

View File

@ -17,7 +17,7 @@ class UdpProtocol : public AbstractProtocol
{ {
private: private:
OstProto::Udp data; OstProto::Udp data;
static UdpConfigForm *configForm; UdpConfigForm *configForm;
enum udpfield enum udpfield
{ {
udp_srcPort = 0, udp_srcPort = 0,
@ -32,16 +32,14 @@ private:
}; };
public: public:
UdpProtocol(ProtocolList &frameProtoList, UdpProtocol(StreamBase *stream);
OstProto::StreamCore *parent = 0);
virtual ~UdpProtocol(); virtual ~UdpProtocol();
static AbstractProtocol* createInstance( static AbstractProtocol* createInstance(StreamBase *stream);
ProtocolList &frameProtoList, virtual quint32 protocolNumber() const;
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;

View File

@ -13,6 +13,6 @@ message Udp {
optional uint32 cksum = 6; optional uint32 cksum = 6;
} }
extend Stream { extend Protocol {
optional Udp udp = 141; optional Udp udp = 141;
} }

View File

@ -2,45 +2,44 @@
#include "vlan.h" #include "vlan.h"
VlanConfigForm *VlanProtocol::configForm = NULL;
VlanConfigForm::VlanConfigForm(QWidget *parent) VlanConfigForm::VlanConfigForm(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
setupUi(this); setupUi(this);
} }
VlanProtocol::VlanProtocol( VlanProtocol::VlanProtocol(StreamBase *stream)
ProtocolList &frameProtoList, : AbstractProtocol(stream)
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) configForm = NULL;
configForm = new VlanConfigForm;
} }
VlanProtocol::~VlanProtocol() VlanProtocol::~VlanProtocol()
{ {
delete configForm;
} }
AbstractProtocol* VlanProtocol::createInstance( AbstractProtocol* VlanProtocol::createInstance(StreamBase *stream)
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{ {
return new VlanProtocol(frameProtoList, streamCore); return new VlanProtocol(stream);
} }
void VlanProtocol::protoDataCopyInto(OstProto::Stream &stream) quint32 VlanProtocol::protocolNumber() const
{ {
// FIXME: multiple headers return OstProto::Protocol::kVlanFieldNumber;
stream.MutableExtension(OstProto::vlan)->CopyFrom(data);
} }
void VlanProtocol::protoDataCopyFrom(const OstProto::Stream &stream) void VlanProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
{ {
// FIXME: multiple headers protocol.MutableExtension(OstProto::vlan)->CopyFrom(data);
if (stream.HasExtension(OstProto::vlan)) protocol.mutable_protocol_id()->set_id(protocolNumber());
data.MergeFrom(stream.GetExtension(OstProto::vlan)); }
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 QString VlanProtocol::name() const
@ -203,22 +202,27 @@ bool VlanProtocol::setFieldData(int index, const QVariant &value,
QWidget* VlanProtocol::configWidget() QWidget* VlanProtocol::configWidget()
{ {
if (configForm == NULL)
configForm = new VlanConfigForm;
return configForm; return configForm;
} }
void VlanProtocol::loadConfigWidget() void VlanProtocol::loadConfigWidget()
{ {
configWidget();
configForm->leTpid->setText(uintToHexStr(fieldData(vlan_tpid, FieldValue).toUInt(), 2)); configForm->leTpid->setText(uintToHexStr(fieldData(vlan_tpid, FieldValue).toUInt(), 2));
configForm->cmbPrio->setCurrentIndex(fieldData(vlan_prio, FieldValue).toUInt()); configForm->cmbPrio->setCurrentIndex(fieldData(vlan_prio, FieldValue).toUInt());
configForm->cmbCfiDei->setCurrentIndex(fieldData(vlan_cfiDei, FieldValue).toUInt()); configForm->cmbCfiDei->setCurrentIndex(fieldData(vlan_cfiDei, FieldValue).toUInt());
configForm->leVlanId->setText(fieldData(vlan_vlanId, FieldValue).toString()); configForm->leVlanId->setText(fieldData(vlan_vlanId, FieldValue).toString());
} }
void VlanProtocol::storeConfigWidget() void VlanProtocol::storeConfigWidget()
{ {
bool isOk; bool isOk;
configWidget();
data.set_is_override_tpid(configForm->cbTpidOverride->isChecked()); data.set_is_override_tpid(configForm->cbTpidOverride->isChecked());
data.set_tpid(configForm->leTpid->text().remove(QChar(' ')).toULong(&isOk, BASE_HEX)); data.set_tpid(configForm->leTpid->text().remove(QChar(' ')).toULong(&isOk, BASE_HEX));
data.set_vlan_tag( data.set_vlan_tag(

View File

@ -17,7 +17,7 @@ class VlanProtocol : public AbstractProtocol
{ {
private: private:
OstProto::Vlan data; OstProto::Vlan data;
static VlanConfigForm *configForm; VlanConfigForm *configForm;
enum Vlanfield enum Vlanfield
{ {
vlan_tpid, vlan_tpid,
@ -32,16 +32,14 @@ private:
}; };
public: public:
VlanProtocol(ProtocolList &frameProtoList, VlanProtocol(StreamBase *stream);
OstProto::StreamCore *parent = 0);
virtual ~VlanProtocol(); virtual ~VlanProtocol();
static AbstractProtocol* createInstance( static AbstractProtocol* createInstance(StreamBase *stream);
ProtocolList &frameProtoList, virtual quint32 protocolNumber() const;
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;

View File

@ -10,6 +10,6 @@ message Vlan {
optional uint32 vlan_tag = 3; // includes prio, cfi and vlanid optional uint32 vlan_tag = 3; // includes prio, cfi and vlanid
} }
extend Stream { extend Protocol {
optional Vlan vlan = 126; optional Vlan vlan = 126;
} }

View File

@ -1,8 +1,12 @@
#include "myservice.h"
#include "qdebug.h"
#include <qglobal.h> #include <qglobal.h>
#include <qendian.h> #include <qendian.h>
#include "qdebug.h"
#include "myservice.h"
#include "../common/protocollist.h"
#include "../common/abstractprotocol.h"
#if 0 #if 0
#include <pcap-int.h> #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 StreamInfo::makePacket(uchar *buf, int bufMaxSize, int n)
{ {
int pktLen, len = 0; int pktLen, len = 0;
// Decide a frame length based on length mode // Decide a frame length based on length mode
switch(mCore->len_mode()) switch(lenMode())
{ {
case OstProto::StreamCore::e_fl_fixed: case OstProto::StreamCore::e_fl_fixed:
pktLen = mCore->frame_len(); pktLen = frameLen();
break; break;
case OstProto::StreamCore::e_fl_inc: case OstProto::StreamCore::e_fl_inc:
pktLen = mCore->frame_len_min() + (n % pktLen = frameLenMin() + (n %
(mCore->frame_len_max() - mCore->frame_len_min() + 1)); (frameLenMax() - frameLenMin() + 1));
break; break;
case OstProto::StreamCore::e_fl_dec: case OstProto::StreamCore::e_fl_dec:
pktLen = mCore->frame_len_max() - (n % pktLen = frameLenMax() - (n %
(mCore->frame_len_max() - mCore->frame_len_min() + 1)); (frameLenMax() - frameLenMin() + 1));
break; break;
case OstProto::StreamCore::e_fl_random: case OstProto::StreamCore::e_fl_random:
pktLen = mCore->frame_len_min() + (qrand() % pktLen = frameLenMin() + (qrand() %
(mCore->frame_len_max() - mCore->frame_len_min() + 1)); (frameLenMax() - frameLenMin() + 1));
break; break;
default: default:
qWarning("Unhandled len mode %d. Using default 64", qWarning("Unhandled len mode %d. Using default 64",
mCore->len_mode()); lenMode());
pktLen = 64; pktLen = 64;
break; break;
} }
@ -81,11 +66,11 @@ int StreamInfo::makePacket(uchar *buf, int bufMaxSize, int n)
return 0; return 0;
// FIXME: Calculated pktLen is an input to Payload Protocol // 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; QByteArray ba;
ba = protocol(mCore->frame_proto(i))->protocolFrameValue(n); ba = proto->protocolFrameValue(n);
if (len + ba.size() < bufMaxSize) if (len + ba.size() < bufMaxSize)
{ {
memcpy(buf+len, ba.constData(), ba.size()); memcpy(buf+len, ba.constData(), ba.size());
@ -94,379 +79,6 @@ int StreamInfo::makePacket(uchar *buf, int bufMaxSize, int n)
} }
return pktLen; 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++) for (int i = 0; i < streamList.size(); i++)
{ {
//_restart: //_restart:
if (streamList[i]->mCore->is_enabled()) if (streamList[i]->isEnabled())
{ {
long numPackets, numBursts; long numPackets, numBursts;
long ibg, ipg; long ibg, ipg;
switch (streamList[i]->mControl->unit()) switch (streamList[i]->sendUnit())
{ {
case OstProto::StreamControl::e_su_bursts: case OstProto::StreamControl::e_su_bursts:
numBursts = streamList[i]->mControl->num_bursts(); numBursts = streamList[i]->numBursts();
numPackets = streamList[i]->mControl->packets_per_burst(); numPackets = streamList[i]->burstSize();
ibg = 1000000/streamList[i]->mControl->bursts_per_sec(); ibg = 1000000/streamList[i]->burstRate();
ipg = 0; ipg = 0;
break; break;
case OstProto::StreamControl::e_su_packets: case OstProto::StreamControl::e_su_packets:
numBursts = 1; numBursts = 1;
numPackets = streamList[i]->mControl->num_packets(); numPackets = streamList[i]->numPackets();
ibg = 0; ibg = 0;
ipg = 1000000/streamList[i]->mControl->packets_per_sec(); ipg = 1000000/streamList[i]->packetRate();
break; break;
default: default:
qWarning("Unhandled stream control unit %d", qWarning("Unhandled stream control unit %d",
streamList[i]->mControl->unit()); streamList[i]->sendUnit());
continue; continue;
} }
qDebug("numBursts = %ld, numPackets = %ld\n", qDebug("numBursts = %ld, numPackets = %ld\n",
@ -672,7 +284,7 @@ void PortInfo::update()
} }
} // for (numBursts) } // for (numBursts)
switch(streamList[i]->mControl->next()) switch(streamList[i]->nextWhat())
{ {
case ::OstProto::StreamControl::e_nw_stop: case ::OstProto::StreamControl::e_nw_stop:
goto _stop_no_more_pkts; goto _stop_no_more_pkts;
@ -697,7 +309,7 @@ void PortInfo::update()
default: default:
qFatal("---------- %s: Unhandled case (%d) -----------", qFatal("---------- %s: Unhandled case (%d) -----------",
__FUNCTION__, streamList[i]->mControl->next() ); __FUNCTION__, streamList[i]->nextWhat() );
break; break;
} }