summaryrefslogtreecommitdiff
path: root/src/tests/test-dcb.c
blob: 0a0924423e7308cd53ce2990ec8e43e04a037635 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/* -*- 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-dcb.h"

typedef struct {
	guint num;
	const char *cmds[];
} DcbExpected;

static gboolean
test_dcb_func (char **argv, guint which, gpointer user_data, GError **error)
{
	DcbExpected *e = user_data;
	char *f;

	g_assert (argv[0] == NULL);
	argv[0] = (which == DCBTOOL) ? "dcbtool" : "fcoeadm";

	f = g_strjoinv (" ", argv);
	if (e->cmds[e->num] == NULL)
		g_assert_cmpstr (f, ==, NULL);
	g_assert_cmpstr (e->cmds[e->num], !=, NULL);
	g_assert_cmpstr (f, ==, e->cmds[e->num++]);
	g_free (f);
	return TRUE;
}

#define DCB_FLAGS_ALL (NM_SETTING_DCB_FLAG_ENABLE | \
                       NM_SETTING_DCB_FLAG_ADVERTISE | \
                       NM_SETTING_DCB_FLAG_WILLING)

static void
test_dcb_fcoe (void)
{
	static DcbExpected expected = { 0,
		{ "dcbtool sc eth0 dcb on",
		  "dcbtool sc eth0 app:fcoe e:1 a:1 w:1",
		  "dcbtool sc eth0 app:fcoe appcfg:40",
		  "dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
		  "dcbtool sc eth0 app:fip e:0 a:0 w:0",
		  "dcbtool sc eth0 pfc e:0 a:0 w:0",
		  "dcbtool sc eth0 pg e:0 a:0 w:0",
		  NULL },
	};
	NMSettingDcb *s_dcb;
	GError *error = NULL;
	gboolean success;

	s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
	g_object_set (G_OBJECT (s_dcb),
	              NM_SETTING_DCB_APP_FCOE_FLAGS, DCB_FLAGS_ALL,
	              NM_SETTING_DCB_APP_FCOE_PRIORITY, 6,
	              NULL);

	success = _dcb_setup ("eth0", s_dcb, test_dcb_func, &expected, &error);
	g_assert_no_error (error);
	g_assert (success);

	g_assert_cmpstr (expected.cmds[expected.num], ==, NULL);
	g_object_unref (s_dcb);
}

static void
test_dcb_iscsi (void)
{
	static DcbExpected expected = { 0,
		{ "dcbtool sc eth0 dcb on",
		  "dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
		  "dcbtool sc eth0 app:iscsi e:1 a:0 w:1",
		  "dcbtool sc eth0 app:iscsi appcfg:08",
		  "dcbtool sc eth0 app:fip e:0 a:0 w:0",
		  "dcbtool sc eth0 pfc e:0 a:0 w:0",
		  "dcbtool sc eth0 pg e:0 a:0 w:0",
		  NULL },
	};
	NMSettingDcb *s_dcb;
	GError *error = NULL;
	gboolean success;

	s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
	g_object_set (G_OBJECT (s_dcb),
	              NM_SETTING_DCB_APP_ISCSI_FLAGS, (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_WILLING),
	              NM_SETTING_DCB_APP_ISCSI_PRIORITY, 3,
	              NULL);

	success = _dcb_setup ("eth0", s_dcb, test_dcb_func, &expected, &error);
	g_assert_no_error (error);
	g_assert (success);

	g_assert_cmpstr (expected.cmds[expected.num], ==, NULL);
	g_object_unref (s_dcb);
}

static void
test_dcb_fip (void)
{
	static DcbExpected expected = { 0,
		{ "dcbtool sc eth0 dcb on",
		  "dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
		  "dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
		  "dcbtool sc eth0 app:fip e:1 a:1 w:0",
		  "dcbtool sc eth0 app:fip appcfg:01",
		  "dcbtool sc eth0 pfc e:0 a:0 w:0",
		  "dcbtool sc eth0 pg e:0 a:0 w:0",
		  NULL },
	};
	NMSettingDcb *s_dcb;
	GError *error = NULL;
	gboolean success;

	s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
	g_object_set (G_OBJECT (s_dcb),
	              NM_SETTING_DCB_APP_FIP_FLAGS, (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE),
	              NM_SETTING_DCB_APP_FIP_PRIORITY, 0,
	              NULL);

	success = _dcb_setup ("eth0", s_dcb, test_dcb_func, &expected, &error);
	g_assert_no_error (error);
	g_assert (success);

	g_assert_cmpstr (expected.cmds[expected.num], ==, NULL);
	g_object_unref (s_dcb);
}

static void
test_dcb_fip_default_prio (void)
{
	static DcbExpected expected = { 0,
		{ "dcbtool sc eth0 dcb on",
		  "dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
		  "dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
		  "dcbtool sc eth0 app:fip e:1 a:1 w:0",
		  "dcbtool sc eth0 pfc e:0 a:0 w:0",
		  "dcbtool sc eth0 pg e:0 a:0 w:0",
		  NULL },
	};
	NMSettingDcb *s_dcb;
	GError *error = NULL;
	gboolean success;

	s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
	g_object_set (G_OBJECT (s_dcb),
	              NM_SETTING_DCB_APP_FIP_FLAGS, (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE),
	              NM_SETTING_DCB_APP_FIP_PRIORITY, -1,
	              NULL);

	success = _dcb_setup ("eth0", s_dcb, test_dcb_func, &expected, &error);
	g_assert_no_error (error);
	g_assert (success);

	g_assert_cmpstr (expected.cmds[expected.num], ==, NULL);
	g_object_unref (s_dcb);
}

static void
test_dcb_pfc (void)
{
	static DcbExpected expected = { 0,
		{ "dcbtool sc eth0 dcb on",
		  "dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
		  "dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
		  "dcbtool sc eth0 app:fip e:0 a:0 w:0",
		  "dcbtool sc eth0 pfc e:1 a:1 w:1",
		  "dcbtool sc eth0 pfc pfcup:01101100",
		  "dcbtool sc eth0 pg e:0 a:0 w:0",
		  NULL },
	};
	NMSettingDcb *s_dcb;
	GError *error = NULL;
	gboolean success;

	s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
	g_object_set (G_OBJECT (s_dcb),
	              NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, DCB_FLAGS_ALL,
	              NULL);

	nm_setting_dcb_set_priority_flow_control (s_dcb, 0, FALSE);
	nm_setting_dcb_set_priority_flow_control (s_dcb, 1, TRUE);
	nm_setting_dcb_set_priority_flow_control (s_dcb, 2, TRUE);
	nm_setting_dcb_set_priority_flow_control (s_dcb, 3, FALSE);
	nm_setting_dcb_set_priority_flow_control (s_dcb, 4, TRUE);
	nm_setting_dcb_set_priority_flow_control (s_dcb, 5, TRUE);
	nm_setting_dcb_set_priority_flow_control (s_dcb, 6, FALSE);
	nm_setting_dcb_set_priority_flow_control (s_dcb, 7, FALSE);

	success = _dcb_setup ("eth0", s_dcb, test_dcb_func, &expected, &error);
	g_assert_no_error (error);
	g_assert (success);

	g_assert_cmpstr (expected.cmds[expected.num], ==, NULL);
	g_object_unref (s_dcb);
}

static void
test_dcb_priority_groups (void)
{
	static DcbExpected expected = { 0,
		{ "dcbtool sc eth0 dcb on",
		  "dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
		  "dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
		  "dcbtool sc eth0 app:fip e:0 a:0 w:0",
		  "dcbtool sc eth0 pfc e:0 a:0 w:0",
		  "dcbtool sc eth0 pg e:1 a:1 w:1",
		  "dcbtool sc eth0 pg pgid:765f3210",
		  "dcbtool sc eth0 pg pgpct:10,40,5,10,5,20,7,3",
		  "dcbtool sc eth0 pg uppct:100,50,33,25,20,16,14,12",
		  "dcbtool sc eth0 pg strict:01010101",
		  "dcbtool sc eth0 pg up2tc:01201201",
		  NULL },
	};
	NMSettingDcb *s_dcb;
	GError *error = NULL;
	gboolean success;
	guint i;

	s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
	g_object_set (G_OBJECT (s_dcb),
	              NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, DCB_FLAGS_ALL,
	              NULL);

	for (i = 0; i < 8; i++) {
		/* Make sure at least one 15/f is present in the group IDs */
		nm_setting_dcb_set_priority_group_id (s_dcb, i, (i == 3) ? 15 : 7 - i);
		nm_setting_dcb_set_priority_bandwidth (s_dcb, i, 100 / (i + 1));
		nm_setting_dcb_set_priority_strict_bandwidth (s_dcb, i, i % 2);
		nm_setting_dcb_set_priority_traffic_class (s_dcb, i, i % 3);
	}

	nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 0, 10);
	nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 1, 40);
	nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 2, 5);
	nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 3, 10);
	nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 4, 5);
	nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 5, 20);
	nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 6, 7);
	nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 7, 3);

	success = _dcb_setup ("eth0", s_dcb, test_dcb_func, &expected, &error);
	g_assert_no_error (error);
	g_assert (success);

	g_assert_cmpstr (expected.cmds[expected.num], ==, NULL);
	g_object_unref (s_dcb);
}

