From 33a58171e5995d9e649b414bfc77f2aab26e4c58 Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Wed, 4 Sep 2019 09:12:29 +0200 Subject: api: autogenerate api trace print/endian In addition to the external vppapitrace tool, VPP itself supports dumping of API trace files. In two formats, "custom-dump" and "dump". "dump" gives a human friendly list, and "custom-dump" is meant to give a list of commands that can be fed to VAT. This patch only deals with "dump". Prior to this fix, auto-generation was only done for the basic types. This fix adds support for any type, including lists, and supports pretty-printing of enums, strings, IP addresses, MAC addresses and so on. Usage: api trace dump For example Change-Id: I4e485680e6dcfce7489299ae6cf31d835071ac40 ---------- trace 48 ----------- vl_api_sw_interface_set_flags_t: _vl_msg_id: 75 client_index: 0 context: 10 sw_if_index: 1 flags: IF_STATUS_API_FLAG_ADMIN_UP ---------- trace 49 ----------- vl_api_sw_interface_add_del_address_t: _vl_msg_id: 88 client_index: 0 context: 11 sw_if_index: 1 is_add: 1 del_all: 0 prefix: 172.16.1.1/24 ---------- trace 51 ----------- vl_api_cli_inband_t: _vl_msg_id: 819 client_index: 0 context: 13 cmd: packet-generator capture pg0 pcap /tmp/vpp-unittest-TestMAP-YhcmDX/pg0_out.pcap disable ---------- trace 58 ----------- vl_api_ip_neighbor_add_del_t: _vl_msg_id: 199 client_index: 0 context: 20 is_add: 1 neighbor: sw_if_index: 2 flags: IP_API_NEIGHBOR_FLAG_NONE mac_address: 0202.0000.ff02 ip_address: fd01:2::2 Signed-off-by: Ole Troan Change-Id: I5556d06008de2762e7c2d35a8b0963ae670b3db1 Type: fix Signed-off-by: Ole Troan Signed-off-by: Ole Troan Signed-off-by: Ole Troan Signed-off-by: Ole Troan Signed-off-by: Ole Troan Signed-off-by: Ole Troan Signed-off-by: Ole Troan Signed-off-by: Ole Troan --- src/vlibapi/api_shared.c | 12 ++++++++++-- src/vlibapi/api_types.h | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/vlibapi') diff --git a/src/vlibapi/api_shared.c b/src/vlibapi/api_shared.c index ce7c4aec712..1e7f5c420c6 100644 --- a/src/vlibapi/api_shared.c +++ b/src/vlibapi/api_shared.c @@ -249,7 +249,6 @@ vl_msg_api_trace_save (api_main_t * am, vl_api_trace_which_t which, FILE * fp) fh.wrapped = tp->wrapped; fh.nitems = clib_host_to_net_u32 (vec_len (tp->traces)); u8 *m = vl_api_serialize_message_table (am, 0); - clib_warning ("Message table length %d", vec_len (m)); fh.msgtbl_size = clib_host_to_net_u32 (vec_len (m)); if (fwrite (&fh, sizeof (fh), 1, fp) != 1) @@ -1059,7 +1058,8 @@ vl_msg_pop_heap (void *oldheap) int vl_api_to_api_string (u32 len, const char *buf, vl_api_string_t * str) { - clib_memcpy_fast (str->buf, buf, len); + if (len) + clib_memcpy_fast (str->buf, buf, len); str->length = htonl (len); return len + sizeof (u32); } @@ -1086,6 +1086,14 @@ vl_api_string_len (vl_api_string_t * astr) return clib_net_to_host_u32 (astr->length); } +u8 * +vl_api_format_string (u8 * s, va_list * args) +{ + vl_api_string_t *a = va_arg (*args, vl_api_string_t *); + vec_add (s, a->buf, clib_net_to_host_u32 (a->length)); + return s; +} + /* * Returns a new vector. Remember to free it after use. */ diff --git a/src/vlibapi/api_types.h b/src/vlibapi/api_types.h index 04f84a5f908..8cd47bb770f 100644 --- a/src/vlibapi/api_types.h +++ b/src/vlibapi/api_types.h @@ -21,7 +21,7 @@ #define included_api_types_h #include - +#include #include #include #include @@ -43,6 +43,7 @@ extern int vl_api_vec_to_api_string (const u8 *vec, vl_api_string_t * str); extern u8 * vl_api_from_api_string (vl_api_string_t * astr); extern u32 vl_api_string_len (vl_api_string_t * astr); extern u8 * vl_api_from_api_to_vec (vl_api_string_t *astr); +extern u8 *vl_api_format_string (u8 *s, va_list *args); #ifdef __cplusplus } -- cgit 1.2.3-korg