api: replace print functions wth format 87/36187/10
authorDamjan Marion <damarion@cisco.com>
Fri, 20 May 2022 14:01:22 +0000 (16:01 +0200)
committerOle Tr�an <otroan@employees.org>
Mon, 26 Sep 2022 08:14:29 +0000 (08:14 +0000)
Type: improvement
Change-Id: I7f7050c19453a69a7fb6c5e62f8f57db847d9144
Signed-off-by: Damjan Marion <damarion@cisco.com>
39 files changed:
src/plugins/acl/acl.c
src/plugins/acl/acl_test.c
src/plugins/adl/adl_api.c
src/plugins/dhcp/dhcp_test.c
src/plugins/dns/dns.c
src/plugins/flowprobe/flowprobe.c
src/plugins/geneve/geneve_test.c
src/plugins/hs_apps/sapi/vpp_echo_bapi.c
src/plugins/http_static/http_static.c
src/plugins/l2tp/l2tp_test.c
src/plugins/lacp/lacp_api.c
src/plugins/lb/api.c
src/plugins/lisp/lisp-cp/lisp_cp_test.c
src/plugins/lisp/lisp-cp/one_test.c
src/plugins/lisp/lisp-gpe/lisp_gpe_test.c
src/plugins/lldp/lldp_test.c
src/plugins/mactime/mactime.c
src/plugins/mactime/mactime_top.c
src/plugins/nsh/nsh-md2-ioam/nsh_md2_ioam_api.c
src/plugins/stn/stn_api.c
src/plugins/tlsopenssl/tls_openssl_api.c
src/plugins/tracedump/tracedump_test.c
src/tools/vppapigen/vppapigen_c.py
src/vat/api_format.c
src/vcl/vcl_bapi.c
src/vlibapi/CMakeLists.txt
src/vlibapi/api.h
src/vlibapi/api_common.h
src/vlibapi/api_doc.rst
src/vlibapi/api_format.c [new file with mode: 0644]
src/vlibapi/api_shared.c
src/vlibmemory/memclnt_api.c
src/vlibmemory/memory_api.c
src/vlibmemory/memory_client.c
src/vlibmemory/socket_api.c
src/vlibmemory/socket_client.c
src/vlibmemory/vlib_api_cli.c
src/vnet/ip6-nd/rd_cp.c
src/vnet/srmpls/sr_mpls_api.c

index a7b8104..eb38150 100644 (file)
@@ -36,7 +36,6 @@
 #include <acl/acl.api_enum.h>
 #include <acl/acl.api_types.h>
 
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 
 #include "fa_node.h"
 #include "public_inlines.h"
index 7514a8e..0c21868 100644 (file)
@@ -36,8 +36,6 @@ uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
 /* Declare message IDs */
 #include <acl/acl.api_enum.h>
 #include <acl/acl.api_types.h>
-#define vl_print(handle, ...)
-#undef vl_print
 #define vl_endianfun            /* define message structures */
 #include <acl/acl.api.h>
 #undef vl_endianfun
index dba3b0c..8bd805d 100644 (file)
@@ -30,7 +30,6 @@
 #include <adl/adl.api_enum.h>
 #include <adl/adl.api_types.h>
 
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 
 #define REPLY_MSG_ID_BASE am->msg_id_base
 #include <vlibapi/api_helper_macros.h>
index c1894ec..d8288e6 100644 (file)
@@ -39,13 +39,11 @@ dhcp_test_main_t dhcp_test_main;
 #define __plugin_msg_base dhcp_test_main.msg_id_base
 #include <vlibapi/vat_helper_macros.h>
 
-/* Macro to finish up custom dump fns */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define FINISH                                  \
-    vec_add1 (s, 0);                            \
-    vl_print (handle, (char *)s);               \
-    vec_free (s);                               \
-    return handle;
+#define FINISH                                                                \
+  vec_add1 (s, 0);                                                            \
+  vlib_cli_output (handle, (char *) s);                                       \
+  vec_free (s);                                                               \
+  return handle;
 
 static int
 api_dhcp_proxy_config (vat_main_t * vam)
index 1839379..4a283bf 100644 (file)
 #define REPLY_MSG_ID_BASE dm->msg_id_base
 #include <vlibapi/api_helper_macros.h>
 
-/* Macro to finish up custom dump fns */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define FINISH                                  \
-    vec_add1 (s, 0);                            \
-    vl_print (handle, (char *)s);               \
-    vec_free (s);                               \
-    return handle;
+#define FINISH                                                                \
+  vec_add1 (s, 0);                                                            \
+  vlib_cli_output (handle, (char *) s);                                       \
+  vec_free (s);                                                               \
+  return handle;
 
 dns_main_t dns_main;
 
index df0e5ff..058a642 100644 (file)
@@ -90,13 +90,11 @@ VNET_FEATURE_INIT (flowprobe_output_l2, static) = {
 };
 /* *INDENT-ON* */
 
-/* Macro to finish up custom dump fns */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define FINISH                                  \
-    vec_add1 (s, 0);                            \
-    vl_print (handle, (char *)s);               \
-    vec_free (s);                               \
-    return handle;
+#define FINISH                                                                \
+  vec_add1 (s, 0);                                                            \
+  vlib_cli_output (handle, (char *) s);                                       \
+  vec_free (s);                                                               \
+  return handle;
 
 static inline ipfix_field_specifier_t *
 flowprobe_template_ip4_fields (ipfix_field_specifier_t * f)
index 2eb3821..e777e9b 100644 (file)
@@ -41,13 +41,11 @@ geneve_test_main_t geneve_test_main;
 #define __plugin_msg_base geneve_test_main.msg_id_base
 #include <vlibapi/vat_helper_macros.h>
 
-/* Macro to finish up custom dump fns */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define FINISH                                  \
-    vec_add1 (s, 0);                            \
-    vl_print (handle, (char *)s);               \
-    vec_free (s);                               \
-    return handle;
+#define FINISH                                                                \
+  vec_add1 (s, 0);                                                            \
+  vlib_cli_output (handle, (char *) s);                                       \
+  vec_free (s);                                                               \
+  return handle;
 
 static void vl_api_geneve_add_del_tunnel_reply_t_handler
   (vl_api_geneve_add_del_tunnel_reply_t * mp)
index e38559c..0652b86 100644 (file)
@@ -556,7 +556,6 @@ _(APPLICATION_DETACH_REPLY, application_detach_reply)            \
 _(APP_ADD_CERT_KEY_PAIR_REPLY, app_add_cert_key_pair_reply)      \
 _(APP_DEL_CERT_KEY_PAIR_REPLY, app_del_cert_key_pair_reply)
 
