diff --git a/autotests/settings/CMakeLists.txt b/autotests/settings/CMakeLists.txt index b727e18..9a1c6ec 100644 --- a/autotests/settings/CMakeLists.txt +++ b/autotests/settings/CMakeLists.txt @@ -1,42 +1,43 @@ 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 iptunnelsettingtest ipv4settingtest ipv6settingtest matchsettingtest olpcmeshsettingtest ovsbridgesettingtest ovsinterfacesettingtest ovspatchsettingtest ovsportsettingtest pppsettingtest pppoesettingtest proxysettingtest serialsettingtest + teamportsettingtest tunsettingtest tcsettingtest usersettingtest vlansettingtest vxlansettingtest vpnsettingtest wimaxsettingtest wiredsettingtest wirelesssettingtest wirelesssecuritysettingtest ) diff --git a/autotests/settings/teamportsettingtest.cpp b/autotests/settings/teamportsettingtest.cpp new file mode 100644 index 0000000..d224d31 --- /dev/null +++ b/autotests/settings/teamportsettingtest.cpp @@ -0,0 +1,130 @@ +/* + Copyright 2018 Pranav Gade + + 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 "teamportsettingtest.h" + +#include "settings/teamportsetting.h" + +#include + +#include + +#if !NM_CHECK_VERSION(1, 10, 0) +#define NM_SETTING_TEAM_PORT_CONFIG "config" +#define NM_SETTING_TEAM_PORT_QUEUE_ID "queue-id" +#define NM_SETTING_TEAM_PORT_PRIO "prio" +#define NM_SETTING_TEAM_PORT_STICKY "sticky" +#define NM_SETTING_TEAM_PORT_LACP_PRIO "lacp-prio" +#define NM_SETTING_TEAM_PORT_LACP_KEY "lacp-key" +#define NM_SETTING_TEAM_PORT_LINK_WATCHERS "link-watchers" +#endif + +void TeamPortSettingTest::testSetting_data() +{ + QTest::addColumn("config"); + QTest::addColumn("lacpKey"); + QTest::addColumn("lacpPrio"); + QTest::addColumn("prio"); + QTest::addColumn("queueId"); + QTest::addColumn("sticky"); + QTest::addColumn("linkWatchers"); + + NMVariantMapList linkWatchers; + QVariantMap linkWatcher; + linkWatcher["one"] = "1"; + linkWatcher["two"] = 2; + linkWatchers.append(linkWatcher); + + + QTest::newRow("setting1") + << QString("abc") // config + << (qint32)1 // lacpKey + << (qint32)1 // lacpPrio + << (qint32)1 // prio + << (qint32)1 // queueId + << true // sticky + << linkWatchers; // linkWatchers +} + +void TeamPortSettingTest::testSetting() +{ + QFETCH(QString, config); + QFETCH(qint32, lacpKey); + QFETCH(qint32, lacpPrio); + QFETCH(qint32, prio); + QFETCH(qint32, queueId); + QFETCH(bool, sticky); + QFETCH(NMVariantMapList, linkWatchers); + + QVariantMap map; + + map.insert(QLatin1String(NM_SETTING_TEAM_PORT_CONFIG), config); + map.insert(QLatin1String(NM_SETTING_TEAM_PORT_LACP_KEY), lacpKey); + map.insert(QLatin1String(NM_SETTING_TEAM_PORT_LACP_PRIO), lacpPrio); + map.insert(QLatin1String(NM_SETTING_TEAM_PORT_PRIO), prio); + map.insert(QLatin1String(NM_SETTING_TEAM_PORT_QUEUE_ID), queueId); + map.insert(QLatin1String(NM_SETTING_TEAM_PORT_STICKY), sticky); + map.insert(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS), QVariant::fromValue(linkWatchers)); + + NetworkManager::TeamPortSetting setting; + setting.fromMap(map); + + QVariantMap map1 = setting.toMap(); + + // Will fail if set some default values, because they are skipped in toMap() method + QVariantMap::const_iterator it = map.constBegin(); + while (it != map.constEnd()) { + if (it.key() != QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS)) { + QCOMPARE(it.value(), map1.value(it.key())); + } + ++it; + } + + NMVariantMapList list = map.value(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS)).value(); + NMVariantMapList list1 = map1.value(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS)).value(); + + QCOMPARE(list.count(), list1.count()); + + int comparedMaps = 0; + for (int i = 0; i < list.size(); ++i) { + QVariantMap varMap = list.at(i); + for (int j = 0; j < list1.size(); ++j) { + QVariantMap varMap1 = list1.at(i); + QVariantMap::const_iterator ite = varMap.constBegin(); + int comparedvals = 0; + while (ite != varMap.constEnd()) { + QVariantMap::const_iterator val1 = varMap1.constFind(ite.key()); + if (val1 != varMap1.constEnd()) { + if (varMap.value(ite.key()) == val1.value()) { + ++comparedvals; + } + } + ++ite; + } + if (comparedvals == varMap.size()) { + comparedMaps++; + } + } + } + ++it; + QCOMPARE(comparedMaps, list.count()); +} + +QTEST_MAIN(TeamPortSettingTest) diff --git a/autotests/settings/teamportsettingtest.h b/autotests/settings/teamportsettingtest.h new file mode 100644 index 0000000..e8daff0 --- /dev/null +++ b/autotests/settings/teamportsettingtest.h @@ -0,0 +1,36 @@ +/* + Copyright 2018 Pranav Gade + + 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_TEAMPORTSETTING_TEST_H +#define NETWORKMANAGERQT_TEAMPORTSETTING_TEST_H + +#include + +class TeamPortSettingTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void testSetting_data(); + void testSetting(); +}; + +#endif // NETWORKMANAGERQT_TEAMPORTSETTING_TEST_H + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f75a874..b15b172 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,286 +1,287 @@ # 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/iptunnelsetting.cpp settings/ipv4setting.cpp settings/ipv6setting.cpp settings/infinibandsetting.cpp settings/matchsetting.cpp settings/olpcmeshsetting.cpp settings/ovsbridgesetting.cpp settings/ovsinterfacesetting.cpp settings/ovspatchsetting.cpp settings/ovsportsetting.cpp settings/pppsetting.cpp settings/pppoesetting.cpp settings/proxysetting.cpp settings/setting.cpp settings/serialsetting.cpp settings/security8021xsetting.cpp + settings/teamportsetting.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/tcsetting.cpp settings/genericsetting.cpp settings/tunsetting.cpp settings/usersetting.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 IpTunnelSetting 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 177ed39..c072bb9 100644 --- a/src/settings/setting.cpp +++ b/src/settings/setting.cpp @@ -1,346 +1,352 @@ /* 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 #if !NM_CHECK_VERSION(1, 14, 0) #define NM_SETTING_MATCH_SETTING_NAME "match" #endif #if !NM_CHECK_VERSION(1, 10, 0) -#define NM_SETTING_TC_CONFIG_SETTING_NAME "tc" #define NM_SETTING_OVS_BRIDGE_SETTING_NAME "ovs-bridge" #define NM_SETTING_OVS_INTERFACE_SETTING_NAME "ovs-interface" #define NM_SETTING_OVS_PATCH_SETTING_NAME "ovs-patch" #define NM_SETTING_OVS_PORT_SETTING_NAME "ovs-port" +#define NM_SETTING_TC_CONFIG_SETTING_NAME "tc" +#define NM_SETTING_TEAM_PORT_SETTING_NAME "team-port" #endif #if !NM_CHECK_VERSION(1, 8, 0) #define NM_SETTING_USER_SETTING_NAME "user" #endif #if !NM_CHECK_VERSION(1, 6, 0) #define NM_SETTING_PROXY_SETTING_NAME "proxy" #endif 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 IpTunnel: typeString = QLatin1String(NM_SETTING_IP_TUNNEL_SETTING_NAME); break; case Proxy: typeString = QLatin1String(NM_SETTING_PROXY_SETTING_NAME); break; case User: typeString = QLatin1String(NM_SETTING_USER_SETTING_NAME); break; case OvsInterface: typeString = QLatin1String(NM_SETTING_OVS_INTERFACE_SETTING_NAME); break; case OvsBridge: typeString = QLatin1String(NM_SETTING_OVS_BRIDGE_SETTING_NAME); break; case OvsPatch: typeString = QLatin1String(NM_SETTING_OVS_PATCH_SETTING_NAME); break; case OvsPort: typeString = QLatin1String(NM_SETTING_OVS_PORT_SETTING_NAME); break; case Match: typeString = QLatin1String(NM_SETTING_MATCH_SETTING_NAME); break; case Tc: typeString = QLatin1String(NM_SETTING_TC_CONFIG_SETTING_NAME); break; + case TeamPort: + typeString = QLatin1String(NM_SETTING_TEAM_PORT_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_IP_TUNNEL_SETTING_NAME)) { type = IpTunnel; } else if (typeString == QLatin1String(NM_SETTING_GENERIC_SETTING_NAME)) { type = Generic; } else if (typeString == QLatin1String(NM_SETTING_USER_SETTING_NAME)) { type = User; } else if (typeString == QLatin1String(NM_SETTING_PROXY_SETTING_NAME)) { type = Proxy; } else if (typeString == QLatin1String(NM_SETTING_OVS_INTERFACE_SETTING_NAME)) { type = OvsInterface; } else if (typeString == QLatin1String(NM_SETTING_OVS_BRIDGE_SETTING_NAME)) { type = OvsBridge; } else if (typeString == QLatin1String(NM_SETTING_OVS_PATCH_SETTING_NAME)) { type = OvsPatch; } else if (typeString == QLatin1String(NM_SETTING_OVS_PORT_SETTING_NAME)) { type = OvsPort; } else if (typeString == QLatin1String(NM_SETTING_MATCH_SETTING_NAME)) { type = Match; } else if (typeString == QLatin1String(NM_SETTING_TC_CONFIG_SETTING_NAME)) { type = Tc; + } else if (typeString == QLatin1String(NM_SETTING_TEAM_PORT_SETTING_NAME)) { + type = TeamPort; } 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 43b5d79..067cf38 100644 --- a/src/settings/setting.h +++ b/src/settings/setting.h @@ -1,162 +1,163 @@ /* 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, Vxlan, IpTunnel, Proxy, User, OvsBridge, OvsInterface, OvsPatch, OvsPort, Match, - Tc + Tc, + TeamPort }; 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/teamportsetting.cpp b/src/settings/teamportsetting.cpp new file mode 100644 index 0000000..28762a3 --- /dev/null +++ b/src/settings/teamportsetting.cpp @@ -0,0 +1,263 @@ +/* + Copyright Pranav Gade + + 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 "teamportsetting.h" +#include "teamportsetting_p.h" + +#include + +#if !NM_CHECK_VERSION(1, 10, 0) +#define NM_SETTING_TEAM_PORT_SETTING_NAME "team-port" + +#define NM_SETTING_TEAM_PORT_CONFIG "config" +#define NM_SETTING_TEAM_PORT_QUEUE_ID "queue-id" +#define NM_SETTING_TEAM_PORT_PRIO "prio" +#define NM_SETTING_TEAM_PORT_STICKY "sticky" +#define NM_SETTING_TEAM_PORT_LACP_PRIO "lacp-prio" +#define NM_SETTING_TEAM_PORT_LACP_KEY "lacp-key" +#define NM_SETTING_TEAM_PORT_LINK_WATCHERS "link-watchers" +#endif + +NetworkManager::TeamPortSettingPrivate::TeamPortSettingPrivate() + : name(NM_SETTING_TEAM_PORT_SETTING_NAME) + , lacpKey(0) + , lacpPrio(255) + , prio(0) + , queueId(-1) + , sticky(false) +{ } + +NetworkManager::TeamPortSetting::TeamPortSetting() + : Setting(Setting::TeamPort) + , d_ptr(new TeamPortSettingPrivate()) +{ } + +NetworkManager::TeamPortSetting::TeamPortSetting(const Ptr &other) + : Setting(other) + , d_ptr(new TeamPortSettingPrivate()) +{ + config(other->config()); + lacpKey(other->lacpKey()); + lacpPrio(other->lacpPrio()); + prio(other->prio()); + queueId(other->queueId()); + sticky(other->sticky()); + setLinkWatchers(other->linkWatchers()); +} + +NetworkManager::TeamPortSetting::~TeamPortSetting() +{ + delete d_ptr; +} + +QString NetworkManager::TeamPortSetting::name() const +{ + Q_D(const TeamPortSetting); + + return d->name; +} + +void NetworkManager::TeamPortSetting::config(QString config) +{ + Q_D(TeamPortSetting); + + d->config = config; +} + +QString NetworkManager::TeamPortSetting::config() const +{ + Q_D(const TeamPortSetting); + + return d->config; +} + +void NetworkManager::TeamPortSetting::lacpKey(qint32 key) +{ + Q_D(TeamPortSetting); + + d->lacpKey = key; +} + +qint32 NetworkManager::TeamPortSetting::lacpKey() const +{ + Q_D(const TeamPortSetting); + + return d->lacpKey; +} + +void NetworkManager::TeamPortSetting::lacpPrio(qint32 priority) +{ + Q_D(TeamPortSetting); + + d->lacpPrio = priority; +} + +qint32 NetworkManager::TeamPortSetting::lacpPrio() const +{ + Q_D(const TeamPortSetting); + + return d->lacpPrio; +} + +void NetworkManager::TeamPortSetting::prio(qint32 prio) +{ + Q_D(TeamPortSetting); + + d->prio = prio; +} + +qint32 NetworkManager::TeamPortSetting::prio() const +{ + Q_D(const TeamPortSetting); + + return d->prio; +} + +void NetworkManager::TeamPortSetting::queueId(qint32 id) +{ + Q_D(TeamPortSetting); + + d->queueId = id; +} + +qint32 NetworkManager::TeamPortSetting::queueId() const +{ + Q_D(const TeamPortSetting); + + return d->queueId; +} + +void NetworkManager::TeamPortSetting::sticky(bool sticky) +{ + Q_D(TeamPortSetting); + + d->sticky = sticky; +} + +bool NetworkManager::TeamPortSetting::sticky() const +{ + Q_D(const TeamPortSetting); + + return d->sticky; +} + +void NetworkManager::TeamPortSetting::setLinkWatchers(const NMVariantMapList &linkWatchers) +{ + Q_D(TeamPortSetting); + + d->linkWatchers = linkWatchers; +} + +NMVariantMapList NetworkManager::TeamPortSetting::linkWatchers() const +{ + Q_D(const TeamPortSetting); + + return d->linkWatchers; +} + + +void NetworkManager::TeamPortSetting::fromMap(const QVariantMap &setting) +{ + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_CONFIG))) { + config(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_CONFIG)).toString()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_LACP_KEY))) { + lacpKey(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_LACP_KEY)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_LACP_PRIO))) { + lacpPrio(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_LACP_PRIO)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_PRIO))) { + prio(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_PRIO)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_QUEUE_ID))) { + queueId(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_QUEUE_ID)).toUInt()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_STICKY))) { + sticky(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_STICKY)).toBool()); + } + + if (setting.contains(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS))) { + setLinkWatchers(qdbus_cast(setting.value(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS)))); + } +} + +QVariantMap NetworkManager::TeamPortSetting::toMap() const +{ + QVariantMap setting; + + if (!config().isEmpty()) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_CONFIG), config()); + } + + if (lacpKey() != 0) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_LACP_KEY), lacpKey()); + } + + if (lacpPrio() != 255) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_LACP_PRIO), lacpPrio()); + } + + if (prio() != 0) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_PRIO), prio()); + } + + if (queueId() != -1) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_QUEUE_ID), queueId()); + } + + if (sticky()) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_STICKY), sticky()); + } + + if (!linkWatchers().empty()) { + setting.insert(QLatin1String(NM_SETTING_TEAM_PORT_LINK_WATCHERS), QVariant::fromValue(linkWatchers())); + } + + return setting; +} + +QDebug NetworkManager::operator <<(QDebug dbg, const NetworkManager::TeamPortSetting &setting) +{ + dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; + dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; + + dbg.nospace() << NM_SETTING_TEAM_PORT_CONFIG << ": " << setting.config() << '\n'; + dbg.nospace() << NM_SETTING_TEAM_PORT_LACP_KEY << ": " << setting.lacpKey() << '\n'; + dbg.nospace() << NM_SETTING_TEAM_PORT_LACP_PRIO << ": " << setting.lacpPrio() << '\n'; + dbg.nospace() << NM_SETTING_TEAM_PORT_PRIO << ": " << setting.prio() << '\n'; + dbg.nospace() << NM_SETTING_TEAM_PORT_QUEUE_ID << ": " << setting.queueId() << '\n'; + dbg.nospace() << NM_SETTING_TEAM_PORT_STICKY << ": " << setting.sticky() << '\n'; + + dbg.nospace() << NM_SETTING_TEAM_PORT_LINK_WATCHERS << ": " << '\n'; + Q_FOREACH (const QVariantMap & linkWatcher, setting.linkWatchers()) { + QVariantMap::const_iterator i = linkWatcher.constBegin(); + while (i != linkWatcher.constEnd()) { + dbg.nospace() << i.key() << ": " << i.value() << '\n'; + } + } + + return dbg.maybeSpace(); +} diff --git a/src/settings/teamportsetting.h b/src/settings/teamportsetting.h new file mode 100644 index 0000000..b186f3a --- /dev/null +++ b/src/settings/teamportsetting.h @@ -0,0 +1,86 @@ +/* + Copyright 2018 Pranav Gade + + 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_TEAM_PORT_SETTING_H +#define NETWORKMANAGERQT_TEAM_PORT_SETTING_H + +#include +#include "setting.h" + +#include + +namespace NetworkManager +{ + +class TeamPortSettingPrivate; + +/** + * Represents TeamPort setting + */ +class NETWORKMANAGERQT_EXPORT TeamPortSetting : public Setting +{ +public: + typedef QSharedPointer Ptr; + typedef QList List; + + TeamPortSetting(); + explicit TeamPortSetting(const Ptr &other); + ~TeamPortSetting() override; + + QString name() const override; + + void config(QString config); + QString config() const; + + void lacpKey(qint32 key); + qint32 lacpKey() const; + + void lacpPrio(qint32 priority); + qint32 lacpPrio() const; + + void prio(qint32 prio); + qint32 prio() const; + + void queueId(qint32 id); + qint32 queueId() const; + + void sticky(bool sticky); + bool sticky() const; + + void setLinkWatchers(const NMVariantMapList &linkWatchers); + NMVariantMapList linkWatchers() const; + + void fromMap(const QVariantMap &setting) override; + + QVariantMap toMap() const override; + +protected: + TeamPortSettingPrivate *d_ptr; + +private: + Q_DECLARE_PRIVATE(TeamPortSetting) +}; + +NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const TeamPortSetting &setting); + +} + +#endif // NETWORKMANAGERQT_TEAM_PORT_SETTING_H + diff --git a/src/settings/teamportsetting_p.h b/src/settings/teamportsetting_p.h new file mode 100644 index 0000000..d07693a --- /dev/null +++ b/src/settings/teamportsetting_p.h @@ -0,0 +1,50 @@ +/* + Copyright 2018 Pranav Gade + + 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_TEAM_PORT_SETTING_P_H +#define NETWORKMANAGERQT_TEAM_PORT_SETTING_P_H + +#include + +typedef QList NMVariantMapList; + +namespace NetworkManager +{ + +class TeamPortSettingPrivate +{ +public: + TeamPortSettingPrivate(); + + QString name; + + QString config; + qint32 lacpKey; + qint32 lacpPrio; + qint32 prio; + qint32 queueId; + bool sticky; + NMVariantMapList linkWatchers; +}; + +} + +#endif // NETWORKMANAGERQT_TEAM_PORT_SETTING_P_H +