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.
38 #include <sys/queue.h>
46 #include <rte_common.h>
47 #include <rte_cycles.h>
48 #include <rte_memory.h>
49 #include <rte_random.h>
50 #include <rte_branch_prediction.h>
54 #include "test_lpm6_routes.h"
56 #define TEST_LPM_ASSERT(cond) do { \
58 printf("Error at line %d: \n", __LINE__); \
63 typedef int32_t (* rte_lpm6_test)(void);
65 static int32_t test0(void);
66 static int32_t test1(void);
67 static int32_t test2(void);
68 static int32_t test3(void);
69 static int32_t test4(void);
70 static int32_t test5(void);
71 static int32_t test6(void);
72 static int32_t test7(void);
73 static int32_t test8(void);
74 static int32_t test9(void);
75 static int32_t test10(void);
76 static int32_t test11(void);
77 static int32_t test12(void);
78 static int32_t test13(void);
79 static int32_t test14(void);
80 static int32_t test15(void);
81 static int32_t test16(void);
82 static int32_t test17(void);
83 static int32_t test18(void);
84 static int32_t test19(void);
85 static int32_t test20(void);
86 static int32_t test21(void);
87 static int32_t test22(void);
88 static int32_t test23(void);
89 static int32_t test24(void);
90 static int32_t test25(void);
91 static int32_t test26(void);
92 static int32_t test27(void);
93 static int32_t perf_test(void);
95 rte_lpm6_test tests6[] = {
128 #define NUM_LPM6_TESTS (sizeof(tests6)/sizeof(tests6[0]))
129 #define RTE_LPM6_TBL24_NUM_ENTRIES (1 << 24)
130 #define RTE_LPM6_LOOKUP_SUCCESS 0x04000000
131 #define MAX_DEPTH 128
132 #define MAX_RULES 1000000
133 #define NUMBER_TBL8S (1 << 16)
134 #define MAX_NUM_TBL8S (1 << 21)
138 IPv6(uint8_t *ip, uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4, uint8_t b5,
139 uint8_t b6, uint8_t b7, uint8_t b8, uint8_t b9, uint8_t b10,
140 uint8_t b11, uint8_t b12, uint8_t b13, uint8_t b14, uint8_t b15,
162 * Check that rte_lpm6_create fails gracefully for incorrect user input
168 struct rte_lpm6 *lpm = NULL;
169 struct rte_lpm6_config config;
171 config.max_rules = MAX_RULES;
172 config.number_tbl8s = NUMBER_TBL8S;
175 /* rte_lpm6_create: lpm name == NULL */
176 lpm = rte_lpm6_create(NULL, SOCKET_ID_ANY, &config);
177 TEST_LPM_ASSERT(lpm == NULL);
179 /* rte_lpm6_create: max_rules = 0 */
180 /* Note: __func__ inserts the function name, in this case "test0". */
181 config.max_rules = 0;
182 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
183 TEST_LPM_ASSERT(lpm == NULL);
185 /* socket_id < -1 is invalid */
186 config.max_rules = MAX_RULES;
187 lpm = rte_lpm6_create(__func__, -2, &config);
188 TEST_LPM_ASSERT(lpm == NULL);
190 /* rte_lpm6_create: number_tbl8s is bigger than the maximum */
191 config.number_tbl8s = MAX_NUM_TBL8S + 1;
192 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
193 TEST_LPM_ASSERT(lpm == NULL);
195 /* rte_lpm6_create: config = NULL */
196 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, NULL);
197 TEST_LPM_ASSERT(lpm == NULL);
203 * Creates two different LPM tables. Tries to create a third one with the same
204 * name as the first one and expects the create function to return the same
210 struct rte_lpm6 *lpm1 = NULL, *lpm2 = NULL, *lpm3 = NULL;
211 struct rte_lpm6_config config;
213 config.max_rules = MAX_RULES;
214 config.number_tbl8s = NUMBER_TBL8S;
217 /* rte_lpm6_create: lpm name == LPM1 */
218 lpm1 = rte_lpm6_create("LPM1", SOCKET_ID_ANY, &config);
219 TEST_LPM_ASSERT(lpm1 != NULL);
221 /* rte_lpm6_create: lpm name == LPM2 */
222 lpm2 = rte_lpm6_create("LPM2", SOCKET_ID_ANY, &config);
223 TEST_LPM_ASSERT(lpm2 != NULL);
225 /* rte_lpm6_create: lpm name == LPM2 */
226 lpm3 = rte_lpm6_create("LPM1", SOCKET_ID_ANY, &config);
227 TEST_LPM_ASSERT(lpm3 == lpm1);
236 * Create lpm table then delete lpm table 100 times
237 * Use a slightly different rules size each time
242 struct rte_lpm6 *lpm = NULL;
243 struct rte_lpm6_config config;
246 config.number_tbl8s = NUMBER_TBL8S;
249 /* rte_lpm6_free: Free NULL */
250 for (i = 0; i < 100; i++) {
251 config.max_rules = MAX_RULES - i;
252 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
253 TEST_LPM_ASSERT(lpm != NULL);
258 /* Can not test free so return success */
263 * Call rte_lpm6_free for NULL pointer user input. Note: free has no return and
264 * therefore it is impossible to check for failure but this test is added to
265 * increase function coverage metrics and to validate that freeing null does
271 struct rte_lpm6 *lpm = NULL;
272 struct rte_lpm6_config config;
274 config.max_rules = MAX_RULES;
275 config.number_tbl8s = NUMBER_TBL8S;
278 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
279 TEST_LPM_ASSERT(lpm != NULL);
287 * Check that rte_lpm6_add fails gracefully for incorrect user input arguments
292 struct rte_lpm6 *lpm = NULL;
293 struct rte_lpm6_config config;
295 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
296 uint8_t depth = 24, next_hop = 100;
299 config.max_rules = MAX_RULES;
300 config.number_tbl8s = NUMBER_TBL8S;
303 /* rte_lpm6_add: lpm == NULL */
304 status = rte_lpm6_add(NULL, ip, depth, next_hop);
305 TEST_LPM_ASSERT(status < 0);
307 /*Create vaild lpm to use in rest of test. */
308 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
309 TEST_LPM_ASSERT(lpm != NULL);
311 /* rte_lpm6_add: depth < 1 */
312 status = rte_lpm6_add(lpm, ip, 0, next_hop);
313 TEST_LPM_ASSERT(status < 0);
315 /* rte_lpm6_add: depth > MAX_DEPTH */
316 status = rte_lpm6_add(lpm, ip, (MAX_DEPTH + 1), next_hop);
317 TEST_LPM_ASSERT(status < 0);
325 * Check that rte_lpm6_delete fails gracefully for incorrect user input
331 struct rte_lpm6 *lpm = NULL;
332 struct rte_lpm6_config config;
333 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
337 config.max_rules = MAX_RULES;
338 config.number_tbl8s = NUMBER_TBL8S;
341 /* rte_lpm_delete: lpm == NULL */
342 status = rte_lpm6_delete(NULL, ip, depth);
343 TEST_LPM_ASSERT(status < 0);
345 /*Create vaild lpm to use in rest of test. */
346 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
347 TEST_LPM_ASSERT(lpm != NULL);
349 /* rte_lpm_delete: depth < 1 */
350 status = rte_lpm6_delete(lpm, ip, 0);
351 TEST_LPM_ASSERT(status < 0);
353 /* rte_lpm_delete: depth > MAX_DEPTH */
354 status = rte_lpm6_delete(lpm, ip, (MAX_DEPTH + 1));
355 TEST_LPM_ASSERT(status < 0);
363 * Check that rte_lpm6_lookup fails gracefully for incorrect user input
369 struct rte_lpm6 *lpm = NULL;
370 struct rte_lpm6_config config;
371 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
372 uint8_t next_hop_return = 0;
375 config.max_rules = MAX_RULES;
376 config.number_tbl8s = NUMBER_TBL8S;
379 /* rte_lpm6_lookup: lpm == NULL */
380 status = rte_lpm6_lookup(NULL, ip, &next_hop_return);
381 TEST_LPM_ASSERT(status < 0);
383 /*Create vaild lpm to use in rest of test. */
384 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
385 TEST_LPM_ASSERT(lpm != NULL);
387 /* rte_lpm6_lookup: ip = NULL */
388 status = rte_lpm6_lookup(lpm, NULL, &next_hop_return);
389 TEST_LPM_ASSERT(status < 0);
391 /* rte_lpm6_lookup: next_hop = NULL */
392 status = rte_lpm6_lookup(lpm, ip, NULL);
393 TEST_LPM_ASSERT(status < 0);
401 * Checks that rte_lpm6_lookup_bulk_func fails gracefully for incorrect user
407 struct rte_lpm6 *lpm = NULL;
408 struct rte_lpm6_config config;
410 int16_t next_hop_return[10];
413 config.max_rules = MAX_RULES;
414 config.number_tbl8s = NUMBER_TBL8S;
417 /* rte_lpm6_lookup: lpm == NULL */
418 status = rte_lpm6_lookup_bulk_func(NULL, ip, next_hop_return, 10);
419 TEST_LPM_ASSERT(status < 0);
421 /*Create vaild lpm to use in rest of test. */
422 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
423 TEST_LPM_ASSERT(lpm != NULL);
425 /* rte_lpm6_lookup: ip = NULL */
426 status = rte_lpm6_lookup_bulk_func(lpm, NULL, next_hop_return, 10);
427 TEST_LPM_ASSERT(status < 0);
429 /* rte_lpm6_lookup: next_hop = NULL */
430 status = rte_lpm6_lookup_bulk_func(lpm, ip, NULL, 10);
431 TEST_LPM_ASSERT(status < 0);
439 * Checks that rte_lpm6_delete_bulk_func fails gracefully for incorrect user
445 struct rte_lpm6 *lpm = NULL;
446 struct rte_lpm6_config config;
451 config.max_rules = MAX_RULES;
452 config.number_tbl8s = NUMBER_TBL8S;
455 /* rte_lpm6_delete: lpm == NULL */
456 status = rte_lpm6_delete_bulk_func(NULL, ip, depth, 10);
457 TEST_LPM_ASSERT(status < 0);
459 /*Create vaild lpm to use in rest of test. */
460 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
461 TEST_LPM_ASSERT(lpm != NULL);
463 /* rte_lpm6_delete: ip = NULL */
464 status = rte_lpm6_delete_bulk_func(lpm, NULL, depth, 10);
465 TEST_LPM_ASSERT(status < 0);
467 /* rte_lpm6_delete: next_hop = NULL */
468 status = rte_lpm6_delete_bulk_func(lpm, ip, NULL, 10);
469 TEST_LPM_ASSERT(status < 0);
477 * Call add, lookup and delete for a single rule with depth < 24.
478 * Check all the combinations for the first three bytes that result in a hit.
479 * Delete the rule and check that the same test returs a miss.
484 struct rte_lpm6 *lpm = NULL;
485 struct rte_lpm6_config config;
486 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
487 uint8_t depth = 16, next_hop_add = 100, next_hop_return = 0;
491 config.max_rules = MAX_RULES;
492 config.number_tbl8s = NUMBER_TBL8S;
495 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
496 TEST_LPM_ASSERT(lpm != NULL);
498 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
499 TEST_LPM_ASSERT(status == 0);
501 for (i = 0; i < UINT8_MAX; i++) {
503 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
504 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
507 status = rte_lpm6_delete(lpm, ip, depth);
508 TEST_LPM_ASSERT(status == 0);
510 for (i = 0; i < UINT8_MAX; i++) {
512 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
513 TEST_LPM_ASSERT(status == -ENOENT);
522 * Adds max_rules + 1 and expects a failure. Deletes a rule, then adds
523 * another one and expects success.
528 struct rte_lpm6 *lpm = NULL;
529 struct rte_lpm6_config config;
530 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
531 uint8_t depth, next_hop_add = 100;
535 config.max_rules = 127;
536 config.number_tbl8s = NUMBER_TBL8S;
539 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
540 TEST_LPM_ASSERT(lpm != NULL);
542 for (i = 1; i < 128; i++) {
544 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
545 TEST_LPM_ASSERT(status == 0);
549 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
550 TEST_LPM_ASSERT(status == -ENOSPC);
553 status = rte_lpm6_delete(lpm, ip, depth);
554 TEST_LPM_ASSERT(status == 0);
557 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
558 TEST_LPM_ASSERT(status == 0);
566 * Creates an LPM table with a small number of tbl8s and exhaust them in the
567 * middle of the process of creating a rule.
572 struct rte_lpm6 *lpm = NULL;
573 struct rte_lpm6_config config;
574 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
575 uint8_t depth, next_hop_add = 100;
578 config.max_rules = MAX_RULES;
579 config.number_tbl8s = 16;
582 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
583 TEST_LPM_ASSERT(lpm != NULL);
586 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
587 TEST_LPM_ASSERT(status == 0);
591 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
592 TEST_LPM_ASSERT(status == 0);
594 status = rte_lpm6_delete(lpm, ip, depth);
595 TEST_LPM_ASSERT(status == 0);
598 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
599 TEST_LPM_ASSERT(status == 0);
601 status = rte_lpm6_delete(lpm, ip, depth);
602 TEST_LPM_ASSERT(status == 0);
605 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
606 TEST_LPM_ASSERT(status == 0);
608 status = rte_lpm6_delete(lpm, ip, depth);
609 TEST_LPM_ASSERT(status == 0);
612 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
613 TEST_LPM_ASSERT(status == -ENOSPC);
616 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
617 TEST_LPM_ASSERT(status == 0);
625 * Creates an LPM table with a small number of tbl8s and exhaust them in the
626 * middle of the process of adding a rule when there is already an existing rule
627 * in that position and needs to be extended.
632 struct rte_lpm6 *lpm = NULL;
633 struct rte_lpm6_config config;
634 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
635 uint8_t depth, next_hop_add = 100;
638 config.max_rules = MAX_RULES;
639 config.number_tbl8s = 16;
642 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
643 TEST_LPM_ASSERT(lpm != NULL);
646 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
647 TEST_LPM_ASSERT(status == 0);
651 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
652 TEST_LPM_ASSERT(status == 0);
655 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
656 TEST_LPM_ASSERT(status == -ENOSPC);
664 * Creates an LPM table with max_rules = 2 and tries to add 3 rules.
665 * Delete one of the rules and tries to add the third one again.
670 struct rte_lpm6 *lpm = NULL;
671 struct rte_lpm6_config config;
672 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
673 uint8_t depth, next_hop_add = 100;
676 config.max_rules = 2;
677 config.number_tbl8s = NUMBER_TBL8S;
680 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
681 TEST_LPM_ASSERT(lpm != NULL);
684 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
685 TEST_LPM_ASSERT(status == 0);
688 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
689 TEST_LPM_ASSERT(status == 0);
692 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
693 TEST_LPM_ASSERT(status == -ENOSPC);
696 status = rte_lpm6_delete(lpm, ip, depth);
697 TEST_LPM_ASSERT(status == 0);
700 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
701 TEST_LPM_ASSERT(status == 0);
709 * Add 2^16 routes with different first 16 bits and depth 25.
710 * Add one more route with the same depth and check that results in a failure.
711 * After that delete the last rule and create the one that was attempted to be
712 * created. This checks tbl8 exhaustion.
717 struct rte_lpm6 *lpm = NULL;
718 struct rte_lpm6_config config;
719 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
720 uint8_t depth = 25, next_hop_add = 100;
724 config.max_rules = MAX_RULES;
725 config.number_tbl8s = NUMBER_TBL8S;
728 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
729 TEST_LPM_ASSERT(lpm != NULL);
731 for (i = 0; i < 256; i++) {
733 for (j = 0; j < 256; j++) {
735 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
736 TEST_LPM_ASSERT(status == 0);
743 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
744 TEST_LPM_ASSERT(status == -ENOSPC);
749 status = rte_lpm6_delete(lpm, ip, depth);
750 TEST_LPM_ASSERT(status == 0);
755 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
756 TEST_LPM_ASSERT(status == 0);
764 * Call add, lookup and delete for a single rule with depth = 24
769 struct rte_lpm6 *lpm = NULL;
770 struct rte_lpm6_config config;
771 uint8_t ip[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
772 uint8_t depth = 24, next_hop_add = 100, next_hop_return = 0;
775 config.max_rules = MAX_RULES;
776 config.number_tbl8s = NUMBER_TBL8S;
779 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
780 TEST_LPM_ASSERT(lpm != NULL);
782 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
783 TEST_LPM_ASSERT(status == 0);
785 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
786 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
788 status = rte_lpm6_delete(lpm, ip, depth);
789 TEST_LPM_ASSERT(status == 0);
791 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
792 TEST_LPM_ASSERT(status == -ENOENT);
800 * Call add, lookup and delete for a single rule with depth > 24
805 struct rte_lpm6 *lpm = NULL;
806 struct rte_lpm6_config config;
807 uint8_t ip[] = {12,12,1,0,0,0,0,0,0,0,0,0,0,0,0,0};
808 uint8_t depth = 128, next_hop_add = 100, next_hop_return = 0;
811 config.max_rules = MAX_RULES;
812 config.number_tbl8s = NUMBER_TBL8S;
815 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
816 TEST_LPM_ASSERT(lpm != NULL);
818 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
819 TEST_LPM_ASSERT(status == 0);
821 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
822 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
824 status = rte_lpm6_delete(lpm, ip, depth);
825 TEST_LPM_ASSERT(status == 0);
827 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
828 TEST_LPM_ASSERT(status == -ENOENT);
836 * Use rte_lpm6_add to add rules which effect only the second half of the lpm
837 * table. Use all possible depths ranging from 1..32. Set the next hop = to the
838 * depth. Check lookup hit for on every add and check for lookup miss on the
839 * first half of the lpm table after each add. Finally delete all rules going
840 * backwards (i.e. from depth = 32 ..1) and carry out a lookup after each
841 * delete. The lookup should return the next_hop_add value related to the
842 * previous depth value (i.e. depth -1).
847 struct rte_lpm6 *lpm = NULL;
848 struct rte_lpm6_config config;
849 uint8_t ip1[] = {127,255,255,255,255,255,255,255,255,
850 255,255,255,255,255,255,255};
851 uint8_t ip2[] = {128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
852 uint8_t depth, next_hop_add, next_hop_return;
855 config.max_rules = MAX_RULES;
856 config.number_tbl8s = NUMBER_TBL8S;
859 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
860 TEST_LPM_ASSERT(lpm != NULL);
862 /* Loop with rte_lpm6_add. */
863 for (depth = 1; depth <= 128; depth++) {
864 /* Let the next_hop_add value = depth. Just for change. */
865 next_hop_add = depth;
867 status = rte_lpm6_add(lpm, ip2, depth, next_hop_add);
868 TEST_LPM_ASSERT(status == 0);
870 /* Check IP in first half of tbl24 which should be empty. */
871 status = rte_lpm6_lookup(lpm, ip1, &next_hop_return);
872 TEST_LPM_ASSERT(status == -ENOENT);
874 status = rte_lpm6_lookup(lpm, ip2, &next_hop_return);
875 TEST_LPM_ASSERT((status == 0) &&
876 (next_hop_return == next_hop_add));
879 /* Loop with rte_lpm6_delete. */
880 for (depth = 128; depth >= 1; depth--) {
881 next_hop_add = (uint8_t) (depth - 1);
883 status = rte_lpm6_delete(lpm, ip2, depth);
884 TEST_LPM_ASSERT(status == 0);
886 status = rte_lpm6_lookup(lpm, ip2, &next_hop_return);
889 TEST_LPM_ASSERT((status == 0) &&
890 (next_hop_return == next_hop_add));
893 TEST_LPM_ASSERT(status == -ENOENT);
896 status = rte_lpm6_lookup(lpm, ip1, &next_hop_return);
897 TEST_LPM_ASSERT(status == -ENOENT);
906 * - Add & lookup to hit invalid TBL24 entry
907 * - Add & lookup to hit valid TBL24 entry not extended
908 * - Add & lookup to hit valid extended TBL24 entry with invalid TBL8 entry
909 * - Add & lookup to hit valid extended TBL24 entry with valid TBL8 entry
914 struct rte_lpm6 *lpm = NULL;
915 struct rte_lpm6_config config;
916 uint8_t ip[16], ip_1[16], ip_2[16];
917 uint8_t depth, depth_1, depth_2, next_hop_add, next_hop_add_1,
918 next_hop_add_2, next_hop_return;
921 config.max_rules = MAX_RULES;
922 config.number_tbl8s = NUMBER_TBL8S;
925 /* Add & lookup to hit invalid TBL24 entry */
926 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
930 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
931 TEST_LPM_ASSERT(lpm != NULL);
933 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
934 TEST_LPM_ASSERT(status == 0);
936 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
937 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
939 status = rte_lpm6_delete(lpm, ip, depth);
940 TEST_LPM_ASSERT(status == 0);
942 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
943 TEST_LPM_ASSERT(status == -ENOENT);
945 rte_lpm6_delete_all(lpm);
947 /* Add & lookup to hit valid TBL24 entry not extended */
948 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
952 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
953 TEST_LPM_ASSERT(status == 0);
955 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
956 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
961 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
962 TEST_LPM_ASSERT(status == 0);
964 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
965 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
969 status = rte_lpm6_delete(lpm, ip, depth);
970 TEST_LPM_ASSERT(status == 0);
974 status = rte_lpm6_delete(lpm, ip, depth);
975 TEST_LPM_ASSERT(status == 0);
977 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
978 TEST_LPM_ASSERT(status == -ENOENT);
980 rte_lpm6_delete_all(lpm);
982 /* Add & lookup to hit valid extended TBL24 entry with invalid TBL8
985 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
989 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
990 TEST_LPM_ASSERT(status == 0);
992 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
993 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
995 IPv6(ip, 128, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
999 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1000 TEST_LPM_ASSERT(status == 0);
1002 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1003 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1005 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1009 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1010 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1012 status = rte_lpm6_delete(lpm, ip, depth);
1013 TEST_LPM_ASSERT(status == 0);
1015 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1016 TEST_LPM_ASSERT(status == -ENOENT);
1018 rte_lpm6_delete_all(lpm);
1020 /* Add & lookup to hit valid extended TBL24 entry with valid TBL8
1023 IPv6(ip_1, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1025 next_hop_add_1 = 101;
1027 IPv6(ip_2, 128, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1029 next_hop_add_2 = 102;
1031 next_hop_return = 0;
1033 status = rte_lpm6_add(lpm, ip_1, depth_1, next_hop_add_1);
1034 TEST_LPM_ASSERT(status == 0);
1036 status = rte_lpm6_lookup(lpm, ip_1, &next_hop_return);
1037 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add_1));
1039 status = rte_lpm6_add(lpm, ip_2, depth_2, next_hop_add_2);
1040 TEST_LPM_ASSERT(status == 0);
1042 status = rte_lpm6_lookup(lpm, ip_2, &next_hop_return);
1043 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add_2));
1045 status = rte_lpm6_delete(lpm, ip_2, depth_2);
1046 TEST_LPM_ASSERT(status == 0);
1048 status = rte_lpm6_lookup(lpm, ip_2, &next_hop_return);
1049 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add_1));
1051 status = rte_lpm6_delete(lpm, ip_1, depth_1);
1052 TEST_LPM_ASSERT(status == 0);
1054 status = rte_lpm6_lookup(lpm, ip_1, &next_hop_return);
1055 TEST_LPM_ASSERT(status == -ENOENT);
1063 * - Add rule that covers a TBL24 range previously invalid & lookup (& delete &
1065 * - Add rule that extends a TBL24 invalid entry & lookup (& delete & lookup)
1066 * - Add rule that extends a TBL24 valid entry & lookup for both rules (&
1068 * - Add rule that updates the next hop in TBL24 & lookup (& delete & lookup)
1069 * - Add rule that updates the next hop in TBL8 & lookup (& delete & lookup)
1070 * - Delete a rule that is not present in the TBL24 & lookup
1071 * - Delete a rule that is not present in the TBL8 & lookup
1076 struct rte_lpm6 *lpm = NULL;
1077 struct rte_lpm6_config config;
1079 uint8_t depth, next_hop_add, next_hop_return;
1082 config.max_rules = MAX_RULES;
1083 config.number_tbl8s = NUMBER_TBL8S;
1086 /* Add rule that covers a TBL24 range previously invalid & lookup
1087 * (& delete & lookup)
1089 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1090 TEST_LPM_ASSERT(lpm != NULL);
1092 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1096 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1097 TEST_LPM_ASSERT(status == 0);
1099 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1100 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1102 status = rte_lpm6_delete(lpm, ip, depth);
1103 TEST_LPM_ASSERT(status == 0);
1105 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1106 TEST_LPM_ASSERT(status == -ENOENT);
1108 rte_lpm6_delete_all(lpm);
1110 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1114 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1115 TEST_LPM_ASSERT(status == 0);
1117 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1118 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1120 status = rte_lpm6_delete(lpm, ip, depth);
1121 TEST_LPM_ASSERT(status == 0);
1123 rte_lpm6_delete_all(lpm);
1126 * Add rule that extends a TBL24 valid entry & lookup for both rules
1127 * (& delete & lookup)
1130 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1134 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1135 TEST_LPM_ASSERT(status == 0);
1137 IPv6(ip, 128, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1141 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1142 TEST_LPM_ASSERT(status == 0);
1144 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1145 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1147 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1150 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1151 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1153 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1156 status = rte_lpm6_delete(lpm, ip, depth);
1157 TEST_LPM_ASSERT(status == 0);
1159 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1160 TEST_LPM_ASSERT(status == -ENOENT);
1162 IPv6(ip, 128, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1165 status = rte_lpm6_delete(lpm, ip, depth);
1166 TEST_LPM_ASSERT(status == 0);
1168 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1169 TEST_LPM_ASSERT(status == -ENOENT);
1171 rte_lpm6_delete_all(lpm);
1174 * Add rule that updates the next hop in TBL24 & lookup
1175 * (& delete & lookup)
1178 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1182 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1183 TEST_LPM_ASSERT(status == 0);
1185 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1186 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1190 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1191 TEST_LPM_ASSERT(status == 0);
1193 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1194 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1196 status = rte_lpm6_delete(lpm, ip, depth);
1197 TEST_LPM_ASSERT(status == 0);
1199 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1200 TEST_LPM_ASSERT(status == -ENOENT);
1202 rte_lpm6_delete_all(lpm);
1205 * Add rule that updates the next hop in TBL8 & lookup
1206 * (& delete & lookup)
1209 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1213 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1214 TEST_LPM_ASSERT(status == 0);
1216 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1217 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1221 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1222 TEST_LPM_ASSERT(status == 0);
1224 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1225 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1227 status = rte_lpm6_delete(lpm, ip, depth);
1228 TEST_LPM_ASSERT(status == 0);
1230 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1231 TEST_LPM_ASSERT(status == -ENOENT);
1233 rte_lpm6_delete_all(lpm);
1235 /* Delete a rule that is not present in the TBL24 & lookup */
1237 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1241 status = rte_lpm6_delete(lpm, ip, depth);
1242 TEST_LPM_ASSERT(status < 0);
1244 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1245 TEST_LPM_ASSERT(status == -ENOENT);
1247 rte_lpm6_delete_all(lpm);
1249 /* Delete a rule that is not present in the TBL8 & lookup */
1251 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1255 status = rte_lpm6_delete(lpm, ip, depth);
1256 TEST_LPM_ASSERT(status < 0);
1258 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1259 TEST_LPM_ASSERT(status == -ENOENT);
1267 * Add two rules, lookup to hit the more specific one, lookup to hit the less
1268 * specific one delete the less specific rule and lookup previous values again;
1269 * add a more specific rule than the existing rule, lookup again
1274 struct rte_lpm6 *lpm = NULL;
1275 struct rte_lpm6_config config;
1277 uint8_t depth, next_hop_add, next_hop_return;
1280 config.max_rules = MAX_RULES;
1281 config.number_tbl8s = NUMBER_TBL8S;
1284 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1285 TEST_LPM_ASSERT(lpm != NULL);
1287 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1291 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1292 TEST_LPM_ASSERT(status == 0);
1294 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10);
1298 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1299 TEST_LPM_ASSERT(status == 0);
1301 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1302 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1304 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1307 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1308 TEST_LPM_ASSERT((status == 0) && (next_hop_return == next_hop_add));
1310 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1313 status = rte_lpm6_delete(lpm, ip, depth);
1314 TEST_LPM_ASSERT(status == 0);
1316 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1317 TEST_LPM_ASSERT(status == -ENOENT);
1319 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10);
1322 status = rte_lpm6_delete(lpm, ip, depth);
1323 TEST_LPM_ASSERT(status == 0);
1325 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1326 TEST_LPM_ASSERT(status == -ENOENT);
1334 * Adds 3 rules and look them up through the lookup_bulk function.
1335 * Includes in the lookup a fourth IP address that won't match
1336 * and checks that the result is as expected.
1341 struct rte_lpm6 *lpm = NULL;
1342 struct rte_lpm6_config config;
1343 uint8_t ip_batch[4][16];
1344 uint8_t depth, next_hop_add;
1345 int16_t next_hop_return[4];
1348 config.max_rules = MAX_RULES;
1349 config.number_tbl8s = NUMBER_TBL8S;
1352 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1353 TEST_LPM_ASSERT(lpm != NULL);
1355 IPv6(ip_batch[0], 128, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1359 status = rte_lpm6_add(lpm, ip_batch[0], depth, next_hop_add);
1360 TEST_LPM_ASSERT(status == 0);
1362 IPv6(ip_batch[1], 128, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1366 status = rte_lpm6_add(lpm, ip_batch[1], depth, next_hop_add);
1367 TEST_LPM_ASSERT(status == 0);
1369 IPv6(ip_batch[2], 128, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1373 status = rte_lpm6_add(lpm, ip_batch[2], depth, next_hop_add);
1374 TEST_LPM_ASSERT(status == 0);
1376 IPv6(ip_batch[3], 128, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1378 status = rte_lpm6_lookup_bulk_func(lpm, ip_batch,
1379 next_hop_return, 4);
1380 TEST_LPM_ASSERT(status == 0 && next_hop_return[0] == 100
1381 && next_hop_return[1] == 101 && next_hop_return[2] == 102
1382 && next_hop_return[3] == -1);
1390 * Adds 5 rules and look them up.
1391 * Use the delete_bulk function to delete two of them. Lookup again.
1392 * Use the delete_bulk function to delete one more. Lookup again.
1393 * Use the delete_bulk function to delete two more, one invalid. Lookup again.
1394 * Use the delete_bulk function to delete the remaining one. Lookup again.
1399 struct rte_lpm6 *lpm = NULL;
1400 struct rte_lpm6_config config;
1401 uint8_t ip_batch[5][16];
1402 uint8_t depth[5], next_hop_add;
1403 int16_t next_hop_return[5];
1406 config.max_rules = MAX_RULES;
1407 config.number_tbl8s = NUMBER_TBL8S;
1410 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1411 TEST_LPM_ASSERT(lpm != NULL);
1413 /* Adds 5 rules and look them up */
1415 IPv6(ip_batch[0], 128, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1419 status = rte_lpm6_add(lpm, ip_batch[0], depth[0], next_hop_add);
1420 TEST_LPM_ASSERT(status == 0);
1422 IPv6(ip_batch[1], 128, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1426 status = rte_lpm6_add(lpm, ip_batch[1], depth[1], next_hop_add);
1427 TEST_LPM_ASSERT(status == 0);
1429 IPv6(ip_batch[2], 128, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1433 status = rte_lpm6_add(lpm, ip_batch[2], depth[2], next_hop_add);
1434 TEST_LPM_ASSERT(status == 0);
1436 IPv6(ip_batch[3], 128, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1440 status = rte_lpm6_add(lpm, ip_batch[3], depth[3], next_hop_add);
1441 TEST_LPM_ASSERT(status == 0);
1443 IPv6(ip_batch[4], 128, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1447 status = rte_lpm6_add(lpm, ip_batch[4], depth[4], next_hop_add);
1448 TEST_LPM_ASSERT(status == 0);
1450 status = rte_lpm6_lookup_bulk_func(lpm, ip_batch,
1451 next_hop_return, 5);
1452 TEST_LPM_ASSERT(status == 0 && next_hop_return[0] == 101
1453 && next_hop_return[1] == 102 && next_hop_return[2] == 103
1454 && next_hop_return[3] == 104 && next_hop_return[4] == 105);
1456 /* Use the delete_bulk function to delete two of them. Lookup again */
1458 status = rte_lpm6_delete_bulk_func(lpm, &ip_batch[0], depth, 2);
1459 TEST_LPM_ASSERT(status == 0);
1461 status = rte_lpm6_lookup_bulk_func(lpm, ip_batch,
1462 next_hop_return, 5);
1463 TEST_LPM_ASSERT(status == 0 && next_hop_return[0] == -1
1464 && next_hop_return[1] == -1 && next_hop_return[2] == 103
1465 && next_hop_return[3] == 104 && next_hop_return[4] == 105);
1467 /* Use the delete_bulk function to delete one more. Lookup again */
1469 status = rte_lpm6_delete_bulk_func(lpm, &ip_batch[2], depth, 1);
1470 TEST_LPM_ASSERT(status == 0);
1472 status = rte_lpm6_lookup_bulk_func(lpm, ip_batch,
1473 next_hop_return, 5);
1474 TEST_LPM_ASSERT(status == 0 && next_hop_return[0] == -1
1475 && next_hop_return[1] == -1 && next_hop_return[2] == -1
1476 && next_hop_return[3] == 104 && next_hop_return[4] == 105);
1478 /* Use the delete_bulk function to delete two, one invalid. Lookup again */
1480 IPv6(ip_batch[4], 128, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1481 status = rte_lpm6_delete_bulk_func(lpm, &ip_batch[3], depth, 2);
1482 TEST_LPM_ASSERT(status == 0);
1484 IPv6(ip_batch[4], 128, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1485 status = rte_lpm6_lookup_bulk_func(lpm, ip_batch,
1486 next_hop_return, 5);
1487 TEST_LPM_ASSERT(status == 0 && next_hop_return[0] == -1
1488 && next_hop_return[1] == -1 && next_hop_return[2] == -1
1489 && next_hop_return[3] == -1 && next_hop_return[4] == 105);
1491 /* Use the delete_bulk function to delete the remaining one. Lookup again */
1493 status = rte_lpm6_delete_bulk_func(lpm, &ip_batch[4], depth, 1);
1494 TEST_LPM_ASSERT(status == 0);
1496 status = rte_lpm6_lookup_bulk_func(lpm, ip_batch,
1497 next_hop_return, 5);
1498 TEST_LPM_ASSERT(status == 0 && next_hop_return[0] == -1
1499 && next_hop_return[1] == -1 && next_hop_return[2] == -1
1500 && next_hop_return[3] == -1 && next_hop_return[4] == -1);
1508 * Add an extended rule (i.e. depth greater than 24, lookup (hit), delete,
1509 * lookup (miss) in a for loop of 1000 times. This will check tbl8 extension
1515 struct rte_lpm6 *lpm = NULL;
1516 struct rte_lpm6_config config;
1519 uint8_t depth, next_hop_add, next_hop_return;
1522 config.max_rules = MAX_RULES;
1523 config.number_tbl8s = NUMBER_TBL8S;
1526 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1527 TEST_LPM_ASSERT(lpm != NULL);
1529 IPv6(ip, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1533 for (i = 0; i < 1000; i++) {
1534 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1535 TEST_LPM_ASSERT(status == 0);
1537 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1538 TEST_LPM_ASSERT((status == 0) &&
1539 (next_hop_return == next_hop_add));
1541 status = rte_lpm6_delete(lpm, ip, depth);
1542 TEST_LPM_ASSERT(status == 0);
1544 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1545 TEST_LPM_ASSERT(status == -ENOENT);
1554 * Sequence of operations for find existing lpm table
1557 * - find existing table: hit
1558 * - find non-existing table: miss
1563 struct rte_lpm6 *lpm = NULL, *result = NULL;
1564 struct rte_lpm6_config config;
1566 config.max_rules = 256 * 32;
1567 config.number_tbl8s = NUMBER_TBL8S;
1571 lpm = rte_lpm6_create("lpm_find_existing", SOCKET_ID_ANY, &config);
1572 TEST_LPM_ASSERT(lpm != NULL);
1574 /* Try to find existing lpm */
1575 result = rte_lpm6_find_existing("lpm_find_existing");
1576 TEST_LPM_ASSERT(result == lpm);
1578 /* Try to find non-existing lpm */
1579 result = rte_lpm6_find_existing("lpm_find_non_existing");
1580 TEST_LPM_ASSERT(result == NULL);
1583 rte_lpm6_delete_all(lpm);
1590 * Add a set of random routes with random depths.
1591 * Lookup different IP addresses that match the routes previously added.
1592 * Checks that the next hop is the expected one.
1593 * The routes, IP addresses and expected result for every case have been
1594 * precalculated by using a python script and stored in a .h file.
1599 struct rte_lpm6 *lpm = NULL;
1600 struct rte_lpm6_config config;
1603 uint8_t depth, next_hop_add, next_hop_return, next_hop_expected;
1606 config.max_rules = MAX_RULES;
1607 config.number_tbl8s = NUMBER_TBL8S;
1610 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1611 TEST_LPM_ASSERT(lpm != NULL);
1613 for (i = 0; i < 1000; i++) {
1614 memcpy(ip, large_route_table[i].ip, 16);
1615 depth = large_route_table[i].depth;
1616 next_hop_add = large_route_table[i].next_hop;
1617 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1618 TEST_LPM_ASSERT(status == 0);
1621 for (i = 0; i < 100000; i++) {
1622 memcpy(ip, large_ips_table[i].ip, 16);
1623 next_hop_expected = large_ips_table[i].next_hop;
1625 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1626 TEST_LPM_ASSERT((status == 0) &&
1627 (next_hop_return == next_hop_expected));
1636 * Test for overwriting of tbl8:
1637 * - add rule /32 and lookup
1638 * - add new rule /24 and lookup
1639 * - add third rule /25 and lookup
1640 * - lookup /32 and /24 rule to ensure the table has not been overwritten.
1645 struct rte_lpm6 *lpm = NULL;
1646 struct rte_lpm6_config config;
1647 uint8_t ip_10_32[] = {10, 10, 10, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1648 uint8_t ip_10_24[] = {10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1649 uint8_t ip_20_25[] = {10, 10, 20, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1650 uint8_t d_ip_10_32 = 32;
1651 uint8_t d_ip_10_24 = 24;
1652 uint8_t d_ip_20_25 = 25;
1653 uint8_t next_hop_ip_10_32 = 100;
1654 uint8_t next_hop_ip_10_24 = 105;
1655 uint8_t next_hop_ip_20_25 = 111;
1656 uint8_t next_hop_return = 0;
1659 config.max_rules = MAX_RULES;
1660 config.number_tbl8s = NUMBER_TBL8S;
1663 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1664 TEST_LPM_ASSERT(lpm != NULL);
1666 if ((status = rte_lpm6_add(lpm, ip_10_32, d_ip_10_32,
1667 next_hop_ip_10_32)) < 0)
1670 status = rte_lpm6_lookup(lpm, ip_10_32, &next_hop_return);
1671 uint8_t test_hop_10_32 = next_hop_return;
1672 TEST_LPM_ASSERT(status == 0);
1673 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_10_32);
1675 if ((status = rte_lpm6_add(lpm, ip_10_24, d_ip_10_24,
1676 next_hop_ip_10_24)) < 0)
1679 status = rte_lpm6_lookup(lpm, ip_10_24, &next_hop_return);
1680 uint8_t test_hop_10_24 = next_hop_return;
1681 TEST_LPM_ASSERT(status == 0);
1682 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_10_24);
1684 if ((status = rte_lpm6_add(lpm, ip_20_25, d_ip_20_25,
1685 next_hop_ip_20_25)) < 0)
1688 status = rte_lpm6_lookup(lpm, ip_20_25, &next_hop_return);
1689 uint8_t test_hop_20_25 = next_hop_return;
1690 TEST_LPM_ASSERT(status == 0);
1691 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_20_25);
1693 if (test_hop_10_32 == test_hop_10_24) {
1694 printf("Next hop return equal\n");
1698 if (test_hop_10_24 == test_hop_20_25){
1699 printf("Next hop return equal\n");
1703 status = rte_lpm6_lookup(lpm, ip_10_32, &next_hop_return);
1704 TEST_LPM_ASSERT(status == 0);
1705 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_10_32);
1707 status = rte_lpm6_lookup(lpm, ip_10_24, &next_hop_return);
1708 TEST_LPM_ASSERT(status == 0);
1709 TEST_LPM_ASSERT(next_hop_return == next_hop_ip_10_24);
1717 * Add a rule that reaches the end of the tree.
1718 * Add a rule that is more generic than the first one.
1719 * Check every possible combination that produces a match for the second rule.
1720 * This tests tbl expansion.
1725 struct rte_lpm6 *lpm = NULL;
1726 struct rte_lpm6_config config;
1727 uint8_t ip[] = {128,128,128,128,128,128,128,128,128,128,128,128,128,128,0,0};
1728 uint8_t depth = 128, next_hop_add = 100, next_hop_return;
1732 config.max_rules = MAX_RULES;
1733 config.number_tbl8s = NUMBER_TBL8S;
1736 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1737 TEST_LPM_ASSERT(lpm != NULL);
1741 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1742 TEST_LPM_ASSERT(status == 0);
1746 status = rte_lpm6_add(lpm, ip, depth, next_hop_add);
1747 TEST_LPM_ASSERT(status == 0);
1749 for (i = 0; i < 256; i++) {
1750 ip[14] = (uint8_t)i;
1751 for (j = 0; j < 256; j++) {
1752 ip[15] = (uint8_t)j;
1753 status = rte_lpm6_lookup(lpm, ip, &next_hop_return);
1754 if (i == 0 && j == 0)
1755 TEST_LPM_ASSERT(status == 0 && next_hop_return == 128);
1757 TEST_LPM_ASSERT(status == 0 && next_hop_return == 112);
1767 * Lookup performance test
1770 #define ITERATIONS (1 << 10)
1771 #define BATCH_SIZE 100000
1774 print_route_distribution(const struct rules_tbl_entry *table, uint32_t n)
1778 printf("Route distribution per prefix width: \n");
1779 printf("DEPTH QUANTITY (PERCENT)\n");
1780 printf("--------------------------- \n");
1783 for(i = 1; i <= 128; i++) {
1784 unsigned depth_counter = 0;
1785 double percent_hits;
1787 for (j = 0; j < n; j++)
1788 if (table[j].depth == (uint8_t) i)
1791 percent_hits = ((double)depth_counter)/((double)n) * 100;
1792 printf("%.2u%15u (%.2f)\n", i, depth_counter, percent_hits);
1800 struct rte_lpm6 *lpm = NULL;
1801 struct rte_lpm6_config config;
1802 uint64_t begin, total_time;
1804 uint8_t next_hop_add = 0xAA, next_hop_return = 0;
1808 config.max_rules = 1000000;
1809 config.number_tbl8s = NUMBER_TBL8S;
1812 rte_srand(rte_rdtsc());
1814 printf("No. routes = %u\n", (unsigned) NUM_ROUTE_ENTRIES);
1816 print_route_distribution(large_route_table, (uint32_t) NUM_ROUTE_ENTRIES);
1818 lpm = rte_lpm6_create(__func__, SOCKET_ID_ANY, &config);
1819 TEST_LPM_ASSERT(lpm != NULL);
1822 begin = rte_rdtsc();
1824 for (i = 0; i < NUM_ROUTE_ENTRIES; i++) {
1825 if (rte_lpm6_add(lpm, large_route_table[i].ip,
1826 large_route_table[i].depth, next_hop_add) == 0)
1830 total_time = rte_rdtsc() - begin;
1832 printf("Unique added entries = %d\n", status);
1833 printf("Average LPM Add: %g cycles\n",
1834 (double)total_time / NUM_ROUTE_ENTRIES);
1836 /* Measure single Lookup */
1840 for (i = 0; i < ITERATIONS; i ++) {
1841 begin = rte_rdtsc();
1843 for (j = 0; j < NUM_IPS_ENTRIES; j ++) {
1844 if (rte_lpm6_lookup(lpm, large_ips_table[j].ip,
1845 &next_hop_return) != 0)
1849 total_time += rte_rdtsc() - begin;
1852 printf("Average LPM Lookup: %.1f cycles (fails = %.1f%%)\n",
1853 (double)total_time / ((double)ITERATIONS * BATCH_SIZE),
1854 (count * 100.0) / (double)(ITERATIONS * BATCH_SIZE));
1856 /* Measure bulk Lookup */
1860 uint8_t ip_batch[NUM_IPS_ENTRIES][16];
1861 int16_t next_hops[NUM_IPS_ENTRIES];
1863 for (i = 0; i < NUM_IPS_ENTRIES; i++)
1864 memcpy(ip_batch[i], large_ips_table[i].ip, 16);
1866 for (i = 0; i < ITERATIONS; i ++) {
1868 /* Lookup per batch */
1869 begin = rte_rdtsc();
1870 rte_lpm6_lookup_bulk_func(lpm, ip_batch, next_hops, NUM_IPS_ENTRIES);
1871 total_time += rte_rdtsc() - begin;
1873 for (j = 0; j < NUM_IPS_ENTRIES; j++)
1874 if (next_hops[j] < 0)
1877 printf("BULK LPM Lookup: %.1f cycles (fails = %.1f%%)\n",
1878 (double)total_time / ((double)ITERATIONS * BATCH_SIZE),
1879 (count * 100.0) / (double)(ITERATIONS * BATCH_SIZE));
1883 begin = rte_rdtsc();
1885 for (i = 0; i < NUM_ROUTE_ENTRIES; i++) {
1886 /* rte_lpm_delete(lpm, ip, depth) */
1887 status += rte_lpm6_delete(lpm, large_route_table[i].ip,
1888 large_route_table[i].depth);
1891 total_time += rte_rdtsc() - begin;
1893 printf("Average LPM Delete: %g cycles\n",
1894 (double)total_time / NUM_ROUTE_ENTRIES);
1896 rte_lpm6_delete_all(lpm);
1903 * Do all unit and performance tests.
1909 int status = -1, global_status = 0;
1911 for (i = 0; i < NUM_LPM6_TESTS; i++) {
1912 status = tests6[i]();
1915 printf("ERROR: LPM Test %s: FAIL\n", RTE_STR(tests6[i]));
1916 global_status = status;
1920 return global_status;
1923 #else /* RTE_LIBRTE_LPM */
1928 printf("The LPM library is not included in this build\n");
1932 #endif /* RTE_LIBRTE_LPM */