Merge branch 'master' into emul
This commit is contained in:
commit
754a9ac20e
@ -80,6 +80,8 @@ class OstinatoRpcChannel(RpcChannel):
|
||||
try:
|
||||
self.log.info('invoking RPC %s(%s): %s', method.name,
|
||||
type(request).__name__, response_class.__name__)
|
||||
if not request.IsInitialized():
|
||||
raise RpcError('missing required fields in request')
|
||||
self.log.debug('serializing request arg %s', request)
|
||||
req = request.SerializeToString()
|
||||
hdr = struct.pack('>HHI', MSG_TYPE_REQUEST, method.index, len(req))
|
||||
|
@ -819,7 +819,8 @@ quint32 Ip4Protocol::protocolFrameCksum(int streamIndex,
|
||||
sum += *((quint16*)(p + 14)); // src-ip lo
|
||||
sum += *((quint16*)(p + 16)); // dst-ip hi
|
||||
sum += *((quint16*)(p + 18)); // dst-ip lo
|
||||
sum += qToBigEndian((quint16) protocolFramePayloadSize()); // len
|
||||
sum += qToBigEndian((quint16)
|
||||
protocolFramePayloadSize(streamIndex)); // len
|
||||
sum += qToBigEndian((quint16) *(p + 9)); // proto
|
||||
|
||||
while(sum>>16)
|
||||
|
@ -21,6 +21,7 @@ PROTOS += \
|
||||
vlan.proto \
|
||||
svlan.proto \
|
||||
vlanstack.proto \
|
||||
stp.proto \
|
||||
arp.proto \
|
||||
ip4.proto \
|
||||
ip6.proto \
|
||||
@ -93,6 +94,7 @@ SOURCES += \
|
||||
dot3.cpp \
|
||||
llc.cpp \
|
||||
snap.cpp \
|
||||
stp.cpp \
|
||||
arp.cpp \
|
||||
ip4.cpp \
|
||||
ip6.cpp \
|
||||
|
@ -15,6 +15,7 @@ FORMS += \
|
||||
dot3.ui \
|
||||
llc.ui \
|
||||
snap.ui \
|
||||
stp.ui \
|
||||
arp.ui \
|
||||
ip4.ui \
|
||||
ip6.ui \
|
||||
@ -59,6 +60,7 @@ HEADERS += \
|
||||
dot2llcconfig.h \
|
||||
snapconfig.h \
|
||||
dot2snapconfig.h \
|
||||
stpconfig.h \
|
||||
arpconfig.h \
|
||||
ip4config.h \
|
||||
ip6config.h \
|
||||
@ -94,6 +96,7 @@ SOURCES += \
|
||||
dot3config.cpp \
|
||||
llcconfig.cpp \
|
||||
snapconfig.cpp \
|
||||
stpconfig.cpp \
|
||||
arpconfig.cpp \
|
||||
ip4config.cpp \
|
||||
ip6config.cpp \
|
||||
@ -112,6 +115,7 @@ SOURCES += \
|
||||
SOURCES += \
|
||||
vlanpdml.cpp \
|
||||
svlanpdml.cpp \
|
||||
stppdml.cpp \
|
||||
eth2pdml.cpp \
|
||||
llcpdml.cpp \
|
||||
arppdml.cpp \
|
||||
|
@ -35,6 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "ip4pdml.h"
|
||||
#include "ip6pdml.h"
|
||||
#include "mldpdml.h"
|
||||
#include "stppdml.h"
|
||||
#include "svlanpdml.h"
|
||||
#include "tcppdml.h"
|
||||
#include "textprotopdml.h"
|
||||
@ -73,6 +74,7 @@ PdmlReader::PdmlReader(OstProto::StreamConfigList *streams)
|
||||
factory_.insert("sdp", PdmlTextProtocol::createInstance);
|
||||
factory_.insert("sip", PdmlTextProtocol::createInstance);
|
||||
factory_.insert("smtp", PdmlTextProtocol::createInstance);
|
||||
factory_.insert("stp", PdmlStpProtocol::createInstance);
|
||||
factory_.insert("tcp", PdmlTcpProtocol::createInstance);
|
||||
factory_.insert("udp", PdmlUdpProtocol::createInstance);
|
||||
factory_.insert("udplite", PdmlUdpProtocol::createInstance);
|
||||
|
@ -140,6 +140,7 @@ message Protocol {
|
||||
kDot2LlcFieldNumber = 206;
|
||||
kDot2SnapFieldNumber = 207;
|
||||
kVlanStackFieldNumber = 208;
|
||||
kStpFieldNumber = 209;
|
||||
|
||||
kArpFieldNumber = 300;
|
||||
kIp4FieldNumber = 301;
|
||||
|
@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "snap.h"
|
||||
#include "dot2snap.h"
|
||||
#include "eth2.h"
|
||||
#include "stp.h"
|
||||
|
||||
// L3 Protos
|
||||
#include "arp.h"
|
||||
@ -89,6 +90,8 @@ ProtocolManager::ProtocolManager()
|
||||
(void*) SnapProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kDot2SnapFieldNumber,
|
||||
(void*) Dot2SnapProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kStpFieldNumber,
|
||||
(void*) StpProtocol::createInstance);
|
||||
|
||||
// Layer 3 Protocols
|
||||
registerProtocol(OstProto::Protocol::kArpFieldNumber,
|
||||
|
@ -30,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "dot2llcconfig.h"
|
||||
#include "snapconfig.h"
|
||||
#include "dot2snapconfig.h"
|
||||
#include "stpconfig.h"
|
||||
// L3 Protocol Widgets
|
||||
#include "arpconfig.h"
|
||||
#include "ip4config.h"
|
||||
@ -93,6 +94,9 @@ ProtocolWidgetFactory::ProtocolWidgetFactory()
|
||||
OstProtocolWidgetFactory->registerProtocolConfigWidget(
|
||||
OstProto::Protocol::kDot2SnapFieldNumber,
|
||||
(void*) Dot2SnapConfigForm::createInstance);
|
||||
OstProtocolWidgetFactory->registerProtocolConfigWidget(
|
||||
OstProto::Protocol::kStpFieldNumber,
|
||||
(void*) StpConfigForm::createInstance);
|
||||
|
||||
// Layer 3 Protocols
|
||||
OstProtocolWidgetFactory->registerProtocolConfigWidget(
|
||||
|
@ -450,7 +450,7 @@ void PythonFileFormat::writeFieldAssignment(
|
||||
std::string val = fieldDesc->is_repeated() ?
|
||||
refl->GetRepeatedStringReference(msg, fieldDesc, index, &val) :
|
||||
refl->GetStringReference(msg, fieldDesc, &val);
|
||||
QString escVal = escapeString(val.c_str());
|
||||
QString escVal = escapeString(QString::fromStdString(val));
|
||||
if (val != fieldDesc->default_value_string())
|
||||
out << fieldName << " = '" << escVal << "'\n";
|
||||
break;
|
||||
|
543
common/stp.cpp
Normal file
543
common/stp.cpp
Normal file
@ -0,0 +1,543 @@
|
||||
/*
|
||||
Copyright (C) 2014 PLVision.
|
||||
|
||||
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/>
|
||||
|
||||
This module is developed by PLVision <developers@plvision.eu>
|
||||
*/
|
||||
|
||||
#include "stp.h"
|
||||
#include <QRegExp>
|
||||
|
||||
#define uintToMacStr(num) \
|
||||
QString("%1").arg(num, 6 * 2, BASE_HEX, QChar('0')) \
|
||||
.replace(QRegExp("([0-9a-fA-F]{2}\\B)"), "\\1:").toUpper()
|
||||
#define ONE_BIT(pos) ((unsigned int)(1 << (pos)))
|
||||
#define BITS(bit) (bit)
|
||||
#define BYTES(byte) (byte)
|
||||
#define BYTES_TO_BITS(byte) (byte * 8)
|
||||
|
||||
#define STP_LLC 0x424203
|
||||
|
||||
StpProtocol::StpProtocol(StreamBase *stream, AbstractProtocol *parent)
|
||||
: AbstractProtocol(stream, parent)
|
||||
{
|
||||
}
|
||||
|
||||
StpProtocol::~StpProtocol()
|
||||
{
|
||||
}
|
||||
|
||||
AbstractProtocol* StpProtocol::createInstance(StreamBase *stream,
|
||||
AbstractProtocol *parent)
|
||||
{
|
||||
return new StpProtocol(stream, parent);
|
||||
}
|
||||
|
||||
quint32 StpProtocol::protocolNumber() const
|
||||
{
|
||||
return OstProto::Protocol::kStpFieldNumber;
|
||||
}
|
||||
|
||||
void StpProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
||||
{
|
||||
protocol.MutableExtension(OstProto::stp)->CopyFrom(data_);
|
||||
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
||||
}
|
||||
|
||||
void StpProtocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
||||
{
|
||||
if (protocol.protocol_id().id() == protocolNumber() &&
|
||||
protocol.HasExtension(OstProto::stp))
|
||||
data_.MergeFrom(protocol.GetExtension(OstProto::stp));
|
||||
}
|
||||
|
||||
QString StpProtocol::name() const
|
||||
{
|
||||
return QString("Spanning Tree Protocol");
|
||||
}
|
||||
|
||||
QString StpProtocol::shortName() const
|
||||
{
|
||||
return QString("STP");
|
||||
}
|
||||
|
||||
quint32 StpProtocol::protocolId(ProtocolIdType type) const
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case ProtocolIdLlc:
|
||||
return STP_LLC;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return AbstractProtocol::protocolId(type);
|
||||
}
|
||||
|
||||
int StpProtocol::fieldCount() const
|
||||
{
|
||||
return stp_fieldCount;
|
||||
}
|
||||
|
||||
AbstractProtocol::FieldFlags StpProtocol::fieldFlags(int index) const
|
||||
{
|
||||
AbstractProtocol::FieldFlags flags;
|
||||
|
||||
flags = AbstractProtocol::fieldFlags(index);
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case stp_protocol_id:
|
||||
case stp_version_id:
|
||||
case stp_bpdu_type:
|
||||
case stp_flags:
|
||||
case stp_root_id:
|
||||
case stp_root_path_cost:
|
||||
case stp_bridge_id:
|
||||
case stp_port_id:
|
||||
case stp_message_age:
|
||||
case stp_max_age:
|
||||
case stp_hello_time:
|
||||
case stp_forward_delay:
|
||||
break;
|
||||
default:
|
||||
qFatal("%s: unimplemented case %d in switch", __PRETTY_FUNCTION__,
|
||||
index);
|
||||
break;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
QVariant StpProtocol::fieldData(int index, FieldAttrib attrib,
|
||||
int streamIndex) const
|
||||
{
|
||||
QString str[] = {"Topology Change", "Topology Change Acknowledgment"};
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case stp_protocol_id:
|
||||
{
|
||||
switch (attrib)
|
||||
{
|
||||
case FieldName:
|
||||
return QString("Protocol Identifier");
|
||||
case FieldValue:
|
||||
return data_.protocol_id();
|
||||
case FieldTextValue:
|
||||
return QString("0x%1").arg(data_.protocol_id(),
|
||||
4, BASE_HEX, QChar('0'));
|
||||
case FieldFrameValue:
|
||||
{
|
||||
QByteArray fv;
|
||||
fv.resize(BYTES(2));
|
||||
qToBigEndian((quint16)data_.protocol_id(),
|
||||
(uchar*)fv.data());
|
||||
return fv;
|
||||
}
|
||||
case FieldBitSize:
|
||||
return BYTES_TO_BITS(2);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case stp_version_id:
|
||||
{
|
||||
switch (attrib)
|
||||
{
|
||||
case FieldName:
|
||||
return QString("Version Identifier");
|
||||
case FieldValue:
|
||||
return data_.protocol_version_id();
|
||||
case FieldTextValue:
|
||||
return QString("%1").arg(
|
||||
data_.protocol_version_id());
|
||||
case FieldFrameValue:
|
||||
return QByteArray(1,
|
||||
(char)data_.protocol_version_id());
|
||||
case FieldBitSize:
|
||||
return BYTES_TO_BITS(1);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case stp_bpdu_type:
|
||||
{
|
||||
switch (attrib)
|
||||
{
|
||||
case FieldName:
|
||||
return QString("BPDU Type");
|
||||
case FieldValue:
|
||||
return data_.bpdu_type();
|
||||
case FieldTextValue:
|
||||
return QString("0x%1").arg(data_.bpdu_type(),
|
||||
2, BASE_HEX, QChar('0'));
|
||||
case FieldFrameValue:
|
||||
return QByteArray(1, (char)data_.bpdu_type());
|
||||
case FieldBitSize:
|
||||
return BYTES_TO_BITS(1);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case stp_flags:
|
||||
{
|
||||
switch (attrib)
|
||||
{
|
||||
case FieldName:
|
||||
return QString("BPDU Flags");
|
||||
case FieldValue:
|
||||
return data_.flags();
|
||||
case FieldTextValue:
|
||||
{
|
||||
QString strTemp = "(";
|
||||
if((data_.flags() & ONE_BIT(0))) strTemp += str[0] + ", ";
|
||||
if((data_.flags() & ONE_BIT(7))) strTemp += str[1] + ", ";
|
||||
strTemp += ")";
|
||||
strTemp.replace(", )", ")");
|
||||
return strTemp;
|
||||
}
|
||||
case FieldFrameValue:
|
||||
return QByteArray(1, (char)data_.flags());
|
||||
case FieldBitSize:
|
||||
return BYTES_TO_BITS(1);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case stp_root_id:
|
||||
{
|
||||
switch (attrib)
|
||||
{
|
||||
case FieldName:
|
||||
return QString("Root Identifier");
|
||||
case FieldValue:
|
||||
return (quint64) data_.root_id();
|
||||
case FieldTextValue:
|
||||
{
|
||||
// Root ID contain two value:
|
||||
// Root ID Priority(first 2 bytes)
|
||||
// and Root ID MAC (last 6 bytes). (IEEE802.1D-2008)
|
||||
quint16 priority = (
|
||||
data_.root_id() & 0xFFFF000000000000ULL) >> (BYTES_TO_BITS(6));
|
||||
quint64 mac = data_.root_id() & 0x0000FFFFFFFFFFFFULL;
|
||||
return QString("Priority: %1 / MAC: %2")
|
||||
.arg(QString::number(priority),
|
||||
uintToMacStr(mac));
|
||||
}
|
||||
case FieldFrameValue:
|
||||
{
|
||||
QByteArray fv;
|
||||
fv.resize(BYTES(8));
|
||||
qToBigEndian((quint64)data_.root_id(), (uchar*)fv.data());
|
||||
return fv;
|
||||
}
|
||||
case FieldBitSize:
|
||||
return BYTES_TO_BITS(8);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case stp_root_path_cost:
|
||||
{
|
||||
switch (attrib)
|
||||
{
|
||||
case FieldName:
|
||||
return QString("Root Path Cost");
|
||||
case FieldValue:
|
||||
return data_.root_path_cost();
|
||||
case FieldTextValue:
|
||||
return QString("%1").arg(data_.root_path_cost());
|
||||
case FieldFrameValue:
|
||||
{
|
||||
QByteArray fv;
|
||||
fv.resize(BYTES(4));
|
||||
qToBigEndian(data_.root_path_cost(), (uchar*)fv.data());
|
||||
return fv;
|
||||
}
|
||||
case FieldBitSize:
|
||||
return BYTES_TO_BITS(4);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case stp_bridge_id:
|
||||
{
|
||||
switch (attrib)
|
||||
{
|
||||
case FieldName:
|
||||
return QString("Bridge Identifier");
|
||||
case FieldValue:
|
||||
return (quint64) data_.bridge_id();
|
||||
case FieldTextValue:
|
||||
{
|
||||
// Bridge ID contain two value:
|
||||
// Bridge ID Priority(first 2 bytes)
|
||||
// and Bridge ID MAC (last 6 bytes). (IEEE802.1D-2008)
|
||||
quint16 priority = (data_.bridge_id() & 0xFFFF000000000000ULL
|
||||
) >> (BYTES_TO_BITS(6));
|
||||
quint64 mac = data_.bridge_id() & 0x0000FFFFFFFFFFFFULL;
|
||||
return QString("Priority: %1 / MAC: %2").arg(QString::number(priority),
|
||||
uintToMacStr(mac));
|
||||
}
|
||||
case FieldFrameValue:
|
||||
{
|
||||
QByteArray fv;
|
||||
fv.resize(BYTES(8));
|
||||
qToBigEndian((quint64)data_.bridge_id(), (uchar*)fv.data());
|
||||
return fv;
|
||||
}
|
||||
case FieldBitSize:
|
||||
return BYTES_TO_BITS(8);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case stp_port_id:
|
||||
{
|
||||
switch (attrib)
|
||||
{
|
||||
case FieldName:
|
||||
return QString("Port Identifier");
|
||||
case FieldValue:
|
||||
return data_.port_id();
|
||||
case FieldTextValue:
|
||||
return QString("0x%1").arg(data_.port_id(), 4,
|
||||
BASE_HEX, QChar('0'));
|
||||
case FieldFrameValue:
|
||||
{
|
||||
QByteArray fv;
|
||||
fv.resize(BYTES(2));
|
||||
qToBigEndian((quint16)data_.port_id(), (uchar*)fv.data());
|
||||
return fv;
|
||||
}
|
||||
case FieldBitSize:
|
||||
return BYTES_TO_BITS(2);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case stp_message_age:
|
||||
{
|
||||
switch (attrib)
|
||||
{
|
||||
case FieldName:
|
||||
return QString("Message Age");
|
||||
case FieldValue:
|
||||
return data_.message_age();
|
||||
case FieldTextValue:
|
||||
return QString("%1").arg(data_.message_age());
|
||||
case FieldFrameValue:
|
||||
{
|
||||
QByteArray fv;
|
||||
fv.resize(BYTES(2));
|
||||
qToBigEndian((quint16)(data_.message_age()),
|
||||
(uchar*)fv.data());
|
||||
return fv;
|
||||
}
|
||||
case FieldBitSize:
|
||||
return BYTES_TO_BITS(2);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case stp_max_age:
|
||||
{
|
||||
switch (attrib)
|
||||
{
|
||||
case FieldName:
|
||||
return QString("Max Age");
|
||||
case FieldValue:
|
||||
return data_.max_age();
|
||||
case FieldTextValue:
|
||||
return QString("%1").arg(data_.max_age());
|
||||
case FieldFrameValue:
|
||||
{
|
||||
QByteArray fv;
|
||||
fv.resize(BYTES(2));
|
||||
qToBigEndian((quint16)data_.max_age(), (uchar*)fv.data());
|
||||
return fv;
|
||||
}
|
||||
case FieldBitSize:
|
||||
return BYTES_TO_BITS(2);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case stp_hello_time:
|
||||
{
|
||||
switch (attrib)
|
||||
{
|
||||
case FieldName:
|
||||
return QString("Hello Time");
|
||||
case FieldValue:
|
||||
return data_.hello_time();
|
||||
case FieldTextValue:
|
||||
return QString("%1").arg(data_.hello_time());
|
||||
case FieldFrameValue:
|
||||
{
|
||||
QByteArray fv;
|
||||
fv.resize(BYTES(2));
|
||||
qToBigEndian((quint16)data_.hello_time(), (uchar*)fv.data());
|
||||
return fv;
|
||||
}
|
||||
case FieldBitSize:
|
||||
return BYTES_TO_BITS(2);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case stp_forward_delay:
|
||||
{
|
||||
switch (attrib)
|
||||
{
|
||||
case FieldName:
|
||||
return QString("Forward Delay");
|
||||
case FieldValue:
|
||||
return data_.forward_delay();
|
||||
case FieldTextValue:
|
||||
return QString("%1").arg(data_.forward_delay());
|
||||
case FieldFrameValue:
|
||||
{
|
||||
QByteArray fv;
|
||||
fv.resize(BYTES(2));
|
||||
qToBigEndian((quint16)data_.forward_delay(),
|
||||
(uchar*)fv.data());
|
||||
return fv;
|
||||
}
|
||||
case FieldBitSize:
|
||||
return BYTES_TO_BITS(2);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return AbstractProtocol::fieldData(index, attrib, streamIndex);
|
||||
}
|
||||
|
||||
bool StpProtocol::setFieldData(int index, const QVariant &value,
|
||||
FieldAttrib attrib)
|
||||
{
|
||||
bool isOk = false;
|
||||
|
||||
if (attrib != FieldValue)
|
||||
return isOk;
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case stp_protocol_id:
|
||||
{
|
||||
quint16 protoId = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data_.set_protocol_id(protoId);
|
||||
break;
|
||||
}
|
||||
case stp_version_id:
|
||||
{
|
||||
quint8 versionId = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data_.set_protocol_version_id(versionId);
|
||||
break;
|
||||
}
|
||||
case stp_bpdu_type:
|
||||
{
|
||||
quint8 bpdu = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data_.set_bpdu_type(bpdu);
|
||||
break;
|
||||
}
|
||||
case stp_flags:
|
||||
{
|
||||
quint8 flags = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data_.set_flags(flags);
|
||||
break;
|
||||
}
|
||||
case stp_root_id:
|
||||
{
|
||||
quint64 rootId = value.toULongLong(&isOk);
|
||||
if (isOk)
|
||||
data_.set_root_id(rootId);
|
||||
break;
|
||||
}
|
||||
case stp_root_path_cost:
|
||||
{
|
||||
quint32 pathCost = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data_.set_root_path_cost(pathCost);
|
||||
break;
|
||||
}
|
||||
case stp_bridge_id:
|
||||
{
|
||||
quint64 bridgeId = value.toULongLong(&isOk);
|
||||
if (isOk)
|
||||
data_.set_bridge_id(bridgeId);
|
||||
break;
|
||||
}
|
||||
case stp_port_id:
|
||||
{
|
||||
quint32 port_id = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data_.set_port_id(port_id);
|
||||
break;
|
||||
}
|
||||
case stp_message_age:
|
||||
{
|
||||
quint32 messageAge = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data_.set_message_age(messageAge);
|
||||
break;
|
||||
}
|
||||
case stp_max_age:
|
||||
{
|
||||
quint32 maxAge = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data_.set_max_age(maxAge);
|
||||
break;
|
||||
}
|
||||
case stp_hello_time:
|
||||
{
|
||||
quint32 helloTime = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data_.set_hello_time(helloTime);
|
||||
break;
|
||||
}
|
||||
case stp_forward_delay:
|
||||
{
|
||||
quint32 forwardDelay = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data_.set_forward_delay(forwardDelay);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return isOk;
|
||||
}
|
110
common/stp.h
Normal file
110
common/stp.h
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
Copyright (C) 2014 PLVision.
|
||||
|
||||
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/>
|
||||
|
||||
This module is developed by PLVision <developers@plvision.eu>
|
||||
*/
|
||||
|
||||
#ifndef _STP_H
|
||||
#define _STP_H
|
||||
|
||||
#include "abstractprotocol.h"
|
||||
#include "stp.pb.h"
|
||||
|
||||
/*
|
||||
Stp Protocol Frame Format -
|
||||
+------------------------------------+------------------+------------------+
|
||||
| Protocol ID | Protocol VID | BPDU type |
|
||||
| (16) | (8) | (8) |
|
||||
+------------------+-----------------+------------------+------------------+
|
||||
| Flags | Root Identifier ->|
|
||||
| (8) | (64) ->|
|
||||
+------------------+-------------------------------------------------------+
|
||||
|-> Root Identifier ->|
|
||||
|-> (64) ->|
|
||||
+------------------+-------------------------------------------------------+
|
||||
|-> Root Identifier| Root Path Cost ->|
|
||||
|-> (8) | (32) ->|
|
||||
+------------------+-------------------------------------------------------+
|
||||
|-> Root Path Cost | Bridge Identifier ->|
|
||||
|-> (32) | (64) ->|
|
||||
+------------------+-------------------------------------------------------+
|
||||
|-> Bridge Identifier ->|
|
||||
|-> (64) ->|
|
||||
+------------------+--------------------------------- --+------------------+
|
||||
|-> Bridge Identif.| Port Identifier | Message Age ->|
|
||||
|-> (64) | (16) | (16) ->|
|
||||
+------------------+------------------------------------+------------------+
|
||||
|-> Message Age | Max Age | Hello Time ->|
|
||||
|-> (16) | (16) | (16) ->|
|
||||
+------------------+------------------------------------+------------------+
|
||||
|-> Hello Time | Forward delay |
|
||||
|-> (16) | (16) |
|
||||
+------------------+------------------------------------+
|
||||
Figures in brackets represent field width in bits
|
||||
*/
|
||||
|
||||
class StpProtocol : public AbstractProtocol
|
||||
{
|
||||
public:
|
||||
enum stpfield
|
||||
{
|
||||
stp_protocol_id = 0,
|
||||
stp_version_id,
|
||||
stp_bpdu_type,
|
||||
stp_flags,
|
||||
stp_root_id,
|
||||
stp_root_path_cost,
|
||||
stp_bridge_id,
|
||||
stp_port_id,
|
||||
stp_message_age,
|
||||
stp_max_age,
|
||||
stp_hello_time,
|
||||
stp_forward_delay,
|
||||
|
||||
stp_fieldCount
|
||||
};
|
||||
|
||||
StpProtocol(StreamBase *stream, AbstractProtocol *parent = 0);
|
||||
virtual ~StpProtocol();
|
||||
|
||||
static AbstractProtocol* createInstance(StreamBase *stream,
|
||||
AbstractProtocol *parent = 0);
|
||||
virtual quint32 protocolNumber() const;
|
||||
|
||||
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
|
||||
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
|
||||
|
||||
virtual quint32 protocolId(ProtocolIdType type) const;
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString shortName() const;
|
||||
|
||||
virtual int fieldCount() const;
|
||||
|
||||
virtual AbstractProtocol::FieldFlags fieldFlags(int index) const;
|
||||
virtual QVariant fieldData(int index, FieldAttrib attrib,
|
||||
int streamIndex = 0) const;
|
||||
virtual bool setFieldData(int index, const QVariant &value,
|
||||
FieldAttrib attrib = FieldValue);
|
||||
|
||||
|
||||
private:
|
||||
OstProto::Stp data_;
|
||||
};
|
||||
|
||||
#endif
|
44
common/stp.proto
Normal file
44
common/stp.proto
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
Copyright (C) 2014 PLVision.
|
||||
|
||||
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/>
|
||||
|
||||
This module is developed by PLVision <developers@plvision.eu>
|
||||
*/
|
||||
|
||||
import "protocol.proto";
|
||||
|
||||
package OstProto;
|
||||
|
||||
// Spanning Tree Protocol
|
||||
message Stp {
|
||||
optional uint32 protocol_id = 1 [default = 0x0000];
|
||||
optional uint32 protocol_version_id = 2 [default = 0x00];
|
||||
optional uint32 bpdu_type = 3 [default = 0x00];
|
||||
optional uint32 flags = 4;
|
||||
optional uint64 root_id = 5;
|
||||
optional uint32 root_path_cost = 6;
|
||||
optional uint64 bridge_id = 7;
|
||||
optional uint32 port_id = 8;
|
||||
optional uint32 message_age = 9;
|
||||
optional uint32 max_age = 10;
|
||||
optional uint32 hello_time = 11;
|
||||
optional uint32 forward_delay = 12;
|
||||
}
|
||||
|
||||
extend Protocol {
|
||||
optional Stp stp = 210;
|
||||
}
|
507
common/stp.ui
Normal file
507
common/stp.ui
Normal file
@ -0,0 +1,507 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Stp</class>
|
||||
<widget class="QWidget" name="Stp">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>615</width>
|
||||
<height>378</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_22">
|
||||
<property name="text">
|
||||
<string>Protocol Identifier</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLineEdit" name="ui_protocol_id">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="cursorPosition">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_24">
|
||||
<property name="text">
|
||||
<string>Version Identifier</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>ui_version_id</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLineEdit" name="ui_version_id">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="cursorPosition">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLineEdit" name="ui_bpdu_type">
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>3</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_27">
|
||||
<property name="text">
|
||||
<string>BPDU Type</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ui_flags_tc_check">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TC</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ui_flags_tca_check">
|
||||
<property name="text">
|
||||
<string>TCA</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>BPDU Flags</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Root Identifier</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="ui_root_id">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="inputMask">
|
||||
<string>>HH HH HH HH HH HH; </string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string> </string>
|
||||
</property>
|
||||
<property name="cursorPosition">
|
||||
<number>17</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Priority</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="ui_root_id_priority">
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="text">
|
||||
<string>MAC Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Path Cost</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="ui_root_path_cost">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>10</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Bridge Identifier</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="ui_bridge_id">
|
||||
<property name="inputMask">
|
||||
<string>>HH HH HH HH HH HH; </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="text">
|
||||
<string>Priority</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_17">
|
||||
<property name="text">
|
||||
<string>MAC Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="ui_bridge_id_priority">
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>Port Identifier</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="ui_port_id_number">
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>3</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>Number</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Priority</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="ui_port_id_priority">
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>3</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<property name="title">
|
||||
<string>Timers</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Message Age (1/256s)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="ui_message_age">
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Max Age (1/256s)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="ui_max_age">
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Hello Time (1/256s)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="ui_hello_time">
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>Forward Delay (1/256s)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="ui_forward_delay">
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder></zorder>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>groupBox_4</zorder>
|
||||
<zorder></zorder>
|
||||
<zorder>verticalSpacer_3</zorder>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>ui_protocol_id</tabstop>
|
||||
<tabstop>ui_version_id</tabstop>
|
||||
<tabstop>ui_bpdu_type</tabstop>
|
||||
<tabstop>ui_flags_tc_check</tabstop>
|
||||
<tabstop>ui_flags_tca_check</tabstop>
|
||||
<tabstop>ui_root_id_priority</tabstop>
|
||||
<tabstop>ui_root_id</tabstop>
|
||||
<tabstop>ui_root_path_cost</tabstop>
|
||||
<tabstop>ui_bridge_id_priority</tabstop>
|
||||
<tabstop>ui_bridge_id</tabstop>
|
||||
<tabstop>ui_port_id_priority</tabstop>
|
||||
<tabstop>ui_port_id_number</tabstop>
|
||||
<tabstop>ui_message_age</tabstop>
|
||||
<tabstop>ui_max_age</tabstop>
|
||||
<tabstop>ui_hello_time</tabstop>
|
||||
<tabstop>ui_forward_delay</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
257
common/stpconfig.cpp
Normal file
257
common/stpconfig.cpp
Normal file
@ -0,0 +1,257 @@
|
||||
/*
|
||||
Copyright (C) 2014 PLVision.
|
||||
|
||||
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/>
|
||||
|
||||
This module is developed by PLVision <developers@plvision.eu>
|
||||
*/
|
||||
|
||||
#include "stpconfig.h"
|
||||
#include "stp.h"
|
||||
|
||||
#include <QRegExpValidator>
|
||||
#include <QIntValidator>
|
||||
|
||||
#define ONE_BYTE_MAX 255
|
||||
#define TWO_BYTE_MAX 65535
|
||||
#define FOUR_BYTE_MAX 4294967295U
|
||||
#define BIT_0 0
|
||||
#define BIT_7 7
|
||||
#define ONE_BIT(pos) ((unsigned int)(1 << (pos)))
|
||||
#define BYTES(byte) (byte * sizeof(unsigned char))
|
||||
#define STR_BYTES_LEN(len) (BYTES(len) * 2)
|
||||
|
||||
class UNumberValidator : public QValidator
|
||||
{
|
||||
private:
|
||||
quint64 min_;
|
||||
quint64 max_;
|
||||
|
||||
public:
|
||||
UNumberValidator(quint64 min, quint64 max, QObject * parent = 0)
|
||||
: QValidator(parent), min_(min), max_(max){}
|
||||
virtual ~UNumberValidator(){}
|
||||
|
||||
virtual QValidator::State validate(QString& input, int& pos) const
|
||||
{
|
||||
QValidator::State state = QValidator::Acceptable;
|
||||
quint64 val = input.toULongLong();
|
||||
if(val < min_ || val > max_)
|
||||
state = QValidator::Invalid;
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
StpConfigForm::StpConfigForm(QWidget *parent)
|
||||
: AbstractProtocolConfigForm(parent)
|
||||
{
|
||||
QRegExp reMac("([0-9,a-f,A-F]{2,2}[:-]){5,5}[0-9,a-f,A-F]{2,2}");
|
||||
setupUi(this);
|
||||
|
||||
QRegExpValidator *validateMACAddress =
|
||||
new QRegExpValidator(reMac, this);
|
||||
UNumberValidator *validateByte =
|
||||
new UNumberValidator(0, ONE_BYTE_MAX, this);
|
||||
UNumberValidator *validate2Byte =
|
||||
new UNumberValidator(0, TWO_BYTE_MAX, this);
|
||||
UNumberValidator *validate4Byte =
|
||||
new UNumberValidator(0, FOUR_BYTE_MAX, this);
|
||||
|
||||
ui_protocol_id->setValidator(validate2Byte);
|
||||
ui_version_id->setValidator(validateByte);
|
||||
|
||||
ui_bpdu_type->setValidator(validateByte);
|
||||
|
||||
ui_root_id_priority->setValidator(validate2Byte);
|
||||
ui_root_id->setValidator(validateMACAddress);
|
||||
|
||||
ui_root_path_cost->setValidator(validate4Byte);
|
||||
|
||||
ui_bridge_id_priority->setValidator(validate2Byte);
|
||||
ui_bridge_id->setValidator(validateMACAddress);
|
||||
|
||||
ui_port_id_priority->setValidator(validateByte);
|
||||
ui_port_id_number->setValidator(validateByte);
|
||||
|
||||
ui_message_age->setValidator(validate2Byte);
|
||||
ui_max_age->setValidator(validate2Byte);
|
||||
ui_hello_time->setValidator(validate2Byte);
|
||||
ui_forward_delay->setValidator(validate2Byte);
|
||||
}
|
||||
|
||||
StpConfigForm::~StpConfigForm()
|
||||
{
|
||||
}
|
||||
|
||||
StpConfigForm* StpConfigForm::createInstance()
|
||||
{
|
||||
return new StpConfigForm;
|
||||
}
|
||||
|
||||
void StpConfigForm::loadWidget(AbstractProtocol *proto)
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
ui_protocol_id->setText(
|
||||
proto->fieldData(
|
||||
StpProtocol::stp_protocol_id,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
ui_version_id->setText(
|
||||
proto->fieldData(
|
||||
StpProtocol::stp_version_id,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
ui_bpdu_type->setText(
|
||||
proto->fieldData(
|
||||
StpProtocol::stp_bpdu_type,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
|
||||
quint8 flags = proto->fieldData(
|
||||
StpProtocol::stp_flags,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt();
|
||||
ui_flags_tc_check->setChecked(flags & ONE_BIT(BIT_0));
|
||||
ui_flags_tca_check->setChecked(flags & ONE_BIT(BIT_7));
|
||||
|
||||
// root priority value stored as the first two bytes of stp_root_id
|
||||
// and the last 6 bytes are root MAC address (IEEE802.1D-2008)
|
||||
quint64 rootId = proto->fieldData(
|
||||
StpProtocol::stp_root_id,
|
||||
AbstractProtocol::FieldValue
|
||||
).toULongLong(&isOk);
|
||||
|
||||
ui_root_id->setText(
|
||||
QString::number(rootId & 0x0000FFFFFFFFFFFFULL, BASE_HEX));
|
||||
ui_root_id_priority->setText(QString::number(rootId >> 48));
|
||||
|
||||
ui_root_path_cost->setText(
|
||||
proto->fieldData(
|
||||
StpProtocol::stp_root_path_cost,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
|
||||
// bridge priority value stored as the first two bytes of stp_bridge_id
|
||||
// and the last 6 bytes are bridge MAC address (IEEE802.1D-2008)
|
||||
quint64 bridgeId = proto->fieldData(
|
||||
StpProtocol::stp_bridge_id,
|
||||
AbstractProtocol::FieldValue
|
||||
).toULongLong(&isOk);
|
||||
|
||||
ui_bridge_id->setText(
|
||||
QString::number(bridgeId & 0x0000FFFFFFFFFFFFULL, BASE_HEX));
|
||||
ui_bridge_id_priority->setText(QString::number(bridgeId >> 48));
|
||||
|
||||
// port priority is a first byte of stp_port_id field
|
||||
// and port ID is a second byte (IEEE802.1D-2008)
|
||||
uint portId = proto->fieldData(
|
||||
StpProtocol::stp_port_id,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt(&isOk);
|
||||
|
||||
ui_port_id_priority->setText(QString::number(portId >> 8));
|
||||
ui_port_id_number->setText(QString::number(portId & ONE_BYTE_MAX));
|
||||
|
||||
ui_message_age->setText(
|
||||
proto->fieldData(
|
||||
StpProtocol::stp_message_age,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
ui_max_age->setText(
|
||||
proto->fieldData(
|
||||
StpProtocol::stp_max_age,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
ui_hello_time->setText(
|
||||
proto->fieldData(
|
||||
StpProtocol::stp_hello_time,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
ui_forward_delay->setText(
|
||||
proto->fieldData(
|
||||
StpProtocol::stp_forward_delay,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
}
|
||||
|
||||
void StpConfigForm::storeWidget(AbstractProtocol *proto)
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
proto->setFieldData(
|
||||
StpProtocol::stp_protocol_id,
|
||||
QString("%1").arg(
|
||||
ui_protocol_id->text().toUInt(&isOk) & TWO_BYTE_MAX));
|
||||
|
||||
proto->setFieldData(
|
||||
StpProtocol::stp_version_id,
|
||||
ui_version_id->text());
|
||||
proto->setFieldData(
|
||||
StpProtocol::stp_bpdu_type,
|
||||
ui_bpdu_type->text());
|
||||
|
||||
char flags = 0;
|
||||
if (ui_flags_tc_check->isChecked()) flags = flags | ONE_BIT(BIT_0);
|
||||
if (ui_flags_tca_check->isChecked()) flags = flags | ONE_BIT(BIT_7);
|
||||
proto->setFieldData(StpProtocol::stp_flags, flags);
|
||||
|
||||
// root priority value stored as the first two bytes of stp_root_id
|
||||
// and the last 6 bytes are root MAC address (IEEE802.1D-2008)
|
||||
quint64 rootIdPrio = ui_root_id_priority->text()
|
||||
.toULongLong(&isOk) & TWO_BYTE_MAX;
|
||||
quint64 rootId = hexStrToUInt64(
|
||||
ui_root_id->text()) | rootIdPrio << 48;
|
||||
proto->setFieldData(StpProtocol::stp_root_id, rootId);
|
||||
|
||||
proto->setFieldData(
|
||||
StpProtocol::stp_root_path_cost,
|
||||
ui_root_path_cost->text());
|
||||
|
||||
// bridge priority value stored as the first two bytes of stp_bridge_id
|
||||
// and the last 6 bytes are bridge MAC address (IEEE802.1D-2008)
|
||||
quint64 bridgeIdPrio =
|
||||
ui_bridge_id_priority->text().toULongLong(&isOk) & TWO_BYTE_MAX;
|
||||
quint64 bridgeId =
|
||||
hexStrToUInt64(ui_bridge_id->text()) | bridgeIdPrio << 48;
|
||||
proto->setFieldData(StpProtocol::stp_bridge_id, bridgeId);
|
||||
|
||||
// port priority is a first byte of stp_port_id field
|
||||
// and port ID is a second byte (IEEE802.1D-2008)
|
||||
ushort portIdPrio =
|
||||
ui_port_id_priority->text().toUInt(&isOk, BASE_DEC) & ONE_BYTE_MAX;
|
||||
ushort portId =
|
||||
ui_port_id_number->text().toUInt(&isOk, BASE_DEC) & ONE_BYTE_MAX;
|
||||
proto->setFieldData(StpProtocol::stp_port_id, portIdPrio << 8 | portId);
|
||||
// timers
|
||||
proto->setFieldData(
|
||||
StpProtocol::stp_message_age,
|
||||
ui_message_age->text().toUInt(&isOk, BASE_DEC) & TWO_BYTE_MAX);
|
||||
proto->setFieldData(
|
||||
StpProtocol::stp_max_age,
|
||||
QString("%1").arg(
|
||||
ui_max_age->text().toUInt(&isOk, BASE_DEC) & TWO_BYTE_MAX));
|
||||
proto->setFieldData(
|
||||
StpProtocol::stp_hello_time,
|
||||
QString("%1").arg(
|
||||
ui_hello_time->text().toUInt(&isOk, BASE_DEC) & TWO_BYTE_MAX));
|
||||
proto->setFieldData(
|
||||
StpProtocol::stp_forward_delay,
|
||||
QString("%1").arg(
|
||||
ui_forward_delay->text().toUInt(&isOk, BASE_DEC) & TWO_BYTE_MAX));
|
||||
}
|
||||
|
43
common/stpconfig.h
Normal file
43
common/stpconfig.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright (C) 2014 PLVision.
|
||||
|
||||
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/>
|
||||
|
||||
This module is developed by PLVision <developers@plvision.eu>
|
||||
*/
|
||||
|
||||
#ifndef _STP_CONFIG_H
|
||||
#define _STP_CONFIG_H
|
||||
|
||||
#include "abstractprotocolconfig.h"
|
||||
#include "ui_stp.h"
|
||||
|
||||
class StpConfigForm :
|
||||
public AbstractProtocolConfigForm,
|
||||
private Ui::Stp
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
StpConfigForm(QWidget *parent = 0);
|
||||
virtual ~StpConfigForm();
|
||||
|
||||
static StpConfigForm* createInstance();
|
||||
|
||||
virtual void loadWidget(AbstractProtocol *proto);
|
||||
virtual void storeWidget(AbstractProtocol *proto);
|
||||
};
|
||||
|
||||
#endif
|
76
common/stppdml.cpp
Normal file
76
common/stppdml.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
Copyright (C) 2014 PLVision.
|
||||
|
||||
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/>
|
||||
|
||||
This module is developed by PLVision <developers@plvision.eu>
|
||||
*/
|
||||
|
||||
#include "stppdml.h"
|
||||
|
||||
#include "stp.pb.h"
|
||||
|
||||
#define ROOT_IDENTIFIER_POS 22
|
||||
#define BRIDGE_IDENTIFIER_POS 34
|
||||
#define BASE_DEC 10
|
||||
#define BASE_HEX 16
|
||||
|
||||
PdmlStpProtocol::PdmlStpProtocol()
|
||||
{
|
||||
ostProtoId_ = OstProto::Protocol::kStpFieldNumber;
|
||||
|
||||
fieldMap_.insert("stp.protocol",
|
||||
OstProto::Stp::kProtocolIdFieldNumber);
|
||||
fieldMap_.insert("stp.version",
|
||||
OstProto::Stp::kProtocolVersionIdFieldNumber);
|
||||
fieldMap_.insert("stp.type", OstProto::Stp::kBpduTypeFieldNumber);
|
||||
fieldMap_.insert("stp.flags", OstProto::Stp::kFlagsFieldNumber);
|
||||
fieldMap_.insert("stp.root.cost", OstProto::Stp::kRootPathCostFieldNumber);
|
||||
fieldMap_.insert("stp.port", OstProto::Stp::kPortIdFieldNumber);
|
||||
fieldMap_.insert("stp.msg_age", OstProto::Stp::kMessageAgeFieldNumber);
|
||||
fieldMap_.insert("stp.max_age", OstProto::Stp::kMaxAgeFieldNumber);
|
||||
fieldMap_.insert("stp.hello", OstProto::Stp::kHelloTimeFieldNumber);
|
||||
fieldMap_.insert("stp.forward", OstProto::Stp::kForwardDelayFieldNumber);
|
||||
}
|
||||
|
||||
PdmlStpProtocol::~PdmlStpProtocol()
|
||||
{
|
||||
}
|
||||
|
||||
PdmlProtocol* PdmlStpProtocol::createInstance()
|
||||
{
|
||||
return new PdmlStpProtocol();
|
||||
}
|
||||
|
||||
void PdmlStpProtocol::unknownFieldHandler(
|
||||
QString name, int pos, int /*size*/,
|
||||
const QXmlStreamAttributes &attributes, OstProto::Protocol *pbProto,
|
||||
OstProto::Stream* /*stream*/)
|
||||
{
|
||||
bool isOk;
|
||||
OstProto::Stp *stp = pbProto->MutableExtension(OstProto::stp);
|
||||
|
||||
if ((name == "") && (pos == ROOT_IDENTIFIER_POS))
|
||||
{
|
||||
stp->set_root_id(attributes.value("value").toString().
|
||||
toULongLong(&isOk, BASE_HEX));
|
||||
}
|
||||
if ((name == "") && (pos == BRIDGE_IDENTIFIER_POS))
|
||||
{
|
||||
stp->set_bridge_id(attributes.value("value").toString().
|
||||
toULongLong(&isOk, BASE_HEX));
|
||||
}
|
||||
}
|
42
common/stppdml.h
Normal file
42
common/stppdml.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
Copyright (C) 2014 PLVision.
|
||||
|
||||
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/>
|
||||
|
||||
This module is developed by PLVision <developers@plvision.eu>
|
||||
*/
|
||||
|
||||
#ifndef _STP_PDML_H
|
||||
#define _STP_PDML_H
|
||||
|
||||
#include "pdmlprotocol.h"
|
||||
|
||||
class PdmlStpProtocol : public PdmlProtocol
|
||||
{
|
||||
public:
|
||||
virtual ~PdmlStpProtocol();
|
||||
|
||||
static PdmlProtocol *createInstance();
|
||||
|
||||
void unknownFieldHandler(QString name, int pos, int size,
|
||||
const QXmlStreamAttributes &attributes,
|
||||
OstProto::Protocol *pbProto, OstProto::Stream* stream);
|
||||
|
||||
protected:
|
||||
PdmlStpProtocol();
|
||||
};
|
||||
|
||||
#endif
|
27
ost.pro
27
ost.pro
@ -1,11 +1,20 @@
|
||||
TEMPLATE = subdirs
|
||||
CONFIG += ordered
|
||||
SUBDIRS = \
|
||||
extra \
|
||||
rpc/pbrpc.pro \
|
||||
common/ostproto.pro \
|
||||
common/ostprotogui.pro \
|
||||
server/drone.pro \
|
||||
client/ostinato.pro \
|
||||
binding/binding.pro
|
||||
SUBDIRS = client server ostproto ostprotogui rpc binding extra
|
||||
|
||||
client.target = client
|
||||
client.file = client/ostinato.pro
|
||||
client.depends = ostproto ostprotogui rpc extra
|
||||
|
||||
server.target = server
|
||||
server.file = server/drone.pro
|
||||
server.depends = ostproto rpc
|
||||
|
||||
ostproto.file = common/ostproto.pro
|
||||
|
||||
ostprotogui.file = common/ostprotogui.pro
|
||||
ostprotogui.depends = extra
|
||||
|
||||
rpc.file = rpc/pbrpc.pro
|
||||
|
||||
binding.target = binding
|
||||
binding.depends = ostproto
|
||||
|
@ -256,6 +256,11 @@ _top:
|
||||
}
|
||||
|
||||
case PB_MSG_TYPE_RESPONSE:
|
||||
{
|
||||
static quint32 cumLen = 0;
|
||||
static QByteArray buffer;
|
||||
int l = 0;
|
||||
|
||||
if (!isPending)
|
||||
{
|
||||
qWarning("not waiting for response");
|
||||
@ -269,8 +274,35 @@ _top:
|
||||
goto _error_exit;
|
||||
}
|
||||
|
||||
msgLen = 0;
|
||||
while (cumLen < len)
|
||||
{
|
||||
if (inStream->Next((const void**)&msg, &msgLen) == false) {
|
||||
//qDebug("No more data or stream error");
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
l = qMin(msgLen, int(len - cumLen));
|
||||
buffer.append(QByteArray((char*)msg, l));
|
||||
cumLen += l;
|
||||
//qDebug("%s: buffer rcvd %d/%d/%d", __PRETTY_FUNCTION__, l, cumLen, len);
|
||||
}
|
||||
|
||||
if (l < msgLen) {
|
||||
qDebug("read extra bytes after response; putting back");
|
||||
inStream->BackUp(msgLen - l);
|
||||
}
|
||||
|
||||
#if 0 // not needed?
|
||||
if (cumLen < len)
|
||||
goto _exit;
|
||||
#endif
|
||||
|
||||
if (len)
|
||||
response->ParseFromBoundedZeroCopyStream(inStream, len);
|
||||
response->ParseFromArray((const void*)buffer, len);
|
||||
|
||||
cumLen = 0;
|
||||
buffer.resize(0);
|
||||
|
||||
// Avoid printing stats
|
||||
if (method != 13)
|
||||
@ -290,7 +322,7 @@ _top:
|
||||
controller->SetFailed("Required fields missing");
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
case PB_MSG_TYPE_ERROR:
|
||||
{
|
||||
static quint32 cumLen = 0;
|
||||
|
@ -81,6 +81,8 @@ LinuxPort::~LinuxPort()
|
||||
{
|
||||
qDebug("In %s", __FUNCTION__);
|
||||
|
||||
allPorts_.removeAll(this);
|
||||
|
||||
if (monitor_->isRunning())
|
||||
{
|
||||
monitor_->stop();
|
||||
|
@ -105,6 +105,10 @@ def ports(request, drone):
|
||||
ports.rx = ost_pb.PortIdList()
|
||||
ports.rx.port_id.add().id = rx_number;
|
||||
|
||||
# stop transmit/capture on ports, if any
|
||||
drone.stopTransmit(ports.tx)
|
||||
drone.stopCapture(ports.rx)
|
||||
|
||||
# delete existing streams, if any, on tx port
|
||||
sid_list = drone.getStreamIdList(ports.tx.port_id[0])
|
||||
drone.deleteStream(sid_list)
|
||||
@ -181,12 +185,13 @@ def test_packet_length(drone, ports, stream, mode):
|
||||
buff = drone.getCaptureBuffer(ports.rx.port_id[0])
|
||||
drone.saveCaptureBuffer(buff, 'capture.pcap')
|
||||
log.info('dumping Rx capture buffer')
|
||||
cap_pkts = subprocess.check_output([tshark, '-n', '-r', 'capture.pcap',
|
||||
'-R', 'udp'])
|
||||
cap_pkts = subprocess.check_output([tshark, '-n', '-r', 'capture.pcap'])
|
||||
print(cap_pkts)
|
||||
cap_pkts = subprocess.check_output([tshark, '-n', '-r', 'capture.pcap',
|
||||
'-R', 'udp', '-o', fmt])
|
||||
print(cap_pkts)
|
||||
result = extract_column(cap_pkts, fmt_col)
|
||||
print(result)
|
||||
diffSum = 0
|
||||
for i in range(len(result)):
|
||||
l = int(result[i]) + 4 # add FCS to length
|
||||
|
@ -8,6 +8,7 @@ import sys
|
||||
import time
|
||||
|
||||
sys.path.insert(1, '../binding')
|
||||
import core
|
||||
from core import ost_pb, DroneProxy
|
||||
from rpc import RpcError
|
||||
from protocols.mac_pb2 import mac
|
||||
@ -115,7 +116,8 @@ try:
|
||||
passed = False
|
||||
suite.test_begin('connectFailsForIncompatibleVersion')
|
||||
try:
|
||||
drone.proxy_version = '0.1.1'
|
||||
orig_version = core.__version__
|
||||
core.__version__ = '0.1.1'
|
||||
drone.connect()
|
||||
except RpcError as e:
|
||||
if ('needs client version' in str(e)):
|
||||
@ -124,7 +126,7 @@ try:
|
||||
else:
|
||||
raise
|
||||
finally:
|
||||
drone.proxy_version = None
|
||||
core.__version__ = orig_version
|
||||
suite.test_end(passed)
|
||||
|
||||
# ----------------------------------------------------------------- #
|
||||
@ -133,7 +135,8 @@ try:
|
||||
passed = False
|
||||
suite.test_begin('checkVersionFailsForInvalidClientVersion')
|
||||
try:
|
||||
drone.proxy_version = '0-1-1'
|
||||
orig_version = core.__version__
|
||||
core.__version__ = '0-1-1'
|
||||
drone.connect()
|
||||
except RpcError as e:
|
||||
if ('invalid version' in str(e)):
|
||||
@ -141,7 +144,7 @@ try:
|
||||
else:
|
||||
raise
|
||||
finally:
|
||||
drone.proxy_version = None
|
||||
core.__version__ = orig_version
|
||||
suite.test_end(passed)
|
||||
|
||||
# ----------------------------------------------------------------- #
|
||||
@ -153,7 +156,8 @@ try:
|
||||
passed = False
|
||||
suite.test_begin('checkVersionReturnsIncompatForDifferentMajorVersion')
|
||||
try:
|
||||
drone.proxy_version = (str(int(drone_version[0])+1)
|
||||
orig_version = core.__version__
|
||||
core.__version__ = (str(int(drone_version[0])+1)
|
||||
+ '.' + drone_version[1])
|
||||
drone.connect()
|
||||
except RpcError as e:
|
||||
@ -163,7 +167,7 @@ try:
|
||||
else:
|
||||
raise
|
||||
finally:
|
||||
drone.proxy_version = None
|
||||
core.__version__ = orig_version
|
||||
suite.test_end(passed)
|
||||
|
||||
# ----------------------------------------------------------------- #
|
||||
@ -175,7 +179,8 @@ try:
|
||||
passed = False
|
||||
suite.test_begin('checkVersionReturnsIncompatForDifferentMinorVersion')
|
||||
try:
|
||||
drone.proxy_version = (drone_version[0]
|
||||
orig_version = core.__version__
|
||||
core.__version__ = (drone_version[0]
|
||||
+ '.' + str(int(drone_version[1])+1))
|
||||
drone.connect()
|
||||
except RpcError as e:
|
||||
@ -185,7 +190,7 @@ try:
|
||||
else:
|
||||
raise
|
||||
finally:
|
||||
drone.proxy_version = None
|
||||
core.__version__ = orig_version
|
||||
suite.test_end(passed)
|
||||
|
||||
# ----------------------------------------------------------------- #
|
||||
@ -196,7 +201,8 @@ try:
|
||||
passed = False
|
||||
suite.test_begin('checkVersionReturnsCompatForDifferentRevisionVersion')
|
||||
try:
|
||||
drone.proxy_version = (drone_version[0]
|
||||
orig_version = core.__version__
|
||||
core.__version__ = (drone_version[0]
|
||||
+ '.' + drone_version[1]
|
||||
+ '.' + '999')
|
||||
drone.connect()
|
||||
@ -204,7 +210,8 @@ try:
|
||||
except RpcError as e:
|
||||
raise
|
||||
finally:
|
||||
drone.proxy_version = None
|
||||
drone.disconnect()
|
||||
core.__version__ = orig_version
|
||||
suite.test_end(passed)
|
||||
|
||||
# ----------------------------------------------------------------- #
|
||||
@ -294,29 +301,28 @@ try:
|
||||
drone.clearStats(rx_port)
|
||||
|
||||
# ----------------------------------------------------------------- #
|
||||
# TODO:
|
||||
# TESTCASE: Verify a RPC with missing required fields in request fails
|
||||
# and subsequently passes when the fields are initialized
|
||||
# ----------------------------------------------------------------- #
|
||||
# passed = False
|
||||
# suite.test_begin('rpcWithMissingRequiredFieldsFails')
|
||||
# pid = ost_pb.PortId()
|
||||
# try:
|
||||
# sid_list = drone.getStreamIdList(pid)
|
||||
# except RpcError as e:
|
||||
# if ('missing required fields in request' in str(e)):
|
||||
# passed = True
|
||||
# else:
|
||||
# raise
|
||||
#
|
||||
# try:
|
||||
# pid.id = tx_port_number
|
||||
# sid_list = drone.getStreamIdList(pid)
|
||||
# except RpcError as e:
|
||||
# passed = False
|
||||
# raise
|
||||
# finally:
|
||||
# suite.test_end(passed)
|
||||
passed = False
|
||||
suite.test_begin('rpcWithMissingRequiredFieldsFails')
|
||||
pid = ost_pb.PortId()
|
||||
try:
|
||||
sid_list = drone.getStreamIdList(pid)
|
||||
except RpcError as e:
|
||||
if ('missing required fields in request' in str(e)):
|
||||
passed = True
|
||||
log.info("Retrying RPC after adding the missing fields")
|
||||
pid.id = tx_port_number
|
||||
try:
|
||||
sid_list = drone.getStreamIdList(pid)
|
||||
except:
|
||||
passed = False
|
||||
raise
|
||||
else:
|
||||
raise
|
||||
finally:
|
||||
suite.test_end(passed)
|
||||
|
||||
# ----------------------------------------------------------------- #
|
||||
# TESTCASE: Verify invoking addStream() during transmit fails
|
||||
@ -379,7 +385,6 @@ try:
|
||||
drone.stopTransmit(tx_port)
|
||||
suite.test_end(passed)
|
||||
|
||||
|
||||
# ----------------------------------------------------------------- #
|
||||
# TESTCASE: Verify invoking startTransmit() during transmit is a NOP,
|
||||
# not a restart
|
||||
@ -417,7 +422,6 @@ try:
|
||||
drone.stopTransmit(tx_port)
|
||||
suite.test_end(passed)
|
||||
|
||||
|
||||
# ----------------------------------------------------------------- #
|
||||
# TESTCASE: Verify invoking startCapture() during capture is a NOP,
|
||||
# not a restart
|
||||
|
Loading…
Reference in New Issue
Block a user