aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-09-30 11:04:39 +0200
committerNeale Ranns <nranns@cisco.com>2019-09-30 15:32:24 +0000
commitae07240340b6fb44b1a8faa38e60da43bfd1307c (patch)
treef2eb56fdf5698ee40613db11a1c32acd6e1716f7 /src
parent10bbfce0264249354f14243fbc166ee0beb41366 (diff)
lb: remove api boilerplate
Type: refactor Change-Id: I5555037386d6f6593ac3328385603a382be1fc2a Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/lb/api.c83
-rw-r--r--src/plugins/lb/lb.api4
-rw-r--r--src/plugins/lb/lb_all_api_h.h24
-rw-r--r--src/plugins/lb/lb_msg_enum.h31
-rw-r--r--src/plugins/lb/lb_test.c149
5 files changed, 50 insertions, 241 deletions
diff --git a/src/plugins/lb/api.c b/src/plugins/lb/api.c
index e2ab2ac25df..cafa212a710 100644
--- a/src/plugins/lb/api.c
+++ b/src/plugins/lb/api.c
@@ -23,47 +23,18 @@
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vpp/app/version.h>
+#include <vnet/format_fns.h>
#include <vnet/ip/ip_types_api.h>
/* define message IDs */
-#include <lb/lb_msg_enum.h>
+#include <lb/lb.api_enum.h>
+#include <lb/lb.api_types.h>
-/* define message structures */
-#define vl_typedefs
-#include <lb/lb_all_api_h.h>
-#undef vl_typedefs
-
-/* define generated endian-swappers */
-#define vl_endianfun
-#include <lb/lb_all_api_h.h>
-#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 <lb/lb_all_api_h.h>
-#undef vl_printfun
-
-/* Get the API version number */
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <lb/lb_all_api_h.h>
-#undef vl_api_version
#define REPLY_MSG_ID_BASE lbm->msg_id_base
#include <vlibapi/api_helper_macros.h>
-/* 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_VIP_DUMP, lb_vip_dump) \
-_(LB_AS_DUMP, lb_as_dump) \
-_(LB_FLUSH_VIP, lb_flush_vip) \
-_(LB_ADD_DEL_INTF_NAT4, lb_add_del_intf_nat4) \
-_(LB_ADD_DEL_INTF_NAT6, lb_add_del_intf_nat6) \
-
-
/* Macro to finish up custom dump fns */
#define FINISH \
vec_add1 (s, 0); \
@@ -444,60 +415,18 @@ static void *vl_api_lb_flush_vip_t_print
FINISH;
}
-/* 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;
-#define _(N,n) \
- vl_msg_api_set_handlers((VL_API_##N + lbm->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_lb_plugin_api_msg;
-#undef _
-
- return 0;
-}
-
-#define vl_msg_name_crc_list
-#include <lb/lb_all_api_h.h>
-#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 _
-}
-
+#include <lb/lb.api.c>
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);
-
- vec_free (name);
+ lbm->msg_id_base = setup_message_id_table ();
- return error;
+ return 0;
}
VLIB_INIT_FUNCTION (lb_api_init);
diff --git a/src/plugins/lb/lb.api b/src/plugins/lb/lb.api
index b479b1b3034..e30bab6fbf2 100644
--- a/src/plugins/lb/lb.api
+++ b/src/plugins/lb/lb.api
@@ -20,6 +20,7 @@ autoreply manual_print define lb_conf
vl_api_ip6_address_t ip6_src_address;
u32 sticky_buckets_per_core;
u32 flow_timeout;
+ option vat_help = "[ip4-src-address <addr>] [ip6-src-address <addr>] [buckets <n>] [timeout <s>]";
};
/** \brief Add a virtual address (or prefix)
@@ -50,6 +51,7 @@ autoreply manual_print define lb_add_del_vip {
u16 node_port;
u32 new_flows_table_length [default=1024];
bool is_del;
+ option vat_help = "<prefix> [protocol (tcp|udp) port <n>] [encap (gre6|gre4|l3dsr|nat4|nat6)] [dscp <n>] [type (nodeport|clusterip) target_port <n>] [new_len <n>] [del]";
};
/** \brief Add an application server for a given VIP
@@ -71,6 +73,7 @@ autoreply manual_print define lb_add_del_as {
vl_api_address_t as_address;
bool is_del;
bool is_flush;
+ option vat_help = "<vip-prefix> [protocol (tcp|udp) port <n>] [<address>] [del] [flush]";
};
/** \brief Flush a given vip
@@ -130,6 +133,7 @@ define lb_as_dump{
vl_api_address_with_prefix_t pfx;
u8 protocol;
u16 port;
+ option vat_help = "<vip-prefix> [protocol (tcp|udp) port <n>]";
};
/** \brief lb_as_details
diff --git a/src/plugins/lb/lb_all_api_h.h b/src/plugins/lb/lb_all_api_h.h
deleted file mode 100644
index 6afc0f35908..00000000000
--- a/src/plugins/lb/lb_all_api_h.h
+++ /dev/null
@@ -1,24 +0,0 @@
-
-/*
- * api_all_api_h.h - skeleton vpp engine plug-in api #include file
- *
- * Copyright (c) <current-year> <your-organization>
- * 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 */
-
-#ifdef vl_printfun
-#include <vnet/format_fns.h>
-#endif
-
-#include <lb/lb.api.h>
diff --git a/src/plugins/lb/lb_msg_enum.h b/src/plugins/lb/lb_msg_enum.h
deleted file mode 100644
index b087aa6c4ef..00000000000
--- a/src/plugins/lb/lb_msg_enum.h
+++ /dev/null
@@ -1,31 +0,0 @@
-
-/*
- * api_msg_enum.h - skeleton vpp engine plug-in message enumeration
- *
- * Copyright (c) <current-year> <your-organization>
- * 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 <vppinfra/byte_order.h>
-
-#define vl_msg_id(n,h) n,
-typedef enum {
-#include <lb/lb_all_api_h.h>
- /* 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 */
diff --git a/src/plugins/lb/lb_test.c b/src/plugins/lb/lb_test.c
index 3da7eb04ffb..7176be8c8d8 100644
--- a/src/plugins/lb/lb_test.c
+++ b/src/plugins/lb/lb_test.c
@@ -23,6 +23,10 @@
#define __plugin_msg_base lb_test_main.msg_id_base
#include <vlibapi/vat_helper_macros.h>
+#include <vnet/format_fns.h>
+#include <lb/lb.api_enum.h>
+#include <lb/lb.api_types.h>
+
//TODO: Move that to vat/plugin_api.c
//////////////////////////
uword unformat_ip46_address (unformat_input_t * input, va_list * args)
@@ -62,37 +66,6 @@ uword unformat_ip46_prefix (unformat_input_t * input, va_list * args)
}
/////////////////////////
-#define vl_msg_id(n,h) n,
-typedef enum {
-#include <lb/lb.api.h>
- /* 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 <lb/lb.api.h>
-#undef vl_typedefs
-
-/* declare message handlers for each api */
-
-#define vl_endianfun /* define message structures */
-#include <lb/lb.api.h>
-#undef vl_endianfun
-
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...)
-#define vl_printfun
-#include <vnet/format_fns.h>
-#include <lb/lb.api.h>
-#undef vl_printfun
-
-/* Get the API version number. */
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <lb/lb.api.h>
-#undef vl_api_version
-
typedef struct {
/* API message ID base */
u16 msg_id_base;
@@ -101,38 +74,6 @@ typedef struct {
lb_test_main_t lb_test_main;
-#define foreach_standard_reply_retval_handler \
-_(lb_conf_reply) \
-_(lb_add_del_vip_reply) \
-_(lb_add_del_as_reply)
-
-#define _(n) \
- static void vl_api_##n##_t_handler \
- (vl_api_##n##_t * mp) \
- { \
- vat_main_t * vam = lb_test_main.vat_main; \
- i32 retval = ntohl(mp->retval); \
- if (vam->async_mode) { \
- vam->async_errors += (retval < 0); \
- } else { \
- vam->retval = retval; \
- vam->result_ready = 1; \
- } \
- }
-foreach_standard_reply_retval_handler;
-#undef _
-
-/*
- * Table of message reply handlers, must include boilerplate handlers
- * we just generated
- */
-#define foreach_vpe_api_reply_msg \
- _(LB_CONF_REPLY, lb_conf_reply) \
- _(LB_ADD_DEL_VIP_REPLY, lb_add_del_vip_reply) \
- _(LB_ADD_DEL_AS_REPLY, lb_add_del_as_reply) \
- _(LB_VIP_DETAILS, lb_vip_details) \
- _(LB_AS_DETAILS, lb_as_details)
-
static int api_lb_conf (vat_main_t * vam)
{
unformat_input_t *line_input = vam->input;
@@ -336,6 +277,41 @@ static int api_lb_add_del_as (vat_main_t * vam)
return ret;
}
+static int api_lb_flush_vip (vat_main_t * vam)
+{
+
+ unformat_input_t *line_input = vam->input;
+ vl_api_lb_flush_vip_t *mp;
+ int ret;
+ ip46_address_t vip_prefix;
+ u8 vip_plen;
+
+ if (!unformat(line_input, "%U", unformat_ip46_prefix,
+ &vip_prefix, &vip_plen, IP46_TYPE_ANY))
+ {
+ errmsg ("lb_add_del_as: invalid vip prefix\n");
+ return -99;
+ }
+
+ M(LB_FLUSH_VIP, mp);
+ clib_memcpy (mp->pfx.address.un.ip6, &vip_prefix.ip6, sizeof (vip_prefix.ip6));
+ mp->pfx.len = vip_plen;
+ S(mp);
+ W (ret);
+ return ret;
+}
+static int api_lb_add_del_intf_nat4 (vat_main_t * vam)
+{
+ // Not yet implemented
+ return -99;
+}
+
+static int api_lb_add_del_intf_nat6 (vat_main_t * vam)
+{
+ // Not yet implemented
+ return -99;
+}
+
static void vl_api_lb_vip_details_t_handler
(vl_api_lb_vip_details_t * mp)
{
@@ -467,49 +443,4 @@ static int api_lb_as_dump (vat_main_t * vam)
return ret;
}
-/*
- * List of messages that the api test plugin sends,
- * and that the data plane plugin processes
- */
-#define foreach_vpe_api_msg \
-_(lb_conf, "[ip4-src-address <addr>] [ip6-src-address <addr>] " \
- "[buckets <n>] [timeout <s>]") \
-_(lb_add_del_vip, "<prefix> " \
- "[protocol (tcp|udp) port <n>] " \
- "[encap (gre6|gre4|l3dsr|nat4|nat6)] " \
- "[dscp <n>] " \
- "[type (nodeport|clusterip) target_port <n>] " \
- "[new_len <n>] [del]") \
-_(lb_add_del_as, "<vip-prefix> [protocol (tcp|udp) port <n>] " \
- "[<address>] [del] [flush]") \
-_(lb_vip_dump, "") \
-_(lb_as_dump, "<vip-prefix> [protocol (tcp|udp) port <n>]")
-
-static void
-lb_api_hookup (vat_main_t *vam)
-{
- lb_test_main_t * lbtm = &lb_test_main;
- /* Hook up handlers for replies from the data plane plug-in */
-#define _(N,n) \
- vl_msg_api_set_handlers((VL_API_##N + lbtm->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 _
-}
-
-VAT_PLUGIN_REGISTER(lb);
+#include <lb/lb.api_test.c>