Protocol Framework basic code in place now. Cleanup pending.

- New Classes:
  o ProtocolManager - singleton with which all protocols register
  o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
  o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
  o createInstance()
  o protocolFrameSize()
  o protocolFrameOffset(), protocolFramePayloadSize()
  o protocolId(), payloadProtocolId()
  o protocolFrameCksum(), protocolFramePayloadCksum()
  0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
This commit is contained in:
Srivats P. 2009-05-10 06:27:17 +00:00
parent 2d856012cb
commit 2ec7fb30c2
46 changed files with 1127 additions and 953 deletions

View File

@ -10,6 +10,12 @@ clean:
$(MAKE) -C server $@ $(MAKE) -C server $@
$(MAKE) -C client $@ $(MAKE) -C client $@
distclean:
$(MAKE) -C rpc $@
$(MAKE) -C common $@
$(MAKE) -C server $@
$(MAKE) -C client $@
qmake: qmake:
cd rpc && qmake && cd .. cd rpc && qmake && cd ..
cd common && qmake && cd .. cd common && qmake && cd ..

View File

@ -98,7 +98,7 @@ bool Port::updateStream(uint streamId, OstProto::Stream *stream)
_found: _found:
streamIndex = i; streamIndex = i;
mStreams[streamIndex]->update(stream); mStreams[streamIndex]->protoDataCopyFrom(*stream);
reorderStreamsByOrdinals(); reorderStreamsByOrdinals();
return true; return true;
@ -167,7 +167,7 @@ void Port::getModifiedStreamsSinceLastSync(
OstProto::Stream *s; OstProto::Stream *s;
s = streamConfigList.add_stream(); s = streamConfigList.add_stream();
mStreams[i]->getConfig(mPortId, *s); mStreams[i]->protoDataCopyInto(*s);
} }
qDebug("Done %s", __FUNCTION__); qDebug("Done %s", __FUNCTION__);
} }

View File

@ -3,173 +3,27 @@
#include "stream.h" #include "stream.h"
#include "../common/mac.h"
#include "../common/payload.h"
#include "../common/eth2.h" // FIXME: proto DB
#include "../common/dot3.h" // FIXME: proto DB
#include "../common/llc.h" // FIXME: proto DB
#include "../common/snap.h" // FIXME: proto DB
#include "../common/ip4.h" // FIXME: proto DB
#include "../common/tcp.h" // FIXME: proto DB
#include "../common/udp.h" // FIXME: proto DB
//-----------------------------------------------------
// Stream Class Methods
//-----------------------------------------------------
Stream::Stream() Stream::Stream()
{ {
mId = 0xFFFFFFFF; //mId = 0xFFFFFFFF;
mCore = new OstProto::StreamCore;
mControl = new OstProto::StreamControl;
// mCore->set_port_id(0xFFFFFFFF);
// mCore->set_stream_id(mId);
mProtocolList.append(new MacProtocol);
mProtocolList.append(new PayloadProtocol(this));
// FIXME: proto DB
mProtocolList.append(new Eth2Protocol);
mProtocolList.append(new Dot3Protocol);
mProtocolList.append(new LlcProtocol);
mProtocolList.append(new SnapProtocol);
mProtocolList.append(new Ip4Protocol);
mProtocolList.append(new TcpProtocol);
mProtocolList.append(new UdpProtocol);
mCore->set_is_enabled(true); mCore->set_is_enabled(true);
mCore->add_frame_proto(51); // MAC (FIXME: hardcoding)
mCore->add_frame_proto(52); // Payload (FIXME: hardcoding) QList<int> protoList;
protoList.append(51);
protoList.append(52);
setFrameProtocol(protoList);
} }
Stream::~Stream() Stream::~Stream()
{ {
for (int i = 0; i < mProtocolList.size(); i++)
delete mProtocolList.at(i);
delete mControl;
delete mCore;
}
void Stream::protoDataCopyFrom(Stream& stream)
{
OstProto::Stream data;
stream.getConfig(0, data);
update(&data);
} }
void Stream::loadProtocolWidgets() void Stream::loadProtocolWidgets()
{ {
for (int i=0; i < mProtocolList.size(); i++) protocols.loadConfigWidgets();
mProtocolList[i]->loadConfigWidget();
} }
void Stream::storeProtocolWidgets() void Stream::storeProtocolWidgets()
{ {
for (int i=0; i < mProtocolList.size(); i++) protocols.storeConfigWidgets();
mProtocolList[i]->storeConfigWidget();
}
/*! Copy current client side config into the OstProto::Stream */
// FIXME - remove portId unused param!
void Stream::getConfig(uint portId, OstProto::Stream &s)
{
s.mutable_stream_id()->set_id(mId);
s.mutable_core()->CopyFrom(*mCore);
s.mutable_control()->CopyFrom(*mControl);
// FIXME - this doesn't take care of multiple headers of same proto
// e.g. IPinIP or double VLAN Tagged
// FIXME: change s from pointer to reference?
for (int i = 0; i < mProtocolList.size(); i++)
{
qDebug("%s: protocol %d", __FUNCTION__, i);
mProtocolList[i]->protoDataCopyInto(s);
}
qDebug("%s: Done", __FUNCTION__);
}
bool Stream::update(OstProto::Stream *stream)
{
mCore->clear_frame_proto();
mCore->MergeFrom(stream->core());
mControl->MergeFrom(stream->control());
// FIXME - this doesn't take care of multiple headers of same proto
// e.g. IPinIP or double VLAN Tagged
// FIXME: change s from pointer to reference?
for (int i = 0; i < mProtocolList.size(); i++)
{
mProtocolList[i]->protoDataCopyFrom(*stream);
}
// FIXME(MED): Re-eval why not store complete OstProto::Stream
// instead of components
return true;
}
QList<int> Stream::frameProtocol()
{
QList<int> protocolList;
for (int i = 0; i < mCore->frame_proto_size(); i++)
protocolList.append(mCore->frame_proto(i));
return protocolList;
}
void Stream::setFrameProtocol(QList<int> protocolList)
{
mCore->clear_frame_proto();
for (int i = 0; i < protocolList.size(); i++)
mCore->add_frame_proto(protocolList.at(i));
}
int Stream::protocolHeaderSize()
{
int size = 0;
for (int i = 0; i < mCore->frame_proto_size(); i++)
size += protocolById(mCore->frame_proto(i))->
protocolFrameValue().size();
return size;
}
AbstractProtocol* Stream::protocolById(int id)
{
// FIXME BAD BAD VERY BAD!
switch(id) {
case 51:
return mProtocolList.at(0);
case 52:
return mProtocolList.at(1);
case 121:
return mProtocolList.at(2);
case 122:
return mProtocolList.at(3);
case 123:
return mProtocolList.at(4);
case 124:
return mProtocolList.at(5);
// case 125 (unused)
#if 0 // todo VLAN
case 126:
return mProtocolList.at(x);
#endif
case 130:
return mProtocolList.at(6);
case 140:
return mProtocolList.at(7);
case 141:
return mProtocolList.at(8);
default:
return NULL;
}
} }

View File

