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 "dcbsetting.h"
8#include "dcbsetting_p.h"
9
10#include <QDebug>
11
12NetworkManager::DcbSettingPrivate::DcbSettingPrivate()
13 : name(NM_SETTING_DCB_SETTING_NAME)
14 , appFcoeMode(NM_SETTING_DCB_FCOE_MODE_FABRIC)
15 , appFcoePriority(-1)
16 , appFipPriority(-1)
17 , appIscsiPriority(-1)
18 , priorityFlowControl({0, 0, 0, 0, 0, 0, 0, 0})
19 , priorityBandwidth({0, 0, 0, 0, 0, 0, 0, 0})
20 , priorityGroupBandwidth({0, 0, 0, 0, 0, 0, 0, 0})
21 , priorityGroupId({0, 0, 0, 0, 0, 0, 0, 0})
22 , priorityStrictBandwidth({0, 0, 0, 0, 0, 0, 0, 0})
23 , priorityTrafficClass({0, 0, 0, 0, 0, 0, 0, 0})
24{
25}
26
27NetworkManager::DcbSetting::DcbSetting()
28 : Setting(Setting::Dcb)
29 , d_ptr(new DcbSettingPrivate())
30{
31}
32
33NetworkManager::DcbSetting::DcbSetting(const Ptr &other)
34 : Setting(other)
35 , d_ptr(new DcbSettingPrivate())
36{
37 setAppFcoeMode(other->appFcoeMode());
38 setAppFcoePriority(other->appFcoePriority());
39 setAppFipPriority(other->appFipPriority());
40 setAppIscsiPriority(other->appIscsiPriority());
41 setAppFcoeFlags(other->appFcoeFlags());
42 setAppFipFlags(other->appFipFlags());
43 setAppIscsiFlags(other->appIscsiFlags());
44 setPriorityGroupFlags(other->priorityGroupFlags());
45 setPriorityFlowControlFlags(other->priorityFlowControlFlags());
46 setPriorityFlowControl(other->priorityFlowControl());
47 setPriorityBandwidth(other->priorityBandwidth());
48 setPriorityGroupBandwidth(other->priorityGroupBandwidth());
49 setPriorityGroupId(other->priorityGroupId());
50 setPriorityStrictBandwidth(other->priorityStrictBandwidth());
51 setPriorityTrafficClass(other->priorityTrafficClass());
52}
53
54NetworkManager::DcbSetting::~DcbSetting()
55{
56 delete d_ptr;
57}
58
59QString NetworkManager::DcbSetting::name() const
60{
61 Q_D(const DcbSetting);
62
63 return d->name;
64}
65
66void NetworkManager::DcbSetting::setAppFcoeMode(const QString &mode)
67{
68 Q_D(DcbSetting);
69
70 d->appFcoeMode = mode;
71}
72
73QString NetworkManager::DcbSetting::appFcoeMode() const
74{
75 Q_D(const DcbSetting);
76
77 return d->appFcoeMode;
78}
79
80void NetworkManager::DcbSetting::setAppFcoePriority(qint32 priority)
81{
82 Q_D(DcbSetting);
83
84 d->appFcoePriority = priority;
85}
86
87qint32 NetworkManager::DcbSetting::appFcoePriority() const
88{
89 Q_D(const DcbSetting);
90
91 return d->appFcoePriority;
92}
93
94void NetworkManager::DcbSetting::setAppFipPriority(qint32 priority)
95{
96 Q_D(DcbSetting);
97
98 d->appFipPriority = priority;
99}
100
101qint32 NetworkManager::DcbSetting::appFipPriority() const
102{
103 Q_D(const DcbSetting);
104
105 return d->appFipPriority;
106}
107
108void NetworkManager::DcbSetting::setAppIscsiPriority(qint32 priority)
109{
110 Q_D(DcbSetting);
111
112 d->appIscsiPriority = priority;
113}
114
115qint32 NetworkManager::DcbSetting::appIscsiPriority() const
116{
117 Q_D(const DcbSetting);
118
119 return d->appIscsiPriority;
120}
121
122void NetworkManager::DcbSetting::setAppFcoeFlags(NetworkManager::DcbSetting::DcbFlags flags)
123{
124 Q_D(DcbSetting);
125
126 d->appFcoeFlags = flags;
127}
128
129NetworkManager::DcbSetting::DcbFlags NetworkManager::DcbSetting::appFcoeFlags() const
130{
131 Q_D(const DcbSetting);
132
133 return d->appFcoeFlags;
134}
135
136void NetworkManager::DcbSetting::setAppFipFlags(NetworkManager::DcbSetting::DcbFlags flags)
137{
138 Q_D(DcbSetting);
139
140 d->appFipFlags = flags;
141}
142
143NetworkManager::DcbSetting::DcbFlags NetworkManager::DcbSetting::appFipFlags() const
144{
145 Q_D(const DcbSetting);
146
147 return d->appFipFlags;
148}
149
150void NetworkManager::DcbSetting::setAppIscsiFlags(NetworkManager::DcbSetting::DcbFlags flags)
151{
152 Q_D(DcbSetting);
153
154 d->appIscsiFlags = flags;
155}
156
157NetworkManager::DcbSetting::DcbFlags NetworkManager::DcbSetting::appIscsiFlags() const
158{
159 Q_D(const DcbSetting);
160
161 return d->appIscsiFlags;
162}
163
164void NetworkManager::DcbSetting::setPriorityGroupFlags(NetworkManager::DcbSetting::DcbFlags flags)
165{
166 Q_D(DcbSetting);
167
168 d->priorityGroupFlags = flags;
169}
170
171NetworkManager::DcbSetting::DcbFlags NetworkManager::DcbSetting::priorityGroupFlags() const
172{
173 Q_D(const DcbSetting);
174
175 return d->priorityGroupFlags;
176}
177
178void NetworkManager::DcbSetting::setPriorityFlowControlFlags(NetworkManager::DcbSetting::DcbFlags flags)
179{
180 Q_D(DcbSetting);
181
182 d->priorityFlowControlFlags = flags;
183}
184
185NetworkManager::DcbSetting::DcbFlags NetworkManager::DcbSetting::priorityFlowControlFlags() const
186{
187 Q_D(const DcbSetting);
188
189 return d->priorityFlowControlFlags;
190}
191
192void NetworkManager::DcbSetting::setPriorityFlowControl(quint32 userPriority, bool enabled)
193{
194 Q_D(DcbSetting);
195
196 if (userPriority < 8) {
197 d->priorityFlowControl[userPriority] = enabled;
198 }
199}
200
201bool NetworkManager::DcbSetting::priorityFlowControl(quint32 userPriority) const
202{
203 Q_D(const DcbSetting);
204
205 if (userPriority < 8) {
206 return d->priorityFlowControl.value(i: userPriority);
207 }
208 return false;
209}
210
211void NetworkManager::DcbSetting::setPriorityFlowControl(const UIntList &list)
212{
213 Q_D(DcbSetting);
214
215 d->priorityFlowControl = list;
216}
217
218UIntList NetworkManager::DcbSetting::priorityFlowControl() const
219{
220 Q_D(const DcbSetting);
221
222 return d->priorityFlowControl;
223}
224
225void NetworkManager::DcbSetting::setPriorityBandwidth(quint32 userPriority, quint32 bandwidthPercent)
226{
227 Q_D(DcbSetting);
228
229 if (userPriority < 8) {
230 d->priorityBandwidth[userPriority] = bandwidthPercent;
231 }
232}
233
234quint32 NetworkManager::DcbSetting::priorityBandwidth(quint32 userPriority) const
235{
236 Q_D(const DcbSetting);
237
238 if (userPriority < 8) {
239 return d->priorityBandwidth.value(i: userPriority);
240 }
241 return 0;
242}
243
244void NetworkManager::DcbSetting::setPriorityBandwidth(const UIntList &list)
245{
246 Q_D(DcbSetting);
247
248 d->priorityBandwidth = list;
249}
250
251UIntList NetworkManager::DcbSetting::priorityBandwidth() const
252{
253 Q_D(const DcbSetting);
254
255 return d->priorityBandwidth;
256}
257
258void NetworkManager::DcbSetting::setPriorityGroupBandwidth(quint32 groupId, quint32 bandwidthPercent)
259{
260 Q_D(DcbSetting);
261
262 if (groupId < 8) {
263 d->priorityGroupBandwidth[groupId] = bandwidthPercent;
264 }
265}
266
267quint32 NetworkManager::DcbSetting::priorityGroupBandwidth(quint32 groupId) const
268{
269 Q_D(const DcbSetting);
270
271 if (groupId < 8) {
272 return d->priorityGroupBandwidth.value(i: groupId);
273 }
274 return 0;
275}
276
277void NetworkManager::DcbSetting::setPriorityGroupBandwidth(const UIntList &list)
278{
279 Q_D(DcbSetting);
280
281 d->priorityGroupBandwidth = list;
282}
283
284UIntList NetworkManager::DcbSetting::priorityGroupBandwidth() const
285{
286 Q_D(const DcbSetting);
287
288 return d->priorityGroupBandwidth;
289}
290
291void NetworkManager::DcbSetting::setPriorityGroupId(quint32 userPriority, quint32 groupId)
292{
293 Q_D(DcbSetting);
294
295 if (userPriority < 8) {
296 d->priorityGroupId[userPriority] = groupId;
297 }
298}
299
300quint32 NetworkManager::DcbSetting::priorityGroupId(quint32 userPriority) const
301{
302 Q_D(const DcbSetting);
303
304 if (userPriority < 8) {
305 return d->priorityGroupId.value(i: userPriority);
306 }
307 return 0;
308}
309
310void NetworkManager::DcbSetting::setPriorityGroupId(const UIntList &list)
311{
312 Q_D(DcbSetting);
313
314 d->priorityGroupId = list;
315}
316
317UIntList NetworkManager::DcbSetting::priorityGroupId() const
318{
319 Q_D(const DcbSetting);
320
321 return d->priorityGroupId;
322}
323
324void NetworkManager::DcbSetting::setPriorityStrictBandwidth(quint32 userPriority, bool strict)
325{
326 Q_D(DcbSetting);
327
328 if (userPriority < 8) {
329 d->priorityStrictBandwidth[userPriority] = strict;
330 }
331}
332
333bool NetworkManager::DcbSetting::priorityStrictBandwidth(quint32 userPriority) const
334{
335 Q_D(const DcbSetting);
336
337 if (userPriority < 8) {
338 return d->priorityStrictBandwidth.value(i: userPriority);
339 }
340 return false;
341}
342
343void NetworkManager::DcbSetting::setPriorityStrictBandwidth(const UIntList &list)
344{
345 Q_D(DcbSetting);
346
347 d->priorityStrictBandwidth = list;
348}
349
350UIntList NetworkManager::DcbSetting::priorityStrictBandwidth() const
351{
352 Q_D(const DcbSetting);
353
354 return d->priorityStrictBandwidth;
355}
356
357void NetworkManager::DcbSetting::setPriorityTrafficClass(quint32 userPriority, quint32 trafficClass)
358{
359 Q_D(DcbSetting);
360
361 if (userPriority < 8) {
362 d->priorityTrafficClass[userPriority] = trafficClass;
363 }
364}
365
366quint32 NetworkManager::DcbSetting::priorityTrafficClass(quint32 userPriority) const
367{
368 Q_D(const DcbSetting);
369
370 if (userPriority < 8) {
371 return d->priorityTrafficClass.value(i: userPriority);
372 }
373 return 0;
374}
375
376void NetworkManager::DcbSetting::setPriorityTrafficClass(const UIntList &list)
377{
378 Q_D(DcbSetting);
379
380 d->priorityTrafficClass = list;
381}
382
383UIntList NetworkManager::DcbSetting::priorityTrafficClass() const
384{
385 Q_D(const DcbSetting);
386
387 return d->priorityTrafficClass;
388}
389
390void NetworkManager::DcbSetting::fromMap(const QVariantMap &setting)
391{
392 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_APP_FCOE_MODE))) {
393 setAppFcoeMode(setting.value(key: QLatin1String(NM_SETTING_DCB_APP_FCOE_MODE)).toString());
394 }
395
396 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_APP_FCOE_PRIORITY))) {
397 setAppFcoePriority(setting.value(key: QLatin1String(NM_SETTING_DCB_APP_FCOE_PRIORITY)).toInt());
398 }
399
400 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_APP_FIP_PRIORITY))) {
401 setAppFipPriority(setting.value(key: QLatin1String(NM_SETTING_DCB_APP_FIP_PRIORITY)).toInt());
402 }
403
404 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_APP_ISCSI_PRIORITY))) {
405 setAppIscsiPriority(setting.value(key: QLatin1String(NM_SETTING_DCB_APP_ISCSI_PRIORITY)).toInt());
406 }
407
408 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_APP_FCOE_FLAGS))) {
409 setAppFcoeFlags(static_cast<DcbFlags>(setting.value(key: QLatin1String(NM_SETTING_DCB_APP_FCOE_FLAGS)).toUInt()));
410 }
411
412 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_APP_FIP_FLAGS))) {
413 setAppFipFlags(static_cast<DcbFlags>(setting.value(key: QLatin1String(NM_SETTING_DCB_APP_FIP_FLAGS)).toUInt()));
414 }
415
416 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_APP_ISCSI_FLAGS))) {
417 setAppIscsiFlags(static_cast<DcbFlags>(setting.value(key: QLatin1String(NM_SETTING_DCB_APP_ISCSI_FLAGS)).toUInt()));
418 }
419
420 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_FLAGS))) {
421 setPriorityGroupFlags(static_cast<DcbFlags>(setting.value(key: QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_FLAGS)).toUInt()));
422 }
423
424 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS))) {
425 setPriorityFlowControlFlags(static_cast<DcbFlags>(setting.value(key: QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS)).toUInt()));
426 }
427
428 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL))) {
429 setPriorityFlowControl(qdbus_cast<UIntList>(v: setting.value(key: QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL))));
430 }
431
432 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH))) {
433 setPriorityBandwidth(qdbus_cast<UIntList>(v: setting.value(key: QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH))));
434 }
435
436 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH))) {
437 setPriorityGroupBandwidth(qdbus_cast<UIntList>(v: setting.value(key: QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH))));
438 }
439
440 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID))) {
441 setPriorityGroupId(qdbus_cast<UIntList>(v: setting.value(key: QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID))));
442 }
443
444 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH))) {
445 setPriorityStrictBandwidth(qdbus_cast<UIntList>(v: setting.value(key: QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH))));
446 }
447
448 if (setting.contains(key: QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS))) {
449 setPriorityTrafficClass(qdbus_cast<UIntList>(v: setting.value(key: QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS))));
450 }
451}
452
453QVariantMap NetworkManager::DcbSetting::toMap() const
454{
455 QVariantMap setting;
456
457 if (!appFcoeMode().isEmpty()) {
458 setting.insert(key: QLatin1String(NM_SETTING_DCB_APP_FCOE_MODE), value: appFcoeMode());
459 }
460
461 if (appFcoePriority() >= 0) {
462 setting.insert(key: QLatin1String(NM_SETTING_DCB_APP_FCOE_PRIORITY), value: appFcoePriority());
463 }
464
465 if (appFipPriority() >= 0) {
466 setting.insert(key: QLatin1String(NM_SETTING_DCB_APP_FIP_PRIORITY), value: appFipPriority());
467 }
468
469 if (appIscsiPriority() >= 0) {
470 setting.insert(key: QLatin1String(NM_SETTING_DCB_APP_ISCSI_PRIORITY), value: appIscsiPriority());
471 }
472
473 setting.insert(key: QLatin1String(NM_SETTING_DCB_APP_FCOE_FLAGS), value: (int)appFcoeFlags());
474 setting.insert(key: QLatin1String(NM_SETTING_DCB_APP_FIP_FLAGS), value: (int)appFipFlags());
475 setting.insert(key: QLatin1String(NM_SETTING_DCB_APP_ISCSI_FLAGS), value: (int)appIscsiFlags());
476 setting.insert(key: QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_FLAGS), value: (int)priorityGroupFlags());
477 setting.insert(key: QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS), value: (int)priorityFlowControlFlags());
478
479 setting.insert(key: QLatin1String(NM_SETTING_DCB_PRIORITY_FLOW_CONTROL), value: QVariant::fromValue(value: priorityFlowControl()));
480 setting.insert(key: QLatin1String(NM_SETTING_DCB_PRIORITY_BANDWIDTH), value: QVariant::fromValue(value: priorityBandwidth()));
481 setting.insert(key: QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH), value: QVariant::fromValue(value: priorityGroupBandwidth()));
482 setting.insert(key: QLatin1String(NM_SETTING_DCB_PRIORITY_GROUP_ID), value: QVariant::fromValue(value: priorityGroupId()));
483 setting.insert(key: QLatin1String(NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH), value: QVariant::fromValue(value: priorityStrictBandwidth()));
484 setting.insert(key: QLatin1String(NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS), value: QVariant::fromValue(value: priorityTrafficClass()));
485
486 return setting;
487}
488
489QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::DcbSetting &setting)
490{
491 dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n';
492 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
493
494 dbg.nospace() << NM_SETTING_DCB_APP_FCOE_MODE << ": " << setting.appFcoeMode() << '\n';
495 dbg.nospace() << NM_SETTING_DCB_APP_FCOE_PRIORITY << ": " << setting.appFcoePriority() << '\n';
496 dbg.nospace() << NM_SETTING_DCB_APP_FIP_PRIORITY << ": " << setting.appFipPriority() << '\n';
497 dbg.nospace() << NM_SETTING_DCB_APP_ISCSI_PRIORITY << ": " << setting.appIscsiPriority() << '\n';
498 dbg.nospace() << NM_SETTING_DCB_APP_FCOE_FLAGS << ": " << setting.appFcoeFlags() << '\n';
499 dbg.nospace() << NM_SETTING_DCB_APP_FIP_FLAGS << ": " << setting.appFipFlags() << '\n';
500 dbg.nospace() << NM_SETTING_DCB_APP_ISCSI_FLAGS << ": " << setting.appIscsiFlags() << '\n';
501 dbg.nospace() << NM_SETTING_DCB_PRIORITY_GROUP_FLAGS << ": " << setting.priorityGroupFlags() << '\n';
502 dbg.nospace() << NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS << ": " << setting.priorityFlowControlFlags() << '\n';
503
504 dbg.nospace() << NM_SETTING_DCB_PRIORITY_FLOW_CONTROL << ": ";
505 const auto flowControlList = setting.priorityFlowControl();
506 for (const quint32 enabled : flowControlList) {
507 dbg.nospace() << enabled << ' ';
508 }
509 dbg.nospace() << '\n';
510
511 dbg.nospace() << NM_SETTING_DCB_PRIORITY_BANDWIDTH << ": ";
512 const auto bwList = setting.priorityBandwidth();
513 for (const quint32 bandwidthPercent : bwList) {
514 dbg.nospace() << bandwidthPercent << ' ';
515 }
516 dbg.nospace() << '\n';
517
518 dbg.nospace() << NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH << ": ";
519 const auto gbwList = setting.priorityGroupBandwidth();
520 for (const quint32 bandwidthPercent : gbwList) {
521 dbg.nospace() << bandwidthPercent << ' ';
522 }
523 dbg.nospace() << '\n';
524
525 dbg.nospace() << NM_SETTING_DCB_PRIORITY_GROUP_ID << ": ";
526 const auto groupIds = setting.priorityGroupId();
527 for (const quint32 groupId : groupIds) {
528 dbg.nospace() << groupId << ' ';
529 }
530 dbg.nospace() << '\n';
531
532 dbg.nospace() << NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH << ": ";
533 const auto strictList = setting.priorityStrictBandwidth();
534 for (const quint32 strict : strictList) {
535 dbg.nospace() << strict << ' ';
536 }
537 dbg.nospace() << '\n';
538
539 dbg.nospace() << NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS << ": ";
540 const auto trafficList = setting.priorityTrafficClass();
541 for (const quint32 trafficClass : trafficList) {
542 dbg.nospace() << trafficClass << ' ';
543 }
544 dbg.nospace() << '\n';
545
546 return dbg.maybeSpace();
547}
548

source code of networkmanager-qt/src/settings/dcbsetting.cpp