ct6: remove api boilerplate 71/22271/5
authorOle Troan <ot@cisco.com>
Wed, 25 Sep 2019 16:42:47 +0000 (18:42 +0200)
committerOle Troan <ot@cisco.com>
Mon, 30 Sep 2019 08:40:16 +0000 (10:40 +0200)
Type: refactor
Change-Id: Ibf00279d8065e7ef4fc06e8b9946dcc7bfd647de
Signed-off-by: Ole Troan <ot@cisco.com>
MAINTAINERS
src/plugins/ct6/CMakeLists.txt
src/plugins/ct6/ct6.api
src/plugins/ct6/ct6.c
src/plugins/ct6/ct6_all_api_h.h [deleted file]
src/plugins/ct6/ct6_msg_enum.h [deleted file]
src/plugins/ct6/ct6_test.c

index b31ee73..c77ff74 100644 (file)
@@ -538,6 +538,11 @@ I: l2e
 M:     Neale Ranns <nranns@cisco.com>
 F:     src/plugins/l2e/
 
+IPv6 Connection Tracker
+I:     ct6
+M:     Dave Barach <dave@barachs.net>
+F:     src/plugins/ct6
+
 THE REST
 I:     misc
 C:     Contact vpp-dev Mailing List <vpp-dev@fd.io>
index 069b33a..74f6c60 100644 (file)
@@ -26,10 +26,6 @@ add_vpp_plugin(ct6
   API_FILES
   ct6.api
 
-  INSTALL_HEADERS
-  ct6_all_api_h.h
-  ct6_msg_enum.h
-
   API_TEST_SOURCES
   ct6_test.c
 )
index 67af42f..10a2825 100644 (file)
@@ -1,7 +1,7 @@
 
 /* Define a simple enable-disable binary API to control the feature */
 
