avf: remote api boilerplate

Type: refactor
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: Iafa1c0d0c1195f88b1a55f0341459c3278c3b2e6
Signed-off-by: Ole Troan <ot@cisco.com>
This commit is contained in:
Ole Troan
2019-09-25 17:33:46 +02:00
committed by Ole Trøan
parent 7eef62b673
commit 74af6f081f
6 changed files with 9 additions and 211 deletions
-4
View File
@@ -30,8 +30,4 @@ add_vpp_plugin(avf
API_TEST_SOURCES
avf_test.c
INSTALL_HEADERS
avf_all_api_h.h
avf_msg_enum.h
)
+2
View File
@@ -38,6 +38,7 @@ define avf_create
u16 rxq_num;
u16 rxq_size;
u16 txq_size;
option vat_help = "<pci-address> [rx-queue-size <size>] [tx-queue-size <size>] [num-rx-queues <size>]";
};
/** \brief
@@ -65,6 +66,7 @@ autoreply define avf_delete
u32 context;
u32 sw_if_index;
option vat_help = "<sw_if_index>";
};
/*
-26
View File
@@ -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 <avf/avf.api.h>
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/
+4 -62
View File
@@ -26,35 +26,11 @@
#include <vlibmemory/api.h>
/* define message IDs */
#include <avf/avf_msg_enum.h>
/* define message structures */
#define vl_typedefs
#include <avf/avf_all_api_h.h>
#undef vl_typedefs
/* define generated endian-swappers */
#define vl_endianfun
#include <avf/avf_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 <avf/avf_all_api_h.h>
#undef vl_printfun
/* get the API version number */
#define vl_api_version(n,v) static u32 api_version=(v);
#include <avf/avf_all_api_h.h>
#undef vl_api_version
#include <avf/avf.api_enum.h>
#include <avf/avf.api_types.h>
#include <vlibapi/api_helper_macros.h>
#define foreach_avf_plugin_api_msg \
_(AVF_CREATE, avf_create) \
_(AVF_DELETE, avf_delete)
static void
vl_api_avf_create_t_handler (vl_api_avf_create_t * mp)
{
@@ -111,49 +87,15 @@ reply:
REPLY_MACRO (VL_API_AVF_DELETE_REPLY + am->msg_id_base);
}
#define vl_msg_name_crc_list
#include <avf/avf_all_api_h.h>
#undef vl_msg_name_crc_list
static void
setup_message_id_table (avf_main_t * avm, api_main_t * am)
{
#define _(id,n,crc) \
vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + avm->msg_id_base);
foreach_vl_msg_name_crc_avf;
#undef _
}
/* set tup the API message handling tables */
#include <avf/avf.api.c>
static clib_error_t *
avf_plugin_api_hookup (vlib_main_t * vm)
{
avf_main_t *avm = &avf_main;
api_main_t *am = &api_main;
u8 *name;
/* construct the API name */
name = format (0, "avf_%08x%c", api_version, 0);
/* ask for a correctly-sized block of API message decode slots */
avm->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 + avm->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_avf_plugin_api_msg;
#undef _
/* set up the (msg_name, crc, message-id) table */
setup_message_id_table (avm, am);
vec_free (name);
avm->msg_id_base = setup_message_id_table ();
return 0;
}
-39
View File
@@ -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 _AVF_MSG_ENUM_H_
#define _AVF_MSG_ENUM_H_
#include <vppinfra/byte_order.h>
#define vl_msg_id(n,h) n,
typedef enum
{
#include <avf/avf_all_api_h.h>
VL_MSG_FIRST_AVAILABLE,
} vl_msg_id_t;
#undef vl_msg_id
#endif /* AVF_MSG_ENUM_H */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/
+3 -80
View File
@@ -31,28 +31,8 @@
#include <vlibapi/vat_helper_macros.h>
/* declare message IDs */
#include <avf/avf_msg_enum.h>
/* define message structures */
#define vl_typedefs
#include <avf/avf_all_api_h.h>
#undef vl_typedefs
/* declare message handlers for each api */
#define vl_endianfun
#include <avf/avf_all_api_h.h>
#undef vl_endianfun
/* instantiate all the print functions we know about */
#define vl_print(handle, ...)
#define vl_printfun
#include <avf/avf_all_api_h.h>
#undef vl_printfun
/* get API version number */
#define vl_api_version(n,v) static u32 api_version=(v);
#include <avf/avf_all_api_h.h>
#undef vp_api_version
#include <avf/avf.api_enum.h>
#include <avf/avf.api_types.h>
typedef struct
{
@@ -63,29 +43,6 @@ typedef struct
avf_test_main_t avf_test_main;
#define foreach_standard_reply_retval_handler \
_(avf_delete_reply)
#define _(n) \
static void vl_api_##n##_t_handler \
(vl_api_##n##_t * mp) \
{ \
vat_main_t * vam = avf_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 \
_(AVF_CREATE_REPLY, avf_create_reply) \
_(AVF_DELETE_REPLY, avf_delete_reply)
/* avf create API */
static int
api_avf_create (vat_main_t * vam)
@@ -192,41 +149,7 @@ api_avf_delete (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 \
_(avf_create, "<pci-address> [rx-queue-size <size>] " \
"[tx-queue-size <size>] [num-rx-queues <size>]") \
_(avf_delete, "<sw_if_index>")
static void
avf_api_hookup (vat_main_t * vam)
{
avf_test_main_t *avm __attribute__ ((unused)) = &avf_test_main;
#define _(N,n) \
vl_msg_api_set_handlers((VL_API_##N + avm->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 _
}
VAT_PLUGIN_REGISTER (avf);
#include <avf/avf.api_test.c>
/*
* fd.io coding-style-patch-verification: ON