Blame src/tests/test-dcb.c

Packit Service 87a54e
/* SPDX-License-Identifier: GPL-2.0-or-later */
Packit 5756e2
/*
Packit 5756e2
 * Copyright (C) 2013 Red Hat, Inc.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
#include "nm-default.h"
Packit 5756e2
Packit 5756e2
#include "nm-dcb.h"
Packit 5756e2
Packit 5756e2
#include "nm-test-utils-core.h"
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    guint       num;
Packit Service a1bd4f
    const char *cmds[];
Packit 5756e2
} DcbExpected;
Packit 5756e2
Packit 5756e2
static gboolean
Packit Service a1bd4f
test_dcb_func(char **argv, guint which, gpointer user_data, GError **error)
Packit 5756e2
{
Packit Service a1bd4f
    DcbExpected *e = user_data;
Packit Service a1bd4f
    char *       f;
Packit Service a1bd4f
Packit Service a1bd4f
    g_assert(argv[0] == NULL);
Packit Service a1bd4f
    argv[0] = (which == DCBTOOL) ? "dcbtool" : "fcoeadm";
Packit Service a1bd4f
Packit Service a1bd4f
    f = g_strjoinv(" ", argv);
Packit Service a1bd4f
    if (e->cmds[e->num] == NULL)
Packit Service a1bd4f
        g_assert_cmpstr(f, ==, NULL);
Packit Service a1bd4f
    g_assert_cmpstr(e->cmds[e->num], !=, NULL);
Packit Service a1bd4f
    g_assert_cmpstr(f, ==, e->cmds[e->num++]);
Packit Service a1bd4f
    g_free(f);
Packit Service a1bd4f
    return TRUE;
Packit 5756e2
}
Packit 5756e2
Packit Service a1bd4f
#define DCB_FLAGS_ALL \
Packit Service a1bd4f
    (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE | NM_SETTING_DCB_FLAG_WILLING)
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
test_dcb_fcoe(void)
Packit 5756e2
{
Packit Service a1bd4f
    static DcbExpected expected = {
Packit Service a1bd4f
        0,
Packit Service a1bd4f
        {"dcbtool sc eth0 app:fcoe e:1 a:1 w:1",
Packit Service a1bd4f
         "dcbtool sc eth0 app:fcoe appcfg:40",
Packit Service a1bd4f
         "dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:fip e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 pfc e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 pg e:0",
Packit Service a1bd4f
         NULL},
Packit Service a1bd4f
    };
Packit Service a1bd4f
    NMSettingDcb *s_dcb;
Packit Service a1bd4f
    GError *      error = NULL;
Packit Service a1bd4f
    gboolean      success;
Packit Service a1bd4f
Packit Service a1bd4f
    s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
Packit Service a1bd4f
    g_object_set(G_OBJECT(s_dcb),
Packit Service a1bd4f
                 NM_SETTING_DCB_APP_FCOE_FLAGS,
Packit Service a1bd4f
                 DCB_FLAGS_ALL,
Packit Service a1bd4f
                 NM_SETTING_DCB_APP_FCOE_PRIORITY,
Packit Service a1bd4f
                 6,
Packit Service a1bd4f
                 NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    success = _dcb_setup("eth0", s_dcb, test_dcb_func, &expected, &error);
Packit Service a1bd4f
    g_assert_no_error(error);
Packit Service a1bd4f
    g_assert(success);
Packit Service a1bd4f
Packit Service a1bd4f
    g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
Packit Service a1bd4f
    g_object_unref(s_dcb);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
test_dcb_iscsi(void)
Packit 5756e2
{
Packit Service a1bd4f
    static DcbExpected expected = {
Packit Service a1bd4f
        0,
Packit Service a1bd4f
        {"dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:iscsi e:1 a:0 w:1",
Packit Service a1bd4f
         "dcbtool sc eth0 app:iscsi appcfg:08",
Packit Service a1bd4f
         "dcbtool sc eth0 app:fip e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 pfc e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 pg e:0",
Packit Service a1bd4f
         NULL},
Packit Service a1bd4f
    };
Packit Service a1bd4f
    NMSettingDcb *s_dcb;
Packit Service a1bd4f
    GError *      error = NULL;
Packit Service a1bd4f
    gboolean      success;
Packit Service a1bd4f
Packit Service a1bd4f
    s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
Packit Service a1bd4f
    g_object_set(G_OBJECT(s_dcb),
Packit Service a1bd4f
                 NM_SETTING_DCB_APP_ISCSI_FLAGS,
Packit Service a1bd4f
                 (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_WILLING),
Packit Service a1bd4f
                 NM_SETTING_DCB_APP_ISCSI_PRIORITY,
Packit Service a1bd4f
                 3,
Packit Service a1bd4f
                 NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    success = _dcb_setup("eth0", s_dcb, test_dcb_func, &expected, &error);
Packit Service a1bd4f
    g_assert_no_error(error);
Packit Service a1bd4f
    g_assert(success);
Packit Service a1bd4f
Packit Service a1bd4f
    g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
Packit Service a1bd4f
    g_object_unref(s_dcb);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
test_dcb_fip(void)
Packit 5756e2
{
Packit Service a1bd4f
    static DcbExpected expected = {
Packit Service a1bd4f
        0,
Packit Service a1bd4f
        {"dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:fip e:1 a:1 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:fip appcfg:01",
Packit Service a1bd4f
         "dcbtool sc eth0 pfc e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 pg e:0",
Packit Service a1bd4f
         NULL},
Packit Service a1bd4f
    };
Packit Service a1bd4f
    NMSettingDcb *s_dcb;
Packit Service a1bd4f
    GError *      error = NULL;
Packit Service a1bd4f
    gboolean      success;
Packit Service a1bd4f
Packit Service a1bd4f
    s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
Packit Service a1bd4f
    g_object_set(G_OBJECT(s_dcb),
Packit Service a1bd4f
                 NM_SETTING_DCB_APP_FIP_FLAGS,
Packit Service a1bd4f
                 (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE),
Packit Service a1bd4f
                 NM_SETTING_DCB_APP_FIP_PRIORITY,
Packit Service a1bd4f
                 0,
Packit Service a1bd4f
                 NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    success = _dcb_setup("eth0", s_dcb, test_dcb_func, &expected, &error);
Packit Service a1bd4f
    g_assert_no_error(error);
Packit Service a1bd4f
    g_assert(success);
Packit Service a1bd4f
Packit Service a1bd4f
    g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
Packit Service a1bd4f
    g_object_unref(s_dcb);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
test_dcb_fip_default_prio(void)
Packit 5756e2
{
Packit Service a1bd4f
    static DcbExpected expected = {
Packit Service a1bd4f
        0,
Packit Service a1bd4f
        {"dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:fip e:1 a:1 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 pfc e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 pg e:0",
Packit Service a1bd4f
         NULL},
Packit Service a1bd4f
    };
Packit Service a1bd4f
    NMSettingDcb *s_dcb;
Packit Service a1bd4f
    GError *      error = NULL;
Packit Service a1bd4f
    gboolean      success;
Packit Service a1bd4f
Packit Service a1bd4f
    s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
Packit Service a1bd4f
    g_object_set(G_OBJECT(s_dcb),
Packit Service a1bd4f
                 NM_SETTING_DCB_APP_FIP_FLAGS,
Packit Service a1bd4f
                 (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE),
Packit Service a1bd4f
                 NM_SETTING_DCB_APP_FIP_PRIORITY,
Packit Service a1bd4f
                 -1,
Packit Service a1bd4f
                 NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    success = _dcb_setup("eth0", s_dcb, test_dcb_func, &expected, &error);
Packit Service a1bd4f
    g_assert_no_error(error);
Packit Service a1bd4f
    g_assert(success);
Packit Service a1bd4f
Packit Service a1bd4f
    g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
Packit Service a1bd4f
    g_object_unref(s_dcb);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
test_dcb_pfc(void)
Packit 5756e2
{
Packit Service a1bd4f
    static DcbExpected expected = {
Packit Service a1bd4f
        0,
Packit Service a1bd4f
        {"dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:fip e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 pfc e:1 a:1 w:1",
Packit Service a1bd4f
         "dcbtool sc eth0 pfc pfcup:01101100",
Packit Service a1bd4f
         "dcbtool sc eth0 pg e:0",
Packit Service a1bd4f
         NULL},
Packit Service a1bd4f
    };
Packit Service a1bd4f
    NMSettingDcb *s_dcb;
Packit Service a1bd4f
    GError *      error = NULL;
Packit Service a1bd4f
    gboolean      success;
Packit Service a1bd4f
Packit Service a1bd4f
    s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
Packit Service a1bd4f
    g_object_set(G_OBJECT(s_dcb), NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, DCB_FLAGS_ALL, NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    nm_setting_dcb_set_priority_flow_control(s_dcb, 0, FALSE);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_flow_control(s_dcb, 1, TRUE);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_flow_control(s_dcb, 2, TRUE);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_flow_control(s_dcb, 3, FALSE);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_flow_control(s_dcb, 4, TRUE);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_flow_control(s_dcb, 5, TRUE);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_flow_control(s_dcb, 6, FALSE);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_flow_control(s_dcb, 7, FALSE);
Packit Service a1bd4f
Packit Service a1bd4f
    success = _dcb_setup("eth0", s_dcb, test_dcb_func, &expected, &error);
Packit Service a1bd4f
    g_assert_no_error(error);
Packit Service a1bd4f
    g_assert(success);
Packit Service a1bd4f
Packit Service a1bd4f
    g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
Packit Service a1bd4f
    g_object_unref(s_dcb);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
test_dcb_priority_groups(void)
Packit 5756e2
{
Packit Service a1bd4f
    static DcbExpected expected = {
Packit Service a1bd4f
        0,
Packit Service a1bd4f
        {"dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:fip e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 pfc e:0 a:0 w:0",
Packit Service a1bd4f
         "dcbtool sc eth0 pg e:1 a:1 w:1"
Packit Service a1bd4f
         " pgid:765f3210"
Packit Service a1bd4f
         " pgpct:10,40,5,10,5,20,7,3"
Packit Service a1bd4f
         " uppct:100,50,33,25,20,16,14,12"
Packit Service a1bd4f
         " strict:01010101"
Packit Service a1bd4f
         " up2tc:01201201",
Packit Service a1bd4f
         NULL},
Packit Service a1bd4f
    };
Packit Service a1bd4f
    NMSettingDcb *s_dcb;
Packit Service a1bd4f
    GError *      error = NULL;
Packit Service a1bd4f
    gboolean      success;
Packit Service a1bd4f
    guint         i;
Packit Service a1bd4f
Packit Service a1bd4f
    s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
Packit Service a1bd4f
    g_object_set(G_OBJECT(s_dcb), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, DCB_FLAGS_ALL, NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    for (i = 0; i < 8; i++) {
Packit Service a1bd4f
        /* Make sure at least one 15/f is present in the group IDs */
