Repair vlib API socket server
[vpp.git] / src / plugins / ioam / udp-ping / udp_ping_api.c
index 8cb8cc9..5219009 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <vlibapi/api.h>
 #include <vlibmemory/api.h>
-#include <vlibsocket/api.h>
+
 
 /* define message IDs */
 #include <ioam/udp-ping/udp_ping_msg_enum.h>
 #include <ioam/udp-ping/udp_ping_all_api_h.h>
 #undef vl_api_version
 
-/*
- * A handy macro to set up a message reply.
- * Assumes that the following variables are available:
- * mp - pointer to request message
- * rmp - pointer to reply message type
- * rv - return value
- */
-
-#define REPLY_MACRO(t)                                          \
-    do {                                                            \
-        unix_shared_memory_queue_t * q =                            \
-        vl_api_client_index_to_input_queue (mp->client_index);      \
-        if (!q)                                                     \
-        return;                                                 \
-        \
-        rmp = vl_msg_api_alloc (sizeof (*rmp));                     \
-        rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base);               \
-        rmp->context = mp->context;                                 \
-        rmp->retval = ntohl(rv);                                    \
-        \
-        vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-    } while(0);
-
-#define REPLY_MACRO2(t, body)                                   \
-    do {                                                            \
-        unix_shared_memory_queue_t * q;                             \
-        rv = vl_msg_api_pd_handler (mp, rv);                        \
-        q = vl_api_client_index_to_input_queue (mp->client_index);  \
-        if (!q)                                                     \
-        return;                                                 \
-        \
-        rmp = vl_msg_api_alloc (sizeof (*rmp));                     \
-        rmp->_vl_msg_id = ntohs((t));                               \
-        rmp->context = mp->context;                                 \
-        rmp->retval = ntohl(rv);                                    \
-        do {body;} while (0);                                       \
-        vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
-    } while(0);
+#define REPLY_MSG_ID_BASE sm->msg_id_base
+#include <vlibapi/api_helper_macros.h>
 
 /* List of message types that this module understands */
-
 #define foreach_udp_ping_api_msg                                      \
     _(UDP_PING_ADD_DEL_REQ, udp_ping_add_del_req)                                     \
     _(UDP_PING_EXPORT_REQ, udp_ping_export_req)                                     \
@@ -159,6 +122,19 @@ udp_ping_api_hookup (vlib_main_t * vm)
   return 0;
 }
 
+#define vl_msg_name_crc_list
+#include <ioam/udp-ping/udp_ping_all_api_h.h>
+#undef vl_msg_name_crc_list
+
+static void
+setup_message_id_table (udp_ping_main_t * sm, api_main_t * am)
+{
+#define _(id,n,crc) \
+  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
+  foreach_vl_msg_name_crc_udp_ping;
+#undef _
+}
+
 static clib_error_t *
 udp_ping_api_init (vlib_main_t * vm)
 {
@@ -174,6 +150,9 @@ udp_ping_api_init (vlib_main_t * vm)
 
   error = udp_ping_api_hookup (vm);
 
+  /* Add our API messages to the global name_crc hash table */
+  setup_message_id_table (sm, &api_main);
+
   vec_free (name);
 
   return error;