@ -2,48 +2,21 @@
#define _STREAM_H #define _STREAM_H
#include <QtGlobal> #include <QtGlobal>
#include <QString> #include <QString>
#include <QList> #include <QList>
#include "../common/protocol.pb.h" #include "../common/protocol.pb.h"
#include "../common/abstractprotocol.h" #include "../common/streambase.h"
// Convenience Defines FIXME class Stream : public StreamBase {
#define IP_PROTO_ICMP 0x01
#define IP_PROTO_IGMP 0x02
#define IP_PROTO_TCP 0x06
#define IP_PROTO_UDP 0x11
class Stream { //quint32 mId;
quint32 mId;
OstProto::StreamCore *mCore;
OstProto::StreamControl *mControl;
QList<AbstractProtocol*> mProtocolList;
public: public:
void* core() { return mCore; } // FIXME(HI): Debug ONLY
void loadProtocolWidgets(); void loadProtocolWidgets();
void storeProtocolWidgets(); void storeProtocolWidgets();
public: public:
enum FrameType {
e_ft_none,
e_ft_eth_2,
e_ft_802_3_raw,
e_ft_802_3_llc,
e_ft_snap
};
enum DataPatternMode {
e_dp_fixed_word,
e_dp_inc_byte,
e_dp_dec_byte,
e_dp_random
};
enum FrameLengthMode { enum FrameLengthMode {
e_fl_fixed, e_fl_fixed,
e_fl_inc, e_fl_inc,
@ -51,20 +24,6 @@ public:
e_fl_random e_fl_random
}; };
enum L3Proto {
e_l3_none,
e_l3_ip,
e_l3_arp,
};
enum L4Proto {
e_l4_none,
e_l4_tcp,
e_l4_udp,
e_l4_icmp,
e_l4_igmp,
};
enum SendUnit { enum SendUnit {
e_su_packets, e_su_packets,
e_su_bursts e_su_bursts
@ -87,19 +46,15 @@ public:
Stream(); Stream();
~Stream(); ~Stream();
void protoDataCopyFrom(Stream& stream); // TODO: Below methods move to StreamBase???
bool operator < (const Stream &s) const bool operator < (const Stream &s) const
{ return(mCore->ordinal() < s.mCore->ordinal()); } { return(mCore->ordinal() < s.mCore->ordinal()); }
void getConfig(uint portId, OstProto::Stream &s);
bool update(OstProto::Stream *stream);
quint32 id() quint32 id()
{ return mId;} { return mStreamId->id();}
bool setId(quint32 id) bool setId(quint32 id)
{ mId = id; return true;} { mStreamId->set_id(id); return true;}
#if 0 // FIXME(HI): needed? #if 0 // FIXME(HI): needed?
quint32 portId() quint32 portId()
@ -123,12 +78,7 @@ public:
bool setName(QString name) bool setName(QString name)
{ mCore->set_name(name.toStdString()); return true; } { mCore->set_name(name.toStdString()); return true; }
// TODO(HI) : ????? // Frame Length (includes FCS)
#if 0
quint16 dataStartOfs;
#endif
// Frame Length (includes CRC)
FrameLengthMode lenMode() FrameLengthMode lenMode()
{ return (FrameLengthMode) mCore->len_mode(); } { return (FrameLengthMode) mCore->len_mode(); }
bool setLenMode(FrameLengthMode lenMode) bool setLenMode(FrameLengthMode lenMode)
@ -192,16 +142,6 @@ public:
{ return (quint32) mControl->bursts_per_sec(); } { return (quint32) mControl->bursts_per_sec(); }
bool setBurstRate(quint32 burstsPerSec) bool setBurstRate(quint32 burstsPerSec)
{ mControl->set_bursts_per_sec(burstsPerSec); return true; } { mControl->set_bursts_per_sec(burstsPerSec); return true; }
//---------------------------------------------------------------
// Methods for use by Packet Model
//---------------------------------------------------------------
QList<int> frameProtocol();
void setFrameProtocol(QList<int> protocolList);
//! Includes ALL protocol headers excluding payload data
int protocolHeaderSize();
AbstractProtocol* protocolById(int id);
}; };
#endif #endif

View File

@ -7,71 +7,38 @@
int StreamConfigDialog::lastTopLevelTabIndex = 0; int StreamConfigDialog::lastTopLevelTabIndex = 0;
int StreamConfigDialog::lastProtoTabIndex = 0; int StreamConfigDialog::lastProtoTabIndex = 0;
// TODO(HI): Write HexLineEdit::setNum() and num() and use it in
// Load/Store stream methods
StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex, StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
QWidget *parent) : QDialog (parent), mPort(port) QWidget *parent) : QDialog (parent), mPort(port)
{ {
OstProto::Stream s;
mCurrentStreamIndex = streamIndex; mCurrentStreamIndex = streamIndex;
mpStream = new Stream; mpStream = new Stream;
mpStream->protoDataCopyFrom(*(mPort.streamByIndex(mCurrentStreamIndex))); mPort.streamByIndex(mCurrentStreamIndex)->protoDataCopyInto(s);
mpStream->protoDataCopyFrom(s);
setupUi(this); setupUi(this);
setupUiExtra(); setupUiExtra();
// setupUi connect(bgFrameType, SIGNAL(buttonClicked(int)),
this, SLOT(updateSelectedProtocols()));
connect(bgL3Proto, SIGNAL(buttonClicked(int)),
this, SLOT(updateSelectedProtocols()));
connect(bgL4Proto, SIGNAL(buttonClicked(int)),
this, SLOT(updateSelectedProtocols()));
// Time to play match the signals and slots! // Time to play match the signals and slots!
connect(rbFtNone, SIGNAL(toggled(bool)), rbL3None, SLOT(setChecked(bool))); connect(rbFtNone, SIGNAL(toggled(bool)), rbL3None, SLOT(setChecked(bool)));
// Show/Hide FrameType related inputs for FT None
connect(rbFtNone, SIGNAL(toggled(bool)), lblDsap, SLOT(setHidden(bool)));
connect(rbFtNone, SIGNAL(toggled(bool)), leDsap, SLOT(setHidden(bool)));
connect(rbFtNone, SIGNAL(toggled(bool)), lblSsap, SLOT(setHidden(bool)));
connect(rbFtNone, SIGNAL(toggled(bool)), leSsap, SLOT(setHidden(bool)));
connect(rbFtNone, SIGNAL(toggled(bool)), lblControl, SLOT(setHidden(bool)));
connect(rbFtNone, SIGNAL(toggled(bool)), leControl, SLOT(setHidden(bool)));
connect(rbFtNone, SIGNAL(toggled(bool)), lblOui, SLOT(setHidden(bool)));
connect(rbFtNone, SIGNAL(toggled(bool)), leOui, SLOT(setHidden(bool)));
connect(rbFtNone, SIGNAL(toggled(bool)), lblType, SLOT(setHidden(bool)));
connect(rbFtNone, SIGNAL(toggled(bool)), leType, SLOT(setHidden(bool)));
// Enable/Disable L3 Protocol Choices for FT None // Enable/Disable L3 Protocol Choices for FT None
connect(rbFtNone, SIGNAL(toggled(bool)), rbL3None, SLOT(setEnabled(bool))); connect(rbFtNone, SIGNAL(toggled(bool)), rbL3None, SLOT(setEnabled(bool)));
connect(rbFtNone, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setDisabled(bool))); connect(rbFtNone, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setDisabled(bool)));
connect(rbFtNone, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setDisabled(bool))); connect(rbFtNone, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setDisabled(bool)));
// Show/Hide FrameType related inputs for FT Ethernet2
connect(rbFtEthernet2, SIGNAL(toggled(bool)), lblDsap, SLOT(setHidden(bool)));
connect(rbFtEthernet2, SIGNAL(toggled(bool)), leDsap, SLOT(setHidden(bool)));
connect(rbFtEthernet2, SIGNAL(toggled(bool)), lblSsap, SLOT(setHidden(bool)));
connect(rbFtEthernet2, SIGNAL(toggled(bool)), leSsap, SLOT(setHidden(bool)));
connect(rbFtEthernet2, SIGNAL(toggled(bool)), lblControl, SLOT(setHidden(bool)));
connect(rbFtEthernet2, SIGNAL(toggled(bool)), leControl, SLOT(setHidden(bool)));
connect(rbFtEthernet2, SIGNAL(toggled(bool)), lblOui, SLOT(setHidden(bool)));
connect(rbFtEthernet2, SIGNAL(toggled(bool)), leOui, SLOT(setHidden(bool)));
connect(rbFtEthernet2, SIGNAL(toggled(bool)), lblType, SLOT(setVisible(bool)));
connect(rbFtEthernet2, SIGNAL(toggled(bool)), leType, SLOT(setVisible(bool)));
// Enable/Disable L3 Protocol Choices for FT Ethernet2 // Enable/Disable L3 Protocol Choices for FT Ethernet2
connect(rbFtEthernet2, SIGNAL(toggled(bool)), rbL3None, SLOT(setEnabled(bool))); connect(rbFtEthernet2, SIGNAL(toggled(bool)), rbL3None, SLOT(setEnabled(bool)));
connect(rbFtEthernet2, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setEnabled(bool))); connect(rbFtEthernet2, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setEnabled(bool)));
connect(rbFtEthernet2, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setEnabled(bool))); connect(rbFtEthernet2, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setEnabled(bool)));
// Show/Hide FrameType related inputs for FT 802.3 Raw
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), lblDsap, SLOT(setHidden(bool)));
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), leDsap, SLOT(setHidden(bool)));
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), lblSsap, SLOT(setHidden(bool)));
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), leSsap, SLOT(setHidden(bool)));
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), lblControl, SLOT(setHidden(bool)));
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), leControl, SLOT(setHidden(bool)));
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), lblOui, SLOT(setHidden(bool)));
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), leOui, SLOT(setHidden(bool)));
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), lblType, SLOT(setHidden(bool)));
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), leType, SLOT(setHidden(bool)));
// Force L3 = None if FT = 802.3 Raw // Force L3 = None if FT = 802.3 Raw
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), rbL3None, SLOT(setChecked(bool))); connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), rbL3None, SLOT(setChecked(bool)));
@ -80,18 +47,6 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setDisabled(bool))); connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setDisabled(bool)));
connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setDisabled(bool))); connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setDisabled(bool)));
// Show/Hide FrameType related inputs for FT 802.3 LLC
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), lblDsap, SLOT(setVisible(bool)));
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), leDsap, SLOT(setVisible(bool)));
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), lblSsap, SLOT(setVisible(bool)));
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), leSsap, SLOT(setVisible(bool)));
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), lblControl, SLOT(setVisible(bool)));
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), leControl, SLOT(setVisible(bool)));
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), lblOui, SLOT(setHidden(bool)));
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), leOui, SLOT(setHidden(bool)));
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), lblType, SLOT(setHidden(bool)));
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), leType, SLOT(setHidden(bool)));
// Force L3 = None if FT = 802.3 LLC (to ensure a valid L3 is selected) // Force L3 = None if FT = 802.3 LLC (to ensure a valid L3 is selected)
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), rbL3None, SLOT(setChecked(bool))); connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), rbL3None, SLOT(setChecked(bool)));
@ -100,31 +55,11 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setEnabled(bool))); connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setEnabled(bool)));
connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setDisabled(bool))); connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setDisabled(bool)));
// Show/Hide FrameType related inputs for FT 802.3 LLC SNAP
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), lblDsap, SLOT(setVisible(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), leDsap, SLOT(setVisible(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), lblSsap, SLOT(setVisible(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), leSsap, SLOT(setVisible(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), lblControl, SLOT(setVisible(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), leControl, SLOT(setVisible(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), lblOui, SLOT(setVisible(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), leOui, SLOT(setVisible(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), lblType, SLOT(setVisible(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), leType, SLOT(setVisible(bool)));
// Enable/Disable L3 Protocol Choices for FT 802.3 LLC SNAP // Enable/Disable L3 Protocol Choices for FT 802.3 LLC SNAP
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), rbL3None, SLOT(setEnabled(bool))); connect(rbFtLlcSnap, SIGNAL(toggled(bool)), rbL3None, SLOT(setEnabled(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setEnabled(bool))); connect(rbFtLlcSnap, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setEnabled(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setEnabled(bool))); connect(rbFtLlcSnap, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setEnabled(bool)));
// Enable/Disable FrameType related inputs for FT 802.3 LLC SNAP
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), lblDsap, SLOT(setDisabled(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), leDsap, SLOT(setDisabled(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), lblSsap, SLOT(setDisabled(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), leSsap, SLOT(setDisabled(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), lblControl, SLOT(setDisabled(bool)));
connect(rbFtLlcSnap, SIGNAL(toggled(bool)), leControl, SLOT(setDisabled(bool)));
// Enable/Disable L4 Protocol Choices for L3 Protocol None // Enable/Disable L4 Protocol Choices for L3 Protocol None
connect(rbL3None, SIGNAL(toggled(bool)), rbL4None, SLOT(setEnabled(bool))); connect(rbL3None, SIGNAL(toggled(bool)), rbL4None, SLOT(setEnabled(bool)));
connect(rbL3None, SIGNAL(toggled(bool)), rbL4Icmp, SLOT(setDisabled(bool))); connect(rbL3None, SIGNAL(toggled(bool)), rbL4Icmp, SLOT(setDisabled(bool)));
@ -152,18 +87,6 @@ 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)));
//TODO: remove if not needed
#if 0
// This set of 'clicks' is a hack to trigger signals at dialog creation
// time so that a coherent 'set' is initialized
// Actual stream values will be initialized by LoadCurrentStream()
rbL3Ipv4->click();
rbL3None->click();
rbFtEthernet2->click();
rbFtNone->click();
#endif
//mmpStreamList = streamList;
LoadCurrentStream(); LoadCurrentStream();
mpPacketModel = new PacketModel(QList<AbstractProtocol*>(), this); mpPacketModel = new PacketModel(QList<AbstractProtocol*>(), this);
tvPacketTree->setModel(mpPacketModel); tvPacketTree->setModel(mpPacketModel);
@ -173,6 +96,10 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
vwPacketDump->setSelectionModel(tvPacketTree->selectionModel()); vwPacketDump->setSelectionModel(tvPacketTree->selectionModel());
// TODO(MED): // TODO(MED):
//! \todo Implement then enable these protocols
rbL3Arp->setHidden(true);
rbL4Icmp->setHidden(true);
rbL4Igmp->setHidden(true);
//! \todo Enable navigation of streams //! \todo Enable navigation of streams
pbPrev->setDisabled(true); pbPrev->setDisabled(true);
pbNext->setDisabled(true); pbNext->setDisabled(true);
@ -181,6 +108,7 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex,
disconnect(rbActionGotoStream, SIGNAL(toggled(bool)), leStreamId, SLOT(setEnabled(bool))); disconnect(rbActionGotoStream, SIGNAL(toggled(bool)), leStreamId, SLOT(setEnabled(bool)));
//! \todo Support Continuous Mode //! \todo Support Continuous Mode
rbModeContinuous->setDisabled(true); rbModeContinuous->setDisabled(true);
// Finally, restore the saved last selected tab for the various tab widgets // Finally, restore the saved last selected tab for the various tab widgets
twTopLevel->setCurrentIndex(lastTopLevelTabIndex); twTopLevel->setCurrentIndex(lastTopLevelTabIndex);
if (twProto->isTabEnabled(lastProtoTabIndex)) if (twProto->isTabEnabled(lastProtoTabIndex))
@ -199,27 +127,25 @@ void StreamConfigDialog::setupUiExtra()
layout = static_cast<QGridLayout*>(twTopLevel->widget(0)->layout()); layout = static_cast<QGridLayout*>(twTopLevel->widget(0)->layout());
layout->addWidget(mpStream->protocolById(52)->configWidget(), 0, 1); layout->addWidget(mpStream->protocol(52)->configWidget(), 0, 1);
qDebug("setupUi wgt = %p", mpStream->protocolById(52)->configWidget()); qDebug("setupUi wgt = %p", mpStream->protocol(52)->configWidget());
} }
// ---- Setup default stuff that cannot be done in designer ---- // ---- Setup default stuff that cannot be done in designer ----
bgFrameType = new QButtonGroup();
foreach(QRadioButton *btn, gbFrameType->findChildren<QRadioButton*>())
bgFrameType->addButton(btn);
// Since the dialog defaults are FT = None, L3 = None, L4 = None; bgL3Proto = new QButtonGroup();
// hide associated input fields since it can't be done in Designer foreach(QRadioButton *btn, gbL3Proto->findChildren<QRadioButton*>())
lblDsap->setHidden(true); bgL3Proto->addButton(btn);
leDsap->setHidden(true);
lblSsap->setHidden(true);
leSsap->setHidden(true);
lblControl->setHidden(true);
leControl->setHidden(true);
lblOui->setHidden(true);
leOui->setHidden(true);
lblType->setHidden(true);
leType->setHidden(true);
twProto->setTabEnabled(2, FALSE); bgL4Proto = new QButtonGroup();
twProto->setTabEnabled(3, FALSE); foreach(QRadioButton *btn, gbL4Proto->findChildren<QRadioButton*>())
bgL4Proto->addButton(btn);
//twProto->setTabEnabled(2, FALSE);
//twProto->setTabEnabled(3, FALSE);
/* /*
** Setup Validators ** Setup Validators
@ -263,18 +189,8 @@ StreamConfigDialog::~StreamConfigDialog()
QLayout *layout = twTopLevel->widget(0)->layout(); QLayout *layout = twTopLevel->widget(0)->layout();
if (layout) if (layout)
{ {
qDebug("dstrct wgt = %p", mpStream->protocolById(52)->configWidget()); layout->removeWidget(mpStream->protocol(52)->configWidget());
#if 0 mpStream->protocol(52)->configWidget()->setParent(0);
int i = layout->indexOf(mpStream->protocolById(52)->configWidget());
if (i >= 0)
{
layout->takeAt(i);
mpStream->protocolById(52)->configWidget()->setParent(0);
}
#endif
layout->removeWidget(mpStream->protocolById(52)->configWidget());
mpStream->protocolById(52)->configWidget()->setParent(0);
} }
} }
@ -296,6 +212,10 @@ StreamConfigDialog::~StreamConfigDialog()
} }
} }
delete bgFrameType;
delete bgL3Proto;
delete bgL4Proto;
delete mpStream; delete mpStream;
} }
@ -340,6 +260,10 @@ void StreamConfigDialog::updateSelectedProtocols()
// Payload // Payload
mSelectedProtocols.append(52); mSelectedProtocols.append(52);
mpStream->setFrameProtocol(mSelectedProtocols);
mpStream->storeProtocolWidgets();
mpStream->loadProtocolWidgets();
} }
@ -399,146 +323,6 @@ void StreamConfigDialog::on_pbNext_clicked()
#endif #endif
} }
void StreamConfigDialog::on_rbFtNone_toggled(bool checked)
{
}
void StreamConfigDialog::on_rbFtEthernet2_toggled(bool checked)
{
}
void StreamConfigDialog::on_rbFt802Dot3Raw_toggled(bool checked)
{
}
void StreamConfigDialog::on_rbFt802Dot3Llc_toggled(bool checked)
{
}
void StreamConfigDialog::on_rbFtLlcSnap_toggled(bool checked)
{
if (checked)
{
leDsap->setText("AA");
leSsap->setText("AA");
leControl->setText("03");
}
}
void StreamConfigDialog::on_rbL3Ipv4_toggled(bool checked)
{
if (checked)
{
twProto->setTabEnabled(2, TRUE);
twProto->setTabText(2, "L3 (IPv4)");
leType->setText("08 00");
// FIXME: Hardcoding
mpStream->protocolById(121)->setFieldData(0 /* type */, 0x800);
mpStream->loadProtocolWidgets(); // FIXME: pass protocol as param
}
else
{
twProto->setTabEnabled(2, FALSE);
twProto->setTabText(2, "L3");
}
}
void StreamConfigDialog::on_rbL3Arp_toggled(bool checked)
{
if (checked)
{
twProto->setTabEnabled(2, TRUE);
twProto->setTabText(2, "L3 (ARP)");
leType->setText("08 06");
// FIXME: Hardcoding
mpStream->protocolById(121)->setFieldData(0 /* type */, 0x806);
mpStream->loadProtocolWidgets(); // FIXME: pass protocol as param
}
else
{
twProto->setTabEnabled(2, FALSE);
twProto->setTabText(2, "L3");
}
}
void StreamConfigDialog::on_rbL4Icmp_toggled(bool checked)
{
QString str;
if (checked)
{
twProto->setTabEnabled(3, TRUE);
twProto->setTabText(3, "L4 (ICMP)");
// FIXME: Hardcoding
mpStream->protocolById(130)->setFieldData(8 /* proto */, IP_PROTO_ICMP);
mpStream->loadProtocolWidgets(); // FIXME: pass protocol as param
}
else
{
twProto->setTabEnabled(3, FALSE);
twProto->setTabText(3, "L4");
}
}
void StreamConfigDialog::on_rbL4Igmp_toggled(bool checked)
{
QString str;
if (checked)
{
twProto->setTabEnabled(3, TRUE);
twProto->setTabText(3, "L4 (IGMP)");
// FIXME: Hardcoding
mpStream->protocolById(130)->setFieldData(8 /* proto */, IP_PROTO_IGMP);
mpStream->loadProtocolWidgets(); // FIXME: pass protocol as param
}
else
{
twProto->setTabEnabled(3, FALSE);
twProto->setTabText(3, "L4");
}
}
void StreamConfigDialog::on_rbL4Tcp_toggled(bool checked)
{
QString str;
if (checked)
{
twProto->setTabEnabled(3, TRUE);
twProto->setTabText(3, "L4 (TCP)");
// FIXME: Hardcoding
mpStream->protocolById(130)->setFieldData(8 /* proto */, IP_PROTO_TCP);
mpStream->loadProtocolWidgets(); // FIXME: pass protocol as param
}
else
{
twProto->setTabEnabled(3, FALSE);
twProto->setTabText(3, "L4");
}
}
void StreamConfigDialog::on_rbL4Udp_toggled(bool checked)
{
QString str;
if (checked)
{
twProto->setTabEnabled(3, TRUE);
twProto->setTabText(3, "L4 (UDP)");
// FIXME: Hardcoding
mpStream->protocolById(130)->setFieldData(8 /* proto */, IP_PROTO_UDP);
mpStream->loadProtocolWidgets(); // FIXME: pass protocol as param
}
else
{
twProto->setTabEnabled(3, FALSE);
twProto->setTabText(3, "L4");
}
}
void StreamConfigDialog::on_twTopLevel_currentChanged(int index) void StreamConfigDialog::on_twTopLevel_currentChanged(int index)
{ {
QList<AbstractProtocol*> protoList; QList<AbstractProtocol*> protoList;
@ -549,8 +333,8 @@ void StreamConfigDialog::on_twTopLevel_currentChanged(int index)
updateSelectedProtocols(); updateSelectedProtocols();
foreach(int i, mSelectedProtocols) foreach(int i, mSelectedProtocols)
if (mpStream->protocolById(i)) if (mpStream->protocol(i))
protoList.append(mpStream->protocolById(i)); protoList.append(mpStream->protocol(i));
mpPacketModel->setSelectedProtocols(protoList); mpPacketModel->setSelectedProtocols(protoList);
StoreCurrentStream(mpStream); StoreCurrentStream(mpStream);
@ -583,42 +367,44 @@ void StreamConfigDialog::on_twProto_currentChanged(int index)
switch(index) switch(index)
{ {
case 1: // L2 case 1: // L2
wl.append(mpStream->protocolById(51)->configWidget()); wl.append(mpStream->protocol("mac")->configWidget());
if (rbFtEthernet2->isChecked()) if (rbFtEthernet2->isChecked())
wl.append(mpStream->protocolById(121)->configWidget()); wl.append(mpStream->protocol("eth2")->configWidget());
else if (rbFt802Dot3Raw->isChecked()) else if (rbFt802Dot3Raw->isChecked())
wl.append(mpStream->protocolById(122)->configWidget()); wl.append(mpStream->protocol("dot3")->configWidget());
else if (rbFt802Dot3Llc->isChecked()) else if (rbFt802Dot3Llc->isChecked())
{ {
wl.append(mpStream->protocolById(122)->configWidget()); wl.append(mpStream->protocol("dot3")->configWidget());
wl.append(mpStream->protocolById(123)->configWidget()); wl.append(mpStream->protocol("llc")->configWidget());
} }
else if (rbFtLlcSnap->isChecked()) else if (rbFtLlcSnap->isChecked())
{ {
wl.append(mpStream->protocolById(122)->configWidget()); wl.append(mpStream->protocol("dot3")->configWidget());
wl.append(mpStream->protocolById(123)->configWidget()); wl.append(mpStream->protocol("llc")->configWidget());
wl.append(mpStream->protocolById(124)->configWidget()); wl.append(mpStream->protocol("snap")->configWidget());
} }
break; break;
case 2: // L3 case 2: // L3
if (rbL3Ipv4->isChecked()) if (rbL3Ipv4->isChecked())
wl.append(mpStream->protocolById(130)->configWidget()); wl.append(mpStream->protocol("ip4")->configWidget());
break; break;
case 3: // L4 case 3: // L4
if (rbL4Tcp->isChecked()) if (rbL4Tcp->isChecked())
wl.append(mpStream->protocolById(140)->configWidget()); wl.append(mpStream->protocol("tcp")->configWidget());
else if (rbL4Udp->isChecked()) else if (rbL4Udp->isChecked())
wl.append(mpStream->protocolById(141)->configWidget()); wl.append(mpStream->protocol("udp")->configWidget());
break; break;
} }
if (wl.size()) if (wl.size())
{
layout = new QVBoxLayout; layout = new QVBoxLayout;
for (int i=0; i < wl.size(); i++) for (int i=0; i < wl.size(); i++)
layout->addWidget(wl.at(i)); layout->addWidget(wl.at(i));
twProto->widget(index)->setLayout(layout); twProto->widget(index)->setLayout(layout);
}
} }
void StreamConfigDialog::update_NumPacketsAndNumBursts() void StreamConfigDialog::update_NumPacketsAndNumBursts()