Packit Service a1bd4f
        nm_setting_dcb_set_priority_group_id(s_dcb, i, (i == 3) ? 15 : 7 - i);
Packit Service a1bd4f
        nm_setting_dcb_set_priority_bandwidth(s_dcb, i, 100 / (i + 1));
Packit Service a1bd4f
        nm_setting_dcb_set_priority_strict_bandwidth(s_dcb, i, i % 2);
Packit Service a1bd4f
        nm_setting_dcb_set_priority_traffic_class(s_dcb, i, i % 3);
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 0, 10);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 1, 40);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 2, 5);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 3, 10);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 4, 5);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 5, 20);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 6, 7);
Packit Service a1bd4f
    nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 7, 3);
Packit Service a1bd4f
Packit Service a1bd4f
    success = _dcb_setup("eth0", s_dcb, test_dcb_func, &expected, &error);
Packit Service a1bd4f
    g_assert_no_error(error);
Packit Service a1bd4f
    g_assert(success);
Packit Service a1bd4f
Packit Service a1bd4f
    g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
Packit Service a1bd4f
    g_object_unref(s_dcb);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
test_dcb_cleanup(void)
Packit 5756e2
{
Packit Service a1bd4f
    static DcbExpected expected = {
Packit Service a1bd4f
        0,
Packit Service a1bd4f
        {"fcoeadm -d eth0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:fcoe e:0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:iscsi e:0",
Packit Service a1bd4f
         "dcbtool sc eth0 app:fip e:0",
Packit Service a1bd4f
         "dcbtool sc eth0 pfc e:0",
Packit Service a1bd4f
         "dcbtool sc eth0 pg e:0",
Packit Service a1bd4f
         "dcbtool sc eth0 dcb off",
Packit Service a1bd4f
         NULL},
Packit Service a1bd4f
    };
Packit Service a1bd4f
    GError * error = NULL;
Packit Service a1bd4f
    gboolean success;
Packit Service a1bd4f
Packit Service a1bd4f
    success = _fcoe_cleanup("eth0", test_dcb_func, &expected, &error);
Packit Service a1bd4f
    g_assert_no_error(error);
Packit Service a1bd4f
    g_assert(success);
Packit Service a1bd4f
Packit Service a1bd4f
    success = _dcb_cleanup("eth0", test_dcb_func, &expected, &error);
Packit Service a1bd4f
    g_assert_no_error(error);
Packit Service a1bd4f
    g_assert(success);
Packit Service a1bd4f
Packit Service a1bd4f
    g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
test_fcoe_create(void)
Packit 5756e2
{
Packit Service a1bd4f
    static DcbExpected expected1 = {
Packit Service a1bd4f
        0,
Packit Service a1bd4f
        {"fcoeadm -m fabric -c eth0", NULL},
Packit Service a1bd4f
    };
Packit Service a1bd4f
    static DcbExpected expected2 = {
Packit Service a1bd4f
        0,
Packit Service a1bd4f
        {"fcoeadm -m vn2vn -c eth0", NULL},
Packit Service a1bd4f
    };
Packit Service a1bd4f
    GError *      error = NULL;
Packit Service a1bd4f
    gboolean      success;
Packit Service a1bd4f
    NMSettingDcb *s_dcb;
Packit Service a1bd4f
Packit Service a1bd4f
    s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
Packit Service a1bd4f
    g_object_set(G_OBJECT(s_dcb), NM_SETTING_DCB_APP_FCOE_FLAGS, DCB_FLAGS_ALL, NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    /* Default mode is fabric */
Packit Service a1bd4f
    success = _fcoe_setup("eth0", s_dcb, test_dcb_func, &expected1, &error);
Packit Service a1bd4f
    g_assert_no_error(error);
Packit Service a1bd4f
    g_assert(success);
Packit Service a1bd4f
Packit Service a1bd4f
    /* Test VN2VN */
Packit Service a1bd4f
    g_object_set(G_OBJECT(s_dcb),
Packit Service a1bd4f
                 NM_SETTING_DCB_APP_FCOE_MODE,
Packit Service a1bd4f
                 NM_SETTING_DCB_FCOE_MODE_VN2VN,
Packit Service a1bd4f
                 NULL);
Packit Service a1bd4f
    success = _fcoe_setup("eth0", s_dcb, test_dcb_func, &expected2, &error);
Packit Service a1bd4f
    g_assert_no_error(error);
Packit Service a1bd4f
    g_assert(success);
Packit Service a1bd4f
Packit Service a1bd4f
    g_object_unref(s_dcb);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
test_fcoe_cleanup(void)
Packit 5756e2
{
Packit Service a1bd4f
    static DcbExpected expected = {
Packit Service a1bd4f
        0,
Packit Service a1bd4f
        {"fcoeadm -d eth0", NULL},
Packit Service a1bd4f
    };
Packit Service a1bd4f
    GError * error = NULL;
Packit Service a1bd4f
    gboolean success;
Packit Service a1bd4f
Packit Service a1bd4f
    success = _fcoe_cleanup("eth0", test_dcb_func, &expected, &error);
Packit Service a1bd4f
    g_assert_no_error(error);
Packit Service a1bd4f
    g_assert(success);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
NMTST_DEFINE();
Packit 5756e2
Packit 5756e2
int
Packit Service a1bd4f
main(int argc, char **argv)
Packit 5756e2
{
Packit Service a1bd4f
    nmtst_init_assert_logging(&argc, &argv, "INFO", "DEFAULT");
Packit Service a1bd4f
Packit Service a1bd4f
    g_test_add_func("/dcb/fcoe", test_dcb_fcoe);
Packit Service a1bd4f
    g_test_add_func("/dcb/iscsi", test_dcb_iscsi);
Packit Service a1bd4f
    g_test_add_func("/dcb/fip", test_dcb_fip);
Packit Service a1bd4f
    g_test_add_func("/dcb/fip-default-priority", test_dcb_fip_default_prio);
Packit Service a1bd4f
    g_test_add_func("/dcb/pfc", test_dcb_pfc);
Packit Service a1bd4f
    g_test_add_func("/dcb/priority-groups", test_dcb_priority_groups);
Packit Service a1bd4f
    g_test_add_func("/dcb/cleanup", test_dcb_cleanup);
Packit Service a1bd4f
    g_test_add_func("/fcoe/create", test_fcoe_create);
Packit Service a1bd4f
    g_test_add_func("/fcoe/cleanup", test_fcoe_cleanup);
Packit Service a1bd4f
Packit Service a1bd4f
    return g_test_run();
Packit 5756e2
}