aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/gtpu
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-09-27 09:35:04 +0200
committerNeale Ranns <nranns@cisco.com>2019-09-27 09:05:47 +0000
commit49228efce444d372140215c6364734683410c2b2 (patch)
tree79000a564a3f68c73c88f692ad9d8a5ac38fc414 /src/plugins/gtpu
parent5c71a2e5a6cb7c70439f25aee1673baefb7c3fca (diff)
gtpu: remove api boilerplate
Type: refactor Change-Id: I08d200fbec805af3109e738eee32c3ecfd61c7cc Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/plugins/gtpu')
-rw-r--r--src/plugins/gtpu/CMakeLists.txt4
-rw-r--r--src/plugins/gtpu/gtpu.api15
-rw-r--r--src/plugins/gtpu/gtpu_all_api_h.h18
-rw-r--r--src/plugins/gtpu/gtpu_api.c71
-rw-r--r--src/plugins/gtpu/gtpu_msg_enum.h31
-rw-r--r--src/plugins/gtpu/gtpu_test.c104
6 files changed, 11 insertions, 232 deletions
diff --git a/src/plugins/gtpu/CMakeLists.txt b/src/plugins/gtpu/CMakeLists.txt
index 805b65f7895..436a3918f05 100644
--- a/src/plugins/gtpu/CMakeLists.txt
+++ b/src/plugins/gtpu/CMakeLists.txt
@@ -25,10 +25,6 @@ add_vpp_plugin(gtpu
API_FILES
gtpu.api
- INSTALL_HEADERS
- gtpu_all_api_h.h
- gtpu_msg_enum.h
-
API_TEST_SOURCES
gtpu_test.c
)
diff --git a/src/plugins/gtpu/gtpu.api b/src/plugins/gtpu/gtpu.api
index f8333ff2ebc..b5f4f029c53 100644
--- a/src/plugins/gtpu/gtpu.api
+++ b/src/plugins/gtpu/gtpu.api
@@ -39,6 +39,7 @@ define gtpu_add_del_tunnel
u32 encap_vrf_id;
u32 decap_next_index;
u32 teid;
+ option vat_help = "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr> { <intfc> | mcast_sw_if_index <nn> } } teid <teid> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]";
};
/** \brief reply for set or delete an GTPU tunnel
@@ -63,6 +64,7 @@ define gtpu_tunnel_dump
u32 client_index;
u32 context;
u32 sw_if_index;
+ option vat_help = "[<intfc> | sw_if_index <nn>]";
};
/** \brief dump details of an GTPU tunnel
@@ -96,23 +98,14 @@ define gtpu_tunnel_details
@param is_ipv6 - if non-zero, enable ipv6-gtpu-bypass, else ipv4-gtpu-bypass
@param enable - if non-zero enable, else disable
*/
-define sw_interface_set_gtpu_bypass
+autoreply define sw_interface_set_gtpu_bypass
{
u32 client_index;
u32 context;
u32 sw_if_index;
u8 is_ipv6;
u8 enable;
-};
-
-/** \brief Interface set gtpu-bypass response
- @param context - sender context, to match reply w/ request
- @param retval - return code for the request
-*/
-define sw_interface_set_gtpu_bypass_reply
-{
- u32 context;
- i32 retval;
+ option vat_help = "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]";
};
/*
diff --git a/src/plugins/gtpu/gtpu_all_api_h.h b/src/plugins/gtpu/gtpu_all_api_h.h
deleted file mode 100644
index dbfe03976b2..00000000000
--- a/src/plugins/gtpu/gtpu_all_api_h.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * gtpu_all_api_h.h - plug-in api #include file
- *
- * Copyright (c) 2017 Intel 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 the generated file, see BUILT_SOURCES in Makefile.am */
-#include <gtpu/gtpu.api.h>
diff --git a/src/plugins/gtpu/gtpu_api.c b/src/plugins/gtpu/gtpu_api.c
index f2f1c297850..2d141159adf 100644
--- a/src/plugins/gtpu/gtpu_api.c
+++ b/src/plugins/gtpu/gtpu_api.c
@@ -27,59 +27,13 @@
#include <gtpu/gtpu.h>
-
-#define vl_msg_id(n,h) n,
-typedef enum
-{
-#include <gtpu/gtpu.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 <gtpu/gtpu.api.h>
-#undef vl_typedefs
-
-/* define generated endian-swappers */
-#define vl_endianfun
-#include <gtpu/gtpu.api.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 <gtpu/gtpu.api.h>
-#undef vl_printfun
-
-/* Get the API version number */
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <gtpu/gtpu.api.h>
-#undef vl_api_version
-
-#define vl_msg_name_crc_list
-#include <gtpu/gtpu.api.h>
-#undef vl_msg_name_crc_list
+#include <gtpu/gtpu.api_enum.h>
+#include <gtpu/gtpu.api_types.h>
#define REPLY_MSG_ID_BASE gtm->msg_id_base
#include <vlibapi/api_helper_macros.h>
static void
-setup_message_id_table (gtpu_main_t * gtm, api_main_t * am)
-{
-#define _(id,n,crc) \
- vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + gtm->msg_id_base);
- foreach_vl_msg_name_crc_gtpu;
-#undef _
-}
-
-#define foreach_gtpu_plugin_api_msg \
-_(SW_INTERFACE_SET_GTPU_BYPASS, sw_interface_set_gtpu_bypass) \
-_(GTPU_ADD_DEL_TUNNEL, gtpu_add_del_tunnel) \
-_(GTPU_TUNNEL_DUMP, gtpu_tunnel_dump)
-
-static void
vl_api_sw_interface_set_gtpu_bypass_t_handler
(vl_api_sw_interface_set_gtpu_bypass_t * mp)
{
@@ -215,30 +169,13 @@ vl_api_gtpu_tunnel_dump_t_handler (vl_api_gtpu_tunnel_dump_t * mp)
}
}
-
+#include <gtpu/gtpu.api.c>
static clib_error_t *
gtpu_api_hookup (vlib_main_t * vm)
{
gtpu_main_t *gtm = &gtpu_main;
- u8 *name = format (0, "gtpu_%08x%c", api_version, 0);
- gtm->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 + gtm->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_gtpu_plugin_api_msg;
-#undef _
-
- /* Add our API messages to the global name_crc hash table */
- setup_message_id_table (gtm, &api_main);
-
+ gtm->msg_id_base = setup_message_id_table ();
return 0;
}
diff --git a/src/plugins/gtpu/gtpu_msg_enum.h b/src/plugins/gtpu/gtpu_msg_enum.h
deleted file mode 100644
index 358a220a53b..00000000000
--- a/src/plugins/gtpu/gtpu_msg_enum.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * gtpu_msg_enum.h - vpp engine plug-in message enumeration
- *
- * Copyright (c) 2017 Intel 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 included_gtpu_msg_enum_h
-#define included_gtpu_msg_enum_h
-
-#include <vppinfra/byte_order.h>
-
-#define vl_msg_id(n,h) n,
-typedef enum
-{
-#include <gtpu/gtpu_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_gtpu_msg_enum_h */
diff --git a/src/plugins/gtpu/gtpu_test.c b/src/plugins/gtpu/gtpu_test.c
index 5e9afa257d0..36f4a8e1e49 100644
--- a/src/plugins/gtpu/gtpu_test.c
+++ b/src/plugins/gtpu/gtpu_test.c
@@ -22,6 +22,8 @@
#define __plugin_msg_base gtpu_test_main.msg_id_base
#include <vlibapi/vat_helper_macros.h>
+#include <gtpu/gtpu.api_enum.h>
+#include <gtpu/gtpu.api_types.h>
uword unformat_ip46_address (unformat_input_t * input, va_list * args)
{
@@ -60,36 +62,6 @@ uword unformat_ip46_prefix (unformat_input_t * input, va_list * args)
}
/////////////////////////
-#define vl_msg_id(n,h) n,
-typedef enum {
-#include <gtpu/gtpu.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 <gtpu/gtpu.api.h>
-#undef vl_typedefs
-
-/* declare message handlers for each api */
-
-#define vl_endianfun /* define message structures */
-#include <gtpu/gtpu.api.h>
-#undef vl_endianfun
-
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...)
-#define vl_printfun
-#include <gtpu/gtpu.api.h>
-#undef vl_printfun
-
-/* Get the API version number. */
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <gtpu/gtpu.api.h>
-#undef vl_api_version
-
typedef struct {
/* API message ID base */
u16 msg_id_base;
@@ -115,36 +87,6 @@ static void vl_api_gtpu_add_del_tunnel_reply_t_handler
}
}
-
-#define foreach_standard_reply_retval_handler \
- _(sw_interface_set_gtpu_bypass_reply)
-
-#define _(n) \
- static void vl_api_##n##_t_handler \
- (vl_api_##n##_t * mp) \
- { \
- vat_main_t * vam = gtpu_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 \
- _(SW_INTERFACE_SET_GTPU_BYPASS_REPLY, sw_interface_set_gtpu_bypass_reply) \
- _(GTPU_ADD_DEL_TUNNEL_REPLY, gtpu_add_del_tunnel_reply) \
- _(GTPU_TUNNEL_DETAILS, gtpu_tunnel_details)
-
-
static uword
api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
{
@@ -436,44 +378,4 @@ api_gtpu_tunnel_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 \
-_(sw_interface_set_gtpu_bypass, \
- "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
-_(gtpu_add_del_tunnel, \
- "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
- "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
- "teid <teid> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
-_(gtpu_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
-
-static void
-gtpu_api_hookup (vat_main_t *vam)
-{
- gtpu_test_main_t * gtm = &gtpu_test_main;
- /* Hook up handlers for replies from the data plane plug-in */
-#define _(N,n) \
- vl_msg_api_set_handlers((VL_API_##N + gtm->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(gtpu);
+#include <gtpu/gtpu.api_test.c>