aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/fib/ip4_fib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/fib/ip4_fib.c')
-rw-r--r--src/vnet/fib/ip4_fib.c81
1 files changed, 78 insertions, 3 deletions
diff --git a/src/vnet/fib/ip4_fib.c b/src/vnet/fib/ip4_fib.c
index 36cf6e73629..45f197444e4 100644
--- a/src/vnet/fib/ip4_fib.c
+++ b/src/vnet/fib/ip4_fib.c
@@ -481,6 +481,43 @@ ip4_fib_table_show_one (ip4_fib_t *fib,
FIB_ENTRY_FORMAT_DETAIL));
}
+u8 *
+format_ip4_fib_table_memory (u8 * s, va_list * args)
+{
+ fib_table_t *fib_table;
+ u64 total_memory;
+
+ total_memory = 0;
+
+ pool_foreach (fib_table, ip4_main.fibs,
+ ({
+ ip4_fib_t *fib;
+ uword fib_size;
+ int i;
+
+ fib = pool_elt_at_index(ip4_main.v4_fibs, fib_table->ft_index);
+ fib_size = ip4_fib_mtrie_memory_usage(&fib->mtrie);
+
+ for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
+ {
+ uword * hash = fib->fib_entry_by_dst_address[i];
+
+ if (NULL != hash)
+ {
+ fib_size += hash_bytes(hash);
+ }
+ }
+
+ total_memory += fib_size;
+ }));
+
+ s = format(s, "%=30s %=6d %=8ld\n",
+ "IPv4 unicast",
+ pool_elts(ip4_main.fibs), total_memory);
+
+ return (s);
+}
+
static clib_error_t *
ip4_show_fib (vlib_main_t * vm,
unformat_input_t * input,
@@ -488,15 +525,17 @@ ip4_show_fib (vlib_main_t * vm,
{
ip4_main_t * im4 = &ip4_main;
fib_table_t * fib_table;
- int verbose, matching, mtrie;
+ u64 total_mtrie_memory, total_hash_memory;
+ int verbose, matching, mtrie, memory;
ip4_address_t matching_address;
u32 matching_mask = 32;
int i, table_id = -1, fib_index = ~0;
int detail = 0;
verbose = 1;
- matching = 0;
- mtrie = 0;
+ matching = mtrie = memory = 0;
+ total_hash_memory = total_mtrie_memory = 0;
+
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (input, "brief") || unformat (input, "summary")
@@ -509,6 +548,10 @@ ip4_show_fib (vlib_main_t * vm,
else if (unformat (input, "mtrie"))
mtrie = 1;
+ else if (unformat (input, "mem") ||
+ unformat (input, "memory"))
+ memory = 1;
+
else if (unformat (input, "%U/%d",
unformat_ip4_address, &matching_address, &matching_mask))
matching = 1;
@@ -535,6 +578,32 @@ ip4_show_fib (vlib_main_t * vm,
if (fib_index != ~0 && fib_index != (int)fib->index)
continue;
+ if (memory)
+ {
+ uword mtrie_size, hash_size;
+
+ mtrie_size = ip4_fib_mtrie_memory_usage(&fib->mtrie);
+ hash_size = 0;
+
+ for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
+ {
+ uword * hash = fib->fib_entry_by_dst_address[i];
+ if (NULL != hash)
+ {
+ hash_size += hash_bytes(hash);
+ }
+ }
+ if (verbose)
+ vlib_cli_output (vm, "%U mtrie:%d hash:%d",
+ format_fib_table_name, fib->index,
+ FIB_PROTOCOL_IP4,
+ mtrie_size,
+ hash_size);
+ total_mtrie_memory += mtrie_size;
+ total_hash_memory += hash_size;
+ continue;
+ }
+
s = format(s, "%U, fib_index:%d, flow hash:[%U] locks:[",
format_fib_table_name, fib->index,
FIB_PROTOCOL_IP4,
@@ -584,6 +653,12 @@ ip4_show_fib (vlib_main_t * vm,
}
}));
+ if (memory)
+ vlib_cli_output (vm, "totals: mtrie:%ld hash:%ld all:%ld",
+ total_mtrie_memory,
+ total_hash_memory,
+ total_mtrie_memory + total_hash_memory);
+
return 0;
}