-define ct6_enable_disable {
+autoreply define ct6_enable_disable {
     /* Client identifier, set from api_main.my_client_index */
     u32 client_index;
 
@@ -16,12 +16,5 @@ define ct6_enable_disable {
 
     /* Interface handle */
     u32 sw_if_index;
-};
-
-define ct6_enable_disable_reply {
-    /* From the request */
-    u32 context;
-
-    /* Return value, zero means all OK */
-    i32 retval;
+    option vat_help = "<intfc> [disable]";
 };
index 3dfa09f..15fa44a 100644 (file)
 #include <vpp/app/version.h>
 
 /* define message IDs */
-#include <ct6/ct6_msg_enum.h>
-
-/* define message structures */
-#define vl_typedefs
-#include <ct6/ct6_all_api_h.h>
-#undef vl_typedefs
-
-/* define generated endian-swappers */
-#define vl_endianfun
-#include <ct6/ct6_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 <ct6/ct6_all_api_h.h>
-#undef vl_printfun
-
-/* Get the API version number */
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <ct6/ct6_all_api_h.h>
-#undef vl_api_version
+#include <ct6/ct6.api_enum.h>
+#include <ct6/ct6.api_types.h>
 
 #define REPLY_MSG_ID_BASE cmp->msg_id_base
 #include <vlibapi/api_helper_macros.h>
 
 ct6_main_t ct6_main;
 
-/* List of message types that this plugin understands */
-
-#define foreach_ct6_plugin_api_msg                           \
-_(CT6_ENABLE_DISABLE, ct6_enable_disable)
-
 /* Action function shared between message handler and debug CLI */
 
 static void
@@ -209,59 +184,18 @@ static void vl_api_ct6_enable_disable_t_handler
   REPLY_MACRO (VL_API_CT6_ENABLE_DISABLE_REPLY);
 }
 
-/* Set up the API message handling tables */
-static clib_error_t *
-ct6_plugin_api_hookup (vlib_main_t * vm)
-{
-  ct6_main_t *cmp = &ct6_main;
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers((VL_API_##N + cmp->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_ct6_plugin_api_msg;
-#undef _
-
-  return 0;
-}
-
-#define vl_msg_name_crc_list
-#include <ct6/ct6_all_api_h.h>
-#undef vl_msg_name_crc_list
-
-static void
-setup_message_id_table (ct6_main_t * cmp, api_main_t * am)
-{
-#define _(id,n,crc)   vl_msg_api_add_msg_name_crc (am, #n "_"  #crc, id + cmp->msg_id_base);
-  foreach_vl_msg_name_crc_ct6;
-#undef _
-}
-
+#include <ct6/ct6.api.c>
 static clib_error_t *
 ct6_init (vlib_main_t * vm)
 {
   ct6_main_t *cmp = &ct6_main;
   clib_error_t *error = 0;
-  u8 *name;
 
   cmp->vlib_main = vm;
   cmp->vnet_main = vnet_get_main ();
 
-  name = format (0, "ct6_%08x%c", api_version, 0);
-
   /* Ask for a correctly-sized block of API message decode slots */
-  cmp->msg_id_base = vl_msg_api_get_msg_ids
-    ((char *) name, VL_MSG_FIRST_AVAILABLE);
-
-  error = ct6_plugin_api_hookup (vm);
-
-  /* Add our API messages to the global name_crc hash table */
-  setup_message_id_table (cmp, &api_main);
-
-  vec_free (name);
+  cmp->msg_id_base = setup_message_id_table ();
 
   /*
    * Set default parameters...
diff --git a/src/plugins/ct6/ct6_all_api_h.h b/src/plugins/ct6/ct6_all_api_h.h
deleted file mode 100644 (file)
index 3642216..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-
-/*
- * ct6_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 */
-#include <ct6/ct6.api.h>
diff --git a/src/plugins/ct6/ct6_msg_enum.h b/src/plugins/ct6/ct6_msg_enum.h
deleted file mode 100644 (file)
index 05b1751..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-
-/*
- * ct6_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_ct6_msg_enum_h
-#define included_ct6_msg_enum_h
-
-#include <vppinfra/byte_order.h>
-
-#define vl_msg_id(n,h) n,
-typedef enum {
-#include <ct6/ct6_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_ct6_msg_enum_h */
index 2f985a6..78663ef 100644 (file)
 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
 
 /* Declare message IDs */
-#include <ct6/ct6_msg_enum.h>
-
-/* define message structures */
-#define vl_typedefs
-#include <ct6/ct6_all_api_h.h>
-#undef vl_typedefs
-
-/* declare message handlers for each api */
-
-#define vl_endianfun           /* define message structures */
-#include <ct6/ct6_all_api_h.h>
-#undef vl_endianfun
-
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...)
-#define vl_printfun
-#include <ct6/ct6_all_api_h.h>
-#undef vl_printfun
-
-/* Get the API version number. */
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <ct6/ct6_all_api_h.h>
-#undef vl_api_version
-
+#include <ct6/ct6.api_enum.h>
+#include <ct6/ct6.api_types.h>
 
 typedef struct
 {
@@ -59,33 +37,6 @@ ct6_test_main_t ct6_test_main;
 #define __plugin_msg_base ct6_test_main.msg_id_base
 #include <vlibapi/vat_helper_macros.h>
 
-#define foreach_standard_reply_retval_handler   \
-_(ct6_enable_disable_reply)
-
-#define _(n)                                            \
-    static void vl_api_##n##_t_handler                  \
-    (vl_api_##n##_t * mp)                               \
-    {                                                   \
-        vat_main_t * vam = ct6_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                                       \
-_(CT6_ENABLE_DISABLE_REPLY, ct6_enable_disable_reply)
-
-
 static int
 api_ct6_enable_disable (vat_main_t * vam)
 {
@@ -139,41 +90,7 @@ api_ct6_enable_disable (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 \
-_(ct6_enable_disable, "<intfc> [disable]")
-
-static void
-ct6_api_hookup (vat_main_t * vam)
-{
-  ct6_test_main_t *ctmp = &ct6_test_main;
-  /* Hook up handlers for replies from the data plane plug-in */
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers((VL_API_##N + ctmp->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 (ct6);
+#include <ct6/ct6.api_test.c>
 
 /*
  * fd.io coding-style-patch-verification: ON