X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Ffib%2Fip6_fib.c;h=6c73d19d8e3207ef489852e4b7cf4bf88ba4bab3;hb=97866a3279b112bba64a65d073e94aa9635d03ad;hp=cecfcbd156059817d96a64db88da096d05dc5027;hpb=e7eba48937c52478d3844745ebb63a4b9ce8d681;p=vpp.git diff --git a/src/vnet/fib/ip6_fib.c b/src/vnet/fib/ip6_fib.c index cecfcbd1560..6c73d19d8e3 100644 --- a/src/vnet/fib/ip6_fib.c +++ b/src/vnet/fib/ip6_fib.c @@ -20,6 +20,12 @@ #include #include +ip6_fib_table_instance_t ip6_fib_table[IP6_FIB_NUM_TABLES]; + +/* ip6 lookup table config parameters */ +u32 ip6_fib_table_nbuckets; +uword ip6_fib_table_size; + static void vnet_ip6_fib_init (u32 fib_index) { @@ -151,11 +157,15 @@ ip6_fib_table_destroy (u32 fib_index) fib_table_t *fib_table = fib_table_get(fib_index, FIB_PROTOCOL_IP6); fib_source_t source; - /* + /* * validate no more routes. */ - ASSERT(0 == fib_table->ft_total_route_counts); - FOR_EACH_FIB_SOURCE(source) +#if CLIB_DEBUG > 0 + if (0 != fib_table->ft_total_route_counts) + fib_table_assert_empty(fib_table); +#endif + + vec_foreach_index(source, fib_table->ft_src_route_counts) { ASSERT(0 == fib_table->ft_src_route_counts[source]); } @@ -164,6 +174,8 @@ ip6_fib_table_destroy (u32 fib_index) { hash_unset (ip6_main.fib_index_by_table_id, fib_table->ft_table_id); } + vec_free (fib_table->ft_locks); + vec_free(fib_table->ft_src_route_counts); pool_put_index(ip6_main.v6_fibs, fib_table->ft_index); pool_put(ip6_main.fibs, fib_table); } @@ -178,7 +190,7 @@ ip6_fib_table_lookup (u32 fib_index, int i, n_p, rv; u64 fib; - table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING]; + table = &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING]; n_p = vec_len (table->prefix_lengths_in_search_order); kv.key[0] = addr->as_u64[0]; @@ -225,7 +237,7 @@ ip6_fib_table_lookup_exact_match (u32 fib_index, u64 fib; int rv; - table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING]; + table = &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING]; mask = &ip6_main.fib_masks[len]; fib = ((u64)((fib_index))<<32); @@ -243,14 +255,29 @@ ip6_fib_table_lookup_exact_match (u32 fib_index, static void compute_prefix_lengths_in_search_order (ip6_fib_table_instance_t *table) { + u8 *old, *prefix_lengths_in_search_order = NULL; int i; - vec_reset_length (table->prefix_lengths_in_search_order); + + /* + * build the list in a scratch space then cutover so the workers + * can continue uninterrupted. + */ + old = table->prefix_lengths_in_search_order; + /* Note: bitmap reversed so this is in fact a longest prefix match */ - clib_bitmap_foreach (i, table->non_empty_dst_address_length_bitmap, - ({ + clib_bitmap_foreach (i, table->non_empty_dst_address_length_bitmap) + { int dst_address_length = 128 - i; - vec_add1(table->prefix_lengths_in_search_order, dst_address_length); - })); + vec_add1(prefix_lengths_in_search_order, dst_address_length); + } + + table->prefix_lengths_in_search_order = prefix_lengths_in_search_order; + + /* + * let the workers go once round the track before we free the old set + */ + vlib_worker_wait_one_loop(); + vec_free(old); } void @@ -263,7 +290,7 @@ ip6_fib_table_entry_remove (u32 fib_index, ip6_address_t *mask; u64 fib; - table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING]; + table = &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING]; mask = &ip6_main.fib_masks[len]; fib = ((u64)((fib_index))<<32); @@ -295,7 +322,7 @@ ip6_fib_table_entry_insert (u32 fib_index, ip6_address_t *mask; u64 fib; - table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING]; + table = &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING]; mask = &ip6_main.fib_masks[len]; fib = ((u64)((fib_index))<<32); @@ -306,12 +333,13 @@ ip6_fib_table_entry_insert (u32 fib_index, clib_bihash_add_del_24_8(&table->ip6_hash, &kv, 1); - table->dst_address_length_refcounts[len]++; - - table->non_empty_dst_address_length_bitmap = - clib_bitmap_set (table->non_empty_dst_address_length_bitmap, - 128 - len, 1); - compute_prefix_lengths_in_search_order (table); + if (0 == table->dst_address_length_refcounts[len]++) + { + table->non_empty_dst_address_length_bitmap = + clib_bitmap_set (table->non_empty_dst_address_length_bitmap, + 128 - len, 1); + compute_prefix_lengths_in_search_order (table); + } } u32 ip6_fib_table_fwding_lookup_with_if_index (ip6_main_t * im, @@ -347,7 +375,7 @@ ip6_fib_table_fwding_dpo_update (u32 fib_index, ip6_address_t *mask; u64 fib; - table = &ip6_main.ip6_table[IP6_FIB_TABLE_FWDING]; + table = &ip6_fib_table[IP6_FIB_TABLE_FWDING]; mask = &ip6_main.fib_masks[len]; fib = ((u64)((fib_index))<<32); @@ -358,12 +386,13 @@ ip6_fib_table_fwding_dpo_update (u32 fib_index, clib_bihash_add_del_24_8(&table->ip6_hash, &kv, 1); - table->dst_address_length_refcounts[len]++; - - table->non_empty_dst_address_length_bitmap = - clib_bitmap_set (table->non_empty_dst_address_length_bitmap, - 128 - len, 1); - compute_prefix_lengths_in_search_order (table); + if (0 == table->dst_address_length_refcounts[len]++) + { + table->non_empty_dst_address_length_bitmap = + clib_bitmap_set (table->non_empty_dst_address_length_bitmap, + 128 - len, 1); + compute_prefix_lengths_in_search_order (table); + } } void @@ -377,7 +406,7 @@ ip6_fib_table_fwding_dpo_remove (u32 fib_index, ip6_address_t *mask; u64 fib; - table = &ip6_main.ip6_table[IP6_FIB_TABLE_FWDING]; + table = &ip6_fib_table[IP6_FIB_TABLE_FWDING]; mask = &ip6_main.fib_masks[len]; fib = ((u64)((fib_index))<<32); @@ -489,7 +518,7 @@ ip6_fib_table_walk (u32 fib_index, }; clib_bihash_foreach_key_value_pair_24_8( - &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, + &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, ip6_fib_walk_cb, &ctx); @@ -510,7 +539,7 @@ ip6_fib_table_sub_tree_walk (u32 fib_index, }; clib_bihash_foreach_key_value_pair_24_8( - &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, + &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, ip6_fib_walk_cb, &ctx); } @@ -573,8 +602,8 @@ format_ip6_fib_table_memory (u8 * s, va_list * args) { uword bytes_inuse; - bytes_inuse = (alloc_arena_next(&(ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash)) + - alloc_arena_next(&(ip6_main.ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash))); + bytes_inuse = (alloc_arena_next(&(ip6_fib_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash)) + + alloc_arena_next(&(ip6_fib_table[IP6_FIB_TABLE_FWDING].ip6_hash))); s = format(s, "%=30s %=6d %=12ld\n", "IPv6 unicast", @@ -588,7 +617,7 @@ typedef struct { u64 count_by_prefix_length[129]; } count_routes_in_fib_at_prefix_length_arg_t; -static void +static int count_routes_in_fib_at_prefix_length (clib_bihash_kv_24_8_t * kvp, void *arg) { @@ -596,11 +625,13 @@ count_routes_in_fib_at_prefix_length (clib_bihash_kv_24_8_t * kvp, int mask_width; if ((kvp->key[2]>>32) != ap->fib_index) - return; + return (BIHASH_WALK_CONTINUE); mask_width = kvp->key[2] & 0xFF; ap->count_by_prefix_length[mask_width]++; + + return (BIHASH_WALK_CONTINUE); } static clib_error_t * @@ -657,17 +688,17 @@ ip6_show_fib (vlib_main_t * vm, { vlib_cli_output (vm, "IPv6 Non-Forwarding Hash Table:\n%U\n", BV (format_bihash), - &im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, + &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, detail); vlib_cli_output (vm, "IPv6 Forwarding Hash Table:\n%U\n", BV (format_bihash), - &im6->ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash, + &ip6_fib_table[IP6_FIB_TABLE_FWDING].ip6_hash, detail); return (NULL); } - pool_foreach (fib_table, im6->fibs, - ({ + pool_foreach (fib_table, im6->fibs) + { fib_source_t source; u8 *s = NULL; @@ -679,13 +710,16 @@ ip6_show_fib (vlib_main_t * vm, if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL) continue; - s = format(s, "%U, fib_index:%d, flow hash:[%U] locks:[", + s = format(s, "%U, fib_index:%d, flow hash:[%U] epoch:%d flags:%U locks:[", format_fib_table_name, fib->index, FIB_PROTOCOL_IP6, fib->index, format_ip_flow_hash_config, - fib_table->ft_flow_hash_config); - FOR_EACH_FIB_SOURCE(source) + fib_table->ft_flow_hash_config, + fib_table->ft_epoch, + format_fib_table_flags, fib_table->ft_flags); + + vec_foreach_index(source, fib_table->ft_locks) { if (0 != fib_table->ft_locks[source]) { @@ -701,7 +735,7 @@ ip6_show_fib (vlib_main_t * vm, /* Show summary? */ if (! verbose) { - clib_bihash_24_8_t * h = &im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash; + clib_bihash_24_8_t * h = &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash; int len; vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count"); @@ -729,7 +763,7 @@ ip6_show_fib (vlib_main_t * vm, { ip6_fib_table_show_one(fib, vm, &matching_address, mask_len, detail); } - })); + } return 0; } @@ -739,7 +773,7 @@ ip6_show_fib (vlib_main_t * vm, * entries for each table. * * @note This command will run for a long time when the FIB tables are - * comprised of millions of entries. For those senarios, consider displaying + * comprised of millions of entries. For those scenarios, consider displaying * in summary mode. * * @cliexpar @@ -835,3 +869,55 @@ VLIB_CLI_COMMAND (ip6_show_fib_command, static) = { .function = ip6_show_fib, }; /* *INDENT-ON* */ + +static clib_error_t * +ip6_config (vlib_main_t * vm, unformat_input_t * input) +{ + uword heapsize = 0; + u32 nbuckets = 0; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "hash-buckets %d", &nbuckets)) + ; + else if (unformat (input, "heap-size %U", + unformat_memory_size, &heapsize)) + ; + else + return clib_error_return (0, "unknown input '%U'", + format_unformat_error, input); + } + + ip6_fib_table_nbuckets = nbuckets; + ip6_fib_table_size = heapsize; + + return 0; +} + +VLIB_EARLY_CONFIG_FUNCTION (ip6_config, "ip6"); + +static clib_error_t * +ip6_fib_init (vlib_main_t * vm) +{ + if (ip6_fib_table_nbuckets == 0) + ip6_fib_table_nbuckets = IP6_FIB_DEFAULT_HASH_NUM_BUCKETS; + + ip6_fib_table_nbuckets = 1 << max_log2 (ip6_fib_table_nbuckets); + + if (ip6_fib_table_size == 0) + ip6_fib_table_size = IP6_FIB_DEFAULT_HASH_MEMORY_SIZE; + + clib_bihash_init_24_8 (&(ip6_fib_table[IP6_FIB_TABLE_FWDING].ip6_hash), + "ip6 FIB fwding table", + ip6_fib_table_nbuckets, ip6_fib_table_size); + clib_bihash_init_24_8 (&ip6_fib_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, + "ip6 FIB non-fwding table", + ip6_fib_table_nbuckets, ip6_fib_table_size); + + return (NULL); +} + +VLIB_INIT_FUNCTION (ip6_fib_init) = +{ + .runs_before = VLIB_INITS("ip6_lookup_init"), +};