1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
11 #include <rte_malloc.h>
14 #include "test_xmmt_ops.h"
16 #define TEST_LPM_ASSERT(cond) do { \
18 printf("Error at line %d: \n", __LINE__); \
23 typedef int32_t (*rte_lpm_test)(void);
25 static int32_t test0(void);
26 static int32_t test1(void);
27 static int32_t test2(void);
28 static int32_t test3(void);
29 static int32_t test4(void);
30 static int32_t test5(void);
31 static int32_t test6(void);
32 static int32_t test7(void);
33 static int32_t test8(void);
34 static int32_t test9(void);
35 static int32_t test10(void);
36 static int32_t test11(void);
37 static int32_t test12(void);
38 static int32_t test13(void);
39 static int32_t test14(void);
40 static int32_t test15(void);
41 static int32_t test16(void);
42 static int32_t test17(void);
43 static int32_t test18(void);
44 static int32_t test19(void);
45 static int32_t test20(void);
46 static int32_t test21(void);
48 rte_lpm_test tests[] = {
76 #define NUMBER_TBL8S 256
80 * Check that rte_lpm_create fails gracefully for incorrect user input
86 struct rte_lpm *lpm = NULL;
87 struct rte_lpm_config config;
89 config.max_rules = MAX_RULES;
90 config.number_tbl8s = NUMBER_TBL8S;
93 /* rte_lpm_create: lpm name == NULL */
94 lpm = rte_lpm_create(NULL, SOCKET_ID_ANY, &config);
95 TEST_LPM_ASSERT(lpm == NULL);
97 /* rte_lpm_create: max_rules = 0 */
98 /* Note: __func__ inserts the function name, in this case "test0". */
100 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
101 TEST_LPM_ASSERT(lpm == NULL);
103 /* socket_id < -1 is invalid */
104 config.max_rules = MAX_RULES;
105 lpm = rte_lpm_create(__func__, -2, &config);
106 TEST_LPM_ASSERT(lpm == NULL);
112 * Create lpm table then delete lpm table 100 times
113 * Use a slightly different rules size each time
118 struct rte_lpm *lpm = NULL;
119 struct rte_lpm_config config;
121 config.number_tbl8s = NUMBER_TBL8S;
125 /* rte_lpm_free: Free NULL */
126 for (i = 0; i < 100; i++) {
127 config.max_rules = MAX_RULES - i;
128 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
129 TEST_LPM_ASSERT(lpm != NULL);
134 /* Can not test free so return success */
139 * Call rte_lpm_free for NULL pointer user input. Note: free has no return and
140 * therefore it is impossible to check for failure but this test is added to
141 * increase function coverage metrics and to validate that freeing null does
147 struct rte_lpm *lpm = NULL;
148 struct rte_lpm_config config;
150 config.max_rules = MAX_RULES;
151 config.number_tbl8s = NUMBER_TBL8S;
154 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
155 TEST_LPM_ASSERT(lpm != NULL);
163 * Check that rte_lpm_add fails gracefully for incorrect user input arguments
168 struct rte_lpm *lpm = NULL;
169 struct rte_lpm_config config;
171 config.max_rules = MAX_RULES;
172 config.number_tbl8s = NUMBER_TBL8S;
174 uint32_t ip = RTE_IPV4(0, 0, 0, 0), next_hop = 100;
178 /* rte_lpm_add: lpm == NULL */
179 status = rte_lpm_add(NULL, ip, depth, next_hop);
180 TEST_LPM_ASSERT(status < 0);
182 /*Create vaild lpm to use in rest of test. */
183 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
184 TEST_LPM_ASSERT(lpm != NULL);
186 /* rte_lpm_add: depth < 1 */
187 status = rte_lpm_add(lpm, ip, 0, next_hop);
188 TEST_LPM_ASSERT(status < 0);
190 /* rte_lpm_add: depth > MAX_DEPTH */
191 status = rte_lpm_add(lpm, ip, (MAX_DEPTH + 1), next_hop);
192 TEST_LPM_ASSERT(status < 0);
200 * Check that rte_lpm_delete fails gracefully for incorrect user input
206 struct rte_lpm *lpm = NULL;
207 struct rte_lpm_config config;
209 config.max_rules = MAX_RULES;
210 config.number_tbl8s = NUMBER_TBL8S;
212 uint32_t ip = RTE_IPV4(0, 0, 0, 0);
216 /* rte_lpm_delete: lpm == NULL */
217 status = rte_lpm_delete(NULL, ip, depth);
218 TEST_LPM_ASSERT(status < 0);
220 /*Create vaild lpm to use in rest of test. */
221 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
222 TEST_LPM_ASSERT(lpm != NULL);
224 /* rte_lpm_delete: depth < 1 */
225 status = rte_lpm_delete(lpm, ip, 0);
226 TEST_LPM_ASSERT(status < 0);
228 /* rte_lpm_delete: depth > MAX_DEPTH */
229 status = rte_lpm_delete(lpm, ip, (MAX_DEPTH + 1));
230 TEST_LPM_ASSERT(status < 0);
238 * Check that rte_lpm_lookup fails gracefully for incorrect user input
244 #if defined(RTE_LIBRTE_LPM_DEBUG)
245 struct rte_lpm *lpm = NULL;
246 struct rte_lpm_config config;
248 config.max_rules = MAX_RULES;
249 config.number_tbl8s = NUMBER_TBL8S;
251 uint32_t ip = RTE_IPV4(0, 0, 0, 0), next_hop_return = 0;
254 /* rte_lpm_lookup: lpm == NULL */
255 status = rte_lpm_lookup(NULL, ip, &next_hop_return);
256 TEST_LPM_ASSERT(status < 0);
258 /*Create vaild lpm to use in rest of test. */
259 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
260 TEST_LPM_ASSERT(lpm != NULL);
262 /* rte_lpm_lookup: depth < 1 */
263 status = rte_lpm_lookup(lpm, ip, NULL);
264 TEST_LPM_ASSERT(status < 0);
274 * Call add, lookup and delete for a single rule with depth <= 24
279 struct rte_lpm *lpm = NULL;
280 struct rte_lpm_config config;
282 config.max_rules = MAX_RULES;
283 config.number_tbl8s = NUMBER_TBL8S;
285 uint32_t ip = RTE_IPV4(0, 0, 0, 0), next_hop_add = 100, next_hop_return = 0;
289 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
290 TEST_LPM_ASSERT(lpm != NULL);
292 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
293 TEST_LPM_ASSERT(status == 0);
295 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
296 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
298 status = rte_lpm_delete(lpm, ip, depth);
299 TEST_LPM_ASSERT(status == 0);
301 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
302 TEST_LPM_ASSERT(status == -ENOENT);
310 * Call add, lookup and delete for a single rule with depth > 24
318 struct rte_lpm *lpm = NULL;
319 struct rte_lpm_config config;
321 config.max_rules = MAX_RULES;
322 config.number_tbl8s = NUMBER_TBL8S;
324 uint32_t ip = RTE_IPV4(0, 0, 0, 0), next_hop_add = 100, next_hop_return = 0;
328 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
329 TEST_LPM_ASSERT(lpm != NULL);
331 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
332 TEST_LPM_ASSERT(status == 0);
334 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
335 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
337 ipx4 = vect_set_epi32(ip, ip + 0x100, ip - 0x100, ip);
338 rte_lpm_lookupx4(lpm, ipx4, hop, UINT32_MAX);
339 TEST_LPM_ASSERT(hop[0] == next_hop_add);
340 TEST_LPM_ASSERT(hop[1] == UINT32_MAX);
341 TEST_LPM_ASSERT(hop[2] == UINT32_MAX);
342 TEST_LPM_ASSERT(hop[3] == next_hop_add);
344 status = rte_lpm_delete(lpm, ip, depth);
345 TEST_LPM_ASSERT(status == 0);
347 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
348 TEST_LPM_ASSERT(status == -ENOENT);
356 * Use rte_lpm_add to add rules which effect only the second half of the lpm
357 * table. Use all possible depths ranging from 1..32. Set the next hop = to the
358 * depth. Check lookup hit for on every add and check for lookup miss on the
359 * first half of the lpm table after each add. Finally delete all rules going
360 * backwards (i.e. from depth = 32 ..1) and carry out a lookup after each
361 * delete. The lookup should return the next_hop_add value related to the
362 * previous depth value (i.e. depth -1).
369 struct rte_lpm *lpm = NULL;
370 struct rte_lpm_config config;
372 config.max_rules = MAX_RULES;
373 config.number_tbl8s = NUMBER_TBL8S;
375 uint32_t ip1 = RTE_IPV4(127, 255, 255, 255), ip2 = RTE_IPV4(128, 0, 0, 0);
376 uint32_t next_hop_add, next_hop_return;
380 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
381 TEST_LPM_ASSERT(lpm != NULL);
383 /* Loop with rte_lpm_add. */
384 for (depth = 1; depth <= 32; depth++) {
385 /* Let the next_hop_add value = depth. Just for change. */
386 next_hop_add = depth;
388 status = rte_lpm_add(lpm, ip2, depth, next_hop_add);
389 TEST_LPM_ASSERT(status == 0);
391 /* Check IP in first half of tbl24 which should be empty. */
392 status = rte_lpm_lookup(lpm, ip1, &next_hop_return);
393 TEST_LPM_ASSERT(status == -ENOENT);
395 status = rte_lpm_lookup(lpm, ip2, &next_hop_return);
396 TEST_LPM_ASSERT((status == 0) &&
397 (next_hop_return == next_hop_add));
399 ipx4 = vect_set_epi32(ip2, ip1, ip2, ip1);
400 rte_lpm_lookupx4(lpm, ipx4, hop, UINT32_MAX);
401 TEST_LPM_ASSERT(hop[0] == UINT32_MAX);
402 TEST_LPM_ASSERT(hop[1] == next_hop_add);
403 TEST_LPM_ASSERT(hop[2] == UINT32_MAX);
404 TEST_LPM_ASSERT(hop[3] == next_hop_add);
407 /* Loop with rte_lpm_delete. */
408 for (depth = 32; depth >= 1; depth--) {
409 next_hop_add = (uint8_t) (depth - 1);
411 status = rte_lpm_delete(lpm, ip2, depth);
412 TEST_LPM_ASSERT(status == 0);
414 status = rte_lpm_lookup(lpm, ip2, &next_hop_return);
417 TEST_LPM_ASSERT((status == 0) &&
418 (next_hop_return == next_hop_add));
420 TEST_LPM_ASSERT(status == -ENOENT);
423 status = rte_lpm_lookup(lpm, ip1, &next_hop_return);
424 TEST_LPM_ASSERT(status == -ENOENT);
426 ipx4 = vect_set_epi32(ip1, ip1, ip2, ip2);
427 rte_lpm_lookupx4(lpm, ipx4, hop, UINT32_MAX);
429 TEST_LPM_ASSERT(hop[0] == next_hop_add);
430 TEST_LPM_ASSERT(hop[1] == next_hop_add);
432 TEST_LPM_ASSERT(hop[0] == UINT32_MAX);
433 TEST_LPM_ASSERT(hop[1] == UINT32_MAX);
435 TEST_LPM_ASSERT(hop[2] == UINT32_MAX);
436 TEST_LPM_ASSERT(hop[3] == UINT32_MAX);
445 * - Add & lookup to hit invalid TBL24 entry
446 * - Add & lookup to hit valid TBL24 entry not extended
447 * - Add & lookup to hit valid extended TBL24 entry with invalid TBL8 entry
448 * - Add & lookup to hit valid extended TBL24 entry with valid TBL8 entry
454 struct rte_lpm *lpm = NULL;
455 struct rte_lpm_config config;
457 config.max_rules = MAX_RULES;
458 config.number_tbl8s = NUMBER_TBL8S;
460 uint32_t ip, ip_1, ip_2;
461 uint8_t depth, depth_1, depth_2;
462 uint32_t next_hop_add, next_hop_add_1, next_hop_add_2, next_hop_return;
465 /* Add & lookup to hit invalid TBL24 entry */
466 ip = RTE_IPV4(128, 0, 0, 0);
470 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
471 TEST_LPM_ASSERT(lpm != NULL);
473 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
474 TEST_LPM_ASSERT(status == 0);
476 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
477 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
479 status = rte_lpm_delete(lpm, ip, depth);
480 TEST_LPM_ASSERT(status == 0);
482 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
483 TEST_LPM_ASSERT(status == -ENOENT);
485 rte_lpm_delete_all(lpm);
487 /* Add & lookup to hit valid TBL24 entry not extended */
488 ip = RTE_IPV4(128, 0, 0, 0);
492 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
493 TEST_LPM_ASSERT(status == 0);
495 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
496 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
501 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
502 TEST_LPM_ASSERT(status == 0);
504 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
505 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
509 status = rte_lpm_delete(lpm, ip, depth);
510 TEST_LPM_ASSERT(status == 0);
514 status = rte_lpm_delete(lpm, ip, depth);
515 TEST_LPM_ASSERT(status == 0);
517 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
518 TEST_LPM_ASSERT(status == -ENOENT);
520 rte_lpm_delete_all(lpm);
522 /* Add & lookup to hit valid extended TBL24 entry with invalid TBL8
524 ip = RTE_IPV4(128, 0, 0, 0);
528 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
529 TEST_LPM_ASSERT(status == 0);
531 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
532 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
534 ip = RTE_IPV4(128, 0, 0, 5);
538 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
539 TEST_LPM_ASSERT(status == 0);
541 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
542 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
544 status = rte_lpm_delete(lpm, ip, depth);
545 TEST_LPM_ASSERT(status == 0);
547 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
548 TEST_LPM_ASSERT(status == -ENOENT);
550 ip = RTE_IPV4(128, 0, 0, 0);
554 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
555 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
557 status = rte_lpm_delete(lpm, ip, depth);
558 TEST_LPM_ASSERT(status == 0);
560 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
561 TEST_LPM_ASSERT(status == -ENOENT);
563 rte_lpm_delete_all(lpm);
565 /* Add & lookup to hit valid extended TBL24 entry with valid TBL8
567 ip_1 = RTE_IPV4(128, 0, 0, 0);
569 next_hop_add_1 = 101;
571 ip_2 = RTE_IPV4(128, 0, 0, 5);
573 next_hop_add_2 = 102;
577 status = rte_lpm_add(lpm, ip_1, depth_1, next_hop_add_1);
578 TEST_LPM_ASSERT(status == 0);
580 status = rte_lpm_lookup(lpm, ip_1, &next_hop_return);
581 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add_1));
583 status = rte_lpm_add(lpm, ip_2, depth_2, next_hop_add_2);
584 TEST_LPM_ASSERT(status == 0);
586 status = rte_lpm_lookup(lpm, ip_2, &next_hop_return);
587 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add_2));
589 status = rte_lpm_delete(lpm, ip_2, depth_2);
590 TEST_LPM_ASSERT(status == 0);
592 status = rte_lpm_lookup(lpm, ip_2, &next_hop_return);
593 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add_1));
595 status = rte_lpm_delete(lpm, ip_1, depth_1);
596 TEST_LPM_ASSERT(status == 0);
598 status = rte_lpm_lookup(lpm, ip_1, &next_hop_return);
599 TEST_LPM_ASSERT(status == -ENOENT);
608 * - Add rule that covers a TBL24 range previously invalid & lookup (& delete &
610 * - Add rule that extends a TBL24 invalid entry & lookup (& delete & lookup)
611 * - Add rule that extends a TBL24 valid entry & lookup for both rules (&
613 * - Add rule that updates the next hop in TBL24 & lookup (& delete & lookup)
614 * - Add rule that updates the next hop in TBL8 & lookup (& delete & lookup)
615 * - Delete a rule that is not present in the TBL24 & lookup
616 * - Delete a rule that is not present in the TBL8 & lookup
623 struct rte_lpm *lpm = NULL;
624 struct rte_lpm_config config;
626 config.max_rules = MAX_RULES;
627 config.number_tbl8s = NUMBER_TBL8S;
629 uint32_t ip, next_hop_add, next_hop_return;
633 /* Add rule that covers a TBL24 range previously invalid & lookup
634 * (& delete & lookup) */
635 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
636 TEST_LPM_ASSERT(lpm != NULL);
638 ip = RTE_IPV4(128, 0, 0, 0);
642 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
643 TEST_LPM_ASSERT(status == 0);
645 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
646 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
648 status = rte_lpm_delete(lpm, ip, depth);
649 TEST_LPM_ASSERT(status == 0);
651 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
652 TEST_LPM_ASSERT(status == -ENOENT);
654 rte_lpm_delete_all(lpm);
656 ip = RTE_IPV4(128, 0, 0, 0);
660 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
661 TEST_LPM_ASSERT(status == 0);
663 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
664 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
666 status = rte_lpm_delete(lpm, ip, depth);
667 TEST_LPM_ASSERT(status == 0);
669 rte_lpm_delete_all(lpm);
671 /* Add rule that extends a TBL24 valid entry & lookup for both rules
672 * (& delete & lookup) */
674 ip = RTE_IPV4(128, 0, 0, 0);
678 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
679 TEST_LPM_ASSERT(status == 0);
681 ip = RTE_IPV4(128, 0, 0, 10);
685 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
686 TEST_LPM_ASSERT(status == 0);
688 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
689 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
691 ip = RTE_IPV4(128, 0, 0, 0);
694 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
695 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
697 ip = RTE_IPV4(128, 0, 0, 0);
700 status = rte_lpm_delete(lpm, ip, depth);
701 TEST_LPM_ASSERT(status == 0);
703 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
704 TEST_LPM_ASSERT(status == -ENOENT);
706 ip = RTE_IPV4(128, 0, 0, 10);
709 status = rte_lpm_delete(lpm, ip, depth);
710 TEST_LPM_ASSERT(status == 0);
712 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
713 TEST_LPM_ASSERT(status == -ENOENT);
715 rte_lpm_delete_all(lpm);
717 /* Add rule that updates the next hop in TBL24 & lookup
718 * (& delete & lookup) */
720 ip = RTE_IPV4(128, 0, 0, 0);
724 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
725 TEST_LPM_ASSERT(status == 0);
727 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
728 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
732 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
733 TEST_LPM_ASSERT(status == 0);
735 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
736 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
738 status = rte_lpm_delete(lpm, ip, depth);
739 TEST_LPM_ASSERT(status == 0);
741 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
742 TEST_LPM_ASSERT(status == -ENOENT);
744 rte_lpm_delete_all(lpm);
746 /* Add rule that updates the next hop in TBL8 & lookup
747 * (& delete & lookup) */
749 ip = RTE_IPV4(128, 0, 0, 0);
753 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
754 TEST_LPM_ASSERT(status == 0);
756 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
757 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
761 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
762 TEST_LPM_ASSERT(status == 0);
764 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
765 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
767 status = rte_lpm_delete(lpm, ip, depth);
768 TEST_LPM_ASSERT(status == 0);
770 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
771 TEST_LPM_ASSERT(status == -ENOENT);
773 rte_lpm_delete_all(lpm);
775 /* Delete a rule that is not present in the TBL24 & lookup */
777 ip = RTE_IPV4(128, 0, 0, 0);
780 status = rte_lpm_delete(lpm, ip, depth);
781 TEST_LPM_ASSERT(status < 0);
783 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
784 TEST_LPM_ASSERT(status == -ENOENT);
786 rte_lpm_delete_all(lpm);
788 /* Delete a rule that is not present in the TBL8 & lookup */
790 ip = RTE_IPV4(128, 0, 0, 0);
793 status = rte_lpm_delete(lpm, ip, depth);
794 TEST_LPM_ASSERT(status < 0);
796 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
797 TEST_LPM_ASSERT(status == -ENOENT);
805 * Add two rules, lookup to hit the more specific one, lookup to hit the less
806 * specific one delete the less specific rule and lookup previous values again;
807 * add a more specific rule than the existing rule, lookup again
814 struct rte_lpm *lpm = NULL;
815 struct rte_lpm_config config;
817 config.max_rules = MAX_RULES;
818 config.number_tbl8s = NUMBER_TBL8S;
820 uint32_t ip, next_hop_add, next_hop_return;
824 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
825 TEST_LPM_ASSERT(lpm != NULL);
827 ip = RTE_IPV4(128, 0, 0, 0);
831 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
832 TEST_LPM_ASSERT(status == 0);
834 ip = RTE_IPV4(128, 0, 0, 10);
838 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
839 TEST_LPM_ASSERT(status == 0);
841 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
842 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
844 ip = RTE_IPV4(128, 0, 0, 0);
847 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
848 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
850 ip = RTE_IPV4(128, 0, 0, 0);
853 status = rte_lpm_delete(lpm, ip, depth);
854 TEST_LPM_ASSERT(status == 0);
856 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
857 TEST_LPM_ASSERT(status == -ENOENT);
859 ip = RTE_IPV4(128, 0, 0, 10);
862 status = rte_lpm_delete(lpm, ip, depth);
863 TEST_LPM_ASSERT(status == 0);
865 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
866 TEST_LPM_ASSERT(status == -ENOENT);
874 * Add an extended rule (i.e. depth greater than 24, lookup (hit), delete,
875 * lookup (miss) in a for loop of 1000 times. This will check tbl8 extension
885 struct rte_lpm *lpm = NULL;
886 struct rte_lpm_config config;
888 config.max_rules = MAX_RULES;
889 config.number_tbl8s = NUMBER_TBL8S;
891 uint32_t ip, i, next_hop_add, next_hop_return;
895 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
896 TEST_LPM_ASSERT(lpm != NULL);
898 ip = RTE_IPV4(128, 0, 0, 0);
902 for (i = 0; i < 1000; i++) {
903 status = rte_lpm_add(lpm, ip, depth, next_hop_add);
904 TEST_LPM_ASSERT(status == 0);
906 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
907 TEST_LPM_ASSERT((status == 0) &&
908 (next_hop_return == next_hop_add));
910 ipx4 = vect_set_epi32(ip, ip + 1, ip, ip - 1);
911 rte_lpm_lookupx4(lpm, ipx4, hop, UINT32_MAX);
912 TEST_LPM_ASSERT(hop[0] == UINT32_MAX);
913 TEST_LPM_ASSERT(hop[1] == next_hop_add);
914 TEST_LPM_ASSERT(hop[2] == UINT32_MAX);
915 TEST_LPM_ASSERT(hop[3] == next_hop_add);
917 status = rte_lpm_delete(lpm, ip, depth);
918 TEST_LPM_ASSERT(status == 0);
920 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
921 TEST_LPM_ASSERT(status == -ENOENT);
930 * Add a rule to tbl24, lookup (hit), then add a rule that will extend this
931 * tbl24 entry, lookup (hit). delete the rule that caused the tbl24 extension,
932 * lookup (miss) and repeat for loop of 1000 times. This will check tbl8
933 * extension and contraction.
940 struct rte_lpm *lpm = NULL;
941 struct rte_lpm_config config;
943 config.max_rules = MAX_RULES;
944 config.number_tbl8s = NUMBER_TBL8S;
946 uint32_t ip, i, next_hop_add_1, next_hop_add_2, next_hop_return;
950 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
951 TEST_LPM_ASSERT(lpm != NULL);
953 ip = RTE_IPV4(128, 0, 0, 0);
955 next_hop_add_1 = 100;
957 status = rte_lpm_add(lpm, ip, depth, next_hop_add_1);
958 TEST_LPM_ASSERT(status == 0);
960 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
961 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add_1));
964 next_hop_add_2 = 101;
966 for (i = 0; i < 1000; i++) {
967 status = rte_lpm_add(lpm, ip, depth, next_hop_add_2);
968 TEST_LPM_ASSERT(status == 0);
970 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
971 TEST_LPM_ASSERT((status == 0) &&
972 (next_hop_return == next_hop_add_2));
974 status = rte_lpm_delete(lpm, ip, depth);
975 TEST_LPM_ASSERT(status == 0);
977 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
978 TEST_LPM_ASSERT((status == 0) &&
979 (next_hop_return == next_hop_add_1));
984 status = rte_lpm_delete(lpm, ip, depth);
985 TEST_LPM_ASSERT(status == 0);
987 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
988 TEST_LPM_ASSERT(status == -ENOENT);
996 * For TBL8 extension exhaustion. Add 512 rules that require a tbl8 extension.
997 * No more tbl8 extensions will be allowed. Now add one more rule that required
998 * a tbl8 extension and get fail.
1004 /* We only use depth = 32 in the loop below so we must make sure
1005 * that we have enough storage for all rules at that depth*/
1007 struct rte_lpm *lpm = NULL;
1008 struct rte_lpm_config config;
1010 config.max_rules = 256 * 32;
1011 config.number_tbl8s = 512;
1013 uint32_t ip, next_hop_base, next_hop_return;
1019 /* Add enough space for 256 rules for every depth */
1020 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
1021 TEST_LPM_ASSERT(lpm != NULL);
1024 next_hop_base = 100;
1025 ip = RTE_IPV4(0, 0, 0, 0);
1027 /* Add 256 rules that require a tbl8 extension */
1028 for (; ip <= RTE_IPV4(0, 1, 255, 0); ip += 256) {
1029 status = rte_lpm_add(lpm, ip, depth, next_hop_base + ip);
1030 TEST_LPM_ASSERT(status == 0);
1032 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
1033 TEST_LPM_ASSERT((status == 0) &&
1034 (next_hop_return == next_hop_base + ip));
1036 ipx4 = vect_set_epi32(ip + 3, ip + 2, ip + 1, ip);
1037 rte_lpm_lookupx4(lpm, ipx4, hop, UINT32_MAX);
1038 TEST_LPM_ASSERT(hop[0] == next_hop_base + ip);
1039 TEST_LPM_ASSERT(hop[1] == UINT32_MAX);
1040 TEST_LPM_ASSERT(hop[2] == UINT32_MAX);
1041 TEST_LPM_ASSERT(hop[3] == UINT32_MAX);
1044 /* All tbl8 extensions have been used above. Try to add one more and
1046 ip = RTE_IPV4(1, 0, 0, 0);
1049 status = rte_lpm_add(lpm, ip, depth, next_hop_base + ip);
1050 TEST_LPM_ASSERT(status < 0);
1058 * Sequence of operations for find existing lpm table
1061 * - find existing table: hit
1062 * - find non-existing table: miss
1068 struct rte_lpm *lpm = NULL, *result = NULL;
1069 struct rte_lpm_config config;
1071 config.max_rules = 256 * 32;
1072 config.number_tbl8s = NUMBER_TBL8S;
1076 lpm = rte_lpm_create("lpm_find_existing", SOCKET_ID_ANY, &config);
1077 TEST_LPM_ASSERT(lpm != NULL);
1079 /* Try to find existing lpm */
1080 result = rte_lpm_find_existing("lpm_find_existing");
1081 TEST_LPM_ASSERT(result == lpm);
1083 /* Try to find non-existing lpm */
1084 result = rte_lpm_find_existing("lpm_find_non_existing");
1085 TEST_LPM_ASSERT(result == NULL);
1088 rte_lpm_delete_all(lpm);
1095 * test failure condition of overloading the tbl8 so no more will fit
1096 * Check we get an error return value in that case
1102 struct rte_lpm_config config;
1104 config.max_rules = 256 * 32;
1105 config.number_tbl8s = NUMBER_TBL8S;
1107 struct rte_lpm *lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
1109 /* ip loops through all possibilities for top 24 bits of address */
1110 for (ip = 0; ip < 0xFFFFFF; ip++) {
1111 /* add an entry within a different tbl8 each time, since
1112 * depth >24 and the top 24 bits are different */
1113 if (rte_lpm_add(lpm, (ip << 8) + 0xF0, 30, 0) < 0)
1117 if (ip != NUMBER_TBL8S) {
1118 printf("Error, unexpected failure with filling tbl8 groups\n");
1119 printf("Failed after %u additions, expected after %u\n",
1120 (unsigned)ip, (unsigned)NUMBER_TBL8S);
1128 * Test for overwriting of tbl8:
1129 * - add rule /32 and lookup
1130 * - add new rule /24 and lookup
1131 * - add third rule /25 and lookup
1132 * - lookup /32 and /24 rule to ensure the table has not been overwritten.
1137 struct rte_lpm *lpm = NULL;
1138 struct rte_lpm_config config;
1140 config.max_rules = MAX_RULES;
1141 config.number_tbl8s = NUMBER_TBL8S;
1143 const uint32_t ip_10_32 = RTE_IPV4(10, 10, 10, 2);
1144 const uint32_t ip_10_24 = RTE_IPV4(10, 10, 10, 0);
1145 const uint32_t ip_20_25 = RTE_IPV4(10, 10, 20, 2);
1146 const uint8_t d_ip_10_32 = 32,
1149 const uint32_t next_hop_ip_10_32 = 100,
1150 next_hop_ip_10_24 = 105,
1151 next_hop_ip_20_25 = 111;
1152 uint32_t next_hop_return = 0;
1155 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
1156 TEST_LPM_ASSERT(lpm != NULL);
1158 if ((status = rte_lpm_add(lpm, ip_10_32, d_ip_10_32,
1159 next_hop_ip_10_32)) < 0)
1162 status = rte_lpm_lookup(lpm, ip_10_32, &next_hop_return);
1163 uint32_t test_hop_10_32 = next_hop_return;
1164 TEST_LPM_ASSERT(status == 0);
1165 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_10_32);
1167 if ((status = rte_lpm_add(lpm, ip_10_24, d_ip_10_24,
1168 next_hop_ip_10_24)) < 0)
1171 status = rte_lpm_lookup(lpm, ip_10_24, &next_hop_return);
1172 uint32_t test_hop_10_24 = next_hop_return;
1173 TEST_LPM_ASSERT(status == 0);
1174 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_10_24);
1176 if ((status = rte_lpm_add(lpm, ip_20_25, d_ip_20_25,
1177 next_hop_ip_20_25)) < 0)
1180 status = rte_lpm_lookup(lpm, ip_20_25, &next_hop_return);
1181 uint32_t test_hop_20_25 = next_hop_return;
1182 TEST_LPM_ASSERT(status == 0);
1183 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_20_25);
1185 if (test_hop_10_32 == test_hop_10_24) {
1186 printf("Next hop return equal\n");
1190 if (test_hop_10_24 == test_hop_20_25) {
1191 printf("Next hop return equal\n");
1195 status = rte_lpm_lookup(lpm, ip_10_32, &next_hop_return);
1196 TEST_LPM_ASSERT(status == 0);
1197 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_10_32);
1199 status = rte_lpm_lookup(lpm, ip_10_24, &next_hop_return);
1200 TEST_LPM_ASSERT(status == 0);
1201 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_10_24);
1209 * Test for recycle of tbl8
1210 * - step 1: add a rule with depth=28 (> 24)
1211 * - step 2: add a rule with same 24-bit prefix and depth=23 (< 24)
1212 * - step 3: delete the first rule
1213 * - step 4: check tbl8 is freed
1214 * - step 5: add a rule same as the first one (depth=28)
1215 * - step 6: check same tbl8 is allocated
1216 * - step 7: add a rule with same 24-bit prefix and depth=24
1217 * - step 8: delete the rule (depth=28) added in step 5
1218 * - step 9: check tbl8 is freed
1219 * - step 10: add a rule with same 24-bit prefix and depth = 28
1220 * - setp 11: check same tbl8 is allocated again
1225 #define group_idx next_hop
1226 struct rte_lpm *lpm = NULL;
1227 struct rte_lpm_config config;
1228 uint32_t ip, next_hop;
1230 uint32_t tbl8_group_index;
1232 config.max_rules = MAX_RULES;
1233 config.number_tbl8s = NUMBER_TBL8S;
1236 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
1237 TEST_LPM_ASSERT(lpm != NULL);
1239 ip = RTE_IPV4(192, 168, 100, 100);
1242 rte_lpm_add(lpm, ip, depth, next_hop);
1244 TEST_LPM_ASSERT(lpm->tbl24[ip>>8].valid_group);
1245 tbl8_group_index = lpm->tbl24[ip>>8].group_idx;
1249 rte_lpm_add(lpm, ip, depth, next_hop);
1250 TEST_LPM_ASSERT(lpm->tbl24[ip>>8].valid_group);
1253 rte_lpm_delete(lpm, ip, depth);
1255 TEST_LPM_ASSERT(!lpm->tbl24[ip>>8].valid_group);
1258 rte_lpm_add(lpm, ip, depth, next_hop);
1260 TEST_LPM_ASSERT(lpm->tbl24[ip>>8].valid_group);
1261 TEST_LPM_ASSERT(tbl8_group_index == lpm->tbl24[ip>>8].group_idx);
1265 rte_lpm_add(lpm, ip, depth, next_hop);
1266 TEST_LPM_ASSERT(lpm->tbl24[ip>>8].valid_group);
1269 rte_lpm_delete(lpm, ip, depth);
1271 TEST_LPM_ASSERT(!lpm->tbl24[ip>>8].valid_group);
1274 rte_lpm_add(lpm, ip, depth, next_hop);
1276 TEST_LPM_ASSERT(lpm->tbl24[ip>>8].valid_group);
1277 TEST_LPM_ASSERT(tbl8_group_index == lpm->tbl24[ip>>8].group_idx);
1285 * rte_lpm_rcu_qsbr_add positive and negative tests.
1286 * - Add RCU QSBR variable to LPM
1287 * - Add another RCU QSBR variable to LPM
1293 struct rte_lpm *lpm = NULL;
1294 struct rte_lpm_config config;
1296 struct rte_rcu_qsbr *qsv;
1297 struct rte_rcu_qsbr *qsv2;
1299 struct rte_lpm_rcu_config rcu_cfg = {0};
1301 config.max_rules = MAX_RULES;
1302 config.number_tbl8s = NUMBER_TBL8S;
1305 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
1306 TEST_LPM_ASSERT(lpm != NULL);
1308 /* Create RCU QSBR variable */
1309 sz = rte_rcu_qsbr_get_memsize(RTE_MAX_LCORE);
1310 qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket(NULL, sz,
1311 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1312 TEST_LPM_ASSERT(qsv != NULL);
1314 status = rte_rcu_qsbr_init(qsv, RTE_MAX_LCORE);
1315 TEST_LPM_ASSERT(status == 0);
1318 /* Invalid QSBR mode */
1320 status = rte_lpm_rcu_qsbr_add(lpm, &rcu_cfg);
1321 TEST_LPM_ASSERT(status != 0);
1323 rcu_cfg.mode = RTE_LPM_QSBR_MODE_DQ;
1324 /* Attach RCU QSBR to LPM table */
1325 status = rte_lpm_rcu_qsbr_add(lpm, &rcu_cfg);
1326 TEST_LPM_ASSERT(status == 0);
1328 /* Create and attach another RCU QSBR to LPM table */
1329 qsv2 = (struct rte_rcu_qsbr *)rte_zmalloc_socket(NULL, sz,
1330 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1331 TEST_LPM_ASSERT(qsv2 != NULL);
1334 rcu_cfg.mode = RTE_LPM_QSBR_MODE_SYNC;
1335 status = rte_lpm_rcu_qsbr_add(lpm, &rcu_cfg);
1336 TEST_LPM_ASSERT(status != 0);
1346 * rte_lpm_rcu_qsbr_add DQ mode functional test.
1347 * Reader and writer are in the same thread in this test.
1348 * - Create LPM which supports 1 tbl8 group at max
1349 * - Add RCU QSBR variable to LPM
1350 * - Add a rule with depth=28 (> 24)
1351 * - Register a reader thread (not a real thread)
1352 * - Reader lookup existing rule
1353 * - Writer delete the rule
1354 * - Reader lookup the rule
1355 * - Writer re-add the rule (no available tbl8 group)
1356 * - Reader report quiescent state and unregister
1357 * - Writer re-add the rule
1358 * - Reader lookup the rule
1363 struct rte_lpm *lpm = NULL;
1364 struct rte_lpm_config config;
1366 struct rte_rcu_qsbr *qsv;
1368 uint32_t ip, next_hop, next_hop_return;
1370 struct rte_lpm_rcu_config rcu_cfg = {0};
1372 config.max_rules = MAX_RULES;
1373 config.number_tbl8s = 1;
1376 lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
1377 TEST_LPM_ASSERT(lpm != NULL);
1379 /* Create RCU QSBR variable */
1380 sz = rte_rcu_qsbr_get_memsize(1);
1381 qsv = (struct rte_rcu_qsbr *)rte_zmalloc_socket(NULL, sz,
1382 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1383 TEST_LPM_ASSERT(qsv != NULL);
1385 status = rte_rcu_qsbr_init(qsv, 1);
1386 TEST_LPM_ASSERT(status == 0);
1389 rcu_cfg.mode = RTE_LPM_QSBR_MODE_DQ;
1390 /* Attach RCU QSBR to LPM table */
1391 status = rte_lpm_rcu_qsbr_add(lpm, &rcu_cfg);
1392 TEST_LPM_ASSERT(status == 0);
1394 ip = RTE_IPV4(192, 0, 2, 100);
1397 status = rte_lpm_add(lpm, ip, depth, next_hop);
1398 TEST_LPM_ASSERT(status == 0);
1399 TEST_LPM_ASSERT(lpm->tbl24[ip>>8].valid_group);
1401 /* Register pseudo reader */
1402 status = rte_rcu_qsbr_thread_register(qsv, 0);
1403 TEST_LPM_ASSERT(status == 0);
1404 rte_rcu_qsbr_thread_online(qsv, 0);
1406 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
1407 TEST_LPM_ASSERT(status == 0);
1408 TEST_LPM_ASSERT(next_hop_return == next_hop);
1411 status = rte_lpm_delete(lpm, ip, depth);
1412 TEST_LPM_ASSERT(status == 0);
1413 TEST_LPM_ASSERT(!lpm->tbl24[ip>>8].valid);
1415 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
1416 TEST_LPM_ASSERT(status != 0);
1418 status = rte_lpm_add(lpm, ip, depth, next_hop);
1419 TEST_LPM_ASSERT(status != 0);
1421 /* Reader quiescent */
1422 rte_rcu_qsbr_quiescent(qsv, 0);
1424 status = rte_lpm_add(lpm, ip, depth, next_hop);
1425 TEST_LPM_ASSERT(status == 0);
1427 rte_rcu_qsbr_thread_offline(qsv, 0);
1428 status = rte_rcu_qsbr_thread_unregister(qsv, 0);
1429 TEST_LPM_ASSERT(status == 0);
1431 status = rte_lpm_lookup(lpm, ip, &next_hop_return);
1432 TEST_LPM_ASSERT(status == 0);
1433 TEST_LPM_ASSERT(next_hop_return == next_hop);
1441 static struct rte_lpm *g_lpm;
1442 static struct rte_rcu_qsbr *g_v;
1443 static uint32_t g_ip = RTE_IPV4(192, 0, 2, 100);
1444 static volatile uint8_t writer_done;
1445 /* Report quiescent state interval every 1024 lookups. Larger critical
1446 * sections in reader will result in writer polling multiple times.
1448 #define QSBR_REPORTING_INTERVAL 1024
1449 #define WRITER_ITERATIONS 512
1452 * Reader thread using rte_lpm data structure with RCU.
1455 test_lpm_rcu_qsbr_reader(void *arg)
1458 uint32_t next_hop_return = 0;
1461 /* Register this thread to report quiescent state */
1462 rte_rcu_qsbr_thread_register(g_v, 0);
1463 rte_rcu_qsbr_thread_online(g_v, 0);
1466 for (i = 0; i < QSBR_REPORTING_INTERVAL; i++)
1467 rte_lpm_lookup(g_lpm, g_ip, &next_hop_return);
1469 /* Update quiescent state */
1470 rte_rcu_qsbr_quiescent(g_v, 0);
1471 } while (!writer_done);
1473 rte_rcu_qsbr_thread_offline(g_v, 0);
1474 rte_rcu_qsbr_thread_unregister(g_v, 0);
1480 * rte_lpm_rcu_qsbr_add sync mode functional test.
1481 * 1 Reader and 1 writer. They cannot be in the same thread in this test.
1482 * - Create LPM which supports 1 tbl8 group at max
1483 * - Add RCU QSBR variable with sync mode to LPM
1484 * - Register a reader thread. Reader keeps looking up a specific rule.
1485 * - Writer keeps adding and deleting a specific rule with depth=28 (> 24)
1490 struct rte_lpm_config config;
1493 uint32_t i, next_hop;
1495 struct rte_lpm_rcu_config rcu_cfg = {0};
1497 if (rte_lcore_count() < 2) {
1498 printf("Not enough cores for %s, expecting at least 2\n",
1500 return TEST_SKIPPED;
1503 config.max_rules = MAX_RULES;
1504 config.number_tbl8s = 1;
1507 g_lpm = rte_lpm_create(__func__, SOCKET_ID_ANY, &config);
1508 TEST_LPM_ASSERT(g_lpm != NULL);
1510 /* Create RCU QSBR variable */
1511 sz = rte_rcu_qsbr_get_memsize(1);
1512 g_v = (struct rte_rcu_qsbr *)rte_zmalloc_socket(NULL, sz,
1513 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1514 TEST_LPM_ASSERT(g_v != NULL);
1516 status = rte_rcu_qsbr_init(g_v, 1);
1517 TEST_LPM_ASSERT(status == 0);
1520 rcu_cfg.mode = RTE_LPM_QSBR_MODE_SYNC;
1521 /* Attach RCU QSBR to LPM table */
1522 status = rte_lpm_rcu_qsbr_add(g_lpm, &rcu_cfg);
1523 TEST_LPM_ASSERT(status == 0);
1526 /* Launch reader thread */
1527 rte_eal_remote_launch(test_lpm_rcu_qsbr_reader, NULL,
1528 rte_get_next_lcore(-1, 1, 0));
1532 status = rte_lpm_add(g_lpm, g_ip, depth, next_hop);
1534 printf("%s: Failed to add rule\n", __func__);
1539 for (i = 0; i < WRITER_ITERATIONS; i++) {
1540 status = rte_lpm_delete(g_lpm, g_ip, depth);
1542 printf("%s: Failed to delete rule at iteration %d\n",
1547 status = rte_lpm_add(g_lpm, g_ip, depth, next_hop);
1549 printf("%s: Failed to add rule at iteration %d\n",
1557 /* Wait until reader exited. */
1558 rte_eal_mp_wait_lcore();
1560 rte_lpm_free(g_lpm);
1563 return (status == 0) ? PASS : -1;
1567 * Do all unit tests.
1574 int status, global_status = 0;
1576 for (i = 0; i < RTE_DIM(tests); i++) {
1577 status = tests[i]();
1579 printf("ERROR: LPM Test %u: FAIL\n", i);
1580 global_status = status;
1584 return global_status;
1587 REGISTER_TEST_COMMAND(lpm_autotest, test_lpm);