libnm-util: add Data Center Bridging (DCB) setting

Includes various fixes & cleanups from Thomas Haller.
This commit is contained in:
Dan Williams 2013-09-13 09:44:56 -05:00
parent 229e3fbe32
commit 77e50740a8
11 changed files with 1815 additions and 2 deletions

1
.gitignore vendored
View file

@ -176,6 +176,7 @@ valgrind-*.log
/libnm-util/tests/test-need-secrets
/libnm-util/tests/test-secrets
/libnm-util/tests/test-setting-8021x
/libnm-util/tests/test-setting-dcb
/libnm-glib/tests/test-remote-settings-client
/src/tests/test-dhcp-options
/src/tests/test-ip4-config

View file

@ -62,6 +62,7 @@
<xi:include href="xml/nm-setting-vlan.xml"/>
<xi:include href="xml/nm-setting-olpc-mesh.xml"/>
<xi:include href="xml/nm-setting-adsl.xml"/>
<xi:include href="xml/nm-setting-dcb.xml"/>
<xi:include href="xml/nm-setting-8021x.xml"/>
<xi:include href="xml/nm-setting-ip4-config.xml"/>
<xi:include href="xml/nm-setting-ip6-config.xml"/>

View file

@ -32,6 +32,7 @@ libnm_util_include_HEADERS = \
nm-setting-bridge.h \
nm-setting-bridge-port.h \
nm-setting-connection.h \
nm-setting-dcb.h \
nm-setting-infiniband.h \
nm-setting-ip4-config.h \
nm-setting-vlan.h \
@ -71,6 +72,7 @@ libnm_util_la_csources = \
nm-setting-bridge.c \
nm-setting-bridge-port.c \
nm-setting-connection.c \
nm-setting-dcb.c \
nm-setting-infiniband.c \
nm-setting-ip4-config.c \
nm-setting-vlan.c \

View file

@ -23,6 +23,7 @@ global:
nm_connection_get_setting_by_name;
nm_connection_get_setting_cdma;
nm_connection_get_setting_connection;
nm_connection_get_setting_dcb;
nm_connection_get_setting_generic;
nm_connection_get_setting_gsm;
nm_connection_get_setting_infiniband;
@ -263,6 +264,32 @@ global:
nm_setting_connection_permissions_user_allowed;
nm_setting_connection_remove_permission;
nm_setting_connection_remove_secondary;
nm_setting_dcb_error_get_type;
nm_setting_dcb_error_quark;
nm_setting_dcb_flags_get_type;
nm_setting_dcb_get_app_fcoe_flags;
nm_setting_dcb_get_app_fcoe_mode;
nm_setting_dcb_get_app_fcoe_priority;
nm_setting_dcb_get_app_fip_flags;
nm_setting_dcb_get_app_fip_priority;
nm_setting_dcb_get_app_iscsi_flags;
nm_setting_dcb_get_app_iscsi_priority;
nm_setting_dcb_get_priority_bandwidth;
nm_setting_dcb_get_priority_flow_control;
nm_setting_dcb_get_priority_flow_control_flags;
nm_setting_dcb_get_priority_group_bandwidth;
nm_setting_dcb_get_priority_group_flags;
nm_setting_dcb_get_priority_group_id;
nm_setting_dcb_get_priority_strict_bandwidth;
nm_setting_dcb_get_priority_traffic_class;
nm_setting_dcb_get_type;
nm_setting_dcb_new;
nm_setting_dcb_set_priority_bandwidth;
nm_setting_dcb_set_priority_flow_control;
nm_setting_dcb_set_priority_group_bandwidth;
nm_setting_dcb_set_priority_group_id;
nm_setting_dcb_set_priority_strict_bandwidth;
nm_setting_dcb_set_priority_traffic_class;
nm_setting_diff;
nm_setting_diff_result_get_type;
nm_setting_duplicate;

View file

