NetworkManagerQt

ovsportsetting.cpp
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
22NetworkManager::OvsPortSettingPrivate::OvsPortSettingPrivate()
23 : name(NM_SETTING_OVS_PORT_SETTING_NAME)
24 , bondDowndelay(0)
25 , bondUpdelay(0)
26 , tag(0)
27{
28}
29
30NetworkManager::OvsPortSetting::OvsPortSetting()
31 : Setting(Setting::OvsPort)
32 , d_ptr(new OvsPortSettingPrivate())
33{
34}
35
36NetworkManager::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
48NetworkManager::OvsPortSetting::~OvsPortSetting()
49{
50 delete d_ptr;
51}
52
54{
55 Q_D(const OvsPortSetting);
56
57 return d->name;
58}
59
60void NetworkManager::OvsPortSetting::setBondDowndelay(quint32 delay)
61{
63
64 d->bondDowndelay = delay;
65}
66
67quint32 NetworkManager::OvsPortSetting::bondDowndelay() const
68{
69 Q_D(const OvsPortSetting);
70
71 return d->bondDowndelay;
72}
73
74void NetworkManager::OvsPortSetting::setBondUpdelay(quint32 delay)
75{
76 Q_D(OvsPortSetting);
77
78 d->bondUpdelay = delay;
79}
80
81quint32 NetworkManager::OvsPortSetting::bondUpdelay() const
82{
83 Q_D(const OvsPortSetting);
84
85 return d->bondUpdelay;
86}
87
88void NetworkManager::OvsPortSetting::setTag(quint32 tag)
89{
90 Q_D(OvsPortSetting);
91
92 d->tag = tag;
93}
94
95quint32 NetworkManager::OvsPortSetting::tag() const
96{
97 Q_D(const OvsPortSetting);
98
99 return d->tag;
100}
101
102void NetworkManager::OvsPortSetting::setBondMode(const QString &mode)
103{
104 Q_D(OvsPortSetting);
105
106 d->bondMode = mode;
107}
108
109QString NetworkManager::OvsPortSetting::bondMode() const
110{
111 Q_D(const OvsPortSetting);
112
113 return d->bondMode;
114}
115
116void NetworkManager::OvsPortSetting::setLacp(const QString &lacp)
117{
118 Q_D(OvsPortSetting);
119
120 d->lacp = lacp;
121}
122
123QString NetworkManager::OvsPortSetting::lacp() const
124{
125 Q_D(const OvsPortSetting);
126
127 return d->lacp;
128}
129
130void NetworkManager::OvsPortSetting::setVlanMode(const QString &mode)
131{
132 Q_D(OvsPortSetting);
133
134 d->vlanMode = mode;
135}
136
137QString NetworkManager::OvsPortSetting::vlanMode() const
138{
139 Q_D(const OvsPortSetting);
140
141 return d->vlanMode;
142}
143
144void NetworkManager::OvsPortSetting::fromMap(const QVariantMap &setting)
145{
146 if (setting.contains(QLatin1String(NM_SETTING_OVS_PORT_BOND_UPDELAY))) {
147 setBondUpdelay(setting.value(QLatin1String(NM_SETTING_OVS_PORT_BOND_UPDELAY)).toUInt());
148 }
149
150 if (setting.contains(QLatin1String(NM_SETTING_OVS_PORT_BOND_DOWNDELAY))) {
151 setBondDowndelay(setting.value(QLatin1String(NM_SETTING_OVS_PORT_BOND_DOWNDELAY)).toUInt());
152 }
153
154 if (setting.contains(QLatin1String(NM_SETTING_OVS_PORT_TAG))) {
155 setTag(setting.value(QLatin1String(NM_SETTING_OVS_PORT_TAG)).toUInt());
156 }
157
158 if (setting.contains(QLatin1String(NM_SETTING_OVS_PORT_BOND_MODE))) {
159 setBondMode(setting.value(QLatin1String(NM_SETTING_OVS_PORT_BOND_MODE)).toString());
160 }
161
162 if (setting.contains(QLatin1String(NM_SETTING_OVS_PORT_LACP))) {
163 setLacp(setting.value(QLatin1String(NM_SETTING_OVS_PORT_LACP)).toString());
164 }
165
166 if (setting.contains(QLatin1String(NM_SETTING_OVS_PORT_VLAN_MODE))) {
167 setVlanMode(setting.value(QLatin1String(NM_SETTING_OVS_PORT_VLAN_MODE)).toString());
168 }
169}
170
172{
173 QVariantMap setting;
174
175 if (bondUpdelay() > 0) {
176 setting.insert(QLatin1String(NM_SETTING_OVS_PORT_BOND_UPDELAY), bondUpdelay());
177 }
178
179 if (bondDowndelay() > 0) {
180 setting.insert(QLatin1String(NM_SETTING_OVS_PORT_BOND_DOWNDELAY), bondDowndelay());
181 }
182
183 if (tag() > 0) {
184 setting.insert(QLatin1String(NM_SETTING_OVS_PORT_TAG), tag());
185 }
186
187 if (!bondMode().isEmpty()) {
188 setting.insert(QLatin1String(NM_SETTING_OVS_PORT_BOND_MODE), bondMode());
189 }
190
191 if (!lacp().isEmpty()) {
192 setting.insert(QLatin1String(NM_SETTING_OVS_PORT_LACP), lacp());
193 }
194
195 if (!vlanMode().isEmpty()) {
196 setting.insert(QLatin1String(NM_SETTING_OVS_PORT_VLAN_MODE), vlanMode());
197 }
198
199 return setting;
200}
201
202QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::OvsPortSetting &setting)
203{
204 dbg.nospace() << "type: " << setting.typeAsString(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}
Represents OvsPort setting.
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
void fromMap(const QVariantMap &setting) override
Must be reimplemented, default implementation does nothing.
QString name() const override
Must be reimplemented, default implementationd does nothing.
void setTag(Elem &elem, Tag &&tag)
QDebug & maybeSpace()
QDebug & nospace()
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.