NOX: Arp - separated protocol and widget as per new framework

This commit is contained in:
Srivats P. 2014-03-28 05:52:15 +05:30
parent 24fbac9c5a
commit e6339e3d09
9 changed files with 347 additions and 202 deletions

View File

@ -87,6 +87,20 @@ public:
bool isOk;
uint a_uint = text.remove(QChar(' ')).toUInt(&isOk, 16);
if (ok)
*ok = isOk;
return a_uint;
}
/*!
Convenience Method - can be used by storeConfigWidget() implementations
*/
quint64 hexStrToUInt64(QString text, bool *ok=NULL)
{
bool isOk;
quint64 a_uint = text.remove(QChar(' ')).toULongLong(&isOk, 16);
if (ok)
*ok = isOk;

View File

@ -17,84 +17,18 @@ 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 <qendian.h>
#include <QHostAddress>
#include "arp.h"
ArpConfigForm::ArpConfigForm(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
opCodeCombo->setValidator(new QIntValidator(0, 0xFFFF, this));
opCodeCombo->addItem(1, "ARP Request");
opCodeCombo->addItem(2, "ARP Reply");
connect(senderHwAddrMode, SIGNAL(currentIndexChanged(int)),
SLOT(on_senderHwAddrMode_currentIndexChanged(int)));
connect(senderProtoAddrMode, SIGNAL(currentIndexChanged(int)),
SLOT(on_senderProtoAddrMode_currentIndexChanged(int)));
connect(targetHwAddrMode, SIGNAL(currentIndexChanged(int)),
SLOT(on_targetHwAddrMode_currentIndexChanged(int)));
connect(targetProtoAddrMode, SIGNAL(currentIndexChanged(int)),
SLOT(on_targetProtoAddrMode_currentIndexChanged(int)));
}
void ArpConfigForm::on_senderHwAddrMode_currentIndexChanged(int index)
{
if (index == OstProto::Arp::kFixed)
senderHwAddrCount->setDisabled(true);
else
senderHwAddrCount->setEnabled(true);
}
void ArpConfigForm::on_targetHwAddrMode_currentIndexChanged(int index)
{
if (index == OstProto::Arp::kFixed)
targetHwAddrCount->setDisabled(true);
else
targetHwAddrCount->setEnabled(true);
}
void ArpConfigForm::on_senderProtoAddrMode_currentIndexChanged(int index)
{
if (index == OstProto::Arp::kFixedHost)
{
senderProtoAddrCount->setDisabled(true);
senderProtoAddrMask->setDisabled(true);
}
else
{
senderProtoAddrCount->setEnabled(true);
senderProtoAddrMask->setEnabled(true);
}
}
void ArpConfigForm::on_targetProtoAddrMode_currentIndexChanged(int index)
{
if (index == OstProto::Arp::kFixedHost)
{
targetProtoAddrCount->setDisabled(true);
targetProtoAddrMask->setDisabled(true);
}
else
{
targetProtoAddrCount->setEnabled(true);
targetProtoAddrMask->setEnabled(true);
}
}
#include <QHostAddress>
ArpProtocol::ArpProtocol(StreamBase *stream, AbstractProtocol *parent)
: AbstractProtocol(stream, parent)
{
_hasPayload = false;
configForm = NULL;
}
ArpProtocol::~ArpProtocol()
{
delete configForm;
}
AbstractProtocol* ArpProtocol::createInstance(StreamBase *stream,
@ -884,110 +818,3 @@ int ArpProtocol::protocolFrameVariableCount() const
return count;
}
QWidget* ArpProtocol::configWidget()
{
if (configForm == NULL)
{
configForm = new ArpConfigForm;
loadConfigWidget();
}
return configForm;
}
void ArpProtocol::loadConfigWidget()
{
configWidget();
configForm->hwType->setText(
fieldData(arp_hwType, FieldValue).toString());
configForm->protoType->setText(uintToHexStr(
fieldData(arp_protoType, FieldValue).toUInt(), 2));
configForm->hwAddrLen->setText(
fieldData(arp_hwAddrLen, FieldValue).toString());
configForm->protoAddrLen->setText(
fieldData(arp_protoAddrLen, FieldValue).toString());
configForm->opCodeCombo->setValue(
fieldData(arp_opCode, FieldValue).toUInt());
configForm->senderHwAddr->setText(uintToHexStr(
fieldData(arp_senderHwAddr, FieldValue).toULongLong(), 6));
configForm->senderHwAddrMode->setCurrentIndex(
fieldData(arp_senderHwAddrMode, FieldValue).toUInt());
configForm->senderHwAddrCount->setText(
fieldData(arp_senderHwAddrCount, FieldValue).toString());
configForm->senderProtoAddr->setText(QHostAddress(
fieldData(arp_senderProtoAddr, FieldValue).toUInt()).toString());
configForm->senderProtoAddrMode->setCurrentIndex(
fieldData(arp_senderProtoAddrMode, FieldValue).toUInt());
configForm->senderProtoAddrCount->setText(
fieldData(arp_senderProtoAddrCount, FieldValue).toString());
configForm->senderProtoAddrMask->setText(QHostAddress(
fieldData(arp_senderProtoAddrMask, FieldValue).toUInt()).toString());
configForm->targetHwAddr->setText(uintToHexStr(
fieldData(arp_targetHwAddr, FieldValue).toULongLong(), 6));
configForm->targetHwAddrMode->setCurrentIndex(
fieldData(arp_targetHwAddrMode, FieldValue).toUInt());
configForm->targetHwAddrCount->setText(
fieldData(arp_targetHwAddrCount, FieldValue).toString());
configForm->targetProtoAddr->setText(QHostAddress(
fieldData(arp_targetProtoAddr, FieldValue).toUInt()).toString());
configForm->targetProtoAddrMode->setCurrentIndex(
fieldData(arp_targetProtoAddrMode, FieldValue).toUInt());
configForm->targetProtoAddrCount->setText(
fieldData(arp_targetProtoAddrCount, FieldValue).toString());
configForm->targetProtoAddrMask->setText(QHostAddress(
fieldData(arp_targetProtoAddrMask, FieldValue).toUInt()).toString());
}
void ArpProtocol::storeConfigWidget()
{
bool isOk;
configWidget();
setFieldData(arp_hwType, configForm->hwType->text());
setFieldData(arp_protoType, configForm->protoType->text().toUInt(
&isOk, BASE_HEX));
setFieldData(arp_hwAddrLen, configForm->hwAddrLen->text());
setFieldData(arp_protoAddrLen, configForm->protoAddrLen->text());
setFieldData(arp_opCode, configForm->opCodeCombo->currentValue());
setFieldData(arp_senderHwAddr, configForm->senderHwAddr->text()
.remove(QChar(' ')).toULongLong(&isOk, BASE_HEX));
setFieldData(arp_senderHwAddrMode,
configForm->senderHwAddrMode->currentIndex());
setFieldData(arp_senderHwAddrCount, configForm->senderHwAddrCount->text());
setFieldData(arp_senderProtoAddr, QHostAddress(
configForm->senderProtoAddr->text()).toIPv4Address());
setFieldData(arp_senderProtoAddrMode,
configForm->senderProtoAddrMode->currentIndex());
setFieldData(arp_senderProtoAddrCount,
configForm->senderProtoAddrCount->text());
setFieldData(arp_senderProtoAddrMask, QHostAddress(
configForm->senderProtoAddrMask->text()).toIPv4Address());
setFieldData(arp_targetHwAddr, configForm->targetHwAddr->text()
.remove(QChar(' ')).toULongLong(&isOk, BASE_HEX));
setFieldData(arp_targetHwAddrMode,
configForm->targetHwAddrMode->currentIndex());
setFieldData(arp_targetHwAddrCount, configForm->targetHwAddrCount->text());
setFieldData(arp_targetProtoAddr, QHostAddress(
configForm->targetProtoAddr->text()).toIPv4Address());
setFieldData(arp_targetProtoAddrMode,
configForm->targetProtoAddrMode->currentIndex());
setFieldData(arp_targetProtoAddrCount,
configForm->targetProtoAddrCount->text());
setFieldData(arp_targetProtoAddrMask, QHostAddress(
configForm->targetProtoAddrMask->text()).toIPv4Address());
}

View File

@ -20,10 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#ifndef _ARP_H
#define _ARP_H
#include "arp.pb.h"
#include "ui_arp.h"
#include "abstractprotocol.h"
#include "arp.pb.h"
/*
Arp Protocol Frame Format -
@ -34,23 +32,9 @@ Arp Protocol Frame Format -
Figures in brackets represent field width in bytes
*/
class ArpConfigForm : public QWidget, public Ui::Arp
{
Q_OBJECT
public:
ArpConfigForm(QWidget *parent = 0);
private slots:
void on_senderHwAddrMode_currentIndexChanged(int index);
void on_senderProtoAddrMode_currentIndexChanged(int index);
void on_targetHwAddrMode_currentIndexChanged(int index);
void on_targetProtoAddrMode_currentIndexChanged(int index);
};
class ArpProtocol : public AbstractProtocol
{
private:
OstProto::Arp data;
ArpConfigForm *configForm;
public:
enum arpfield
{
// Frame Fields
@ -86,7 +70,6 @@ private:
arp_fieldCount
};
public:
ArpProtocol(StreamBase *stream, AbstractProtocol *parent = 0);
virtual ~ArpProtocol();
@ -113,9 +96,8 @@ public:
virtual bool isProtocolFrameValueVariable() const;
virtual int protocolFrameVariableCount() const;
virtual QWidget* configWidget();
virtual void loadConfigWidget();
virtual void storeConfigWidget();
private:
OstProto::Arp data;
};
#endif

270
common/arpconfig.cpp Normal file
View File

@ -0,0 +1,270 @@
/*
Copyright (C) 2010 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 "arpconfig.h"
#include "arp.h"
#include <QHostAddress>
ArpConfigForm::ArpConfigForm(QWidget *parent)
: AbstractProtocolConfigForm(parent)
{
setupUi(this);
opCodeCombo->setValidator(new QIntValidator(0, 0xFFFF, this));
opCodeCombo->addItem(1, "ARP Request");
opCodeCombo->addItem(2, "ARP Reply");
connect(senderHwAddrMode, SIGNAL(currentIndexChanged(int)),
SLOT(on_senderHwAddrMode_currentIndexChanged(int)));
connect(senderProtoAddrMode, SIGNAL(currentIndexChanged(int)),
SLOT(on_senderProtoAddrMode_currentIndexChanged(int)));
connect(targetHwAddrMode, SIGNAL(currentIndexChanged(int)),
SLOT(on_targetHwAddrMode_currentIndexChanged(int)));
connect(targetProtoAddrMode, SIGNAL(currentIndexChanged(int)),
SLOT(on_targetProtoAddrMode_currentIndexChanged(int)));
}
ArpConfigForm::~ArpConfigForm()
{
}
ArpConfigForm* ArpConfigForm::createInstance()
{
return new ArpConfigForm;
}
void ArpConfigForm::loadWidget(AbstractProtocol *proto)
{
hwType->setText(
proto->fieldData(
ArpProtocol::arp_hwType,
AbstractProtocol::FieldValue
).toString());
protoType->setText(uintToHexStr(
proto->fieldData(
ArpProtocol::arp_protoType,
AbstractProtocol::FieldValue
).toUInt(), 2));
hwAddrLen->setText(
proto->fieldData(
ArpProtocol::arp_hwAddrLen,
AbstractProtocol::FieldValue
).toString());
protoAddrLen->setText(
proto->fieldData(
ArpProtocol::arp_protoAddrLen,
AbstractProtocol::FieldValue
).toString());
opCodeCombo->setValue(
proto->fieldData(
ArpProtocol::arp_opCode,
AbstractProtocol::FieldValue
).toUInt());
senderHwAddr->setText(uintToHexStr(
proto->fieldData(
ArpProtocol::arp_senderHwAddr,
AbstractProtocol::FieldValue
).toULongLong(), 6));
senderHwAddrMode->setCurrentIndex(
proto->fieldData(
ArpProtocol::arp_senderHwAddrMode,
AbstractProtocol::FieldValue
).toUInt());
senderHwAddrCount->setText(
proto->fieldData(
ArpProtocol::arp_senderHwAddrCount,
AbstractProtocol::FieldValue
).toString());
senderProtoAddr->setText(QHostAddress(
proto->fieldData(
ArpProtocol::arp_senderProtoAddr,
AbstractProtocol::FieldValue
).toUInt()).toString());
senderProtoAddrMode->setCurrentIndex(
proto->fieldData(
ArpProtocol::arp_senderProtoAddrMode,
AbstractProtocol::FieldValue
).toUInt());
senderProtoAddrCount->setText(
proto->fieldData(
ArpProtocol::arp_senderProtoAddrCount,
AbstractProtocol::FieldValue
).toString());
senderProtoAddrMask->setText(QHostAddress(
proto->fieldData(
ArpProtocol::arp_senderProtoAddrMask,
AbstractProtocol::FieldValue
).toUInt()).toString());
targetHwAddr->setText(uintToHexStr(
proto->fieldData(
ArpProtocol::arp_targetHwAddr,
AbstractProtocol::FieldValue
).toULongLong(), 6));
targetHwAddrMode->setCurrentIndex(
proto->fieldData(
ArpProtocol::arp_targetHwAddrMode,
AbstractProtocol::FieldValue
).toUInt());
targetHwAddrCount->setText(
proto->fieldData(
ArpProtocol::arp_targetHwAddrCount,
AbstractProtocol::FieldValue
).toString());
targetProtoAddr->setText(QHostAddress(
proto->fieldData(
ArpProtocol::arp_targetProtoAddr,
AbstractProtocol::FieldValue
).toUInt()).toString());
targetProtoAddrMode->setCurrentIndex(
proto->fieldData(
ArpProtocol::arp_targetProtoAddrMode,
AbstractProtocol::FieldValue
).toUInt());
targetProtoAddrCount->setText(
proto->fieldData(
ArpProtocol::arp_targetProtoAddrCount,
AbstractProtocol::FieldValue
).toString());
targetProtoAddrMask->setText(QHostAddress(
proto->fieldData(
ArpProtocol::arp_targetProtoAddrMask,
AbstractProtocol::FieldValue
).toUInt()).toString());
}
void ArpConfigForm::storeWidget(AbstractProtocol *proto)
{
proto->setFieldData(
ArpProtocol::arp_hwType,
hwType->text());
proto->setFieldData(
ArpProtocol::arp_protoType,
hexStrToUInt(protoType->text()));
proto->setFieldData(
ArpProtocol::arp_hwAddrLen,
hwAddrLen->text());
proto->setFieldData(
ArpProtocol::arp_protoAddrLen,
protoAddrLen->text());
proto->setFieldData(
ArpProtocol::arp_opCode,
opCodeCombo->currentValue());
proto->setFieldData(
ArpProtocol::arp_senderHwAddr,
hexStrToUInt64(senderHwAddr->text()));
proto->setFieldData(
ArpProtocol::arp_senderHwAddrMode,
senderHwAddrMode->currentIndex());
proto->setFieldData(
ArpProtocol::arp_senderHwAddrCount,
senderHwAddrCount->text());
proto->setFieldData(
ArpProtocol::arp_senderProtoAddr,
QHostAddress(senderProtoAddr->text()).toIPv4Address());
proto->setFieldData(
ArpProtocol::arp_senderProtoAddrMode,
senderProtoAddrMode->currentIndex());
proto->setFieldData(
ArpProtocol::arp_senderProtoAddrCount,
senderProtoAddrCount->text());
proto->setFieldData(
ArpProtocol::arp_senderProtoAddrMask,
QHostAddress(senderProtoAddrMask->text()).toIPv4Address());
proto->setFieldData(
ArpProtocol::arp_targetHwAddr,
hexStrToUInt64(targetHwAddr->text()));
proto->setFieldData(
ArpProtocol::arp_targetHwAddrMode,
targetHwAddrMode->currentIndex());
proto->setFieldData(
ArpProtocol::arp_targetHwAddrCount,
targetHwAddrCount->text());
proto->setFieldData(
ArpProtocol::arp_targetProtoAddr,
QHostAddress(targetProtoAddr->text()).toIPv4Address());
proto->setFieldData(
ArpProtocol::arp_targetProtoAddrMode,
targetProtoAddrMode->currentIndex());
proto->setFieldData(
ArpProtocol::arp_targetProtoAddrCount,
targetProtoAddrCount->text());
proto->setFieldData(
ArpProtocol::arp_targetProtoAddrMask,
QHostAddress(targetProtoAddrMask->text()).toIPv4Address());
}
/*
* ------------ Private Slots --------------
*/
void ArpConfigForm::on_senderHwAddrMode_currentIndexChanged(int index)
{
if (index == OstProto::Arp::kFixed)
senderHwAddrCount->setDisabled(true);
else
senderHwAddrCount->setEnabled(true);
}
void ArpConfigForm::on_targetHwAddrMode_currentIndexChanged(int index)
{
if (index == OstProto::Arp::kFixed)
targetHwAddrCount->setDisabled(true);
else
targetHwAddrCount->setEnabled(true);
}
void ArpConfigForm::on_senderProtoAddrMode_currentIndexChanged(int index)
{
if (index == OstProto::Arp::kFixedHost)
{
senderProtoAddrCount->setDisabled(true);
senderProtoAddrMask->setDisabled(true);
}
else
{
senderProtoAddrCount->setEnabled(true);
senderProtoAddrMask->setEnabled(true);
}
}
void ArpConfigForm::on_targetProtoAddrMode_currentIndexChanged(int index)
{
if (index == OstProto::Arp::kFixedHost)
{
targetProtoAddrCount->setDisabled(true);
targetProtoAddrMask->setDisabled(true);
}
else
{
targetProtoAddrCount->setEnabled(true);
targetProtoAddrMask->setEnabled(true);
}
}

46
common/arpconfig.h Normal file
View File

@ -0,0 +1,46 @@
/*
Copyright (C) 2010 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_CONFIG_H
#define _ARP_CONFIG_H
#include "abstractprotocolconfig.h"
#include "ui_arp.h"
class ArpConfigForm :
public AbstractProtocolConfigForm,
private Ui::Arp
{
Q_OBJECT
public:
ArpConfigForm(QWidget *parent = 0);
virtual ~ArpConfigForm();
static ArpConfigForm* createInstance();
virtual void loadWidget(AbstractProtocol *proto);
virtual void storeWidget(AbstractProtocol *proto);
private slots:
void on_senderHwAddrMode_currentIndexChanged(int index);
void on_senderProtoAddrMode_currentIndexChanged(int index);
void on_targetHwAddrMode_currentIndexChanged(int index);
void on_targetProtoAddrMode_currentIndexChanged(int index);
};
#endif

View File

@ -56,10 +56,10 @@ HEADERS += \
dot2llc.h \
snap.h \
dot2snap.h \
arp.h \
ip6.h
HEADERS1 += \
arp.h \
ip4.h \
ipv4addressdelegate.h \
ipv6addressdelegate.h \
@ -95,10 +95,10 @@ SOURCES += \
dot3.cpp \
llc.cpp \
snap.cpp \
arp.cpp \
ip6.cpp
SOURCES1 += \
arp.cpp \
ip4.cpp \
icmp.cpp \
gmp.cpp \

View File

@ -15,10 +15,10 @@ FORMS += \
dot3.ui \
llc.ui \
snap.ui \
arp.ui \
ip6.ui \
FORMS1 += \
arp.ui \
ip4.ui \
icmp.ui \
gmp.ui \
@ -58,6 +58,7 @@ HEADERS += \
dot2llcconfig.h \
snapconfig.h \
dot2snapconfig.h \
arpconfig.h \
ip6config.h
SOURCES += \
@ -79,6 +80,7 @@ SOURCES += \
dot3config.cpp \
llcconfig.cpp \
snapconfig.cpp \
arpconfig.cpp \
ip6config.cpp
QMAKE_DISTCLEAN += object_script.*

View File

@ -22,7 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "protocol.pb.h"
#if 0
#include "arp.h"
#include "ip4.h"
#include "ip6over4.h"
#include "ip4over6.h"
@ -49,6 +48,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "snap.h"
#include "dot2snap.h"
#include "eth2.h"
#include "arp.h"
#include "ip6.h"
#endif
@ -60,8 +60,6 @@ ProtocolManager::ProtocolManager()
themselves (once this is done remove the #includes for all the protocols)
*/
#if 0
registerProtocol(OstProto::Protocol::kArpFieldNumber,
(void*) ArpProtocol::createInstance);
registerProtocol(OstProto::Protocol::kIp4FieldNumber,
(void*) Ip4Protocol::createInstance);
registerProtocol(OstProto::Protocol::kIp6over4FieldNumber,
@ -119,6 +117,8 @@ ProtocolManager::ProtocolManager()
registerProtocol(OstProto::Protocol::kDot2SnapFieldNumber,
(void*) Dot2SnapProtocol::createInstance);
registerProtocol(OstProto::Protocol::kArpFieldNumber,
(void*) ArpProtocol::createInstance);
registerProtocol(OstProto::Protocol::kIp6FieldNumber,
(void*) Ip6Protocol::createInstance);
#endif

View File

@ -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 "arpconfig.h"
#include "ip6config.h"
ProtocolWidgetFactory *OstProtocolWidgetFactory;
@ -77,6 +78,9 @@ ProtocolWidgetFactory::ProtocolWidgetFactory()
OstProto::Protocol::kDot2SnapFieldNumber,
(void*) Dot2SnapConfigForm::createInstance);
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kArpFieldNumber,
(void*) ArpConfigForm::createInstance);
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kIp6FieldNumber,
(void*) Ip6ConfigForm::createInstance);