@ -1326,6 +1326,22 @@ nm_connection_get_setting_connection (NMConnection *connection)
return (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
}
/**
* nm_connection_get_setting_dcb:
* @connection: the #NMConnection
*
* A shortcut to return any #NMSettingDcb the connection might contain.
*
* Returns: (transfer none): an #NMSettingDcb if the connection contains one, otherwise NULL
**/
NMSettingDcb *
nm_connection_get_setting_dcb (NMConnection *connection)
{
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
return (NMSettingDcb *) nm_connection_get_setting (connection, NM_TYPE_SETTING_DCB);
}
/**
* nm_connection_get_setting_generic:
* @connection: the #NMConnection

View file

@ -39,6 +39,7 @@
#include <nm-setting-bridge-port.h>
#include <nm-setting-cdma.h>
#include <nm-setting-connection.h>
#include <nm-setting-dcb.h>
#include <nm-setting-generic.h>
#include <nm-setting-gsm.h>
#include <nm-setting-infiniband.h>
@ -208,6 +209,7 @@ NMSettingBridge * nm_connection_get_setting_bridge (NMConnec
NMSettingBridgePort * nm_connection_get_setting_bridge_port (NMConnection *connection);
NMSettingCdma * nm_connection_get_setting_cdma (NMConnection *connection);
NMSettingConnection * nm_connection_get_setting_connection (NMConnection *connection);
NMSettingDcb * nm_connection_get_setting_dcb (NMConnection *connection);
NMSettingGeneric * nm_connection_get_setting_generic (NMConnection *connection);
NMSettingGsm * nm_connection_get_setting_gsm (NMConnection *connection);
NMSettingInfiniband * nm_connection_get_setting_infiniband (NMConnection *connection);

1258
libnm-util/nm-setting-dcb.c Normal file

File diff suppressed because it is too large Load diff

187
libnm-util/nm-setting-dcb.h Normal file
View file

@ -0,0 +1,187 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* Dan Williams <dcbw@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* (C) Copyright 2013 Red Hat, Inc.
*/
#ifndef NM_SETTING_DCB_H
#define NM_SETTING_DCB_H
#include <nm-setting.h>
G_BEGIN_DECLS
#define NM_TYPE_SETTING_DCB (nm_setting_dcb_get_type ())
#define NM_SETTING_DCB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_DCB, NMSettingDcb))
#define NM_SETTING_DCB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_DCB, NMSettingDcbClass))
#define NM_IS_SETTING_DCB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_DCB))
#define NM_IS_SETTING_DCB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_DCB))
#define NM_SETTING_DCB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_DCB, NMSettingDcbClass))
#define NM_SETTING_DCB_SETTING_NAME "dcb"
/**
* NMSettingDcbError:
* @NM_SETTING_DCB_ERROR_UNKNOWN: unknown or unclassified error
* @NM_SETTING_DCB_ERROR_INVALID_PROPERTY: the property was invalid
* @NM_SETTING_DCB_ERROR_MISSING_PROPERTY: the property was missing and is
* required
*/
typedef enum {
NM_SETTING_DCB_ERROR_UNKNOWN = 0, /*< nick=UnknownError >*/
NM_SETTING_DCB_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
NM_SETTING_DCB_ERROR_MISSING_PROPERTY /*< nick=MissingProperty >*/
} NMSettingDcbError;
#define NM_SETTING_DCB_ERROR nm_setting_dcb_error_quark ()
GQuark nm_setting_dcb_error_quark (void);
/**
* NMSettingDcbFlags:
* @NM_SETTING_DCB_FLAG_NONE: no flag
* @NM_SETTING_DCB_FLAG_ENABLE: the feature is enabled
* @NM_SETTING_DCB_FLAG_ADVERTISE: the feature is advertised
* @NM_SETTING_DCB_FLAG_WILLING: the feature is willing to change based on
* peer configuration advertisements
*
* DCB feature flags.
*
* Since: 0.9.10
**/
typedef enum {
NM_SETTING_DCB_FLAG_NONE = 0x00000000,
NM_SETTING_DCB_FLAG_ENABLE = 0x00000001,
NM_SETTING_DCB_FLAG_ADVERTISE = 0x00000002,
NM_SETTING_DCB_FLAG_WILLING = 0x00000004
} NMSettingDcbFlags;
/**
* NM_SETTING_DCB_FCOE_MODE_FABRIC:
*
* Indicates that the FCoE controller should use "fabric" mode (default)
*
* Since: 0.9.10
*/
#define NM_SETTING_DCB_FCOE_MODE_FABRIC "fabric"
/**
* NM_SETTING_DCB_FCOE_MODE_VN2VN:
*
* Indicates that the FCoE controller should use "VN2VN" mode.
*
* Since: 0.9.10
*/
#define NM_SETTING_DCB_FCOE_MODE_VN2VN "vn2vn"
/* Properties */
#define NM_SETTING_DCB_APP_FCOE_FLAGS "app-fcoe-flags"
#define NM_SETTING_DCB_APP_FCOE_PRIORITY "app-fcoe-priority"
#define NM_SETTING_DCB_APP_FCOE_MODE "app-fcoe-mode"
#define NM_SETTING_DCB_APP_ISCSI_FLAGS "app-iscsi-flags"
#define NM_SETTING_DCB_APP_ISCSI_PRIORITY "app-iscsi-priority"
#define NM_SETTING_DCB_APP_FIP_FLAGS "app-fip-flags"
#define NM_SETTING_DCB_APP_FIP_PRIORITY "app-fip-priority"
#define NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS "priority-flow-control-flags"
#define NM_SETTING_DCB_PRIORITY_FLOW_CONTROL "priority-flow-control"
#define NM_SETTING_DCB_PRIORITY_GROUP_FLAGS "priority-group-flags"
#define NM_SETTING_DCB_PRIORITY_GROUP_ID "priority-group-id"
#define NM_SETTING_DCB_PRIORITY_GROUP_BANDWIDTH "priority-group-bandwidth"
#define NM_SETTING_DCB_PRIORITY_BANDWIDTH "priority-bandwidth"
#define NM_SETTING_DCB_PRIORITY_STRICT_BANDWIDTH "priority-strict-bandwidth"
#define NM_SETTING_DCB_PRIORITY_TRAFFIC_CLASS "priority-traffic-class"
typedef struct {
NMSetting parent;
} NMSettingDcb;
typedef struct {
NMSettingClass parent;
/* Padding for future expansion */
void (*_reserved1) (void);
void (*_reserved2) (void);
void (*_reserved3) (void);
void (*_reserved4) (void);
} NMSettingDcbClass;
GType nm_setting_dcb_get_type (void);
NMSetting * nm_setting_dcb_new (void);
NMSettingDcbFlags nm_setting_dcb_get_app_fcoe_flags (NMSettingDcb *setting);
gint nm_setting_dcb_get_app_fcoe_priority (NMSettingDcb *setting);
const char * nm_setting_dcb_get_app_fcoe_mode (NMSettingDcb *setting);
NMSettingDcbFlags nm_setting_dcb_get_app_iscsi_flags (NMSettingDcb *setting);
gint nm_setting_dcb_get_app_iscsi_priority (NMSettingDcb *setting);
NMSettingDcbFlags nm_setting_dcb_get_app_fip_flags (NMSettingDcb *setting);
gint nm_setting_dcb_get_app_fip_priority (NMSettingDcb *setting);
/* Priority Flow Control */
NMSettingDcbFlags nm_setting_dcb_get_priority_flow_control_flags (NMSettingDcb *setting);
gboolean nm_setting_dcb_get_priority_flow_control (NMSettingDcb *setting,
guint user_priority);
void nm_setting_dcb_set_priority_flow_control (NMSettingDcb *setting,
guint user_priority,
gboolean enabled);
/* Priority Groups */
NMSettingDcbFlags nm_setting_dcb_get_priority_group_flags (NMSettingDcb *setting);
guint nm_setting_dcb_get_priority_group_id (NMSettingDcb *setting,
guint user_priority);
void nm_setting_dcb_set_priority_group_id (NMSettingDcb *setting,
guint user_priority,
guint group_id);
guint nm_setting_dcb_get_priority_group_bandwidth (NMSettingDcb *setting,
guint group_id);
void nm_setting_dcb_set_priority_group_bandwidth (NMSettingDcb *setting,
guint group_id,
guint bandwidth_percent);
guint nm_setting_dcb_get_priority_bandwidth (NMSettingDcb *setting,
guint user_priority);
void nm_setting_dcb_set_priority_bandwidth (NMSettingDcb *setting,
guint user_priority,
guint bandwidth_percent);
gboolean nm_setting_dcb_get_priority_strict_bandwidth (NMSettingDcb *setting,
guint user_priority);
void nm_setting_dcb_set_priority_strict_bandwidth (NMSettingDcb *setting,
guint user_priority,
gboolean strict);
guint nm_setting_dcb_get_priority_traffic_class (NMSettingDcb *setting,
guint user_priority);
void nm_setting_dcb_set_priority_traffic_class (NMSettingDcb *setting,
guint user_priority,
guint traffic_class);
G_END_DECLS
#endif /* NM_SETTING_DCB_H */

