summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-09-30 11:19:28 +0200
committerNeale Ranns <nranns@cisco.com>2019-09-30 15:32:17 +0000
commit10bbfce0264249354f14243fbc166ee0beb41366 (patch)
treed90e22bc4f9af37e7964b80dc5f6afce9ad15aa5 /src
parent0d935531f9d25b18af85a14195665db324e834d8 (diff)
vmxnet3: remove api boilerplate
Type: refactor Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I009e806997461ad790f125d6359993862e1c5e5d
Diffstat (limited to 'src')
-rw-r--r--src/plugins/vmxnet3/CMakeLists.txt4
-rw-r--r--src/plugins/vmxnet3/vmxnet3.api2
-rw-r--r--src/plugins/vmxnet3/vmxnet3_all_api_h.h26
-rw-r--r--src/plugins/vmxnet3/vmxnet3_api.c130
-rw-r--r--src/plugins/vmxnet3/vmxnet3_msg_enum.h39
-rw-r--r--src/plugins/vmxnet3/vmxnet3_test.c118
6 files changed, 10 insertions, 309 deletions
diff --git a/src/plugins/vmxnet3/CMakeLists.txt b/src/plugins/vmxnet3/CMakeLists.txt
index a81d8d59387..9e45b949819 100644
--- a/src/plugins/vmxnet3/CMakeLists.txt
+++ b/src/plugins/vmxnet3/CMakeLists.txt
@@ -30,8 +30,4 @@ add_vpp_plugin(vmxnet3
API_TEST_SOURCES
vmxnet3_test.c
-
- INSTALL_HEADERS
- vmxnet3_all_api_h.h
- vmxnet3_msg_enum.h
)
diff --git a/src/plugins/vmxnet3/vmxnet3.api b/src/plugins/vmxnet3/vmxnet3.api
index 191c2ccbd02..6c4a1774756 100644
--- a/src/plugins/vmxnet3/vmxnet3.api
+++ b/src/plugins/vmxnet3/vmxnet3.api
@@ -46,6 +46,7 @@ define vmxnet3_create
u16 txq_num;
u8 bind;
u8 enable_gso;
+ option vat_help = "<pci-address> [rx-queue-size <size>] [tx-queue-size <size>] [num-tx-queues <num>] [num-rx-queues <num>] [bind] [gso]";
};
/** \brief
@@ -73,6 +74,7 @@ autoreply define vmxnet3_delete
u32 context;
u32 sw_if_index;
+ option vat_help = "sw_if_index <sw_if_index>";
};
/** \brief vmxnet3_tx_list structure
diff --git a/src/plugins/vmxnet3/vmxnet3_all_api_h.h b/src/plugins/vmxnet3/vmxnet3_all_api_h.h
deleted file mode 100644
index 7dee01bf417..00000000000
--- a/src/plugins/vmxnet3/vmxnet3_all_api_h.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- *------------------------------------------------------------------
- * Copyright (c) 2018 Cisco and/or its affiliates.
- * 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 <vmxnet3/vmxnet3.api.h>
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/plugins/vmxnet3/vmxnet3_api.c b/src/plugins/vmxnet3/vmxnet3_api.c
index c7f60ee723f..fa7554e3301 100644
--- a/src/plugins/vmxnet3/vmxnet3_api.c
+++ b/src/plugins/vmxnet3/vmxnet3_api.c
@@ -26,40 +26,11 @@
#include <vlibmemory/api.h>
/* define message IDs */
-#include <vmxnet3/vmxnet3_msg_enum.h>
-
-/* define message structures */
-#define vl_typedefs
-#include <vmxnet3/vmxnet3_all_api_h.h>
-#undef vl_typedefs
-
-/* define generated endian-swappers */
-#define vl_endianfun
-#include <vmxnet3/vmxnet3_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__)
-
-/* get the API version number */
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <vmxnet3/vmxnet3_all_api_h.h>
-#undef vl_api_version
-
-/* Macro to finish up custom dump fns */
-#define FINISH \
- vec_add1 (s, 0); \
- vl_print (handle, (char *)s); \
- vec_free (s); \
- return handle;
+#include <vmxnet3/vmxnet3.api_enum.h>
+#include <vmxnet3/vmxnet3.api_types.h>
#include <vlibapi/api_helper_macros.h>
-#define foreach_vmxnet3_plugin_api_msg \
-_(VMXNET3_CREATE, vmxnet3_create) \
-_(VMXNET3_DELETE, vmxnet3_delete) \
-_(VMXNET3_DUMP, vmxnet3_dump)
-
static void
vl_api_vmxnet3_create_t_handler (vl_api_vmxnet3_create_t * mp)
{
@@ -91,32 +62,6 @@ vl_api_vmxnet3_create_t_handler (vl_api_vmxnet3_create_t * mp)
/* *INDENT-ON* */
}
-static void *
-vl_api_vmxnet3_create_t_print (vl_api_vmxnet3_create_t * mp, void *handle)
-{
- u8 *s;
- u32 pci_addr = ntohl (mp->pci_addr);
-
- s = format (0, "SCRIPT: vmxnet3_create ");
- s = format (s, "%U ", format_vlib_pci_addr, &pci_addr);
- if (mp->enable_elog)
- s = format (s, "elog ");
- if (mp->bind)
- s = format (s, "bind ");
- if (mp->enable_gso)
- s = format (s, "gso ");
- if (mp->rxq_size)
- s = format (s, "rx-queue-size %u ", ntohs (mp->rxq_size));
- if (mp->txq_size)
- s = format (s, "tx-queue-size %u ", ntohs (mp->txq_size));
- if (mp->rxq_num)
- s = format (s, "num-rx-queues %u ", ntohs (mp->rxq_num));
- if (mp->txq_num)
- s = format (s, "num-tx-queues %u ", ntohs (mp->txq_num));
-
- FINISH;
-}
-
static void
vl_api_vmxnet3_delete_t_handler (vl_api_vmxnet3_delete_t * mp)
{
@@ -145,17 +90,6 @@ reply:
REPLY_MACRO (VL_API_VMXNET3_DELETE_REPLY + vmxm->msg_id_base);
}
-static void *
-vl_api_vmxnet3_delete_t_print (vl_api_vmxnet3_delete_t * mp, void *handle)
-{
- u8 *s;
-
- s = format (0, "SCRIPT: vmxnet3_delete ");
- s = format (s, "sw_if_index %d ", ntohl (mp->sw_if_index));
-
- FINISH;
-}
-
static void
send_vmxnet3_details (vl_api_registration_t * reg, vmxnet3_device_t * vd,
vnet_sw_interface_t * swif, u8 * interface_name,
@@ -253,71 +187,15 @@ vl_api_vmxnet3_dump_t_handler (vl_api_vmxnet3_dump_t * mp)
vec_free (if_name);
}
-static void *
-vl_api_vmxnet3_dump_t_print (vl_api_vmxnet3_dump_t * mp, void *handle)
-{
- u8 *s;
-
- s = format (0, "SCRIPT: vmxnet3_dump ");
-
- FINISH;
-}
-
-#define vl_msg_name_crc_list
-#include <vmxnet3/vmxnet3_all_api_h.h>
-#undef vl_msg_name_crc_list
-
-static void
-setup_message_id_table (vmxnet3_main_t * vmxm, api_main_t * am)
-{
-#define _(id,n,crc) \
- vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + vmxm->msg_id_base);
- foreach_vl_msg_name_crc_vmxnet3;
-#undef _
-}
-
-static void
-plugin_custom_dump_configure (vmxnet3_main_t * vmxm)
-{
-#define _(n,f) api_main.msg_print_handlers \
- [VL_API_##n + vmxm->msg_id_base] \
- = (void *) vl_api_##f##_t_print;
- foreach_vmxnet3_plugin_api_msg;
-#undef _
-}
-
/* set tup the API message handling tables */
+#include <vmxnet3/vmxnet3.api.c>
clib_error_t *
vmxnet3_plugin_api_hookup (vlib_main_t * vm)
{
vmxnet3_main_t *vmxm = &vmxnet3_main;
- api_main_t *am = &api_main;
- u8 *name;
-
- /* construct the API name */
- name = format (0, "vmxnet3_%08x%c", api_version, 0);
/* ask for a correctly-sized block of API message decode slots */
- vmxm->msg_id_base = vl_msg_api_get_msg_ids
- ((char *) name, VL_MSG_FIRST_AVAILABLE);
-
-#define _(N,n) \
- vl_msg_api_set_handlers((VL_API_##N + vmxm->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_vmxnet3_plugin_api_msg;
-#undef _
-
- /* set up the (msg_name, crc, message-id) table */
- setup_message_id_table (vmxm, am);
-
- plugin_custom_dump_configure (vmxm);
-
- vec_free (name);
+ vmxm->msg_id_base = setup_message_id_table ();
return 0;
}
diff --git a/src/plugins/vmxnet3/vmxnet3_msg_enum.h b/src/plugins/vmxnet3/vmxnet3_msg_enum.h
deleted file mode 100644
index 3086fb3bfc4..00000000000
--- a/src/plugins/vmxnet3/vmxnet3_msg_enum.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *------------------------------------------------------------------
- * Copyright (c) 2018 Cisco and/or its affiliates.
- * 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 _VMXNET3_MSG_ENUM_H_
-#define _VMXNET3_MSG_ENUM_H_
-
-#include <vppinfra/byte_order.h>
-
-#define vl_msg_id(n,h) n,
-typedef enum
-{
-#include <vmxnet3/vmxnet3_all_api_h.h>
- VL_MSG_FIRST_AVAILABLE,
-} vl_msg_id_t;
-#undef vl_msg_id
-
-#endif /* VMXNET3_MSG_ENUM_H */
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/plugins/vmxnet3/vmxnet3_test.c b/src/plugins/vmxnet3/vmxnet3_test.c
index 987026e3878..0d991a301a5 100644
--- a/src/plugins/vmxnet3/vmxnet3_test.c
+++ b/src/plugins/vmxnet3/vmxnet3_test.c
@@ -31,34 +31,9 @@
#include <vlibapi/vat_helper_macros.h>
/* declare message IDs */
-#include <vmxnet3/vmxnet3_msg_enum.h>
-
-/* Get CRC codes of the messages defined outside of this plugin */
-#define vl_msg_name_crc_list
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_msg_name_crc_list
-
-/* define message structures */
-#define vl_typedefs
-#include <vpp/api/vpe_all_api_h.h>
-#include <vmxnet3/vmxnet3_all_api_h.h>
-#undef vl_typedefs
-
-/* declare message handlers for each api */
-#define vl_endianfun
-#include <vmxnet3/vmxnet3_all_api_h.h>
-#undef vl_endianfun
-
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...)
-#define vl_printfun
-#include <vmxnet3/vmxnet3_all_api_h.h>
-#undef vl_printfun
-
-/* get API version number */
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <vmxnet3/vmxnet3_all_api_h.h>
-#undef vp_api_version
+#include <vmxnet3/vmxnet3.api_enum.h>
+#include <vmxnet3/vmxnet3.api_types.h>
+#include <vpp/api/vpe.api_types.h>
typedef struct
{
@@ -70,30 +45,6 @@ typedef struct
vmxnet3_test_main_t vmxnet3_test_main;
-#define foreach_standard_reply_retval_handler \
-_(vmxnet3_delete_reply)
-
-#define _(n) \
- static void vl_api_##n##_t_handler \
- (vl_api_##n##_t * mp) \
- { \
- vat_main_t * vam = vmxnet3_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 _
-
-#define foreach_vpe_api_reply_msg \
-_(VMXNET3_CREATE_REPLY, vmxnet3_create_reply) \
-_(VMXNET3_DELETE_REPLY, vmxnet3_delete_reply) \
-_(VMXNET3_DETAILS, vmxnet3_details)
-
/* vmxnet3 create API */
static int
api_vmxnet3_create (vat_main_t * vam)
@@ -287,68 +238,7 @@ vl_api_vmxnet3_details_t_handler (vl_api_vmxnet3_details_t * mp)
}
}
-/*
- * List of messages that the api test plugin sends,
- * and that the data plane plugin processes
- */
-#define foreach_vpe_api_msg \
-_(vmxnet3_create, "<pci-address> [rx-queue-size <size>] " \
- "[tx-queue-size <size>] [num-tx-queues <num>]" \
- "[num-rx-queues <num>] [bind] [gso]") \
-_(vmxnet3_delete, "sw_if_index <sw_if_index>") \
-_(vmxnet3_dump, "")
-
-static void
-vmxnet3_vat_api_hookup (vat_main_t * vam)
-{
- vmxnet3_test_main_t *vxm __attribute__ ((unused)) = &vmxnet3_test_main;
-#define _(N,n) \
- vl_msg_api_set_handlers((VL_API_##N + vxm->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 _
-
-#define _(n,h) \
- hash_set_mem (vam->function_by_name, #n, api_##n);
- foreach_vpe_api_msg;
-#undef _
-
-#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)
-{
- vmxnet3_test_main_t *vxm = &vmxnet3_test_main;
- u8 *name;
-
- vxm->vat_main = vam;
-
- name = format (0, "vmxnet3_%08x%c", api_version, 0);
- vxm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
- vec_free (name);
-
- if (vxm->msg_id_base == (u16) ~ 0)
- return clib_error_return (0, "vmxnet3 plugin not loaded...");
-
- /* Get the control ping ID */
-#define _(id,n,crc) \
- const char *id ## _CRC __attribute__ ((unused)) = #n "_" #crc;
- foreach_vl_msg_name_crc_vpe;
-#undef _
- vxm->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
-
- vmxnet3_vat_api_hookup (vam);
-
- return 0;
-}
+#include <vmxnet3/vmxnet3.api_test.c>
/*
* fd.io coding-style-patch-verification: ON