Convert message macro S to accept a message pointer parameter;
[vpp.git] / src / plugins / ioam / lib-vxlan-gpe / vxlan_gpe_test.c
index b5fee72..ee25a87 100644 (file)
@@ -24,6 +24,9 @@
 #include <vlibsocket/api.h>
 #include <vppinfra/error.h>
 
+#define __plugin_msg_base vxlan_gpe_test_main.msg_id_base
+#include <vlibapi/vat_helper_macros.h>
+
 /* Declare message IDs */
 #include <ioam/lib-vxlan-gpe/vxlan_gpe_msg_enum.h>
 
@@ -96,49 +99,9 @@ _(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)  \
 
-
-/* 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));                         \
-    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);
-
-#define M2(T,t,n)                                               \
-do {                                                            \
-    vam->result_ready = 0;                                      \
-    mp = vl_msg_api_alloc(sizeof(*mp)+(n));                     \
-    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) + 1.0;         \
-                                                \
-    while (vat_time_now (vam) < timeout) {      \
-        if (vam->result_ready == 1) {           \
-            return (vam->retval);               \
-        }                                       \
-    }                                           \
-    return -99;                                 \
-} while(0);
-
-
 static int
 api_vxlan_gpe_ioam_enable (vat_main_t * vam)
 {
-  vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
-
   unformat_input_t *input = vam->input;
   vl_api_vxlan_gpe_ioam_enable_t *mp;
   f64 timeout;
@@ -162,14 +125,14 @@ api_vxlan_gpe_ioam_enable (vat_main_t * vam)
       else
        break;
     }
-  M (VXLAN_GPE_IOAM_ENABLE, vxlan_gpe_ioam_enable);
+  M (VXLAN_GPE_IOAM_ENABLE, mp);
   mp->id = htons (id);
   mp->trace_ppc = has_ppc_option;
   mp->pow_enable = has_pow_option;
   mp->trace_enable = has_trace_option;
 
 
-  S;
+  S (mp);
   W;
 
   return (0);
@@ -179,12 +142,11 @@ api_vxlan_gpe_ioam_enable (vat_main_t * vam)
 static int
 api_vxlan_gpe_ioam_disable (vat_main_t * vam)
 {
-  vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
   vl_api_vxlan_gpe_ioam_disable_t *mp;
   f64 timeout;
 
-  M (VXLAN_GPE_IOAM_DISABLE, vxlan_gpe_ioam_disable);
-  S;
+  M (VXLAN_GPE_IOAM_DISABLE, mp);
+  S (mp);
   W;
   return 0;
 }
@@ -192,8 +154,6 @@ api_vxlan_gpe_ioam_disable (vat_main_t * vam)
 static int
 api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
 {
-  vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
-
   unformat_input_t *line_input = vam->input;
   vl_api_vxlan_gpe_ioam_vni_enable_t *mp;
   ip4_address_t local4, remote4;
@@ -263,7 +223,7 @@ api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
       return -99;
     }
 
-  M (VXLAN_GPE_IOAM_VNI_ENABLE, vxlan_gpe_ioam_vni_enable);
+  M (VXLAN_GPE_IOAM_VNI_ENABLE, mp);
 
 
   if (ipv6_set)
@@ -280,7 +240,7 @@ api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
   mp->vni = ntohl (vni);
   mp->is_ipv6 = ipv6_set;
 
-  S;
+  S (mp);
   W;
 
   return (0);
@@ -289,8 +249,6 @@ api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
 static int
 api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
 {
-  vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
-
   unformat_input_t *line_input = vam->input;
   vl_api_vxlan_gpe_ioam_vni_disable_t *mp;
   ip4_address_t local4, remote4;
@@ -360,7 +318,7 @@ api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
       return -99;
     }
 
-  M (VXLAN_GPE_IOAM_VNI_DISABLE, vxlan_gpe_ioam_vni_disable);
+  M (VXLAN_GPE_IOAM_VNI_DISABLE, mp);
 
 
   if (ipv6_set)
@@ -377,7 +335,7 @@ api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
   mp->vni = ntohl (vni);
   mp->is_ipv6 = ipv6_set;
 
-  S;
+  S (mp);
   W;
 
   return 0;
@@ -386,8 +344,6 @@ api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
 static int
 api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
 {
-  vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
-
   unformat_input_t *line_input = vam->input;
   vl_api_vxlan_gpe_ioam_transit_enable_t *mp;
   ip4_address_t local4;
@@ -433,7 +389,7 @@ api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
     }
 
 
-  M (VXLAN_GPE_IOAM_TRANSIT_ENABLE, vxlan_gpe_ioam_transit_enable);
+  M (VXLAN_GPE_IOAM_TRANSIT_ENABLE, mp);
 
 
   if (ipv6_set)
@@ -449,7 +405,7 @@ api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
   mp->outer_fib_index = htonl (outer_fib_index);
   mp->is_ipv6 = ipv6_set;
 
-  S;
+  S (mp);
   W;
 
   return (0);
@@ -458,8 +414,6 @@ api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
 static int
 api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
 {
-  vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
-
   unformat_input_t *line_input = vam->input;
   vl_api_vxlan_gpe_ioam_transit_disable_t *mp;
   ip4_address_t local4;
@@ -505,7 +459,7 @@ api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
     }
 
 
-  M (VXLAN_GPE_IOAM_TRANSIT_DISABLE, vxlan_gpe_ioam_transit_disable);
+  M (VXLAN_GPE_IOAM_TRANSIT_DISABLE, mp);
 
 
   if (ipv6_set)
@@ -520,7 +474,7 @@ api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
   mp->outer_fib_index = htonl (outer_fib_index);
   mp->is_ipv6 = ipv6_set;
 
-  S;
+  S (mp);
   W;
 
 
@@ -545,8 +499,8 @@ _(vxlan_gpe_ioam_transit_disable, ""\
   "dst-ip <dst_ip> [outer-fib-index <outer_fib_index>]") \
 
 
-void
-vat_api_hookup (vat_main_t * vam)
+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 */
@@ -584,7 +538,7 @@ vat_plugin_register (vat_main_t * vam)
   sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
 
   if (sm->msg_id_base != (u16) ~ 0)
-    vat_api_hookup (vam);
+    vxlan_gpe_vat_api_hookup (vam);
 
   vec_free (name);