diff options
44 files changed, 1124 insertions, 1306 deletions
@@ -57,6 +57,11 @@ committers: email: 'jsamain+fdio@cisco.com' id: 'jsamain' timezone: '' + - name: 'Angelo Mantellini' + company: 'Cisco' + email:'manangel@cisco.com' + id: 'manang' + timezone: '' tsc: # yamllint disable rule:line-length approval: '' 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 f96bf13a6..15425b513 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 (DISABLE_SHARED_LIBRARIES) @@ -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..0b387404b 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,47 +37,28 @@ #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> +#include <vnet/ip/ip46_address.h> #define APP_NAME "hicn_plugin" #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), ¶ms, 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), ¶ms, 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), ¶ms, 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,86 @@ 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; + + if (!data){ + ret = -1; + goto err; + } + + data->buffer = malloc(sizeof(hc_route_t)); + data->size = 1; - 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->buffer) { + ret = -1; + goto err_free; + } - if (!(msg.callback_ctx)) return VAPI_ENOMEM; + ret = vapi_hicn_api_routes_dump(s->g_vapi_ctx_instance, hicnp_msg, parse_route_list, data); - 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, - }; + if (ret != VAPI_OK) + goto err_free; - return hc_execute_command(s, (hc_msg_t *)&msg, sizeof(msg), ¶ms, pdata, - async); + *pdata = data; + + vapi_unlock(); + return ret; + + err_free: + free(data); + err: + vapi_unlock(); + return ret; } int hc_route_list(hc_sock_t *s, hc_data_t **pdata) { @@ -1226,57 +885,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 +945,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 +975,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), ¶ms, &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; + } + + retval = vapi_hicn_api_face_add(s->g_vapi_ctx_instance, hicnp_msg, parse_face_create, data); -/* FACE DELETE */ -int parse_face_delete(uint8_t *src, uint8_t *dst) { - // No need to write anything on the dst, no data expected + 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), ¶ms, 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), ¶ms, (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) diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c index 5072c3d6c..dc3ac16d4 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/hicn_plugin.c @@ -39,7 +39,7 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **private_ctx) { hicn_subscribe_events(session, &subscription); // IETF subscribe - // ietf_subscribe_events(session, &subscription); + ietf_subscribe_events(session, &subscription); /* set subscription as our private context */ diff --git a/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c b/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c index b3d31ff80..b46b38b89 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c +++ b/ctrl/sysrepo-plugins/hicn-plugin/plugin/ietf/ietf_interface.c @@ -30,7 +30,6 @@ #include "../hicn_vpp_comm.h" - DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON; typedef struct hicn_interface_ @@ -38,8 +37,8 @@ typedef struct hicn_interface_ u32 sw_if_index; char interface_name[VPP_INTFC_NAME_LEN]; u8 l2_address[VPP_MAC_ADDRESS_LEN]; - u32 l2_address_length; u64 link_speed; + u32 flags; u16 link_mtu; u8 admin_up_down; u8 link_up_down; @@ -293,8 +292,7 @@ ietf_sw_interface_dump_cb (struct vapi_ctx_s *ctx, void *callback_ctx, thisIntfc->sw_if_index = reply->sw_if_index; memcpy(thisIntfc->interface_name, reply->interface_name, VPP_INTFC_NAME_LEN); - thisIntfc->l2_address_length = reply->l2_address_length; - memcpy(thisIntfc->l2_address, reply->l2_address, reply->l2_address_length ); + memcpy(thisIntfc->l2_address, reply->l2_address, VPP_MAC_ADDRESS_LEN ); //thisIntfc->link_speed = reply->link_speed; #define ONE_MEGABIT (uint64_t)1000000 switch (reply->link_speed << VNET_HW_INTERFACE_FLAG_SPEED_SHIFT) @@ -305,8 +303,7 @@ ietf_sw_interface_dump_cb (struct vapi_ctx_s *ctx, void *callback_ctx, } thisIntfc->link_mtu = reply->link_mtu; - thisIntfc->admin_up_down = reply->admin_up_down; - thisIntfc->link_up_down = reply->link_up_down; + thisIntfc->flags = reply->flags; dctx->num_ifs += 1; } @@ -352,10 +349,10 @@ i32 ietf_interface_add_del_addr( u32 sw_if_index, u8 is_add, u8 is_ipv6, u8 del_ vapi_msg_sw_interface_add_del_address *msg = vapi_alloc_sw_interface_add_del_address(g_vapi_ctx_instance); msg->payload.sw_if_index = sw_if_index; msg->payload.is_add = is_add; - msg->payload.is_ipv6 = is_ipv6; + msg->payload.prefix.address.af = is_ipv6 ? ADDRESS_IP6 : ADDRESS_IP4; msg->payload.del_all = del_all; - msg->payload.address_length = address_length; - memcpy(msg->payload.address, address, VPP_IP6_ADDRESS_LEN); + msg->payload.prefix.len = address_length; + memcpy(msg->payload.prefix.address.un.ip6, address, VPP_IP6_ADDRESS_LEN); if(vapi_sw_interface_add_del_address(g_vapi_ctx_instance,msg,call_sw_interface_add_del_address,NULL)!=VAPI_OK){ SRP_LOG_DBGMSG("Operation failed"); @@ -370,7 +367,7 @@ i32 ietf_setInterfaceFlags(u32 sw_if_index, u8 admin_up_down) i32 ret = -1; vapi_msg_sw_interface_set_flags *msg = vapi_alloc_sw_interface_set_flags(g_vapi_ctx_instance); msg->payload.sw_if_index = sw_if_index; - msg->payload.admin_up_down = admin_up_down; + msg->payload.flags = admin_up_down? IF_STATUS_API_FLAG_ADMIN_UP : 0; if(vapi_sw_interface_set_flags(g_vapi_ctx_instance,msg,call_sw_interface_set_flags,NULL)!=VAPI_OK){ SRP_LOG_DBGMSG("Operation failed"); diff --git a/extras/CMakeLists.txt b/extras/CMakeLists.txt index 6629f3809..88668df0b 100644 --- a/extras/CMakeLists.txt +++ b/extras/CMakeLists.txt @@ -22,9 +22,9 @@ list(APPEND CMAKE_MODULE_PATH set (DESTDIR ${CMAKE_BINARY_DIR}/extras-root) # add_subdirectory(router-plugin) -# add_subdirectory(libmemif) -add_subdirectory(libyang) -add_subdirectory(sysrepo) +add_subdirectory(libmemif) +# add_subdirectory(libyang) +# add_subdirectory(sysrepo) if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) diff --git a/extras/libmemif/CMakeLists.txt b/extras/libmemif/CMakeLists.txt index 8d141510a..70388f139 100644 --- a/extras/libmemif/CMakeLists.txt +++ b/extras/libmemif/CMakeLists.txt @@ -25,7 +25,7 @@ include(ExternalProject) ExternalProject_Add(libmemif GIT_REPOSITORY https://github.com/FDio/vpp.git - GIT_TAG v19.08.1 + GIT_TAG v20.01 GIT_SHALLOW TRUE PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libmemif PATCH_COMMAND bash -c "cp ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists1.patch ./extras/libmemif/CMakeLists.txt && cp ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists2.patch ./extras/libmemif/src/CMakeLists.txt" diff --git a/hicn-plugin/CMakeLists.txt b/hicn-plugin/CMakeLists.txt index e8347c150..ea933d8a0 100644 --- a/hicn-plugin/CMakeLists.txt +++ b/hicn-plugin/CMakeLists.txt @@ -12,6 +12,7 @@ # limitations under the License. cmake_minimum_required(VERSION 3.5 FATAL_ERROR) + project(hicn-plugin) include(GNUInstallDirs) @@ -20,6 +21,7 @@ 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) @@ -35,283 +37,6 @@ 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) +add_subdirectory(src) -#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) diff --git a/hicn-plugin/src/CMakeLists.txt b/hicn-plugin/src/CMakeLists.txt new file mode 100644 index 000000000..68c583e0b --- /dev/null +++ b/hicn-plugin/src/CMakeLists.txt @@ -0,0 +1,301 @@ +# 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) + +# 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/2001/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/2001/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/2001/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/2001/src/vnet/ip/ip_types.api -o ${CMAKE_CURRENT_BINARY_DIR}/vnet/ip/ip_types.api; + fi; + if [ ! -e ${CMAKE_CURRENT_BINARY_DIR}/vnet/ip/ip_format_fns.h ]; then + curl https://raw.githubusercontent.com/FDio/vpp/master/src/vnet/ip/ip_format_fns.h -o ${CMAKE_CURRENT_BINARY_DIR}/vnet/ip/ip_format_fns.h; + 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 --outputdir ${CMAKE_CURRENT_BINARY_DIR}/vpp_plugins/hicn/ + 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 --outputdir ${CMAKE_CURRENT_BINARY_DIR}/vapi/ +) +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 "") + +message (STATUS "hicn-plugin variable ${HICN_PLUGIN}") + +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 + ${VPP_INCLUDE_DIRS} + CACHE INTERNAL "" FORCE) +set(HICNPLUGIN_LIBRARIES ${VPP_LIBRARIES} CACHE INTERNAL "" FORCE)
\ No newline at end of file diff --git a/hicn-plugin/src/cache_policies/cs_lru.c b/hicn-plugin/src/cache_policies/cs_lru.c index 45c4b5b79..079af58ab 100644 --- a/hicn-plugin/src/cache_policies/cs_lru.c +++ b/hicn-plugin/src/cache_policies/cs_lru.c @@ -240,9 +240,7 @@ hicn_cs_lru_flush (vlib_main_t * vm, struct hicn_pit_cs_s *pitcs, lrunode->bucket_id) { //The bucket is in the non overflown - bucket = - pool_elt_at_index (pitcs->pcs_table->ht_buckets, - lrunode->bucket_id); + bucket = pitcs->pcs_table->ht_buckets + lrunode->bucket_id; } else { diff --git a/hicn-plugin/src/faces/app/address_mgr.c b/hicn-plugin/src/faces/app/address_mgr.c index 76a7e0f6d..1674379c4 100644 --- a/hicn-plugin/src/faces/app/address_mgr.c +++ b/hicn-plugin/src/faces/app/address_mgr.c @@ -25,7 +25,7 @@ #include <vnet/ip/ip4.h> //ip4_add_del_ip_address #include <vnet/ip/ip6.h> //ip6_add_del_ip_address #include <vnet/fib/fib_types.h> //FIB_PROTOCOL_IP4/6, FIB_NODE_INDEX_INVALID -#include <vnet/fib/fib_entry.h> //FIB_SOURCE_PLUGIN_HI +#include <vnet/fib/fib_entry.h> //FIB_SOURCE_PRIORITY_HI #include <vnet/fib/fib_table.h> #include <vppinfra/format.h> #include <vnet/interface.h> //appif_flags @@ -89,19 +89,19 @@ get_two_ip4_addresses (ip4_address_t * appif_addr, ip4_address_t * nh_addr) fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 0, appif_addr->as_u8); fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, HICN_FIB_TABLE, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); fib_entry_index = fib_table_lookup_exact_match (fib_index, &fib_pfx); - fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PLUGIN_HI); + fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PRIORITY_HI); if (fib_entry_index != FIB_NODE_INDEX_INVALID) { fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 0, nh_addr->as_u8); fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, HICN_FIB_TABLE, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); fib_entry_index = fib_table_lookup_exact_match (fib_index, &fib_pfx); fib_table_unlock (fib_index, fib_pfx.fp_proto, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); } if (fib_entry_index != FIB_NODE_INDEX_INVALID) { @@ -141,19 +141,19 @@ get_two_ip6_addresses (ip6_address_t * appif_addr, ip6_address_t * nh_addr) fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 1, appif_addr->as_u8); fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, HICN_FIB_TABLE, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); fib_entry_index = fib_table_lookup_exact_match (fib_index, &fib_pfx); - fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PLUGIN_HI); + fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PRIORITY_HI); if (fib_entry_index != FIB_NODE_INDEX_INVALID) { fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 0, nh_addr->as_u8); fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, HICN_FIB_TABLE, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); fib_entry_index = fib_table_lookup_exact_match (fib_index, &fib_pfx); fib_table_unlock (fib_index, fib_pfx.fp_proto, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); } if (fib_entry_index != FIB_NODE_INDEX_INVALID) { @@ -184,9 +184,9 @@ get_ip4_address () fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 0, prefix->as_u8); fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, HICN_FIB_TABLE, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); fib_entry_index = fib_table_lookup_exact_match (fib_index, &fib_pfx); - fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PLUGIN_HI); + fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PRIORITY_HI); increment_v4_address (prefix, 1); } while (fib_entry_index != FIB_NODE_INDEX_INVALID); @@ -211,9 +211,9 @@ get_ip6_address () fib_pfx.fp_addr = to_ip46 ( /* is_v6 */ 1, prefix->as_u8); fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, HICN_FIB_TABLE, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); fib_entry_index = fib_table_lookup_exact_match (fib_index, &fib_pfx); - fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PLUGIN_HI); + fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PRIORITY_HI); increment_v6_address (prefix, 1); } while (fib_entry_index != FIB_NODE_INDEX_INVALID); diff --git a/hicn-plugin/src/faces/app/face_prod_node.c b/hicn-plugin/src/faces/app/face_prod_node.c index 48e7c4259..0ef25fe94 100644 --- a/hicn-plugin/src/faces/app/face_prod_node.c +++ b/hicn-plugin/src/faces/app/face_prod_node.c @@ -80,7 +80,7 @@ match_ip4_name (u32 * name, fib_prefix_t * prefix) } static_always_inline int -match_ip6_name (u32x4 * name, fib_prefix_t * prefix) +match_ip6_name (u8 * name, fib_prefix_t * prefix) { union { @@ -89,18 +89,8 @@ match_ip6_name (u32x4 * name, fib_prefix_t * prefix) u32 as_u32[4]; } xor_sum __attribute__ ((aligned (sizeof (u32x4)))); -#ifdef CLIB_HAVE_VEC128 - if (U32X4_ALIGNED (name)) - { //SSE can't handle unaligned data - xor_sum.as_u32x4 = *((u32x4 *) name) & - UNION_CAST (prefix->fp_addr.ip6.as_u64[0], u32x4); - } - else -#endif /* CLIB_HAVE_VEC128 */ - { - xor_sum.as_u64[0] = ((u64 *) name)[0] & prefix->fp_addr.ip6.as_u64[0]; - xor_sum.as_u64[1] = ((u64 *) name)[1] & prefix->fp_addr.ip6.as_u64[1]; - } + xor_sum.as_u64[0] = ((u64 *) name)[0] & prefix->fp_addr.ip6.as_u64[0]; + xor_sum.as_u64[1] = ((u64 *) name)[1] & prefix->fp_addr.ip6.as_u64[1]; return (xor_sum.as_u64[0] == prefix->fp_addr.ip6.as_u64[0]) && (xor_sum.as_u64[1] == prefix->fp_addr.ip6.as_u64[1]); @@ -120,7 +110,7 @@ hicn_face_prod_next_from_data_hdr (vlib_node_runtime_t * node, } else if (PREDICT_TRUE (v == 0x60 && !ip46_address_is_ip4 (&prefix->fp_addr))) { - match_res = match_ip6_name ((u32x4 *) & (ptr[8]), prefix); + match_res = match_ip6_name (& (ptr[8]), prefix); } return match_res ? HICN_FACE_PROD_NEXT_DATA_IP4 + (v == diff --git a/hicn-plugin/src/faces/face.h b/hicn-plugin/src/faces/face.h index d4f7f356a..b758ece06 100644 --- a/hicn-plugin/src/faces/face.h +++ b/hicn-plugin/src/faces/face.h @@ -20,7 +20,6 @@ #include <vlib/vlib.h> #include <vnet/dpo/dpo.h> #include <vnet/adj/adj_types.h> - #include "../hicn.h" typedef u8 hicn_face_flags_t; diff --git a/hicn-plugin/src/faces/ip/face_ip.c b/hicn-plugin/src/faces/ip/face_ip.c index d4ba158de..f4ae5429d 100644 --- a/hicn-plugin/src/faces/ip/face_ip.c +++ b/hicn-plugin/src/faces/ip/face_ip.c @@ -172,7 +172,7 @@ hicn_face_ip_del (hicn_face_id_t face_id) * @brief Helper for handling midchain adjacencies */ void face_midchain_fixup_t (vlib_main_t * vm, - struct ip_adjacency_t_ * adj, + const struct ip_adjacency_t_ * adj, vlib_buffer_t * b0, const void *data) { vnet_buffer (b0)->sw_if_index[VLIB_TX] = 0; @@ -213,7 +213,7 @@ hicn_face_ip_find_adj (const ip46_address_t * remote_addr, { u32 fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, HICN_FIB_TABLE, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); diff --git a/hicn-plugin/src/faces/ip/face_ip_node.c b/hicn-plugin/src/faces/ip/face_ip_node.c index 1229b4eaa..0eeeab6fb 100644 --- a/hicn-plugin/src/faces/ip/face_ip_node.c +++ b/hicn-plugin/src/faces/ip/face_ip_node.c @@ -589,7 +589,7 @@ hicn_face_rewrite_interest (vlib_main_t * vm, vlib_buffer_t * b0, u32 fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, HICN_FIB_TABLE, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); diff --git a/hicn-plugin/src/faces/ip/iface_ip_node.c b/hicn-plugin/src/faces/ip/iface_ip_node.c index 62ccc514d..8adef50d9 100644 --- a/hicn-plugin/src/faces/ip/iface_ip_node.c +++ b/hicn-plugin/src/faces/ip/iface_ip_node.c @@ -13,11 +13,11 @@ * limitations under the License. */ -#include <hicn/hicn.h> #include "face_ip.h" #include "dpo_ip.h" #include "../../strategy_dpo_manager.h" #include "../face.h" +#include "../../hicn.h" #include "../../infra.h" #include "../../cache_policies/cs_lru.h" diff --git a/hicn-plugin/src/faces/udp/face_udp.c b/hicn-plugin/src/faces/udp/face_udp.c index 54d773358..e2fa3227b 100644 --- a/hicn-plugin/src/faces/udp/face_udp.c +++ b/hicn-plugin/src/faces/udp/face_udp.c @@ -147,7 +147,7 @@ hicn_face_udp_add (const ip46_address_t * local_addr, u32 fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, HICN_FIB_TABLE, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); ip_adj = fib_entry_get_adj (fib_entry_index); @@ -199,7 +199,7 @@ hicn_face_udp_add (const ip46_address_t * local_addr, *pfaceid = hicn_dpoi_get_index (face); dpo_proto = DPO_PROTO_IP4; - fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PLUGIN_HI); + fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PRIORITY_HI); } else if (!ip46_address_is_ip4 (local_addr) && !ip46_address_is_ip4 (remote_addr)) @@ -211,7 +211,7 @@ hicn_face_udp_add (const ip46_address_t * local_addr, u32 fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, HICN_FIB_TABLE, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); ip_adj = fib_entry_get_adj (fib_entry_index); @@ -254,7 +254,7 @@ hicn_face_udp_add (const ip46_address_t * local_addr, *pfaceid = hicn_dpoi_get_index (face); dpo_proto = DPO_PROTO_IP6; - fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PLUGIN_HI); + fib_table_unlock (fib_index, fib_pfx.fp_proto, FIB_SOURCE_PRIORITY_HI); } else { diff --git a/hicn-plugin/src/faces/udp/face_udp_node.c b/hicn-plugin/src/faces/udp/face_udp_node.c index 232b86d70..c82336659 100644 --- a/hicn-plugin/src/faces/udp/face_udp_node.c +++ b/hicn-plugin/src/faces/udp/face_udp_node.c @@ -557,7 +557,7 @@ hicn_face_udp4_encap (vlib_main_t * vm, u32 fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, HICN_FIB_TABLE, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); @@ -625,7 +625,7 @@ hicn_face_udp6_encap (vlib_main_t * vm, u32 fib_index = fib_table_find_or_create_and_lock (fib_pfx.fp_proto, HICN_FIB_TABLE, - FIB_SOURCE_PLUGIN_HI); + FIB_SOURCE_PRIORITY_HI); fib_entry_index = fib_table_lookup (fib_index, &fib_pfx); diff --git a/hicn-plugin/src/hicn.api b/hicn-plugin/src/hicn.api index 673f67c43..b226dfe4d 100644 --- a/hicn-plugin/src/hicn.api +++ b/hicn-plugin/src/hicn.api @@ -16,13 +16,13 @@ option version = "5.1.0"; import "vnet/ip/ip_types.api"; -enum face_type +enum hicn_face_type { IP_FACE = 0, UDP_FACE, }; -enum punt_type +enum hicn_punt_type { IP_PUNT = 0, UDP_PUNT, @@ -375,7 +375,7 @@ define hicn_api_face_add u32 context; /* Type of face to add */ - vl_api_face_type_t type; + vl_api_hicn_face_type_t type; /* Face to add */ vl_api_hicn_face_union_t face; @@ -426,7 +426,7 @@ define hicn_api_faces_details u32 faceid; /* Type of face to add */ - vl_api_face_type_t type; + vl_api_hicn_face_type_t type; /* Face to add */ vl_api_hicn_face_union_t face; @@ -465,7 +465,7 @@ define hicn_api_face_get_reply u32 faceid; /* Type of face to add */ - vl_api_face_type_t type; + vl_api_hicn_face_type_t type; /* Face to add */ vl_api_hicn_face_union_t face; @@ -672,7 +672,7 @@ define hicn_api_punting_add u32 context; /* Type of punting rule */ - vl_api_punt_type_t type; + vl_api_hicn_punt_type_t type; /* Prefix to match */ vl_api_hicn_punting_union_t rule; @@ -696,7 +696,7 @@ define hicn_api_punting_del u32 context; /* Type of punting rule */ - vl_api_punt_type_t type; + vl_api_hicn_punt_type_t type; /* Prefix to match */ vl_api_hicn_punting_union_t rule; diff --git a/hicn-plugin/src/hicn.c b/hicn-plugin/src/hicn.c index a30eac4ff..b4a26ec8f 100644 --- a/hicn-plugin/src/hicn.c +++ b/hicn-plugin/src/hicn.c @@ -27,6 +27,7 @@ #include "faces/app/address_mgr.h" #include "face_db.h" #include "faces/udp/face_udp.h" +#include "route.h" hicn_main_t hicn_main; /* Module vars */ @@ -258,6 +259,9 @@ hicn_init (vlib_main_t * vm) hicn_face_module_init (vm); + /* Init the route module*/ + hicn_route_init(); + return error; } diff --git a/hicn-plugin/src/hicn.h b/hicn-plugin/src/hicn.h index 1b57ce9e2..b469a7ed9 100644 --- a/hicn-plugin/src/hicn.h +++ b/hicn-plugin/src/hicn.h @@ -16,7 +16,19 @@ #ifndef __HICN_H__ #define __HICN_H__ +#define ip_address_t hicn_ip_address_t +#define ip_address_cmp hicn_ip_address_cmp +#define ip_prefix_t hicn_ip_prefix_t +#define ip_prefix_cmp hicn_ip_prefix_cmp +#undef ip_prefix_len +#define ip_prefix_len hicn_ip_prefix_len #include <hicn/hicn.h> +#undef ip_address_t +#undef ip_address_cmp +#undef ip_prefix_t +#undef ip_prefix_cmp +#undef ip_prefix_len +#define ip_prefix_len(_a) (_a)->len #include <netinet/in.h> #include <vnet/ip/ip.h> diff --git a/hicn-plugin/src/hicn_api.c b/hicn-plugin/src/hicn_api.c index 639840647..4601ae316 100644 --- a/hicn-plugin/src/hicn_api.c +++ b/hicn-plugin/src/hicn_api.c @@ -23,8 +23,8 @@ #include <vlibmemory/api.h> #include <vnet/dpo/load_balance.h> #include <vnet/ip/ip_types_api.h> +#include <vnet/ip/ip_format_fns.h> -#include "hicn.h" #include "faces/ip/face_ip.h" #include "faces/udp/face_udp.h" #include "infra.h" @@ -41,55 +41,17 @@ #include "route.h" /* define message IDs */ -#include <hicn/hicn_msg_enum.h> +#include <hicn/hicn.api_enum.h> +#include <hicn/hicn.api_types.h> /* define generated endian-swappers */ #define vl_endianfun #include <hicn/hicn_all_api_h.h> #undef vl_endianfun -/* instantiate all the print functions we know about */ -#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) -#define vl_printfun -#include <hicn/hicn_all_api_h.h> -#undef vl_printfun - -/* Get the API version number */ -#define vl_api_version(n, v) static u32 api_version=(v); -#include <hicn/hicn_all_api_h.h> -#undef vl_api_version - #define REPLY_MSG_ID_BASE sm->msg_id_base #include <vlibapi/api_helper_macros.h> -/****** List of message types that this plugin understands ******/ - -#define foreach_hicn_plugin_api_msg \ - _(HICN_API_NODE_PARAMS_SET, hicn_api_node_params_set) \ - _(HICN_API_NODE_PARAMS_GET, hicn_api_node_params_get) \ - _(HICN_API_NODE_STATS_GET, hicn_api_node_stats_get) \ - _(HICN_API_FACE_IP_ADD, hicn_api_face_ip_add) \ - _(HICN_API_FACE_IP_DEL, hicn_api_face_ip_del) \ - _(HICN_API_FACE_IP_PARAMS_GET, hicn_api_face_ip_params_get) \ - _(HICN_API_FACE_ADD, hicn_api_face_add) \ - _(HICN_API_FACE_DEL, hicn_api_face_del) \ - _(HICN_API_FACES_DUMP, hicn_api_faces_dump) \ - _(HICN_API_FACE_GET, hicn_api_face_get) \ - _(HICN_API_FACE_STATS_DUMP, hicn_api_face_stats_dump) \ - _(HICN_API_ROUTE_GET, hicn_api_route_get) \ - _(HICN_API_ROUTES_DUMP, hicn_api_routes_dump) \ - _(HICN_API_ROUTE_NHOPS_ADD, hicn_api_route_nhops_add) \ - _(HICN_API_ROUTE_DEL, hicn_api_route_del) \ - _(HICN_API_ROUTE_NHOP_DEL, hicn_api_route_nhop_del) \ - _(HICN_API_STRATEGIES_GET, hicn_api_strategies_get) \ - _(HICN_API_STRATEGY_GET, hicn_api_strategy_get) \ - _(HICN_API_PUNTING_ADD, hicn_api_punting_add) \ - _(HICN_API_PUNTING_DEL, hicn_api_punting_del) \ - _(HICN_API_REGISTER_PROD_APP, hicn_api_register_prod_app) \ - _(HICN_API_FACE_PROD_DEL, hicn_api_face_prod_del) \ - _(HICN_API_REGISTER_CONS_APP, hicn_api_register_cons_app) \ - _(HICN_API_FACE_CONS_DEL, hicn_api_face_cons_del) - /****** SUPPORTING FUNCTION DECLARATIONS ******/ /* @@ -352,7 +314,7 @@ vl_api_hicn_api_face_add_t_handler (vl_api_hicn_api_face_add_t * mp) hicn_main_t *sm = &hicn_main; hicn_face_id_t face_id; - vl_api_face_type_t face_type = clib_net_to_host_u32(mp->type); + vl_api_hicn_face_type_t face_type = clib_net_to_host_u32(mp->type); switch (face_type) { @@ -1044,49 +1006,15 @@ vl_api_hicn_api_face_cons_del_t_handler (vl_api_hicn_api_face_cons_del_t * mp) /************************************************************************************/ -#define vl_msg_name_crc_list -#include <hicn/hicn_all_api_h.h> -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (hicn_main_t * hm, api_main_t * am) -{ -#define _(id,n,crc) \ - vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + hm->msg_id_base); - foreach_vl_msg_name_crc_hicn; -#undef _ -} - +#include <hicn/hicn.api.c> /* Set up the API message handling tables */ clib_error_t * hicn_api_plugin_hookup (vlib_main_t * vm) { hicn_main_t *hm = &hicn_main; - api_main_t *am = &api_main; - - /* Get a correctly-sized block of API message decode slots */ - u8 *name = format (0, "hicn_%08x%c", api_version, 0); - hm->msg_id_base = vl_msg_api_get_msg_ids ((char *) name, - VL_MSG_FIRST_AVAILABLE); - vec_free (name); - -#define _(N, n) \ - vl_msg_api_set_handlers(hm->msg_id_base + VL_API_##N, \ - #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_plugin_api_msg; -#undef _ - - /* - * Set up the (msg_name, crc, message-id) table - */ - setup_message_id_table (hm, am); + hm->msg_id_base = setup_message_id_table (); return 0; } diff --git a/hicn-plugin/src/hicn_api_test.c b/hicn-plugin/src/hicn_api_test.c index 704e66352..3e93300d7 100644 --- a/hicn-plugin/src/hicn_api_test.c +++ b/hicn-plugin/src/hicn_api_test.c @@ -24,46 +24,20 @@ #include <vnet/ip/ip6_packet.h> #include <vnet/ip/format.h> #include <vnet/ip/ip_types_api.h> +#include <vnet/ip/ip_format_fns.h> #define __plugin_msg_base hicn_test_main.msg_id_base #include <vlibapi/vat_helper_macros.h> +#include <vpp/api/vpe.api_types.h> + #include <hicn/hicn_api.h> #include "error.h" -// uword unformat_sw_if_index(unformat_input_t * input, va_list * args); /* Declare message IDs */ #include "hicn_msg_enum.h" -/* define message structures */ -#define vl_typedefs -#include <vpp/api/vpe_all_api_h.h> -#include <hicn/hicn_all_api_h.h> -#undef vl_typedefs - -/* Get CRC codes of the messages defined outside of this plugin */ -#define vl_msg_name_crc_list -#include <vpp/api/vpe_all_api_h.h> -#undef vl_msg_name_crc_list - -/* declare message handlers for each api */ - -#define vl_endianfun /* define message structures */ -#include "hicn_all_api_h.h" -#undef vl_endianfun - -/* instantiate all the print functions we know about */ -#define vl_print(handle, ...) -#define vl_printfun -#include "hicn_all_api_h.h" -#undef vl_printfun - -/* Get the API version number. */ -#define vl_api_version(n, v) static u32 api_version=(v); -#include "hicn_all_api_h.h" -#undef vl_api_version - /* SUPPORTING FUNCTIONS NOT LOADED BY VPP_API_TEST */ uword unformat_ip46_address (unformat_input_t * input, va_list * args) @@ -253,9 +227,8 @@ _(hicn_api_face_del_reply) \ _(hicn_api_route_nhops_add_reply) \ _(hicn_api_route_del_reply) \ _(hicn_api_route_nhop_del_reply) \ -_(hicn_api_punting_add_reply) \ -_(hicn_api_face_cons_del_reply) \ -_(hicn_api_face_prod_del_reply) +_(hicn_api_punting_add_reply) \ +_(hicn_api_punting_del_reply) #define _(n) \ static void vl_api_##n##_t_handler \ @@ -608,6 +581,34 @@ api_hicn_api_face_udp_add (vat_main_t * vam) return ret; } +static int +api_hicn_api_face_add (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + int ret = HICN_ERROR_NONE; + u32 type = ~0; + + /* Parse args required to build the message */ + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat + (input, "type %d", &type)); + else + { + break; + } + } + + vam->input = input; + + if (type == IP_FACE) + ret = api_hicn_api_face_ip_add(vam); + else if (type == UDP_FACE) + ret = api_hicn_api_face_udp_add(vam); + + return ret; +} + static void vl_api_hicn_api_face_add_reply_t_handler (vl_api_hicn_api_face_add_reply_t * rmp) @@ -1553,6 +1554,38 @@ api_hicn_api_udp_punting_add (vat_main_t * vam) return ret; } +static int +api_hicn_api_punting_add (vat_main_t * vam) +{ + unformat_input_t *input = vam->input; + u32 type = ~0; + int ret = 0; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "type %d", &type)) + {; + } + else + { + break; + } + } + + vam->input = input; + if (type == IP_PUNT) + ret = api_hicn_api_ip_punting_add (vam); + else if (type == UDP_PUNT) + ret = api_hicn_api_udp_punting_add (vam); + + return ret; +} + +static int +api_hicn_api_punting_del (vat_main_t * vam) +{ + return 0; +} static int api_hicn_api_register_prod_app (vat_main_t * vam) @@ -1753,90 +1786,7 @@ static void format_ip46_address, IP46_TYPE_ANY, &src_addr6); } -/* - * List of messages that the api test plugin sends, and that the data plane - * plugin processes - */ -#define foreach_vpe_api_msg \ -_(hicn_api_node_params_set, "PIT size <sz> CS size <sz>" \ - "PIT minlimit <f> PIT maxlimit <f> [disable] ") \ -_(hicn_api_node_params_get, "") \ -_(hicn_api_node_stats_get, "") \ -_(hicn_api_face_ip_del, "face <faceID>") \ -_(hicn_api_face_ip_add, "local <address> remote <address> intfc <swif>")\ -_(hicn_api_face_udp_add, "local <address> port <port> remote <address> port <port> intfc <swif>") \ -_(hicn_api_face_del, "face <faceID>") \ -_(hicn_api_faces_dump, "") \ -_(hicn_api_face_get, "face <faceID>") \ -_(hicn_api_face_stats_dump, "") \ -_(hicn_api_route_nhops_add, "add prefix <IP4/IP6>/<subnet> face <faceID> weight <weight>") \ -_(hicn_api_face_ip_params_get, "face <faceID>") \ -_(hicn_api_route_get, "prefix <IP4/IP6>/<subnet>") \ -_(hicn_api_routes_dump, "") \ -_(hicn_api_route_del, "prefix <IP4/IP6>/<subnet>") \ -_(hicn_api_route_nhop_del, "del prefix <IP4/IP6>/<subnet> face <faceID>") \ -_(hicn_api_strategies_get, "") \ -_(hicn_api_strategy_get, "strategy <id>") \ -_(hicn_api_ip_punting_add, "prefix <IP4/IP6>/<subnet> intfc <swif>") \ -_(hicn_api_udp_punting_add, "prefix <IP4/IP6>/<subnet> intfc <swif> sport <port> dport <port> ip4/ip6") \ -_(hicn_api_register_prod_app, "prefix <IP4/IP6>/<subnet> id <appif_id>") \ -_(hicn_api_face_prod_del, "face <faceID>") \ -_(hicn_api_register_cons_app, "") \ -_(hicn_api_face_cons_del, "face <faceID>") - -void -hicn_vat_api_hookup (vat_main_t * vam) -{ - hicn_test_main_t *sm = &hicn_test_main; - /* Hook up handlers for replies from the data plane plug-in */ -#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_vpe_api_reply_msg; -#undef _ - - /* API messages we can send */ -#define _(n, h) hash_set_mem (vam->function_by_name, #n, api_##n); - foreach_vpe_api_msg; -#undef _ - - /* Help strings */ -#define _(n, h) hash_set_mem (vam->help_by_name, #n, h); - foreach_vpe_api_msg; -#undef _ -} - -clib_error_t * -vat_plugin_register (vat_main_t * vam) -{ - hicn_test_main_t *sm = &hicn_test_main; - u8 *name; - - sm->vat_main = vam; - - /* Ask the vpp engine for the first assigned message-id */ - name = format (0, "hicn_%08x%c", api_version, 0); - sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name); - - /* Get the control ping ID */ -#define _(id,n,crc) \ - const char *id ## _CRC __attribute__ ((unused)) = #n "_" #crc; - foreach_vl_msg_name_crc_vpe; -#undef _ - sm->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC)); - - if (sm->msg_id_base != (u16) ~ 0) - hicn_vat_api_hookup (vam); - - vec_free (name); - - return 0; -} +#include <hicn/hicn.api_test.c> /* * fd.io coding-style-patch-verification: ON diff --git a/hicn-plugin/src/mapme.h b/hicn-plugin/src/mapme.h index 5b89e5709..071590ede 100644 --- a/hicn-plugin/src/mapme.h +++ b/hicn-plugin/src/mapme.h @@ -18,7 +18,7 @@ #include <vnet/dpo/load_balance.h> #include <vnet/buffer.h> -#include <hicn/hicn.h> +//#include <hicn/hicn.h> #include <hicn/mapme.h> #include "hicn.h" diff --git a/hicn-plugin/src/mapme_ack_node.c b/hicn-plugin/src/mapme_ack_node.c index 4f377447d..ebb12a124 100644 --- a/hicn-plugin/src/mapme_ack_node.c +++ b/hicn-plugin/src/mapme_ack_node.c @@ -14,8 +14,8 @@ */ #include <vnet/ip/ip6_packet.h> -#include <hicn/hicn.h> +#include "hicn.h" #include "mapme.h" #include "mapme_ack.h" #include "mapme_eventmgr.h" diff --git a/hicn-plugin/src/mapme_ctrl_node.c b/hicn-plugin/src/mapme_ctrl_node.c index 3985f3073..cef3d0944 100644 --- a/hicn-plugin/src/mapme_ctrl_node.c +++ b/hicn-plugin/src/mapme_ctrl_node.c @@ -18,8 +18,8 @@ */ #include <vnet/ip/ip6_packet.h> #include <vnet/dpo/load_balance.h> -#include <hicn/hicn.h> +#include "hicn.h" #include "mapme.h" #include "mapme_ctrl.h" #include "mapme_eventmgr.h" diff --git a/hicn-plugin/src/punt.c b/hicn-plugin/src/punt.c index 74d4c1056..d62cf992d 100644 --- a/hicn-plugin/src/punt.c +++ b/hicn-plugin/src/punt.c @@ -27,7 +27,6 @@ #include <vnet/ethernet/packet.h> #include <vnet/fib/fib_types.h> #include <vlib/global_funcs.h> -#include <hicn/hicn.h> #include "hicn.h" #include "infra.h" diff --git a/hicn-plugin/src/punt.h b/hicn-plugin/src/punt.h index 7ad96c791..0e821ccb7 100644 --- a/hicn-plugin/src/punt.h +++ b/hicn-plugin/src/punt.h @@ -18,7 +18,8 @@ #include <vppinfra/error.h> #include <vnet/fib/fib_types.h> -#include <hicn/hicn.h> +#include "hicn.h" +#include <vnet/classify/vnet_classify.h> #define HICN_CLASSIFY_TABLE_MEMORY_SIZE (2*1024*1024) // 2MB allocated for the classification table #define HICN_PUNTING_BUFFER_SIZE_32 (32) diff --git a/hicn-plugin/src/route.c b/hicn-plugin/src/route.c index 5ece5cfdb..85ad9f729 100644 --- a/hicn-plugin/src/route.c +++ b/hicn-plugin/src/route.c @@ -27,6 +27,10 @@ #include "error.h" #include "strategies/dpo_mw.h" +#define FIB_SOURCE_HICN 0x04 //Right after the FIB_SOURCE_INTERFACE priority + +fib_source_t hicn_fib_src; + int hicn_route_get_dpo (const fib_prefix_t * prefix, const dpo_id_t ** hicn_dpo, u32 * fib_index) @@ -44,7 +48,7 @@ hicn_route_get_dpo (const fib_prefix_t * prefix, */ *fib_index = fib_table_find_or_create_and_lock (prefix->fp_proto, HICN_FIB_TABLE, - FIB_SOURCE_PLUGIN_HI); + hicn_fib_src); fib_entry_index = fib_table_lookup_exact_match (*fib_index, prefix); if (fib_entry_index != FIB_NODE_INDEX_INVALID) @@ -81,7 +85,7 @@ hicn_route_get_dpo (const fib_prefix_t * prefix, * Remove the lock from the table. We keep one lock per route, not * per dpo */ - fib_table_unlock (*fib_index, prefix->fp_proto, FIB_SOURCE_PLUGIN_HI); + fib_table_unlock (*fib_index, prefix->fp_proto, hicn_fib_src); return ret; } @@ -220,12 +224,12 @@ hicn_route_add (hicn_face_id_t * face_id, u32 len, fib_node_index_t new_fib_node_index = fib_table_entry_special_dpo_add (fib_index, prefix, - FIB_SOURCE_PLUGIN_HI, + hicn_fib_src, FIB_ENTRY_FLAG_EXCLUSIVE, &dpo); /* We added a route, therefore add one lock to the table */ - fib_table_lock (fib_index, prefix->fp_proto, FIB_SOURCE_PLUGIN_HI); + fib_table_lock (fib_index, prefix->fp_proto, hicn_fib_src); dpo_unlock (&dpo); ret = @@ -259,13 +263,12 @@ hicn_route_del (fib_prefix_t * prefix) if (ret == HICN_ERROR_NONE) { - fib_table_entry_special_remove (HICN_FIB_TABLE, prefix, - FIB_SOURCE_PLUGIN_HI); + fib_table_entry_special_remove (HICN_FIB_TABLE, prefix, hicn_fib_src); /* * Remove the lock from the table. We keep one lock per route */ - fib_table_unlock (fib_index, prefix->fp_proto, FIB_SOURCE_PLUGIN_HI); + fib_table_unlock (fib_index, prefix->fp_proto, hicn_fib_src); } //Remember to remove the lock from the table when removing the entry return ret; @@ -289,12 +292,13 @@ hicn_route_del_nhop (fib_prefix_t * prefix, hicn_face_id_t face_id) vft_id = hicn_dpo_get_vft_id (hicn_dpo_id); dpo_vft = hicn_dpo_get_vft (vft_id); ret = dpo_vft->hicn_dpo_del_nh (face_id, hicn_dpo_id->dpoi_index, - prefix); + prefix); - hicn_dpo_ctx_t * dpo_ctx = dpo_vft->hicn_dpo_get_ctx(hicn_dpo_id->dpoi_index); + hicn_dpo_ctx_t *dpo_ctx = + dpo_vft->hicn_dpo_get_ctx (hicn_dpo_id->dpoi_index); if (ret == HICN_ERROR_NONE && !dpo_ctx->entry_count) - ret = hicn_route_del(prefix); + ret = hicn_route_del (prefix); } //Remember to remove the lock from the table when removing the entry return ret; @@ -349,7 +353,7 @@ hicn_route_set_strategy (fib_prefix_t * prefix, u8 strategy_id) fib_node_index_t new_fib_node_index = fib_table_entry_special_dpo_update (fib_index, prefix, - FIB_SOURCE_PLUGIN_HI, + hicn_fib_src, FIB_ENTRY_FLAG_EXCLUSIVE, &new_dpo_id); @@ -364,6 +368,13 @@ hicn_route_set_strategy (fib_prefix_t * prefix, u8 strategy_id) } +void +hicn_route_init () +{ + hicn_fib_src = fib_source_allocate ("hicn", + FIB_SOURCE_HICN, FIB_SOURCE_BH_API); +} + /* * fd.io coding-style-patch-verification: ON * diff --git a/hicn-plugin/src/route.h b/hicn-plugin/src/route.h index f6e32d8e0..5877f31a8 100644 --- a/hicn-plugin/src/route.h +++ b/hicn-plugin/src/route.h @@ -52,6 +52,9 @@ int hicn_route_del_nhop (fib_prefix_t * prefix, u32 face_id); int hicn_route_set_strategy (fib_prefix_t * prefix, u32 strategy_id); +/* Init route internal strustures */ +void +hicn_route_init(); #endif /* //__HICN_ROUTE__ */ /* diff --git a/hicn-plugin/src/strategy_dpo_ctx.h b/hicn-plugin/src/strategy_dpo_ctx.h index c6de6b78c..00b11412b 100644 --- a/hicn-plugin/src/strategy_dpo_ctx.h +++ b/hicn-plugin/src/strategy_dpo_ctx.h @@ -19,7 +19,6 @@ #include <vnet/dpo/dpo.h> #include <vnet/fib/fib_table.h> -#include "hicn.h" #include "params.h" #include "faces/face.h" diff --git a/hicn-plugin/vapi/CMakeLists.txt b/hicn-plugin/vapi/CMakeLists.txt new file mode 100644 index 000000000..03fd489ca --- /dev/null +++ b/hicn-plugin/vapi/CMakeLists.txt @@ -0,0 +1,60 @@ +# 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) + +# 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_LIBRARY_VAPICLIENT}) + +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/lib/includes/hicn/common.h b/lib/includes/hicn/common.h index 33323da1b..30f370241 100644 --- a/lib/includes/hicn/common.h +++ b/lib/includes/hicn/common.h @@ -143,6 +143,7 @@ struct iovec #include <vnet/ip/ip4_packet.h> // ip4_address_t #include <vnet/ip/ip6_packet.h> // ip6_address_t +#include <vnet/ip/ip46_address.h> #else diff --git a/libtransport/CMakeLists.txt b/libtransport/CMakeLists.txt index 75d5827cc..8f70208ab 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..af7fa5a03 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> @@ -32,12 +33,10 @@ #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[] = { @@ -51,16 +50,6 @@ const char *HICN_ERROR_STRING[] = { 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; } @@ -93,10 +82,11 @@ 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)) { + if(ip46_address_is_ip4((ip46_address_t *)&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 { @@ -108,7 +98,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 +116,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 +155,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 +178,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 +203,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 +213,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..9e701bf80 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_, ¶ms); 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_, ¶ms); + hicn_vapi_face_cons_del(VPPForwarderInterface::sock_, ¶ms); params.face_id = face_id2_; - hicn_vapi_face_cons_del(*(vapi_ctx_t *)VPPForwarderInterface::sock_, ¶ms); + hicn_vapi_face_cons_del(VPPForwarderInterface::sock_, ¶ms); } else { hicn_del_face_app_input_params params; params.face_id = face_id1_; - hicn_vapi_face_prod_del(*(vapi_ctx_t *)VPPForwarderInterface::sock_, ¶ms); + hicn_vapi_face_prod_del(VPPForwarderInterface::sock_, ¶ms); } 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..9f8000828 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_; }; @@ -81,4 +84,4 @@ class VPPForwarderInterface } // namespace transport -#endif
\ No newline at end of file +#endif diff --git a/libtransport/src/hicn/transport/protocols/raaqm.cc b/libtransport/src/hicn/transport/protocols/raaqm.cc index ec7ce19cc..21a59bc9a 100644 --- a/libtransport/src/hicn/transport/protocols/raaqm.cc +++ b/libtransport/src/hicn/transport/protocols/raaqm.cc @@ -104,7 +104,6 @@ void RaaqmTransportProtocol::reset() { index_manager_->setFirstSuffix(name->getSuffix()); std::queue<Interest::Ptr> empty; std::swap(interest_to_retransmit_, empty); - current_window_size_ = 1; stats_.reset(); // Reset reassembly component diff --git a/scripts/build-extras.sh b/scripts/build-extras.sh index cbf2113ba..4112298a8 100644 --- a/scripts/build-extras.sh +++ b/scripts/build-extras.sh @@ -22,10 +22,10 @@ PACKAGECLOUD_RELEASE_REPO_DEB="https://packagecloud.io/install/repositories/fdio PACKAGECLOUD_RELEASE_REPO_RPM="https://packagecloud.io/install/repositories/fdio/release/script.rpm.sh" VPP_GIT_REPO="https://git.fd.io/vpp" -VPP_BRANCH="stable/1908" +VPP_BRANCH="stable/2001" -VPP_VERSION_DEB="19.08.1-release" -VPP_VERSION_RPM="19.08.1-release.x86_64" +VPP_VERSION_DEB="20.01-release" +VPP_VERSION_RPM="20.01-release.x86_64" BUILD_TOOLS_UBUNTU="build-essential doxygen" LIBSSL_LIBEVENT_UBUNTU="libevent-dev libssl-dev" diff --git a/scripts/build-packages.sh b/scripts/build-packages.sh index 3efd92cc4..6ec32c0a7 100644 --- a/scripts/build-packages.sh +++ b/scripts/build-packages.sh @@ -22,10 +22,10 @@ PACKAGECLOUD_RELEASE_REPO_DEB="https://packagecloud.io/install/repositories/fdio PACKAGECLOUD_RELEASE_REPO_RPM="https://packagecloud.io/install/repositories/fdio/release/script.rpm.sh" VPP_GIT_REPO="https://git.fd.io/vpp" -VPP_BRANCH="stable/1908" +VPP_BRANCH="stable/2001" -VPP_VERSION_DEB="19.08.1-release" -VPP_VERSION_RPM="19.08.1-release.x86_64" +VPP_VERSION_DEB="20.01-release" +VPP_VERSION_RPM="20.01-release.x86_64" BUILD_TOOLS_UBUNTU="build-essential doxygen" LIBSSL_LIBEVENT_UBUNTU="libevent-dev libssl-dev" @@ -44,6 +44,22 @@ DEPS_UBUNTU="libparc-dev \ sysrepo \ python3-ply" + +DEPS_UBUNTU_NOVERSION="libparc-dev \ + libmemif-dev \ + libmemif \ + libasio-dev \ + libconfig-dev \ + libcurl4-openssl-dev \ + vpp \ + vpp-dev \ + libvppinfra \ + libvppinfra-dev \ + vpp-plugin-core \ + libyang \ + sysrepo \ + python3-ply" + DEPS_CMAKE_UBUNTU="curl" # BUILD_TOOLS_GROUP_CENTOS="'Development Tools'" @@ -102,7 +118,7 @@ setup_fdio_repo() { if [ "${DISTRIB_ID}" == "ubuntu" ]; then rm -r /etc/apt/sources.list.d/* - curl -s ${PACKAGECLOUD_RELEASE_REPO_DEB} | sudo bash + curl -s ${PACKAGECLOUD_RELEASE_REPO_DEB} | sudo bash elif [ "${DISTRIB_ID}" == "centos" ]; then curl -s ${PACKAGECLOUD_RELEASE_REPO_RPM} | sudo bash curl ${LATEST_EPEL_REPO} > epel-release-latest-7.noarch.rpm @@ -140,7 +156,7 @@ setup() { # Install dependencies if [ ${DISTRIB_ID} == "ubuntu" ]; then - echo ${BUILD_TOOLS_UBUNTU} ${DEPS_UBUNTU} | xargs sudo ${apt_get} install -y --allow-unauthenticated --no-install-recommends + echo ${BUILD_TOOLS_UBUNTU} ${DEPS_UBUNTU_NOVERSION} | xargs sudo ${apt_get} install -y --allow-unauthenticated --no-install-recommends elif [ ${DISTRIB_ID} == "centos" ]; then # echo ${BUILD_TOOLS_GROUP_CENTOS} | xargs sudo yum groupinstall -y --nogpgcheck echo ${DEPS_CENTOS} | xargs sudo yum install -y --nogpgcheck |