1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 * Copyright 2016 Red Hat, Inc.
20 #include "nm-default.h"
23 #include "nm-setting-bond.h"
24 #include "nm-connection.h"
25 #include "nm-simple-connection.h"
26 #include "nm-setting-connection.h"
27 #include "nm-errors.h"
29 #include "nm-test-utils.h"
32 create_bond_connection (NMConnection **con, NMSettingBond **s_bond)
34 NMSettingConnection *s_con;
39 *con = nmtst_create_minimal_connection ("bond",
41 NM_SETTING_BOND_SETTING_NAME,
46 g_object_set (s_con, NM_SETTING_CONNECTION_INTERFACE_NAME, "bond0", NULL);
48 *s_bond = (NMSettingBond *) nm_setting_bond_new ();
51 nm_connection_add_setting (*con, NM_SETTING (*s_bond));
54 #define test_verify_options(exp, ...) \
56 const char *__opts[] = { __VA_ARGS__ , NULL }; \
58 _test_verify_options (__opts, exp); \
62 _test_verify_options (const char **options, gboolean expected_result)
64 gs_unref_object NMConnection *con = NULL;
65 NMSettingBond *s_bond;
70 create_bond_connection (&con, &s_bond);
72 for (option = options; option[0] && option[1]; option += 2)
73 g_assert (nm_setting_bond_add_option (s_bond, option[0], option[1]));
75 if (expected_result) {
76 nmtst_assert_connection_verifies_and_normalizable (con);
77 nmtst_connection_normalize (con);
78 success = nm_setting_verify ((NMSetting *) s_bond, con, &error);
79 nmtst_assert_success (success, error);
81 nmtst_assert_connection_unnormalizable (con,
83 NM_CONNECTION_ERROR_INVALID_PROPERTY);
90 test_verify_options (TRUE,
93 test_verify_options (FALSE,
94 /* arp_interval not supported in balance-alb mode */
95 "mode", "balance-alb",
97 "arp_ip_target", "1.2.3.4");
98 test_verify_options (FALSE,
99 /* arp_ip_target requires arp_interval */
100 "mode", "balance-rr",
101 "arp_ip_target", "1.2.3.4");
102 test_verify_options (TRUE,
103 "mode", "balance-rr",
105 "arp_ip_target", "1.2.3.4");
106 test_verify_options (FALSE,
107 /* num_grat_arp, num_unsol_na cannot be different */
108 "mode", "balance-rr",
110 "num_unsol_na", "4");
111 test_verify_options (TRUE,
112 "mode", "balance-rr",
114 "num_unsol_na", "5");
115 test_verify_options (TRUE,
116 "mode", "active-backup",
118 test_verify_options (FALSE,
119 /* primary requires mode=active-backup */
122 test_verify_options (TRUE,
124 "lacp_rate", "fast");
125 test_verify_options (FALSE,
126 /* lacp_rate=fast requires mode=802.3ad */
127 "mode", "balance-rr",
128 "lacp_rate", "fast");
129 test_verify_options (TRUE,
131 "ad_actor_system", "ae:00:11:33:44:55");
135 test_compare_options (gboolean exp_res, const char **opts1, const char **opts2)
137 gs_unref_object NMSettingBond *s_bond1 = NULL, *s_bond2 = NULL;
140 s_bond1 = (NMSettingBond *) nm_setting_bond_new ();
142 s_bond2 = (NMSettingBond *) nm_setting_bond_new ();
145 for (p = opts1; p[0] && p[1]; p += 2)
146 g_assert (nm_setting_bond_add_option (s_bond1, p[0], p[1]));
148 for (p = opts2; p[0] && p[1]; p += 2)
149 g_assert (nm_setting_bond_add_option (s_bond2, p[0], p[1]));
151 g_assert_cmpint (nm_setting_compare ((NMSetting *) s_bond1,
152 (NMSetting *) s_bond2,
153 NM_SETTING_COMPARE_FLAG_EXACT),
161 test_compare_options (TRUE,
162 ((const char *[]){ "mode", "balance-rr", "miimon", "1", NULL }),
163 ((const char *[]){ "mode", "balance-rr", "miimon", "1", NULL }));
164 test_compare_options (FALSE,
165 ((const char *[]){ "mode", "balance-rr", "miimon", "1", NULL }),
166 ((const char *[]){ "mode", "balance-rr", "miimon", "2", NULL }));
168 /* ignore default values */
169 test_compare_options (TRUE,
170 ((const char *[]){ "miimon", "1", NULL }),
171 ((const char *[]){ "miimon", "1", "updelay", "0", NULL }));
173 /* special handling of num_grat_arp, num_unsol_na */
174 test_compare_options (FALSE,
175 ((const char *[]){ "num_grat_arp", "2", NULL }),
176 ((const char *[]){ "num_grat_arp", "1", NULL }));
177 test_compare_options (TRUE,
178 ((const char *[]){ "num_grat_arp", "3", NULL }),
179 ((const char *[]){ "num_unsol_na", "3", NULL }));
180 test_compare_options (TRUE,
181 ((const char *[]){ "num_grat_arp", "4", NULL }),
182 ((const char *[]){ "num_unsol_na", "4", "num_grat_arp", "4", NULL }));
185 #define TPATH "/libnm/settings/bond/"
190 main (int argc, char **argv)
192 nmtst_init (&argc, &argv, TRUE);
194 g_test_add_func (TPATH "verify", test_verify);
195 g_test_add_func (TPATH "compare", test_compare);
197 return g_test_run ();