ioam: use explicit api types 80/23880/2
authorOle Troan <ot@cisco.com>
Mon, 9 Dec 2019 13:25:09 +0000 (14:25 +0100)
committerPaul Vinciguerra <pvinci@vinciconsulting.com>
Tue, 10 Dec 2019 04:11:04 +0000 (04:11 +0000)
Also remove API boilerplate.

Type: fix
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: I62e795f5af3843af7912707ade4ba178ff326942

18 files changed:
src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.api
src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c
src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_test.c
src/plugins/ioam/export/ioam_export.api
src/plugins/ioam/export/ioam_export.c
src/plugins/ioam/export/ioam_export_test.c
src/plugins/ioam/ioam_test.c
src/plugins/ioam/ip6/ioam_cache.api
src/plugins/ioam/lib-pot/pot.api
src/plugins/ioam/lib-pot/pot_api.c
src/plugins/ioam/lib-pot/pot_test.c
src/plugins/ioam/lib-trace/trace_test.c
src/plugins/ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api
src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_api.c
src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_test.c
src/plugins/ioam/udp-ping/udp_ping.api
src/plugins/ioam/udp-ping/udp_ping_api.c
src/plugins/ioam/udp-ping/udp_ping_test.c

index f6a63df..64a36b8 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 option version = "1.0.0";
+import "vnet/ip/ip_types.api";
 
 /* Define a simple binary API to control the feature */
 
@@ -26,11 +27,11 @@ autoreply define vxlan_gpe_ioam_export_enable_disable {
     u32 context;
 
     /* Enable / disable the feature */
-    u8 is_disable;
+    bool is_disable;
 
     /* Collector ip address */
-    u8 collector_address[4];
-    u8 src_address[4];
+    vl_api_ip4_address_t collector_address;
+    vl_api_ip4_address_t src_address;
 
     /* Src ip address */
 };
index cc3713c..f802a04 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <vlibapi/api.h>
 #include <vlibmemory/api.h>
-
+#include <vnet/format_fns.h>
 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
 
 /* define message IDs */
index a3a253f..1fc48f7 100644 (file)
 #include <vlibapi/api.h>
 #include <vlibmemory/api.h>
 #include <vppinfra/error.h>
+#include <vnet/format_fns.h>
 
