From 4d37bf9821d469f2c96ec3b2ddf8940320d9aa69 Mon Sep 17 00:00:00 2001 From: Filip Tehlar Date: Fri, 4 Jun 2021 11:55:48 +0000 Subject: nsh: api cleanup use autogenerated code Type: improvement Signed-off-by: Filip Tehlar Change-Id: I91a55412f96b138c3c00cbb8943d271c8a6452c9 --- src/plugins/nsh/nsh_api.c | 92 +++------------------------------------------- src/plugins/nsh/nsh_test.c | 90 ++------------------------------------------- 2 files changed, 8 insertions(+), 174 deletions(-) (limited to 'src') diff --git a/src/plugins/nsh/nsh_api.c b/src/plugins/nsh/nsh_api.c index 143285e3a3b..1faaea36c50 100644 --- a/src/plugins/nsh/nsh_api.c +++ b/src/plugins/nsh/nsh_api.c @@ -21,52 +21,10 @@ #include #include #include - -/* define message IDs */ -#define vl_msg_id(n,h) n, -typedef enum -{ -#include - /* We'll want to know how many messages IDs we need... */ - VL_MSG_FIRST_AVAILABLE, -} vl_msg_id_t; -#undef vl_msg_id - -/* define message structures */ -#define vl_typedefs -#include -#undef vl_typedefs - -/* define generated endian-swappers */ -#define vl_endianfun -#include -#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 -#undef vl_printfun - -/* Get the API version number */ -#define vl_api_version(n,v) static u32 api_version=(v); -#include -#undef vl_api_version - -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - -#define REPLY_MSG_ID_BASE nm->msg_id_base #include -/* List of message types that this plugin understands */ - -#define foreach_nsh_plugin_api_msg \ - _(NSH_ADD_DEL_ENTRY, nsh_add_del_entry) \ - _(NSH_ENTRY_DUMP, nsh_entry_dump) \ - _(NSH_ADD_DEL_MAP, nsh_add_del_map) \ - _(NSH_MAP_DUMP, nsh_map_dump) +#include +#include /** * @brief CLI function for NSH admin up/down @@ -210,7 +168,6 @@ static void vl_api_nsh_add_del_map_t_handler (vl_api_nsh_add_del_map_t * mp) { vl_api_nsh_add_del_map_reply_t *rmp; - nsh_main_t *nm = &nsh_main; int rv; nsh_add_del_map_args_t _a, *a = &_a; u32 map_index = ~0; @@ -592,7 +549,6 @@ static void vl_api_nsh_add_del_entry_t_handler (vl_api_nsh_add_del_entry_t * mp) { vl_api_nsh_add_del_entry_reply_t *rmp; - nsh_main_t *nm = &nsh_main; int rv; nsh_add_del_entry_args_t _a, *a = &_a; u32 entry_index = ~0; @@ -666,54 +622,16 @@ vl_api_nsh_entry_dump_t_handler (vl_api_nsh_entry_dump_t * mp) } } -static void -setup_message_id_table (nsh_main_t * nm, api_main_t * am) -{ -#define _(id,n,crc) \ - vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + nm->msg_id_base); - foreach_vl_msg_name_crc_nsh; -#undef _ -} +#include /* Set up the API message handling tables */ -static clib_error_t * -nsh_plugin_api_hookup (vlib_main_t * vm) -{ - nsh_main_t *nm __attribute__ ((unused)) = &nsh_main; -#define _(N,n) \ - vl_msg_api_set_handlers((VL_API_##N + nm->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); - foreach_nsh_plugin_api_msg; -#undef _ - - return 0; -} - clib_error_t * nsh_api_init (vlib_main_t * vm, nsh_main_t * nm) { - clib_error_t *error; - u8 *name; - - name = format (0, "nsh_%08x%c", api_version, 0); - - /* Set up the API */ - nm->msg_id_base = vl_msg_api_get_msg_ids - ((char *) name, VL_MSG_FIRST_AVAILABLE); - - error = nsh_plugin_api_hookup (vm); - /* Add our API messages to the global name_crc hash table */ - setup_message_id_table (nm, vlibapi_get_main ()); + nm->msg_id_base = setup_message_id_table (); - vec_free (name); - - return error; + return 0; } /* diff --git a/src/plugins/nsh/nsh_test.c b/src/plugins/nsh/nsh_test.c index 091ad97dfe9..129ff67f453 100644 --- a/src/plugins/nsh/nsh_test.c +++ b/src/plugins/nsh/nsh_test.c @@ -19,44 +19,15 @@ #include #include #include - +#include +#include uword unformat_sw_if_index (unformat_input_t * input, va_list * args); -/* define message IDs */ -#define vl_msg_id(n,h) n, -typedef enum { -#include - /* We'll want to know how many messages IDs we need... */ - VL_MSG_FIRST_AVAILABLE, -} vl_msg_id_t; -#undef vl_msg_id - /* define message structures */ #define vl_typedefs #include #undef vl_typedefs -/* define generated endian-swappers */ -#define vl_endianfun -#include -#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 -#undef vl_printfun - -/* Get the API version number */ -#define vl_api_version(n,v) static u32 api_version=(v); -#include -#undef vl_api_version - -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - - typedef struct { /* API message ID base */ u16 msg_id_base; @@ -355,59 +326,4 @@ static int api_nsh_map_dump (vat_main_t * vam) W; } -/* - * List of messages that the api test plugin sends, - * and that the data plane plugin processes - */ -#define foreach_vpe_api_msg \ -_(nsh_add_del_entry, "{nsp nsi } c1 c2 c3 c4 [md-type ] [tlv ] [del]") \ -_(nsh_entry_dump, "") \ -_(nsh_add_del_map, "nsp nsi [del] mapped-nsp mapped-nsi [encap-gre-intf | encap-vxlan-gpe-intf | encap-none]") \ -_(nsh_map_dump, "") - -static void -nsh_vat_api_hookup (vat_main_t *vam) -{ - nsh_test_main_t * sm = &nsh_test_main; - /* Hook up handlers for replies from the data plane plug-in */ -#define _(N,n) \ - vl_msg_api_set_handlers((VL_API_##N + sm->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); - foreach_vpe_api_reply_msg; -#undef _ - - /* API messages we can send */ -#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n); - foreach_vpe_api_msg; -#undef _ - - /* Help strings */ -#define _(n,h) hash_set_mem (vam->help_by_name, #n, h); - foreach_vpe_api_msg; -#undef _ -} - -clib_error_t * vat_plugin_register (vat_main_t *vam) -{ - nsh_test_main_t * sm = &nsh_test_main; - u8 * name; - - sm->vat_main = vam; - - /* Ask the vpp engine for the first assigned message-id */ - name = format (0, "nsh_%08x%c", api_version, 0); - sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name); - vec_free(name); - - if (sm->msg_id_base != (u16) ~0) - nsh_vat_api_hookup (vam); - else - return clib_error_return (0, "nsh plugin not loaded..."); - - return 0; -} +#include -- cgit 1.2.3-korg