View File

@ -29,6 +29,10 @@ public:
private: private:
//QList<Stream> *mpStreamList; //QList<Stream> *mpStreamList;
QButtonGroup *bgFrameType;
QButtonGroup *bgL3Proto;
QButtonGroup *bgL4Proto;
Port& mPort; Port& mPort;
uint mCurrentStreamIndex; uint mCurrentStreamIndex;
Stream *mpStream; Stream *mpStream;
@ -45,7 +49,6 @@ private:
static int lastProtoTabIndex; static int lastProtoTabIndex;
void setupUiExtra(); void setupUiExtra();
void updateSelectedProtocols();
void LoadCurrentStream(); void LoadCurrentStream();
void StoreCurrentStream(Stream *pStream); void StoreCurrentStream(Stream *pStream);
@ -54,18 +57,7 @@ private slots:
void on_pbPrev_clicked(); void on_pbPrev_clicked();
void on_pbNext_clicked(); void on_pbNext_clicked();
void on_rbFtNone_toggled(bool checked); void updateSelectedProtocols();
void on_rbFtEthernet2_toggled(bool checked);
void on_rbFt802Dot3Raw_toggled(bool checked);
void on_rbFt802Dot3Llc_toggled(bool checked);
void on_rbFtLlcSnap_toggled(bool checked);
void on_rbL3Ipv4_toggled(bool checked);
void on_rbL3Arp_toggled(bool checked);
void on_rbL4Icmp_toggled(bool checked);
void on_rbL4Igmp_toggled(bool checked);
void on_rbL4Tcp_toggled(bool checked);
void on_rbL4Udp_toggled(bool checked);
void on_twTopLevel_currentChanged(int index); void on_twTopLevel_currentChanged(int index);
void on_twProto_currentChanged(int index); void on_twProto_currentChanged(int index);

View File

@ -59,7 +59,7 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
<item row="0" column="2" > <item row="0" column="2" >
<widget class="QGroupBox" name="gbFrameLength" > <widget class="QGroupBox" name="gbFrameLength" >
<property name="title" > <property name="title" >
<string>Frame Length (including CRC)</string> <string>Frame Length (including FCS)</string>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout" >
<item row="0" column="0" > <item row="0" column="0" >
@ -159,164 +159,60 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
</attribute> </attribute>
<layout class="QGridLayout" > <layout class="QGridLayout" >
<item rowspan="2" row="0" column="0" > <item rowspan="2" row="0" column="0" >
<widget class="QGroupBox" name="groupBox_4" > <widget class="QGroupBox" name="gbFrameType" >
<property name="title" > <property name="title" >
<string>Frame Type</string> <string>Frame Type</string>
</property> </property>
<layout class="QHBoxLayout" > <layout class="QVBoxLayout" >
<item> <item>
<layout class="QHBoxLayout" > <widget class="QRadioButton" name="rbFtNone" >
<item> <property name="text" >
<layout class="QVBoxLayout" > <string>None</string>
<item> </property>
<widget class="QRadioButton" name="rbFtNone" > <property name="checked" >
<property name="text" > <bool>true</bool>
<string>None</string> </property>
</property> </widget>
<property name="checked" > </item>
<bool>true</bool> <item>
</property> <widget class="QRadioButton" name="rbFtEthernet2" >
</widget> <property name="text" >
</item> <string>Ethernet II</string>
<item> </property>
<widget class="QRadioButton" name="rbFtEthernet2" > <property name="checked" >
<property name="text" > <bool>false</bool>
<string>Ethernet II</string> </property>
</property> </widget>
<property name="checked" > </item>
<bool>false</bool> <item>
</property> <widget class="QRadioButton" name="rbFt802Dot3Raw" >
</widget> <property name="text" >
</item> <string>802.3 Raw</string>
<item> </property>
<widget class="QRadioButton" name="rbFt802Dot3Raw" > </widget>
<property name="text" > </item>
<string>802.3 Raw</string> <item>
</property> <widget class="QRadioButton" name="rbFt802Dot3Llc" >
</widget> <property name="text" >
</item> <string>802.3 LLC</string>
<item> </property>
<widget class="QRadioButton" name="rbFt802Dot3Llc" > <property name="checked" >
<property name="text" > <bool>false</bool>
<string>802.3 LLC</string> </property>
</property> </widget>
<property name="checked" > </item>
<bool>false</bool> <item>
</property> <widget class="QRadioButton" name="rbFtLlcSnap" >
</widget> <property name="text" >
</item> <string>LLC SNAP</string>
<item> </property>
<widget class="QRadioButton" name="rbFtLlcSnap" > </widget>
<property name="text" >
<string>LLC SNAP</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="lblDsap" >
<property name="text" >
<string>DSAP</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLineEdit" name="leDsap" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="inputMask" >
<string>HH; </string>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="lblSsap" >
<property name="text" >
<string>SSAP</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="leSsap" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="inputMask" >
<string>HH; </string>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="lblControl" >
<property name="text" >
<string>Control</string>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QLineEdit" name="leControl" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="inputMask" >
<string>HH; </string>
</property>
</widget>
</item>
<item row="3" column="0" >
<widget class="QLabel" name="lblOui" >
<property name="text" >
<string>OUI</string>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QLineEdit" name="leOui" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="inputMask" >
<string>HH HH HH; </string>
</property>
</widget>
</item>
<item row="4" column="0" >
<widget class="QLabel" name="lblType" >
<property name="text" >
<string>Type</string>
</property>
</widget>
</item>
<item row="4" column="1" >
<widget class="QLineEdit" name="leType" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="inputMask" >
<string>HH HH; </string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="1" > <item row="0" column="1" >
<widget class="QGroupBox" name="groupBox_8" > <widget class="QGroupBox" name="gbL3Proto" >
<property name="title" > <property name="title" >
<string>L3</string> <string>L3</string>
</property> </property>
@ -358,7 +254,7 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
</widget> </widget>
</item> </item>
<item row="1" column="1" > <item row="1" column="1" >
<widget class="QGroupBox" name="groupBox_9" > <widget class="QGroupBox" name="gbL4Proto" >
<property name="title" > <property name="title" >
<string>L4</string> <string>L4</string>
</property> </property>
@ -416,7 +312,7 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="2" column="0" > <item row="2" column="1" >
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>

View File