-#define __plugin_msg_base export_test_main.msg_id_base
+#define __plugin_msg_base vxlan_gpe_ioam_export_test_main.msg_id_base
 #include <vlibapi/vat_helper_macros.h>
 
 /* Declare message IDs */
 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.api_enum.h>
 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.api_types.h>
 
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-
-#define vl_endianfun           /* define message structures */
-#define vl_printfun
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.api.h>
-#undef vl_endianfun
-#undef vl_printfun
-#undef vl_api_version
-
 typedef struct
 {
   /* API message ID base */
   u16 msg_id_base;
   vat_main_t *vat_main;
-} export_test_main_t;
-
-static export_test_main_t export_test_main;
-
-#define foreach_standard_reply_retval_handler   \
-_(vxlan_gpe_ioam_export_enable_disable_reply)
-
-#define _(n)                                            \
-    static void vl_api_##n##_t_handler                  \
-    (vl_api_##n##_t * mp)                               \
-    {                                                   \
-        vat_main_t * vam = export_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 _
+} vxlan_gpe_ioam_export_test_main_t;
 
-/*
- * Table of message reply handlers, must include boilerplate handlers
- * we just generated
- */
-#define foreach_vpe_api_reply_msg                                       \
-_(VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE_REPLY, vxlan_gpe_ioam_export_enable_disable_reply)
+vxlan_gpe_ioam_export_test_main_t vxlan_gpe_ioam_export_test_main;
 
 static int
 api_vxlan_gpe_ioam_export_enable_disable (vat_main_t * vam)
@@ -105,58 +69,9 @@ api_vxlan_gpe_ioam_export_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 \
-_(vxlan_gpe_ioam_export_enable_disable, "<intfc> [disable]")
-
-static void
-vxlan_gpe_ioam_vat_api_hookup (vat_main_t * vam)
-{
-  export_test_main_t *sm = &export_test_main;
-  /* Hook up handlers for replies from the data plane plug-in */
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers((VL_API_##N + sm->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 _
-}
-
-clib_error_t *
-vxlan_gpe_ioam_export_vat_plugin_register (vat_main_t * vam)
-{
-  export_test_main_t *sm = &export_test_main;
-  u8 *name;
-
-  sm->vat_main = vam;
-
-  name = format (0, "vxlan_gpe_ioam_export_%08x%c", api_version, 0);
-  sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (sm->msg_id_base != (u16) ~ 0)
-    vxlan_gpe_ioam_vat_api_hookup (vam);
-
-  vec_free (name);
-
-  return 0;
-}
+/* Override generated plugin register symbol */
+#define vat_plugin_register vxlan_gpe_ioam_export_vat_plugin_register
+#include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.api_test.c>
 
 /*
  * fd.io coding-style-patch-verification: ON
index c127bd2..2e77ded 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 option version = "1.0.0";
+import "vnet/ip/ip_types.api";
 
 /* Define a simple binary API to control the feature */
 
@@ -26,11 +27,11 @@ autoreply define ioam_export_ip6_enable_disable {
     u32 context;
 
     /* Enable / disable the feature */
-    u8 is_disable;
+    bool is_disable;
 
     /* Collector ip address */
-    u8 collector_address[4];
-    u8 src_address[4];
+    vl_api_ip4_address_t collector_address;
+    vl_api_ip4_address_t src_address;
 
     /* Src ip address */
 };
index f4c39a0..21695af 100644 (file)
@@ -25,7 +25,7 @@
 #include <vlibapi/api.h>
 #include <vlibmemory/api.h>
 #include <vnet/ip/ip6_hop_by_hop.h>
-
+#include <vnet/format_fns.h>
 
 /* define message IDs */
 #include <ioam/export/ioam_export.api_enum.h>
index b7d53c2..a98a5f5 100644 (file)
 #include <vlibapi/api.h>
 #include <vlibmemory/api.h>
 #include <vppinfra/error.h>
+#include <vnet/format_fns.h>
 
-#define __plugin_msg_base export_test_main.msg_id_base
+#define __plugin_msg_base ioam_export_test_main.msg_id_base
 #include <vlibapi/vat_helper_macros.h>
 
-
 /* Declare message IDs */
 #include <ioam/export/ioam_export.api_enum.h>
 #include <ioam/export/ioam_export.api_types.h>
 
-#define vl_endianfun            /* define message structures */
-#define vl_printfun
-#define vl_api_version(n,v) static u32 api_version=(v);
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#include <ioam/export/ioam_export.api.h>
-#undef vl_endianfun
-#undef vl_printfun
-#undef vl_api_version
-
 typedef struct
 {
   /* API message ID base */
   u16 msg_id_base;
   vat_main_t *vat_main;
-} export_test_main_t;
-
-static export_test_main_t export_test_main;
-
-#define foreach_standard_reply_retval_handler   \
-_(ioam_export_ip6_enable_disable_reply)
-
-#define _(n)                                            \
-    static void vl_api_##n##_t_handler                  \
-    (vl_api_##n##_t * mp)                               \
-    {                                                   \
-        vat_main_t * vam = export_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                                       \
-_(IOAM_EXPORT_IP6_ENABLE_DISABLE_REPLY, ioam_export_ip6_enable_disable_reply)
+} ioam_export_test_main_t;
 
+static ioam_export_test_main_t ioam_export_test_main;
 
 static int
 api_ioam_export_ip6_enable_disable (vat_main_t * vam)
@@ -105,55 +69,6 @@ api_ioam_export_ip6_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 \
-_(ioam_export_ip6_enable_disable, "<intfc> [disable]")
-
-static void
-ioam_export_vat_api_hookup (vat_main_t * vam)
-{
-  export_test_main_t *sm = &export_test_main;
-  /* Hook up handlers for replies from the data plane plug-in */
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers((VL_API_##N + sm->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 _
-}
-
-clib_error_t *
-ioam_export_vat_plugin_register (vat_main_t * vam)
-{
-  export_test_main_t *sm = &export_test_main;
-  u8 *name;
-
-  sm->vat_main = vam;
-
-  name = format (0, "ioam_export_%08x%c", api_version, 0);
-  sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (sm->msg_id_base != (u16) ~ 0)
-    ioam_export_vat_api_hookup (vam);
-
-  vec_free (name);
-
-  return 0;
-}
+/* Override generated plugin register symbol */
+#define vat_plugin_register ioam_export_vat_plugin_register
+#include <ioam/export/ioam_export.api_test.c>
index 323c8d7..228ac07 100644 (file)
 #include <vat/vat.h>
 #include <vlibapi/api.h>
 #include <vlibmemory/api.h>
+#include <vnet/format_fns.h>
+#include <vnet/ip/ip_types_api.h>
 
 clib_error_t * vxlan_gpe_ioam_export_vat_plugin_register (vat_main_t * vam);
 clib_error_t * pot_vat_plugin_register (vat_main_t *vam);
 clib_error_t * trace_vat_plugin_register (vat_main_t * vam);
 clib_error_t * vxlan_gpe_vat_plugin_register (vat_main_t * vam);
 clib_error_t * udp_ping_vat_plugin_register (vat_main_t * vam);
+clib_error_t * ioam_export_vat_plugin_register (vat_main_t * vam);
 
 clib_error_t *
 vat_plugin_register (vat_main_t *vam)
@@ -43,5 +46,22 @@ vat_plugin_register (vat_main_t *vam)
   if ((err = udp_ping_vat_plugin_register (vam)))
     return err;
 
+  if ((err = ioam_export_vat_plugin_register (vam)))
+    return err;
+
+  return 0;
+}
+uword unformat_ip46_address (unformat_input_t * input, va_list * args)
+{
+  ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
+  ip46_type_t type = va_arg (*args, ip46_type_t);
+  if ((type != IP46_TYPE_IP6) &&
+      unformat(input, "%U", unformat_ip4_address, &ip46->ip4)) {
+    ip46_address_mask_ip4(ip46);
+    return 1;
+  } else if ((type != IP46_TYPE_IP4) &&
+      unformat(input, "%U", unformat_ip6_address, &ip46->ip6)) {
+    return 1;
+  }
   return 0;
 }
index 71a048b..963c033 100644 (file)
@@ -26,6 +26,5 @@ autoreply define ioam_cache_ip6_enable_disable {
     u32 context;
 
     /* Enable / disable the feature */
-    u8 is_disable;
-
+    bool is_disable;
 };
index 45dc537..18a8f2b 100644 (file)
@@ -25,7 +25,6 @@ option version = "1.0.0";
     @param max_bits - Max bits to be used for Random number generation
     @param lpc - Lagrange basis polynomial
     @param polynomial_public - pre-evaluated public polynomial 
-    @param list_name_len - length of the name of this profile list
     @param list_name - name of this profile list
 */
 autoreply define pot_profile_add {
@@ -39,34 +38,29 @@ autoreply define pot_profile_add {
   u8  max_bits;
   u64 lpc;
   u64 polynomial_public;
-  u8 list_name_len;
-  u8 list_name[list_name_len];
+  string list_name[];
 };
 
 /** \brief Proof of Transit(POT): Activate POT profile in the list
     @param id - id of the profile 
-    @param list_name_len - length of the name of this profile list
     @param list_name - name of this profile list
 */
 autoreply define pot_profile_activate {
   u32 client_index;
   u32 context;
   u8 id;
-  u8 list_name_len;
-  u8 list_name[list_name_len];
+  string list_name[];
 };
 
 /** \brief Delete POT Profile 
     @param client_index - opaque cookie to identify the sender
     @param context - sender context, to match reply w/ request
-    @param list_name_len - length of the name of the profile list
     @param list_name - name of profile list to delete
 */
 autoreply define pot_profile_del {
   u32 client_index;
   u32 context;
-  u8 list_name_len;
-  u8 list_name[list_name_len];
+  string list_name[];
 };
 
 /** \brief Show POT Profiles
index 0d0e49d..2ecfc51 100644 (file)
@@ -43,8 +43,7 @@ static void vl_api_pot_profile_add_t_handler
     pot_profile *profile = NULL;
     u8 *name = 0;
 
-    if (mp->list_name_len)
-        name = format(0, "%s", mp->list_name);
+    name = vl_api_from_api_to_vec(&mp->list_name);
 
     pot_profile_list_init(name);
     id = mp->id;
@@ -122,8 +121,7 @@ static void vl_api_pot_profile_activate_t_handler
     u8 id;
     u8 *name = NULL;
 
-    if (mp->list_name_len)
-        name = format(0, "%s", mp->list_name);
+    name = vl_api_from_api_to_vec(&mp->list_name);
     if (!pot_profile_list_is_enabled(name)) {
         rv = -1;
     } else {
index 1db4286..90cff23 100644 (file)
 #include <ioam/lib-pot/pot.api_enum.h>
 #include <ioam/lib-pot/pot.api_types.h>
 
-#define vl_endianfun            /* define message structures */
-#define vl_printfun
-#define vl_api_version(n,v) static u32 api_version=(v);
-#define vl_print(handle, ...)
-#include <ioam/lib-pot/pot.api.h>
-#undef vl_endianfun
-#undef vl_printfun
-#undef vl_api_version
-
 typedef struct {
     /* API message ID base */
     u16 msg_id_base;
@@ -48,66 +39,6 @@ typedef struct {
 
 pot_test_main_t pot_test_main;
 
-#define foreach_standard_reply_retval_handler     \
-_(pot_profile_add_reply)                          \
-_(pot_profile_activate_reply)                     \
-_(pot_profile_del_reply)
-
-#define foreach_custom_reply_retval_handler                    \
-_(pot_profile_show_config_details,                             \
-    errmsg("           ID:%d\n",mp->id);                       \
-    errmsg("    Validator:%d\n",mp->validator);                \
-    errmsg("   secret_key:%Lx\n",clib_net_to_host_u64(mp->secret_key));                \
-    errmsg("  secret_share:%Lx\n",clib_net_to_host_u64(mp->secret_share));             \
-    errmsg("        prime:%Lx\n",clib_net_to_host_u64(mp->prime));                     \
-    errmsg("      bitmask:%Lx\n",clib_net_to_host_u64(mp->bit_mask));          \
-    errmsg("          lpc:%Lx\n",clib_net_to_host_u64(mp->lpc));                       \
-    errmsg("   public poly:%Lx\n",clib_net_to_host_u64(mp->polynomial_public));        \
-               )
-
-#define _(n)                                            \
-    static void vl_api_##n##_t_handler                  \
-    (vl_api_##n##_t * mp)                               \
-    {                                                   \
-        vat_main_t * vam = pot_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 _(n,body)                                       \
-    static void vl_api_##n##_t_handler                  \
-    (vl_api_##n##_t * mp)                               \
-    {                                                   \
-        vat_main_t * vam = pot_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;                      \
-        }                                               \
-       do{body;}while(0);                              \
-    }
-foreach_custom_reply_retval_handler;
-#undef _
-
-/*
- * Table of message reply handlers, must include boilerplate handlers
- * we just generated
- */
-#define foreach_vpe_api_reply_msg                                       \
-_(POT_PROFILE_ADD_REPLY, pot_profile_add_reply)                         \
-_(POT_PROFILE_ACTIVATE_REPLY, pot_profile_activate_reply)               \
-_(POT_PROFILE_DEL_REPLY, pot_profile_del_reply)                         \
-_(POT_PROFILE_SHOW_CONFIG_DETAILS, pot_profile_show_config_details)
-
 static int api_pot_profile_add (vat_main_t *vam)
 {
 #define MAX_BITS 64
@@ -155,10 +86,9 @@ static int api_pot_profile_add (vat_main_t *vam)
         goto OUT;
       }
 
-    M2(POT_PROFILE_ADD, mp, vec_len(name));
+    M2(POT_PROFILE_ADD, mp, sizeof(vl_api_string_t) + vec_len(name));
 
-    mp->list_name_len = vec_len(name);
-    clib_memcpy(mp->list_name, name, mp->list_name_len);
+    vl_api_to_api_string(vec_len(name), (const char *)name, &mp->list_name);
     mp->secret_share = clib_host_to_net_u64(secret_share);
     mp->polynomial_public = clib_host_to_net_u64(poly2);
     mp->lpc = clib_host_to_net_u64(lpc);
@@ -211,10 +141,8 @@ static int api_pot_profile_activate (vat_main_t *vam)
         goto OUT;
       }
 
-    M2(POT_PROFILE_ACTIVATE, mp, vec_len(name));
-
-    mp->list_name_len = vec_len(name);
-    clib_memcpy(mp->list_name, name, mp->list_name_len);
+    M2(POT_PROFILE_ACTIVATE, mp, sizeof(vl_api_string_t) + vec_len(name));
+    vl_api_to_api_string(vec_len(name), (const char *)name, &mp->list_name);
     mp->id = id;
 
     S(mp);
@@ -233,7 +161,6 @@ static int api_pot_profile_del (vat_main_t *vam)
     int ret;
 
     M(POT_PROFILE_DEL, mp);
-    mp->list_name_len = 0;
     S(mp);
     W (ret);
     return ret;
@@ -260,64 +187,11 @@ static int api_pot_profile_show_config_dump (vat_main_t *vam)
     W (ret);
     return ret;
 }
-
-/*
- * List of messages that the api test plugin sends,
- * and that the data plane plugin processes
- */
-#define foreach_vpe_api_msg \
-_(pot_profile_add, "name <name> id [0-1] "                              \
-  "prime-number <0xu64> bits-in-random [0-64] "                         \
-  "secret-share <0xu64> lpc <0xu64> polynomial-public <0xu64> "         \
-  "[validator-key <0xu64>] [validity <0xu64>]")                         \
-_(pot_profile_activate, "name <name> id [0-1] ")                       \
-_(pot_profile_del, "[id <nn>]")                                         \
-_(pot_profile_show_config_dump, "id [0-1]")
-
-static void
-pot_vat_api_hookup (vat_main_t *vam)
+static int vl_api_pot_profile_show_config_details_t_handler (vat_main_t *vam)
 {
-    pot_test_main_t * sm = &pot_test_main;
-    /* Hook up handlers for replies from the data plane plug-in */
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers((VL_API_##N + sm->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 _
+  return -1;
 }
 
-
-clib_error_t *
-pot_vat_plugin_register (vat_main_t *vam)
-{
-  pot_test_main_t * sm = &pot_test_main;
-  u8 * name;
-
-  sm->vat_main = vam;
-
-  name = format (0, "ioam_pot_%08x%c", api_version, 0);
-  sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-  vec_free(name);
-
-  if (sm->msg_id_base != (u16) ~0)
-    pot_vat_api_hookup (vam);
-  else
-    return clib_error_return (0, "ioam_pot plugin not loaded...");
-
-  return 0;
-}
+/* Override generated plugin register symbol */
+#define vat_plugin_register pot_vat_plugin_register
+#include <ioam/lib-pot/pot.api_test.c>
index 8981478..d1f9db4 100644 (file)
 #include <ioam/lib-trace/trace.api_enum.h>
 #include <ioam/lib-trace/trace.api_types.h>
 
-#define vl_endianfun           /* define message structures */
-#define vl_printfun
-#define vl_api_version(n,v) static u32 api_version=(v);
-#define vl_print(handle, ...)
-#include <ioam/lib-trace/trace.api.h>
-#undef vl_endianfun
-#undef vl_printfun
-#undef vl_api_version
-
 typedef struct
 {
   /* API message ID base */
@@ -49,62 +40,6 @@ typedef struct
 
 trace_test_main_t trace_test_main;
 
-#define foreach_standard_reply_retval_handler     \
-_(trace_profile_add_reply)                          \
-_(trace_profile_del_reply)
-
-#define foreach_custom_reply_handler     \
-_(trace_profile_show_config_reply,                                                                             \
-  if(mp->trace_type)                                                                                           \
-  {                                                                                                            \
-     errmsg("                        Trace Type : 0x%x (%d)\n",mp->trace_type, mp->trace_type);                        \
-     errmsg("         Trace timestamp precision : %d \n",mp->trace_tsp);                                       \
-     errmsg("                           Node Id : 0x%x (%d)\n",htonl(mp->node_id), htonl(mp->node_id));                \
-     errmsg("                          App Data : 0x%x (%d)\n",htonl(mp->app_data), htonl(mp->app_data));      \
-  }                                                                                                            \
-    else errmsg("No valid trace profile configuration found\n");)
-#define _(n)                                            \
-    static void vl_api_##n##_t_handler                  \
-    (vl_api_##n##_t * mp)                               \
-    {                                                   \
-        vat_main_t * vam = trace_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 _(n,body)                                       \
-    static void vl_api_##n##_t_handler                  \
-    (vl_api_##n##_t * mp)                               \
-    {                                                   \
-        vat_main_t * vam = trace_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;                      \
-        }                                               \
-       if(retval>=0)do{body;} while(0);                 \
-       else errmsg("Error, retval: %d",retval);        \
-    }
-foreach_custom_reply_handler;
-#undef _
-/*
- * Table of message reply handlers, must include boilerplate handlers
- * we just generated
- */
-#define foreach_vpe_api_reply_msg                                       \
-_(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply)                         \
-_(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply)                         \
-_(TRACE_PROFILE_SHOW_CONFIG_REPLY, trace_profile_show_config_reply)
-
 static int
 api_trace_profile_add (vat_main_t * vam)
 {
@@ -174,62 +109,15 @@ api_trace_profile_show_config (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 \
-_(trace_profile_add, ""\
-  "trace-type <0x1f|0x3|0x9|0x11|0x19> trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> app-data <app_data in hex>")  \
-_(trace_profile_del, "[id <nn>]")                    \
-_(trace_profile_show_config, "[id <nn>]")
-
-
-static void
-ioam_trace_vat_api_hookup (vat_main_t * vam)
+static int
+vl_api_trace_profile_show_config_reply_t_handler (vat_main_t * vam)
 {
-  trace_test_main_t *sm = &trace_test_main;
-  /* Hook up handlers for replies from the data plane plug-in */
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers((VL_API_##N + sm->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 _
+  return -1;
 }
 
-clib_error_t *
-trace_vat_plugin_register (vat_main_t * vam)
-{
-  trace_test_main_t *sm = &trace_test_main;
-  u8 *name;
-
-  sm->vat_main = vam;
-
-  name = format (0, "ioam_trace_%08x%c", api_version, 0);
-  sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (sm->msg_id_base != (u16) ~ 0)
-    ioam_trace_vat_api_hookup (vam);
-
-  vec_free (name);
-
-  return 0;
-}
+/* Override generated plugin register symbol */
+#define vat_plugin_register trace_vat_plugin_register
+#include <ioam/lib-trace/trace.api_test.c>
 
 /*
  * fd.io coding-style-patch-verification: ON
index 0cbdf6d..36dc1a4 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 option version = "1.0.0";
+import "vnet/ip/ip_types.api";
 
 /** \brief iOAM Over VxLAN-GPE - Set iOAM transport for VxLAN-GPE
     @param client_index - opaque cookie to identify the sender
@@ -30,8 +31,8 @@ autoreply define vxlan_gpe_ioam_enable {
   u32 context;
   u16 id;
   u8 trace_ppc;
-  u8 pow_enable;
-  u8 trace_enable;
+  bool pow_enable;
+  bool trace_enable;
 };
 
 /** \brief iOAM for VxLAN-GPE disable
@@ -58,9 +59,8 @@ autoreply define vxlan_gpe_ioam_vni_enable {
   u32 client_index;
   u32 context;
   u32 vni;
-  u8  local[16];
-  u8  remote[16];
-  u8  is_ipv6;
+  vl_api_address_t local;
+  vl_api_address_t remote;
 };
 
 /** \brief Disable iOAM for a VNI (VXLAN-GPE)
@@ -75,9 +75,8 @@ autoreply define vxlan_gpe_ioam_vni_disable {
   u32 client_index;
   u32 context;
   u32 vni;
-  u8  local[16];
-  u8  remote[16];
-  u8  is_ipv6;
+  vl_api_address_t local;
+  vl_api_address_t remote;
 };
 
 /** \brief Enable iOAM for a VXLAN-GPE transit
@@ -91,8 +90,7 @@ autoreply define vxlan_gpe_ioam_transit_enable {
   u32 client_index;
   u32 context;
   u32 outer_fib_index;
-  u8  dst_addr[16];
-  u8  is_ipv6;
+  vl_api_address_t dst_addr;
 };
 
 /** \brief Disable iOAM for VXLAN-GPE transit
@@ -106,7 +104,6 @@ autoreply define vxlan_gpe_ioam_transit_disable {
   u32 client_index;
   u32 context;
   u32 outer_fib_index;
-  u8  dst_addr[16];
-  u8  is_ipv6;
+  vl_api_address_t dst_addr;
 };
 
index 7748434..6255ce5 100644 (file)
@@ -25,7 +25,8 @@
 #include <vlibapi/api_helper_macros.h>
 #include <vlibapi/api.h>
 #include <vlibmemory/api.h>
-
+#include <vnet/format_fns.h>
+#include <vnet/ip/ip_types_api.h>
 
 /* define message IDs */
 #include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api_enum.h>
@@ -84,10 +85,11 @@ static void vl_api_vxlan_gpe_ioam_vni_enable_t_handler
   u32 vni;
 
 
-  if (!mp->is_ipv6)
+  if (clib_net_to_host_u32 (mp->local.af) == ADDRESS_IP4 &&
+      clib_net_to_host_u32 (mp->remote.af) == ADDRESS_IP4)
     {
-      clib_memcpy (&key4.local, &mp->local, sizeof (key4.local));
-      clib_memcpy (&key4.remote, &mp->remote, sizeof (key4.remote));
+      clib_memcpy (&key4.local, &mp->local.un.ip4, sizeof (key4.local));
+      clib_memcpy (&key4.remote, &mp->remote.un.ip4, sizeof (key4.remote));
       vni = clib_net_to_host_u32 (mp->vni);
       key4.vni = clib_host_to_net_u32 (vni << 8);
       key4.pad = 0;
@@ -106,7 +108,7 @@ static void vl_api_vxlan_gpe_ioam_vni_enable_t_handler
 
   error = vxlan_gpe_ioam_set (t, hm->has_trace_option,
                              hm->has_pot_option,
-                             hm->has_ppc_option, mp->is_ipv6);
+                             hm->has_ppc_option, 0 /* is_ipv6 */ );
 
 
   if (error)
@@ -132,7 +134,8 @@ static void vl_api_vxlan_gpe_ioam_vni_disable_t_handler
   u32 vni;
 
 
-  if (!mp->is_ipv6)
+  if (clib_net_to_host_u32 (mp->local.af) == ADDRESS_IP4 &&
+      clib_net_to_host_u32 (mp->remote.af) == ADDRESS_IP4)
     {
       clib_memcpy (&key4.local, &mp->local, sizeof (key4.local));
       clib_memcpy (&key4.remote, &mp->remote, sizeof (key4.remote));
@@ -173,16 +176,12 @@ static void vl_api_vxlan_gpe_ioam_transit_enable_t_handler
   vxlan_gpe_ioam_main_t *sm = &vxlan_gpe_ioam_main;
   ip46_address_t dst_addr;
 
-  clib_memset (&dst_addr.ip4, 0, sizeof (dst_addr.ip4));
-  if (!mp->is_ipv6)
-    {
-      clib_memcpy (&dst_addr.ip4, &mp->dst_addr, sizeof (dst_addr.ip4));
-    }
+  ip_address_decode (&mp->dst_addr, &dst_addr);
+  bool is_ip6 = clib_net_to_host_u32 (mp->dst_addr.af) == ADDRESS_IP6;
   rv = vxlan_gpe_enable_disable_ioam_for_dest (sm->vlib_main,
                                               dst_addr,
                                               ntohl (mp->outer_fib_index),
-                                              mp->is_ipv6 ? 0 : 1,
-                                              1 /* is_add */ );
+                                              is_ip6, 1 /* is_add */ );
 
   REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_TRANSIT_ENABLE_REPLY);
 }
@@ -195,16 +194,11 @@ static void vl_api_vxlan_gpe_ioam_transit_disable_t_handler
   vxlan_gpe_ioam_main_t *sm = &vxlan_gpe_ioam_main;
   ip46_address_t dst_addr;
 
-  clib_memset (&dst_addr.ip4, 0, sizeof (dst_addr.ip4));
-  if (!mp->is_ipv6)
-    {
-      clib_memcpy (&dst_addr.ip4, &mp->dst_addr, sizeof (dst_addr.ip4));
-    }
-
+  ip_address_decode (&mp->dst_addr, &dst_addr);
+  bool is_ip6 = clib_net_to_host_u32 (mp->dst_addr.af) == ADDRESS_IP6;
   rv = vxlan_gpe_ioam_disable_for_dest (sm->vlib_main,
                                        dst_addr,
-                                       ntohl (mp->outer_fib_index),
-                                       mp->is_ipv6 ? 0 : 1);
+                                       ntohl (mp->outer_fib_index), is_ip6);
   REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_TRANSIT_DISABLE_REPLY);
 }
 
index c7eea8b..dad39f2 100644 (file)
 #include <vlibmemory/api.h>
 
 #include <vppinfra/error.h>
+#include <vnet/format_fns.h>
+#include <vnet/ip/ip_types_api.h>
 
-#define __plugin_msg_base vxlan_gpe_test_main.msg_id_base
+#define __plugin_msg_base ioam_vxlan_gpe_test_main.msg_id_base
 #include <vlibapi/vat_helper_macros.h>
 
 /* Declare message IDs */
 #include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api_enum.h>
 #include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api_types.h>
 
-#define vl_endianfun           /* define message structures */
-#define vl_printfun
-#define vl_api_version(n,v) static u32 api_version=(v);
-#define vl_print(handle, ...)
-#include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api.h>
-#undef vl_endianfun
-#undef vl_printfun
-#undef vl_api_version
-
 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam_packet.h>
 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
 
@@ -48,45 +41,9 @@ typedef struct
   /* API message ID base */
   u16 msg_id_base;
   vat_main_t *vat_main;
-} vxlan_gpe_test_main_t;
-
-vxlan_gpe_test_main_t vxlan_gpe_test_main;
-
-#define foreach_standard_reply_retval_handler     \
-_(vxlan_gpe_ioam_enable_reply)                    \
-_(vxlan_gpe_ioam_disable_reply)                   \
-_(vxlan_gpe_ioam_vni_enable_reply)                \
-_(vxlan_gpe_ioam_vni_disable_reply)               \
-_(vxlan_gpe_ioam_transit_enable_reply)            \
-_(vxlan_gpe_ioam_transit_disable_reply)
-
-#define _(n)                                            \
-    static void vl_api_##n##_t_handler                  \
-    (vl_api_##n##_t * mp)                               \
-    {                                                   \
-        vat_main_t * vam = vxlan_gpe_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 _
+} ioam_vxlan_gpe_test_main_t;
 
-/*
- * Table of message reply handlers, must include boilerplate handlers
- * we just generated
- */
-#define foreach_vpe_api_reply_msg                                              \
-_(VXLAN_GPE_IOAM_ENABLE_REPLY, vxlan_gpe_ioam_enable_reply)                    \
-_(VXLAN_GPE_IOAM_DISABLE_REPLY, vxlan_gpe_ioam_disable_reply)                  \
-_(VXLAN_GPE_IOAM_VNI_ENABLE_REPLY, vxlan_gpe_ioam_vni_enable_reply)            \
-_(VXLAN_GPE_IOAM_VNI_DISABLE_REPLY, vxlan_gpe_ioam_vni_disable_reply)          \
-_(VXLAN_GPE_IOAM_TRANSIT_ENABLE_REPLY, vxlan_gpe_ioam_transit_enable_reply)    \
-_(VXLAN_GPE_IOAM_TRANSIT_DISABLE_REPLY, vxlan_gpe_ioam_transit_disable_reply)  \
+ioam_vxlan_gpe_test_main_t ioam_vxlan_gpe_test_main;
 
 static int
 api_vxlan_gpe_ioam_enable (vat_main_t * vam)
@@ -144,9 +101,7 @@ api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
 {
   unformat_input_t *line_input = vam->input;
   vl_api_vxlan_gpe_ioam_vni_enable_t *mp;
-  ip4_address_t local4, remote4;
-  ip6_address_t local6, remote6;
-  u8 ipv4_set = 0, ipv6_set = 0;
+  ip46_address_t local, remote;
   u8 local_set = 0;
   u8 remote_set = 0;
   u32 vni;
@@ -156,30 +111,15 @@ api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
 
   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
     {
-      if (unformat (line_input, "local %U", unformat_ip4_address, &local4))
+      if (unformat (line_input, "local %U", unformat_ip46_address, &local))
        {
          local_set = 1;
-         ipv4_set = 1;
        }
       else if (unformat (line_input, "remote %U",
-                        unformat_ip4_address, &remote4))
+                        unformat_ip46_address, &remote))
        {
          remote_set = 1;
-         ipv4_set = 1;
        }
-      else if (unformat (line_input, "local %U",
-                        unformat_ip6_address, &local6))
-       {
-         local_set = 1;
-         ipv6_set = 1;
-       }
-      else if (unformat (line_input, "remote %U",
-                        unformat_ip6_address, &remote6))
-       {
-         remote_set = 1;
-         ipv6_set = 1;
-       }
-
       else if (unformat (line_input, "vni %d", &vni))
        vni_set = 1;
       else
@@ -199,7 +139,7 @@ api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
       errmsg ("tunnel remote address not specified\n");
       return -99;
     }
-  if (ipv4_set && ipv6_set)
+  if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
     {
       errmsg ("both IPv4 and IPv6 addresses specified");
       return -99;
@@ -213,20 +153,14 @@ api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
 
   M (VXLAN_GPE_IOAM_VNI_ENABLE, mp);
 
-
-  if (ipv6_set)
-    {
-      clib_memcpy (&mp->local, &local6, sizeof (local6));
-      clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
-    }
-  else
-    {
-      clib_memcpy (&mp->local, &local4, sizeof (local4));
-      clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
-    }
+  ip_address_encode (&local,
+                    ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
+                    IP46_TYPE_IP6, &mp->local);
+  ip_address_encode (&local,
+                    ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
+                    IP46_TYPE_IP6, &mp->remote);
 
   mp->vni = ntohl (vni);
-  mp->is_ipv6 = ipv6_set;
 
   S (mp);
   W (ret);
@@ -238,9 +172,7 @@ api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
 {
   unformat_input_t *line_input = vam->input;
   vl_api_vxlan_gpe_ioam_vni_disable_t *mp;
-  ip4_address_t local4, remote4;
-  ip6_address_t local6, remote6;
-  u8 ipv4_set = 0, ipv6_set = 0;
+  ip46_address_t local, remote;
   u8 local_set = 0;
   u8 remote_set = 0;
   u32 vni;
@@ -250,30 +182,15 @@ api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
 
   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
     {
-      if (unformat (line_input, "local %U", unformat_ip4_address, &local4))
+      if (unformat (line_input, "local %U", unformat_ip46_address, &local))
        {
          local_set = 1;
-         ipv4_set = 1;
        }
       else if (unformat (line_input, "remote %U",
-                        unformat_ip4_address, &remote4))
+                        unformat_ip46_address, &remote))
        {
          remote_set = 1;
-         ipv4_set = 1;
        }
-      else if (unformat (line_input, "local %U",
-                        unformat_ip6_address, &local6))
-       {
-         local_set = 1;
-         ipv6_set = 1;
-       }
-      else if (unformat (line_input, "remote %U",
-                        unformat_ip6_address, &remote6))
-       {
-         remote_set = 1;
-         ipv6_set = 1;
-       }
-
       else if (unformat (line_input, "vni %d", &vni))
        vni_set = 1;
       else
@@ -293,7 +210,7 @@ api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
       errmsg ("tunnel remote address not specified\n");
       return -99;
     }
-  if (ipv4_set && ipv6_set)
+  if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
     {
       errmsg ("both IPv4 and IPv6 addresses specified");
       return -99;
@@ -307,20 +224,14 @@ api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
 
   M (VXLAN_GPE_IOAM_VNI_DISABLE, mp);
 
-
-  if (ipv6_set)
-    {
-      clib_memcpy (&mp->local, &local6, sizeof (local6));
-      clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
-    }
-  else
-    {
-      clib_memcpy (&mp->local, &local4, sizeof (local4));
-      clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
-    }
+  ip_address_encode (&local,
+                    ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
+                    IP46_TYPE_IP6, &mp->local);
+  ip_address_encode (&local,
+                    ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
+                    IP46_TYPE_IP6, &mp->remote);
 
   mp->vni = ntohl (vni);
-  mp->is_ipv6 = ipv6_set;
 
   S (mp);
   W (ret);
@@ -332,9 +243,7 @@ api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
 {
   unformat_input_t *line_input = vam->input;
   vl_api_vxlan_gpe_ioam_transit_enable_t *mp;
-  ip4_address_t local4;
-  ip6_address_t local6;
-  u8 ipv4_set = 0, ipv6_set = 0;
+  ip46_address_t local;
   u8 local_set = 0;
   u32 outer_fib_index = 0;
   int ret;
@@ -342,18 +251,10 @@ api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
 
   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
     {
-      if (unformat (line_input, "dst-ip %U", unformat_ip4_address, &local4))
-       {
-         local_set = 1;
-         ipv4_set = 1;
-       }
-      else if (unformat (line_input, "dst-ip %U",
-                        unformat_ip6_address, &local6))
+      if (unformat (line_input, "dst-ip %U", unformat_ip46_address, &local))
        {
          local_set = 1;
-         ipv6_set = 1;
        }
-
       else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
        ;
       else
@@ -368,28 +269,17 @@ api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
       errmsg ("destination address not specified\n");
       return -99;
     }
-  if (ipv4_set && ipv6_set)
-    {
-      errmsg ("both IPv4 and IPv6 addresses specified");
-      return -99;
-    }
-
 
   M (VXLAN_GPE_IOAM_TRANSIT_ENABLE, mp);
 
 
-  if (ipv6_set)
+  if (!ip46_address_is_ip4 (&local))
     {
       errmsg ("IPv6 currently unsupported");
       return -1;
     }
-  else
-    {
-      clib_memcpy (&mp->dst_addr, &local4, sizeof (local4));
-    }
-
+  ip_address_encode (&local, IP46_TYPE_IP4, &mp->dst_addr);
   mp->outer_fib_index = htonl (outer_fib_index);
-  mp->is_ipv6 = ipv6_set;
 
   S (mp);
   W (ret);
@@ -401,9 +291,7 @@ api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
 {
   unformat_input_t *line_input = vam->input;
   vl_api_vxlan_gpe_ioam_transit_disable_t *mp;
-  ip4_address_t local4;
-  ip6_address_t local6;
-  u8 ipv4_set = 0, ipv6_set = 0;
+  ip46_address_t local;
   u8 local_set = 0;
   u32 outer_fib_index = 0;
   int ret;
@@ -411,18 +299,10 @@ api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
 
   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
     {
-      if (unformat (line_input, "dst-ip %U", unformat_ip4_address, &local4))
-       {
-         local_set = 1;
-         ipv4_set = 1;
-       }
-      else if (unformat (line_input, "dst-ip %U",
-                        unformat_ip6_address, &local6))
+      if (unformat (line_input, "dst-ip %U", unformat_ip46_address, &local))
        {
          local_set = 1;
-         ipv6_set = 1;
        }
-
       else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
        ;
       else
@@ -437,96 +317,26 @@ api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
       errmsg ("destination address not specified\n");
       return -99;
     }
-  if (ipv4_set && ipv6_set)
-    {
-      errmsg ("both IPv4 and IPv6 addresses specified");
-      return -99;
-    }
-
 
   M (VXLAN_GPE_IOAM_TRANSIT_DISABLE, mp);
 
 
-  if (ipv6_set)
+  if (!ip46_address_is_ip4 (&local))
     {
       return -1;
     }
-  else
-    {
-      clib_memcpy (&mp->dst_addr, &local4, sizeof (local4));
-    }
+  ip_address_encode (&local, IP46_TYPE_IP4, &mp->dst_addr);
 
   mp->outer_fib_index = htonl (outer_fib_index);
-  mp->is_ipv6 = ipv6_set;
 
   S (mp);
   W (ret);
   return ret;
 }
 
-/*
- * List of messages that the api test plugin sends,
- * and that the data plane plugin processes
- */
-#define foreach_vpe_api_msg \
-_(vxlan_gpe_ioam_enable, ""\
-  "[trace] [pow] [ppc <encap|ppc decap>]") \
-_(vxlan_gpe_ioam_disable, "")                    \
-_(vxlan_gpe_ioam_vni_enable, ""\
-  "local <local_vtep_ip> remote <remote_vtep_ip> vni <vnid>") \
-_(vxlan_gpe_ioam_vni_disable, ""\
-  "local <local_vtep_ip> remote <remote_vtep_ip> vni <vnid>") \
-_(vxlan_gpe_ioam_transit_enable, ""\
-  "dst-ip <dst_ip> [outer-fib-index <outer_fib_index>]") \
-_(vxlan_gpe_ioam_transit_disable, ""\
-  "dst-ip <dst_ip> [outer-fib-index <outer_fib_index>]") \
-
-
-static void
-vxlan_gpe_vat_api_hookup (vat_main_t * vam)
-{
-  vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
-  /* Hook up handlers for replies from the data plane plug-in */
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers((VL_API_##N + sm->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 _
-}
-
-clib_error_t *
-vxlan_gpe_vat_plugin_register (vat_main_t * vam)
-{
-  vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
-  u8 *name;
-
-  sm->vat_main = vam;
-
-  name = format (0, "ioam_vxlan_gpe_%08x%c", api_version, 0);
-  sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (sm->msg_id_base != (u16) ~ 0)
-    vxlan_gpe_vat_api_hookup (vam);
-
-  vec_free (name);
-
-  return 0;
-}
+/* Override generated plugin register symbol */
+#define vat_plugin_register vxlan_gpe_vat_plugin_register
+#include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api_test.c>
 
 /*
  * fd.io coding-style-patch-verification: ON
index 72e578c..6b6213a 100644 (file)
@@ -14,7 +14,8 @@
  * limitations under the License.
  */
 
-option version = "2.0.0";
+option version = "3.0.0";
+import "vnet/ip/ip_types.api";
 
 /** \brief UDP-Probe Add/Delete request 
     @param src_ip_address - Source ipv4/v6 address for the udp-ping flow
@@ -30,14 +31,13 @@ option version = "2.0.0";
 autoreply define udp_ping_add_del {
   u32 client_index;
   u32 context;
-  u8 src_ip_address[16];
-  u8 dst_ip_address[16];
+  vl_api_address_t src_ip_address;
+  vl_api_address_t dst_ip_address;
   u16 start_src_port;
   u16 end_src_port;
   u16 start_dst_port;
   u16 end_dst_port;
   u16 interval;
-  u8 is_ipv4;
   u8 dis;
   u8 fault_det;
   u8 reserve[3];
@@ -51,6 +51,6 @@ autoreply define udp_ping_add_del {
 autoreply define udp_ping_export {
    u32 client_index;
    u32 context;
-   u32 enable;
+   bool enable;
 };
 
index 82f56aa..6c54e0d 100644 (file)
@@ -25,7 +25,8 @@
 
 #include <vlibapi/api.h>
 #include <vlibmemory/api.h>
-
+#include <vnet/format_fns.h>
+#include <vnet/ip/ip_types_api.h>
 
 /* define message IDs */
 #include <ioam/udp-ping/udp_ping.api_enum.h>
@@ -42,16 +43,13 @@ vl_api_udp_ping_add_del_t_handler (vl_api_udp_ping_add_del_t * mp)
   udp_ping_main_t *sm = &udp_ping_main;
   vl_api_udp_ping_add_del_reply_t *rmp;
 
-  if (mp->is_ipv4)
+  if (clib_net_to_host_u32 (mp->src_ip_address.af) == ADDRESS_IP4)
     {
       rv = -1;                 //Not supported
       goto ERROROUT;
     }
-
-  clib_memcpy ((void *) &src.ip6, (void *) mp->src_ip_address,
-              sizeof (ip6_address_t));
-  clib_memcpy ((void *) &dst.ip6, (void *) mp->dst_ip_address,
-              sizeof (ip6_address_t));
+  ip_address_decode (&mp->src_ip_address, &src);
+  ip_address_decode (&mp->dst_ip_address, &dst);
 
   ip46_udp_ping_set_flow (src, dst,
                          ntohs (mp->start_src_port),
index d435b22..84b878c 100644 (file)
 
 #include <vppinfra/error.h>
 #include <vnet/ip/ip.h>
+#include <vnet/format_fns.h>
+#include <vnet/ip/ip_types_api.h>
+
+#define __plugin_msg_base udp_ping_test_main.msg_id_base
+#include <vlibapi/vat_helper_macros.h>
 
 /* Declare message IDs */
 #include <ioam/udp-ping/udp_ping.api_enum.h>
 #include <ioam/udp-ping/udp_ping.api_types.h>
 
-#define vl_endianfun           /* define message structures */
-#define vl_printfun
-#define vl_print(handle, ...)
-#define vl_api_version(n,v) static u32 api_version=(v);
-#include <ioam/udp-ping/udp_ping.api.h>
-#undef vl_endianfun
-#undef vl_printfun
-#undef vl_api_version
-
 typedef struct
 {
   /* API message ID base */
@@ -47,79 +43,21 @@ typedef struct
 
 udp_ping_test_main_t udp_ping_test_main;
 
-#define foreach_standard_reply_retval_handler     \
-_(udp_ping_add_del_reply)                          \
-_(udp_ping_export_reply)
-
-#define _(n)                                            \
-    static void vl_api_##n##_t_handler                  \
-    (vl_api_##n##_t * mp)                               \
-    {                                                   \
-        vat_main_t * vam = udp_ping_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                                       \
-_(UDP_PING_ADD_DEL_REPLY, udp_ping_add_del_reply)                         \
-_(UDP_PING_EXPORT_REPLY, udp_ping_export_reply)                         \
-
-
-/* M: construct, but don't yet send a message */
-
-#define M(T,t)                                                  \
-do {                                                            \
-    vam->result_ready = 0;                                      \
-    mp = vl_msg_api_alloc(sizeof(*mp));                         \
-    clib_memset (mp, 0, sizeof (*mp));                               \
-    mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base);      \
-    mp->client_index = vam->my_client_index;                    \
-} while(0);
-
-/* S: send a message */
-#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
-
-/* W: wait for results, with timeout */
-#define W                                       \
-do {                                            \
-    timeout = vat_time_now (vam) + 5.0;         \
-                                                \
-    while (vat_time_now (vam) < timeout) {      \
-        if (vam->result_ready == 1) {           \
-            return (vam->retval);               \
-        }                                       \
-    }                                           \
-    return -99;                                 \
-} while(0);
-
 static int
 api_udp_ping_add_del (vat_main_t * vam)
 {
-  udp_ping_test_main_t *sm = &udp_ping_test_main;
   unformat_input_t *input = vam->input;
   vl_api_udp_ping_add_del_t *mp;
   int rv = 0;
-  ip6_address_t dst, src;
+  ip46_address_t dst, src;
   u32 start_src_port, end_src_port;
   u32 start_dst_port, end_dst_port;
   u32 interval;
   u8 is_disable = 0;
-  f64 timeout;
 
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
-      if (unformat (input, "src %U", unformat_ip6_address, &src))
+      if (unformat (input, "src %U", unformat_ip46_address, &src))
        ;
       else if (unformat (input, "start-src-port %d", &start_src_port))
        ;
@@ -129,7 +67,7 @@ api_udp_ping_add_del (vat_main_t * vam)
        ;
       else if (unformat (input, "end-dst-port %d", &end_dst_port))
        ;
-      else if (unformat (input, "dst %U", unformat_ip6_address, &dst))
+      else if (unformat (input, "dst %U", unformat_ip46_address, &dst))
        ;
       else if (unformat (input, "interval %d", &interval))
        ;
@@ -139,20 +77,19 @@ api_udp_ping_add_del (vat_main_t * vam)
        break;
     }
 
-  M (UDP_PING_ADD_DEL, udp_ping_add);
+  M (UDP_PING_ADD_DEL, mp);
 
-  clib_memcpy (mp->src_ip_address, &src, 16);
-  clib_memcpy (mp->dst_ip_address, &dst, 16);
+  ip_address_encode (&src, IP46_TYPE_IP6, &mp->src_ip_address);
+  ip_address_encode (&dst, IP46_TYPE_IP6, &mp->dst_ip_address);
   mp->start_src_port = (u16) start_src_port;
   mp->end_src_port = (u16) end_src_port;
   mp->start_dst_port = (u16) start_dst_port;
   mp->end_dst_port = (u16) end_dst_port;
   mp->interval = (u16) interval;
-  mp->is_ipv4 = 0;
   mp->dis = is_disable;
 
-  S;
-  W;
+  S (mp);
+  W (rv);
 
   return (rv);
 }
@@ -160,12 +97,10 @@ api_udp_ping_add_del (vat_main_t * vam)
 static int
 api_udp_ping_export (vat_main_t * vam)
 {
-  udp_ping_test_main_t *sm = &udp_ping_test_main;
   unformat_input_t *input = vam->input;
   vl_api_udp_ping_export_t *mp;
   int rv = 0;
   int is_add = 1;
-  f64 timeout;
 
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
     {
@@ -177,75 +112,19 @@ api_udp_ping_export (vat_main_t * vam)
        break;
     }
 
-  M (UDP_PING_EXPORT, udp_ping_export);
+  M (UDP_PING_EXPORT, mp);
 
   mp->enable = is_add;
 
-  S;
-  W;
+  S (mp);
+  W (rv);
 
   return (rv);
 }
 
-/*
- * List of messages that the api test plugin sends,
- * and that the data plane plugin processes
- */
-#define foreach_vpe_api_msg \
-_(udp_ping_add_del, "src <local IPv6 address>  start-src-port <first local port> "\
-  "end-src-port <last local port> " \
-  "dst <remote IPv6 address> start-dst-port <first destination port> "\
-  "end-dst-port <last destination port> "\
-  "interval <time interval in sec for which ping packet will be sent> "\
-  "[disable]")                         \
-_(udp_ping_export, "export [disable]")                                         \
-
-
-static void
-udp_ping_test_api_hookup (vat_main_t * vam)
-{
-  udp_ping_test_main_t *sm = &udp_ping_test_main;
-  /* Hook up handlers for replies from the data plane plug-in */
-#define _(N,n)                                                  \
-    vl_msg_api_set_handlers((VL_API_##N + sm->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 _
-}
-
-clib_error_t *
-udp_ping_vat_plugin_register (vat_main_t * vam)
-{
-  udp_ping_test_main_t *sm = &udp_ping_test_main;
-  u8 *name;
-
-  sm->vat_main = vam;
-
-  name = format (0, "udp_ping_%08x%c", api_version, 0);
-  sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (sm->msg_id_base != (u16) ~ 0)
-    udp_ping_test_api_hookup (vam);
-
-  vec_free (name);
-
-  return 0;
-}
+/* Override generated plugin register symbol */
+#define vat_plugin_register udp_ping_vat_plugin_register
+#include <ioam/udp-ping/udp_ping.api_test.c>
 
 /*
  * fd.io coding-style-patch-verification: ON