Localize the timeout variable within the W message macro.
[vpp.git] / src / plugins / flowperpkt / flowperpkt_test.c
index 716818f..4cc1cfb 100644 (file)
@@ -20,6 +20,9 @@
 #include <vlibsocket/api.h>
 #include <vppinfra/error.h>
 
+#define __plugin_msg_base flowperpkt_test_main.msg_id_base
+#include <vlibapi/vat_helper_macros.h>
+
 /**
  * @file vpp_api_test plugin
  */
@@ -88,49 +91,10 @@ foreach_standard_reply_retval_handler;
 _(FLOWPERPKT_TX_INTERFACE_ADD_DEL_REPLY,        \
   flowperpkt_tx_interface_add_del_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_flowperpkt_tx_interface_add_del (vat_main_t * vam)
 {
-  flowperpkt_test_main_t *sm = &flowperpkt_test_main;
   unformat_input_t *i = vam->input;
-  f64 timeout;
   int enable_disable = 1;
   u8 which = 0;                        /* ipv4 by default */
   u32 sw_if_index = ~0;
@@ -158,13 +122,13 @@ api_flowperpkt_tx_interface_add_del (vat_main_t * vam)
     }
 
   /* Construct the API message */
-  M (FLOWPERPKT_TX_INTERFACE_ADD_DEL, flowperpkt_tx_interface_add_del);
+  M (FLOWPERPKT_TX_INTERFACE_ADD_DEL, mp);
   mp->sw_if_index = ntohl (sw_if_index);
   mp->is_add = enable_disable;
   mp->which = which;
 
   /* send it... */
-  S;
+  S (mp);
 
   /* Wait for a reply... */
   W;
@@ -177,8 +141,8 @@ api_flowperpkt_tx_interface_add_del (vat_main_t * vam)
 #define foreach_vpe_api_msg \
 _(flowperpkt_tx_interface_add_del, "<intfc> [disable]")
 
-void
-vat_api_hookup (vat_main_t * vam)
+static void
+flowperpkt_vat_api_hookup (vat_main_t * vam)
 {
   flowperpkt_test_main_t *sm = &flowperpkt_test_main;
   /* Hook up handlers for replies from the data plane plug-in */
@@ -218,7 +182,7 @@ vat_plugin_register (vat_main_t * vam)
 
   /* Don't attempt to hook up API messages if the data plane plugin is AWOL */
   if (sm->msg_id_base != (u16) ~ 0)
-    vat_api_hookup (vam);
+    flowperpkt_vat_api_hookup (vam);
 
   vec_free (name);