NOX: IPv4 - Separated protocol and widget as per new framework
This commit is contained in:
parent
e6339e3d09
commit
d818b90a8f
388
common/ip4.cpp
388
common/ip4.cpp
@ -17,66 +17,17 @@ 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 "ip4.h"
|
||||
|
||||
Ip4ConfigForm::Ip4ConfigForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
leIpVersion->setValidator(new QIntValidator(0, 15, this));
|
||||
|
||||
connect(cmbIpSrcAddrMode, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(on_cmbIpSrcAddrMode_currentIndexChanged(int)));
|
||||
connect(cmbIpDstAddrMode, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(on_cmbIpDstAddrMode_currentIndexChanged(int)));
|
||||
}
|
||||
|
||||
Ip4ConfigForm::~Ip4ConfigForm()
|
||||
{
|
||||
qDebug("IPv4 Config Form destructor called");
|
||||
}
|
||||
|
||||
void Ip4ConfigForm::on_cmbIpSrcAddrMode_currentIndexChanged(int index)
|
||||
{
|
||||
if (index == OstProto::Ip4::e_im_fixed)
|
||||
{
|
||||
leIpSrcAddrCount->setDisabled(true);
|
||||
leIpSrcAddrMask->setDisabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
leIpSrcAddrCount->setEnabled(true);
|
||||
leIpSrcAddrMask->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Ip4ConfigForm::on_cmbIpDstAddrMode_currentIndexChanged(int index)
|
||||
{
|
||||
if (index == OstProto::Ip4::e_im_fixed)
|
||||
{
|
||||
leIpDstAddrCount->setDisabled(true);
|
||||
leIpDstAddrMask->setDisabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
leIpDstAddrCount->setEnabled(true);
|
||||
leIpDstAddrMask->setEnabled(true);
|
||||
}
|
||||
}
|
||||
#include <QHostAddress>
|
||||
|
||||
Ip4Protocol::Ip4Protocol(StreamBase *stream, AbstractProtocol *parent)
|
||||
: AbstractProtocol(stream, parent)
|
||||
{
|
||||
configForm = NULL;
|
||||
}
|
||||
|
||||
Ip4Protocol::~Ip4Protocol()
|
||||
{
|
||||
delete configForm;
|
||||
}
|
||||
|
||||
AbstractProtocol* Ip4Protocol::createInstance(StreamBase *stream,
|
||||
@ -558,21 +509,87 @@ QVariant Ip4Protocol::fieldData(int index, FieldAttrib attrib,
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Meta fields
|
||||
|
||||
// Meta fields
|
||||
case ip4_isOverrideVer:
|
||||
switch(attrib)
|
||||
{
|
||||
case FieldValue: return data.is_override_ver();
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case ip4_isOverrideHdrLen:
|
||||
switch(attrib)
|
||||
{
|
||||
case FieldValue: return data.is_override_hdrlen();
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case ip4_isOverrideTotLen:
|
||||
switch(attrib)
|
||||
{
|
||||
case FieldValue: return data.is_override_totlen();
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case ip4_isOverrideProto:
|
||||
switch(attrib)
|
||||
{
|
||||
case FieldValue: return data.is_override_proto();
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case ip4_isOverrideCksum:
|
||||
switch(attrib)
|
||||
{
|
||||
case FieldValue: return data.is_override_cksum();
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ip4_srcAddrMode:
|
||||
switch(attrib)
|
||||
{
|
||||
case FieldValue: return data.src_ip_mode();
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case ip4_srcAddrCount:
|
||||
switch(attrib)
|
||||
{
|
||||
case FieldValue: return data.src_ip_count();
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case ip4_srcAddrMask:
|
||||
switch(attrib)
|
||||
{
|
||||
case FieldValue: return data.src_ip_mask();
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ip4_dstAddrMode:
|
||||
switch(attrib)
|
||||
{
|
||||
case FieldValue: return data.dst_ip_mode();
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case ip4_dstAddrCount:
|
||||
switch(attrib)
|
||||
{
|
||||
case FieldValue: return data.dst_ip_count();
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case ip4_dstAddrMask:
|
||||
switch(attrib)
|
||||
{
|
||||
case FieldValue: return data.dst_ip_mask();
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -586,19 +603,191 @@ bool Ip4Protocol::setFieldData(int index, const QVariant &value,
|
||||
bool isOk = false;
|
||||
|
||||
if (attrib != FieldValue)
|
||||
return false;
|
||||
goto _exit;
|
||||
|
||||
switch (index)
|
||||
{
|
||||
case ip4_ver:
|
||||
{
|
||||
uint version = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_ver_hdrlen(
|
||||
((version & 0xF) << 4)
|
||||
| (data.ver_hdrlen() & 0x0F));
|
||||
break;
|
||||
}
|
||||
case ip4_hdrLen:
|
||||
{
|
||||
uint hdrLen = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_ver_hdrlen(
|
||||
(data.ver_hdrlen() & 0xF0)
|
||||
| (hdrLen & 0x0F));
|
||||
break;
|
||||
}
|
||||
case ip4_tos:
|
||||
{
|
||||
uint tos = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_tos(tos);
|
||||
break;
|
||||
}
|
||||
case ip4_totLen:
|
||||
{
|
||||
uint totLen = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_totlen(totLen);
|
||||
break;
|
||||
}
|
||||
case ip4_id:
|
||||
{
|
||||
uint id = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_id(id);
|
||||
break;
|
||||
}
|
||||
case ip4_flags:
|
||||
{
|
||||
uint flags = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_flags(flags);
|
||||
break;
|
||||
}
|
||||
case ip4_fragOfs:
|
||||
{
|
||||
uint fragOfs = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_frag_ofs(fragOfs);
|
||||
break;
|
||||
}
|
||||
case ip4_ttl:
|
||||
{
|
||||
uint ttl = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_ttl(ttl);
|
||||
break;
|
||||
}
|
||||
case ip4_proto:
|
||||
{
|
||||
uint proto = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_proto(proto);
|
||||
break;
|
||||
}
|
||||
case ip4_cksum:
|
||||
{
|
||||
uint cksum = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_cksum(cksum);
|
||||
break;
|
||||
}
|
||||
case ip4_srcAddr:
|
||||
{
|
||||
quint32 srcIp = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_src_ip(srcIp);
|
||||
break;
|
||||
}
|
||||
case ip4_dstAddr:
|
||||
{
|
||||
quint32 dstIp = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_dst_ip(dstIp);
|
||||
break;
|
||||
}
|
||||
|
||||
// Meta-fields
|
||||
case ip4_isOverrideVer:
|
||||
{
|
||||
bool ovr = value.toBool();
|
||||
data.set_is_override_ver(ovr);
|
||||
isOk = true;
|
||||
break;
|
||||
}
|
||||
case ip4_isOverrideHdrLen:
|
||||
{
|
||||
bool ovr = value.toBool();
|
||||
data.set_is_override_hdrlen(ovr);
|
||||
isOk = true;
|
||||
break;
|
||||
}
|
||||
case ip4_isOverrideTotLen:
|
||||
{
|
||||
bool ovr = value.toBool();
|
||||
data.set_is_override_totlen(ovr);
|
||||
isOk = true;
|
||||
break;
|
||||
}
|
||||
case ip4_isOverrideProto:
|
||||
{
|
||||
bool ovr = value.toBool();
|
||||
data.set_is_override_proto(ovr);
|
||||
isOk = true;
|
||||
break;
|
||||
}
|
||||
case ip4_isOverrideCksum:
|
||||
{
|
||||
bool ovr = value.toBool();
|
||||
data.set_is_override_cksum(ovr);
|
||||
isOk = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case ip4_srcAddrMode:
|
||||
{
|
||||
uint mode = value.toUInt(&isOk);
|
||||
if (isOk && data.IpAddrMode_IsValid(mode))
|
||||
data.set_src_ip_mode(OstProto::Ip4::IpAddrMode(mode));
|
||||
else
|
||||
isOk = false;
|
||||
break;
|
||||
}
|
||||
case ip4_srcAddrCount:
|
||||
{
|
||||
uint count = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_src_ip_count(count);
|
||||
break;
|
||||
}
|
||||
case ip4_srcAddrMask:
|
||||
{
|
||||
quint32 mask = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_src_ip_mask(mask);
|
||||
break;
|
||||
}
|
||||
|
||||
case ip4_dstAddrMode:
|
||||
{
|
||||
uint mode = value.toUInt(&isOk);
|
||||
if (isOk && data.IpAddrMode_IsValid(mode))
|
||||
data.set_dst_ip_mode(OstProto::Ip4::IpAddrMode(mode));
|
||||
else
|
||||
isOk = false;
|
||||
break;
|
||||
}
|
||||
case ip4_dstAddrCount:
|
||||
{
|
||||
uint count = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_dst_ip_count(count);
|
||||
break;
|
||||
}
|
||||
case ip4_dstAddrMask:
|
||||
{
|
||||
quint32 mask = value.toUInt(&isOk);
|
||||
if (isOk)
|
||||
data.set_dst_ip_mask(mask);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
qFatal("%s: unimplemented case %d in switch", __PRETTY_FUNCTION__,
|
||||
index);
|
||||
break;
|
||||
}
|
||||
|
||||
_exit:
|
||||
return isOk;
|
||||
}
|
||||
|
||||
@ -655,98 +844,3 @@ quint32 Ip4Protocol::protocolFrameCksum(int streamIndex,
|
||||
|
||||
return AbstractProtocol::protocolFrameCksum(streamIndex, cksumType);
|
||||
}
|
||||
|
||||
QWidget* Ip4Protocol::configWidget()
|
||||
{
|
||||
if (configForm == NULL)
|
||||
{
|
||||
configForm = new Ip4ConfigForm;
|
||||
loadConfigWidget();
|
||||
}
|
||||
return configForm;
|
||||
}
|
||||
|
||||
void Ip4Protocol::loadConfigWidget()
|
||||
{
|
||||
configWidget();
|
||||
|
||||
configForm->cbIpVersionOverride->setChecked(data.is_override_ver());
|
||||
configForm->leIpVersion->setText(fieldData(ip4_ver, FieldValue).toString());
|
||||
|
||||
configForm->cbIpHdrLenOverride->setChecked(data.is_override_hdrlen());
|
||||
configForm->leIpHdrLen->setText(fieldData(ip4_hdrLen, FieldValue).toString());
|
||||
|
||||
configForm->leIpTos->setText(uintToHexStr(data.tos(), 1));
|
||||
|
||||
configForm->cbIpLengthOverride->setChecked(data.is_override_totlen());
|
||||
configForm->leIpLength->setText(fieldData(ip4_totLen, FieldValue).toString());
|
||||
|
||||
configForm->leIpId->setText(uintToHexStr(data.id(), 2));
|
||||
configForm->leIpFragOfs->setText(QString().setNum(data.frag_ofs()));
|
||||
configForm->cbIpFlagsDf->setChecked((data.flags() & IP_FLAG_DF) > 0);
|
||||
configForm->cbIpFlagsMf->setChecked((data.flags() & IP_FLAG_MF) > 0);
|
||||
|
||||
configForm->leIpTtl->setText(QString().setNum(data.ttl()));
|
||||
|
||||
configForm->cbIpProtocolOverride->setChecked(data.is_override_proto());
|
||||
configForm->leIpProto->setText(uintToHexStr(
|
||||
fieldData(ip4_proto, FieldValue).toUInt(), 1));
|
||||
|
||||
configForm->cbIpCksumOverride->setChecked(data.is_override_cksum());
|
||||
configForm->leIpCksum->setText(uintToHexStr(
|
||||
fieldData(ip4_cksum, FieldValue).toUInt(), 2));
|
||||
|
||||
configForm->leIpSrcAddr->setText(QHostAddress(data.src_ip()).toString());
|
||||
configForm->cmbIpSrcAddrMode->setCurrentIndex(data.src_ip_mode());
|
||||
configForm->leIpSrcAddrCount->setText(QString().setNum(data.src_ip_count()));
|
||||
configForm->leIpSrcAddrMask->setText(QHostAddress(data.src_ip_mask()).toString());
|
||||
|
||||
configForm->leIpDstAddr->setText(QHostAddress(data.dst_ip()).toString());
|
||||
configForm->cmbIpDstAddrMode->setCurrentIndex(data.dst_ip_mode());
|
||||
configForm->leIpDstAddrCount->setText(QString().setNum(data.dst_ip_count()));
|
||||
configForm->leIpDstAddrMask->setText(QHostAddress(data.dst_ip_mask()).toString());
|
||||
}
|
||||
|
||||
void Ip4Protocol::storeConfigWidget()
|
||||
{
|
||||
uint ff = 0;
|
||||
bool isOk;
|
||||
|
||||
configWidget();
|
||||
|
||||
data.set_is_override_ver(configForm->cbIpVersionOverride->isChecked());
|
||||
data.set_ver_hdrlen(((configForm->leIpVersion->text().toULong(&isOk) & 0x0F) << 4) |
|
||||
(configForm->leIpHdrLen->text().toULong(&isOk) & 0x0F));
|
||||
data.set_is_override_hdrlen(configForm->cbIpHdrLenOverride->isChecked());
|
||||
|
||||
data.set_tos(configForm->leIpTos->text().toULong(&isOk, 16));
|
||||
|
||||
data.set_totlen(configForm->leIpLength->text().toULong(&isOk));
|
||||
data.set_is_override_totlen(configForm->cbIpLengthOverride->isChecked());
|
||||
|
||||
data.set_id(configForm->leIpId->text().remove(QChar(' ')).toULong(&isOk, 16));
|
||||
data.set_frag_ofs(configForm->leIpFragOfs->text().toULong(&isOk));
|
||||
|
||||
if (configForm->cbIpFlagsDf->isChecked()) ff |= IP_FLAG_DF;
|
||||
if (configForm->cbIpFlagsMf->isChecked()) ff |= IP_FLAG_MF;
|
||||
data.set_flags(ff);
|
||||
|
||||
data.set_ttl(configForm->leIpTtl->text().toULong(&isOk));
|
||||
|
||||
data.set_is_override_proto(configForm->cbIpProtocolOverride->isChecked());
|
||||
data.set_proto(configForm->leIpProto->text().remove(QChar(' ')).toULong(&isOk, 16));
|
||||
|
||||
data.set_is_override_cksum(configForm->cbIpCksumOverride->isChecked());
|
||||
data.set_cksum(configForm->leIpCksum->text().remove(QChar(' ')).toULong(&isOk, 16));
|
||||
|
||||
data.set_src_ip(QHostAddress(configForm->leIpSrcAddr->text()).toIPv4Address());
|
||||
data.set_src_ip_mode((OstProto::Ip4_IpAddrMode)configForm->cmbIpSrcAddrMode->currentIndex());
|
||||
data.set_src_ip_count(configForm->leIpSrcAddrCount->text().toULong(&isOk));
|
||||
data.set_src_ip_mask(QHostAddress(configForm->leIpSrcAddrMask->text()).toIPv4Address());
|
||||
|
||||
data.set_dst_ip(QHostAddress(configForm->leIpDstAddr->text()).toIPv4Address());
|
||||
data.set_dst_ip_mode((OstProto::Ip4_IpAddrMode)configForm->cmbIpDstAddrMode->currentIndex());
|
||||
data.set_dst_ip_count(configForm->leIpDstAddrCount->text().toULong(&isOk));
|
||||
data.set_dst_ip_mask(QHostAddress(configForm->leIpDstAddrMask->text()).toIPv4Address());
|
||||
}
|
||||
|
||||
|
25
common/ip4.h
25
common/ip4.h
@ -21,31 +21,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#define _IPV4_H
|
||||
|
||||
#include "abstractprotocol.h"
|
||||
|
||||
#include "ip4.pb.h"
|
||||
#include "ui_ip4.h"
|
||||
|
||||
#define IP_FLAG_MF 0x1
|
||||
#define IP_FLAG_DF 0x2
|
||||
#define IP_FLAG_UNUSED 0x4
|
||||
|
||||
|
||||
class Ip4ConfigForm : public QWidget, public Ui::ip4
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Ip4ConfigForm(QWidget *parent = 0);
|
||||
~Ip4ConfigForm();
|
||||
private slots:
|
||||
void on_cmbIpSrcAddrMode_currentIndexChanged(int index);
|
||||
void on_cmbIpDstAddrMode_currentIndexChanged(int index);
|
||||
};
|
||||
|
||||
class Ip4Protocol : public AbstractProtocol
|
||||
{
|
||||
private:
|
||||
OstProto::Ip4 data;
|
||||
Ip4ConfigForm *configForm;
|
||||
public:
|
||||
enum ip4field
|
||||
{
|
||||
ip4_ver = 0,
|
||||
@ -61,6 +45,7 @@ private:
|
||||
ip4_srcAddr,
|
||||
ip4_dstAddr,
|
||||
|
||||
// Meta-fields
|
||||
ip4_isOverrideVer,
|
||||
ip4_isOverrideHdrLen,
|
||||
ip4_isOverrideTotLen,
|
||||
@ -78,7 +63,6 @@ private:
|
||||
ip4_fieldCount
|
||||
};
|
||||
|
||||
public:
|
||||
Ip4Protocol(StreamBase *stream, AbstractProtocol *parent = 0);
|
||||
virtual ~Ip4Protocol();
|
||||
|
||||
@ -107,9 +91,8 @@ public:
|
||||
virtual quint32 protocolFrameCksum(int streamIndex = 0,
|
||||
CksumType cksumType = CksumIp) const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
virtual void storeConfigWidget();
|
||||
private:
|
||||
OstProto::Ip4 data;
|
||||
};
|
||||
|
||||
|
||||
|
297
common/ip4config.cpp
Normal file
297
common/ip4config.cpp
Normal file
@ -0,0 +1,297 @@
|
||||
/*
|
||||
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 "ip4config.h"
|
||||
#include "ip4.h"
|
||||
|
||||
#include <QHostAddress>
|
||||
|
||||
Ip4ConfigForm::Ip4ConfigForm(QWidget *parent)
|
||||
: AbstractProtocolConfigForm(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
leIpVersion->setValidator(new QIntValidator(0, 15, this));
|
||||
|
||||
connect(cmbIpSrcAddrMode, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(on_cmbIpSrcAddrMode_currentIndexChanged(int)));
|
||||
connect(cmbIpDstAddrMode, SIGNAL(currentIndexChanged(int)),
|
||||
this, SLOT(on_cmbIpDstAddrMode_currentIndexChanged(int)));
|
||||
}
|
||||
|
||||
Ip4ConfigForm::~Ip4ConfigForm()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Ip4ConfigForm* Ip4ConfigForm::createInstance()
|
||||
{
|
||||
return new Ip4ConfigForm;
|
||||
}
|
||||
|
||||
void Ip4ConfigForm::loadWidget(AbstractProtocol *proto)
|
||||
{
|
||||
cbIpVersionOverride->setChecked(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_isOverrideVer,
|
||||
AbstractProtocol::FieldValue
|
||||
).toBool());
|
||||
leIpVersion->setText(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_ver,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
|
||||
cbIpHdrLenOverride->setChecked(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_isOverrideHdrLen,
|
||||
AbstractProtocol::FieldValue
|
||||
).toBool());
|
||||
leIpHdrLen->setText(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_hdrLen,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
|
||||
leIpTos->setText(uintToHexStr(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_tos,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt(), 1));
|
||||
|
||||
cbIpLengthOverride->setChecked(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_isOverrideTotLen,
|
||||
AbstractProtocol::FieldValue
|
||||
).toBool());
|
||||
leIpLength->setText(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_totLen,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
|
||||
leIpId->setText(uintToHexStr(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_id,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt(), 2));
|
||||
leIpFragOfs->setText(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_fragOfs,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
cbIpFlagsDf->setChecked((
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_flags,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt() & IP_FLAG_DF) > 0);
|
||||
cbIpFlagsMf->setChecked((
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_flags,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt() & IP_FLAG_MF) > 0);
|
||||
|
||||
leIpTtl->setText(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_ttl,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
|
||||
cbIpProtocolOverride->setChecked(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_isOverrideProto,
|
||||
AbstractProtocol::FieldValue
|
||||
).toBool());
|
||||
leIpProto->setText(uintToHexStr(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_proto,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt(), 1));
|
||||
|
||||
cbIpCksumOverride->setChecked(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_isOverrideCksum,
|
||||
AbstractProtocol::FieldValue
|
||||
).toBool());
|
||||
leIpCksum->setText(uintToHexStr(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_cksum,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt(), 2));
|
||||
|
||||
leIpSrcAddr->setText(QHostAddress(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_srcAddr,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt()).toString());
|
||||
cmbIpSrcAddrMode->setCurrentIndex(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_srcAddrMode,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt());
|
||||
leIpSrcAddrCount->setText(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_srcAddrCount,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
leIpSrcAddrMask->setText(QHostAddress(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_srcAddrMask,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt()).toString());
|
||||
|
||||
leIpDstAddr->setText(QHostAddress(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_dstAddr,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt()).toString());
|
||||
cmbIpDstAddrMode->setCurrentIndex(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_dstAddrMode,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt());
|
||||
leIpDstAddrCount->setText(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_dstAddrCount,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
leIpDstAddrMask->setText(QHostAddress(
|
||||
proto->fieldData(
|
||||
Ip4Protocol::ip4_dstAddrMask,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt()).toString());
|
||||
}
|
||||
|
||||
void Ip4ConfigForm::storeWidget(AbstractProtocol *proto)
|
||||
{
|
||||
uint ff = 0;
|
||||
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_isOverrideVer,
|
||||
cbIpVersionOverride->isChecked());
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_ver,
|
||||
leIpVersion->text());
|
||||
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_isOverrideHdrLen,
|
||||
cbIpHdrLenOverride->isChecked());
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_hdrLen,
|
||||
leIpHdrLen->text());
|
||||
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_tos,
|
||||
hexStrToUInt(leIpTos->text()));
|
||||
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_totLen,
|
||||
leIpLength->text());
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_isOverrideTotLen,
|
||||
cbIpLengthOverride->isChecked());
|
||||
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_id,
|
||||
hexStrToUInt(leIpId->text()));
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_fragOfs,
|
||||
leIpFragOfs->text());
|
||||
|
||||
if (cbIpFlagsDf->isChecked()) ff |= IP_FLAG_DF;
|
||||
if (cbIpFlagsMf->isChecked()) ff |= IP_FLAG_MF;
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_flags,
|
||||
ff);
|
||||
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_ttl,
|
||||
leIpTtl->text());
|
||||
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_isOverrideProto,
|
||||
cbIpProtocolOverride->isChecked());
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_proto,
|
||||
hexStrToUInt(leIpProto->text()));
|
||||
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_isOverrideCksum,
|
||||
cbIpCksumOverride->isChecked());
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_cksum,
|
||||
hexStrToUInt(leIpCksum->text()));
|
||||
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_srcAddr,
|
||||
QHostAddress(leIpSrcAddr->text()).toIPv4Address());
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_srcAddrMode,
|
||||
(OstProto::Ip4_IpAddrMode)cmbIpSrcAddrMode->currentIndex());
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_srcAddrCount,
|
||||
leIpSrcAddrCount->text());
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_srcAddrMask,
|
||||
QHostAddress(leIpSrcAddrMask->text()).toIPv4Address());
|
||||
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_dstAddr,
|
||||
QHostAddress(leIpDstAddr->text()).toIPv4Address());
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_dstAddrMode,
|
||||
(OstProto::Ip4_IpAddrMode)cmbIpDstAddrMode->currentIndex());
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_dstAddrCount,
|
||||
leIpDstAddrCount->text());
|
||||
proto->setFieldData(
|
||||
Ip4Protocol::ip4_dstAddrMask,
|
||||
QHostAddress(leIpDstAddrMask->text()).toIPv4Address());
|
||||
}
|
||||
|
||||
/*
|
||||
* Slots
|
||||
*/
|
||||
void Ip4ConfigForm::on_cmbIpSrcAddrMode_currentIndexChanged(int index)
|
||||
{
|
||||
if (index == OstProto::Ip4::e_im_fixed)
|
||||
{
|
||||
leIpSrcAddrCount->setDisabled(true);
|
||||
leIpSrcAddrMask->setDisabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
leIpSrcAddrCount->setEnabled(true);
|
||||
leIpSrcAddrMask->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Ip4ConfigForm::on_cmbIpDstAddrMode_currentIndexChanged(int index)
|
||||
{
|
||||
if (index == OstProto::Ip4::e_im_fixed)
|
||||
{
|
||||
leIpDstAddrCount->setDisabled(true);
|
||||
leIpDstAddrMask->setDisabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
leIpDstAddrCount->setEnabled(true);
|
||||
leIpDstAddrMask->setEnabled(true);
|
||||
}
|
||||
}
|
44
common/ip4config.h
Normal file
44
common/ip4config.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
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 _IPV4_CONFIG_H
|
||||
#define _IPV4_CONFIG_H
|
||||
|
||||
#include "abstractprotocolconfig.h"
|
||||
#include "ui_ip4.h"
|
||||
|
||||
class Ip4ConfigForm :
|
||||
public AbstractProtocolConfigForm,
|
||||
private Ui::ip4
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Ip4ConfigForm(QWidget *parent = 0);
|
||||
virtual ~Ip4ConfigForm();
|
||||
|
||||
static Ip4ConfigForm* createInstance();
|
||||
|
||||
virtual void loadWidget(AbstractProtocol *proto);
|
||||
virtual void storeWidget(AbstractProtocol *proto);
|
||||
|
||||
private slots:
|
||||
void on_cmbIpSrcAddrMode_currentIndexChanged(int index);
|
||||
void on_cmbIpDstAddrMode_currentIndexChanged(int index);
|
||||
};
|
||||
#endif
|
@ -57,10 +57,10 @@ HEADERS += \
|
||||
snap.h \
|
||||
dot2snap.h \
|
||||
arp.h \
|
||||
ip4.h \
|
||||
ip6.h
|
||||
|
||||
HEADERS1 += \
|
||||
ip4.h \
|
||||
ipv4addressdelegate.h \
|
||||
ipv6addressdelegate.h \
|
||||
ip6over4.h \
|
||||
@ -96,10 +96,10 @@ SOURCES += \
|
||||
llc.cpp \
|
||||
snap.cpp \
|
||||
arp.cpp \
|
||||
ip4.cpp \
|
||||
ip6.cpp
|
||||
|
||||
SOURCES1 += \
|
||||
ip4.cpp \
|
||||
icmp.cpp \
|
||||
gmp.cpp \
|
||||
igmp.cpp \
|
||||
|
@ -16,10 +16,10 @@ FORMS += \
|
||||
llc.ui \
|
||||
snap.ui \
|
||||
arp.ui \
|
||||
ip6.ui \
|
||||
ip4.ui \
|
||||
ip6.ui
|
||||
|
||||
FORMS1 += \
|
||||
ip4.ui \
|
||||
icmp.ui \
|
||||
gmp.ui \
|
||||
tcp.ui \
|
||||
@ -59,6 +59,7 @@ HEADERS += \
|
||||
snapconfig.h \
|
||||
dot2snapconfig.h \
|
||||
arpconfig.h \
|
||||
ip4config.h \
|
||||
ip6config.h
|
||||
|
||||
SOURCES += \
|
||||
@ -81,6 +82,7 @@ SOURCES += \
|
||||
llcconfig.cpp \
|
||||
snapconfig.cpp \
|
||||
arpconfig.cpp \
|
||||
ip4config.cpp \
|
||||
ip6config.cpp
|
||||
|
||||
QMAKE_DISTCLEAN += object_script.*
|
||||
|
@ -22,7 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "protocol.pb.h"
|
||||
#if 0
|
||||
#include "ip4.h"
|
||||
#include "ip6over4.h"
|
||||
#include "ip4over6.h"
|
||||
#include "ip4over4.h"
|
||||
@ -49,6 +48,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "dot2snap.h"
|
||||
#include "eth2.h"
|
||||
#include "arp.h"
|
||||
#include "ip4.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::kIp4FieldNumber,
|
||||
(void*) Ip4Protocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kIp6over4FieldNumber,
|
||||
(void*) Ip6over4Protocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kIp4over6FieldNumber,
|
||||
@ -119,6 +117,8 @@ ProtocolManager::ProtocolManager()
|
||||
|
||||
registerProtocol(OstProto::Protocol::kArpFieldNumber,
|
||||
(void*) ArpProtocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kIp4FieldNumber,
|
||||
(void*) Ip4Protocol::createInstance);
|
||||
registerProtocol(OstProto::Protocol::kIp6FieldNumber,
|
||||
(void*) Ip6Protocol::createInstance);
|
||||
#endif
|
||||
|
@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#include "snapconfig.h"
|
||||
#include "dot2snapconfig.h"
|
||||
#include "arpconfig.h"
|
||||
#include "ip4config.h"
|
||||
#include "ip6config.h"
|
||||
|
||||
ProtocolWidgetFactory *OstProtocolWidgetFactory;
|
||||
@ -81,6 +82,9 @@ ProtocolWidgetFactory::ProtocolWidgetFactory()
|
||||
OstProtocolWidgetFactory->registerProtocolConfigWidget(
|
||||
OstProto::Protocol::kArpFieldNumber,
|
||||
(void*) ArpConfigForm::createInstance);
|
||||
OstProtocolWidgetFactory->registerProtocolConfigWidget(
|
||||
OstProto::Protocol::kIp4FieldNumber,
|
||||
(void*) Ip4ConfigForm::createInstance);
|
||||
OstProtocolWidgetFactory->registerProtocolConfigWidget(
|
||||
OstProto::Protocol::kIp6FieldNumber,
|
||||
(void*) Ip6ConfigForm::createInstance);
|
||||
|
Loading…
Reference in New Issue
Block a user