diff --git a/autotests/settings/CMakeLists.txt b/autotests/settings/CMakeLists.txt index f347957..64981fa 100644 --- a/autotests/settings/CMakeLists.txt +++ b/autotests/settings/CMakeLists.txt @@ -1,34 +1,35 @@ macro(NETWORKMANAGERQT_AUTOTESTS) foreach(_testname ${ARGN}) ecm_add_test(${_testname}.cpp LINK_LIBRARIES Qt5::Test KF5NetworkManagerQt_static) endforeach(_testname) endmacro(NETWORKMANAGERQT_AUTOTESTS) NETWORKMANAGERQT_AUTOTESTS( 8021xsettingtest adslsettingtest bluetoothsettingtest bondsettingtest bridgesettingtest bridgeportsettingtest cdmasettingtest connectionsettingtest gsmsettingtest infinibandsettingtest ipv4settingtest ipv6settingtest olpcmeshsettingtest pppsettingtest pppoesettingtest serialsettingtest vlansettingtest + vxlansettingtest vpnsettingtest wimaxsettingtest wiredsettingtest wirelesssettingtest wirelesssecuritysettingtest ) if (${NETWORKMANAGER_VERSION} VERSION_EQUAL 1.1.92 OR ${NETWORKMANAGER_VERSION} VERSION_GREATER 1.1.92) ecm_add_test(tunsettingtest.cpp LINK_LIBRARIES Qt5::Test KF5NetworkManagerQt_static) endif() diff --git a/autotests/settings/vxlansettingtest.cpp b/autotests/settings/vxlansettingtest.cpp new file mode 100644 index 0000000..06edd6f --- /dev/null +++ b/autotests/settings/vxlansettingtest.cpp @@ -0,0 +1,116 @@ +/* + Copyright 2018 Billy Laws + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "vxlansettingtest.h" + +#include "settings/vxlansetting.h" + +#include + +#include + +void VxlanSettingTest::testSetting_data() +{ + QTest::addColumn("ageing"); + QTest::addColumn("destinationPort"); + QTest::addColumn("id"); + QTest::addColumn("l2Miss"); + QTest::addColumn("l3Miss"); + QTest::addColumn("learning"); + QTest::addColumn("limit"); + QTest::addColumn("local"); + QTest::addColumn("parent"); + QTest::addColumn("proxy"); + QTest::addColumn("remote"); + QTest::addColumn("rsc"); + QTest::addColumn("sourcePortMax"); + QTest::addColumn("sourcePortMin"); + QTest::addColumn("tos"); + QTest::addColumn("ttl"); + + QTest::newRow("setting1") + << (quint32) 2 // ageing + << (quint32) 334 // destinationPort + << (quint32) 2 // id + << (bool) true // l2Miss + << (bool) true // l3Miss + << (bool) false // learning + << (quint32) 2 // limit + << QString("foo") // local + << QString("bar") // parent + << (bool) true // proxy + << QString("foo") // remote + << (bool) true // rsc + << (quint32) 2 // sourcePortMax + << (quint32) 2 // sourcePortMin + << (quint32) 2 // tos + << (quint32) 2; // ttl +} + +void VxlanSettingTest::testSetting() +{ + QFETCH(quint32, ageing); + QFETCH(quint32, destinationPort); + QFETCH(quint32, id); + QFETCH(bool, l2Miss); + QFETCH(bool, l3Miss); + QFETCH(bool, learning); + QFETCH(quint32, limit); + QFETCH(QString, local); + QFETCH(QString, parent); + QFETCH(bool, proxy); + QFETCH(QString, remote); + QFETCH(bool, rsc); + QFETCH(quint32, sourcePortMax); + QFETCH(quint32, sourcePortMin); + QFETCH(quint32, tos); + QFETCH(quint32, ttl); + + QVariantMap map; + + map.insert(QLatin1String(NM_SETTING_VXLAN_AGEING), ageing); + map.insert(QLatin1String(NM_SETTING_VXLAN_DESTINATION_PORT), destinationPort); + map.insert(QLatin1String(NM_SETTING_VXLAN_ID), id); + map.insert(QLatin1String(NM_SETTING_VXLAN_L2_MISS), l2Miss); + map.insert(QLatin1String(NM_SETTING_VXLAN_L3_MISS), l3Miss); + map.insert(QLatin1String(NM_SETTING_VXLAN_LEARNING), learning); + map.insert(QLatin1String(NM_SETTING_VXLAN_LIMIT), limit); + map.insert(QLatin1String(NM_SETTING_VXLAN_LOCAL), local); + map.insert(QLatin1String(NM_SETTING_VXLAN_PARENT), parent); + map.insert(QLatin1String(NM_SETTING_VXLAN_PROXY), proxy); + map.insert(QLatin1String(NM_SETTING_VXLAN_REMOTE), remote); + map.insert(QLatin1String(NM_SETTING_VXLAN_RSC), rsc); + map.insert(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MAX), sourcePortMax); + map.insert(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MIN), sourcePortMin); + map.insert(QLatin1String(NM_SETTING_VXLAN_TOS), tos); + map.insert(QLatin1String(NM_SETTING_VXLAN_TTL), ttl); + + NetworkManager::VxlanSetting setting; + setting.fromMap(map); + + QVariantMap map1 = setting.toMap(); + QVariantMap::const_iterator it = map.constBegin(); + while (it != map.constEnd()) { + QCOMPARE(it.value(), map1.value(it.key())); + ++it; + } +} + +QTEST_MAIN(VxlanSettingTest) diff --git a/autotests/settings/vxlansettingtest.h b/autotests/settings/vxlansettingtest.h new file mode 100644 index 0000000..24f521d --- /dev/null +++ b/autotests/settings/vxlansettingtest.h @@ -0,0 +1,35 @@ +/* + Copyright 2018 Billy Laws + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef NETWORKMANAGERQT_VXLANSETTING_TEST_H +#define NETWORKMANAGERQT_VXLANSETTING_TEST_H + +#include + +class VxlanSettingTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testSetting_data(); + void testSetting(); +}; + +#endif // NETWORKMANAGERQT_VXLANSETTING_TEST_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe8cd70..0c7645a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,275 +1,276 @@ # add_subdirectory(dbus) include_directories( ${NETWORKMANAGER_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/dbus ${CMAKE_CURRENT_SOURCE_DIR}/settings ) set(NetworkManagerQt_PART_SRCS device.cpp accesspoint.cpp activeconnection.cpp adsldevice.cpp bluetoothdevice.cpp bonddevice.cpp bridgedevice.cpp connection.cpp dhcp4config.cpp dhcp6config.cpp devicestatistics.cpp dnsconfiguration.cpp dnsdomain.cpp infinibanddevice.cpp ipaddress.cpp iproute.cpp ipconfig.cpp manager.cpp modemdevice.cpp olpcmeshdevice.cpp secretagent.cpp settings.cpp utils.cpp vlandevice.cpp vpnconnection.cpp vpnplugin.cpp wimaxdevice.cpp wimaxnsp.cpp wireddevice.cpp wirelessdevice.cpp wirelessnetwork.cpp generictypes.cpp genericdevice.cpp gredevice.cpp iptunneldevice.cpp macvlandevice.cpp teamdevice.cpp tundevice.cpp vethdevice.cpp wimaxdevice.cpp wimaxnsp.cpp ) set(NetworkManagerQt_SETTINGS_SRCS settings/adslsetting.cpp settings/bluetoothsetting.cpp settings/bondsetting.cpp settings/bridgesetting.cpp settings/bridgeportsetting.cpp settings/cdmasetting.cpp settings/connectionsettings.cpp settings/gsmsetting.cpp settings/ipv4setting.cpp settings/ipv6setting.cpp settings/infinibandsetting.cpp settings/olpcmeshsetting.cpp settings/pppsetting.cpp settings/pppoesetting.cpp settings/setting.cpp settings/serialsetting.cpp settings/security8021xsetting.cpp #settings/template.cpp settings/vlansetting.cpp settings/vpnsetting.cpp settings/wimaxsetting.cpp settings/wiredsetting.cpp settings/wirelesssetting.cpp settings/wirelesssecuritysetting.cpp settings/teamsetting.cpp settings/genericsetting.cpp settings/tunsetting.cpp + settings/vxlansetting.cpp ) set(DBUS_INTERFACE_SRCS dbus/accesspointinterface.cpp dbus/activeconnectioninterface.cpp dbus/adsldeviceinterface.cpp dbus/agentmanagerinterface.cpp dbus/bluetoothdeviceinterface.cpp dbus/bonddeviceinterface.cpp dbus/bridgedeviceinterface.cpp dbus/connectioninterface.cpp dbus/deviceinterface.cpp dbus/devicestatisticsinterface.cpp dbus/dhcp4configinterface.cpp dbus/dhcp6configinterface.cpp dbus/dnsmanagerinterface.cpp dbus/genericdeviceinterface.cpp dbus/gredeviceinterface.cpp dbus/checkpointinterface.cpp dbus/infinibanddeviceinterface.cpp dbus/iptunneldeviceinterface.cpp dbus/ip4configinterface.cpp dbus/ip6configinterface.cpp dbus/macsecdeviceinterface.cpp dbus/macvlandeviceinterface.cpp dbus/modemdeviceinterface.cpp dbus/networkmanagerinterface.cpp dbus/olpcmeshdeviceinterface.cpp dbus/pppinterface.cpp dbus/secretagentadaptor.cpp dbus/settingsinterface.cpp dbus/teamdeviceinterface.cpp dbus/tundeviceinterface.cpp dbus/vethdeviceinterface.cpp dbus/vlandeviceinterface.cpp dbus/vpnconnectioninterface.cpp dbus/vpnplugininterface.cpp dbus/vxlandeviceinterface.cpp dbus/wimaxdeviceinterface.cpp dbus/wimaxnspinterface.cpp dbus/wireddeviceinterface.cpp dbus/wirelessdeviceinterface.cpp ) add_library(KF5NetworkManagerQt SHARED ${NetworkManagerQt_PART_SRCS} ${NetworkManagerQt_SETTINGS_SRCS} ${DBUS_INTERFACE_SRCS}) generate_export_header(KF5NetworkManagerQt EXPORT_FILE_NAME ${NetworkManagerQt_BINARY_DIR}/networkmanagerqt/networkmanagerqt_export.h BASE_NAME NetworkManagerQt) add_library(KF5::NetworkManagerQt ALIAS KF5NetworkManagerQt) target_include_directories(KF5NetworkManagerQt INTERFACE "$") # for examples to build target_include_directories(KF5NetworkManagerQt PUBLIC "$") target_link_libraries(KF5NetworkManagerQt PUBLIC Qt5::Core Qt5::Network Qt5::DBus) set_target_properties(KF5NetworkManagerQt PROPERTIES VERSION ${NETWORKMANAGERQT_VERSION_STRING} SOVERSION ${NETWORKMANAGERQT_SOVERSION} EXPORT_NAME NetworkManagerQt ) if (${NETWORKMANAGER_VERSION} VERSION_EQUAL 1.0.0 OR ${NETWORKMANAGER_VERSION} VERSION_GREATER 1.0.0) target_include_directories(KF5NetworkManagerQt PUBLIC ${NM-CORE_INCLUDE_DIRS}) else() target_include_directories(KF5NetworkManagerQt PUBLIC ${NETWORKMANAGER_INCLUDE_DIRS} SYSTEM PUBLIC ${NM-UTIL_INCLUDE_DIRS} ${NM-GLIB_INCLUDE_DIRS}) endif() ########### static lib for tests ############### add_library(KF5NetworkManagerQt_static STATIC ${NetworkManagerQt_PART_SRCS} ${NetworkManagerQt_SETTINGS_SRCS} ${DBUS_INTERFACE_SRCS}) set_target_properties(KF5NetworkManagerQt_static PROPERTIES COMPILE_FLAGS -DNMQT_STATIC=1) target_link_libraries(KF5NetworkManagerQt_static PUBLIC Qt5::Core Qt5::Network Qt5::DBus) target_include_directories(KF5NetworkManagerQt_static PUBLIC "$") ecm_generate_headers(NetworkManagerQt_CamelCase_HEADERS HEADER_NAMES AccessPoint ActiveConnection AdslDevice BluetoothDevice BondDevice BridgeDevice Connection Device DeviceStatistics Dhcp4Config Dhcp6Config DnsConfiguration DnsDomain GenericDevice GenericTypes GreDevice InfinibandDevice IpAddress IpConfig IpRoute IpTunnelDevice MacVlanDevice Manager ModemDevice OlpcMeshDevice SecretAgent Settings TeamDevice TunDevice Utils VethDevice VlanDevice VpnConnection VpnPlugin WimaxDevice WimaxNsp WiredDevice WirelessDevice WirelessNetwork REQUIRED_HEADERS NetworkManagerQt_HEADERS PREFIX NetworkManagerQt ) ecm_generate_headers(NetworkManagerQt_SETTINGS_CamelCase_HEADERS HEADER_NAMES AdslSetting BluetoothSetting BondSetting BridgeSetting BridgePortSetting CdmaSetting ConnectionSettings GsmSetting GenericSetting InfinibandSetting Ipv4Setting Ipv6Setting OlpcMeshSetting PppoeSetting PppSetting Security8021xSetting SerialSetting Setting TeamSetting TunSetting VlanSetting VpnSetting WimaxSetting WiredSetting WirelessSecuritySetting WirelessSetting RELATIVE settings REQUIRED_HEADERS NetworkManagerQt_SETTINGS_HEADERS PREFIX NetworkManagerQt ) install(TARGETS KF5NetworkManagerQt EXPORT KF5NetworkManagerQtTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${NetworkManagerQt_CamelCase_HEADERS} ${NetworkManagerQt_SETTINGS_CamelCase_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/NetworkManagerQt/NetworkManagerQt COMPONENT Devel ) install(FILES ${NetworkManagerQt_BINARY_DIR}/networkmanagerqt/networkmanagerqt_export.h ${NetworkManagerQt_HEADERS} ${NetworkManagerQt_SETTINGS_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/NetworkManagerQt/networkmanagerqt COMPONENT Devel ) if(BUILD_QCH) ecm_add_qch( KF5NetworkManagerQt_QCH NAME NetworkManagerQt BASE_NAME KF5NetworkManagerQt VERSION ${KF5_VERSION} ORG_DOMAIN org.kde SOURCES # using only public headers, to cover only public API ${NetworkManagerQt_HEADERS} ${NetworkManagerQt_SETTINGS_HEADERS} MD_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md" LINK_QCHS Qt5Core_QCH Qt5Network_QCH Qt5DBus_QCH BLANK_MACROS NETWORKMANAGERQT_EXPORT NETWORKMANAGERQT_DEPRECATED NETWORKMANAGERQT_DEPRECATED_EXPORT TAGFILE_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} QCH_INSTALL_DESTINATION ${KDE_INSTALL_QTQCHDIR} COMPONENT Devel ) endif() include(ECMGeneratePriFile) ecm_generate_pri_file(BASE_NAME NetworkManagerQt LIB_NAME KF5NetworkManagerQt DEPS "core" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/NetworkManagerQt) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) diff --git a/src/settings/setting.cpp b/src/settings/setting.cpp index 774865a..651a30f 100644 --- a/src/settings/setting.cpp +++ b/src/settings/setting.cpp @@ -1,276 +1,281 @@ /* Copyright 2012-2013 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "setting.h" #undef signals #include #include #define signals Q_SIGNALS #include namespace NetworkManager { class SettingPrivate { public: SettingPrivate(); Setting::SettingType type; bool initialized; }; QDebug operator <<(QDebug dbg, const Setting &setting) { dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; return dbg.maybeSpace(); } } NetworkManager::SettingPrivate::SettingPrivate(): type(Setting::Wired), initialized(false) { } QString NetworkManager::Setting::typeAsString(NetworkManager::Setting::SettingType type) { QString typeString; switch (type) { case Cdma: typeString = QLatin1String(NM_SETTING_CDMA_SETTING_NAME); break; case Gsm: typeString = QLatin1String(NM_SETTING_GSM_SETTING_NAME); break; case Bluetooth: typeString = QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME); break; case Ipv4: typeString = QLatin1String(NM_SETTING_IP4_CONFIG_SETTING_NAME); break; case Ipv6: typeString = QLatin1String(NM_SETTING_IP6_CONFIG_SETTING_NAME); break; case Ppp: typeString = QLatin1String(NM_SETTING_PPP_SETTING_NAME); break; case Pppoe: typeString = QLatin1String(NM_SETTING_PPPOE_SETTING_NAME); break; case Security8021x: typeString = QLatin1String(NM_SETTING_802_1X_SETTING_NAME); break; case Serial: typeString = QLatin1String(NM_SETTING_SERIAL_SETTING_NAME); break; case Vpn: typeString = QLatin1String(NM_SETTING_VPN_SETTING_NAME); break; case Wired: typeString = QLatin1String(NM_SETTING_WIRED_SETTING_NAME); break; case Wireless: typeString = QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME); break; case WirelessSecurity: typeString = QLatin1String(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); break; case OlpcMesh: typeString = QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME); break; case Vlan: typeString = QLatin1String(NM_SETTING_VLAN_SETTING_NAME); break; case Wimax: typeString = QLatin1String(NM_SETTING_WIMAX_SETTING_NAME); break; case Bond: typeString = QLatin1String(NM_SETTING_BOND_SETTING_NAME); break; case Bridge: typeString = QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME); break; case Team: typeString = QLatin1String(NM_SETTING_TEAM_SETTING_NAME); break; + case Vxlan: + typeString = QLatin1String(NM_SETTING_VXLAN_SETTING_NAME); + break; case NetworkManager::Setting::Generic: typeString = QLatin1String(NM_SETTING_GENERIC_SETTING_NAME); break; default: break; } return typeString; } NetworkManager::Setting::SettingType NetworkManager::Setting::typeFromString(const QString &typeString) { SettingType type = Wired; if (typeString == QLatin1String(NM_SETTING_CDMA_SETTING_NAME)) { type = Cdma; } else if (typeString == QLatin1String(NM_SETTING_GSM_SETTING_NAME)) { type = Gsm; } else if (typeString == QLatin1String(NM_SETTING_BLUETOOTH_SETTING_NAME)) { type = Bluetooth; } else if (typeString == QLatin1String(NM_SETTING_IP4_CONFIG_SETTING_NAME)) { type = Ipv4; } else if (typeString == QLatin1String(NM_SETTING_IP6_CONFIG_SETTING_NAME)) { type = Ipv6; } else if (typeString == QLatin1String(NM_SETTING_PPP_SETTING_NAME)) { type = Ppp; } else if (typeString == QLatin1String(NM_SETTING_PPPOE_SETTING_NAME)) { type = Pppoe; } else if (typeString == QLatin1String(NM_SETTING_SERIAL_SETTING_NAME)) { type = Serial; } else if (typeString == QLatin1String(NM_SETTING_802_1X_SETTING_NAME)) { type = Security8021x; } else if (typeString == QLatin1String(NM_SETTING_VPN_SETTING_NAME)) { type = Vpn; } else if (typeString == QLatin1String(NM_SETTING_WIRED_SETTING_NAME)) { type = Wired; } else if (typeString == QLatin1String(NM_SETTING_WIRELESS_SETTING_NAME)) { type = Wireless; } else if (typeString == QLatin1String(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)) { type = WirelessSecurity; } else if (typeString == QLatin1String(NM_SETTING_OLPC_MESH_SETTING_NAME)) { type = OlpcMesh; } else if (typeString == QLatin1String(NM_SETTING_VLAN_SETTING_NAME)) { type = Vlan; } else if (typeString == QLatin1String(NM_SETTING_WIMAX_SETTING_NAME)) { type = Wimax; } else if (typeString == QLatin1String(NM_SETTING_BOND_SETTING_NAME)) { type = Bond; } else if (typeString == QLatin1String(NM_SETTING_BRIDGE_SETTING_NAME)) { type = Bridge; } else if (typeString == QLatin1String(NM_SETTING_TEAM_SETTING_NAME)) { type = Team; + } else if (typeString == QLatin1String(NM_SETTING_VXLAN_SETTING_NAME)) { + type = Vxlan; } else if (typeString == QLatin1String(NM_SETTING_GENERIC_SETTING_NAME)) { type = Generic; } return type; } NetworkManager::Setting::Setting(SettingType type) : d_ptr(new SettingPrivate()) { setType(type); } NetworkManager::Setting::Setting(const NetworkManager::Setting::Ptr &setting) : d_ptr(new SettingPrivate()) { setInitialized(!setting->isNull()); setType(setting->type()); } NetworkManager::Setting::~Setting() { delete d_ptr; } void NetworkManager::Setting::fromMap(const QVariantMap &map) { Q_UNUSED(map); } QVariantMap NetworkManager::Setting::toMap() const { return QVariantMap(); } QStringList NetworkManager::Setting::needSecrets(bool requestNew) const { Q_UNUSED(requestNew); return QStringList(); } QString NetworkManager::Setting::name() const { return QString(); } void NetworkManager::Setting::secretsFromMap(const QVariantMap &map) { Q_UNUSED(map); } void NetworkManager::Setting::secretsFromStringMap(const NMStringMap &map) { QVariantMap secretsMap; NMStringMap::ConstIterator i = map.constBegin(); while (i != map.constEnd()) { secretsMap.insert(i.key(), i.value()); ++i; } secretsFromMap(secretsMap); } QVariantMap NetworkManager::Setting::secretsToMap() const { return QVariantMap(); } NMStringMap NetworkManager::Setting::secretsToStringMap() const { NMStringMap ret; QVariantMap secretsMap = secretsToMap(); QVariantMap::ConstIterator i = secretsMap.constBegin(); while (i != secretsMap.constEnd()) { ret.insert(i.key(), i.value().toString()); ++i; } return ret; } void NetworkManager::Setting::setInitialized(bool initialized) { Q_D(Setting); d->initialized = initialized; } bool NetworkManager::Setting::isNull() const { Q_D(const Setting); return !d->initialized; } void NetworkManager::Setting::setType(NetworkManager::Setting::SettingType type) { Q_D(Setting); d->type = type; } NetworkManager::Setting::SettingType NetworkManager::Setting::type() const { Q_D(const Setting); return d->type; } diff --git a/src/settings/setting.h b/src/settings/setting.h index af546a4..ecbf44a 100644 --- a/src/settings/setting.h +++ b/src/settings/setting.h @@ -1,152 +1,153 @@ /* Copyright 2012-2013 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef NETWORKMANAGERQT_SETTING_H #define NETWORKMANAGERQT_SETTING_H #include #include "generictypes.h" #undef signals #include #define signals Q_SIGNALS #include #include #include #include namespace NetworkManager { class SettingPrivate; /** * Base class for all kinds of setting */ class NETWORKMANAGERQT_EXPORT Setting { public: typedef QSharedPointer Ptr; typedef QList List; enum SettingType { Adsl, Cdma, Gsm, Infiniband, Ipv4, Ipv6, Ppp, Pppoe, Security8021x, Serial, Vpn, Wired, Wireless, WirelessSecurity, Bluetooth, OlpcMesh, Vlan, Wimax, Bond, Bridge, BridgePort, Team, Generic, - Tun + Tun, + Vxlan }; enum SecretFlagType { None = 0, AgentOwned = 0x01, NotSaved = 0x02, NotRequired = 0x04 }; Q_DECLARE_FLAGS(SecretFlags, SecretFlagType) enum MacAddressRandomization { MacAddressRandomizationDefault = 0, MacAddressRandomizationNever, MacAddressRandomizationAlways }; static QString typeAsString(SettingType type); static SettingType typeFromString(const QString &type); explicit Setting(SettingType type); explicit Setting(const Ptr &setting); virtual ~Setting(); /** * @brief Must be reimplemented, default implementation does nothing */ virtual void fromMap(const QVariantMap &map); /** * @brief Must be reimplemented, default implementationd does nothing */ virtual QVariantMap toMap() const; virtual void secretsFromMap(const QVariantMap &map); /** * @brief secretsFromStringMap is a convenience function * to set the secrets from a map of strings. * @param map to extract secrets from */ virtual void secretsFromStringMap(const NMStringMap &map); virtual QVariantMap secretsToMap() const; /** * @brief secretsToStringMap is a convenience function * to get the secrets to map of strings. * @return string map with current secrets */ virtual NMStringMap secretsToStringMap() const; virtual QStringList needSecrets(bool requestNew = false) const; /** * @brief Must be reimplemented, default implementationd does nothing */ virtual QString name() const; void setInitialized(bool initialized); bool isNull() const; void setType(SettingType type); SettingType type() const; protected: SettingPrivate *d_ptr; private: Q_DECLARE_PRIVATE(Setting) }; Q_DECLARE_OPERATORS_FOR_FLAGS(Setting::SecretFlags) NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const Setting &setting); } #endif // NETWORKMANAGERQT_SETTING_H diff --git a/src/settings/vxlansetting.cpp b/src/settings/vxlansetting.cpp new file mode 100644 index 0000000..d4fbd74 --- /dev/null +++ b/src/settings/vxlansetting.cpp @@ -0,0 +1,467 @@ +/* + Copyright 2018 Billy Laws + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include "vxlansetting.h" +#include "vxlansetting_p.h" + +#include + +NetworkManager::VxlanSettingPrivate::VxlanSettingPrivate() + : name(NM_SETTING_VXLAN_SETTING_NAME) + , ageing(32) + , destinationPort(8472) + , id(0) + , l2Miss(false) + , l3Miss(false) + , learning(true) + , limit(0) + , proxy(false) + , rsc(false) + , sourcePortMax(0) + , sourcePortMin(0) + , tos(0) + , ttl(0) +{ } + +NetworkManager::VxlanSetting::VxlanSetting() + : Setting(Setting::Vxlan) + , d_ptr(new VxlanSettingPrivate()) +{ } + +NetworkManager::VxlanSetting::VxlanSetting(const NetworkManager::VxlanSetting::Ptr &other) + : Setting(other) + , d_ptr(new VxlanSettingPrivate()) +{ + setAgeing(other->ageing()); + setDestinationPort(other->destinationPort()); + setId(other->id()); + setL2Miss(other->l2Miss()); + setL3Miss(other->l3Miss()); + setLearning(other->learning()); + setLimit(other->limit()); + setLocal(other->local()); + setParent(other->parent()); + setProxy(other->proxy()); + setRemote(other->remote()); + setRsc(other->rsc()); + setSourcePortMax(other->sourcePortMax()); + setSourcePortMin(other->sourcePortMin()); + setTos(other->tos()); + setTtl(other->ttl()); +} + +NetworkManager::VxlanSetting::~VxlanSetting() +{ + delete d_ptr; +} + +QString NetworkManager::VxlanSetting::name() const +{ + Q_D(const VxlanSetting); + + return d->name; +} + +void NetworkManager::VxlanSetting::setAgeing(quint32 ageing) +{ + Q_D(VxlanSetting); + + d->ageing = ageing; +} + +quint32 NetworkManager::VxlanSetting::ageing() const +{ + Q_D(const VxlanSetting); + + return d->ageing; +} + +void NetworkManager::VxlanSetting::setDestinationPort(quint32 port) +{ + Q_D(VxlanSetting); + + d->destinationPort = port; +} + +quint32 NetworkManager::VxlanSetting::destinationPort() const +{ + Q_D(const VxlanSetting); + + return d->destinationPort; +} + +void NetworkManager::VxlanSetting::setId(quint32 id) +{ + Q_D(VxlanSetting); + + d->id = id; +} + +quint32 NetworkManager::VxlanSetting::id() const +{ + Q_D(const VxlanSetting); + + return d->id; +} + +void NetworkManager::VxlanSetting::setL2Miss(bool enable) +{ + Q_D(VxlanSetting); + + d->l2Miss = enable; +} + +bool NetworkManager::VxlanSetting::l2Miss() const +{ + Q_D(const VxlanSetting); + + return d->l2Miss; +} + +void NetworkManager::VxlanSetting::setL3Miss(bool enable) +{ + Q_D(VxlanSetting); + + d->l3Miss = enable; +} + +bool NetworkManager::VxlanSetting::l3Miss() const +{ + Q_D(const VxlanSetting); + + return d->l3Miss; +} + +void NetworkManager::VxlanSetting::setLearning(bool enable) +{ + Q_D(VxlanSetting); + + d->learning = enable; +} + +bool NetworkManager::VxlanSetting::learning() const +{ + Q_D(const VxlanSetting); + + return d->learning; +} + + +void NetworkManager::VxlanSetting::setLimit(quint32 limit) +{ + Q_D(VxlanSetting); + + d->limit = limit; +} + +quint32 NetworkManager::VxlanSetting::limit() const +{ + Q_D(const VxlanSetting); + + return d->limit; +} + +void NetworkManager::VxlanSetting::setLocal(QString local) +{ + Q_D(VxlanSetting); + + d->local = local; +} + +QString NetworkManager::VxlanSetting::local() const +{ + Q_D(const VxlanSetting); + + return d->local; +} + +void NetworkManager::VxlanSetting::setParent(QString parent) +{ + Q_D(VxlanSetting); + + d->parent = parent; +} + +QString NetworkManager::VxlanSetting::parent() const +{ + Q_D(const VxlanSetting); + + return d->parent; +} + +void NetworkManager::VxlanSetting::setProxy(bool enable) +{ + Q_D(VxlanSetting); + + d->proxy = enable; +} + +bool NetworkManager::VxlanSetting::proxy() const +{ + Q_D(const VxlanSetting); + + return d->proxy; +} + +void NetworkManager::VxlanSetting::setRemote(QString remote) +{ + Q_D(VxlanSetting); + + d->remote = remote; +} + +QString NetworkManager::VxlanSetting::remote() const +{ + Q_D(const VxlanSetting); + + return d->remote; +} + +void NetworkManager::VxlanSetting::setRsc(bool enable) +{ + Q_D(VxlanSetting); + + d->rsc = enable; +} + +bool NetworkManager::VxlanSetting::rsc() const +{ + Q_D(const VxlanSetting); + + return d->rsc; +} + +void NetworkManager::VxlanSetting::setSourcePortMax(quint32 maxPort) +{ + Q_D(VxlanSetting); + + d->sourcePortMax = maxPort; +} + +quint32 NetworkManager::VxlanSetting::sourcePortMax() const +{ + Q_D(const VxlanSetting); + + return d->sourcePortMax; +} + +void NetworkManager::VxlanSetting::setSourcePortMin(quint32 minPort) +{ + Q_D(VxlanSetting); + + d->sourcePortMin = minPort; +} + +quint32 NetworkManager::VxlanSetting::sourcePortMin() const +{ + Q_D(const VxlanSetting); + + return d->sourcePortMin; +} + +void NetworkManager::VxlanSetting::setTos(quint32 tos) +{ + Q_D(VxlanSetting); + + d->tos = tos; +} + +quint32 NetworkManager::VxlanSetting::tos() const +{ + Q_D(const VxlanSetting); + + return d->tos; +} + +void NetworkManager::VxlanSetting::setTtl(quint32 ttl) +{ + Q_D(VxlanSetting); + + d->ttl = ttl; +} + +quint32 NetworkManager::VxlanSetting::ttl() const +{ + Q_D(const VxlanSetting); + + return d->ttl; +} +void NetworkManager::VxlanSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_AGEING))) { + setAgeing(setting.value(QLatin1String(NM_SETTING_VXLAN_AGEING)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_DESTINATION_PORT))) { + setDestinationPort(setting.value(QLatin1String(NM_SETTING_VXLAN_DESTINATION_PORT)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_ID))) { + setId(setting.value(QLatin1String(NM_SETTING_VXLAN_ID)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_L2_MISS))) { + setL2Miss(setting.value(QLatin1String(NM_SETTING_VXLAN_L2_MISS)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_L3_MISS))) { + setL3Miss(setting.value(QLatin1String(NM_SETTING_VXLAN_L3_MISS)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_LEARNING))) { + setLearning(setting.value(QLatin1String(NM_SETTING_VXLAN_LEARNING)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_LIMIT))) { + setLimit(setting.value(QLatin1String(NM_SETTING_VXLAN_LIMIT)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_LOCAL))) { + setLocal(setting.value(QLatin1String(NM_SETTING_VXLAN_LOCAL)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_PARENT))) { + setParent(setting.value(QLatin1String(NM_SETTING_VXLAN_PARENT)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_PROXY))) { + setProxy(setting.value(QLatin1String(NM_SETTING_VXLAN_PROXY)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_REMOTE))) { + setRemote(setting.value(QLatin1String(NM_SETTING_VXLAN_REMOTE)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_RSC))) { + setRsc(setting.value(QLatin1String(NM_SETTING_VXLAN_RSC)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MAX))) { + setSourcePortMax(setting.value(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MAX)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MIN))) { + setSourcePortMin(setting.value(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MIN)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_TOS))) { + setTos(setting.value(QLatin1String(NM_SETTING_VXLAN_TOS)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_VXLAN_TTL))) { + setTtl(setting.value(QLatin1String(NM_SETTING_VXLAN_TTL)).toUInt()); + } +} + +QVariantMap NetworkManager::VxlanSetting::toMap() const +{ + QVariantMap setting; + + if (ageing() != 32) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_AGEING), ageing()); + } + + if (destinationPort() != 8472) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_DESTINATION_PORT), destinationPort()); + } + + if (id()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_ID), id()); + } + + if (l2Miss()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_L2_MISS), l2Miss()); + } + + if (l3Miss()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_L3_MISS), l3Miss()); + } + + if (!learning()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_LEARNING), learning()); + } + + if (limit()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_LIMIT), limit()); + } + + if (!local().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_LOCAL), local()); + } + + if (!parent().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_PARENT), parent()); + } + + if (proxy()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_PROXY), proxy()); + } + + if (!remote().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_REMOTE), remote()); + } + + if (rsc()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_RSC), rsc()); + } + + if (sourcePortMax()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MAX), sourcePortMax()); + } + + if (sourcePortMin()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_SOURCE_PORT_MIN), sourcePortMin()); + } + + if (tos()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_TOS), tos()); + } + + if (ttl()) { + setting.insert(QLatin1String(NM_SETTING_VXLAN_TTL), ttl()); + } + + return setting; +} + +QDebug NetworkManager::operator <<(QDebug dbg, const NetworkManager::VxlanSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_VXLAN_AGEING << ": " << setting.ageing() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_DESTINATION_PORT << ": " << setting.destinationPort() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_ID << ": " << setting.id() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_L2_MISS << ": " << setting.l2Miss() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_L3_MISS << ": " << setting.l3Miss() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_LEARNING << ": " << setting.learning() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_LIMIT << ": " << setting.limit() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_LOCAL << ": " << setting.local() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_PARENT << ": " << setting.parent() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_PROXY << ": " << setting.proxy() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_REMOTE << ": " << setting.remote() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_RSC << ": " << setting.rsc() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_SOURCE_PORT_MAX << ": " << setting.sourcePortMax() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_SOURCE_PORT_MIN << ": " << setting.sourcePortMin() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_TOS << ": " << setting.tos() << '\n'; + dbg.nospace() << NM_SETTING_VXLAN_TTL << ": " << setting.ttl() << '\n'; + + return dbg.maybeSpace(); +} diff --git a/src/settings/vxlansetting.h b/src/settings/vxlansetting.h new file mode 100644 index 0000000..d8e19a0 --- /dev/null +++ b/src/settings/vxlansetting.h @@ -0,0 +1,111 @@ +/* + Copyright 2018 Billy Laws + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef NETWORKMANAGERQT_VXLAN_SETTING_H +#define NETWORKMANAGERQT_VXLAN_SETTING_H + +#include +#include "setting.h" + +#include + +namespace NetworkManager +{ + +class VxlanSettingPrivate; + +/** + * Represents vxlan setting + */ +class NETWORKMANAGERQT_EXPORT VxlanSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + VxlanSetting(); + explicit VxlanSetting(const Ptr &other); + ~VxlanSetting() override; + + QString name() const override; + + void setAgeing(quint32 ageing); + quint32 ageing() const; + + void setDestinationPort(quint32 port); + quint32 destinationPort() const; + + void setId(quint32 id); + quint32 id() const; + + void setL2Miss(bool enable); + bool l2Miss() const; + + void setL3Miss(bool enable); + bool l3Miss() const; + + void setLearning(bool enable); + bool learning() const; + + void setLimit(quint32 limit); + quint32 limit() const; + + void setLocal(QString local); + QString local() const; + + void setParent(QString parent); + QString parent() const; + + void setProxy(bool enable); + bool proxy() const; + + void setRemote(QString remote); + QString remote() const; + + void setRsc(bool enable); + bool rsc() const; + + void setSourcePortMax(quint32 maxPort); + quint32 sourcePortMax() const; + + void setSourcePortMin(quint32 minPort); + quint32 sourcePortMin() const; + + void setTos(quint32 tos); + quint32 tos() const; + + void setTtl(quint32 ttl); + quint32 ttl() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + VxlanSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(VxlanSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const VxlanSetting &setting); + +} + +#endif // NETWORKMANAGERQT_VXLAN_SETTING_H diff --git a/src/settings/vxlansetting_p.h b/src/settings/vxlansetting_p.h new file mode 100644 index 0000000..b0f3313 --- /dev/null +++ b/src/settings/vxlansetting_p.h @@ -0,0 +1,55 @@ +/* + Copyright 2018 Billy Laws + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#ifndef NETWORKMANAGERQT_VXLAN_SETTING_P_H +#define NETWORKMANAGERQT_VXLAN_SETTING_P_H + +#include + +namespace NetworkManager +{ + +class VxlanSettingPrivate +{ +public: + VxlanSettingPrivate(); + + QString name; + quint32 ageing; + quint32 destinationPort; + quint32 id; + bool l2Miss; + bool l3Miss; + bool learning; + quint32 limit; + QString local; + QString parent; + bool proxy; + QString remote; + bool rsc; + quint32 sourcePortMax; + quint32 sourcePortMin; + quint32 tos; + quint32 ttl; +}; + +} + +#endif // NETWORKMANAGERQT_VXLAN_SETTING_P_H