static void
test_dcb_cleanup (void)
{
	static DcbExpected expected = { 0,
		{ "dcbtool sc eth0 dcb off", NULL },
	};
	GError *error = NULL;
	gboolean success;

	success = _dcb_cleanup ("eth0", test_dcb_func, &expected, &error);
	g_assert_no_error (error);
	g_assert (success);
}

static void
test_fcoe_create (void)
{
	static DcbExpected expected1 = { 0,
		{ "fcoeadm -m fabric -c eth0", NULL },
	};
	static DcbExpected expected2 = { 0,
		{ "fcoeadm -m vn2vn -c eth0", NULL },
	};
	GError *error = NULL;
	gboolean success;
	NMSettingDcb *s_dcb;

	s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
	g_object_set (G_OBJECT (s_dcb),
	              NM_SETTING_DCB_APP_FCOE_FLAGS, DCB_FLAGS_ALL,
	              NULL);

	/* Default mode is fabric */
	success = _fcoe_setup ("eth0", s_dcb, test_dcb_func, &expected1, &error);
	g_assert_no_error (error);
	g_assert (success);

	/* Test VN2VN */
	g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_FCOE_MODE, NM_SETTING_DCB_FCOE_MODE_VN2VN, NULL);
	success = _fcoe_setup ("eth0", s_dcb, test_dcb_func, &expected2, &error);
	g_assert_no_error (error);
	g_assert (success);

	g_object_unref (s_dcb);
}

static void
test_fcoe_cleanup (void)
{
	static DcbExpected expected = { 0,
		{ "fcoeadm -d eth0", NULL },
	};
	GError *error = NULL;
	gboolean success;

	success = _fcoe_cleanup ("eth0", test_dcb_func, &expected, &error);
	g_assert_no_error (error);
	g_assert (success);
}

/*******************************************/

int
main (int argc, char **argv)
{
	g_test_init (&argc, &argv, NULL);

	g_type_init ();

	g_test_add_func ("/dcb/fcoe", test_dcb_fcoe);
	g_test_add_func ("/dcb/iscsi", test_dcb_iscsi);
	g_test_add_func ("/dcb/fip", test_dcb_fip);
	g_test_add_func ("/dcb/fip-default-priority", test_dcb_fip_default_prio);
	g_test_add_func ("/dcb/pfc", test_dcb_pfc);
	g_test_add_func ("/dcb/priority-groups", test_dcb_priority_groups);
	g_test_add_func ("/dcb/cleanup", test_dcb_cleanup);
	g_test_add_func ("/fcoe/create", test_fcoe_create);
	g_test_add_func ("/fcoe/cleanup", test_fcoe_cleanup);

	return g_test_run ();
}