1 | /* |
2 | SPDX-FileCopyrightText: Pranav Gade <pranavgade20@gmail.com> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | |
7 | #include "ovsbridgesetting.h" |
8 | #include "ovsbridgesetting_p.h" |
9 | |
10 | #include <QDebug> |
11 | |
12 | #if !NM_CHECK_VERSION(1, 10, 0) |
13 | #define NM_SETTING_OVS_BRIDGE_SETTING_NAME "ovs-bridge" |
14 | #define NM_SETTING_OVS_BRIDGE_FAIL_MODE "fail-mode" |
15 | #define NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE "mcast-snooping-enable" |
16 | #define NM_SETTING_OVS_BRIDGE_RSTP_ENABLE "rstp-enable" |
17 | #define NM_SETTING_OVS_BRIDGE_STP_ENABLE "stp-enable" |
18 | #endif |
19 | |
20 | NetworkManager::OvsBridgeSettingPrivate::OvsBridgeSettingPrivate() |
21 | : name(NM_SETTING_OVS_BRIDGE_SETTING_NAME) |
22 | , mcastSnoopingEnable(false) |
23 | , rstpEnable(false) |
24 | , stpEnable(false) |
25 | { |
26 | } |
27 | |
28 | NetworkManager::OvsBridgeSetting::OvsBridgeSetting() |
29 | : Setting(Setting::OvsBridge) |
30 | , d_ptr(new OvsBridgeSettingPrivate()) |
31 | { |
32 | } |
33 | |
34 | NetworkManager::OvsBridgeSetting::OvsBridgeSetting(const Ptr &other) |
35 | : Setting(other) |
36 | , d_ptr(new OvsBridgeSettingPrivate()) |
37 | { |
38 | setFailMode(other->failMode()); |
39 | setMcastSnoopingEnable(other->mcastSnoopingEnable()); |
40 | setRstpEnable(other->rstpEnable()); |
41 | setStpEnable(other->stpEnable()); |
42 | } |
43 | |
44 | NetworkManager::OvsBridgeSetting::~OvsBridgeSetting() |
45 | { |
46 | delete d_ptr; |
47 | } |
48 | |
49 | QString NetworkManager::OvsBridgeSetting::name() const |
50 | { |
51 | Q_D(const OvsBridgeSetting); |
52 | |
53 | return d->name; |
54 | } |
55 | |
56 | void NetworkManager::OvsBridgeSetting::setMcastSnoopingEnable(bool mcastSnoopingEnable) |
57 | { |
58 | Q_D(OvsBridgeSetting); |
59 | |
60 | d->mcastSnoopingEnable = mcastSnoopingEnable; |
61 | } |
62 | |
63 | bool NetworkManager::OvsBridgeSetting::mcastSnoopingEnable() const |
64 | { |
65 | Q_D(const OvsBridgeSetting); |
66 | |
67 | return d->mcastSnoopingEnable; |
68 | } |
69 | |
70 | void NetworkManager::OvsBridgeSetting::setRstpEnable(bool rstpEnable) |
71 | { |
72 | Q_D(OvsBridgeSetting); |
73 | |
74 | d->rstpEnable = rstpEnable; |
75 | } |
76 | |
77 | bool NetworkManager::OvsBridgeSetting::rstpEnable() const |
78 | { |
79 | Q_D(const OvsBridgeSetting); |
80 | |
81 | return d->rstpEnable; |
82 | } |
83 | |
84 | void NetworkManager::OvsBridgeSetting::setStpEnable(bool stpEnable) |
85 | { |
86 | Q_D(OvsBridgeSetting); |
87 | |
88 | d->stpEnable = stpEnable; |
89 | } |
90 | |
91 | bool NetworkManager::OvsBridgeSetting::stpEnable() const |
92 | { |
93 | Q_D(const OvsBridgeSetting); |
94 | |
95 | return d->stpEnable; |
96 | } |
97 | |
98 | void NetworkManager::OvsBridgeSetting::setFailMode(const QString &mode) |
99 | { |
100 | Q_D(OvsBridgeSetting); |
101 | |
102 | d->failMode = mode; |
103 | } |
104 | |
105 | QString NetworkManager::OvsBridgeSetting::failMode() const |
106 | { |
107 | Q_D(const OvsBridgeSetting); |
108 | |
109 | return d->failMode; |
110 | } |
111 | |
112 | void NetworkManager::OvsBridgeSetting::fromMap(const QVariantMap &setting) |
113 | { |
114 | if (setting.contains(key: QLatin1String(NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE))) { |
115 | setMcastSnoopingEnable(setting.value(key: QLatin1String(NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE)).toBool()); |
116 | } |
117 | |
118 | if (setting.contains(key: QLatin1String(NM_SETTING_OVS_BRIDGE_RSTP_ENABLE))) { |
119 | setRstpEnable(setting.value(key: QLatin1String(NM_SETTING_OVS_BRIDGE_RSTP_ENABLE)).toBool()); |
120 | } |
121 | |
122 | if (setting.contains(key: QLatin1String(NM_SETTING_OVS_BRIDGE_STP_ENABLE))) { |
123 | setStpEnable(setting.value(key: QLatin1String(NM_SETTING_OVS_BRIDGE_STP_ENABLE)).toBool()); |
124 | } |
125 | |
126 | if (setting.contains(key: QLatin1String(NM_SETTING_OVS_BRIDGE_FAIL_MODE))) { |
127 | setFailMode(setting.value(key: QLatin1String(NM_SETTING_OVS_BRIDGE_FAIL_MODE)).toString()); |
128 | } |
129 | } |
130 | |
131 | QVariantMap NetworkManager::OvsBridgeSetting::toMap() const |
132 | { |
133 | QVariantMap setting; |
134 | |
135 | setting.insert(key: QLatin1String(NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE), value: mcastSnoopingEnable()); |
136 | setting.insert(key: QLatin1String(NM_SETTING_OVS_BRIDGE_RSTP_ENABLE), value: rstpEnable()); |
137 | setting.insert(key: QLatin1String(NM_SETTING_OVS_BRIDGE_STP_ENABLE), value: stpEnable()); |
138 | |
139 | if (!failMode().isEmpty()) { |
140 | setting.insert(key: QLatin1String(NM_SETTING_OVS_BRIDGE_FAIL_MODE), value: failMode()); |
141 | } |
142 | |
143 | return setting; |
144 | } |
145 | |
146 | QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::OvsBridgeSetting &setting) |
147 | { |
148 | dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n'; |
149 | dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; |
150 | |
151 | dbg.nospace() << NM_SETTING_OVS_BRIDGE_MCAST_SNOOPING_ENABLE << ": " << setting.mcastSnoopingEnable() << '\n'; |
152 | dbg.nospace() << NM_SETTING_OVS_BRIDGE_RSTP_ENABLE << ": " << setting.rstpEnable() << '\n'; |
153 | dbg.nospace() << NM_SETTING_OVS_BRIDGE_STP_ENABLE << ": " << setting.stpEnable() << '\n'; |
154 | dbg.nospace() << NM_SETTING_OVS_BRIDGE_FAIL_MODE << ": " << setting.failMode() << '\n'; |
155 | |
156 | return dbg.maybeSpace(); |
157 | } |
158 | |