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 "ovsportsetting.h" |
8 | #include "ovsportsetting_p.h" |
9 | |
10 | #include <QDebug> |
11 | |
12 | #if !NM_CHECK_VERSION(1, 10, 0) |
13 | #define NM_SETTING_OVS_PORT_SETTING_NAME "ovs-port" |
14 | #define NM_SETTING_OVS_PORT_VLAN_MODE "vlan-mode" |
15 | #define NM_SETTING_OVS_PORT_TAG "tag" |
16 | #define NM_SETTING_OVS_PORT_LACP "lacp" |
17 | #define NM_SETTING_OVS_PORT_BOND_MODE "bond-mode" |
18 | #define NM_SETTING_OVS_PORT_BOND_UPDELAY "bond-updelay" |
19 | #define NM_SETTING_OVS_PORT_BOND_DOWNDELAY "bond-downdelay" |
20 | #endif |
21 | |
22 | NetworkManager::OvsPortSettingPrivate::OvsPortSettingPrivate() |
23 | : name(NM_SETTING_OVS_PORT_SETTING_NAME) |
24 | , bondDowndelay(0) |
25 | , bondUpdelay(0) |
26 | , tag(0) |
27 | { |
28 | } |
29 | |
30 | NetworkManager::OvsPortSetting::OvsPortSetting() |
31 | : Setting(Setting::OvsPort) |
32 | , d_ptr(new OvsPortSettingPrivate()) |
33 | { |
34 | } |
35 | |
36 | NetworkManager::OvsPortSetting::OvsPortSetting(const Ptr &other) |
37 | : Setting(other) |
38 | , d_ptr(new OvsPortSettingPrivate()) |
39 | { |
40 | setBondDowndelay(other->bondDowndelay()); |
41 | setBondUpdelay(other->bondUpdelay()); |
42 | setTag(other->tag()); |
43 | setBondMode(other->bondMode()); |
44 | setLacp(other->lacp()); |
45 | setVlanMode(other->vlanMode()); |
46 | } |
47 | |
48 | NetworkManager::OvsPortSetting::~OvsPortSetting() |
49 | { |
50 | delete d_ptr; |
51 | } |
52 | |
53 | QString NetworkManager::OvsPortSetting::name() const |
54 | { |
55 | Q_D(const OvsPortSetting); |
56 | |
57 | return d->name; |
58 | } |
59 | |
60 | void NetworkManager::OvsPortSetting::setBondDowndelay(quint32 delay) |
61 | { |
62 | Q_D(OvsPortSetting); |
63 | |
64 | d->bondDowndelay = delay; |
65 | } |
66 | |
67 | quint32 NetworkManager::OvsPortSetting::bondDowndelay() const |
68 | { |
69 | Q_D(const OvsPortSetting); |
70 | |
71 | return d->bondDowndelay; |
72 | } |
73 | |
74 | void NetworkManager::OvsPortSetting::setBondUpdelay(quint32 delay) |
75 | { |
76 | Q_D(OvsPortSetting); |
77 | |
78 | d->bondUpdelay = delay; |
79 | } |
80 | |
81 | quint32 NetworkManager::OvsPortSetting::bondUpdelay() const |
82 | { |
83 | Q_D(const OvsPortSetting); |
84 | |
85 | return d->bondUpdelay; |
86 | } |
87 | |
88 | void NetworkManager::OvsPortSetting::setTag(quint32 tag) |
89 | { |
90 | Q_D(OvsPortSetting); |
91 | |
92 | d->tag = tag; |
93 | } |
94 | |
95 | quint32 NetworkManager::OvsPortSetting::tag() const |
96 | { |
97 | Q_D(const OvsPortSetting); |
98 | |
99 | return d->tag; |
100 | } |
101 | |
102 | void NetworkManager::OvsPortSetting::setBondMode(const QString &mode) |
103 | { |
104 | Q_D(OvsPortSetting); |
105 | |
106 | d->bondMode = mode; |
107 | } |
108 | |
109 | QString NetworkManager::OvsPortSetting::bondMode() const |
110 | { |
111 | Q_D(const OvsPortSetting); |
112 | |
113 | return d->bondMode; |
114 | } |
115 | |
116 | void NetworkManager::OvsPortSetting::setLacp(const QString &lacp) |
117 | { |
118 | Q_D(OvsPortSetting); |
119 | |
120 | d->lacp = lacp; |
121 | } |
122 | |
123 | QString NetworkManager::OvsPortSetting::lacp() const |
124 | { |
125 | Q_D(const OvsPortSetting); |
126 | |
127 | return d->lacp; |
128 | } |
129 | |
130 | void NetworkManager::OvsPortSetting::setVlanMode(const QString &mode) |
131 | { |
132 | Q_D(OvsPortSetting); |
133 | |
134 | d->vlanMode = mode; |
135 | } |
136 | |
137 | QString NetworkManager::OvsPortSetting::vlanMode() const |
138 | { |
139 | Q_D(const OvsPortSetting); |
140 | |
141 | return d->vlanMode; |
142 | } |
143 | |
144 | void NetworkManager::OvsPortSetting::fromMap(const QVariantMap &setting) |
145 | { |
146 | if (setting.contains(key: QLatin1String(NM_SETTING_OVS_PORT_BOND_UPDELAY))) { |
147 | setBondUpdelay(setting.value(key: QLatin1String(NM_SETTING_OVS_PORT_BOND_UPDELAY)).toUInt()); |
148 | } |
149 | |
150 | if (setting.contains(key: QLatin1String(NM_SETTING_OVS_PORT_BOND_DOWNDELAY))) { |
151 | setBondDowndelay(setting.value(key: QLatin1String(NM_SETTING_OVS_PORT_BOND_DOWNDELAY)).toUInt()); |
152 | } |
153 | |
154 | if (setting.contains(key: QLatin1String(NM_SETTING_OVS_PORT_TAG))) { |
155 | setTag(setting.value(key: QLatin1String(NM_SETTING_OVS_PORT_TAG)).toUInt()); |
156 | } |
157 | |
158 | if (setting.contains(key: QLatin1String(NM_SETTING_OVS_PORT_BOND_MODE))) { |
159 | setBondMode(setting.value(key: QLatin1String(NM_SETTING_OVS_PORT_BOND_MODE)).toString()); |
160 | } |
161 | |
162 | if (setting.contains(key: QLatin1String(NM_SETTING_OVS_PORT_LACP))) { |
163 | setLacp(setting.value(key: QLatin1String(NM_SETTING_OVS_PORT_LACP)).toString()); |
164 | } |
165 | |
166 | if (setting.contains(key: QLatin1String(NM_SETTING_OVS_PORT_VLAN_MODE))) { |
167 | setVlanMode(setting.value(key: QLatin1String(NM_SETTING_OVS_PORT_VLAN_MODE)).toString()); |
168 | } |
169 | } |
170 | |
171 | QVariantMap NetworkManager::OvsPortSetting::toMap() const |
172 | { |
173 | QVariantMap setting; |
174 | |
175 | if (bondUpdelay() > 0) { |
176 | setting.insert(key: QLatin1String(NM_SETTING_OVS_PORT_BOND_UPDELAY), value: bondUpdelay()); |
177 | } |
178 | |
179 | if (bondDowndelay() > 0) { |
180 | setting.insert(key: QLatin1String(NM_SETTING_OVS_PORT_BOND_DOWNDELAY), value: bondDowndelay()); |
181 | } |
182 | |
183 | if (tag() > 0) { |
184 | setting.insert(key: QLatin1String(NM_SETTING_OVS_PORT_TAG), value: tag()); |
185 | } |
186 | |
187 | if (!bondMode().isEmpty()) { |
188 | setting.insert(key: QLatin1String(NM_SETTING_OVS_PORT_BOND_MODE), value: bondMode()); |
189 | } |
190 | |
191 | if (!lacp().isEmpty()) { |
192 | setting.insert(key: QLatin1String(NM_SETTING_OVS_PORT_LACP), value: lacp()); |
193 | } |
194 | |
195 | if (!vlanMode().isEmpty()) { |
196 | setting.insert(key: QLatin1String(NM_SETTING_OVS_PORT_VLAN_MODE), value: vlanMode()); |
197 | } |
198 | |
199 | return setting; |
200 | } |
201 | |
202 | QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::OvsPortSetting &setting) |
203 | { |
204 | dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n'; |
205 | dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; |
206 | |
207 | dbg.nospace() << NM_SETTING_OVS_PORT_BOND_UPDELAY << ": " << setting.bondUpdelay() << '\n'; |
208 | dbg.nospace() << NM_SETTING_OVS_PORT_BOND_DOWNDELAY << ": " << setting.bondDowndelay() << '\n'; |
209 | dbg.nospace() << NM_SETTING_OVS_PORT_TAG << ": " << setting.tag() << '\n'; |
210 | dbg.nospace() << NM_SETTING_OVS_PORT_BOND_MODE << ": " << setting.bondMode() << '\n'; |
211 | dbg.nospace() << NM_SETTING_OVS_PORT_LACP << ": " << setting.lacp() << '\n'; |
212 | dbg.nospace() << NM_SETTING_OVS_PORT_VLAN_MODE << ": " << setting.vlanMode() << '\n'; |
213 | |
214 | return dbg.maybeSpace(); |
215 | } |
216 | |