diff --git a/Makefile b/Makefile index c285580..574c0a1 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,12 @@ clean: $(MAKE) -C server $@ $(MAKE) -C client $@ +distclean: + $(MAKE) -C rpc $@ + $(MAKE) -C common $@ + $(MAKE) -C server $@ + $(MAKE) -C client $@ + qmake: cd rpc && qmake && cd .. cd common && qmake && cd .. diff --git a/client/port.cpp b/client/port.cpp index 64c7865..291b1b5 100644 --- a/client/port.cpp +++ b/client/port.cpp @@ -98,7 +98,7 @@ bool Port::updateStream(uint streamId, OstProto::Stream *stream) _found: streamIndex = i; - mStreams[streamIndex]->update(stream); + mStreams[streamIndex]->protoDataCopyFrom(*stream); reorderStreamsByOrdinals(); return true; @@ -167,7 +167,7 @@ void Port::getModifiedStreamsSinceLastSync( OstProto::Stream *s; s = streamConfigList.add_stream(); - mStreams[i]->getConfig(mPortId, *s); + mStreams[i]->protoDataCopyInto(*s); } qDebug("Done %s", __FUNCTION__); } diff --git a/client/stream.cpp b/client/stream.cpp index 3af3509..b978913 100644 --- a/client/stream.cpp +++ b/client/stream.cpp @@ -3,173 +3,27 @@ #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() { - 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); - + //mId = 0xFFFFFFFF; mCore->set_is_enabled(true); - mCore->add_frame_proto(51); // MAC (FIXME: hardcoding) - mCore->add_frame_proto(52); // Payload (FIXME: hardcoding) + + QList protoList; + protoList.append(51); + protoList.append(52); + setFrameProtocol(protoList); } 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() { - for (int i=0; i < mProtocolList.size(); i++) - mProtocolList[i]->loadConfigWidget(); + protocols.loadConfigWidgets(); } void Stream::storeProtocolWidgets() { - for (int i=0; i < mProtocolList.size(); i++) - 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 Stream::frameProtocol() -{ - QList protocolList; - - for (int i = 0; i < mCore->frame_proto_size(); i++) - protocolList.append(mCore->frame_proto(i)); - - return protocolList; -} - -void Stream::setFrameProtocol(QList 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; - } + protocols.storeConfigWidgets(); } diff --git a/client/stream.h b/client/stream.h index c4884d4..1c19b19 100644 --- a/client/stream.h +++ b/client/stream.h @@ -2,48 +2,21 @@ #define _STREAM_H #include - #include #include + #include "../common/protocol.pb.h" -#include "../common/abstractprotocol.h" +#include "../common/streambase.h" -// Convenience Defines FIXME -#define IP_PROTO_ICMP 0x01 -#define IP_PROTO_IGMP 0x02 -#define IP_PROTO_TCP 0x06 -#define IP_PROTO_UDP 0x11 +class Stream : public StreamBase { -class Stream { - - quint32 mId; - OstProto::StreamCore *mCore; - OstProto::StreamControl *mControl; - - QList mProtocolList; + //quint32 mId; public: - - void* core() { return mCore; } // FIXME(HI): Debug ONLY void loadProtocolWidgets(); void storeProtocolWidgets(); 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 { e_fl_fixed, e_fl_inc, @@ -51,20 +24,6 @@ public: 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 { e_su_packets, e_su_bursts @@ -87,19 +46,15 @@ public: Stream(); ~Stream(); - void protoDataCopyFrom(Stream& stream); + // TODO: Below methods move to StreamBase??? bool operator < (const Stream &s) const { return(mCore->ordinal() < s.mCore->ordinal()); } - - void getConfig(uint portId, OstProto::Stream &s); - bool update(OstProto::Stream *stream); - quint32 id() - { return mId;} + { return mStreamId->id();} bool setId(quint32 id) - { mId = id; return true;} + { mStreamId->set_id(id); return true;} #if 0 // FIXME(HI): needed? quint32 portId() @@ -123,12 +78,7 @@ public: bool setName(QString name) { mCore->set_name(name.toStdString()); return true; } -// TODO(HI) : ????? -#if 0 - quint16 dataStartOfs; -#endif - - // Frame Length (includes CRC) + // Frame Length (includes FCS) FrameLengthMode lenMode() { return (FrameLengthMode) mCore->len_mode(); } bool setLenMode(FrameLengthMode lenMode) @@ -192,16 +142,6 @@ public: { return (quint32) mControl->bursts_per_sec(); } bool setBurstRate(quint32 burstsPerSec) { mControl->set_bursts_per_sec(burstsPerSec); return true; } - - //--------------------------------------------------------------- - // Methods for use by Packet Model - //--------------------------------------------------------------- - QList frameProtocol(); - void setFrameProtocol(QList protocolList); - - //! Includes ALL protocol headers excluding payload data - int protocolHeaderSize(); - AbstractProtocol* protocolById(int id); }; #endif diff --git a/client/streamconfigdialog.cpp b/client/streamconfigdialog.cpp index 0079240..b69ef67 100644 --- a/client/streamconfigdialog.cpp +++ b/client/streamconfigdialog.cpp @@ -7,71 +7,38 @@ int StreamConfigDialog::lastTopLevelTabIndex = 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, QWidget *parent) : QDialog (parent), mPort(port) { + OstProto::Stream s; mCurrentStreamIndex = streamIndex; - mpStream = new Stream; - mpStream->protoDataCopyFrom(*(mPort.streamByIndex(mCurrentStreamIndex))); + mPort.streamByIndex(mCurrentStreamIndex)->protoDataCopyInto(s); + mpStream->protoDataCopyFrom(s); setupUi(this); 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! 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 connect(rbFtNone, SIGNAL(toggled(bool)), rbL3None, SLOT(setEnabled(bool))); connect(rbFtNone, SIGNAL(toggled(bool)), rbL3Ipv4, 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 connect(rbFtEthernet2, SIGNAL(toggled(bool)), rbL3None, SLOT(setEnabled(bool))); connect(rbFtEthernet2, SIGNAL(toggled(bool)), rbL3Ipv4, 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 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)), 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) 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)), 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 connect(rbFtLlcSnap, SIGNAL(toggled(bool)), rbL3None, SLOT(setEnabled(bool))); connect(rbFtLlcSnap, SIGNAL(toggled(bool)), rbL3Ipv4, 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 connect(rbL3None, SIGNAL(toggled(bool)), rbL4None, SLOT(setEnabled(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 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(); mpPacketModel = new PacketModel(QList(), this); tvPacketTree->setModel(mpPacketModel); @@ -173,6 +96,10 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex, vwPacketDump->setSelectionModel(tvPacketTree->selectionModel()); // TODO(MED): + //! \todo Implement then enable these protocols + rbL3Arp->setHidden(true); + rbL4Icmp->setHidden(true); + rbL4Igmp->setHidden(true); //! \todo Enable navigation of streams pbPrev->setDisabled(true); pbNext->setDisabled(true); @@ -181,6 +108,7 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex, disconnect(rbActionGotoStream, SIGNAL(toggled(bool)), leStreamId, SLOT(setEnabled(bool))); //! \todo Support Continuous Mode rbModeContinuous->setDisabled(true); + // Finally, restore the saved last selected tab for the various tab widgets twTopLevel->setCurrentIndex(lastTopLevelTabIndex); if (twProto->isTabEnabled(lastProtoTabIndex)) @@ -199,27 +127,25 @@ void StreamConfigDialog::setupUiExtra() layout = static_cast(twTopLevel->widget(0)->layout()); - layout->addWidget(mpStream->protocolById(52)->configWidget(), 0, 1); - qDebug("setupUi wgt = %p", mpStream->protocolById(52)->configWidget()); + layout->addWidget(mpStream->protocol(52)->configWidget(), 0, 1); + qDebug("setupUi wgt = %p", mpStream->protocol(52)->configWidget()); } // ---- Setup default stuff that cannot be done in designer ---- + bgFrameType = new QButtonGroup(); + foreach(QRadioButton *btn, gbFrameType->findChildren()) + bgFrameType->addButton(btn); - // Since the dialog defaults are FT = None, L3 = None, L4 = None; - // hide associated input fields since it can't be done in Designer - lblDsap->setHidden(true); - 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); + bgL3Proto = new QButtonGroup(); + foreach(QRadioButton *btn, gbL3Proto->findChildren()) + bgL3Proto->addButton(btn); - twProto->setTabEnabled(2, FALSE); - twProto->setTabEnabled(3, FALSE); + bgL4Proto = new QButtonGroup(); + foreach(QRadioButton *btn, gbL4Proto->findChildren()) + bgL4Proto->addButton(btn); + + //twProto->setTabEnabled(2, FALSE); + //twProto->setTabEnabled(3, FALSE); /* ** Setup Validators @@ -263,18 +189,8 @@ StreamConfigDialog::~StreamConfigDialog() QLayout *layout = twTopLevel->widget(0)->layout(); if (layout) { - qDebug("dstrct wgt = %p", mpStream->protocolById(52)->configWidget()); -#if 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); - + layout->removeWidget(mpStream->protocol(52)->configWidget()); + mpStream->protocol(52)->configWidget()->setParent(0); } } @@ -296,6 +212,10 @@ StreamConfigDialog::~StreamConfigDialog() } } + delete bgFrameType; + delete bgL3Proto; + delete bgL4Proto; + delete mpStream; } @@ -340,6 +260,10 @@ void StreamConfigDialog::updateSelectedProtocols() // Payload mSelectedProtocols.append(52); + + mpStream->setFrameProtocol(mSelectedProtocols); + mpStream->storeProtocolWidgets(); + mpStream->loadProtocolWidgets(); } @@ -399,146 +323,6 @@ void StreamConfigDialog::on_pbNext_clicked() #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) { QList protoList; @@ -549,8 +333,8 @@ void StreamConfigDialog::on_twTopLevel_currentChanged(int index) updateSelectedProtocols(); foreach(int i, mSelectedProtocols) - if (mpStream->protocolById(i)) - protoList.append(mpStream->protocolById(i)); + if (mpStream->protocol(i)) + protoList.append(mpStream->protocol(i)); mpPacketModel->setSelectedProtocols(protoList); StoreCurrentStream(mpStream); @@ -583,42 +367,44 @@ void StreamConfigDialog::on_twProto_currentChanged(int index) switch(index) { case 1: // L2 - wl.append(mpStream->protocolById(51)->configWidget()); + wl.append(mpStream->protocol("mac")->configWidget()); if (rbFtEthernet2->isChecked()) - wl.append(mpStream->protocolById(121)->configWidget()); + wl.append(mpStream->protocol("eth2")->configWidget()); else if (rbFt802Dot3Raw->isChecked()) - wl.append(mpStream->protocolById(122)->configWidget()); + wl.append(mpStream->protocol("dot3")->configWidget()); else if (rbFt802Dot3Llc->isChecked()) { - wl.append(mpStream->protocolById(122)->configWidget()); - wl.append(mpStream->protocolById(123)->configWidget()); + wl.append(mpStream->protocol("dot3")->configWidget()); + wl.append(mpStream->protocol("llc")->configWidget()); } else if (rbFtLlcSnap->isChecked()) { - wl.append(mpStream->protocolById(122)->configWidget()); - wl.append(mpStream->protocolById(123)->configWidget()); - wl.append(mpStream->protocolById(124)->configWidget()); + wl.append(mpStream->protocol("dot3")->configWidget()); + wl.append(mpStream->protocol("llc")->configWidget()); + wl.append(mpStream->protocol("snap")->configWidget()); } break; case 2: // L3 if (rbL3Ipv4->isChecked()) - wl.append(mpStream->protocolById(130)->configWidget()); + wl.append(mpStream->protocol("ip4")->configWidget()); break; case 3: // L4 if (rbL4Tcp->isChecked()) - wl.append(mpStream->protocolById(140)->configWidget()); + wl.append(mpStream->protocol("tcp")->configWidget()); else if (rbL4Udp->isChecked()) - wl.append(mpStream->protocolById(141)->configWidget()); + wl.append(mpStream->protocol("udp")->configWidget()); break; } - if (wl.size()) + if (wl.size()) + { layout = new QVBoxLayout; - for (int i=0; i < wl.size(); i++) - layout->addWidget(wl.at(i)); + for (int i=0; i < wl.size(); i++) + layout->addWidget(wl.at(i)); - twProto->widget(index)->setLayout(layout); + twProto->widget(index)->setLayout(layout); + } } void StreamConfigDialog::update_NumPacketsAndNumBursts() diff --git a/client/streamconfigdialog.h b/client/streamconfigdialog.h index f6c5a41..75cae99 100644 --- a/client/streamconfigdialog.h +++ b/client/streamconfigdialog.h @@ -29,6 +29,10 @@ public: private: //QList *mpStreamList; + QButtonGroup *bgFrameType; + QButtonGroup *bgL3Proto; + QButtonGroup *bgL4Proto; + Port& mPort; uint mCurrentStreamIndex; Stream *mpStream; @@ -45,7 +49,6 @@ private: static int lastProtoTabIndex; void setupUiExtra(); - void updateSelectedProtocols(); void LoadCurrentStream(); void StoreCurrentStream(Stream *pStream); @@ -54,18 +57,7 @@ private slots: void on_pbPrev_clicked(); void on_pbNext_clicked(); - void on_rbFtNone_toggled(bool checked); - 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 updateSelectedProtocols(); void on_twTopLevel_currentChanged(int index); void on_twProto_currentChanged(int index); diff --git a/client/streamconfigdialog.ui b/client/streamconfigdialog.ui index e410c81..9eba69a 100644 --- a/client/streamconfigdialog.ui +++ b/client/streamconfigdialog.ui @@ -59,7 +59,7 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff - Frame Length (including CRC) + Frame Length (including FCS) @@ -159,164 +159,60 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff - + Frame Type - + - - - - - - - None - - - true - - - - - - - Ethernet II - - - false - - - - - - - 802.3 Raw - - - - - - - 802.3 LLC - - - false - - - - - - - LLC SNAP - - - - - - - - - Qt::Vertical - - - - - - - - - DSAP - - - - - - - true - - - HH; - - - - - - - SSAP - - - - - - - true - - - HH; - - - - - - - Control - - - - - - - true - - - HH; - - - - - - - OUI - - - - - - - true - - - HH HH HH; - - - - - - - Type - - - - - - - true - - - HH HH; - - - - - - + + + None + + + true + + + + + + + Ethernet II + + + false + + + + + + + 802.3 Raw + + + + + + + 802.3 LLC + + + false + + + + + + + LLC SNAP + + - + L3 @@ -358,7 +254,7 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff - + L4 @@ -416,7 +312,7 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff - + Qt::Vertical diff --git a/common/abstractprotocol.cpp b/common/abstractprotocol.cpp index 429c6a3..04d0d67 100644 --- a/common/abstractprotocol.cpp +++ b/common/abstractprotocol.cpp @@ -1,3 +1,4 @@ +#include #include "abstractprotocol.h" /*! @@ -18,19 +19,30 @@ - metaFieldCount() - 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; metaCount = -1; + protoSize = -1; } 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 In the base class this is a pure virtual function. Subclasses should @@ -38,7 +50,7 @@ AbstractProtocol::~AbstractProtocol() stream.AddExtension()->CopyFrom() */ /* - \fn virtual void protoDataCopyFrom(const OstProto::Stream &stream) = 0; + \fn virtual void protoDataCopyFrom(const OstProto::OstProto::StreamCore &stream) = 0; FIXME */ /*! 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 "(incorrect)" alongwith the actual checksum value. \n 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, int streamIndex) const @@ -151,6 +168,81 @@ bool AbstractProtocol::setFieldData(int index, const QVariant &value, return false; } +quint32 AbstractProtocol::protocolId(ProtocolIdType type) const +{ + return 0; +} + +quint32 AbstractProtocol::payloadProtocolId(ProtocolIdType type) const +{ + quint32 id = 0xFFFFFFFF; + QLinkedListIterator 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 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 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 inserted into the stream's frame The default implementation forms and returns an ordered concatenation of @@ -223,3 +315,53 @@ QByteArray AbstractProtocol::protocolFrameValue(int streamIndex) const 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 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; +} + diff --git a/common/abstractprotocol.h b/common/abstractprotocol.h index 7c7255e..ec0584b 100644 --- a/common/abstractprotocol.h +++ b/common/abstractprotocol.h @@ -5,7 +5,9 @@ #include #include #include +#include +//#include "../rpc/pbhelper.h" #include "../common/protocol.pb.h" #define BASE_BIN (2) @@ -13,16 +15,24 @@ #define BASE_DEC (10) #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 ProtocolList; class AbstractProtocol { private: mutable int metaCount; + mutable int protoSize; mutable QString protoAbbr; protected: - Stream *stream; + OstProto::StreamCore *stream; + ProtocolList &frameProtocols; public: enum FieldAttrib { @@ -34,15 +44,29 @@ public: 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(); + static AbstractProtocol* createInstance( + ProtocolList &frameProtoList, + OstProto::StreamCore *streamCore = 0); + virtual void protoDataCopyInto(OstProto::Stream &stream) = 0; virtual void protoDataCopyFrom(const OstProto::Stream &stream) = 0; virtual QString name() const; virtual QString shortName() const; + virtual quint32 protocolId(ProtocolIdType type) const; + quint32 payloadProtocolId(ProtocolIdType type) const; + virtual int fieldCount() const; virtual int metaFieldCount() const; int frameFieldCount() const; @@ -53,6 +77,12 @@ public: FieldAttrib attrib = FieldValue); 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 void loadConfigWidget() = 0; diff --git a/common/dot3.cpp b/common/dot3.cpp index 67b70d9..448c0c5 100644 --- a/common/dot3.cpp +++ b/common/dot3.cpp @@ -3,6 +3,8 @@ #include "Dot3.h" +#define SZ_FCS 4 + Dot3ConfigForm *Dot3Protocol::configForm = NULL; Dot3ConfigForm::Dot3ConfigForm(QWidget *parent) @@ -11,8 +13,10 @@ Dot3ConfigForm::Dot3ConfigForm(QWidget *parent) setupUi(this); } -Dot3Protocol::Dot3Protocol(Stream *parent) - : AbstractProtocol(parent) +Dot3Protocol::Dot3Protocol( + ProtocolList &frameProtoList, + OstProto::StreamCore *parent) + : AbstractProtocol(frameProtoList, parent) { if (configForm == NULL) 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) { // FIXME: multiple headers @@ -61,14 +72,27 @@ QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib, case FieldName: return QString("Length"); case FieldValue: - return data.length(); + { + quint16 len; + + len = stream->frame_len() - SZ_FCS; + return len; + } case FieldTextValue: - return QString("%1").arg(data.length()); + { + quint16 len; + + len = stream->frame_len() - SZ_FCS; + return QString("%1").arg(len); + } case FieldFrameValue: { + quint16 len; QByteArray fv; + + len = stream->frame_len() - SZ_FCS; fv.resize(2); - qToBigEndian((quint16) data.length(), (uchar*) fv.data()); + qToBigEndian(len, (uchar*) fv.data()); return fv; } default: @@ -98,7 +122,8 @@ QWidget* Dot3Protocol::configWidget() void Dot3Protocol::loadConfigWidget() { - configForm->leLength->setText(QString().setNum(data.length())); + configForm->leLength->setText( + fieldData(dot3_length, FieldValue).toString()); } void Dot3Protocol::storeConfigWidget() diff --git a/common/dot3.h b/common/dot3.h index e49f312..3b98b24 100644 --- a/common/dot3.h +++ b/common/dot3.h @@ -26,9 +26,14 @@ private: }; public: - Dot3Protocol(Stream *parent = 0); + Dot3Protocol(ProtocolList &frameProtoList, + OstProto::StreamCore *parent = 0); virtual ~Dot3Protocol(); + static AbstractProtocol* createInstance( + ProtocolList &frameProtoList, + OstProto::StreamCore *streamCore = 0); + virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream); diff --git a/common/eth2.cpp b/common/eth2.cpp index caaf75b..9fbfda6 100644 --- a/common/eth2.cpp +++ b/common/eth2.cpp @@ -11,8 +11,10 @@ Eth2ConfigForm::Eth2ConfigForm(QWidget *parent) setupUi(this); } -Eth2Protocol::Eth2Protocol(Stream *parent) - : AbstractProtocol(parent) +Eth2Protocol::Eth2Protocol( + ProtocolList &frameProtoList, + OstProto::StreamCore *parent) + : AbstractProtocol(frameProtoList, parent) { if (configForm == NULL) 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) { // FIXME: multiple headers @@ -56,26 +65,31 @@ QVariant Eth2Protocol::fieldData(int index, FieldAttrib attrib, switch (index) { case eth2_type: + { + quint16 type; switch(attrib) { case FieldName: return QString("Type"); case FieldValue: - return data.type(); + type = payloadProtocolId(ProtocolIdEth); + return type; 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: { QByteArray fv; + type = payloadProtocolId(ProtocolIdEth); fv.resize(2); - qToBigEndian((quint16) data.type(), (uchar*) fv.data()); + qToBigEndian((quint16) type, (uchar*) fv.data()); return fv; } default: break; } break; - + } default: break; } @@ -112,12 +126,8 @@ QWidget* Eth2Protocol::configWidget() void Eth2Protocol::loadConfigWidget() { -#define uintToHexStr(num, bytesize) \ - QString("%1").arg((num), (bytesize)*2 , 16, QChar('0')) - - configForm->leType->setText(uintToHexStr(data.type(), 2)); - -#undef uintToHexStr + configForm->leType->setText(uintToHexStr( + fieldData(eth2_type, FieldValue).toUInt(), 2)); } void Eth2Protocol::storeConfigWidget() diff --git a/common/eth2.h b/common/eth2.h index 580b712..e71659d 100644 --- a/common/eth2.h +++ b/common/eth2.h @@ -26,9 +26,14 @@ private: }; public: - Eth2Protocol(Stream *parent = 0); + Eth2Protocol(ProtocolList &frameProtoList, + OstProto::StreamCore *parent = 0); virtual ~Eth2Protocol(); + static AbstractProtocol* createInstance( + ProtocolList &frameProtoList, + OstProto::StreamCore *streamCore = 0); + virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream); diff --git a/common/eth2.ui b/common/eth2.ui index 9099dbb..a79068c 100644 --- a/common/eth2.ui +++ b/common/eth2.ui @@ -32,10 +32,10 @@ - true + false - HH HH; + >HH HH; diff --git a/common/ip4.cpp b/common/ip4.cpp index 625d3c7..260c720 100644 --- a/common/ip4.cpp +++ b/common/ip4.cpp @@ -44,9 +44,16 @@ void Ip4ConfigForm::on_cmbIpDstAddrMode_currentIndexChanged(int index) } } -Ip4Protocol::Ip4Protocol(Stream *parent) - : AbstractProtocol(parent) +Ip4Protocol::Ip4Protocol( + ProtocolList &frameProtoList, + OstProto::StreamCore *parent) + : AbstractProtocol(frameProtoList, parent) { +#if 0 + PbHelper pbh; + + pbh.ForceSetSingularDefault(&data); +#endif if (configForm == NULL) 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) { // FIXME: multiple headers @@ -78,6 +92,19 @@ QString Ip4Protocol::shortName() const 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 { return ip4_fieldCount; @@ -139,25 +166,42 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib, } break; case ip4_totLen: + { switch(attrib) { case FieldName: return QString("Total Length"); case FieldValue: - return data.totlen(); + { + int totlen; + totlen = data.is_override_totlen() ? data.totlen() : + (protocolFramePayloadSize() + 20); + return totlen; + } case FieldFrameValue: { QByteArray fv; + int totlen; + totlen = data.is_override_totlen() ? data.totlen() : + (protocolFramePayloadSize() + 20); fv.resize(2); - qToBigEndian((quint16) data.totlen(), (uchar*) fv.data()); + qToBigEndian((quint16) totlen, (uchar*) fv.data()); return fv; } 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: break; } break; + } case ip4_id: switch(attrib) { @@ -244,42 +288,86 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib, } break; case ip4_proto: + { switch(attrib) { case FieldName: return QString("Protocol"); case FieldValue: - return data.proto(); + { + unsigned char id = payloadProtocolId(ProtocolIdIp); + return id; + } case FieldFrameValue: - return QByteArray(1, (char)data.proto()); + { + unsigned char id = payloadProtocolId(ProtocolIdIp); + return QByteArray(1, (char) id); + } case FieldTextValue: + { + unsigned char id = payloadProtocolId(ProtocolIdIp); return QString("0x%1"). - arg(data.proto(), 2, BASE_HEX, QChar('0')); + arg(id, 2, BASE_HEX, QChar('0')); + } default: break; } break; + } case ip4_cksum: + { + switch(attrib) { case FieldName: return QString("Header Checksum"); 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: { 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); - qToBigEndian((quint16) data.cksum(), (uchar*) fv.data()); + qToBigEndian((quint16) cksum, (uchar*) fv.data()); return fv; } 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"). - arg(data.cksum(), 4, BASE_HEX, QChar('0'));; + arg(cksum, 4, BASE_HEX, QChar('0'));; + } + case FieldBitSize: + return 16; default: break; } break; + } case ip4_srcAddr: switch(attrib) { @@ -381,27 +469,27 @@ QWidget* Ip4Protocol::configWidget() void Ip4Protocol::loadConfigWidget() { -#define uintToHexStr(num, str, size) QString().setNum(num, 16) configForm->leIpVersion->setText(QString().setNum(data.ver_hdrlen() >> 4)); configForm->cbIpVersionOverride->setChecked(data.is_override_ver()); configForm->leIpHdrLen->setText(QString().setNum(data.ver_hdrlen() & 0x0F)); configForm->cbIpHdrLenOverride->setChecked(data.is_override_hdrlen()); - configForm->leIpTos->setText(uintToHexStr(data.tos(), QString(), 1)); - - configForm->leIpLength->setText(QString().setNum(data.totlen())); + configForm->leIpTos->setText(uintToHexStr(data.tos(), 1)); + configForm->leIpLength->setText(fieldData(ip4_totLen, FieldValue).toString()); 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->cbIpFlagsDf->setChecked((data.flags() & IP_FLAG_DF) > 0); configForm->cbIpFlagsMf->setChecked((data.flags() & IP_FLAG_MF) > 0); 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->leIpSrcAddr->setText(QHostAddress(data.src_ip()).toString()); diff --git a/common/ip4.h b/common/ip4.h index 73d3004..1bf8ccc 100644 --- a/common/ip4.h +++ b/common/ip4.h @@ -58,15 +58,20 @@ private: }; public: - Ip4Protocol(Stream *parent = 0); + Ip4Protocol(ProtocolList &frameProtoList, + OstProto::StreamCore *parent = 0); virtual ~Ip4Protocol(); + static AbstractProtocol* createInstance( + ProtocolList &frameProtoList, + OstProto::StreamCore *streamCore = 0); + virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual QString name() const; virtual QString shortName() const; - + virtual quint32 protocolId(ProtocolIdType type) const; virtual int fieldCount() const; virtual QVariant fieldData(int index, FieldAttrib attrib, diff --git a/common/ip4.ui b/common/ip4.ui index 35a85bf..785e7e3 100644 --- a/common/ip4.ui +++ b/common/ip4.ui @@ -28,7 +28,7 @@ false - 4 + @@ -45,7 +45,7 @@ false - 5 + @@ -59,7 +59,7 @@ - HH; + >HH; @@ -100,7 +100,7 @@ - HH HH; + >HH HH; @@ -149,7 +149,7 @@ - 64 + @@ -183,7 +183,7 @@ false - HH HH; + >HH HH; @@ -291,8 +291,11 @@ false + + 009.009.009.009; + - 255.255.255.255 + ... @@ -355,8 +358,11 @@ false + + 009.009.009.009; + - 255.255.255.255 + ... diff --git a/common/llc.cpp b/common/llc.cpp index 394ca2c..c0183ca 100644 --- a/common/llc.cpp +++ b/common/llc.cpp @@ -11,8 +11,10 @@ LlcConfigForm::LlcConfigForm(QWidget *parent) setupUi(this); } -LlcProtocol::LlcProtocol(Stream *parent) - : AbstractProtocol(parent) +LlcProtocol::LlcProtocol( + ProtocolList &frameProtoList, + OstProto::StreamCore *parent) + : AbstractProtocol(frameProtoList, parent) { if (configForm == NULL) 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) { // FIXME: multiple headers @@ -53,6 +62,14 @@ int LlcProtocol::fieldCount() const QVariant LlcProtocol::fieldData(int index, FieldAttrib attrib, 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) { case llc_dsap: @@ -61,11 +78,11 @@ QVariant LlcProtocol::fieldData(int index, FieldAttrib attrib, case FieldName: return QString("DSAP"); case FieldValue: - return data.dsap(); + return dsap; case FieldTextValue: - return QString("%1").arg(data.dsap(), BASE_HEX); + return QString("%1").arg(dsap, 2, BASE_HEX, QChar('0')); case FieldFrameValue: - return QByteArray(1, (char)(data.dsap())); + return QByteArray(1, (char)(dsap)); default: break; } @@ -74,13 +91,13 @@ QVariant LlcProtocol::fieldData(int index, FieldAttrib attrib, switch(attrib) { case FieldName: - return QString("DSAP"); + return QString("SSAP"); case FieldValue: - return data.ssap(); + return ssap; case FieldTextValue: - return QString("%1").arg(data.ssap(), BASE_HEX); + return QString("%1").arg(ssap, 2, BASE_HEX, QChar('0')); case FieldFrameValue: - return QByteArray(1, (char)(data.ssap())); + return QByteArray(1, (char)(ssap)); default: break; } @@ -89,13 +106,13 @@ QVariant LlcProtocol::fieldData(int index, FieldAttrib attrib, switch(attrib) { case FieldName: - return QString("DSAP"); + return QString("Control"); case FieldValue: - return data.ctl(); + return ctl; case FieldTextValue: - return QString("%1").arg(data.ctl(), BASE_HEX); + return QString("%1").arg(ctl, 2, BASE_HEX, QChar('0')); case FieldFrameValue: - return QByteArray(1, (char)(data.ctl())); + return QByteArray(1, (char)(ctl)); default: break; } @@ -123,9 +140,16 @@ QWidget* LlcProtocol::configWidget() void LlcProtocol::loadConfigWidget() { - configForm->leDsap->setText(QString("%1").arg(data.dsap(), 2, BASE_HEX, QChar('0'))); - configForm->leSsap->setText(QString("%1").arg(data.ssap(), 2, BASE_HEX, QChar('0'))); - configForm->leControl->setText(QString("%1").arg(data.ctl(), 2, BASE_HEX, QChar('0'))); +#define uintToHexStr(num, bytes) \ + QString("%1").arg(num, bytes*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() diff --git a/common/llc.h b/common/llc.h index 18e1181..8403fab 100644 --- a/common/llc.h +++ b/common/llc.h @@ -31,9 +31,14 @@ private: }; public: - LlcProtocol(Stream *parent = 0); + LlcProtocol(ProtocolList &frameProtoList, + OstProto::StreamCore *parent = 0); virtual ~LlcProtocol(); + static AbstractProtocol* createInstance( + ProtocolList &frameProtoList, + OstProto::StreamCore *streamCore = 0); + virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream); diff --git a/common/llc.ui b/common/llc.ui index 4518b3d..5f305a0 100644 --- a/common/llc.ui +++ b/common/llc.ui @@ -38,10 +38,10 @@ - true + false - HH; + >HH; @@ -58,10 +58,10 @@ - true + false - HH; + >HH; @@ -78,10 +78,10 @@ - true + false - HH; + >HH; diff --git a/common/mac.cpp b/common/mac.cpp index 59b2607..53defa7 100644 --- a/common/mac.cpp +++ b/common/mac.cpp @@ -46,8 +46,10 @@ void MacConfigForm::on_cmbSrcMacMode_currentIndexChanged(int index) } -MacProtocol::MacProtocol(Stream *parent) - : AbstractProtocol(parent) +MacProtocol::MacProtocol( + ProtocolList &frameProtoList, + OstProto::StreamCore *parent) + : AbstractProtocol(frameProtoList, parent) { if (configForm == NULL) 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) { // FIXME: multiple headers @@ -174,13 +183,12 @@ QWidget* MacProtocol::configWidget() void MacProtocol::loadConfigWidget() { -#define uintToHexStr(num, str, size) QString().setNum(num, 16) - configForm->leDstMac->setText(uintToHexStr(data.dst_mac(), str, 6)); + configForm->leDstMac->setText(uintToHexStr(data.dst_mac(), 6)); configForm->cmbDstMacMode->setCurrentIndex(data.dst_mac_mode()); configForm->leDstMacCount->setText(QString().setNum(data.dst_mac_count())); 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->leSrcMacCount->setText(QString().setNum(data.src_mac_count())); configForm->leSrcMacStep->setText(QString().setNum(data.src_mac_step())); diff --git a/common/mac.h b/common/mac.h index 2842475..575b9b1 100644 --- a/common/mac.h +++ b/common/mac.h @@ -39,9 +39,14 @@ private: }; public: - MacProtocol(Stream *parent = 0); + MacProtocol(ProtocolList &frameProtoList, + OstProto::StreamCore *parent = 0); virtual ~MacProtocol(); + static AbstractProtocol* createInstance( + ProtocolList &frameProtoList, + OstProto::StreamCore *streamCore = 0); + virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream); diff --git a/common/mac.ui b/common/mac.ui index 9095f29..9afb006 100644 --- a/common/mac.ui +++ b/common/mac.ui @@ -49,7 +49,7 @@ - HH HH HH HH HH HH; + >HH HH HH HH HH HH; @@ -111,7 +111,7 @@ - HH HH HH HH HH HH; + >HH HH HH HH HH HH; diff --git a/common/ostproto.pro b/common/ostproto.pro index 3bd8e9c..59b2453 100644 --- a/common/ostproto.pro +++ b/common/ostproto.pro @@ -26,6 +26,9 @@ PROTOS += \ udp.proto HEADERS += \ abstractprotocol.h \ + protocolmanager.h \ + protocolcollection.h \ + streambase.h \ mac.h \ payload.h \ eth2.h \ @@ -37,6 +40,9 @@ HEADERS += \ udp.h SOURCES += \ abstractprotocol.cpp \ + protocolmanager.cpp \ + protocolcollection.cpp \ + streambase.cpp \ mac.cpp \ payload.cpp \ eth2.cpp \ diff --git a/common/payload.cpp b/common/payload.cpp index 8feecf9..8e79c7d 100644 --- a/common/payload.cpp +++ b/common/payload.cpp @@ -1,9 +1,11 @@ #include #include -#include "../client/stream.h" +//#include "../client/stream.h" #include "payload.h" +#define SZ_FCS 4 + PayloadConfigForm *PayloadProtocol::configForm = NULL; PayloadConfigForm::PayloadConfigForm(QWidget *parent) @@ -29,8 +31,10 @@ void PayloadConfigForm::on_cmbPatternMode_currentIndexChanged(int index) } } -PayloadProtocol::PayloadProtocol(Stream *parent) - : AbstractProtocol(parent) +PayloadProtocol::PayloadProtocol( + ProtocolList &frameProtoList, + OstProto::StreamCore *parent) + : AbstractProtocol(frameProtoList, parent) { if (configForm == NULL) 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) { // FIXME: multiple headers @@ -88,10 +99,8 @@ QVariant PayloadProtocol::fieldData(int index, FieldAttrib attrib, QByteArray fv; int dataLen; - // FIXME: cannot use stream since it is only on client not - // on server - //dataLen = stream->frameLen() - stream->protocolHeaderSize(); - dataLen = 64; + dataLen = stream->frame_len() - protocolFrameOffset(); + dataLen -= SZ_FCS; fv.resize(dataLen+4); switch(data.pattern_mode()) { @@ -159,10 +168,8 @@ QWidget* PayloadProtocol::configWidget() void PayloadProtocol::loadConfigWidget() { -#define uintToHexStr(num, str, size) QString().setNum(num, 16) - configForm->cmbPatternMode->setCurrentIndex(data.pattern_mode()); - configForm->lePattern->setText(uintToHexStr(data.pattern(), QString(), 4)); + configForm->lePattern->setText(uintToHexStr(data.pattern(), 4)); } void PayloadProtocol::storeConfigWidget() diff --git a/common/payload.h b/common/payload.h index aa66f5d..4a1dc03 100644 --- a/common/payload.h +++ b/common/payload.h @@ -31,9 +31,14 @@ private: }; public: - PayloadProtocol(Stream *parent = 0); + PayloadProtocol(ProtocolList &frameProtoList, + OstProto::StreamCore *parent = 0); virtual ~PayloadProtocol(); + static AbstractProtocol* createInstance( + ProtocolList &frameProtoList, + OstProto::StreamCore *streamCore = 0); + virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream); diff --git a/common/payload.ui b/common/payload.ui index 9de7ce1..c0a1b31 100644 --- a/common/payload.ui +++ b/common/payload.ui @@ -46,7 +46,7 @@ - HH HH HH HH; + >HH HH HH HH; diff --git a/common/protocolcollection.cpp b/common/protocolcollection.cpp new file mode 100644 index 0000000..60e6d21 --- /dev/null +++ b/common/protocolcollection.cpp @@ -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 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 iter(protocols); + + while (iter.hasNext()) + { + iter.next(); + if (iter.value()) + { + delete iter.value(); + iter.remove(); + } + } +} + +void ProtocolCollection::protoDataCopyFrom(const OstProto::Stream &stream) const +{ + QMapIterator iter(protocols); + + while (iter.hasNext()) + { + iter.next(); + if (iter.value()) + { + iter.value()->protoDataCopyFrom(stream); + } + } +} + +void ProtocolCollection::protoDataCopyInto(OstProto::Stream &stream) const +{ + QMapIterator iter(protocols); + + while (iter.hasNext()) + { + iter.next(); + if (iter.value()) + { + iter.value()->protoDataCopyInto(stream); + } + } +} + +void ProtocolCollection::loadConfigWidgets() const +{ + QMapIterator iter(protocols); + + while (iter.hasNext()) + { + iter.next(); + if (iter.value()) + { + iter.value()->loadConfigWidget(); + } + } +} + +void ProtocolCollection::storeConfigWidgets() const +{ + QMapIterator 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)); +} diff --git a/common/protocolcollection.h b/common/protocolcollection.h new file mode 100644 index 0000000..61ca418 --- /dev/null +++ b/common/protocolcollection.h @@ -0,0 +1,30 @@ +#ifndef _PROTOCOL_COLLECTION_H +#define _PROTOCOL_COLLECTION_H + +#include +#include + +#include "abstractprotocol.h" +#include "protocolmanager.h" + +class ProtocolCollection { + + ProtocolManager &protoManager; + QMap 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 diff --git a/common/protocolmanager.cpp b/common/protocolmanager.cpp new file mode 100644 index 0000000..7b49e33 --- /dev/null +++ b/common/protocolmanager.cpp @@ -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 ProtocolManager::factory; +QMap 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); +} diff --git a/common/protocolmanager.h b/common/protocolmanager.h new file mode 100644 index 0000000..5d8e1ca --- /dev/null +++ b/common/protocolmanager.h @@ -0,0 +1,18 @@ +#ifndef _PROTOCOL_MANAGER_H +#define _PROTOCOL_MANAGER_H + +#include + +class ProtocolManager +{ +public: + static QMap nameToNumberMap; + static QMap factory; + +public: + ProtocolManager(); + void registerProtocol(int protoNumber, QString protoName, + void *protoCreator); +}; + +#endif diff --git a/common/snap.cpp b/common/snap.cpp index 33f841e..46cca1e 100644 --- a/common/snap.cpp +++ b/common/snap.cpp @@ -11,8 +11,10 @@ SnapConfigForm::SnapConfigForm(QWidget *parent) setupUi(this); } -SnapProtocol::SnapProtocol(Stream *parent) - : AbstractProtocol(parent) +SnapProtocol::SnapProtocol( + ProtocolList &frameProtoList, + OstProto::StreamCore *parent) + : AbstractProtocol(frameProtoList, parent) { if (configForm == NULL) 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) { // FIXME: multiple headers @@ -45,6 +54,17 @@ QString SnapProtocol::shortName() const 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 { return snap_fieldCount; @@ -76,7 +96,33 @@ QVariant SnapProtocol::fieldData(int index, FieldAttrib attrib, 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: break; } @@ -99,14 +145,17 @@ QWidget* SnapProtocol::configWidget() void SnapProtocol::loadConfigWidget() { -#define uintToHexStr(num, str, size) QString().setNum(num, 16) - configForm->leOui->setText(uintToHexStr(data.oui(), str, 3)); + configForm->leOui->setText(uintToHexStr( + fieldData(snap_oui, FieldValue).toUInt(), 3)); + configForm->leType->setText(uintToHexStr( + fieldData(snap_type, FieldValue).toUInt(), 2)); } void SnapProtocol::storeConfigWidget() { 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)); } diff --git a/common/snap.h b/common/snap.h index 9913b0f..ba0a3b6 100644 --- a/common/snap.h +++ b/common/snap.h @@ -21,19 +21,26 @@ private: enum snapfield { snap_oui = 0, + snap_type, snap_fieldCount }; public: - SnapProtocol(Stream *parent = 0); + SnapProtocol(ProtocolList &frameProtoList, + OstProto::StreamCore *parent = 0); virtual ~SnapProtocol(); + static AbstractProtocol* createInstance( + ProtocolList &frameProtoList, + OstProto::StreamCore *streamCore = 0); + virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual QString name() const; virtual QString shortName() const; + virtual quint32 protocolId(ProtocolIdType type) const; virtual int fieldCount() const; diff --git a/common/snap.proto b/common/snap.proto index b6c310c..c5ea432 100644 --- a/common/snap.proto +++ b/common/snap.proto @@ -4,7 +4,7 @@ package OstProto; message Snap { optional uint32 oui = 1; - //optional uint32 type = 2; + optional uint32 type = 2; } extend Stream { diff --git a/common/snap.ui b/common/snap.ui index 1f2b789..9d0e4a5 100644 --- a/common/snap.ui +++ b/common/snap.ui @@ -29,10 +29,10 @@ - true + false - HH HH HH; + >HH HH HH; @@ -46,10 +46,10 @@ - true + false - HH HH; + >HH HH; diff --git a/common/streambase.cpp b/common/streambase.cpp new file mode 100644 index 0000000..4bd4faf --- /dev/null +++ b/common/streambase.cpp @@ -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 StreamBase::frameProtocol() +{ + QList protocolList; + + for (int i = 0; i < mCore->frame_proto_size(); i++) + protocolList.append(mCore->frame_proto(i)); + + return protocolList; +} + +void StreamBase::setFrameProtocol(QList 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); +} + diff --git a/common/streambase.h b/common/streambase.h new file mode 100644 index 0000000..c8eb2c8 --- /dev/null +++ b/common/streambase.h @@ -0,0 +1,36 @@ +#ifndef _STREAM_BASE_H +#define _STREAM_BASE_H + +#include + +#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 frameProtocol(); + void setFrameProtocol(QList protocolList); + + AbstractProtocol* protocol(int protoNum); + AbstractProtocol* protocol(QString protoName); + + // TODO: make a copy constructor +}; + +#endif diff --git a/common/tcp.cpp b/common/tcp.cpp index 4c81c1c..26b14c0 100644 --- a/common/tcp.cpp +++ b/common/tcp.cpp @@ -11,8 +11,10 @@ TcpConfigForm::TcpConfigForm(QWidget *parent) setupUi(this); } -TcpProtocol::TcpProtocol(Stream *parent) - : AbstractProtocol(parent) +TcpProtocol::TcpProtocol( + ProtocolList &frameProtoList, + OstProto::StreamCore *parent) + : AbstractProtocol(frameProtoList, parent) { if (configForm == NULL) 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) { // FIXME: multiple headers @@ -45,6 +54,17 @@ QString TcpProtocol::shortName() const 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 { return tcp_fieldCount; @@ -149,7 +169,7 @@ QVariant TcpProtocol::fieldData(int index, FieldAttrib attrib, case FieldTextValue: return QString("%1").arg((data.hdrlen_rsvd() >> 4) & 0x0F); case FieldFrameValue: - return QByteArray(1, (char)((data.hdrlen_rsvd() >> 4) & 0x0F)); + return QByteArray(1, (char)(data.hdrlen_rsvd() & 0xF0)); case FieldBitSize: return 4; default: @@ -303,7 +323,6 @@ QWidget* TcpProtocol::configWidget() void TcpProtocol::loadConfigWidget() { -#define uintToHexStr(num, str, size) QString().setNum(num, 16) configForm->leTcpSrcPort->setText(QString().setNum(data.src_port())); configForm->leTcpDstPort->setText(QString().setNum(data.dst_port())); diff --git a/common/tcp.h b/common/tcp.h index 9fc2367..0637fc1 100644 --- a/common/tcp.h +++ b/common/tcp.h @@ -45,14 +45,20 @@ private: }; public: - TcpProtocol(Stream *parent = 0); + TcpProtocol(ProtocolList &frameProtoList, + OstProto::StreamCore *parent = 0); virtual ~TcpProtocol(); + static AbstractProtocol* createInstance( + ProtocolList &frameProtoList, + OstProto::StreamCore *streamCore = 0); + virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual QString name() const; virtual QString shortName() const; + virtual quint32 protocolId(ProtocolIdType type) const; virtual int fieldCount() const; diff --git a/common/tcp.ui b/common/tcp.ui index 4a333be..e19e9fb 100644 --- a/common/tcp.ui +++ b/common/tcp.ui @@ -43,7 +43,7 @@ false - HH HH; + >HH HH; diff --git a/common/udp.cpp b/common/udp.cpp index c2e1bfe..4d8585a 100644 --- a/common/udp.cpp +++ b/common/udp.cpp @@ -11,8 +11,10 @@ UdpConfigForm::UdpConfigForm(QWidget *parent) setupUi(this); } -UdpProtocol::UdpProtocol(Stream *parent) - : AbstractProtocol(parent) +UdpProtocol::UdpProtocol( + ProtocolList &frameProtoList, + OstProto::StreamCore *parent) + : AbstractProtocol(frameProtoList, parent) { if (configForm == NULL) 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) { // FIXME: multiple headers @@ -45,6 +54,17 @@ QString UdpProtocol::shortName() const 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 { return udp_fieldCount; @@ -98,26 +118,47 @@ QVariant UdpProtocol::fieldData(int index, FieldAttrib attrib, break; case udp_totLen: + { + switch(attrib) { case FieldName: return QString("Datagram Length"); case FieldValue: - return data.totlen(); - case FieldTextValue: - return QString("%1").arg(data.totlen()); + { + int totlen; + + totlen = data.is_override_totlen() ? + data.totlen() : + (protocolFramePayloadSize() + 8); + return totlen; + } case FieldFrameValue: { QByteArray fv; + int totlen; + totlen = data.is_override_totlen() ? + data.totlen() : + (protocolFramePayloadSize() + 8); fv.resize(2); - qToBigEndian((quint16) data.totlen(), (uchar*) fv.data()); + qToBigEndian((quint16) totlen, (uchar*) fv.data()); 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: break; } break; - + } case udp_cksum: switch(attrib) { @@ -173,7 +214,6 @@ QWidget* UdpProtocol::configWidget() void UdpProtocol::loadConfigWidget() { -#define uintToHexStr(num, str, size) QString().setNum(num, 16) configForm->leUdpSrcPort->setText(QString().setNum(data.src_port())); configForm->leUdpDstPort->setText(QString().setNum(data.dst_port())); diff --git a/common/udp.h b/common/udp.h index 4fe5147..5c40330 100644 --- a/common/udp.h +++ b/common/udp.h @@ -32,14 +32,20 @@ private: }; public: - UdpProtocol(Stream *parent = 0); + UdpProtocol(ProtocolList &frameProtoList, + OstProto::StreamCore *parent = 0); virtual ~UdpProtocol(); + static AbstractProtocol* createInstance( + ProtocolList &frameProtoList, + OstProto::StreamCore *streamCore = 0); + virtual void protoDataCopyInto(OstProto::Stream &stream); virtual void protoDataCopyFrom(const OstProto::Stream &stream); virtual QString name() const; virtual QString shortName() const; + virtual quint32 protocolId(ProtocolIdType type) const; virtual int fieldCount() const; diff --git a/common/udp.ui b/common/udp.ui index e8e29d3..c5c9862 100644 --- a/common/udp.ui +++ b/common/udp.ui @@ -62,7 +62,7 @@ false - HH HH; + >HH HH; @@ -97,5 +97,38 @@ - + + + cbUdpLengthOverride + toggled(bool) + leUdpLength + setEnabled(bool) + + + 59 + 63 + + + 149 + 63 + + + + + cbUdpCksumOverride + toggled(bool) + leUdpCksum + setEnabled(bool) + + + 55 + 106 + + + 158 + 106 + + + + diff --git a/common/vlan.ui b/common/vlan.ui index 0ae3be6..c35dc89 100644 --- a/common/vlan.ui +++ b/common/vlan.ui @@ -126,7 +126,7 @@ true - HH HH; + >HH HH; diff --git a/server/myservice.cpp b/server/myservice.cpp index 20bbda0..546fda5 100644 --- a/server/myservice.cpp +++ b/server/myservice.cpp @@ -4,17 +4,6 @@ #include #include -#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 #include #include @@ -25,62 +14,19 @@ StreamInfo::StreamInfo() { +#if 0 PbHelper pbh; - pbh.ForceSetSingularDefault(&mCore); - pbh.ForceSetSingularDefault(&mControl); - - 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); + pbh.ForceSetSingularDefault(mCore); + pbh.ForceSetSingularDefault(mControl); +#endif } 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, 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 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 pktLen, len = 0; // Decide a frame length based on length mode - switch(mCore.len_mode()) + switch(mCore->len_mode()) { case OstProto::StreamCore::e_fl_fixed: - pktLen = mCore.frame_len(); + pktLen = mCore->frame_len(); break; case OstProto::StreamCore::e_fl_inc: - pktLen = mCore.frame_len_min() + (n % - (mCore.frame_len_max() - mCore.frame_len_min() + 1)); + pktLen = mCore->frame_len_min() + (n % + (mCore->frame_len_max() - mCore->frame_len_min() + 1)); break; case OstProto::StreamCore::e_fl_dec: - pktLen = mCore.frame_len_max() - (n % - (mCore.frame_len_max() - mCore.frame_len_min() + 1)); + pktLen = mCore->frame_len_max() - (n % + (mCore->frame_len_max() - mCore->frame_len_min() + 1)); break; case OstProto::StreamCore::e_fl_random: - pktLen = mCore.frame_len_min() + (qrand() % - (mCore.frame_len_max() - mCore.frame_len_min() + 1)); + pktLen = mCore->frame_len_min() + (qrand() % + (mCore->frame_len_max() - mCore->frame_len_min() + 1)); break; default: qWarning("Unhandled len mode %d. Using default 64", - mCore.len_mode()); + mCore->len_mode()); pktLen = 64; break; } @@ -179,14 +81,11 @@ int StreamInfo::makePacket(uchar *buf, int bufMaxSize, int n) return 0; // FIXME: Calculated pktLen is an input to Payload Protocol - - // FIXME: checksums!!! - - for (int i = 0; i < mCore.frame_proto_size(); i++) + for (int i = 0; i < mCore->frame_proto_size(); i++) { QByteArray ba; - ba = protocolById(mCore.frame_proto(i))->protocolFrameValue(n); + ba = protocol(mCore->frame_proto(i))->protocolFrameValue(n); if (len + ba.size() < bufMaxSize) { memcpy(buf+len, ba.constData(), ba.size()); @@ -690,28 +589,28 @@ void PortInfo::update() for (int i = 0; i < streamList.size(); i++) { //_restart: - if (streamList[i]->mCore.is_enabled()) + if (streamList[i]->mCore->is_enabled()) { long numPackets, numBursts; long ibg, ipg; - switch (streamList[i]->mControl.unit()) + switch (streamList[i]->mControl->unit()) { case OstProto::StreamControl::e_su_bursts: - numBursts = streamList[i]->mControl.num_bursts(); - numPackets = streamList[i]->mControl.packets_per_burst(); - ibg = 1000000/streamList[i]->mControl.bursts_per_sec(); + numBursts = streamList[i]->mControl->num_bursts(); + numPackets = streamList[i]->mControl->packets_per_burst(); + ibg = 1000000/streamList[i]->mControl->bursts_per_sec(); ipg = 0; break; case OstProto::StreamControl::e_su_packets: numBursts = 1; - numPackets = streamList[i]->mControl.num_packets(); + numPackets = streamList[i]->mControl->num_packets(); ibg = 0; - ipg = 1000000/streamList[i]->mControl.packets_per_sec(); + ipg = 1000000/streamList[i]->mControl->packets_per_sec(); break; default: qWarning("Unhandled stream control unit %d", - streamList[i]->mControl.unit()); + streamList[i]->mControl->unit()); continue; } qDebug("numBursts = %ld, numPackets = %ld\n", @@ -773,7 +672,7 @@ void PortInfo::update() } } // for (numBursts) - switch(streamList[i]->mControl.next()) + switch(streamList[i]->mControl->next()) { case ::OstProto::StreamControl::e_nw_stop: goto _stop_no_more_pkts; @@ -798,7 +697,7 @@ void PortInfo::update() default: qFatal("---------- %s: Unhandled case (%d) -----------", - __FUNCTION__, streamList[i]->mControl.next() ); + __FUNCTION__, streamList[i]->mControl->next() ); break; } @@ -1378,18 +1277,7 @@ const ::OstProto::StreamIdList* request, s = response->add_stream(); - s->mutable_stream_id()->CopyFrom( - 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); - } + portInfo[portIdx]->streamList[streamIndex]->protoDataCopyInto(*s); } _exit: @@ -1494,17 +1382,8 @@ const ::OstProto::StreamConfigList* request, if (streamIndex < 0) continue; // TODO(LOW): Partial status of RPC - portInfo[portIdx]->streamList[streamIndex]->mCore.clear_frame_proto(); - portInfo[portIdx]->streamList[streamIndex]->mCore.MergeFrom( - 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)); - } + portInfo[portIdx]->streamList[streamIndex]->protoDataCopyFrom( + request->stream(i)); // TODO(LOW): fill-in response "Ack"???? } diff --git a/server/myservice.h b/server/myservice.h index 6a662fd..7a4f331 100644 --- a/server/myservice.h +++ b/server/myservice.h @@ -8,7 +8,7 @@ #endif #include "../common/protocol.pb.h" -#include "../common/abstractprotocol.h" +#include "../common/streambase.h" #include "abstracthost.h" #include #include @@ -30,31 +30,19 @@ class MyService; -class StreamInfo +class StreamInfo : public StreamBase { friend class MyService; friend class PortInfo; OstProto::StreamId mStreamId; - OstProto::StreamCore mCore; - OstProto::StreamControl mControl; - QList mProtocolList; public: StreamInfo(); ~StreamInfo(); 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); -public: - bool operator < (const StreamInfo &s) const - { return(mCore.ordinal() < s.mCore.ordinal()); } };