diff options
author | Andrew Yourtchenko <ayourtch@gmail.com> | 2017-04-21 14:47:02 +0200 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2017-05-15 21:14:51 +0000 |
commit | c6833f804e6f1ac00c3d04c26237a2543713de95 (patch) | |
tree | 82ece6b64a41a19bedce0b6acc729fa5ab6a44e1 /vpp-api-test/vat/plugin_api.c | |
parent | a558f61eb9bf6eec7803e0afe78cce14a590d4e1 (diff) |
Fix pretty-printing in "api trace custom-dump" (VPP-683)stable/1701
This commit is different from the ones in 1704 and master
in that it also adds format_ip6_address which was missing
and is needed by the print functions.
Change-Id: I45a4c28bc54c6e7e01bf42c6c6e38a96a292a31d
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
Diffstat (limited to 'vpp-api-test/vat/plugin_api.c')
-rw-r--r-- | vpp-api-test/vat/plugin_api.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/vpp-api-test/vat/plugin_api.c b/vpp-api-test/vat/plugin_api.c index 4e1eb897844..c96982f54aa 100644 --- a/vpp-api-test/vat/plugin_api.c +++ b/vpp-api-test/vat/plugin_api.c @@ -194,6 +194,56 @@ format_ip4_address (u8 * s, va_list * args) } u8 * +format_ip6_address (u8 * s, va_list * args) +{ + ip6_address_t *a = va_arg (*args, ip6_address_t *); + u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon; + + i_max_n_zero = ARRAY_LEN (a->as_u16); + max_n_zeros = 0; + i_first_zero = i_max_n_zero; + n_zeros = 0; + for (i = 0; i < ARRAY_LEN (a->as_u16); i++) + { + u32 is_zero = a->as_u16[i] == 0; + if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16)) + { + i_first_zero = i; + n_zeros = 0; + } + n_zeros += is_zero; + if ((!is_zero && n_zeros > max_n_zeros) + || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros)) + { + i_max_n_zero = i_first_zero; + max_n_zeros = n_zeros; + i_first_zero = ARRAY_LEN (a->as_u16); + n_zeros = 0; + } + } + + last_double_colon = 0; + for (i = 0; i < ARRAY_LEN (a->as_u16); i++) + { + if (i == i_max_n_zero && max_n_zeros > 1) + { + s = format (s, "::"); + i += max_n_zeros - 1; + last_double_colon = 1; + } + else + { + s = format (s, "%s%x", + (last_double_colon || i == 0) ? "" : ":", + clib_net_to_host_u16 (a->as_u16[i])); + last_double_colon = 0; + } + } + + return s; +} + +u8 * format_ethernet_address (u8 * s, va_list * args) { u8 *a = va_arg (*args, u8 *); |