1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA.
19 * Copyright 2013 Red Hat, Inc.
22 #include "nm-default.h"
26 #include "nm-setting-dcb.h"
28 #include "nm-utils-private.h"
29 #include "nm-setting-private.h"
30 #include "nm-core-enum-types.h"
33 * SECTION:nm-setting-dcb
34 * @short_description: Connection properties for Data Center Bridging
36 * The #NMSettingDcb object is a #NMSetting subclass that describes properties
37 * for enabling and using Data Center Bridging (DCB) on Ethernet networks.
38 * DCB is a set of protocols (including 802.1Qbb, 802.1Qaz, 802.1Qau, and
39 * 802.1AB) to eliminate packet loss in Ethernet networks and support the use
40 * of storage technologies like Fibre Channel over Ethernet (FCoE) and iSCSI.
43 G_DEFINE_TYPE_WITH_CODE (NMSettingDcb, nm_setting_dcb, NM_TYPE_SETTING,
44 _nm_register_setting (DCB, 2))
45 NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_DCB)
47 #define NM_SETTING_DCB_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_DCB, NMSettingDcbPrivate))
50 NMSettingDcbFlags app_fcoe_flags;
51 gint app_fcoe_priority;
54 NMSettingDcbFlags app_iscsi_flags;
55 gint app_iscsi_priority;
57 NMSettingDcbFlags app_fip_flags;
58 gint app_fip_priority;
60 /* Priority Flow Control */
61 NMSettingDcbFlags pfc_flags;
65 NMSettingDcbFlags priority_group_flags;
66 guint priority_group_id[8];
67 guint priority_group_bandwidth[8];
68 guint priority_bandwidth[8];
69 guint priority_strict[8];
70 guint priority_traffic_class[8];
71 } NMSettingDcbPrivate;
76 PROP_APP_FCOE_PRIORITY,
80 PROP_APP_ISCSI_PRIORITY,
83 PROP_APP_FIP_PRIORITY,
88 PROP_PRIORITY_GROUP_FLAGS,
89 PROP_PRIORITY_GROUP_ID,
90 PROP_PRIORITY_GROUP_BANDWIDTH,
91 PROP_PRIORITY_BANDWIDTH,
93 PROP_PRIORITY_TRAFFIC_CLASS,
101 * Creates a new #NMSettingDcb object with default values.
103 * Returns: (transfer full): the new empty #NMSettingDcb object
106 nm_setting_dcb_new (void)
108 return (NMSetting *) g_object_new (NM_TYPE_SETTING_DCB, NULL);
112 * nm_setting_dcb_get_app_fcoe_flags:
113 * @setting: the #NMSettingDcb
115 * Returns: the #NMSettingDcb:app-fcoe-flags property of the setting
118 nm_setting_dcb_get_app_fcoe_flags (NMSettingDcb *setting)
120 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
122 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_fcoe_flags;
126 * nm_setting_dcb_get_app_fcoe_priority:
127 * @setting: the #NMSettingDcb
129 * Returns: the #NMSettingDcb:app-fcoe-priority property of the setting
132 nm_setting_dcb_get_app_fcoe_priority (NMSettingDcb *setting)
134 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
136 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_fcoe_priority;
140 * nm_setting_dcb_get_app_fcoe_mode:
141 * @setting: the #NMSettingDcb
143 * Returns: the #NMSettingDcb:app-fcoe-mode property of the setting
146 nm_setting_dcb_get_app_fcoe_mode (NMSettingDcb *setting)
148 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), NULL);
150 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_fcoe_mode;
154 * nm_setting_dcb_get_app_iscsi_flags:
155 * @setting: the #NMSettingDcb
157 * Returns: the #NMSettingDcb:app-iscsi-flags property of the setting
160 nm_setting_dcb_get_app_iscsi_flags (NMSettingDcb *setting)
162 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
164 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_iscsi_flags;
168 * nm_setting_dcb_get_app_iscsi_priority:
169 * @setting: the #NMSettingDcb
171 * Returns: the #NMSettingDcb:app-iscsi-priority property of the setting
174 nm_setting_dcb_get_app_iscsi_priority (NMSettingDcb *setting)
176 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
178 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_iscsi_priority;
182 * nm_setting_dcb_get_app_fip_flags:
183 * @setting: the #NMSettingDcb
185 * Returns: the #NMSettingDcb:app-fip-flags property of the setting
188 nm_setting_dcb_get_app_fip_flags (NMSettingDcb *setting)
190 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
192 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_fip_flags;
196 * nm_setting_dcb_get_app_fip_priority:
197 * @setting: the #NMSettingDcb
199 * Returns: the #NMSettingDcb:app-fip-priority property of the setting
202 nm_setting_dcb_get_app_fip_priority (NMSettingDcb *setting)
204 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
206 return NM_SETTING_DCB_GET_PRIVATE (setting)->app_fip_priority;
210 * nm_setting_dcb_get_priority_flow_control_flags:
211 * @setting: the #NMSettingDcb
213 * Returns: the #NMSettingDcb:priority-flow-control-flags property of the setting
216 nm_setting_dcb_get_priority_flow_control_flags (NMSettingDcb *setting)
218 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
220 return NM_SETTING_DCB_GET_PRIVATE (setting)->pfc_flags;
224 * nm_setting_dcb_get_priority_flow_control:
225 * @setting: the #NMSettingDcb
226 * @user_priority: the User Priority (0 - 7) to retrieve flow control for
228 * Returns: %TRUE if flow control is enabled for the given @user_priority,
229 * %FALSE if not enabled
232 nm_setting_dcb_get_priority_flow_control (NMSettingDcb *setting, guint user_priority)
234 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), FALSE);
235 g_return_val_if_fail (user_priority <= 7, FALSE);
237 return !!NM_SETTING_DCB_GET_PRIVATE (setting)->pfc[user_priority];
241 * nm_setting_dcb_set_priority_flow_control:
242 * @setting: the #NMSettingDcb
243 * @user_priority: the User Priority (0 - 7) to set flow control for
244 * @enabled: %TRUE to enable flow control for this priority, %FALSE to disable it
246 * These values are only valid when #NMSettingDcb:priority-flow-control includes
247 * the %NM_SETTING_DCB_FLAG_ENABLE flag.
250 nm_setting_dcb_set_priority_flow_control (NMSettingDcb *setting,
254 NMSettingDcbPrivate *priv;
255 guint uint_enabled = enabled ? 1 : 0;
257 g_return_if_fail (NM_IS_SETTING_DCB (setting));
258 g_return_if_fail (user_priority <= 7);
260 priv = NM_SETTING_DCB_GET_PRIVATE (setting);
261 if (priv->pfc[user_priority] != uint_enabled) {
262 priv->pfc[user_priority] = uint_enabled;
263 g_object_notify (G_OBJECT (setting), NM_SETTING_DCB_PRIORITY_FLOW_CONTROL);
268 * nm_setting_dcb_get_priority_group_flags:
269 * @setting: the #NMSettingDcb
271 * Returns: the #NMSettingDcb:priority-group-flags property of the setting
274 nm_setting_dcb_get_priority_group_flags (NMSettingDcb *setting)
276 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
278 return NM_SETTING_DCB_GET_PRIVATE (setting)->priority_group_flags;
282 * nm_setting_dcb_get_priority_group_id:
283 * @setting: the #NMSettingDcb
284 * @user_priority: the User Priority (0 - 7) to retrieve the group ID for
286 * Returns: the group number @user_priority is assigned to. These values are
287 * only valid when #NMSettingDcb:priority-group-flags includes the
288 * %NM_SETTING_DCB_FLAG_ENABLE flag.
291 nm_setting_dcb_get_priority_group_id (NMSettingDcb *setting, guint user_priority)
293 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
294 g_return_val_if_fail (user_priority <= 7, 0);
296 return NM_SETTING_DCB_GET_PRIVATE (setting)->priority_group_id[user_priority];
300 * nm_setting_dcb_set_priority_group_id:
301 * @setting: the #NMSettingDcb
302 * @user_priority: the User Priority (0 - 7) to set flow control for
303 * @group_id: the group (0 - 7) to assign @user_priority to, or 15 for the
304 * unrestricted group.
306 * These values are only valid when #NMSettingDcb:priority-group-flags includes
307 * the %NM_SETTING_DCB_FLAG_ENABLE flag.
310 nm_setting_dcb_set_priority_group_id (NMSettingDcb *setting,
314 NMSettingDcbPrivate *priv;
316 g_return_if_fail (NM_IS_SETTING_DCB (setting));
317 g_return_if_fail (user_priority <= 7);
318 g_return_if_fail (group_id <= 7 || group_id == 15);
320 priv = NM_SETTING_DCB_GET_PRIVATE (setting);
321 if (priv->priority_group_id[user_priority] != group_id) {
322 priv->priority_group_id[user_priority] = group_id;
323 g_object_notify (G_OBJECT (setting), NM_SETTING_DCB_PRIORITY_GROUP_ID);
328 * nm_setting_dcb_get_priority_group_bandwidth:
329 * @setting: the #NMSettingDcb
330 * @group_id: the priority group (0 - 7) to retrieve the bandwidth percentage for
332 * Returns: the bandwidth percentage assigned to @group_id. These values are
333 * only valid when #NMSettingDcb:priority-group-flags includes the
334 * %NM_SETTING_DCB_FLAG_ENABLE flag.
337 nm_setting_dcb_get_priority_group_bandwidth (NMSettingDcb *setting, guint group_id)
339 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
340 g_return_val_if_fail (group_id <= 7, FALSE);
342 return NM_SETTING_DCB_GET_PRIVATE (setting)->priority_group_bandwidth[group_id];
346 * nm_setting_dcb_set_priority_group_bandwidth:
347 * @setting: the #NMSettingDcb
348 * @group_id: the priority group (0 - 7) to set the bandwidth percentage for
349 * @bandwidth_percent: the bandwidth percentage (0 - 100) to assign to @group_id to
351 * These values are only valid when #NMSettingDcb:priority-group-flags includes
352 * the %NM_SETTING_DCB_FLAG_ENABLE flag.
355 nm_setting_dcb_set_priority_group_bandwidth (NMSettingDcb *setting,
357 guint bandwidth_percent)
359 NMSettingDcbPrivate *priv;
361 g_return_if_fail (NM_IS_SETTING_DCB (setting));
362 g_return_if_fail (group_id <= 7);
363 g_return_if_fail (bandwidth_percent <= 100);
365 priv = NM_SETTING_DCB_GET_PRIVATE (setting);
366 if (priv->priority_group_bandwidth[group_id] != bandwidth_percent) {
367 priv->priority_group_bandwidth[group_id] = bandwidth_percent;
368 g_object_notify (G_OBJECT (setting), NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH);
373 * nm_setting_dcb_get_priority_bandwidth:
374 * @setting: the #NMSettingDcb
375 * @user_priority: the User Priority (0 - 7) to retrieve the group bandwidth percentage for
377 * Returns: the allowed bandwidth percentage of @user_priority in its priority group.
378 * These values are only valid when #NMSettingDcb:priority-group-flags includes the
379 * %NM_SETTING_DCB_FLAG_ENABLE flag.
382 nm_setting_dcb_get_priority_bandwidth (NMSettingDcb *setting, guint user_priority)
384 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
385 g_return_val_if_fail (user_priority <= 7, FALSE);
387 return NM_SETTING_DCB_GET_PRIVATE (setting)->priority_bandwidth[user_priority];
391 * nm_setting_dcb_set_priority_bandwidth:
392 * @setting: the #NMSettingDcb
393 * @user_priority: the User Priority (0 - 7) to set the bandwidth percentage for
394 * @bandwidth_percent: the bandwidth percentage (0 - 100) that @user_priority is
395 * allowed to use within its priority group
397 * These values are only valid when #NMSettingDcb:priority-group-flags includes
398 * the %NM_SETTING_DCB_FLAG_ENABLE flag.
401 nm_setting_dcb_set_priority_bandwidth (NMSettingDcb *setting,
403 guint bandwidth_percent)
405 NMSettingDcbPrivate *priv;
407 g_return_if_fail (NM_IS_SETTING_DCB (setting));
408 g_return_if_fail (user_priority <= 7);
409 g_return_if_fail (bandwidth_percent <= 100);
411 priv = NM_SETTING_DCB_GET_PRIVATE (setting);
412 if (priv->priority_bandwidth[user_priority] != bandwidth_percent) {
413 priv->priority_bandwidth[user_priority] = bandwidth_percent;
414 g_object_notify (G_OBJECT (setting), NM_SETTING_DCB_PRIORITY_BANDWIDTH);
419 * nm_setting_dcb_get_priority_strict_bandwidth:
420 * @setting: the #NMSettingDcb
421 * @user_priority: the User Priority (0 - 7) to retrieve strict bandwidth for
423 * Returns: %TRUE if @user_priority may use all of the bandwidth allocated to its
424 * assigned group, or %FALSE if not. These values are only valid when
425 * #NMSettingDcb:priority-group-flags includes the %NM_SETTING_DCB_FLAG_ENABLE flag.
428 nm_setting_dcb_get_priority_strict_bandwidth (NMSettingDcb *setting, guint user_priority)
430 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
431 g_return_val_if_fail (user_priority <= 7, FALSE);
433 return !!NM_SETTING_DCB_GET_PRIVATE (setting)->priority_strict[user_priority];
437 * nm_setting_dcb_set_priority_strict_bandwidth:
438 * @setting: the #NMSettingDcb
439 * @user_priority: the User Priority (0 - 7) to set strict bandwidth for
440 * @strict: %TRUE to allow @user_priority to use all the bandwidth allocated to
441 * its priority group, or %FALSE if not
443 * These values are only valid when #NMSettingDcb:priority-group-flags includes
444 * the %NM_SETTING_DCB_FLAG_ENABLE flag.
447 nm_setting_dcb_set_priority_strict_bandwidth (NMSettingDcb *setting,
451 NMSettingDcbPrivate *priv;
452 guint uint_strict = strict ? 1 : 0;
454 g_return_if_fail (NM_IS_SETTING_DCB (setting));
455 g_return_if_fail (user_priority <= 7);
457 priv = NM_SETTING_DCB_GET_PRIVATE (setting);
458 if (priv->priority_strict[user_priority] != uint_strict) {
459 priv->priority_strict[user_priority] = uint_strict;
460 g_object_notify (G_OBJECT (setting), NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH);
465 * nm_setting_dcb_get_priority_traffic_class:
466 * @setting: the #NMSettingDcb
467 * @user_priority: the User Priority (0 - 7) to retrieve the traffic class for
469 * Returns: the traffic class assigned to @user_priority. These values are only
470 * valid when #NMSettingDcb:priority-group-flags includes the
471 * %NM_SETTING_DCB_FLAG_ENABLE flag.
474 nm_setting_dcb_get_priority_traffic_class (NMSettingDcb *setting, guint user_priority)
476 g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
477 g_return_val_if_fail (user_priority <= 7, FALSE);
479 return NM_SETTING_DCB_GET_PRIVATE (setting)->priority_traffic_class[user_priority];
483 * nm_setting_dcb_set_priority_traffic_clas:
484 * @setting: the #NMSettingDcb
485 * @user_priority: the User Priority (0 - 7) to set the bandwidth percentage for
486 * @traffic_class: the traffic_class (0 - 7) that @user_priority should map to
488 * These values are only valid when #NMSettingDcb:priority-group-flags includes
489 * the %NM_SETTING_DCB_FLAG_ENABLE flag.
492 nm_setting_dcb_set_priority_traffic_class (NMSettingDcb *setting,
496 NMSettingDcbPrivate *priv;
498 g_return_if_fail (NM_IS_SETTING_DCB (setting));
499 g_return_if_fail (user_priority <= 7);
500 g_return_if_fail (traffic_class <= 7);
502 priv = NM_SETTING_DCB_GET_PRIVATE (setting);
503 if (priv->priority_traffic_class[user_priority] != traffic_class) {
504 priv->priority_traffic_class[user_priority] = traffic_class;
505 g_object_notify (G_OBJECT (setting), NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS);
509 /******************************************************************/
511 #define DCB_FLAGS_ALL (NM_SETTING_DCB_FLAG_ENABLE | \
512 NM_SETTING_DCB_FLAG_ADVERTISE | \
513 NM_SETTING_DCB_FLAG_WILLING)
516 check_dcb_flags (NMSettingDcbFlags flags, const char *prop_name, GError **error)
518 if (flags & ~DCB_FLAGS_ALL) {
519 g_set_error_literal (error,
521 NM_CONNECTION_ERROR_INVALID_PROPERTY,
523 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
527 if (!(flags & NM_SETTING_DCB_FLAG_ENABLE) && (flags & ~NM_SETTING_DCB_FLAG_ENABLE)) {
528 g_set_error_literal (error,
530 NM_CONNECTION_ERROR_INVALID_PROPERTY,
531 _("flags invalid - disabled"));
532 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
540 check_uint_array (const guint *array,
542 NMSettingDcbFlags flags,
546 const char *prop_name,
551 /* Ensure each element is <= to max or equals extra */
552 for (i = 0; i < len; i++) {
553 if (!(flags & NM_SETTING_DCB_FLAG_ENABLE) && array[i]) {
554 g_set_error_literal (error,
556 NM_CONNECTION_ERROR_INVALID_PROPERTY,
557 _("property invalid (not enabled)"));
558 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
562 if ((array[i] > max) && (array[i] != extra)) {
563 g_set_error_literal (error,
565 NM_CONNECTION_ERROR_INVALID_PROPERTY,
566 _("element invalid"));
567 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
573 /* Verify sum of percentages */
575 if (flags & NM_SETTING_DCB_FLAG_ENABLE) {
576 /* If the feature is enabled, sum must equal 100% */
578 g_set_error_literal (error,
580 NM_CONNECTION_ERROR_INVALID_PROPERTY,
582 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
586 /* If the feature is disabled, sum must equal 0%, which was checked
587 * by the for() loop above.
589 g_assert_cmpint (sum, ==, 0);
597 check_priority (gint val,
598 NMSettingDcbFlags flags,
599 const char *prop_name,
602 if (!(flags & NM_SETTING_DCB_FLAG_ENABLE) && (val >= 0)) {
603 g_set_error_literal (error,
605 NM_CONNECTION_ERROR_INVALID_PROPERTY,
606 _("property invalid (not enabled)"));
607 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
611 if (val < -1 || val > 7) {
612 g_set_error_literal (error,
614 NM_CONNECTION_ERROR_INVALID_PROPERTY,
615 _("property invalid"));
616 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, prop_name);
623 verify (NMSetting *setting, NMConnection *connection, GError **error)
625 NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
627 if (!check_dcb_flags (priv->app_fcoe_flags, NM_SETTING_DCB_APP_FCOE_FLAGS, error))
630 if (!check_priority (priv->app_fcoe_priority, priv->app_fcoe_flags, NM_SETTING_DCB_APP_FCOE_PRIORITY, error))
633 if (!priv->app_fcoe_mode) {
634 g_set_error_literal (error,
636 NM_CONNECTION_ERROR_MISSING_PROPERTY,
637 _("property missing"));
638 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, NM_SETTING_DCB_APP_FCOE_MODE);
642 if (strcmp (priv->app_fcoe_mode, NM_SETTING_DCB_FCOE_MODE_FABRIC) &&
643 strcmp (priv->app_fcoe_mode, NM_SETTING_DCB_FCOE_MODE_VN2VN)) {
644 g_set_error_literal (error,
646 NM_CONNECTION_ERROR_INVALID_PROPERTY,
647 _("property invalid"));
648 g_prefix_error (error, "%s.%s: ", NM_SETTING_DCB_SETTING_NAME, NM_SETTING_DCB_APP_FCOE_MODE);
652 if (!check_dcb_flags (priv->app_iscsi_flags, NM_SETTING_DCB_APP_ISCSI_FLAGS, error))
655 if (!check_priority (priv->app_iscsi_priority, priv->app_iscsi_flags, NM_SETTING_DCB_APP_ISCSI_PRIORITY, error))
658 if (!check_dcb_flags (priv->app_fip_flags, NM_SETTING_DCB_APP_FIP_FLAGS, error))
661 if (!check_priority (priv->app_fip_priority, priv->app_fip_flags, NM_SETTING_DCB_APP_FIP_PRIORITY, error))
664 if (!check_dcb_flags (priv->pfc_flags, NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, error))
667 if (!check_uint_array (priv->pfc, G_N_ELEMENTS (priv->pfc), priv->pfc_flags, 1, 0, FALSE, NM_SETTING_DCB_PRIORITY_FLOW_CONTROL, error))
670 if (!check_dcb_flags (priv->priority_group_flags, NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, error))
673 if (!check_uint_array (priv->priority_group_id,
674 G_N_ELEMENTS (priv->priority_group_id),
675 priv->priority_group_flags,
679 NM_SETTING_DCB_PRIORITY_GROUP_ID,
683 if (!check_uint_array (priv->priority_group_bandwidth,
684 G_N_ELEMENTS (priv->priority_group_bandwidth),
685 priv->priority_group_flags,
689 NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH,
693 /* FIXME: sum bandwidths in each group */
694 if (!check_uint_array (priv->priority_bandwidth,
695 G_N_ELEMENTS (priv->priority_bandwidth),
696 priv->priority_group_flags,
700 NM_SETTING_DCB_PRIORITY_BANDWIDTH,
704 if (!check_uint_array (priv->priority_strict,
705 G_N_ELEMENTS (priv->priority_strict),
706 priv->priority_group_flags,
710 NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH,
714 if (!check_uint_array (priv->priority_traffic_class,
715 G_N_ELEMENTS (priv->priority_traffic_class),
716 priv->priority_group_flags,
720 NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS,
727 /******************************************************************/
730 nm_setting_dcb_init (NMSettingDcb *setting)
734 G_STATIC_ASSERT (sizeof (guint) == sizeof (gboolean));
737 set_array_from_gvalue (const GValue *v, uint *a, size_t len)
739 GArray *src = g_value_get_boxed (v);
740 const guint total_len = len * sizeof (a[0]);
742 memset (a, 0, total_len);
744 g_return_if_fail (g_array_get_element_size (src) == sizeof (a[0]));
745 g_return_if_fail (src->len == len);
746 memcpy (a, src->data, total_len);
749 #define SET_ARRAY_FROM_GVALUE(v, a) set_array_from_gvalue (v, a, G_N_ELEMENTS (a))
752 set_gvalue_from_array (GValue *v, uint *a, size_t len)
754 GArray *src = g_array_sized_new (FALSE, TRUE, sizeof (guint), len);
756 g_array_append_vals (src, a, len);
757 g_value_take_boxed (v, src);
760 #define SET_GVALUE_FROM_ARRAY(v, a) set_gvalue_from_array (v, a, G_N_ELEMENTS (a))
763 _nm_setting_dcb_uint_array_to_dbus (const GValue *prop_value)
765 GArray *src = g_value_get_boxed (prop_value);
767 return g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, src->data, src->len, sizeof (guint32));
771 _nm_setting_dcb_uint_array_from_dbus (GVariant *dbus_value,
777 array = g_variant_get_fixed_array (dbus_value, &length, sizeof (guint32));
778 set_gvalue_from_array (prop_value, (guint *) array, length);
782 set_property (GObject *object, guint prop_id,
783 const GValue *value, GParamSpec *pspec)
785 NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (object);
788 case PROP_APP_FCOE_FLAGS:
789 priv->app_fcoe_flags = g_value_get_flags (value);
791 case PROP_APP_FCOE_PRIORITY:
792 priv->app_fcoe_priority = g_value_get_int (value);
794 case PROP_APP_FCOE_MODE:
795 g_free (priv->app_fcoe_mode);
796 priv->app_fcoe_mode = g_value_dup_string (value);
798 case PROP_APP_ISCSI_FLAGS:
799 priv->app_iscsi_flags = g_value_get_flags (value);
801 case PROP_APP_ISCSI_PRIORITY:
802 priv->app_iscsi_priority = g_value_get_int (value);
804 case PROP_APP_FIP_FLAGS:
805 priv->app_fip_flags = g_value_get_flags (value);
807 case PROP_APP_FIP_PRIORITY:
808 priv->app_fip_priority = g_value_get_int (value);
811 priv->pfc_flags = g_value_get_flags (value);
814 SET_ARRAY_FROM_GVALUE (value, priv->pfc);
816 case PROP_PRIORITY_GROUP_FLAGS:
817 priv->priority_group_flags = g_value_get_flags (value);
819 case PROP_PRIORITY_GROUP_ID:
820 SET_ARRAY_FROM_GVALUE (value, priv->priority_group_id);
822 case PROP_PRIORITY_GROUP_BANDWIDTH:
823 SET_ARRAY_FROM_GVALUE (value, priv->priority_group_bandwidth);
825 case PROP_PRIORITY_BANDWIDTH:
826 SET_ARRAY_FROM_GVALUE (value, priv->priority_bandwidth);
828 case PROP_PRIORITY_STRICT:
829 SET_ARRAY_FROM_GVALUE (value, priv->priority_strict);
831 case PROP_PRIORITY_TRAFFIC_CLASS:
832 SET_ARRAY_FROM_GVALUE (value, priv->priority_traffic_class);
835 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
841 get_property (GObject *object, guint prop_id,
842 GValue *value, GParamSpec *pspec)
844 NMSettingDcb *setting = NM_SETTING_DCB (object);
845 NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
848 case PROP_APP_FCOE_FLAGS:
849 g_value_set_flags (value, priv->app_fcoe_flags);
851 case PROP_APP_FCOE_PRIORITY:
852 g_value_set_int (value, priv->app_fcoe_priority);
854 case PROP_APP_FCOE_MODE:
855 g_value_set_string (value, priv->app_fcoe_mode);
857 case PROP_APP_ISCSI_FLAGS:
858 g_value_set_flags (value, priv->app_iscsi_flags);
860 case PROP_APP_ISCSI_PRIORITY:
861 g_value_set_int (value, priv->app_iscsi_priority);
863 case PROP_APP_FIP_FLAGS:
864 g_value_set_flags (value, priv->app_fip_flags);
866 case PROP_APP_FIP_PRIORITY:
867 g_value_set_int (value, priv->app_fip_priority);
870 g_value_set_flags (value, priv->pfc_flags);
873 SET_GVALUE_FROM_ARRAY (value, priv->pfc);
875 case PROP_PRIORITY_GROUP_FLAGS:
876 g_value_set_flags (value, priv->priority_group_flags);
878 case PROP_PRIORITY_GROUP_ID:
879 SET_GVALUE_FROM_ARRAY (value, priv->priority_group_id);
881 case PROP_PRIORITY_GROUP_BANDWIDTH:
882 SET_GVALUE_FROM_ARRAY (value, priv->priority_group_bandwidth);
884 case PROP_PRIORITY_BANDWIDTH:
885 SET_GVALUE_FROM_ARRAY (value, priv->priority_bandwidth);
887 case PROP_PRIORITY_STRICT:
888 SET_GVALUE_FROM_ARRAY (value, priv->priority_strict);
890 case PROP_PRIORITY_TRAFFIC_CLASS:
891 SET_GVALUE_FROM_ARRAY (value, priv->priority_traffic_class);
894 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
900 finalize (GObject *object)
902 NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (object);
904 g_free (priv->app_fcoe_mode);
906 G_OBJECT_CLASS (nm_setting_dcb_parent_class)->finalize (object);
910 nm_setting_dcb_class_init (NMSettingDcbClass *setting_class)
912 GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
913 NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
915 g_type_class_add_private (setting_class, sizeof (NMSettingDcbPrivate));
917 /* virtual methods */
918 object_class->set_property = set_property;
919 object_class->get_property = get_property;
920 object_class->finalize = finalize;
921 parent_class->verify = verify;
925 * NMSettingDcb:app-fcoe-flags:
927 * Specifies the #NMSettingDcbFlags for the DCB FCoE application. Flags may
928 * be any combination of %NM_SETTING_DCB_FLAG_ENABLE,
929 * %NM_SETTING_DCB_FLAG_ADVERTISE, and %NM_SETTING_DCB_FLAG_WILLING.
932 * property: app-fcoe-flags
933 * variable: DCB_APP_FCOE_ENABLE, DCB_APP_FCOE_ADVERTISE, DCB_APP_FCOE_WILLING
934 * description: FCOE flags.
936 * example: DCB_APP_FCOE_ENABLE=yes DCB_APP_FCOE_ADVERTISE=yes
939 g_object_class_install_property
940 (object_class, PROP_APP_FCOE_FLAGS,
941 g_param_spec_flags (NM_SETTING_DCB_APP_FCOE_FLAGS, "", "",
942 NM_TYPE_SETTING_DCB_FLAGS,
943 NM_SETTING_DCB_FLAG_NONE,
945 G_PARAM_STATIC_STRINGS));
948 * NMSettingDcb:app-fcoe-priority:
950 * The highest User Priority (0 - 7) which FCoE frames should use, or -1 for
951 * default priority. Only used when the #NMSettingDcb:app-fcoe-flags
952 * property includes the %NM_SETTING_DCB_FLAG_ENABLE flag.
955 * property: app-fcoe-priority
956 * variable: DCB_APP_FCOE_PRIORITY
958 * description: Priority of FCoE frames.
961 g_object_class_install_property
962 (object_class, PROP_APP_FCOE_PRIORITY,
963 g_param_spec_int (NM_SETTING_DCB_APP_FCOE_PRIORITY, "", "",
967 G_PARAM_STATIC_STRINGS));
970 * NMSettingDcb:app-fcoe-mode:
972 * The FCoE controller mode; either %NM_SETTING_DCB_FCOE_MODE_FABRIC
973 * (default) or %NM_SETTING_DCB_FCOE_MODE_VN2VN.
976 * property: app-fcoe-mode
977 * variable: DCB_APP_FCOE_MODE
978 * values: fabric, vn2vn
980 * description: FCoE controller mode.
983 g_object_class_install_property
984 (object_class, PROP_APP_FCOE_MODE,
985 g_param_spec_string (NM_SETTING_DCB_APP_FCOE_MODE, "", "",
986 NM_SETTING_DCB_FCOE_MODE_FABRIC,
989 G_PARAM_STATIC_STRINGS));
992 * NMSettingDcb:app-iscsi-flags:
994 * Specifies the #NMSettingDcbFlags for the DCB iSCSI application. Flags
995 * may be any combination of %NM_SETTING_DCB_FLAG_ENABLE,
996 * %NM_SETTING_DCB_FLAG_ADVERTISE, and %NM_SETTING_DCB_FLAG_WILLING.
999 * property: app-iscsi-flags
1000 * variable: DCB_APP_ISCSI_ENABLE, DCB_APP_ISCSI_ADVERTISE, DCB_APP_ISCSI_WILLING
1002 * description: iSCSI flags.
1005 g_object_class_install_property
1006 (object_class, PROP_APP_ISCSI_FLAGS,
1007 g_param_spec_flags (NM_SETTING_DCB_APP_ISCSI_FLAGS, "", "",
1008 NM_TYPE_SETTING_DCB_FLAGS,
1009 NM_SETTING_DCB_FLAG_NONE,
1011 G_PARAM_STATIC_STRINGS));
1014 * NMSettingDcb:app-iscsi-priority:
1016 * The highest User Priority (0 - 7) which iSCSI frames should use, or -1
1017 * for default priority. Only used when the #NMSettingDcb:app-iscsi-flags
1018 * property includes the %NM_SETTING_DCB_FLAG_ENABLE flag.
1021 * property: app-iscsi-priority
1022 * variable: DCB_APP_ISCSI_PRIORITY
1024 * description: Priority of iSCSI frames.
1027 g_object_class_install_property
1028 (object_class, PROP_APP_ISCSI_PRIORITY,
1029 g_param_spec_int (NM_SETTING_DCB_APP_ISCSI_PRIORITY, "", "",
1033 G_PARAM_STATIC_STRINGS));
1036 * NMSettingDcb:app-fip-flags:
1038 * Specifies the #NMSettingDcbFlags for the DCB FIP application. Flags may
1039 * be any combination of %NM_SETTING_DCB_FLAG_ENABLE,
1040 * %NM_SETTING_DCB_FLAG_ADVERTISE, and %NM_SETTING_DCB_FLAG_WILLING.
1043 * property: app-fip-flags
1044 * variable: DCB_APP_FIP_ENABLE, DCB_APP_FIP_ADVERTISE, DCB_APP_FIP_WILLING
1046 * description: FIP flags.
1049 g_object_class_install_property
1050 (object_class, PROP_APP_FIP_FLAGS,
1051 g_param_spec_flags (NM_SETTING_DCB_APP_FIP_FLAGS, "", "",
1052 NM_TYPE_SETTING_DCB_FLAGS,
1053 NM_SETTING_DCB_FLAG_NONE,
1055 G_PARAM_STATIC_STRINGS));
1058 * NMSettingDcb:app-fip-priority:
1060 * The highest User Priority (0 - 7) which FIP frames should use, or -1 for
1061 * default priority. Only used when the #NMSettingDcb:app-fip-flags
1062 * property includes the %NM_SETTING_DCB_FLAG_ENABLE flag.
1065 * property: app-fip-priority
1066 * variable: DCB_APP_FIP_PRIORITY
1068 * description: Priority of FIP frames.
1071 g_object_class_install_property
1072 (object_class, PROP_APP_FIP_PRIORITY,
1073 g_param_spec_int (NM_SETTING_DCB_APP_FIP_PRIORITY, "", "",
1077 G_PARAM_STATIC_STRINGS));
1080 * NMSettingDcb:priority-flow-control-flags:
1082 * Specifies the #NMSettingDcbFlags for DCB Priority Flow Control (PFC).
1083 * Flags may be any combination of %NM_SETTING_DCB_FLAG_ENABLE,
1084 * %NM_SETTING_DCB_FLAG_ADVERTISE, and %NM_SETTING_DCB_FLAG_WILLING.
1087 * property: priority-flow-control-flags
1088 * variable: DCB_PFC_ENABLE, DCB_PFC_ADVERTISE, DCB_PFC_WILLING
1090 * description: Priority flow control flags.
1093 g_object_class_install_property
1094 (object_class, PROP_PFC_FLAGS,
1095 g_param_spec_flags (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, "", "",
1096 NM_TYPE_SETTING_DCB_FLAGS,
1097 NM_SETTING_DCB_FLAG_NONE,
1099 G_PARAM_STATIC_STRINGS));
1102 * NMSettingDcb:priority-flow-control:
1104 * An array of 8 boolean values, where the array index corresponds to the User
1105 * Priority (0 - 7) and the value indicates whether or not the corresponding
1106 * priority should transmit priority pause.
1108 * Element-type: gboolean
1111 * property: priority-flow-control
1112 * variable: DCB_PFC_UP
1113 * description: Priority flow control values. String of 8 "0" and "1", where "0".
1114 * means "do not transmit priority pause", "1" means "transmit pause".
1115 * example: DCB_PFC_UP=01101110
1118 g_object_class_install_property
1119 (object_class, PROP_PFC,
1120 g_param_spec_boxed (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL, "", "",
1123 G_PARAM_STATIC_STRINGS));
1124 _nm_setting_class_transform_property (parent_class, NM_SETTING_DCB_PRIORITY_FLOW_CONTROL,
1125 G_VARIANT_TYPE ("au"),
1126 _nm_setting_dcb_uint_array_to_dbus,
1127 _nm_setting_dcb_uint_array_from_dbus);
1130 * NMSettingDcb:priority-group-flags:
1132 * Specifies the #NMSettingDcbFlags for DCB Priority Groups. Flags may be
1133 * any combination of %NM_SETTING_DCB_FLAG_ENABLE,
1134 * %NM_SETTING_DCB_FLAG_ADVERTISE, and %NM_SETTING_DCB_FLAG_WILLING.
1137 * property: priority-group-flags
1138 * variable: DCB_PG_ENABLE, DCB_PG_ADVERTISE, DCB_PG_WILLING
1140 * description: Priority groups flags.
1143 g_object_class_install_property
1144 (object_class, PROP_PRIORITY_GROUP_FLAGS,
1145 g_param_spec_flags (NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, "", "",
1146 NM_TYPE_SETTING_DCB_FLAGS,
1147 NM_SETTING_DCB_FLAG_NONE,
1149 G_PARAM_STATIC_STRINGS));
1152 * NMSettingDcb:priority-group-id:
1154 * An array of 8 uint values, where the array index corresponds to the User
1155 * Priority (0 - 7) and the value indicates the Priority Group ID. Allowed
1156 * Priority Group ID values are 0 - 7 or 15 for the unrestricted group.
1158 * Element-type: guint
1161 * property: priority-group-id
1162 * variable: DCB_PG_ID
1163 * description: Priority groups values. String of eight priorities (0 - 7) or "f"
1165 * example: DCB_PG_ID=1205f173
1168 g_object_class_install_property
1169 (object_class, PROP_PRIORITY_GROUP_ID,
1170 g_param_spec_boxed (NM_SETTING_DCB_PRIORITY_GROUP_ID, "", "",
1173 G_PARAM_STATIC_STRINGS));
1174 _nm_setting_class_transform_property (parent_class, NM_SETTING_DCB_PRIORITY_GROUP_ID,
1175 G_VARIANT_TYPE ("au"),
1176 _nm_setting_dcb_uint_array_to_dbus,
1177 _nm_setting_dcb_uint_array_from_dbus);
1180 * NMSettingDcb:priority-group-bandwidth:
1182 * An array of 8 uint values, where the array index corresponds to the
1183 * Priority Group ID (0 - 7) and the value indicates the percentage of link
1184 * bandwidth allocated to that group. Allowed values are 0 - 100, and the
1185 * sum of all values must total 100 percent.
1187 * Element-type: guint
1190 * property: priority-group-bandwidth
1191 * variable: DCB_PG_PCT
1192 * description: Priority groups values. Eight bandwidths (in percent), separated with commas.
1193 * example: DCB_PG_PCT=10,5,10,15,10,10,10,30
1196 g_object_class_install_property
1197 (object_class, PROP_PRIORITY_GROUP_BANDWIDTH,
1198 g_param_spec_boxed (NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH, "", "",
1201 G_PARAM_STATIC_STRINGS));
1202 _nm_setting_class_transform_property (parent_class, NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH,
1203 G_VARIANT_TYPE ("au"),
1204 _nm_setting_dcb_uint_array_to_dbus,
1205 _nm_setting_dcb_uint_array_from_dbus);
1208 * NMSettingDcb:priority-bandwidth:
1210 * An array of 8 uint values, where the array index corresponds to the User
1211 * Priority (0 - 7) and the value indicates the percentage of bandwidth of
1212 * the priority's assigned group that the priority may use. The sum of all
1213 * percentages for priorities which belong to the same group must total 100
1216 * Element-type: guint
1219 * property: priority-bandwidth
1220 * variable: DCB_PG_UPPCT
1221 * description: Priority values. Eight bandwidths (in percent), separated with commas.
1222 * The sum of the numbers must be 100.
1223 * example: DCB_PG_UPPCT=7,13,10,10,15,15,10,20
1226 g_object_class_install_property
1227 (object_class, PROP_PRIORITY_BANDWIDTH,
1228 g_param_spec_boxed (NM_SETTING_DCB_PRIORITY_BANDWIDTH, "", "",
1231 G_PARAM_STATIC_STRINGS));
1232 _nm_setting_class_transform_property (parent_class, NM_SETTING_DCB_PRIORITY_BANDWIDTH,
1233 G_VARIANT_TYPE ("au"),
1234 _nm_setting_dcb_uint_array_to_dbus,
1235 _nm_setting_dcb_uint_array_from_dbus);
1238 * NMSettingDcb:priority-strict-bandwidth:
1240 * An array of 8 boolean values, where the array index corresponds to the User
1241 * Priority (0 - 7) and the value indicates whether or not the priority may
1242 * use all of the bandwidth allocated to its assigned group.
1244 * Element-type: gboolean
1247 * property: priority-strict-bandwidth
1248 * variable: DCB_PG_STRICT
1249 * description: Priority values. String of eight "0" or "1", where "0" means
1250 * "may not utilize all bandwidth", "1" means "may utilize all bandwidth".
1251 * example: DCB_PG_STRICT=01101110
1254 g_object_class_install_property
1255 (object_class, PROP_PRIORITY_STRICT,
1256 g_param_spec_boxed (NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH, "", "",
1259 G_PARAM_STATIC_STRINGS));
1260 _nm_setting_class_transform_property (parent_class, NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH,
1261 G_VARIANT_TYPE ("au"),
1262 _nm_setting_dcb_uint_array_to_dbus,
1263 _nm_setting_dcb_uint_array_from_dbus);
1266 * NMSettingDcb:priority-traffic-class:
1268 * An array of 8 uint values, where the array index corresponds to the User
1269 * Priority (0 - 7) and the value indicates the traffic class (0 - 7) to
1270 * which the priority is mapped.
1272 * Element-type: guint
1275 * property: priority-traffic-class
1276 * variable: DCB_PG_UP2TC
1277 * description: Priority values. String of eight trafic class values (0 - 7).
1278 * example: DCB_PG_UP2TC=01623701
1281 g_object_class_install_property
1282 (object_class, PROP_PRIORITY_TRAFFIC_CLASS,
1283 g_param_spec_boxed (NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS, "", "",
1286 G_PARAM_STATIC_STRINGS));
1287 _nm_setting_class_transform_property (parent_class, NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS,
1288 G_VARIANT_TYPE ("au"),
1289 _nm_setting_dcb_uint_array_to_dbus,
1290 _nm_setting_dcb_uint_array_from_dbus);