diff --git a/Makefile b/Makefile index 8b555c4..c285580 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ all: - $(MAKE) -C rpc install + $(MAKE) -C rpc $(MAKE) -C common $(MAKE) -C server $(MAKE) -C client @@ -11,4 +11,7 @@ clean: $(MAKE) -C client $@ qmake: - for %%d in (rpc common server client) cd %%d; qmake; cd..; + cd rpc && qmake && cd .. + cd common && qmake && cd .. + cd server && qmake && cd .. + cd client && qmake && cd .. diff --git a/client/dumpview.cpp b/client/dumpview.cpp index 79edab9..3393d5b 100644 --- a/client/dumpview.cpp +++ b/client/dumpview.cpp @@ -1,6 +1,7 @@ #include "dumpview.h" -//public: +//! \todo Enable Scrollbars + DumpView::DumpView(QWidget *parent) { int w, h; @@ -78,8 +79,8 @@ QModelIndex DumpView::indexAt( const QPoint &point ) const _exit: // Clear existing selection selrow = -1; -#endif +#endif return QModelIndex(); } @@ -148,55 +149,73 @@ void DumpView::selectionChanged( const QItemSelection &selected, void DumpView::populateDump(QByteArray &dump, int &selOfs, int &selSize, QModelIndex parent) { - // TODO(LOW): Assumption - only single selection - enforce/ensure this + // FIXME: Use new enum instead of Qt::UserRole + //! \todo (low): generalize this for any model not just our pkt model + + Q_ASSERT(!parent.isValid()); + + qDebug("!!!! %d $$$$", dump.size()); for(int i = 0; i < model()->rowCount(parent); i++) { QModelIndex index = model()->index(i, 0, parent); - if (model()->hasChildren(index)) - { - // Non Leaf + Q_ASSERT(index.isValid()); - // A non-leaf has no dump data of its own but is rather a - // container for its children. So we calculate ofs/size based - // on this fact - if (selectionModel()->isSelected(index)) + // Assumption: protocol data is in bytes (not bits) + qDebug("%d: %d bytes", i, model()->data(index, Qt::UserRole).toByteArray().size()); + dump.append(model()->data(index, Qt::UserRole).toByteArray()); + + } + + if (selectionModel()->selectedIndexes().size()) + { + int j, bits; + QModelIndex index; + + Q_ASSERT(selectionModel()->selectedIndexes().size() == 1); + index = selectionModel()->selectedIndexes().at(0); + + if (index.parent().isValid()) + { + // Field + + // SelOfs = SUM(protocol sizes before selected field's protocol) + + // SUM(field sizes before selected field) + + selOfs = 0; + j = index.parent().row() - 1; + while (j >= 0) { - selOfs = dump.size(); - populateDump(dump, selOfs, selSize, index); - selSize = dump.size() - selOfs; + selOfs += model()->data(index.parent().sibling(j,0), + Qt::UserRole).toByteArray().size(); + j--; } - else + + bits = 0; + j = index.row() - 1; + while (j >= 0) { - populateDump(dump, selOfs, selSize, index); + bits += model()->data(index.sibling(j,0), Qt::UserRole+1). + toInt(); + j--; } + selOfs += bits/8; + selSize = model()->data(index, Qt::UserRole).toByteArray().size(); } else { - // Leaf - if (selectionModel()->isSelected(index)) + // Protocol + selOfs = 0; + j = index.row() - 1; + while (j >= 0) { - int size, j; - - selOfs = dump.size(); - size = model()->data(index, Qt::UserRole).toByteArray().size(); - - // Take care of multiple indexes (2 or more) mapping onto - // same dump byte(s) - j = i-1; - while ((size == 0) && (j >= 0)) - { - size = model()->data(index.sibling(j,0), Qt::UserRole). - toByteArray().size(); - selOfs -= size; - j++; - } - selSize = size; + selOfs += model()->data(index.sibling(j,0), Qt::UserRole). + toByteArray().size(); + j--; } - dump.append(model()->data(index, Qt::UserRole).toByteArray()); - } - // FIXME: Use RawValueRole instead of UserRole + selSize = model()->data(index, Qt::UserRole).toByteArray().size(); + } } } @@ -208,7 +227,7 @@ void DumpView::paintEvent(QPaintEvent* event) QRect dumpRect = mDumpPaneTopRect; QRect asciiRect = mAsciiPaneTopRect; QPalette pal = palette(); - QByteArray data; + static QByteArray data; //QByteArray ba; int selOfs = -1, selSize; int curSelOfs, curSelSize; @@ -222,7 +241,10 @@ void DumpView::paintEvent(QPaintEvent* event) painter.fillRect(rect(), QBrush(QColor(Qt::white))); if (model()) + { + data.clear(); populateDump(data, selOfs, selSize); + } // display the offset, dump and ascii panes 8 + 8 bytes on a line for (int i = 0; i < data.size(); i+=16) @@ -289,7 +311,8 @@ void DumpView::paintEvent(QPaintEvent* event) QRect r; QString selectedAsciiStr, selectedDumpStr; - qDebug("dumpview::paintEvent - Highlighted"); + qDebug("dumpview::paintEvent - Highlighted (%d, %d)", + curSelOfs, curSelSize); // construct the dumpStr and asciiStr for (int k = curSelOfs; (k < (curSelOfs + curSelSize)); k++) diff --git a/client/hexlineedit.cpp b/client/hexlineedit.cpp index 85d5ccf..dcb6c20 100644 --- a/client/hexlineedit.cpp +++ b/client/hexlineedit.cpp @@ -39,15 +39,17 @@ void HexLineEdit::focusOutEvent( QFocusEvent *e ) QLineEdit::focusOutEvent( e ); emit focusOut(); #else +#define uintToHexStr(num, bytesize) \ + QString("%1").arg((num), (bytesize)*2 , 16, QChar('0')) + bool isOk; ulong num; - QString str; qDebug("before = %s\n", text().toAscii().data()); num = text().remove(QChar(' ')).toULong(&isOk, 16); - setText(uintToHexStr(num, str, 4)); + setText(uintToHexStr(num, 4)); qDebug("after = %s\n", text().toAscii().data()); - qDebug("after2 = %s\n", str.toAscii().data()); +#undef uintToHexStr #endif } diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp index 4e6fb64..0a0e0fb 100644 --- a/client/mainwindow.cpp +++ b/client/mainwindow.cpp @@ -1,6 +1,10 @@ #include "mainwindow.h" #include "portgrouplist.h" +#if 0 +#include "dbgthread.h" +#endif + #include "ui_about.h" PortGroupList *pgl; @@ -23,14 +27,16 @@ MainWindow::MainWindow(QWidget *parent) addDockWidget(Qt::TopDockWidgetArea, portsDock); connect(actionFileExit, SIGNAL(triggered()), this, SLOT(close())); +#if 0 + { + DbgThread *dbg = new DbgThread(pgl); + dbg->start(); + } +#endif } MainWindow::~MainWindow() { - delete statsDock; - delete portsDock; - delete statsWindow; - delete portsWindow; } void MainWindow::on_actionHelpAbout_triggered() diff --git a/client/ostinato.pro b/client/ostinato.pro index 9bb3cd2..707969e 100644 --- a/client/ostinato.pro +++ b/client/ostinato.pro @@ -1,10 +1,13 @@ TEMPLATE = app CONFIG += qt debug QT += network -INCLUDEPATH += "../rpc/" +INCLUDEPATH += "../rpc/" "../common/" LIBS += -lprotobuf +win32:LIBS += -L"../common/debug" -lostproto +unix: LIBS += -L"../common" -lostproto win32:LIBS += -L"../rpc/debug" -lpbrpc unix:LIBS += -L"../rpc" -lpbrpc +POST_TARGETDEPS += "../common/debug/libostproto.a" "../rpc/debug/libpbrpc.a" RESOURCES += ostinato.qrc HEADERS += \ dumpview.h \ @@ -50,10 +53,5 @@ SOURCES += \ streamlistdelegate.cpp \ streammodel.cpp -# Protocol Buffer Sources - -SOURCES += \ - ..\common\protocol.pb.cc - # TODO(LOW): Test only include(modeltest.pri) diff --git a/client/packetmodel.cpp b/client/packetmodel.cpp index a1d4b7f..f48f713 100644 --- a/client/packetmodel.cpp +++ b/client/packetmodel.cpp @@ -1,26 +1,36 @@ #include #include "packetmodel.h" -PacketModel::PacketModel(Stream *pStream, QObject *parent) +PacketModel::PacketModel(const QList &selectedProtocols, + QObject *parent) { - mpStream = pStream; + mSelectedProtocols = selectedProtocols; +} + +void PacketModel::setSelectedProtocols( + const QList &selectedProtocols) +{ + mSelectedProtocols = selectedProtocols; + reset(); } int PacketModel::rowCount(const QModelIndex &parent) const { IndexId parentId; + // qDebug("in %s", __FUNCTION__); + // Parent == Invalid i.e. Invisible Root. // ==> Children are Protocol (Top Level) Items if (!parent.isValid()) - return mpStream->numProtocols(); + return mSelectedProtocols.size(); // Parent - Valid Item parentId.w = parent.internalId(); switch(parentId.ws.type) { case ITYP_PROTOCOL: - return mpStream->protocol(parentId.ws.protocol)->numFields(); + return mSelectedProtocols.at(parentId.ws.protocol)->frameFieldCount(); case ITYP_FIELD: return 0; default: @@ -125,11 +135,13 @@ QVariant PacketModel::data(const QModelIndex &index, int role) const switch(id.ws.type) { case ITYP_PROTOCOL: - return QByteArray(); + qDebug("*** %d/%d", id.ws.protocol, mSelectedProtocols.size()); + return mSelectedProtocols.at(id.ws.protocol)-> + protocolFrameValue(); case ITYP_FIELD: - return mpStream->protocol(id.ws.protocol)->fieldRawValue( - index.row()); + return mSelectedProtocols.at(id.ws.protocol)->fieldData( + index.row(), AbstractProtocol::FieldFrameValue); default: qWarning("%s: Unhandled ItemType", __FUNCTION__); @@ -137,6 +149,25 @@ QVariant PacketModel::data(const QModelIndex &index, int role) const return QByteArray(); } + // FIXME: Use a new enum here instead of UserRole + if (role == (Qt::UserRole+1)) + { + switch(id.ws.type) + { + case ITYP_PROTOCOL: + return mSelectedProtocols.at(id.ws.protocol)-> + protocolFrameValue().size(); + + case ITYP_FIELD: + return mSelectedProtocols.at(id.ws.protocol)->fieldData( + index.row(), AbstractProtocol::FieldBitSize); + + default: + qWarning("%s: Unhandled ItemType", __FUNCTION__); + } + return QVariant(); + } + if (role != Qt::DisplayRole) return QVariant(); @@ -144,13 +175,14 @@ QVariant PacketModel::data(const QModelIndex &index, int role) const { case ITYP_PROTOCOL: return QString("%1 (%2)") - .arg(mpStream->protocol(id.ws.protocol)->protocolShortName()) - .arg(mpStream->protocol(id.ws.protocol)->protocolName()); + .arg(mSelectedProtocols.at(id.ws.protocol)->shortName()) + .arg(mSelectedProtocols.at(id.ws.protocol)->name()); case ITYP_FIELD: - return mpStream->protocol(id.ws.protocol)->fieldName(index.row()) + - QString(" : ") + - mpStream->protocol(id.ws.protocol)->fieldTextValue(index.row()); + return mSelectedProtocols.at(id.ws.protocol)->fieldData(index.row(), + AbstractProtocol::FieldName).toString() + QString(" : ") + + mSelectedProtocols.at(id.ws.protocol)->fieldData(index.row(), + AbstractProtocol::FieldTextValue).toString(); default: qWarning("%s: Unhandled ItemType", __FUNCTION__); diff --git a/client/packetmodel.h b/client/packetmodel.h index 1134a14..b268134 100644 --- a/client/packetmodel.h +++ b/client/packetmodel.h @@ -2,15 +2,16 @@ #define _PACKET_MODEL_H #include -#include "stream.h" - -#define NEW_IMPL // FIXME(HI) - Use this and remove old one +#include "abstractprotocol.h" class PacketModel: public QAbstractItemModel { public: - PacketModel(Stream *pStream, QObject *parent = 0); + PacketModel(const QList &selectedProtocols, + QObject *parent = 0); + void setSelectedProtocols( + const QList &selectedProtocols); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; @@ -33,89 +34,7 @@ private: } ws; } IndexId; - Stream *mpStream; - -#ifdef NEW_IMPL -// Nothing - required stuff is part of Stream Class -#else - QList mPacketProtocols; - - typedef struct - { - QString name; - QString abbr; - QString textValue; - } FieldInfo; - - typedef struct - { - uint handle; - QString name; - QString abbr; - QList fieldList; - } ProtocolInfo; - - //! Contains registration info (name, size etc) for all protocols - // and fields within the protocol - QList mProtocols; - void registerProto(uint handle, char *name, char *abbr); - void registerField(uint protoHandle, char *name, char *abbr); - - void registerFrameTypeProto(); - void registerVlanProto(); - void registerIpProto(); - void registerArpProto(); - void registerTcpProto(); - void registerUdpProto(); - void registerIcmpProto(); - void registerIgmpProto(); - void registerData(); - void registerInvalidProto(); - - void populatePacketProtocols(); - - int protoCount() const; - int fieldCount(int protocol) const; - QString protoName(int protocol) const; - QString fieldName(int protocol, int field) const; - QVariant fieldTextValue(int protocol, int field) const; - - QVariant ethField(int field, int role) const; - QVariant llcField(int field, int role) const; - QVariant snapField(int field, int role) const; - QVariant svlanField(int field, int role) const; - QVariant ipField(int field, int role) const; - QVariant tcpField(int field, int role) const; - QVariant udpField(int field, int role) const; - -// FIXME(HIGH): Is this how I want this? -#define PTYP_L2_NONE 1 -#define PTYP_L2_ETH_2 2 -#define PTYP_L2_802_3_RAW 3 - -#define PTYP_L2_802_3_LLC 4 -#define PTYP_L2_SNAP 5 - -#define PTYP_SVLAN 10 -#define PTYP_CVLAN 11 - -#define PTYP_L3_IP 30 -#define PTYP_L3_ARP 31 - -#define PTYP_L4_TCP 40 -#define PTYP_L4_UDP 41 -#define PTYP_L4_ICMP 42 -#define PTYP_L4_IGMP 43 - -#define PTYP_INVALID 0 -#define PTYP_DATA 0xFF - -#endif // NEW_IMPL - -#define FROL_NAME 1 -#define FROL_TEXT_VALUE 2 - -#define BASE_HEX 16 + QList mSelectedProtocols; }; #endif diff --git a/client/port.cpp b/client/port.cpp index 3ee571e..64c7865 100644 --- a/client/port.cpp +++ b/client/port.cpp @@ -32,7 +32,7 @@ void Port::updatePortConfig(OstProto::Port *port) void Port::updateStreamOrdinalsFromIndex() { for (int i=0; i < mStreams.size(); i++) - mStreams[i].setOrdinal(i); + mStreams[i]->setOrdinal(i); } void Port::reorderStreamsByOrdinals() @@ -42,12 +42,12 @@ void Port::reorderStreamsByOrdinals() bool Port::newStreamAt(int index) { - Stream s; + Stream *s = new Stream; if (index > mStreams.size()) return false; - s.setId(newStreamId()); + s->setId(newStreamId()); mStreams.insert(index, s); updateStreamOrdinalsFromIndex(); @@ -59,7 +59,7 @@ bool Port::deleteStreamAt(int index) if (index >= mStreams.size()) return false; - mStreams.removeAt(index); + delete mStreams.takeAt(index); updateStreamOrdinalsFromIndex(); return true; @@ -67,9 +67,9 @@ bool Port::deleteStreamAt(int index) bool Port::insertStream(uint streamId) { - Stream s; + Stream *s = new Stream; - s.setId(streamId); + s->setId(streamId); // FIXME(MED): If a stream with id already exists, what do we do? mStreams.append(s); @@ -88,7 +88,7 @@ bool Port::updateStream(uint streamId, OstProto::Stream *stream) for (i = 0; i < mStreams.size(); i++) { - if (streamId == mStreams[i].id()) + if (streamId == mStreams[i]->id()) goto _found; } @@ -98,7 +98,7 @@ bool Port::updateStream(uint streamId, OstProto::Stream *stream) _found: streamIndex = i; - mStreams[streamIndex].update(stream); + mStreams[streamIndex]->update(stream); reorderStreamsByOrdinals(); return true; @@ -114,7 +114,7 @@ void Port::getDeletedStreamsSinceLastSync( for (j = 0; j < mStreams.size(); j++) { - if (mLastSyncStreamList[i] == mStreams[j].id()) + if (mLastSyncStreamList[i] == mStreams[j]->id()) break; } @@ -140,7 +140,7 @@ void Port::getNewStreamsSinceLastSync( streamIdList.clear_stream_id(); for (int i = 0; i < mStreams.size(); i++) { - if (mLastSyncStreamList.contains(mStreams[i].id())) + if (mLastSyncStreamList.contains(mStreams[i]->id())) { // existing stream! continue; @@ -151,7 +151,7 @@ void Port::getNewStreamsSinceLastSync( OstProto::StreamId *s; s = streamIdList.add_stream_id(); - s->set_id(mStreams[i].id()); + s->set_id(mStreams[i]->id()); } } } @@ -167,8 +167,9 @@ void Port::getModifiedStreamsSinceLastSync( OstProto::Stream *s; s = streamConfigList.add_stream(); - mStreams[i].getConfig(mPortId, s); + mStreams[i]->getConfig(mPortId, *s); } + qDebug("Done %s", __FUNCTION__); } void Port::when_syncComplete() @@ -177,7 +178,7 @@ void Port::when_syncComplete() mLastSyncStreamList.clear(); for (int i=0; iid()); } void Port::updateStats(OstProto::PortStats *portStats) diff --git a/client/port.h b/client/port.h index c10eeb3..126b28d 100644 --- a/client/port.h +++ b/client/port.h @@ -23,7 +23,7 @@ private: QString mUserAlias; // user defined QList mLastSyncStreamList; - QList mStreams; // sorted by stream's ordinal value + QList mStreams; // sorted by stream's ordinal value uint newStreamId(); void updateStreamOrdinalsFromIndex(); @@ -65,7 +65,7 @@ public: //void setExclusive(bool flag); int numStreams() { return mStreams.size(); } - Stream& streamByIndex(int index) + Stream* streamByIndex(int index) { Q_ASSERT(index < mStreams.size()); return mStreams[index]; diff --git a/client/portgroup.cpp b/client/portgroup.cpp index 4630c72..f9f84d2 100644 --- a/client/portgroup.cpp +++ b/client/portgroup.cpp @@ -1,5 +1,4 @@ #include "portgroup.h" -#include "../common/protocol.h" #include @@ -400,7 +399,7 @@ _request: OstProto::StreamId *s; s = streamIdList.add_stream_id(); - s->set_id(mPorts[portIndex].streamByIndex(j).id()); + s->set_id(mPorts[portIndex].streamByIndex(j)->id()); } streamConfigList->Clear(); diff --git a/client/portstatsfilter.ui b/client/portstatsfilter.ui index 8423db3..af9af02 100644 --- a/client/portstatsfilter.ui +++ b/client/portstatsfilter.ui @@ -12,6 +12,9 @@ Select Ports + + :/icons/portstats_filter.png + @@ -121,7 +124,9 @@ lvSelected buttonBox - + + + buttonBox diff --git a/client/stream.cpp b/client/stream.cpp index 0afd8df..3af3509 100644 --- a/client/stream.cpp +++ b/client/stream.cpp @@ -3,951 +3,21 @@ #include "stream.h" -#include - -#define BASE_HEX 16 - -QString PayloadProtocol::fieldTextValue(int index) -{ - int len; - quint32 pat; - QString textValue; - - if (parentStream) - { - qDebug("phs = %d", parentStream->protocolHeaderSize()); - len = parentStream->frameLen() - parentStream->protocolHeaderSize(); - pat = parentStream->pattern(); - } - else - { - len = 1500; // FIXME(HI): testing only - pat = 0x0a0b0c0d; - } - - // Make a larger string and then resize to the correct size to - // take care of the case where len is not a multiple of pattern size - if (len > 0) - { - // TODO(LOW): allow non-4byte patterns!!! - int w = 4; // data pattern size - - for (int i = 0; i < (len/w + 1); i++) - textValue.append(QString("%1").arg( - pat, w*2, BASE_HEX, QChar('0'))); - textValue.resize(len); - } - - return textValue; -} - -QByteArray PayloadProtocol::fieldRawValue(int index) -{ - int len; - quint32 pat; - QByteArray rawValue; - - if (parentStream) - { - qDebug("phs = %d", parentStream->protocolHeaderSize()); - len = parentStream->frameLen() - parentStream->protocolHeaderSize(); - pat = parentStream->pattern(); - } - else - { - len = 1500; // FIXME(HI): testing only - pat = 0x0a0b0c0d; - } - - // Make a larger byteArray and then resize to the correct size to - // take care of the case where len is not a multiple of pattern size - if (len > 0) - { - // TODO(LOW): allow non-4byte patterns!!! - int w = 4; // data pattern size - - rawValue.resize(len + 4); - for (int i = 0; i < (len/w + 1); i++) - qToBigEndian(pat, (uchar*) (rawValue.data() + i*sizeof(pat))); - rawValue.resize(len); - } - - return rawValue; -} - -QString MacProtocol::fieldName(int index) -{ - QString name; - - switch(index) - { - case 0: - name = QString("Destination Mac Address"); - break; - case 1: - name = QString("Source Mac Address"); - break; - default: - name = QString(); - break; - } - - return name; -} - -QString MacProtocol::fieldTextValue(int index) -{ - QString textValue; - - // FIXME(MED): Mac Addr formatting - switch(index) - { - case 0: - textValue = QString("%1"). - arg(dstMac(), 12, BASE_HEX, QChar('0')); - break; - case 1: - textValue = QString("%1"). - arg(srcMac(), 12, BASE_HEX, QChar('0')); - break; - default: - textValue = QString(); - break; - } - - return textValue; -} - -QByteArray MacProtocol::fieldRawValue(int index) -{ - QByteArray rawValue; - - switch(index) - { - case 0: - rawValue.resize(8); - qToBigEndian(dstMac(), (uchar *) rawValue.data()); - rawValue.remove(0, 2); - qDebug("dstMac(%d): %s", rawValue.size(), rawValue.toHex().constData()); - break; - case 1: - rawValue.resize(8); - qToBigEndian(srcMac(), (uchar *) rawValue.data()); - rawValue.remove(0, 2); - qDebug("srcMac(%d): %s", rawValue.size(), rawValue.toHex().constData()); - break; - default: - break; - } - - return rawValue; -} - -QString LlcProtocol::fieldName(int index) -{ - QString name; - - switch(index) - { - case 0: - name = QString("DSAP"); - break; - case 1: - name = QString("SSAP"); - break; - case 2: - name = QString("Control"); - break; - default: - name = QString(); - break; - } - - return name; -} - -QString LlcProtocol::fieldTextValue(int index) -{ - QString textValue; - - switch(index) - { - case 0: - textValue = QString("0x%1"). - arg(dsap(), 2, BASE_HEX, QChar('0')); - break; - case 1: - textValue = QString("0x%1"). - arg(ssap(), 2, BASE_HEX, QChar('0')); - break; - case 2: - textValue = QString("0x%1"). - arg(ctl(), 2, BASE_HEX, QChar('0')); - break; - default: - textValue = QString(); - break; - } - - return textValue; -} - -QByteArray LlcProtocol::fieldRawValue(int index) -{ - QByteArray rawValue; - - switch(index) - { - case 0: - rawValue.resize(1); - rawValue[0] = dsap(); - break; - case 1: - rawValue.resize(1); - rawValue[0] = ssap(); - break; - case 2: - rawValue.resize(1); - rawValue[0] = ctl(); - break; - default: - break; - } - - return rawValue; -} - -QString SnapProtocol::fieldName(int index) -{ - QString name; - - switch(index) - { - case 0: - name = QString("OUI"); - break; - default: - name = QString(); - break; - } - - return name; -} - -QString SnapProtocol::fieldTextValue(int index) -{ - QString textValue; - - switch(index) - { - case 0: - textValue = QString("0x%1"). - arg(oui(), 6, BASE_HEX, QChar('0')); - break; - default: - textValue = QString(); - break; - } - - return textValue; -} - -QByteArray SnapProtocol::fieldRawValue(int index) -{ - QByteArray rawValue; - - switch(index) - { - case 0: - rawValue.resize(4); - qToBigEndian(oui(), (uchar *) rawValue.data()); - rawValue.remove(0, 1); - break; - default: - break; - } - - return rawValue; -} - -QString Eth2Protocol::fieldName(int index) -{ - QString name; - - switch(index) - { - case 0: - name = QString("Type"); - break; - default: - name = QString(); - break; - } - return name; -} - -QString Eth2Protocol::fieldTextValue(int index) -{ - QString textValue; - - switch(index) - { - case 0: - textValue = QString("0x%1"). - arg(type(), 4, BASE_HEX, QChar('0')); - break; - default: - textValue = QString(); - break; - } - return textValue; -} - -QByteArray Eth2Protocol::fieldRawValue(int index) -{ - QByteArray rawValue; - - switch(index) - { - case 0: - rawValue.resize(2); - qToBigEndian(type(), (uchar*) rawValue.data()); - break; - default: - break; - } - - return rawValue; -} - -QString Dot3Protocol::fieldName(int index) -{ - QString name; - - switch(index) - { - case 0: - name = QString("Length"); - break; - default: - name = QString(); - break; - } - return name; -} - -QString Dot3Protocol::fieldTextValue(int index) -{ - if (parentStream) - return QString("%1").arg(parentStream->frameLen()); - else - return QString("00"); -} - -QByteArray Dot3Protocol::fieldRawValue(int index) -{ - QByteArray ba; - - if (parentStream) - qToBigEndian((quint16) parentStream->frameLen(), (uchar*) ba.data()); - else - { - ba.resize(2); - ba[0] = ba[1] = 0; - } - - return ba; -} - -int VlanProtocol::numFields() -{ - if (isSingleTagged()) - return 4; - else if (isDoubleTagged()) - return 8; - else - { - Q_ASSERT(isUntagged()); - return 0; - } -} - -QString VlanProtocol::fieldName(int index) -{ - QString name; - - if (isDoubleTagged()) - { - switch(index) - { - case 0: - name = QString("TPID"); - break; - case 1: - name = QString("PCP"); - break; - case 2: - name = QString("DE"); - break; - case 3: - name = QString("VlanId"); - break; - default: - index -= 4; - goto _single_tag; - } - - goto _exit; - } - -_single_tag: - switch(index) - { - case 0: - name = QString("TPID"); - break; - case 1: - name = QString("Priority"); - break; - case 2: - name = QString("CFI"); - break; - case 3: - name = QString("VlanId"); - break; - default: - name = QString(); - break; - } - -_exit: - return name; -} - -QString VlanProtocol::fieldTextValue(int index) -{ - QString textValue; - - if (isDoubleTagged()) - { - switch(index) - { - case 0: - textValue = QString("0x%1"). - arg(stpid(), 4, BASE_HEX, QChar('0')); - break; - case 1: - textValue = QString("%1"). - arg(svlanPrio()); - break; - case 2: - textValue = QString("%1"). - arg(svlanCfi()); - break; - case 3: - textValue = QString("%1"). - arg(svlanId()); - break; - default: - index -= 4; - goto _single_tag; - } - - goto _exit; - } - -_single_tag: - switch(index) - { - case 0: - textValue = QString("0x%1"). - arg(ctpid(), 4, BASE_HEX, QChar('0')); - break; - case 1: - textValue = QString("%1"). - arg(cvlanPrio()); - break; - case 2: - textValue = QString("%1"). - arg(cvlanCfi()); - break; - case 3: - textValue = QString("%1"). - arg(cvlanId()); - break; - default: - textValue = QString(); - break; - } - -_exit: - return textValue; -} - -QByteArray VlanProtocol::fieldRawValue(int index) -{ - QByteArray rawValue; - - if (isDoubleTagged()) - { - switch(index) - { - case 0: - rawValue.resize(2); - qToBigEndian(stpid(), (uchar*) rawValue.data()); - break; - case 1: - rawValue.resize(2); - qToBigEndian((svlanPrio() << 13) | (svlanCfi() < 12) | svlanId(), - (uchar*) rawValue.data()); - break; - case 2: - // Combined with prio above - break; - case 3: - // Combined with prio above - break; - default: - index -= 4; - goto _single_tag; - } - - goto _exit; - } - -_single_tag: - switch(index) - { - case 0: - rawValue.resize(2); - qToBigEndian(ctpid(), (uchar*) rawValue.data()); - break; - case 1: - rawValue.resize(2); - qToBigEndian((cvlanPrio() << 13) | (cvlanCfi() < 12) | cvlanId(), - (uchar*) rawValue.data()); - break; - case 2: - // Combined with prio above - break; - case 3: - // Combined with prio above - break; - default: - break; - } - -_exit: - return rawValue; -} - -QString IpProtocol::fieldName(int index) -{ - QString name; - - switch(index) - { - case 0: - name = QString("Version"); - break; - case 1: - name = QString("Header Length"); - break; - case 2: - name = QString("TOS/DSCP"); - break; - case 3: - name = QString("Total Length"); - break; - case 4: - name = QString("ID"); - break; - case 5: - name = QString("Flags"); - break; - case 6: - name = QString("Fragment Offset"); - break; - case 7: - name = QString("TTL"); - break; - case 8: - name = QString("Protocol Type"); - break; - case 9: - name = QString("Checksum"); - break; - case 10: - name = QString("Source IP"); - break; - case 11: - name = QString("Destination IP"); - break; - default: - name = QString(); - } - - return name; -} - -QString IpProtocol::fieldTextValue(int index) -{ - QString textValue; - - switch(index) - { - case 0: - textValue = QString("%1"). - arg(ver()); - break; - case 1: - textValue = QString("%1"). - arg(hdrLen()); - break; - case 2: - textValue = QString("0x%1"). - arg(tos(), 2, BASE_HEX, QChar('0')); - break; - case 3: - textValue = QString("%1"). - arg(totLen()); - break; - case 4: - textValue = QString("0x%1"). - arg(id(), 2, BASE_HEX, QChar('0')); - break; - case 5: - textValue = QString("0x%1"). - arg(flags(), 2, BASE_HEX, QChar('0')); // FIXME(MED): bitmap? - break; - case 6: - textValue = QString("%1"). - arg(fragOfs()); - break; - case 7: - textValue = QString("%1"). - arg(ttl()); - break; - case 8: - textValue = QString("0x%1"). - arg(proto(), 2, BASE_HEX, QChar('0')); - break; - case 9: - textValue = QString("0x%1"). - arg(cksum(), 4, BASE_HEX, QChar('0')); - break; - case 10: - textValue = QHostAddress(srcIp()).toString(); - break; - case 11: - textValue = QHostAddress(dstIp()).toString(); - break; - default: - textValue = QString(); - } - - return textValue; -} - -QByteArray IpProtocol::fieldRawValue(int index) -{ - QByteArray rawValue; - - switch(index) - { - case 0: - rawValue.resize(1); - //qToBigEndian((ver() << 4) | hdrLen(), (uchar*) rawValue.data()); - rawValue[0]=(ver() << 4) | hdrLen(); - break; - case 1: - // Combined with previous 4 bits of ver!! - break; - case 2: - rawValue.resize(1); - qToBigEndian(tos(), (uchar*) rawValue.data()); - break; - case 3: - rawValue.resize(2); - qToBigEndian(totLen(), (uchar*) rawValue.data()); - break; - case 4: - rawValue.resize(2); - qToBigEndian(id(), (uchar*) rawValue.data()); - break; - case 5: - rawValue.resize(2); - qToBigEndian((quint16)((flags() << 13) | fragOfs()), - (uchar*) rawValue.data()); - break; - case 6: - // Combined with previous 3 bits of flags!! - break; - case 7: - rawValue.resize(1); - qToBigEndian(ttl(), (uchar*) rawValue.data()); - break; - case 8: - rawValue.resize(1); - qToBigEndian(proto(), (uchar*) rawValue.data()); - break; - case 9: - rawValue.resize(2); - qToBigEndian(cksum(), (uchar*) rawValue.data()); - break; - case 10: - rawValue.resize(4); - qToBigEndian(srcIp(), (uchar*) rawValue.data()); - break; - case 11: - rawValue.resize(4); - qToBigEndian(dstIp(), (uchar*) rawValue.data()); - break; - default: - break; - } - - return rawValue; -} - -QString TcpProtocol::fieldName(int index) -{ - QString name; - - switch(index) - { - case 0: - name = QString("Source Port"); - break; - case 1: - name = QString("Destination Port"); - break; - case 2: - name = QString("Seq Number"); - break; - case 3: - name = QString("Ack Number"); - break; - case 4: - name = QString("Header Length"); - break; - case 5: - name = QString("Reserved"); - break; - case 6: - name = QString("Flags"); - break; - case 7: - name = QString("Window"); - break; - case 8: - name = QString("Checksum"); - break; - case 9: - name = QString("Urgent Pointer"); - break; - default: - name = QString(); - } - - return name; -} - -QString TcpProtocol::fieldTextValue(int index) -{ - QString textValue; - - switch(index) - { - case 0: - textValue = QString("%1"). - arg(srcPort()); - break; - case 1: - textValue = QString("%1"). - arg(dstPort()); - break; - case 2: - textValue = QString("%1"). - arg(seqNum()); - break; - case 3: - textValue = QString("%1"). - arg(ackNum()); - break; - case 4: - textValue = QString("%1"). - arg(hdrLen()); - break; - case 5: - textValue = QString("%1"). - arg(rsvd()); - break; - case 6: - textValue = QString("0x%1"). - arg(flags(), 2, BASE_HEX, QChar('0')); - break; - case 7: - textValue = QString("%1"). - arg(window(), 2, BASE_HEX, QChar('0')); - break; - case 8: - textValue = QString("0x%1"). - arg(cksum(), 4, BASE_HEX, QChar('0')); - break; - case 9: - textValue = QString("%1"). - arg(urgPtr()); - break; - default: - textValue = QString(); - } - - return textValue; -} - -QByteArray TcpProtocol::fieldRawValue(int index) -{ - QByteArray rawValue; - - switch(index) - { - case 0: - rawValue.resize(2); - qToBigEndian(srcPort(), (uchar*) rawValue.data()); - break; - case 1: - rawValue.resize(2); - qToBigEndian(dstPort(), (uchar*) rawValue.data()); - break; - case 2: - rawValue.resize(4); - qToBigEndian(seqNum(), (uchar*) rawValue.data()); - break; - case 3: - rawValue.resize(4); - qToBigEndian(ackNum(), (uchar*) rawValue.data()); - break; - case 4: - rawValue.resize(1); - rawValue[0] = (hdrLen() << 4) | rsvd(); - break; - case 5: - // Combined with hdrLen above - break; - case 6: - rawValue.resize(1); - rawValue[0] = flags(); - break; - case 7: - rawValue.resize(2); - qToBigEndian(window(), (uchar*) rawValue.data()); - break; - case 8: - rawValue.resize(2); - qToBigEndian(cksum(), (uchar*) rawValue.data()); - break; - case 9: - rawValue.resize(2); - qToBigEndian(urgPtr(), (uchar*) rawValue.data()); - break; - default: - break; - } - - return rawValue; -} - -QString UdpProtocol::fieldName(int index) -{ - QString name; - - switch(index) - { - case 0: - name = QString("Source Port"); - break; - case 1: - name = QString("Destination Port"); - break; - case 2: - name = QString("Total Length"); - break; - case 3: - name = QString("Checksum"); - break; - default: - name = QString(); - } - - return name; -} - -QString UdpProtocol::fieldTextValue(int index) -{ - QString textValue; - - switch(index) - { - case 0: - textValue = QString("%1"). - arg(srcPort()); - break; - case 1: - textValue = QString("%1"). - arg(dstPort()); - break; - case 2: - textValue = QString("%1"). - arg(totLen()); - break; - case 3: - textValue = QString("0x%1"). - arg(cksum(), 4, BASE_HEX, QChar('0')); - break; - default: - textValue = QString(); - } - - return textValue; -} - -QByteArray UdpProtocol::fieldRawValue(int index) -{ - QByteArray rawValue; - - switch(index) - { - case 0: - rawValue.resize(2); - qToBigEndian(srcPort(), (uchar*) rawValue.data()); - break; - case 1: - rawValue.resize(2); - qToBigEndian(dstPort(), (uchar*) rawValue.data()); - break; - case 2: - rawValue.resize(2); - qToBigEndian(totLen(), (uchar*) rawValue.data()); - break; - case 3: - rawValue.resize(2); - qToBigEndian(cksum(), (uchar*) rawValue.data()); - break; - default: - break; - } - - return rawValue; -} - +#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; @@ -958,274 +28,148 @@ Stream::Stream() // mCore->set_port_id(0xFFFFFFFF); // mCore->set_stream_id(mId); - mUnknown = new UnknownProtocol; - mPayload = new PayloadProtocol(); //FIXME(MED): need to pass parent stream + mProtocolList.append(new MacProtocol); + mProtocolList.append(new PayloadProtocol(this)); - mMac = new MacProtocol; - - mLlc = new LlcProtocol; - mSnap = new SnapProtocol; - mEth2 = new Eth2Protocol; - mDot3 = new Dot3Protocol(); // FIXME(MED): need to pass parent stream - mVlan = new VlanProtocol; - - mIp = new IpProtocol; - mArp = new ArpProtocol; - - mTcp = new TcpProtocol; - mUdp = new UdpProtocol; - mIcmp = new IcmpProtocol; - mIgmp = new IgmpProtocol; + // 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->add_frame_proto(51); // MAC (FIXME: hardcoding) + mCore->add_frame_proto(52); // Payload (FIXME: hardcoding) } -void Stream::getConfig(uint portId, OstProto::Stream *s) +Stream::~Stream() { - s->mutable_stream_id()->set_id(mId); + for (int i = 0; i < mProtocolList.size(); i++) + delete mProtocolList.at(i); - s->mutable_core()->CopyFrom(*mCore); - s->mutable_control()->CopyFrom(*mControl); + delete mControl; + delete mCore; +} - mMac->getConfig(s->mutable_mac()); - mMac->getConfig(s->mutable_mac()); - mLlc->getConfig(s->mutable_llc()); - mSnap->getConfig(s->mutable_snap()); - mEth2->getConfig(s->mutable_eth2()); - mVlan->getConfig(s->mutable_vlan()); +void Stream::protoDataCopyFrom(Stream& stream) +{ + OstProto::Stream data; - mIp->getConfig(s->mutable_ip()); - mArp->getConfig(s->mutable_arp()); + stream.getConfig(0, data); + update(&data); +} - mTcp->getConfig(s->mutable_tcp()); - mUdp->getConfig(s->mutable_udp()); - mIcmp->getConfig(s->mutable_icmp()); - mIgmp->getConfig(s->mutable_igmp()); +void Stream::loadProtocolWidgets() +{ + for (int i=0; i < mProtocolList.size(); i++) + mProtocolList[i]->loadConfigWidget(); +} + +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->MergeFrom(stream->core()); - mControl->MergeFrom(stream->control()); - mMac->update(stream->mac()); - - mLlc->update(stream->llc()); - mSnap->update(stream->snap()); - mEth2->update(stream->eth2()); - mVlan->update(stream->vlan()); - - mIp->update(stream->ip()); - mArp->update(stream->arp()); - - //mTcp->update(stream->tcp()); - mTcp->setProtoData(stream->mutable_tcp()); - mUdp->update(stream->udp()); - mIcmp->update(stream->icmp()); - mIgmp->update(stream->igmp()); - - // FIXME(MED): Re-eval why not store complete OstProto::Stream - // instead of components - return true; - } -// FIXME(HIGH): Replace this by some Protocol Registration mechanism at Init -#define PTYP_L2_NONE 1 -#define PTYP_L2_ETH_2 2 -#define PTYP_L2_802_3_RAW 3 - -#define PTYP_L2_802_3_LLC 4 -#define PTYP_L2_SNAP 5 - -#define PTYP_VLAN 10 - -#define PTYP_L3_IP 30 -#define PTYP_L3_ARP 31 - -#define PTYP_L4_TCP 40 -#define PTYP_L4_UDP 41 -#define PTYP_L4_ICMP 42 -#define PTYP_L4_IGMP 43 - -#define PTYP_INVALID 0 -#define PTYP_DATA 0xFF - -void Stream::updateSelectedProtocols() { - int proto; + mCore->clear_frame_proto(); + mCore->MergeFrom(stream->core()); + mControl->MergeFrom(stream->control()); - // Clear the selected protocols list - selectedProtocols.clear(); - - // Check and populate L2 Protocol - switch(frameType()) + // 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++) { - case Stream::e_ft_none: - proto = PTYP_L2_NONE; - break; - - case Stream::e_ft_eth_2: - selectedProtocols.append(PTYP_L2_NONE); - proto = PTYP_L2_ETH_2; - break; - - case Stream::e_ft_802_3_raw: - selectedProtocols.append(PTYP_L2_NONE); - proto = PTYP_L2_802_3_RAW; - break; - - case Stream::e_ft_802_3_llc: - selectedProtocols.append(PTYP_L2_NONE); - proto = PTYP_L2_802_3_LLC; - break; - - case Stream::e_ft_snap: - selectedProtocols.append(PTYP_L2_NONE); - selectedProtocols.append(PTYP_L2_802_3_LLC); - proto = PTYP_L2_SNAP; - break; - - default: - qDebug("%s: Unsupported frametype %d", __FUNCTION__, - frameType()); - proto = PTYP_INVALID; + mProtocolList[i]->protoDataCopyFrom(*stream); } - selectedProtocols.append(proto); - // Check and populate VLANs, if present - if (!vlan()->isUntagged()) - selectedProtocols.append(PTYP_VLAN); + // FIXME(MED): Re-eval why not store complete OstProto::Stream + // instead of components + return true; +} - // Check and populate L3 protocols - switch (l3Proto()) - { - case Stream::e_l3_none : - goto _data; - break; +QList Stream::frameProtocol() +{ + QList protocolList; - case Stream::e_l3_ip : - proto = PTYP_L3_IP; - break; + for (int i = 0; i < mCore->frame_proto_size(); i++) + protocolList.append(mCore->frame_proto(i)); - case Stream::e_l3_arp: - proto = PTYP_L3_ARP; - break; + return protocolList; +} - default: - qDebug("%s: Unsupported L3 Proto %d", __FUNCTION__, - l3Proto()); - proto = PTYP_INVALID; - } - selectedProtocols.append(proto); - - // Check and populate L4 protocol - switch(l4Proto()) - { - case Stream::e_l4_none: - goto _data; - break; - case Stream::e_l4_tcp: - proto = PTYP_L4_TCP; - break; - case Stream::e_l4_udp: - proto = PTYP_L4_UDP; - break; - case Stream::e_l4_icmp: - proto = PTYP_L4_ICMP; - break; - case Stream::e_l4_igmp: - proto = PTYP_L4_IGMP; - break; - default: - qDebug("%s: Unsupported L4 Proto %d", __FUNCTION__, - l4Proto()); - proto = PTYP_INVALID; - }; - selectedProtocols.append(proto); - -_data: - - mProtocolHeaderSize = 0; -#ifndef SRIVATSP -#if 0 - for (int i = 0; i < selectedProtocols.size(); i++) - mProtocolHeaderSize += protocol(i)->protocolRawValue().size(); -#endif -#endif - selectedProtocols.append(PTYP_DATA); +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() { - updateSelectedProtocols(); // FIXME(HI): shd not happen everytime - return mProtocolHeaderSize; + int size = 0; + + for (int i = 0; i < mCore->frame_proto_size(); i++) + size += protocolById(mCore->frame_proto(i))-> + protocolFrameValue().size(); + + return size; } -int Stream::numProtocols() +AbstractProtocol* Stream::protocolById(int id) { - updateSelectedProtocols(); // FIXME(HI): shd not happen everytime - return selectedProtocols.size(); -} - -#if 0 -int Stream::protocolId(int index) -{ - updateSelectedProtocols(); // FIXME(HI): shd not happen everytime - if (index < selectedProtocols.size()) - return selectedProtocols.at(index); - else - return -1; -} -int Stream::protocolIndex(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 - -AbstractProtocol* Stream::protocol(int index) -{ - int id; - - updateSelectedProtocols(); // FIXME(HI): shd not happen everytime - - id = selectedProtocols.at(index); - - switch(id) - { - case PTYP_L2_NONE: - return mac(); - case PTYP_L2_ETH_2: - return eth2(); - case PTYP_L2_802_3_RAW: - return dot3(); - - case PTYP_L2_802_3_LLC: - return llc(); - - case PTYP_L2_SNAP: - return snap(); - - case PTYP_VLAN: - return vlan(); - - case PTYP_L3_IP: - return ip(); - case PTYP_L3_ARP: - return arp(); - - case PTYP_L4_TCP: - return tcp(); - case PTYP_L4_UDP: - return udp(); - case PTYP_L4_ICMP: - return icmp(); - case PTYP_L4_IGMP: - return igmp(); - - case PTYP_INVALID: - return mUnknown; - case PTYP_DATA: - return mPayload; + case 130: + return mProtocolList.at(6); + case 140: + return mProtocolList.at(7); + case 141: + return mProtocolList.at(8); default: - return mUnknown; + return NULL; } } - diff --git a/client/stream.h b/client/stream.h index 434c008..c4884d4 100644 --- a/client/stream.h +++ b/client/stream.h @@ -6,10 +6,7 @@ #include #include #include "../common/protocol.pb.h" - -class StreamConfigDialog; -class StreamModel; -class PacketModel; +#include "../common/abstractprotocol.h" // Convenience Defines FIXME #define IP_PROTO_ICMP 0x01 @@ -17,864 +14,19 @@ class PacketModel; #define IP_PROTO_TCP 0x06 #define IP_PROTO_UDP 0x11 - -class Stream; - -class AbstractProtocol -{ - // TODO(LOW) -public: - /*! - Subclasses should return reference to their protocol specific - ::google::protobuf::Message - */ - virtual ::google::protobuf::Message& data() = 0; - /*! Subclasses can directly use this method. No need for overload */ - void getConfig(::google::protobuf::Message *msg) - { msg->CopyFrom(data()); } - - bool setProtoData(::google::protobuf::Message *msg) - { data().MergeFrom(*msg); return true; } - - virtual QString protocolName() - { return QString("AbstractProtocol"); } - virtual QString protocolShortName() - { return QString("AbsProto"); } - virtual int numFields() - { return 1; } - QByteArray protocolRawValue() - { - QByteArray ba; -#ifndef SRIVATSP -#else - for (int i=0; i < numFields(); i++) - ba.append(fieldRawValue(i)); -#endif - return ba; - } - virtual QString fieldName(int index) - { return QString("AbstractField"); } - virtual QString fieldTextValue(int index) - { return QString("AbstractFieldValue"); } - virtual QByteArray fieldRawValue(int index) - { return QByteArray(4, '\0'); } -}; - -class UnknownProtocol: public AbstractProtocol -{ - OstProto::Ack d; // FIXME(HI): replace 'Ack' with something else - -public: - virtual ~UnknownProtocol() {} - - virtual ::google::protobuf::Message& data() { return d; } - - virtual QString protocolName() - { return QString("UnknownProtocol"); } - QString protocolShortName() - { return QString("???Proto"); } - int numFields() - { return 1; } - QString fieldName(int index) - { return QString("UnknownField"); } - QString fieldTextValue(int index) - { return QString("UnknownFieldValue"); } - QByteArray fieldRawValue(int index) - { return QByteArray(); } -}; - -class PayloadProtocol: public AbstractProtocol -{ - Stream *parentStream; - OstProto::Ack d; // FIXME(HI): move payload related vars from - // stream into here - -public: - PayloadProtocol (Stream *stream = NULL) { parentStream = stream; } - virtual ~PayloadProtocol() {} - - virtual ::google::protobuf::Message& data() { return d; } - - virtual QString protocolName() - { return QString("Payload Data"); } - QString protocolShortName() - { return QString("DATA"); } - int numFields() - { return 1; } - QString fieldName(int index) - { return QString("Data"); } - QString fieldTextValue(int index); - QByteArray fieldRawValue(int index); -}; - -class MacProtocol : public AbstractProtocol -{ -private: - OstProto::Mac d; - -public: - enum MacAddrMode { - MacAddrFixed, - MacAddrInc, - MacAddrDec - }; - virtual ~MacProtocol() {} - virtual ::google::protobuf::Message& data() {return d;} - - bool update(OstProto::Mac mac) { d.MergeFrom(mac); return true; } - - // Dst Mac - quint64 dstMac() - { return d.dst_mac(); } - - bool setDstMac(quint64 dstMac) - { d.set_dst_mac(dstMac); return true; } - - MacAddrMode dstMacMode() - { return (MacAddrMode) d.dst_mac_mode(); } - bool setDstMacMode(MacAddrMode dstMacMode) - { d.set_dst_mac_mode((OstProto::Mac::MacAddrMode)dstMacMode); return true; } - - quint16 dstMacCount() - { return d.dst_mac_count(); } - bool setDstMacCount(quint16 dstMacCount) - { d.set_dst_mac_count(dstMacCount); return true; } - - quint16 dstMacStep() - { return d.dst_mac_step(); } - bool setDstMacStep(quint16 dstMacStep) - { d.set_dst_mac_step(dstMacStep); return true; } - - // Src Mac - quint64 srcMac() - { return d.src_mac(); } - - bool setSrcMac(quint64 srcMac) - { d.set_src_mac(srcMac); return true; } - - MacAddrMode srcMacMode() - { return (MacAddrMode) d.src_mac_mode(); } - bool setSrcMacMode(MacAddrMode srcMacMode) - { d.set_src_mac_mode((OstProto::Mac::MacAddrMode)srcMacMode); return true; } - - quint16 srcMacCount() - { return d.src_mac_count(); } - bool setSrcMacCount(quint16 srcMacCount) - { d.set_src_mac_count(srcMacCount); return true; } - - quint16 srcMacStep() - { return d.src_mac_step(); } - bool setSrcMacStep(quint16 srcMacStep) - { d.set_src_mac_step(srcMacStep); return true; } - - - virtual QString protocolName() - { return QString("Media Access Control"); } - QString protocolShortName() - { return QString("MAC"); } - int numFields() - { return 2; } - QString fieldName(int index); - QString fieldTextValue(int index); - QByteArray fieldRawValue(int index); -}; - -class LlcProtocol : public AbstractProtocol -{ -private: - OstProto::Llc d; - -public: - virtual ~LlcProtocol() {} - virtual ::google::protobuf::Message& data() {return d;} - - bool update(OstProto::Llc llc) { d.MergeFrom(llc); return true; } - - quint8 dsap() - { return d.dsap(); } - bool setDsap(quint8 dsap) - { d.set_dsap(dsap); return true; } - - quint8 ssap() - { return d.ssap(); } - bool setSsap(quint8 ssap) - { d.set_ssap(ssap); return true; } - - quint8 ctl() - { return d.ctl(); } - bool setCtl(quint8 ctl) - { d.set_ctl(ctl); return true; } - - - virtual QString protocolName() - { return QString("802.3 Logical Link Control"); } - QString protocolShortName() - { return QString("LLC"); } - int numFields() - { return 3; } - QString fieldName(int index); - QString fieldTextValue(int index); - QByteArray fieldRawValue(int index); -}; - -class SnapProtocol : public AbstractProtocol -{ -private: - OstProto::Snap d; - -public: - virtual ~SnapProtocol() {} - virtual ::google::protobuf::Message& data() {return d;} - bool update(OstProto::Snap snap) { d.MergeFrom(snap); return true; } - - quint32 oui() - { return d.oui(); } - bool setOui(quint32 oui) - { d.set_oui(oui); return true; } - -// "Type" field: use from eth2 -#if 0 - quint16 type() - { return d.type(); } - bool setType(quint16 type) - { d.set_type(type); return true; } -#endif - virtual QString protocolName() - { return QString("SubNetwork Access Protocol"); } - QString protocolShortName() - { return QString("SNAP"); } - int numFields() - { return 1; } - QString fieldName(int index); - QString fieldTextValue(int index); - QByteArray fieldRawValue(int index); -}; - - -class Eth2Protocol : public AbstractProtocol -{ -private: - OstProto::Eth2 d; - -public: - virtual ~Eth2Protocol() {} - virtual ::google::protobuf::Message& data() {return d;} - bool update(OstProto::Eth2 eth2) { d.MergeFrom(eth2); return true; } - - quint16 type() - { return d.type(); } - bool setType(quint16 type) - { d.set_type(type); return true; } - - - virtual QString protocolName() - { return QString("Protocol Type"); } - QString protocolShortName() - { return QString("TYPE"); } - int numFields() - { return 1; } - QString fieldName(int index); - QString fieldTextValue(int index); - QByteArray fieldRawValue(int index); -}; - - -class Dot3Protocol : public AbstractProtocol -{ -private: - Stream *parentStream; - OstProto::Ack d; // FIXME(HI): replace 'ack' with somehting else - -public: - Dot3Protocol(Stream *stream = NULL) - { parentStream = stream; qDebug("parentStream = %p", stream); } - virtual ~Dot3Protocol() {} - virtual ::google::protobuf::Message& data() {return d;} - -#if 0 // FIXME(HI): remove? - quint16 length() - { return d.length(); } - bool setLength(quint16 length) - { return true; } -#endif - - virtual QString protocolName() - { return QString("802.3 Length"); } - QString protocolShortName() - { return QString("LEN"); } - int numFields() - { return 1; } - QString fieldName(int index); - QString fieldTextValue(int index); - QByteArray fieldRawValue(int index); -}; - -class VlanProtocol : public AbstractProtocol -{ - OstProto::Vlan d; -public: - virtual ~VlanProtocol() {} - virtual ::google::protobuf::Message& data() {return d;} - bool update(OstProto::Vlan vlan) { d.MergeFrom(vlan); return true; } - - enum VlanFlag { - VlanCvlanTagged = 0x01, - VlanCtpidOverride = 0x02, - VlanSvlanTagged = 0x04, - VlanStpidOverride = 0x08, - }; - Q_DECLARE_FLAGS(VlanFlags, VlanFlag); - - VlanFlags vlanFlags() - { - VlanFlags f; - - if (d.is_cvlan_tagged()) f|= VlanCvlanTagged; - if (d.is_ctpid_override()) f|= VlanCtpidOverride; - if (d.is_svlan_tagged()) f|= VlanSvlanTagged; - if (d.is_stpid_override()) f|= VlanStpidOverride; - - return f; - } - - bool setVlanFlags(VlanFlags vlanFlags) - { - d.set_is_cvlan_tagged(vlanFlags.testFlag(VlanCvlanTagged)); - d.set_is_ctpid_override(vlanFlags.testFlag(VlanCtpidOverride)); - d.set_is_svlan_tagged(vlanFlags.testFlag(VlanSvlanTagged)); - d.set_is_stpid_override(vlanFlags.testFlag(VlanStpidOverride)); - - return true; - } - - bool isUntagged() - { - if (!d.is_cvlan_tagged() && !d.is_svlan_tagged()) - return true; - else - return false; - } - - bool isSingleTagged() - { - if (( d.is_cvlan_tagged() && !d.is_svlan_tagged()) || - (!d.is_cvlan_tagged() && d.is_svlan_tagged()) ) - return true; - else - return false; - } - - bool isDoubleTagged() - { - if (d.is_cvlan_tagged() && d.is_svlan_tagged()) - return true; - else - return false; - } - - // CVLAN - quint16 ctpid() - { return d.ctpid(); } - bool setCtpid(quint16 ctpid) - { d.set_ctpid(ctpid); return true; } - - quint8 cvlanPrio() - { return (d.cvlan_tag() >> 13); } - bool setCvlanPrio(quint8 cvlanPrio) - { d.set_cvlan_tag((d.cvlan_tag() & 0x1FFF) | ((cvlanPrio & 0x3) << 13)); - return true; } - - quint8 cvlanCfi() - { return ((d.cvlan_tag() & 0x1000) >> 12); } - bool setCvlanCfi(quint8 cvlanCfi) - { d.set_cvlan_tag((d.cvlan_tag() & 0xEFFF) | ((cvlanCfi & 0x01) << 12)); - return true; } - - quint16 cvlanId() - { return (d.cvlan_tag() & 0x0FFF); } - bool setCvlanId(quint16 cvlanId) - { d.set_cvlan_tag((d.cvlan_tag() & 0xF000) | ((cvlanId & 0x0FFF))); - return true; } - - // SVLAN - quint16 stpid() - { return d.stpid(); } - bool setStpid(quint16 stpid) - { d.set_stpid(stpid); return true; } - quint8 svlanPrio() - { return (d.svlan_tag() >> 13); } - bool setSvlanPrio(quint8 svlanPrio) - { d.set_svlan_tag((d.svlan_tag() & 0x1FFF) | ((svlanPrio & 0x3) << 13)); - return true; } - - quint8 svlanCfi() - { return ((d.svlan_tag() & 0x1000) >> 12); } - bool setSvlanCfi(quint8 svlanCfi) - { d.set_svlan_tag((d.svlan_tag() & 0xEFFF) | ((svlanCfi & 0x01) << 12)); - return true; } - - quint16 svlanId() - { return (d.svlan_tag() & 0x0FFF); } - bool setSvlanId(quint16 svlanId) - { d.set_svlan_tag((d.svlan_tag() & 0xF000) | ((svlanId & 0x0FFF))); - return true; } - - virtual QString protocolName() - { return QString("Virtual Local Access Network"); } - QString protocolShortName() - { return QString("VLAN"); } - int numFields(); - QString fieldName(int index); - QString fieldTextValue(int index); - QByteArray fieldRawValue(int index); -}; - -// IP -class IpProtocol : public AbstractProtocol -{ -private: - OstProto::Ip d; - -public: - virtual ~IpProtocol() {} - virtual ::google::protobuf::Message& data() {return d;} - - bool update(OstProto::Ip ip) { d.MergeFrom(ip); return true; } - - enum IpAddrMode { - IpAddrFixed, - IpAddrIncHost, - IpAddrDecHost, - IpAddrRandomHost - }; - - enum IpFlag { - IpOverrideVersion = 0x01, - IpOverrideHdrLen = 0x02, - IpOverrideTotLen = 0x04, - IpOverrideCksum = 0x08 - }; - Q_DECLARE_FLAGS(IpFlags, IpFlag); - - IpFlags ipFlags() - { - IpFlags f; - - if (d.is_override_ver()) f|= IpOverrideVersion; - if (d.is_override_hdrlen()) f|= IpOverrideHdrLen; - if (d.is_override_totlen()) f|= IpOverrideTotLen; - if (d.is_override_cksum()) f|= IpOverrideCksum; - - return f; - } - - bool setIpFlags(IpFlags ipFlags) - { - if (ipFlags.testFlag(IpOverrideVersion)) - d.set_is_override_ver(true); - else - d.set_is_override_ver(false); - - if (ipFlags.testFlag(IpOverrideHdrLen)) - d.set_is_override_hdrlen(true); - else - d.set_is_override_hdrlen(false); - - if (ipFlags.testFlag(IpOverrideTotLen)) - d.set_is_override_totlen(true); - else - d.set_is_override_totlen(false); - - if (ipFlags.testFlag(IpOverrideCksum)) - d.set_is_override_cksum(true); - else - d.set_is_override_cksum(false); - - return true; - } - - quint8 ver() - { return (d.ver_hdrlen() >> 4); } - bool setVer(quint8 ver) - { d.set_ver_hdrlen((d.ver_hdrlen() & 0x0F) | (ver << 4)); return true; } - - quint8 hdrLen() - { return (d.ver_hdrlen() & 0xF); } - bool setHdrLen(quint8 hdrLen) - { d.set_ver_hdrlen((d.ver_hdrlen() & 0xF0) | hdrLen); return true; } - - quint8 tos() - { return d.tos(); } - bool setTos(quint8 tos) - { d.set_tos(tos); return true; } - - quint16 totLen() - { return d.tot_len(); } - bool setTotLen(quint16 totLen) - { d.set_tot_len(totLen); return true; } - - quint16 id() - { return d.id(); } - bool setId(quint16 id) - { d.set_id(id); return true; } - - quint16 flags() - { return d.flags(); } - bool setFlags(quint16 flags) - { d.set_flags(flags); return true; } -#define IP_FLAG_UNUSED 0x1 -#define IP_FLAG_DF 0x2 -#define IP_FLAG_MF 0x4 - - quint16 fragOfs() - { return d.frag_ofs(); } - bool setFragOfs(quint16 fragOfs) - { d.set_frag_ofs(fragOfs); return true; } - - quint8 ttl() - { return d.ttl(); } - bool setTtl(quint8 ttl) - { d.set_ttl(ttl); return true; } - - quint8 proto() - { return d.proto(); } - bool setProto(quint8 proto) - { d.set_proto(proto); return true; } - - quint16 cksum() - { return d.cksum(); } - bool setCksum(quint16 cksum) - { d.set_cksum(cksum); return true; } - - // Source IP - quint32 srcIp() - { return d.src_ip(); } - bool setSrcIp(quint32 srcIp) - { d.set_src_ip(srcIp); return true; } - - IpAddrMode srcIpMode() - { return (IpAddrMode) d.src_ip_mode(); } - bool setSrcIpMode(IpAddrMode srcIpMode) - { d.set_src_ip_mode((OstProto::Ip::IpAddrMode)srcIpMode); return true; } - - quint16 srcIpCount() - { return d.src_ip_count(); } - bool setSrcIpCount(quint16 srcIpCount) - { d.set_src_ip_count(srcIpCount); return true; } - - quint32 srcIpMask() - { return d.src_ip_mask(); } - bool setSrcIpMask(quint32 srcIpMask) - { d.set_src_ip_mask(srcIpMask); return true; } - - // Destination IP - quint32 dstIp() - { return d.dst_ip(); } - bool setDstIp(quint32 dstIp) - { d.set_dst_ip(dstIp); return true; } - - IpAddrMode dstIpMode() - { return (IpAddrMode) d.dst_ip_mode(); } - bool setDstIpMode(IpAddrMode dstIpMode) - { d.set_dst_ip_mode((OstProto::Ip::IpAddrMode)dstIpMode); return true; } - - quint16 dstIpCount() - { return d.dst_ip_count(); } - bool setDstIpCount(quint16 dstIpCount) - { d.set_dst_ip_count(dstIpCount); return true; } - - quint32 dstIpMask() - { return d.dst_ip_mask(); } - bool setDstIpMask(quint32 dstIpMask) - { d.set_dst_ip_mask(dstIpMask); return true; } - - // TODO(LOW): Options - - - virtual QString protocolName() - { return QString("Internet Protocol version 4"); } - QString protocolShortName() - { return QString("IPv4"); } - int numFields() - { return 12; } - QString fieldName(int index); - QString fieldTextValue(int index); - QByteArray fieldRawValue(int index); -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(IpProtocol::IpFlags) - -class ArpProtocol: public AbstractProtocol -{ - // TODO(LOW): ARP - OstProto::Arp d; - -public: - virtual ~ArpProtocol() {} - virtual ::google::protobuf::Message& data() {return d;} - bool update(OstProto::Arp arp) { d.MergeFrom(arp); return true; } -}; - -// TCP -class TcpProtocol : public AbstractProtocol -{ -private: - OstProto::Tcp d; - -public: - virtual ~TcpProtocol() {} - virtual ::google::protobuf::Message& data() {return d;} - - bool update(OstProto::Tcp tcp) { d.MergeFrom(tcp); return true; } - - enum TcpFlag - { - TcpOverrideHdrLen = 0x01, - TcpOverrideCksum = 0x02 - }; - Q_DECLARE_FLAGS(TcpFlags, TcpFlag); - - TcpFlags tcpFlags() - { - TcpFlags f; - - if (d.is_override_hdrlen()) f|= TcpOverrideHdrLen; - if (d.is_override_cksum()) f|= TcpOverrideCksum; - - return f; - } - - bool setTcpFlags(TcpFlags tcpFlags) - { - if (tcpFlags.testFlag(TcpOverrideHdrLen)) - d.set_is_override_hdrlen(true); - else - d.set_is_override_hdrlen(false); - - if (tcpFlags.testFlag(TcpOverrideCksum)) - d.set_is_override_cksum(true); - else - d.set_is_override_cksum(false); - - return true; - } - - quint16 srcPort() - { return d.src_port(); } - bool setSrcPort(quint16 srcPort) - { d.set_src_port(srcPort); return true; } - - quint16 dstPort() - { return d.dst_port(); } - bool setDstPort(quint16 dstPort) - { d.set_dst_port(dstPort); return true; } - - quint32 seqNum() - { return d.seq_num(); } - bool setSeqNum(quint32 seqNum) - { d.set_seq_num(seqNum); return true;} - - quint32 ackNum() - { return d.ack_num(); } - bool setAckNum(quint32 ackNum) - { d.set_ack_num(ackNum); return true;} - - quint8 hdrLen() - { return (d.hdrlen_rsvd() >> 4); } - bool setHdrLen(quint8 hdrLen) - { d.set_hdrlen_rsvd((d.hdrlen_rsvd() & 0x0F) | (hdrLen << 4)); return true; } - - quint8 rsvd() - { return (d.hdrlen_rsvd() & 0xF); } - bool setRsvd(quint8 rsvd) - { d.set_hdrlen_rsvd((d.hdrlen_rsvd() & 0xF0) | rsvd); return true; } - - - // TODO(MED): convert to enum maybe? - quint8 flags() - { return d.flags(); } - bool setFlags(quint8 flags) - { d.set_flags(flags); return true; } -#define TCP_FLAG_URG 0x01 -#define TCP_FLAG_ACK 0x02 -#define TCP_FLAG_PSH 0x04 -#define TCP_FLAG_RST 0x08 -#define TCP_FLAG_SYN 0x10 -#define TCP_FLAG_FIN 0x20 - - quint16 window() - { return d.window(); } - bool setWindow(quint16 window) - { d.set_window(window); return true; } - - quint16 cksum() - { return d.cksum(); } - bool setCksum(quint16 cksum) - { d.set_cksum(cksum); return true; } - - quint16 urgPtr() - { return d.urg_ptr(); } - bool setUrgPtr(quint16 urg_ptr) - { d.set_urg_ptr(urg_ptr); return true; } - - - virtual QString protocolName() - { return QString("Transmission Control Protocol"); } - QString protocolShortName() - { return QString("TCP"); } - int numFields() - { return 10; } - QString fieldName(int index); - QString fieldTextValue(int index); - QByteArray fieldRawValue(int index); -}; -Q_DECLARE_OPERATORS_FOR_FLAGS(TcpProtocol::TcpFlags) - - -// UDP -class UdpProtocol : public AbstractProtocol -{ -private: - OstProto::Udp d; - -public: - virtual ~UdpProtocol() {} - virtual ::google::protobuf::Message& data() {return d;} - - bool update(OstProto::Udp udp) { d.MergeFrom(udp); return true; } - - enum UdpFlag - { - UdpOverrideTotLen = 0x01, - UdpOverrideCksum = 0x02 - }; - Q_DECLARE_FLAGS(UdpFlags, UdpFlag); - - UdpFlags udpFlags() - { - UdpFlags f; - - if (d.is_override_totlen()) f|= UdpOverrideTotLen; - if (d.is_override_cksum()) f|= UdpOverrideCksum; - - return f; - } - - bool setUdpFlags(UdpFlags udpFlags) - { - if (udpFlags.testFlag(UdpOverrideTotLen)) - d.set_is_override_totlen(true); - else - d.set_is_override_totlen(false); - - if (udpFlags.testFlag(UdpOverrideCksum)) - d.set_is_override_cksum(true); - else - d.set_is_override_cksum(false); - - return true; - } - - quint16 srcPort() - { return d.src_port(); } - bool setSrcPort(quint16 srcPort) - { d.set_src_port(srcPort); return true; } - - quint16 dstPort() - { return d.dst_port(); } - bool setDstPort(quint16 dstPort) - { d.set_dst_port(dstPort); return true; } - - quint16 totLen() - { return d.totlen(); } - bool setTotLen(quint16 totLen) - { d.set_totlen(totLen); return true; } - - quint16 cksum() - { return d.cksum(); } - bool setCksum(quint16 cksum) - { d.set_cksum(cksum); return true; } - - - virtual QString protocolName() - { return QString("User Datagram Protocol"); } - QString protocolShortName() - { return QString("UDP"); } - int numFields() - { return 4; } - QString fieldName(int index); - QString fieldTextValue(int index); - QByteArray fieldRawValue(int index); -}; - -class IcmpProtocol : public AbstractProtocol -{ -// TODO(LOW): ICMP - OstProto::Icmp d; - -public: - virtual ~IcmpProtocol() {} - virtual ::google::protobuf::Message& data() {return d;} - bool update(OstProto::Icmp icmp) { d.MergeFrom(icmp); return true; } -}; - -class IgmpProtocol : public AbstractProtocol -{ -// TODO(LOW): IGMP - OstProto::Igmp d; - -public: - virtual ~IgmpProtocol() {} - virtual ::google::protobuf::Message& data() {return d;} - bool update(OstProto::Igmp igmp) { d.MergeFrom(igmp); return true; } -}; - - class Stream { quint32 mId; OstProto::StreamCore *mCore; OstProto::StreamControl *mControl; - UnknownProtocol *mUnknown; - PayloadProtocol *mPayload; - MacProtocol *mMac; - - LlcProtocol *mLlc; - SnapProtocol *mSnap; - Eth2Protocol *mEth2; - Dot3Protocol *mDot3; - - VlanProtocol *mVlan; - - IpProtocol *mIp; - ArpProtocol *mArp; - - TcpProtocol *mTcp; - UdpProtocol *mUdp; - IcmpProtocol *mIcmp; - IgmpProtocol *mIgmp; + QList mProtocolList; public: - //PayloadProtocol* Payload() { return mPayload; } - MacProtocol* mac() { return mMac; } void* core() { return mCore; } // FIXME(HI): Debug ONLY - - LlcProtocol* llc() { return mLlc; } - SnapProtocol* snap() { return mSnap; } - Eth2Protocol* eth2() { return mEth2; } - Dot3Protocol* dot3() { return mDot3; } - VlanProtocol* vlan() { return mVlan; } - - IpProtocol* ip() { return mIp; } - ArpProtocol* arp() { return mArp; } - - TcpProtocol* tcp() { return mTcp; } - UdpProtocol* udp() { return mUdp; } - IcmpProtocol* icmp() { return mIcmp; } - IgmpProtocol* igmp() { return mIgmp; } - + void loadProtocolWidgets(); + void storeProtocolWidgets(); public: enum FrameType { @@ -933,12 +85,15 @@ public: // Methods // ------------------------------------------------------- Stream(); + ~Stream(); + + void protoDataCopyFrom(Stream& stream); bool operator < (const Stream &s) const { return(mCore->ordinal() < s.mCore->ordinal()); } - void getConfig(uint portId, OstProto::Stream *s); + void getConfig(uint portId, OstProto::Stream &s); bool update(OstProto::Stream *stream); quint32 id() @@ -968,23 +123,6 @@ public: bool setName(QString name) { mCore->set_name(name.toStdString()); return true; } - FrameType frameType() - { return (FrameType) mCore->ft(); } - bool setFrameType(FrameType frameType) - { mCore->set_ft((OstProto::StreamCore::FrameType) frameType); return true; } - - // Data Pattern - DataPatternMode patternMode() - { return (DataPatternMode) mCore->pattern_mode(); } - bool setPatternMode(DataPatternMode patternMode) - { mCore->set_pattern_mode( - (OstProto::StreamCore::DataPatternMode) patternMode); return true; } - - quint32 pattern() - { return mCore->pattern(); } - bool setPattern(quint32 pattern) - { mCore->set_pattern(pattern); return true; } - // TODO(HI) : ????? #if 0 quint16 dataStartOfs; @@ -1012,18 +150,6 @@ public: bool setFrameLenMax(quint16 frameLenMax) { mCore->set_frame_len_max(frameLenMax); return true; } - L3Proto l3Proto() - { return (L3Proto) mCore->l3_proto(); } - bool setL3Proto(L3Proto l3Proto) - { mCore->set_l3_proto((OstProto::StreamCore::L3Proto) l3Proto); - return true; } - - L4Proto l4Proto() - { return (L4Proto) mCore->l4_proto(); } - bool setL4Proto(L4Proto l4Proto) - { mCore->set_l4_proto((OstProto::StreamCore::L4Proto) l4Proto); - return true; } - SendUnit sendUnit() { return (SendUnit) mControl->unit(); } bool setSendUnit(SendUnit sendUnit) @@ -1070,21 +196,12 @@ public: //--------------------------------------------------------------- // Methods for use by Packet Model //--------------------------------------------------------------- - - int numProtocols(); + QList frameProtocol(); + void setFrameProtocol(QList protocolList); //! Includes ALL protocol headers excluding payload data int protocolHeaderSize(); -#if 0 - int protocolId(int index); - int protocolIndex(int id); -#endif - AbstractProtocol* protocol(int index); -private: - QList selectedProtocols; - int mProtocolHeaderSize; - void updateSelectedProtocols(); - + AbstractProtocol* protocolById(int id); }; #endif diff --git a/client/streamconfigdialog.cpp b/client/streamconfigdialog.cpp index 8b99561..0079240 100644 --- a/client/streamconfigdialog.cpp +++ b/client/streamconfigdialog.cpp @@ -13,6 +13,11 @@ int StreamConfigDialog::lastProtoTabIndex = 0; StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex, QWidget *parent) : QDialog (parent), mPort(port) { + mCurrentStreamIndex = streamIndex; + + mpStream = new Stream; + mpStream->protoDataCopyFrom(*(mPort.streamByIndex(mCurrentStreamIndex))); + setupUi(this); setupUiExtra(); @@ -158,19 +163,15 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex, rbFtNone->click(); #endif - //mpStreamList = streamList; - mCurrentStreamIndex = streamIndex; + //mmpStreamList = streamList; LoadCurrentStream(); - mpPacketModel = new PacketModel(&mPort.streamByIndex(mCurrentStreamIndex), - this); + mpPacketModel = new PacketModel(QList(), this); tvPacketTree->setModel(mpPacketModel); mpPacketModelTester = new ModelTest(mpPacketModel); tvPacketTree->header()->hide(); vwPacketDump->setModel(mpPacketModel); vwPacketDump->setSelectionModel(tvPacketTree->selectionModel()); - - // TODO(MED): //! \todo Enable navigation of streams pbPrev->setDisabled(true); @@ -180,7 +181,6 @@ 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)) @@ -193,6 +193,16 @@ void StreamConfigDialog::setupUiExtra() QRegExp reHex4B("[0-9,a-f,A-F]{1,8}"); QRegExp reMac("([0-9,a-f,A-F]{2,2}[:-]){5,5}[0-9,a-f,A-F]{2,2}"); + // Add the Payload widget to the dialog + { + QGridLayout *layout; + + layout = static_cast(twTopLevel->widget(0)->layout()); + + layout->addWidget(mpStream->protocolById(52)->configWidget(), 0, 1); + qDebug("setupUi wgt = %p", mpStream->protocolById(52)->configWidget()); + } + // ---- Setup default stuff that cannot be done in designer ---- // Since the dialog defaults are FT = None, L3 = None, L4 = None; @@ -218,6 +228,7 @@ void StreamConfigDialog::setupUiExtra() lePktLen->setValidator(new QIntValidator(MIN_PKT_LEN, MAX_PKT_LEN, this)); // L2 Ethernet +#if 0 // Proto FW leDstMac->setValidator(new QRegExpValidator(reMac, this)); leSrcMac->setValidator(new QRegExpValidator(reMac, this)); leDstMacCount->setValidator(new QIntValidator(1, MAX_MAC_ITER_COUNT, this)); @@ -225,6 +236,7 @@ void StreamConfigDialog::setupUiExtra() leCvlanTpid->setValidator(new QRegExpValidator(reHex2B, this)); leSvlanTpid->setValidator(new QRegExpValidator(reHex2B, this)); //leEtherType->setValidator(new QRegExpValidator(reHex2B, this)); +#endif /* ** Setup Connections @@ -244,31 +256,93 @@ StreamConfigDialog::~StreamConfigDialog() { delete mpPacketModelTester; delete mpPacketModel; + + // Remove payload data widget so that it is not deleted when this object + // is destroyed + { + 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); + + } + } + + // Remove any existing widget on the L2-L4 Tabs lest they are deleted + // when this object is destoryed + for (int i = 1; i <= 3; i++) + { + QLayout *layout = twProto->widget(i)->layout(); + if (layout) + { + QLayoutItem *child; + while ((child = layout->takeAt(0)) != 0) + { + Q_ASSERT(child->widget() != 0); + // Don't delete the child widget - reparent it + child->widget()->setParent(0); + } + delete layout; + } + } + + delete mpStream; } -void StreamConfigDialog::on_cmbPatternMode_currentIndexChanged(QString mode) +void StreamConfigDialog::updateSelectedProtocols() { - if (mode == "Fixed Word") + mSelectedProtocols.clear(); + + // FIXME: Hardcoded numbers! + + // Mac + mSelectedProtocols.append(51); + + if (rbFtEthernet2->isChecked()) + mSelectedProtocols.append(121); + else if (rbFt802Dot3Raw->isChecked()) + mSelectedProtocols.append(122); + else if (rbFt802Dot3Llc->isChecked()) { - lePattern->setEnabled(true); + mSelectedProtocols.append(122); + mSelectedProtocols.append(123); } - else if (mode == "Increment Byte") + else if (rbFtLlcSnap->isChecked()) { - lePattern->setDisabled(true); - } - else if (mode == "Decrement Byte") - { - lePattern->setDisabled(true); - } - if (mode == "Random") - { - lePattern->setDisabled(true); - } - else - { - qWarning("Unhandled/Unknown PatternMode = %s", mode.toAscii().data()); + mSelectedProtocols.append(122); + mSelectedProtocols.append(123); + mSelectedProtocols.append(124); } + + if (rbL3Ipv4->isChecked()) + mSelectedProtocols.append(130); + else if (rbL3Arp->isChecked()) + mSelectedProtocols.append(131); + + if (rbL4Tcp->isChecked()) + mSelectedProtocols.append(140); + else if (rbL4Udp->isChecked()) + mSelectedProtocols.append(141); + else if (rbL4Icmp->isChecked()) + mSelectedProtocols.append(142); + else if (rbL4Igmp->isChecked()) + mSelectedProtocols.append(143); + + // Payload + mSelectedProtocols.append(52); } + + void StreamConfigDialog::on_cmbPktLenMode_currentIndexChanged(QString mode) { if (mode == "Fixed") @@ -301,63 +375,6 @@ void StreamConfigDialog::on_cmbPktLenMode_currentIndexChanged(QString mode) } } - -void StreamConfigDialog::on_cmbDstMacMode_currentIndexChanged(QString mode) -{ - if (mode == "Fixed") - { - leDstMacCount->setEnabled(false); - leDstMacStep->setEnabled(false); - } - else - { - leDstMacCount->setEnabled(true); - leDstMacStep->setEnabled(true); - } -} - -void StreamConfigDialog::on_cmbSrcMacMode_currentIndexChanged(QString mode) -{ - if (mode == "Fixed") - { - leSrcMacCount->setEnabled(false); - leSrcMacStep->setEnabled(false); - } - else - { - leSrcMacCount->setEnabled(true); - leSrcMacStep->setEnabled(true); - } -} - -void StreamConfigDialog::on_cmbIpSrcAddrMode_currentIndexChanged(QString mode) -{ - if (mode == "Fixed") - { - leIpSrcAddrCount->setDisabled(true); - leIpSrcAddrMask->setDisabled(true); - } - else - { - leIpSrcAddrCount->setEnabled(true); - leIpSrcAddrMask->setEnabled(true); - } -} - -void StreamConfigDialog::on_cmbIpDstAddrMode_currentIndexChanged(QString mode) -{ - if (mode == "Fixed") - { - leIpDstAddrCount->setDisabled(true); - leIpDstAddrMask->setDisabled(true); - } - else - { - leIpDstAddrCount->setEnabled(true); - leIpDstAddrMask->setEnabled(true); - } -} - void StreamConfigDialog::on_pbPrev_clicked() { #if 0 @@ -412,10 +429,13 @@ void StreamConfigDialog::on_rbL3Ipv4_toggled(bool checked) { if (checked) { - swL3Proto->setCurrentIndex(0); 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 { @@ -428,10 +448,13 @@ void StreamConfigDialog::on_rbL3Arp_toggled(bool checked) { if (checked) { - swL3Proto->setCurrentIndex(1); 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 { @@ -446,10 +469,11 @@ void StreamConfigDialog::on_rbL4Icmp_toggled(bool checked) if (checked) { - swL4Proto->setCurrentIndex(2); twProto->setTabEnabled(3, TRUE); twProto->setTabText(3, "L4 (ICMP)"); - leIpProto->setText(uintToHexStr(IP_PROTO_ICMP, str, 1)); + // FIXME: Hardcoding + mpStream->protocolById(130)->setFieldData(8 /* proto */, IP_PROTO_ICMP); + mpStream->loadProtocolWidgets(); // FIXME: pass protocol as param } else { @@ -464,10 +488,11 @@ void StreamConfigDialog::on_rbL4Igmp_toggled(bool checked) if (checked) { - swL4Proto->setCurrentIndex(3); twProto->setTabEnabled(3, TRUE); twProto->setTabText(3, "L4 (IGMP)"); - leIpProto->setText(uintToHexStr(IP_PROTO_IGMP, str, 1)); + // FIXME: Hardcoding + mpStream->protocolById(130)->setFieldData(8 /* proto */, IP_PROTO_IGMP); + mpStream->loadProtocolWidgets(); // FIXME: pass protocol as param } else { @@ -482,10 +507,11 @@ void StreamConfigDialog::on_rbL4Tcp_toggled(bool checked) if (checked) { - swL4Proto->setCurrentIndex(0); twProto->setTabEnabled(3, TRUE); twProto->setTabText(3, "L4 (TCP)"); - leIpProto->setText(uintToHexStr(IP_PROTO_TCP, str, 1)); + // FIXME: Hardcoding + mpStream->protocolById(130)->setFieldData(8 /* proto */, IP_PROTO_TCP); + mpStream->loadProtocolWidgets(); // FIXME: pass protocol as param } else { @@ -500,10 +526,11 @@ void StreamConfigDialog::on_rbL4Udp_toggled(bool checked) if (checked) { - swL4Proto->setCurrentIndex(1); twProto->setTabEnabled(3, TRUE); twProto->setTabText(3, "L4 (UDP)"); - leIpProto->setText(uintToHexStr(IP_PROTO_UDP, str, 1)); + // FIXME: Hardcoding + mpStream->protocolById(130)->setFieldData(8 /* proto */, IP_PROTO_UDP); + mpStream->loadProtocolWidgets(); // FIXME: pass protocol as param } else { @@ -512,6 +539,88 @@ void StreamConfigDialog::on_rbL4Udp_toggled(bool checked) } } +void StreamConfigDialog::on_twTopLevel_currentChanged(int index) +{ + QList protoList; + + // We only process the "Packet View" tab + if (index != 2) + return; + + updateSelectedProtocols(); + foreach(int i, mSelectedProtocols) + if (mpStream->protocolById(i)) + protoList.append(mpStream->protocolById(i)); + + mpPacketModel->setSelectedProtocols(protoList); + StoreCurrentStream(mpStream); +} + +void StreamConfigDialog::on_twProto_currentChanged(int index) +{ + QLayout *layout; + QList wl; + + // We need to process only indices 1-3 i.e. the L2, L3 and L4 tabs + if ((index < 1) || (index > 3)) + return; + + // Remove any existing widget on the activated tab + layout = twProto->widget(index)->layout(); + if (layout) + { + QLayoutItem *child; + while ((child = layout->takeAt(0)) != 0) + { + Q_ASSERT(child->widget() != 0); + // Don't delete the child widget - reparent it + child->widget()->setParent(0); + } + delete layout; + } + + // FIXME: protocol id hardcodings + switch(index) + { + case 1: // L2 + wl.append(mpStream->protocolById(51)->configWidget()); + if (rbFtEthernet2->isChecked()) + wl.append(mpStream->protocolById(121)->configWidget()); + else if (rbFt802Dot3Raw->isChecked()) + wl.append(mpStream->protocolById(122)->configWidget()); + else if (rbFt802Dot3Llc->isChecked()) + { + wl.append(mpStream->protocolById(122)->configWidget()); + wl.append(mpStream->protocolById(123)->configWidget()); + } + else if (rbFtLlcSnap->isChecked()) + { + wl.append(mpStream->protocolById(122)->configWidget()); + wl.append(mpStream->protocolById(123)->configWidget()); + wl.append(mpStream->protocolById(124)->configWidget()); + } + break; + case 2: // L3 + if (rbL3Ipv4->isChecked()) + wl.append(mpStream->protocolById(130)->configWidget()); + break; + case 3: // L4 + if (rbL4Tcp->isChecked()) + wl.append(mpStream->protocolById(140)->configWidget()); + else if (rbL4Udp->isChecked()) + wl.append(mpStream->protocolById(141)->configWidget()); + break; + } + + if (wl.size()) + layout = new QVBoxLayout; + + for (int i=0; i < wl.size(); i++) + layout->addWidget(wl.at(i)); + + twProto->widget(index)->setLayout(layout); +} + void StreamConfigDialog::update_NumPacketsAndNumBursts() { if (rbSendPackets->isChecked() && rbModeFixed->isChecked()) @@ -525,28 +634,6 @@ void StreamConfigDialog::update_NumPacketsAndNumBursts() leNumBursts->setEnabled(false); } -QString & uintToHexStr(quint64 num, QString &hexStr, quint8 octets) -{ - int i; - QChar zero('0'); - - hexStr = ""; - - for (i = octets; i > 0; i--) - { - ushort byte; - QString str1 = "%1"; - QString str; - - byte = num & 0xff; - str = str1.arg(byte, 2, 16, zero).append(' '); - hexStr.prepend(str); - num = num >> 8; - } - - return hexStr; -} - #if 0 void StreamConfigDialog::on_lePattern_editingFinished() { @@ -563,234 +650,133 @@ void StreamConfigDialog::on_lePattern_editingFinished() void StreamConfigDialog::LoadCurrentStream() { - Stream *pStream = &mPort.streamByIndex(mCurrentStreamIndex); QString str; - qDebug("loading pStream %p", pStream); + qDebug("loading mpStream %p", mpStream); // Meta Data { - cmbPatternMode->setCurrentIndex(pStream->patternMode()); - lePattern->setText(uintToHexStr(pStream->pattern(), str, 4)); - - cmbPktLenMode->setCurrentIndex(pStream->lenMode()); - lePktLen->setText(str.setNum(pStream->frameLen())); - lePktLenMin->setText(str.setNum(pStream->frameLenMin())); - lePktLenMax->setText(str.setNum(pStream->frameLenMax())); + cmbPktLenMode->setCurrentIndex(mpStream->lenMode()); + lePktLen->setText(str.setNum(mpStream->frameLen())); + lePktLenMin->setText(str.setNum(mpStream->frameLenMin())); + lePktLenMax->setText(str.setNum(mpStream->frameLenMax())); } // Protocols { - qDebug("ft = %d\n", pStream->frameType()); - switch(pStream->frameType()) + int i; + + qDebug("Selected Protocols.size() = %d", mSelectedProtocols.size()); + mSelectedProtocols = mpStream->frameProtocol(); + qDebug("Selected Protocols.size() = %d", mSelectedProtocols.size()); + for (i = 0; i < mSelectedProtocols.size(); i++) + qDebug("%d: %d", i, mSelectedProtocols.at(i)); + + Q_ASSERT(mSelectedProtocols.size() >= 2); // Mac + Payload: mandatory + + i = 0; + Q_ASSERT(mSelectedProtocols.at(i) == 51); // Mac + i++; + + if (mSelectedProtocols.at(i) == 52) // Payload { - case Stream::e_ft_none: - rbFtNone->setChecked(TRUE); - break; - case Stream::e_ft_eth_2: - rbFtEthernet2->setChecked(TRUE); - break; - case Stream::e_ft_802_3_raw: - rbFt802Dot3Raw->setChecked(TRUE); - break; - case Stream::e_ft_802_3_llc: - rbFt802Dot3Llc->setChecked(TRUE); - break; - case Stream::e_ft_snap: - rbFtLlcSnap->setChecked(TRUE); - break; + i++; + goto _proto_parse_done; } - - leDsap->setText(uintToHexStr(pStream->llc()->dsap(), str, 1)); - leSsap->setText(uintToHexStr(pStream->llc()->ssap(), str, 1)); - leControl->setText(uintToHexStr(pStream->llc()->ctl(), str, 1)); - leOui->setText(uintToHexStr(pStream->snap()->oui(), str, 3)); - - leType->setText(uintToHexStr(pStream->eth2()->type(), str, 2)); - - switch(pStream->l3Proto()) + else if (mSelectedProtocols.at(i) == 121) // Eth2 { - case Stream::e_l3_none: - rbL3None->setChecked(true); - break; - case Stream::e_l3_ip: - rbL3Ipv4->setChecked(true); - break; - case Stream::e_l3_arp: - rbL3Arp->setChecked(true); - break; - default: - qDebug("%s: unknown L3 Protocol %d", __FUNCTION__, - pStream->l3Proto()); + rbFtEthernet2->setChecked(true); + i++; } - - switch(pStream->l4Proto()) + else if (mSelectedProtocols.at(i) == 122) // 802.3 RAW { - case Stream::e_l4_none: - rbL4None->setChecked(true); - break; - case Stream::e_l4_tcp: - rbL4Tcp->setChecked(true); - break; - case Stream::e_l4_udp: - rbL4Udp->setChecked(true); - break; - case Stream::e_l4_icmp: - rbL4Icmp->setChecked(true); - break; - case Stream::e_l4_igmp: - rbL4Igmp->setChecked(true); - break; - default: - qDebug("%s: unknown l4 Protocol %d", __FUNCTION__, - pStream->l4Proto()); - } - } - - // L2 - { - // L2 | Ethernet - { - leDstMac->setText(uintToHexStr(pStream->mac()->dstMac(), str, 6)); - cmbDstMacMode->setCurrentIndex(pStream->mac()->dstMacMode()); - leDstMacCount->setText(str.setNum(pStream->mac()->dstMacCount())); - leDstMacStep->setText(str.setNum(pStream->mac()->dstMacStep())); - - leSrcMac->setText(uintToHexStr(pStream->mac()->srcMac(), str, 6)); - cmbSrcMacMode->setCurrentIndex(pStream->mac()->srcMacMode()); - leSrcMacCount->setText(str.setNum(pStream->mac()->srcMacCount())); - leSrcMacStep->setText(str.setNum(pStream->mac()->srcMacStep())); - + if ((mSelectedProtocols.size() > (i+1)) && + (mSelectedProtocols.at(i+1) == 123)) // 802.3 LLC { - VlanProtocol *vlan = pStream->vlan(); - VlanProtocol::VlanFlags f; - - cmbCvlanPrio->setCurrentIndex(vlan->cvlanPrio()); - cmbCvlanCfi->setCurrentIndex(vlan->cvlanCfi()); - leCvlanId->setText(str.setNum(vlan->cvlanId())); - leCvlanTpid->setText(str.setNum(vlan->ctpid())); - cbCvlanTpidOverride->setChecked(vlan->vlanFlags().testFlag( - VlanProtocol::VlanCtpidOverride)); - gbCvlan->setChecked(vlan->vlanFlags().testFlag( - VlanProtocol::VlanCvlanTagged)); - - cmbSvlanPrio->setCurrentIndex(vlan->svlanPrio()); - cmbSvlanCfi->setCurrentIndex(vlan->svlanCfi()); - leSvlanId->setText(str.setNum(vlan->svlanId())); - leSvlanTpid->setText(str.setNum(vlan->stpid())); - cbSvlanTpidOverride->setChecked(vlan->vlanFlags().testFlag( - VlanProtocol::VlanStpidOverride)); - gbSvlan->setChecked(vlan->vlanFlags().testFlag( - VlanProtocol::VlanSvlanTagged)); + if ((mSelectedProtocols.size() > (i+2)) && + (mSelectedProtocols.at(i+2) == 124)) // SNAP + { + rbFtLlcSnap->setChecked(true); + i+=3; + } + else + { + rbFt802Dot3Llc->setChecked(true); + i+=2; + } + } + else + { + rbFt802Dot3Raw->setChecked(true); + i++; } } - } + else + rbFtNone->setChecked(true); - // L3 - { - // L3 | IP + // L3 + if (mSelectedProtocols.at(i) == 52) // Payload { - leIpVersion->setText(str.setNum(pStream->ip()->ver())); - cbIpVersionOverride->setChecked( - pStream->ip()->ipFlags().testFlag(IpProtocol::IpOverrideVersion)); - leIpHdrLen->setText(str.setNum(pStream->ip()->hdrLen())); - cbIpHdrLenOverride->setChecked( - pStream->ip()->ipFlags().testFlag(IpProtocol::IpOverrideHdrLen)); - - leIpTos->setText(uintToHexStr(pStream->ip()->tos(), str, 1)); - - leIpLength->setText(str.setNum(pStream->ip()->totLen())); - cbIpLengthOverride->setChecked( - pStream->ip()->ipFlags().testFlag(IpProtocol::IpOverrideTotLen)); - - leIpId->setText(uintToHexStr(pStream->ip()->id(), str, 2)); - leIpFragOfs->setText(str.setNum(pStream->ip()->fragOfs())); - cbIpFlagsDf->setChecked((pStream->ip()->flags() & IP_FLAG_DF) > 0); - cbIpFlagsMf->setChecked((pStream->ip()->flags() & IP_FLAG_MF) > 0); - - leIpTtl->setText(str.setNum(pStream->ip()->ttl())); - leIpProto->setText(uintToHexStr(pStream->ip()->proto(), str, 1)); - - leIpCksum->setText(uintToHexStr(pStream->ip()->cksum(), str, 2)); - cbIpCksumOverride->setChecked( - pStream->ip()->ipFlags().testFlag(IpProtocol::IpOverrideCksum)); - - leIpSrcAddr->setText(QHostAddress(pStream->ip()->srcIp()).toString()); - cmbIpSrcAddrMode->setCurrentIndex(pStream->ip()->srcIpMode()); - leIpSrcAddrCount->setText(str.setNum(pStream->ip()->srcIpCount())); - leIpSrcAddrMask->setText(QHostAddress(pStream->ip()->srcIpMask()).toString()); - - leIpDstAddr->setText(QHostAddress(pStream->ip()->dstIp()).toString()); - cmbIpDstAddrMode->setCurrentIndex(pStream->ip()->dstIpMode()); - leIpDstAddrCount->setText(str.setNum(pStream->ip()->dstIpCount())); - leIpDstAddrMask->setText(QHostAddress(pStream->ip()->dstIpMask()).toString()); + i++; + goto _proto_parse_done; } - - // L3 | ARP + else if (mSelectedProtocols.at(i) == 130) // IP4 { - // TODO(LOW) + rbL3Ipv4->setChecked(true); + i++; } - } - - // L4 - { - // L4 | TCP + else if (mSelectedProtocols.at(i) == 131) // ARP { - leTcpSrcPort->setText(str.setNum(pStream->tcp()->srcPort())); - leTcpDstPort->setText(str.setNum(pStream->tcp()->dstPort())); - - leTcpSeqNum->setText(str.setNum(pStream->tcp()->seqNum())); - leTcpAckNum->setText(str.setNum(pStream->tcp()->ackNum())); - - leTcpHdrLen->setText(str.setNum(pStream->tcp()->hdrLen())); - cbTcpHdrLenOverride->setChecked((pStream->tcp()->tcpFlags(). - testFlag(TcpProtocol::TcpOverrideHdrLen))); - - leTcpWindow->setText(str.setNum(pStream->tcp()->window())); - - leTcpCksum->setText(str.setNum(pStream->tcp()->cksum())); - cbTcpCksumOverride->setChecked((pStream->tcp()->tcpFlags(). - testFlag(TcpProtocol::TcpOverrideCksum))); - - leTcpUrgentPointer->setText(str.setNum(pStream->tcp()->urgPtr())); - - cbTcpFlagsUrg->setChecked((pStream->tcp()->flags() & TCP_FLAG_URG) > 0); - cbTcpFlagsAck->setChecked((pStream->tcp()->flags() & TCP_FLAG_ACK) > 0); - cbTcpFlagsPsh->setChecked((pStream->tcp()->flags() & TCP_FLAG_PSH) > 0); - cbTcpFlagsRst->setChecked((pStream->tcp()->flags() & TCP_FLAG_RST) > 0); - cbTcpFlagsSyn->setChecked((pStream->tcp()->flags() & TCP_FLAG_SYN) > 0); - cbTcpFlagsFin->setChecked((pStream->tcp()->flags() & TCP_FLAG_FIN) > 0); + rbL3Arp->setChecked(true); + i++; } + else + rbL3None->setChecked(true); - // L4 | UDP + if (i == mSelectedProtocols.size()) + goto _proto_parse_done; + + // L4 + if (mSelectedProtocols.at(i) == 52) // Payload { - leUdpSrcPort->setText(str.setNum(pStream->udp()->srcPort())); - leUdpDstPort->setText(str.setNum(pStream->udp()->dstPort())); - - leUdpLength->setText(str.setNum(pStream->udp()->totLen())); - cbUdpLengthOverride->setChecked((pStream->udp()->udpFlags(). - testFlag(UdpProtocol::UdpOverrideTotLen))); - - - leUdpCksum->setText(str.setNum(pStream->udp()->cksum())); - cbUdpCksumOverride->setChecked((pStream->udp()->udpFlags(). - testFlag(UdpProtocol::UdpOverrideCksum))); + i++; + goto _proto_parse_done; } - - // L4 | ICMP + else if (mSelectedProtocols.at(i) == 140) // TCP { - // TODO(LOW) + rbL4Tcp->setChecked(true); + i++; } - - // L4 | IGMP + else if (mSelectedProtocols.at(i) == 141) // UDP { - // TODO(LOW) + rbL4Udp->setChecked(true); + i++; } + else if (mSelectedProtocols.at(i) == 142) // ICMP + { + rbL4Icmp->setChecked(true); + i++; + } + else if (mSelectedProtocols.at(i) == 143) // IGMP + { + rbL4Igmp->setChecked(true); + i++; + } + else + rbL4None->setChecked(true); + + Q_ASSERT(mSelectedProtocols.at(i) == 52); // Payload + i++; + +_proto_parse_done: + Q_ASSERT(i == mSelectedProtocols.size()); + + mpStream->loadProtocolWidgets(); } // Stream Control { - switch (pStream->sendUnit()) + switch (mpStream->sendUnit()) { case Stream::e_su_packets: rbSendPackets->setChecked(true); @@ -799,10 +785,10 @@ void StreamConfigDialog::LoadCurrentStream() rbSendBursts->setChecked(true); break; default: - qWarning("Unhandled sendUnit = %d\n", pStream->sendUnit()); + qWarning("Unhandled sendUnit = %d\n", mpStream->sendUnit()); } - switch (pStream->sendMode()) + switch (mpStream->sendMode()) { case Stream::e_sm_fixed: rbModeFixed->setChecked(true); @@ -811,10 +797,10 @@ void StreamConfigDialog::LoadCurrentStream() rbModeContinuous->setChecked(true); break; default: - qWarning("Unhandled sendMode = %d\n", pStream->sendMode()); + qWarning("Unhandled sendMode = %d\n", mpStream->sendMode()); } - switch(pStream->nextWhat()) + switch(mpStream->nextWhat()) { case Stream::e_nw_stop: rbActionStop->setChecked(true); @@ -826,31 +812,27 @@ void StreamConfigDialog::LoadCurrentStream() rbActionGotoStream->setChecked(true); break; default: - qWarning("Unhandled nextAction = %d\n", pStream->nextWhat()); + qWarning("Unhandled nextAction = %d\n", mpStream->nextWhat()); } - leNumPackets->setText(QString().setNum(pStream->numPackets())); - leNumBursts->setText(QString().setNum(pStream->numBursts())); - lePacketsPerBurst->setText(QString().setNum(pStream->burstSize())); - lePacketsPerSec->setText(QString().setNum(pStream->packetRate())); - leBurstsPerSec->setText(QString().setNum(pStream->burstRate())); + leNumPackets->setText(QString().setNum(mpStream->numPackets())); + leNumBursts->setText(QString().setNum(mpStream->numBursts())); + lePacketsPerBurst->setText(QString().setNum(mpStream->burstSize())); + lePacketsPerSec->setText(QString().setNum(mpStream->packetRate())); + leBurstsPerSec->setText(QString().setNum(mpStream->burstRate())); // TODO(MED): Change this when we support goto to specific stream leStreamId->setText(QString("0")); } } -void StreamConfigDialog::StoreCurrentStream() +void StreamConfigDialog::StoreCurrentStream(Stream *pStream) { - Stream *pStream = &mPort.streamByIndex(mCurrentStreamIndex); QString str; bool isOk; qDebug("storing pStream %p", pStream); // Meta Data - pStream->setPatternMode((Stream::DataPatternMode) cmbPatternMode->currentIndex()); - pStream->setPattern(lePattern->text().remove(QChar(' ')).toULong(&isOk, 16)); - pStream->setLenMode((Stream::FrameLengthMode) cmbPktLenMode->currentIndex()); pStream->setFrameLen(lePktLen->text().toULong(&isOk)); pStream->setFrameLenMin(lePktLenMin->text().toULong(&isOk)); @@ -858,235 +840,9 @@ void StreamConfigDialog::StoreCurrentStream() // Protocols { - if (rbFtNone->isChecked()) - pStream->setFrameType(Stream::e_ft_none); - else if (rbFtEthernet2->isChecked()) - pStream->setFrameType(Stream::e_ft_eth_2); - else if (rbFt802Dot3Raw->isChecked()) - pStream->setFrameType(Stream::e_ft_802_3_raw); - else if (rbFt802Dot3Llc->isChecked()) - pStream->setFrameType(Stream::e_ft_802_3_llc); - else if (rbFtLlcSnap->isChecked()) - pStream->setFrameType(Stream::e_ft_snap); - qDebug("store ft(%d)\n", pStream->frameType()); - - pStream->llc()->setDsap(leDsap->text().remove(QChar(' ')).toULong(&isOk, 16)); - pStream->llc()->setSsap(leSsap->text().remove(QChar(' ')).toULong(&isOk, 16)); - pStream->llc()->setCtl(leControl->text().remove(QChar(' ')).toULong(&isOk, 16)); - pStream->snap()->setOui(leOui->text().remove(QChar(' ')).toULong(&isOk, 16)); - pStream->eth2()->setType(leType->text().remove(QChar(' ')).toULong(&isOk, 16)); - - if (rbL3None->isChecked()) - pStream->setL3Proto(Stream::e_l3_none); - else if (rbL3Ipv4->isChecked()) - pStream->setL3Proto(Stream::e_l3_ip); - else if (rbL3Arp->isChecked()) - pStream->setL3Proto(Stream::e_l3_arp); - else - { - qCritical("No L3 Protocol??? Problem in Code!!!"); - pStream->setL3Proto(Stream::e_l3_none); - } - - if (rbL4None->isChecked()) - pStream->setL4Proto(Stream::e_l4_none); - else if (rbL4Tcp->isChecked()) - pStream->setL4Proto(Stream::e_l4_tcp); - else if (rbL4Udp->isChecked()) - pStream->setL4Proto(Stream::e_l4_udp); - else if (rbL4Icmp->isChecked()) - pStream->setL4Proto(Stream::e_l4_icmp); - else if (rbL4Igmp->isChecked()) - pStream->setL4Proto(Stream::e_l4_igmp); - else - { - qCritical("No L4 Protocol??? Problem in Code!!!"); - pStream->setL4Proto(Stream::e_l4_none); - } - } - - // L2 - { - // L2 | Ethernet - { - qDebug("%s: LL dstMac = %llx", __FUNCTION__, - leDstMac->text().remove(QChar(' ')).toULongLong(&isOk, 16)); - pStream->mac()->setDstMac( - leDstMac->text().remove(QChar(' ')).toULongLong(&isOk, 16)); -#if 1 - qDebug("%s: dstMac = %llx", __FUNCTION__, - pStream->mac()->dstMac()); - qDebug("%s: dstMac = [%s] %d", __FUNCTION__, - leDstMac->text().toAscii().constData(), isOk); -#endif - pStream->mac()->setDstMacMode( - (MacProtocol::MacAddrMode) cmbDstMacMode->currentIndex()); - pStream->mac()->setDstMacCount( - leDstMacCount->text().toULong(&isOk)); - pStream->mac()->setDstMacStep( - leDstMacStep->text().toULong(&isOk)); - - pStream->mac()->setSrcMac( - leSrcMac->text().remove(QChar(' ')).toULongLong(&isOk, 16)); - qDebug("%s: srcMac = %llx", __FUNCTION__, - pStream->mac()->srcMac()); - qDebug("%s: srcMac = [%s] %d", __FUNCTION__, - leSrcMac->text().toAscii().constData(), isOk); - pStream->mac()->setSrcMacMode( - (MacProtocol::MacAddrMode) cmbSrcMacMode->currentIndex()); - pStream->mac()->setSrcMacCount( - leSrcMacCount->text().toULong(&isOk)); - pStream->mac()->setSrcMacStep( - - leSrcMacStep->text().toULong(&isOk)); - - { - VlanProtocol *vlan = pStream->vlan(); - VlanProtocol::VlanFlags f = 0; - - vlan->setCvlanPrio(cmbCvlanPrio->currentIndex()); - vlan->setCvlanCfi(cmbCvlanCfi->currentIndex()); - vlan->setCvlanId(leCvlanId->text().toULong(&isOk)); - vlan->setCtpid(leCvlanTpid->text().remove(QChar(' ')).toULong(&isOk, 16)); - if (cbCvlanTpidOverride->isChecked()) - f |= VlanProtocol::VlanCtpidOverride; - if (gbCvlan->isChecked()) - f |= VlanProtocol::VlanCvlanTagged; - - vlan->setSvlanPrio(cmbSvlanPrio->currentIndex()); - vlan->setSvlanCfi(cmbSvlanCfi->currentIndex()); - vlan->setSvlanId(leSvlanId->text().toULong(&isOk)); - vlan->setStpid(leSvlanTpid->text().remove(QChar(' ')).toULong(&isOk, 16)); - if (cbSvlanTpidOverride->isChecked()) - f |= VlanProtocol::VlanStpidOverride; - if (gbSvlan->isChecked()) - f |= VlanProtocol::VlanSvlanTagged; - - vlan->setVlanFlags(f); - } - } - } - - // L3 - { - // L3 | IP - { - IpProtocol *ip = pStream->ip(); - IpProtocol::IpFlags f = 0; - int ff = 0; - - ip->setVer(leIpVersion->text().toULong(&isOk)); - if (cbIpVersionOverride->isChecked()) - f |= IpProtocol::IpOverrideVersion; - ip->setHdrLen(leIpHdrLen->text().toULong(&isOk)); - if (cbIpHdrLenOverride->isChecked()) - f |= IpProtocol::IpOverrideHdrLen; - - ip->setTos(leIpTos->text().toULong(&isOk, 16)); - - ip->setTotLen(leIpLength->text().toULong(&isOk)); - if (cbIpLengthOverride->isChecked()) - f |= IpProtocol::IpOverrideHdrLen; - - ip->setId(leIpId->text().remove(QChar(' ')).toULong(&isOk, 16)); - ip->setFragOfs(leIpFragOfs->text().toULong(&isOk)); - - if (cbIpFlagsDf->isChecked()) ff |= IP_FLAG_DF; - if (cbIpFlagsMf->isChecked()) ff |= IP_FLAG_MF; - ip->setFlags(ff); - - ip->setTtl(leIpTtl->text().toULong(&isOk)); - ip->setProto(leIpProto->text().remove(QChar(' ')).toULong(&isOk, 16)); - - ip->setCksum(leIpCksum->text().remove(QChar(' ')).toULong(&isOk)); - if (cbIpCksumOverride->isChecked()) - f |= IpProtocol::IpOverrideCksum; - - ip->setSrcIp(QHostAddress(leIpSrcAddr->text()).toIPv4Address()); - ip->setSrcIpMode((IpProtocol::IpAddrMode) cmbIpSrcAddrMode->currentIndex()); - ip->setSrcIpCount(leIpSrcAddrCount->text().toULong(&isOk)); - ip->setSrcIpMask(QHostAddress(leIpSrcAddrMask->text()).toIPv4Address()); - - ip->setDstIp(QHostAddress(leIpDstAddr->text()).toIPv4Address()); - ip->setDstIpMode((IpProtocol::IpAddrMode) cmbIpDstAddrMode->currentIndex()); - ip->setDstIpCount(leIpDstAddrCount->text().toULong(&isOk)); - ip->setDstIpMask(QHostAddress(leIpDstAddrMask->text()).toIPv4Address()); - - ip->setIpFlags(f); - } - - // L3 | ARP - { - // TODO(LOW) - } - } - - // L4 - { - // L4 | TCP - { - TcpProtocol *tcp = pStream->tcp(); - TcpProtocol::TcpFlags f = 0; - int ff = 0; - - tcp->setSrcPort(leTcpSrcPort->text().toULong(&isOk)); - tcp->setDstPort(leTcpDstPort->text().toULong(&isOk)); - - tcp->setSeqNum(leTcpSeqNum->text().toULong(&isOk)); - tcp->setAckNum(leTcpAckNum->text().toULong(&isOk)); - - tcp->setHdrLen(leTcpHdrLen->text().toULong(&isOk)); - if (cbTcpHdrLenOverride->isChecked()) - f |= TcpProtocol::TcpOverrideHdrLen; - - tcp->setWindow(leTcpWindow->text().toULong(&isOk)); - - tcp->setCksum(leTcpCksum->text().remove(QChar(' ')).toULong(&isOk)); - if (cbTcpCksumOverride->isChecked()) - f |= TcpProtocol::TcpOverrideCksum; - - tcp->setUrgPtr(leTcpUrgentPointer->text().toULong(&isOk)); - - if (cbTcpFlagsUrg->isChecked()) ff |= TCP_FLAG_URG; - if (cbTcpFlagsAck->isChecked()) ff |= TCP_FLAG_ACK; - if (cbTcpFlagsPsh->isChecked()) ff |= TCP_FLAG_PSH; - if (cbTcpFlagsRst->isChecked()) ff |= TCP_FLAG_RST; - if (cbTcpFlagsSyn->isChecked()) ff |= TCP_FLAG_SYN; - if (cbTcpFlagsFin->isChecked()) ff |= TCP_FLAG_FIN; - tcp->setFlags(ff); - - tcp->setTcpFlags(f); - } - - // L4 | UDP - { - UdpProtocol *udp = pStream->udp(); - UdpProtocol::UdpFlags f = 0; - - udp->setSrcPort(leUdpSrcPort->text().toULong(&isOk)); - udp->setDstPort(leUdpDstPort->text().toULong(&isOk)); - - udp->setTotLen(leUdpLength->text().toULong(&isOk)); - - if (cbUdpLengthOverride->isChecked()) - f |= UdpProtocol::UdpOverrideTotLen; - - udp->setCksum(leUdpCksum->text().remove(QChar(' ')).toULong(&isOk)); - if (cbUdpCksumOverride->isChecked()) - f |= UdpProtocol::UdpOverrideCksum; - - udp->setUdpFlags(f); - } - - // L4 | ICMP - { - // TODO)(LOW) - } - - // L4 | IGMP - { - // TODO(LOW) - } + updateSelectedProtocols(); + pStream->setFrameProtocol(mSelectedProtocols); + pStream->storeProtocolWidgets(); } // Stream Control @@ -1119,11 +875,9 @@ void StreamConfigDialog::StoreCurrentStream() void StreamConfigDialog::on_pbOk_clicked() { // Store dialog contents into stream - StoreCurrentStream(); + StoreCurrentStream(mPort.streamByIndex(mCurrentStreamIndex)); qDebug("stream stored"); lastTopLevelTabIndex = twTopLevel->currentIndex(); lastProtoTabIndex = twProto->currentIndex(); } -//Junk Line for introducing a compiler error - diff --git a/client/streamconfigdialog.h b/client/streamconfigdialog.h index 7dbedbe..f6c5a41 100644 --- a/client/streamconfigdialog.h +++ b/client/streamconfigdialog.h @@ -14,7 +14,7 @@ /* ** TODO -** - Improve HexStr handling +** \todo Improve HexStr handling ** */ @@ -31,9 +31,13 @@ private: Port& mPort; uint mCurrentStreamIndex; + Stream *mpStream; + QList mSelectedProtocols; + PacketModel *mpPacketModel; ModelTest *mpPacketModelTester; + // The following static variables are used to track the "selected" tab // for the various tab widgets so that it can be restored when the dialog // is opened the next time @@ -41,16 +45,12 @@ private: static int lastProtoTabIndex; void setupUiExtra(); + void updateSelectedProtocols(); void LoadCurrentStream(); - void StoreCurrentStream(); + void StoreCurrentStream(Stream *pStream); private slots: - void on_cmbPatternMode_currentIndexChanged(QString mode); void on_cmbPktLenMode_currentIndexChanged(QString mode); - void on_cmbDstMacMode_currentIndexChanged(QString mode); - void on_cmbSrcMacMode_currentIndexChanged(QString mode); - void on_cmbIpSrcAddrMode_currentIndexChanged(QString mode); - void on_cmbIpDstAddrMode_currentIndexChanged(QString mode); void on_pbPrev_clicked(); void on_pbNext_clicked(); @@ -59,21 +59,20 @@ private slots: 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_twProto_currentChanged(int index); + void update_NumPacketsAndNumBursts(); void on_pbOk_clicked(); }; -QString & uintToHexStr(quint64 num, QString &hexStr, quint8 octets); - #endif diff --git a/client/streamconfigdialog.ui b/client/streamconfigdialog.ui index 70fea95..e410c81 100644 --- a/client/streamconfigdialog.ui +++ b/client/streamconfigdialog.ui @@ -8,13 +8,16 @@ 0 0 - 534 - 521 + 590 + 517 Edit Stream + + :/icons/stream_edit.png + QLineEdit:enabled[inputMask = "HH; "], QLineEdit:enabled[inputMask = "HH HH; "], @@ -35,7 +38,7 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff 0 - + Packet Config @@ -53,57 +56,8 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff - - - - Data Pattern - - - - - - - Fixed Word - - - - - Increment Byte - - - - - Decrement Byte - - - - - Random - - - - - - - - HH HH HH HH; - - - - - - 11 - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - + Frame Length (including CRC) @@ -494,1198 +448,24 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff L2 - - - - - Ethernet - - - - - - Destination - - - - - - - HH HH HH HH HH HH; - - - - - - - - - - - Fixed - - - - - Increment - - - - - Decrement - - - - - - - - Count - - - - - - - false - - - 1 - - - 1 - - - - - - - Step - - - - - - - false - - - 1 - - - 1 - - - - - - - Source - - - - - - - HH HH HH HH HH HH; - - - - - - - - - - - Fixed - - - - - Increment - - - - - Decrement - - - - - - - - Count - - - - - - - false - - - 1 - - - - - - - Step - - - - - - - false - - - 1 - - - 1 - - - - - - - - - - VLAN/CVLAN - - - true - - - false - - - - - - Priority - - - - - - - CFI - - - - - - - VLAN - - - - - - - false - - - Override TPID - - - - - - - false - - - - 0 - - - - - 1 - - - - - 2 - - - - - 3 - - - - - 4 - - - - - 5 - - - - - 6 - - - - - 7 - - - - - - - - false - - - - 0 - - - - - 1 - - - - - - - - false - - - 0 - - - - - - - false - - - HH HH; - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - SVLAN - - - true - - - false - - - - - - Priority - - - - - - - CFI - - - - - - - VLAN - - - - - - - false - - - Override TPID - - - - - - - false - - - - 0 - - - - - 1 - - - - - 2 - - - - - 3 - - - - - 4 - - - - - 5 - - - - - 6 - - - - - 7 - - - - - - - - false - - - - 0 - - - - - 1 - - - - - - - - false - - - 0 - - - - - - - false - - - HH HH; - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + L3 - - - - - 0 - - - - - - - - - Override Version - - - - - - - false - - - 4 - - - - - - - Override Header Length - - - - - - - false - - - 5 - - - - - - - TOS/DSCP - - - - - - - HH; - - - - - - - - - - false - - - ... - - - - - - - Override Length - - - - - - - false - - - - - - - Identification - - - - - - - HH HH; - - - - - - - - - Qt::Vertical - - - - - - - - - Fragment Offset - - - - - - - - - - Don't Fragment - - - - - - - More Fragments - - - - - - - Time To Live (TTL) - - - - - - - 64 - - - - - - - Protocol - - - - - - - false - - - - - - - - - - Override Checksum - - - - - - - false - - - HH HH; - - - - - - - - - - - - false - - - - - - Mode - - - - - - - Count - - - - - - - Mask - - - - - - - Source - - - - - - - 009.009.009.009; - - - ... - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - Fixed - - - - - Increment Host - - - - - Decrement Host - - - - - Random Host - - - - - - - - false - - - - - - - - - - false - - - 255.255.255.255 - - - - - - - Destination - - - - - - - 000.000.000.000; - - - ... - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - Fixed - - - - - Increment Host - - - - - Decrement Host - - - - - Random Host - - - - - - - - false - - - - - - - - - - false - - - 255.255.255.255 - - - - - - - - - - - - Options - - - - - - - false - - - TODO - - - - - - - false - - - ... - - - - - - - - - Qt::Vertical - - - - 469 - 16 - - - - - - - - - - - 105 - 100 - 296 - 76 - - - - ARP : TODO - - - Qt::AlignCenter - - - - - - L4 - - - - - 0 - - - - - - - - - Source Port - - - - - - - - - - Destination Port - - - - - - - - - - Sequence Number - - - - - - - - - - Acknowledgement Number - - - - - - - - - - Override Header Length (x4) - - - - - - - false - - - - - - - Window - - - - - - - - - - Override Checksum - - - - - - - false - - - HH HH; - - - - - - - Urgent Pointer - - - - - - - - - - - - Qt::Vertical - - - - - - - Flags - - - - - - URG - - - - - - - ACK - - - - - - - PSH - - - - - - - RST - - - - - - - SYN - - - - - - - FIN - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Vertical - - - - 20 - 181 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - Source Port - - - - - - - - - - Destination Port - - - - - - - - - - Override Length - - - - - - - false - - - - - - - Override Checksum - - - - - - - false - - - HH HH; - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - ICMP: TODO - - - - - - - - - - - IGMP: TODO - - - - - - - - + - + Stream Control @@ -2042,7 +822,7 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff - + Packet View @@ -2118,11 +898,6 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff - - HexLineEdit - QLineEdit -
hexlineedit.h
-
DumpView QWidget @@ -2132,326 +907,16 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff
twTopLevel - cmbPatternMode - lePattern cmbPktLenMode lePktLen lePktLenMin lePktLenMax twProto - leDstMac - cmbDstMacMode - leDstMacCount - leDstMacStep - leSrcMac - cmbSrcMacMode - leSrcMacCount - leSrcMacStep - gbCvlan - cmbCvlanPrio - cmbCvlanCfi - leCvlanId - cbCvlanTpidOverride - leCvlanTpid - gbSvlan - cmbSvlanPrio - cmbSvlanCfi - leSvlanId - cbSvlanTpidOverride - leSvlanTpid - - cbCvlanTpidOverride - toggled(bool) - leCvlanTpid - setEnabled(bool) - - - 112 - 267 - - - 112 - 267 - - - - - cbSvlanTpidOverride - toggled(bool) - leSvlanTpid - setEnabled(bool) - - - 112 - 267 - - - 112 - 267 - - - - - gbCvlan - toggled(bool) - cmbCvlanPrio - setEnabled(bool) - - - 92 - 267 - - - 92 - 267 - - - - - gbCvlan - toggled(bool) - cmbCvlanCfi - setEnabled(bool) - - - 92 - 267 - - - 92 - 267 - - - - - gbCvlan - toggled(bool) - leCvlanId - setEnabled(bool) - - - 92 - 267 - - - 92 - 267 - - - - - gbCvlan - toggled(bool) - cbCvlanTpidOverride - setEnabled(bool) - - - 92 - 267 - - - 112 - 267 - - - - - gbSvlan - toggled(bool) - cmbSvlanPrio - setEnabled(bool) - - - 92 - 267 - - - 92 - 267 - - - - - gbSvlan - toggled(bool) - leSvlanId - setEnabled(bool) - - - 92 - 267 - - - 92 - 267 - - - - - gbSvlan - toggled(bool) - cbSvlanTpidOverride - setEnabled(bool) - - - 92 - 267 - - - 112 - 267 - - - - - gbSvlan - toggled(bool) - cmbSvlanCfi - setEnabled(bool) - - - 92 - 267 - - - 92 - 267 - - - - - cbUdpLengthOverride - toggled(bool) - leUdpLength - setEnabled(bool) - - - 145 - 334 - - - 145 - 334 - - - - - cbUdpCksumOverride - toggled(bool) - leUdpCksum - setEnabled(bool) - - - 145 - 334 - - - 145 - 334 - - - - - cbIpVersionOverride - toggled(bool) - leIpVersion - setEnabled(bool) - - - 123 - 305 - - - 123 - 305 - - - - - cbIpHdrLenOverride - toggled(bool) - leIpHdrLen - setEnabled(bool) - - - 123 - 305 - - - 123 - 305 - - - - - cbIpLengthOverride - toggled(bool) - leIpLength - setEnabled(bool) - - - 123 - 305 - - - 123 - 305 - - - - - cbIpCksumOverride - toggled(bool) - leIpCksum - setEnabled(bool) - - - 192 - 305 - - - 192 - 305 - - - - - cbTcpHdrLenOverride - toggled(bool) - leTcpHdrLen - setEnabled(bool) - - - 145 - 334 - - - 145 - 334 - - - - - cbTcpCksumOverride - toggled(bool) - leTcpCksum - setEnabled(bool) - - - 145 - 334 - - - 145 - 334 - - - pbOk clicked() @@ -2459,11 +924,11 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff accept() - 460 - 510 + 440 + 466 - 565 + 533 433 @@ -2475,11 +940,11 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff reject() - 543 - 510 + 523 + 466 - 561 + 533 466 @@ -2491,12 +956,12 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff setEnabled(bool) - 136 - 120 + 281 + 137 - 136 - 120 + 281 + 169 @@ -2507,12 +972,12 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff setEnabled(bool) - 41 - 101 + 30 + 66 - 96 - 120 + 30 + 266 @@ -2523,12 +988,12 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff setEnabled(bool) - 41 - 120 + 30 + 91 - 78 - 120 + 30 + 312 @@ -2539,12 +1004,12 @@ QLineEdit:enabled[inputMask = "HH HH HH HH HH HH; "] { background-color: #ccccff setEnabled(bool) - 41 - 120 + 30 + 91 - 136 - 120 + 134 + 177 diff --git a/client/streammodel.cpp b/client/streammodel.cpp index 6680f58..c1b887c 100644 --- a/client/streammodel.cpp +++ b/client/streammodel.cpp @@ -82,7 +82,7 @@ QVariant StreamModel::data(const QModelIndex &index, int role) const case StreamName: { if ((role == Qt::DisplayRole) || (role == Qt::EditRole)) - return mCurrentPort->streamByIndex(index.row()).name(); + return mCurrentPort->streamByIndex(index.row())->name(); else return QVariant(); break; @@ -91,7 +91,7 @@ QVariant StreamModel::data(const QModelIndex &index, int role) const { if ((role == Qt::CheckStateRole)) { - if (mCurrentPort->streamByIndex(index.row()).isEnabled()) + if (mCurrentPort->streamByIndex(index.row())->isEnabled()) return Qt::Checked; else return Qt::Unchecked; @@ -102,7 +102,7 @@ QVariant StreamModel::data(const QModelIndex &index, int role) const } case StreamNextWhat: { - int val = mCurrentPort->streamByIndex(index.row()).nextWhat(); + int val = mCurrentPort->streamByIndex(index.row())->nextWhat(); if (role == Qt::DisplayRole) return nextWhatOptionList().at(val); @@ -131,19 +131,19 @@ bool StreamModel::setData(const QModelIndex &index, const QVariant &value, int r { // Edit Supported Fields case StreamName: - mCurrentPort->streamByIndex(index.row()).setName(value.toString()); + mCurrentPort->streamByIndex(index.row())->setName(value.toString()); emit(dataChanged(index, index)); return true; case StreamStatus: - mCurrentPort->streamByIndex(index.row()).setIsEnabled(value.toBool()); + mCurrentPort->streamByIndex(index.row())->setIsEnabled(value.toBool()); emit(dataChanged(index, index)); return true; case StreamNextWhat: if (role == Qt::EditRole) { - mCurrentPort->streamByIndex(index.row()).setNextWhat( + mCurrentPort->streamByIndex(index.row())->setNextWhat( (Stream::NextWhat)value.toInt()); emit(dataChanged(index, index)); return true; diff --git a/common/Makefile b/common/Makefile deleted file mode 100644 index 7c95f2b..0000000 --- a/common/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -RM=del -PROTOC=protoc - -#-#-# - -all: protocol.pb.cc - -protocol.pb.cc: protocol.proto - $(PROTOC) --cpp_out=. $< - -clean: - $(RM) *.pb.h *.pb.cc - -distclean: clean diff --git a/common/abstractprotocol.cpp b/common/abstractprotocol.cpp new file mode 100644 index 0000000..429c6a3 --- /dev/null +++ b/common/abstractprotocol.cpp @@ -0,0 +1,225 @@ +#include "abstractprotocol.h" + +/*! + \class AbstractProtocol + + // FIXME - update this text + Bare Minimum set of methods that a subclass needs to reimplement + - protoDataCopyInto() [pure virtual] + - protoDataCopyFrom() [pure virtual] + - fieldCount() + + Any useful protocol should also provide implementations for + - name() + - shortName() + - fieldName() + + Protocols with meta fields should additionally implement + - metaFieldCount() + - isMetaField() +*/ +AbstractProtocol::AbstractProtocol(Stream *parent) +{ + stream = parent; + metaCount = -1; +} + +AbstractProtocol::~AbstractProtocol() +{ +} + + +/*! + \fn virtual void protoDataCopyInto(OstProto::Stream &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 + implement this function by using - \n + stream.AddExtension()->CopyFrom() */ + +/* + \fn virtual void protoDataCopyFrom(const OstProto::Stream &stream) = 0; + FIXME */ + +/*! Returns the full name of the protocol \n + The default implementation returns a null string */ +QString AbstractProtocol::name() const +{ + return QString(); +} + +/*! Returns the short name or abbreviation of the protocol \n + The default implementation forms and returns a abbreviation composed + of all the upper case chars in name() \n + The default implementation caches the abbreviation on its first invocation + and subsequently returns the cached abbreviation */ +QString AbstractProtocol::shortName() const +{ + if (protoAbbr.isNull()) + { + QString abbr; + + for (int i = 0; i < name().size(); i++) + if (name().at(i).isUpper()) abbr.append(name().at(i)); + + if (abbr.size()) + protoAbbr = abbr; + else + protoAbbr = QString(""); + } + + return protoAbbr; +} + +/*! Returns the number of fields (both Frame and Meta fields) \n + The default implementation returns zero */ +int AbstractProtocol::fieldCount() const +{ + return 0; +} + +/*! Returns the number of meta fields \n + The default implementation counts and returns the number of fields for which + fieldData(index, FieldIsMeta) return true\n + The default implementation caches the count on its first invocation + and subsequently returns the cached count */ +int AbstractProtocol::metaFieldCount() const +{ + if (metaCount < 0) + { + int c = 0; + for (int i = 0; i < fieldCount() ; i++) + if (fieldData(i, FieldIsMeta).toBool()) + c++; + metaCount = c; + } + + return metaCount; +} + +/*! Returns the number of frame fields \n + Convenience method - same as fieldCount() minus metaFieldCount() */ +int AbstractProtocol::frameFieldCount() const +{ + //qDebug("%s:%d, %d", __FUNCTION__, fieldCount(), metaFieldCount()); + return (fieldCount() - metaFieldCount()); +} + +/*! Returns the requested field attribute data \n + Protocols which have meta fields that vary a frame field across + streams may use the streamIndex to return the appropriate field value \n + Some field attriubutes e.g. FieldName may be invariant across streams\n + The default implementation returns the fieldValue() converted to string + The FieldTextValue attribute may include additional information about + 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 + */ +QVariant AbstractProtocol::fieldData(int index, FieldAttrib attrib, + int streamIndex) const +{ + switch (attrib) + { + case FieldName: + return QString(); + case FieldBitSize: + return fieldData(index, FieldFrameValue, streamIndex). + toByteArray().size() * 8; + case FieldValue: + return 0; + case FieldFrameValue: + return QByteArray(); + case FieldTextValue: + return QString(); + case FieldIsMeta: + return false; + + default: + qFatal("%s:%d: unhandled case %d\n", __FUNCTION__, __LINE__, + attrib); + } + + return QVariant(); +} + +/*! Sets the value of a field corresponding to index \n + Returns true if field is successfully set, false otherwise \n + The default implementation always returns false */ +bool AbstractProtocol::setFieldData(int index, const QVariant &value, + FieldAttrib attrib) +{ + return false; +} + +/*! 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 + the FrameValue of all the 'frame' fields of the protocol taking care of fields + which are not an integral number of bytes\n */ +QByteArray AbstractProtocol::protocolFrameValue(int streamIndex) const +{ + QByteArray proto, field; + int bits, lastbitpos = 0; + + for (int i=0; i < fieldCount() ; i++) + { + if (!fieldData(i, FieldIsMeta).toBool()) + { + field = fieldData(i, FieldFrameValue, streamIndex).toByteArray(); + bits = fieldData(i, FieldBitSize, streamIndex).toUInt(); + if (bits == 0) + continue; + + qDebug("<<< %d, %d >>>>", proto.size(), field.size()); + + if (bits == field.size() * 8) + { + if (lastbitpos == 0) + proto.append(field); + else + { + Q_ASSERT(field.size() > 0); + + char c = proto[proto.size() - 1]; + proto[proto.size() - 1] = c | (field.at(0) >> lastbitpos); + for (int j = 0; j < field.size() - 1; j++) + proto.append(field.at(j) << lastbitpos | + field.at(j+1) >> lastbitpos); + } + } + else if (bits < field.size() * 8) + { + int u, v; + + u = bits / 8; + v = bits % 8; + if (lastbitpos == 0) + { + proto.append(field.left(u+1)); + char c = proto[proto.size() - 1]; + proto[proto.size() - 1] = c & (0xFF << (8 - v)); + lastbitpos = v; + } + else + { + char c = proto[proto.size() - 1]; + proto[proto.size() - 1] = c | (field.at(0) >> lastbitpos); + for (int j = 0; j < (u - 1); j++) + proto.append(field.at(j) << lastbitpos | + field.at(j+1) >> lastbitpos); + if (u) + proto.append( field.at(u) & (0xFF << (8 - v)) ); + lastbitpos = (lastbitpos + bits) % 8; + } + } + else // if (bits > field.size() * 8) + { + qFatal("bitsize more than FrameValue size. skipping..."); + continue; + } + } + } + + return proto; +} + diff --git a/common/abstractprotocol.h b/common/abstractprotocol.h new file mode 100644 index 0000000..7c7255e --- /dev/null +++ b/common/abstractprotocol.h @@ -0,0 +1,62 @@ +#ifndef _ABSTRACT_PROTOCOL_H +#define _ABSTRACT_PROTOCOL_H + +#include +#include +#include +#include + +#include "../common/protocol.pb.h" + +#define BASE_BIN (2) +#define BASE_OCT (8) +#define BASE_DEC (10) +#define BASE_HEX (16) + +class Stream; + +class AbstractProtocol +{ +private: + mutable int metaCount; + mutable QString protoAbbr; + +protected: + Stream *stream; + +public: + enum FieldAttrib { + FieldName, //! name + FieldValue, //! value in host byte order (user editable) + FieldTextValue, //! value as text + FieldFrameValue, //! frame encoded value in network byte order + FieldBitSize, //! size in bits + FieldIsMeta //! bool indicating if field is meta + }; + + AbstractProtocol(Stream *parent = 0); + virtual ~AbstractProtocol(); + + virtual void protoDataCopyInto(OstProto::Stream &stream) = 0; + virtual void protoDataCopyFrom(const OstProto::Stream &stream) = 0; + + virtual QString name() const; + virtual QString shortName() const; + + virtual int fieldCount() const; + virtual int metaFieldCount() const; + int frameFieldCount() const; + + virtual QVariant fieldData(int index, FieldAttrib attrib, + int streamIndex = 0) const; + virtual bool setFieldData(int index, const QVariant &value, + FieldAttrib attrib = FieldValue); + + QByteArray protocolFrameValue(int streamIndex = 0) const; + + virtual QWidget* configWidget() = 0; + virtual void loadConfigWidget() = 0; + virtual void storeConfigWidget() = 0; +}; + +#endif diff --git a/common/dot3.cpp b/common/dot3.cpp new file mode 100644 index 0000000..67b70d9 --- /dev/null +++ b/common/dot3.cpp @@ -0,0 +1,110 @@ +#include +#include + +#include "Dot3.h" + +Dot3ConfigForm *Dot3Protocol::configForm = NULL; + +Dot3ConfigForm::Dot3ConfigForm(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); +} + +Dot3Protocol::Dot3Protocol(Stream *parent) + : AbstractProtocol(parent) +{ + if (configForm == NULL) + configForm = new Dot3ConfigForm; +} + +Dot3Protocol::~Dot3Protocol() +{ +} + +void Dot3Protocol::protoDataCopyInto(OstProto::Stream &stream) +{ + // FIXME: multiple headers + stream.MutableExtension(OstProto::dot3)->CopyFrom(data); +} + +void Dot3Protocol::protoDataCopyFrom(const OstProto::Stream &stream) +{ + // FIXME: multiple headers + if (stream.HasExtension(OstProto::dot3)) + data.MergeFrom(stream.GetExtension(OstProto::dot3)); +} + +QString Dot3Protocol::name() const +{ + return QString("802.3"); +} + +QString Dot3Protocol::shortName() const +{ + return QString("802.3"); +} + +int Dot3Protocol::fieldCount() const +{ + return dot3_fieldCount; +} + +QVariant Dot3Protocol::fieldData(int index, FieldAttrib attrib, + int streamIndex) const +{ + switch (index) + { + case dot3_length: + switch(attrib) + { + case FieldName: + return QString("Length"); + case FieldValue: + return data.length(); + case FieldTextValue: + return QString("%1").arg(data.length()); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.length(), (uchar*) fv.data()); + return fv; + } + default: + break; + } + break; + + default: + break; + } + + return AbstractProtocol::fieldData(index, attrib, streamIndex); +} + +bool Dot3Protocol::setFieldData(int index, const QVariant &value, + FieldAttrib attrib) +{ + // FIXME + return false; +} + + +QWidget* Dot3Protocol::configWidget() +{ + return configForm; +} + +void Dot3Protocol::loadConfigWidget() +{ + configForm->leLength->setText(QString().setNum(data.length())); +} + +void Dot3Protocol::storeConfigWidget() +{ + bool isOk; + + data.set_length(configForm->leLength->text().toULong(&isOk)); +} + diff --git a/common/dot3.h b/common/dot3.h new file mode 100644 index 0000000..e49f312 --- /dev/null +++ b/common/dot3.h @@ -0,0 +1,50 @@ +#ifndef _DOT3_H +#define _DOT3_H + +#include "abstractprotocol.h" + +#include "dot3.pb.h" +#include "ui_Dot3.h" + +class Dot3ConfigForm : public QWidget, public Ui::dot3 +{ + Q_OBJECT +public: + Dot3ConfigForm(QWidget *parent = 0); +}; + +class Dot3Protocol : public AbstractProtocol +{ +private: + OstProto::Dot3 data; + static Dot3ConfigForm *configForm; + enum Dot3field + { + dot3_length, + + dot3_fieldCount + }; + +public: + Dot3Protocol(Stream *parent = 0); + virtual ~Dot3Protocol(); + + virtual void protoDataCopyInto(OstProto::Stream &stream); + virtual void protoDataCopyFrom(const OstProto::Stream &stream); + + virtual QString name() const; + virtual QString shortName() const; + + virtual int fieldCount() const; + + virtual QVariant fieldData(int index, FieldAttrib attrib, + int streamIndex = 0) const; + virtual bool setFieldData(int index, const QVariant &value, + FieldAttrib attrib = FieldValue); + + virtual QWidget* configWidget(); + virtual void loadConfigWidget(); + virtual void storeConfigWidget(); +}; + +#endif diff --git a/common/dot3.proto b/common/dot3.proto new file mode 100644 index 0000000..37f78ca --- /dev/null +++ b/common/dot3.proto @@ -0,0 +1,12 @@ +import "protocol.proto"; + +package OstProto; + +// 802.3 +message Dot3 { + optional uint32 length = 1; +} + +extend Stream { + optional Dot3 dot3 = 122; +} diff --git a/common/dot3.ui b/common/dot3.ui new file mode 100644 index 0000000..d452bd0 --- /dev/null +++ b/common/dot3.ui @@ -0,0 +1,59 @@ + + dot3 + + + + 0 + 0 + 131 + 72 + + + + Form + + + + + + 802.3 + + + + + + Length + + + leLength + + + + + + + false + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + diff --git a/common/eth2.cpp b/common/eth2.cpp new file mode 100644 index 0000000..caaf75b --- /dev/null +++ b/common/eth2.cpp @@ -0,0 +1,129 @@ +#include +#include + +#include "eth2.h" + +Eth2ConfigForm *Eth2Protocol::configForm = NULL; + +Eth2ConfigForm::Eth2ConfigForm(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); +} + +Eth2Protocol::Eth2Protocol(Stream *parent) + : AbstractProtocol(parent) +{ + if (configForm == NULL) + configForm = new Eth2ConfigForm; +} + +Eth2Protocol::~Eth2Protocol() +{ +} + +void Eth2Protocol::protoDataCopyInto(OstProto::Stream &stream) +{ + // FIXME: multiple headers + stream.MutableExtension(OstProto::eth2)->CopyFrom(data); +} + +void Eth2Protocol::protoDataCopyFrom(const OstProto::Stream &stream) +{ + // FIXME: multiple headers + if (stream.HasExtension(OstProto::eth2)) + data.MergeFrom(stream.GetExtension(OstProto::eth2)); +} + +QString Eth2Protocol::name() const +{ + return QString("Ethernet II"); +} + +QString Eth2Protocol::shortName() const +{ + return QString("Eth II"); +} + +int Eth2Protocol::fieldCount() const +{ + return eth2_fieldCount; +} + +QVariant Eth2Protocol::fieldData(int index, FieldAttrib attrib, + int streamIndex) const +{ + switch (index) + { + case eth2_type: + switch(attrib) + { + case FieldName: + return QString("Type"); + case FieldValue: + return data.type(); + case FieldTextValue: + return QString("%1").arg(data.type(), 16); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.type(), (uchar*) fv.data()); + return fv; + } + default: + break; + } + break; + + default: + break; + } + + return AbstractProtocol::fieldData(index, attrib, streamIndex); +} + +bool Eth2Protocol::setFieldData(int index, const QVariant &value, + FieldAttrib attrib) +{ + bool isOk = false; + + if (attrib != FieldValue) + return false; + + switch (index) + { + case eth2_type: + { + uint type = value.toUInt(&isOk); + if (isOk) + data.set_type(type); + } + default: + break; + } + return isOk; +} + +QWidget* Eth2Protocol::configWidget() +{ + return configForm; +} + +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 +} + +void Eth2Protocol::storeConfigWidget() +{ + bool isOk; + + data.set_type(configForm->leType->text().remove(QChar(' ')).toULong(&isOk, 16)); +} + diff --git a/common/eth2.h b/common/eth2.h new file mode 100644 index 0000000..580b712 --- /dev/null +++ b/common/eth2.h @@ -0,0 +1,50 @@ +#ifndef _ETH2_H +#define _ETH2_H + +#include "abstractprotocol.h" + +#include "eth2.pb.h" +#include "ui_eth2.h" + +class Eth2ConfigForm : public QWidget, public Ui::eth2 +{ + Q_OBJECT +public: + Eth2ConfigForm(QWidget *parent = 0); +}; + +class Eth2Protocol : public AbstractProtocol +{ +private: + OstProto::Eth2 data; + static Eth2ConfigForm *configForm; + enum eth2field + { + eth2_type = 0, + + eth2_fieldCount + }; + +public: + Eth2Protocol(Stream *parent = 0); + virtual ~Eth2Protocol(); + + virtual void protoDataCopyInto(OstProto::Stream &stream); + virtual void protoDataCopyFrom(const OstProto::Stream &stream); + + virtual QString name() const; + virtual QString shortName() const; + + virtual int fieldCount() const; + + virtual QVariant fieldData(int index, FieldAttrib attrib, + int streamIndex = 0) const; + virtual bool setFieldData(int index, const QVariant &value, + FieldAttrib attrib = FieldValue); + + virtual QWidget* configWidget(); + virtual void loadConfigWidget(); + virtual void storeConfigWidget(); +}; + +#endif diff --git a/common/eth2.proto b/common/eth2.proto new file mode 100644 index 0000000..224c25d --- /dev/null +++ b/common/eth2.proto @@ -0,0 +1,12 @@ +import "protocol.proto"; + +package OstProto; + +// Ethernet II +message Eth2 { + optional uint32 type = 1; +} + +extend Stream { + optional Eth2 eth2 = 121; +} diff --git a/common/eth2.ui b/common/eth2.ui new file mode 100644 index 0000000..9099dbb --- /dev/null +++ b/common/eth2.ui @@ -0,0 +1,62 @@ + + eth2 + + + + 0 + 0 + 166 + 72 + + + + Form + + + + + + Ethernet II + + + + + + Ethernet Type + + + leType + + + + + + + true + + + HH HH; + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + diff --git a/common/ip4.cpp b/common/ip4.cpp new file mode 100644 index 0000000..625d3c7 --- /dev/null +++ b/common/ip4.cpp @@ -0,0 +1,455 @@ +#include +#include + +#include "ip4.h" + +Ip4ConfigForm *Ip4Protocol::configForm = NULL; + +Ip4ConfigForm::Ip4ConfigForm(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); + + connect(cmbIpSrcAddrMode, SIGNAL(currentIndexChanged(int)), + this, SLOT(on_cmbIpSrcAddrMode_currentIndexChanged(int))); + connect(cmbIpDstAddrMode, SIGNAL(currentIndexChanged(int)), + this, SLOT(on_cmbIpDstAddrMode_currentIndexChanged(int))); +} + +void Ip4ConfigForm::on_cmbIpSrcAddrMode_currentIndexChanged(int index) +{ + if (index == OstProto::Ip4::e_im_fixed) + { + leIpSrcAddrCount->setDisabled(true); + leIpSrcAddrMask->setDisabled(true); + } + else + { + leIpSrcAddrCount->setEnabled(true); + leIpSrcAddrMask->setEnabled(true); + } +} + +void Ip4ConfigForm::on_cmbIpDstAddrMode_currentIndexChanged(int index) +{ + if (index == OstProto::Ip4::e_im_fixed) + { + leIpDstAddrCount->setDisabled(true); + leIpDstAddrMask->setDisabled(true); + } + else + { + leIpDstAddrCount->setEnabled(true); + leIpDstAddrMask->setEnabled(true); + } +} + +Ip4Protocol::Ip4Protocol(Stream *parent) + : AbstractProtocol(parent) +{ + if (configForm == NULL) + configForm = new Ip4ConfigForm; +} + +Ip4Protocol::~Ip4Protocol() +{ +} + +void Ip4Protocol::protoDataCopyInto(OstProto::Stream &stream) +{ + // FIXME: multiple headers + stream.MutableExtension(OstProto::ip4)->CopyFrom(data); +} + +void Ip4Protocol::protoDataCopyFrom(const OstProto::Stream &stream) +{ + // FIXME: multiple headers + if (stream.HasExtension(OstProto::ip4)) + data.MergeFrom(stream.GetExtension(OstProto::ip4)); +} + +QString Ip4Protocol::name() const +{ + return QString("Internet Protocol ver 4"); +} + +QString Ip4Protocol::shortName() const +{ + return QString("IPv4"); +} + +int Ip4Protocol::fieldCount() const +{ + return ip4_fieldCount; +} + +QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib, + int streamIndex) const +{ + switch (index) + { + case ip4_ver: + switch(attrib) + { + case FieldName: + return QString("Version"); + case FieldValue: + return (data.ver_hdrlen() >> 4) & 0x0F; + case FieldTextValue: + return QString("%1").arg((data.ver_hdrlen() >> 4) & 0x0F); + case FieldFrameValue: + return QByteArray(1, (char)(data.ver_hdrlen() & 0xF0)); + case FieldBitSize: + return 4; + default: + break; + } + break; + case ip4_hdrLen: + switch(attrib) + { + case FieldName: + return QString("Header Length"); + case FieldValue: + return data.ver_hdrlen() & 0x0F; + case FieldTextValue: + return QString("%1").arg(data.ver_hdrlen() & 0x0F); + case FieldFrameValue: + return QByteArray(1, (char)(data.ver_hdrlen() << 4)); + case FieldBitSize: + return 4; + default: + break; + } + break; + case ip4_tos: + switch(attrib) + { + case FieldName: + return QString("TOS/DSCP"); + case FieldValue: + return data.tos(); + case FieldFrameValue: + return QByteArray(1, (char) data.tos()); + case FieldTextValue: + return QString("0x%1"). + arg(data.tos(), 2, BASE_HEX, QChar('0'));; + default: + break; + } + break; + case ip4_totLen: + switch(attrib) + { + case FieldName: + return QString("Total Length"); + case FieldValue: + return data.totlen(); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.totlen(), (uchar*) fv.data()); + return fv; + } + case FieldTextValue: + return QString("%1").arg(data.totlen()); + default: + break; + } + break; + case ip4_id: + switch(attrib) + { + case FieldName: + return QString("Identification"); + case FieldValue: + return data.id(); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.id(), (uchar*)fv.data()); + return fv; + } + case FieldTextValue: + return QString("0x%1"). + arg(data.id(), 2, BASE_HEX, QChar('0'));; + default: + break; + } + break; + case ip4_flags: + switch(attrib) + { + case FieldName: + return QString("Flags"); + case FieldValue: + return data.flags(); + case FieldFrameValue: + return QByteArray(1, (char) data.flags()); + case FieldTextValue: + { + QString s; + s.append("Unused:"); + s.append(data.flags() & IP_FLAG_UNUSED ? "1" : "0"); + s.append(" Don't Fragment:"); + s.append(data.flags() & IP_FLAG_DF ? "1" : "0"); + s.append(" More Fragments:"); + s.append(data.flags() & IP_FLAG_MF ? "1" : "0"); + return s; + } + case FieldBitSize: + return 3; + default: + break; + } + break; + case ip4_fragOfs: + switch(attrib) + { + case FieldName: + return QString("Fragment Offset"); + case FieldValue: + return data.frag_ofs(); + case FieldFrameValue: + { + QByteArray fv; + // FIXME need to shift for 13 bits + fv.resize(2); + qToBigEndian((quint16) data.frag_ofs(), (uchar*) fv.data()); + return fv; + } + case FieldTextValue: + return QString("%1").arg(data.frag_ofs()); + case FieldBitSize: + return 13; + default: + break; + } + break; + case ip4_ttl: + switch(attrib) + { + case FieldName: + return QString("Time to Live"); + case FieldValue: + return data.ttl(); + case FieldFrameValue: + return QByteArray(1, (char)data.ttl()); + case FieldTextValue: + return QString("%1").arg(data.ttl()); + default: + break; + } + break; + case ip4_proto: + switch(attrib) + { + case FieldName: + return QString("Protocol"); + case FieldValue: + return data.proto(); + case FieldFrameValue: + return QByteArray(1, (char)data.proto()); + case FieldTextValue: + return QString("0x%1"). + arg(data.proto(), 2, BASE_HEX, QChar('0')); + default: + break; + } + break; + case ip4_cksum: + switch(attrib) + { + case FieldName: + return QString("Header Checksum"); + case FieldValue: + return data.cksum(); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.cksum(), (uchar*) fv.data()); + return fv; + } + case FieldTextValue: + return QString("0x%1"). + arg(data.cksum(), 4, BASE_HEX, QChar('0'));; + default: + break; + } + break; + case ip4_srcAddr: + switch(attrib) + { + case FieldName: + return QString("Source"); + case FieldValue: + return data.src_ip(); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(4); + qToBigEndian((quint32) data.src_ip(), (uchar*) fv.data()); + return fv; + } + case FieldTextValue: + return QHostAddress(data.src_ip()).toString(); + default: + break; + } + break; + case ip4_dstAddr: + switch(attrib) + { + case FieldName: + return QString("Destination"); + case FieldValue: + return data.dst_ip(); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(4); + qToBigEndian((quint32) data.dst_ip(), (uchar*) fv.data()); + return fv; + } + case FieldTextValue: + return QHostAddress(data.dst_ip()).toString(); + default: + break; + } + break; + + // Meta fields + + case ip4_isOverrideVer: + case ip4_isOverrideHdrLen: + case ip4_isOverrideTotLen: + case ip4_isOverrideCksum: + + case ip4_srcAddrMode: + case ip4_srcAddrCount: + case ip4_srcAddrMask: + + case ip4_dstAddrMode: + case ip4_dstAddrCount: + case ip4_dstAddrMask: + switch(attrib) + { + case FieldIsMeta: + return true; + default: + break; + } + break; + + default: + break; + } + + return AbstractProtocol::fieldData(index, attrib, streamIndex); +} + +bool Ip4Protocol::setFieldData(int index, const QVariant &value, + FieldAttrib attrib) +{ + bool isOk = false; + + if (attrib != FieldValue) + return false; + + switch (index) + { + case ip4_proto: + { + uint proto = value.toUInt(&isOk); + if (isOk) + data.set_proto(proto); + } + default: + break; + } + return isOk; +} + + +QWidget* Ip4Protocol::configWidget() +{ + return configForm; +} + +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->cbIpLengthOverride->setChecked(data.is_override_totlen()); + + configForm->leIpId->setText(uintToHexStr(data.id(), QString(), 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->leIpCksum->setText(uintToHexStr(data.cksum(), QString(), 2)); + configForm->cbIpCksumOverride->setChecked(data.is_override_cksum()); + + configForm->leIpSrcAddr->setText(QHostAddress(data.src_ip()).toString()); + configForm->cmbIpSrcAddrMode->setCurrentIndex(data.src_ip_mode()); + configForm->leIpSrcAddrCount->setText(QString().setNum(data.src_ip_count())); + configForm->leIpSrcAddrMask->setText(QHostAddress(data.src_ip_mask()).toString()); + + configForm->leIpDstAddr->setText(QHostAddress(data.dst_ip()).toString()); + configForm->cmbIpDstAddrMode->setCurrentIndex(data.dst_ip_mode()); + configForm->leIpDstAddrCount->setText(QString().setNum(data.dst_ip_count())); + configForm->leIpDstAddrMask->setText(QHostAddress(data.dst_ip_mask()).toString()); +} + +void Ip4Protocol::storeConfigWidget() +{ + uint ff = 0; + bool isOk; + + data.set_is_override_ver(configForm->cbIpVersionOverride->isChecked()); + data.set_ver_hdrlen(((configForm->leIpVersion->text().toULong(&isOk) & 0x0F) << 4) | + (configForm->leIpHdrLen->text().toULong(&isOk) & 0x0F)); + data.set_is_override_hdrlen(configForm->cbIpHdrLenOverride->isChecked()); + + data.set_tos(configForm->leIpTos->text().toULong(&isOk, 16)); + + data.set_totlen(configForm->leIpLength->text().toULong(&isOk)); + data.set_is_override_totlen(configForm->cbIpLengthOverride->isChecked()); + + data.set_id(configForm->leIpId->text().remove(QChar(' ')).toULong(&isOk, 16)); + data.set_frag_ofs(configForm->leIpFragOfs->text().toULong(&isOk)); + + if (configForm->cbIpFlagsDf->isChecked()) ff |= IP_FLAG_DF; + if (configForm->cbIpFlagsMf->isChecked()) ff |= IP_FLAG_MF; + data.set_flags(ff); + + data.set_ttl(configForm->leIpTtl->text().toULong(&isOk)); + data.set_proto(configForm->leIpProto->text().remove(QChar(' ')).toULong(&isOk, 16)); + + data.set_cksum(configForm->leIpCksum->text().remove(QChar(' ')).toULong(&isOk)); + data.set_is_override_cksum(configForm->cbIpCksumOverride->isChecked()); + + data.set_src_ip(QHostAddress(configForm->leIpSrcAddr->text()).toIPv4Address()); + data.set_src_ip_mode((OstProto::Ip4_IpAddrMode)configForm->cmbIpSrcAddrMode->currentIndex()); + data.set_src_ip_count(configForm->leIpSrcAddrCount->text().toULong(&isOk)); + data.set_src_ip_mask(QHostAddress(configForm->leIpSrcAddrMask->text()).toIPv4Address()); + + data.set_dst_ip(QHostAddress(configForm->leIpDstAddr->text()).toIPv4Address()); + data.set_dst_ip_mode((OstProto::Ip4_IpAddrMode)configForm->cmbIpDstAddrMode->currentIndex()); + data.set_dst_ip_count(configForm->leIpDstAddrCount->text().toULong(&isOk)); +} + diff --git a/common/ip4.h b/common/ip4.h new file mode 100644 index 0000000..73d3004 --- /dev/null +++ b/common/ip4.h @@ -0,0 +1,83 @@ +#ifndef _IPV4_H +#define _IPV4_H + +#include "abstractprotocol.h" + +#include "ip4.pb.h" +#include "ui_ip4.h" + +#define IP_FLAG_UNUSED 0x1 +#define IP_FLAG_DF 0x2 +#define IP_FLAG_MF 0x4 + + +class Ip4ConfigForm : public QWidget, public Ui::ip4 +{ + Q_OBJECT +public: + Ip4ConfigForm(QWidget *parent = 0); +private slots: + void on_cmbIpSrcAddrMode_currentIndexChanged(int index); + void on_cmbIpDstAddrMode_currentIndexChanged(int index); +}; + +class Ip4Protocol : public AbstractProtocol +{ +private: + OstProto::Ip4 data; + static Ip4ConfigForm *configForm; + enum ip4field + { + ip4_ver = 0, + ip4_hdrLen, + ip4_tos, + ip4_totLen, + ip4_id, + ip4_flags, + ip4_fragOfs, + ip4_ttl, + ip4_proto, + ip4_cksum, + ip4_srcAddr, + ip4_dstAddr, + + ip4_isOverrideVer, + ip4_isOverrideHdrLen, + ip4_isOverrideTotLen, + ip4_isOverrideCksum, + + ip4_srcAddrMode, + ip4_srcAddrCount, + ip4_srcAddrMask, + + ip4_dstAddrMode, + ip4_dstAddrCount, + ip4_dstAddrMask, + + ip4_fieldCount + }; + +public: + Ip4Protocol(Stream *parent = 0); + virtual ~Ip4Protocol(); + + virtual void protoDataCopyInto(OstProto::Stream &stream); + virtual void protoDataCopyFrom(const OstProto::Stream &stream); + + virtual QString name() const; + virtual QString shortName() const; + + virtual int fieldCount() const; + + virtual QVariant fieldData(int index, FieldAttrib attrib, + int streamIndex = 0) const; + virtual bool setFieldData(int index, const QVariant &value, + FieldAttrib attrib = FieldValue); + + virtual QWidget* configWidget(); + virtual void loadConfigWidget(); + virtual void storeConfigWidget(); +}; + + +#endif diff --git a/common/ip4.proto b/common/ip4.proto new file mode 100644 index 0000000..af61255 --- /dev/null +++ b/common/ip4.proto @@ -0,0 +1,47 @@ +import "protocol.proto"; + +package OstProto; +// IPv4 +message Ip4 { + + enum IpAddrMode { + e_im_fixed = 0; + e_im_inc_host = 1; + e_im_dec_host = 2; + e_im_random_host = 3; + } + + optional bool is_override_ver = 1; + optional bool is_override_hdrlen = 2; + optional bool is_override_totlen = 3; + optional bool is_override_cksum = 4; + + optional uint32 ver_hdrlen = 5 [default = 0x45]; + optional uint32 tos = 6; + optional uint32 totlen = 7; + optional uint32 id = 8 [default = 1234]; + // TODO: rename flags to frag_flags + optional uint32 flags = 9; + optional uint32 frag_ofs = 10; + optional uint32 ttl = 11 [default = 127]; + optional uint32 proto = 12; + optional uint32 cksum = 13; + + // Source IP + optional fixed32 src_ip = 14; + optional IpAddrMode src_ip_mode = 15 [default = e_im_fixed]; + optional uint32 src_ip_count = 16 [default = 16]; + optional fixed32 src_ip_mask = 17 [default = 0xFFFFFFFF]; + + // Destination IP + optional fixed32 dst_ip = 18; + optional IpAddrMode dst_ip_mode = 19 [default = e_im_fixed]; + optional uint32 dst_ip_count = 20 [default = 16]; + optional fixed32 dst_ip_mask = 21 [default = 0xFFFFFFFF]; + + // TODO: Options +} + +extend Stream { + optional Ip4 ip4 = 130; +} diff --git a/common/ip4.ui b/common/ip4.ui new file mode 100644 index 0000000..35a85bf --- /dev/null +++ b/common/ip4.ui @@ -0,0 +1,479 @@ + + ip4 + + + + 0 + 0 + 504 + 296 + + + + Form + + + + + + + + Override Version + + + + + + + false + + + 4 + + + + + + + Override Header Length + + + + + + + false + + + 5 + + + + + + + TOS/DSCP + + + + + + + HH; + + + + + + + + + + false + + + ... + + + + + + + Override Length + + + + + + + false + + + + + + + Identification + + + + + + + HH HH; + + + + + + + + + Qt::Vertical + + + + + + + + + Fragment Offset + + + + + + + + + + Don't Fragment + + + + + + + More Fragments + + + + + + + Time To Live (TTL) + + + + + + + 64 + + + + + + + Protocol + + + + + + + false + + + + + + + + + + Override Checksum + + + + + + + false + + + HH HH; + + + + + + + + + + + + false + + + + + + Qt::Horizontal + + + + 101 + 20 + + + + + + + + Mode + + + + + + + Count + + + + + + + Mask + + + + + + + Source + + + + + + + 009.009.009.009; + + + ... + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + Fixed + + + + + Increment Host + + + + + Decrement Host + + + + + Random Host + + + + + + + + false + + + + + + + + + + false + + + 255.255.255.255 + + + + + + + Destination + + + + + + + 000.000.000.000; + + + ... + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + Fixed + + + + + Increment Host + + + + + Decrement Host + + + + + Random Host + + + + + + + + false + + + + + + + + + + false + + + 255.255.255.255 + + + + + + + + + + + + Options + + + + + + + false + + + TODO + + + + + + + false + + + ... + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + cbIpVersionOverride + toggled(bool) + leIpVersion + setEnabled(bool) + + + 108 + 11 + + + 195 + 11 + + + + + cbIpHdrLenOverride + toggled(bool) + leIpHdrLen + setEnabled(bool) + + + 118 + 43 + + + 166 + 43 + + + + + cbIpLengthOverride + toggled(bool) + leIpLength + setEnabled(bool) + + + 79 + 97 + + + 172 + 97 + + + + + cbIpCksumOverride + toggled(bool) + leIpCksum + setEnabled(bool) + + + 345 + 122 + + + 406 + 122 + + + + + diff --git a/common/llc.cpp b/common/llc.cpp new file mode 100644 index 0000000..394ca2c --- /dev/null +++ b/common/llc.cpp @@ -0,0 +1,139 @@ +#include +#include + +#include "llc.h" + +LlcConfigForm *LlcProtocol::configForm = NULL; + +LlcConfigForm::LlcConfigForm(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); +} + +LlcProtocol::LlcProtocol(Stream *parent) + : AbstractProtocol(parent) +{ + if (configForm == NULL) + configForm = new LlcConfigForm; +} + +LlcProtocol::~LlcProtocol() +{ +} + +void LlcProtocol::protoDataCopyInto(OstProto::Stream &stream) +{ + // FIXME: multiple headers + stream.MutableExtension(OstProto::llc)->CopyFrom(data); +} + +void LlcProtocol::protoDataCopyFrom(const OstProto::Stream &stream) +{ + // FIXME: multiple headers + if (stream.HasExtension(OstProto::llc)) + data.MergeFrom(stream.GetExtension(OstProto::llc)); +} + +QString LlcProtocol::name() const +{ + return QString("802.3 Logical Link Control"); +} + +QString LlcProtocol::shortName() const +{ + return QString("LLC"); +} + +int LlcProtocol::fieldCount() const +{ + return llc_fieldCount; +} + +QVariant LlcProtocol::fieldData(int index, FieldAttrib attrib, + int streamIndex) const +{ + switch (index) + { + case llc_dsap: + switch(attrib) + { + case FieldName: + return QString("DSAP"); + case FieldValue: + return data.dsap(); + case FieldTextValue: + return QString("%1").arg(data.dsap(), BASE_HEX); + case FieldFrameValue: + return QByteArray(1, (char)(data.dsap())); + default: + break; + } + break; + case llc_ssap: + switch(attrib) + { + case FieldName: + return QString("DSAP"); + case FieldValue: + return data.ssap(); + case FieldTextValue: + return QString("%1").arg(data.ssap(), BASE_HEX); + case FieldFrameValue: + return QByteArray(1, (char)(data.ssap())); + default: + break; + } + break; + case llc_ctl: + switch(attrib) + { + case FieldName: + return QString("DSAP"); + case FieldValue: + return data.ctl(); + case FieldTextValue: + return QString("%1").arg(data.ctl(), BASE_HEX); + case FieldFrameValue: + return QByteArray(1, (char)(data.ctl())); + default: + break; + } + break; + + default: + break; + } + + return AbstractProtocol::fieldData(index, attrib, streamIndex); +} + +bool LlcProtocol::setFieldData(int index, const QVariant &value, + FieldAttrib attrib) +{ + // FIXME + return false; +} + + +QWidget* LlcProtocol::configWidget() +{ + return configForm; +} + +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'))); +} + +void LlcProtocol::storeConfigWidget() +{ + bool isOk; + + data.set_dsap(configForm->leDsap->text().toULong(&isOk, BASE_HEX)); + data.set_ssap(configForm->leSsap->text().toULong(&isOk, BASE_HEX)); + data.set_ctl(configForm->leControl->text().toULong(&isOk, BASE_HEX)); +} + diff --git a/common/llc.h b/common/llc.h new file mode 100644 index 0000000..18e1181 --- /dev/null +++ b/common/llc.h @@ -0,0 +1,55 @@ +#ifndef _LLC_H +#define _LLC_H + +#include +#include + +#include "abstractprotocol.h" + +#include "llc.pb.h" +#include "ui_llc.h" + +class LlcConfigForm : public QWidget, public Ui::llc +{ + Q_OBJECT +public: + LlcConfigForm(QWidget *parent = 0); +}; + +class LlcProtocol : public AbstractProtocol +{ +private: + OstProto::Llc data; + static LlcConfigForm *configForm; + enum llcfield + { + llc_dsap = 0, + llc_ssap, + llc_ctl, + + llc_fieldCount + }; + +public: + LlcProtocol(Stream *parent = 0); + virtual ~LlcProtocol(); + + virtual void protoDataCopyInto(OstProto::Stream &stream); + virtual void protoDataCopyFrom(const OstProto::Stream &stream); + + virtual QString name() const; + virtual QString shortName() const; + + virtual int fieldCount() const; + + virtual QVariant fieldData(int index, FieldAttrib attrib, + int streamIndex = 0) const; + virtual bool setFieldData(int index, const QVariant &value, + FieldAttrib attrib = FieldValue); + + virtual QWidget* configWidget(); + virtual void loadConfigWidget(); + virtual void storeConfigWidget(); +}; + +#endif diff --git a/common/llc.proto b/common/llc.proto new file mode 100644 index 0000000..c57cdbe --- /dev/null +++ b/common/llc.proto @@ -0,0 +1,13 @@ +import "protocol.proto"; + +package OstProto; + +message Llc { + optional uint32 dsap = 1; + optional uint32 ssap = 2; + optional uint32 ctl = 3; +} + +extend Stream { + optional Llc llc = 123; +} diff --git a/common/llc.ui b/common/llc.ui new file mode 100644 index 0000000..4518b3d --- /dev/null +++ b/common/llc.ui @@ -0,0 +1,108 @@ + + llc + + + + 0 + 0 + 304 + 72 + + + + + 0 + 0 + + + + Form + + + + + + LLC + + + + + + DSAP + + + leDsap + + + + + + + true + + + HH; + + + + + + + SSAP + + + leSsap + + + + + + + true + + + HH; + + + + + + + Control + + + leControl + + + + + + + true + + + HH; + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + diff --git a/common/mac.cpp b/common/mac.cpp new file mode 100644 index 0000000..59b2607 --- /dev/null +++ b/common/mac.cpp @@ -0,0 +1,207 @@ +#include +#include + +#include "mac.h" + +MacConfigForm *MacProtocol::configForm = NULL; + +MacConfigForm::MacConfigForm(QWidget *parent) + : QWidget(parent) +{ + QRegExp reMac("([0-9,a-f,A-F]{2,2}[:-]){5,5}[0-9,a-f,A-F]{2,2}"); + + setupUi(this); + leDstMac->setValidator(new QRegExpValidator(reMac, this)); + leSrcMac->setValidator(new QRegExpValidator(reMac, this)); + leDstMacCount->setValidator(new QIntValidator(1, MAX_MAC_ITER_COUNT, this)); + leSrcMacCount->setValidator(new QIntValidator(1, MAX_MAC_ITER_COUNT, this)); +} + +void MacConfigForm::on_cmbDstMacMode_currentIndexChanged(int index) +{ + if (index == OstProto::Mac::e_mm_fixed) + { + leDstMacCount->setEnabled(false); + leDstMacStep->setEnabled(false); + } + else + { + leDstMacCount->setEnabled(true); + leDstMacStep->setEnabled(true); + } +} + +void MacConfigForm::on_cmbSrcMacMode_currentIndexChanged(int index) +{ + if (index == OstProto::Mac::e_mm_fixed) + { + leSrcMacCount->setEnabled(false); + leSrcMacStep->setEnabled(false); + } + else + { + leSrcMacCount->setEnabled(true); + leSrcMacStep->setEnabled(true); + } +} + + +MacProtocol::MacProtocol(Stream *parent) + : AbstractProtocol(parent) +{ + if (configForm == NULL) + configForm = new MacConfigForm; +} + +MacProtocol::~MacProtocol() +{ +} + +void MacProtocol::protoDataCopyInto(OstProto::Stream &stream) +{ + // FIXME: multiple headers + stream.MutableExtension(OstProto::mac)->CopyFrom(data); +} + +void MacProtocol::protoDataCopyFrom(const OstProto::Stream &stream) +{ + // FIXME: multiple headers + if (stream.HasExtension(OstProto::mac)) + data.MergeFrom(stream.GetExtension(OstProto::mac)); +} + +QString MacProtocol::name() const +{ + return QString("Media Access Protocol"); +} + +QString MacProtocol::shortName() const +{ + return QString("MAC"); +} + +int MacProtocol::fieldCount() const +{ + return mac_fieldCount; +} + +QVariant MacProtocol::fieldData(int index, FieldAttrib attrib, + int streamIndex) const +{ + switch (index) + { + case mac_dstAddr: + switch(attrib) + { + case FieldName: + return QString("Desination"); + case FieldValue: + return data.dst_mac(); + case FieldTextValue: + return QString("%1").arg(data.dst_mac(), 12, BASE_HEX, + QChar('0')); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(8); + qToBigEndian((quint64) data.dst_mac(), (uchar*) fv.data()); + fv.remove(0, 2); + return fv; + } + default: + break; + } + break; + + case mac_srcAddr: + switch(attrib) + { + case FieldName: + return QString("Source"); + case FieldValue: + return data.src_mac(); + case FieldTextValue: + return QString("%1").arg(data.src_mac(), 12, BASE_HEX, + QChar('0')); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(8); + qToBigEndian((quint64) data.src_mac(), (uchar*) fv.data()); + fv.remove(0, 2); + return fv; + } + default: + break; + } + break; + + // Meta fields + case mac_dstMacMode: + case mac_dstMacCount: + case mac_dstMacStep: + case mac_srcMacMode: + case mac_srcMacCount: + case mac_srcMacStep: + switch(attrib) + { + case FieldIsMeta: + return true; + default: + break; + } + break; + + default: + break; + } + + return AbstractProtocol::fieldData(index, attrib, streamIndex); +} + +bool MacProtocol::setFieldData(int index, const QVariant &value, + FieldAttrib attrib) +{ + // FIXME + return false; +} + + +QWidget* MacProtocol::configWidget() +{ + return configForm; +} + +void MacProtocol::loadConfigWidget() +{ +#define uintToHexStr(num, str, size) QString().setNum(num, 16) + configForm->leDstMac->setText(uintToHexStr(data.dst_mac(), str, 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->cmbSrcMacMode->setCurrentIndex(data.src_mac_mode()); + configForm->leSrcMacCount->setText(QString().setNum(data.src_mac_count())); + configForm->leSrcMacStep->setText(QString().setNum(data.src_mac_step())); +} + +void MacProtocol::storeConfigWidget() +{ + bool isOk; + + data.set_dst_mac(configForm->leDstMac->text().remove(QChar(' ')). + toULongLong(&isOk, 16)); + data.set_dst_mac_mode((OstProto::Mac::MacAddrMode) configForm-> + cmbDstMacMode->currentIndex()); + data.set_dst_mac_count(configForm->leDstMacCount->text().toULong(&isOk)); + data.set_dst_mac_step(configForm->leDstMacStep->text().toULong(&isOk)); + + data.set_src_mac(configForm->leSrcMac->text().remove(QChar(' ')). + toULongLong(&isOk, 16)); + data.set_src_mac_mode((OstProto::Mac::MacAddrMode) configForm-> + cmbSrcMacMode->currentIndex()); + data.set_src_mac_count(configForm->leSrcMacCount->text().toULong(&isOk)); + data.set_src_mac_step(configForm->leSrcMacStep->text().toULong(&isOk)); +} + diff --git a/common/mac.h b/common/mac.h new file mode 100644 index 0000000..2842475 --- /dev/null +++ b/common/mac.h @@ -0,0 +1,63 @@ +#ifndef _MAC_H +#define _MAC_H + +#include "abstractprotocol.h" + +#include "mac.pb.h" +#include "ui_mac.h" + +#define MAX_MAC_ITER_COUNT 256 + +class MacConfigForm : public QWidget, public Ui::mac +{ + Q_OBJECT +public: + MacConfigForm(QWidget *parent = 0); +private slots: + void on_cmbDstMacMode_currentIndexChanged(int index); + void on_cmbSrcMacMode_currentIndexChanged(int index); +}; + +class MacProtocol : public AbstractProtocol +{ +private: + OstProto::Mac data; + static MacConfigForm *configForm; + enum macfield + { + mac_dstAddr = 0, + mac_srcAddr, + + mac_dstMacMode, + mac_dstMacCount, + mac_dstMacStep, + mac_srcMacMode, + mac_srcMacCount, + mac_srcMacStep, + + mac_fieldCount + }; + +public: + MacProtocol(Stream *parent = 0); + virtual ~MacProtocol(); + + virtual void protoDataCopyInto(OstProto::Stream &stream); + virtual void protoDataCopyFrom(const OstProto::Stream &stream); + + virtual QString name() const; + virtual QString shortName() const; + + virtual int fieldCount() const; + + virtual QVariant fieldData(int index, FieldAttrib attrib, + int streamIndex = 0) const; + virtual bool setFieldData(int index, const QVariant &value, + FieldAttrib attrib = FieldValue); + + virtual QWidget* configWidget(); + virtual void loadConfigWidget(); + virtual void storeConfigWidget(); +}; + +#endif diff --git a/common/mac.proto b/common/mac.proto new file mode 100644 index 0000000..c4c5253 --- /dev/null +++ b/common/mac.proto @@ -0,0 +1,29 @@ +import "protocol.proto"; + +package OstProto; + +// Ethernet +message Mac { + + enum MacAddrMode { + e_mm_fixed = 0; + e_mm_inc = 1; + e_mm_dec = 2; + } + + // Dst Mac + optional uint64 dst_mac = 1; + optional MacAddrMode dst_mac_mode = 2 [default = e_mm_fixed]; + optional uint32 dst_mac_count = 3 [default = 16]; + optional uint32 dst_mac_step = 4 [default = 1]; + + // Src Mac + optional uint32 src_mac = 5; + optional MacAddrMode src_mac_mode = 6 [default = e_mm_fixed]; + optional uint32 src_mac_count = 7 [default = 16]; + optional uint32 src_mac_step = 8 [default = 1]; +} + +extend Stream { + optional Mac mac = 51; +} diff --git a/common/mac.ui b/common/mac.ui new file mode 100644 index 0000000..9095f29 --- /dev/null +++ b/common/mac.ui @@ -0,0 +1,190 @@ + + mac + + + + 0 + 0 + 423 + 144 + + + + Form + + + + + + MAC + + + + + + Mode + + + + + + + Step + + + + + + + Destination + + + + + + + + 120 + 0 + + + + HH HH HH HH HH HH; + + + + + + + + + + + Fixed + + + + + Increment + + + + + Decrement + + + + + + + + false + + + 1 + + + 1 + + + + + + + false + + + 1 + + + 1 + + + + + + + Source + + + + + + + HH HH HH HH HH HH; + + + + + + + + + + + Fixed + + + + + Increment + + + + + Decrement + + + + + + + + false + + + 1 + + + + + + + false + + + 1 + + + 1 + + + + + + + Count + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + diff --git a/common/ostproto.pro b/common/ostproto.pro new file mode 100644 index 0000000..3bd8e9c --- /dev/null +++ b/common/ostproto.pro @@ -0,0 +1,63 @@ +TEMPLATE = lib +CONFIG += qt staticlib +QT += network +LIBS += \ + -lprotobuf +FORMS += \ + mac.ui \ + payload.ui \ + eth2.ui \ + dot3.ui \ + llc.ui \ + snap.ui \ + ip4.ui \ + tcp.ui \ + udp.ui +PROTOS += \ + protocol.proto \ + mac.proto \ + payload.proto \ + eth2.proto \ + dot3.proto \ + llc.proto \ + snap.proto \ + ip4.proto \ + tcp.proto \ + udp.proto +HEADERS += \ + abstractprotocol.h \ + mac.h \ + payload.h \ + eth2.h \ + dot3.h \ + llc.h \ + snap.h \ + ip4.h \ + tcp.h \ + udp.h +SOURCES += \ + abstractprotocol.cpp \ + mac.cpp \ + payload.cpp \ + eth2.cpp \ + dot3.cpp \ + llc.cpp \ + snap.cpp \ + ip4.cpp \ + tcp.cpp \ + udp.cpp + +protobuf_decl.name = protobuf header +protobuf_decl.input = PROTOS +protobuf_decl.output = ${QMAKE_FILE_BASE}.pb.h +protobuf_decl.commands = protoc --cpp_out="." ${QMAKE_FILE_NAME} +protobuf_decl.variable_out = GENERATED_FILES +QMAKE_EXTRA_COMPILERS += protobuf_decl + +protobuf_impl.name = protobuf implementation +protobuf_impl.input = PROTOS +protobuf_impl.output = ${QMAKE_FILE_BASE}.pb.cc +protobuf_impl.depends = ${QMAKE_FILE_BASE}.pb.h +protobuf_impl.commands = $$escape_expand(\n) +protobuf_impl.variable_out = GENERATED_SOURCES +QMAKE_EXTRA_COMPILERS += protobuf_impl diff --git a/common/payload.cpp b/common/payload.cpp new file mode 100644 index 0000000..8feecf9 --- /dev/null +++ b/common/payload.cpp @@ -0,0 +1,176 @@ +#include +#include + +#include "../client/stream.h" +#include "payload.h" + +PayloadConfigForm *PayloadProtocol::configForm = NULL; + +PayloadConfigForm::PayloadConfigForm(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); +} + +void PayloadConfigForm::on_cmbPatternMode_currentIndexChanged(int index) +{ + switch(index) + { + case OstProto::Payload::e_dp_fixed_word: + lePattern->setEnabled(true); + break; + case OstProto::Payload::e_dp_inc_byte: + case OstProto::Payload::e_dp_dec_byte: + case OstProto::Payload::e_dp_random: + lePattern->setDisabled(true); + break; + default: + qWarning("Unhandled/Unknown PatternMode = %d",index); + } +} + +PayloadProtocol::PayloadProtocol(Stream *parent) + : AbstractProtocol(parent) +{ + if (configForm == NULL) + configForm = new PayloadConfigForm; +} + +PayloadProtocol::~PayloadProtocol() +{ +} + +void PayloadProtocol::protoDataCopyInto(OstProto::Stream &stream) +{ + // FIXME: multiple headers + stream.MutableExtension(OstProto::payload)->CopyFrom(data); +} + +void PayloadProtocol::protoDataCopyFrom(const OstProto::Stream &stream) +{ + // FIXME: multiple headers + if (stream.HasExtension(OstProto::payload)) + data.MergeFrom(stream.GetExtension(OstProto::payload)); +} + +QString PayloadProtocol::name() const +{ + return QString("Payload Data"); +} + +QString PayloadProtocol::shortName() const +{ + return QString("DATA"); +} + +int PayloadProtocol::fieldCount() const +{ + return payload_fieldCount; +} + +QVariant PayloadProtocol::fieldData(int index, FieldAttrib attrib, + int streamIndex) const +{ + switch (index) + { + case payload_dataPattern: + switch(attrib) + { + case FieldName: + return QString("Data"); + case FieldValue: + return data.pattern(); + case FieldTextValue: + return QString(fieldData(index, FieldFrameValue, + streamIndex).toByteArray().toHex()); + case FieldFrameValue: + { + QByteArray fv; + int dataLen; + + // FIXME: cannot use stream since it is only on client not + // on server + //dataLen = stream->frameLen() - stream->protocolHeaderSize(); + dataLen = 64; + fv.resize(dataLen+4); + switch(data.pattern_mode()) + { + case OstProto::Payload::e_dp_fixed_word: + for (int i = 0; i < (dataLen/4)+1; i++) + qToBigEndian((quint32) data.pattern(), + (uchar*)(fv.data()+(i*4)) ); + break; + case OstProto::Payload::e_dp_inc_byte: + for (int i = 0; i < dataLen; i++) + fv[i] = i % (0xFF + 1); + break; + case OstProto::Payload::e_dp_dec_byte: + for (int i = 0; i < dataLen; i++) + fv[i] = 0xFF - (i % (0xFF + 1)); + break; + case OstProto::Payload::e_dp_random: + for (int i = 0; i < dataLen; i++) + fv[i] = qrand() % (0xFF + 1); + break; + default: + qWarning("Unhandled data pattern %d", + data.pattern_mode()); + } + fv.resize(dataLen); + return fv; + } + default: + break; + } + break; + + // Meta fields + + case payload_dataPatternMode: + switch(attrib) + { + case FieldIsMeta: + return true; + default: + break; + } + break; + + default: + break; + } + + return AbstractProtocol::fieldData(index, attrib, streamIndex); +} + +bool PayloadProtocol::setFieldData(int index, const QVariant &value, + FieldAttrib attrib) +{ + // FIXME + return false; +} + + +QWidget* PayloadProtocol::configWidget() +{ + return configForm; + //return new PayloadConfigForm; +} + +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)); +} + +void PayloadProtocol::storeConfigWidget() +{ + bool isOk; + + data.set_pattern_mode((OstProto::Payload::DataPatternMode) + configForm->cmbPatternMode->currentIndex()); + data.set_pattern(configForm->lePattern->text().remove(QChar(' ')).toULong(&isOk, 16)); +} + diff --git a/common/payload.h b/common/payload.h new file mode 100644 index 0000000..aa66f5d --- /dev/null +++ b/common/payload.h @@ -0,0 +1,55 @@ +#ifndef _PAYLOAD_H +#define _PAYLOAD_H + +#include "abstractprotocol.h" + +#include "payload.pb.h" +#include "ui_payload.h" + +class PayloadConfigForm : public QWidget, public Ui::payload +{ + Q_OBJECT +public: + PayloadConfigForm(QWidget *parent = 0); +private slots: + void on_cmbPatternMode_currentIndexChanged(int index); +}; + +class PayloadProtocol : public AbstractProtocol +{ +private: + OstProto::Payload data; + static PayloadConfigForm *configForm; + enum payloadfield + { + payload_dataPattern, + + // Meta fields + payload_dataPatternMode, + + payload_fieldCount + }; + +public: + PayloadProtocol(Stream *parent = 0); + virtual ~PayloadProtocol(); + + virtual void protoDataCopyInto(OstProto::Stream &stream); + virtual void protoDataCopyFrom(const OstProto::Stream &stream); + + virtual QString name() const; + virtual QString shortName() const; + + virtual int fieldCount() const; + + virtual QVariant fieldData(int index, FieldAttrib attrib, + int streamIndex = 0) const; + virtual bool setFieldData(int index, const QVariant &value, + FieldAttrib attrib = FieldValue); + + virtual QWidget* configWidget(); + virtual void loadConfigWidget(); + virtual void storeConfigWidget(); +}; + +#endif diff --git a/common/payload.proto b/common/payload.proto new file mode 100644 index 0000000..e97f33c --- /dev/null +++ b/common/payload.proto @@ -0,0 +1,22 @@ +import "protocol.proto"; + +package OstProto; + +message Payload { + enum DataPatternMode { + e_dp_fixed_word = 0; + e_dp_inc_byte = 1; + e_dp_dec_byte = 2; + e_dp_random = 3; + } + + // Data Pattern + optional DataPatternMode pattern_mode = 1; + optional uint32 pattern = 2; + + //optional uint32 data_start_ofs = 13; +} + +extend Stream { + optional Payload payload = 52; +} diff --git a/common/payload.ui b/common/payload.ui new file mode 100644 index 0000000..9de7ce1 --- /dev/null +++ b/common/payload.ui @@ -0,0 +1,69 @@ + + payload + + + + 0 + 0 + 142 + 98 + + + + Form + + + + + + Data Pattern + + + + + + + Fixed Word + + + + + Increment Byte + + + + + Decrement Byte + + + + + Random + + + + + + + + HH HH HH HH; + + + + + + 11 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + diff --git a/common/protocol.h b/common/protocol.h deleted file mode 100644 index 01f35f6..0000000 --- a/common/protocol.h +++ /dev/null @@ -1,169 +0,0 @@ -#ifndef _PROTOCOL_H -#define _PROTOCOL_H - -#define UINT8 unsigned char -#define UINT16 unsigned short -#define UINT32 unsigned int - -#define BYTESWAP4(x) \ - (((x & 0xFF000000) >> 24) | \ - ((x & 0x00FF0000) >> 8) | \ - ((x & 0x0000FF00) << 8) | \ - ((x & 0x000000FF) << 24)) - -#define BYTESWAP2(x) \ - (((x & 0xFF00) >> 8) | \ - ((x & 0x00FF) << 8)) - -// TODO: portability -#define HTONL(x) BYTESWAP4(x) -#define NTOHL(x) BYTESWAP4(x) -#define HTONS(x) BYTESWAP2(x) -#define NTOHS(x) BYTESWAP2(x) - - -typedef struct { - UINT8 ver; - UINT8 resv1; - UINT16 resv2; - UINT16 msgType; - UINT16 msgLen; -} tCommHdr; - -typedef enum { - e_MT_GetCapability=1, // C-->S - e_MT_CapabilityInfo, // C<--S - - e_MT_ChangePortConfig, // C-->S - e_MT_GetPortConfig, // C-->S - e_MT_PortInfo, // C<--S - - e_MT_StartTx, // C-->S - e_MT_StopTx, // C-->S - e_MT_StartCapture, // C-->S - e_MT_StopCapture, // C-->S - e_MT_GetCaptureBuffer, // C-->S - e_MT_CaptureBufferInfo, // C-->S - - e_MT_GetStats, // C-->S - e_MT_StatsInfo, // C<--S - e_MT_ClearStats, // C-->S - -} eMsgType; - -typedef enum { - e_TT_PortCapability=0x0000, - - e_TT_StreamOper = 0x0100, - e_TT_StreamName, - e_TT_StreamStatus, - e_TT_StreamFrameLength, - e_TT_StreamDataPattern, - e_TT_StreamHeaderData, -} eTlvType; - -typedef struct { - UINT16 tlvType; - UINT16 tlvLen; -} tTlv; - -typedef struct { - UINT16 tlvType; - UINT16 tlvLen; - UINT32 portId; - UINT32 portSpeed; -#define TLV_MAX_PORT_NAME 64 -#define TLV_MAX_PORT_DESC 64 - char portName[TLV_MAX_PORT_NAME]; - char portDesc[TLV_MAX_PORT_DESC]; -} tTlvPortCapability; - -typedef struct { - UINT16 tlvType; - UINT16 tlvLen; - UINT32 portId; - UINT32 streamId; -} tTlvStream; - -typedef struct { - UINT16 tlvType; - UINT16 tlvLen; - UINT32 portId; - UINT32 streamId; - UINT16 rsvd; - UINT16 streamOper; -#define TLV_STREAM_OPER_INSERT_HEAD 0x0001 -#define TLV_STREAM_OPER_INSERT_TAIL 0x0002 -#define TLV_STREAM_OPER_INSERT_BEFORE 0x0003 -#define TLV_STREAM_OPER_DELETE 0x0010 - UINT32 StreamId; -} tTlvStreamOper; - -typedef struct { - UINT16 tlvType; - UINT16 tlvLen; - UINT32 portId; - UINT32 streamId; - char streamName[0]; -} tTlvStreamName; - -typedef struct { - UINT16 tlvType; - UINT16 tlvLen; - UINT32 portId; - UINT32 streamId; - UINT32 streamStatus; -#define TLV_STREAM_STATUS_DISABLED 0 -#define TLV_STREAM_STATUS_ENABLED 1 -} tTlvStreamStatus; - -typedef struct { - UINT16 tlvType; - UINT16 tlvLen; - UINT32 portId; - UINT32 streamId; - UINT16 frameLenMode; -#define TLV_STREAM_FRAME_LEN_MODE_FIXED 0x0000 -#define TLV_STREAM_FRAME_LEN_MODE_RANDOM 0x0001 -#define TLV_STREAM_FRAME_LEN_MODE_INCREMENT 0x0002 -#define TLV_STREAM_FRAME_LEN_MODE_DECREMENT 0x0003 - UINT16 frameLen; - UINT16 frameLenMin; - UINT16 frameLenMax; -} tTlvStreamFrameLength; - -typedef struct { - UINT16 tlvType; - UINT16 tlvLen; - UINT32 portId; - UINT32 streamId; - UINT16 dataPatternMode; -#define TLV_STREAM_DATA_PATTERN_MODE_FIXED 0x0000 -#define TLV_STREAM_DATA_PATTERN_MODE_RANDOM 0x0001 -#define TLV_STREAM_DATA_PATTERN_MODE_INCREMENT 0x0002 -#define TLV_STREAM_DATA_PATTERN_MODE_DECREMENT 0x0003 - UINT16 rsvd; - UINT32 dataPattern; -} tTlvStreamDataPattern; - -typedef struct { - UINT16 tlvType; - UINT16 tlvLen; - UINT32 portId; - UINT32 streamId; - UINT16 rsvd; - UINT16 headerLen; - UINT8 header[0]; -} tTlvStreamHeaderData; - -typedef union { - tTlvStream tlv; - tTlvStreamOper oper; - tTlvStreamName name; - tTlvStreamStatus status; - tTlvStreamFrameLength frameLen; - tTlvStreamDataPattern dataPattern; - tTlvStreamHeaderData headerData; -} uTlvStream; - -#endif diff --git a/common/protocol.proto b/common/protocol.proto index 7038517..a809795 100644 --- a/common/protocol.proto +++ b/common/protocol.proto @@ -4,177 +4,11 @@ package OstProto; -// Ethernet -message Mac { - - enum MacAddrMode { - e_mm_fixed = 0; - e_mm_inc = 1; - e_mm_dec = 2; - } - - // Dst Mac - optional uint64 dst_mac = 1; - optional MacAddrMode dst_mac_mode = 2 [default = e_mm_fixed]; - optional uint32 dst_mac_count = 3 [default = 16]; - optional uint32 dst_mac_step = 4 [default = 1]; - - // Src Mac - optional uint32 src_mac = 5; - optional MacAddrMode src_mac_mode = 6 [default = e_mm_fixed]; - optional uint32 src_mac_count = 7 [default = 16]; - optional uint32 src_mac_step = 8 [default = 1]; -} - -message Llc { - optional uint32 dsap = 1; - optional uint32 ssap = 2; - optional uint32 ctl = 3; -} - -message Snap { - optional uint32 oui = 1; - //optional uint32 type = 2; -} - -message Eth2 { - optional uint32 type = 1; -} - -message Vlan { - // VLAN presence/absence - optional bool is_cvlan_tagged = 9; - optional bool is_ctpid_override = 10; - optional bool is_svlan_tagged = 11; - optional bool is_stpid_override = 12; - - // VLAN values - optional uint32 ctpid = 13; - optional uint32 cvlan_tag = 14; // includes prio, cfi and cvlanid - optional uint32 stpid = 15; - optional uint32 svlan_tag = 16; // includes pcp, de and svlanid -} - -// IP -message Ip { - - enum IpAddrMode { - e_im_fixed = 0; - e_im_inc_host = 1; - e_im_dec_host = 2; - e_im_random_host = 3; - } - - optional bool is_override_ver = 1; - optional bool is_override_hdrlen = 2; - optional bool is_override_totlen = 3; - optional bool is_override_cksum = 4; - - optional uint32 ver_hdrlen = 5 [default = 0x45]; - optional uint32 tos = 6; - optional uint32 tot_len = 7; - optional uint32 id = 8 [default = 1234]; - // TODO: rename flags to frag_flags - optional uint32 flags = 9; - optional uint32 frag_ofs = 10; - optional uint32 ttl = 11 [default = 127]; - optional uint32 proto = 12; - optional uint32 cksum = 13; - - // Source IP - optional fixed32 src_ip = 14; - optional IpAddrMode src_ip_mode = 15 [default = e_im_fixed]; - optional uint32 src_ip_count = 16 [default = 16]; - optional fixed32 src_ip_mask = 17 [default = 0xFFFFFFFF]; - - // Destination IP - optional fixed32 dst_ip = 18; - optional IpAddrMode dst_ip_mode = 19 [default = e_im_fixed]; - optional uint32 dst_ip_count = 20 [default = 16]; - optional fixed32 dst_ip_mask = 21 [default = 0xFFFFFFFF]; - - // TODO: Options -} - -message Arp { -// TODO: ARP -} - -message Tcp { - - optional bool is_override_hdrlen = 1; - optional bool is_override_cksum = 2; - - optional uint32 src_port = 3 [default = 8902]; - optional uint32 dst_port = 4 [default = 80]; - - optional uint32 seq_num = 5 [default = 129018]; - optional uint32 ack_num = 6; - - optional uint32 hdrlen_rsvd = 7 [default = 0x50]; - optional uint32 flags = 8; - - optional uint32 window = 9 [default = 1024]; - optional uint32 cksum = 10; - optional uint32 urg_ptr = 11; -} - -// UDP -message Udp { - optional bool is_override_totlen = 1; - optional bool is_override_cksum = 2; - - optional uint32 src_port = 3 [default = 8902]; - optional uint32 dst_port = 4 [default = 80]; - optional uint32 totlen = 5; - optional uint32 cksum = 6; -} - -// TODO: ICMP -message Icmp { -} - -// TODO: IGMP -message Igmp { -} - message StreamId { required uint32 id = 1; } message StreamCore { - - enum FrameType { - e_ft_none = 0; - e_ft_eth_2 = 1; - e_ft_802_3_raw = 2; - e_ft_802_3_llc = 3; - e_ft_snap = 4; - } - - enum L3Proto { - e_l3_none = 0; - e_l3_ip = 1; - e_l3_arp = 2; - //e_l3_other = 3; - } - - enum L4Proto { - e_l4_none = 0; - e_l4_tcp = 1; - e_l4_udp = 2; - e_l4_icmp = 3; - e_l4_igmp = 4; - //e_l4_other = 5; - } - - enum DataPatternMode { - e_dp_fixed_word = 0; - e_dp_inc_byte = 1; - e_dp_dec_byte = 2; - e_dp_random = 3; - } - enum FrameLengthMode { e_fl_fixed = 0; e_fl_inc = 1; @@ -187,11 +21,6 @@ message StreamCore { optional bool is_enabled = 2; optional uint32 ordinal = 3; - // Data Pattern - optional DataPatternMode pattern_mode = 11; - optional uint32 pattern = 12; - optional uint32 data_start_ofs = 13; - // Frame Length (includes CRC) optional FrameLengthMode len_mode = 14 [default = e_fl_fixed]; optional uint32 frame_len = 15 [default = 64]; @@ -199,9 +28,7 @@ message StreamCore { optional uint32 frame_len_max = 17 [default = 1518]; // Currently Selected Protocols - optional FrameType ft = 21 [default = e_ft_none]; - optional L3Proto l3_proto = 22; - optional L4Proto l4_proto = 23; + repeated uint32 frame_proto = 20; } message StreamControl { @@ -240,24 +67,8 @@ message Stream { optional StreamCore core = 2; optional StreamControl control = 3; - // Protocol data - L2 - optional Mac mac = 51; - - optional Llc llc = 52; - optional Snap snap = 53; - optional Eth2 eth2 = 54; - optional Vlan vlan = 55; - - // Protocol data - L3 - optional Ip ip = 61; - optional Arp arp = 62; - - // Protocol data - L4 - optional Tcp tcp = 71; - optional Udp udp = 72; - optional Icmp icmp = 73; - optional Igmp igmp = 74; - + extensions 51 to 100; // Reserved for Ostinato Use + extensions 101 to 200; // Available for use by protocols } message Void { @@ -281,7 +92,6 @@ message StreamIdList { repeated StreamId stream_id = 2; } - message Port { required PortId port_id = 1; optional string name = 2; diff --git a/common/snap.cpp b/common/snap.cpp new file mode 100644 index 0000000..33f841e --- /dev/null +++ b/common/snap.cpp @@ -0,0 +1,112 @@ +#include +#include + +#include "snap.h" + +SnapConfigForm *SnapProtocol::configForm = NULL; + +SnapConfigForm::SnapConfigForm(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); +} + +SnapProtocol::SnapProtocol(Stream *parent) + : AbstractProtocol(parent) +{ + if (configForm == NULL) + configForm = new SnapConfigForm; +} + +SnapProtocol::~SnapProtocol() +{ +} + +void SnapProtocol::protoDataCopyInto(OstProto::Stream &stream) +{ + // FIXME: multiple headers + stream.MutableExtension(OstProto::snap)->CopyFrom(data); +} + +void SnapProtocol::protoDataCopyFrom(const OstProto::Stream &stream) +{ + // FIXME: multiple headers + if (stream.HasExtension(OstProto::snap)) + data.MergeFrom(stream.GetExtension(OstProto::snap)); +} + +QString SnapProtocol::name() const +{ + return QString("SubNetwork Access Protocol"); +} + +QString SnapProtocol::shortName() const +{ + return QString("SNAP"); +} + +int SnapProtocol::fieldCount() const +{ + return snap_fieldCount; +} + +QVariant SnapProtocol::fieldData(int index, FieldAttrib attrib, + int streamIndex) const +{ + switch (index) + { + case snap_oui: + switch(attrib) + { + case FieldName: + return QString("OUI"); + case FieldValue: + return data.oui(); + case FieldTextValue: + return QString("%1").arg(data.oui(), 6, BASE_HEX, QChar('0')); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(4); + qToBigEndian((quint32) data.oui(), (uchar*) fv.data()); + fv.remove(0, 1); + return fv; + } + default: + break; + } + break; + + default: + break; + } + + return AbstractProtocol::fieldData(index, attrib, streamIndex); +} + +bool SnapProtocol::setFieldData(int index, const QVariant &value, + FieldAttrib attrib) +{ + // FIXME + return false; +} + + +QWidget* SnapProtocol::configWidget() +{ + return configForm; +} + +void SnapProtocol::loadConfigWidget() +{ +#define uintToHexStr(num, str, size) QString().setNum(num, 16) + configForm->leOui->setText(uintToHexStr(data.oui(), str, 3)); +} + +void SnapProtocol::storeConfigWidget() +{ + bool isOk; + + data.set_oui(configForm->leOui->text().remove(QChar(' ')).toULong(&isOk, 16)); +} + diff --git a/common/snap.h b/common/snap.h new file mode 100644 index 0000000..9913b0f --- /dev/null +++ b/common/snap.h @@ -0,0 +1,50 @@ +#ifndef _SNAP_H +#define _SNAP_H + +#include "abstractprotocol.h" + +#include "snap.pb.h" +#include "ui_snap.h" + +class SnapConfigForm : public QWidget, public Ui::snap +{ + Q_OBJECT +public: + SnapConfigForm(QWidget *parent = 0); +}; + +class SnapProtocol : public AbstractProtocol +{ +private: + OstProto::Snap data; + static SnapConfigForm *configForm; + enum snapfield + { + snap_oui = 0, + + snap_fieldCount + }; + +public: + SnapProtocol(Stream *parent = 0); + virtual ~SnapProtocol(); + + virtual void protoDataCopyInto(OstProto::Stream &stream); + virtual void protoDataCopyFrom(const OstProto::Stream &stream); + + virtual QString name() const; + virtual QString shortName() const; + + virtual int fieldCount() const; + + virtual QVariant fieldData(int index, FieldAttrib attrib, + int streamIndex = 0) const; + virtual bool setFieldData(int index, const QVariant &value, + FieldAttrib attrib = FieldValue); + + virtual QWidget* configWidget(); + virtual void loadConfigWidget(); + virtual void storeConfigWidget(); +}; + +#endif diff --git a/common/snap.proto b/common/snap.proto new file mode 100644 index 0000000..b6c310c --- /dev/null +++ b/common/snap.proto @@ -0,0 +1,12 @@ +import "protocol.proto"; + +package OstProto; + +message Snap { + optional uint32 oui = 1; + //optional uint32 type = 2; +} + +extend Stream { + optional Snap snap = 124; +} diff --git a/common/snap.ui b/common/snap.ui new file mode 100644 index 0000000..1f2b789 --- /dev/null +++ b/common/snap.ui @@ -0,0 +1,89 @@ + + snap + + + + 0 + 0 + 293 + 98 + + + + Form + + + + + + SNAP + + + + + + OUI + + + + + + + true + + + HH HH HH; + + + + + + + Type + + + + + + + true + + + HH HH; + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/common/tcp.cpp b/common/tcp.cpp new file mode 100644 index 0000000..4c81c1c --- /dev/null +++ b/common/tcp.cpp @@ -0,0 +1,360 @@ +#include +#include + +#include "tcp.h" + +TcpConfigForm *TcpProtocol::configForm = NULL; + +TcpConfigForm::TcpConfigForm(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); +} + +TcpProtocol::TcpProtocol(Stream *parent) + : AbstractProtocol(parent) +{ + if (configForm == NULL) + configForm = new TcpConfigForm; +} + +TcpProtocol::~TcpProtocol() +{ +} + +void TcpProtocol::protoDataCopyInto(OstProto::Stream &stream) +{ + // FIXME: multiple headers + stream.MutableExtension(OstProto::tcp)->CopyFrom(data); +} + +void TcpProtocol::protoDataCopyFrom(const OstProto::Stream &stream) +{ + // FIXME: multiple headers + if (stream.HasExtension(OstProto::tcp)) + data.MergeFrom(stream.GetExtension(OstProto::tcp)); +} + +QString TcpProtocol::name() const +{ + return QString("Transmission Control Protocol"); +} + +QString TcpProtocol::shortName() const +{ + return QString("TCP"); +} + +int TcpProtocol::fieldCount() const +{ + return tcp_fieldCount; +} + +QVariant TcpProtocol::fieldData(int index, FieldAttrib attrib, + int streamIndex) const +{ + switch (index) + { + case tcp_src_port: + switch(attrib) + { + case FieldName: + return QString("Source Port"); + case FieldValue: + return data.src_port(); + case FieldTextValue: + return QString("%1").arg(data.src_port()); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.src_port(), (uchar*) fv.data()); + return fv; + } + default: + break; + } + break; + + case tcp_dst_port: + switch(attrib) + { + case FieldName: + return QString("Destination Port"); + case FieldValue: + return data.dst_port(); + case FieldTextValue: + return QString("%1").arg(data.dst_port()); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.dst_port(), (uchar*) fv.data()); + return fv; + } + default: + break; + } + break; + + case tcp_seq_num: + switch(attrib) + { + case FieldName: + return QString("Sequence Number"); + case FieldValue: + return data.seq_num(); + case FieldTextValue: + return QString("%1").arg(data.seq_num()); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(4); + qToBigEndian((quint32) data.seq_num(), (uchar*) fv.data()); + return fv; + } + default: + break; + } + break; + + case tcp_ack_num: + switch(attrib) + { + case FieldName: + return QString("Sequence Number"); + case FieldValue: + return data.ack_num(); + case FieldTextValue: + return QString("%1").arg(data.ack_num()); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(4); + qToBigEndian((quint32) data.ack_num(), (uchar*) fv.data()); + return fv; + } + default: + break; + } + break; + + case tcp_hdrlen: + switch(attrib) + { + case FieldName: + return QString("Header Length"); + case FieldValue: + return ((data.hdrlen_rsvd() >> 4) & 0x0F); + case FieldTextValue: + return QString("%1").arg((data.hdrlen_rsvd() >> 4) & 0x0F); + case FieldFrameValue: + return QByteArray(1, (char)((data.hdrlen_rsvd() >> 4) & 0x0F)); + case FieldBitSize: + return 4; + default: + break; + } + break; + + case tcp_rsvd: + switch(attrib) + { + case FieldName: + return QString("Reserved"); + case FieldValue: + return (data.hdrlen_rsvd() & 0x0F); + case FieldTextValue: + return QString("%1").arg(data.hdrlen_rsvd() & 0x0F); + case FieldFrameValue: + return QByteArray(1, (char)(data.hdrlen_rsvd() & 0x0F)); + case FieldBitSize: + return 4; + default: + break; + } + break; + + case tcp_flags: + switch(attrib) + { + case FieldName: + return QString("Flags"); + case FieldValue: + return (data.flags()); + case FieldTextValue: + { + QString s; + s.append("URG: "); + s.append(data.flags() & TCP_FLAG_URG ? "1" : "0"); + s.append(" ACK: "); + s.append(data.flags() & TCP_FLAG_ACK ? "1" : "0"); + s.append(" PSH: "); + s.append(data.flags() & TCP_FLAG_PSH ? "1" : "0"); + s.append(" RST: "); + s.append(data.flags() & TCP_FLAG_RST ? "1" : "0"); + s.append(" SYN: "); + s.append(data.flags() & TCP_FLAG_SYN ? "1" : "0"); + s.append(" FIN: "); + s.append(data.flags() & TCP_FLAG_FIN ? "1" : "0"); + return s; + } + case FieldFrameValue: + return QByteArray(1, (char)(data.flags() & 0x3F)); + default: + break; + } + break; + + case tcp_window: + switch(attrib) + { + case FieldName: + return QString("Window Size"); + case FieldValue: + return data.window(); + case FieldTextValue: + return QString("%1").arg(data.window()); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.window(), (uchar*) fv.data()); + return fv; + } + default: + break; + } + break; + + case tcp_cksum: + switch(attrib) + { + case FieldName: + return QString("Checksum"); + case FieldValue: + return data.cksum(); + case FieldTextValue: + return QString("%1").arg(data.cksum()); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.cksum(), (uchar*) fv.data()); + return fv; + } + default: + break; + } + break; + + case tcp_urg_ptr: + switch(attrib) + { + case FieldName: + return QString("Urgent Pointer"); + case FieldValue: + return data.urg_ptr(); + case FieldTextValue: + return QString("%1").arg(data.urg_ptr()); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.urg_ptr(), (uchar*) fv.data()); + return fv; + } + default: + break; + } + break; + + // Meta fields + case tcp_is_override_hdrlen: + case tcp_is_override_cksum: + switch(attrib) + { + case FieldIsMeta: + return true; + default: + break; + } + break; + + default: + break; + } + + return AbstractProtocol::fieldData(index, attrib, streamIndex); +} + +bool TcpProtocol::setFieldData(int index, const QVariant &value, + FieldAttrib attrib) +{ + // FIXME + return false; +} + + +QWidget* TcpProtocol::configWidget() +{ + return configForm; +} + +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())); + + configForm->leTcpSeqNum->setText(QString().setNum(data.seq_num())); + configForm->leTcpAckNum->setText(QString().setNum(data.ack_num())); + + configForm->leTcpHdrLen->setText(QString().setNum((data.hdrlen_rsvd() >> 4) & 0x0F)); + configForm->cbTcpHdrLenOverride->setChecked(data.is_override_hdrlen()); + + configForm->leTcpWindow->setText(QString().setNum(data.window())); + + configForm->leTcpCksum->setText(QString().setNum(data.cksum())); + configForm->cbTcpCksumOverride->setChecked(data.is_override_cksum()); + + configForm->leTcpUrgentPointer->setText(QString().setNum(data.urg_ptr())); + + configForm->cbTcpFlagsUrg->setChecked((data.flags() & TCP_FLAG_URG) > 0); + configForm->cbTcpFlagsAck->setChecked((data.flags() & TCP_FLAG_ACK) > 0); + configForm->cbTcpFlagsPsh->setChecked((data.flags() & TCP_FLAG_PSH) > 0); + configForm->cbTcpFlagsRst->setChecked((data.flags() & TCP_FLAG_RST) > 0); + configForm->cbTcpFlagsSyn->setChecked((data.flags() & TCP_FLAG_SYN) > 0); + configForm->cbTcpFlagsFin->setChecked((data.flags() & TCP_FLAG_FIN) > 0); +} + +void TcpProtocol::storeConfigWidget() +{ + bool isOk; + int ff = 0; + + data.set_src_port(configForm->leTcpSrcPort->text().toULong(&isOk)); + data.set_dst_port(configForm->leTcpDstPort->text().toULong(&isOk)); + + data.set_seq_num(configForm->leTcpSeqNum->text().toULong(&isOk)); + data.set_ack_num(configForm->leTcpAckNum->text().toULong(&isOk)); + + data.set_hdrlen_rsvd((configForm->leTcpHdrLen->text().toULong(&isOk) << 4) & 0xF0); + data.set_is_override_hdrlen(configForm->cbTcpHdrLenOverride->isChecked()); + + data.set_window(configForm->leTcpWindow->text().toULong(&isOk)); + + data.set_cksum(configForm->leTcpCksum->text().remove(QChar(' ')).toULong(&isOk)); + data.set_is_override_cksum(configForm->cbTcpCksumOverride->isChecked()); + + data.set_urg_ptr(configForm->leTcpUrgentPointer->text().toULong(&isOk)); + + if (configForm->cbTcpFlagsUrg->isChecked()) ff |= TCP_FLAG_URG; + if (configForm->cbTcpFlagsAck->isChecked()) ff |= TCP_FLAG_ACK; + if (configForm->cbTcpFlagsPsh->isChecked()) ff |= TCP_FLAG_PSH; + if (configForm->cbTcpFlagsRst->isChecked()) ff |= TCP_FLAG_RST; + if (configForm->cbTcpFlagsSyn->isChecked()) ff |= TCP_FLAG_SYN; + if (configForm->cbTcpFlagsFin->isChecked()) ff |= TCP_FLAG_FIN; + data.set_flags(ff); +} + diff --git a/common/tcp.h b/common/tcp.h new file mode 100644 index 0000000..9fc2367 --- /dev/null +++ b/common/tcp.h @@ -0,0 +1,69 @@ +#ifndef _TCP_H +#define _TCP_H + +#include "abstractprotocol.h" + +#include "tcp.pb.h" +#include "ui_tcp.h" + +#define TCP_FLAG_URG 0x01 +#define TCP_FLAG_ACK 0x02 +#define TCP_FLAG_PSH 0x04 +#define TCP_FLAG_RST 0x08 +#define TCP_FLAG_SYN 0x10 +#define TCP_FLAG_FIN 0x20 + +class TcpConfigForm : public QWidget, public Ui::tcp +{ + Q_OBJECT +public: + TcpConfigForm(QWidget *parent = 0); +}; + +class TcpProtocol : public AbstractProtocol +{ +private: + OstProto::Tcp data; + static TcpConfigForm *configForm; + enum tcpfield + { + tcp_src_port = 0, + tcp_dst_port, + tcp_seq_num, + tcp_ack_num, + tcp_hdrlen, + tcp_rsvd, + tcp_flags, + tcp_window, + tcp_cksum, + tcp_urg_ptr, + + tcp_is_override_hdrlen, + tcp_is_override_cksum, + + tcp_fieldCount + }; + +public: + TcpProtocol(Stream *parent = 0); + virtual ~TcpProtocol(); + + virtual void protoDataCopyInto(OstProto::Stream &stream); + virtual void protoDataCopyFrom(const OstProto::Stream &stream); + + virtual QString name() const; + virtual QString shortName() const; + + virtual int fieldCount() const; + + virtual QVariant fieldData(int index, FieldAttrib attrib, + int streamIndex = 0) const; + virtual bool setFieldData(int index, const QVariant &value, + FieldAttrib attrib = FieldValue); + + virtual QWidget* configWidget(); + virtual void loadConfigWidget(); + virtual void storeConfigWidget(); +}; + +#endif diff --git a/common/tcp.proto b/common/tcp.proto new file mode 100644 index 0000000..8144bad --- /dev/null +++ b/common/tcp.proto @@ -0,0 +1,27 @@ +import "protocol.proto"; + +package OstProto; +// Tcp +message Tcp { + + optional bool is_override_hdrlen = 1; + optional bool is_override_cksum = 2; + + optional uint32 src_port = 3 [default = 8902]; + optional uint32 dst_port = 4 [default = 80]; + + optional uint32 seq_num = 5 [default = 129018]; + optional uint32 ack_num = 6; + + optional uint32 hdrlen_rsvd = 7 [default = 0x50]; + optional uint32 flags = 8; + + optional uint32 window = 9 [default = 1024]; + optional uint32 cksum = 10; + optional uint32 urg_ptr = 11; +} + +extend Stream { + optional Tcp tcp = 140; +} + diff --git a/common/tcp.ui b/common/tcp.ui new file mode 100644 index 0000000..4a333be --- /dev/null +++ b/common/tcp.ui @@ -0,0 +1,228 @@ + + tcp + + + + 0 + 0 + 447 + 194 + + + + Form + + + + + + Source Port + + + + + + + + + + Qt::Vertical + + + + + + + Override Checksum + + + + + + + false + + + HH HH; + + + + + + + Destination Port + + + + + + + + + + Urgent Pointer + + + + + + + + + + Sequence Number + + + + + + + + + + Flags + + + + + + URG + + + + + + + ACK + + + + + + + PSH + + + + + + + RST + + + + + + + SYN + + + + + + + FIN + + + + + + + + + + Qt::Horizontal + + + + 21 + 20 + + + + + + + + Acknowledgement Number + + + + + + + + + + Override Header Length (x4) + + + + + + + false + + + + + + + Window + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + cbTcpHdrLenOverride + toggled(bool) + leTcpHdrLen + setEnabled(bool) + + + 141 + 123 + + + 187 + 123 + + + + + cbTcpCksumOverride + toggled(bool) + leTcpCksum + setEnabled(bool) + + + 316 + 14 + + + 384 + 17 + + + + + diff --git a/common/udp.cpp b/common/udp.cpp new file mode 100644 index 0000000..c2e1bfe --- /dev/null +++ b/common/udp.cpp @@ -0,0 +1,200 @@ +#include +#include + +#include "udp.h" + +UdpConfigForm *UdpProtocol::configForm = NULL; + +UdpConfigForm::UdpConfigForm(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); +} + +UdpProtocol::UdpProtocol(Stream *parent) + : AbstractProtocol(parent) +{ + if (configForm == NULL) + configForm = new UdpConfigForm; +} + +UdpProtocol::~UdpProtocol() +{ +} + +void UdpProtocol::protoDataCopyInto(OstProto::Stream &stream) +{ + // FIXME: multiple headers + stream.MutableExtension(OstProto::udp)->CopyFrom(data); +} + +void UdpProtocol::protoDataCopyFrom(const OstProto::Stream &stream) +{ + // FIXME: multiple headers + if (stream.HasExtension(OstProto::udp)) + data.MergeFrom(stream.GetExtension(OstProto::udp)); +} + +QString UdpProtocol::name() const +{ + return QString("User Datagram Protocol"); +} + +QString UdpProtocol::shortName() const +{ + return QString("UDP"); +} + +int UdpProtocol::fieldCount() const +{ + return udp_fieldCount; +} + +QVariant UdpProtocol::fieldData(int index, FieldAttrib attrib, + int streamIndex) const +{ + switch (index) + { + case udp_srcPort: + switch(attrib) + { + case FieldName: + return QString("Source Port"); + case FieldValue: + return data.src_port(); + case FieldTextValue: + return QString("%1").arg(data.src_port()); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.src_port(), (uchar*) fv.data()); + return fv; + } + default: + break; + } + break; + + case udp_dstPort: + switch(attrib) + { + case FieldName: + return QString("Destination Port"); + case FieldValue: + return data.dst_port(); + case FieldTextValue: + return QString("%1").arg(data.dst_port()); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.dst_port(), (uchar*) fv.data()); + return fv; + } + default: + break; + } + 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()); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.totlen(), (uchar*) fv.data()); + return fv; + } + default: + break; + } + break; + + case udp_cksum: + switch(attrib) + { + case FieldName: + return QString("Checksum"); + case FieldValue: + return data.cksum(); + case FieldTextValue: + return QString("%1").arg(data.cksum()); + case FieldFrameValue: + { + QByteArray fv; + fv.resize(2); + qToBigEndian((quint16) data.cksum(), (uchar*) fv.data()); + return fv; + } + default: + break; + } + break; + + // Meta fields + case udp_isOverrideTotLen: + case udp_isOverrideCksum: + switch(attrib) + { + case FieldIsMeta: + return true; + default: + break; + } + break; + + default: + break; + } + + return AbstractProtocol::fieldData(index, attrib, streamIndex); +} + +bool UdpProtocol::setFieldData(int index, const QVariant &value, + FieldAttrib attrib) +{ + // FIXME + return false; +} + + +QWidget* UdpProtocol::configWidget() +{ + return configForm; +} + +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())); + + configForm->leUdpLength->setText(QString().setNum(data.totlen())); + configForm->cbUdpLengthOverride->setChecked(data.is_override_totlen()); + + configForm->leUdpCksum->setText(QString().setNum(data.cksum())); + configForm->cbUdpCksumOverride->setChecked(data.is_override_cksum()); +} + +void UdpProtocol::storeConfigWidget() +{ + bool isOk; + + data.set_src_port(configForm->leUdpSrcPort->text().toULong(&isOk)); + data.set_dst_port(configForm->leUdpDstPort->text().toULong(&isOk)); + + data.set_totlen(configForm->leUdpLength->text().toULong(&isOk)); + data.set_is_override_totlen(configForm->cbUdpLengthOverride->isChecked()); + + data.set_cksum(configForm->leUdpCksum->text().remove(QChar(' ')).toULong(&isOk)); + data.set_is_override_cksum(configForm->cbUdpCksumOverride->isChecked()); +} + diff --git a/common/udp.h b/common/udp.h new file mode 100644 index 0000000..4fe5147 --- /dev/null +++ b/common/udp.h @@ -0,0 +1,56 @@ +#ifndef _UDP_H +#define _UDP_H + +#include "abstractprotocol.h" + +#include "udp.pb.h" +#include "ui_udp.h" + +class UdpConfigForm : public QWidget, public Ui::udp +{ + Q_OBJECT +public: + UdpConfigForm(QWidget *parent = 0); +}; + +class UdpProtocol : public AbstractProtocol +{ +private: + OstProto::Udp data; + static UdpConfigForm *configForm; + enum udpfield + { + udp_srcPort = 0, + udp_dstPort, + udp_totLen, + udp_cksum, + + udp_isOverrideTotLen, + udp_isOverrideCksum, + + udp_fieldCount + }; + +public: + UdpProtocol(Stream *parent = 0); + virtual ~UdpProtocol(); + + virtual void protoDataCopyInto(OstProto::Stream &stream); + virtual void protoDataCopyFrom(const OstProto::Stream &stream); + + virtual QString name() const; + virtual QString shortName() const; + + virtual int fieldCount() const; + + virtual QVariant fieldData(int index, FieldAttrib attrib, + int streamIndex = 0) const; + virtual bool setFieldData(int index, const QVariant &value, + FieldAttrib attrib = FieldValue); + + virtual QWidget* configWidget(); + virtual void loadConfigWidget(); + virtual void storeConfigWidget(); +}; + +#endif diff --git a/common/udp.proto b/common/udp.proto new file mode 100644 index 0000000..5f9680d --- /dev/null +++ b/common/udp.proto @@ -0,0 +1,18 @@ +import "protocol.proto"; + +package OstProto; + +// UDP +message Udp { + optional bool is_override_totlen = 1; + optional bool is_override_cksum = 2; + + optional uint32 src_port = 3 [default = 8902]; + optional uint32 dst_port = 4 [default = 80]; + optional uint32 totlen = 5; + optional uint32 cksum = 6; +} + +extend Stream { + optional Udp udp = 141; +} diff --git a/common/udp.ui b/common/udp.ui new file mode 100644 index 0000000..e8e29d3 --- /dev/null +++ b/common/udp.ui @@ -0,0 +1,101 @@ + + udp + + + + 0 + 0 + 217 + 144 + + + + Form + + + + + + + + Source Port + + + + + + + + + + Destination Port + + + + + + + + + + Override Length + + + + + + + false + + + + + + + Override Checksum + + + + + + + false + + + HH HH; + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/common/vlan.proto b/common/vlan.proto new file mode 100644 index 0000000..d5ac773 --- /dev/null +++ b/common/vlan.proto @@ -0,0 +1,17 @@ +import "protocol.proto"; + +package OstProto; +message Vlan { + // VLAN presence/absence + optional bool is_tpid_override = 10; + + // VLAN values + optional uint32 ctpid = 13; + optional uint32 cvlan_tag = 14; // includes prio, cfi and cvlanid + optional uint32 stpid = 15; + optional uint32 svlan_tag = 16; // includes pcp, de and svlanid +} + +extend Stream { + optional Vlan vlan = 126; +} diff --git a/common/vlan.ui b/common/vlan.ui new file mode 100644 index 0000000..0ae3be6 --- /dev/null +++ b/common/vlan.ui @@ -0,0 +1,168 @@ + + Form + + + + 0 + 0 + 271 + 90 + + + + Form + + + + + + + + Priority + + + + + + + CFI + + + + + + + VLAN + + + + + + + true + + + Override TPID + + + + + + + true + + + + 0 + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 7 + + + + + + + + true + + + + 0 + + + + + 1 + + + + + + + + true + + + 0 + + + + + + + true + + + HH HH; + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/rpc/pbrpc.pro b/rpc/pbrpc.pro index 79c0e08..3465da3 100644 --- a/rpc/pbrpc.pro +++ b/rpc/pbrpc.pro @@ -1,13 +1,8 @@ TEMPLATE = lib -CONFIG += qt +CONFIG += qt staticlib QT += network DEFINES += HAVE_REMOTE INCLUDEPATH += "c:\msys\1.0\local\include" LIBS += -L"C:\msys\1.0\local\lib" -lprotobuf HEADERS += rpcserver.h pbrpccontroller.h pbrpcchannel.h SOURCES += rpcserver.cpp pbrpcchannel.cpp -client.path = ..\client\debug -client.files = debug\libpbrpc.a debug\pbrpc.dll -server.path = ..\server\debug -server.files = debug\libpbrpc.a debug\pbrpc.dll -INSTALLS += client server diff --git a/server/drone.pro b/server/drone.pro index 15d69b1..c42d9a4 100644 --- a/server/drone.pro +++ b/server/drone.pro @@ -3,15 +3,17 @@ CONFIG += qt debug QT += network DEFINES += HAVE_REMOTE WPCAP INCLUDEPATH += "../rpc" +LIBS += -lprotobuf win32:LIBS += -lwpcap -lpacket unix:LIBS += -lpcap +win32:LIBS += -L"../common/debug" -lostproto +unix:LIBS += -L"../common" -lostproto win32:LIBS += -L"../rpc/debug" -lpbrpc unix:LIBS += -L"../rpc" -lpbrpc +POST_TARGETDEPS += "../common/debug/libostproto.a" "../rpc/debug/libpbrpc.a" HEADERS += drone.h FORMS += drone.ui SOURCES += drone_main.cpp drone.cpp SOURCES += myservice.cpp - SOURCES += pcapextra.cpp -SOURCES += "..\common\protocol.pb.cc" diff --git a/server/myservice.cpp b/server/myservice.cpp index 085f6f5..20bbda0 100644 --- a/server/myservice.cpp +++ b/server/myservice.cpp @@ -4,6 +4,17 @@ #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 @@ -12,6 +23,64 @@ #define LOG(...) {sprintf(logStr, __VA_ARGS__); host->Log(logStr);} #define MB (1024*1024) +StreamInfo::StreamInfo() +{ + 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); +} + +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; + } +} + quint32 StreamInfo::pseudoHdrCksumPartial(quint32 srcIp, quint32 dstIp, quint8 protocol, quint16 len) { @@ -76,33 +145,29 @@ quint16 StreamInfo::ipv4Cksum(uchar *buf, int len, quint32 partialSum) int StreamInfo::makePacket(uchar *buf, int bufMaxSize, int n) { - int u, pktLen, dataLen, len = 0; - quint32 srcIp, dstIp; // need it later for TCP/UDP cksum calculation - quint32 cumCksum = 0; // cumulative cksum used to combine partial cksums - int tcpOfs, udpOfs; // needed to fill in cksum later - uchar scratch[8]; + int pktLen, len = 0; // Decide a frame length based on length mode - switch(d.core().len_mode()) + switch(mCore.len_mode()) { case OstProto::StreamCore::e_fl_fixed: - pktLen = d.core().frame_len(); + pktLen = mCore.frame_len(); break; case OstProto::StreamCore::e_fl_inc: - pktLen = d.core().frame_len_min() + (n % - (d.core().frame_len_max() - d.core().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 = d.core().frame_len_max() - (n % - (d.core().frame_len_max() - d.core().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 = d.core().frame_len_min() + (qrand() % - (d.core().frame_len_max() - d.core().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", - d.core().len_mode()); + mCore.len_mode()); pktLen = 64; break; } @@ -113,6 +178,31 @@ int StreamInfo::makePacket(uchar *buf, int bufMaxSize, int n) if ((pktLen < 0) || (pktLen > bufMaxSize)) return 0; + // FIXME: Calculated pktLen is an input to Payload Protocol + + // FIXME: checksums!!! + + for (int i = 0; i < mCore.frame_proto_size(); i++) + { + QByteArray ba; + + ba = protocolById(mCore.frame_proto(i))->protocolFrameValue(n); + if (len + ba.size() < bufMaxSize) + { + memcpy(buf+len, ba.constData(), ba.size()); + } + len += ba.size(); + } + + return pktLen; + +#if 0 // Proto FW + int u, pktLen, dataLen, len = 0; + quint32 srcIp, dstIp; // need it later for TCP/UDP cksum calculation + quint32 cumCksum = 0; // cumulative cksum used to combine partial cksums + int tcpOfs, udpOfs; // needed to fill in cksum later + uchar scratch[8]; + // We always have a Mac Header! switch (d.mac().dst_mac_mode()) { @@ -449,7 +539,9 @@ int StreamInfo::makePacket(uchar *buf, int bufMaxSize, int n) default: qWarning("Unhandled data pattern %d", d.core().pattern_mode()); } +#endif +#if 0 // Proto FW // Calculate TCP/UDP checksum over the data pattern/payload and fill in switch (d.core().l4_proto()) { @@ -473,8 +565,9 @@ int StreamInfo::makePacket(uchar *buf, int bufMaxSize, int n) // No cksum processing required break; } - return pktLen; +#endif + } @@ -597,28 +690,28 @@ void PortInfo::update() for (int i = 0; i < streamList.size(); i++) { //_restart: - if (streamList[i].d.core().is_enabled()) + if (streamList[i]->mCore.is_enabled()) { long numPackets, numBursts; long ibg, ipg; - switch (streamList[i].d.control().unit()) + switch (streamList[i]->mControl.unit()) { case OstProto::StreamControl::e_su_bursts: - numBursts = streamList[i].d.control().num_bursts(); - numPackets = streamList[i].d.control().packets_per_burst(); - ibg = 1000000/streamList[i].d.control().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].d.control().num_packets(); + numPackets = streamList[i]->mControl.num_packets(); ibg = 0; - ipg = 1000000/streamList[i].d.control().packets_per_sec(); + ipg = 1000000/streamList[i]->mControl.packets_per_sec(); break; default: qWarning("Unhandled stream control unit %d", - streamList[i].d.control().unit()); + streamList[i]->mControl.unit()); continue; } qDebug("numBursts = %ld, numPackets = %ld\n", @@ -631,7 +724,7 @@ void PortInfo::update() { int len; - len = streamList[i].makePacket(pktBuf, sizeof(pktBuf), + len = streamList[i]->makePacket(pktBuf, sizeof(pktBuf), j * numPackets + k); if (len > 0) { @@ -680,7 +773,7 @@ void PortInfo::update() } } // for (numBursts) - switch(streamList[i].d.control().next()) + switch(streamList[i]->mControl.next()) { case ::OstProto::StreamControl::e_nw_stop: goto _stop_no_more_pkts; @@ -705,7 +798,7 @@ void PortInfo::update() default: qFatal("---------- %s: Unhandled case (%d) -----------", - __FUNCTION__, streamList[i].d.control().next() ); + __FUNCTION__, streamList[i]->mControl.next() ); break; } @@ -1124,7 +1217,7 @@ int MyService::getStreamIndex(unsigned int portIdx, for (i = 0; i < portInfo[portIdx]->streamList.size(); i++) { - if (streamId == portInfo[portIdx]->streamList.at(i).d.stream_id().id()) + if (streamId == portInfo[portIdx]->streamList.at(i)->mStreamId.id()) goto _found; } @@ -1247,12 +1340,10 @@ const ::OstProto::PortId* request, response->mutable_port_id()->set_id(portIdx); for (int j = 0; j < portInfo[portIdx]->streamList.size(); j++) { - OstProto::StreamId *s, *q; - - q = portInfo[portIdx]->streamList[j].d.mutable_stream_id(); + OstProto::StreamId *s; s = response->add_stream_id(); - s->CopyFrom(*q); + s->CopyFrom(portInfo[portIdx]->streamList[j]->mStreamId); } _exit: @@ -1286,7 +1377,19 @@ const ::OstProto::StreamIdList* request, continue; // TODO(LOW): Partial status of RPC s = response->add_stream(); - s->CopyFrom(portInfo[portIdx]->streamList[streamIndex].d); + + 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); + } } _exit: @@ -1312,7 +1415,7 @@ const ::OstProto::StreamIdList* request, for (int i = 0; i < request->stream_id_size(); i++) { int streamIndex; - StreamInfo s; + StreamInfo *s = new StreamInfo; // If stream with same id as in request exists already ==> error!! streamIndex = getStreamIndex(portIdx, request->stream_id(i).id()); @@ -1322,7 +1425,7 @@ const ::OstProto::StreamIdList* request, // Append a new "default" stream - actual contents of the new stream is // expected in a subsequent "modifyStream" request - set the stream id // now itself however!!! - s.d.mutable_stream_id()->CopyFrom(request->stream_id(i)); + s->mStreamId.CopyFrom(request->stream_id(i)); portInfo[portIdx]->streamList.append(s); // TODO(LOW): fill-in response "Ack"???? @@ -1357,7 +1460,7 @@ const ::OstProto::StreamIdList* request, if (streamIndex < 0) continue; // TODO(LOW): Partial status of RPC - portInfo[portIdx]->streamList.removeAt(streamIndex); + delete portInfo[portIdx]->streamList.takeAt(streamIndex); // TODO(LOW): fill-in response "Ack"???? } @@ -1391,8 +1494,17 @@ const ::OstProto::StreamConfigList* request, if (streamIndex < 0) continue; // TODO(LOW): Partial status of RPC - portInfo[portIdx]->streamList[streamIndex].d.MergeFrom( - request->stream(i)); + 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)); + } // TODO(LOW): fill-in response "Ack"???? } diff --git a/server/myservice.h b/server/myservice.h index bbf019c..6a662fd 100644 --- a/server/myservice.h +++ b/server/myservice.h @@ -8,6 +8,7 @@ #endif #include "../common/protocol.pb.h" +#include "../common/abstractprotocol.h" #include "abstracthost.h" #include #include @@ -34,10 +35,18 @@ class StreamInfo friend class MyService; friend class PortInfo; - OstProto::Stream d; - - StreamInfo() { PbHelper pbh; pbh.ForceSetSingularDefault(&d); } + 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); @@ -45,7 +54,7 @@ class StreamInfo int makePacket(uchar *buf, int bufMaxSize, int n); public: bool operator < (const StreamInfo &s) const - { return(d.core().ordinal() < s.d.core().ordinal()); } + { return(mCore.ordinal() < s.mCore.ordinal()); } }; @@ -146,7 +155,7 @@ class PortInfo struct timeval lastTsTx; //! used for Rate Stats calculations /*! StreamInfo::d::stream_id and index into streamList[] are NOT same! */ - QList streamList; + QList streamList; public: PortInfo(uint id, pcap_if_t *dev);