-#define vl_print(handle, ...) fformat (handle, __VA_ARGS__)
 #define vl_endianfun
 #include <vnet/session/session.api.h>
 #undef vl_endianfun
@@ -586,12 +585,11 @@ echo_api_hookup (echo_main_t * em)
     return;
 
 #define _(N, n)                                                               \
-  vl_msg_api_set_handlers (                                                   \
-    REPLY_MSG_ID_BASE + VL_API_##N, #n, vl_api_##n##_t_handler,               \
-    vl_noop_handler, vl_api_##n##_t_endian, vl_api_##n##_t_print,             \
-    sizeof (vl_api_##n##_t), 1, vl_api_##n##_t_print_json,                    \
-    vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson,                           \
-    vl_api_##n##_t_calc_size);
+  vl_msg_api_set_handlers (REPLY_MSG_ID_BASE + VL_API_##N, #n,                \
+                          vl_api_##n##_t_handler, vl_api_##n##_t_endian,     \
+                          vl_api_##n##_t_format, sizeof (vl_api_##n##_t), 1, \
+                          vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson,    \
+                          vl_api_##n##_t_calc_size);
   foreach_quic_echo_msg;
 #undef _
 }
index 005eefc..8f8fe37 100644 (file)
@@ -27,7 +27,6 @@
 
 #include <vpp/api/types.h>
 
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 
 #define REPLY_MSG_ID_BASE hsm->msg_id_base
 #include <vlibapi/api_helper_macros.h>
index fef6121..3369131 100644 (file)
@@ -41,13 +41,11 @@ l2tp_test_main_t l2tp_test_main;
 #define __plugin_msg_base l2tp_test_main.msg_id_base
 #include <vlibapi/vat_helper_macros.h>
 
-/* Macro to finish up custom dump fns */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define FINISH                                  \
-    vec_add1 (s, 0);                            \
-    vl_print (handle, (char *)s);               \
-    vec_free (s);                               \
-    return handle;
+#define FINISH                                                                \
+  vec_add1 (s, 0);                                                            \
+  vlib_cli_output (handle, (char *) s);                                       \
+  vec_free (s);                                                               \
+  return handle;
 
 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
   (vl_api_l2tpv3_create_tunnel_reply_t * mp)
index fab28cb..cdf05aa 100644 (file)
 #include <lacp/lacp.api_enum.h>
 #include <lacp/lacp.api_types.h>
 
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-
-/* Macro to finish up custom dump fns */
-#define FINISH                                  \
-    vec_add1 (s, 0);                            \
-    vl_print (handle, (char *)s);               \
-    vec_free (s);                               \
-    return handle;
+#define FINISH                                                                \
+  vec_add1 (s, 0);                                                            \
+  vlib_cli_output (handle, (char *) s);                                       \
+  vec_free (s);                                                               \
+  return handle;
 
 #define REPLY_MSG_ID_BASE lm->msg_id_base
 #include <vlibapi/api_helper_macros.h>
index e44f815..3aa745c 100644 (file)
 #include <lb/lb.api_enum.h>
 #include <lb/lb.api_types.h>
 
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 
 #define REPLY_MSG_ID_BASE lbm->msg_id_base
 #include <vlibapi/api_helper_macros.h>
 
-/* Macro to finish up custom dump fns */
-#define FINISH                                  \
-    vec_add1 (s, 0);                            \
-    vl_print (handle, (char *)s);               \
-    vec_free (s);                               \
-    return handle;
+#define FINISH                                                                \
+  vec_add1 (s, 0);                                                            \
+  vlib_cli_output (handle, (char *) s);                                       \
+  vec_free (s);                                                               \
+  return handle;
 
 static void
 vl_api_lb_conf_t_handler
index 0ab4180..8657aae 100644 (file)
@@ -41,13 +41,11 @@ lisp_test_main_t lisp_test_main;
 #define __plugin_msg_base lisp_test_main.msg_id_base
 #include <vlibapi/vat_helper_macros.h>
 
-/* Macro to finish up custom dump fns */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define FINISH                                  \
-    vec_add1 (s, 0);                            \
-    vl_print (handle, (char *)s);               \
-    vec_free (s);                               \
-    return handle;
+#define FINISH                                                                \
+  vec_add1 (s, 0);                                                            \
+  vlib_cli_output (handle, (char *) s);                                       \
+  vec_free (s);                                                               \
+  return handle;
 
 typedef struct
 {
index 7ca1f31..ad308b7 100644 (file)
@@ -41,13 +41,11 @@ one_test_main_t one_test_main;
 #define __plugin_msg_base one_test_main.msg_id_base
 #include <vlibapi/vat_helper_macros.h>
 
-/* Macro to finish up custom dump fns */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define FINISH                                  \
-    vec_add1 (s, 0);                            \
-    vl_print (handle, (char *)s);               \
-    vec_free (s);                               \
-    return handle;
+#define FINISH                                                                \
+  vec_add1 (s, 0);                                                            \
+  vlib_cli_output (handle, (char *) s);                                       \
+  vec_free (s);                                                               \
+  return handle;
 
 #define LISP_PING(_lm, mp_ping)                                         \
   if (!(_lm)->ping_id)                                                  \
index 6f40e64..2f1a418 100644 (file)
@@ -41,13 +41,11 @@ lisp_gpe_test_main_t lisp_gpe_test_main;
 #define __plugin_msg_base lisp_gpe_test_main.msg_id_base
 #include <vlibapi/vat_helper_macros.h>
 
-/* Macro to finish up custom dump fns */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define FINISH                                  \
-    vec_add1 (s, 0);                            \
-    vl_print (handle, (char *)s);               \
-    vec_free (s);                               \
-    return handle;
+#define FINISH                                                                \
+  vec_add1 (s, 0);                                                            \
+  vlib_cli_output (handle, (char *) s);                                       \
+  vec_free (s);                                                               \
+  return handle;
 
 #define LISP_PING(_lm, mp_ping)                                         \
   if (!(_lm)->ping_id)                                                  \
index 661487c..6eb3e0f 100644 (file)
@@ -38,13 +38,11 @@ lldp_test_main_t lldp_test_main;
 #define __plugin_msg_base lldp_test_main.msg_id_base
 #include <vlibapi/vat_helper_macros.h>
 
-/* Macro to finish up custom dump fns */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define FINISH                                  \
-    vec_add1 (s, 0);                            \
-    vl_print (handle, (char *)s);               \
-    vec_free (s);                               \
-    return handle;
+#define FINISH                                                                \
+  vec_add1 (s, 0);                                                            \
+  vlib_cli_output (handle, (char *) s);                                       \
+  vec_free (s);                                                               \
+  return handle;
 
 static int
 api_lldp_config (vat_main_t * vam)
index f878ffe..ffb41c2 100644 (file)
@@ -28,7 +28,6 @@
 #include <mactime/mactime.api_enum.h>
 #include <mactime/mactime.api_types.h>
 
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 
 #define REPLY_MSG_ID_BASE mm->msg_id_base
 #include <vlibapi/api_helper_macros.h>
index d7223f4..60c3e5c 100644 (file)
@@ -106,7 +106,6 @@ vl_api_mactime_details_t_handler (vl_api_mactime_details_t * mp)
     }
 }
 
-#define vl_print(handle, ...) fformat(handle, __VA_ARGS__)
 #define vl_endianfun           /* define message structures */
 #include <mactime/mactime.api.h>
 #undef vl_endianfun
@@ -145,10 +144,9 @@ connect_to_vpp (char *name)
 
 #define _(N, n)                                                               \
   vl_msg_api_set_handlers ((VL_API_##N + mm->msg_id_base), #n,                \
-                          vl_api_##n##_t_handler, vl_noop_handler,           \
-                          vl_api_##n##_t_endian, vl_api_##n##_t_print,       \
-                          sizeof (vl_api_##n##_t), 1, vl_api_##n##_t_tojson, \
-                          vl_api_##n##_t_fromjson);
+                          vl_api_##n##_t_handler, vl_api_##n##_t_endian,     \
+                          vl_api_##n##_t_format, sizeof (vl_api_##n##_t), 1, \
+                          vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson);
   foreach_mactime_api_msg;
 #undef _
 
index 9ed835b..36c2216 100644 (file)
@@ -38,7 +38,6 @@
 #undef vl_endianfun
 
 /* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 #define vl_printfun
 #include <nsh/nsh.api.h>
 #undef vl_printfun
index e868593..8d96014 100644 (file)
 #define REPLY_MSG_ID_BASE stn_main.msg_id_base
 #include <vlibapi/api_helper_macros.h>
 
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-/* Macro to finish up custom dump fns */
-#define FINISH                                  \
-    vec_add1 (s, 0);                            \
-    vl_print (handle, (char *)s);               \
-    vec_free (s);                               \
-    return handle;
+#define FINISH                                                                \
+  vec_add1 (s, 0);                                                            \
+  vlib_cli_output (handle, (char *) s);                                       \
+  vec_free (s);                                                               \
+  return handle;
 
 static void
 vl_api_stn_add_del_rule_t_handler (vl_api_stn_add_del_rule_t * mp)
index c34829f..0b17271 100644 (file)
@@ -23,7 +23,6 @@
 #include <tlsopenssl/tls_openssl.api_enum.h>
 #include <tlsopenssl/tls_openssl.api_types.h>
 
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 
 #define REPLY_MSG_ID_BASE om->msg_id_base
 #include <vlibapi/api_helper_macros.h>
index abb8105..f2bb63e 100644 (file)
@@ -235,7 +235,6 @@ api_trace_clear_capture (vat_main_t * vam)
 
 
 
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 #define vl_endianfun
 #include <tracedump/tracedump.api.h>
 #undef vl_endianfun
@@ -251,9 +250,8 @@ manual_setup_message_id_table (vat_main_t * vam)
 {
   vl_msg_api_set_handlers (
     VL_API_TRACE_DETAILS + tracedump_test_main.msg_id_base, "trace_details",
-    vl_api_trace_details_t_handler, vl_noop_handler,
-    vl_api_trace_details_t_endian, vl_api_trace_details_t_print,
-    sizeof (vl_api_trace_details_t), 1, vl_api_trace_details_t_print_json,
+    vl_api_trace_details_t_handler, vl_api_trace_details_t_endian,
+    vl_api_trace_details_t_format, sizeof (vl_api_trace_details_t), 1,
     vl_api_trace_details_t_tojson, vl_api_trace_details_t_fromjson,
     vl_api_trace_details_t_calc_size);
 }
index a065653..b9f9e07 100644 (file)
@@ -1028,9 +1028,9 @@ def printfun(objs, stream, modulename):
 """
 
     signature = """\
-static inline void *vl_api_{name}_t_print{suffix} (vl_api_{name}_t *a, void *handle)
+static inline u8 *vl_api_{name}_t_format (u8 *s,  va_list *args)
 {{
-    u8 *s = 0;
+    __attribute__((unused)) vl_api_{name}_t *a = va_arg (*args, vl_api_{name}_t *);
     u32 indent __attribute__((unused)) = 2;
     int i __attribute__((unused));
 """
@@ -1041,27 +1041,14 @@ static inline void *vl_api_{name}_t_print{suffix} (vl_api_{name}_t *a, void *han
     pp = Printfun(stream)
     for t in objs:
         if t.manual_print:
-            write("/***** manual: vl_api_%s_t_print  *****/\n\n" % t.name)
+            write("/***** manual: vl_api_%s_t_format *****/\n\n" % t.name)
             continue
         write(signature.format(name=t.name, suffix=""))
         write("    /* Message definition: vl_api_{}_t: */\n".format(t.name))
         write('    s = format(s, "vl_api_%s_t:");\n' % t.name)
         for o in t.block:
             pp.print_obj(o, stream)
-        write("    vec_add1(s, 0);\n")
-        write("    vl_print (handle, (char *)s);\n")
-        write("    vec_free (s);\n")
-        write("    return handle;\n")
-        write("}\n\n")
-
-        write(signature.format(name=t.name, suffix="_json"))
-        write("    cJSON * o = vl_api_{}_t_tojson(a);\n".format(t.name))
-        write("    (void)s;\n")
-        write("    char *out = cJSON_Print(o);\n")
-        write("    vl_print(handle, out);\n")
-        write("    cJSON_Delete(o);\n")
-        write("    cJSON_free(out);\n")
-        write("    return handle;\n")
+        write("    return s;\n")
         write("}\n\n")
 
     write("\n#endif")
@@ -1103,7 +1090,7 @@ static inline u8 *format_vl_api_{name}_t (u8 *s, va_list * args)
             continue
 
         if t.manual_print:
-            write("/***** manual: vl_api_%s_t_print  *****/\n\n" % t.name)
+            write("/***** manual: vl_api_%s_t_format *****/\n\n" % t.name)
             continue
 
         if t.__class__.__name__ == "Using":
@@ -1525,7 +1512,6 @@ def generate_c_boilerplate(services, defines, counters, file_crc, module, stream
 #undef vl_calsizefun
 
 /* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 #define vl_printfun
 #include "{module}.api.h"
 #undef vl_printfun
@@ -1556,12 +1542,10 @@ def generate_c_boilerplate(services, defines, counters, file_crc, module, stream
             " {{.id = VL_API_{ID} + msg_id_base,\n"
             '   .name = "{n}",\n'
             "   .handler = vl_api_{n}_t_handler,\n"
-            "   .cleanup = vl_noop_handler,\n"
             "   .endian = vl_api_{n}_t_endian,\n"
-            "   .print = vl_api_{n}_t_print,\n"
+            "   .format_fn = vl_api_{n}_t_format,\n"
             "   .traced = 1,\n"
             "   .replay = 1,\n"
-            "   .print_json = vl_api_{n}_t_print_json,\n"
             "   .tojson = vl_api_{n}_t_tojson,\n"
             "   .fromjson = vl_api_{n}_t_fromjson,\n"
             "   .calc_size = vl_api_{n}_t_calc_size,\n"
@@ -1577,12 +1561,10 @@ def generate_c_boilerplate(services, defines, counters, file_crc, module, stream
                 "{{.id = VL_API_{ID} + msg_id_base,\n"
                 '  .name = "{n}",\n'
                 "  .handler = 0,\n"
-                "  .cleanup = vl_noop_handler,\n"
                 "  .endian = vl_api_{n}_t_endian,\n"
-                "  .print = vl_api_{n}_t_print,\n"
+                "  .format_fn = vl_api_{n}_t_format,\n"
                 "  .traced = 1,\n"
                 "  .replay = 1,\n"
-                "  .print_json = vl_api_{n}_t_print_json,\n"
                 "  .tojson = vl_api_{n}_t_tojson,\n"
                 "  .fromjson = vl_api_{n}_t_fromjson,\n"
                 "  .calc_size = vl_api_{n}_t_calc_size,\n"
@@ -1631,7 +1613,6 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
 #undef vl_calsizefun
 
 /* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 #define vl_printfun
 #include "{module}.api.h"
 #undef vl_printfun
@@ -1678,8 +1659,10 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
                 continue
             write("static void\n")
             write("vl_api_{n}_t_handler (vl_api_{n}_t * mp) {{\n".format(n=e))
-            write('    vl_print(0, "{n} event called:");\n'.format(n=e))
-            write("    vl_api_{n}_t_print(mp, 0);\n".format(n=e))
+            write('    vlib_cli_output(0, "{n} event called:");\n'.format(n=e))
+            write(
+                '    vlib_cli_output(0, "%U", vl_api_{n}_t_format, mp);\n'.format(n=e)
+            )
             write("}\n")
 
     write("static void\n")
@@ -1689,11 +1672,9 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
             "   vl_msg_api_set_handlers(VL_API_{ID} + msg_id_base, "
             '                           "{n}",\n'
             "                           vl_api_{n}_t_handler, "
-            "                           vl_noop_handler,\n"
             "                           vl_api_{n}_t_endian, "
-            "                           vl_api_{n}_t_print,\n"
+            "                           vl_api_{n}_t_format,\n"
             "                           sizeof(vl_api_{n}_t), 1,\n"
-            "                           vl_api_{n}_t_print_json,\n"
             "                           vl_api_{n}_t_tojson,\n"
             "                           vl_api_{n}_t_fromjson,\n"
             "                           vl_api_{n}_t_calc_size);\n".format(
@@ -1720,11 +1701,9 @@ def generate_c_test_boilerplate(services, defines, file_crc, module, plugin, str
                 "   vl_msg_api_set_handlers(VL_API_{ID} + msg_id_base, "
                 '                          "{n}",\n'
                 "                           vl_api_{n}_t_handler, "
-                "                           vl_noop_handler,\n"
                 "                           vl_api_{n}_t_endian, "
-                "                           vl_api_{n}_t_print,\n"
+                "                           vl_api_{n}_t_format,\n"
                 "                           sizeof(vl_api_{n}_t), 1,\n"
-                "                           vl_api_{n}_t_print_json,\n"
                 "                           vl_api_{n}_t_tojson,\n"
                 "                           vl_api_{n}_t_fromjson,\n"
                 "                           vl_api_{n}_t_calc_size);\n".format(
@@ -1968,7 +1947,6 @@ def generate_c_test2_boilerplate(services, defines, module, stream):
 #include "{module}.api.h"
 #undef vl_calsizefun
 
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 #define vl_printfun
 #include "{module}.api.h"
 #undef vl_printfun
index 14546b5..72ce34f 100644 (file)
 #undef vl_calcsizefun
 
 /* instantiate all the print functions we know about */
-#if VPP_API_TEST_BUILTIN == 0
-#define vl_print(handle, ...)
-#else
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#endif
 #define vl_printfun
 #include <vlibmemory/memclnt.api.h>
 #undef vl_printfun
@@ -564,9 +559,6 @@ ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
 }
 
 
-#define vl_api_bridge_domain_details_t_endian vl_noop_handler
-#define vl_api_bridge_domain_details_t_print vl_noop_handler
-
 static void vl_api_get_first_msg_id_reply_t_handler
   (vl_api_get_first_msg_id_reply_t * mp)
 {
@@ -2742,9 +2734,8 @@ vat_api_hookup (vat_main_t * vam)
 {
 #define _(N, n)                                                               \
   vl_msg_api_set_handlers (                                                   \
-    VL_API_##N + 1, #n, vl_api_##n##_t_handler_uni, vl_noop_handler,          \
-    vl_api_##n##_t_endian, vl_api_##n##_t_print, sizeof (vl_api_##n##_t), 1,  \
-    vl_api_##n##_t_print_json, vl_api_##n##_t_tojson,                         \
+    VL_API_##N + 1, #n, vl_api_##n##_t_handler_uni, vl_api_##n##_t_endian,    \
+    vl_api_##n##_t_format, sizeof (vl_api_##n##_t), 1, vl_api_##n##_t_tojson, \
     vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);
   foreach_vpe_api_reply_msg;
 #if VPP_API_TEST_BUILTIN == 0
index bbb0420..7e5203d 100644 (file)
@@ -271,7 +271,6 @@ vl_api_app_del_cert_key_pair_reply_t_handler (
   _ (APP_DEL_CERT_KEY_PAIR_REPLY, app_del_cert_key_pair_reply)                \
   _ (APP_WORKER_ADD_DEL_REPLY, app_worker_add_del_reply)
 
-#define vl_print(handle, ...) fformat (handle, __VA_ARGS__)
 #define vl_endianfun         /* define message structures */
 #include <vnet/session/session.api.h>
 #undef vl_endianfun
@@ -303,12 +302,11 @@ vcl_bapi_hookup (void)
     return;
 
 #define _(N, n)                                                               \
-  vl_msg_api_set_handlers (                                                   \
-    REPLY_MSG_ID_BASE + VL_API_##N, #n, vl_api_##n##_t_handler,               \
-    vl_noop_handler, vl_api_##n##_t_endian, vl_api_##n##_t_print,             \
-    sizeof (vl_api_##n##_t), 1, vl_api_##n##_t_print_json,                    \
-    vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson,                           \
-    vl_api_##n##_t_calc_size);
+  vl_msg_api_set_handlers (REPLY_MSG_ID_BASE + VL_API_##N, #n,                \
+                          vl_api_##n##_t_handler, vl_api_##n##_t_endian,     \
+                          vl_api_##n##_t_format, sizeof (vl_api_##n##_t), 1, \
+                          vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson,    \
+                          vl_api_##n##_t_calc_size);
   foreach_sock_msg;
 #undef _
 }
index 95bb4cf..6476b5a 100644 (file)
@@ -14,6 +14,7 @@
 add_vpp_library (vlibapi
   SOURCES
   api_shared.c
+  api_format.c
   node_serialize.c
   memory_shared.c
 
index f838a80..705678b 100644 (file)
@@ -148,6 +148,9 @@ vl_api_allow_msg_replay (api_main_t *am, u32 msg_id, int v)
   am->msg_data[msg_id].replay_allowed = v != 0;
 }
 
+format_function_t format_vl_api_msg_text;
+format_function_t format_vl_api_msg_json;
+
 #endif /* included_api_h */
 /*
  * fd.io coding-style-patch-verification: ON
index 66a547f..37ffb58 100644 (file)
@@ -122,8 +122,7 @@ typedef struct
   void *handler;               /**< the message handler  */
   void *cleanup;               /**< non-default message cleanup handler */
   void *endian;                        /**< message endian function  */
-  void *print;                 /**< message print function  */
-  void *print_json;            /**< message print function (JSON format)  */
+  void *format_fn;             /**< message format function  */
   void *tojson;                        /**< binary to JSON convert function */
   void *fromjson;              /**< JSON to binary convert function */
   void *calc_size;             /**< message size calculation */
@@ -173,10 +172,9 @@ void vl_msg_api_cleanup_handler (void *the_msg);
 void vl_msg_api_replay_handler (void *the_msg);
 void vl_msg_api_socket_handler (void *the_msg, uword msg_len);
 void vl_msg_api_set_handlers (int msg_id, char *msg_name, void *handler,
-                             void *cleanup, void *endian, void *print,
-                             int msg_size, int traced, void *print_json,
-                             void *tojson, void *fromjson,
-                             void *validate_size);
+                             void *endian, format_function_t *format,
+                             int msg_size, int traced, void *tojson,
+                             void *fromjson, void *validate_size);
 void vl_msg_api_clean_handlers (int msg_id);
 void vl_msg_api_config (vl_msg_api_msg_config_t *);
 void vl_msg_api_set_cleanup_handler (int msg_id, void *fp);
@@ -191,7 +189,6 @@ void vl_msg_api_barrier_trace_context (const char *context)
 #define vl_msg_api_barrier_trace_context(X)
 #endif
 void vl_msg_api_free (void *);
-void vl_noop_handler (void *mp);
 void vl_msg_api_increment_missing_client_counter (void);
 void vl_msg_api_post_mortem_dump (void);
 void vl_msg_api_post_mortem_dump_enable_disable (int enable);
@@ -234,6 +231,9 @@ typedef struct
   /** Message name vector */
   const char *name;
 
+  /** Message format function */
+  format_function_t *format_fn;
+
   /** Message convert function vector */
   cJSON *(*tojson_handler) (void *);
 
@@ -243,12 +243,6 @@ typedef struct
   /** Message endian handler vector */
   void (*endian_handler) (void *);
 
-  /** Message print function vector */
-  void (*print_handler) (void *, void *);
-
-  /** Message print function vector in JSON */
-  void (*print_json_handler) (void *, void *);
-
   /** Message calc size function vector */
   uword (*calc_size_func) (void *);
 
index 7d2b80a..2131cc1 100644 (file)
@@ -300,7 +300,6 @@ Set up message handlers about as follows:
        #undef vl_endianfun
 
        /* instantiate all the print functions we know about */
-       #define vl_print(handle, ...)
        #define vl_printfun
        #include <vpp/api/vpe_all_api_h.h>
        #undef vl_printfun
diff --git a/src/vlibapi/api_format.c b/src/vlibapi/api_format.c
new file mode 100644 (file)
index 0000000..f7bb9d3
--- /dev/null
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: Apache-2.0
+ * Copyright(c) 2022 Cisco Systems, Inc.
+ */
+
+#include <vppinfra/format.h>
+#include <vlibapi/api.h>
+
+u8 *
+format_vl_api_msg_text (u8 *s, va_list *args)
+{
+  api_main_t *am = va_arg (*args, api_main_t *);
+  u32 msg_id = va_arg (*args, u32);
+  void *msg = va_arg (*args, void *);
+  vl_api_msg_data_t *m = vl_api_get_msg_data (am, msg_id);
+
+  if (m->format_fn)
+    s = format (s, "%U", m->format_fn, msg);
+  else
+    s = format (s, "[format handler missing for `%s`]", m->name);
+  return s;
+}
+
+u8 *
+format_vl_api_msg_json (u8 *s, va_list *args)
+{
+  api_main_t *am = va_arg (*args, api_main_t *);
+  u32 msg_id = va_arg (*args, u32);
+  void *msg = va_arg (*args, void *);
+  vl_api_msg_data_t *m = vl_api_get_msg_data (am, msg_id);
+
+  cJSON *o = m->tojson_handler (msg);
+  char *out = cJSON_Print (o);
+
+  s = format (s, "%s", out);
+
+  cJSON_Delete (o);
+  cJSON_free (out);
+  return s;
+}
index 73ef3ce..0a98348 100644 (file)
@@ -531,10 +531,7 @@ msg_handler_internal (api_main_t *am, void *the_msg, uword msg_len,
       if (am->msg_print_flag)
        {
          fformat (stdout, "[%d]: %s\n", id, m->name);
-         if (m->print_handler)
-           m->print_handler (the_msg, stdout);
-         else
-           fformat (stdout, "  [no registered print fn]\n");
+         fformat (stdout, "%U", format_vl_api_msg_text, am, id, the_msg);
        }
 
       uword calc_size = 0;
@@ -769,8 +766,7 @@ vl_msg_api_config (vl_msg_api_msg_config_t * c)
   m->handler = c->handler;
   m->cleanup_handler = c->cleanup;
   m->endian_handler = c->endian;
-  m->print_handler = c->print;
-  m->print_json_handler = c->print_json;
+  m->format_fn = c->format_fn;
   m->tojson_handler = c->tojson;
   m->fromjson_handler = c->fromjson;
   m->calc_size_func = c->calc_size;
@@ -793,10 +789,9 @@ vl_msg_api_config (vl_msg_api_msg_config_t * c)
  * preserve the old API for a while
  */
 void
-vl_msg_api_set_handlers (int id, char *name, void *handler, void *cleanup,
-                        void *endian, void *print, int size, int traced,
-                        void *print_json, void *tojson, void *fromjson,
-                        void *calc_size)
+vl_msg_api_set_handlers (int id, char *name, void *handler, void *endian,
+                        format_function_t *format, int size, int traced,
+                        void *tojson, void *fromjson, void *calc_size)
 {
   vl_msg_api_msg_config_t cfg;
   vl_msg_api_msg_config_t *c = &cfg;
@@ -806,9 +801,8 @@ vl_msg_api_set_handlers (int id, char *name, void *handler, void *cleanup,
   c->id = id;
   c->name = name;
   c->handler = handler;
-  c->cleanup = cleanup;
   c->endian = endian;
-  c->print = print;
+  c->format_fn = format;
   c->traced = traced;
   c->replay = 1;
   c->message_bounce = 0;
@@ -816,7 +810,6 @@ vl_msg_api_set_handlers (int id, char *name, void *handler, void *cleanup,
   c->is_autoendian = 0;
   c->tojson = tojson;
   c->fromjson = fromjson;
-  c->print_json = print_json;
   c->calc_size = calc_size;
   vl_msg_api_config (c);
 }
@@ -884,12 +877,6 @@ vl_msg_api_trace_get (api_main_t * am, vl_api_trace_which_t which)
     }
 }
 
-void
-vl_noop_handler (void *mp)
-{
-}
-
-
 static u8 post_mortem_dump_enabled;
 
 void
index 9e2971a..0717d81 100644 (file)
@@ -48,7 +48,6 @@
 #undef vl_typedefs
 
 /* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 #define vl_printfun
 #include <vlibmemory/vl_memory_api_h.h>
 #undef vl_printfun
@@ -175,10 +174,8 @@ vlib_api_init (void)
       c->id = VL_API_##N;                                                     \
       c->name = #n;                                                           \
       c->handler = vl_api_##n##_t_handler;                                    \
-      c->cleanup = vl_noop_handler;                                           \
       c->endian = vl_api_##n##_t_endian;                                      \
-      c->print = vl_api_##n##_t_print;                                        \
-      c->print_json = vl_api_##n##_t_print_json;                              \
+      c->format_fn = vl_api_##n##_t_format;                                   \
       c->tojson = vl_api_##n##_t_tojson;                                      \
       c->fromjson = vl_api_##n##_t_fromjson;                                  \
       c->calc_size = vl_api_##n##_t_calc_size;                                \
@@ -711,18 +708,16 @@ rpc_api_hookup (vlib_main_t *vm)
   api_main_t *am = vlibapi_get_main ();
 #define _(N, n)                                                               \
   vl_msg_api_set_handlers (                                                   \
-    VL_API_##N, #n, vl_api_##n##_t_handler, vl_noop_handler, vl_noop_handler, \
-    vl_api_##n##_t_print, sizeof (vl_api_##n##_t), 0 /* do not trace */,      \
-    vl_api_##n##_t_print_json, vl_api_##n##_t_tojson,                         \
+    VL_API_##N, #n, vl_api_##n##_t_handler, 0, vl_api_##n##_t_format,         \
+    sizeof (vl_api_##n##_t), 0 /* do not trace */, vl_api_##n##_t_tojson,     \
     vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);
   foreach_rpc_api_msg;
 #undef _
 
 #define _(N, n)                                                               \
   vl_msg_api_set_handlers (                                                   \
-    VL_API_##N, #n, vl_api_##n##_t_handler, vl_noop_handler, vl_noop_handler, \
-    vl_api_##n##_t_print, sizeof (vl_api_##n##_t), 1 /* do trace */,          \
-    vl_api_##n##_t_print_json, vl_api_##n##_t_tojson,                         \
+    VL_API_##N, #n, vl_api_##n##_t_handler, 0, vl_api_##n##_t_format,         \
+    sizeof (vl_api_##n##_t), 1 /* do trace */, vl_api_##n##_t_tojson,         \
     vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);
   foreach_plugin_trace_msg;
 #undef _
index 80d8628..01fe49b 100644 (file)
@@ -28,7 +28,6 @@
 #undef vl_typedefs
 
 /* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 #define vl_printfun
 #include <vlibmemory/vl_memory_api_h.h>
 #undef vl_printfun
@@ -504,18 +503,21 @@ vl_mem_api_init (const char *region_name)
   if ((rv = vl_map_shmem (region_name, 1 /* is_vlib */ )) < 0)
     return rv;
 
-#define _(N,n,t) do {                                            \
-    c->id = VL_API_##N;                                         \
-    c->name = #n;                                               \
-    c->handler = vl_api_##n##_t_handler;                        \
-    c->cleanup = vl_noop_handler;                               \
-    c->endian = vl_api_##n##_t_endian;                          \
-    c->print = vl_api_##n##_t_print;                            \
-    c->size = sizeof(vl_api_##n##_t);                           \
-    c->traced = t; /* trace, so these msgs print */             \
-    c->replay = 0; /* don't replay client create/delete msgs */ \
-    c->message_bounce = 0; /* don't bounce this message */     \
-    vl_msg_api_config(c);} while (0);
+#define _(N, n, t)                                                            \
+  do                                                                          \
+    {                                                                         \
+      c->id = VL_API_##N;                                                     \
+      c->name = #n;                                                           \
+      c->handler = vl_api_##n##_t_handler;                                    \
+      c->endian = vl_api_##n##_t_endian;                                      \
+      c->format_fn = vl_api_##n##_t_format;                                   \
+      c->size = sizeof (vl_api_##n##_t);                                      \
+      c->traced = t;        /* trace, so these msgs print */                 \
+      c->replay = 0;        /* don't replay client create/delete msgs */     \
+      c->message_bounce = 0; /* don't bounce this message */                  \
+      vl_msg_api_config (c);                                                  \
+    }                                                                         \
+  while (0);
 
   foreach_vlib_api_msg;
 #undef _
@@ -770,7 +772,6 @@ vl_mem_api_handler_with_vm_node (api_main_t *am, svm_region_t *vlib_rp,
   u16 id = clib_net_to_host_u16 (*((u16 *) the_msg));
   vl_api_msg_data_t *m = vl_api_get_msg_data (am, id);
   u8 *(*handler) (void *, void *, void *);
-  u8 *(*print_fp) (void *, void *);
   svm_region_t *old_vlib_rp;
   void *save_shmem_hdr;
   int is_mp_safe = 1;
@@ -802,15 +803,7 @@ vl_mem_api_handler_with_vm_node (api_main_t *am, svm_region_t *vlib_rp,
       if (PREDICT_FALSE (am->msg_print_flag))
        {
          fformat (stdout, "[%d]: %s\n", id, m->name);
-         print_fp = (void *) am->msg_data[id].print_handler;
-         if (print_fp == 0)
-           {
-             fformat (stdout, "  [no registered print fn for msg %d]\n", id);
-           }
-         else
-           {
-             (*print_fp) (the_msg, vm);
-           }
+         fformat (stdout, "%U", format_vl_api_msg_text, am, id, the_msg);
        }
       is_mp_safe = am->msg_data[id].is_mp_safe;
 
index 330390e..738c4e5 100644 (file)
@@ -44,7 +44,6 @@
 #undef vl_calcsizefun
 
 /* instantiate all the print functions we know about */
-#define vl_print(handle, ...) clib_warning (__VA_ARGS__)
 #define vl_printfun
 #include <vlibmemory/vl_memory_api_h.h>
 #undef vl_printfun
@@ -155,11 +154,6 @@ vl_api_memclnt_create_reply_t_handler (vl_api_memclnt_create_reply_t * mp)
     }
 }
 
-static void
-noop_handler (void *notused)
-{
-}
-
 void vl_msg_api_send_shmem (svm_queue_t * q, u8 * elem);
 int
 vl_client_connect (const char *name, int ctx_quota, int input_queue_size)
@@ -373,9 +367,8 @@ vl_client_install_client_message_handlers (void)
   api_main_t *am = vlibapi_get_main ();
 #define _(N, n)                                                               \
   vl_msg_api_set_handlers (                                                   \
-    VL_API_##N, #n, vl_api_##n##_t_handler, noop_handler,                     \
-    vl_api_##n##_t_endian, vl_api_##n##_t_print, sizeof (vl_api_##n##_t), 0,  \
-    vl_api_##n##_t_print_json, vl_api_##n##_t_tojson,                         \
+    VL_API_##N, #n, vl_api_##n##_t_handler, vl_api_##n##_t_endian,            \
+    vl_api_##n##_t_format, sizeof (vl_api_##n##_t), 0, vl_api_##n##_t_tojson, \
     vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);                       \
   am->msg_data[VL_API_##N].replay_allowed = 0;
   foreach_api_msg;
index e451d62..106fcb2 100644 (file)
@@ -35,7 +35,6 @@
 #undef vl_typedefs
 
 /* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 #define vl_printfun
 #include <vlibmemory/vl_memory_api_h.h>
 #undef vl_printfun
@@ -798,9 +797,8 @@ vl_sock_api_init (vlib_main_t * vm)
 
 #define _(N, n, t)                                                            \
   vl_msg_api_set_handlers (                                                   \
-    VL_API_##N, #n, vl_api_##n##_t_handler, vl_noop_handler,                  \
-    vl_api_##n##_t_endian, vl_api_##n##_t_print, sizeof (vl_api_##n##_t), t,  \
-    vl_api_##n##_t_print_json, vl_api_##n##_t_tojson,                         \
+    VL_API_##N, #n, vl_api_##n##_t_handler, vl_api_##n##_t_endian,            \
+    vl_api_##n##_t_format, sizeof (vl_api_##n##_t), t, vl_api_##n##_t_tojson, \
     vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);                       \
   am->msg_data[VL_API_##N].replay_allowed = 0;
   foreach_vlib_api_msg;
index 237d222..1eccb73 100644 (file)
@@ -41,7 +41,6 @@
 #undef vl_calcsizefun
 
 /* instantiate all the print functions we know about */
-#define vl_print(handle, ...) clib_warning (__VA_ARGS__)
 #define vl_printfun
 #include <vlibmemory/vl_memory_api_h.h>
 #undef vl_printfun
@@ -427,20 +426,14 @@ vl_api_sockclnt_create_reply_t_handler (vl_api_sockclnt_create_reply_t * mp)
 _(SOCKCLNT_CREATE_REPLY, sockclnt_create_reply)                        \
 _(SOCK_INIT_SHM_REPLY, sock_init_shm_reply)                    \
 
-static void
-noop_handler (void *notused)
-{
-}
-
 void
 vl_sock_client_install_message_handlers (void)
 {
 
 #define _(N, n)                                                               \
   vl_msg_api_set_handlers (                                                   \
-    VL_API_##N, #n, vl_api_##n##_t_handler, noop_handler,                     \
-    vl_api_##n##_t_endian, vl_api_##n##_t_print, sizeof (vl_api_##n##_t), 0,  \
-    vl_api_##n##_t_print_json, vl_api_##n##_t_tojson,                         \
+    VL_API_##N, #n, vl_api_##n##_t_handler, vl_api_##n##_t_endian,            \
+    vl_api_##n##_t_format, sizeof (vl_api_##n##_t), 0, vl_api_##n##_t_tojson, \
     vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);
   foreach_sock_client_api_msg;
 #undef _
index e53ea95..5b62e61 100644 (file)
@@ -584,40 +584,24 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
       switch (which)
        {
        case DUMP_JSON:
-         if (m && m->print_json_handler)
-           {
-             m->print_json_handler (tmpbuf + sizeof (uword), vm);
-           }
-         else
-           {
-             vlib_cli_output (vm, "Skipping msg id %d: no JSON print fcn\n",
-                              msg_id);
-             break;
-           }
+         vlib_cli_output (vm, "%U", format_vl_api_msg_json, am, msg_id,
+                          tmpbuf + sizeof (uword));
          break;
 
        case DUMP:
-         if (m && m->print_handler)
-           {
-             m->print_handler (tmpbuf + sizeof (uword), vm);
-           }
-         else
-           {
-             vlib_cli_output (vm, "Skipping msg id %d: no print fcn\n",
-                              msg_id);
-             break;
-           }
+         vlib_cli_output (vm, "%U", format_vl_api_msg_text, am, msg_id,
+                          tmpbuf + sizeof (uword));
          break;
 
        case INITIALIZERS:
-         if (m && m->print_handler)
+         if (m)
            {
              u8 *s;
              int j;
 
-             vlib_cli_output (vm, "/*");
+             vlib_cli_output (vm, "/*%U*/", format_vl_api_msg_text, am,
+                              msg_id, tmpbuf + sizeof (uword));
 
-             m->print_handler (tmpbuf + sizeof (uword), vm);
              vlib_cli_output (vm, "*/\n");
 
              s = format (0, "static u8 * vl_api_%s_%d[%d] = {", m->name, i,
@@ -636,7 +620,7 @@ vl_msg_api_process_file (vlib_main_t * vm, u8 * filename,
          break;
 
        case REPLAY:
-         if (m && m->print_handler && m->replay_allowed)
+         if (m && m->handler && m->replay_allowed)
            {
              if (!m->is_mp_safe)
                vl_msg_api_barrier_sync ();
@@ -690,7 +674,6 @@ vl_msg_print_trace (u8 *msg, void *ctx)
   api_main_t *am = vlibapi_get_main ();
   u16 msg_id = ntohs (*((u16 *) msg));
   vl_api_msg_data_t *m = vl_api_get_msg_data (am, msg_id);
-  void (*handler) (void *, void *) = 0;
   u8 is_json = a->is_json;
   u8 *tmpbuf = 0;
 
@@ -710,12 +693,9 @@ vl_msg_print_trace (u8 *msg, void *ctx)
       m->endian_handler (tmpbuf);
     }
 
-  handler = is_json ? m->print_json_handler : m->print_handler;
-
-  if (handler)
-    handler (msg, a->vm);
-  else
-    vlib_cli_output (a->vm, "Skipping msg id %d: no print fcn\n", msg_id);
+  vlib_cli_output (a->vm, "%U\n",
+                  is_json ? format_vl_api_msg_json : format_vl_api_msg_text,
+                  am, msg_id, msg);
 
   vec_free (tmpbuf);
   return 0;
@@ -868,11 +848,14 @@ vl_msg_exec_json_command (vlib_main_t *vm, cJSON *o)
          goto end;
        }
 
-      if (!m->is_mp_safe)
-       vl_msg_api_barrier_sync ();
-      m->handler (msg);
-      if (!m->is_mp_safe)
-       vl_msg_api_barrier_release ();
+      if (m->handler)
+       {
+         if (!m->is_mp_safe)
+           vl_msg_api_barrier_sync ();
+         m->handler (msg);
+         if (!m->is_mp_safe)
+           vl_msg_api_barrier_release ();
+       }
     }
 
   rv = 0;
index 13fd90d..1840233 100644 (file)
@@ -72,8 +72,6 @@ enum
   RD_CP_EVENT_INTERRUPT,
 };
 
-#define vl_api_ip6_nd_address_autoconfig_t_print vl_noop_handler
-
 static void
 router_solicitation_start_stop (u32 sw_if_index, u8 start)
 {
index 45107f0..8642db9 100644 (file)
@@ -29,7 +29,6 @@
 #include <vnet/srmpls/sr_mpls.api_enum.h>
 #include <vnet/srmpls/sr_mpls.api_types.h>
 
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 
 #define vl_api_version(n, v) static u32 api_version = v;
 #include <vnet/srmpls/sr_mpls.api.h>
@@ -194,12 +193,11 @@ sr_mpls_api_hookup (vlib_main_t * vm)
   vec_free (name);
 
 #define _(N, n)                                                               \
-  vl_msg_api_set_handlers (                                                   \
-    REPLY_MSG_ID_BASE + VL_API_##N, #n, vl_api_##n##_t_handler,               \
-    vl_noop_handler, vl_api_##n##_t_endian, vl_api_##n##_t_print,             \
-    sizeof (vl_api_##n##_t), 1, vl_api_##n##_t_print_json,                    \
-    vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson,                           \
-    vl_api_##n##_t_calc_size);
+  vl_msg_api_set_handlers (REPLY_MSG_ID_BASE + VL_API_##N, #n,                \
+                          vl_api_##n##_t_handler, vl_api_##n##_t_endian,     \
+                          vl_api_##n##_t_format, sizeof (vl_api_##n##_t), 1, \
+                          vl_api_##n##_t_tojson, vl_api_##n##_t_fromjson,    \
+                          vl_api_##n##_t_calc_size);
   foreach_vpe_api_msg;
 #undef _
 
@@ -209,9 +207,8 @@ sr_mpls_api_hookup (vlib_main_t * vm)
    */
   vl_msg_api_set_handlers (
     REPLY_MSG_ID_BASE + VL_API_SR_MPLS_POLICY_ADD, "sr_mpls_policy_add",
-    vl_api_sr_mpls_policy_add_t_handler, vl_noop_handler,
-    vl_api_sr_mpls_policy_add_t_endian, vl_api_sr_mpls_policy_add_t_print, 256,
-    1, vl_api_sr_mpls_policy_add_t_print_json,
+    vl_api_sr_mpls_policy_add_t_handler, vl_api_sr_mpls_policy_add_t_endian,
+    vl_api_sr_mpls_policy_add_t_format, 256, 1,
     vl_api_sr_mpls_policy_add_t_tojson, vl_api_sr_mpls_policy_add_t_fromjson,
     vl_api_sr_mpls_policy_add_t_calc_size);
 
@@ -221,9 +218,8 @@ sr_mpls_api_hookup (vlib_main_t * vm)
    */
   vl_msg_api_set_handlers (
     REPLY_MSG_ID_BASE + VL_API_SR_MPLS_POLICY_MOD, "sr_mpls_policy_mod",
-    vl_api_sr_mpls_policy_mod_t_handler, vl_noop_handler,
-    vl_api_sr_mpls_policy_mod_t_endian, vl_api_sr_mpls_policy_mod_t_print, 256,
-    1, vl_api_sr_mpls_policy_mod_t_print_json,
+    vl_api_sr_mpls_policy_mod_t_handler, vl_api_sr_mpls_policy_mod_t_endian,
+    vl_api_sr_mpls_policy_mod_t_format, 256, 1,
     vl_api_sr_mpls_policy_mod_t_tojson, vl_api_sr_mpls_policy_mod_t_fromjson,
     vl_api_sr_mpls_policy_mod_t_calc_size);