nat: use correct data types for memory sizes
[vpp.git] / src / plugins / l3xc / l3xc_api.c
index 45c01fa..847acaa 100644 (file)
 #include <vlibmemory/api.h>
 
 /* define message IDs */
-#include <l3xc/l3xc_msg_enum.h>
-
-/* define message structures */
-#define vl_typedefs
-#include <l3xc/l3xc_all_api_h.h>
-#undef vl_typedefs
-
-/* define generated endian-swappers */
-#define vl_endianfun
-#include <l3xc/l3xc_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 <l3xc/l3xc_all_api_h.h>
-#undef vl_printfun
-
-/* Get the API version number */
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <l3xc/l3xc_all_api_h.h>
-#undef vl_api_version
+#include <vnet/format_fns.h>
+#include <l3xc/l3xc.api_enum.h>
+#include <l3xc/l3xc.api_types.h>
 
 /**
  * Base message ID fot the plugin
@@ -58,14 +39,6 @@ static u32 l3xc_base_msg_id;
 
 #include <vlibapi/api_helper_macros.h>
 
-/* List of message types that this plugin understands */
-
-#define foreach_l3xc_plugin_api_msg                     \
-  _(L3XC_PLUGIN_GET_VERSION, l3xc_plugin_get_version)   \
-  _(L3XC_UPDATE, l3xc_update)                           \
-  _(L3XC_DEL, l3xc_del)                                 \
-  _(L3XC_DUMP, l3xc_dump)
-
 static void
 vl_api_l3xc_plugin_get_version_t_handler (vl_api_l3xc_plugin_get_version_t *
                                          mp)
@@ -108,7 +81,7 @@ vl_api_l3xc_update_t_handler (vl_api_l3xc_update_t * mp)
   for (pi = 0; pi < mp->l3xc.n_paths; pi++)
     {
       path = &paths[pi];
-      rv = fib_path_api_parse (&mp->l3xc.paths[pi], path);
+      rv = fib_api_path_decode (&mp->l3xc.paths[pi], path);
 
       if (0 != rv)
        {
@@ -155,9 +128,12 @@ typedef struct l3xc_dump_walk_ctx_t_
 static int
 l3xc_send_details (u32 l3xci, void *args)
 {
-  fib_route_path_encode_t *api_rpaths = NULL, *api_rpath;
+  fib_path_encode_ctx_t path_ctx = {
+    .rpaths = NULL,
+  };
   vl_api_l3xc_details_t *mp;
   l3xc_dump_walk_ctx_t *ctx;
+  fib_route_path_t *rpath;
   vl_api_fib_path_t *fp;
   size_t msg_size;
   l3xc_t *l3xc;
@@ -177,13 +153,12 @@ l3xc_send_details (u32 l3xci, void *args)
   mp->l3xc.n_paths = n_paths;
   mp->l3xc.sw_if_index = htonl (l3xc->l3xc_sw_if_index);
 
-  fib_path_list_walk_w_ext (l3xc->l3xc_pl, NULL, fib_path_encode,
-                           &api_rpaths);
+  fib_path_list_walk_w_ext (l3xc->l3xc_pl, NULL, fib_path_encode, &path_ctx);
 
   fp = mp->l3xc.paths;
-  vec_foreach (api_rpath, api_rpaths)
+  vec_foreach (rpath, path_ctx.rpaths)
   {
-    fib_api_path_encode (api_rpath, fp);
+    fib_api_path_encode (rpath, fp);
     fp++;
   }
 
@@ -226,56 +201,14 @@ vl_api_l3xc_dump_t_handler (vl_api_l3xc_dump_t * mp)
     }
 }
 
-#define vl_msg_name_crc_list
-#include <l3xc/l3xc_all_api_h.h>
-#undef vl_msg_name_crc_list
-
-/* Set up the API message handling tables */
-static clib_error_t *
-l3xc_plugin_api_hookup (vlib_main_t * vm)
-{
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers((VL_API_##N + l3xc_base_msg_id),     \
-                            #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_l3xc_plugin_api_msg;
-#undef _
-
-  return 0;
-}
-
-static void
-setup_message_id_table (api_main_t * apim)
-{
-#define _(id,n,crc) \
-  vl_msg_api_add_msg_name_crc (apim, #n "_" #crc, id + l3xc_base_msg_id);
-  foreach_vl_msg_name_crc_l3xc;
-#undef _
-}
-
+#include <l3xc/l3xc.api.c>
 static clib_error_t *
 l3xc_api_init (vlib_main_t * vm)
 {
-  clib_error_t *error = 0;
-
-  u8 *name = format (0, "l3xc_%08x%c", api_version, 0);
-
   /* Ask for a correctly-sized block of API message decode slots */
-  l3xc_base_msg_id = vl_msg_api_get_msg_ids ((char *) name,
-                                            VL_MSG_FIRST_AVAILABLE);
-
-  error = l3xc_plugin_api_hookup (vm);
+  l3xc_base_msg_id = setup_message_id_table ();
 
-  /* Add our API messages to the global name_crc hash table */
-  setup_message_id_table (&api_main);
-
-  vec_free (name);
-
-  return error;
+  return 0;
 }
 
 VLIB_INIT_FUNCTION (l3xc_api_init);