2009-04-27 11:51:44 -05:00
|
|
|
#include <qendian.h>
|
|
|
|
#include <QHostAddress>
|
|
|
|
|
|
|
|
#include "mac.h"
|
|
|
|
|
|
|
|
MacConfigForm::MacConfigForm(QWidget *parent)
|
2009-12-28 02:31:28 -06:00
|
|
|
: QWidget(parent)
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
QRegExp reMac("([0-9,a-f,A-F]{2,2}[:-]){5,5}[0-9,a-f,A-F]{2,2}");
|
2009-04-27 11:51:44 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
setupUi(this);
|
|
|
|
leDstMac->setValidator(new QRegExpValidator(reMac, this));
|
|
|
|
leSrcMac->setValidator(new QRegExpValidator(reMac, this));
|
|
|
|
leDstMacCount->setValidator(new QIntValidator(1, MAX_MAC_ITER_COUNT, this));
|
|
|
|
leSrcMacCount->setValidator(new QIntValidator(1, MAX_MAC_ITER_COUNT, this));
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
MacConfigForm::~MacConfigForm()
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
qDebug("In MacConfigForm destructor");
|
2009-08-02 09:52:34 -05:00
|
|
|
}
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
void MacConfigForm::on_cmbDstMacMode_currentIndexChanged(int index)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
if (index == OstProto::Mac::e_mm_fixed)
|
|
|
|
{
|
|
|
|
leDstMacCount->setEnabled(false);
|
|
|
|
leDstMacStep->setEnabled(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
leDstMacCount->setEnabled(true);
|
|
|
|
leDstMacStep->setEnabled(true);
|
|
|
|
}
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MacConfigForm::on_cmbSrcMacMode_currentIndexChanged(int index)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
if (index == OstProto::Mac::e_mm_fixed)
|
|
|
|
{
|
|
|
|
leSrcMacCount->setEnabled(false);
|
|
|
|
leSrcMacStep->setEnabled(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
leSrcMacCount->setEnabled(true);
|
|
|
|
leSrcMacStep->setEnabled(true);
|
|
|
|
}
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-14 10:16:56 -05:00
|
|
|
MacProtocol::MacProtocol(StreamBase *stream, AbstractProtocol *parent)
|
2009-12-28 02:31:28 -06:00
|
|
|
: AbstractProtocol(stream, parent)
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
configForm = NULL;
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MacProtocol::~MacProtocol()
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
delete configForm;
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
2009-10-14 10:16:56 -05:00
|
|
|
AbstractProtocol* MacProtocol::createInstance(StreamBase *stream
|
2009-12-28 02:31:28 -06:00
|
|
|
, AbstractProtocol *parent)
|
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 01:27:17 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return new MacProtocol(stream, parent);
|
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 01:27:17 -05:00
|
|
|
}
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
quint32 MacProtocol::protocolNumber() const
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return OstProto::Protocol::kMacFieldNumber;
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
2009-08-02 09:52:34 -05:00
|
|
|
void MacProtocol::protoDataCopyInto(OstProto::Protocol &protocol) const
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
protocol.MutableExtension(OstProto::mac)->CopyFrom(data);
|
|
|
|
protocol.mutable_protocol_id()->set_id(protocolNumber());
|
2009-08-02 09:52:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MacProtocol::protoDataCopyFrom(const OstProto::Protocol &protocol)
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
if (protocol.protocol_id().id() == protocolNumber() &&
|
|
|
|
protocol.HasExtension(OstProto::mac))
|
|
|
|
data.MergeFrom(protocol.GetExtension(OstProto::mac));
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MacProtocol::name() const
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return QString("Media Access Protocol");
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MacProtocol::shortName() const
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return QString("MAC");
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
int MacProtocol::fieldCount() const
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return mac_fieldCount;
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
2009-05-24 09:54:11 -05:00
|
|
|
AbstractProtocol::FieldFlags MacProtocol::fieldFlags(int index) const
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
AbstractProtocol::FieldFlags flags;
|
|
|
|
|
|
|
|
flags = AbstractProtocol::fieldFlags(index);
|
|
|
|
|
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case mac_dstAddr:
|
|
|
|
case mac_srcAddr:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case mac_dstMacMode:
|
|
|
|
case mac_dstMacCount:
|
|
|
|
case mac_dstMacStep:
|
|
|
|
case mac_srcMacMode:
|
|
|
|
case mac_srcMacCount:
|
|
|
|
case mac_srcMacStep:
|
|
|
|
flags |= FieldIsMeta;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
2009-05-24 09:54:11 -05:00
|
|
|
}
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
QVariant MacProtocol::fieldData(int index, FieldAttrib attrib,
|
2009-12-28 02:31:28 -06:00
|
|
|
int streamIndex) const
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
switch (index)
|
|
|
|
{
|
|
|
|
case mac_dstAddr:
|
|
|
|
{
|
|
|
|
int u;
|
|
|
|
quint64 dstMac = 0;
|
|
|
|
|
|
|
|
switch (data.dst_mac_mode())
|
|
|
|
{
|
|
|
|
case OstProto::Mac::e_mm_fixed:
|
|
|
|
dstMac = data.dst_mac();
|
|
|
|
break;
|
|
|
|
case OstProto::Mac::e_mm_inc:
|
|
|
|
u = (streamIndex % data.dst_mac_count()) *
|
|
|
|
data.dst_mac_step();
|
|
|
|
dstMac = data.dst_mac() + u;
|
|
|
|
break;
|
|
|
|
case OstProto::Mac::e_mm_dec:
|
|
|
|
u = (streamIndex % data.dst_mac_count()) *
|
|
|
|
data.dst_mac_step();
|
|
|
|
dstMac = data.dst_mac() - u;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qWarning("Unhandled dstMac_mode %d", data.dst_mac_mode());
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldName:
|
|
|
|
return QString("Desination");
|
|
|
|
case FieldValue:
|
|
|
|
return dstMac;
|
|
|
|
case FieldTextValue:
|
|
|
|
return uintToHexStr(dstMac, 6);
|
|
|
|
case FieldFrameValue:
|
|
|
|
{
|
|
|
|
QByteArray fv;
|
|
|
|
fv.resize(8);
|
|
|
|
qToBigEndian(dstMac, (uchar*) fv.data());
|
|
|
|
fv.remove(0, 2);
|
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case mac_srcAddr:
|
|
|
|
{
|
|
|
|
int u;
|
|
|
|
quint64 srcMac = 0;
|
|
|
|
|
|
|
|
switch (data.src_mac_mode())
|
|
|
|
{
|
|
|
|
case OstProto::Mac::e_mm_fixed:
|
|
|
|
srcMac = data.src_mac();
|
|
|
|
break;
|
|
|
|
case OstProto::Mac::e_mm_inc:
|
|
|
|
u = (streamIndex % data.src_mac_count()) *
|
|
|
|
data.src_mac_step();
|
|
|
|
srcMac = data.src_mac() + u;
|
|
|
|
break;
|
|
|
|
case OstProto::Mac::e_mm_dec:
|
|
|
|
u = (streamIndex % data.src_mac_count()) *
|
|
|
|
data.src_mac_step();
|
|
|
|
srcMac = data.src_mac() - u;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qWarning("Unhandled srcMac_mode %d", data.src_mac_mode());
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(attrib)
|
|
|
|
{
|
|
|
|
case FieldName:
|
|
|
|
return QString("Source");
|
|
|
|
case FieldValue:
|
|
|
|
return srcMac;
|
|
|
|
case FieldTextValue:
|
|
|
|
return uintToHexStr(srcMac, 6);
|
|
|
|
case FieldFrameValue:
|
|
|
|
{
|
|
|
|
QByteArray fv;
|
|
|
|
fv.resize(8);
|
|
|
|
qToBigEndian(srcMac, (uchar*) fv.data());
|
|
|
|
fv.remove(0, 2);
|
|
|
|
return fv;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Meta fields
|
|
|
|
case mac_dstMacMode:
|
|
|
|
case mac_dstMacCount:
|
|
|
|
case mac_dstMacStep:
|
|
|
|
case mac_srcMacMode:
|
|
|
|
case mac_srcMacCount:
|
|
|
|
case mac_srcMacStep:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AbstractProtocol::fieldData(index, attrib, streamIndex);
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MacProtocol::setFieldData(int index, const QVariant &value,
|
2009-12-28 02:31:28 -06:00
|
|
|
FieldAttrib attrib)
|
2009-04-27 11:51:44 -05:00
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
return false;
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
2009-11-13 10:00:57 -06:00
|
|
|
bool MacProtocol::isProtocolFrameValueVariable() const
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
if ((data.dst_mac_mode() != OstProto::Mac::e_mm_fixed) ||
|
|
|
|
(data.src_mac_mode() != OstProto::Mac::e_mm_fixed))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
2009-11-13 10:00:57 -06:00
|
|
|
}
|
|
|
|
|
2009-04-27 11:51:44 -05:00
|
|
|
|
|
|
|
QWidget* MacProtocol::configWidget()
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
if (configForm == NULL)
|
|
|
|
{
|
|
|
|
configForm = new MacConfigForm;
|
|
|
|
loadConfigWidget();
|
|
|
|
}
|
|
|
|
return configForm;
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MacProtocol::loadConfigWidget()
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
configWidget();
|
2009-08-02 09:52:34 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
configForm->leDstMac->setText(uintToHexStr(data.dst_mac(), 6));
|
|
|
|
configForm->cmbDstMacMode->setCurrentIndex(data.dst_mac_mode());
|
|
|
|
configForm->leDstMacCount->setText(QString().setNum(data.dst_mac_count()));
|
|
|
|
configForm->leDstMacStep->setText(QString().setNum(data.dst_mac_step()));
|
2009-04-27 11:51:44 -05:00
|
|
|
|
2009-12-28 02:31:28 -06:00
|
|
|
configForm->leSrcMac->setText(uintToHexStr(data.src_mac(), 6));
|
|
|
|
configForm->cmbSrcMacMode->setCurrentIndex(data.src_mac_mode());
|
|
|
|
configForm->leSrcMacCount->setText(QString().setNum(data.src_mac_count()));
|
|
|
|
configForm->leSrcMacStep->setText(QString().setNum(data.src_mac_step()));
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void MacProtocol::storeConfigWidget()
|
|
|
|
{
|
2009-12-28 02:31:28 -06:00
|
|
|
bool isOk;
|
|
|
|
|
|
|
|
configWidget();
|
|
|
|
|
|
|
|
data.set_dst_mac(configForm->leDstMac->text().remove(QChar(' ')).
|
|
|
|
toULongLong(&isOk, 16));
|
|
|
|
data.set_dst_mac_mode((OstProto::Mac::MacAddrMode) configForm->
|
|
|
|
cmbDstMacMode->currentIndex());
|
|
|
|
data.set_dst_mac_count(configForm->leDstMacCount->text().toULong(&isOk));
|
|
|
|
data.set_dst_mac_step(configForm->leDstMacStep->text().toULong(&isOk));
|
|
|
|
|
|
|
|
data.set_src_mac(configForm->leSrcMac->text().remove(QChar(' ')).
|
|
|
|
toULongLong(&isOk, 16));
|
|
|
|
data.set_src_mac_mode((OstProto::Mac::MacAddrMode) configForm->
|
|
|
|
cmbSrcMacMode->currentIndex());
|
|
|
|
data.set_src_mac_count(configForm->leSrcMacCount->text().toULong(&isOk));
|
|
|
|
data.set_src_mac_step(configForm->leSrcMacStep->text().toULong(&isOk));
|
2009-04-27 11:51:44 -05:00
|
|
|
}
|
|
|
|
|