diff --git a/common/ostproto.pro b/common/ostproto.pro
index 92863ca..deb3b12 100644
--- a/common/ostproto.pro
+++ b/common/ostproto.pro
@@ -48,6 +48,7 @@ HEADERS += \
mac.h \
payload.h \
dot3.h \
+ vlan.h \
eth2.h \
ip6.h
@@ -56,7 +57,6 @@ HEADERS1 += \
snap.h \
dot2llc.h \
dot2snap.h \
- vlan.h \
svlan.h \
vlanstack.h \
arp.h \
@@ -89,6 +89,7 @@ SOURCES = \
SOURCES += \
mac.cpp \
payload.cpp \
+ vlan.cpp \
dot3.cpp \
eth2.cpp \
ip6.cpp
@@ -96,7 +97,6 @@ SOURCES += \
SOURCES1 += \
llc.cpp \
snap.cpp \
- vlan.cpp \
svlan.cpp \
arp.cpp \
ip4.cpp \
diff --git a/common/ostprotogui.pro b/common/ostprotogui.pro
index 8f3c4ee..f72f14f 100644
--- a/common/ostprotogui.pro
+++ b/common/ostprotogui.pro
@@ -10,6 +10,7 @@ FORMS = \
FORMS += \
mac.ui \
payload.ui \
+ vlan.ui \
dot3.ui \
eth2.ui \
ip6.ui \
@@ -17,7 +18,6 @@ FORMS += \
FORMS1 += \
llc.ui \
snap.ui \
- vlan.ui \
arp.ui \
ip4.ui \
icmp.ui \
@@ -48,6 +48,7 @@ HEADERS += \
protocolwidgetfactory.h \
macconfig.h \
payloadconfig.h \
+ vlanconfig.h \
dot3config.h \
eth2config.h \
ip6config.h
@@ -66,6 +67,7 @@ SOURCES += \
protocolwidgetfactory.cpp \
macconfig.cpp \
payloadconfig.cpp \
+ vlanconfig.cpp \
dot3config.cpp \
eth2config.cpp \
ip6config.cpp
diff --git a/common/protocolmanager.cpp b/common/protocolmanager.cpp
index c8c0bb7..aaeecb2 100644
--- a/common/protocolmanager.cpp
+++ b/common/protocolmanager.cpp
@@ -26,7 +26,6 @@ along with this program. If not, see
#include "snap.h"
#include "dot2llc.h"
#include "dot2snap.h"
-#include "vlan.h"
#include "vlanstack.h"
#include "arp.h"
#include "ip4.h"
@@ -47,6 +46,7 @@ along with this program. If not, see
#include "mac.h"
#include "payload.h"
#include "dot3.h"
+#include "vlan.h"
#include "eth2.h"
#include "ip6.h"
#endif
@@ -70,8 +70,6 @@ ProtocolManager::ProtocolManager()
registerProtocol(OstProto::Protocol::kSvlanFieldNumber,
(void*) SVlanProtocol::createInstance);
- registerProtocol(OstProto::Protocol::kVlanFieldNumber,
- (void*) VlanProtocol::createInstance);
registerProtocol(OstProto::Protocol::kVlanStackFieldNumber,
(void*) VlanStackProtocol::createInstance);
@@ -116,8 +114,13 @@ ProtocolManager::ProtocolManager()
registerProtocol(OstProto::Protocol::kDot3FieldNumber,
(void*) Dot3Protocol::createInstance);
+
+ registerProtocol(OstProto::Protocol::kVlanFieldNumber,
+ (void*) VlanProtocol::createInstance);
+
registerProtocol(OstProto::Protocol::kEth2FieldNumber,
(void*) Eth2Protocol::createInstance);
+
registerProtocol(OstProto::Protocol::kIp6FieldNumber,
(void*) Ip6Protocol::createInstance);
#endif
diff --git a/common/protocolwidgetfactory.cpp b/common/protocolwidgetfactory.cpp
index 82a7231..7a330f1 100644
--- a/common/protocolwidgetfactory.cpp
+++ b/common/protocolwidgetfactory.cpp
@@ -22,6 +22,7 @@ along with this program. If not, see
#include "macconfig.h"
#include "payloadconfig.h"
#include "dot3config.h"
+#include "vlanconfig.h"
#include "eth2config.h"
#include "ip6config.h"
@@ -44,9 +45,15 @@ ProtocolWidgetFactory::ProtocolWidgetFactory()
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kDot3FieldNumber,
(void*) Dot3ConfigForm::createInstance);
+
+ OstProtocolWidgetFactory->registerProtocolConfigWidget(
+ OstProto::Protocol::kVlanFieldNumber,
+ (void*) VlanConfigForm::createInstance);
+
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kEth2FieldNumber,
(void*) Eth2ConfigForm::createInstance);
+
OstProtocolWidgetFactory->registerProtocolConfigWidget(
OstProto::Protocol::kIp6FieldNumber,
(void*) Ip6ConfigForm::createInstance);
diff --git a/common/vlan.cpp b/common/vlan.cpp
index 95b2304..cb07cd2 100644
--- a/common/vlan.cpp
+++ b/common/vlan.cpp
@@ -17,25 +17,15 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-#include
-
#include "vlan.h"
-VlanConfigForm::VlanConfigForm(QWidget *parent)
- : QWidget(parent)
-{
- setupUi(this);
-}
-
VlanProtocol::VlanProtocol(StreamBase *stream, AbstractProtocol *parent)
: AbstractProtocol(stream, parent)
{
- configForm = NULL;
}
VlanProtocol::~VlanProtocol()
{
- delete configForm;
}
AbstractProtocol* VlanProtocol::createInstance(StreamBase *stream,
@@ -206,6 +196,12 @@ QVariant VlanProtocol::fieldData(int index, FieldAttrib attrib,
// Meta fields
case vlan_isOverrideTpid:
+ switch(attrib)
+ {
+ case FieldValue: return data.is_override_tpid();
+ default: break;
+ }
+ break;
default:
break;
}
@@ -213,45 +209,62 @@ QVariant VlanProtocol::fieldData(int index, FieldAttrib attrib,
return AbstractProtocol::fieldData(index, attrib, streamIndex);
}
-bool VlanProtocol::setFieldData(int /*index*/, const QVariant &/*value*/,
- FieldAttrib /*attrib*/)
+bool VlanProtocol::setFieldData(int index, const QVariant &value,
+ FieldAttrib attrib)
{
- return false;
-}
+ bool isOk = false;
+ if (attrib != FieldValue)
+ goto _exit;
-QWidget* VlanProtocol::configWidget()
-{
- if (configForm == NULL)
+ switch (index)
{
- configForm = new VlanConfigForm;
- loadConfigWidget();
+ case vlan_tpid:
+ {
+ uint tpid = value.toUInt(&isOk);
+ if (isOk)
+ data.set_tpid(tpid);
+ break;
+ }
+ case vlan_prio:
+ {
+ uint prio = value.toUInt(&isOk);
+ if (isOk)
+ data.set_vlan_tag(
+ ((prio & 0x07) << 13) | (data.vlan_tag() & 0x1FFF));
+ break;
+ }
+ case vlan_cfiDei:
+ {
+ uint cfiDei = value.toUInt(&isOk);
+ if (isOk)
+ data.set_vlan_tag(
+ ((cfiDei & 0x01) << 12) | (data.vlan_tag() & 0xEFFF));
+ break;
+ }
+ case vlan_vlanId:
+ {
+ uint vlanId = value.toUInt(&isOk);
+ if (isOk)
+ data.set_vlan_tag(
+ (vlanId & 0x0FFF) | (data.vlan_tag() & 0xF000));
+ break;
+ }
+
+ // Meta-Fields
+ case vlan_isOverrideTpid:
+ {
+ bool override = value.toUInt(&isOk);
+ if (isOk)
+ data.set_is_override_tpid(override);
+ break;
+ }
+ default:
+ qFatal("%s: unimplemented case %d in switch", __PRETTY_FUNCTION__,
+ index);
+ break;
}
- return configForm;
+
+_exit:
+ return isOk;
}
-
-void VlanProtocol::loadConfigWidget()
-{
- configWidget();
-
- configForm->cbTpidOverride->setChecked(data.is_override_tpid());
- configForm->leTpid->setText(uintToHexStr(fieldData(vlan_tpid, FieldValue).toUInt(), 2));
- configForm->cmbPrio->setCurrentIndex(fieldData(vlan_prio, FieldValue).toUInt());
- configForm->cmbCfiDei->setCurrentIndex(fieldData(vlan_cfiDei, FieldValue).toUInt());
- configForm->leVlanId->setText(fieldData(vlan_vlanId, FieldValue).toString());
-}
-
-void VlanProtocol::storeConfigWidget()
-{
- bool isOk;
-
- configWidget();
-
- data.set_is_override_tpid(configForm->cbTpidOverride->isChecked());
- data.set_tpid(configForm->leTpid->text().remove(QChar(' ')).toULong(&isOk, BASE_HEX));
- data.set_vlan_tag(
- ((configForm->cmbPrio->currentIndex() & 0x07) << 13) |
- ((configForm->cmbCfiDei->currentIndex() & 0x01) << 12) |
- (configForm->leVlanId->text().toULong(&isOk) & 0x0FFF));
-}
-
diff --git a/common/vlan.h b/common/vlan.h
index 728572b..26cf874 100644
--- a/common/vlan.h
+++ b/common/vlan.h
@@ -17,25 +17,15 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-#ifndef _Vlan_H
-#define _Vlan_H
+#ifndef _VLAN_H
+#define _VLAN_H
#include "abstractprotocol.h"
-
#include "vlan.pb.h"
-#include "ui_vlan.h"
-
-class VlanConfigForm : public QWidget, public Ui::Vlan
-{
- Q_OBJECT
-public:
- VlanConfigForm(QWidget *parent = 0);
-};
class VlanProtocol : public AbstractProtocol
{
-private:
- VlanConfigForm *configForm;
+public:
enum Vlanfield
{
vlan_tpid,
@@ -49,10 +39,6 @@ private:
vlan_fieldCount
};
-protected:
- OstProto::Vlan data;
-
-public:
VlanProtocol(StreamBase *stream, AbstractProtocol *parent = 0);
virtual ~VlanProtocol();
@@ -74,9 +60,8 @@ public:
virtual bool setFieldData(int index, const QVariant &value,
FieldAttrib attrib = FieldValue);
- virtual QWidget* configWidget();
- virtual void loadConfigWidget();
- virtual void storeConfigWidget();
+protected:
+ OstProto::Vlan data;
};
#endif
diff --git a/common/vlan.ui b/common/vlan.ui
index 3e0326d..72e49c0 100644
--- a/common/vlan.ui
+++ b/common/vlan.ui
@@ -5,156 +5,158 @@
0
0
- 268
- 96
+ 274
+ 106
Form
-
-
- 6
-
-
- 9
-
-
- 9
-
-
- 9
-
-
- 9
-
- -
-
-
+
+
-
+
+
+ true
+
+
+ Override TPID
+
+
+
+ -
+
+
+ Priority
+
+
+
+ -
+
+
+ CFI/DEI
+
+
+
+ -
+
+
VLAN
-
-
-
-
-
- true
-
-
- Override TPID
-
-
-
- -
-
-
- Priority
-
-
-
- -
-
-
- CFI/DEI
-
-
-
- -
-
-
- VLAN
-
-
-
- -
-
-
- false
-
-
- >HH HH;
-
-
-
-
-
-
- -
-
-
- true
-
-
-
-
- 0
-
-
- -
-
- 1
-
-
- -
-
- 2
-
-
- -
-
- 3
-
-
- -
-
- 4
-
-
- -
-
- 5
-
-
- -
-
- 6
-
-
- -
-
- 7
-
-
-
-
- -
-
-
- true
-
-
-
-
- 0
-
-
- -
-
- 1
-
-
-
-
- -
-
-
- true
-
-
- 0
-
-
-
-
+ -
+
+
+ false
+
+
+ >HH HH;
+
+
+
+
+
+
+ -
+
+
+ true
+
+
-
+
+ 0
+
+
+ -
+
+ 1
+
+
+ -
+
+ 2
+
+
+ -
+
+ 3
+
+
+ -
+
+ 4
+
+
+ -
+
+ 5
+
+
+ -
+
+ 6
+
+
+ -
+
+ 7
+
+
+
+
+ -
+
+
+ true
+
+
-
+
+ 0
+
+
+ -
+
+ 1
+
+
+
+
+ -
+
+
+ true
+
+
+ 0
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 111
+ 20
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 51
+
+
+
+
diff --git a/common/vlanconfig.cpp b/common/vlanconfig.cpp
new file mode 100644
index 0000000..35241bd
--- /dev/null
+++ b/common/vlanconfig.cpp
@@ -0,0 +1,87 @@
+/*
+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
+*/
+
+#include "vlanconfig.h"
+#include "vlan.h"
+
+VlanConfigForm::VlanConfigForm(QWidget *parent)
+ : AbstractProtocolConfigForm(parent)
+{
+ setupUi(this);
+}
+
+VlanConfigForm::~VlanConfigForm()
+{
+}
+
+VlanConfigForm* VlanConfigForm::createInstance()
+{
+ return new VlanConfigForm;
+}
+
+void VlanConfigForm::loadWidget(AbstractProtocol *proto)
+{
+ cbTpidOverride->setChecked(
+ proto->fieldData(
+ VlanProtocol::vlan_isOverrideTpid,
+ AbstractProtocol::FieldValue
+ ).toBool());
+ leTpid->setText(uintToHexStr(
+ proto->fieldData(
+ VlanProtocol::vlan_tpid,
+ AbstractProtocol::FieldValue)
+ .toUInt(), 2));
+ cmbPrio->setCurrentIndex(
+ proto->fieldData(
+ VlanProtocol::vlan_prio,
+ AbstractProtocol::FieldValue)
+ .toUInt());
+ cmbCfiDei->setCurrentIndex(
+ proto->fieldData(
+ VlanProtocol::vlan_cfiDei,
+ AbstractProtocol::FieldValue)
+ .toUInt());
+ leVlanId->setText(
+ proto->fieldData(
+ VlanProtocol::vlan_vlanId,
+ AbstractProtocol::FieldValue)
+ .toString());
+}
+
+void VlanConfigForm::storeWidget(AbstractProtocol *proto)
+{
+ bool isOk;
+
+ proto->setFieldData(
+ VlanProtocol::vlan_isOverrideTpid,
+ cbTpidOverride->isChecked());
+ proto->setFieldData(
+ VlanProtocol::vlan_tpid,
+ leTpid->text().remove(QChar(' ')).toUInt(&isOk, BASE_HEX));
+ proto->setFieldData(
+ VlanProtocol::vlan_prio,
+ cmbPrio->currentIndex());
+ proto->setFieldData(
+ VlanProtocol::vlan_cfiDei,
+ cmbCfiDei->currentIndex());
+ proto->setFieldData(
+ VlanProtocol::vlan_vlanId,
+ leVlanId->text());
+}
+
diff --git a/common/vlanconfig.h b/common/vlanconfig.h
new file mode 100644
index 0000000..a761873
--- /dev/null
+++ b/common/vlanconfig.h
@@ -0,0 +1,41 @@
+/*
+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
+*/
+
+#ifndef _VLAN_CONFIG_H
+#define _VLAN_CONFIG_H
+
+#include "abstractprotocolconfig.h"
+#include "ui_vlan.h"
+
+class VlanConfigForm :
+ public AbstractProtocolConfigForm,
+ private Ui::Vlan
+{
+ Q_OBJECT
+public:
+ VlanConfigForm(QWidget *parent = 0);
+ virtual ~VlanConfigForm();
+
+ static VlanConfigForm* createInstance();
+
+ virtual void loadWidget(AbstractProtocol *proto);
+ virtual void storeWidget(AbstractProtocol *proto);
+};
+
+#endif