From a0cb32cb9fba93ec4b91e7d227c07d1b2099091b Mon Sep 17 00:00:00 2001 From: Paul Vinciguerra Date: Sun, 14 Jul 2019 13:47:43 -0400 Subject: [PATCH] lb: update api.c to use scaffolding from latest skel Type: refactor Change-Id: I01329385684f4a4f477cb046079b554ae3024ded Signed-off-by: Paul Vinciguerra --- src/plugins/lb/api.c | 97 ++++++++++++++++++++++++++----------------- src/plugins/lb/lb.api | 8 ++-- src/plugins/lb/lb_all_api_h.h | 19 +++++++++ src/plugins/lb/lb_msg_enum.h | 31 ++++++++++++++ 4 files changed, 112 insertions(+), 43 deletions(-) create mode 100644 src/plugins/lb/lb_all_api_h.h create mode 100644 src/plugins/lb/lb_msg_enum.h diff --git a/src/plugins/lb/api.c b/src/plugins/lb/api.c index 953654cd956..ad92b9b97dd 100644 --- a/src/plugins/lb/api.c +++ b/src/plugins/lb/api.c @@ -13,6 +13,8 @@ * limitations under the License. */ +#include +#include #include #include @@ -20,50 +22,42 @@ #include #include #include +#include - -#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 IDs */ +#include /* define message structures */ #define vl_typedefs -#include +#include #undef vl_typedefs /* define generated endian-swappers */ #define vl_endianfun -#include +#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 +#include #undef vl_api_version -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - - #define REPLY_MSG_ID_BASE lbm->msg_id_base #include -static void -setup_message_id_table (lb_main_t * lbm, api_main_t * am) -{ -#define _(id,n,crc) \ - vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + lbm->msg_id_base); - foreach_vl_msg_name_crc_lb; -#undef _ -} +/* List of message types that this plugin understands */ +#define foreach_lb_plugin_api_msg \ +_(LB_CONF, lb_conf) \ +_(LB_ADD_DEL_VIP, lb_add_del_vip) \ +_(LB_ADD_DEL_AS, lb_add_del_as) \ +_(LB_FLUSH_VIP, lb_flush_vip) \ + /* Macro to finish up custom dump fns */ #define FINISH \ @@ -290,20 +284,11 @@ static void *vl_api_lb_flush_vip_t_print FINISH; } -/* List of message types that this plugin understands */ -#define foreach_lb_plugin_api_msg \ -_(LB_CONF, lb_conf) \ -_(LB_ADD_DEL_VIP, lb_add_del_vip) \ -_(LB_ADD_DEL_AS, lb_add_del_as) \ -_(LB_FLUSH_VIP, lb_flush_vip) - -static clib_error_t * lb_api_init (vlib_main_t * vm) +/* Set up the API message handling tables */ +static clib_error_t * +lb_plugin_api_hookup (vlib_main_t *vm) { - lb_main_t *lbm = &lb_main; - u8 *name = format (0, "lb_%08x%c", api_version, 0); - lbm->msg_id_base = vl_msg_api_get_msg_ids - ((char *) name, VL_MSG_FIRST_AVAILABLE); - +lb_main_t *lbm = &lb_main; #define _(N,n) \ vl_msg_api_set_handlers((VL_API_##N + lbm->msg_id_base), \ #n, \ @@ -315,10 +300,44 @@ static clib_error_t * lb_api_init (vlib_main_t * vm) foreach_lb_plugin_api_msg; #undef _ + return 0; +} + +#define vl_msg_name_crc_list +#include +#undef vl_msg_name_crc_list + +static void +setup_message_id_table (lb_main_t * lmp, api_main_t * am) +{ +#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + lmp->msg_id_base); + foreach_vl_msg_name_crc_lb ; +#undef _ +} + +static clib_error_t * lb_api_init (vlib_main_t * vm) +{ + lb_main_t * lbm = &lb_main; + clib_error_t * error = 0; + u8 * name; + + lbm->vlib_main = vm; + lbm->vnet_main = vnet_get_main(); + + name = format (0, "lb_%08x%c", api_version, 0); + + /* Ask for a correctly-sized block of API message decode slots */ + lbm->msg_id_base = vl_msg_api_get_msg_ids + ((char *) name, VL_MSG_FIRST_AVAILABLE); + + error = lb_plugin_api_hookup (vm); + /* Add our API messages to the global name_crc hash table */ setup_message_id_table (lbm, &api_main); - return 0; + vec_free (name); + + return error; } VLIB_INIT_FUNCTION (lb_api_init); diff --git a/src/plugins/lb/lb.api b/src/plugins/lb/lb.api index 190e32011b3..c24440936d3 100644 --- a/src/plugins/lb/lb.api +++ b/src/plugins/lb/lb.api @@ -11,7 +11,7 @@ import "vnet/ip/ip_types.api"; @param flow_timeout - Time in seconds after which, if no packet is received for a given flow, the flow is removed from the established flow table. */ -autoreply define lb_conf +autoreply manual_print define lb_conf { u32 client_index; u32 context; @@ -37,7 +37,7 @@ autoreply define lb_conf for this VIP (must be power of 2). @param is_del - The VIP should be removed. */ -autoreply define lb_add_del_vip { +autoreply manual_print define lb_add_del_vip { u32 client_index; u32 context; u8 ip_prefix[16]; @@ -64,7 +64,7 @@ autoreply define lb_add_del_vip { @param is_del - The AS should be removed. @param is_flush - The sessions related to this AS should be flushed. */ -autoreply define lb_add_del_as { +autoreply manual_print define lb_add_del_as { u32 client_index; u32 context; u8 vip_ip_prefix[16]; @@ -84,7 +84,7 @@ autoreply define lb_add_del_as { @param protocol - tcp or udp. @param port - destination port. */ -autoreply define lb_flush_vip { +autoreply manual_print define lb_flush_vip { u32 client_index; u32 context; u8 ip_prefix[16]; diff --git a/src/plugins/lb/lb_all_api_h.h b/src/plugins/lb/lb_all_api_h.h new file mode 100644 index 00000000000..6d830d710d2 --- /dev/null +++ b/src/plugins/lb/lb_all_api_h.h @@ -0,0 +1,19 @@ + +/* + * api_all_api_h.h - skeleton vpp engine plug-in api #include file + * + * Copyright (c) + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* Include the generated file, see BUILT_SOURCES in Makefile.am */ +#include diff --git a/src/plugins/lb/lb_msg_enum.h b/src/plugins/lb/lb_msg_enum.h new file mode 100644 index 00000000000..b087aa6c4ef --- /dev/null +++ b/src/plugins/lb/lb_msg_enum.h @@ -0,0 +1,31 @@ + +/* + * api_msg_enum.h - skeleton vpp engine plug-in message enumeration + * + * Copyright (c) + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef included_lb_msg_enum_h +#define included_lb_msg_enum_h + +#include + +#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 + +#endif /* included_lb_msg_enum_h */ -- 2.16.6