View file

@ -16,7 +16,8 @@ noinst_PROGRAMS = \
test-crypto \
test-secrets \
test-general \
test-setting-8021x
test-setting-8021x \
test-setting-dcb
test_settings_defaults_SOURCES = \
test-settings-defaults.c
@ -58,10 +59,19 @@ test_setting_8021x_LDADD = \
$(GLIB_LIBS) \
$(DBUS_LIBS)
check-local: test-settings-defaults test-crypto test-secrets
test_setting_dcb_SOURCES = \
test-setting-dcb.c
test_setting_dcb_LDADD = \
$(top_builddir)/libnm-util/libnm-util.la \
$(GLIB_LIBS) \
$(DBUS_LIBS)
check-local: test-settings-defaults test-crypto test-secrets test-setting-8021x test-setting-dcb
$(abs_builddir)/test-settings-defaults
$(abs_builddir)/test-secrets
$(abs_builddir)/test-general
$(abs_builddir)/test-setting-dcb
# Private key and CA certificate in the same file (PEM)
$(abs_builddir)/test-setting-8021x $(srcdir)/certs/test_key_and_cert.pem "test"

View file

@ -0,0 +1,308 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2013 Red Hat, Inc.
*
*/
#include <glib.h>
#include <string.h>
#include <nm-utils.h>
#include "nm-setting-dcb.h"
#define DCB_FLAGS_ALL (NM_SETTING_DCB_FLAG_ENABLE | \
NM_SETTING_DCB_FLAG_ADVERTISE | \
NM_SETTING_DCB_FLAG_WILLING)
static void
test_dcb_flags_valid (void)
{
NMSettingDcb *s_dcb;
GError *error = NULL;
gboolean success;
guint i;
s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
g_assert (s_dcb);
g_assert_cmpint (nm_setting_dcb_get_app_fcoe_flags (s_dcb), ==, 0);
g_assert_cmpint (nm_setting_dcb_get_app_iscsi_flags (s_dcb), ==, 0);
g_assert_cmpint (nm_setting_dcb_get_app_fip_flags (s_dcb), ==, 0);
g_assert_cmpint (nm_setting_dcb_get_priority_flow_control_flags (s_dcb), ==, 0);
g_assert_cmpint (nm_setting_dcb_get_priority_group_flags (s_dcb), ==, 0);
g_object_set (G_OBJECT (s_dcb),
NM_SETTING_DCB_APP_FCOE_FLAGS, DCB_FLAGS_ALL,
NM_SETTING_DCB_APP_ISCSI_FLAGS, DCB_FLAGS_ALL,
NM_SETTING_DCB_APP_FIP_FLAGS, DCB_FLAGS_ALL,
NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, DCB_FLAGS_ALL,
NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, DCB_FLAGS_ALL,
NULL);
/* Priority Group Bandwidth must total 100% */
for (i = 0; i < 7; i++)
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, i, 12);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 7, 16);
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error);
g_assert_no_error (error);
g_assert (success);
g_assert_cmpint (nm_setting_dcb_get_app_fcoe_flags (s_dcb), ==, DCB_FLAGS_ALL);
g_assert_cmpint (nm_setting_dcb_get_app_iscsi_flags (s_dcb), ==, DCB_FLAGS_ALL);
g_assert_cmpint (nm_setting_dcb_get_app_fip_flags (s_dcb), ==, DCB_FLAGS_ALL);
g_assert_cmpint (nm_setting_dcb_get_priority_flow_control_flags (s_dcb), ==, DCB_FLAGS_ALL);
g_assert_cmpint (nm_setting_dcb_get_priority_group_flags (s_dcb), ==, DCB_FLAGS_ALL);
}
#define TEST_FLAG(p, f, v) \
{ \
/* GObject property min/max should ensure the property does not get set to \
* the invalid value, so we ensure the value we just tried to set is 0 and \
* that verify is successful since the property never got set. \
*/ \
g_object_set (G_OBJECT (s_dcb), p, v, NULL); \
g_assert_cmpint (f (s_dcb), ==, 0); \
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
g_assert_no_error (error); \
g_assert (success); \
}
static void
test_dcb_flags_invalid (void)
{
NMSettingDcb *s_dcb;
GError *error = NULL;
gboolean success;
s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
g_assert (s_dcb);
TEST_FLAG (NM_SETTING_DCB_APP_FCOE_FLAGS, nm_setting_dcb_get_app_fcoe_flags, 0x332523);
TEST_FLAG (NM_SETTING_DCB_APP_ISCSI_FLAGS, nm_setting_dcb_get_app_iscsi_flags, 0xFF);
TEST_FLAG (NM_SETTING_DCB_APP_FIP_FLAGS, nm_setting_dcb_get_app_fip_flags, 0x1111);
TEST_FLAG (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, nm_setting_dcb_get_priority_flow_control_flags, G_MAXUINT32);
TEST_FLAG (NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, nm_setting_dcb_get_priority_group_flags,
(NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE | NM_SETTING_DCB_FLAG_WILLING) + 1);
}
#define TEST_APP_PRIORITY(lcprop, ucprop, v) \
{ \
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_##ucprop##_FLAGS, NM_SETTING_DCB_FLAG_NONE, NULL); \
\
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_##ucprop##_PRIORITY, v, NULL); \
g_assert_cmpint (nm_setting_dcb_get_app_##lcprop##_priority (s_dcb), ==, v); \
\
/* Assert that the setting is invalid while the app is disabled unless v is default */ \
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
if (v >= 0) { \
g_assert_error (error, NM_SETTING_DCB_ERROR, NM_SETTING_DCB_ERROR_INVALID_PROPERTY); \
g_assert (success == FALSE); \
} else { \
g_assert_no_error (error); \
g_assert (success); \
} \
g_clear_error (&error); \
\
/* Set the enable flag and re-verify, this time it should be valid */ \
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_##ucprop##_FLAGS, NM_SETTING_DCB_FLAG_ENABLE, NULL); \
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
g_assert_no_error (error); \
g_assert (success); \
\
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_##ucprop##_PRIORITY, 0, NULL); \
}
static void
test_dcb_app_priorities (void)
{
NMSettingDcb *s_dcb;
GError *error = NULL;
gboolean success;
s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
g_assert (s_dcb);
/* Defaults */
g_assert_cmpint (nm_setting_dcb_get_app_fcoe_priority (s_dcb), ==, -1);
g_assert_cmpint (nm_setting_dcb_get_app_iscsi_priority (s_dcb), ==, -1);
g_assert_cmpint (nm_setting_dcb_get_app_fip_priority (s_dcb), ==, -1);
TEST_APP_PRIORITY (fcoe, FCOE, 6);
TEST_APP_PRIORITY (iscsi, ISCSI, 5);
TEST_APP_PRIORITY (fip, FIP, 4);
TEST_APP_PRIORITY (fcoe, FCOE, -1);
TEST_APP_PRIORITY (iscsi, ISCSI, -1);
TEST_APP_PRIORITY (fip, FIP, -1);
}
#define TEST_PRIORITY_VALID(fn, id, val, flagsprop, verify) \
{ \
/* Assert that setting the value gets the same value back out */ \
nm_setting_dcb_set_priority_##fn (s_dcb, id, val); \
g_assert_cmpint (nm_setting_dcb_get_priority_##fn (s_dcb, id), ==, val); \
\
if (verify) { \
if (val != 0) { \
/* Assert that verify fails because the flags do not include 'enabled' \
* and a value has been set. \
*/ \
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
g_assert_error (error, NM_SETTING_DCB_ERROR, NM_SETTING_DCB_ERROR_INVALID_PROPERTY); \
g_assert (success == FALSE); \
g_clear_error (&error); \
} \
\
/* Assert that adding the 'enabled' flag verifies the setting */ \
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_PRIORITY_##flagsprop##_FLAGS, NM_SETTING_DCB_FLAG_ENABLE, NULL); \
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
g_assert_no_error (error); \
g_assert (success); \
} \
\
/* Reset everything */ \
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_PRIORITY_##flagsprop##_FLAGS, NM_SETTING_DCB_FLAG_NONE, NULL); \
nm_setting_dcb_set_priority_##fn (s_dcb, id, 0); \
}
/* If Priority Groups are enabled, PG bandwidth must equal 100% */
#define SET_VALID_PRIORITY_GROUP_BANDWIDTH \
{ \
guint x; \
for (x = 0; x < 7; x++) \
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, x, 12); \
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 7, 16); \
}
static void
test_dcb_priorities_valid (void)
{
NMSettingDcb *s_dcb;
GError *error = NULL;
gboolean success;
guint i;
s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
g_assert (s_dcb);
for (i = 0; i < 8; i++)
TEST_PRIORITY_VALID (flow_control, i, TRUE, FLOW_CONTROL, TRUE);
SET_VALID_PRIORITY_GROUP_BANDWIDTH
for (i = 0; i < 8; i++) {
TEST_PRIORITY_VALID (group_id, i, i, GROUP, TRUE);
TEST_PRIORITY_VALID (group_id, i, 7 - i, GROUP, TRUE);
}
/* Clear PG bandwidth from earlier tests */
for (i = 0; i < 8; i++)
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, i, 0);
/* Priority Group Bandwidth must add up to 100% if enabled, which requires
* some dancing for verifying individual values here.
*/
for (i = 0; i < 8; i++) {
guint other = 7 - (i % 8);
/* Set another priority group to the remaining bandwidth */
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, other, 100 - i);
TEST_PRIORITY_VALID (group_bandwidth, i, i, GROUP, TRUE);
/* Set another priority group to the remaining bandwidth */
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, other, 100 - (7 - i));
TEST_PRIORITY_VALID (group_bandwidth, i, 7 - i, GROUP, TRUE);
/* Clear remaining bandwidth */
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, other, 0);
}
SET_VALID_PRIORITY_GROUP_BANDWIDTH
for (i = 0; i < 8; i++) {
TEST_PRIORITY_VALID (bandwidth, i, i, GROUP, TRUE);
TEST_PRIORITY_VALID (bandwidth, i, 7 - i, GROUP, TRUE);
}
SET_VALID_PRIORITY_GROUP_BANDWIDTH
for (i = 0; i < 8; i++)
TEST_PRIORITY_VALID (strict_bandwidth, i, TRUE, GROUP, TRUE);
SET_VALID_PRIORITY_GROUP_BANDWIDTH
for (i = 0; i < 8; i++) {
TEST_PRIORITY_VALID (traffic_class, i, i, GROUP, TRUE);
TEST_PRIORITY_VALID (traffic_class, i, 7 - i, GROUP, TRUE);
}
}
static void
test_dcb_bandwidth_sums (void)
{
NMSettingDcb *s_dcb;
GError *error = NULL;
gboolean success;
s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
g_assert (s_dcb);
/* Assert that setting the value gets the same value back out */
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 0, 9);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 1, 10);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 2, 11);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 3, 12);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 4, 13);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 5, 14);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 6, 15);
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 7, 16);
/* Assert verify success when sums total 100% */
g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, NM_SETTING_DCB_FLAG_ENABLE, NULL);
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error);
g_assert_no_error (error);
g_assert (success);
/* Assert verify fails when sums do not total 100% */
nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 4, 20);
success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error);
g_assert_error (error, NM_SETTING_DCB_ERROR, NM_SETTING_DCB_ERROR_INVALID_PROPERTY);
g_assert (success == FALSE);
g_clear_error (&error);
}
#define TPATH "/libnm-util/settings/dcb/"
int main (int argc, char **argv)
{
GError *error = NULL;
gboolean success;
g_test_init (&argc, &argv, NULL);
g_type_init ();
success = nm_utils_init (&error);
g_assert_no_error (error);
g_assert (success);
g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
g_test_add_func (TPATH "flags-valid", test_dcb_flags_valid);
g_test_add_func (TPATH "flags-invalid", test_dcb_flags_invalid);
g_test_add_func (TPATH "app-priorities", test_dcb_app_priorities);
g_test_add_func (TPATH "priorities", test_dcb_priorities_valid);
g_test_add_func (TPATH "bandwidth-sums", test_dcb_bandwidth_sums);
return g_test_run ();
}

View file

@ -19,6 +19,7 @@ libnm-util/nm-setting-bridge-port.c
libnm-util/nm-setting-bridge.c
libnm-util/nm-setting-cdma.c
libnm-util/nm-setting-connection.c
libnm-util/nm-setting-dcb.c
libnm-util/nm-setting-gsm.c
libnm-util/nm-setting-infiniband.c
libnm-util/nm-setting-ip4-config.c