aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlibapi
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-07-30 15:38:13 +0200
committerDave Barach <openvpp@barachs.net>2019-08-12 12:37:37 +0000
commitaf8075529fd660a487d1c2b8069da1b4a3714ec3 (patch)
tree782606eebdf728caf6d6568f907f3d3c594a26a5 /src/vlibapi
parent3d674e86b719a876be15f05b7ef9cb635717016e (diff)
api: vppapitrace JSON/API trace converter
Usage: vppapitrace.py [-h] [--debug] [--apidir APIDIR] {convert,replay} ... optional arguments: -h, --help show this help message and exit --debug enable debug mode --apidir APIDIR Location of JSON API definitions subcommands: valid subcommands {convert,replay} additional help convert Convert API trace to JSON or Python and back replay Replay messages to running VPP instance To convert an API trace file to JSON: vppapitrace convert /tmp/api.trace trace.json To convert an (edited) JSON file back to API trace for replay: vppapitrace convert trace.json api-edited.trace To generate a Python file that can be replayed: vppapitrace convert /tmp/api.trace trace.py vppapitrace convert trace.json trace.py Replay it to a running VPP instance: vppapitrace replay --socket /tmp/api.trace In VPP that file can be replayed with: vpp# api trace replay api-edited.trace This patch also modifies the API binary trace format, to include the message id to message name table. Ticket: VPP-1733 Change-Id: Ie6441efb53c1c93c9f778f6ae9c1758bccc8dd87 Type: refactor Signed-off-by: Ole Troan <ot@cisco.com> (cherry picked from commit edfe2c0079a756f5fb1108037c39450e3521c8bd) Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
Diffstat (limited to 'src/vlibapi')
-rw-r--r--src/vlibapi/api.h4
-rw-r--r--src/vlibapi/api_shared.c36
2 files changed, 36 insertions, 4 deletions
diff --git a/src/vlibapi/api.h b/src/vlibapi/api.h
index 7238a31f2f3..3eef0503310 100644
--- a/src/vlibapi/api.h
+++ b/src/vlibapi/api.h
@@ -30,9 +30,9 @@
/* *INDENT-OFF* */
typedef CLIB_PACKED ( struct {
- u8 endian;
- u8 wrapped;
u32 nitems;
+ u32 msgtbl_size;
+ u8 wrapped;
}) vl_api_trace_file_header_t;
/* *INDENT-ON* */
diff --git a/src/vlibapi/api_shared.c b/src/vlibapi/api_shared.c
index 355be35c677..ce7c4aec712 100644
--- a/src/vlibapi/api_shared.c
+++ b/src/vlibapi/api_shared.c
@@ -189,6 +189,29 @@ vl_msg_api_trace_free (api_main_t * am, vl_api_trace_which_t which)
return 0;
}
+u8 *
+vl_api_serialize_message_table (api_main_t * am, u8 * vector)
+{
+ serialize_main_t _sm, *sm = &_sm;
+ hash_pair_t *hp;
+ u32 nmsg = hash_elts (am->msg_index_by_name_and_crc);
+
+ serialize_open_vector (sm, vector);
+
+ /* serialize the count */
+ serialize_integer (sm, nmsg, sizeof (u32));
+
+ /* *INDENT-OFF* */
+ hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
+ ({
+ serialize_likely_small_unsigned_integer (sm, hp->value[0]);
+ serialize_cstring (sm, (char *) hp->key);
+ }));
+ /* *INDENT-ON* */
+
+ return serialize_close_vector (sm);
+}
+
int
vl_msg_api_trace_save (api_main_t * am, vl_api_trace_which_t which, FILE * fp)
{
@@ -223,15 +246,24 @@ vl_msg_api_trace_save (api_main_t * am, vl_api_trace_which_t which, FILE * fp)
}
/* Write the file header */
- fh.nitems = vec_len (tp->traces);
- fh.endian = tp->endian;
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)
{
return (-10);
}
+ /* Write the message table */
+ if (fwrite (m, vec_len (m), 1, fp) != 1)
+ {
+ return (-14);
+ }
+ vec_free (m);
+
/* No-wrap case */
if (tp->wrapped == 0)
{