@ -1,3 +1,4 @@
#include <qendian.h>
#include "abstractprotocol.h" #include "abstractprotocol.h"
/*! /*!
@ -18,19 +19,30 @@
- metaFieldCount() - metaFieldCount()
- isMetaField() - isMetaField()
*/ */
AbstractProtocol::AbstractProtocol(Stream *parent) AbstractProtocol::AbstractProtocol(
ProtocolList &frameProtoList,
OstProto::StreamCore *parent)
: frameProtocols(frameProtoList)
{ {
qDebug("%s: &frameproto = %p/%p (sz:%d)", __FUNCTION__, &frameProtocols, &frameProtoList, frameProtocols.size());
stream = parent; stream = parent;
metaCount = -1; metaCount = -1;
protoSize = -1;
} }
AbstractProtocol::~AbstractProtocol() AbstractProtocol::~AbstractProtocol()
{ {
} }
AbstractProtocol* AbstractProtocol::createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{
return NULL;
}
/*! /*!
\fn virtual void protoDataCopyInto(OstProto::Stream &stream) = 0; \fn virtual void protoDataCopyInto(OstProto::OstProto::StreamCore &stream) = 0;
Copy the protocol's protobuf into the passed in stream \n Copy the protocol's protobuf into the passed in stream \n
In the base class this is a pure virtual function. Subclasses should In the base class this is a pure virtual function. Subclasses should
@ -38,7 +50,7 @@ AbstractProtocol::~AbstractProtocol()
stream.AddExtension(<ExtId>)->CopyFrom(<protobuf_data>) */ stream.AddExtension(<ExtId>)->CopyFrom(<protobuf_data>) */
/* /*
\fn virtual void protoDataCopyFrom(const OstProto::Stream &stream) = 0; \fn virtual void protoDataCopyFrom(const OstProto::OstProto::StreamCore &stream) = 0;
FIXME */ FIXME */
/*! Returns the full name of the protocol \n /*! Returns the full name of the protocol \n
@ -114,6 +126,11 @@ int AbstractProtocol::frameFieldCount() const
the field's value e.g. a checksum field may include "(correct)" or the field's value e.g. a checksum field may include "(correct)" or
"(incorrect)" alongwith the actual checksum value. \n "(incorrect)" alongwith the actual checksum value. \n
The default implementation returns FIXME The default implementation returns FIXME
\note If a subclass uses any of the below functions to derive
FieldFrameValue, the subclass should handle and return a value for
FieldBitSize to prevent endless recrusion -
- protocolFrameCksum()
*/ */
QVariant AbstractProtocol::fieldData(int index, FieldAttrib attrib, QVariant AbstractProtocol::fieldData(int index, FieldAttrib attrib,
int streamIndex) const int streamIndex) const
@ -151,6 +168,81 @@ bool AbstractProtocol::setFieldData(int index, const QVariant &value,
return false; return false;
} }
quint32 AbstractProtocol::protocolId(ProtocolIdType type) const
{
return 0;
}
quint32 AbstractProtocol::payloadProtocolId(ProtocolIdType type) const
{
quint32 id = 0xFFFFFFFF;
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols);
if (iter.findNext(this))
{
if (iter.hasNext())
id = iter.next()->protocolId(type);
}
qDebug("%s: payloadProtocolId = %u", __FUNCTION__, id);
return id;
}
int AbstractProtocol::protocolFrameSize() const
{
if (protoSize < 0)
{
int bitsize = 0;
for (int i = 0; i < fieldCount(); i++)
{
if (!fieldData(i, FieldIsMeta).toBool())
bitsize += fieldData(i, FieldBitSize).toUInt();
}
protoSize = (bitsize+7)/8;
}
qDebug("%s: protoSize = %d", __FUNCTION__, protoSize);
return protoSize;
}
int AbstractProtocol::protocolFrameOffset() const
{
int size = 0;
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols);
if (iter.findNext(this))
{
iter.previous();
while (iter.hasPrevious())
size += iter.previous()->protocolFrameSize();
}
else
return -1;
qDebug("%s: ofs = %d", __FUNCTION__, size);
return size;
}
int AbstractProtocol::protocolFramePayloadSize() const
{
int size = 0;
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols);
if (iter.findNext(this))
{
while (iter.hasNext())
size += iter.next()->protocolFrameSize();
}
else
return -1;
qDebug("%s: payloadSize = %d", __FUNCTION__, size);
return size;
}
/*! Returns a byte array encoding the protocol (and its fields) which can be /*! Returns a byte array encoding the protocol (and its fields) which can be
inserted into the stream's frame inserted into the stream's frame
The default implementation forms and returns an ordered concatenation of The default implementation forms and returns an ordered concatenation of
@ -223,3 +315,53 @@ QByteArray AbstractProtocol::protocolFrameValue(int streamIndex) const
return proto; return proto;
} }
QVariant AbstractProtocol::protocolFrameCksum() const
{
QByteArray fv;
quint16 *ip;
quint32 len, sum = 0;
fv = protocolFrameValue(-1);
ip = (quint16*) fv.constData();
len = fv.size();
while(len > 1)
{
sum += *ip;
if(sum & 0x80000000)
sum = (sum & 0xFFFF) + (sum >> 16);
ip++;
len -= 2;
}
if (len)
sum += (unsigned short) *(unsigned char *)ip;
while(sum>>16)
sum = (sum & 0xFFFF) + (sum >> 16);
return qFromBigEndian((quint16) ~sum);
}
QVariant AbstractProtocol::protocolFramePayloadCksum() const
{
int cksum = 0;
QLinkedListIterator<const AbstractProtocol*> iter(frameProtocols);
if (iter.findNext(this))
{
while (iter.hasNext())
cksum += iter.next()->protocolFrameCksum().toUInt(); // TODO: chg to partial
}
else
return -1;
#if 0
while(cksum>>16)
cksum = (cksum & 0xFFFF) + (cksum >> 16);
return (quint16) ~cksum;
#endif
return cksum;
}

View File

@ -5,7 +5,9 @@
#include <QVariant> #include <QVariant>
#include <QByteArray> #include <QByteArray>
#include <QWidget> #include <QWidget>
#include <QLinkedList>
//#include "../rpc/pbhelper.h"
#include "../common/protocol.pb.h" #include "../common/protocol.pb.h"
#define BASE_BIN (2) #define BASE_BIN (2)
@ -13,16 +15,24 @@
#define BASE_DEC (10) #define BASE_DEC (10)
#define BASE_HEX (16) #define BASE_HEX (16)
class Stream; #define uintToHexStr(num, bytes) \
QString("%1").arg(num, bytes*2, BASE_HEX, QChar('0'))
class OstProto::StreamCore;
class AbstractProtocol;
typedef QLinkedList<const AbstractProtocol*> ProtocolList;
class AbstractProtocol class AbstractProtocol
{ {
private: private:
mutable int metaCount; mutable int metaCount;
mutable int protoSize;
mutable QString protoAbbr; mutable QString protoAbbr;
protected: protected:
Stream *stream; OstProto::StreamCore *stream;
ProtocolList &frameProtocols;
public: public:
enum FieldAttrib { enum FieldAttrib {
@ -34,15 +44,29 @@ public:
FieldIsMeta //! bool indicating if field is meta FieldIsMeta //! bool indicating if field is meta
}; };
AbstractProtocol(Stream *parent = 0); enum ProtocolIdType {
ProtocolIdLlc,
ProtocolIdEth,
ProtocolIdIp,
};
AbstractProtocol(ProtocolList &frameProtoList,
OstProto::StreamCore *parent = 0);
virtual ~AbstractProtocol(); virtual ~AbstractProtocol();
static AbstractProtocol* createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream) = 0; virtual void protoDataCopyInto(OstProto::Stream &stream) = 0;
virtual void protoDataCopyFrom(const OstProto::Stream &stream) = 0; virtual void protoDataCopyFrom(const OstProto::Stream &stream) = 0;
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;
virtual quint32 protocolId(ProtocolIdType type) const;
quint32 payloadProtocolId(ProtocolIdType type) const;
virtual int fieldCount() const; virtual int fieldCount() const;
virtual int metaFieldCount() const; virtual int metaFieldCount() const;
int frameFieldCount() const; int frameFieldCount() const;
@ -53,6 +77,12 @@ public:
FieldAttrib attrib = FieldValue); FieldAttrib attrib = FieldValue);
QByteArray protocolFrameValue(int streamIndex = 0) const; QByteArray protocolFrameValue(int streamIndex = 0) const;
int protocolFrameSize() const;
int protocolFrameOffset() const;
int protocolFramePayloadSize() const;
virtual QVariant protocolFrameCksum() const;
QVariant protocolFramePayloadCksum() const;
virtual QWidget* configWidget() = 0; virtual QWidget* configWidget() = 0;
virtual void loadConfigWidget() = 0; virtual void loadConfigWidget() = 0;

View File

@ -3,6 +3,8 @@
#include "Dot3.h" #include "Dot3.h"
#define SZ_FCS 4
Dot3ConfigForm *Dot3Protocol::configForm = NULL; Dot3ConfigForm *Dot3Protocol::configForm = NULL;
Dot3ConfigForm::Dot3ConfigForm(QWidget *parent) Dot3ConfigForm::Dot3ConfigForm(QWidget *parent)
@ -11,8 +13,10 @@ Dot3ConfigForm::Dot3ConfigForm(QWidget *parent)
setupUi(this); setupUi(this);
} }
Dot3Protocol::Dot3Protocol(Stream *parent) Dot3Protocol::Dot3Protocol(
: AbstractProtocol(parent) ProtocolList &frameProtoList,
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) if (configForm == NULL)
configForm = new Dot3ConfigForm; configForm = new Dot3ConfigForm;
@ -22,6 +26,13 @@ Dot3Protocol::~Dot3Protocol()
{ {
} }
AbstractProtocol* Dot3Protocol::createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{
return new Dot3Protocol(frameProtoList, streamCore);
}
void Dot3Protocol::protoDataCopyInto(OstProto::Stream &stream) void Dot3Protocol::protoDataCopyInto(OstProto::Stream &stream)
{ {
// FIXME: multiple headers // FIXME: multiple headers
@ -61,14 +72,27 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib,
case FieldName: case FieldName:
return QString("Length"); return QString("Length");
case FieldValue: case FieldValue:
return data.length(); {
quint16 len;
len = stream->frame_len() - SZ_FCS;
return len;
}
case FieldTextValue: case FieldTextValue:
return QString("%1").arg(data.length()); {
quint16 len;
len = stream->frame_len() - SZ_FCS;
return QString("%1").arg(len);
}
case FieldFrameValue: case FieldFrameValue:
{ {
quint16 len;
QByteArray fv; QByteArray fv;
len = stream->frame_len() - SZ_FCS;
fv.resize(2); fv.resize(2);
qToBigEndian((quint16) data.length(), (uchar*) fv.data()); qToBigEndian(len, (uchar*) fv.data());
return fv; return fv;
} }
default: default:
@ -98,7 +122,8 @@ QWidget* Dot3Protocol::configWidget()
void Dot3Protocol::loadConfigWidget() void Dot3Protocol::loadConfigWidget()
{ {
configForm->leLength->setText(QString().setNum(data.length())); configForm->leLength->setText(
fieldData(dot3_length, FieldValue).toString());
} }
void Dot3Protocol::storeConfigWidget() void Dot3Protocol::storeConfigWidget()

View File

@ -26,9 +26,14 @@ private:
}; };
public: public:
Dot3Protocol(Stream *parent = 0); Dot3Protocol(ProtocolList &frameProtoList,
OstProto::StreamCore *parent = 0);
virtual ~Dot3Protocol(); virtual ~Dot3Protocol();
static AbstractProtocol* createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Stream &stream);
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream);

View File

@ -11,8 +11,10 @@ Eth2ConfigForm::Eth2ConfigForm(QWidget *parent)
setupUi(this); setupUi(this);
} }
Eth2Protocol::Eth2Protocol(Stream *parent) Eth2Protocol::Eth2Protocol(
: AbstractProtocol(parent) ProtocolList &frameProtoList,
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) if (configForm == NULL)
configForm = new Eth2ConfigForm; configForm = new Eth2ConfigForm;
@ -22,6 +24,13 @@ Eth2Protocol::~Eth2Protocol()
{ {
} }
AbstractProtocol* Eth2Protocol::createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{
return new Eth2Protocol(frameProtoList, streamCore);
}
void Eth2Protocol::protoDataCopyInto(OstProto::Stream &stream) void Eth2Protocol::protoDataCopyInto(OstProto::Stream &stream)
{ {
// FIXME: multiple headers // FIXME: multiple headers
@ -56,26 +65,31 @@ QVariant Eth2Protocol::fieldData(int index, FieldAttrib attrib,
switch (index) switch (index)
{ {
case eth2_type: case eth2_type:
{
quint16 type;
switch(attrib) switch(attrib)
{ {
case FieldName: case FieldName:
return QString("Type"); return QString("Type");
case FieldValue: case FieldValue:
return data.type(); type = payloadProtocolId(ProtocolIdEth);
return type;
case FieldTextValue: case FieldTextValue:
return QString("%1").arg(data.type(), 16); type = payloadProtocolId(ProtocolIdEth);
return QString("0x%1").arg(type, 4, BASE_HEX, QChar('0'));
case FieldFrameValue: case FieldFrameValue:
{ {
QByteArray fv; QByteArray fv;
type = payloadProtocolId(ProtocolIdEth);
fv.resize(2); fv.resize(2);
qToBigEndian((quint16) data.type(), (uchar*) fv.data()); qToBigEndian((quint16) type, (uchar*) fv.data());
return fv; return fv;
} }
default: default:
break; break;
} }
break; break;
}
default: default:
break; break;
} }
@ -112,12 +126,8 @@ QWidget* Eth2Protocol::configWidget()
void Eth2Protocol::loadConfigWidget() void Eth2Protocol::loadConfigWidget()
{ {
#define uintToHexStr(num, bytesize) \ configForm->leType->setText(uintToHexStr(
QString("%1").arg((num), (bytesize)*2 , 16, QChar('0')) fieldData(eth2_type, FieldValue).toUInt(), 2));
configForm->leType->setText(uintToHexStr(data.type(), 2));
#undef uintToHexStr
} }
void Eth2Protocol::storeConfigWidget() void Eth2Protocol::storeConfigWidget()

View File

@ -26,9 +26,14 @@ private:
}; };
public: public:
Eth2Protocol(Stream *parent = 0); Eth2Protocol(ProtocolList &frameProtoList,
OstProto::StreamCore *parent = 0);
virtual ~Eth2Protocol(); virtual ~Eth2Protocol();
static AbstractProtocol* createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Stream &stream);
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream);

View File

@ -32,10 +32,10 @@
<item> <item>
<widget class="QLineEdit" name="leType" > <widget class="QLineEdit" name="leType" >
<property name="enabled" > <property name="enabled" >
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="inputMask" > <property name="inputMask" >
<string>HH HH; </string> <string>>HH HH; </string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -44,9 +44,16 @@ void Ip4ConfigForm::on_cmbIpDstAddrMode_currentIndexChanged(int index)
} }
} }
Ip4Protocol::Ip4Protocol(Stream *parent) Ip4Protocol::Ip4Protocol(
: AbstractProtocol(parent) ProtocolList &frameProtoList,
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
#if 0
PbHelper pbh;
pbh.ForceSetSingularDefault(&data);
#endif
if (configForm == NULL) if (configForm == NULL)
configForm = new Ip4ConfigForm; configForm = new Ip4ConfigForm;
} }
@ -55,6 +62,13 @@ Ip4Protocol::~Ip4Protocol()
{ {
} }
AbstractProtocol* Ip4Protocol::createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{
return new Ip4Protocol(frameProtoList, streamCore);
}
void Ip4Protocol::protoDataCopyInto(OstProto::Stream &stream) void Ip4Protocol::protoDataCopyInto(OstProto::Stream &stream)
{ {
// FIXME: multiple headers // FIXME: multiple headers
@ -78,6 +92,19 @@ QString Ip4Protocol::shortName() const
return QString("IPv4"); return QString("IPv4");
} }
quint32 Ip4Protocol::protocolId(ProtocolIdType type) const
{
switch(type)
{
case ProtocolIdLlc: return 0x060603;
case ProtocolIdEth: return 0x0800;
case ProtocolIdIp: return 0x04;
default:break;
}
return AbstractProtocol::protocolId(type);
}
int Ip4Protocol::fieldCount() const int Ip4Protocol::fieldCount() const
{ {
return ip4_fieldCount; return ip4_fieldCount;
@ -139,25 +166,42 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
} }
break; break;
case ip4_totLen: case ip4_totLen:
{
switch(attrib) switch(attrib)
{ {
case FieldName: case FieldName:
return QString("Total Length"); return QString("Total Length");
case FieldValue: case FieldValue:
return data.totlen(); {
int totlen;
totlen = data.is_override_totlen() ? data.totlen() :
(protocolFramePayloadSize() + 20);
return totlen;
}
case FieldFrameValue: case FieldFrameValue:
{ {
QByteArray fv; QByteArray fv;
int totlen;
totlen = data.is_override_totlen() ? data.totlen() :
(protocolFramePayloadSize() + 20);
fv.resize(2); fv.resize(2);
qToBigEndian((quint16) data.totlen(), (uchar*) fv.data()); qToBigEndian((quint16) totlen, (uchar*) fv.data());
return fv; return fv;
} }
case FieldTextValue: case FieldTextValue:
return QString("%1").arg(data.totlen()); {
int totlen;
totlen = data.is_override_totlen() ? data.totlen() :
(protocolFramePayloadSize() + 20);
return QString("%1").arg(totlen);
}
case FieldBitSize:
return 16;
default: default:
break; break;
} }
break; break;
}
case ip4_id: case ip4_id:
switch(attrib) switch(attrib)
{ {
@ -244,42 +288,86 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
} }
break; break;
case ip4_proto: case ip4_proto:
{
switch(attrib) switch(attrib)
{ {
case FieldName: case FieldName:
return QString("Protocol"); return QString("Protocol");
case FieldValue: case FieldValue:
return data.proto(); {
unsigned char id = payloadProtocolId(ProtocolIdIp);
return id;
}
case FieldFrameValue: case FieldFrameValue:
return QByteArray(1, (char)data.proto()); {
unsigned char id = payloadProtocolId(ProtocolIdIp);
return QByteArray(1, (char) id);
}
case FieldTextValue: case FieldTextValue:
{
unsigned char id = payloadProtocolId(ProtocolIdIp);
return QString("0x%1"). return QString("0x%1").
arg(data.proto(), 2, BASE_HEX, QChar('0')); arg(id, 2, BASE_HEX, QChar('0'));
}
default: default:
break; break;
} }
break; break;
}
case ip4_cksum: case ip4_cksum:
{
switch(attrib) switch(attrib)
{ {
case FieldName: case FieldName:
return QString("Header Checksum"); return QString("Header Checksum");
case FieldValue: case FieldValue:
return data.cksum(); {
quint16 cksum;
if (streamIndex < 0)
cksum = 0;
else if (data.is_override_cksum())
cksum = data.cksum();
else
cksum = protocolFrameCksum().toUInt();
return cksum;
}
case FieldFrameValue: case FieldFrameValue:
{ {
QByteArray fv; QByteArray fv;
quint16 cksum;
if (streamIndex < 0)
cksum = 0;
else if (data.is_override_cksum())
cksum = data.cksum();
else
cksum = protocolFrameCksum().toUInt();
fv.resize(2); fv.resize(2);
qToBigEndian((quint16) data.cksum(), (uchar*) fv.data()); qToBigEndian((quint16) cksum, (uchar*) fv.data());
return fv; return fv;
} }
case FieldTextValue: case FieldTextValue:
{
quint16 cksum;
if (streamIndex < 0)
cksum = 0;
else if (data.is_override_cksum())
cksum = data.cksum();
else
cksum = protocolFrameCksum().toUInt();
return QString("0x%1"). return QString("0x%1").
arg(data.cksum(), 4, BASE_HEX, QChar('0'));; arg(cksum, 4, BASE_HEX, QChar('0'));;
}
case FieldBitSize:
return 16;
default: default:
break; break;
} }
break; break;
}
case ip4_srcAddr: case ip4_srcAddr:
switch(attrib) switch(attrib)
{ {
@ -381,27 +469,27 @@ QWidget* Ip4Protocol::configWidget()
void Ip4Protocol::loadConfigWidget() void Ip4Protocol::loadConfigWidget()
{ {
#define uintToHexStr(num, str, size) QString().setNum(num, 16)
configForm->leIpVersion->setText(QString().setNum(data.ver_hdrlen() >> 4)); configForm->leIpVersion->setText(QString().setNum(data.ver_hdrlen() >> 4));
configForm->cbIpVersionOverride->setChecked(data.is_override_ver()); configForm->cbIpVersionOverride->setChecked(data.is_override_ver());
configForm->leIpHdrLen->setText(QString().setNum(data.ver_hdrlen() & 0x0F)); configForm->leIpHdrLen->setText(QString().setNum(data.ver_hdrlen() & 0x0F));
configForm->cbIpHdrLenOverride->setChecked(data.is_override_hdrlen()); configForm->cbIpHdrLenOverride->setChecked(data.is_override_hdrlen());
configForm->leIpTos->setText(uintToHexStr(data.tos(), QString(), 1)); configForm->leIpTos->setText(uintToHexStr(data.tos(), 1));
configForm->leIpLength->setText(fieldData(ip4_totLen, FieldValue).toString());
configForm->leIpLength->setText(QString().setNum(data.totlen()));
configForm->cbIpLengthOverride->setChecked(data.is_override_totlen()); configForm->cbIpLengthOverride->setChecked(data.is_override_totlen());
configForm->leIpId->setText(uintToHexStr(data.id(), QString(), 2)); configForm->leIpId->setText(uintToHexStr(data.id(), 2));
configForm->leIpFragOfs->setText(QString().setNum(data.frag_ofs())); configForm->leIpFragOfs->setText(QString().setNum(data.frag_ofs()));
configForm->cbIpFlagsDf->setChecked((data.flags() & IP_FLAG_DF) > 0); configForm->cbIpFlagsDf->setChecked((data.flags() & IP_FLAG_DF) > 0);
configForm->cbIpFlagsMf->setChecked((data.flags() & IP_FLAG_MF) > 0); configForm->cbIpFlagsMf->setChecked((data.flags() & IP_FLAG_MF) > 0);
configForm->leIpTtl->setText(QString().setNum(data.ttl())); configForm->leIpTtl->setText(QString().setNum(data.ttl()));
configForm->leIpProto->setText(uintToHexStr(data.proto(), QString(), 1)); configForm->leIpProto->setText(uintToHexStr(
fieldData(ip4_proto, FieldValue).toUInt(), 1));
configForm->leIpCksum->setText(uintToHexStr(data.cksum(), QString(), 2)); configForm->leIpCksum->setText(uintToHexStr(
fieldData(ip4_cksum, FieldValue).toUInt(), 2));
configForm->cbIpCksumOverride->setChecked(data.is_override_cksum()); configForm->cbIpCksumOverride->setChecked(data.is_override_cksum());
configForm->leIpSrcAddr->setText(QHostAddress(data.src_ip()).toString()); configForm->leIpSrcAddr->setText(QHostAddress(data.src_ip()).toString());

View File

@ -58,15 +58,20 @@ private:
}; };
public: public:
Ip4Protocol(Stream *parent = 0); Ip4Protocol(ProtocolList &frameProtoList,
OstProto::StreamCore *parent = 0);
virtual ~Ip4Protocol(); virtual ~Ip4Protocol();
static AbstractProtocol* createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Stream &stream);
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;
virtual quint32 protocolId(ProtocolIdType type) const;
virtual int fieldCount() const; virtual int fieldCount() const;
virtual QVariant fieldData(int index, FieldAttrib attrib, virtual QVariant fieldData(int index, FieldAttrib attrib,

View File

@ -28,7 +28,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text" > <property name="text" >
<string>4</string> <string/>
</property> </property>
</widget> </widget>
</item> </item>
@ -45,7 +45,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text" > <property name="text" >
<string>5</string> <string/>
</property> </property>
</widget> </widget>
</item> </item>
@ -59,7 +59,7 @@
<item row="2" column="1" > <item row="2" column="1" >
<widget class="QLineEdit" name="leIpTos" > <widget class="QLineEdit" name="leIpTos" >
<property name="inputMask" > <property name="inputMask" >
<string>HH; </string> <string>>HH; </string>
</property> </property>
<property name="text" > <property name="text" >
<string/> <string/>
@ -100,7 +100,7 @@
<item row="4" column="1" > <item row="4" column="1" >
<widget class="QLineEdit" name="leIpId" > <widget class="QLineEdit" name="leIpId" >
<property name="inputMask" > <property name="inputMask" >
<string>HH HH; </string> <string>>HH HH; </string>
</property> </property>
</widget> </widget>
</item> </item>
@ -149,7 +149,7 @@
<item row="2" column="1" > <item row="2" column="1" >
<widget class="QLineEdit" name="leIpTtl" > <widget class="QLineEdit" name="leIpTtl" >
<property name="text" > <property name="text" >
<string>64</string> <string/>
</property> </property>
</widget> </widget>
</item> </item>
@ -183,7 +183,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="inputMask" > <property name="inputMask" >
<string>HH HH; </string> <string>>HH HH; </string>
</property> </property>
</widget> </widget>
</item> </item>
@ -291,8 +291,11 @@
<property name="enabled" > <property name="enabled" >
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="inputMask" >
<string>009.009.009.009; </string>
</property>
<property name="text" > <property name="text" >
<string>255.255.255.255</string> <string>...</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -355,8 +358,11 @@
<property name="enabled" > <property name="enabled" >
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="inputMask" >
<string>009.009.009.009; </string>
</property>
<property name="text" > <property name="text" >
<string>255.255.255.255</string> <string>...</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -11,8 +11,10 @@ LlcConfigForm::LlcConfigForm(QWidget *parent)
setupUi(this); setupUi(this);
} }
LlcProtocol::LlcProtocol(Stream *parent) LlcProtocol::LlcProtocol(
: AbstractProtocol(parent) ProtocolList &frameProtoList,
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) if (configForm == NULL)
configForm = new LlcConfigForm; configForm = new LlcConfigForm;
@ -22,6 +24,13 @@ LlcProtocol::~LlcProtocol()
{ {
} }
AbstractProtocol* LlcProtocol::createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{
return new LlcProtocol(frameProtoList, streamCore);
}
void LlcProtocol::protoDataCopyInto(OstProto::Stream &stream) void LlcProtocol::protoDataCopyInto(OstProto::Stream &stream)
{ {
// FIXME: multiple headers // FIXME: multiple headers
@ -53,6 +62,14 @@ int LlcProtocol::fieldCount() const
QVariant LlcProtocol::fieldData(int index, FieldAttrib attrib, QVariant LlcProtocol::fieldData(int index, FieldAttrib attrib,
int streamIndex) const int streamIndex) const
{ {
quint32 id;
quint8 dsap, ssap, ctl;
id = payloadProtocolId(ProtocolIdLlc);
dsap = (id >> 16) & 0xFF;
ssap = (id >> 8) & 0xFF;
ctl = (id >> 0) & 0xFF;
switch (index) switch (index)
{ {
case llc_dsap: case llc_dsap:
@ -61,11 +78,11 @@ QVariant LlcProtocol::fieldData(int index, FieldAttrib attrib,
case FieldName: case FieldName:
return QString("DSAP"); return QString("DSAP");
case FieldValue: case FieldValue:
return data.dsap(); return dsap;
case FieldTextValue: case FieldTextValue:
return QString("%1").arg(data.dsap(), BASE_HEX); return QString("%1").arg(dsap, 2, BASE_HEX, QChar('0'));
case FieldFrameValue: case FieldFrameValue:
return QByteArray(1, (char)(data.dsap())); return QByteArray(1, (char)(dsap));
default: default:
break; break;
} }
@ -74,13 +91,13 @@ QVariant LlcProtocol::fieldData(int index, FieldAttrib attrib,
switch(attrib) switch(attrib)
{ {
case FieldName: case FieldName:
return QString("DSAP"); return QString("SSAP");
case FieldValue: case FieldValue:
return data.ssap(); return ssap;
case FieldTextValue: case FieldTextValue:
return QString("%1").arg(data.ssap(), BASE_HEX); return QString("%1").arg(ssap, 2, BASE_HEX, QChar('0'));
case FieldFrameValue: case FieldFrameValue:
return QByteArray(1, (char)(data.ssap())); return QByteArray(1, (char)(ssap));
default: default:
break; break;
} }
@ -89,13 +106,13 @@ QVariant LlcProtocol::fieldData(int index, FieldAttrib attrib,
switch(attrib) switch(attrib)
{ {
case FieldName: case FieldName:
return QString("DSAP"); return QString("Control");
case FieldValue: case FieldValue:
return data.ctl(); return ctl;
case FieldTextValue: case FieldTextValue:
return QString("%1").arg(data.ctl(), BASE_HEX); return QString("%1").arg(ctl, 2, BASE_HEX, QChar('0'));
case FieldFrameValue: case FieldFrameValue:
return QByteArray(1, (char)(data.ctl())); return QByteArray(1, (char)(ctl));
default: default:
break; break;
} }
@ -123,9 +140,16 @@ QWidget* LlcProtocol::configWidget()
void LlcProtocol::loadConfigWidget() void LlcProtocol::loadConfigWidget()
{ {
configForm->leDsap->setText(QString("%1").arg(data.dsap(), 2, BASE_HEX, QChar('0'))); #define uintToHexStr(num, bytes) \
configForm->leSsap->setText(QString("%1").arg(data.ssap(), 2, BASE_HEX, QChar('0'))); QString("%1").arg(num, bytes*2, BASE_HEX, QChar('0'))
configForm->leControl->setText(QString("%1").arg(data.ctl(), 2, BASE_HEX, QChar('0')));
configForm->leDsap->setText(uintToHexStr(
fieldData(llc_dsap, FieldValue).toUInt(), 1));
configForm->leSsap->setText(uintToHexStr(
fieldData(llc_ssap, FieldValue).toUInt(), 1));
configForm->leControl->setText(uintToHexStr(
fieldData(llc_ctl, FieldValue).toUInt(), 1));
#undef uintToHexStr
} }
void LlcProtocol::storeConfigWidget() void LlcProtocol::storeConfigWidget()

View File

@ -31,9 +31,14 @@ private:
}; };
public: public:
LlcProtocol(Stream *parent = 0); LlcProtocol(ProtocolList &frameProtoList,
OstProto::StreamCore *parent = 0);
virtual ~LlcProtocol(); virtual ~LlcProtocol();
static AbstractProtocol* createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Stream &stream);
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream);

View File

@ -38,10 +38,10 @@
<item> <item>
<widget class="QLineEdit" name="leDsap" > <widget class="QLineEdit" name="leDsap" >
<property name="enabled" > <property name="enabled" >
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="inputMask" > <property name="inputMask" >
<string>HH; </string> <string>>HH; </string>
</property> </property>
</widget> </widget>
</item> </item>
@ -58,10 +58,10 @@
<item> <item>
<widget class="QLineEdit" name="leSsap" > <widget class="QLineEdit" name="leSsap" >
<property name="enabled" > <property name="enabled" >
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="inputMask" > <property name="inputMask" >
<string>HH; </string> <string>>HH; </string>
</property> </property>
</widget> </widget>
</item> </item>
@ -78,10 +78,10 @@
<item> <item>
<widget class="QLineEdit" name="leControl" > <widget class="QLineEdit" name="leControl" >
<property name="enabled" > <property name="enabled" >
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="inputMask" > <property name="inputMask" >
<string>HH; </string> <string>>HH; </string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -46,8 +46,10 @@ void MacConfigForm::on_cmbSrcMacMode_currentIndexChanged(int index)
} }
MacProtocol::MacProtocol(Stream *parent) MacProtocol::MacProtocol(
: AbstractProtocol(parent) ProtocolList &frameProtoList,
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) if (configForm == NULL)
configForm = new MacConfigForm; configForm = new MacConfigForm;
@ -57,6 +59,13 @@ MacProtocol::~MacProtocol()
{ {
} }
AbstractProtocol* MacProtocol::createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{
return new MacProtocol(frameProtoList, streamCore);
}
void MacProtocol::protoDataCopyInto(OstProto::Stream &stream) void MacProtocol::protoDataCopyInto(OstProto::Stream &stream)
{ {
// FIXME: multiple headers // FIXME: multiple headers
@ -174,13 +183,12 @@ QWidget* MacProtocol::configWidget()
void MacProtocol::loadConfigWidget() void MacProtocol::loadConfigWidget()
{ {
#define uintToHexStr(num, str, size) QString().setNum(num, 16) configForm->leDstMac->setText(uintToHexStr(data.dst_mac(), 6));
configForm->leDstMac->setText(uintToHexStr(data.dst_mac(), str, 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()));
configForm->leDstMacStep->setText(QString().setNum(data.dst_mac_step())); configForm->leDstMacStep->setText(QString().setNum(data.dst_mac_step()));
configForm->leSrcMac->setText(uintToHexStr(data.src_mac(), QString(), 6)); configForm->leSrcMac->setText(uintToHexStr(data.src_mac(), 6));
configForm->cmbSrcMacMode->setCurrentIndex(data.src_mac_mode()); configForm->cmbSrcMacMode->setCurrentIndex(data.src_mac_mode());
configForm->leSrcMacCount->setText(QString().setNum(data.src_mac_count())); configForm->leSrcMacCount->setText(QString().setNum(data.src_mac_count()));
configForm->leSrcMacStep->setText(QString().setNum(data.src_mac_step())); configForm->leSrcMacStep->setText(QString().setNum(data.src_mac_step()));

View File

@ -39,9 +39,14 @@ private:
}; };
public: public:
MacProtocol(Stream *parent = 0); MacProtocol(ProtocolList &frameProtoList,
OstProto::StreamCore *parent = 0);
virtual ~MacProtocol(); virtual ~MacProtocol();
static AbstractProtocol* createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Stream &stream);
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream);

View File

@ -49,7 +49,7 @@
</size> </size>
</property> </property>
<property name="inputMask" > <property name="inputMask" >
<string>HH HH HH HH HH HH; </string> <string>>HH HH HH HH HH HH; </string>
</property> </property>
<property name="text" > <property name="text" >
<string> </string> <string> </string>
@ -111,7 +111,7 @@
<item row="2" column="1" > <item row="2" column="1" >
<widget class="QLineEdit" name="leSrcMac" > <widget class="QLineEdit" name="leSrcMac" >
<property name="inputMask" > <property name="inputMask" >
<string>HH HH HH HH HH HH; </string> <string>>HH HH HH HH HH HH; </string>
</property> </property>
<property name="text" > <property name="text" >
<string> </string> <string> </string>

View File

@ -26,6 +26,9 @@ PROTOS += \
udp.proto udp.proto
HEADERS += \ HEADERS += \
abstractprotocol.h \ abstractprotocol.h \
protocolmanager.h \
protocolcollection.h \
streambase.h \
mac.h \ mac.h \
payload.h \ payload.h \
eth2.h \ eth2.h \
@ -37,6 +40,9 @@ HEADERS += \
udp.h udp.h
SOURCES += \ SOURCES += \
abstractprotocol.cpp \ abstractprotocol.cpp \
protocolmanager.cpp \
protocolcollection.cpp \
streambase.cpp \
mac.cpp \ mac.cpp \
payload.cpp \ payload.cpp \
eth2.cpp \ eth2.cpp \

View File

@ -1,9 +1,11 @@
#include <qendian.h> #include <qendian.h>
#include <QHostAddress> #include <QHostAddress>
#include "../client/stream.h" //#include "../client/stream.h"
#include "payload.h" #include "payload.h"
#define SZ_FCS 4
PayloadConfigForm *PayloadProtocol::configForm = NULL; PayloadConfigForm *PayloadProtocol::configForm = NULL;
PayloadConfigForm::PayloadConfigForm(QWidget *parent) PayloadConfigForm::PayloadConfigForm(QWidget *parent)
@ -29,8 +31,10 @@ void PayloadConfigForm::on_cmbPatternMode_currentIndexChanged(int index)
} }
} }
PayloadProtocol::PayloadProtocol(Stream *parent) PayloadProtocol::PayloadProtocol(
: AbstractProtocol(parent) ProtocolList &frameProtoList,
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) if (configForm == NULL)
configForm = new PayloadConfigForm; configForm = new PayloadConfigForm;
@ -40,6 +44,13 @@ PayloadProtocol::~PayloadProtocol()
{ {
} }
AbstractProtocol* PayloadProtocol::createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{
return new PayloadProtocol(frameProtoList, streamCore);
}
void PayloadProtocol::protoDataCopyInto(OstProto::Stream &stream) void PayloadProtocol::protoDataCopyInto(OstProto::Stream &stream)
{ {
// FIXME: multiple headers // FIXME: multiple headers
@ -88,10 +99,8 @@ QVariant PayloadProtocol::fieldData(int index, FieldAttrib attrib,
QByteArray fv; QByteArray fv;
int dataLen; int dataLen;
// FIXME: cannot use stream since it is only on client not dataLen = stream->frame_len() - protocolFrameOffset();
// on server dataLen -= SZ_FCS;
//dataLen = stream->frameLen() - stream->protocolHeaderSize();
dataLen = 64;
fv.resize(dataLen+4); fv.resize(dataLen+4);
switch(data.pattern_mode()) switch(data.pattern_mode())
{ {
@ -159,10 +168,8 @@ QWidget* PayloadProtocol::configWidget()
void PayloadProtocol::loadConfigWidget() void PayloadProtocol::loadConfigWidget()
{ {
#define uintToHexStr(num, str, size) QString().setNum(num, 16)
configForm->cmbPatternMode->setCurrentIndex(data.pattern_mode()); configForm->cmbPatternMode->setCurrentIndex(data.pattern_mode());
configForm->lePattern->setText(uintToHexStr(data.pattern(), QString(), 4)); configForm->lePattern->setText(uintToHexStr(data.pattern(), 4));
} }
void PayloadProtocol::storeConfigWidget() void PayloadProtocol::storeConfigWidget()

View File

@ -31,9 +31,14 @@ private:
}; };
public: public:
PayloadProtocol(Stream *parent = 0); PayloadProtocol(ProtocolList &frameProtoList,
OstProto::StreamCore *parent = 0);
virtual ~PayloadProtocol(); virtual ~PayloadProtocol();
static AbstractProtocol* createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Stream &stream);
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream);

View File

@ -46,7 +46,7 @@
<item> <item>
<widget class="QLineEdit" name="lePattern" > <widget class="QLineEdit" name="lePattern" >
<property name="inputMask" > <property name="inputMask" >
<string>HH HH HH HH; </string> <string>>HH HH HH HH; </string>
</property> </property>
<property name="text" > <property name="text" >
<string> </string> <string> </string>

View File

@ -0,0 +1,106 @@
#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

@ -0,0 +1,30 @@
#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

View File

@ -0,0 +1,38 @@
#include "protocolmanager.h"
#include "mac.h"
#include "payload.h"
#include "eth2.h"
#include "dot3.h"
#include "llc.h"
#include "snap.h"
#include "ip4.h"
#include "tcp.h"
#include "udp.h"
QMap<int, void*> ProtocolManager::factory;
QMap<QString, int> ProtocolManager::nameToNumberMap;
ProtocolManager OstProtocolManager;
ProtocolManager::ProtocolManager()
{
registerProtocol(51, QString("mac"), (void*) MacProtocol::createInstance);
registerProtocol(52, QString("payload"), (void*) PayloadProtocol::createInstance);
registerProtocol(121, QString("eth2"), (void*) Eth2Protocol::createInstance);
registerProtocol(122, QString("dot3"), (void*) Dot3Protocol::createInstance);
registerProtocol(123, QString("llc"), (void*) LlcProtocol::createInstance);
registerProtocol(124, QString("snap"), (void*) SnapProtocol::createInstance);
registerProtocol(130, QString("ip4"), (void*) Ip4Protocol::createInstance);
registerProtocol(140, QString("tcp"), (void*) TcpProtocol::createInstance);
registerProtocol(141, QString("udp"), (void*) UdpProtocol::createInstance);
}
void ProtocolManager::registerProtocol(int protoNumber, QString protoName,
void *protoInstanceCreator)
{
// TODO: validate incoming params for duplicates with existing
nameToNumberMap.insert(protoName, protoNumber);
factory.insert(protoNumber, protoInstanceCreator);
}

18
common/protocolmanager.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef _PROTOCOL_MANAGER_H
#define _PROTOCOL_MANAGER_H
#include <QMap>
class ProtocolManager
{
public:
static QMap<QString, int> nameToNumberMap;
static QMap<int, void*> factory;
public:
ProtocolManager();
void registerProtocol(int protoNumber, QString protoName,
void *protoCreator);
};
#endif

View File

@ -11,8 +11,10 @@ SnapConfigForm::SnapConfigForm(QWidget *parent)
setupUi(this); setupUi(this);
} }
SnapProtocol::SnapProtocol(Stream *parent) SnapProtocol::SnapProtocol(
: AbstractProtocol(parent) ProtocolList &frameProtoList,
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) if (configForm == NULL)
configForm = new SnapConfigForm; configForm = new SnapConfigForm;
@ -22,6 +24,13 @@ SnapProtocol::~SnapProtocol()
{ {
} }
AbstractProtocol* SnapProtocol::createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{
return new SnapProtocol(frameProtoList, streamCore);
}
void SnapProtocol::protoDataCopyInto(OstProto::Stream &stream) void SnapProtocol::protoDataCopyInto(OstProto::Stream &stream)
{ {
// FIXME: multiple headers // FIXME: multiple headers
@ -45,6 +54,17 @@ QString SnapProtocol::shortName() const
return QString("SNAP"); return QString("SNAP");
} }
quint32 SnapProtocol::protocolId(ProtocolIdType type) const
{
switch(type)
{
case ProtocolIdLlc: return 0xAAAA03;
default: break;
}
return AbstractProtocol::protocolId(type);
}
int SnapProtocol::fieldCount() const int SnapProtocol::fieldCount() const
{ {
return snap_fieldCount; return snap_fieldCount;
@ -76,7 +96,33 @@ QVariant SnapProtocol::fieldData(int index, FieldAttrib attrib,
break; break;
} }
break; break;
case snap_type:
{
quint16 type;
switch(attrib)
{
case FieldName:
return QString("Type");
case FieldValue:
type = payloadProtocolId(ProtocolIdEth);
return type;
case FieldTextValue:
type = payloadProtocolId(ProtocolIdEth);
return QString("%1").arg(type, 4, BASE_HEX, QChar('0'));
case FieldFrameValue:
{
QByteArray fv;
fv.resize(2);
type = payloadProtocolId(ProtocolIdEth);
qToBigEndian(type, (uchar*) fv.data());
return fv;
}
default:
break;
}
break;
}
default: default:
break; break;
} }
@ -99,14 +145,17 @@ QWidget* SnapProtocol::configWidget()
void SnapProtocol::loadConfigWidget() void SnapProtocol::loadConfigWidget()
{ {
#define uintToHexStr(num, str, size) QString().setNum(num, 16) configForm->leOui->setText(uintToHexStr(
configForm->leOui->setText(uintToHexStr(data.oui(), str, 3)); fieldData(snap_oui, FieldValue).toUInt(), 3));
configForm->leType->setText(uintToHexStr(
fieldData(snap_type, FieldValue).toUInt(), 2));
} }
void SnapProtocol::storeConfigWidget() void SnapProtocol::storeConfigWidget()
{ {
bool isOk; bool isOk;
data.set_oui(configForm->leOui->text().remove(QChar(' ')).toULong(&isOk, 16)); data.set_oui(configForm->leOui->text().toULong(&isOk, BASE_HEX));
data.set_type(configForm->leType->text().toULong(&isOk, BASE_HEX));
} }

View File

@ -21,19 +21,26 @@ private:
enum snapfield enum snapfield
{ {
snap_oui = 0, snap_oui = 0,
snap_type,
snap_fieldCount snap_fieldCount
}; };
public: public:
SnapProtocol(Stream *parent = 0); SnapProtocol(ProtocolList &frameProtoList,
OstProto::StreamCore *parent = 0);
virtual ~SnapProtocol(); virtual ~SnapProtocol();
static AbstractProtocol* createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Stream &stream);
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;
virtual quint32 protocolId(ProtocolIdType type) const;
virtual int fieldCount() const; virtual int fieldCount() const;

View File

@ -4,7 +4,7 @@ package OstProto;
message Snap { message Snap {
optional uint32 oui = 1; optional uint32 oui = 1;
//optional uint32 type = 2; optional uint32 type = 2;
} }
extend Stream { extend Stream {

View File

@ -29,10 +29,10 @@
<item> <item>
<widget class="QLineEdit" name="leOui" > <widget class="QLineEdit" name="leOui" >
<property name="enabled" > <property name="enabled" >
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="inputMask" > <property name="inputMask" >
<string>HH HH HH; </string> <string>>HH HH HH; </string>
</property> </property>
</widget> </widget>
</item> </item>
@ -46,10 +46,10 @@
<item> <item>
<widget class="QLineEdit" name="leType" > <widget class="QLineEdit" name="leType" >
<property name="enabled" > <property name="enabled" >
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="inputMask" > <property name="inputMask" >
<string>HH HH; </string> <string>>HH HH; </string>
</property> </property>
</widget> </widget>
</item> </item>

69
common/streambase.cpp Normal file
View File

@ -0,0 +1,69 @@
#include "streambase.h"
StreamBase::StreamBase() :
mStreamId(new OstProto::StreamId),
mCore(new OstProto::StreamCore),
mControl(new OstProto::StreamControl),
protocols(currentFrameProtocols, mCore)
{
mStreamId->set_id(0xFFFFFFFF);
}
StreamBase::~StreamBase()
{
delete mStreamId;
delete mCore;
delete mControl;
}
void StreamBase::protoDataCopyFrom(const OstProto::Stream &stream)
{
mStreamId->CopyFrom(stream.stream_id());
mCore->CopyFrom(stream.core());
mControl->CopyFrom(stream.control());
protocols.protoDataCopyFrom(stream);
setFrameProtocol(frameProtocol());
}
void StreamBase::protoDataCopyInto(OstProto::Stream &stream) const
{
stream.mutable_stream_id()->CopyFrom(*mStreamId);
stream.mutable_core()->CopyFrom(*mCore);
stream.mutable_control()->CopyFrom(*mControl);
protocols.protoDataCopyInto(stream);
}
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));
currentFrameProtocols.append(protocols.protocol(protocolList.at(i)));
}
}
AbstractProtocol* StreamBase::protocol(int protoNum)
{
return protocols.protocol(protoNum);
}
AbstractProtocol* StreamBase::protocol(QString protoName)
{
return protocols.protocol(protoName);
}

36
common/streambase.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef _STREAM_BASE_H
#define _STREAM_BASE_H
#include <QList>
#include "protocolcollection.h"
class StreamBase
{
protected: // TODO: temp - make private
OstProto::StreamId *mStreamId;
OstProto::StreamCore *mCore;
OstProto::StreamControl *mControl;
private:
ProtocolList currentFrameProtocols;
protected:
ProtocolCollection protocols;
public:
StreamBase();
~StreamBase();
void protoDataCopyFrom(const OstProto::Stream &stream);
void protoDataCopyInto(OstProto::Stream &stream) const;
QList<int> frameProtocol();
void setFrameProtocol(QList<int> protocolList);
AbstractProtocol* protocol(int protoNum);
AbstractProtocol* protocol(QString protoName);
// TODO: make a copy constructor
};
#endif

View File

@ -11,8 +11,10 @@ TcpConfigForm::TcpConfigForm(QWidget *parent)
setupUi(this); setupUi(this);
} }
TcpProtocol::TcpProtocol(Stream *parent) TcpProtocol::TcpProtocol(
: AbstractProtocol(parent) ProtocolList &frameProtoList,
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) if (configForm == NULL)
configForm = new TcpConfigForm; configForm = new TcpConfigForm;
@ -22,6 +24,13 @@ TcpProtocol::~TcpProtocol()
{ {
} }
AbstractProtocol* TcpProtocol::createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{
return new TcpProtocol(frameProtoList, streamCore);
}
void TcpProtocol::protoDataCopyInto(OstProto::Stream &stream) void TcpProtocol::protoDataCopyInto(OstProto::Stream &stream)
{ {
// FIXME: multiple headers // FIXME: multiple headers
@ -45,6 +54,17 @@ QString TcpProtocol::shortName() const
return QString("TCP"); return QString("TCP");
} }
quint32 TcpProtocol::protocolId(ProtocolIdType type) const
{
switch(type)
{
case ProtocolIdIp: return 0x06;
default: break;
}
return AbstractProtocol::protocolId(type);
}
int TcpProtocol::fieldCount() const int TcpProtocol::fieldCount() const
{ {
return tcp_fieldCount; return tcp_fieldCount;
@ -149,7 +169,7 @@ QVariant TcpProtocol::fieldData(int index, FieldAttrib attrib,
case FieldTextValue: case FieldTextValue:
return QString("%1").arg((data.hdrlen_rsvd() >> 4) & 0x0F); return QString("%1").arg((data.hdrlen_rsvd() >> 4) & 0x0F);
case FieldFrameValue: case FieldFrameValue:
return QByteArray(1, (char)((data.hdrlen_rsvd() >> 4) & 0x0F)); return QByteArray(1, (char)(data.hdrlen_rsvd() & 0xF0));
case FieldBitSize: case FieldBitSize:
return 4; return 4;
default: default:
@ -303,7 +323,6 @@ QWidget* TcpProtocol::configWidget()
void TcpProtocol::loadConfigWidget() void TcpProtocol::loadConfigWidget()
{ {
#define uintToHexStr(num, str, size) QString().setNum(num, 16)
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()));

View File

@ -45,14 +45,20 @@ private:
}; };
public: public:
TcpProtocol(Stream *parent = 0); TcpProtocol(ProtocolList &frameProtoList,
OstProto::StreamCore *parent = 0);
virtual ~TcpProtocol(); virtual ~TcpProtocol();
static AbstractProtocol* createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Stream &stream);
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;
virtual quint32 protocolId(ProtocolIdType type) const;
virtual int fieldCount() const; virtual int fieldCount() const;

View File

@ -43,7 +43,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="inputMask" > <property name="inputMask" >
<string>HH HH; </string> <string>>HH HH; </string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -11,8 +11,10 @@ UdpConfigForm::UdpConfigForm(QWidget *parent)
setupUi(this); setupUi(this);
} }
UdpProtocol::UdpProtocol(Stream *parent) UdpProtocol::UdpProtocol(
: AbstractProtocol(parent) ProtocolList &frameProtoList,
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{ {
if (configForm == NULL) if (configForm == NULL)
configForm = new UdpConfigForm; configForm = new UdpConfigForm;
@ -22,6 +24,13 @@ UdpProtocol::~UdpProtocol()
{ {
} }
AbstractProtocol* UdpProtocol::createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{
return new UdpProtocol(frameProtoList, streamCore);
}
void UdpProtocol::protoDataCopyInto(OstProto::Stream &stream) void UdpProtocol::protoDataCopyInto(OstProto::Stream &stream)
{ {
// FIXME: multiple headers // FIXME: multiple headers
@ -45,6 +54,17 @@ QString UdpProtocol::shortName() const
return QString("UDP"); return QString("UDP");
} }
quint32 UdpProtocol::protocolId(ProtocolIdType type) const
{
switch(type)
{
case ProtocolIdIp: return 0x11;
default: break;
}
return AbstractProtocol::protocolId(type);
}
int UdpProtocol::fieldCount() const int UdpProtocol::fieldCount() const
{ {
return udp_fieldCount; return udp_fieldCount;
@ -98,26 +118,47 @@ QVariant UdpProtocol::fieldData(int index, FieldAttrib attrib,
break; break;
case udp_totLen: case udp_totLen:
{
switch(attrib) switch(attrib)
{ {
case FieldName: case FieldName:
return QString("Datagram Length"); return QString("Datagram Length");
case FieldValue: case FieldValue:
return data.totlen(); {
case FieldTextValue: int totlen;
return QString("%1").arg(data.totlen());
totlen = data.is_override_totlen() ?
data.totlen() :
(protocolFramePayloadSize() + 8);
return totlen;
}
case FieldFrameValue: case FieldFrameValue:
{ {
QByteArray fv; QByteArray fv;
int totlen;
totlen = data.is_override_totlen() ?
data.totlen() :
(protocolFramePayloadSize() + 8);
fv.resize(2); fv.resize(2);
qToBigEndian((quint16) data.totlen(), (uchar*) fv.data()); qToBigEndian((quint16) totlen, (uchar*) fv.data());
return fv; return fv;
} }
case FieldTextValue:
{
int totlen;
totlen = data.is_override_totlen() ?
data.totlen() :
(protocolFramePayloadSize() + 8);
return QString("%1").arg(totlen);
}
case FieldBitSize:
return 16;
default: default:
break; break;
} }
break; break;
}
case udp_cksum: case udp_cksum:
switch(attrib) switch(attrib)
{ {
@ -173,7 +214,6 @@ QWidget* UdpProtocol::configWidget()
void UdpProtocol::loadConfigWidget() void UdpProtocol::loadConfigWidget()
{ {
#define uintToHexStr(num, str, size) QString().setNum(num, 16)
configForm->leUdpSrcPort->setText(QString().setNum(data.src_port())); configForm->leUdpSrcPort->setText(QString().setNum(data.src_port()));
configForm->leUdpDstPort->setText(QString().setNum(data.dst_port())); configForm->leUdpDstPort->setText(QString().setNum(data.dst_port()));

View File

@ -32,14 +32,20 @@ private:
}; };
public: public:
UdpProtocol(Stream *parent = 0); UdpProtocol(ProtocolList &frameProtoList,
OstProto::StreamCore *parent = 0);
virtual ~UdpProtocol(); virtual ~UdpProtocol();
static AbstractProtocol* createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore = 0);
virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyInto(OstProto::Stream &stream);
virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream);
virtual QString name() const; virtual QString name() const;
virtual QString shortName() const; virtual QString shortName() const;
virtual quint32 protocolId(ProtocolIdType type) const;
virtual int fieldCount() const; virtual int fieldCount() const;

View File

@ -62,7 +62,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="inputMask" > <property name="inputMask" >
<string>HH HH; </string> <string>>HH HH; </string>
</property> </property>
</widget> </widget>
</item> </item>
@ -97,5 +97,38 @@
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections>
<connection>
<sender>cbUdpLengthOverride</sender>
<signal>toggled(bool)</signal>
<receiver>leUdpLength</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>59</x>
<y>63</y>
</hint>
<hint type="destinationlabel" >
<x>149</x>
<y>63</y>
</hint>
</hints>
</connection>
<connection>
<sender>cbUdpCksumOverride</sender>
<signal>toggled(bool)</signal>
<receiver>leUdpCksum</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel" >
<x>55</x>
<y>106</y>
</hint>
<hint type="destinationlabel" >
<x>158</x>
<y>106</y>
</hint>
</hints>
</connection>
</connections>
</ui> </ui>

View File

@ -126,7 +126,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="inputMask" > <property name="inputMask" >
<string>HH HH; </string> <string>>HH HH; </string>
</property> </property>
<property name="text" > <property name="text" >
<string> </string> <string> </string>

View File

@ -4,17 +4,6 @@
#include <qglobal.h> #include <qglobal.h>
#include <qendian.h> #include <qendian.h>
#include "../common/mac.h"
#include "../common/payload.h"
#include "../common/eth2.h" // FIXME: proto DB
#include "../common/dot3.h" // FIXME: proto DB
#include "../common/llc.h" // FIXME: proto DB
#include "../common/snap.h" // FIXME: proto DB
#include "../common/ip4.h" // FIXME: proto DB
#include "../common/tcp.h" // FIXME: proto DB
#include "../common/udp.h" // FIXME: proto DB
#if 0 #if 0
#include <pcap-int.h> #include <pcap-int.h>
#include <Ntddndis.h> #include <Ntddndis.h>
@ -25,62 +14,19 @@
StreamInfo::StreamInfo() StreamInfo::StreamInfo()
{ {
#if 0
PbHelper pbh; PbHelper pbh;
pbh.ForceSetSingularDefault(&mCore); pbh.ForceSetSingularDefault(mCore);
pbh.ForceSetSingularDefault(&mControl); pbh.ForceSetSingularDefault(mControl);
#endif
mProtocolList.append(new MacProtocol);
mProtocolList.append(new PayloadProtocol());
// FIXME: proto DB
mProtocolList.append(new Eth2Protocol);
mProtocolList.append(new Dot3Protocol);
mProtocolList.append(new LlcProtocol);
mProtocolList.append(new SnapProtocol);
mProtocolList.append(new Ip4Protocol);
mProtocolList.append(new TcpProtocol);
mProtocolList.append(new UdpProtocol);
} }
StreamInfo::~StreamInfo() StreamInfo::~StreamInfo()
{ {
for (int i = 0; i < mProtocolList.size(); i++)
delete mProtocolList.at(i);
}
AbstractProtocol* StreamInfo::protocolById(int id)
{
// FIXME BAD BAD VERY BAD!
switch(id) {
case 51:
return mProtocolList.at(0);
case 52:
return mProtocolList.at(1);
case 121:
return mProtocolList.at(2);
case 122:
return mProtocolList.at(3);
case 123:
return mProtocolList.at(4);
case 124:
return mProtocolList.at(5);
// case 125 (unused)
#if 0 // todo VLAN
case 126:
return mProtocolList.at(x);
#endif
case 130:
return mProtocolList.at(6);
case 140:
return mProtocolList.at(7);
case 141:
return mProtocolList.at(8);
default:
return NULL;
}
} }
#if 0
quint32 StreamInfo::pseudoHdrCksumPartial(quint32 srcIp, quint32 dstIp, quint32 StreamInfo::pseudoHdrCksumPartial(quint32 srcIp, quint32 dstIp,
quint8 protocol, quint16 len) quint8 protocol, quint16 len)
{ {
@ -96,78 +42,34 @@ quint32 StreamInfo::pseudoHdrCksumPartial(quint32 srcIp, quint32 dstIp,
// Above calculation done assuming 'big endian' - so convert to host order // Above calculation done assuming 'big endian' - so convert to host order
return qFromBigEndian(sum); return qFromBigEndian(sum);
} }
#endif
quint32 StreamInfo::ipv4CksumPartial(uchar *buf, int len)
{
quint32 sum = 0;
quint16 *ip = (quint16*) buf;
if (len & 0x0001)
{
qFatal("Cannot calculate partial checksum on non multiple of 2 length");
return 0;
}
while(len)
{
sum += *ip;
if(sum & 0x80000000)
sum = (sum & 0xFFFF) + (sum >> 16);
ip++;
len -= 2;
}
return sum;
}
quint16 StreamInfo::ipv4Cksum(uchar *buf, int len, quint32 partialSum)
{
quint32 sum = partialSum;
quint16 *ip = (quint16*) buf;
while(len > 1)
{
sum += *ip;
if(sum & 0x80000000)
sum = (sum & 0xFFFF) + (sum >> 16);
ip++;
len -= 2;
}
if (len)
sum += (unsigned short) *(unsigned char *)ip;
while(sum>>16)
sum = (sum & 0xFFFF) + (sum >> 16);
return (quint16) ~sum;
}
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(mCore->len_mode())
{ {
case OstProto::StreamCore::e_fl_fixed: case OstProto::StreamCore::e_fl_fixed:
pktLen = mCore.frame_len(); pktLen = mCore->frame_len();
break; break;
case OstProto::StreamCore::e_fl_inc: case OstProto::StreamCore::e_fl_inc:
pktLen = mCore.frame_len_min() + (n % pktLen = mCore->frame_len_min() + (n %
(mCore.frame_len_max() - mCore.frame_len_min() + 1)); (mCore->frame_len_max() - mCore->frame_len_min() + 1));
break; break;
case OstProto::StreamCore::e_fl_dec: case OstProto::StreamCore::e_fl_dec:
pktLen = mCore.frame_len_max() - (n % pktLen = mCore->frame_len_max() - (n %
(mCore.frame_len_max() - mCore.frame_len_min() + 1)); (mCore->frame_len_max() - mCore->frame_len_min() + 1));
break; break;
case OstProto::StreamCore::e_fl_random: case OstProto::StreamCore::e_fl_random:
pktLen = mCore.frame_len_min() + (qrand() % pktLen = mCore->frame_len_min() + (qrand() %
(mCore.frame_len_max() - mCore.frame_len_min() + 1)); (mCore->frame_len_max() - mCore->frame_len_min() + 1));
break; break;
default: default:
qWarning("Unhandled len mode %d. Using default 64", qWarning("Unhandled len mode %d. Using default 64",
mCore.len_mode()); mCore->len_mode());
pktLen = 64; pktLen = 64;
break; break;
} }
@ -179,14 +81,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++)
// FIXME: checksums!!!
for (int i = 0; i < mCore.frame_proto_size(); i++)
{ {
QByteArray ba; QByteArray ba;
ba = protocolById(mCore.frame_proto(i))->protocolFrameValue(n); ba = protocol(mCore->frame_proto(i))->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());
@ -690,28 +589,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]->mCore->is_enabled())
{ {
long numPackets, numBursts; long numPackets, numBursts;
long ibg, ipg; long ibg, ipg;
switch (streamList[i]->mControl.unit()) switch (streamList[i]->mControl->unit())
{ {
case OstProto::StreamControl::e_su_bursts: case OstProto::StreamControl::e_su_bursts:
numBursts = streamList[i]->mControl.num_bursts(); numBursts = streamList[i]->mControl->num_bursts();
numPackets = streamList[i]->mControl.packets_per_burst(); numPackets = streamList[i]->mControl->packets_per_burst();
ibg = 1000000/streamList[i]->mControl.bursts_per_sec(); ibg = 1000000/streamList[i]->mControl->bursts_per_sec();
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]->mControl->num_packets();
ibg = 0; ibg = 0;
ipg = 1000000/streamList[i]->mControl.packets_per_sec(); ipg = 1000000/streamList[i]->mControl->packets_per_sec();
break; break;
default: default:
qWarning("Unhandled stream control unit %d", qWarning("Unhandled stream control unit %d",
streamList[i]->mControl.unit()); streamList[i]->mControl->unit());
continue; continue;
} }
qDebug("numBursts = %ld, numPackets = %ld\n", qDebug("numBursts = %ld, numPackets = %ld\n",
@ -773,7 +672,7 @@ void PortInfo::update()
} }
} // for (numBursts) } // for (numBursts)
switch(streamList[i]->mControl.next()) switch(streamList[i]->mControl->next())
{ {
case ::OstProto::StreamControl::e_nw_stop: case ::OstProto::StreamControl::e_nw_stop:
goto _stop_no_more_pkts; goto _stop_no_more_pkts;
@ -798,7 +697,7 @@ void PortInfo::update()
default: default:
qFatal("---------- %s: Unhandled case (%d) -----------", qFatal("---------- %s: Unhandled case (%d) -----------",
__FUNCTION__, streamList[i]->mControl.next() ); __FUNCTION__, streamList[i]->mControl->next() );
break; break;
} }
@ -1378,18 +1277,7 @@ const ::OstProto::StreamIdList* request,
s = response->add_stream(); s = response->add_stream();
s->mutable_stream_id()->CopyFrom( portInfo[portIdx]->streamList[streamIndex]->protoDataCopyInto(*s);
portInfo[portIdx]->streamList[streamIndex]->mStreamId);
s->mutable_core()->CopyFrom(
portInfo[portIdx]->streamList[streamIndex]->mCore);
s->mutable_control()->CopyFrom(
portInfo[portIdx]->streamList[streamIndex]->mControl);
for (int j=0; j < portInfo[portIdx]->streamList[streamIndex]->
mProtocolList.size(); j++)
{
portInfo[portIdx]->streamList[streamIndex]->
mProtocolList[j]->protoDataCopyInto(*s);
}
} }
_exit: _exit:
@ -1494,17 +1382,8 @@ const ::OstProto::StreamConfigList* request,
if (streamIndex < 0) if (streamIndex < 0)
continue; // TODO(LOW): Partial status of RPC continue; // TODO(LOW): Partial status of RPC
portInfo[portIdx]->streamList[streamIndex]->mCore.clear_frame_proto(); portInfo[portIdx]->streamList[streamIndex]->protoDataCopyFrom(
portInfo[portIdx]->streamList[streamIndex]->mCore.MergeFrom( request->stream(i));
request->stream(i).core());
portInfo[portIdx]->streamList[streamIndex]->mControl.MergeFrom(
request->stream(i).control());
for (int j=0; j < portInfo[portIdx]->streamList[streamIndex]->
mProtocolList.size(); j++)
{
portInfo[portIdx]->streamList[streamIndex]->
mProtocolList[j]->protoDataCopyFrom(request->stream(i));
}
// TODO(LOW): fill-in response "Ack"???? // TODO(LOW): fill-in response "Ack"????
} }

View File

@ -8,7 +8,7 @@
#endif #endif
#include "../common/protocol.pb.h" #include "../common/protocol.pb.h"
#include "../common/abstractprotocol.h" #include "../common/streambase.h"
#include "abstracthost.h" #include "abstracthost.h"
#include <pcap.h> #include <pcap.h>
#include <QtGlobal> #include <QtGlobal>
@ -30,31 +30,19 @@
class MyService; class MyService;
class StreamInfo class StreamInfo : public StreamBase
{ {
friend class MyService; friend class MyService;
friend class PortInfo; friend class PortInfo;
OstProto::StreamId mStreamId; OstProto::StreamId mStreamId;
OstProto::StreamCore mCore;
OstProto::StreamControl mControl;
QList<AbstractProtocol*> mProtocolList;
public: public:
StreamInfo(); StreamInfo();
~StreamInfo(); ~StreamInfo();
private: private:
AbstractProtocol* protocolById(int id);
quint32 pseudoHdrCksumPartial(quint32 srcIp, quint32 dstIp,
quint8 protocol, quint16 len);
quint32 ipv4CksumPartial(uchar *buf, int len);
quint16 ipv4Cksum(uchar *buf, int len, quint32 partialSum = 0);
int makePacket(uchar *buf, int bufMaxSize, int n); int makePacket(uchar *buf, int bufMaxSize, int n);
public:
bool operator < (const StreamInfo &s) const
{ return(mCore.ordinal() < s.mCore.ordinal()); }
}; };