1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
10 #include <rte_cycles.h>
11 #include <rte_random.h>
12 #include <rte_memory.h>
16 #include "test_lpm6_data.h"
18 #define TEST_FIB_ASSERT(cond) do { \
20 printf("Error at line %d:\n", __LINE__); \
25 #define ITERATIONS (1 << 10)
26 #define BATCH_SIZE 100000
27 #define NUMBER_TBL8S (1 << 16)
30 print_route_distribution(const struct rules_tbl_entry *table, uint32_t n)
34 printf("Route distribution per prefix width:\n");
35 printf("DEPTH QUANTITY (PERCENT)\n");
36 printf("---------------------------\n");
39 for (i = 1; i <= 128; i++) {
40 unsigned int depth_counter = 0;
43 for (j = 0; j < n; j++)
44 if (table[j].depth == (uint8_t) i)
47 percent_hits = ((double)depth_counter)/((double)n) * 100;
48 printf("%.2u%15u (%.2f)\n", i, depth_counter, percent_hits);
54 bits_in_nh(uint8_t nh_sz)
56 return 8 * (1 << nh_sz);
59 static inline uint64_t
60 get_max_nh(uint8_t nh_sz)
62 return ((1ULL << (bits_in_nh(nh_sz) - 1)) - 1);
68 struct rte_fib6 *fib = NULL;
69 struct rte_fib6_conf conf;
70 uint64_t begin, total_time;
72 uint64_t next_hop_add;
75 uint8_t ip_batch[NUM_IPS_ENTRIES][16];
76 uint64_t next_hops[NUM_IPS_ENTRIES];
78 conf.type = RTE_FIB6_TRIE;
80 conf.max_routes = 1000000;
81 conf.trie.nh_sz = RTE_FIB6_TRIE_4B;
82 conf.trie.num_tbl8 = RTE_MIN(get_max_nh(conf.trie.nh_sz), 1000000U);
84 rte_srand(rte_rdtsc());
86 printf("No. routes = %u\n", (unsigned int) NUM_ROUTE_ENTRIES);
88 print_route_distribution(large_route_table,
89 (uint32_t)NUM_ROUTE_ENTRIES);
91 /* Only generate IPv6 address of each item in large IPS table,
92 * here next_hop is not needed.
94 generate_large_ips_table(0);
96 fib = rte_fib6_create(__func__, SOCKET_ID_ANY, &conf);
97 TEST_FIB_ASSERT(fib != NULL);
102 for (i = 0; i < NUM_ROUTE_ENTRIES; i++) {
103 next_hop_add = (i & ((1 << 14) - 1)) + 1;
104 if (rte_fib6_add(fib, large_route_table[i].ip,
105 large_route_table[i].depth, next_hop_add) == 0)
109 total_time = rte_rdtsc() - begin;
111 printf("Unique added entries = %d\n", status);
112 printf("Average FIB Add: %g cycles\n",
113 (double)total_time / NUM_ROUTE_ENTRIES);
115 /* Measure bulk Lookup */
119 for (i = 0; i < NUM_IPS_ENTRIES; i++)
120 memcpy(ip_batch[i], large_ips_table[i].ip, 16);
122 for (i = 0; i < ITERATIONS; i++) {
124 /* Lookup per batch */
126 rte_fib6_lookup_bulk(fib, ip_batch, next_hops, NUM_IPS_ENTRIES);
127 total_time += rte_rdtsc() - begin;
129 for (j = 0; j < NUM_IPS_ENTRIES; j++)
130 if (next_hops[j] == 0)
133 printf("BULK FIB Lookup: %.1f cycles (fails = %.1f%%)\n",
134 (double)total_time / ((double)ITERATIONS * BATCH_SIZE),
135 (count * 100.0) / (double)(ITERATIONS * BATCH_SIZE));
141 for (i = 0; i < NUM_ROUTE_ENTRIES; i++) {
142 /* rte_fib_delete(fib, ip, depth) */
143 status += rte_fib6_delete(fib, large_route_table[i].ip,
144 large_route_table[i].depth);
147 total_time = rte_rdtsc() - begin;
149 printf("Average FIB Delete: %g cycles\n",
150 (double)total_time / NUM_ROUTE_ENTRIES);
157 REGISTER_TEST_COMMAND(fib6_perf_autotest, test_fib6_perf);