summaryrefslogtreecommitdiffstats
path: root/libtransport/src
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/src')
-rw-r--r--libtransport/src/hicn/transport/core/hicn_vapi.c36
-rw-r--r--libtransport/src/hicn/transport/core/memif_vapi.c34
-rw-r--r--libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc23
-rw-r--r--libtransport/src/hicn/transport/core/vpp_forwarder_interface.h13
4 files changed, 70 insertions, 36 deletions
diff --git a/libtransport/src/hicn/transport/core/hicn_vapi.c b/libtransport/src/hicn/transport/core/hicn_vapi.c
index cca5a552a..9cb96231a 100644
--- a/libtransport/src/hicn/transport/core/hicn_vapi.c
+++ b/libtransport/src/hicn/transport/core/hicn_vapi.c
@@ -24,6 +24,7 @@
#include <hicn/name.h>
#undef HICN_VPP_PLUGIN
+#include <vapi/vapi_safe.h>
#include <vlib/vlib.h>
#include <vlibapi/api.h>
#include <vlibmemory/api.h>
@@ -93,7 +94,8 @@ static vapi_error_e register_prod_app_cb(vapi_ctx_t ctx,
int hicn_vapi_register_prod_app(
vapi_ctx_t ctx, hicn_producer_input_params *input_params,
hicn_producer_output_params *output_params) {
-
+
+ vapi_lock();
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)) {
@@ -108,7 +110,9 @@ int hicn_vapi_register_prod_app(
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);
+ int ret = vapi_hicn_api_register_prod_app(ctx, msg, register_prod_app_cb, output_params);
+ vapi_unlock();
+ return ret;
}
static vapi_error_e face_prod_del_cb(vapi_ctx_t ctx,
@@ -124,12 +128,16 @@ static vapi_error_e face_prod_del_cb(vapi_ctx_t ctx,
int hicn_vapi_face_prod_del(
vapi_ctx_t ctx, hicn_del_face_app_input_params *input_params) {
-
+ vapi_lock();
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);
+ printf("Deleting producer face %d\n", msg->payload.faceid);
+ int ret = vapi_hicn_api_face_prod_del(ctx, msg, face_prod_del_cb, NULL);
+ printf("DONE Deleting producer face %d\n", input_params->face_id);
+ vapi_unlock();
+ return ret;
}
static vapi_error_e register_cons_app_cb(vapi_ctx_t ctx,
@@ -159,11 +167,14 @@ int hicn_vapi_register_cons_app(
vapi_ctx_t ctx, hicn_consumer_input_params *input_params,
hicn_consumer_output_params *output_params) {
+ vapi_lock();
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);
+ int ret = vapi_hicn_api_register_cons_app(ctx, msg, register_cons_app_cb, output_params);
+ vapi_unlock();
+ return ret;
}
static vapi_error_e face_cons_del_cb(vapi_ctx_t ctx,
@@ -179,12 +190,15 @@ static vapi_error_e face_cons_del_cb(vapi_ctx_t ctx,
int hicn_vapi_face_cons_del(
vapi_ctx_t ctx, hicn_del_face_app_input_params *input_params) {
-
+
+ vapi_lock();
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);
+ int ret = vapi_hicn_api_face_cons_del(ctx, msg, face_cons_del_cb, NULL);
+ vapi_unlock();
+ return ret;
}
static vapi_error_e reigster_route_cb(vapi_ctx_t ctx,
@@ -201,7 +215,8 @@ static vapi_error_e reigster_route_cb(vapi_ctx_t ctx,
int hicn_vapi_register_route(
vapi_ctx_t ctx,
hicn_producer_set_route_params *input_params) {
-
+
+ vapi_lock();
vapi_msg_hicn_api_route_nhops_add * msg = vapi_alloc_hicn_api_route_nhops_add(ctx);
fib_prefix_t prefix;
@@ -210,7 +225,10 @@ int hicn_vapi_register_route(
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);
+ int ret = vapi_hicn_api_route_nhops_add(ctx, msg, reigster_route_cb, NULL);
+
+ vapi_unlock();
+ return ret;
}
char *hicn_vapi_get_error_string(int ret_val) {
diff --git a/libtransport/src/hicn/transport/core/memif_vapi.c b/libtransport/src/hicn/transport/core/memif_vapi.c
index b0bf77e40..11cf42441 100644
--- a/libtransport/src/hicn/transport/core/memif_vapi.c
+++ b/libtransport/src/hicn/transport/core/memif_vapi.c
@@ -16,6 +16,7 @@
#ifdef __vpp__
+#include <vapi/vapi_safe.h>
#include <vppinfra/clib.h>
#include <hicn/transport/core/memif_vapi.h>
#include <fcntl.h>
@@ -49,9 +50,11 @@ static vapi_error_e memif_details_cb(vapi_ctx_t ctx,
int memif_vapi_get_next_memif_id(vapi_ctx_t ctx,
uint32_t *memif_id) {
-
+ vapi_lock();
vapi_msg_memif_dump * msg = vapi_alloc_memif_dump(ctx);
- return vapi_memif_dump(ctx, msg, memif_details_cb, memif_id);
+ int ret = vapi_memif_dump(ctx, msg, memif_details_cb, memif_id);
+ vapi_unlock();
+ return ret;
}
static vapi_error_e memif_create_cb(vapi_ctx_t ctx,
@@ -72,26 +75,32 @@ static vapi_error_e memif_create_cb(vapi_ctx_t ctx,
int memif_vapi_create_memif(vapi_ctx_t ctx,
memif_create_params_t *input_params,
memif_output_params_t *output_params) {
+ vapi_lock();
vapi_msg_memif_create * msg = vapi_alloc_memif_create(ctx);
+ int ret = 0;
if (input_params->socket_id == ~0) {
// invalid socket-id
- return -1;
+ ret = -1;
+ goto END;
}
if (!is_pow2(input_params->ring_size)) {
// ring size must be power of 2
- return -1;
+ ret = -1;
+ goto END;
}
if (input_params->rx_queues > 255 || input_params->rx_queues < 1) {
// rx queue must be between 1 - 255
- return -1;
+ ret = -1;
+ goto END;
}
if (input_params->tx_queues > 255 || input_params->tx_queues < 1) {
// tx queue must be between 1 - 255
- return -1;
+ ret = -1;
+ goto END;
}
msg->payload.role = input_params->role;
@@ -103,8 +112,10 @@ int memif_vapi_create_memif(vapi_ctx_t ctx,
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);
-
+ ret = vapi_memif_create(ctx, msg, memif_create_cb, output_params);
+ END:
+ vapi_unlock();
+ return ret;
}
static vapi_error_e memif_delete_cb(vapi_ctx_t ctx,
@@ -120,11 +131,14 @@ static vapi_error_e memif_delete_cb(vapi_ctx_t ctx,
int memif_vapi_delete_memif(vapi_ctx_t ctx,
uint32_t sw_if_index) {
+ vapi_lock();
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);
+ int ret = vapi_memif_delete(ctx, msg, memif_delete_cb, NULL);
+ vapi_unlock();
+ return ret;
}
-#endif // __vpp__ \ No newline at end of file
+#endif // __vpp__
diff --git a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc
index 976d25a2f..06672279e 100644
--- a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc
+++ b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc
@@ -45,7 +45,6 @@ VPPForwarderInterface::VPPForwarderInterface(MemifConnector &connector)
face_id1_(~0),
face_id2_(~0),
is_consumer_(false){
- sock_ = hc_sock_create();
}
VPPForwarderInterface::~VPPForwarderInterface() {}
@@ -57,7 +56,7 @@ uint32_t VPPForwarderInterface::getMemifConfiguration() {
memif_create_params_t input_params = {0};
int ret = memif_vapi_get_next_memif_id(
- *(vapi_ctx_t *)VPPForwarderInterface::sock_, &memif_id_);
+ *VPPForwarderInterface::sock_, &memif_id_);
if (ret < 0) {
throw errors::RuntimeException(
@@ -74,7 +73,7 @@ uint32_t VPPForwarderInterface::getMemifConfiguration() {
memif_output_params_t output_params = {0};
- ret = memif_vapi_create_memif(*(vapi_ctx_t *)VPPForwarderInterface::sock_,
+ ret = memif_vapi_create_memif(*VPPForwarderInterface::sock_,
&input_params, &output_params);
if (ret < 0) {
@@ -97,7 +96,7 @@ void VPPForwarderInterface::consumerConnection() {
- int ret = hicn_vapi_register_cons_app(*(vapi_ctx_t *)VPPForwarderInterface::sock_,
+ int ret = hicn_vapi_register_cons_app(*VPPForwarderInterface::sock_,
&input, &output);
if (ret < 0) {
@@ -120,7 +119,7 @@ void VPPForwarderInterface::producerConnection() {
void VPPForwarderInterface::connect(bool is_consumer) {
std::lock_guard<std::mutex> connection_lock(global_lock_);
- hc_sock_connect(sock_);
+ vapi_connect_safe(sock_, 0);
sw_if_index_ = getMemifConfiguration();
@@ -158,7 +157,7 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) {
input.cs_reserved = content_store_reserved_;
int ret = hicn_vapi_register_prod_app(
- *(vapi_ctx_t *)VPPForwarderInterface::sock_, &input, &output);
+ *VPPForwarderInterface::sock_, &input, &output);
if (ret < 0) {
throw errors::RuntimeException(hicn_vapi_get_error_string(ret));
@@ -175,7 +174,7 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) {
params.prefix->len = addr.len;
params.face_id = face_id1_;
- int ret = hicn_vapi_register_route(*(vapi_ctx_t *)VPPForwarderInterface::sock_,
+ int ret = hicn_vapi_register_route(*VPPForwarderInterface::sock_,
&params);
if (ret < 0) {
@@ -191,25 +190,25 @@ void VPPForwarderInterface::closeConnection() {
if (is_consumer_) {
hicn_del_face_app_input_params params;
params.face_id = face_id1_;
- hicn_vapi_face_cons_del(*(vapi_ctx_t *)VPPForwarderInterface::sock_, &params);
+ hicn_vapi_face_cons_del(*VPPForwarderInterface::sock_, &params);
params.face_id = face_id2_;
- hicn_vapi_face_cons_del(*(vapi_ctx_t *)VPPForwarderInterface::sock_, &params);
+ hicn_vapi_face_cons_del(*VPPForwarderInterface::sock_, &params);
}
else {
hicn_del_face_app_input_params params;
params.face_id = face_id1_;
- hicn_vapi_face_prod_del(*(vapi_ctx_t *)VPPForwarderInterface::sock_, &params);
+ hicn_vapi_face_prod_del(*VPPForwarderInterface::sock_, &params);
}
if (sw_if_index_ != uint32_t(~0)) {
- int ret = memif_vapi_delete_memif(*(vapi_ctx_t *)VPPForwarderInterface::sock_,
+ int ret = memif_vapi_delete_memif(*VPPForwarderInterface::sock_,
sw_if_index_);
if (ret < 0) {
TRANSPORT_LOGE("Error deleting memif with sw idx %u.", sw_if_index_);
}
}
- hc_sock_free(sock_);
+ vapi_disconnect_safe();
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 b9fd44dbe..da7507176 100644
--- a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.h
+++ b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.h
@@ -17,12 +17,15 @@
#include <hicn/transport/config.h>
-extern "C" {
-#include <hicn/ctrl.h>
-}
-
#ifdef __vpp__
+#ifdef always_inline
+#undef always_inline
+#endif
+extern "C" {
+#include <vapi/vapi_safe.h>
+};
+
#include <hicn/transport/core/forwarder_interface.h>
#include <hicn/transport/core/memif_connector.h>
#include <hicn/transport/core/prefix.h>
@@ -73,7 +76,7 @@ class VPPForwarderInterface
uint32_t face_id1_;
uint32_t face_id2_;
bool is_consumer_;
- hc_sock_t *sock_;
+ vapi_ctx_t *sock_;
static std::mutex global_lock_;
};