4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <rte_memory.h>
43 #include "test_lpm6_data.h"
45 #define TEST_LPM_ASSERT(cond) do { \
47 printf("Error at line %d: \n", __LINE__); \
52 typedef int32_t (* rte_lpm6_test)(void);
54 static int32_t test0(void);
55 static int32_t test1(void);
56 static int32_t test2(void);
57 static int32_t test3(void);
58 static int32_t test4(void);
59 static int32_t test5(void);
60 static int32_t test6(void);
61 static int32_t test7(void);
62 static int32_t test8(void);
63 static int32_t test9(void);
64 static int32_t test10(void);
65 static int32_t test11(void);
66 static int32_t test12(void);
67 static int32_t test13(void);
68 static int32_t test14(void);
69 static int32_t test15(void);
70 static int32_t test16(void);
71 static int32_t test17(void);
72 static int32_t test18(void);
73 static int32_t test19(void);
74 static int32_t test20(void);
75 static int32_t test21(void);
76 static int32_t test22(void);
77 static int32_t test23(void);
78 static int32_t test24(void);
79 static int32_t test25(void);
80 static int32_t test26(void);
81 static int32_t test27(void);
83 rte_lpm6_test tests6[] = {
115 #define NUM_LPM6_TESTS (sizeof(tests6)/sizeof(tests6[0]))
116 #define MAX_DEPTH 128
117 #define MAX_RULES 1000000
118 #define NUMBER_TBL8S (1 << 16)
119 #define MAX_NUM_TBL8S (1 << 21)
123 IPv6(uint8_t *ip, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5,
124 uint8_t b6, uint8_t b7, uint8_t b8, uint8_t b9, uint8_t b10,
125 uint8_t b11, uint8_t b12, uint8_t b13, uint8_t b14, uint8_t b15,
147 * Check that rte_lpm6_create fails gracefully for incorrect user input
153 struct rte_lpm6 *lpm = NULL;
154 struct rte_lpm6_config config;
156 config.max_rules = MAX_RULES;
157 config.number_tbl8s = NUMBER_TBL8S;
160 /* rte_lpm6_create: lpm name == NULL */
161 lpm = rte_lpm6_create(NULL, SOCKET_ID_ANY, &config);
162 TEST_LPM_ASSERT(lpm == NULL);
164 /* rte_lpm6_create: max_rules = 0 */
165 /* Note: __func__ inserts the function name, in this case "test0". */
166 config.max_rules = 0;
167 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
168 TEST_LPM_ASSERT(lpm == NULL);
170 /* socket_id < -1 is invalid */
171 config.max_rules = MAX_RULES;
172 lpm = rte_lpm6_create(__func__, -2, &config);
173 TEST_LPM_ASSERT(lpm == NULL);
175 /* rte_lpm6_create: number_tbl8s is bigger than the maximum */
176 config.number_tbl8s = MAX_NUM_TBL8S + 1;
177 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
178 TEST_LPM_ASSERT(lpm == NULL);
180 /* rte_lpm6_create: config = NULL */
181 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, NULL);
182 TEST_LPM_ASSERT(lpm == NULL);
188 * Creates two different LPM tables. Tries to create a third one with the same
189 * name as the first one and expects the create function to return the same
195 struct rte_lpm6 *lpm1 = NULL, *lpm2 = NULL, *lpm3 = NULL;
196 struct rte_lpm6_config config;
198 config.max_rules = MAX_RULES;
199 config.number_tbl8s = NUMBER_TBL8S;
202 /* rte_lpm6_create: lpm name == LPM1 */
203 lpm1 = rte_lpm6_create("LPM1", SOCKET_ID_ANY, &config);
204 TEST_LPM_ASSERT(lpm1 != NULL);
206 /* rte_lpm6_create: lpm name == LPM2 */
207 lpm2 = rte_lpm6_create("LPM2", SOCKET_ID_ANY, &config);
208 TEST_LPM_ASSERT(lpm2 != NULL);
210 /* rte_lpm6_create: lpm name == LPM2 */
211 lpm3 = rte_lpm6_create("LPM1", SOCKET_ID_ANY, &config);
212 TEST_LPM_ASSERT(lpm3 == NULL);
221 * Create lpm table then delete lpm table 20 times
222 * Use a slightly different rules size each time
227 struct rte_lpm6 *lpm = NULL;
228 struct rte_lpm6_config config;
231 config.number_tbl8s = NUMBER_TBL8S;
234 /* rte_lpm6_free: Free NULL */
235 for (i = 0; i < 20; i++) {
236 config.max_rules = MAX_RULES - i;
237 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
238 TEST_LPM_ASSERT(lpm != NULL);
243 /* Can not test free so return success */
248 * Call rte_lpm6_free for NULL pointer user input. Note: free has no return and
249 * therefore it is impossible to check for failure but this test is added to
250 * increase function coverage metrics and to validate that freeing null does
256 struct rte_lpm6 *lpm = NULL;
257 struct rte_lpm6_config config;
259 config.max_rules = MAX_RULES;
260 config.number_tbl8s = NUMBER_TBL8S;
263 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
264 TEST_LPM_ASSERT(lpm != NULL);
272 * Check that rte_lpm6_add fails gracefully for incorrect user input arguments
277 struct rte_lpm6 *lpm = NULL;
278 struct rte_lpm6_config config;
280 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
281 uint8_t depth = 24, next_hop = 100;
284 config.max_rules = MAX_RULES;
285 config.number_tbl8s = NUMBER_TBL8S;
288 /* rte_lpm6_add: lpm == NULL */
289 status = rte_lpm6_add(NULL, ip, depth, next_hop);
290 TEST_LPM_ASSERT(status < 0);
292 /*Create vaild lpm to use in rest of test. */
293 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
294 TEST_LPM_ASSERT(lpm != NULL);
296 /* rte_lpm6_add: depth < 1 */
297 status = rte_lpm6_add(lpm, ip, 0, next_hop);
298 TEST_LPM_ASSERT(status < 0);
300 /* rte_lpm6_add: depth > MAX_DEPTH */
301 status = rte_lpm6_add(lpm, ip, (MAX_DEPTH + 1), next_hop);
302 TEST_LPM_ASSERT(status < 0);
310 * Check that rte_lpm6_delete fails gracefully for incorrect user input
316 struct rte_lpm6 *lpm = NULL;
317 struct rte_lpm6_config config;
318 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
322 config.max_rules = MAX_RULES;
323 config.number_tbl8s = NUMBER_TBL8S;
326 /* rte_lpm_delete: lpm == NULL */
327 status = rte_lpm6_delete(NULL, ip, depth);
328 TEST_LPM_ASSERT(status < 0);
330 /*Create vaild lpm to use in rest of test. */
331 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
332 TEST_LPM_ASSERT(lpm != NULL);
334 /* rte_lpm_delete: depth < 1 */
335 status = rte_lpm6_delete(lpm, ip, 0);
336 TEST_LPM_ASSERT(status < 0);
338 /* rte_lpm_delete: depth > MAX_DEPTH */
339 status = rte_lpm6_delete(lpm, ip, (MAX_DEPTH + 1));
340 TEST_LPM_ASSERT(status < 0);
348 * Check that rte_lpm6_lookup fails gracefully for incorrect user input
354 struct rte_lpm6 *lpm = NULL;
355 struct rte_lpm6_config config;
356 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
357 uint8_t next_hop_return = 0;
360 config.max_rules = MAX_RULES;
361 config.number_tbl8s = NUMBER_TBL8S;
364 /* rte_lpm6_lookup: lpm == NULL */
365 status = rte_lpm6_lookup(NULL, ip, &next_hop_return);
366 TEST_LPM_ASSERT(status < 0);
368 /*Create vaild lpm to use in rest of test. */
369 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
370 TEST_LPM_ASSERT(lpm != NULL);
372 /* rte_lpm6_lookup: ip = NULL */
373 status = rte_lpm6_lookup(lpm, NULL, &next_hop_return);
374 TEST_LPM_ASSERT(status < 0);
376 /* rte_lpm6_lookup: next_hop = NULL */
377 status = rte_lpm6_lookup(lpm, ip, NULL);
378 TEST_LPM_ASSERT(status < 0);
386 * Checks that rte_lpm6_lookup_bulk_func fails gracefully for incorrect user
392 struct rte_lpm6 *lpm = NULL;
393 struct rte_lpm6_config config;
395 int16_t next_hop_return[10];
398 config.max_rules = MAX_RULES;
399 config.number_tbl8s = NUMBER_TBL8S;
402 /* rte_lpm6_lookup: lpm == NULL */
403 status = rte_lpm6_lookup_bulk_func(NULL, ip, next_hop_return, 10);
404 TEST_LPM_ASSERT(status < 0);
406 /*Create vaild lpm to use in rest of test. */
407 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
408 TEST_LPM_ASSERT(lpm != NULL);
410 /* rte_lpm6_lookup: ip = NULL */
411 status = rte_lpm6_lookup_bulk_func(lpm, NULL, next_hop_return, 10);
412 TEST_LPM_ASSERT(status < 0);
414 /* rte_lpm6_lookup: next_hop = NULL */
415 status = rte_lpm6_lookup_bulk_func(lpm, ip, NULL, 10);
416 TEST_LPM_ASSERT(status < 0);
424 * Checks that rte_lpm6_delete_bulk_func fails gracefully for incorrect user
430 struct rte_lpm6 *lpm = NULL;
431 struct rte_lpm6_config config;
436 config.max_rules = MAX_RULES;
437 config.number_tbl8s = NUMBER_TBL8S;
440 /* rte_lpm6_delete: lpm == NULL */
441 status = rte_lpm6_delete_bulk_func(NULL, ip, depth, 10);
442 TEST_LPM_ASSERT(status < 0);
444 /*Create vaild lpm to use in rest of test. */
445 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
446 TEST_LPM_ASSERT(lpm != NULL);
448 /* rte_lpm6_delete: ip = NULL */
449 status = rte_lpm6_delete_bulk_func(lpm, NULL, depth, 10);
450 TEST_LPM_ASSERT(status < 0);
452 /* rte_lpm6_delete: next_hop = NULL */
453 status = rte_lpm6_delete_bulk_func(lpm, ip, NULL, 10);
454 TEST_LPM_ASSERT(status < 0);
462 * Call add, lookup and delete for a single rule with depth < 24.
463 * Check all the combinations for the first three bytes that result in a hit.
464 * Delete the rule and check that the same test returs a miss.
469 struct rte_lpm6 *lpm = NULL;
470 struct rte_lpm6_config config;
471 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
472 uint8_t depth = 16, next_hop_add = 100, next_hop_return = 0;
476 config.max_rules = MAX_RULES;
477 config.number_tbl8s = NUMBER_TBL8S;
480 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
481 TEST_LPM_ASSERT(lpm != NULL);
483 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
484 TEST_LPM_ASSERT(status == 0);
486 for (i = 0; i < UINT8_MAX; i++) {
488 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
489 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
492 status = rte_lpm6_delete(lpm, ip, depth);
493 TEST_LPM_ASSERT(status == 0);
495 for (i = 0; i < UINT8_MAX; i++) {
497 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
498 TEST_LPM_ASSERT(status == -ENOENT);
507 * Adds max_rules + 1 and expects a failure. Deletes a rule, then adds
508 * another one and expects success.
513 struct rte_lpm6 *lpm = NULL;
514 struct rte_lpm6_config config;
515 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
516 uint8_t depth, next_hop_add = 100;
520 config.max_rules = 127;
521 config.number_tbl8s = NUMBER_TBL8S;
524 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
525 TEST_LPM_ASSERT(lpm != NULL);
527 for (i = 1; i < 128; i++) {
529 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
530 TEST_LPM_ASSERT(status == 0);
534 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
535 TEST_LPM_ASSERT(status == -ENOSPC);
538 status = rte_lpm6_delete(lpm, ip, depth);
539 TEST_LPM_ASSERT(status == 0);
542 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
543 TEST_LPM_ASSERT(status == 0);
551 * Creates an LPM table with a small number of tbl8s and exhaust them in the
552 * middle of the process of creating a rule.
557 struct rte_lpm6 *lpm = NULL;
558 struct rte_lpm6_config config;
559 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
560 uint8_t depth, next_hop_add = 100;
563 config.max_rules = MAX_RULES;
564 config.number_tbl8s = 16;
567 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
568 TEST_LPM_ASSERT(lpm != NULL);
571 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
572 TEST_LPM_ASSERT(status == 0);
576 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
577 TEST_LPM_ASSERT(status == 0);
579 status = rte_lpm6_delete(lpm, ip, depth);
580 TEST_LPM_ASSERT(status == 0);
583 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
584 TEST_LPM_ASSERT(status == 0);
586 status = rte_lpm6_delete(lpm, ip, depth);
587 TEST_LPM_ASSERT(status == 0);
590 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
591 TEST_LPM_ASSERT(status == 0);
593 status = rte_lpm6_delete(lpm, ip, depth);
594 TEST_LPM_ASSERT(status == 0);
597 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
598 TEST_LPM_ASSERT(status == -ENOSPC);
601 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
602 TEST_LPM_ASSERT(status == 0);
610 * Creates an LPM table with a small number of tbl8s and exhaust them in the
611 * middle of the process of adding a rule when there is already an existing rule
612 * in that position and needs to be extended.
617 struct rte_lpm6 *lpm = NULL;
618 struct rte_lpm6_config config;
619 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
620 uint8_t depth, next_hop_add = 100;
623 config.max_rules = MAX_RULES;
624 config.number_tbl8s = 16;
627 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
628 TEST_LPM_ASSERT(lpm != NULL);
631 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
632 TEST_LPM_ASSERT(status == 0);
636 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
637 TEST_LPM_ASSERT(status == 0);
640 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
641 TEST_LPM_ASSERT(status == -ENOSPC);
649 * Creates an LPM table with max_rules = 2 and tries to add 3 rules.
650 * Delete one of the rules and tries to add the third one again.
655 struct rte_lpm6 *lpm = NULL;
656 struct rte_lpm6_config config;
657 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
658 uint8_t depth, next_hop_add = 100;
661 config.max_rules = 2;
662 config.number_tbl8s = NUMBER_TBL8S;
665 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
666 TEST_LPM_ASSERT(lpm != NULL);
669 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
670 TEST_LPM_ASSERT(status == 0);
673 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
674 TEST_LPM_ASSERT(status == 0);
677 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
678 TEST_LPM_ASSERT(status == -ENOSPC);
681 status = rte_lpm6_delete(lpm, ip, depth);
682 TEST_LPM_ASSERT(status == 0);
685 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
686 TEST_LPM_ASSERT(status == 0);
694 * Add 2^12 routes with different first 12 bits and depth 25.
695 * Add one more route with the same depth and check that results in a failure.
696 * After that delete the last rule and create the one that was attempted to be
697 * created. This checks tbl8 exhaustion.
702 struct rte_lpm6 *lpm = NULL;
703 struct rte_lpm6_config config;
704 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
705 uint8_t depth = 25, next_hop_add = 100;
709 config.max_rules = MAX_RULES;
710 config.number_tbl8s = 256;
713 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
714 TEST_LPM_ASSERT(lpm != NULL);
716 for (i = 0; i < 256; i++) {
718 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
719 TEST_LPM_ASSERT(status == 0);
724 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
725 TEST_LPM_ASSERT(status == -ENOSPC);
729 status = rte_lpm6_delete(lpm, ip, depth);
730 TEST_LPM_ASSERT(status == 0);
734 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
735 TEST_LPM_ASSERT(status == 0);
743 * Call add, lookup and delete for a single rule with depth = 24
748 struct rte_lpm6 *lpm = NULL;
749 struct rte_lpm6_config config;
750 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
751 uint8_t depth = 24, next_hop_add = 100, next_hop_return = 0;
754 config.max_rules = MAX_RULES;
755 config.number_tbl8s = NUMBER_TBL8S;
758 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
759 TEST_LPM_ASSERT(lpm != NULL);
761 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
762 TEST_LPM_ASSERT(status == 0);
764 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
765 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
767 status = rte_lpm6_delete(lpm, ip, depth);
768 TEST_LPM_ASSERT(status == 0);
770 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
771 TEST_LPM_ASSERT(status == -ENOENT);
779 * Call add, lookup and delete for a single rule with depth > 24
784 struct rte_lpm6 *lpm = NULL;
785 struct rte_lpm6_config config;
786 uint8_t ip[] = {12,12,1,0,0,0,0,0,0,0,0,0,0,0,0,0};
787 uint8_t depth = 128, next_hop_add = 100, next_hop_return = 0;
790 config.max_rules = MAX_RULES;
791 config.number_tbl8s = NUMBER_TBL8S;
794 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
795 TEST_LPM_ASSERT(lpm != NULL);
797 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
798 TEST_LPM_ASSERT(status == 0);
800 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
801 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
803 status = rte_lpm6_delete(lpm, ip, depth);
804 TEST_LPM_ASSERT(status == 0);
806 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
807 TEST_LPM_ASSERT(status == -ENOENT);
815 * Use rte_lpm6_add to add rules which effect only the second half of the lpm
816 * table. Use all possible depths ranging from 1..32. Set the next hop = to the
817 * depth. Check lookup hit for on every add and check for lookup miss on the
818 * first half of the lpm table after each add. Finally delete all rules going
819 * backwards (i.e. from depth = 32 ..1) and carry out a lookup after each
820 * delete. The lookup should return the next_hop_add value related to the
821 * previous depth value (i.e. depth -1).
826 struct rte_lpm6 *lpm = NULL;
827 struct rte_lpm6_config config;
828 uint8_t ip1[] = {127,255,255,255,255,255,255,255,255,
829 255,255,255,255,255,255,255};
830 uint8_t ip2[] = {128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
831 uint8_t depth, next_hop_add, next_hop_return;
834 config.max_rules = MAX_RULES;
835 config.number_tbl8s = NUMBER_TBL8S;
838 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
839 TEST_LPM_ASSERT(lpm != NULL);
841 /* Loop with rte_lpm6_add. */
842 for (depth = 1; depth <= 16; depth++) {
843 /* Let the next_hop_add value = depth. Just for change. */
844 next_hop_add = depth;
846 status = rte_lpm6_add(lpm, ip2, depth, next_hop_add);
847 TEST_LPM_ASSERT(status == 0);
849 /* Check IP in first half of tbl24 which should be empty. */
850 status = rte_lpm6_lookup(lpm, ip1, &next_hop_return);
851 TEST_LPM_ASSERT(status == -ENOENT);
853 status = rte_lpm6_lookup(lpm, ip2, &next_hop_return);
854 TEST_LPM_ASSERT((status == 0) &&
855 (next_hop_return == next_hop_add));
858 /* Loop with rte_lpm6_delete. */
859 for (depth = 16; depth >= 1; depth--) {
860 next_hop_add = (uint8_t) (depth - 1);
862 status = rte_lpm6_delete(lpm, ip2, depth);
863 TEST_LPM_ASSERT(status == 0);
865 status = rte_lpm6_lookup(lpm, ip2, &next_hop_return);
868 TEST_LPM_ASSERT((status == 0) &&
869 (next_hop_return == next_hop_add));
872 TEST_LPM_ASSERT(status == -ENOENT);
875 status = rte_lpm6_lookup(lpm, ip1, &next_hop_return);
876 TEST_LPM_ASSERT(status == -ENOENT);
885 * - Add & lookup to hit invalid TBL24 entry
886 * - Add & lookup to hit valid TBL24 entry not extended
887 * - Add & lookup to hit valid extended TBL24 entry with invalid TBL8 entry
888 * - Add & lookup to hit valid extended TBL24 entry with valid TBL8 entry
893 struct rte_lpm6 *lpm = NULL;
894 struct rte_lpm6_config config;
895 uint8_t ip[16], ip_1[16], ip_2[16];
896 uint8_t depth, depth_1, depth_2, next_hop_add, next_hop_add_1,
897 next_hop_add_2, next_hop_return;
900 config.max_rules = MAX_RULES;
901 config.number_tbl8s = NUMBER_TBL8S;
904 /* Add & lookup to hit invalid TBL24 entry */
905 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
909 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
910 TEST_LPM_ASSERT(lpm != NULL);
912 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
913 TEST_LPM_ASSERT(status == 0);
915 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
916 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
918 status = rte_lpm6_delete(lpm, ip, depth);
919 TEST_LPM_ASSERT(status == 0);
921 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
922 TEST_LPM_ASSERT(status == -ENOENT);
924 rte_lpm6_delete_all(lpm);
926 /* Add & lookup to hit valid TBL24 entry not extended */
927 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
931 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
932 TEST_LPM_ASSERT(status == 0);
934 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
935 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
940 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
941 TEST_LPM_ASSERT(status == 0);
943 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
944 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
948 status = rte_lpm6_delete(lpm, ip, depth);
949 TEST_LPM_ASSERT(status == 0);
953 status = rte_lpm6_delete(lpm, ip, depth);
954 TEST_LPM_ASSERT(status == 0);
956 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
957 TEST_LPM_ASSERT(status == -ENOENT);
959 rte_lpm6_delete_all(lpm);
961 /* Add & lookup to hit valid extended TBL24 entry with invalid TBL8
964 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
968 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
969 TEST_LPM_ASSERT(status == 0);
971 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
972 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
974 IPv6(ip, 128, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
978 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
979 TEST_LPM_ASSERT(status == 0);
981 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
982 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
984 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
988 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
989 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
991 status = rte_lpm6_delete(lpm, ip, depth);
992 TEST_LPM_ASSERT(status == 0);
994 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
995 TEST_LPM_ASSERT(status == -ENOENT);
997 rte_lpm6_delete_all(lpm);
999 /* Add & lookup to hit valid extended TBL24 entry with valid TBL8
1002 IPv6(ip_1, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1004 next_hop_add_1 = 101;
1006 IPv6(ip_2, 128, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1008 next_hop_add_2 = 102;
1010 next_hop_return = 0;
1012 status = rte_lpm6_add(lpm, ip_1, depth_1, next_hop_add_1);
1013 TEST_LPM_ASSERT(status == 0);
1015 status = rte_lpm6_lookup(lpm, ip_1, &next_hop_return);
1016 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add_1));
1018 status = rte_lpm6_add(lpm, ip_2, depth_2, next_hop_add_2);
1019 TEST_LPM_ASSERT(status == 0);
1021 status = rte_lpm6_lookup(lpm, ip_2, &next_hop_return);
1022 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add_2));
1024 status = rte_lpm6_delete(lpm, ip_2, depth_2);
1025 TEST_LPM_ASSERT(status == 0);
1027 status = rte_lpm6_lookup(lpm, ip_2, &next_hop_return);
1028 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add_1));
1030 status = rte_lpm6_delete(lpm, ip_1, depth_1);
1031 TEST_LPM_ASSERT(status == 0);
1033 status = rte_lpm6_lookup(lpm, ip_1, &next_hop_return);
1034 TEST_LPM_ASSERT(status == -ENOENT);
1042 * - Add rule that covers a TBL24 range previously invalid & lookup (& delete &
1044 * - Add rule that extends a TBL24 invalid entry & lookup (& delete & lookup)
1045 * - Add rule that extends a TBL24 valid entry & lookup for both rules (&
1047 * - Add rule that updates the next hop in TBL24 & lookup (& delete & lookup)
1048 * - Add rule that updates the next hop in TBL8 & lookup (& delete & lookup)
1049 * - Delete a rule that is not present in the TBL24 & lookup
1050 * - Delete a rule that is not present in the TBL8 & lookup
1055 struct rte_lpm6 *lpm = NULL;
1056 struct rte_lpm6_config config;
1058 uint8_t depth, next_hop_add, next_hop_return;
1061 config.max_rules = MAX_RULES;
1062 config.number_tbl8s = NUMBER_TBL8S;
1065 /* Add rule that covers a TBL24 range previously invalid & lookup
1066 * (& delete & lookup)
1068 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1069 TEST_LPM_ASSERT(lpm != NULL);
1071 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1075 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1076 TEST_LPM_ASSERT(status == 0);
1078 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1079 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1081 status = rte_lpm6_delete(lpm, ip, depth);
1082 TEST_LPM_ASSERT(status == 0);
1084 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1085 TEST_LPM_ASSERT(status == -ENOENT);
1087 rte_lpm6_delete_all(lpm);
1089 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1093 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1094 TEST_LPM_ASSERT(status == 0);
1096 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1097 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1099 status = rte_lpm6_delete(lpm, ip, depth);
1100 TEST_LPM_ASSERT(status == 0);
1102 rte_lpm6_delete_all(lpm);
1105 * Add rule that extends a TBL24 valid entry & lookup for both rules
1106 * (& delete & lookup)
1109 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1113 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1114 TEST_LPM_ASSERT(status == 0);
1116 IPv6(ip, 128, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1120 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1121 TEST_LPM_ASSERT(status == 0);
1123 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1124 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1126 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1129 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1130 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1132 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1135 status = rte_lpm6_delete(lpm, ip, depth);
1136 TEST_LPM_ASSERT(status == 0);
1138 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1139 TEST_LPM_ASSERT(status == -ENOENT);
1141 IPv6(ip, 128, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1144 status = rte_lpm6_delete(lpm, ip, depth);
1145 TEST_LPM_ASSERT(status == 0);
1147 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1148 TEST_LPM_ASSERT(status == -ENOENT);
1150 rte_lpm6_delete_all(lpm);
1153 * Add rule that updates the next hop in TBL24 & lookup
1154 * (& delete & lookup)
1157 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1161 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1162 TEST_LPM_ASSERT(status == 0);
1164 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1165 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1169 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1170 TEST_LPM_ASSERT(status == 0);
1172 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1173 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1175 status = rte_lpm6_delete(lpm, ip, depth);
1176 TEST_LPM_ASSERT(status == 0);
1178 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1179 TEST_LPM_ASSERT(status == -ENOENT);
1181 rte_lpm6_delete_all(lpm);
1184 * Add rule that updates the next hop in TBL8 & lookup
1185 * (& delete & lookup)
1188 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1192 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1193 TEST_LPM_ASSERT(status == 0);
1195 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1196 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1200 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1201 TEST_LPM_ASSERT(status == 0);
1203 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1204 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1206 status = rte_lpm6_delete(lpm, ip, depth);
1207 TEST_LPM_ASSERT(status == 0);
1209 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1210 TEST_LPM_ASSERT(status == -ENOENT);
1212 rte_lpm6_delete_all(lpm);
1214 /* Delete a rule that is not present in the TBL24 & lookup */
1216 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1220 status = rte_lpm6_delete(lpm, ip, depth);
1221 TEST_LPM_ASSERT(status < 0);
1223 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1224 TEST_LPM_ASSERT(status == -ENOENT);
1226 rte_lpm6_delete_all(lpm);
1228 /* Delete a rule that is not present in the TBL8 & lookup */
1230 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1234 status = rte_lpm6_delete(lpm, ip, depth);
1235 TEST_LPM_ASSERT(status < 0);
1237 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1238 TEST_LPM_ASSERT(status == -ENOENT);
1246 * Add two rules, lookup to hit the more specific one, lookup to hit the less
1247 * specific one delete the less specific rule and lookup previous values again;
1248 * add a more specific rule than the existing rule, lookup again
1253 struct rte_lpm6 *lpm = NULL;
1254 struct rte_lpm6_config config;
1256 uint8_t depth, next_hop_add, next_hop_return;
1259 config.max_rules = MAX_RULES;
1260 config.number_tbl8s = NUMBER_TBL8S;
1263 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1264 TEST_LPM_ASSERT(lpm != NULL);
1266 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1270 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1271 TEST_LPM_ASSERT(status == 0);
1273 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10);
1277 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1278 TEST_LPM_ASSERT(status == 0);
1280 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1281 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1283 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1286 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1287 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1289 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1292 status = rte_lpm6_delete(lpm, ip, depth);
1293 TEST_LPM_ASSERT(status == 0);
1295 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1296 TEST_LPM_ASSERT(status == -ENOENT);
1298 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10);
1301 status = rte_lpm6_delete(lpm, ip, depth);
1302 TEST_LPM_ASSERT(status == 0);
1304 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1305 TEST_LPM_ASSERT(status == -ENOENT);
1313 * Adds 3 rules and look them up through the lookup_bulk function.
1314 * Includes in the lookup a fourth IP address that won't match
1315 * and checks that the result is as expected.
1320 struct rte_lpm6 *lpm = NULL;
1321 struct rte_lpm6_config config;
1322 uint8_t ip_batch[4][16];
1323 uint8_t depth, next_hop_add;
1324 int16_t next_hop_return[4];
1327 config.max_rules = MAX_RULES;
1328 config.number_tbl8s = NUMBER_TBL8S;
1331 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1332 TEST_LPM_ASSERT(lpm != NULL);
1334 IPv6(ip_batch[0], 128, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1338 status = rte_lpm6_add(lpm, ip_batch[0], depth, next_hop_add);
1339 TEST_LPM_ASSERT(status == 0);
1341 IPv6(ip_batch[1], 128, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1345 status = rte_lpm6_add(lpm, ip_batch[1], depth, next_hop_add);
1346 TEST_LPM_ASSERT(status == 0);
1348 IPv6(ip_batch[2], 128, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1352 status = rte_lpm6_add(lpm, ip_batch[2], depth, next_hop_add);
1353 TEST_LPM_ASSERT(status == 0);
1355 IPv6(ip_batch[3], 128, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1357 status = rte_lpm6_lookup_bulk_func(lpm, ip_batch,
1358 next_hop_return, 4);
1359 TEST_LPM_ASSERT(status == 0 && next_hop_return[0] == 100
1360 && next_hop_return[1] == 101 && next_hop_return[2] == 102
1361 && next_hop_return[3] == -1);
1369 * Adds 5 rules and look them up.
1370 * Use the delete_bulk function to delete two of them. Lookup again.
1371 * Use the delete_bulk function to delete one more. Lookup again.
1372 * Use the delete_bulk function to delete two more, one invalid. Lookup again.
1373 * Use the delete_bulk function to delete the remaining one. Lookup again.
1378 struct rte_lpm6 *lpm = NULL;
1379 struct rte_lpm6_config config;
1380 uint8_t ip_batch[5][16];
1381 uint8_t depth[5], next_hop_add;
1382 int16_t next_hop_return[5];
1385 config.max_rules = MAX_RULES;
1386 config.number_tbl8s = NUMBER_TBL8S;
1389 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1390 TEST_LPM_ASSERT(lpm != NULL);
1392 /* Adds 5 rules and look them up */
1394 IPv6(ip_batch[0], 128, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1398 status = rte_lpm6_add(lpm, ip_batch[0], depth[0], next_hop_add);
1399 TEST_LPM_ASSERT(status == 0);
1401 IPv6(ip_batch[1], 128, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1405 status = rte_lpm6_add(lpm, ip_batch[1], depth[1], next_hop_add);
1406 TEST_LPM_ASSERT(status == 0);
1408 IPv6(ip_batch[2], 128, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1412 status = rte_lpm6_add(lpm, ip_batch[2], depth[2], next_hop_add);
1413 TEST_LPM_ASSERT(status == 0);
1415 IPv6(ip_batch[3], 128, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1419 status = rte_lpm6_add(lpm, ip_batch[3], depth[3], next_hop_add);
1420 TEST_LPM_ASSERT(status == 0);
1422 IPv6(ip_batch[4], 128, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1426 status = rte_lpm6_add(lpm, ip_batch[4], depth[4], next_hop_add);
1427 TEST_LPM_ASSERT(status == 0);
1429 status = rte_lpm6_lookup_bulk_func(lpm, ip_batch,
1430 next_hop_return, 5);
1431 TEST_LPM_ASSERT(status == 0 && next_hop_return[0] == 101
1432 && next_hop_return[1] == 102 && next_hop_return[2] == 103
1433 && next_hop_return[3] == 104 && next_hop_return[4] == 105);
1435 /* Use the delete_bulk function to delete two of them. Lookup again */
1437 status = rte_lpm6_delete_bulk_func(lpm, &ip_batch[0], depth, 2);
1438 TEST_LPM_ASSERT(status == 0);
1440 status = rte_lpm6_lookup_bulk_func(lpm, ip_batch,
1441 next_hop_return, 5);
1442 TEST_LPM_ASSERT(status == 0 && next_hop_return[0] == -1
1443 && next_hop_return[1] == -1 && next_hop_return[2] == 103
1444 && next_hop_return[3] == 104 && next_hop_return[4] == 105);
1446 /* Use the delete_bulk function to delete one more. Lookup again */
1448 status = rte_lpm6_delete_bulk_func(lpm, &ip_batch[2], depth, 1);
1449 TEST_LPM_ASSERT(status == 0);
1451 status = rte_lpm6_lookup_bulk_func(lpm, ip_batch,
1452 next_hop_return, 5);
1453 TEST_LPM_ASSERT(status == 0 && next_hop_return[0] == -1
1454 && next_hop_return[1] == -1 && next_hop_return[2] == -1
1455 && next_hop_return[3] == 104 && next_hop_return[4] == 105);
1457 /* Use the delete_bulk function to delete two, one invalid. Lookup again */
1459 IPv6(ip_batch[4], 128, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1460 status = rte_lpm6_delete_bulk_func(lpm, &ip_batch[3], depth, 2);
1461 TEST_LPM_ASSERT(status == 0);
1463 IPv6(ip_batch[4], 128, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1464 status = rte_lpm6_lookup_bulk_func(lpm, ip_batch,
1465 next_hop_return, 5);
1466 TEST_LPM_ASSERT(status == 0 && next_hop_return[0] == -1
1467 && next_hop_return[1] == -1 && next_hop_return[2] == -1
1468 && next_hop_return[3] == -1 && next_hop_return[4] == 105);
1470 /* Use the delete_bulk function to delete the remaining one. Lookup again */
1472 status = rte_lpm6_delete_bulk_func(lpm, &ip_batch[4], depth, 1);
1473 TEST_LPM_ASSERT(status == 0);
1475 status = rte_lpm6_lookup_bulk_func(lpm, ip_batch,
1476 next_hop_return, 5);
1477 TEST_LPM_ASSERT(status == 0 && next_hop_return[0] == -1
1478 && next_hop_return[1] == -1 && next_hop_return[2] == -1
1479 && next_hop_return[3] == -1 && next_hop_return[4] == -1);
1487 * Add an extended rule (i.e. depth greater than 24, lookup (hit), delete,
1488 * lookup (miss) in a for loop of 30 times. This will check tbl8 extension
1494 struct rte_lpm6 *lpm = NULL;
1495 struct rte_lpm6_config config;
1498 uint8_t depth, next_hop_add, next_hop_return;
1501 config.max_rules = MAX_RULES;
1502 config.number_tbl8s = NUMBER_TBL8S;
1505 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1506 TEST_LPM_ASSERT(lpm != NULL);
1508 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1512 for (i = 0; i < 30; i++) {
1513 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1514 TEST_LPM_ASSERT(status == 0);
1516 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1517 TEST_LPM_ASSERT((status == 0) &&
1518 (next_hop_return == next_hop_add));
1520 status = rte_lpm6_delete(lpm, ip, depth);
1521 TEST_LPM_ASSERT(status == 0);
1523 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1524 TEST_LPM_ASSERT(status == -ENOENT);
1533 * Sequence of operations for find existing lpm table
1536 * - find existing table: hit
1537 * - find non-existing table: miss
1542 struct rte_lpm6 *lpm = NULL, *result = NULL;
1543 struct rte_lpm6_config config;
1545 config.max_rules = 256 * 32;
1546 config.number_tbl8s = NUMBER_TBL8S;
1550 lpm = rte_lpm6_create("lpm_find_existing", SOCKET_ID_ANY, &config);
1551 TEST_LPM_ASSERT(lpm != NULL);
1553 /* Try to find existing lpm */
1554 result = rte_lpm6_find_existing("lpm_find_existing");
1555 TEST_LPM_ASSERT(result == lpm);
1557 /* Try to find non-existing lpm */
1558 result = rte_lpm6_find_existing("lpm_find_non_existing");
1559 TEST_LPM_ASSERT(result == NULL);
1562 rte_lpm6_delete_all(lpm);
1569 * Add a set of random routes with random depths.
1570 * Lookup different IP addresses that match the routes previously added.
1571 * Checks that the next hop is the expected one.
1572 * The routes, IP addresses and expected result for every case have been
1573 * precalculated by using a python script and stored in a .h file.
1578 struct rte_lpm6 *lpm = NULL;
1579 struct rte_lpm6_config config;
1582 uint8_t depth, next_hop_add, next_hop_return, next_hop_expected;
1585 config.max_rules = MAX_RULES;
1586 config.number_tbl8s = NUMBER_TBL8S;
1589 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1590 TEST_LPM_ASSERT(lpm != NULL);
1592 for (i = 0; i < 1000; i++) {
1593 memcpy(ip, large_route_table[i].ip, 16);
1594 depth = large_route_table[i].depth;
1595 next_hop_add = large_route_table[i].next_hop;
1596 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1597 TEST_LPM_ASSERT(status == 0);
1600 /* generate large IPS table and expected next_hops */
1601 generate_large_ips_table(1);
1603 for (i = 0; i < 100000; i++) {
1604 memcpy(ip, large_ips_table[i].ip, 16);
1605 next_hop_expected = large_ips_table[i].next_hop;
1607 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1608 TEST_LPM_ASSERT((status == 0) &&
1609 (next_hop_return == next_hop_expected));
1618 * Test for overwriting of tbl8:
1619 * - add rule /32 and lookup
1620 * - add new rule /24 and lookup
1621 * - add third rule /25 and lookup
1622 * - lookup /32 and /24 rule to ensure the table has not been overwritten.
1627 struct rte_lpm6 *lpm = NULL;
1628 struct rte_lpm6_config config;
1629 uint8_t ip_10_32[] = {10, 10, 10, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1630 uint8_t ip_10_24[] = {10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1631 uint8_t ip_20_25[] = {10, 10, 20, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1632 uint8_t d_ip_10_32 = 32;
1633 uint8_t d_ip_10_24 = 24;
1634 uint8_t d_ip_20_25 = 25;
1635 uint8_t next_hop_ip_10_32 = 100;
1636 uint8_t next_hop_ip_10_24 = 105;
1637 uint8_t next_hop_ip_20_25 = 111;
1638 uint8_t next_hop_return = 0;
1641 config.max_rules = MAX_RULES;
1642 config.number_tbl8s = NUMBER_TBL8S;
1645 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1646 TEST_LPM_ASSERT(lpm != NULL);
1648 if ((status = rte_lpm6_add(lpm, ip_10_32, d_ip_10_32,
1649 next_hop_ip_10_32)) < 0)
1652 status = rte_lpm6_lookup(lpm, ip_10_32, &next_hop_return);
1653 uint8_t test_hop_10_32 = next_hop_return;
1654 TEST_LPM_ASSERT(status == 0);
1655 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_10_32);
1657 if ((status = rte_lpm6_add(lpm, ip_10_24, d_ip_10_24,
1658 next_hop_ip_10_24)) < 0)
1661 status = rte_lpm6_lookup(lpm, ip_10_24, &next_hop_return);
1662 uint8_t test_hop_10_24 = next_hop_return;
1663 TEST_LPM_ASSERT(status == 0);
1664 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_10_24);
1666 if ((status = rte_lpm6_add(lpm, ip_20_25, d_ip_20_25,
1667 next_hop_ip_20_25)) < 0)
1670 status = rte_lpm6_lookup(lpm, ip_20_25, &next_hop_return);
1671 uint8_t test_hop_20_25 = next_hop_return;
1672 TEST_LPM_ASSERT(status == 0);
1673 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_20_25);
1675 if (test_hop_10_32 == test_hop_10_24) {
1676 printf("Next hop return equal\n");
1680 if (test_hop_10_24 == test_hop_20_25){
1681 printf("Next hop return equal\n");
1685 status = rte_lpm6_lookup(lpm, ip_10_32, &next_hop_return);
1686 TEST_LPM_ASSERT(status == 0);
1687 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_10_32);
1689 status = rte_lpm6_lookup(lpm, ip_10_24, &next_hop_return);
1690 TEST_LPM_ASSERT(status == 0);
1691 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_10_24);
1699 * Add a rule that reaches the end of the tree.
1700 * Add a rule that is more generic than the first one.
1701 * Check every possible combination that produces a match for the second rule.
1702 * This tests tbl expansion.
1707 struct rte_lpm6 *lpm = NULL;
1708 struct rte_lpm6_config config;
1709 uint8_t ip[] = {128,128,128,128,128,128,128,128,128,128,128,128,128,128,0,0};
1710 uint8_t depth = 128, next_hop_add = 100, next_hop_return;
1714 config.max_rules = MAX_RULES;
1715 config.number_tbl8s = NUMBER_TBL8S;
1718 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1719 TEST_LPM_ASSERT(lpm != NULL);
1723 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1724 TEST_LPM_ASSERT(status == 0);
1728 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1729 TEST_LPM_ASSERT(status == 0);
1731 for (i = 0; i < 256; i++) {
1732 ip[14] = (uint8_t)i;
1733 for (j = 0; j < 256; j++) {
1734 ip[15] = (uint8_t)j;
1735 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1736 if (i == 0 && j == 0)
1737 TEST_LPM_ASSERT(status == 0 && next_hop_return == 128);
1739 TEST_LPM_ASSERT(status == 0 && next_hop_return == 112);
1749 * Do all unit tests.
1755 int status = -1, global_status = 0;
1757 for (i = 0; i < NUM_LPM6_TESTS; i++) {
1758 printf("# test %02d\n", i);
1759 status = tests6[i]();
1762 printf("ERROR: LPM Test %s: FAIL\n", RTE_STR(tests6[i]));
1763 global_status = status;
1767 return global_status;
1770 REGISTER_TEST_COMMAND(lpm6_autotest, test_lpm6);