Index: autotests/settings/CMakeLists.txt =================================================================== --- autotests/settings/CMakeLists.txt +++ autotests/settings/CMakeLists.txt @@ -28,6 +28,7 @@ pppoesettingtest proxysettingtest serialsettingtest + teamportsettingtest tunsettingtest tcsettingtest usersettingtest Index: autotests/settings/teamportsettingtest.h =================================================================== --- /dev/null +++ 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 + Index: autotests/settings/teamportsettingtest.cpp =================================================================== --- /dev/null +++ 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()) { + QCOMPARE(varMap.value(ite.key()), val1.value()); + ++comparedvals; + } + } + ++ite; + } + if (comparedvals == varMap.size()) { + comparedMaps++; + } + } + } + QCOMPARE(comparedMaps, list.count()); +} + +QTEST_MAIN(TeamPortSettingTest) Index: src/CMakeLists.txt =================================================================== --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -75,6 +75,7 @@ settings/setting.cpp settings/serialsetting.cpp settings/security8021xsetting.cpp + settings/teamportsetting.cpp #settings/template.cpp settings/vlansetting.cpp settings/vpnsetting.cpp Index: src/settings/setting.h =================================================================== --- src/settings/setting.h +++ src/settings/setting.h @@ -81,7 +81,8 @@ OvsPatch, OvsPort, Match, - Tc + Tc, + TeamPort }; enum SecretFlagType { Index: src/settings/setting.cpp =================================================================== --- src/settings/setting.cpp +++ src/settings/setting.cpp @@ -32,11 +32,12 @@ #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) @@ -165,6 +166,9 @@ 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; @@ -239,6 +243,8 @@ 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; Index: src/settings/teamportsetting.h =================================================================== --- /dev/null +++ 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 + Index: src/settings/teamportsetting.cpp =================================================================== --- /dev/null +++ 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() >= 0) { + 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(); +} Index: src/settings/teamportsetting_p.h =================================================================== --- /dev/null +++ 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 +