summaryrefslogtreecommitdiffstats
path: root/src/plugins/lb/lb_test.c
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/plugins/lb/lb_test.c
parent10bbfce0264249354f14243fbc166ee0beb41366 (diff)
lb: remove api boilerplate
Type: refactor Change-Id: I5555037386d6f6593ac3328385603a382be1fc2a Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/plugins/lb/lb_test.c')
-rw-r--r--src/plugins/lb/lb_test.c149
1 files changed, 40 insertions, 109 deletions
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>