summaryrefslogtreecommitdiffstats
path: root/libtransport/src
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/src')
-rw-r--r--libtransport/src/hicn/transport/core/CMakeLists.txt10
-rw-r--r--libtransport/src/hicn/transport/core/hicn_binary_api.c296
-rw-r--r--libtransport/src/hicn/transport/core/hicn_vapi.c220
-rw-r--r--libtransport/src/hicn/transport/core/hicn_vapi.h (renamed from libtransport/src/hicn/transport/core/hicn_binary_api.h)28
-rw-r--r--libtransport/src/hicn/transport/core/memif_binary_api.c220
-rw-r--r--libtransport/src/hicn/transport/core/memif_connector.h2
-rw-r--r--libtransport/src/hicn/transport/core/memif_vapi.c130
-rw-r--r--libtransport/src/hicn/transport/core/memif_vapi.h (renamed from libtransport/src/hicn/transport/core/memif_binary_api.h)10
-rw-r--r--libtransport/src/hicn/transport/core/vpp_binary_api.c251
-rw-r--r--libtransport/src/hicn/transport/core/vpp_binary_api.h77
-rw-r--r--libtransport/src/hicn/transport/core/vpp_binary_api_internal.h74
-rw-r--r--libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc60
-rw-r--r--libtransport/src/hicn/transport/core/vpp_forwarder_interface.h8
13 files changed, 402 insertions, 984 deletions
diff --git a/libtransport/src/hicn/transport/core/CMakeLists.txt b/libtransport/src/hicn/transport/core/CMakeLists.txt
index 0e674fcac..8439fdf45 100644
--- a/libtransport/src/hicn/transport/core/CMakeLists.txt
+++ b/libtransport/src/hicn/transport/core/CMakeLists.txt
@@ -55,17 +55,15 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
list(APPEND HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/vpp_forwarder_interface.h
${CMAKE_CURRENT_SOURCE_DIR}/memif_connector.h
- ${CMAKE_CURRENT_SOURCE_DIR}/hicn_binary_api.h
- ${CMAKE_CURRENT_SOURCE_DIR}/vpp_binary_api.h
- ${CMAKE_CURRENT_SOURCE_DIR}/memif_binary_api.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn_vapi.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/memif_vapi.h
)
list(APPEND SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/vpp_forwarder_interface.cc
${CMAKE_CURRENT_SOURCE_DIR}/memif_connector.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/hicn_binary_api.c
- ${CMAKE_CURRENT_SOURCE_DIR}/vpp_binary_api.c
- ${CMAKE_CURRENT_SOURCE_DIR}/memif_binary_api.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn_vapi.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/memif_vapi.c
)
endif()
diff --git a/libtransport/src/hicn/transport/core/hicn_binary_api.c b/libtransport/src/hicn/transport/core/hicn_binary_api.c
deleted file mode 100644
index 1f8dfd326..000000000
--- a/libtransport/src/hicn/transport/core/hicn_binary_api.c
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hicn/transport/config.h>
-
-#ifdef __vpp__
-
-#include <hicn/transport/core/hicn_binary_api.h>
-#include <hicn/transport/core/vpp_binary_api_internal.h>
-#include <hicn/transport/utils/log.h>
-
-#define HICN_VPP_PLUGIN
-#include <hicn/name.h>
-#undef HICN_VPP_PLUGIN
-
-#include <fcntl.h>
-#include <inttypes.h>
-#include <semaphore.h>
-#include <string.h>
-#include <sys/stat.h>
-
-#include <vlib/vlib.h>
-#include <vlibapi/api.h>
-#include <vlibmemory/api.h>
-#include <vppinfra/error.h>
-
-#include <vnet/ip/format.h>
-#include <vnet/ip/ip4_packet.h>
-#include <vnet/ip/ip6_packet.h>
-#include <vnet/ip/ip_types_api.h>
-#include <vnet/fib/fib_types.h>
-
-#include <vpp_plugins/hicn/error.h>
-#include <vpp_plugins/hicn/hicn_api.h>
-
-// uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
-
-/* Declare message IDs */
-#include <hicn/hicn_msg_enum.h>
-
-#define vl_endianfun
-#define vl_typedefs
-#include <vnet/ip/ip_types.api.h>
-#undef vl_typedefs
-#undef vl_endianfun
-
-#define vl_endianfun /* define message structures */
-#define vl_print(handle, ...)
-#define vl_printfun
-#define vl_api_version(n, v) static u32 api_version = (v);
-#define vl_msg_name_crc_list
-#include <hicn/hicn_all_api_h.h>
-#undef vl_msg_name_crc_list
-#undef vl_api_version
-#undef vl_printfun
-#undef vl_endianfun
-/////////////////////////////////////////////////////
-const char *HICN_ERROR_STRING[] = {
-#define _(a, b, c) c,
- foreach_hicn_error
-#undef _
-};
-/////////////////////////////////////////////////////
-
-/*********************** Missing Symbol in vpp libraries *************************/
-u8 *
-format_vl_api_address_union (u8 * s, va_list * args)
-{
- const vl_api_address_union_t *addr =
- va_arg (*args, vl_api_address_union_t *);
- vl_api_address_family_t af = va_arg (*args, vl_api_address_family_t);
-
- if (ADDRESS_IP6 == af)
- s = format (s, "%U", format_ip6_address, addr->ip6);
- else
- s = format (s, "%U", format_ip4_address, addr->ip4);
-
- return s;
-}
-
-/*********************************************************************************/
-
-static context_store_t context_store = {
- .global_pointers_map_index = 0,
-};
-
-/*
- * Table of message reply handlers, must include boilerplate handlers
- * we just generated
- */
-#define foreach_hicn_api_reply_msg \
- _(HICN_API_REGISTER_PROD_APP_REPLY, hicn_api_register_prod_app_reply) \
- _(HICN_API_FACE_PROD_DEL_REPLY, hicn_api_face_prod_del_reply) \
- _(HICN_API_REGISTER_CONS_APP_REPLY, hicn_api_register_cons_app_reply) \
- _(HICN_API_FACE_CONS_DEL_REPLY, hicn_api_face_cons_del_reply) \
- _(HICN_API_ROUTE_NHOPS_ADD_REPLY, hicn_api_route_nhops_add_reply)
-
-int hicn_binary_api_register_prod_app(
- vpp_plugin_binary_api_t *api, hicn_producer_input_params *input_params,
- hicn_producer_output_params *output_params) {
- vl_api_hicn_api_register_prod_app_t *mp;
- vpp_plugin_binary_api_t *hm = api;
- vpp_binary_api_set_user_param(api->vpp_api, output_params);
-
- /* Construct the API message */
- M(HICN_API_REGISTER_PROD_APP, mp);
-
- CONTEXT_SAVE(context_store, api, mp)
-
- fib_prefix_t prefix;
- memcpy(&prefix.fp_addr, &input_params->prefix->address, sizeof(ip46_address_t));
- prefix.fp_len = input_params->prefix->len;
- prefix.fp_proto = ip46_address_is_ip4(&prefix.fp_addr) ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
- ip_prefix_encode(&prefix, &(mp->prefix));
- mp->swif = clib_host_to_net_u32(input_params->swif);
- mp->cs_reserved = clib_host_to_net_u32(input_params->cs_reserved);
-
- return vpp_binary_api_send_request_wait_reply(api->vpp_api, mp);
-}
-
-static void vl_api_hicn_api_register_prod_app_reply_t_handler(
- vl_api_hicn_api_register_prod_app_reply_t *mp) {
- vpp_plugin_binary_api_t *binary_api;
- CONTEXT_GET(context_store, mp, binary_api);
- hicn_producer_output_params *params =
- vpp_binary_api_get_user_param(binary_api->vpp_api);
-
- vpp_binary_api_set_ret_value(binary_api->vpp_api,
- clib_net_to_host_u32(mp->retval));
- params->cs_reserved = mp->cs_reserved;
- params->prod_addr = (ip_address_t *)malloc(sizeof(ip_address_t));
- ip_address_decode(&mp->prod_addr, (ip46_address_t *)(params->prod_addr));
- params->face_id = clib_net_to_host_u32(mp->faceid);
-
- vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api);
-}
-
-int hicn_binary_api_face_prod_del(
- vpp_plugin_binary_api_t *api, hicn_del_face_app_input_params *input_params) {
- vl_api_hicn_api_face_prod_del_t *mp;
- vpp_plugin_binary_api_t *hm = api;
-
- //vpp_binary_api_set_user_param(hm->vpp_api, output_params);
-
- /* Construct the API message */
- M(HICN_API_FACE_PROD_DEL, mp);
-
- mp->faceid = clib_host_to_net_u32(input_params->face_id);
-
- CONTEXT_SAVE(context_store, api, mp)
-
- return vpp_binary_api_send_request_wait_reply(api->vpp_api, mp);
-}
-
-static void vl_api_hicn_api_face_prod_del_reply_t_handler(
- vl_api_hicn_api_face_prod_del_reply_t *mp) {
- vpp_plugin_binary_api_t *binary_api;
- CONTEXT_GET(context_store, mp, binary_api);
-
- vpp_binary_api_set_ret_value(binary_api->vpp_api,
- clib_net_to_host_u32(mp->retval));
-
- vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api);
-}
-
-int hicn_binary_api_register_cons_app(
- vpp_plugin_binary_api_t *api, hicn_consumer_input_params *input_params,
- hicn_consumer_output_params *output_params) {
- vl_api_hicn_api_register_cons_app_t *mp;
- vpp_plugin_binary_api_t *hm = api;
-
- vpp_binary_api_set_user_param(hm->vpp_api, output_params);
-
- /* Construct the API message */
- M(HICN_API_REGISTER_CONS_APP, mp);
-
- mp->swif = clib_host_to_net_u32(input_params->swif);
-
- CONTEXT_SAVE(context_store, api, mp)
-
- return vpp_binary_api_send_request_wait_reply(api->vpp_api, mp);
-}
-
-static void vl_api_hicn_api_register_cons_app_reply_t_handler(
- vl_api_hicn_api_register_cons_app_reply_t *mp) {
- vpp_plugin_binary_api_t *binary_api;
- CONTEXT_GET(context_store, mp, binary_api);
- hicn_consumer_output_params *params =
- vpp_binary_api_get_user_param(binary_api->vpp_api);
-
- vpp_binary_api_set_ret_value(binary_api->vpp_api,
- clib_net_to_host_u32(mp->retval));
-
- ip_address_decode(&mp->src_addr4, (ip46_address_t *)params->src4);
- ip_address_decode(&mp->src_addr6, (ip46_address_t *)params->src6);
- params->face_id1 = clib_host_to_net_u32(mp->faceid1);
- params->face_id2 = clib_host_to_net_u32(mp->faceid2);
-
- vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api);
-}
-
-int hicn_binary_api_face_cons_del(
- vpp_plugin_binary_api_t *api, hicn_del_face_app_input_params *input_params) {
- vl_api_hicn_api_face_cons_del_t *mp;
- vpp_plugin_binary_api_t *hm = api;
-
- /* Construct the API message */
- M(HICN_API_FACE_CONS_DEL, mp);
-
- mp->faceid = clib_host_to_net_u32(input_params->face_id);
-
- CONTEXT_SAVE(context_store, api, mp)
-
- return vpp_binary_api_send_request_wait_reply(api->vpp_api, mp);
-}
-
-static void vl_api_hicn_api_face_cons_del_reply_t_handler(
- vl_api_hicn_api_face_cons_del_reply_t *mp) {
- vpp_plugin_binary_api_t *binary_api;
- CONTEXT_GET(context_store, mp, binary_api);
-
- vpp_binary_api_set_ret_value(binary_api->vpp_api,
- clib_net_to_host_u32(mp->retval));
-
- vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api);
-}
-
-int hicn_binary_api_register_route(
- vpp_plugin_binary_api_t *api,
- hicn_producer_set_route_params *input_params) {
- vl_api_hicn_api_route_nhops_add_t *mp;
- vpp_plugin_binary_api_t *hm = api;
-
- /* Construct the API message */
- M(HICN_API_ROUTE_NHOPS_ADD, mp);
-
- CONTEXT_SAVE(context_store, api, mp)
- fib_prefix_t prefix;
- memcpy(&prefix.fp_addr, &input_params->prefix->address, sizeof(ip46_address_t));
- prefix.fp_len = input_params->prefix->len;
- mp->face_ids[0] = clib_host_to_net_u32(input_params->face_id);
- mp->n_faces = 1;
-
- return vpp_binary_api_send_request_wait_reply(api->vpp_api, mp);
-}
-
-static void vl_api_hicn_api_route_nhops_add_reply_t_handler(
- vl_api_hicn_api_route_nhops_add_reply_t *mp) {
- vpp_plugin_binary_api_t *binary_api;
- CONTEXT_GET(context_store, mp, binary_api);
-
- vpp_binary_api_set_ret_value(binary_api->vpp_api,
- clib_net_to_host_u32(mp->retval));
-
- vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api);
-}
-
-static int hicn_binary_api_setup_handlers(vpp_plugin_binary_api_t *binary_api) {
- vpp_plugin_binary_api_t *sm __attribute__((unused)) = binary_api;
-#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_hicn_api_reply_msg;
-#undef _
- return 0;
-}
-
-char *hicn_binary_api_get_error_string(int ret_val) {
- return get_error_string(ret_val);
-}
-
-vpp_plugin_binary_api_t *hicn_binary_api_init(vpp_binary_api_t *api) {
- vpp_plugin_binary_api_t *ret = malloc(sizeof(vpp_plugin_binary_api_t));
- u8 *name = format(0, "hicn_%08x%c", api_version, 0);
- ret->msg_id_base = vl_client_get_first_plugin_msg_id((char *)name);
- ret->vpp_api = api;
- ret->my_client_index = vpp_binary_api_get_client_index(api);
- hicn_binary_api_setup_handlers(ret);
- return ret;
-}
-
-#endif // __vpp__
diff --git a/libtransport/src/hicn/transport/core/hicn_vapi.c b/libtransport/src/hicn/transport/core/hicn_vapi.c
new file mode 100644
index 000000000..cca5a552a
--- /dev/null
+++ b/libtransport/src/hicn/transport/core/hicn_vapi.c
@@ -0,0 +1,220 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hicn/transport/config.h>
+
+#ifdef __vpp__
+
+#include <hicn/transport/core/hicn_vapi.h>
+#include <hicn/transport/utils/log.h>
+
+#define HICN_VPP_PLUGIN
+#include <hicn/name.h>
+#undef HICN_VPP_PLUGIN
+
+#include <vlib/vlib.h>
+#include <vlibapi/api.h>
+#include <vlibmemory/api.h>
+#include <vppinfra/error.h>
+
+#include <vnet/ip/format.h>
+#include <vnet/ip/ip4_packet.h>
+#include <vnet/ip/ip6_packet.h>
+#include <vnet/ip/ip_types_api.h>
+#include <vnet/fib/fib_types.h>
+
+#include <vpp_plugins/hicn/error.h>
+#include <vapi/hicn.api.vapi.h>
+//#include <vpp_plugins/hicn/hicn_api.h>
+
+/////////////////////////////////////////////////////
+const char *HICN_ERROR_STRING[] = {
+#define _(a, b, c) c,
+ foreach_hicn_error
+#undef _
+};
+/////////////////////////////////////////////////////
+
+/*********************** Missing Symbol in vpp libraries *************************/
+u8 *
+format_vl_api_address_union (u8 * s, va_list * args)
+{
+ // const vl_api_address_union_t *addr =
+ // va_arg (*args, vl_api_address_union_t *);
+ // vl_api_address_family_t af = va_arg (*args, vl_api_address_family_t);
+
+ // if (ADDRESS_IP6 == af)
+ // s = format (s, "%U", format_ip6_address, addr->ip6);
+ // else
+ // s = format (s, "%U", format_ip4_address, addr->ip4);
+
+ // return s;
+ return NULL;
+}
+
+/*********************************************************************************/
+
+DEFINE_VAPI_MSG_IDS_HICN_API_JSON
+
+static vapi_error_e register_prod_app_cb(vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_hicn_api_register_prod_app_reply *reply) {
+ hicn_producer_output_params * output_params = (hicn_producer_output_params *)callback_ctx;
+
+ if(reply == NULL)
+ return rv;
+
+ output_params->cs_reserved = reply->cs_reserved;
+ output_params->prod_addr = (ip_address_t *)malloc(sizeof(ip_address_t));
+ memset(output_params->prod_addr, 0, sizeof(ip_address_t));
+ if(reply->prod_addr.af == ADDRESS_IP6)
+ memcpy(&output_params->prod_addr->v6, reply->prod_addr.un.ip6, sizeof(ip6_address_t));
+ else
+ memcpy(&output_params->prod_addr->v4, reply->prod_addr.un.ip4, sizeof(ip4_address_t));
+ output_params->face_id = reply->faceid;
+
+ return reply->retval;
+}
+
+int hicn_vapi_register_prod_app(
+ vapi_ctx_t ctx, hicn_producer_input_params *input_params,
+ hicn_producer_output_params *output_params) {
+
+ vapi_msg_hicn_api_register_prod_app * msg = vapi_alloc_hicn_api_register_prod_app(ctx);
+
+ if(ip46_address_is_ip4(&input_params->prefix->address)) {
+ memcpy(&msg->payload.prefix.address.un.ip4, &input_params->prefix->address, sizeof(ip4_address_t));
+ msg->payload.prefix.address.af = ADDRESS_IP4;
+ } else {
+ memcpy(&msg->payload.prefix.address.un.ip6, &input_params->prefix->address, sizeof(ip6_address_t));
+ msg->payload.prefix.address.af = ADDRESS_IP6;
+ }
+ msg->payload.prefix.len = input_params->prefix->len;
+
+ msg->payload.swif = input_params->swif;
+ msg->payload.cs_reserved = input_params->cs_reserved;
+
+ return vapi_hicn_api_register_prod_app(ctx, msg, register_prod_app_cb, output_params);
+}
+
+static vapi_error_e face_prod_del_cb(vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_hicn_api_face_prod_del_reply *reply) {
+ if(reply == NULL)
+ return rv;
+
+ return reply->retval;
+}
+
+int hicn_vapi_face_prod_del(
+ vapi_ctx_t ctx, hicn_del_face_app_input_params *input_params) {
+
+ vapi_msg_hicn_api_face_prod_del * msg = vapi_alloc_hicn_api_face_prod_del(ctx);
+
+ msg->payload.faceid = input_params->face_id;
+
+ return vapi_hicn_api_face_prod_del(ctx, msg, face_prod_del_cb, NULL);
+}
+
+static vapi_error_e register_cons_app_cb(vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_hicn_api_register_cons_app_reply *reply) {
+ hicn_consumer_output_params * output_params = (hicn_consumer_output_params *)callback_ctx;
+
+ if(reply == NULL)
+ return rv;
+
+ output_params->src6 = (ip_address_t *)malloc(sizeof(ip_address_t));
+ output_params->src4 = (ip_address_t *)malloc(sizeof(ip_address_t));
+ memset(output_params->src6, 0, sizeof(ip_address_t));
+ memset(output_params->src4, 0, sizeof(ip_address_t));
+ memcpy(&output_params->src6->v6, &reply->src_addr6.un.ip6, sizeof(ip6_address_t));
+ memcpy(&output_params->src4->v4, &reply->src_addr4.un.ip4, sizeof(ip4_address_t));
+
+ output_params->face_id1 = reply->faceid1;
+ output_params->face_id2 = reply->faceid2;
+
+ return reply->retval;
+}
+
+int hicn_vapi_register_cons_app(
+ vapi_ctx_t ctx, hicn_consumer_input_params *input_params,
+ hicn_consumer_output_params *output_params) {
+
+ vapi_msg_hicn_api_register_cons_app * msg = vapi_alloc_hicn_api_register_cons_app(ctx);
+
+ msg->payload.swif = input_params->swif;
+
+ return vapi_hicn_api_register_cons_app(ctx, msg, register_cons_app_cb, output_params);
+}
+
+static vapi_error_e face_cons_del_cb(vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_hicn_api_face_cons_del_reply *reply) {
+ if(reply == NULL)
+ return rv;
+
+ return reply->retval;
+}
+
+int hicn_vapi_face_cons_del(
+ vapi_ctx_t ctx, hicn_del_face_app_input_params *input_params) {
+
+ vapi_msg_hicn_api_face_cons_del * msg = vapi_alloc_hicn_api_face_cons_del(ctx);
+
+ msg->payload.faceid = input_params->face_id;
+
+ return vapi_hicn_api_face_cons_del(ctx, msg, face_cons_del_cb, NULL);
+}
+
+static vapi_error_e reigster_route_cb(vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_hicn_api_route_nhops_add_reply *reply) {
+ if(reply == NULL)
+ return rv;
+
+ return reply->retval;
+}
+
+int hicn_vapi_register_route(
+ vapi_ctx_t ctx,
+ hicn_producer_set_route_params *input_params) {
+
+ vapi_msg_hicn_api_route_nhops_add * msg = vapi_alloc_hicn_api_route_nhops_add(ctx);
+
+ fib_prefix_t prefix;
+ memcpy(&prefix.fp_addr, &input_params->prefix->address, sizeof(ip46_address_t));
+ prefix.fp_len = input_params->prefix->len;
+ msg->payload.face_ids[0] = input_params->face_id;
+ msg->payload.n_faces = 1;
+
+ return vapi_hicn_api_route_nhops_add(ctx, msg, reigster_route_cb, NULL);
+}
+
+char *hicn_vapi_get_error_string(int ret_val) {
+ return get_error_string(ret_val);
+}
+
+#endif // __vpp__
diff --git a/libtransport/src/hicn/transport/core/hicn_binary_api.h b/libtransport/src/hicn/transport/core/hicn_vapi.h
index 11543da19..f2718e6f5 100644
--- a/libtransport/src/hicn/transport/core/hicn_binary_api.h
+++ b/libtransport/src/hicn/transport/core/hicn_vapi.h
@@ -20,12 +20,12 @@
#ifdef __vpp__
-#include <hicn/transport/core/vpp_binary_api.h>
-
#ifdef __cplusplus
extern "C" {
#endif
+#include <vapi/vapi.h>
+
#include "stdint.h"
typedef struct {
@@ -60,26 +60,24 @@ typedef struct {
uint32_t face_id;
} hicn_producer_set_route_params;
-vpp_plugin_binary_api_t* hicn_binary_api_init(vpp_binary_api_t* api);
-
-int hicn_binary_api_register_prod_app(
- vpp_plugin_binary_api_t* api, hicn_producer_input_params* input_params,
+int hicn_vapi_register_prod_app(
+ vapi_ctx_t ctx, hicn_producer_input_params* input_params,
hicn_producer_output_params* output_params);
-int hicn_binary_api_register_cons_app(
- vpp_plugin_binary_api_t* api, hicn_consumer_input_params* input_params,
+int hicn_vapi_register_cons_app(
+ vapi_ctx_t ctx, hicn_consumer_input_params* input_params,
hicn_consumer_output_params* output_params);
-int hicn_binary_api_register_route(
- vpp_plugin_binary_api_t* api, hicn_producer_set_route_params* input_params);
+int hicn_vapi_register_route(
+ vapi_ctx_t ctx, hicn_producer_set_route_params* input_params);
-int hicn_binary_api_face_cons_del(
- vpp_plugin_binary_api_t *api, hicn_del_face_app_input_params *input_params);
+int hicn_vapi_face_cons_del(
+ vapi_ctx_t ctx, hicn_del_face_app_input_params *input_params);
-int hicn_binary_api_face_prod_del(
- vpp_plugin_binary_api_t *api, hicn_del_face_app_input_params *input_params);
+int hicn_vapi_face_prod_del(
+ vapi_ctx_t ctx, hicn_del_face_app_input_params *input_params);
-char* hicn_binary_api_get_error_string(int ret_val);
+char* hicn_vapi_get_error_string(int ret_val);
#ifdef __cplusplus
}
diff --git a/libtransport/src/hicn/transport/core/memif_binary_api.c b/libtransport/src/hicn/transport/core/memif_binary_api.c
deleted file mode 100644
index 834c8db13..000000000
--- a/libtransport/src/hicn/transport/core/memif_binary_api.c
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hicn/transport/config.h>
-
-#ifdef __vpp__
-
-#include <hicn/transport/core/memif_binary_api.h>
-#include <hicn/transport/core/vpp_binary_api_internal.h>
-#include <hicn/transport/utils/log.h>
-
-#include <fcntl.h>
-#include <inttypes.h>
-#include <semaphore.h>
-#include <string.h>
-#include <sys/stat.h>
-
-#include <vlibapi/api.h>
-#include <vlibmemory/api.h>
-
-// uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
-
-/* Declare message IDs */
-#include <memif/memif_msg_enum.h>
-
-#define vl_msg_name_crc_list
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_msg_name_crc_list
-
-#define vl_typedefs
-#define vl_endianfun
-#define vl_print(handle, ...)
-#define vl_printfun
-#define vl_api_version(n, v) static u32 api_version = (v);
-#define vl_msg_name_crc_list
-#include <memif/memif_all_api_h.h>
-#undef vl_msg_name_crc_list
-#undef vl_api_version
-#undef vl_printfun
-#undef vl_endianfun
-#undef vl_typedefs
-
-/* define message structures */
-#define vl_typedefs
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_typedefs
-
-static context_store_t context_store = {
- .global_pointers_map_index = 0,
-};
-
-/*
- * Table of message reply handlers, must include boilerplate handlers
- * we just generated
- */
-#define foreach_memif_api_reply_msg \
- _(MEMIF_CREATE_REPLY, memif_create_reply) \
- _(MEMIF_DELETE_REPLY, memif_delete_reply) \
- _(MEMIF_DETAILS, memif_details)
-
-int memif_binary_api_get_next_memif_id(vpp_plugin_binary_api_t *api,
- uint32_t *memif_id) {
- // Dump all the memif interfaces and return the next to the largest memif id
- vl_api_memif_dump_t *mp;
- vpp_plugin_binary_api_t *hm = api;
-
- M(MEMIF_DUMP, mp);
- uint32_t *user_param = malloc(sizeof(uint32_t));
- *user_param = 0;
- vpp_binary_api_set_user_param(api->vpp_api, user_param);
-
- CONTEXT_SAVE(context_store, api, mp);
-
- vpp_binary_api_send_request(api->vpp_api, mp);
-
- vpp_binary_api_send_receive_ping(api->vpp_api);
-
- user_param = vpp_binary_api_get_user_param(api->vpp_api);
- *memif_id = *(uint32_t *)(user_param);
- free(user_param);
-
- return vpp_binary_api_get_ret_value(api->vpp_api);
-}
-
-static void vl_api_memif_details_t_handler(vl_api_memif_details_t *mp) {
- vpp_plugin_binary_api_t *binary_api;
- CONTEXT_GET(context_store, mp, binary_api);
- uint32_t *last_memif_id = vpp_binary_api_get_user_param(binary_api->vpp_api);
- uint32_t current_memif_id = clib_net_to_host_u32(mp->id);
- if (current_memif_id >= *last_memif_id) {
- *last_memif_id = current_memif_id + 1;
- }
-}
-
-int memif_binary_api_create_memif(vpp_plugin_binary_api_t *api,
- memif_create_params_t *input_params,
- memif_output_params_t *output_params) {
- vl_api_memif_create_t *mp;
- vpp_plugin_binary_api_t *hm = api;
-
- if (input_params->socket_id == ~0) {
- // invalid socket-id
- return -1;
- }
-
- if (!is_pow2(input_params->ring_size)) {
- // ring size must be power of 2
- return -1;
- }
-
- if (input_params->rx_queues > 255 || input_params->rx_queues < 1) {
- // rx queue must be between 1 - 255
- return -1;
- }
-
- if (input_params->tx_queues > 255 || input_params->tx_queues < 1) {
- // tx queue must be between 1 - 255
- return -1;
- }
-
- vpp_binary_api_set_user_param(api->vpp_api, output_params);
-
- /* Construct the API message */
- M(MEMIF_CREATE, mp);
-
- CONTEXT_SAVE(context_store, api, mp)
-
- mp->role = input_params->role;
- mp->mode = input_params->mode;
- mp->rx_queues = input_params->rx_queues;
- mp->tx_queues = input_params->tx_queues;
- mp->id = clib_host_to_net_u32(input_params->id);
- mp->socket_id = clib_host_to_net_u32(input_params->socket_id);
- mp->ring_size = clib_host_to_net_u32(input_params->ring_size);
- mp->buffer_size = clib_host_to_net_u16(input_params->buffer_size);
-
- int ret = vpp_binary_api_send_request_wait_reply(api->vpp_api, mp);
- if (ret < 0) {
- return ret;
- }
-
- return vpp_binary_api_set_int_state(api->vpp_api, output_params->sw_if_index,
- UP);
-}
-int memif_binary_api_delete_memif(vpp_plugin_binary_api_t *api,
- uint32_t sw_if_index) {
- vl_api_memif_delete_t *mp;
- vpp_plugin_binary_api_t *hm = api;
-
- /* Construct the API message */
- M(MEMIF_DELETE, mp);
-
- CONTEXT_SAVE(context_store, api, mp)
-
- mp->sw_if_index = htonl(sw_if_index);
-
- return vpp_binary_api_send_request_wait_reply(api->vpp_api, mp);
-}
-
-static void vl_api_memif_create_reply_t_handler(
- vl_api_memif_create_reply_t *mp) {
- vpp_plugin_binary_api_t *binary_api;
- CONTEXT_GET(context_store, mp, binary_api);
- memif_output_params_t *params =
- vpp_binary_api_get_user_param(binary_api->vpp_api);
-
- vpp_binary_api_set_ret_value(binary_api->vpp_api,
- clib_net_to_host_u32(mp->retval));
- params->sw_if_index = clib_net_to_host_u32(mp->sw_if_index);
-
- vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api);
-}
-
-static void vl_api_memif_delete_reply_t_handler(
- vl_api_memif_delete_reply_t *mp) {
- vpp_plugin_binary_api_t *binary_api;
- CONTEXT_GET(context_store, mp, binary_api);
-
- vpp_binary_api_set_ret_value(binary_api->vpp_api,
- clib_net_to_host_u32(mp->retval));
-
- vpp_binary_api_unlock_waiting_thread(binary_api->vpp_api);
-}
-
-static int memif_binary_api_setup_handlers(
- vpp_plugin_binary_api_t *binary_api) {
- vpp_plugin_binary_api_t *sm __attribute__((unused)) = binary_api;
-#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_memif_api_reply_msg;
-#undef _
- return 0;
-}
-
-vpp_plugin_binary_api_t *memif_binary_api_init(vpp_binary_api_t *api) {
- vpp_plugin_binary_api_t *ret = malloc(sizeof(vpp_plugin_binary_api_t));
- u8 *name = format(0, "memif_%08x%c", api_version, 0);
- ret->msg_id_base = vl_client_get_first_plugin_msg_id((char *)name);
- ret->vpp_api = api;
- ret->my_client_index = vpp_binary_api_get_client_index(api);
- memif_binary_api_setup_handlers(ret);
- return ret;
-}
-
-#endif // __vpp__ \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/core/memif_connector.h b/libtransport/src/hicn/transport/core/memif_connector.h
index 4f43c97ef..bf4e2d56c 100644
--- a/libtransport/src/hicn/transport/core/memif_connector.h
+++ b/libtransport/src/hicn/transport/core/memif_connector.h
@@ -17,7 +17,7 @@
#include <hicn/transport/config.h>
#include <hicn/transport/core/connector.h>
-#include <hicn/transport/core/hicn_binary_api.h>
+//#include <hicn/transport/core/hicn_vapi.h>
#include <hicn/transport/portability/portability.h>
#include <hicn/transport/utils/epoll_event_reactor.h>
#include <hicn/transport/utils/fd_deadline_timer.h>
diff --git a/libtransport/src/hicn/transport/core/memif_vapi.c b/libtransport/src/hicn/transport/core/memif_vapi.c
new file mode 100644
index 000000000..b0bf77e40
--- /dev/null
+++ b/libtransport/src/hicn/transport/core/memif_vapi.c
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <hicn/transport/config.h>
+
+#ifdef __vpp__
+
+#include <vppinfra/clib.h>
+#include <hicn/transport/core/memif_vapi.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <semaphore.h>
+#include <string.h>
+#include <sys/stat.h>
+
+DEFINE_VAPI_MSG_IDS_MEMIF_API_JSON
+
+static vapi_error_e memif_details_cb(vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_memif_details *reply) {
+ uint32_t *last_memif_id = (uint32_t *)callback_ctx;
+ uint32_t current_memif_id = 0;
+ if (reply != NULL) {
+ current_memif_id = reply->id;
+ }
+ else {
+ return rv;
+ }
+
+ if (current_memif_id >= *last_memif_id) {
+ *last_memif_id = current_memif_id + 1;
+ }
+
+ return rv;
+}
+
+int memif_vapi_get_next_memif_id(vapi_ctx_t ctx,
+ uint32_t *memif_id) {
+
+ vapi_msg_memif_dump * msg = vapi_alloc_memif_dump(ctx);
+ return vapi_memif_dump(ctx, msg, memif_details_cb, memif_id);
+}
+
+static vapi_error_e memif_create_cb(vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_memif_create_reply *reply) {
+ memif_output_params_t *output_params = (memif_output_params_t *)callback_ctx;
+
+ if (reply == NULL)
+ return rv;
+
+ output_params->sw_if_index = reply->sw_if_index;
+
+ return rv;
+}
+
+int memif_vapi_create_memif(vapi_ctx_t ctx,
+ memif_create_params_t *input_params,
+ memif_output_params_t *output_params) {
+ vapi_msg_memif_create * msg = vapi_alloc_memif_create(ctx);
+
+ if (input_params->socket_id == ~0) {
+ // invalid socket-id
+ return -1;
+ }
+
+ if (!is_pow2(input_params->ring_size)) {
+ // ring size must be power of 2
+ return -1;
+ }
+
+ if (input_params->rx_queues > 255 || input_params->rx_queues < 1) {
+ // rx queue must be between 1 - 255
+ return -1;
+ }
+
+ if (input_params->tx_queues > 255 || input_params->tx_queues < 1) {
+ // tx queue must be between 1 - 255
+ return -1;
+ }
+
+ msg->payload.role = input_params->role;
+ msg->payload.mode = input_params->mode;
+ msg->payload.rx_queues = input_params->rx_queues;
+ msg->payload.tx_queues = input_params->tx_queues;
+ msg->payload.id = input_params->id;
+ msg->payload.socket_id = input_params->socket_id;
+ msg->payload.ring_size = input_params->ring_size;
+ msg->payload.buffer_size = input_params->buffer_size;
+
+ return vapi_memif_create(ctx, msg, memif_create_cb, output_params);
+
+}
+
+static vapi_error_e memif_delete_cb(vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_memif_delete_reply *reply) {
+ if(reply == NULL)
+ return rv;
+
+ return reply->retval;
+}
+
+int memif_vapi_delete_memif(vapi_ctx_t ctx,
+ uint32_t sw_if_index) {
+ vapi_msg_memif_delete * msg = vapi_alloc_memif_delete(ctx);
+
+ msg->payload.sw_if_index = sw_if_index;
+
+ return vapi_memif_delete(ctx, msg, memif_delete_cb, NULL);
+}
+
+#endif // __vpp__ \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/core/memif_binary_api.h b/libtransport/src/hicn/transport/core/memif_vapi.h
index b950292b9..c045cf093 100644
--- a/libtransport/src/hicn/transport/core/memif_binary_api.h
+++ b/libtransport/src/hicn/transport/core/memif_vapi.h
@@ -16,7 +16,6 @@
#pragma once
#include <hicn/transport/config.h>
-#include <hicn/transport/core/vpp_binary_api.h>
#ifdef __vpp__
@@ -24,6 +23,7 @@
extern "C" {
#endif
+#include <vapi/memif.api.vapi.h>
#include "stdint.h"
typedef struct memif_create_params_s {
@@ -43,16 +43,14 @@ typedef struct memif_output_params_s {
uint32_t sw_if_index;
} memif_output_params_t;
-vpp_plugin_binary_api_t *memif_binary_api_init(vpp_binary_api_t *api);
-
-int memif_binary_api_get_next_memif_id(vpp_plugin_binary_api_t *api,
+int memif_vapi_get_next_memif_id(vapi_ctx_t ctx,
uint32_t *memif_id);
-int memif_binary_api_create_memif(vpp_plugin_binary_api_t *api,
+int memif_vapi_create_memif(vapi_ctx_t ctx,
memif_create_params_t *input_params,
memif_output_params_t *output_params);
-int memif_binary_api_delete_memif(vpp_plugin_binary_api_t *api,
+int memif_vapi_delete_memif(vapi_ctx_t ctx,
uint32_t sw_if_index);
#ifdef __cplusplus
diff --git a/libtransport/src/hicn/transport/core/vpp_binary_api.c b/libtransport/src/hicn/transport/core/vpp_binary_api.c
deleted file mode 100644
index d54ef257e..000000000
--- a/libtransport/src/hicn/transport/core/vpp_binary_api.c
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hicn/transport/config.h>
-
-#ifdef __vpp__
-
-#include <hicn/transport/core/vpp_binary_api.h>
-#include <hicn/transport/core/vpp_binary_api_internal.h>
-#include <hicn/transport/utils/log.h>
-
-#include <vat/vat.h>
-#include <vlibapi/api.h>
-#include <vlibmemory/api.h>
-
-#include <vnet/ip/ip.h>
-#include <vppinfra/error.h>
-
-#include <fcntl.h>
-#include <inttypes.h>
-#include <string.h>
-#include <sys/stat.h>
-
-#include <vpp/api/vpe_msg_enum.h>
-
-#define vl_typedefs
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_typedefs
-
-#define vl_endianfun
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_endianfun
-
-#define vl_print(handle, ...)
-#define vl_printfun
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_printfun
-
-/* Get CRC codes of the messages */
-#define vl_msg_name_crc_list
-#include <vpp/api/vpe_all_api_h.h>
-#undef vl_msg_name_crc_list
-
-#include <semaphore.h>
-
-struct vpp_binary_api {
- api_main_t *api_main;
- u32 my_client_index;
- unix_shared_memory_queue_t *vl_input_queue;
- vlib_main_t *vlib_main;
- sem_t *semaphore;
- u32 ping_id;
- int ret_val;
- void *user_param;
-};
-
-static context_store_t context_store = {
- .global_pointers_map_index = 0,
-};
-
-/*
- * Table of message reply handlers, must include boilerplate handlers
- * we just generated
- */
-#define foreach_memif_api_reply_msg \
- _(MEMIF_CREATE_REPLY, memif_create_reply) \
- _(MEMIF_DELETE_REPLY, memif_delete_reply) \
- _(MEMIF_DETAILS, memif_details)
-
-/**
- * @brief Generic VPP request structure.
- */
-typedef struct __attribute__((packed)) vl_generic_request_s {
- u16 _vl_msg_id;
- u32 client_index;
- u32 context;
-} vl_generic_request_t;
-
-/**
- * @brief Generic VPP reply structure (response with a single message).
- */
-typedef struct __attribute__((packed)) vl_generic_reply_s {
- u16 _vl_msg_id;
- u32 context;
- i32 retval;
-} vl_generic_reply_t;
-
-static void vl_api_control_ping_reply_t_handler(
- vl_api_control_ping_reply_t *mp) {
- // Just unblock main thread
- vpp_binary_api_t *binary_api;
- CONTEXT_GET(context_store, mp, binary_api);
- binary_api->ret_val = ntohl(mp->retval);
- vpp_binary_api_unlock_waiting_thread(binary_api);
-}
-
-static void vl_api_sw_interface_set_flags_reply_t_handler(
- vl_api_control_ping_reply_t *mp) {
- // Unblock main thread setting reply message status code
- vpp_binary_api_t *binary_api;
- CONTEXT_GET(context_store, mp, binary_api);
- binary_api->ret_val = ntohl(mp->retval);
- vpp_binary_api_unlock_waiting_thread(binary_api);
-}
-
-static int vpp_connect_to_vlib(vpp_binary_api_t *binary_api, char *name) {
- clib_mem_init_thread_safe(0, 256 << 20);
- if (vl_client_connect_to_vlib("/vpe-api", name, 32) < 0) {
- return -1;
- }
-
- binary_api->vl_input_queue = binary_api->api_main->shmem_hdr->vl_input_queue;
- binary_api->my_client_index = binary_api->api_main->my_client_index;
-
- return 0;
-}
-
-vpp_binary_api_t *vpp_binary_api_init(const char *app_name) {
- vpp_binary_api_t *ret = malloc(sizeof(vpp_binary_api_t));
- ret->api_main = &api_main;
- ret->vlib_main = &vlib_global_main;
-
- vpp_connect_to_vlib(ret, (char *)app_name);
- ret->semaphore = sem_open(app_name, O_CREAT, 0, 0);
-
- return ret;
-}
-
-void vpp_binary_api_destroy(vpp_binary_api_t *api) {
- sem_close(api->semaphore);
- free(api);
- vl_client_disconnect_from_vlib();
-}
-
-void vpp_binary_api_unlock_waiting_thread(vpp_binary_api_t *api) {
- sem_post(api->semaphore);
-}
-
-void vpp_binary_api_send_receive_ping(vpp_binary_api_t *api) {
- /* Use a control ping for synchronization */
-
- /* Get the control ping ID */
-#define _(id, n, crc) \
- const char *id##_CRC __attribute__((unused)) = #n "_" #crc;
- foreach_vl_msg_name_crc_vpe;
-#undef _
-
- int ping_reply_id =
- vl_msg_api_get_msg_index((u8 *)(VL_API_CONTROL_PING_REPLY_CRC));
- vl_msg_api_set_handlers(ping_reply_id, "control_ping_reply",
- vl_api_control_ping_reply_t_handler, vl_noop_handler,
- vl_api_control_ping_reply_t_endian,
- vl_api_control_ping_reply_t_print,
- sizeof(vl_api_control_ping_reply_t), 1);
-
- vl_api_control_ping_t *mp_ping;
- mp_ping = vl_msg_api_alloc_as_if_client(sizeof(*mp_ping));
- mp_ping->_vl_msg_id = clib_host_to_net_u16(
- vl_msg_api_get_msg_index((u8 *)(VL_API_CONTROL_PING_CRC)));
- mp_ping->client_index = api->my_client_index;
-
- CONTEXT_SAVE(context_store, api, mp_ping);
-
- TRANSPORT_LOGD("Sending ping id %u", mp_ping->_vl_msg_id);
-
- vpp_binary_api_send_request_wait_reply(api, mp_ping);
-}
-
-int vpp_binary_api_set_int_state(vpp_binary_api_t *api, uint32_t sw_index,
- link_state_t state) {
-#define _(id, n, crc) \
- const char *id##_CRC __attribute__((unused)) = #n "_" #crc;
- foreach_vl_msg_name_crc_vpe;
-#undef _
-
- int sw_interface_set_flags_reply_id = VL_API_SW_INTERFACE_SET_FLAGS_REPLY;
- vl_msg_api_set_handlers(
- sw_interface_set_flags_reply_id, "sw_interface_set_flags_reply",
- vl_api_sw_interface_set_flags_reply_t_handler, vl_noop_handler,
- vl_api_sw_interface_set_flags_reply_t_endian,
- vl_api_sw_interface_set_flags_reply_t_print,
- sizeof(vl_api_sw_interface_set_flags_reply_t), 1);
-
- vl_api_sw_interface_set_flags_t *mp;
- mp = vl_msg_api_alloc_as_if_client(sizeof(*mp));
- mp->_vl_msg_id = clib_host_to_net_u16(VL_API_SW_INTERFACE_SET_FLAGS);
- mp->client_index = api->my_client_index;
- mp->sw_if_index = clib_host_to_net_u32(sw_index);
- mp->admin_up_down = (u8)state;
-
- CONTEXT_SAVE(context_store, api, mp);
-
- TRANSPORT_LOGD("Sending set int flags id %u", mp->_vl_msg_id);
-
- return vpp_binary_api_send_request_wait_reply(api, mp);
-}
-
-void vpp_binary_api_send_request(vpp_binary_api_t *api, void *request) {
- vl_generic_request_t *req = NULL;
-
- req = (vl_generic_request_t *)request;
- TRANSPORT_LOGD("Sending a request to VPP (id=%d).\n", ntohs(req->_vl_msg_id));
-
- S(api, req);
-}
-
-int vpp_binary_api_get_ret_value(vpp_binary_api_t *api) { return api->ret_val; }
-
-void vpp_binary_api_set_ret_value(vpp_binary_api_t *api, int ret_val) {
- api->ret_val = ret_val;
-}
-
-void *vpp_binary_api_get_user_param(vpp_binary_api_t *api) {
- return api->user_param;
-}
-
-void vpp_binary_api_set_user_param(vpp_binary_api_t *api, void *user_param) {
- api->user_param = user_param;
-}
-
-uint32_t vpp_binary_api_get_client_index(vpp_binary_api_t *api) {
- return api->my_client_index;
-}
-
-void vpp_binary_api_set_client_index(vpp_binary_api_t *api,
- uint32_t client_index) {
- api->my_client_index = client_index;
-}
-
-int vpp_binary_api_send_request_wait_reply(vpp_binary_api_t *api,
- void *request) {
- vpp_binary_api_send_request(api, request);
-
- sem_wait(api->semaphore);
-
- return api->ret_val;
-}
-
-#endif // __vpp__ \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/core/vpp_binary_api.h b/libtransport/src/hicn/transport/core/vpp_binary_api.h
deleted file mode 100644
index 932a59ec2..000000000
--- a/libtransport/src/hicn/transport/core/vpp_binary_api.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <hicn/transport/config.h>
-
-#ifdef __vpp__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdint.h>
-#include <stdlib.h>
-
-typedef struct vpp_binary_api vpp_binary_api_t;
-typedef struct vpp_plugin_binary_api vpp_plugin_binary_api_t;
-
-typedef enum link_state_s { UP = 1, DOWN = 0 } link_state_t;
-
-/**
- * @brief Instantiate a new vpp_binary_api_t data structure and
- * connect the application to the local VPP forwarder.
- */
-vpp_binary_api_t *vpp_binary_api_init(const char *app_name);
-
-/**
- * @brief Destroy the vpp_binary_api_t and disconnect from VPP.
- */
-void vpp_binary_api_destroy(vpp_binary_api_t *api);
-
-void vpp_binary_api_send_receive_ping(vpp_binary_api_t *api);
-
-int vpp_binary_api_set_int_state(vpp_binary_api_t *api, uint32_t sw_index,
- link_state_t state);
-
-/**
- * @brief Send request to VPP and wait for reply.
- */
-int vpp_binary_api_send_request_wait_reply(vpp_binary_api_t *api,
- void *request);
-
-void vpp_binary_api_unlock_waiting_thread(vpp_binary_api_t *api);
-
-void vpp_binary_api_send_request(vpp_binary_api_t *api, void *request);
-
-int vpp_binary_api_get_ret_value(vpp_binary_api_t *api);
-
-void vpp_binary_api_set_ret_value(vpp_binary_api_t *api, int ret_val);
-
-void *vpp_binary_api_get_user_param(vpp_binary_api_t *api);
-
-void vpp_binary_api_set_user_param(vpp_binary_api_t *api, void *user_param);
-
-uint32_t vpp_binary_api_get_client_index(vpp_binary_api_t *api);
-
-void vpp_binary_api_set_client_index(vpp_binary_api_t *api,
- uint32_t client_index);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // __vpp__ \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/core/vpp_binary_api_internal.h b/libtransport/src/hicn/transport/core/vpp_binary_api_internal.h
deleted file mode 100644
index a6e2c01a3..000000000
--- a/libtransport/src/hicn/transport/core/vpp_binary_api_internal.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <hicn/transport/config.h>
-
-#ifdef __vpp__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <semaphore.h>
-#include <vlibapi/api.h>
-#include <vlibmemory/api.h>
-
-#include <stdint.h>
-
-typedef struct vpp_binary_api vpp_binary_api_t;
-
-struct vpp_plugin_binary_api {
- vpp_binary_api_t *vpp_api;
- u16 msg_id_base;
- u32 my_client_index;
-};
-
-#define POINTER_MAP_SIZE 32
-typedef struct {
- void *global_pointers_map[POINTER_MAP_SIZE];
- uint8_t global_pointers_map_index;
-} context_store_t;
-
-#define CONTEXT_SAVE(context_store, pointer, mp) \
- do { \
- context_store \
- .global_pointers_map[context_store.global_pointers_map_index] = \
- pointer; \
- mp->context = context_store.global_pointers_map_index++; \
- context_store.global_pointers_map_index %= POINTER_MAP_SIZE; \
- } while (0);
-
-#define CONTEXT_GET(context_store, mp, pointer) \
- do { \
- pointer = context_store.global_pointers_map[mp->context]; \
- } while (0);
-
-#define M(T, mp) \
- do { \
- mp = vl_msg_api_alloc_as_if_client(sizeof(*mp)); \
- memset(mp, 0, sizeof(*mp)); \
- mp->_vl_msg_id = ntohs(VL_API_##T + hm->msg_id_base); \
- mp->client_index = hm->my_client_index; \
- } while (0);
-
-#define S(api, mp) (vl_msg_api_send_shmem(api->vl_input_queue, (u8 *)&mp))
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // __vpp__ \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc
index 45a37d551..976d25a2f 100644
--- a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc
+++ b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc
@@ -17,8 +17,8 @@
#ifdef __vpp__
-#include <hicn/transport/core/hicn_binary_api.h>
-#include <hicn/transport/core/memif_binary_api.h>
+#include <hicn/transport/core/hicn_vapi.h>
+#include <hicn/transport/core/memif_vapi.h>
#include <hicn/transport/core/prefix.h>
#include <hicn/transport/core/vpp_forwarder_interface.h>
@@ -37,9 +37,6 @@ namespace transport {
namespace core {
-vpp_binary_api_t *VPPForwarderInterface::api_ = nullptr;
-vpp_plugin_binary_api_t *VPPForwarderInterface::memif_api_ = nullptr;
-vpp_plugin_binary_api_t *VPPForwarderInterface::hicn_api_ = nullptr;
std::mutex VPPForwarderInterface::global_lock_;
VPPForwarderInterface::VPPForwarderInterface(MemifConnector &connector)
@@ -47,7 +44,9 @@ VPPForwarderInterface::VPPForwarderInterface(MemifConnector &connector)
sw_if_index_(~0),
face_id1_(~0),
face_id2_(~0),
- is_consumer_(false) {}
+ is_consumer_(false){
+ sock_ = hc_sock_create();
+ }
VPPForwarderInterface::~VPPForwarderInterface() {}
@@ -57,8 +56,8 @@ VPPForwarderInterface::~VPPForwarderInterface() {}
uint32_t VPPForwarderInterface::getMemifConfiguration() {
memif_create_params_t input_params = {0};
- int ret = memif_binary_api_get_next_memif_id(
- VPPForwarderInterface::memif_api_, &memif_id_);
+ int ret = memif_vapi_get_next_memif_id(
+ *(vapi_ctx_t *)VPPForwarderInterface::sock_, &memif_id_);
if (ret < 0) {
throw errors::RuntimeException(
@@ -75,7 +74,7 @@ uint32_t VPPForwarderInterface::getMemifConfiguration() {
memif_output_params_t output_params = {0};
- ret = memif_binary_api_create_memif(VPPForwarderInterface::memif_api_,
+ ret = memif_vapi_create_memif(*(vapi_ctx_t *)VPPForwarderInterface::sock_,
&input_params, &output_params);
if (ret < 0) {
@@ -96,11 +95,13 @@ void VPPForwarderInterface::consumerConnection() {
output.src6 = &ip6_address;
input.swif = sw_if_index_;
- int ret = hicn_binary_api_register_cons_app(VPPForwarderInterface::hicn_api_,
+
+
+ int ret = hicn_vapi_register_cons_app(*(vapi_ctx_t *)VPPForwarderInterface::sock_,
&input, &output);
if (ret < 0) {
- throw errors::RuntimeException(hicn_binary_api_get_error_string(ret));
+ throw errors::RuntimeException(hicn_vapi_get_error_string(ret));
}
face_id1_ = output.face_id1;
@@ -119,18 +120,7 @@ void VPPForwarderInterface::producerConnection() {
void VPPForwarderInterface::connect(bool is_consumer) {
std::lock_guard<std::mutex> connection_lock(global_lock_);
- srand(time(nullptr));
- int secret = rand() % (1 << 10);
- std::stringstream app_name;
- app_name << "Libtransport_" << secret;
-
- if (!VPPForwarderInterface::memif_api_) {
- VPPForwarderInterface::api_ = vpp_binary_api_init(app_name.str().c_str());
- VPPForwarderInterface::memif_api_ =
- memif_binary_api_init(VPPForwarderInterface::api_);
- VPPForwarderInterface::hicn_api_ =
- hicn_binary_api_init(VPPForwarderInterface::api_);
- }
+ hc_sock_connect(sock_);
sw_if_index_ = getMemifConfiguration();
@@ -167,11 +157,11 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) {
input.prefix->len = addr.len;
input.cs_reserved = content_store_reserved_;
- int ret = hicn_binary_api_register_prod_app(
- VPPForwarderInterface::hicn_api_, &input, &output);
+ int ret = hicn_vapi_register_prod_app(
+ *(vapi_ctx_t *)VPPForwarderInterface::sock_, &input, &output);
if (ret < 0) {
- throw errors::RuntimeException(hicn_binary_api_get_error_string(ret));
+ throw errors::RuntimeException(hicn_vapi_get_error_string(ret));
}
inet6_address_ = *output.prod_addr;
@@ -185,42 +175,42 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) {
params.prefix->len = addr.len;
params.face_id = face_id1_;
- int ret = hicn_binary_api_register_route(VPPForwarderInterface::hicn_api_,
+ int ret = hicn_vapi_register_route(*(vapi_ctx_t *)VPPForwarderInterface::sock_,
&params);
if (ret < 0) {
- throw errors::RuntimeException(hicn_binary_api_get_error_string(ret));
+ throw errors::RuntimeException(hicn_vapi_get_error_string(ret));
}
}
}
void VPPForwarderInterface::closeConnection() {
- if (VPPForwarderInterface::api_) {
+ if (VPPForwarderInterface::sock_) {
connector_.close();
if (is_consumer_) {
hicn_del_face_app_input_params params;
params.face_id = face_id1_;
- hicn_binary_api_face_cons_del(VPPForwarderInterface::hicn_api_, &params);
+ hicn_vapi_face_cons_del(*(vapi_ctx_t *)VPPForwarderInterface::sock_, &params);
params.face_id = face_id2_;
- hicn_binary_api_face_cons_del(VPPForwarderInterface::hicn_api_, &params);
+ hicn_vapi_face_cons_del(*(vapi_ctx_t *)VPPForwarderInterface::sock_, &params);
}
else {
hicn_del_face_app_input_params params;
params.face_id = face_id1_;
- hicn_binary_api_face_prod_del(VPPForwarderInterface::hicn_api_, &params);
+ hicn_vapi_face_prod_del(*(vapi_ctx_t *)VPPForwarderInterface::sock_, &params);
}
if (sw_if_index_ != uint32_t(~0)) {
- int ret = memif_binary_api_delete_memif(VPPForwarderInterface::memif_api_,
+ int ret = memif_vapi_delete_memif(*(vapi_ctx_t *)VPPForwarderInterface::sock_,
sw_if_index_);
if (ret < 0) {
TRANSPORT_LOGE("Error deleting memif with sw idx %u.", sw_if_index_);
}
}
- vpp_binary_api_destroy(VPPForwarderInterface::api_);
- VPPForwarderInterface::api_ = nullptr;
+ hc_sock_free(sock_);
+ VPPForwarderInterface::sock_ = nullptr;
}
}
diff --git a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.h b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.h
index b1cb4b9b3..b9fd44dbe 100644
--- a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.h
+++ b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.h
@@ -17,6 +17,10 @@
#include <hicn/transport/config.h>
+extern "C" {
+#include <hicn/ctrl.h>
+}
+
#ifdef __vpp__
#include <hicn/transport/core/forwarder_interface.h>
@@ -63,15 +67,13 @@ class VPPForwarderInterface
void producerConnection();
- static vpp_binary_api_t *api_;
- static vpp_plugin_binary_api_t *memif_api_;
- static vpp_plugin_binary_api_t *hicn_api_;
uint32_t memif_id_;
uint32_t sw_if_index_;
//A consumer socket in vpp has two faces (ipv4 and ipv6)
uint32_t face_id1_;
uint32_t face_id2_;
bool is_consumer_;
+ hc_sock_t *sock_;
static std::mutex global_lock_;
};