Fix STP PCAP/PDML import

As originally written it worked only with Eth encap
This commit is contained in:
Srivats P 2020-04-07 21:08:21 +05:30
parent 63e648bbfe
commit c25256bfb5
2 changed files with 20 additions and 4 deletions

View File

@ -23,8 +23,8 @@ This module is developed by PLVision <developers@plvision.eu>
#include "stp.pb.h"
#define ROOT_IDENTIFIER_POS 22
#define BRIDGE_IDENTIFIER_POS 34
#define ROOT_IDENTIFIER_POS 5
#define BRIDGE_IDENTIFIER_POS 17
#define BASE_DEC 10
#define BASE_HEX 16
@ -55,6 +55,14 @@ PdmlProtocol* PdmlStpProtocol::createInstance()
return new PdmlStpProtocol();
}
void PdmlStpProtocol::preProtocolHandler(QString /*name*/,
const QXmlStreamAttributes& attributes,
int /*expectedPos*/, OstProto::Protocol* /*pbProto*/,
OstProto::Stream* /*stream*/)
{
_protoStartPos = attributes.value("pos").toUInt();
}
void PdmlStpProtocol::unknownFieldHandler(
QString name, int pos, int /*size*/,
const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto,
@ -63,12 +71,12 @@ void PdmlStpProtocol::unknownFieldHandler(
bool isOk;
OstProto::Stp *stp = pbProto->MutableExtension(OstProto::stp);
if ((name == "") && (pos == ROOT_IDENTIFIER_POS))
if ((name == "") && (relativePos(pos) == ROOT_IDENTIFIER_POS))
{
stp->set_root_id(attributes.value("value").toString().
toULongLong(&isOk, BASE_HEX));
}
if ((name == "") && (pos == BRIDGE_IDENTIFIER_POS))
if ((name == "") && (relativePos(pos) == BRIDGE_IDENTIFIER_POS))
{
stp->set_bridge_id(attributes.value("value").toString().
toULongLong(&isOk, BASE_HEX));

View File

@ -31,12 +31,20 @@ public:
static PdmlProtocol *createInstance();
void preProtocolHandler(QString name,
const QXmlStreamAttributes& attributes,
int expectedPos, OstProto::Protocol* pbProto,
OstProto::Stream* stream);
void unknownFieldHandler(QString name, int pos, int size,
const QXmlStreamAttributes &attributes,
OstProto::Protocol *pbProto, OstProto::Stream* stream);
protected:
PdmlStpProtocol();
private:
int relativePos(int pos) { return pos - _protoStartPos; }
int _protoStartPos{0};
};
#endif