summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmake/Modules/FindSafeVapi.cmake40
-rw-r--r--ctrl/libhicnctrl/CMakeLists.txt6
-rw-r--r--ctrl/libhicnctrl/src/hicn_plugin_api.c1033
-rw-r--r--hicn-plugin/CMakeLists.txt303
-rw-r--r--hicn-plugin/src/CMakeLists.txt318
-rw-r--r--hicn-plugin/vapi/CMakeLists.txt70
-rw-r--r--hicn-plugin/vapi/include/vapi/vapi_safe.h19
-rw-r--r--hicn-plugin/vapi/vapi_safe.c75
-rw-r--r--libtransport/CMakeLists.txt10
-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
13 files changed, 949 insertions, 1031 deletions
diff --git a/cmake/Modules/FindSafeVapi.cmake b/cmake/Modules/FindSafeVapi.cmake
new file mode 100644
index 000000000..a9077ae14
--- /dev/null
+++ b/cmake/Modules/FindSafeVapi.cmake
@@ -0,0 +1,40 @@
+# Copyright (c) 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.
+
+set(SAFE_VAPI_SEARCH_PATH_LIST
+ ${SAFE_VAPI_HOME}
+ $ENV{SAFE_VAPI_HOME}
+ /usr/local
+ /opt
+ /usr
+)
+
+find_path(SAFE_VAPI_INCLUDE_DIR vapi/vapi_safe.h
+ HINTS ${SAFE_VAPI_SEARCH_PATH_LIST}
+ PATH_SUFFIXES include
+ DOC "Find the vapi_safe includes"
+)
+
+find_library(SAFE_VAPI_LIBRARY NAMES libsafe_vapi.so
+ HINTS ${SAFE_VAPI_SEARCH_PATH_LIST}
+ PATH_SUFFIXES lib/x86_64-linux-gnu/
+ DOC "Find the vapi safe lib"
+)
+
+set(SAFE_VAPI_LIBRARIES ${SAFE_VAPI_LIBRARY})
+set(SAFE_VAPI_INCLUDE_DIRS ${SAFE_VAPI_INCLUDE_DIR})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Hicnlight SAFE_VAPI_LIBRARIES SAFE_VAPI_INCLUDE_DIRS)
+
+mark_as_advanced(SAFE_VAPI_LIBRARY SAFE_VAPI_INCLUDE_DIR)
diff --git a/ctrl/libhicnctrl/CMakeLists.txt b/ctrl/libhicnctrl/CMakeLists.txt
index ff586ff22..63e27ba42 100644
--- a/ctrl/libhicnctrl/CMakeLists.txt
+++ b/ctrl/libhicnctrl/CMakeLists.txt
@@ -40,6 +40,7 @@ if (BUILD_HICNPLUGIN AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(LIBHICNCTRL ${LIBHICNCTRL}-memif)
set(LINK_FLAGS "-Wl,-unresolved-symbols=ignore-in-shared-libs")
list(APPEND HICN_LIBRARIES ${HICNPLUGIN_LIBRARIES})
+ list(APPEND HICN_LIBRARIES ${SAFE_VAPI_LIBRARIES})
endif()
set(LIBHICNCTRL ${LIBHICNCTRL} CACHE INTERNAL "" FORCE)
@@ -58,7 +59,8 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(HICN_INCLUDE_DIRS
${HICN_INCLUDE_DIRS}
- ${HICNPLUGIN_INCLUDE_DIRS})
+ ${HICNPLUGIN_INCLUDE_DIRS}
+ ${SAFE_VAPI_INCLUDE_DIRS})
else()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
@@ -71,10 +73,12 @@ else()
HICN_INCLUDE_DIRS
${HICN_INCLUDE_DIRS}
${HICNPLUGIN_INCLUDE_DIRS}
+ ${SAFE_VAPI_INCLUDE_DIRS}
)
list(APPEND DEPENDENCIES
hicn_plugin
+ ${SAFE_VAPI_SHARED}
)
else ()
set(HICN_LIBRARIES ${LIBHICN_SHARED})
diff --git a/ctrl/libhicnctrl/src/hicn_plugin_api.c b/ctrl/libhicnctrl/src/hicn_plugin_api.c
index 52c83959e..fc8954b65 100644
--- a/ctrl/libhicnctrl/src/hicn_plugin_api.c
+++ b/ctrl/libhicnctrl/src/hicn_plugin_api.c
@@ -26,6 +26,7 @@
#include <string.h> // memmove, strcasecmp
#include <sys/socket.h> // socket
#include <unistd.h> // close, fcntl
+#include <vapi/vapi_safe.h>
#include <hicn/ctrl/api.h>
#include <hicn/ctrl/commands.h>
@@ -36,6 +37,7 @@
#include <vapi/interface.api.vapi.h>
#include <hicn/util/log.h>
#include <hicn/util/map.h>
+#include <hicn/error.h>
#include <vnet/ip/ip6_packet.h>
#include <vnet/ip/ip_types_api.h>
@@ -43,40 +45,20 @@
#define MAX_OUTSTANDING_REQUESTS 4
#define RESPONSE_QUEUE_SIZE 2
-// #define vl_typedefs
-// #include <vpp/api/vpe_all_api_h.h>
-// #undef vl_typedefs
-
DEFINE_VAPI_MSG_IDS_HICN_API_JSON
DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON
DEFINE_VAPI_MSG_IDS_IP_API_JSON
typedef struct {
- u32 sockets_count;
vapi_ctx_t g_vapi_ctx_instance;
bool async;
} vapi_skc_ctx_t;
vapi_skc_ctx_t vapi_skc = {
- .sockets_count = 0,
.g_vapi_ctx_instance = NULL,
.async = false,
};
-/*
- * Internal state associated to a pending request
- */
-typedef struct {
- vapi_ctx_t g_vapi_ctx_instance;
- int seq;
- // Reusing the buffer of data to hold both the unparsed response from the
- // forwarder and the result of the parsing
- hc_data_t *data;
- /* Information used to process results */
- int size_in;
- HC_PARSE parse;
-} hc_sock_request_t;
-
/**
* Messages to the forwarder might be multiplexed thanks to the seqNum fields in
* the header_control_message structure. The forwarder simply answers back the
@@ -84,9 +66,9 @@ typedef struct {
* outgoing queries so that replied can be demultiplexed and treated
* appropriately.
*/
-TYPEDEF_MAP_H(hc_sock_map, int, hc_sock_request_t *);
-TYPEDEF_MAP(hc_sock_map, int, hc_sock_request_t *, int_cmp, int_snprintf,
- generic_snprintf);
+/* TYPEDEF_MAP_H(hc_sock_map, int, hc_sock_request_t *); */
+/* TYPEDEF_MAP(hc_sock_map, int, hc_sock_request_t *, int_cmp, int_snprintf, */
+/* generic_snprintf); */
struct hc_sock_s {
vapi_ctx_t g_vapi_ctx_instance;
@@ -100,23 +82,8 @@ struct hc_sock_s {
int seq;
bool async;
- hc_sock_map_t *map;
};
-hc_sock_request_t *hc_sock_request_create(int seq, hc_data_t *data,
- HC_PARSE parse) {
- assert(data);
-
- hc_sock_request_t *request = malloc(sizeof(hc_sock_request_t));
- if (!request) return NULL;
- request->seq = seq;
- request->data = data;
- request->parse = parse;
- request->size_in = 0;
- return request;
-}
-
-void hc_sock_request_free(hc_sock_request_t *request) { free(request); }
/******************************************************************************
* Message helper types and aliases
@@ -160,11 +127,6 @@ typedef union {
#undef _
} hc_msg_payload_t;
-#define IS_DUMP_MSG(a) (a == vapi_msg_id_hicn_api_face_stats_dump || \
- a == vapi_msg_id_hicn_api_routes_dump || \
- a == vapi_msg_id_hicn_api_faces_dump || \
- a == vapi_msg_id_sw_interface_dump)
-
typedef struct __attribute__ ((__packed__)) {
hc_msg_header_t hdr;
hc_msg_payload_t payload;
@@ -173,8 +135,8 @@ typedef struct __attribute__ ((__packed__)) {
typedef void (* NTOH)(void *msg);
typedef struct __attribute__((__packed__)) {
- hc_sock_t *s;
- uint32_t ctx_msg;
+ hc_data_t *data;
+ uint32_t curr_msg;
} callback_ctx_t;
typedef struct __attribute__((__packed__)) {
@@ -242,43 +204,22 @@ hc_sock_t *hc_sock_create(void) {
memset(s, 0, sizeof(hc_sock_t));
- s->map = hc_sock_map_create();
- if (!s->map) goto ERR_MAP;
-
//By default the socket is blocking -- not async
s->async = 0;
return s;
-ERR_MAP:
- free(s);
ERR_SOCK:
return NULL;
}
void hc_sock_free(hc_sock_t *s) {
- hc_sock_request_t **request_array = NULL;
- int n = hc_sock_map_get_value_array(s->map, &request_array);
- if (n < 0) {
- ERROR("Could not retrieve pending request array for freeing up resources");
- } else {
- for (unsigned i = 0; i < n; i++) {
- hc_sock_request_t *request = request_array[i];
- hc_sock_request_free(request);
- }
- free(request_array);
- }
-
- hc_sock_map_free(s->map);
if (s->url) free(s->url);
close(s->fd);
free(s);
- vapi_skc.sockets_count--;
- if (vapi_skc.sockets_count == 0) {
- vapi_disconnect(vapi_skc.g_vapi_ctx_instance);
- vapi_skc.g_vapi_ctx_instance = NULL;
- }
+ vapi_disconnect_safe();
+ vapi_skc.g_vapi_ctx_instance = NULL;
}
int hc_sock_get_next_seq(hc_sock_t *s) {
@@ -292,126 +233,21 @@ int hc_sock_set_nonblocking(hc_sock_t *s) {
int hc_sock_get_fd(hc_sock_t *s) { return 1; }
-vapi_error_e vapi_cb(vapi_ctx_t ctx, void *callback_ctx, vapi_error_e error, bool is_last, void *payload) {
- callback_ctx_t *ctx_call = (callback_ctx_t *)callback_ctx;
- hc_sock_t *s = ctx_call->s;
- int ret = VAPI_OK;
-
- if ((s->woff != s->roff) && (s->woff % RECV_BUFLEN == 0)) {
- ERROR("[hc_sock_process] No more space on the buffer to store responces");
- ret = VAPI_ENOMEM;
- goto END;
- }
-
- if (is_last) {
- s->buffer[s->woff % RECV_BUFLEN] = ctx_call->ctx_msg;
- s->woff++;
- }
-
- if(!payload) {
- ret = VAPI_ENOMEM;
- goto END;
- }
-
- hc_sock_request_t *request = NULL;
- if (hc_sock_map_get(s->map, ctx_call->ctx_msg, &request) <
- 0) {
- ERROR("[hc_sock_process] Error searching for matching request");
- ret = VAPI_ENOMEM;
- goto END;
- }
-
- if (request->data->current == request->data->size) {
- if (request->data->size == 0){
- request->data->size = 1;
- request->data->buffer = malloc(request->data->in_element_size * request->data->size);
- } else {
- request->data->buffer = realloc(request->data->buffer, request->data->in_element_size * request->data->size * 2);
- request->data->size *=2;
- }
- }
-
- if (!request->data->buffer) {
- request->data->size = 0;
- ret = VAPI_ENOMEM;
- goto END;
- }
-
- memcpy(request->data->buffer +
- request->data->current * request->data->in_element_size,
- payload, request->data->in_element_size);
- request->data->current++;
-
-END:
- if (is_last)
- free(callback_ctx);
-
- return ret;
-}
-
int hc_sock_connect(hc_sock_t *s) {
- if (vapi_skc.g_vapi_ctx_instance == NULL) {
- vapi_error_e rv = vapi_ctx_alloc(&vapi_skc.g_vapi_ctx_instance);
- rv = vapi_connect(vapi_skc.g_vapi_ctx_instance, APP_NAME, NULL,
- MAX_OUTSTANDING_REQUESTS, RESPONSE_QUEUE_SIZE,
- s->async ? VAPI_MODE_NONBLOCKING : VAPI_MODE_BLOCKING, true);
- vapi_skc.async = s->async;
- if (rv != VAPI_OK) {
- vapi_ctx_free(vapi_skc.g_vapi_ctx_instance);
- goto ERR_CONNECT;
- }
- s->g_vapi_ctx_instance = vapi_skc.g_vapi_ctx_instance;
- printf("[hc_sock_connect] *connected %s ok", APP_NAME);
- } else if (s->async == vapi_skc.async){
- s->g_vapi_ctx_instance = vapi_skc.g_vapi_ctx_instance;
- printf("[hc_sock_connect] *connected %s ok", APP_NAME);
- } else {
- printf("Unable to create %s socket", s->async ? "non blocking" : "blocking");
+
+ vapi_error_e rv = vapi_connect_safe(&s->g_vapi_ctx_instance, s->async);
+ if (rv != VAPI_OK)
goto ERR_CONNECT;
- }
- vapi_skc.sockets_count++;
return 0;
ERR_CONNECT:
- ERROR("[hc_sock_connect] connection %s failes", APP_NAME);
+ ERROR("[hc_sock_connect] connection failed");
return -1;
}
int hc_sock_send(hc_sock_t *s, hc_msg_t *msg, size_t msglen, int seq) {
- vapi_cb_t callback = ((hc_msg_s *)msg)->callback;
- callback_ctx_t *callback_ctx = ((hc_msg_s *)msg)->callback_ctx;
-
- if (!msg || !callback) {
- return VAPI_EINVAL;
- }
- if (vapi_is_nonblocking(s->g_vapi_ctx_instance) && vapi_requests_full(s->g_vapi_ctx_instance)) {
- return VAPI_EAGAIN;
- }
- vapi_error_e rv;
- if (VAPI_OK != (rv = vapi_producer_lock (s->g_vapi_ctx_instance))) {
- return rv;
- }
- ((hc_msg_s *)msg)->hicnp_msg->hdr.context = seq;
- callback_ctx->ctx_msg = seq;
- vapi_msg_id_t msg_id = vapi_lookup_vapi_msg_id_t(s->g_vapi_ctx_instance, ((hc_msg_s *)msg)->hicnp_msg->hdr._vl_msg_id);
- ((hc_msg_s *)msg)->ntoh(((hc_msg_s *)msg)->hicnp_msg);
- if (IS_DUMP_MSG(msg_id)) {
- if (VAPI_OK == (rv = vapi_send_with_control_ping (s->g_vapi_ctx_instance, ((hc_msg_s *)msg)->hicnp_msg, seq))) {
- vapi_store_request(s->g_vapi_ctx_instance, seq, true, (vapi_cb_t)callback, callback_ctx);
- }
- } else {
- if (VAPI_OK == (rv = vapi_send (s->g_vapi_ctx_instance, ((hc_msg_s *)msg)->hicnp_msg))) {
- vapi_store_request(s->g_vapi_ctx_instance, seq, false, (vapi_cb_t)callback, callback_ctx);
- }
- }
-
- if (rv != VAPI_OK) {
- if (VAPI_OK != vapi_producer_unlock (s->g_vapi_ctx_instance)) {
- abort (); /* this really shouldn't happen */
- }
- }
- return rv;
+ return -1;
}
int hc_sock_get_available(hc_sock_t *s, u8 **buffer, size_t *size) {
@@ -420,201 +256,19 @@ int hc_sock_get_available(hc_sock_t *s, u8 **buffer, size_t *size) {
}
int hc_sock_recv(hc_sock_t *s) {
- vapi_error_e rv;
- if (VAPI_OK != vapi_producer_unlock (s->g_vapi_ctx_instance)) {
- abort (); /* this really shouldn't happen */
- }
- if (vapi_is_nonblocking(s->g_vapi_ctx_instance)) {
- rv = VAPI_OK;
- } else {
- rv = vapi_dispatch(s->g_vapi_ctx_instance);
- }
-
- return rv;
+ // NOT IMPLEMENTED
+ return -1;
}
int hc_sock_process(hc_sock_t *s, hc_data_t **pdata) {
- int err = 0;
- int seq = s->buffer[s->roff % RECV_BUFLEN];
-
- hc_sock_request_t *request = NULL;
- if (hc_sock_map_get(s->map, seq, &request) < 0) {
- ERROR("[hc_sock_process] Error searching for matching request");
- return -1;
- }
- if (!request) {
- ERROR("[hc_sock_process] No request matching received sequence number");
- return -1;
- }
-
- if (s->roff == s->woff) {
- ERROR("[hc_sock_process] No data received for the corresponding request");
- return -1;
- }
-
- if(request->parse != NULL)
- err = request->parse((u8 *)request, NULL);
- request->data->complete = 1;
- if (!err && request->data->complete_cb != NULL)
- err = request->data->complete_cb(request->data, s);
- s->roff++;
-
- if (pdata) *pdata = request->data;
-
- hc_sock_map_remove(s->map, seq, NULL);
- hc_sock_request_free(request);
-
- return err;
-}
-
-int hc_sock_callback(hc_sock_t *s, hc_data_t **pdata) {
- hc_data_t *data = NULL;
-
- for (;;) {
- int n = hc_sock_recv(s);
- if (n == 0) {
- goto ERR_EOF;
- }
- if (n < 0) {
- switch (errno) {
- case ECONNRESET:
- case ENODEV:
- /* Forwarder restarted */
- WARN("Forwarder likely restarted: not (yet) implemented");
- goto ERR;
- case EWOULDBLOCK:
- // DEBUG("Would block... stop reading from socket");
- goto END;
- default:
- perror("hc_sock_recv");
- goto ERR;
- }
- }
- if (hc_sock_process(s, &data) < 0) {
- goto ERR;
- }
- }
-END:
- if (pdata)
- *pdata = data;
- else
- hc_data_free(data);
- return 0;
-
-ERR:
- hc_data_free(data);
-ERR_EOF:
+ //NOT IMPLEMENTED
return -1;
}
-int hc_sock_reset(hc_sock_t *s) {
- s->roff = s->woff = 0;
- return 0;
-}
-
/******************************************************************************
* Command-specific structures and functions
******************************************************************************/
-typedef int (*HC_PARSE)(const u8 *, u8 *);
-
-typedef struct {
- hc_action_t cmd;
- command_id cmd_id;
- size_t size_in;
- size_t size_out;
- HC_PARSE parse;
- data_callback_t complete_cb;
-} hc_command_params_t;
-
-int hc_execute_command(hc_sock_t *s, hc_msg_t *msg, size_t msg_len,
- hc_command_params_t *params, hc_data_t **pdata,
- bool async) {
- if (async) assert(!pdata);
-
- /* Sanity check */
- switch (params->cmd) {
- case ACTION_CREATE:
- assert(params->size_in != 0); /* payload repeated */
- //assert(params->size_out == 0); //Face will return the face id
- //assert(params->parse == NULL);
- break;
- case ACTION_DELETE:
- assert(params->size_in != 0); /* payload repeated */
- assert(params->size_out == 0);
- //assert(params->parse == NULL);
- break;
- case ACTION_LIST:
- assert(params->size_in != 0);
- assert(params->size_out != 0);
- //assert(params->parse != NULL);
- break;
- case ACTION_SET:
- assert(params->size_in != 0);
- assert(params->size_out == 0);
- //assert(params->parse == NULL);
- break;
- default:
- return -1;
- }
-
- /* XXX data will at least store the result (complete) */
- hc_data_t *data = hc_data_create(params->size_in, params->size_out, params->complete_cb);
- if (!data) {
- ERROR("[hc_execute_command] Could not create data storage");
- goto ERR_DATA;
- }
-
- int seq = hc_sock_get_next_seq(s);
-
- /* Create state used to process the request */
- hc_sock_request_t *request = NULL;
- request = hc_sock_request_create(seq, data, params->parse);
- if (!request) {
- ERROR("[hc_execute_command] Could not create request state");
- goto ERR_REQUEST;
- }
-
- /* Add state to map */
- if (hc_sock_map_add(s->map, seq, request) < 0) {
- ERROR("[hc_execute_command] Error adding request state to map");
- goto ERR_MAP;
- }
-
- if (hc_sock_send(s, msg, msg_len, seq) < 0) {
- ERROR("[hc_execute_command] Error sending message");
- goto ERR_PROCESS;
- }
-
- if (async) return 0;
-
- while (!data->complete) {
- // CAN WE COLLAPSE THEM INTO A SINGLE COMMAND? Ideally the process would be
- // done in the recv
- /*
- * As the socket is non blocking it might happen that we need to read
- * several times before success... shall we alternate between blocking
- * and non-blocking mode ?
- */
- if (hc_sock_recv(s) < 0) continue; // break;
- if (hc_sock_process(s, pdata) < 0) {
- ERROR("[hc_execute_command] Error processing socket results");
- goto ERR_PROCESS;
- }
- }
-
- if (!pdata) hc_data_free(data);
-
- return 0;
-
-ERR_PROCESS:
-ERR_MAP:
- hc_sock_request_free(request);
-ERR_REQUEST:
- hc_data_free(data);
-ERR_DATA:
- return -1;
-}
/*----------------------------------------------------------------------------*
* Listeners
@@ -691,104 +345,137 @@ vapi_error_e process_ip_info(struct vapi_ctx_s *ctx,
return rv;
}
-/* A listener in vpp is an interface with classify enabled */
-int listener_list_complete_cb(struct hc_data_s * data, void *ctx) {
- // No need to write anything on the dst, no data expected
+typedef struct {
+ u32 swif;
+ char interface_name[INTERFACE_LEN];
+} hc_vapi_interface_t;
+
+vapi_error_e listener_list_complete_cb (struct vapi_ctx_s *ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_sw_interface_details *reply) {
+
+ if (reply == NULL || rv != VAPI_OK)
+ return rv;
+
+ if (is_last)
+ return 0;
+
+ hc_data_t *data = (hc_data_t *)callback_ctx;
+
+ if (data->size == data->current) {
+ data->buffer = realloc(data->buffer, sizeof(hc_vapi_interface_t) * data->size * 2);
+
+ if (!data->buffer)
+ return VAPI_ENOMEM;
+
+ data->size *=2;
+ }
+
+ hc_vapi_interface_t *swif = &((hc_vapi_interface_t*)data->buffer)[data->current];
+
+ swif[0].swif = reply->sw_if_index;
+ memcpy(swif[0].interface_name, reply->interface_name, INTERFACE_LEN);
+
+ data->current++;
+
+ return rv;
+}
- hc_sock_t *s = (hc_sock_t *)ctx;
- int n_interfaces = data->current;
- u32 *swifs = malloc(sizeof(u32) * n_interfaces);
+/* LISTENER LIST */
+int hc_listener_list(hc_sock_t *s, hc_data_t **pdata) {
int retval = VAPI_OK;
+ vapi_lock();
+ vapi_msg_sw_interface_dump *hicnp_msg;
+ hicnp_msg = vapi_alloc_sw_interface_dump(s->g_vapi_ctx_instance);
- if (!swifs) {
+ if (!hicnp_msg) {
retval = VAPI_ENOMEM;
goto END;
}
- for (int i = 0; i < n_interfaces; i++) {
- vapi_payload_sw_interface_details *reply =
- (vapi_payload_sw_interface_details *)(data->buffer + i * data->in_element_size);
- swifs[i] = reply->sw_if_index;
+ hicnp_msg->payload.sw_if_index = ~0;
+ hicnp_msg->payload.name_filter_valid = 0;
+
+ hc_data_t *data = hc_data_create(0, sizeof(hc_vapi_interface_t),NULL);
+
+ if (!data) {
+ retval = -1;
+ goto END;
+ }
+
+ hc_data_t *data2 = hc_data_create(0, 1,NULL);
+
+ if (!data2) {
+ retval = -1;
+ goto END;
}
- vapi_payload_sw_interface_details * temp = (vapi_payload_sw_interface_details *)data->buffer;
- data->buffer = malloc(sizeof(hc_listener_t));
+ data->buffer = malloc(sizeof(hc_vapi_interface_t));
data->size = 1;
- data->current = 0;
if (!data->buffer) {
- data->current = 0;
- retval = VAPI_ENOMEM;
+ free (data);
+ retval = -1;
+ goto FREE_DATA;
+ }
+
+ int ret = vapi_sw_interface_dump(s->g_vapi_ctx_instance, hicnp_msg, listener_list_complete_cb, data);
+
+ if (ret != VAPI_OK) {
+ free(data->buffer);
+ free(data);
+ retval = -1;
+ goto FREE_DATA_BUFFER;
+ }
+
+ data2->buffer = malloc(sizeof(hc_listener_t));
+ data2->size = 1;
+ data2->out_element_size = 1;
+
+ if (!data2->buffer) {
+ free (data2->buffer);
+ retval =1 -1;
goto CLEAN;
}
/* Query the forwarder for each interface */
- for(int i = 0; i < n_interfaces; i++) {
- size_t index = data->current;
+ for(int i = 0; i < data->current; i++) {
+ int index = data2->current;
vapi_msg_ip_address_dump* msg = vapi_alloc_ip_address_dump(s->g_vapi_ctx_instance);
- msg->payload.sw_if_index = swifs[i];
+ msg->payload.sw_if_index = ((hc_vapi_interface_t *)data->buffer)[i].swif;
msg->payload.is_ipv6 = 0;
- vapi_payload_sw_interface_details *reply =
- &(temp[i]);
- int retval = vapi_ip_address_dump(s->g_vapi_ctx_instance, msg, process_ip_info, data);
+ retval = vapi_ip_address_dump(s->g_vapi_ctx_instance, msg, process_ip_info, data2);
vapi_msg_ip_address_dump* msg2 = vapi_alloc_ip_address_dump(s->g_vapi_ctx_instance);
-
+
if (retval) goto CLEAN;
-
- msg2->payload.sw_if_index = swifs[i];
+
+ msg2->payload.sw_if_index = ((hc_vapi_interface_t *)data->buffer)[i].swif;
msg2->payload.is_ipv6 = 1;
- retval = vapi_ip_address_dump(s->g_vapi_ctx_instance, msg2, process_ip_info, data);
- for (size_t j = index; j < data->current; j++) {
- memcpy(((hc_listener_t *)(data->buffer))[j].interface_name, reply->interface_name, INTERFACE_LEN);
+ retval = vapi_ip_address_dump(s->g_vapi_ctx_instance, msg2, process_ip_info, data2);
+ for (size_t j = index; j < data2->current; j++) {
+ memcpy(((hc_listener_t *)(data2->buffer))[j].interface_name, ((hc_vapi_interface_t*)(data->buffer))[i].interface_name, INTERFACE_LEN);
}
-
+
if (retval) goto CLEAN;
}
CLEAN:
- free(swifs);
- free(temp);
-
-END:
- data->size = data->current;
- data->out_element_size = sizeof(hc_listener_t);
+FREE_DATA_BUFFER:
+ free(data->buffer);
+FREE_DATA:
+ free(data);
+
+ data2->size = data2->current;
+ data2->out_element_size = sizeof(hc_listener_t);
+ *pdata = data2;
+ END:
+ vapi_unlock();
return retval;
}
-/* LISTENER LIST */
-int hc_listener_list(hc_sock_t *s, hc_data_t **pdata) {
- hc_msg_s msg;
- vapi_msg_sw_interface_dump *hicnp_msg;
- hicnp_msg = vapi_alloc_sw_interface_dump(s->g_vapi_ctx_instance);
-
- if (!hicnp_msg) return VAPI_ENOMEM;
-
- msg.hicnp_msg = (hc_hicnp_t *)hicnp_msg;
- msg.callback = &vapi_cb;
- msg.callback_ctx = malloc(sizeof(callback_ctx_t));
- msg.callback_ctx->s = s;
- msg.ntoh = (NTOH)&vapi_msg_sw_interface_dump_hton;
-
- if (!(msg.callback_ctx)) return VAPI_ENOMEM;
-
- hicnp_msg->payload.sw_if_index = ~0;
- hicnp_msg->payload.name_filter_valid = 0;
-
- //hicnp_msg->payload.type = 1; //0 v4, 1 v6
- hc_command_params_t params = {
- .cmd = ACTION_LIST,
- .cmd_id = LIST_LISTENERS,
- .size_in = sizeof(vapi_msg_sw_interface_details),
- .size_out = sizeof(hc_listener_t),
- .parse = (HC_PARSE)NULL,
- .complete_cb = listener_list_complete_cb,
- };
-
- return hc_execute_command(s, (hc_msg_t *)&msg, sizeof(msg), &params, pdata,
- false);
-}
-
int hc_listener_list_async(hc_sock_t *s, hc_data_t **pdata) {
// NOT IMPLEMENTED
return -1;
@@ -940,36 +627,29 @@ int hc_connection_set_admin_state_async(hc_sock_t *s,
*----------------------------------------------------------------------------*/
/* ROUTE CREATE */
-int parse_route_create(uint8_t *src, uint8_t *dst) {
- // No need to write anything on the dst, no data expected
+vapi_error_e parse_route_create( 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 || rv != VAPI_OK)
+ return rv;
- hc_sock_request_t *request = (hc_sock_request_t *)src;
- vapi_payload_hicn_api_route_nhops_add_reply *reply =
- (vapi_payload_hicn_api_route_nhops_add_reply *)request->data->buffer;
+ if (reply->retval != VAPI_OK)
+ return reply->retval;
- int retval = reply->retval;
- free(reply);
- return retval;
+ return reply->retval;
}
int _hc_route_create(hc_sock_t *s, hc_route_t *route, bool async) {
if (!IS_VALID_FAMILY(route->family)) return -1;
- hc_msg_s msg;
-
+ vapi_lock();
vapi_msg_hicn_api_route_nhops_add *hicnp_msg;
hicnp_msg = vapi_alloc_hicn_api_route_nhops_add(s->g_vapi_ctx_instance);
if (!hicnp_msg) return VAPI_ENOMEM;
- msg.hicnp_msg = (hc_hicnp_t *)hicnp_msg;
- msg.callback = &vapi_cb;
- msg.callback_ctx = malloc(sizeof(callback_ctx_t));
- msg.callback_ctx->s = s;
- msg.ntoh = (NTOH)&vapi_msg_hicn_api_route_nhops_add_hton;
-
- if (!(msg.callback_ctx)) return VAPI_ENOMEM;
-
if (route->family == AF_INET) {
memcpy(&hicnp_msg->payload.prefix.address.un.ip4[0], &route->remote_addr.v4, 4);
}
@@ -982,17 +662,10 @@ int _hc_route_create(hc_sock_t *s, hc_route_t *route, bool async) {
hicnp_msg->payload.face_ids[0] = route->face_id;
hicnp_msg->payload.n_faces = 1;
- hc_command_params_t params = {
- .cmd = ACTION_CREATE,
- .cmd_id = ADD_ROUTE,
- .size_in =
- sizeof(vapi_msg_hicn_api_route_nhops_add),
- .size_out = 0,
- .parse = (HC_PARSE)parse_route_create,
- };
+ vapi_error_e ret = vapi_hicn_api_route_nhops_add(s->g_vapi_ctx_instance, hicnp_msg, parse_route_create, NULL);
+ vapi_unlock();
+ return ret;
- return hc_execute_command(s, (hc_msg_t *)&msg, sizeof(msg), &params, NULL,
- async);
}
int hc_route_create(hc_sock_t *s, hc_route_t *route) {
@@ -1004,54 +677,38 @@ int hc_route_create_async(hc_sock_t *s, hc_route_t *route) {
}
/* ROUTE DELETE */
+vapi_error_e parse_route_delete( vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_hicn_api_route_nhop_del_reply *reply) {
+ if (reply == NULL || rv != VAPI_OK)
+ return rv;
-int parse_route_delete(uint8_t *src, uint8_t *dst) {
- // No need to write anything on the dst, no data expected
-
- hc_sock_request_t *request = (hc_sock_request_t *)src;
- vapi_payload_hicn_api_route_nhop_del_reply *reply =
- (vapi_payload_hicn_api_route_nhop_del_reply *)request->data->buffer;
+ if (reply->retval != VAPI_OK)
+ return reply->retval;
- int retval = reply->retval;
- free(reply);
- return retval;
+ return reply->retval;
}
int _hc_route_delete(hc_sock_t *s, hc_route_t *route, bool async) {
if (!IS_VALID_FAMILY(route->family)) return -1;
- hc_msg_s msg;
-
+ vapi_lock();
vapi_msg_hicn_api_route_nhop_del *hicnp_msg;
hicnp_msg = vapi_alloc_hicn_api_route_nhop_del(s->g_vapi_ctx_instance);
if (!hicnp_msg) return VAPI_ENOMEM;
- msg.hicnp_msg = (hc_hicnp_t *)hicnp_msg;
- msg.callback = &vapi_cb;
- msg.callback_ctx = malloc(sizeof(callback_ctx_t));
- msg.callback_ctx->s = s;
- msg.ntoh = (NTOH)&vapi_msg_hicn_api_route_nhop_del_hton;
-
- if (!(msg.callback_ctx)) return VAPI_ENOMEM;
-
memcpy(&hicnp_msg->payload.prefix.address.un.ip6[0], &route->remote_addr, 16);
hicnp_msg->payload.prefix.address.af =
route->family == AF_INET ? ADDRESS_IP4 : ADDRESS_IP6;
hicnp_msg->payload.prefix.len = route->len;
hicnp_msg->payload.faceid = route->face_id;
- hc_command_params_t params = {
- .cmd = ACTION_DELETE,
- .cmd_id = REMOVE_ROUTE,
- .size_in =
- sizeof(vapi_msg_hicn_api_route_nhop_del),
- .size_out = 0,
- .parse = (HC_PARSE)parse_route_delete,
- };
-
- return hc_execute_command(s, (hc_msg_t *)&msg, sizeof(msg), &params, NULL,
- async);
+ int retval = vapi_hicn_api_route_nhop_del(s->g_vapi_ctx_instance, hicnp_msg, parse_route_delete, NULL);
+ vapi_unlock();
+ return retval;
}
int hc_route_delete(hc_sock_t *s, hc_route_t *route) {
@@ -1063,84 +720,83 @@ int hc_route_delete_async(hc_sock_t *s, hc_route_t *route) {
}
/* ROUTE LIST */
-int parse_route_list(uint8_t *src, uint8_t *dst) {
- // No need to write anything on the dst, no data expected
+vapi_error_e parse_route_list( vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_hicn_api_routes_details *reply) {
- hc_sock_request_t *request = (hc_sock_request_t *)src;
+ if (reply == NULL || rv != VAPI_OK)
+ return rv;
- int size = 0;
- for (int i = 0; i < request->data->current; i++) {
- vapi_payload_hicn_api_routes_details *reply =
- (vapi_payload_hicn_api_routes_details
- *)(request->data->buffer + i * request->data->in_element_size);
- size += reply->nfaces;
- }
- hc_route_t *output = malloc(sizeof(hc_route_t) * size);
+ if (reply->retval != VAPI_OK)
+ return reply->retval;
- int res = VAPI_OK;
+ hc_data_t *data = (hc_data_t *)callback_ctx;
- if (!output) {
- size = 0;
- res = VAPI_ENOMEM;
- goto END;
+ int empty_spots = data->size - data->current;
+ if (empty_spots < reply->nfaces) {
+ int new_size = data->size + (reply->nfaces - empty_spots);
+ data->buffer = realloc(data->buffer, sizeof(hc_route_t) * (new_size));
+ if (!data->buffer)
+ return VAPI_ENOMEM;
+
+ data->size =new_size;
}
- int cur = 0;
- for (int j = 0; j < request->data->current; j++) {
- vapi_payload_hicn_api_routes_details *reply =
- (vapi_payload_hicn_api_routes_details
- *)(request->data->buffer + j * request->data->in_element_size);
- for (int i = 0; i < reply->nfaces; i++) {
- output[cur].face_id = reply->faceids[i];
- output[cur].cost = 1;
- output[cur].len = reply->prefix.len;
- if (reply->prefix.address.af == ADDRESS_IP6)
+ for (int i = 0; i < reply->nfaces; i++) {
+ hc_route_t * route = &((hc_route_t*)(data->buffer))[data->current];
+ route->face_id = reply->faceids[i];
+ route->cost = 1;
+ route->len = reply->prefix.len;
+ if (reply->prefix.address.af == ADDRESS_IP6)
{
- memcpy(output[cur].remote_addr.v6.as_u8, reply->prefix.address.un.ip6, 16);
+ memcpy(route->remote_addr.v6.as_u8, reply->prefix.address.un.ip6, 16);
}
else
{
- memcpy(output[cur].remote_addr.v4.as_u8, reply->prefix.address.un.ip4, 4);
+ memcpy(route->remote_addr.v4.as_u8, reply->prefix.address.un.ip4, 4);
}
- output[cur].family = reply->prefix.address.af == ADDRESS_IP6? AF_INET6 : AF_INET;
- cur++;
- }
+ route->family = reply->prefix.address.af == ADDRESS_IP6? AF_INET6 : AF_INET;
+ data->current++;
}
-END:
- free(request->data->buffer);
- request->data->buffer = (void *)output;
- request->data->size = size;
- request->data->out_element_size = sizeof(hc_route_t);
- return res;
+ return reply->retval;
}
int _hc_route_list(hc_sock_t *s, hc_data_t **pdata, bool async) {
- hc_msg_s msg;
-
+ vapi_lock();
vapi_msg_hicn_api_routes_dump *hicnp_msg;
hicnp_msg = vapi_alloc_hicn_api_routes_dump(s->g_vapi_ctx_instance);
- if (!hicnp_msg) return VAPI_ENOMEM;
+ hc_data_t *data = hc_data_create(0, sizeof(hc_route_t),NULL);
+ int ret = VAPI_OK;
- msg.hicnp_msg = (hc_hicnp_t *)hicnp_msg;
- msg.callback = &vapi_cb;
- msg.callback_ctx = malloc(sizeof(callback_ctx_t));
- msg.callback_ctx->s = s;
- msg.ntoh = (NTOH)&vapi_msg_hicn_api_routes_dump_hton;
+ if (!data){
+ ret = -1;
+ goto err;
+ }
+
+ data->buffer = malloc(sizeof(hc_route_t));
+ data->size = 1;
- if (!(msg.callback_ctx)) return VAPI_ENOMEM;
+ if (!data->buffer) {
+ ret = -1;
+ goto err_free;
+ }
- hc_command_params_t params = {
- .cmd = ACTION_LIST,
- .cmd_id = LIST_ROUTES,
- .size_in = sizeof(vapi_msg_hicn_api_routes_details),
- .size_out = sizeof(hc_route_t),
- .parse = (HC_PARSE)parse_route_list,
- };
+ ret = vapi_hicn_api_routes_dump(s->g_vapi_ctx_instance, hicnp_msg, parse_route_list, data);
- return hc_execute_command(s, (hc_msg_t *)&msg, sizeof(msg), &params, pdata,
- async);
+ if (ret != VAPI_OK)
+ goto err_free;
+
+ *pdata = data;
+
+ err_free:
+ free(data);
+ err:
+ vapi_unlock();
+ return ret;
}
int hc_route_list(hc_sock_t *s, hc_data_t **pdata) {
@@ -1226,57 +882,46 @@ int hc_connection_to_local_listener(const hc_connection_t *connection,
}
/* FACE CREATE */
-int parse_face_create(uint8_t *src, uint8_t *dst) {
- // No need to write anything on the dst, no data expected
+vapi_error_e parse_face_create( vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_hicn_api_face_add_reply *reply) {
- hc_sock_request_t *request = (hc_sock_request_t *)src;
- vapi_payload_hicn_api_face_add_reply *reply =
- (vapi_payload_hicn_api_face_add_reply *)request->data->buffer;
+ if (reply == NULL || rv != VAPI_OK)
+ return rv;
- hc_face_t *output = malloc(sizeof(hc_face_t));
+ if (reply->retval != VAPI_OK)
+ return reply->retval;
- int retval = VAPI_OK;
- int size = 1;
+ hc_data_t *data = (hc_data_t *)callback_ctx;
- if (!output) {
- size = 0;
- retval = VAPI_ENOMEM;
- goto END;
- }
+ hc_face_t *output = (hc_face_t *)data->buffer;
output->id = reply->faceid;
- retval = reply->retval;
-
-END:
- free(request->data->buffer);
- request->data->buffer = (void *)output;
- request->data->size = size;
- request->data->out_element_size = sizeof(hc_face_t);
- return retval;
+ return reply->retval;
}
int hc_face_create(hc_sock_t *s, hc_face_t *face) {
- hc_msg_s msg;
+ vapi_lock();
vapi_msg_hicn_api_face_add *hicnp_msg;
hicnp_msg = vapi_alloc_hicn_api_face_add(s->g_vapi_ctx_instance);
- if (!hicnp_msg) return VAPI_ENOMEM;
-
- msg.hicnp_msg = (hc_hicnp_t *)hicnp_msg;
- msg.callback = &vapi_cb;
- msg.callback_ctx = malloc(sizeof(callback_ctx_t));
- msg.callback_ctx->s = s;
- msg.ntoh = (NTOH)&vapi_msg_hicn_api_face_add_hton;
-
- if (!msg.callback_ctx) return VAPI_ENOMEM;
+ int retval = VAPI_OK;
+ if (!hicnp_msg) {
+ retval = VAPI_ENOMEM;
+ goto END;
+ }
switch(face->face.type) {
case FACE_TYPE_HICN:
{
u8 check = ip46_address_is_ip4((ip46_address_t *)&(face->face.local_addr)) == ip46_address_is_ip4((ip46_address_t *)&(face->face.remote_addr));
- if (!check)
- return -1;
+ if (!check) {
+ retval = -1;
+ goto END;
+ }
hicnp_msg->payload.type = IP_FACE;
if (ip46_address_is_ip4((ip46_address_t *)&(face->face.local_addr)))
@@ -1297,11 +942,13 @@ int hc_face_create(hc_sock_t *s, hc_face_t *face) {
memcpy(hicnp_msg->payload.face.ip.if_name, face->face.netdevice.name, IFNAMSIZ);
break;
}
- case FACE_TYPE_UDP:
+ case FACE_TYPE_UDP:
{
u8 check = ip46_address_is_ip4((ip46_address_t *)&(face->face.local_addr)) == ip46_address_is_ip4((ip46_address_t *)&(face->face.remote_addr));
- if (!check)
- return -1;
+ if (!check) {
+ retval = -1;
+ goto END;
+ }
hicnp_msg->payload.type = UDP_FACE;
if (ip46_address_is_ip4((ip46_address_t *)&(face->face.local_addr)))
@@ -1325,179 +972,189 @@ int hc_face_create(hc_sock_t *s, hc_face_t *face) {
break;
}
default:
- return -1;
+ {
+ retval = -1;
+ goto END;
+ }
}
- hc_command_params_t params = {
- .cmd = ACTION_CREATE,
- .cmd_id = ADD_CONNECTION,
- .size_in =
- sizeof(vapi_msg_hicn_api_face_add),
- .size_out = sizeof(hc_face_t),
- .parse = (HC_PARSE)parse_face_create,
- };
+ hc_data_t *data = hc_data_create(0, sizeof(hc_face_t),NULL);
- hc_data_t *data;
+ if (!data) {
+ retval = -1;
+ goto END;
+ }
- int ret = hc_execute_command(s, (hc_msg_t *)&msg, sizeof(msg), &params, &data,
- false);
- if (ret == 0)
- face->id = ((hc_face_t *)data->buffer)->id;
+ data->buffer = malloc(sizeof(hc_face_t));
+ data->out_element_size = sizeof(hc_face_t);
- return ret;
-}
+ if (!data->buffer) {
+ free (data);
+ retval = -1;
+ goto END;
+ }
-/* FACE DELETE */
-int parse_face_delete(uint8_t *src, uint8_t *dst) {
- // No need to write anything on the dst, no data expected
+ retval = vapi_hicn_api_face_add(s->g_vapi_ctx_instance, hicnp_msg, parse_face_create, data);
+
+ if (retval != VAPI_OK)
+ goto END;
- hc_sock_request_t *request = (hc_sock_request_t *)src;
- vapi_payload_hicn_api_face_del_reply *reply =
- (vapi_payload_hicn_api_face_del_reply *)request->data->buffer;
+ face->id = ((hc_face_t *)data->buffer)->id;
- int retval = reply->retval;
- free(reply);
+ END:
+ vapi_unlock();
return retval;
}
-int hc_face_delete(hc_sock_t *s, hc_face_t *face) {
+vapi_error_e parse_face_delete( vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_hicn_api_face_del_reply *reply) {
- hc_msg_s msg;
+ if (reply == NULL || rv != VAPI_OK)
+ return rv;
+
+ return reply->retval;
+}
+
+int hc_face_delete(hc_sock_t *s, hc_face_t *face) {
vapi_msg_hicn_api_face_del *hicnp_msg;
+ vapi_lock();
hicnp_msg = vapi_alloc_hicn_api_face_del(s->g_vapi_ctx_instance);
if (!hicnp_msg) return VAPI_ENOMEM;
- msg.hicnp_msg = (hc_hicnp_t *)hicnp_msg;
- msg.callback = &vapi_cb;
- msg.callback_ctx = malloc(sizeof(callback_ctx_t));
- msg.callback_ctx->s = s;
- msg.ntoh = (NTOH)&vapi_msg_hicn_api_face_del_hton;
-
- if (!msg.callback_ctx) return VAPI_ENOMEM;
-
hicnp_msg->payload.faceid = face->id;
- hc_command_params_t params = {
- .cmd = ACTION_DELETE,
- .cmd_id = REMOVE_ROUTE,
- .size_in =
- sizeof(vapi_msg_hicn_api_face_del),
- .size_out = 0,
- .parse = (HC_PARSE)parse_face_delete,
- };
-
- return hc_execute_command(s, (hc_msg_t *)&msg, sizeof(msg), &params, NULL,
- false);
+ int retval = vapi_hicn_api_face_del(s->g_vapi_ctx_instance, hicnp_msg, parse_face_delete, NULL);
+ vapi_unlock();
+ return retval;
}
/* FACE LIST */
-int parse_face_list(uint8_t *src, uint8_t *dst) {
- // No need to write anything on the dst, no data expected
+vapi_error_e parse_face_list( vapi_ctx_t ctx,
+ void *callback_ctx,
+ vapi_error_e rv,
+ bool is_last,
+ vapi_payload_hicn_api_faces_details *reply) {
- hc_sock_request_t *request = (hc_sock_request_t *)src;
- hc_face_t *output = malloc(sizeof(hc_face_t)*request->data->current);
+ if (reply == NULL || rv != VAPI_OK)
+ return rv;
- int retval = VAPI_OK;
- int cur = 0;
+ if (reply->retval != VAPI_OK)
+ return reply->retval;
- if (!output) {
- retval = VAPI_ENOMEM;
- request->data->current = 0;
- goto END;
+ hc_data_t *data = (hc_data_t *)callback_ctx;
+
+ if (data->size == data->current) {
+ int new_size = data->size *2;
+ data->buffer = realloc(data->buffer, sizeof(hc_face_t) * (new_size));
+ if (!data->buffer)
+ return VAPI_ENOMEM;
+
+ data->size =new_size;
}
- for (int j = 0; j < request->data->current; j++) {
- vapi_payload_hicn_api_faces_details *reply =
- (vapi_payload_hicn_api_faces_details
- *)(request->data->buffer + j * request->data->in_element_size);
- retval = reply->retval;
- switch(reply->type)
+ int retval = VAPI_OK;
+
+ hc_face_t * face = &((hc_face_t *)(data->buffer))[data->current];
+ switch(reply->type)
{
- case IP_FACE:
+ case IP_FACE:
{
if (reply->face.ip.local_addr.af == ADDRESS_IP4)
{
- memcpy(output[j].face.local_addr.v4.as_u8, reply->face.ip.local_addr.un.ip4, IPV4_ADDR_LEN);
- memcpy(output[j].face.remote_addr.v4.as_u8, reply->face.ip.remote_addr.un.ip4, IPV4_ADDR_LEN);
+ memcpy(face->face.local_addr.v4.as_u8, reply->face.ip.local_addr.un.ip4, IPV4_ADDR_LEN);
+ memcpy(face->face.remote_addr.v4.as_u8, reply->face.ip.remote_addr.un.ip4, IPV4_ADDR_LEN);
}
else
{
- memcpy(output[j].face.local_addr.v6.as_u8, reply->face.ip.local_addr.un.ip6, IPV6_ADDR_LEN);
- memcpy(output[j].face.remote_addr.v6.as_u8, reply->face.ip.remote_addr.un.ip6, IPV6_ADDR_LEN);
+ memcpy(face->face.local_addr.v6.as_u8, reply->face.ip.local_addr.un.ip6, IPV6_ADDR_LEN);
+ memcpy(face->face.remote_addr.v6.as_u8, reply->face.ip.remote_addr.un.ip6, IPV6_ADDR_LEN);
}
- output[j].face.type = FACE_TYPE_HICN;
- output[j].id = reply->faceid;
- output[j].face.netdevice.index = reply->face.ip.swif;
- memcpy(output[j].face.netdevice.name, reply->face.ip.if_name, IFNAMSIZ);
+ face->face.type = FACE_TYPE_HICN;
+ face->id = reply->faceid;
+ face->face.netdevice.index = reply->face.ip.swif;
+ memcpy(face->face.netdevice.name, reply->face.ip.if_name, IFNAMSIZ);
break;
}
case UDP_FACE:
{
if (reply->face.ip.local_addr.af == ADDRESS_IP4)
{
- memcpy(output[j].face.local_addr.v4.as_u8, reply->face.udp.local_addr.un.ip4, IPV4_ADDR_LEN);
- memcpy(output[j].face.remote_addr.v4.as_u8, reply->face.udp.remote_addr.un.ip4, IPV4_ADDR_LEN);
+ memcpy(face->face.local_addr.v4.as_u8, reply->face.udp.local_addr.un.ip4, IPV4_ADDR_LEN);
+ memcpy(face->face.remote_addr.v4.as_u8, reply->face.udp.remote_addr.un.ip4, IPV4_ADDR_LEN);
}
else
{
- memcpy(output[j].face.local_addr.v6.as_u8, reply->face.udp.local_addr.un.ip6, IPV6_ADDR_LEN);
- memcpy(output[j].face.remote_addr.v6.as_u8, reply->face.udp.remote_addr.un.ip6, IPV6_ADDR_LEN);
+ memcpy(face->face.local_addr.v6.as_u8, reply->face.udp.local_addr.un.ip6, IPV6_ADDR_LEN);
+ memcpy(face->face.remote_addr.v6.as_u8, reply->face.udp.remote_addr.un.ip6, IPV6_ADDR_LEN);
}
- output[j].face.local_port = reply->face.udp.lport;
- output[j].face.remote_port = reply->face.udp.rport;
- output[j].face.type = FACE_TYPE_UDP;
- output[j].id = reply->faceid;
- output[j].face.netdevice.index = reply->face.udp.swif;
- memcpy(output[j].face.netdevice.name, reply->face.udp.if_name, IFNAMSIZ);
+ face->face.local_port = reply->face.udp.lport;
+ face->face.remote_port = reply->face.udp.rport;
+ face->face.type = FACE_TYPE_UDP;
+ face->id = reply->faceid;
+ face->face.netdevice.index = reply->face.udp.swif;
+ memcpy(face->face.netdevice.name, reply->face.udp.if_name, IFNAMSIZ);
break;
}
default:
retval = -1;
}
if (!retval)
- cur++;
- }
+ data->current++;
-END:
- free(request->data->buffer);
- request->data->buffer = (void *)output;
- request->data->size = request->data->current;
- request->data->out_element_size = sizeof(hc_face_t);
- return retval;
+ return reply->retval;
}
int hc_face_list(hc_sock_t *s, hc_data_t **pdata) {
- hc_msg_s msg;
-
+ vapi_lock();
vapi_msg_hicn_api_faces_dump *hicnp_msg;
hicnp_msg = vapi_alloc_hicn_api_faces_dump(s->g_vapi_ctx_instance);
- if (!hicnp_msg) return VAPI_ENOMEM;
-
- msg.hicnp_msg = (hc_hicnp_t *)hicnp_msg;
- msg.callback = &vapi_cb;
- msg.callback_ctx = malloc(sizeof(callback_ctx_t));
- msg.callback_ctx->s = s;
- msg.ntoh = (NTOH)&vapi_msg_hicn_api_faces_dump_hton;
+ int retval = 0;
+ if (!hicnp_msg) {
+ retval = VAPI_ENOMEM;
+ goto END;
+ }
- if (!msg.callback_ctx) return VAPI_ENOMEM;
+ hc_data_t *data = hc_data_create(0, sizeof(hc_face_t),NULL);
+ if (!data) {
+ retval = -1;
+ goto END;
+ }
- hc_command_params_t params = {
- .cmd = ACTION_LIST,
- .cmd_id = LIST_CONNECTIONS,
- .size_in = sizeof(vapi_msg_hicn_api_faces_details),
- .size_out = sizeof(hc_face_t),
- .parse = (HC_PARSE)parse_face_list,
- };
+ data->buffer = malloc(sizeof(hc_face_t));
+ data->size = 1;
- return hc_execute_command(s, (hc_msg_t *)&msg, sizeof(msg), &params, (hc_data_t**)pdata,
- false);
+ if (!data->buffer) {
+ free (data);
+ retval = -1;
+ goto err;
}
+
+ retval = vapi_hicn_api_faces_dump(s->g_vapi_ctx_instance, hicnp_msg, parse_face_list, data);
+ *pdata = data;
+
+ if (retval != VAPI_OK)
+ goto err;
+
+ data->size = data->current;
+ vapi_unlock();
+ return retval;
+
+ err:
+ free(data);
+ END:
+ vapi_unlock();
+ return retval;
+}
+
int hc_connection_parse_to_face(void *in, hc_face_t *face) { return 0; }
int hc_face_list_async(hc_sock_t *s)
@@ -1663,4 +1320,4 @@ u8 *
format_vl_api_address_union (u8 * s, va_list * args)
{
return NULL;
-}
+} \ No newline at end of file
diff --git a/hicn-plugin/CMakeLists.txt b/hicn-plugin/CMakeLists.txt
index e8347c150..d0781e8fa 100644
--- a/hicn-plugin/CMakeLists.txt
+++ b/hicn-plugin/CMakeLists.txt
@@ -12,306 +12,7 @@
# limitations under the License.
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
-project(hicn-plugin)
-include(GNUInstallDirs)
+add_subdirectory(src)
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
- "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules/"
- "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/"
-)
-
-set (CMAKE_CXX_STANDARD 11)
-set (CMAKE_C_STANDARD 11)
-
-# Check for memfd_create syscall
-include(CheckSymbolExists)
-CHECK_SYMBOL_EXISTS ( "__NR_memfd_create" "sys/syscall.h" HAVE_MEMFD_CREATE )
-if ( HAVE_MEMFD_CREATE )
- add_definitions ( -DHAVE_MEMFD_CREATE )
-endif()
-
-set(HICN_PLUGIN hicn-plugin CACHE INTERNAL "" FORCE)
-
-include (Packaging)
-
-# Dependencies
-
-find_package(Vpp REQUIRED)
-
-include_directories(${VPP_INCLUDE_DIR})
-
-set(LIBHICN_FILES
- ../lib/src/mapme.c
- ../lib/src/name.c
- ../lib/src/ops.c
- ../lib/src/protocol/ah.c
- ../lib/src/protocol/icmp.c
- ../lib/src/protocol/ipv4.c
- ../lib/src/protocol/ipv6.c
- ../lib/src/protocol/tcp.c
-)
-
-set(LIBHICN_HEADER_FILES_SRC
- ../lib/includes/hicn/hicn.h
- ../lib/includes/hicn/base.h
- ../lib/includes/hicn/common.h
- ../lib/includes/hicn/error.h
- ../lib/includes/hicn/header.h
- ../lib/includes/hicn/name.h
- ../lib/includes/hicn/protocol.h
- ../lib/includes/hicn/ops.h
- ../lib/includes/hicn/mapme.h
-)
-
-set(LIBHICN_HEADER_FILES_PROTOCOL
- ../lib/includes/hicn/protocol/ah.h
- ../lib/includes/hicn/protocol/icmp.h
- ../lib/includes/hicn/protocol/icmprd.h
- ../lib/includes/hicn/protocol/ipv4.h
- ../lib/includes/hicn/protocol/ipv6.h
- ../lib/includes/hicn/protocol/tcp.h
- ../lib/includes/hicn/protocol/udp.h
-)
-
-set(LIBHICN_HEADER_FILES_UTIL
- ../lib/includes/hicn/util/ip_address.h
- ../lib/includes/hicn/util/token.h
- ../lib/includes/hicn/util/types.h
-)
-
-set(HICN_PLUGIN_SOURCE_FILES
- src/hicn.c
- src/hicn_api.c
- src/cli.c
- src/hashtb.c
- src/mgmt.c
- src/pcs.c
- src/route.c
- src/strategy_dpo_manager.c
- src/strategy.c
- src/interest_pcslookup_node.c
- src/interest_hitpit_node.c
- src/interest_hitcs_node.c
- src/data_pcslookup_node.c
- src/data_fwd_node.c
- src/data_push_node.c
- src/error.c
- src/faces/face_cli.c
- src/faces/face.c
- src/faces/ip/face_ip.c
- src/faces/ip/face_ip_cli.c
- src/faces/ip/face_ip_node.c
- src/faces/ip/iface_ip_node.c
- src/faces/ip/dpo_ip.c
- src/faces/udp/face_udp.c
- src/faces/udp/face_udp_cli.c
- src/faces/udp/face_udp_node.c
- src/faces/udp/iface_udp_node.c
- src/faces/udp/dpo_udp.c
- src/faces/app/address_mgr.c
- src/faces/app/face_cons.c
- src/faces/app/face_prod.c
- src/faces/app/face_prod_node.c
- src/faces/app/face_app_cli.c
- src/punt.c
- src/pg.c
- src/strategies/dpo_mw.c
- src/strategies/strategy_mw.c
- src/strategies/strategy_mw_cli.c
- src/strategies/dpo_rr.c
- src/strategies/strategy_rr.c
- src/cache_policies/cs_lru.c
- src/mapme_ack_node.c
- src/mapme_ctrl_node.c
- src/mapme_eventmgr.c
-)
-
-set(HICN_PLUGIN_HEADER_FILES
- src/hicn_all_api_h.h
- src/hashtb.h
- src/mgmt.h
- src/params.h
- src/pcs.h
- src/hicn_api.h
- src/hicn.h
- src/state.h
- src/infra.h
- src/hicn_msg_enum.h
- src/parser.h
- src/route.h
- src/strategy_dpo_ctx.h
- src/strategy_dpo_manager.h
- src/strategy.h
- src/interest_pcslookup.h
- src/interest_hitpit.h
- src/interest_hitcs.h
- src/data_pcslookup.h
- src/data_fwd.h
- src/error.h
- src/face_db.h
- src/faces/face.h
- src/faces/ip/face_ip.h
- src/faces/ip/face_ip_node.h
- src/faces/ip/iface_ip_node.h
- src/faces/ip/dpo_ip.h
- src/faces/udp/face_udp.h
- src/faces/udp/face_udp_node.h
- src/faces/udp/iface_udp_node.h
- src/faces/udp/dpo_udp.h
- src/faces/app/address_mgr.h
- src/faces/app/face_cons.h
- src/faces/app/face_prod.h
- src/punt.h
- src/pg.h
- src/strategies/dpo_mw.h
- src/strategies/strategy_mw.h
- src/strategies/dpo_rr.h
- src/strategies/strategy_rr.h
- src/cache_policies/cs_policy.h
- src/cache_policies/cs_lru.h
- src/mapme.h
- src/mapme_ack.h
- src/mapme_ctrl.h
- src/mapme_eventmgr.h
-)
-
-set(HICN_API_TEST_SOURCE_FILES
- src/hicn_api_test.c
- src/error.c)
-
-set(HICN_API_HEADER_FILES
- src/hicn_msg_enum.h
- src/hicn_all_api_h.h
- src/hicn_api.h
- src/error.h)
-
-set(HICN_API_GENERATED_FILES
- ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.h)
-
-set(HICN_VAPI_GENERATED_FILES
- ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.vapi.h
- ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.vapi.hpp)
-
-set(HICN_VPP_STARTUP_CONF_FILE
- ${CMAKE_BINARY_DIR}/startup.conf)
-
-if (NOT VPP_HOME)
- set(VPP_HOME /usr)
-endif()
-
-if (NOT CMAKE_BUILD_TYPE)
- set (CMAKE_BUILD_TYPE "Release")
-endif (NOT CMAKE_BUILD_TYPE)
-
-SET(HICN_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} CACHE STRING "hicn_install_prefix")
-
-if (CMAKE_BUILD_TYPE STREQUAL "Release")
- set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -march=native -O3 -g")
-elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
- set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -march=native -O0 -g")
- add_definitions(-DCLIB_DEBUG -fPIC -fstack-protector-all)
-endif()
-
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/hicn)
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/vapi)
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/vnet/ip)
-
-# These files are missing from vpp binary distribution
-execute_process(
- COMMAND
- bash -c
- "if [ ! -e ${CMAKE_CURRENT_BINARY_DIR}/vapi_json_parser.py ]; then
- curl https://raw.githubusercontent.com/FDio/vpp/stable/1908/src/vpp-api/vapi/vapi_json_parser.py -o ${CMAKE_CURRENT_BINARY_DIR}/vapi_json_parser.py;
- fi;
- if [ ! -e ${CMAKE_CURRENT_BINARY_DIR}/vapi_c_gen.py ]; then
- curl https://raw.githubusercontent.com/FDio/vpp/stable/1908/src/vpp-api/vapi/vapi_c_gen.py -o ${CMAKE_CURRENT_BINARY_DIR}/vapi_c_gen.py;
- fi;
- if [ ! -e ${CMAKE_CURRENT_BINARY_DIR}/vapi_cpp_gen.py ]; then
- curl https://raw.githubusercontent.com/FDio/vpp/stable/1908/src/vpp-api/vapi/vapi_cpp_gen.py -o ${CMAKE_CURRENT_BINARY_DIR}/vapi_cpp_gen.py;
- fi;
- if [ ! -e ${CMAKE_CURRENT_BINARY_DIR}/vnet/ip/ip_types.api ]; then
- curl https://raw.githubusercontent.com/FDio/vpp/stable/1908/src/vnet/ip/ip_types.api -o ${CMAKE_CURRENT_BINARY_DIR}/vnet/ip/ip_types.api;
- fi;
- chmod +x ${CMAKE_CURRENT_BINARY_DIR}/vapi_json_parser.py ${CMAKE_CURRENT_BINARY_DIR}/vapi_c_gen.py ${CMAKE_CURRENT_BINARY_DIR}/vapi_cpp_gen.py"
-)
-
-add_custom_command(
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.h ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.json
- COMMAND ${VPP_HOME}/bin/vppapigen ARGS --includedir ${CMAKE_CURRENT_BINARY_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/src/hicn.api --output ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.h
- COMMAND ${VPP_HOME}/bin/vppapigen ARGS JSON --includedir ${CMAKE_CURRENT_BINARY_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/src/hicn.api --output ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.json
-)
-add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.vapi.h ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.vapi.hpp
- COMMAND ${CMAKE_CURRENT_BINARY_DIR}/vapi_c_gen.py ARGS ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.json
- COMMAND ${CMAKE_CURRENT_BINARY_DIR}/vapi_cpp_gen.py ARGS ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.json
- DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.json
-)
-
-include_directories(SYSTEM)
-include_directories(${CMAKE_CURRENT_BINARY_DIR})
-
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHICN_VPP_PLUGIN=1")
-add_library(hicn_plugin SHARED
- ${LIBHICN_FILES}
- ${HICN_PLUGIN_SOURCE_FILES}
- ${HICN_API_GENERATED_FILES}
- ${HICN_VAPI_GENERATED_FILES})
-
-file(COPY ${HICN_API_HEADER_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn)
-include_directories(${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins)
-
-file(COPY ${LIBHICN_HEADER_FILES_SRC} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/hicn)
-file(COPY ${LIBHICN_HEADER_FILES_PROTOCOL} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/hicn/protocol)
-file(COPY ${LIBHICN_HEADER_FILES_UTIL} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/hicn/util)
-
-add_library(hicn_api_test_plugin SHARED
- ${HICN_API_TEST_SOURCE_FILES}
- ${HICN_API_GENERATED_FILES})
-
-set(VPP_INSTALL_PLUGIN ${HICN_INSTALL_PREFIX}/vpp_plugins)
-set(VPP_INSTALL_API_TEST_PLUGIN ${HICN_INSTALL_PREFIX}/vpp_api_test_plugins CACHE STRING "vpp_install_api_test_plugin")
-set(VPP_STARTUP_CONF /etc/vpp/)
-
-set_target_properties(hicn_plugin
- PROPERTIES
- LINKER_LANGUAGE C
- INSTALL_RPATH ${VPP_INSTALL_PLUGIN}
- PREFIX "")
-set_target_properties(hicn_api_test_plugin
- PROPERTIES
- LINKER_LANGUAGE C
- PREFIX "")
-
-install(DIRECTORY
- DESTINATION ${VPP_INSTALL_PLUGIN}
- COMPONENT ${HICN_PLUGIN})
-install(TARGETS hicn_plugin
- DESTINATION
- ${VPP_INSTALL_PLUGIN}
- COMPONENT ${HICN_PLUGIN})
-
-install(DIRECTORY
- DESTINATION ${VPP_INSTALL_API_TEST_PLUGIN}
- COMPONENT ${HICN_PLUGIN})
-install(TARGETS hicn_api_test_plugin
- DESTINATION ${VPP_INSTALL_API_TEST_PLUGIN}
- COMPONENT ${HICN_PLUGIN})
-
-install(FILES ${HICN_API_HEADER_FILES} ${HICN_API_GENERATED_FILES}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/vpp_plugins/hicn
- COMPONENT ${HICN_PLUGIN}-dev)
-
-install(FILES ${HICN_API_GENERATED_FILES}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/vpp_plugins/hicn
- COMPONENT ${HICN_PLUGIN_DEV})
-
-install(FILES ${HICN_VAPI_GENERATED_FILES}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/vapi
- COMPONENT ${HICN_PLUGIN}-dev)
-
-#Set variables for other project depending on hicn-plugin
-set(HICNPLUGIN_INCLUDE_DIRS
- ${CMAKE_CURRENT_BINARY_DIR}
- ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins
- CACHE INTERNAL "" FORCE)
-set(HICNPLUGIN_LIBRARIES ${VPP_LIBRARIES} CACHE INTERNAL "" FORCE) \ No newline at end of file
+add_subdirectory(vapi) \ No newline at end of file
diff --git a/hicn-plugin/src/CMakeLists.txt b/hicn-plugin/src/CMakeLists.txt
new file mode 100644
index 000000000..0f2debcb9
--- /dev/null
+++ b/hicn-plugin/src/CMakeLists.txt
@@ -0,0 +1,318 @@
+# 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.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+project(hicn-plugin)
+
+include(GNUInstallDirs)
+
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
+ "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/Modules/"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules/"
+)
+include(BuildMacros)
+
+set (CMAKE_CXX_STANDARD 11)
+set (CMAKE_C_STANDARD 11)
+
+# Check for memfd_create syscall
+include(CheckSymbolExists)
+CHECK_SYMBOL_EXISTS ( "__NR_memfd_create" "sys/syscall.h" HAVE_MEMFD_CREATE )
+if ( HAVE_MEMFD_CREATE )
+ add_definitions ( -DHAVE_MEMFD_CREATE )
+endif()
+
+set(${HICN_PLUGIN}-dev hicn-plugin CACHE INTERNAL "" FORCE SCOPE PARENT)
+
+include (Packaging)
+
+# Dependencies
+
+find_package(Vpp REQUIRED)
+
+include_directories(${VPP_INCLUDE_DIR})
+
+set(LIBHICN_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/src/mapme.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/src/name.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/src/ops.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/src/protocol/ah.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/src/protocol/icmp.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/src/protocol/ipv4.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/src/protocol/ipv6.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/src/protocol/tcp.c
+)
+
+set(LIBHICN_HEADER_FILES_SRC
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/hicn.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/base.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/common.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/error.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/header.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/name.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/protocol.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/ops.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/mapme.h
+)
+
+set(LIBHICN_HEADER_FILES_PROTOCOL
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/protocol/ah.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/protocol/icmp.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/protocol/icmprd.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/protocol/ipv4.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/protocol/ipv6.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/protocol/tcp.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/protocol/udp.h
+)
+
+set(LIBHICN_HEADER_FILES_UTIL
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/util/ip_address.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/util/token.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/includes/hicn/util/types.h
+)
+
+set(HICN_PLUGIN_SOURCE_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn_api.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/cli.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/hashtb.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/mgmt.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/pcs.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/route.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategy_dpo_manager.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategy.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/interest_pcslookup_node.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/interest_hitpit_node.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/interest_hitcs_node.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/data_pcslookup_node.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/data_fwd_node.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/data_push_node.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/error.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/face_cli.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/face.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/face_ip.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/face_ip_cli.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/face_ip_node.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/iface_ip_node.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/dpo_ip.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/face_udp.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/face_udp_cli.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/face_udp_node.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/iface_udp_node.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/dpo_udp.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/address_mgr.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/face_cons.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/face_prod.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/face_prod_node.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/face_app_cli.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/punt.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/pg.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategies/dpo_mw.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategies/strategy_mw.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategies/strategy_mw_cli.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategies/dpo_rr.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategies/strategy_rr.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/cache_policies/cs_lru.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/mapme_ack_node.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/mapme_ctrl_node.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/mapme_eventmgr.c
+)
+
+set(HICN_PLUGIN_HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn_all_api_h.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hashtb.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/mgmt.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/params.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/pcs.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn_api.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/state.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/infra.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn_msg_enum.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/parser.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/route.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategy_dpo_ctx.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategy_dpo_manager.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategy.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/interest_pcslookup.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/interest_hitpit.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/interest_hitcs.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/data_pcslookup.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/data_fwd.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/error.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/face_db.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/face.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/face_ip.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/face_ip_node.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/iface_ip_node.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/ip/dpo_ip.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/face_udp.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/face_udp_node.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/iface_udp_node.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/udp/dpo_udp.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/address_mgr.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/face_cons.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/faces/app/face_prod.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/punt.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/pg.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategies/dpo_mw.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategies/strategy_mw.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategies/dpo_rr.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/strategies/strategy_rr.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/cache_policies/cs_policy.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/cache_policies/cs_lru.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/mapme.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/mapme_ack.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/mapme_ctrl.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/mapme_eventmgr.h
+)
+
+set(HICN_API_TEST_SOURCE_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn_api_test.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/error.c)
+
+set(HICN_API_HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn_msg_enum.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn_all_api_h.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hicn_api.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/error.h)
+
+set(HICN_API_GENERATED_FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.h)
+
+set(HICN_VAPI_GENERATED_FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.vapi.h
+ ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.vapi.hpp)
+
+set(HICN_VPP_STARTUP_CONF_FILE
+ ${CMAKE_BINARY_DIR}/startup.conf)
+
+if (NOT VPP_HOME)
+ set(VPP_HOME /usr)
+endif()
+
+if (NOT CMAKE_BUILD_TYPE)
+ set (CMAKE_BUILD_TYPE "Release")
+endif (NOT CMAKE_BUILD_TYPE)
+
+SET(HICN_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} CACHE STRING "hicn_install_prefix")
+
+if (CMAKE_BUILD_TYPE STREQUAL "Release")
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wall -march=native -O3 -g")
+elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -march=native -O0 -g")
+ add_definitions(-DCLIB_DEBUG -fPIC -fstack-protector-all)
+endif()
+
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/hicn)
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/vapi)
+file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/vnet/ip)
+
+# These files are missing from vpp binary distribution
+execute_process(
+ COMMAND
+ bash -c
+ "if [ ! -e ${CMAKE_CURRENT_BINARY_DIR}/vapi_json_parser.py ]; then
+ curl https://raw.githubusercontent.com/FDio/vpp/stable/1908/src/vpp-api/vapi/vapi_json_parser.py -o ${CMAKE_CURRENT_BINARY_DIR}/vapi_json_parser.py;
+ fi;
+ if [ ! -e ${CMAKE_CURRENT_BINARY_DIR}/vapi_c_gen.py ]; then
+ curl https://raw.githubusercontent.com/FDio/vpp/stable/1908/src/vpp-api/vapi/vapi_c_gen.py -o ${CMAKE_CURRENT_BINARY_DIR}/vapi_c_gen.py;
+ fi;
+ if [ ! -e ${CMAKE_CURRENT_BINARY_DIR}/vapi_cpp_gen.py ]; then
+ curl https://raw.githubusercontent.com/FDio/vpp/stable/1908/src/vpp-api/vapi/vapi_cpp_gen.py -o ${CMAKE_CURRENT_BINARY_DIR}/vapi_cpp_gen.py;
+ fi;
+ if [ ! -e ${CMAKE_CURRENT_BINARY_DIR}/vnet/ip/ip_types.api ]; then
+ curl https://raw.githubusercontent.com/FDio/vpp/stable/1908/src/vnet/ip/ip_types.api -o ${CMAKE_CURRENT_BINARY_DIR}/vnet/ip/ip_types.api;
+ fi;
+ chmod +x ${CMAKE_CURRENT_BINARY_DIR}/vapi_json_parser.py ${CMAKE_CURRENT_BINARY_DIR}/vapi_c_gen.py ${CMAKE_CURRENT_BINARY_DIR}/vapi_cpp_gen.py"
+)
+
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.h ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.json
+ COMMAND ${VPP_HOME}/bin/vppapigen ARGS --includedir ${CMAKE_CURRENT_BINARY_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/hicn.api --output ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/hicn.api.h
+ COMMAND ${VPP_HOME}/bin/vppapigen ARGS JSON --includedir ${CMAKE_CURRENT_BINARY_DIR} --input ${CMAKE_CURRENT_SOURCE_DIR}/hicn.api --output ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.json
+)
+add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.vapi.h ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.vapi.hpp
+ COMMAND ${CMAKE_CURRENT_BINARY_DIR}/vapi_c_gen.py ARGS ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.json
+ COMMAND ${CMAKE_CURRENT_BINARY_DIR}/vapi_cpp_gen.py ARGS ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.json
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/vapi/hicn.api.json
+)
+
+include_directories(SYSTEM)
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHICN_VPP_PLUGIN=1")
+add_library(hicn_plugin SHARED
+ ${LIBHICN_FILES}
+ ${HICN_PLUGIN_SOURCE_FILES}
+ ${HICN_API_GENERATED_FILES}
+ ${HICN_VAPI_GENERATED_FILES})
+
+file(COPY ${HICN_API_HEADER_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn)
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins)
+
+file(COPY ${LIBHICN_HEADER_FILES_SRC} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/hicn)
+file(COPY ${LIBHICN_HEADER_FILES_PROTOCOL} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/hicn/protocol)
+file(COPY ${LIBHICN_HEADER_FILES_UTIL} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/hicn/util)
+
+add_library(hicn_api_test_plugin SHARED
+ ${HICN_API_TEST_SOURCE_FILES}
+ ${HICN_API_GENERATED_FILES})
+
+set(VPP_INSTALL_PLUGIN ${HICN_INSTALL_PREFIX}/vpp_plugins)
+set(VPP_INSTALL_API_TEST_PLUGIN ${HICN_INSTALL_PREFIX}/vpp_api_test_plugins CACHE STRING "vpp_install_api_test_plugin")
+set(VPP_STARTUP_CONF /etc/vpp/)
+
+set_target_properties(hicn_plugin
+ PROPERTIES
+ LINKER_LANGUAGE C
+ INSTALL_RPATH ${VPP_INSTALL_PLUGIN}
+ PREFIX "")
+set_target_properties(hicn_api_test_plugin
+ PROPERTIES
+ LINKER_LANGUAGE C
+ PREFIX "")
+
+install(DIRECTORY
+ DESTINATION ${VPP_INSTALL_PLUGIN}
+ COMPONENT ${HICN_PLUGIN})
+install(TARGETS hicn_plugin
+ DESTINATION
+ ${VPP_INSTALL_PLUGIN}
+ COMPONENT ${HICN_PLUGIN})
+
+install(DIRECTORY
+ DESTINATION ${VPP_INSTALL_API_TEST_PLUGIN}
+ COMPONENT ${HICN_PLUGIN})
+install(TARGETS hicn_api_test_plugin
+ DESTINATION ${VPP_INSTALL_API_TEST_PLUGIN}
+ COMPONENT ${HICN_PLUGIN})
+
+install(FILES ${HICN_API_HEADER_FILES} ${HICN_API_GENERATED_FILES}
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/vpp_plugins/hicn
+ COMPONENT ${HICN_PLUGIN}-dev)
+
+install(FILES ${HICN_API_GENERATED_FILES}
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/vpp_plugins/hicn
+ COMPONENT ${HICN_PLUGIN}-dev)
+
+install(FILES ${HICN_VAPI_GENERATED_FILES}
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/vapi
+ COMPONENT ${HICN_PLUGIN}-dev)
+
+#Set variables for other project depending on hicn-plugin
+set(HICNPLUGIN_INCLUDE_DIRS
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins
+ CACHE INTERNAL "" FORCE)
+set(HICNPLUGIN_LIBRARIES ${VPP_LIBRARIES} CACHE INTERNAL "" FORCE) \ No newline at end of file
diff --git a/hicn-plugin/vapi/CMakeLists.txt b/hicn-plugin/vapi/CMakeLists.txt
new file mode 100644
index 000000000..00bcaf49f
--- /dev/null
+++ b/hicn-plugin/vapi/CMakeLists.txt
@@ -0,0 +1,70 @@
+# Copyright (c) 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.
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+
+set(SAFE_VAPI safe_vapi CACHE INTERNAL "" FORCE)
+set(SAFE_VAPI_SHARED ${SAFE_VAPI}.shared CACHE INTERNAL "" FORCE)
+set(SAFE_VAPI_STATIC ${SAFE_VAPI}.static CACHE INTERNAL "" FORCE)
+
+project(${SAFE_VAPI})
+
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
+ "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/Modules/"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules/"
+)
+
+include (Packaging)
+include (BuildMacros)
+
+# Dependencies
+
+find_package(Vpp REQUIRED)
+
+list(APPEND HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/include/vapi/vapi_safe.h
+)
+
+list(APPEND SOURCE_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/vapi_safe.c
+)
+
+set (LIBRARIES
+ ${VPP_LIBRARIES})
+
+list (APPEND INCLUDE_DIRS
+ ${VPP_INCLUDE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/include)
+
+build_library(${SAFE_VAPI}
+ SHARED STATIC
+ SOURCES ${SOURCE_FILES} ${HEADER_FILES}
+ INSTALL_HEADERS ${HEADER_FILES}
+ LINK_LIBRARIES ${LIBRARIES}
+ COMPONENT ${HICN_PLUGIN}
+ INCLUDE_DIRS ${INCLUDE_DIRS}
+ INSTALL_ROOT_DIR /
+ DEFINITIONS ${COMPILER_DEFINITIONS}
+ )
+
+set(SAFE_VAPI_INCLUDE_DIRS
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
+ "" CACHE INTERNAL
+ "" FORCE
+)
+
+set(SAFE_VAPI_LIBRARIES
+ ${SAFE_VAPI_SHARED}
+ "" CACHE INTERNAL
+ "" FORCE
+)
+
diff --git a/hicn-plugin/vapi/include/vapi/vapi_safe.h b/hicn-plugin/vapi/include/vapi/vapi_safe.h
new file mode 100644
index 000000000..df1114cde
--- /dev/null
+++ b/hicn-plugin/vapi/include/vapi/vapi_safe.h
@@ -0,0 +1,19 @@
+#ifndef VAPI_SAFE
+#include <vapi/vapi.h>
+#include <pthread.h>
+
+extern pthread_mutex_t *mutex;
+
+vapi_error_e vapi_connect_safe(vapi_ctx_t * vapi_ctx_ret, int async);
+
+vapi_error_e vapi_disconnect_safe();
+void vapi_lock();
+
+void vapi_unlock();
+
+#define VAPI_SAFE (NAME, res, ...) \
+ vapi_lock(); \
+ res = ## NAME (__ARGS__); \
+ vapi_unlock();
+
+#endif //VAPI_SAFE
diff --git a/hicn-plugin/vapi/vapi_safe.c b/hicn-plugin/vapi/vapi_safe.c
new file mode 100644
index 000000000..c1d66c0ac
--- /dev/null
+++ b/hicn-plugin/vapi/vapi_safe.c
@@ -0,0 +1,75 @@
+#include <vapi/vapi_safe.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define APP_NAME "hicn_plugin"
+#define MAX_OUTSTANDING_REQUESTS 4
+#define RESPONSE_QUEUE_SIZE 2
+
+pthread_mutex_t *mutex = NULL;
+vapi_ctx_t g_vapi_ctx_instance = NULL;
+u32 count = 0;
+int lock = 0;
+
+vapi_error_e vapi_connect_safe(vapi_ctx_t *vapi_ctx_ret, int async) {
+ vapi_error_e rv = VAPI_OK;
+
+ while (!__sync_bool_compare_and_swap(&lock, 0, 1));
+
+ if (!g_vapi_ctx_instance && !mutex)
+ {
+ rv = vapi_ctx_alloc(&g_vapi_ctx_instance);
+ if (rv != VAPI_OK)
+ goto err;
+
+ mutex = malloc(sizeof(pthread_mutex_t));
+ if (!mutex)
+ goto err_mutex_alloc;
+
+ if (pthread_mutex_init(mutex, NULL) != 0) {
+ printf("Mutex init failed\n");
+ goto err_mutex_init;
+ }
+ }
+
+ if (!count)
+ {
+ rv = vapi_connect(g_vapi_ctx_instance, APP_NAME, NULL,
+ MAX_OUTSTANDING_REQUESTS, RESPONSE_QUEUE_SIZE,
+ async ? VAPI_MODE_NONBLOCKING : VAPI_MODE_BLOCKING, true);
+
+ if (rv != VAPI_OK)
+ goto err_vapi;
+
+ count++;
+ }
+
+ *vapi_ctx_ret = g_vapi_ctx_instance;
+
+ while (!__sync_bool_compare_and_swap(&lock, 1, 0));
+ return rv;
+
+ err_vapi:
+ vapi_ctx_free(g_vapi_ctx_instance);
+ err_mutex_init:
+ free(mutex);
+ err_mutex_alloc:
+ err:
+ while (!__sync_bool_compare_and_swap(&lock, 1, 0));
+ return VAPI_ENOMEM;
+}
+
+vapi_error_e vapi_disconnect_safe() {
+ pthread_mutex_lock(mutex);
+ vapi_error_e rv = VAPI_OK;
+ pthread_mutex_unlock(mutex);
+ return rv;
+}
+
+void vapi_lock() {
+ pthread_mutex_lock(mutex);
+}
+
+void vapi_unlock() {
+ pthread_mutex_unlock(mutex);
+}
diff --git a/libtransport/CMakeLists.txt b/libtransport/CMakeLists.txt
index cc302d09a..6c79c9118 100644
--- a/libtransport/CMakeLists.txt
+++ b/libtransport/CMakeLists.txt
@@ -83,11 +83,11 @@ endif()
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
if (__vpp__)
find_package(HicnPlugin REQUIRED)
- find_package(Libhicnctrl REQUIRED)
+ find_package(SafeVapi REQUIRED)
list(APPEND LIBRARIES
${LIBMEMIF_LIBRARIES}
- ${LIBHICNCTRL_SHARED}
+ ${SAFE_VAPI_LIBRARIES}
)
endif()
@@ -107,12 +107,12 @@ else()
if (__vpp__)
list(APPEND DEPENDENCIES
hicn_plugin
- ${LIBHICNCTRL_SHARED}
+ ${SAFE_VAPI_SHARED}
)
- set(LIBHICNCTRL_LIBRARIES ${LIBHICNCTRL_SHARED})
list(APPEND LIBRARIES
${LIBMEMIF_LIBRARIES}
+ ${SAFE_VAPI_LIBRARIES}
)
endif()
endif()
@@ -120,7 +120,7 @@ endif()
list(APPEND LIBTRANSPORT_INTERNAL_INCLUDE_DIRS
${LIBMEMIF_INCLUDE_DIRS}
- ${LIBHICNCTRL_INCLUSE_DIRS}
+ ${SAFE_VAPI_INCLUDE_DIRS}
)
include(Packaging)
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_;
};