NOX: IPv6 - Separated protocol and widget as per new framework
This commit is contained in:
parent
f39031d663
commit
bdc1252b95
147
common/ip6.cpp
147
common/ip6.cpp
@ -18,66 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
#include "ip6.h"
|
||||
|
||||
#include "ipv6addressvalidator.h"
|
||||
|
||||
#include <QHostAddress>
|
||||
#include <qendian.h>
|
||||
|
||||
Ip6ConfigForm::Ip6ConfigForm(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
version->setValidator(new QIntValidator(0, 0xF, this));
|
||||
payloadLength->setValidator(new QIntValidator(0, 0xFFFF, this));
|
||||
hopLimit->setValidator(new QIntValidator(0, 0xFF, this));
|
||||
|
||||
srcAddr->setValidator(new IPv6AddressValidator(this));
|
||||
srcAddrCount->setValidator(new QIntValidator(this));
|
||||
//srcAddrPrefix->setValidator(new QIntValidator(0, 128, this));
|
||||
|
||||
dstAddr->setValidator(new IPv6AddressValidator(this));
|
||||
dstAddrCount->setValidator(new QIntValidator(this));
|
||||
//dstAddrPrefix->setValidator(new QIntValidator(0, 128, this));
|
||||
}
|
||||
|
||||
void Ip6ConfigForm::on_srcAddr_editingFinished()
|
||||
{
|
||||
srcAddr->setText(QHostAddress(srcAddr->text()).toString());
|
||||
}
|
||||
|
||||
void Ip6ConfigForm::on_dstAddr_editingFinished()
|
||||
{
|
||||
dstAddr->setText(QHostAddress(dstAddr->text()).toString());
|
||||
}
|
||||
|
||||
void Ip6ConfigForm::on_srcAddrModeCombo_currentIndexChanged(int index)
|
||||
{
|
||||
bool enabled = (index > 0);
|
||||
|
||||
srcAddrCount->setEnabled(enabled);
|
||||
srcAddrPrefix->setEnabled(enabled);
|
||||
}
|
||||
|
||||
void Ip6ConfigForm::on_dstAddrModeCombo_currentIndexChanged(int index)
|
||||
{
|
||||
bool enabled = (index > 0);
|
||||
|
||||
dstAddrCount->setEnabled(enabled);
|
||||
dstAddrPrefix->setEnabled(enabled);
|
||||
}
|
||||
|
||||
Ip6Protocol::Ip6Protocol(StreamBase *stream, AbstractProtocol *parent)
|
||||
: AbstractProtocol(stream, parent)
|
||||
{
|
||||
/* The configWidget is created lazily */
|
||||
configForm = NULL;
|
||||
}
|
||||
|
||||
Ip6Protocol::~Ip6Protocol()
|
||||
{
|
||||
delete configForm;
|
||||
}
|
||||
|
||||
AbstractProtocol* Ip6Protocol::createInstance(StreamBase *stream,
|
||||
@ -854,100 +804,3 @@ quint32 Ip6Protocol::protocolFrameCksum(int streamIndex,
|
||||
return AbstractProtocol::protocolFrameCksum(streamIndex, cksumType);
|
||||
}
|
||||
|
||||
QWidget* Ip6Protocol::configWidget()
|
||||
{
|
||||
/* Lazy creation of the configWidget */
|
||||
if (configForm == NULL)
|
||||
{
|
||||
configForm = new Ip6ConfigForm;
|
||||
loadConfigWidget();
|
||||
}
|
||||
|
||||
return configForm;
|
||||
}
|
||||
|
||||
void Ip6Protocol::loadConfigWidget()
|
||||
{
|
||||
configWidget();
|
||||
|
||||
configForm->isVersionOverride->setChecked(
|
||||
fieldData(ip6_isOverrideVersion, FieldValue).toBool());
|
||||
configForm->version->setText(
|
||||
fieldData(ip6_version, FieldValue).toString());
|
||||
|
||||
configForm->trafficClass->setText(uintToHexStr(
|
||||
fieldData(ip6_trafficClass, FieldValue).toUInt(), 1));
|
||||
|
||||
configForm->flowLabel->setText(QString("%1").arg(
|
||||
fieldData(ip6_flowLabel, FieldValue).toUInt(),5, BASE_HEX, QChar('0')));
|
||||
|
||||
configForm->isPayloadLengthOverride->setChecked(
|
||||
fieldData(ip6_isOverridePayloadLength, FieldValue).toBool());
|
||||
configForm->payloadLength->setText(
|
||||
fieldData(ip6_payloadLength, FieldValue).toString());
|
||||
|
||||
configForm->isNextHeaderOverride->setChecked(
|
||||
fieldData(ip6_isOverrideNextHeader, FieldValue).toBool());
|
||||
configForm->nextHeader->setText(uintToHexStr(
|
||||
fieldData(ip6_nextHeader, FieldValue).toUInt(), 1));
|
||||
|
||||
configForm->hopLimit->setText(
|
||||
fieldData(ip6_hopLimit, FieldValue).toString());
|
||||
|
||||
configForm->srcAddr->setText(
|
||||
fieldData(ip6_srcAddress, FieldTextValue).toString());
|
||||
configForm->srcAddrModeCombo->setCurrentIndex(
|
||||
fieldData(ip6_srcAddrMode, FieldValue).toUInt());
|
||||
configForm->srcAddrCount->setText(
|
||||
fieldData(ip6_srcAddrCount, FieldValue).toString());
|
||||
configForm->srcAddrPrefix->setText(
|
||||
fieldData(ip6_srcAddrPrefix, FieldValue).toString());
|
||||
|
||||
configForm->dstAddr->setText(
|
||||
fieldData(ip6_dstAddress, FieldTextValue).toString());
|
||||
configForm->dstAddrModeCombo->setCurrentIndex(
|
||||
fieldData(ip6_dstAddrMode, FieldValue).toUInt());
|
||||
configForm->dstAddrCount->setText(
|
||||
fieldData(ip6_dstAddrCount, FieldValue).toString());
|
||||
configForm->dstAddrPrefix->setText(
|
||||
fieldData(ip6_dstAddrPrefix, FieldValue).toString());
|
||||
}
|
||||
|
||||
void Ip6Protocol::storeConfigWidget()
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
configWidget();
|
||||
|
||||
setFieldData(ip6_isOverrideVersion,
|
||||
configForm->isVersionOverride->isChecked());
|
||||
setFieldData(ip6_version, configForm->version->text());
|
||||
|
||||
setFieldData(ip6_trafficClass,
|
||||
configForm->trafficClass->text().remove(QChar(' ')).toUInt(&isOk, BASE_HEX));
|
||||
|
||||
setFieldData(ip6_flowLabel,
|
||||
configForm->flowLabel->text().remove(QChar(' ')).toUInt(&isOk, BASE_HEX));
|
||||
|
||||
setFieldData(ip6_isOverridePayloadLength,
|
||||
configForm->isPayloadLengthOverride->isChecked());
|
||||
setFieldData(ip6_payloadLength, configForm->payloadLength->text());
|
||||
|
||||
setFieldData(ip6_isOverrideNextHeader,
|
||||
configForm->isNextHeaderOverride->isChecked());
|
||||
setFieldData(ip6_nextHeader,
|
||||
configForm->nextHeader->text().remove(QChar(' ')).toUInt(&isOk, BASE_HEX));
|
||||
|
||||
setFieldData(ip6_hopLimit, configForm->hopLimit->text());
|
||||
|
||||
setFieldData(ip6_srcAddress, configForm->srcAddr->text());
|
||||
setFieldData(ip6_srcAddrMode, configForm->srcAddrModeCombo->currentIndex());
|
||||
setFieldData(ip6_srcAddrCount, configForm->srcAddrCount->text());
|
||||
setFieldData(ip6_srcAddrPrefix, configForm->srcAddrPrefix->text());
|
||||
|
||||
setFieldData(ip6_dstAddress, configForm->dstAddr->text());
|
||||
setFieldData(ip6_dstAddrMode, configForm->dstAddrModeCombo->currentIndex());
|
||||
setFieldData(ip6_dstAddrCount, configForm->dstAddrCount->text());
|
||||
setFieldData(ip6_dstAddrPrefix, configForm->dstAddrPrefix->text());
|
||||
}
|
||||
|
||||
|
27
common/ip6.h
27
common/ip6.h
@ -20,10 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
#ifndef _IP6_H
|
||||
#define _IP6_H
|
||||
|
||||
#include "ip6.pb.h"
|
||||
#include "ui_ip6.h"
|
||||
|
||||
#include "abstractprotocol.h"
|
||||
#include "ip6.pb.h"
|
||||
|
||||
/*
|
||||
IPv6 Protocol Frame Format -
|
||||
@ -47,23 +45,9 @@ IPv6 Protocol Frame Format -
|
||||
Figures in brackets represent field width in bits
|
||||
*/
|
||||
|
||||
class Ip6ConfigForm : public QWidget, public Ui::Ip6
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Ip6ConfigForm(QWidget *parent = 0);
|
||||
private slots:
|
||||
void on_srcAddr_editingFinished();
|
||||
void on_dstAddr_editingFinished();
|
||||
void on_srcAddrModeCombo_currentIndexChanged(int index);
|
||||
void on_dstAddrModeCombo_currentIndexChanged(int index);
|
||||
};
|
||||
|
||||
class Ip6Protocol : public AbstractProtocol
|
||||
{
|
||||
private:
|
||||
OstProto::Ip6 data;
|
||||
Ip6ConfigForm *configForm;
|
||||
public:
|
||||
enum ip6field
|
||||
{
|
||||
// Frame Fields
|
||||
@ -92,7 +76,6 @@ private:
|
||||
ip6_fieldCount
|
||||
};
|
||||
|
||||
public:
|
||||
Ip6Protocol(StreamBase *stream, AbstractProtocol *parent = 0);
|
||||
virtual ~Ip6Protocol();
|
||||
|
||||
@ -122,10 +105,8 @@ public:
|
||||
|
||||
virtual quint32 protocolFrameCksum(int streamIndex = 0,
|
||||
CksumType cksumType = CksumIp) const;
|
||||
|
||||
virtual QWidget* configWidget();
|
||||
virtual void loadConfigWidget();
|
||||
virtual void storeConfigWidget();
|
||||
private:
|
||||
OstProto::Ip6 data;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
233
common/ip6config.cpp
Normal file
233
common/ip6config.cpp
Normal file
@ -0,0 +1,233 @@
|
||||
/*
|
||||
Copyright (C) 2010-2014 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 "ip6config.h"
|
||||
#include "ip6.h"
|
||||
#include "ipv6addressvalidator.h"
|
||||
#include <QHostAddress>
|
||||
|
||||
Ip6ConfigForm::Ip6ConfigForm(QWidget *parent)
|
||||
: AbstractProtocolConfigForm(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
version->setValidator(new QIntValidator(0, 0xF, this));
|
||||
payloadLength->setValidator(new QIntValidator(0, 0xFFFF, this));
|
||||
hopLimit->setValidator(new QIntValidator(0, 0xFF, this));
|
||||
|
||||
srcAddr->setValidator(new IPv6AddressValidator(this));
|
||||
srcAddrCount->setValidator(new QIntValidator(this));
|
||||
//srcAddrPrefix->setValidator(new QIntValidator(0, 128, this));
|
||||
|
||||
dstAddr->setValidator(new IPv6AddressValidator(this));
|
||||
dstAddrCount->setValidator(new QIntValidator(this));
|
||||
//dstAddrPrefix->setValidator(new QIntValidator(0, 128, this));
|
||||
}
|
||||
|
||||
AbstractProtocolConfigForm* Ip6ConfigForm::createInstance()
|
||||
{
|
||||
return new Ip6ConfigForm;
|
||||
}
|
||||
|
||||
void Ip6ConfigForm::on_srcAddr_editingFinished()
|
||||
{
|
||||
srcAddr->setText(QHostAddress(srcAddr->text()).toString());
|
||||
}
|
||||
|
||||
void Ip6ConfigForm::on_dstAddr_editingFinished()
|
||||
{
|
||||
dstAddr->setText(QHostAddress(dstAddr->text()).toString());
|
||||
}
|
||||
|
||||
void Ip6ConfigForm::on_srcAddrModeCombo_currentIndexChanged(int index)
|
||||
{
|
||||
bool enabled = (index > 0);
|
||||
|
||||
srcAddrCount->setEnabled(enabled);
|
||||
srcAddrPrefix->setEnabled(enabled);
|
||||
}
|
||||
|
||||
void Ip6ConfigForm::on_dstAddrModeCombo_currentIndexChanged(int index)
|
||||
{
|
||||
bool enabled = (index > 0);
|
||||
|
||||
dstAddrCount->setEnabled(enabled);
|
||||
dstAddrPrefix->setEnabled(enabled);
|
||||
}
|
||||
|
||||
void Ip6ConfigForm::loadWidget(AbstractProtocol *ip6Proto)
|
||||
{
|
||||
isVersionOverride->setChecked(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_isOverrideVersion,
|
||||
AbstractProtocol::FieldValue
|
||||
).toBool());
|
||||
version->setText(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_version,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
|
||||
trafficClass->setText(uintToHexStr(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_trafficClass,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt(), 1));
|
||||
|
||||
flowLabel->setText(QString("%1").arg(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_flowLabel,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt(), 5, BASE_HEX, QChar('0')));
|
||||
|
||||
isPayloadLengthOverride->setChecked(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_isOverridePayloadLength,
|
||||
AbstractProtocol::FieldValue
|
||||
).toBool());
|
||||
payloadLength->setText(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_payloadLength,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
|
||||
isNextHeaderOverride->setChecked(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_isOverrideNextHeader,
|
||||
AbstractProtocol::FieldValue
|
||||
).toBool());
|
||||
nextHeader->setText(uintToHexStr(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_nextHeader,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt(), 1));
|
||||
|
||||
hopLimit->setText(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_hopLimit,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
|
||||
srcAddr->setText(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_srcAddress,
|
||||
AbstractProtocol::FieldTextValue
|
||||
).toString());
|
||||
srcAddrModeCombo->setCurrentIndex(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_srcAddrMode,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt());
|
||||
srcAddrCount->setText(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_srcAddrCount,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
srcAddrPrefix->setText(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_srcAddrPrefix,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
|
||||
dstAddr->setText(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_dstAddress,
|
||||
AbstractProtocol::FieldTextValue
|
||||
).toString());
|
||||
dstAddrModeCombo->setCurrentIndex(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_dstAddrMode,
|
||||
AbstractProtocol::FieldValue
|
||||
).toUInt());
|
||||
dstAddrCount->setText(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_dstAddrCount,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
dstAddrPrefix->setText(
|
||||
ip6Proto->fieldData(
|
||||
Ip6Protocol::ip6_dstAddrPrefix,
|
||||
AbstractProtocol::FieldValue
|
||||
).toString());
|
||||
}
|
||||
|
||||
void Ip6ConfigForm::storeWidget(AbstractProtocol *ip6Proto)
|
||||
{
|
||||
bool isOk;
|
||||
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_isOverrideVersion,
|
||||
isVersionOverride->isChecked());
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_version,
|
||||
version->text());
|
||||
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_trafficClass,
|
||||
trafficClass->text().remove(QChar(' ')).toUInt(&isOk, BASE_HEX));
|
||||
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_flowLabel,
|
||||
flowLabel->text().remove(QChar(' ')).toUInt(&isOk, BASE_HEX));
|
||||
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_isOverridePayloadLength,
|
||||
isPayloadLengthOverride->isChecked());
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_payloadLength,
|
||||
payloadLength->text());
|
||||
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_isOverrideNextHeader,
|
||||
isNextHeaderOverride->isChecked());
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_nextHeader,
|
||||
nextHeader->text().remove(QChar(' ')).toUInt(&isOk, BASE_HEX));
|
||||
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_hopLimit,
|
||||
hopLimit->text());
|
||||
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_srcAddress,
|
||||
srcAddr->text());
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_srcAddrMode,
|
||||
srcAddrModeCombo->currentIndex());
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_srcAddrCount,
|
||||
srcAddrCount->text());
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_srcAddrPrefix,
|
||||
srcAddrPrefix->text());
|
||||
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_dstAddress,
|
||||
dstAddr->text());
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_dstAddrMode,
|
||||
dstAddrModeCombo->currentIndex());
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_dstAddrCount,
|
||||
dstAddrCount->text());
|
||||
ip6Proto->setFieldData(
|
||||
Ip6Protocol::ip6_dstAddrPrefix,
|
||||
dstAddrPrefix->text());
|
||||
}
|
||||
|
44
common/ip6config.h
Normal file
44
common/ip6config.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
Copyright (C) 2010-2014 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 _IP6_CONFIG_H
|
||||
#define _IP6_CONFIG_H
|
||||
|
||||
#include "abstractprotocolconfig.h"
|
||||
#include "ui_ip6.h"
|
||||
|
||||
class Ip6ConfigForm :
|
||||
public AbstractProtocolConfigForm,
|
||||
private Ui::Ip6
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Ip6ConfigForm(QWidget *parent = 0);
|
||||
static AbstractProtocolConfigForm* createInstance();
|
||||
|
||||
virtual void loadWidget(AbstractProtocol *ip6Proto);
|
||||
virtual void storeWidget(AbstractProtocol *ip6Proto);
|
||||
|
||||
private slots:
|
||||
void on_srcAddr_editingFinished();
|
||||
void on_dstAddr_editingFinished();
|
||||
void on_srcAddrModeCombo_currentIndexChanged(int index);
|
||||
void on_dstAddrModeCombo_currentIndexChanged(int index);
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user