From c87aafad759f92ae630fec52079a08ace607410b Mon Sep 17 00:00:00 2001 From: Neale Ranns Date: Wed, 29 Nov 2017 00:59:31 -0800 Subject: Include allocated table memory in 'sh fib mem' output DBGvpp# sh fib mem FIB memory Tables: SAFI Number Bytes IPv4 unicast 2 673066 IPv6 unicast 2 1054608 MPLS 1 4194312 IPv4 multicast 2 2322 IPv6 multicast 2 ??? Nodes: Name Size in-use /allocated totals Entry 96 20 / 20 1920/1920 Entry Source 32 0 / 0 0/0 Entry Path-Extensions 60 0 / 0 0/0 multicast-Entry 192 12 / 12 2304/2304 Path-list 40 28 / 28 1120/1120 uRPF-list 16 20 / 20 320/320 Path 72 28 / 28 2016/2016 Node-list elements 20 28 / 28 560/560 Node-list heads 8 30 / 30 240/240 Change-Id: I8c8f6f1c87502a40265bf4f302d0daef111a4a4e Signed-off-by: Neale Ranns --- src/vnet/mfib/ip4_mfib.c | 70 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 3 deletions(-) (limited to 'src/vnet/mfib/ip4_mfib.c') diff --git a/src/vnet/mfib/ip4_mfib.c b/src/vnet/mfib/ip4_mfib.c index b2482580678..7040fa71764 100644 --- a/src/vnet/mfib/ip4_mfib.c +++ b/src/vnet/mfib/ip4_mfib.c @@ -305,6 +305,42 @@ ip4_mfib_table_walk (ip4_mfib_t *mfib, } } +u8 * +format_ip4_mfib_table_memory (u8 * s, va_list * args) +{ + mfib_table_t *mfib_table; + u64 total_memory; + + total_memory = 0; + + pool_foreach (mfib_table, ip4_main.mfibs, + ({ + ip4_mfib_t *mfib = &mfib_table->v4; + uword mfib_size; + int i; + + mfib_size = 0; + + for (i = 0; i < ARRAY_LEN (mfib->fib_entry_by_dst_address); i++) + { + uword * hash = mfib->fib_entry_by_dst_address[i]; + + if (NULL != hash) + { + mfib_size += hash_bytes(hash); + } + } + + total_memory += mfib_size; + })); + + s = format(s, "%=30s %=6d %=8ld\n", + "IPv4 multicast", + pool_elts(ip4_main.mfibs), total_memory); + + return (s); +} + static void ip4_mfib_table_show_all (ip4_mfib_t *mfib, vlib_main_t * vm) @@ -363,20 +399,23 @@ ip4_show_mfib (vlib_main_t * vm, { ip4_main_t * im4 = &ip4_main; mfib_table_t *mfib_table; - int verbose, matching; + int verbose, matching, memory; ip4_address_t grp, src = {{0}}; u32 mask = 32; + u64 total_hash_memory; int i, table_id = -1, fib_index = ~0; verbose = 1; - matching = 0; + memory = matching = 0; + total_hash_memory = 0; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "brief") || unformat (input, "summary") || unformat (input, "sum")) verbose = 0; - + else if (unformat (input, "mem") || unformat (input, "memory")) + memory = 1; else if (unformat (input, "%U %U", unformat_ip4_address, &src, unformat_ip4_address, &grp)) @@ -412,6 +451,29 @@ ip4_show_mfib (vlib_main_t * vm, if (fib_index != ~0 && fib_index != (int)mfib->index) continue; + if (memory) + { + uword hash_size; + + hash_size = 0; + + for (i = 0; i < ARRAY_LEN (mfib->fib_entry_by_dst_address); i++) + { + uword * hash = mfib->fib_entry_by_dst_address[i]; + if (NULL != hash) + { + hash_size += hash_bytes(hash); + } + } + if (verbose) + vlib_cli_output (vm, "%U hash:%d", + format_mfib_table_name, mfib->index, + FIB_PROTOCOL_IP4, + hash_size); + total_hash_memory += hash_size; + continue; + } + vlib_cli_output (vm, "%U, fib_index %d", format_mfib_table_name, mfib->index, FIB_PROTOCOL_IP4, mfib->index); @@ -439,6 +501,8 @@ ip4_show_mfib (vlib_main_t * vm, ip4_mfib_table_show_one(mfib, vm, &src, &grp, mask); } })); + if (memory) + vlib_cli_output (vm, "totals: hash:%ld", total_hash_memory); return 0; } -- cgit 1.2.3-korg