Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018 Vladimir Medvedkin <medvedkinv@gmail.com>
3 : : * Copyright(c) 2019 Intel Corporation
4 : : */
5 : :
6 : : #include <stdio.h>
7 : : #include <stdint.h>
8 : : #include <stdlib.h>
9 : :
10 : : #include <rte_memory.h>
11 : : #include <rte_log.h>
12 : : #include <rte_rib6.h>
13 : : #include <rte_fib6.h>
14 : : #include <rte_malloc.h>
15 : :
16 : : #include "test.h"
17 : :
18 : : typedef int32_t (*rte_fib6_test)(void);
19 : :
20 : : static int32_t test_create_invalid(void);
21 : : static int32_t test_multiple_create(void);
22 : : static int32_t test_free_null(void);
23 : : static int32_t test_add_del_invalid(void);
24 : : static int32_t test_get_invalid(void);
25 : : static int32_t test_lookup(void);
26 : : static int32_t test_wraparound(void);
27 : : static int32_t test_invalid_rcu(void);
28 : : static int32_t test_fib_rcu_sync_rw(void);
29 : : static int32_t test_drift(void);
30 : : static int32_t test_drift_compression(void);
31 : : static int32_t test_drift_multilevel(void);
32 : : static int32_t test_drift_stress(void);
33 : : static int32_t test_drift_tight_pool(void);
34 : : static int32_t test_tbl8_install_peak(void);
35 : : static int32_t test_tbl8_install_peak_dq(void);
36 : : static int32_t test_tbl8_dq_modify(void);
37 : :
38 : : #define MAX_ROUTES (1 << 16)
39 : : /** Maximum number of tbl8 for 2-byte entries */
40 : : #define MAX_TBL8 (1 << 15)
41 : :
42 : : /*
43 : : * Check that rte_fib6_create fails gracefully for incorrect user input
44 : : * arguments
45 : : */
46 : : int32_t
47 : 1 : test_create_invalid(void)
48 : : {
49 : : struct rte_fib6 *fib = NULL;
50 : : struct rte_fib6_conf config;
51 : :
52 : 1 : config.max_routes = MAX_ROUTES;
53 : 1 : config.rib_ext_sz = 0;
54 : 1 : config.default_nh = 0;
55 : 1 : config.type = RTE_FIB6_DUMMY;
56 : :
57 : : /* rte_fib6_create: fib name == NULL */
58 : 1 : fib = rte_fib6_create(NULL, SOCKET_ID_ANY, &config);
59 [ - + ]: 1 : RTE_TEST_ASSERT(fib == NULL,
60 : : "Call succeeded with invalid parameters\n");
61 : :
62 : : /* rte_fib6_create: config == NULL */
63 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, NULL);
64 [ - + ]: 1 : RTE_TEST_ASSERT(fib == NULL,
65 : : "Call succeeded with invalid parameters\n");
66 : :
67 : : /* socket_id < -1 is invalid */
68 : 1 : fib = rte_fib6_create(__func__, -2, &config);
69 [ - + ]: 1 : RTE_TEST_ASSERT(fib == NULL,
70 : : "Call succeeded with invalid parameters\n");
71 : :
72 : : /* rte_fib6_create: max_routes = 0 */
73 : 1 : config.max_routes = 0;
74 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
75 [ - + ]: 1 : RTE_TEST_ASSERT(fib == NULL,
76 : : "Call succeeded with invalid parameters\n");
77 : 1 : config.max_routes = MAX_ROUTES;
78 : :
79 : 1 : config.type = RTE_FIB6_TRIE + 1;
80 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
81 [ - + ]: 1 : RTE_TEST_ASSERT(fib == NULL,
82 : : "Call succeeded with invalid parameters\n");
83 : :
84 : 1 : config.type = RTE_FIB6_TRIE;
85 : 1 : config.trie.num_tbl8 = MAX_TBL8;
86 : :
87 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_8B + 1;
88 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
89 [ - + ]: 1 : RTE_TEST_ASSERT(fib == NULL,
90 : : "Call succeeded with invalid parameters\n");
91 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_8B;
92 : :
93 : 1 : config.trie.num_tbl8 = 0;
94 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
95 [ - + ]: 1 : RTE_TEST_ASSERT(fib == NULL,
96 : : "Call succeeded with invalid parameters\n");
97 : :
98 : : return TEST_SUCCESS;
99 : : }
100 : :
101 : : /*
102 : : * Create fib table then delete fib table 10 times
103 : : * Use a slightly different rules size each time
104 : : */
105 : : int32_t
106 : 0 : test_multiple_create(void)
107 : : {
108 : : struct rte_fib6 *fib = NULL;
109 : : struct rte_fib6_conf config;
110 : : int32_t i;
111 : :
112 : 0 : config.rib_ext_sz = 0;
113 : 0 : config.default_nh = 0;
114 : 0 : config.type = RTE_FIB6_DUMMY;
115 : :
116 [ # # ]: 0 : for (i = 0; i < 100; i++) {
117 : 0 : config.max_routes = MAX_ROUTES - i;
118 : 0 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
119 [ # # ]: 0 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
120 : 0 : rte_fib6_free(fib);
121 : : }
122 : : /* Can not test free so return success */
123 : : return TEST_SUCCESS;
124 : : }
125 : :
126 : : /*
127 : : * Call rte_fib6_free for NULL pointer user input. Note: free has no return and
128 : : * therefore it is impossible to check for failure but this test is added to
129 : : * increase function coverage metrics and to validate that freeing null does
130 : : * not crash.
131 : : */
132 : : int32_t
133 : 1 : test_free_null(void)
134 : : {
135 : : struct rte_fib6 *fib = NULL;
136 : : struct rte_fib6_conf config;
137 : :
138 : 1 : config.max_routes = MAX_ROUTES;
139 : 1 : config.rib_ext_sz = 0;
140 : 1 : config.default_nh = 0;
141 : 1 : config.type = RTE_FIB6_DUMMY;
142 : :
143 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
144 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
145 : :
146 : 1 : rte_fib6_free(fib);
147 : 1 : rte_fib6_free(NULL);
148 : :
149 : 1 : return TEST_SUCCESS;
150 : : }
151 : :
152 : : /*
153 : : * Check that rte_fib6_add and rte_fib6_delete fails gracefully
154 : : * for incorrect user input arguments
155 : : */
156 : : int32_t
157 : 1 : test_add_del_invalid(void)
158 : : {
159 : : struct rte_fib6 *fib = NULL;
160 : : struct rte_fib6_conf config;
161 : : uint64_t nh = 100;
162 : 1 : struct rte_ipv6_addr ip = RTE_IPV6_ADDR_UNSPEC;
163 : : int ret;
164 : : uint8_t depth = 24;
165 : :
166 : 1 : config.max_routes = MAX_ROUTES;
167 : 1 : config.rib_ext_sz = 0;
168 : 1 : config.default_nh = 0;
169 : 1 : config.type = RTE_FIB6_DUMMY;
170 : :
171 : : /* rte_fib6_add: fib == NULL */
172 : 1 : ret = rte_fib6_add(NULL, &ip, depth, nh);
173 [ - + ]: 1 : RTE_TEST_ASSERT(ret < 0,
174 : : "Call succeeded with invalid parameters\n");
175 : :
176 : : /* rte_fib6_delete: fib == NULL */
177 : 1 : ret = rte_fib6_delete(NULL, &ip, depth);
178 [ - + ]: 1 : RTE_TEST_ASSERT(ret < 0,
179 : : "Call succeeded with invalid parameters\n");
180 : :
181 : : /*Create valid fib to use in rest of test. */
182 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
183 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
184 : :
185 : : /* rte_fib6_add: depth > RTE_IPV6_MAX_DEPTH */
186 : 1 : ret = rte_fib6_add(fib, &ip, RTE_IPV6_MAX_DEPTH + 1, nh);
187 [ - + ]: 1 : RTE_TEST_ASSERT(ret < 0,
188 : : "Call succeeded with invalid parameters\n");
189 : :
190 : : /* rte_fib6_delete: depth > RTE_IPV6_MAX_DEPTH */
191 : 1 : ret = rte_fib6_delete(fib, &ip, RTE_IPV6_MAX_DEPTH + 1);
192 [ - + ]: 1 : RTE_TEST_ASSERT(ret < 0,
193 : : "Call succeeded with invalid parameters\n");
194 : :
195 : 1 : rte_fib6_free(fib);
196 : :
197 : 1 : return TEST_SUCCESS;
198 : : }
199 : :
200 : : /*
201 : : * Check that rte_fib6_get_dp and rte_fib6_get_rib fails gracefully
202 : : * for incorrect user input arguments
203 : : */
204 : : int32_t
205 : 1 : test_get_invalid(void)
206 : : {
207 : : void *p;
208 : :
209 : 1 : p = rte_fib6_get_dp(NULL);
210 [ - + ]: 1 : RTE_TEST_ASSERT(p == NULL,
211 : : "Call succeeded with invalid parameters\n");
212 : :
213 : 1 : p = rte_fib6_get_rib(NULL);
214 [ - + ]: 1 : RTE_TEST_ASSERT(p == NULL,
215 : : "Call succeeded with invalid parameters\n");
216 : :
217 : : return TEST_SUCCESS;
218 : : }
219 : :
220 : : /*
221 : : * Add routes for one supernet with all possible depths and do lookup
222 : : * on each step
223 : : * After delete routes with doing lookup on each step
224 : : */
225 : : static int
226 : 1020 : lookup_and_check_asc(struct rte_fib6 *fib,
227 : : struct rte_ipv6_addr *ip_arr,
228 : : struct rte_ipv6_addr *ip_missing, uint64_t def_nh,
229 : : uint32_t n)
230 : : {
231 : : uint64_t nh_arr[RTE_IPV6_MAX_DEPTH];
232 : : int ret;
233 : : uint32_t i = 0;
234 : :
235 : 1020 : ret = rte_fib6_lookup_bulk(fib, ip_arr, nh_arr, RTE_IPV6_MAX_DEPTH);
236 [ - + ]: 1020 : RTE_TEST_ASSERT(ret == 0, "Failed to lookup\n");
237 : :
238 [ + + ]: 67064 : for (; i <= RTE_IPV6_MAX_DEPTH - n; i++)
239 [ - + ]: 66044 : RTE_TEST_ASSERT(nh_arr[i] == n,
240 : : "Failed to get proper nexthop\n");
241 : :
242 [ + + ]: 65536 : for (; i < RTE_IPV6_MAX_DEPTH; i++)
243 [ - + ]: 64516 : RTE_TEST_ASSERT(nh_arr[i] == --n,
244 : : "Failed to get proper nexthop\n");
245 : :
246 : 1020 : ret = rte_fib6_lookup_bulk(fib, ip_missing, nh_arr, 1);
247 [ + - - + ]: 1020 : RTE_TEST_ASSERT((ret == 0) && (nh_arr[0] == def_nh),
248 : : "Failed to get proper nexthop\n");
249 : :
250 : : return TEST_SUCCESS;
251 : : }
252 : :
253 : : static int
254 : 1032 : lookup_and_check_desc(struct rte_fib6 *fib,
255 : : struct rte_ipv6_addr *ip_arr,
256 : : struct rte_ipv6_addr *ip_missing, uint64_t def_nh,
257 : : uint32_t n)
258 : : {
259 : : uint64_t nh_arr[RTE_IPV6_MAX_DEPTH];
260 : : int ret;
261 : : uint32_t i = 0;
262 : :
263 : 1032 : ret = rte_fib6_lookup_bulk(fib, ip_arr, nh_arr, RTE_IPV6_MAX_DEPTH);
264 [ - + ]: 1032 : RTE_TEST_ASSERT(ret == 0, "Failed to lookup\n");
265 : :
266 [ + + ]: 66568 : for (; i < n; i++)
267 [ - + ]: 65536 : RTE_TEST_ASSERT(nh_arr[i] == RTE_IPV6_MAX_DEPTH - i,
268 : : "Failed to get proper nexthop\n");
269 : :
270 [ + + ]: 67592 : for (; i < RTE_IPV6_MAX_DEPTH; i++)
271 [ - + ]: 66560 : RTE_TEST_ASSERT(nh_arr[i] == def_nh,
272 : : "Failed to get proper nexthop\n");
273 : :
274 : 1032 : ret = rte_fib6_lookup_bulk(fib, ip_missing, nh_arr, 1);
275 [ + - - + ]: 1032 : RTE_TEST_ASSERT((ret == 0) && (nh_arr[0] == def_nh),
276 : : "Failed to get proper nexthop\n");
277 : :
278 : : return TEST_SUCCESS;
279 : : }
280 : :
281 : : static int
282 : 4 : check_fib(struct rte_fib6 *fib)
283 : : {
284 : : uint64_t def_nh = 100;
285 : : struct rte_ipv6_addr ip_arr[RTE_IPV6_MAX_DEPTH];
286 : 4 : struct rte_ipv6_addr ip_add = RTE_IPV6(0x8000, 0, 0, 0, 0, 0, 0, 0);
287 : 4 : struct rte_ipv6_addr ip_missing =
288 : : RTE_IPV6(0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff);
289 : : uint32_t i, j;
290 : : int ret;
291 : :
292 [ + + ]: 516 : for (i = 0; i < RTE_IPV6_MAX_DEPTH; i++) {
293 : 512 : ip_arr[i] = ip_add;
294 : 512 : j = (RTE_IPV6_MAX_DEPTH - i) / CHAR_BIT;
295 [ + + ]: 512 : if (j < RTE_IPV6_ADDR_SIZE) {
296 : 508 : ip_arr[i].a[j] |= UINT8_MAX >> ((RTE_IPV6_MAX_DEPTH - i) % CHAR_BIT);
297 [ + + ]: 4288 : for (j++; j < RTE_IPV6_ADDR_SIZE; j++)
298 : 3780 : ip_arr[i].a[j] = 0xff;
299 : : }
300 : : }
301 : :
302 : 4 : ret = lookup_and_check_desc(fib, ip_arr, &ip_missing, def_nh, 0);
303 [ - + ]: 4 : RTE_TEST_ASSERT(ret == TEST_SUCCESS, "Lookup and check fails\n");
304 : :
305 [ + + ]: 516 : for (i = 1; i <= RTE_IPV6_MAX_DEPTH; i++) {
306 : 512 : ret = rte_fib6_add(fib, &ip_add, i, i);
307 [ - + ]: 512 : RTE_TEST_ASSERT(ret == 0, "Failed to add a route\n");
308 : 512 : ret = lookup_and_check_asc(fib, ip_arr, &ip_missing, def_nh, i);
309 [ - + ]: 512 : RTE_TEST_ASSERT(ret == TEST_SUCCESS,
310 : : "Lookup and check fails\n");
311 : : }
312 : :
313 [ + + ]: 512 : for (i = RTE_IPV6_MAX_DEPTH; i > 1; i--) {
314 : 508 : ret = rte_fib6_delete(fib, &ip_add, i);
315 [ - + ]: 508 : RTE_TEST_ASSERT(ret == 0, "Failed to delete a route\n");
316 : 508 : ret = lookup_and_check_asc(fib, ip_arr, &ip_missing,
317 : : def_nh, i - 1);
318 : :
319 [ - + ]: 508 : RTE_TEST_ASSERT(ret == TEST_SUCCESS,
320 : : "Lookup and check fails\n");
321 : : }
322 : 4 : ret = rte_fib6_delete(fib, &ip_add, i);
323 [ - + ]: 4 : RTE_TEST_ASSERT(ret == 0, "Failed to delete a route\n");
324 : 4 : ret = lookup_and_check_desc(fib, ip_arr, &ip_missing, def_nh, 0);
325 [ - + ]: 4 : RTE_TEST_ASSERT(ret == TEST_SUCCESS,
326 : : "Lookup and check fails\n");
327 : :
328 [ + + ]: 516 : for (i = 0; i < RTE_IPV6_MAX_DEPTH; i++) {
329 : 512 : ret = rte_fib6_add(fib, &ip_add, RTE_IPV6_MAX_DEPTH - i,
330 : 512 : RTE_IPV6_MAX_DEPTH - i);
331 [ - + ]: 512 : RTE_TEST_ASSERT(ret == 0, "Failed to add a route\n");
332 : 512 : ret = lookup_and_check_desc(fib, ip_arr, &ip_missing,
333 : : def_nh, i + 1);
334 [ - + ]: 512 : RTE_TEST_ASSERT(ret == TEST_SUCCESS,
335 : : "Lookup and check fails\n");
336 : : }
337 : :
338 [ + + ]: 516 : for (i = 1; i <= RTE_IPV6_MAX_DEPTH; i++) {
339 : 512 : ret = rte_fib6_delete(fib, &ip_add, i);
340 [ - + ]: 512 : RTE_TEST_ASSERT(ret == 0, "Failed to delete a route\n");
341 : 512 : ret = lookup_and_check_desc(fib, ip_arr, &ip_missing, def_nh,
342 : : RTE_IPV6_MAX_DEPTH - i);
343 [ - + ]: 512 : RTE_TEST_ASSERT(ret == TEST_SUCCESS,
344 : : "Lookup and check fails\n");
345 : : }
346 : :
347 : : return TEST_SUCCESS;
348 : : }
349 : :
350 : : int32_t
351 : 1 : test_lookup(void)
352 : : {
353 : : struct rte_fib6 *fib = NULL;
354 : : struct rte_fib6_conf config;
355 : : uint64_t def_nh = 100;
356 : : int ret;
357 : :
358 : 1 : config.max_routes = MAX_ROUTES;
359 : 1 : config.rib_ext_sz = 0;
360 : 1 : config.default_nh = def_nh;
361 : 1 : config.type = RTE_FIB6_DUMMY;
362 : :
363 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
364 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
365 : 1 : ret = check_fib(fib);
366 [ - + ]: 1 : RTE_TEST_ASSERT(ret == TEST_SUCCESS,
367 : : "Check_fib fails for DUMMY type\n");
368 : 1 : rte_fib6_free(fib);
369 : :
370 : 1 : config.type = RTE_FIB6_TRIE;
371 : :
372 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_2B;
373 : 1 : config.trie.num_tbl8 = MAX_TBL8 - 1;
374 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
375 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
376 : 1 : ret = check_fib(fib);
377 [ - + ]: 1 : RTE_TEST_ASSERT(ret == TEST_SUCCESS,
378 : : "Check_fib fails for TRIE_2B type\n");
379 : 1 : rte_fib6_free(fib);
380 : :
381 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_4B;
382 : 1 : config.trie.num_tbl8 = MAX_TBL8;
383 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
384 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
385 : 1 : ret = check_fib(fib);
386 [ - + ]: 1 : RTE_TEST_ASSERT(ret == TEST_SUCCESS,
387 : : "Check_fib fails for TRIE_4B type\n");
388 : 1 : rte_fib6_free(fib);
389 : :
390 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_8B;
391 : 1 : config.trie.num_tbl8 = MAX_TBL8;
392 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
393 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
394 : 1 : ret = check_fib(fib);
395 [ - + ]: 1 : RTE_TEST_ASSERT(ret == TEST_SUCCESS,
396 : : "Check_fib fails for TRIE_8B type\n");
397 : 1 : rte_fib6_free(fib);
398 : :
399 : 1 : return TEST_SUCCESS;
400 : : }
401 : :
402 : : /*
403 : : * Reproducer for the address wraparound bug in modify_dp(). When the
404 : : * more-specific routes under a modified prefix cover its range up to
405 : : * ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff, and the last of them starts
406 : : * exactly at the current left edge, the left edge wraps to :: and the
407 : : * entire table must not be overwritten.
408 : : *
409 : : * Case A: ADD ::/0, ::/1 and 8000::/1, then DEL ::/0. Both /1
410 : : * routes must still resolve.
411 : : * Case B: ADD 2001:db8::/32, ffff:...:ff00/121 and
412 : : * ffff:...:ff80/121, then ADD their covering
413 : : * ffff:...:ff00/120. No lookup result may change.
414 : : */
415 : : static int32_t
416 : 1 : test_wraparound(void)
417 : : {
418 : 1 : struct rte_fib6_conf config = { 0 };
419 : : struct rte_fib6 *fib;
420 : 1 : const struct rte_ipv6_addr zero = RTE_IPV6(0, 0, 0, 0, 0, 0, 0, 0);
421 : 1 : const struct rte_ipv6_addr high = RTE_IPV6(0x8000, 0, 0, 0, 0, 0, 0, 0);
422 : 1 : const struct rte_ipv6_addr net = RTE_IPV6(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0);
423 : 1 : const struct rte_ipv6_addr top00 = RTE_IPV6(0xffff, 0xffff, 0xffff,
424 : : 0xffff, 0xffff, 0xffff, 0xffff, 0xff00);
425 : 1 : const struct rte_ipv6_addr top80 = RTE_IPV6(0xffff, 0xffff, 0xffff,
426 : : 0xffff, 0xffff, 0xffff, 0xffff, 0xff80);
427 : : uint64_t def_nh = 100;
428 : : struct rte_ipv6_addr ip[4];
429 : : uint64_t nh[4];
430 : : int ret;
431 : :
432 : 1 : config.max_routes = 1024;
433 : : config.rib_ext_sz = 0;
434 : 1 : config.default_nh = def_nh;
435 : 1 : config.type = RTE_FIB6_TRIE;
436 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_4B;
437 : 1 : config.trie.num_tbl8 = 256;
438 : :
439 : : /* Case A */
440 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
441 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
442 : :
443 : 1 : ret = rte_fib6_add(fib, &zero, 0, 1);
444 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "ADD ::/0 failed (ret=%d)\n", ret);
445 : 1 : ret = rte_fib6_add(fib, &zero, 1, 2);
446 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "ADD ::/1 failed (ret=%d)\n", ret);
447 : 1 : ret = rte_fib6_add(fib, &high, 1, 3);
448 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "ADD 8000::/1 failed (ret=%d)\n", ret);
449 : :
450 : 1 : ret = rte_fib6_delete(fib, &zero, 0);
451 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "DEL ::/0 failed (ret=%d)\n", ret);
452 : :
453 : 1 : ip[0] = (struct rte_ipv6_addr)RTE_IPV6(0, 0, 0, 0, 0, 0, 0, 1);
454 : 1 : ip[1] = (struct rte_ipv6_addr)RTE_IPV6(0xffff, 0, 0, 0, 0, 0, 0, 1);
455 : 1 : ret = rte_fib6_lookup_bulk(fib, ip, nh, 2);
456 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "Lookup failed (ret=%d)\n", ret);
457 [ - + ]: 1 : RTE_TEST_ASSERT(nh[0] == 2,
458 : : "::1: got nh %" PRIu64 ", want 2\n", nh[0]);
459 [ - + ]: 1 : RTE_TEST_ASSERT(nh[1] == 3,
460 : : "ffff::1: got nh %" PRIu64 ", want 3\n", nh[1]);
461 : :
462 : 1 : rte_fib6_free(fib);
463 : :
464 : : /* Case B */
465 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
466 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
467 : :
468 : 1 : ret = rte_fib6_add(fib, &net, 32, 10);
469 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "ADD 2001:db8::/32 failed (ret=%d)\n", ret);
470 : 1 : ret = rte_fib6_add(fib, &top00, 121, 5);
471 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0,
472 : : "ADD ffff:...:ff00/121 failed (ret=%d)\n", ret);
473 : 1 : ret = rte_fib6_add(fib, &top80, 121, 6);
474 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0,
475 : : "ADD ffff:...:ff80/121 failed (ret=%d)\n", ret);
476 : :
477 : 1 : ret = rte_fib6_add(fib, &top00, 120, 7);
478 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0,
479 : : "ADD ffff:...:ff00/120 failed (ret=%d)\n", ret);
480 : :
481 : 1 : ip[0] = (struct rte_ipv6_addr)RTE_IPV6(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1);
482 : 1 : ip[1] = (struct rte_ipv6_addr)RTE_IPV6(0, 0, 0, 0, 0, 0, 0, 1);
483 : 1 : ip[2] = top00;
484 : 1 : ip[2].a[15] = 0x01;
485 : 1 : ip[3] = top80;
486 : 1 : ip[3].a[15] = 0x81;
487 : 1 : ret = rte_fib6_lookup_bulk(fib, ip, nh, 4);
488 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "Lookup failed (ret=%d)\n", ret);
489 [ - + ]: 1 : RTE_TEST_ASSERT(nh[0] == 10,
490 : : "2001:db8::1: got nh %" PRIu64 ", want 10\n", nh[0]);
491 [ - + ]: 1 : RTE_TEST_ASSERT(nh[1] == def_nh,
492 : : "::1: got nh %" PRIu64 ", want %" PRIu64 "\n",
493 : : nh[1], def_nh);
494 [ - + ]: 1 : RTE_TEST_ASSERT(nh[2] == 5,
495 : : "ffff:...:ff01: got nh %" PRIu64 ", want 5\n", nh[2]);
496 [ - + ]: 1 : RTE_TEST_ASSERT(nh[3] == 6,
497 : : "ffff:...:ff81: got nh %" PRIu64 ", want 6\n", nh[3]);
498 : :
499 : 1 : rte_fib6_free(fib);
500 : 1 : return TEST_SUCCESS;
501 : : }
502 : :
503 : : /*
504 : : * rte_fib6_rcu_qsbr_add positive and negative tests.
505 : : * - Add RCU QSBR variable to FIB
506 : : * - Add another RCU QSBR variable to FIB
507 : : * - Check returns
508 : : */
509 : : int32_t
510 : 1 : test_invalid_rcu(void)
511 : : {
512 : : struct rte_fib6 *fib = NULL;
513 : 1 : struct rte_fib6_conf config = { 0 };
514 : : size_t sz;
515 : : struct rte_rcu_qsbr *qsv;
516 : : struct rte_rcu_qsbr *qsv2;
517 : : int32_t status;
518 : 1 : struct rte_fib6_rcu_config rcu_cfg = {0};
519 : : uint64_t def_nh = 100;
520 : :
521 : 1 : config.max_routes = MAX_ROUTES;
522 : : config.rib_ext_sz = 0;
523 : 1 : config.default_nh = def_nh;
524 : :
525 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
526 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
527 : :
528 : : /* Create RCU QSBR variable */
529 : 1 : sz = rte_rcu_qsbr_get_memsize(RTE_MAX_LCORE);
530 : 1 : qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket(NULL, sz, RTE_CACHE_LINE_SIZE,
531 : : SOCKET_ID_ANY);
532 [ - + ]: 1 : RTE_TEST_ASSERT(qsv != NULL, "Can not allocate memory for RCU\n");
533 : :
534 : 1 : status = rte_rcu_qsbr_init(qsv, RTE_MAX_LCORE);
535 [ - + ]: 1 : RTE_TEST_ASSERT(status == 0, "Can not initialize RCU\n");
536 : :
537 : 1 : rcu_cfg.v = qsv;
538 : :
539 : : /* adding rcu to RTE_FIB6_DUMMY FIB type */
540 : 1 : config.type = RTE_FIB6_DUMMY;
541 : 1 : rcu_cfg.mode = RTE_FIB6_QSBR_MODE_SYNC;
542 : 1 : status = rte_fib6_rcu_qsbr_add(fib, &rcu_cfg);
543 [ - + ]: 1 : RTE_TEST_ASSERT(status == -ENOTSUP,
544 : : "rte_fib6_rcu_qsbr_add returned wrong error status when called with DUMMY type FIB\n");
545 : 1 : rte_fib6_free(fib);
546 : :
547 : 1 : config.type = RTE_FIB6_TRIE;
548 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_4B;
549 : 1 : config.trie.num_tbl8 = MAX_TBL8;
550 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
551 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
552 : :
553 : : /* Call rte_fib6_rcu_qsbr_add without fib or config */
554 : 1 : status = rte_fib6_rcu_qsbr_add(NULL, &rcu_cfg);
555 [ - + ]: 1 : RTE_TEST_ASSERT(status == -EINVAL, "RCU added without fib\n");
556 : 1 : status = rte_fib6_rcu_qsbr_add(fib, NULL);
557 [ - + ]: 1 : RTE_TEST_ASSERT(status == -EINVAL, "RCU added without config\n");
558 : :
559 : : /* Invalid QSBR mode */
560 : 1 : rcu_cfg.mode = 2;
561 : 1 : status = rte_fib6_rcu_qsbr_add(fib, &rcu_cfg);
562 [ - + ]: 1 : RTE_TEST_ASSERT(status == -EINVAL, "RCU added with incorrect mode\n");
563 : :
564 : 1 : rcu_cfg.mode = RTE_FIB6_QSBR_MODE_DQ;
565 : :
566 : : /* Attach RCU QSBR to FIB to check for double attach */
567 : 1 : status = rte_fib6_rcu_qsbr_add(fib, &rcu_cfg);
568 [ - + ]: 1 : RTE_TEST_ASSERT(status == 0, "Can not attach RCU to FIB\n");
569 : :
570 : : /* Create and attach another RCU QSBR to FIB table */
571 : 1 : qsv2 = (struct rte_rcu_qsbr *)rte_zmalloc_socket(NULL, sz, RTE_CACHE_LINE_SIZE,
572 : : SOCKET_ID_ANY);
573 [ - + ]: 1 : RTE_TEST_ASSERT(qsv2 != NULL, "Can not allocate memory for RCU\n");
574 : :
575 : 1 : rcu_cfg.v = qsv2;
576 : 1 : rcu_cfg.mode = RTE_FIB6_QSBR_MODE_SYNC;
577 : 1 : status = rte_fib6_rcu_qsbr_add(fib, &rcu_cfg);
578 [ - + ]: 1 : RTE_TEST_ASSERT(status == -EEXIST, "Secondary RCU was mistakenly attached\n");
579 : :
580 : 1 : rte_fib6_free(fib);
581 : 1 : rte_free(qsv);
582 : 1 : rte_free(qsv2);
583 : :
584 : 1 : return TEST_SUCCESS;
585 : : }
586 : :
587 : : static struct rte_fib6 *g_fib;
588 : : static struct rte_rcu_qsbr *g_v;
589 : : static struct rte_ipv6_addr g_ip = RTE_IPV6(0x2001, 0xabcd, 0, 0, 0, 0, 0, 1);
590 : : static volatile uint8_t writer_done;
591 : : /* Report quiescent state interval every 1024 lookups. Larger critical
592 : : * sections in reader will result in writer polling multiple times.
593 : : */
594 : : #define QSBR_REPORTING_INTERVAL 1024
595 : : #define WRITER_ITERATIONS 512
596 : :
597 : : /*
598 : : * Reader thread using rte_fib6 data structure with RCU.
599 : : */
600 : : static int
601 : 1 : test_fib_rcu_qsbr_reader(void *arg)
602 : : {
603 : : int i;
604 : 1 : uint64_t next_hop_return = 0;
605 : :
606 : : RTE_SET_USED(arg);
607 : : /* Register this thread to report quiescent state */
608 : 1 : rte_rcu_qsbr_thread_register(g_v, 0);
609 : 1 : rte_rcu_qsbr_thread_online(g_v, 0);
610 : :
611 : : do {
612 [ + + ]: 528900 : for (i = 0; i < QSBR_REPORTING_INTERVAL; i++)
613 : 528384 : rte_fib6_lookup_bulk(g_fib, &g_ip, &next_hop_return, 1);
614 : :
615 : : /* Update quiescent state */
616 [ + + ]: 516 : rte_rcu_qsbr_quiescent(g_v, 0);
617 [ + + ]: 516 : } while (!writer_done);
618 : :
619 : 1 : rte_rcu_qsbr_thread_offline(g_v, 0);
620 : 1 : rte_rcu_qsbr_thread_unregister(g_v, 0);
621 : :
622 : 1 : return 0;
623 : : }
624 : :
625 : : /*
626 : : * rte_fib6_rcu_qsbr_add sync mode functional test.
627 : : * 1 Reader and 1 writer. They cannot be in the same thread in this test.
628 : : * - Create FIB which supports 1 tbl8 group at max
629 : : * - Add RCU QSBR variable with sync mode to FIB
630 : : * - Register a reader thread. Reader keeps looking up a specific rule.
631 : : * - Writer keeps adding and deleting a specific rule with depth=28 (> 24)
632 : : */
633 : : int32_t
634 : 1 : test_fib_rcu_sync_rw(void)
635 : : {
636 : 1 : struct rte_fib6_conf config = { 0 };
637 : : size_t sz;
638 : : int32_t status;
639 : : uint32_t i, next_hop;
640 : : uint8_t depth;
641 : 1 : struct rte_fib6_rcu_config rcu_cfg = {0};
642 : : uint64_t def_nh = 100;
643 : :
644 [ - + ]: 1 : if (rte_lcore_count() < 2) {
645 : : printf("Not enough cores for %s, expecting at least 2\n", __func__);
646 : 0 : return TEST_SKIPPED;
647 : : }
648 : :
649 : 1 : config.max_routes = MAX_ROUTES;
650 : 1 : config.rib_ext_sz = 0;
651 : 1 : config.default_nh = def_nh;
652 : 1 : config.type = RTE_FIB6_TRIE;
653 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_4B;
654 : 1 : config.trie.num_tbl8 = 1;
655 : :
656 : 1 : g_fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
657 [ - + ]: 1 : RTE_TEST_ASSERT(g_fib != NULL, "Failed to create FIB\n");
658 : :
659 : : /* Create RCU QSBR variable */
660 : 1 : sz = rte_rcu_qsbr_get_memsize(1);
661 : 1 : g_v = (struct rte_rcu_qsbr *)rte_zmalloc_socket(NULL, sz, RTE_CACHE_LINE_SIZE,
662 : : SOCKET_ID_ANY);
663 [ - + ]: 1 : RTE_TEST_ASSERT(g_v != NULL, "Can not allocate memory for RCU\n");
664 : :
665 : 1 : status = rte_rcu_qsbr_init(g_v, 1);
666 [ - + ]: 1 : RTE_TEST_ASSERT(status == 0, "Can not initialize RCU\n");
667 : :
668 : 1 : rcu_cfg.v = g_v;
669 : 1 : rcu_cfg.mode = RTE_FIB6_QSBR_MODE_SYNC;
670 : : /* Attach RCU QSBR to FIB table */
671 : 1 : status = rte_fib6_rcu_qsbr_add(g_fib, &rcu_cfg);
672 [ - + ]: 1 : RTE_TEST_ASSERT(status == 0, "Can not attach RCU to FIB\n");
673 : :
674 : 1 : writer_done = 0;
675 : : /* Launch reader thread */
676 : 1 : rte_eal_remote_launch(test_fib_rcu_qsbr_reader, NULL, rte_get_next_lcore(-1, 1, 0));
677 : :
678 : : depth = 28;
679 : : next_hop = 1;
680 : 1 : status = rte_fib6_add(g_fib, &g_ip, depth, next_hop);
681 [ - + ]: 1 : if (status != 0) {
682 : : printf("%s: Failed to add rule\n", __func__);
683 : 0 : goto error;
684 : : }
685 : :
686 : : /* Writer update */
687 [ + + ]: 513 : for (i = 0; i < WRITER_ITERATIONS; i++) {
688 : 512 : status = rte_fib6_delete(g_fib, &g_ip, depth);
689 [ - + ]: 512 : if (status != 0) {
690 : : printf("%s: Failed to delete rule at iteration %d\n", __func__, i);
691 : 0 : goto error;
692 : : }
693 : :
694 : 512 : status = rte_fib6_add(g_fib, &g_ip, depth, next_hop);
695 [ - + ]: 512 : if (status != 0) {
696 : : printf("%s: Failed to add rule at iteration %d\n", __func__, i);
697 : 0 : goto error;
698 : : }
699 : : }
700 : :
701 : 1 : error:
702 : 1 : writer_done = 1;
703 : : /* Wait until reader exited. */
704 : 1 : rte_eal_mp_wait_lcore();
705 : :
706 : 1 : rte_fib6_free(g_fib);
707 : 1 : rte_free(g_v);
708 : :
709 [ - + ]: 1 : return status == 0 ? TEST_SUCCESS : TEST_FAILED;
710 : : }
711 : :
712 : : /*
713 : : * Reproducer for the rsvd_tbl8s drift bug. The tbl8 reservation
714 : : * accounting must remain balanced even when a covering parent prefix
715 : : * is removed between an ADD and its later matching DEL.
716 : : *
717 : : * Layout: one /28 parent (fcde::/28) and three /48 siblings under it
718 : : * (fcde:0:6000::/48, fcde:1:6000::/48, fcde:2:6000::/48). The second
719 : : * hextet's high 12 bits are zero, so the three /48 IPs all fall inside
720 : : * the /28.
721 : : *
722 : : * One asymmetric sequence is enough to wrap the counter:
723 : : * ADD /28 rsvd_tbl8s += 1
724 : : * ADD /48 child_0,1,2 (with /28 parent) rsvd_tbl8s += 2 each (+6)
725 : : * DEL /28 (sibling /48 found) rsvd_tbl8s -= 0
726 : : * DEL /48 child_0,1,2 (no parent left) rsvd_tbl8s -= 3 each (-9)
727 : : */
728 : : static int32_t
729 : 1 : test_drift(void)
730 : : {
731 : 1 : struct rte_fib6_conf config = { 0 };
732 : : struct rte_fib6 *fib;
733 : 1 : struct rte_ipv6_addr parent =
734 : : RTE_IPV6(0xfcde, 0, 0, 0, 0, 0, 0, 0);
735 : 1 : struct rte_ipv6_addr child[3] = {
736 : : RTE_IPV6(0xfcde, 0, 0x6000, 0, 0, 0, 0, 0),
737 : : RTE_IPV6(0xfcde, 1, 0x6000, 0, 0, 0, 0, 0),
738 : : RTE_IPV6(0xfcde, 2, 0x6000, 0, 0, 0, 0, 0),
739 : : };
740 : : unsigned int c;
741 : : int ret;
742 : :
743 : 1 : config.max_routes = 1024;
744 : : config.rib_ext_sz = 0;
745 : : config.default_nh = 0;
746 : 1 : config.type = RTE_FIB6_TRIE;
747 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_2B;
748 : 1 : config.trie.num_tbl8 = 256;
749 : :
750 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
751 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
752 : :
753 : 1 : ret = rte_fib6_add(fib, &parent, 28, 0xa);
754 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "ADD /28 failed (ret=%d)\n", ret);
755 : :
756 [ + + ]: 4 : for (c = 0; c < 3; c++) {
757 : 3 : ret = rte_fib6_add(fib, &child[c], 48, 0xb + c);
758 [ - + ]: 3 : RTE_TEST_ASSERT(ret == 0,
759 : : "ADD /48 child %u failed (ret=%d)\n", c, ret);
760 : : }
761 : :
762 : 1 : ret = rte_fib6_delete(fib, &parent, 28);
763 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "DEL /28 failed (ret=%d)\n", ret);
764 : :
765 [ + + ]: 4 : for (c = 0; c < 3; c++) {
766 : 3 : ret = rte_fib6_delete(fib, &child[c], 48);
767 [ - + ]: 3 : RTE_TEST_ASSERT(ret == 0,
768 : : "DEL /48 child %u failed (ret=%d)\n", c, ret);
769 : : }
770 : :
771 : : /* Pre-fix: -ENOSPC. Post-fix: succeeds. */
772 : 1 : ret = rte_fib6_add(fib, &parent, 28, 0xe);
773 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0,
774 : : "Fresh ADD /28 spuriously failed (ret=%d)\n", ret);
775 : :
776 : 1 : ret = rte_fib6_delete(fib, &parent, 28);
777 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "Final DEL /28 failed (ret=%d)\n", ret);
778 : :
779 : 1 : rte_fib6_free(fib);
780 : 1 : return TEST_SUCCESS;
781 : : }
782 : :
783 : : /*
784 : : * Exercise compression (same nh as parent), forced decompression on
785 : : * DEL parent, then re-compression after re-adding the same ancestor.
786 : : * The tbl8 reservation accounting must remain balanced even though
787 : : * the child is physically decompressed/recompressed in the dataplane.
788 : : *
789 : : * Layout: parent fcde::/28 and child fcde:0:6000::/48, both nh=1.
790 : : *
791 : : * ADD /28 (no ancestor) rsvd_tbl8s += 1
792 : : * ADD /48 (compressed under /28) rsvd_tbl8s += 2
793 : : * DEL /28 (decompresses /48) rsvd unchanged (/48 keeps)
794 : : * re-ADD /28 (re-compresses /48) rsvd unchanged
795 : : * DEL /48 rsvd_tbl8s -= 2
796 : : * DEL /28 rsvd_tbl8s -= 1
797 : : */
798 : : static int32_t
799 : 1 : test_drift_compression(void)
800 : : {
801 : 1 : struct rte_fib6_conf config = { 0 };
802 : : struct rte_fib6 *fib;
803 : 1 : struct rte_ipv6_addr parent = RTE_IPV6(0xfcde, 0, 0, 0, 0, 0, 0, 0);
804 : 1 : struct rte_ipv6_addr child = RTE_IPV6(0xfcde, 0, 0x6000, 0, 0, 0, 0, 0);
805 : : int ret;
806 : :
807 : 1 : config.max_routes = 1024;
808 : : config.rib_ext_sz = 0;
809 : : config.default_nh = 0;
810 : 1 : config.type = RTE_FIB6_TRIE;
811 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_2B;
812 : 1 : config.trie.num_tbl8 = 256;
813 : :
814 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
815 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
816 : :
817 : : /* Compressed: child shares the parent's nh, modify_dp is skipped */
818 : 1 : ret = rte_fib6_add(fib, &parent, 28, 1);
819 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "ADD /28 failed\n");
820 : 1 : ret = rte_fib6_add(fib, &child, 48, 1);
821 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "ADD /48 (compressed) failed\n");
822 : :
823 : : /* DEL parent forces decompression: child must be materialized */
824 : 1 : ret = rte_fib6_delete(fib, &parent, 28);
825 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "DEL /28 (decompression) failed\n");
826 : :
827 : : /* Re-add parent with same nh: child becomes compressed again */
828 : 1 : ret = rte_fib6_add(fib, &parent, 28, 1);
829 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "Re-ADD /28 failed\n");
830 : :
831 : 1 : ret = rte_fib6_delete(fib, &child, 48);
832 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "DEL /48 failed\n");
833 : 1 : ret = rte_fib6_delete(fib, &parent, 28);
834 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "DEL /28 final failed\n");
835 : :
836 : 1 : rte_fib6_free(fib);
837 : 1 : return TEST_SUCCESS;
838 : : }
839 : :
840 : : /*
841 : : * Three-level nesting with compressed and non-compressed paths, then
842 : : * DEL of the middle prefix. The byte-boundary supernet accounting
843 : : * must remain balanced through the chain.
844 : : *
845 : : * Layout: grand fcde::/28 nh=1, mid fcde:0:6000::/48 nh=1 (compressed
846 : : * under grand), leaf fcde:0:6000::4000::/96 nh=2 (not compressed).
847 : : *
848 : : * ADD /28 (no ancestor) rsvd_tbl8s += 1
849 : : * ADD /48 (compressed under /28) rsvd_tbl8s += 2
850 : : * ADD /96 (not compressed under /48) rsvd_tbl8s += 6
851 : : * DEL /48 (leaf /96 still covers 32, 40) rsvd_tbl8s -= 0
852 : : * DEL /28 (only level 24 was solely /28's) rsvd_tbl8s -= 0
853 : : * DEL /96 (last route gone, all freed) rsvd_tbl8s -= 9
854 : : *
855 : : * Boundaries get refunded only on the DEL that makes them empty;
856 : : * intermediate DELs that leave a covering descendant are refund-free.
857 : : */
858 : : static int32_t
859 : 1 : test_drift_multilevel(void)
860 : : {
861 : 1 : struct rte_fib6_conf config = { 0 };
862 : : struct rte_fib6 *fib;
863 : 1 : struct rte_ipv6_addr grand = RTE_IPV6(0xfcde, 0, 0, 0, 0, 0, 0, 0);
864 : 1 : struct rte_ipv6_addr mid = RTE_IPV6(0xfcde, 0, 0x6000, 0, 0, 0, 0, 0);
865 : 1 : struct rte_ipv6_addr leaf = RTE_IPV6(0xfcde, 0, 0x6000, 0, 0, 0x4000, 0, 0);
866 : : int ret;
867 : :
868 : 1 : config.max_routes = 1024;
869 : : config.rib_ext_sz = 0;
870 : : config.default_nh = 0;
871 : 1 : config.type = RTE_FIB6_TRIE;
872 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_2B;
873 : 1 : config.trie.num_tbl8 = 256;
874 : :
875 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
876 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
877 : :
878 : 1 : ret = rte_fib6_add(fib, &grand, 28, 1);
879 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "ADD /28 failed\n");
880 : 1 : ret = rte_fib6_add(fib, &mid, 48, 1); /* compressed under /28 */
881 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "ADD /48 failed\n");
882 : 1 : ret = rte_fib6_add(fib, &leaf, 96, 2); /* non-compressed under /48 */
883 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "ADD /96 failed\n");
884 : :
885 : : /* DEL the middle prefix: byte-boundary accounting must stay
886 : : * coherent so the subsequent operations succeed.
887 : : */
888 : 1 : ret = rte_fib6_delete(fib, &mid, 48);
889 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "DEL /48 failed\n");
890 : :
891 : 1 : ret = rte_fib6_delete(fib, &grand, 28);
892 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "DEL /28 failed\n");
893 : 1 : ret = rte_fib6_delete(fib, &leaf, 96);
894 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "DEL /96 failed\n");
895 : :
896 : 1 : rte_fib6_free(fib);
897 : 1 : return TEST_SUCCESS;
898 : : }
899 : :
900 : : /*
901 : : * Pseudo-random ADD/DEL sequence over 8 prefixes with varying depths
902 : : * and next-hops. A hand-rolled LCG (not rte_rand) makes the sequence
903 : : * reproducible across runs and DPDK versions. After all prefixes are
904 : : * removed, a final ADD/DEL pair must succeed - it would fail under a
905 : : * leaked rsvd_tbl8s.
906 : : *
907 : : * depths[1] and depths[6] both use /36 on purpose: ips[1] and ips[6]
908 : : * are distinct prefixes, so this exercises two parallel /36 ADD/DEL
909 : : * paths that share byte boundaries 24 and 32.
910 : : */
911 : : static int32_t
912 : 1 : test_drift_stress(void)
913 : : {
914 : 1 : uint8_t depths[8] = { 28, 36, 40, 48, 64, 80, 36, 128 };
915 : 1 : struct rte_fib6_conf config = { 0 };
916 : 1 : struct rte_ipv6_addr ips[8] = {
917 : : RTE_IPV6(0xfcde, 0, 0, 0, 0, 0, 0, 0),
918 : : RTE_IPV6(0xfcde, 0x1, 0, 0, 0, 0, 0, 0),
919 : : RTE_IPV6(0xfcde, 0x2, 0, 0, 0, 0, 0, 0),
920 : : RTE_IPV6(0xfcde, 0x2, 0x4000, 0, 0, 0, 0, 0),
921 : : RTE_IPV6(0xfcde, 0x2, 0x4000, 0x1000, 0, 0, 0, 0),
922 : : RTE_IPV6(0xfcde, 0x2, 0x4000, 0x1000, 0x1, 0, 0, 0),
923 : : RTE_IPV6(0xfcde, 0x3, 0, 0, 0, 0, 0, 0),
924 : : RTE_IPV6(0xfcde, 0x3, 0, 0, 0, 0, 0, 0x1),
925 : : };
926 : 1 : uint8_t live[8] = { 0 };
927 : : struct rte_fib6 *fib;
928 : : uint32_t seed = 0x4242;
929 : : unsigned int i, idx;
930 : : int ret;
931 : :
932 : 1 : config.max_routes = 64;
933 : : config.rib_ext_sz = 0;
934 : : config.default_nh = 0;
935 : 1 : config.type = RTE_FIB6_TRIE;
936 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_2B;
937 : 1 : config.trie.num_tbl8 = 256;
938 : :
939 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
940 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
941 : :
942 [ + + ]: 2001 : for (i = 0; i < 2000; i++) {
943 : 2000 : seed = seed * 1103515245u + 12345u;
944 : 2000 : idx = (seed >> 8) & 7;
945 [ + + ]: 2000 : if (live[idx]) {
946 : 998 : ret = rte_fib6_delete(fib, &ips[idx], depths[idx]);
947 [ - + ]: 998 : RTE_TEST_ASSERT(ret == 0,
948 : : "DEL idx %u (depth /%u) failed (ret=%d)\n",
949 : : idx, depths[idx], ret);
950 : 998 : live[idx] = 0;
951 : : } else {
952 : 1002 : uint64_t nh = ((seed >> 16) & 0xff) + 1;
953 : 1002 : ret = rte_fib6_add(fib, &ips[idx], depths[idx], nh);
954 [ - + ]: 1002 : RTE_TEST_ASSERT(ret == 0,
955 : : "ADD idx %u (depth /%u nh=%" PRIu64 ") failed (ret=%d)\n",
956 : : idx, depths[idx], nh, ret);
957 : 1002 : live[idx] = 1;
958 : : }
959 : : }
960 : :
961 : : /* Drain everything */
962 [ + + ]: 9 : for (i = 0; i < RTE_DIM(live); i++) {
963 [ + + ]: 8 : if (live[i]) {
964 : 4 : ret = rte_fib6_delete(fib, &ips[i], depths[i]);
965 [ - + ]: 4 : RTE_TEST_ASSERT(ret == 0,
966 : : "final drain DEL idx %u failed (ret=%d)\n",
967 : : i, ret);
968 : : }
969 : : }
970 : :
971 : : /* If rsvd_tbl8s had leaked, this fresh ADD would fail */
972 : 1 : ret = rte_fib6_add(fib, &ips[0], depths[0], 0xff);
973 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0,
974 : : "post-drain ADD failed (rsvd leaked?) (ret=%d)\n", ret);
975 : 1 : ret = rte_fib6_delete(fib, &ips[0], depths[0]);
976 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "post-drain DEL failed\n");
977 : :
978 : 1 : rte_fib6_free(fib);
979 : 1 : return TEST_SUCCESS;
980 : : }
981 : :
982 : : /* Tight-pool re-compression scenario. Pool sized to exactly the
983 : : * highest legitimate envelope: an ADD that becomes a closer ancestor
984 : : * of an existing descendant must succeed because the byte-boundary
985 : : * supernet accounting reports the same envelope post-operation.
986 : : *
987 : : * num_tbl8 = 3
988 : : * ADD /28 nh=1 rsvd = 1
989 : : * ADD /48 nh=1 (compr.) rsvd = 3 (/48 reserves 2 new boundaries)
990 : : * DEL /28 rsvd unchanged (/48 still holds them)
991 : : * RE-ADD /28 nh=1 rsvd unchanged (already reserved)
992 : : * (pre-fix: pre-check rejects)
993 : : */
994 : : static int32_t
995 : 1 : test_drift_tight_pool(void)
996 : : {
997 : 1 : struct rte_fib6_conf config = { 0 };
998 : : struct rte_fib6 *fib;
999 : 1 : struct rte_ipv6_addr parent = RTE_IPV6(0xfcde, 0, 0, 0, 0, 0, 0, 0);
1000 : 1 : struct rte_ipv6_addr child = RTE_IPV6(0xfcde, 0, 0x6000, 0, 0, 0, 0, 0);
1001 : : int ret;
1002 : :
1003 : 1 : config.max_routes = 16;
1004 : : config.rib_ext_sz = 0;
1005 : : config.default_nh = 0;
1006 : 1 : config.type = RTE_FIB6_TRIE;
1007 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_2B;
1008 : 1 : config.trie.num_tbl8 = 3;
1009 : :
1010 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
1011 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
1012 : :
1013 : 1 : ret = rte_fib6_add(fib, &parent, 28, 1);
1014 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "ADD /28 failed (ret=%d)\n", ret);
1015 : 1 : ret = rte_fib6_add(fib, &child, 48, 1);
1016 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "ADD /48 failed (ret=%d)\n", ret);
1017 : 1 : ret = rte_fib6_delete(fib, &parent, 28);
1018 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "DEL /28 failed (ret=%d)\n", ret);
1019 : :
1020 : : /* Re-add /28: byte boundary 24 is already occupied by the /48,
1021 : : * so the re-added /28 introduces no new reservation. The
1022 : : * envelope stays at 3 and still fits the pool of 3.
1023 : : */
1024 : 1 : ret = rte_fib6_add(fib, &parent, 28, 1);
1025 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0,
1026 : : "Re-ADD /28 spuriously failed (ret=%d)\n", ret);
1027 : :
1028 : 1 : ret = rte_fib6_delete(fib, &child, 48);
1029 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "DEL /48 failed (ret=%d)\n", ret);
1030 : 1 : ret = rte_fib6_delete(fib, &parent, 28);
1031 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "Final DEL /28 failed (ret=%d)\n", ret);
1032 : :
1033 : 1 : rte_fib6_free(fib);
1034 : 1 : return TEST_SUCCESS;
1035 : : }
1036 : :
1037 : : /*
1038 : : * Byte-aligned prefixes must not take a temporary tbl8: a /32 fits a pool of
1039 : : * one, a /24 and a /16 still fit once the pool is full, and the /32 can be
1040 : : * deleted from a full pool, giving its tbl8 back to a following /25.
1041 : : */
1042 : : static int32_t
1043 : 1 : test_tbl8_install_peak(void)
1044 : : {
1045 : 1 : struct rte_ipv6_addr aligned = RTE_IPV6(0x2001, 0x0db8, 0, 0, 0, 0, 0, 0);
1046 : 1 : struct rte_ipv6_addr p24 = RTE_IPV6(0x2002, 0x0100, 0, 0, 0, 0, 0, 0);
1047 : 1 : struct rte_ipv6_addr p16 = RTE_IPV6(0x2003, 0, 0, 0, 0, 0, 0, 0);
1048 : 1 : struct rte_ipv6_addr unaligned = RTE_IPV6(0xfc00, 0, 0, 0, 0, 0, 0, 0);
1049 : 1 : struct rte_fib6_conf config = { 0 };
1050 : : struct rte_fib6 *fib;
1051 : : uint64_t nh;
1052 : : int ret;
1053 : :
1054 : 1 : config.max_routes = 16;
1055 : : config.default_nh = 0;
1056 : 1 : config.type = RTE_FIB6_TRIE;
1057 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_2B;
1058 : 1 : config.trie.num_tbl8 = 1;
1059 : :
1060 : 1 : fib = rte_fib6_create("peak", SOCKET_ID_ANY, &config);
1061 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
1062 : :
1063 : 1 : ret = rte_fib6_add(fib, &aligned, 33, 1);
1064 [ - + ]: 1 : RTE_TEST_ASSERT(ret == -ENOSPC, "/33 needs 2 Tbl8s, can not fit pool of 1 (ret=%d)\n", ret);
1065 : 1 : rte_fib6_lookup_bulk(fib, &aligned, &nh, 1);
1066 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 0, "empty table lookup got nh=%u\n", (unsigned int)nh);
1067 : :
1068 : 1 : ret = rte_fib6_add(fib, &aligned, 32, 1);
1069 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "/32 must fit pool of 1 (ret=%d)\n", ret);
1070 : 1 : rte_fib6_lookup_bulk(fib, &aligned, &nh, 1);
1071 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 1, "/32 lookup got nh=%u\n", (unsigned int)nh);
1072 : :
1073 : : /* the pool is full, prefixes up to /24 need no tbl8 at all */
1074 : 1 : ret = rte_fib6_add(fib, &p24, 24, 2);
1075 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "/24 must fit full pool (ret=%d)\n", ret);
1076 : 1 : rte_fib6_lookup_bulk(fib, &p24, &nh, 1);
1077 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 2, "/24 lookup got nh=%u\n", (unsigned int)nh);
1078 : 1 : ret = rte_fib6_add(fib, &p16, 16, 3);
1079 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "/16 must fit full pool (ret=%d)\n", ret);
1080 : 1 : rte_fib6_lookup_bulk(fib, &p16, &nh, 1);
1081 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 3, "/16 lookup got nh=%u\n", (unsigned int)nh);
1082 : :
1083 : 1 : ret = rte_fib6_add(fib, &unaligned, 25, 4);
1084 [ - + ]: 1 : RTE_TEST_ASSERT(ret == -ENOSPC,
1085 : : "/25 in full pool expected -ENOSPC, got %d\n", ret);
1086 : 1 : rte_fib6_lookup_bulk(fib, &unaligned, &nh, 1);
1087 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 0,
1088 : : "rejected /25 must leave the dataplane clean, got nh=%u\n",
1089 : : (unsigned int)nh);
1090 : :
1091 : 1 : ret = rte_fib6_delete(fib, &aligned, 32);
1092 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0,
1093 : : "/32 delete from full pool failed (ret=%d)\n", ret);
1094 : 1 : rte_fib6_lookup_bulk(fib, &aligned, &nh, 1);
1095 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 0, "deleted /32 lookup got nh=%u\n",
1096 : : (unsigned int)nh);
1097 : :
1098 : 1 : ret = rte_fib6_add(fib, &unaligned, 25, 4);
1099 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0,
1100 : : "/25 must fit pool of 1 after /32 delete (ret=%d)\n", ret);
1101 : 1 : rte_fib6_lookup_bulk(fib, &unaligned, &nh, 1);
1102 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 4, "/25 lookup got nh=%u\n", (unsigned int)nh);
1103 : :
1104 : 1 : rte_fib6_free(fib);
1105 : 1 : return TEST_SUCCESS;
1106 : : }
1107 : :
1108 : : /*
1109 : : * In QSBR defer mode a freed group stays out of the pool until reclaimed, so
1110 : : * rsvd_tbl8s underestimates occupancy. A /40 needing two groups must be
1111 : : * refused by physical count without leaking, so a following /25 needing one
1112 : : * group fits.
1113 : : */
1114 : : static int32_t
1115 : 1 : test_tbl8_install_peak_dq(void)
1116 : : {
1117 : 1 : struct rte_ipv6_addr a = RTE_IPV6(0x2001, 0x0db8, 0, 0, 0, 0, 0, 0);
1118 : 1 : struct rte_ipv6_addr b = RTE_IPV6(0xfc00, 0, 0, 0, 0, 0, 0, 0);
1119 : 1 : struct rte_ipv6_addr c = RTE_IPV6(0xfd00, 0, 0, 0, 0, 0, 0, 0);
1120 : 1 : struct rte_fib6_rcu_config rcu_cfg = { 0 };
1121 : 1 : struct rte_fib6_conf config = { 0 };
1122 : : struct rte_rcu_qsbr *v;
1123 : : struct rte_fib6 *fib;
1124 : : uint64_t nh;
1125 : : size_t sz;
1126 : : int ret;
1127 : :
1128 : 1 : config.max_routes = 16;
1129 : : config.default_nh = 0;
1130 : 1 : config.type = RTE_FIB6_TRIE;
1131 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_2B;
1132 : 1 : config.trie.num_tbl8 = 2;
1133 : :
1134 : 1 : fib = rte_fib6_create("peak_dq", SOCKET_ID_ANY, &config);
1135 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
1136 : :
1137 : 1 : sz = rte_rcu_qsbr_get_memsize(1);
1138 : 1 : v = rte_zmalloc_socket(NULL, sz, RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1139 [ - + ]: 1 : RTE_TEST_ASSERT(v != NULL, "Can not allocate RCU\n");
1140 : 1 : ret = rte_rcu_qsbr_init(v, 1);
1141 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "Can not init RCU\n");
1142 : 1 : rcu_cfg.v = v;
1143 : 1 : rcu_cfg.mode = RTE_FIB6_QSBR_MODE_DQ;
1144 : 1 : ret = rte_fib6_rcu_qsbr_add(fib, &rcu_cfg);
1145 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "Can not attach RCU (ret=%d)\n", ret);
1146 : :
1147 : : /* an online reader that never reports quiescence blocks reclamation */
1148 : 1 : rte_rcu_qsbr_thread_register(v, 0);
1149 : : rte_rcu_qsbr_thread_online(v, 0);
1150 : :
1151 : 1 : ret = rte_fib6_add(fib, &b, 25, 1);
1152 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "/25 add failed (ret=%d)\n", ret);
1153 : 1 : ret = rte_fib6_delete(fib, &b, 25);
1154 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "/25 delete failed (ret=%d)\n", ret);
1155 : : /* the /25 group is now deferred, still physically out of the pool */
1156 : :
1157 : 1 : ret = rte_fib6_add(fib, &a, 40, 2);
1158 [ - + ]: 1 : RTE_TEST_ASSERT(ret == -ENOSPC,
1159 : : "/40 must be rejected while a group is deferred, got %d\n",
1160 : : ret);
1161 : 1 : rte_fib6_lookup_bulk(fib, &a, &nh, 1);
1162 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 0,
1163 : : "rejected /40 must leave the dataplane clean, got nh=%u\n",
1164 : : (unsigned int)nh);
1165 : :
1166 : : /* a second /25 needs one group: it fits only if the /40 leaked nothing */
1167 : 1 : ret = rte_fib6_add(fib, &c, 25, 3);
1168 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0,
1169 : : "2nd /25 rejected: /40 leaked a group under defer (ret=%d)\n",
1170 : : ret);
1171 : 1 : rte_fib6_lookup_bulk(fib, &c, &nh, 1);
1172 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 3, "2nd /25 lookup got nh=%u\n", (unsigned int)nh);
1173 : :
1174 : : rte_rcu_qsbr_thread_offline(v, 0);
1175 : 1 : rte_rcu_qsbr_thread_unregister(v, 0);
1176 : 1 : rte_fib6_free(fib);
1177 : 1 : rte_free(v);
1178 : 1 : return TEST_SUCCESS;
1179 : : }
1180 : :
1181 : : /*
1182 : : * In QSBR defer mode, changing or deleting a prefix may need tbl8 groups for
1183 : : * its more specifics while the groups they used are still deferred. The
1184 : : * update must be refused before it touches the dataplane, and succeed once
1185 : : * the deferred groups are reclaimed.
1186 : : */
1187 : : static int32_t
1188 : 1 : test_tbl8_dq_modify(void)
1189 : : {
1190 : 1 : struct rte_ipv6_addr p24 = RTE_IPV6(0x2001, 0x0d00, 0, 0, 0, 0, 0, 0);
1191 : 1 : struct rte_ipv6_addr p32 = RTE_IPV6(0x2001, 0x0db8, 0, 0, 0, 0, 0, 0);
1192 : 1 : struct rte_ipv6_addr p33 = RTE_IPV6(0x2001, 0x0dff, 0, 0, 0, 0, 0, 0);
1193 : 1 : struct rte_fib6_rcu_config rcu_cfg = { 0 };
1194 : 1 : struct rte_fib6_conf config = { 0 };
1195 : : struct rte_rcu_qsbr *v;
1196 : : struct rte_fib6 *fib;
1197 : : uint64_t nh;
1198 : : size_t sz;
1199 : : int ret;
1200 : :
1201 : 1 : config.max_routes = 16;
1202 : : config.default_nh = 0;
1203 : 1 : config.type = RTE_FIB6_TRIE;
1204 : 1 : config.trie.nh_sz = RTE_FIB6_TRIE_2B;
1205 : 1 : config.trie.num_tbl8 = 3;
1206 : :
1207 : 1 : fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &config);
1208 [ - + ]: 1 : RTE_TEST_ASSERT(fib != NULL, "Failed to create FIB\n");
1209 : :
1210 : 1 : sz = rte_rcu_qsbr_get_memsize(1);
1211 : 1 : v = rte_zmalloc_socket(NULL, sz, RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1212 [ - + ]: 1 : RTE_TEST_ASSERT(v != NULL, "Can not allocate RCU\n");
1213 : 1 : ret = rte_rcu_qsbr_init(v, 1);
1214 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "Can not init RCU\n");
1215 : 1 : rcu_cfg.v = v;
1216 : 1 : rcu_cfg.mode = RTE_FIB6_QSBR_MODE_DQ;
1217 : 1 : ret = rte_fib6_rcu_qsbr_add(fib, &rcu_cfg);
1218 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "Can not attach RCU (ret=%d)\n", ret);
1219 : :
1220 : : /* an online reader that never reports quiescence blocks reclamation */
1221 : 1 : rte_rcu_qsbr_thread_register(v, 0);
1222 : : rte_rcu_qsbr_thread_online(v, 0);
1223 : :
1224 : 1 : ret = rte_fib6_add(fib, &p24, 24, 3);
1225 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "/24 add failed (ret=%d)\n", ret);
1226 : 1 : ret = rte_fib6_add(fib, &p32, 32, 5);
1227 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "/32 add failed (ret=%d)\n", ret);
1228 : 1 : ret = rte_fib6_add(fib, &p33, 33, 5);
1229 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "/33 add failed (ret=%d)\n", ret);
1230 : :
1231 : : /*
1232 : : * Moving the /32 and /33 to the /24 next hop frees their two groups,
1233 : : * which stay deferred. One group is left in the pool.
1234 : : */
1235 : 1 : ret = rte_fib6_add(fib, &p32, 32, 3);
1236 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "/32 next hop change failed (ret=%d)\n", ret);
1237 : 1 : ret = rte_fib6_add(fib, &p33, 33, 3);
1238 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "/33 next hop change failed (ret=%d)\n", ret);
1239 : :
1240 : : /* changing or deleting the /24 needs two groups for the /32 and /33 */
1241 : 1 : ret = rte_fib6_add(fib, &p24, 24, 7);
1242 [ - + ]: 1 : RTE_TEST_ASSERT(ret == -ENOSPC,
1243 : : "/24 next hop change expected -ENOSPC, got %d\n", ret);
1244 : 1 : rte_fib6_lookup_bulk(fib, &p24, &nh, 1);
1245 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 3,
1246 : : "rejected /24 change must leave the dataplane intact, got nh=%u\n",
1247 : : (unsigned int)nh);
1248 : :
1249 : 1 : ret = rte_fib6_delete(fib, &p24, 24);
1250 [ - + ]: 1 : RTE_TEST_ASSERT(ret == -ENOSPC,
1251 : : "/24 delete expected -ENOSPC, got %d\n", ret);
1252 : 1 : rte_fib6_lookup_bulk(fib, &p24, &nh, 1);
1253 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 3,
1254 : : "rejected /24 delete must leave the dataplane intact, got nh=%u\n",
1255 : : (unsigned int)nh);
1256 : :
1257 : : /* the reader reports quiescence, the deferred groups can be reclaimed */
1258 : : rte_rcu_qsbr_quiescent(v, 0);
1259 : :
1260 : 1 : ret = rte_fib6_delete(fib, &p24, 24);
1261 [ - + ]: 1 : RTE_TEST_ASSERT(ret == 0, "/24 delete failed (ret=%d)\n", ret);
1262 : 1 : rte_fib6_lookup_bulk(fib, &p24, &nh, 1);
1263 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 0, "deleted /24 lookup got nh=%u\n",
1264 : : (unsigned int)nh);
1265 : 1 : rte_fib6_lookup_bulk(fib, &p32, &nh, 1);
1266 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 3, "/32 lookup got nh=%u\n", (unsigned int)nh);
1267 : 1 : rte_fib6_lookup_bulk(fib, &p33, &nh, 1);
1268 [ - + ]: 1 : RTE_TEST_ASSERT(nh == 3, "/33 lookup got nh=%u\n", (unsigned int)nh);
1269 : :
1270 : : rte_rcu_qsbr_thread_offline(v, 0);
1271 : 1 : rte_rcu_qsbr_thread_unregister(v, 0);
1272 : 1 : rte_fib6_free(fib);
1273 : 1 : rte_free(v);
1274 : 1 : return TEST_SUCCESS;
1275 : : }
1276 : :
1277 : : static struct unit_test_suite fib6_fast_tests = {
1278 : : .suite_name = "fib6 autotest",
1279 : : .setup = NULL,
1280 : : .teardown = NULL,
1281 : : .unit_test_cases = {
1282 : : TEST_CASE(test_create_invalid),
1283 : : TEST_CASE(test_free_null),
1284 : : TEST_CASE(test_add_del_invalid),
1285 : : TEST_CASE(test_get_invalid),
1286 : : TEST_CASE(test_lookup),
1287 : : TEST_CASE(test_wraparound),
1288 : : TEST_CASE(test_invalid_rcu),
1289 : : TEST_CASE(test_fib_rcu_sync_rw),
1290 : : TEST_CASE(test_drift),
1291 : : TEST_CASE(test_drift_compression),
1292 : : TEST_CASE(test_drift_multilevel),
1293 : : TEST_CASE(test_drift_stress),
1294 : : TEST_CASE(test_drift_tight_pool),
1295 : : TEST_CASE(test_tbl8_install_peak),
1296 : : TEST_CASE(test_tbl8_install_peak_dq),
1297 : : TEST_CASE(test_tbl8_dq_modify),
1298 : : TEST_CASES_END()
1299 : : }
1300 : : };
1301 : :
1302 : : static struct unit_test_suite fib6_slow_tests = {
1303 : : .suite_name = "fib6 slow autotest",
1304 : : .setup = NULL,
1305 : : .teardown = NULL,
1306 : : .unit_test_cases = {
1307 : : TEST_CASE(test_multiple_create),
1308 : : TEST_CASES_END()
1309 : : }
1310 : : };
1311 : :
1312 : : /*
1313 : : * Do all unit tests.
1314 : : */
1315 : : static int
1316 : 1 : test_fib6(void)
1317 : : {
1318 : 1 : return unit_test_suite_runner(&fib6_fast_tests);
1319 : : }
1320 : :
1321 : : static int
1322 : 0 : test_slow_fib6(void)
1323 : : {
1324 : 0 : return unit_test_suite_runner(&fib6_slow_tests);
1325 : : }
1326 : :
1327 : 306 : REGISTER_FAST_TEST(fib6_autotest, NOHUGE_OK, ASAN_OK, test_fib6);
1328 : 306 : REGISTER_PERF_TEST(fib6_slow_autotest, test_slow_fib6);
|