ostinato/common/snap.cpp
Srivats P. 2ec7fb30c2 Protocol Framework basic code in place now. Cleanup pending.
- New Classes:
  o ProtocolManager - singleton with which all protocols register
  o ProtocolCollection - Aggregates all registered protocols; exports methods to work on all protocols
  o StreamBase - aggregates ProtocolCollection with Stream Core and Control; the client/server side stream classes now derive from StreamBase leading to major reduction in their code (more cleanup pending)
- AbstractProtocol now supports the additional methods
  o createInstance()
  o protocolFrameSize()
  o protocolFrameOffset(), protocolFramePayloadSize()
  o protocolId(), payloadProtocolId()
  o protocolFrameCksum(), protocolFramePayloadCksum()
  0 constructor takes an extra param - frameProtoList
- Specific protocols - eth2, llc, snap, ip4, udp, tcp now return length, protocol id and cksums correctly (tcp/udp cksum pending)
- StreamConfigDialog - protocol controls for length, cksum and protocolid are automatically updated (not fully working yet)
2009-05-10 06:27:17 +00:00

162 lines
3.1 KiB
C++

#include <qendian.h>
#include <QHostAddress>
#include "snap.h"
SnapConfigForm *SnapProtocol::configForm = NULL;
SnapConfigForm::SnapConfigForm(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
}
SnapProtocol::SnapProtocol(
ProtocolList &frameProtoList,
OstProto::StreamCore *parent)
: AbstractProtocol(frameProtoList, parent)
{
if (configForm == NULL)
configForm = new SnapConfigForm;
}
SnapProtocol::~SnapProtocol()
{
}
AbstractProtocol* SnapProtocol::createInstance(
ProtocolList &frameProtoList,
OstProto::StreamCore *streamCore)
{
return new SnapProtocol(frameProtoList, streamCore);
}
void SnapProtocol::protoDataCopyInto(OstProto::Stream &stream)
{
// FIXME: multiple headers
stream.MutableExtension(OstProto::snap)->CopyFrom(data);
}
void SnapProtocol::protoDataCopyFrom(const OstProto::Stream &stream)
{
// FIXME: multiple headers
if (stream.HasExtension(OstProto::snap))
data.MergeFrom(stream.GetExtension(OstProto::snap));
}
QString SnapProtocol::name() const
{
return QString("SubNetwork Access Protocol");
}
QString SnapProtocol::shortName() const
{
return QString("SNAP");
}
quint32 SnapProtocol::protocolId(ProtocolIdType type) const
{
switch(type)
{
case ProtocolIdLlc: return 0xAAAA03;
default: break;
}
return AbstractProtocol::protocolId(type);
}
int SnapProtocol::fieldCount() const
{
return snap_fieldCount;
}
QVariant SnapProtocol::fieldData(int index, FieldAttrib attrib,
int streamIndex) const
{
switch (index)
{
case snap_oui:
switch(attrib)
{
case FieldName:
return QString("OUI");
case FieldValue:
return data.oui();
case FieldTextValue:
return QString("%1").arg(data.oui(), 6, BASE_HEX, QChar('0'));
case FieldFrameValue:
{
QByteArray fv;
fv.resize(4);
qToBigEndian((quint32) data.oui(), (uchar*) fv.data());
fv.remove(0, 1);
return fv;
}
default:
break;
}
break;
case snap_type:
{
quint16 type;
switch(attrib)
{
case FieldName:
return QString("Type");
case FieldValue:
type = payloadProtocolId(ProtocolIdEth);
return type;
case FieldTextValue:
type = payloadProtocolId(ProtocolIdEth);
return QString("%1").arg(type, 4, BASE_HEX, QChar('0'));
case FieldFrameValue:
{
QByteArray fv;
fv.resize(2);
type = payloadProtocolId(ProtocolIdEth);
qToBigEndian(type, (uchar*) fv.data());
return fv;
}
default:
break;
}
break;
}
default:
break;
}
return AbstractProtocol::fieldData(index, attrib, streamIndex);
}
bool SnapProtocol::setFieldData(int index, const QVariant &value,
FieldAttrib attrib)
{
// FIXME
return false;
}
QWidget* SnapProtocol::configWidget()
{
return configForm;
}
void SnapProtocol::loadConfigWidget()
{
configForm->leOui->setText(uintToHexStr(
fieldData(snap_oui, FieldValue).toUInt(), 3));
configForm->leType->setText(uintToHexStr(
fieldData(snap_type, FieldValue).toUInt(), 2));
}
void SnapProtocol::storeConfigWidget()
{
bool isOk;
data.set_oui(configForm->leOui->text().toULong(&isOk, BASE_HEX));
data.set_type(configForm->leType->text().toULong(&isOk, BASE_HEX));
}