NOX - Extracted each xxxPdmlProtocol from pdmlprotocols.h/.cpp into its own .h/.cpp. It is now more evident that while implementing a new protocol, one has to implement the xxxConfigFrom and xxxPdmlProtocol as well.
This commit is contained in:
parent
6193db495d
commit
40837fae40
41
common/arppdml.cpp
Normal file
41
common/arppdml.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "arppdml.h"
|
||||
|
||||
#include "arp.pb.h"
|
||||
|
||||
PdmlArpProtocol::PdmlArpProtocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kArpFieldNumber;
|
||||
|
||||
fieldMap_.insert("arp.opcode", OstProto::Arp::kOpCodeFieldNumber);
|
||||
fieldMap_.insert("arp.src.hw_mac", OstProto::Arp::kSenderHwAddrFieldNumber);
|
||||
fieldMap_.insert("arp.src.proto_ipv4",
|
||||
OstProto::Arp::kSenderProtoAddrFieldNumber);
|
||||
fieldMap_.insert("arp.dst.hw_mac", OstProto::Arp::kTargetHwAddrFieldNumber);
|
||||
fieldMap_.insert("arp.dst.proto_ipv4",
|
||||
OstProto::Arp::kTargetProtoAddrFieldNumber);
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlArpProtocol::createInstance()
|
||||
{
|
||||
return new PdmlArpProtocol();
|
||||
}
|
||||
|
34
common/arppdml.h
Normal file
34
common/arppdml.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _ARP_PDML_H
|
||||
#define _ARP_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlArpProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
protected:
|
||||
PdmlArpProtocol();
|
||||
};
|
||||
|
||||
#endif
|
124
common/eth2pdml.cpp
Normal file
124
common/eth2pdml.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "eth2pdml.h"
|
||||
|
||||
#include "dot3.pb.h"
|
||||
#include "eth2.pb.h"
|
||||
#include "mac.pb.h"
|
||||
#include "vlan.pb.h"
|
||||
|
||||
PdmlEthProtocol::PdmlEthProtocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kMacFieldNumber;
|
||||
|
||||
fieldMap_.insert("eth.dst", OstProto::Mac::kDstMacFieldNumber);
|
||||
fieldMap_.insert("eth.src", OstProto::Mac::kSrcMacFieldNumber);
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlEthProtocol::createInstance()
|
||||
{
|
||||
return new PdmlEthProtocol();
|
||||
}
|
||||
|
||||
void PdmlEthProtocol::unknownFieldHandler(QString name, int /*pos*/,
|
||||
int /*size*/, const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol* /*pbProto*/, OstProto::Stream *stream)
|
||||
{
|
||||
if (name == "eth.vlan.tpid")
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
uint tpid = attributes.value("value").toString()
|
||||
.toUInt(&isOk, kBaseHex);
|
||||
|
||||
OstProto::Protocol *proto = stream->add_protocol();
|
||||
|
||||
proto->mutable_protocol_id()->set_id(
|
||||
OstProto::Protocol::kVlanFieldNumber);
|
||||
|
||||
OstProto::Vlan *vlan = proto->MutableExtension(OstProto::vlan);
|
||||
|
||||
vlan->set_tpid(tpid);
|
||||
vlan->set_is_override_tpid(true);
|
||||
}
|
||||
else if (name == "eth.vlan.id")
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
uint tag = attributes.value("unmaskedvalue").isEmpty() ?
|
||||
attributes.value("value").toString().toUInt(&isOk, kBaseHex) :
|
||||
attributes.value("unmaskedvalue").toString().toUInt(&isOk,kBaseHex);
|
||||
|
||||
OstProto::Vlan *vlan = stream->mutable_protocol(
|
||||
stream->protocol_size()-1)->MutableExtension(OstProto::vlan);
|
||||
|
||||
vlan->set_vlan_tag(tag);
|
||||
}
|
||||
else if (name == "eth.type")
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
uint type = attributes.value("value").toString()
|
||||
.toUInt(&isOk, kBaseHex);
|
||||
|
||||
OstProto::Protocol *proto = stream->add_protocol();
|
||||
|
||||
proto->mutable_protocol_id()->set_id(
|
||||
OstProto::Protocol::kEth2FieldNumber);
|
||||
|
||||
OstProto::Eth2 *eth2 = proto->MutableExtension(OstProto::eth2);
|
||||
|
||||
eth2->set_type(type);
|
||||
eth2->set_is_override_type(true);
|
||||
}
|
||||
else if (name == "eth.len")
|
||||
{
|
||||
OstProto::Protocol *proto = stream->add_protocol();
|
||||
|
||||
proto->mutable_protocol_id()->set_id(
|
||||
OstProto::Protocol::kDot3FieldNumber);
|
||||
|
||||
OstProto::Dot3 *dot3 = proto->MutableExtension(OstProto::dot3);
|
||||
|
||||
bool isOk;
|
||||
dot3->set_length(attributes.value("value").toString().toUInt(&isOk, kBaseHex));
|
||||
dot3->set_is_override_length(true);
|
||||
}
|
||||
#if 0
|
||||
else if (name == "eth.trailer")
|
||||
{
|
||||
QByteArray trailer = QByteArray::fromHex(
|
||||
attributes.value("value").toString().toUtf8());
|
||||
|
||||
stream->mutable_core()->mutable_name()->append(trailer.constData(),
|
||||
trailer.size());
|
||||
}
|
||||
else if ((name == "eth.fcs") ||
|
||||
attributes.value("show").toString().startsWith("Frame check sequence"))
|
||||
{
|
||||
QByteArray trailer = QByteArray::fromHex(
|
||||
attributes.value("value").toString().toUtf8());
|
||||
|
||||
stream->mutable_core()->mutable_name()->append(trailer.constData(),
|
||||
trailer.size());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
38
common/eth2pdml.h
Normal file
38
common/eth2pdml.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _ETH2_PDML_H
|
||||
#define _ETH2_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlEthProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
|
||||
protected:
|
||||
PdmlEthProtocol();
|
||||
};
|
||||
|
||||
#endif
|
100
common/icmp6pdml.cpp
Normal file
100
common/icmp6pdml.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "icmp6pdml.h"
|
||||
|
||||
#include "icmp.pb.h"
|
||||
#include "sample.pb.h"
|
||||
|
||||
PdmlIcmp6Protocol::PdmlIcmp6Protocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kSampleFieldNumber;
|
||||
|
||||
proto_ = NULL;
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlIcmp6Protocol::createInstance()
|
||||
{
|
||||
return new PdmlIcmp6Protocol();
|
||||
}
|
||||
|
||||
void PdmlIcmp6Protocol::preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
int expectedPos, OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream)
|
||||
{
|
||||
proto_ = NULL;
|
||||
ostProtoId_ = OstProto::Protocol::kSampleFieldNumber;
|
||||
icmp_.preProtocolHandler(name, attributes, expectedPos, pbProto, stream);
|
||||
mld_.preProtocolHandler(name, attributes, expectedPos, pbProto, stream);
|
||||
}
|
||||
|
||||
void PdmlIcmp6Protocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream)
|
||||
{
|
||||
if (proto_)
|
||||
proto_->postProtocolHandler(pbProto, stream);
|
||||
else
|
||||
stream->mutable_protocol()->RemoveLast();
|
||||
|
||||
proto_ = NULL;
|
||||
ostProtoId_ = OstProto::Protocol::kSampleFieldNumber;
|
||||
}
|
||||
|
||||
void PdmlIcmp6Protocol::unknownFieldHandler(QString name,
|
||||
int pos, int size, const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
||||
{
|
||||
if (proto_)
|
||||
{
|
||||
proto_->unknownFieldHandler(name, pos, size, attributes, pbProto,
|
||||
stream);
|
||||
}
|
||||
else if (name == "icmpv6.type")
|
||||
{
|
||||
bool isOk;
|
||||
uint type = attributes.value("value").toString().toUInt(
|
||||
&isOk, kBaseHex);
|
||||
|
||||
if (((type >= 130) && (type <= 132)) || (type == 143))
|
||||
{
|
||||
// MLD
|
||||
proto_ = &mld_;
|
||||
fieldMap_ = mld_.fieldMap_;
|
||||
ostProtoId_ = OstProto::Protocol::kMldFieldNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
// ICMP
|
||||
proto_ = &icmp_;
|
||||
fieldMap_ = icmp_.fieldMap_;
|
||||
ostProtoId_ = OstProto::Protocol::kIcmpFieldNumber;
|
||||
}
|
||||
|
||||
pbProto->mutable_protocol_id()->set_id(ostProtoId_);
|
||||
pbProto->MutableExtension(OstProto::sample)->Clear();
|
||||
|
||||
fieldHandler(name, attributes, pbProto, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug("unexpected field %s", name.toAscii().constData());
|
||||
}
|
||||
}
|
||||
|
50
common/icmp6pdml.h
Normal file
50
common/icmp6pdml.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _ICMP6_PDML_H
|
||||
#define _ICMP6_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
#include "icmppdml.h"
|
||||
#include "mldpdml.h"
|
||||
|
||||
class PdmlIcmp6Protocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlIcmp6Protocol();
|
||||
private:
|
||||
PdmlIcmpProtocol icmp_;
|
||||
PdmlMldProtocol mld_;
|
||||
PdmlProtocol *proto_;
|
||||
};
|
||||
|
||||
#endif
|
93
common/icmppdml.cpp
Normal file
93
common/icmppdml.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "icmppdml.h"
|
||||
|
||||
#include "icmp.pb.h"
|
||||
|
||||
PdmlIcmpProtocol::PdmlIcmpProtocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kIcmpFieldNumber;
|
||||
|
||||
fieldMap_.insert("icmp.type", OstProto::Icmp::kTypeFieldNumber);
|
||||
fieldMap_.insert("icmp.code", OstProto::Icmp::kCodeFieldNumber);
|
||||
fieldMap_.insert("icmp.checksum", OstProto::Icmp::kChecksumFieldNumber);
|
||||
fieldMap_.insert("icmp.ident", OstProto::Icmp::kIdentifierFieldNumber);
|
||||
fieldMap_.insert("icmp.seq", OstProto::Icmp::kSequenceFieldNumber);
|
||||
|
||||
fieldMap_.insert("icmpv6.type", OstProto::Icmp::kTypeFieldNumber);
|
||||
fieldMap_.insert("icmpv6.code", OstProto::Icmp::kCodeFieldNumber);
|
||||
fieldMap_.insert("icmpv6.checksum", OstProto::Icmp::kChecksumFieldNumber);
|
||||
fieldMap_.insert("icmpv6.echo.identifier",
|
||||
OstProto::Icmp::kIdentifierFieldNumber);
|
||||
fieldMap_.insert("icmpv6.echo.sequence_number",
|
||||
OstProto::Icmp::kSequenceFieldNumber);
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlIcmpProtocol::createInstance()
|
||||
{
|
||||
return new PdmlIcmpProtocol();
|
||||
}
|
||||
|
||||
void PdmlIcmpProtocol::preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes& /*attributes*/, int /*expectedPos*/,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream* /*stream*/)
|
||||
{
|
||||
OstProto::Icmp *icmp = pbProto->MutableExtension(OstProto::icmp);
|
||||
|
||||
if (name == "icmp")
|
||||
icmp->set_icmp_version(OstProto::Icmp::kIcmp4);
|
||||
else if (name == "icmpv6")
|
||||
icmp->set_icmp_version(OstProto::Icmp::kIcmp6);
|
||||
|
||||
icmp->set_is_override_checksum(true);
|
||||
|
||||
icmp->set_type(kIcmpInvalidType);
|
||||
}
|
||||
|
||||
void PdmlIcmpProtocol::unknownFieldHandler(QString /*name*/, int /*pos*/,
|
||||
int /*size*/, const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream* /*stream*/)
|
||||
{
|
||||
bool isOk;
|
||||
OstProto::Icmp *icmp = pbProto->MutableExtension(OstProto::icmp);
|
||||
|
||||
if ((icmp->icmp_version() == OstProto::Icmp::kIcmp6)
|
||||
&& (icmp->type() >= kIcmp6EchoRequest)
|
||||
&& (icmp->type() <= kIcmp6EchoReply))
|
||||
{
|
||||
QString addrHexStr = attributes.value("value").toString();
|
||||
|
||||
// Wireshark 1.4.x does not have these as filterable fields
|
||||
if (attributes.value("show").toString().startsWith("ID"))
|
||||
icmp->set_identifier(addrHexStr.toUInt(&isOk, kBaseHex));
|
||||
else if (attributes.value("show").toString().startsWith("Sequence"))
|
||||
icmp->set_sequence(addrHexStr.toUInt(&isOk, kBaseHex));
|
||||
}
|
||||
}
|
||||
|
||||
void PdmlIcmpProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream)
|
||||
{
|
||||
OstProto::Icmp *icmp = pbProto->MutableExtension(OstProto::icmp);
|
||||
|
||||
if (icmp->type() == kIcmpInvalidType)
|
||||
stream->mutable_protocol()->RemoveLast();
|
||||
}
|
||||
|
48
common/icmppdml.h
Normal file
48
common/icmppdml.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _ICMP_PDML_H
|
||||
#define _ICMP_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlIcmpProtocol : public PdmlProtocol
|
||||
{
|
||||
friend class PdmlIcmp6Protocol;
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlIcmpProtocol();
|
||||
private:
|
||||
static const uint kIcmpInvalidType = 0xFFFFFFFF;
|
||||
|
||||
static const uint kIcmp6EchoRequest = 128;
|
||||
static const uint kIcmp6EchoReply = 129;
|
||||
};
|
||||
|
||||
#endif
|
141
common/igmppdml.cpp
Normal file
141
common/igmppdml.cpp
Normal file
@ -0,0 +1,141 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "igmppdml.h"
|
||||
|
||||
#include "igmp.pb.h"
|
||||
|
||||
PdmlIgmpProtocol::PdmlIgmpProtocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kIgmpFieldNumber;
|
||||
|
||||
fieldMap_.insert("igmp.max_resp",
|
||||
OstProto::Gmp::kMaxResponseTimeFieldNumber); // FIXME
|
||||
fieldMap_.insert("igmp.checksum", OstProto::Gmp::kChecksumFieldNumber);
|
||||
|
||||
fieldMap_.insert("igmp.s", OstProto::Gmp::kSFlagFieldNumber);
|
||||
fieldMap_.insert("igmp.qrv", OstProto::Gmp::kQrvFieldNumber);
|
||||
fieldMap_.insert("igmp.qqic", OstProto::Gmp::kQqiFieldNumber); // FIXME
|
||||
|
||||
fieldMap_.insert("igmp.num_grp_recs",
|
||||
OstProto::Gmp::kGroupRecordCountFieldNumber);
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlIgmpProtocol::createInstance()
|
||||
{
|
||||
return new PdmlIgmpProtocol();
|
||||
}
|
||||
|
||||
void PdmlIgmpProtocol::preProtocolHandler(QString /*name*/,
|
||||
const QXmlStreamAttributes& /*attributes*/, int /*expectedPos*/,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream* /*stream*/)
|
||||
{
|
||||
OstProto::Gmp *igmp = pbProto->MutableExtension(OstProto::igmp);
|
||||
|
||||
igmp->set_is_override_rsvd_code(true);
|
||||
igmp->set_is_override_checksum(true);
|
||||
igmp->set_is_override_source_count(true);
|
||||
igmp->set_is_override_group_record_count(true);
|
||||
|
||||
version_ = 0;
|
||||
}
|
||||
|
||||
void PdmlIgmpProtocol::unknownFieldHandler(QString name, int /*pos*/,
|
||||
int /*size*/, const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream* /*stream*/)
|
||||
{
|
||||
bool isOk;
|
||||
OstProto::Gmp *igmp = pbProto->MutableExtension(OstProto::igmp);
|
||||
QString valueHexStr = attributes.value("value").toString();
|
||||
|
||||
if (name == "igmp.version")
|
||||
{
|
||||
version_ = attributes.value("show").toString().toUInt(&isOk);
|
||||
}
|
||||
else if (name == "igmp.type")
|
||||
{
|
||||
uint type = valueHexStr.toUInt(&isOk, kBaseHex);
|
||||
if (type == kIgmpQuery)
|
||||
{
|
||||
switch(version_)
|
||||
{
|
||||
case 1: type = kIgmpV1Query; break;
|
||||
case 2: type = kIgmpV2Query; break;
|
||||
case 3: type = kIgmpV3Query; break;
|
||||
}
|
||||
}
|
||||
igmp->set_type(type);
|
||||
}
|
||||
else if (name == "igmp.record_type")
|
||||
{
|
||||
OstProto::Gmp::GroupRecord *rec = igmp->add_group_records();
|
||||
rec->set_type(OstProto::Gmp::GroupRecord::RecordType(
|
||||
valueHexStr.toUInt(&isOk, kBaseHex)));
|
||||
rec->set_is_override_source_count(true);
|
||||
rec->set_is_override_aux_data_length(true);
|
||||
}
|
||||
else if (name == "igmp.aux_data_len")
|
||||
{
|
||||
igmp->mutable_group_records(igmp->group_records_size() - 1)->
|
||||
set_aux_data_length(valueHexStr.toUInt(&isOk, kBaseHex));
|
||||
}
|
||||
else if (name == "igmp.num_src")
|
||||
{
|
||||
if (igmp->group_record_count())
|
||||
igmp->mutable_group_records(igmp->group_records_size() - 1)->
|
||||
set_source_count(valueHexStr.toUInt(&isOk, kBaseHex));
|
||||
else
|
||||
igmp->set_source_count(valueHexStr.toUInt(&isOk, kBaseHex));
|
||||
}
|
||||
else if (name == "igmp.maddr")
|
||||
{
|
||||
if (igmp->group_record_count())
|
||||
igmp->mutable_group_records(igmp->group_records_size() - 1)->
|
||||
mutable_group_address()->set_v4(
|
||||
valueHexStr.toUInt(&isOk, kBaseHex));
|
||||
else
|
||||
igmp->mutable_group_address()->set_v4(
|
||||
valueHexStr.toUInt(&isOk, kBaseHex));
|
||||
}
|
||||
else if (name == "igmp.saddr")
|
||||
{
|
||||
if (igmp->group_record_count())
|
||||
igmp->mutable_group_records(igmp->group_records_size() - 1)->
|
||||
add_sources()->set_v4(valueHexStr.toUInt(&isOk, kBaseHex));
|
||||
else
|
||||
igmp->add_sources()->set_v4(valueHexStr.toUInt(&isOk, kBaseHex));
|
||||
}
|
||||
else if (name == "igmp.aux_data")
|
||||
{
|
||||
QByteArray ba = QByteArray::fromHex(
|
||||
attributes.value("value").toString().toUtf8());
|
||||
igmp->mutable_group_records(igmp->group_records_size() - 1)->
|
||||
set_aux_data(ba.constData(), ba.size());
|
||||
}
|
||||
}
|
||||
|
||||
void PdmlIgmpProtocol::postProtocolHandler(OstProto::Protocol* /*pbProto*/,
|
||||
OstProto::Stream *stream)
|
||||
{
|
||||
// version is 0 for IGMP like protocols such as RGMP which we don't
|
||||
// support currently
|
||||
if (version_ == 0)
|
||||
stream->mutable_protocol()->RemoveLast();
|
||||
}
|
||||
|
49
common/igmppdml.h
Normal file
49
common/igmppdml.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _IGMP_PDML_H
|
||||
#define _IGMP_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlIgmpProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlIgmpProtocol();
|
||||
private:
|
||||
static const uint kIgmpQuery = 0x11;
|
||||
static const uint kIgmpV1Query = 0x11;
|
||||
static const uint kIgmpV2Query = 0xFF11;
|
||||
static const uint kIgmpV3Query = 0xFE11;
|
||||
|
||||
uint version_;
|
||||
};
|
||||
|
||||
#endif
|
93
common/ip4pdml.cpp
Normal file
93
common/ip4pdml.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "ip4pdml.h"
|
||||
|
||||
#include "hexdump.pb.h"
|
||||
#include "ip4.pb.h"
|
||||
|
||||
PdmlIp4Protocol::PdmlIp4Protocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kIp4FieldNumber;
|
||||
|
||||
fieldMap_.insert("ip.version", OstProto::Ip4::kVerHdrlenFieldNumber);
|
||||
fieldMap_.insert("ip.dsfield", OstProto::Ip4::kTosFieldNumber);
|
||||
fieldMap_.insert("ip.len", OstProto::Ip4::kTotlenFieldNumber);
|
||||
fieldMap_.insert("ip.id", OstProto::Ip4::kIdFieldNumber);
|
||||
//fieldMap_.insert("ip.flags", OstProto::Ip4::kFlagsFieldNumber);
|
||||
fieldMap_.insert("ip.frag_offset", OstProto::Ip4::kFragOfsFieldNumber);
|
||||
fieldMap_.insert("ip.ttl", OstProto::Ip4::kTtlFieldNumber);
|
||||
fieldMap_.insert("ip.proto", OstProto::Ip4::kProtoFieldNumber);
|
||||
fieldMap_.insert("ip.checksum", OstProto::Ip4::kCksumFieldNumber);
|
||||
fieldMap_.insert("ip.src", OstProto::Ip4::kSrcIpFieldNumber);
|
||||
fieldMap_.insert("ip.dst", OstProto::Ip4::kDstIpFieldNumber);
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlIp4Protocol::createInstance()
|
||||
{
|
||||
return new PdmlIp4Protocol();
|
||||
}
|
||||
|
||||
void PdmlIp4Protocol::unknownFieldHandler(QString name, int /*pos*/,
|
||||
int /*size*/, const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream* /*stream*/)
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
if ((name == "ip.options") ||
|
||||
attributes.value("show").toString().startsWith("Options"))
|
||||
{
|
||||
options_ = QByteArray::fromHex(
|
||||
attributes.value("value").toString().toUtf8());
|
||||
}
|
||||
else if (name == "ip.flags")
|
||||
{
|
||||
OstProto::Ip4 *ip4 = pbProto->MutableExtension(OstProto::ip4);
|
||||
|
||||
ip4->set_flags(attributes.value("value").toString().toUInt(&isOk, kBaseHex) >> 5);
|
||||
}
|
||||
}
|
||||
|
||||
void PdmlIp4Protocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream)
|
||||
{
|
||||
OstProto::Ip4 *ip4 = pbProto->MutableExtension(OstProto::ip4);
|
||||
|
||||
ip4->set_is_override_ver(true);
|
||||
ip4->set_is_override_hdrlen(true);
|
||||
ip4->set_is_override_totlen(true);
|
||||
ip4->set_is_override_proto(true);
|
||||
ip4->set_is_override_cksum(true);
|
||||
|
||||
if (options_.size())
|
||||
{
|
||||
OstProto::Protocol *proto = stream->add_protocol();
|
||||
|
||||
proto->mutable_protocol_id()->set_id(
|
||||
OstProto::Protocol::kHexDumpFieldNumber);
|
||||
|
||||
OstProto::HexDump *hexDump = proto->MutableExtension(OstProto::hexDump);
|
||||
|
||||
hexDump->mutable_content()->append(options_.constData(),
|
||||
options_.size());
|
||||
hexDump->set_pad_until_end(false);
|
||||
options_.resize(0);
|
||||
}
|
||||
}
|
||||
|
41
common/ip4pdml.h
Normal file
41
common/ip4pdml.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _IP4_PDML_H
|
||||
#define _IP4_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlIp4Protocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlIp4Protocol();
|
||||
private:
|
||||
QByteArray options_;
|
||||
};
|
||||
|
||||
#endif
|
76
common/ip6pdml.cpp
Normal file
76
common/ip6pdml.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "ip6pdml.h"
|
||||
|
||||
#include "ip6.pb.h"
|
||||
|
||||
PdmlIp6Protocol::PdmlIp6Protocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kIp6FieldNumber;
|
||||
|
||||
fieldMap_.insert("ipv6.version", OstProto::Ip6::kVersionFieldNumber);
|
||||
fieldMap_.insert("ipv6.class", OstProto::Ip6::kTrafficClassFieldNumber);
|
||||
fieldMap_.insert("ipv6.flow", OstProto::Ip6::kFlowLabelFieldNumber);
|
||||
fieldMap_.insert("ipv6.plen", OstProto::Ip6::kPayloadLengthFieldNumber);
|
||||
fieldMap_.insert("ipv6.nxt", OstProto::Ip6::kNextHeaderFieldNumber);
|
||||
fieldMap_.insert("ipv6.hlim", OstProto::Ip6::kHopLimitFieldNumber);
|
||||
|
||||
// ipv6.src and ipv6.dst handled as unknown fields
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlIp6Protocol::createInstance()
|
||||
{
|
||||
return new PdmlIp6Protocol();
|
||||
}
|
||||
|
||||
void PdmlIp6Protocol::unknownFieldHandler(QString name, int /*pos*/,
|
||||
int /*size*/, const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream* /*stream*/)
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
if (name == "ipv6.src")
|
||||
{
|
||||
OstProto::Ip6 *ip6 = pbProto->MutableExtension(OstProto::ip6);
|
||||
QString addrHexStr = attributes.value("value").toString();
|
||||
|
||||
ip6->set_src_addr_hi(addrHexStr.left(16).toULongLong(&isOk, kBaseHex));
|
||||
ip6->set_src_addr_lo(addrHexStr.right(16).toULongLong(&isOk, kBaseHex));
|
||||
}
|
||||
else if (name == "ipv6.dst")
|
||||
{
|
||||
OstProto::Ip6 *ip6 = pbProto->MutableExtension(OstProto::ip6);
|
||||
QString addrHexStr = attributes.value("value").toString();
|
||||
|
||||
ip6->set_dst_addr_hi(addrHexStr.left(16).toULongLong(&isOk, kBaseHex));
|
||||
ip6->set_dst_addr_lo(addrHexStr.right(16).toULongLong(&isOk, kBaseHex));
|
||||
}
|
||||
}
|
||||
|
||||
void PdmlIp6Protocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream* /*stream*/)
|
||||
{
|
||||
OstProto::Ip6 *ip6 = pbProto->MutableExtension(OstProto::ip6);
|
||||
|
||||
ip6->set_is_override_version(true);
|
||||
ip6->set_is_override_payload_length(true);
|
||||
ip6->set_is_override_next_header(true);
|
||||
}
|
||||
|
39
common/ip6pdml.h
Normal file
39
common/ip6pdml.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _IP6_PDML_H
|
||||
#define _IP6_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlIp6Protocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlIp6Protocol();
|
||||
};
|
||||
|
||||
#endif
|
80
common/llcpdml.cpp
Normal file
80
common/llcpdml.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "llcpdml.h"
|
||||
|
||||
#include "llc.pb.h"
|
||||
#include "snap.pb.h"
|
||||
|
||||
#include <QRegExp>
|
||||
|
||||
PdmlLlcProtocol::PdmlLlcProtocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kLlcFieldNumber;
|
||||
|
||||
fieldMap_.insert("llc.dsap", OstProto::Llc::kDsapFieldNumber);
|
||||
fieldMap_.insert("llc.ssap", OstProto::Llc::kSsapFieldNumber);
|
||||
fieldMap_.insert("llc.control", OstProto::Llc::kCtlFieldNumber);
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlLlcProtocol::createInstance()
|
||||
{
|
||||
return new PdmlLlcProtocol();
|
||||
}
|
||||
|
||||
void PdmlLlcProtocol::unknownFieldHandler(QString name, int /*pos*/,
|
||||
int /*size*/, const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol* /*pbProto*/, OstProto::Stream *stream)
|
||||
{
|
||||
if (name == "llc.oui")
|
||||
{
|
||||
OstProto::Protocol *proto = stream->add_protocol();
|
||||
|
||||
proto->mutable_protocol_id()->set_id(
|
||||
OstProto::Protocol::kSnapFieldNumber);
|
||||
|
||||
OstProto::Snap *snap = proto->MutableExtension(OstProto::snap);
|
||||
|
||||
bool isOk;
|
||||
snap->set_oui(attributes.value("value").toString()
|
||||
.toUInt(&isOk, kBaseHex));
|
||||
snap->set_is_override_oui(true);
|
||||
}
|
||||
else if ((name == "llc.type") || (name.contains(QRegExp("llc\\..*pid"))))
|
||||
{
|
||||
OstProto::Snap *snap = stream->mutable_protocol(
|
||||
stream->protocol_size()-1)->MutableExtension(OstProto::snap);
|
||||
|
||||
bool isOk;
|
||||
snap->set_type(attributes.value("value").toString()
|
||||
.toUInt(&isOk, kBaseHex));
|
||||
snap->set_is_override_type(true);
|
||||
}
|
||||
}
|
||||
|
||||
void PdmlLlcProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream* /*stream*/)
|
||||
{
|
||||
OstProto::Llc *llc = pbProto->MutableExtension(OstProto::llc);
|
||||
|
||||
llc->set_is_override_dsap(true);
|
||||
llc->set_is_override_ssap(true);
|
||||
llc->set_is_override_ctl(true);
|
||||
}
|
||||
|
39
common/llcpdml.h
Normal file
39
common/llcpdml.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _LLC_PDML_H
|
||||
#define _LLC_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlLlcProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlLlcProtocol();
|
||||
};
|
||||
|
||||
#endif
|
133
common/mldpdml.cpp
Normal file
133
common/mldpdml.cpp
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "mldpdml.h"
|
||||
|
||||
#include "mld.pb.h"
|
||||
|
||||
PdmlMldProtocol::PdmlMldProtocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kMldFieldNumber;
|
||||
|
||||
fieldMap_.insert("icmpv6.code", OstProto::Gmp::kRsvdCodeFieldNumber);
|
||||
fieldMap_.insert("icmpv6.checksum", OstProto::Gmp::kChecksumFieldNumber);
|
||||
fieldMap_.insert("icmpv6.mld.maximum_response_delay",
|
||||
OstProto::Gmp::kMaxResponseTimeFieldNumber); // FIXME
|
||||
|
||||
fieldMap_.insert("icmpv6.mld.flag.s", OstProto::Gmp::kSFlagFieldNumber);
|
||||
fieldMap_.insert("icmpv6.mld.flag.qrv", OstProto::Gmp::kQrvFieldNumber);
|
||||
fieldMap_.insert("icmpv6.mld.qqi", OstProto::Gmp::kQqiFieldNumber); // FIXME
|
||||
fieldMap_.insert("icmpv6.mld.nb_sources",
|
||||
OstProto::Gmp::kSourceCountFieldNumber);
|
||||
|
||||
fieldMap_.insert("icmpv6.mldr.nb_mcast_records",
|
||||
OstProto::Gmp::kGroupRecordCountFieldNumber);
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlMldProtocol::createInstance()
|
||||
{
|
||||
return new PdmlMldProtocol();
|
||||
}
|
||||
|
||||
void PdmlMldProtocol::preProtocolHandler(QString /*name*/,
|
||||
const QXmlStreamAttributes &attributes, int /*expectedPos*/,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream* /*stream*/)
|
||||
{
|
||||
bool isOk;
|
||||
OstProto::Gmp *mld = pbProto->MutableExtension(OstProto::mld);
|
||||
|
||||
mld->set_is_override_rsvd_code(true);
|
||||
mld->set_is_override_checksum(true);
|
||||
mld->set_is_override_source_count(true);
|
||||
mld->set_is_override_group_record_count(true);
|
||||
|
||||
protoSize_ = attributes.value("size").toString().toUInt(&isOk);
|
||||
}
|
||||
|
||||
void PdmlMldProtocol::unknownFieldHandler(QString name, int /*pos*/,
|
||||
int /*size*/, const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream* /*stream*/)
|
||||
{
|
||||
bool isOk;
|
||||
OstProto::Gmp *mld = pbProto->MutableExtension(OstProto::mld);
|
||||
QString valueHexStr = attributes.value("value").toString();
|
||||
|
||||
if (name == "icmpv6.type")
|
||||
{
|
||||
uint type = valueHexStr.toUInt(&isOk, kBaseHex);
|
||||
|
||||
if ((type == kMldQuery) && (protoSize_ >= 28))
|
||||
type = kMldV2Query;
|
||||
|
||||
mld->set_type(type);
|
||||
}
|
||||
else if (name == "icmpv6.mld.multicast_address")
|
||||
{
|
||||
mld->mutable_group_address()->set_v6_hi(
|
||||
valueHexStr.left(16).toULongLong(&isOk, kBaseHex));
|
||||
mld->mutable_group_address()->set_v6_lo(
|
||||
valueHexStr.right(16).toULongLong(&isOk, kBaseHex));
|
||||
}
|
||||
else if (name == "icmpv6.mld.source_address")
|
||||
{
|
||||
OstProto::Gmp::IpAddress *ip = mld->add_sources();
|
||||
ip->set_v6_hi(valueHexStr.left(16).toULongLong(&isOk, kBaseHex));
|
||||
ip->set_v6_lo(valueHexStr.right(16).toULongLong(&isOk, kBaseHex));
|
||||
}
|
||||
else if (name == "icmpv6.mldr.mar.record_type")
|
||||
{
|
||||
OstProto::Gmp::GroupRecord *rec = mld->add_group_records();
|
||||
rec->set_type(OstProto::Gmp::GroupRecord::RecordType(
|
||||
valueHexStr.toUInt(&isOk, kBaseHex)));
|
||||
rec->set_is_override_source_count(true);
|
||||
rec->set_is_override_aux_data_length(true);
|
||||
}
|
||||
else if (name == "icmpv6.mldr.mar.aux_data_len")
|
||||
{
|
||||
mld->mutable_group_records(mld->group_records_size() - 1)->
|
||||
set_aux_data_length(valueHexStr.toUInt(&isOk, kBaseHex));
|
||||
}
|
||||
else if (name == "icmpv6.mldr.mar.nb_sources")
|
||||
{
|
||||
mld->mutable_group_records(mld->group_records_size() - 1)->
|
||||
set_source_count(valueHexStr.toUInt(&isOk, kBaseHex));
|
||||
}
|
||||
else if (name == "icmpv6.mldr.mar.multicast_address")
|
||||
{
|
||||
OstProto::Gmp::IpAddress *ip = mld->mutable_group_records(
|
||||
mld->group_records_size() - 1)->mutable_group_address();
|
||||
ip->set_v6_hi(valueHexStr.left(16).toULongLong(&isOk, kBaseHex));
|
||||
ip->set_v6_lo(valueHexStr.right(16).toULongLong(&isOk, kBaseHex));
|
||||
}
|
||||
else if (name == "icmpv6.mldr.mar.source_address")
|
||||
{
|
||||
OstProto::Gmp::IpAddress *ip = mld->mutable_group_records(
|
||||
mld->group_records_size() - 1)->add_sources();
|
||||
ip->set_v6_hi(valueHexStr.left(16).toULongLong(&isOk, kBaseHex));
|
||||
ip->set_v6_lo(valueHexStr.right(16).toULongLong(&isOk, kBaseHex));
|
||||
}
|
||||
else if (name == "icmpv6.mldr.mar.auxiliary_data")
|
||||
{
|
||||
QByteArray ba = QByteArray::fromHex(
|
||||
attributes.value("value").toString().toUtf8());
|
||||
mld->mutable_group_records(mld->group_records_size() - 1)->
|
||||
set_aux_data(ba.constData(), ba.size());
|
||||
}
|
||||
}
|
||||
|
47
common/mldpdml.h
Normal file
47
common/mldpdml.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _MLD_PDML_H
|
||||
#define _MLD_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlMldProtocol : public PdmlProtocol
|
||||
{
|
||||
friend class PdmlIcmp6Protocol;
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlMldProtocol();
|
||||
private:
|
||||
static const uint kMldQuery = 0x82;
|
||||
static const uint kMldV1Query = 0x82;
|
||||
static const uint kMldV2Query = 0xFF82;
|
||||
|
||||
uint protoSize_;
|
||||
};
|
||||
|
||||
#endif
|
@ -107,6 +107,22 @@ SOURCES += \
|
||||
sampleconfig.cpp \
|
||||
userscriptconfig.cpp
|
||||
|
||||
SOURCES += \
|
||||
vlanpdml.cpp \
|
||||
svlanpdml.cpp \
|
||||
eth2pdml.cpp \
|
||||
llcpdml.cpp \
|
||||
arppdml.cpp \
|
||||
ip4pdml.cpp \
|
||||
ip6pdml.cpp \
|
||||
icmppdml.cpp \
|
||||
icmp6pdml.cpp \
|
||||
igmppdml.cpp \
|
||||
mldpdml.cpp \
|
||||
tcppdml.cpp \
|
||||
udppdml.cpp \
|
||||
textprotopdml.cpp
|
||||
|
||||
QMAKE_DISTCLEAN += object_script.*
|
||||
|
||||
include(../protobuf.pri)
|
||||
|
@ -615,7 +615,7 @@ bool PcapFileFormat::saveStreams(const OstProto::StreamConfigList streams,
|
||||
fd_.writeRawData(pktBuf.data(), pktHdr.inclLen);
|
||||
|
||||
if (s.packetRate())
|
||||
pktHdr.tsUsec += 1000000/s.packetRate();
|
||||
pktHdr.tsUsec += quint32(1e6/s.packetRate());
|
||||
if (pktHdr.tsUsec >= 1000000)
|
||||
{
|
||||
pktHdr.tsSec++;
|
||||
|
@ -19,8 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
const int kBaseHex = 16;
|
||||
|
||||
PdmlProtocol::PdmlProtocol()
|
||||
{
|
||||
ostProtoId_ = -1;
|
||||
|
@ -27,6 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include <QString>
|
||||
#include <QXmlStreamAttributes>
|
||||
|
||||
const int kBaseHex = 16;
|
||||
|
||||
class PdmlProtocol
|
||||
{
|
||||
public:
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -68,246 +68,4 @@ protected:
|
||||
PdmlFrameProtocol();
|
||||
};
|
||||
|
||||
class PdmlEthProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
|
||||
protected:
|
||||
PdmlEthProtocol();
|
||||
};
|
||||
|
||||
class PdmlSvlanProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlSvlanProtocol();
|
||||
};
|
||||
|
||||
class PdmlVlanProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlVlanProtocol();
|
||||
};
|
||||
|
||||
class PdmlLlcProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlLlcProtocol();
|
||||
};
|
||||
|
||||
class PdmlArpProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
protected:
|
||||
PdmlArpProtocol();
|
||||
};
|
||||
|
||||
class PdmlIp4Protocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlIp4Protocol();
|
||||
private:
|
||||
QByteArray options_;
|
||||
};
|
||||
|
||||
class PdmlIp6Protocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlIp6Protocol();
|
||||
};
|
||||
|
||||
class PdmlIcmpProtocol : public PdmlProtocol
|
||||
{
|
||||
friend class PdmlIcmp6Protocol;
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlIcmpProtocol();
|
||||
private:
|
||||
static const uint kIcmpInvalidType = 0xFFFFFFFF;
|
||||
|
||||
static const uint kIcmp6EchoRequest = 128;
|
||||
static const uint kIcmp6EchoReply = 129;
|
||||
};
|
||||
|
||||
class PdmlMldProtocol : public PdmlProtocol
|
||||
{
|
||||
friend class PdmlIcmp6Protocol;
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlMldProtocol();
|
||||
private:
|
||||
static const uint kMldQuery = 0x82;
|
||||
static const uint kMldV1Query = 0x82;
|
||||
static const uint kMldV2Query = 0xFF82;
|
||||
|
||||
uint protoSize_;
|
||||
};
|
||||
|
||||
class PdmlIcmp6Protocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlIcmp6Protocol();
|
||||
private:
|
||||
PdmlIcmpProtocol icmp_;
|
||||
PdmlMldProtocol mld_;
|
||||
PdmlProtocol *proto_;
|
||||
};
|
||||
|
||||
class PdmlIgmpProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlIgmpProtocol();
|
||||
private:
|
||||
static const uint kIgmpQuery = 0x11;
|
||||
static const uint kIgmpV1Query = 0x11;
|
||||
static const uint kIgmpV2Query = 0xFF11;
|
||||
static const uint kIgmpV3Query = 0xFE11;
|
||||
|
||||
uint version_;
|
||||
};
|
||||
|
||||
class PdmlTcpProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlTcpProtocol();
|
||||
private:
|
||||
QByteArray options_;
|
||||
QByteArray segmentData_;
|
||||
};
|
||||
|
||||
class PdmlUdpProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlUdpProtocol();
|
||||
};
|
||||
|
||||
class PdmlTextProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlTextProtocol();
|
||||
private:
|
||||
enum ContentType {
|
||||
kUnknownContent,
|
||||
kTextContent,
|
||||
kOtherContent
|
||||
};
|
||||
|
||||
bool detectEol_;
|
||||
ContentType contentType_;
|
||||
int expPos_;
|
||||
int endPos_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -26,6 +26,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "pdmlprotocols.h"
|
||||
|
||||
#include "arppdml.h"
|
||||
#include "eth2pdml.h"
|
||||
#include "llcpdml.h"
|
||||
#include "icmppdml.h"
|
||||
#include "icmp6pdml.h"
|
||||
#include "igmppdml.h"
|
||||
#include "ip4pdml.h"
|
||||
#include "ip6pdml.h"
|
||||
#include "mldpdml.h"
|
||||
#include "svlanpdml.h"
|
||||
#include "tcppdml.h"
|
||||
#include "textprotopdml.h"
|
||||
#include "udppdml.h"
|
||||
#include "vlanpdml.h"
|
||||
|
||||
PdmlReader::PdmlReader(OstProto::StreamConfigList *streams)
|
||||
{
|
||||
//gPdmlReader = this;
|
||||
|
110
common/svlanpdml.cpp
Normal file
110
common/svlanpdml.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "svlanpdml.h"
|
||||
|
||||
#include "eth2.pb.h"
|
||||
#include "svlan.pb.h"
|
||||
|
||||
PdmlSvlanProtocol::PdmlSvlanProtocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kSvlanFieldNumber;
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlSvlanProtocol::createInstance()
|
||||
{
|
||||
return new PdmlSvlanProtocol();
|
||||
}
|
||||
|
||||
void PdmlSvlanProtocol::preProtocolHandler(QString /*name*/,
|
||||
const QXmlStreamAttributes& /*attributes*/, int /*expectedPos*/,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
||||
{
|
||||
OstProto::Vlan *svlan = pbProto->MutableExtension(OstProto::svlan);
|
||||
|
||||
svlan->set_tpid(0x88a8);
|
||||
svlan->set_is_override_tpid(true);
|
||||
|
||||
// If a eth2 protocol precedes svlan, we remove the eth2 protocol
|
||||
// 'coz the eth2.etherType is actually the svlan.tpid
|
||||
//
|
||||
// We assume that the current protocol is the last in the stream
|
||||
int index = stream->protocol_size() - 1;
|
||||
if ((index > 1)
|
||||
&& (stream->protocol(index).protocol_id().id()
|
||||
== OstProto::Protocol::kSvlanFieldNumber)
|
||||
&& (stream->protocol(index - 1).protocol_id().id()
|
||||
== OstProto::Protocol::kEth2FieldNumber))
|
||||
{
|
||||
stream->mutable_protocol()->SwapElements(index, index - 1);
|
||||
Q_ASSERT(stream->protocol(index).protocol_id().id()
|
||||
== OstProto::Protocol::kEth2FieldNumber);
|
||||
stream->mutable_protocol()->RemoveLast();
|
||||
}
|
||||
}
|
||||
|
||||
void PdmlSvlanProtocol::unknownFieldHandler(QString name, int /*pos*/,
|
||||
int /*size*/, const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
||||
{
|
||||
if ((name == "ieee8021ad.id") || (name == "ieee8021ad.svid"))
|
||||
{
|
||||
bool isOk;
|
||||
OstProto::Vlan *svlan = pbProto->MutableExtension(OstProto::svlan);
|
||||
uint tag = attributes.value("unmaskedvalue").isEmpty() ?
|
||||
attributes.value("value").toString().toUInt(&isOk, kBaseHex) :
|
||||
attributes.value("unmaskedvalue").toString().toUInt(&isOk,kBaseHex);
|
||||
|
||||
svlan->set_vlan_tag(tag);
|
||||
}
|
||||
else if (name == "ieee8021ad.cvid")
|
||||
{
|
||||
OstProto::Protocol *proto = stream->add_protocol();
|
||||
|
||||
proto->mutable_protocol_id()->set_id(
|
||||
OstProto::Protocol::kSvlanFieldNumber);
|
||||
|
||||
OstProto::Vlan *svlan = proto->MutableExtension(OstProto::svlan);
|
||||
|
||||
svlan->set_tpid(0x88a8);
|
||||
svlan->set_is_override_tpid(true);
|
||||
|
||||
bool isOk;
|
||||
uint tag = attributes.value("unmaskedvalue").isEmpty() ?
|
||||
attributes.value("value").toString().toUInt(&isOk, kBaseHex) :
|
||||
attributes.value("unmaskedvalue").toString().toUInt(&isOk,kBaseHex);
|
||||
|
||||
svlan->set_vlan_tag(tag);
|
||||
}
|
||||
else if (name == "ieee8021ah.etype") // yes 'ah' not 'ad' - not a typo!
|
||||
{
|
||||
OstProto::Protocol *proto = stream->add_protocol();
|
||||
|
||||
proto->mutable_protocol_id()->set_id(
|
||||
OstProto::Protocol::kEth2FieldNumber);
|
||||
|
||||
bool isOk;
|
||||
OstProto::Eth2 *eth2 = proto->MutableExtension(OstProto::eth2);
|
||||
|
||||
eth2->set_type(attributes.value("value")
|
||||
.toString().toUInt(&isOk, kBaseHex));
|
||||
eth2->set_is_override_type(true);
|
||||
}
|
||||
}
|
||||
|
40
common/svlanpdml.h
Normal file
40
common/svlanpdml.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _SVLAN_PDML_H
|
||||
#define _SVLAN_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlSvlanProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlSvlanProtocol();
|
||||
};
|
||||
|
||||
#endif
|
98
common/tcppdml.cpp
Normal file
98
common/tcppdml.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "tcppdml.h"
|
||||
|
||||
#include "hexdump.pb.h"
|
||||
#include "tcp.pb.h"
|
||||
|
||||
PdmlTcpProtocol::PdmlTcpProtocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kTcpFieldNumber;
|
||||
|
||||
fieldMap_.insert("tcp.srcport", OstProto::Tcp::kSrcPortFieldNumber);
|
||||
fieldMap_.insert("tcp.dstport", OstProto::Tcp::kDstPortFieldNumber);
|
||||
fieldMap_.insert("tcp.seq", OstProto::Tcp::kSeqNumFieldNumber);
|
||||
fieldMap_.insert("tcp.ack", OstProto::Tcp::kAckNumFieldNumber);
|
||||
fieldMap_.insert("tcp.hdr_len", OstProto::Tcp::kHdrlenRsvdFieldNumber);
|
||||
fieldMap_.insert("tcp.flags", OstProto::Tcp::kFlagsFieldNumber);
|
||||
fieldMap_.insert("tcp.window_size", OstProto::Tcp::kWindowFieldNumber);
|
||||
fieldMap_.insert("tcp.checksum", OstProto::Tcp::kCksumFieldNumber);
|
||||
fieldMap_.insert("tcp.urgent_pointer", OstProto::Tcp::kUrgPtrFieldNumber);
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlTcpProtocol::createInstance()
|
||||
{
|
||||
return new PdmlTcpProtocol();
|
||||
}
|
||||
|
||||
void PdmlTcpProtocol::unknownFieldHandler(QString name, int /*pos*/,
|
||||
int /*size*/, const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream* /*stream*/)
|
||||
{
|
||||
if (name == "tcp.options")
|
||||
options_ = QByteArray::fromHex(attributes.value("value").toString().toUtf8());
|
||||
else if (name == "")
|
||||
{
|
||||
if (attributes.value("show").toString().startsWith("Acknowledgement number"))
|
||||
{
|
||||
bool isOk;
|
||||
OstProto::Tcp *tcp = pbProto->MutableExtension(OstProto::tcp);
|
||||
|
||||
tcp->set_ack_num(attributes.value("value").toString().toUInt(&isOk, kBaseHex));
|
||||
}
|
||||
#if 0
|
||||
else if (attributes.value("show").toString().startsWith("TCP segment data"))
|
||||
{
|
||||
segmentData_ = QByteArray::fromHex(attributes.value("value").toString().toUtf8());
|
||||
stream->mutable_core()->mutable_name()->insert(0,
|
||||
segmentData_.constData(), segmentData_.size());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void PdmlTcpProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream)
|
||||
{
|
||||
OstProto::Tcp *tcp = pbProto->MutableExtension(OstProto::tcp);
|
||||
|
||||
qDebug("Tcp: post\n");
|
||||
|
||||
tcp->set_is_override_src_port(true);
|
||||
tcp->set_is_override_dst_port(true);
|
||||
tcp->set_is_override_hdrlen(true);
|
||||
tcp->set_is_override_cksum(true);
|
||||
|
||||
if (options_.size())
|
||||
{
|
||||
OstProto::Protocol *proto = stream->add_protocol();
|
||||
|
||||
proto->mutable_protocol_id()->set_id(
|
||||
OstProto::Protocol::kHexDumpFieldNumber);
|
||||
|
||||
OstProto::HexDump *hexDump = proto->MutableExtension(OstProto::hexDump);
|
||||
|
||||
hexDump->mutable_content()->append(options_.constData(),
|
||||
options_.size());
|
||||
hexDump->set_pad_until_end(false);
|
||||
options_.resize(0);
|
||||
}
|
||||
}
|
||||
|
42
common/tcppdml.h
Normal file
42
common/tcppdml.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _TCP_PDML_H
|
||||
#define _TCP_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlTcpProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlTcpProtocol();
|
||||
private:
|
||||
QByteArray options_;
|
||||
QByteArray segmentData_;
|
||||
};
|
||||
|
||||
#endif
|
171
common/textprotopdml.cpp
Normal file
171
common/textprotopdml.cpp
Normal file
@ -0,0 +1,171 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "textprotopdml.h"
|
||||
|
||||
#include "textproto.pb.h"
|
||||
|
||||
PdmlTextProtocol::PdmlTextProtocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kTextProtocolFieldNumber;
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlTextProtocol::createInstance()
|
||||
{
|
||||
return new PdmlTextProtocol();
|
||||
}
|
||||
|
||||
void PdmlTextProtocol::preProtocolHandler(QString /*name*/,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
||||
{
|
||||
bool isOk;
|
||||
int size;
|
||||
int pos = attributes.value("pos").toString().toUInt(&isOk);
|
||||
|
||||
if (!isOk)
|
||||
{
|
||||
if (expectedPos >= 0)
|
||||
expPos_ = pos = expectedPos;
|
||||
else
|
||||
goto _skip_pos_size_proc;
|
||||
}
|
||||
|
||||
size = attributes.value("size").toString().toUInt(&isOk);
|
||||
if (!isOk)
|
||||
goto _skip_pos_size_proc;
|
||||
|
||||
// If pos+size goes beyond the frame length, this is a "reassembled"
|
||||
// protocol and should be skipped
|
||||
if ((pos + size) > int(stream->core().frame_len()))
|
||||
goto _skip_pos_size_proc;
|
||||
|
||||
expPos_ = pos;
|
||||
endPos_ = expPos_ + size;
|
||||
|
||||
_skip_pos_size_proc:
|
||||
qDebug("expPos_ = %d, endPos_ = %d", expPos_, endPos_);
|
||||
OstProto::TextProtocol *text = pbProto->MutableExtension(
|
||||
OstProto::textProtocol);
|
||||
|
||||
text->set_port_num(0);
|
||||
text->set_eol(OstProto::TextProtocol::kCrLf); // by default we assume CRLF
|
||||
|
||||
detectEol_ = true;
|
||||
contentType_ = kUnknownContent;
|
||||
}
|
||||
|
||||
void PdmlTextProtocol::unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto,
|
||||
OstProto::Stream* /*stream*/)
|
||||
{
|
||||
_retry:
|
||||
switch(contentType_)
|
||||
{
|
||||
case kUnknownContent:
|
||||
if (name == "data")
|
||||
contentType_ = kOtherContent;
|
||||
else
|
||||
contentType_ = kTextContent;
|
||||
goto _retry;
|
||||
break;
|
||||
|
||||
case kTextContent:
|
||||
{
|
||||
OstProto::TextProtocol *text = pbProto->MutableExtension(
|
||||
OstProto::textProtocol);
|
||||
|
||||
if ((name == "data")
|
||||
|| (attributes.value("show") == "HTTP chunked response"))
|
||||
{
|
||||
contentType_ = kOtherContent;
|
||||
goto _retry;
|
||||
}
|
||||
|
||||
if (pos < expPos_)
|
||||
break;
|
||||
|
||||
if ((pos + size) > endPos_)
|
||||
break;
|
||||
|
||||
if (pos > expPos_)
|
||||
{
|
||||
int gap = pos - expPos_;
|
||||
QByteArray filler(gap, '\n');
|
||||
|
||||
if (text->eol() == OstProto::TextProtocol::kCrLf)
|
||||
{
|
||||
if (gap & 0x01) // Odd
|
||||
{
|
||||
filler.resize(gap/2 + 1);
|
||||
filler[0]=int(' ');
|
||||
}
|
||||
else // Even
|
||||
filler.resize(gap/2);
|
||||
}
|
||||
|
||||
text->mutable_text()->append(filler.constData(), filler.size());
|
||||
expPos_ += gap;
|
||||
}
|
||||
|
||||
QByteArray line = QByteArray::fromHex(
|
||||
attributes.value("value").toString().toUtf8());
|
||||
|
||||
if (detectEol_)
|
||||
{
|
||||
if (line.right(2) == "\r\n")
|
||||
text->set_eol(OstProto::TextProtocol::kCrLf);
|
||||
else if (line.right(1) == "\r")
|
||||
text->set_eol(OstProto::TextProtocol::kCr);
|
||||
else if (line.right(1) == "\n")
|
||||
text->set_eol(OstProto::TextProtocol::kLf);
|
||||
|
||||
detectEol_ = false;
|
||||
}
|
||||
|
||||
// Convert line endings to LF only - Qt reqmt that TextProto honours
|
||||
line.replace("\r\n", "\n");
|
||||
line.replace('\r', '\n');
|
||||
|
||||
text->mutable_text()->append(line.constData(), line.size());
|
||||
expPos_ += size;
|
||||
break;
|
||||
}
|
||||
case kOtherContent:
|
||||
// Do nothing!
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
void PdmlTextProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream)
|
||||
{
|
||||
OstProto::TextProtocol *text = pbProto->MutableExtension(
|
||||
OstProto::textProtocol);
|
||||
|
||||
// Empty Text Content - remove ourselves
|
||||
if (text->text().length() == 0)
|
||||
stream->mutable_protocol()->RemoveLast();
|
||||
|
||||
expPos_ = endPos_ = -1;
|
||||
detectEol_ = true;
|
||||
contentType_ = kUnknownContent;
|
||||
}
|
53
common/textprotopdml.h
Normal file
53
common/textprotopdml.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _TEXT_PROTO_PDML_H
|
||||
#define _TEXT_PROTO_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlTextProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlTextProtocol();
|
||||
private:
|
||||
enum ContentType {
|
||||
kUnknownContent,
|
||||
kTextContent,
|
||||
kOtherContent
|
||||
};
|
||||
|
||||
bool detectEol_;
|
||||
ContentType contentType_;
|
||||
int expPos_;
|
||||
int endPos_;
|
||||
};
|
||||
|
||||
#endif
|
53
common/udppdml.cpp
Normal file
53
common/udppdml.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "udppdml.h"
|
||||
|
||||
#include "udp.pb.h"
|
||||
|
||||
PdmlUdpProtocol::PdmlUdpProtocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kUdpFieldNumber;
|
||||
|
||||
fieldMap_.insert("udp.srcport", OstProto::Udp::kSrcPortFieldNumber);
|
||||
fieldMap_.insert("udp.dstport", OstProto::Udp::kDstPortFieldNumber);
|
||||
fieldMap_.insert("udp.length", OstProto::Udp::kTotlenFieldNumber);
|
||||
fieldMap_.insert("udp.checksum_coverage",
|
||||
OstProto::Udp::kTotlenFieldNumber);
|
||||
fieldMap_.insert("udp.checksum", OstProto::Udp::kCksumFieldNumber);
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlUdpProtocol::createInstance()
|
||||
{
|
||||
return new PdmlUdpProtocol();
|
||||
}
|
||||
|
||||
void PdmlUdpProtocol::postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream* /*stream*/)
|
||||
{
|
||||
OstProto::Udp *udp = pbProto->MutableExtension(OstProto::udp);
|
||||
|
||||
qDebug("Udp: post\n");
|
||||
|
||||
udp->set_is_override_src_port(true);
|
||||
udp->set_is_override_dst_port(true);
|
||||
udp->set_is_override_totlen(true);
|
||||
udp->set_is_override_cksum(true);
|
||||
}
|
||||
|
35
common/udppdml.h
Normal file
35
common/udppdml.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _UDP_PDML_H
|
||||
#define _UDP_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlUdpProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
virtual void postProtocolHandler(OstProto::Protocol *pbProto,
|
||||
OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlUdpProtocol();
|
||||
};
|
||||
|
||||
#endif
|
91
common/vlanpdml.cpp
Normal file
91
common/vlanpdml.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "vlanpdml.h"
|
||||
|
||||
#include "eth2.pb.h"
|
||||
#include "vlan.pb.h"
|
||||
|
||||
PdmlVlanProtocol::PdmlVlanProtocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kVlanFieldNumber;
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlVlanProtocol::createInstance()
|
||||
{
|
||||
return new PdmlVlanProtocol();
|
||||
}
|
||||
|
||||
void PdmlVlanProtocol::preProtocolHandler(QString /*name*/,
|
||||
const QXmlStreamAttributes& /*attributes*/, int /*expectedPos*/,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
||||
{
|
||||
OstProto::Vlan *vlan = pbProto->MutableExtension(OstProto::vlan);
|
||||
|
||||
vlan->set_tpid(0x8100);
|
||||
vlan->set_is_override_tpid(true);
|
||||
|
||||
// If a eth2 protocol precedes vlan, we remove the eth2 protocol
|
||||
// 'coz the eth2.etherType is actually the vlan.tpid
|
||||
//
|
||||
// We assume that the current protocol is the last in the stream
|
||||
int index = stream->protocol_size() - 1;
|
||||
if ((index > 1)
|
||||
&& (stream->protocol(index).protocol_id().id()
|
||||
== OstProto::Protocol::kVlanFieldNumber)
|
||||
&& (stream->protocol(index - 1).protocol_id().id()
|
||||
== OstProto::Protocol::kEth2FieldNumber))
|
||||
{
|
||||
stream->mutable_protocol()->SwapElements(index, index - 1);
|
||||
Q_ASSERT(stream->protocol(index).protocol_id().id()
|
||||
== OstProto::Protocol::kEth2FieldNumber);
|
||||
stream->mutable_protocol()->RemoveLast();
|
||||
}
|
||||
}
|
||||
|
||||
void PdmlVlanProtocol::unknownFieldHandler(QString name, int /*pos*/,
|
||||
int /*size*/, const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream)
|
||||
{
|
||||
if (name == "vlan.id")
|
||||
{
|
||||
bool isOk;
|
||||
OstProto::Vlan *vlan = pbProto->MutableExtension(OstProto::vlan);
|
||||
uint tag = attributes.value("unmaskedvalue").isEmpty() ?
|
||||
attributes.value("value").toString().toUInt(&isOk, kBaseHex) :
|
||||
attributes.value("unmaskedvalue").toString().toUInt(&isOk,kBaseHex);
|
||||
|
||||
vlan->set_vlan_tag(tag);
|
||||
}
|
||||
else if (name == "vlan.etype")
|
||||
{
|
||||
OstProto::Protocol *proto = stream->add_protocol();
|
||||
|
||||
proto->mutable_protocol_id()->set_id(
|
||||
OstProto::Protocol::kEth2FieldNumber);
|
||||
|
||||
bool isOk;
|
||||
OstProto::Eth2 *eth2 = proto->MutableExtension(OstProto::eth2);
|
||||
|
||||
eth2->set_type(attributes.value("value")
|
||||
.toString().toUInt(&isOk, kBaseHex));
|
||||
eth2->set_is_override_type(true);
|
||||
}
|
||||
}
|
||||
|
40
common/vlanpdml.h
Normal file
40
common/vlanpdml.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright (C) 2011 Srivats P.
|
||||
|
||||
This file is part of "Ostinato"
|
||||
|
||||
This is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#ifndef _VLAN_PDML_H
|
||||
#define _VLAN_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlVlanProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
static PdmlProtocol* createInstance();
|
||||
|
||||
virtual void preProtocolHandler(QString name,
|
||||
const QXmlStreamAttributes &attributes, int expectedPos,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
virtual void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream *stream);
|
||||
protected:
|
||||
PdmlVlanProtocol();
|
||||
};
|
||||
|
||||
#endif
|
@ -5,23 +5,28 @@ INCLUDEPATH += "../rpc/" "../common/" "../client"
|
||||
win32 {
|
||||
LIBS += -lwpcap -lpacket
|
||||
CONFIG(debug, debug|release) {
|
||||
LIBS += -L"../common/debug" -lostproto
|
||||
LIBS += -L"../common/debug" -lostprotogui -lostproto
|
||||
LIBS += -L"../rpc/debug" -lpbrpc
|
||||
POST_TARGETDEPS += \
|
||||
"../common/debug/libostprotogui.a" \
|
||||
"../common/debug/libostproto.a" \
|
||||
"../rpc/debug/libpbrpc.a"
|
||||
} else {
|
||||
LIBS += -L"../common/release" -lostproto
|
||||
LIBS += -L"../common/release" -lostprotogui -lostproto
|
||||
LIBS += -L"../rpc/release" -lpbrpc
|
||||
POST_TARGETDEPS += \
|
||||
"../common/release/libostprotogui.a" \
|
||||
"../common/release/libostproto.a" \
|
||||
"../rpc/release/libpbrpc.a"
|
||||
}
|
||||
} else {
|
||||
LIBS += -lpcap
|
||||
LIBS += -L"../common" -lostproto
|
||||
LIBS += -L"../common" -lostprotogui -lostproto
|
||||
LIBS += -L"../rpc" -lpbrpc
|
||||
POST_TARGETDEPS += "../common/libostproto.a" "../rpc/libpbrpc.a"
|
||||
POST_TARGETDEPS += \
|
||||
"../common/libostprotogui.a" \
|
||||
"../common/libostproto.a" \
|
||||
"../rpc/libpbrpc.a"
|
||||
}
|
||||
LIBS += -lprotobuf
|
||||
LIBS += -L"../extra/qhexedit2/$(OBJECTS_DIR)/" -lqhexedit2
|
||||
|
Loading…
Reference in New Issue
Block a user