diff --git a/client/streamconfigdialog.cpp b/client/streamconfigdialog.cpp index 30649b3..5201099 100644 --- a/client/streamconfigdialog.cpp +++ b/client/streamconfigdialog.cpp @@ -43,60 +43,60 @@ StreamConfigDialog::StreamConfigDialog(Port &port, uint streamIndex, // Time to play match the signals and slots! - // If L1/FT = None, force subsequent protocol level(s) also to None - connect(rbL1None, SIGNAL(toggled(bool)), this, SLOT(forceProtocolNone(bool))); - connect(rbFtNone, SIGNAL(toggled(bool)), this, SLOT(forceProtocolNone(bool))); + // If L1/L2(FT)/L3 = None, force subsequent protocol level(s) also to None + connect(rbL1None, SIGNAL(toggled(bool)), SLOT(forceProtocolNone(bool))); + connect(rbFtNone, SIGNAL(toggled(bool)), SLOT(forceProtocolNone(bool))); + connect(rbL3None, SIGNAL(toggled(bool)), SLOT(forceProtocolNone(bool))); - // Enable/Disable L3 Protocol Choices for FT Ethernet2 - connect(rbFtEthernet2, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setEnabled(bool))); - connect(rbFtEthernet2, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setEnabled(bool))); - - // Force L3 = None if FT = 802.3 Raw - connect(rbFt802Dot3Raw, SIGNAL(clicked(bool)), rbL3None, SLOT(click())); - connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setDisabled(bool))); - connect(rbFt802Dot3Raw, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setDisabled(bool))); - - // Force L3 = None if FT = 802.3 LLC (to ensure a valid L3 is selected) - connect(rbFt802Dot3Llc, SIGNAL(clicked(bool)), rbL3None, SLOT(click())); - - // Enable/Disable L3 Protocol Choices for FT 802Dot3Llc - connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setEnabled(bool))); - connect(rbFt802Dot3Llc, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setDisabled(bool))); - - // Enable/Disable L3 Protocol Choices for FT 802.3 LLC SNAP - connect(rbFtLlcSnap, SIGNAL(toggled(bool)), rbL3Ipv4, SLOT(setEnabled(bool))); - connect(rbFtLlcSnap, SIGNAL(toggled(bool)), rbL3Arp, SLOT(setEnabled(bool))); - - // Force L3 = Other if FT = Other + // If L1/L2(FT)/L3/L4 = Other, force subsequent protocol to Other and + // disable the subsequent protocol group as well + connect(rbL1Other, SIGNAL(toggled(bool)), rbFtOther, SLOT(setChecked(bool))); + connect(rbL1Other, SIGNAL(toggled(bool)), gbFrameType, SLOT(setDisabled(bool))); connect(rbFtOther, SIGNAL(toggled(bool)), rbL3Other, SLOT(setChecked(bool))); connect(rbFtOther, SIGNAL(toggled(bool)), gbL3Proto, SLOT(setDisabled(bool))); - - // If L3 = None, force subsequent protocol level also to None - connect(rbL3None, SIGNAL(toggled(bool)), this, SLOT(forceProtocolNone(bool))); - - // Enable/Disable L4 Protocol Choices for L3 Protocol IPv4 - connect(rbL3Ipv4, SIGNAL(toggled(bool)), rbL4Icmp, SLOT(setEnabled(bool))); - connect(rbL3Ipv4, SIGNAL(toggled(bool)), rbL4Igmp, SLOT(setEnabled(bool))); - connect(rbL3Ipv4, SIGNAL(toggled(bool)), rbL4Tcp, SLOT(setEnabled(bool))); - connect(rbL3Ipv4, SIGNAL(toggled(bool)), rbL4Udp, SLOT(setEnabled(bool))); - - // Enable/Disable L4 Protocol Choices for L3 Protocol ARP - connect(rbL3Arp, SIGNAL(toggled(bool)), rbL4Icmp, SLOT(setDisabled(bool))); - connect(rbL3Arp, SIGNAL(toggled(bool)), rbL4Igmp, SLOT(setDisabled(bool))); - connect(rbL3Arp, SIGNAL(toggled(bool)), rbL4Tcp, SLOT(setDisabled(bool))); - connect(rbL3Arp, SIGNAL(toggled(bool)), rbL4Udp, SLOT(setDisabled(bool))); - - // Force L4 Protocol = None if L3 Protocol is set to ARP - connect(rbL3Arp, SIGNAL(clicked(bool)), rbL4None, SLOT(click())); - - // Force L4 = Other if L3 = Other connect(rbL3Other, SIGNAL(toggled(bool)), rbL4Other, SLOT(setChecked(bool))); connect(rbL3Other, SIGNAL(toggled(bool)), gbL4Proto, SLOT(setDisabled(bool))); - - // Force Payload = Other if L4 = Other connect(rbL4Other, SIGNAL(toggled(bool)), rbPayloadOther, SLOT(setChecked(bool))); connect(rbL4Other, SIGNAL(toggled(bool)), gbPayloadProto, SLOT(setDisabled(bool))); + // Setup valid subsequent protocols for L2 and L3 protocols + for (int i = ProtoL2; i <= ProtoL3; i++) + { + foreach(QAbstractButton *btn1, bgProto[i]->buttons()) + { + int id1 = bgProto[i]->id(btn1); + + if (id1 != ButtonIdNone && id1 != ButtonIdOther) + { + int validProtocolCount = 0; + + foreach(QAbstractButton *btn2, bgProto[i+1]->buttons()) + { + int id2 = bgProto[i+1]->id(btn2); + + if (id2 != ButtonIdNone && id2 != ButtonIdOther) + { + if (OstProtocolManager.isValidNeighbour(id1, id2)) + { + connect(btn1, SIGNAL(toggled(bool)), + btn2, SLOT(setEnabled(bool))); + validProtocolCount++; + } + else + connect(btn1, SIGNAL(toggled(bool)), + btn2, SLOT(setDisabled(bool))); + } + } + + // If btn1 has no subsequent valid protocols, + // force subsequent Protocol to 'None' + if (validProtocolCount == 0) + connect(btn1, SIGNAL(clicked(bool)), + bgProto[i+1]->button(ButtonIdNone), SLOT(click())); + } + } + } + mpAvailableProtocolsModel = new QStringListModel( OstProtocolManager.protocolDatabase(), this); lvAllProtocols->setModel(mpAvailableProtocolsModel); @@ -729,8 +729,16 @@ void StreamConfigDialog::updateSelectProtocolsSimpleWidget() id = _iter->next()->protocolNumber(); btn = bgProto[i]->button(id); - if (btn && btn->isEnabled()) - btn->click(); + if (btn) + { + if (btn->isEnabled()) + btn->click(); + else + { + btn->setChecked(true); + __updateProtocol(i, id); + } + } else { switch (i) diff --git a/common/abstractprotocol.cpp b/common/abstractprotocol.cpp index 10678fb..3dd58ae 100644 --- a/common/abstractprotocol.cpp +++ b/common/abstractprotocol.cpp @@ -44,7 +44,7 @@ AbstractProtocol* AbstractProtocol::createInstance(StreamBase *stream, quint32 AbstractProtocol::protocolNumber() const { - qDebug("Something wrong!!!"); + qFatal("Something wrong!!!"); return 0xFFFFFFFF; } @@ -193,6 +193,11 @@ bool AbstractProtocol::setFieldData(int index, const QVariant &value, return false; } +AbstractProtocol::ProtocolIdType AbstractProtocol::protocolIdType() const +{ + return ProtocolIdNone; +} + quint32 AbstractProtocol::protocolId(ProtocolIdType type) const { return 0; @@ -360,6 +365,49 @@ QByteArray AbstractProtocol::protocolFrameValue(int streamIndex, bool forCksum) return proto; } +bool AbstractProtocol::isProtocolFrameValueVariable() const +{ + return false; +} + +bool AbstractProtocol::isProtocolFrameSizeVariable() const +{ + return false; +} + +bool AbstractProtocol::isProtocolFramePayloadValueVariable() const +{ + AbstractProtocol *p = next; + + while (p) + { + if (p->isProtocolFrameValueVariable()) + return true; + p = p->next; + } + if (parent && parent->isProtocolFramePayloadValueVariable()) + return true; + + return false; +} + +bool AbstractProtocol::isProtocolFramePayloadSizeVariable() const +{ + AbstractProtocol *p = next; + + while (p) + { + if (p->isProtocolFrameSizeVariable()) + return true; + p = p->next; + } + if (parent && parent->isProtocolFramePayloadSizeVariable()) + return true; + + return false; +} + + /*! \note If a subclass uses protocolFrameCksum() from within fieldData() to derive a cksum field, it MUST handle and return the 'FieldBitSize' diff --git a/common/abstractprotocol.h b/common/abstractprotocol.h index 3e1dc12..ccf1b12 100644 --- a/common/abstractprotocol.h +++ b/common/abstractprotocol.h @@ -56,6 +56,7 @@ public: }; enum ProtocolIdType { + ProtocolIdNone, ProtocolIdLlc, ProtocolIdEth, ProtocolIdIp, @@ -82,6 +83,7 @@ public: virtual QString name() const; virtual QString shortName() const; + virtual ProtocolIdType protocolIdType() const; virtual quint32 protocolId(ProtocolIdType type) const; quint32 payloadProtocolId(ProtocolIdType type) const; @@ -101,6 +103,11 @@ public: int protocolFrameOffset(int streamIndex = 0) const; int protocolFramePayloadSize(int streamIndex = 0) const; + virtual bool isProtocolFrameValueVariable() const; + virtual bool isProtocolFrameSizeVariable() const; + bool isProtocolFramePayloadValueVariable() const; + bool isProtocolFramePayloadSizeVariable() const; + virtual quint32 protocolFrameCksum(int streamIndex = 0, CksumType cksumType = CksumIp) const; quint32 protocolFrameHeaderCksum(int streamIndex = 0, diff --git a/common/comboprotocol.h b/common/comboprotocol.h index 34cba86..dbfd682 100644 --- a/common/comboprotocol.h +++ b/common/comboprotocol.h @@ -84,6 +84,11 @@ public: return protoA->shortName() + "/" + protoB->shortName(); } + virtual ProtocolIdType protocolIdType() const + { + return protoB->protocolIdType(); + } + virtual quint32 protocolId(ProtocolIdType type) const { return protoA->protocolId(type); @@ -133,7 +138,21 @@ public: virtual int protocolFrameSize() const; int protocolFrameOffset() const; int protocolFramePayloadSize() const; +#endif + virtual bool isProtocolFrameValueVariable() const + { + return (protoA->isProtocolFrameValueVariable() + || protoB->isProtocolFrameValueVariable()); + } + + virtual bool isProtocolFrameSizeVariable() const + { + return (protoA->isProtocolFrameSizeVariable() + || protoB->isProtocolFrameSizeVariable()); + } + +#if 0 virtual quint32 protocolFrameCksum(int streamIndex = 0, CksumType cksumType = CksumIp) const; quint32 protocolFrameHeaderCksum(int streamIndex = 0, diff --git a/common/dot3.cpp b/common/dot3.cpp index 0a88d50..ac2a878 100644 --- a/common/dot3.cpp +++ b/common/dot3.cpp @@ -119,6 +119,10 @@ bool Dot3Protocol::setFieldData(int index, const QVariant &value, return false; } +bool Dot3Protocol::isProtocolFrameValueVariable() const +{ + return isProtocolFramePayloadSizeVariable(); +} QWidget* Dot3Protocol::configWidget() { diff --git a/common/dot3.h b/common/dot3.h index def1031..9e0e8c1 100644 --- a/common/dot3.h +++ b/common/dot3.h @@ -46,6 +46,8 @@ public: virtual bool setFieldData(int index, const QVariant &value, FieldAttrib attrib = FieldValue); + virtual bool isProtocolFrameValueVariable() const; + virtual QWidget* configWidget(); virtual void loadConfigWidget(); virtual void storeConfigWidget(); diff --git a/common/eth2.cpp b/common/eth2.cpp index 7a6f7b5..0028b51 100644 --- a/common/eth2.cpp +++ b/common/eth2.cpp @@ -54,6 +54,11 @@ QString Eth2Protocol::shortName() const return QString("Eth II"); } +AbstractProtocol::ProtocolIdType Eth2Protocol::protocolIdType() const +{ + return ProtocolIdEth; +} + int Eth2Protocol::fieldCount() const { return eth2_fieldCount; diff --git a/common/eth2.h b/common/eth2.h index 0555d65..fcf6b7d 100644 --- a/common/eth2.h +++ b/common/eth2.h @@ -39,6 +39,8 @@ public: virtual QString name() const; virtual QString shortName() const; + virtual ProtocolIdType protocolIdType() const; + virtual int fieldCount() const; virtual QVariant fieldData(int index, FieldAttrib attrib, diff --git a/common/ip4.cpp b/common/ip4.cpp index c929872..4c28bfb 100644 --- a/common/ip4.cpp +++ b/common/ip4.cpp @@ -94,6 +94,11 @@ QString Ip4Protocol::shortName() const return QString("IPv4"); } +AbstractProtocol::ProtocolIdType Ip4Protocol::protocolIdType() const +{ + return ProtocolIdIp; +} + quint32 Ip4Protocol::protocolId(ProtocolIdType type) const { switch(type) @@ -572,6 +577,15 @@ bool Ip4Protocol::setFieldData(int index, const QVariant &value, return isOk; } +bool Ip4Protocol::isProtocolFrameValueVariable() const +{ + if ((data.src_ip_mode() != OstProto::Ip4::e_im_fixed) + || (data.dst_ip_mode() != OstProto::Ip4::e_im_fixed)) + return true; + else + return false; +} + quint32 Ip4Protocol::protocolFrameCksum(int streamIndex, CksumType cksumType) const { diff --git a/common/ip4.h b/common/ip4.h index e378755..34f4c37 100644 --- a/common/ip4.h +++ b/common/ip4.h @@ -71,6 +71,7 @@ public: virtual QString name() const; virtual QString shortName() const; + virtual ProtocolIdType protocolIdType() const; virtual quint32 protocolId(ProtocolIdType type) const; virtual int fieldCount() const; @@ -82,6 +83,8 @@ public: virtual quint32 protocolFrameCksum(int streamIndex = 0, CksumType cksumType = CksumIp) const; + virtual bool isProtocolFrameValueVariable() const; + virtual QWidget* configWidget(); virtual void loadConfigWidget(); virtual void storeConfigWidget(); diff --git a/common/llc.cpp b/common/llc.cpp index e949e08..25cc307 100644 --- a/common/llc.cpp +++ b/common/llc.cpp @@ -54,6 +54,11 @@ QString LlcProtocol::shortName() const return QString("LLC"); } +AbstractProtocol::ProtocolIdType LlcProtocol::protocolIdType() const +{ + return ProtocolIdLlc; +} + int LlcProtocol::fieldCount() const { return llc_fieldCount; diff --git a/common/llc.h b/common/llc.h index 3555e92..741f493 100644 --- a/common/llc.h +++ b/common/llc.h @@ -44,6 +44,8 @@ public: virtual QString name() const; virtual QString shortName() const; + virtual ProtocolIdType protocolIdType() const; + virtual int fieldCount() const; virtual QVariant fieldData(int index, FieldAttrib attrib, diff --git a/common/mac.cpp b/common/mac.cpp index 8e468a3..1d7ed87 100644 --- a/common/mac.cpp +++ b/common/mac.cpp @@ -239,6 +239,15 @@ bool MacProtocol::setFieldData(int index, const QVariant &value, return false; } +bool MacProtocol::isProtocolFrameValueVariable() const +{ + if ((data.dst_mac_mode() != OstProto::Mac::e_mm_fixed) || + (data.src_mac_mode() != OstProto::Mac::e_mm_fixed)) + return true; + else + return false; +} + QWidget* MacProtocol::configWidget() { diff --git a/common/mac.h b/common/mac.h index a493bd6..b6165b7 100644 --- a/common/mac.h +++ b/common/mac.h @@ -61,6 +61,8 @@ public: virtual bool setFieldData(int index, const QVariant &value, FieldAttrib attrib = FieldValue); + virtual bool isProtocolFrameValueVariable() const; + virtual QWidget* configWidget(); virtual void loadConfigWidget(); virtual void storeConfigWidget(); diff --git a/common/payload.cpp b/common/payload.cpp index 1125b73..4bbca2e 100644 --- a/common/payload.cpp +++ b/common/payload.cpp @@ -187,6 +187,23 @@ bool PayloadProtocol::setFieldData(int index, const QVariant &value, return false; } +bool PayloadProtocol::isProtocolFrameValueVariable() const +{ + if (isProtocolFrameSizeVariable() + || data.pattern_mode() == OstProto::Payload::e_dp_random) + return true; + else + return false; +} + +bool PayloadProtocol::isProtocolFrameSizeVariable() const +{ + if (mpStream->lenMode() == StreamBase::e_fl_fixed) + return false; + else + return true; +} + QWidget* PayloadProtocol::configWidget() { diff --git a/common/payload.h b/common/payload.h index c2d5f4d..9437a8c 100644 --- a/common/payload.h +++ b/common/payload.h @@ -54,6 +54,9 @@ public: virtual bool setFieldData(int index, const QVariant &value, FieldAttrib attrib = FieldValue); + virtual bool isProtocolFrameValueVariable() const; + virtual bool isProtocolFrameSizeVariable() const; + virtual QWidget* configWidget(); virtual void loadConfigWidget(); virtual void storeConfigWidget(); diff --git a/common/protocolmanager.cpp b/common/protocolmanager.cpp index 56c1912..8a9547d 100644 --- a/common/protocolmanager.cpp +++ b/common/protocolmanager.cpp @@ -24,42 +24,69 @@ ProtocolManager::ProtocolManager() themselves (once this is done remove the #includes for all the protocols) */ registerProtocol(OstProto::Protocol::kMacFieldNumber, - QString("mac"), (void*) MacProtocol::createInstance); + (void*) MacProtocol::createInstance); registerProtocol(OstProto::Protocol::kPayloadFieldNumber, - QString("payload"), (void*) PayloadProtocol::createInstance); + (void*) PayloadProtocol::createInstance); registerProtocol(OstProto::Protocol::kEth2FieldNumber, - QString("eth2"), (void*) Eth2Protocol::createInstance); + (void*) Eth2Protocol::createInstance); registerProtocol(OstProto::Protocol::kDot3FieldNumber, - QString("dot3"), (void*) Dot3Protocol::createInstance); + (void*) Dot3Protocol::createInstance); registerProtocol(OstProto::Protocol::kLlcFieldNumber, - QString("llc"), (void*) LlcProtocol::createInstance); + (void*) LlcProtocol::createInstance); registerProtocol(OstProto::Protocol::kSnapFieldNumber, - QString("snap"), (void*) SnapProtocol::createInstance); + (void*) SnapProtocol::createInstance); registerProtocol(OstProto::Protocol::kDot2LlcFieldNumber, - QString("dot2Llc"), (void*) Dot2LlcProtocol::createInstance); + (void*) Dot2LlcProtocol::createInstance); registerProtocol(OstProto::Protocol::kDot2SnapFieldNumber, - QString("dot2Snap"), (void*) Dot2SnapProtocol::createInstance); + (void*) Dot2SnapProtocol::createInstance); registerProtocol(OstProto::Protocol::kSvlanFieldNumber, - QString("svlan"), (void*) VlanProtocol::createInstance); + (void*) SVlanProtocol::createInstance); registerProtocol(OstProto::Protocol::kVlanFieldNumber, - QString("vlan"), (void*) VlanProtocol::createInstance); + (void*) VlanProtocol::createInstance); registerProtocol(OstProto::Protocol::kVlanStackFieldNumber, - QString("vlanstack"), (void*) VlanStackProtocol::createInstance); + (void*) VlanStackProtocol::createInstance); registerProtocol(OstProto::Protocol::kIp4FieldNumber, - QString("ip4"), (void*) Ip4Protocol::createInstance); + (void*) Ip4Protocol::createInstance); registerProtocol(OstProto::Protocol::kTcpFieldNumber, - QString("tcp"), (void*) TcpProtocol::createInstance); + (void*) TcpProtocol::createInstance); registerProtocol(OstProto::Protocol::kUdpFieldNumber, - QString("udp"), (void*) UdpProtocol::createInstance); + (void*) UdpProtocol::createInstance); + + populateNeighbourProtocols(); } -void ProtocolManager::registerProtocol(int protoNumber, QString protoName, +void ProtocolManager::registerProtocol(int protoNumber, void *protoInstanceCreator) { + AbstractProtocol *p; + //! \todo (MED) validate incoming params for duplicates with existing - nameToNumberMap.insert(protoName, protoNumber); - numberToNameMap.insert(protoNumber, protoName); + factory.insert(protoNumber, protoInstanceCreator); + + p = createProtocol(protoNumber, NULL); + protocolList.append(p); + + numberToNameMap.insert(protoNumber, p->shortName()); + nameToNumberMap.insert(p->shortName(), protoNumber); +} + +void ProtocolManager::populateNeighbourProtocols() +{ + neighbourProtocols.clear(); + + foreach(AbstractProtocol *p, protocolList) + { + if (p->protocolIdType() != AbstractProtocol::ProtocolIdNone) + { + foreach(AbstractProtocol *q, protocolList) + { + if (q->protocolId(p->protocolIdType())) + neighbourProtocols.insert( + p->protocolNumber(), q->protocolNumber()); + } + } + } } AbstractProtocol* ProtocolManager::createProtocol(int protoNumber, @@ -84,6 +111,14 @@ AbstractProtocol* ProtocolManager::createProtocol(QString protoName, return createProtocol(nameToNumberMap.value(protoName), stream, parent); } +bool ProtocolManager::isValidNeighbour(int protoPrefix, int protoSuffix) +{ + if (neighbourProtocols.contains(protoPrefix, protoSuffix)) + return true; + else + return false; +} + QStringList ProtocolManager::protocolDatabase() { return numberToNameMap.values(); diff --git a/common/protocolmanager.h b/common/protocolmanager.h index 985253b..c619099 100644 --- a/common/protocolmanager.h +++ b/common/protocolmanager.h @@ -11,19 +11,24 @@ class ProtocolManager { QMap numberToNameMap; QMap nameToNumberMap; + QMultiMap neighbourProtocols; QMap factory; + QList protocolList; + + void populateNeighbourProtocols(); public: ProtocolManager(); - void registerProtocol(int protoNumber, QString protoName, - void *protoCreator); + void registerProtocol(int protoNumber, void *protoInstanceCreator); AbstractProtocol* createProtocol(int protoNumber, StreamBase *stream, AbstractProtocol *parent = 0); AbstractProtocol* createProtocol(QString protoName, StreamBase *stream, AbstractProtocol *parent = 0); + bool isValidNeighbour(int protoPrefix, int protoSuffix); + QStringList protocolDatabase(); }; diff --git a/common/snap.cpp b/common/snap.cpp index 3dfd7e4..0f7d477 100644 --- a/common/snap.cpp +++ b/common/snap.cpp @@ -54,6 +54,11 @@ QString SnapProtocol::shortName() const return QString("SNAP"); } +AbstractProtocol::ProtocolIdType SnapProtocol::protocolIdType() const +{ + return ProtocolIdEth; +} + quint32 SnapProtocol::protocolId(ProtocolIdType type) const { switch(type) diff --git a/common/snap.h b/common/snap.h index a2531f6..c4018ad 100644 --- a/common/snap.h +++ b/common/snap.h @@ -39,6 +39,8 @@ public: virtual QString name() const; virtual QString shortName() const; + + virtual ProtocolIdType protocolIdType() const; virtual quint32 protocolId(ProtocolIdType type) const; virtual int fieldCount() const; diff --git a/common/streambase.cpp b/common/streambase.cpp index 1ed8d7f..5bd2dcb 100644 --- a/common/streambase.cpp +++ b/common/streambase.cpp @@ -20,11 +20,13 @@ StreamBase::StreamBase() : iter = createProtocolListIterator(); // By default newly created streams have the mac and payload protocols - proto = OstProtocolManager.createProtocol("mac", this); + proto = OstProtocolManager.createProtocol( + OstProto::Protocol::kMacFieldNumber, this); iter->insert(proto); qDebug("stream: mac = %p", proto); - proto = OstProtocolManager.createProtocol("payload", this); + proto = OstProtocolManager.createProtocol( + OstProto::Protocol::kPayloadFieldNumber, this); iter->insert(proto); qDebug("stream: payload = %p", proto); @@ -104,7 +106,7 @@ void StreamBase::setFrameProtocol(ProtocolList protocolList) } #endif -ProtocolListIterator* StreamBase::createProtocolListIterator() +ProtocolListIterator* StreamBase::createProtocolListIterator() const { return new ProtocolListIterator(*currentFrameProtocols); } @@ -158,7 +160,7 @@ bool StreamBase::setName(QString name) return true; } -StreamBase::FrameLengthMode StreamBase::lenMode() +StreamBase::FrameLengthMode StreamBase::lenMode() const { return (StreamBase::FrameLengthMode) mCore->len_mode(); } @@ -169,7 +171,7 @@ bool StreamBase::setLenMode(FrameLengthMode lenMode) return true; } -quint16 StreamBase::frameLen(int streamIndex) +quint16 StreamBase::frameLen(int streamIndex) const { int pktLen; @@ -211,7 +213,7 @@ bool StreamBase::setFrameLen(quint16 frameLen) return true; } -quint16 StreamBase::frameLenMin() +quint16 StreamBase::frameLenMin() const { return mCore->frame_len_min(); } @@ -222,7 +224,7 @@ bool StreamBase::setFrameLenMin(quint16 frameLenMin) return true; } -quint16 StreamBase::frameLenMax() +quint16 StreamBase::frameLenMax() const { return mCore->frame_len_max(); } @@ -233,17 +235,18 @@ bool StreamBase::setFrameLenMax(quint16 frameLenMax) return true; } -StreamBase::SendUnit StreamBase::sendUnit() +StreamBase::SendUnit StreamBase::sendUnit() const { return (StreamBase::SendUnit) mControl->unit(); } + bool StreamBase::setSendUnit(SendUnit sendUnit) { mControl->set_unit((OstProto::StreamControl::SendUnit) sendUnit); return true; } -StreamBase::SendMode StreamBase::sendMode() +StreamBase::SendMode StreamBase::sendMode() const { return (StreamBase::SendMode) mControl->mode(); } @@ -255,7 +258,7 @@ bool StreamBase::setSendMode(SendMode sendMode) return true; } -StreamBase::NextWhat StreamBase::nextWhat() +StreamBase::NextWhat StreamBase::nextWhat() const { return (StreamBase::NextWhat) mControl->next(); } @@ -266,7 +269,7 @@ bool StreamBase::setNextWhat(NextWhat nextWhat) return true; } -quint32 StreamBase::numPackets() +quint32 StreamBase::numPackets() const { return (quint32) mControl->num_packets(); } @@ -277,7 +280,7 @@ bool StreamBase::setNumPackets(quint32 numPackets) return true; } -quint32 StreamBase::numBursts() +quint32 StreamBase::numBursts() const { return (quint32) mControl->num_bursts(); } @@ -288,7 +291,7 @@ bool StreamBase::setNumBursts(quint32 numBursts) return true; } -quint32 StreamBase::burstSize() +quint32 StreamBase::burstSize() const { return (quint32) mControl->packets_per_burst(); } @@ -299,7 +302,7 @@ bool StreamBase::setBurstSize(quint32 packetsPerBurst) return true; } -quint32 StreamBase::packetRate() +quint32 StreamBase::packetRate() const { return (quint32) mControl->packets_per_sec(); } @@ -310,7 +313,7 @@ bool StreamBase::setPacketRate(quint32 packetsPerSec) return true; } -quint32 StreamBase::burstRate() +quint32 StreamBase::burstRate() const { return (quint32) mControl->bursts_per_sec(); } @@ -320,3 +323,57 @@ bool StreamBase::setBurstRate(quint32 burstsPerSec) mControl->set_bursts_per_sec(burstsPerSec); return true; } + +bool StreamBase::isFrameVariable() const +{ + ProtocolListIterator *iter; + + iter = createProtocolListIterator(); + while (iter->hasNext()) + { + AbstractProtocol *proto; + + proto = iter->next(); + if (proto->isProtocolFrameValueVariable()) + goto _exit; + } + delete iter; + return false; + +_exit: + delete iter; + return true; +} + +int StreamBase::frameValue(uchar *buf, int bufMaxSize, int n) const +{ + int pktLen, len = 0; + + pktLen = frameLen(n); + + // pktLen is adjusted for CRC/FCS which will be added by the NIC + pktLen -= 4; + + if ((pktLen < 0) || (pktLen > bufMaxSize)) + return 0; + + ProtocolListIterator *iter; + + iter = createProtocolListIterator(); + while (iter->hasNext()) + { + AbstractProtocol *proto; + QByteArray ba; + + proto = iter->next(); + ba = proto->protocolFrameValue(n); + + if (len + ba.size() < bufMaxSize) + memcpy(buf+len, ba.constData(), ba.size()); + len += ba.size(); + } + delete iter; + + return pktLen; +} + diff --git a/common/streambase.h b/common/streambase.h index 878b2d7..45f0cbb 100644 --- a/common/streambase.h +++ b/common/streambase.h @@ -26,7 +26,7 @@ public: void protoDataCopyFrom(const OstProto::Stream &stream); void protoDataCopyInto(OstProto::Stream &stream) const; - ProtocolListIterator* createProtocolListIterator(); + ProtocolListIterator* createProtocolListIterator() const; //! \todo (LOW) should we have a copy constructor?? @@ -76,41 +76,44 @@ public: bool setName(QString name) ; // Frame Length (includes FCS); - FrameLengthMode lenMode(); + FrameLengthMode lenMode() const; bool setLenMode(FrameLengthMode lenMode); - quint16 frameLen(int streamIndex = 0); + quint16 frameLen(int streamIndex = 0) const; bool setFrameLen(quint16 frameLen); - quint16 frameLenMin(); + quint16 frameLenMin() const; bool setFrameLenMin(quint16 frameLenMin); - quint16 frameLenMax(); + quint16 frameLenMax() const; bool setFrameLenMax(quint16 frameLenMax); - SendUnit sendUnit(); + SendUnit sendUnit() const; bool setSendUnit(SendUnit sendUnit); - SendMode sendMode(); + SendMode sendMode() const; bool setSendMode(SendMode sendMode); - NextWhat nextWhat(); + NextWhat nextWhat() const; bool setNextWhat(NextWhat nextWhat); - quint32 numPackets(); + quint32 numPackets() const; bool setNumPackets(quint32 numPackets); - quint32 numBursts(); + quint32 numBursts() const; bool setNumBursts(quint32 numBursts); - quint32 burstSize(); + quint32 burstSize() const; bool setBurstSize(quint32 packetsPerBurst); - quint32 packetRate(); + quint32 packetRate() const; bool setPacketRate(quint32 packetsPerSec); - quint32 burstRate(); + quint32 burstRate() const; bool setBurstRate(quint32 burstsPerSec); + + bool isFrameVariable() const; + int frameValue(uchar *buf, int bufMaxSize, int n) const; }; #endif diff --git a/common/tcp.cpp b/common/tcp.cpp index be16120..6bbc271 100644 --- a/common/tcp.cpp +++ b/common/tcp.cpp @@ -380,6 +380,13 @@ bool TcpProtocol::setFieldData(int index, const QVariant &value, return false; } +bool TcpProtocol::isProtocolFrameValueVariable() const +{ + if (data.is_override_cksum()) + return false; + else + return isProtocolFramePayloadValueVariable(); +} QWidget* TcpProtocol::configWidget() { diff --git a/common/tcp.h b/common/tcp.h index cfd43a6..72cfbf8 100644 --- a/common/tcp.h +++ b/common/tcp.h @@ -67,6 +67,8 @@ public: virtual bool setFieldData(int index, const QVariant &value, FieldAttrib attrib = FieldValue); + virtual bool isProtocolFrameValueVariable() const; + virtual QWidget* configWidget(); virtual void loadConfigWidget(); virtual void storeConfigWidget(); diff --git a/common/udp.cpp b/common/udp.cpp index 0d5b772..9cb74ec 100644 --- a/common/udp.cpp +++ b/common/udp.cpp @@ -258,6 +258,13 @@ bool UdpProtocol::setFieldData(int index, const QVariant &value, return false; } +bool UdpProtocol::isProtocolFrameValueVariable() const +{ + if (data.is_override_totlen() && data.is_override_cksum()) + return false; + else + return isProtocolFramePayloadValueVariable(); +} QWidget* UdpProtocol::configWidget() { diff --git a/common/udp.h b/common/udp.h index 278809a..663456b 100644 --- a/common/udp.h +++ b/common/udp.h @@ -54,6 +54,8 @@ public: virtual bool setFieldData(int index, const QVariant &value, FieldAttrib attrib = FieldValue); + virtual bool isProtocolFrameValueVariable() const; + virtual QWidget* configWidget(); virtual void loadConfigWidget(); virtual void storeConfigWidget(); diff --git a/server/myservice.cpp b/server/myservice.cpp index 54b0895..93afc8b 100644 --- a/server/myservice.cpp +++ b/server/myservice.cpp @@ -25,39 +25,6 @@ StreamInfo::~StreamInfo() { } -int StreamInfo::makePacket(uchar *buf, int bufMaxSize, int n) -{ - int pktLen, len = 0; - - pktLen = frameLen(n); - - // pktLen is adjusted for CRC/FCS which will be added by the NIC - pktLen -= 4; - - if ((pktLen < 0) || (pktLen > bufMaxSize)) - return 0; - - ProtocolListIterator *iter; - - iter = createProtocolListIterator(); - while (iter->hasNext()) - { - AbstractProtocol *proto; - QByteArray ba; - - proto = iter->next(); - ba = proto->protocolFrameValue(n); - - if (len + ba.size() < bufMaxSize) - memcpy(buf+len, ba.constData(), ba.size()); - len += ba.size(); - } - delete iter; - - return pktLen; -} - - // // ------------------ PortInfo -------------------- // @@ -195,6 +162,8 @@ void PortInfo::updateLinkState() void PortInfo::update() { + int len; + bool isVariable; uchar pktBuf[2000]; pcap_pkthdr pktHdr; ost_pcap_send_queue sendQ; @@ -249,17 +218,25 @@ void PortInfo::update() numBursts, numPackets); qDebug("ibg = %ld, ipg = %ld\n", ibg, ipg); + if (streamList[i]->isFrameVariable()) + { + isVariable = true; + } + else + { + isVariable = false; + len = streamList[i]->frameValue(pktBuf, sizeof(pktBuf), 0); + } + for (int j = 0; j < numBursts; j++) { for (int k = 0; k < numPackets; k++) { - int len; - - /*! \todo (HIGH) if pkt contents do not change across - pkts then don't call makePacket(), rather reuse the - previous */ - len = streamList[i]->makePacket(pktBuf, sizeof(pktBuf), + if (isVariable) + { + len = streamList[i]->frameValue(pktBuf, sizeof(pktBuf), j * numPackets + k); + } if (len > 0) { pktHdr.caplen = pktHdr.len = len; @@ -784,7 +761,6 @@ void PortInfo::PortCapture::run() { if (!capFile.open()) qFatal("Unable to open temp cap file"); - return; } qDebug("cap file = %s", capFile.fileName().toAscii().constData()); diff --git a/server/myservice.h b/server/myservice.h index ebd1db1..bafe9b9 100644 --- a/server/myservice.h +++ b/server/myservice.h @@ -46,9 +46,6 @@ class StreamInfo : public StreamBase public: StreamInfo(); ~StreamInfo(); - -private: - int makePacket(uchar *buf, int bufMaxSize, int n); };