diff options
Diffstat (limited to 'ctrl/libhicnctrl/includes')
-rw-r--r-- | ctrl/libhicnctrl/includes/CMakeLists.txt | 17 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/ctrl.h | 2 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl.h | 2 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/api.h | 495 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/face.h | 206 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/hicn-light-ng.h | 427 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/hicn-light.h (renamed from ctrl/libhicnctrl/includes/hicn/ctrl/commands.h) | 14 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/route.h | 27 |
8 files changed, 818 insertions, 372 deletions
diff --git a/ctrl/libhicnctrl/includes/CMakeLists.txt b/ctrl/libhicnctrl/includes/CMakeLists.txt index 50cfa4ad5..1a90690a4 100644 --- a/ctrl/libhicnctrl/includes/CMakeLists.txt +++ b/ctrl/libhicnctrl/includes/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2017-2019 Cisco and/or its affiliates. +# Copyright (c) 2021-2022 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: @@ -11,17 +11,24 @@ # See the License for the specific language governing permissions and # limitations under the License. -set(LIBHICNCTRL_INCLUDE_DIRS - ${CMAKE_CURRENT_SOURCE_DIR} "" +############################################################## +# Public headers directory +############################################################## +set(Libhicnctrl_INCLUDE_DIRS + ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "" FORCE ) + +############################################################## +# To install header files +############################################################## set(TO_INSTALL_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/ctrl.h ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ctrl/api.h - ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ctrl/commands.h - ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ctrl/face.h + ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ctrl/hicn-light.h + ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ctrl/hicn-light-ng.h ${CMAKE_CURRENT_SOURCE_DIR}/hicn/ctrl/route.h PARENT_SCOPE ) diff --git a/ctrl/libhicnctrl/includes/ctrl.h b/ctrl/libhicnctrl/includes/ctrl.h index e61b7a482..477afd152 100644 --- a/ctrl/libhicnctrl/includes/ctrl.h +++ b/ctrl/libhicnctrl/includes/ctrl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2021 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: diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl.h b/ctrl/libhicnctrl/includes/hicn/ctrl.h index e61b7a482..477afd152 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2021 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: diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h index b5a968800..8a59cf4d8 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/api.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/api.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 Cisco and/or its affiliates. + * Copyright (c) 2021 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: @@ -67,15 +67,24 @@ #include <stdbool.h> #include <stdint.h> +#include <stddef.h> // object_offset_t #include <hicn/util/ip_address.h> -#include <hicn/ctrl/commands.h> -#include "face.h" +#include <hicn/face.h> +#include <hicn/strategy.h> +/* + * This has to be common between hicn-light and hicn-plugin. We now we keep the + * minimum of the two + */ +#define SYMBOLIC_NAME_LEN 16 #define HICN_DEFAULT_PORT 9695 #define HOTFIXMARGIN 0 +#define INVALID_FACE_ID ~0 +#define INVALID_NETDEVICE_ID ~0 + /** * \brief Defines the default size for the allocated data arrays holding the * results of API calls. @@ -99,26 +108,70 @@ * Message helper types and aliases ******************************************************************************/ -#define foreach_command \ - _(UNDEFINED) \ - _(CREATE) \ - _(UPDATE) \ - _(DELETE) \ - _(LIST) \ - _(SET) \ +/* Action */ + +#define foreach_action \ + _(UNDEFINED) \ + _(CREATE) \ + _(UPDATE) \ + _(DELETE) \ + _(LIST) \ + _(SET) \ + _(SERVE) \ + _(STORE) \ + _(CLEAR) \ _(N) typedef enum { #define _(x) ACTION_##x, - foreach_command + foreach_action #undef _ } hc_action_t; +extern const char *action_str[]; + +#define action_str(x) action_str[x] + +hc_action_t action_from_str(const char *action_str); + +/* Object type */ + +#define foreach_object \ + _(UNDEFINED) \ + _(CONNECTION) \ + _(LISTENER) \ + _(ROUTE) \ + _(FACE) \ + _(STRATEGY) \ + _(PUNTING) \ + _(POLICY) \ + _(CACHE) \ + _(MAPME) \ + _(LOCAL_PREFIX) \ + _(PROBE) \ + _(SUBSCRIPTION) \ + _(N) + +typedef enum { +#define _(x) OBJECT_##x, + foreach_object +#undef _ +} hc_object_type_t; + +extern const char *object_str[]; + +#define object_str(x) object_str[x] + +hc_object_type_t object_from_str(const char *object_str); + +#define IS_VALID_OBJECT_TYPE(x) IS_VALID_ENUM_TYPE(OBJECT, x) +#define IS_VALID_ACTION(x) IS_VALID_ENUM_TYPE(ACTION, x) + /** * \brief hICN control message header */ typedef struct hc_msg_s hc_msg_t; - +typedef struct hc_result_s hc_result_t; /****************************************************************************** * Control Data ******************************************************************************/ @@ -140,7 +193,8 @@ typedef struct hc_data_s { bool complete; /* Callbacks */ - data_callback_t complete_cb; // XXX int (*complete_cb)(struct hc_data_s * data); + data_callback_t + complete_cb; // XXX int (*complete_cb)(struct hc_data_s * data); void *complete_cb_data; int ret; } hc_data_t; @@ -149,7 +203,8 @@ typedef struct hc_data_s { * Create a structure holding the results of an hICN control request. * \result The newly create data structure. */ -hc_data_t *hc_data_create(size_t in_element_size, size_t out_element_size, data_callback_t complete_cb); +hc_data_t *hc_data_create(size_t in_element_size, size_t out_element_size, + data_callback_t complete_cb); /** * Free a structure holding the results of an hICN control request. @@ -214,38 +269,49 @@ int hc_data_reset(hc_data_t *data); * \param [out] found - A pointer to the element, or NULL if not found. * \return Error code */ -#define GENERATE_FIND_HEADER(TYPE) \ -int \ -hc_ ## TYPE ## _find(hc_data_t * data, const hc_ ## TYPE ## _t * element, \ - hc_ ## TYPE ## _t **found) - -#define GENERATE_FIND(TYPE) \ -int \ -hc_ ## TYPE ## _find(hc_data_t * data, const hc_ ## TYPE ## _t * element, \ - hc_ ## TYPE ## _t **found) \ -{ \ - foreach_type(hc_ ## TYPE ## _t, x, data) { \ - if (hc_ ## TYPE ## _cmp(x, element) == 0) { \ - *found = x; \ - return 0; \ - } \ - }; \ - *found = NULL; /* this is optional */ \ - return 0; \ -} +#define GENERATE_FIND_HEADER(TYPE) \ + int hc_##TYPE##_find(hc_data_t *data, const hc_##TYPE##_t *element, \ + hc_##TYPE##_t **found) + +#define GENERATE_FIND(TYPE) \ + int hc_##TYPE##_find(hc_data_t *data, const hc_##TYPE##_t *element, \ + hc_##TYPE##_t **found) { \ + foreach_type(hc_##TYPE##_t, x, data) { \ + if (hc_##TYPE##_cmp(x, element) == 0) { \ + *found = x; \ + return 0; \ + } \ + }; \ + *found = NULL; /* this is optional */ \ + return 0; \ + } /****************************************************************************** * Control socket ******************************************************************************/ -/* This should be at least equal to the maximum packet size */ -#define RECV_BUFLEN 8192 +/* With UDP, the buffer should be able to receieve a full packet, and thus MTU + * (max 9000) is sufficient. Messages will be received fully one by one. + * With TCP, the buffer should be at least able to receive a message header and + * the maximum size of a data element, so any reasonable size will be correct, + * it might just optimize performance. Messages might arrive in chunks that the + * library is able to parse. + */ +#define JUMBO_MTU 9000 +#define RECV_BUFLEN 65535 + +#define foreach_forwarder_type \ + _(UNDEFINED) \ + _(HICNLIGHT) \ + _(HICNLIGHT_NG) \ + _(VPP) \ + _(N) typedef enum { - HICNLIGHT, - VPP, - UNDEFINED -} forwarder_t; +#define _(x) x, + foreach_forwarder_type +#undef _ +} forwarder_type_t; /** * \brief Holds the state of an hICN control socket @@ -257,22 +323,26 @@ typedef struct hc_sock_s hc_sock_t; * \param [in] url - The URL to connect to. * \return an hICN control socket */ -hc_sock_t * -hc_sock_create_url(const char * url); +hc_sock_t *hc_sock_create_url(const char *url); /** * \brief Create an hICN control socket using the provided forwarder. * \return an hICN control socket */ -hc_sock_t * -hc_sock_create_forwarder(forwarder_t forwarder); +hc_sock_t *hc_sock_create_forwarder(forwarder_type_t forwarder); + +/** + * \brief Create an hICN control socket using the provided forwarder and a URL. + * \return an hICN control socket + */ +hc_sock_t *hc_sock_create_forwarder_url(forwarder_type_t forwarder, + const char *url); /** * \brief Create an hICN control socket using the default connection type. * \return an hICN control socket */ -hc_sock_t * -hc_sock_create(void); +hc_sock_t *hc_sock_create(void); /** * \brief Frees an hICN control socket @@ -324,7 +394,7 @@ int hc_sock_get_available(hc_sock_t *s, u8 **buffer, size_t *size); * \param [in] msglen - Length of the message to send * \return Error code */ -int hc_sock_send(hc_sock_t *s, hc_msg_t *msg, size_t msglen, int seq); +int hc_sock_send(hc_sock_t *s, hc_msg_t *msg, size_t msglen, uint32_t seq); /** * \brief Helper for reading socket contents @@ -356,6 +426,13 @@ int hc_sock_callback(hc_sock_t *s, hc_data_t **data); */ int hc_sock_reset(hc_sock_t *s); +void hc_sock_increment_woff(hc_sock_t *s, size_t bytes); + +int hc_sock_prepare_send(hc_sock_t *s, hc_result_t *result, + data_callback_t complete_cb, void *complete_cb_data); + +int hc_sock_set_recv_timeout_ms(hc_sock_t *s, long timeout_ms); + /****************************************************************************** * Command-specific structures and functions ******************************************************************************/ @@ -420,50 +497,11 @@ int hc_sock_reset(hc_sock_t *s); VAR < (TYPE *)(data->buffer + data->size * data->out_element_size); \ VAR++) -/** - * New type is defined to reconciliate different enum for add and list. - * Also, values not implemented have been removed for clarity. - */ -#define foreach_connection_type \ - _(UNDEFINED) \ - _(TCP) \ - _(UDP) \ - _(HICN) \ - _(N) - -typedef enum { -#define _(x) CONNECTION_TYPE_##x, - foreach_connection_type -#undef _ -} hc_connection_type_t; - -#define MAXSZ_HC_CONNECTION_TYPE_ 9 -#define MAXSZ_HC_CONNECTION_TYPE MAXSZ_HC_CONNECTION_TYPE_ + NULLTERM + HOTFIXMARGIN - -extern const char *connection_type_str[]; - -hc_connection_type_t connection_type_from_str(const char *str); - -/* Same order as connection_state_t in hicn/core/connectionState.h */ -#define foreach_connection_state \ - _(UNDEFINED) \ - _(DOWN) \ - _(UP) \ - _(N) - -typedef enum { -#define _(x) HC_CONNECTION_STATE_##x, - foreach_connection_state -#undef _ -} hc_connection_state_t; - -#define MAXSZ_HC_CONNECTION_STATE_ 9 -#define MAXSZ_HC_CONNECTION_STATE MAXSZ_HC_CONNECTION_STATE_ + NULLTERM - -extern const char *connection_state_str[]; - typedef int (*HC_PARSE)(const u8 *, u8 *); +#define INPUT_ERROR -2 +#define UNSUPPORTED_CMD_ERROR -3 + /*----------------------------------------------------------------------------* * Listeners *----------------------------------------------------------------------------*/ @@ -473,27 +511,28 @@ typedef struct { char name[SYMBOLIC_NAME_LEN]; /* K.w */ // XXX clarify what used for char interface_name[INTERFACE_LEN]; /* Kr. */ u32 id; - hc_connection_type_t type; /* .rw */ - int family; /* .rw */ - ip_address_t local_addr; /* .rw */ - u16 local_port; /* .rw */ + face_type_t type; /* .rw */ + int family; /* .rw */ + ip_address_t local_addr; /* .rw */ + u16 local_port; /* .rw */ } hc_listener_t; int hc_listener_create(hc_sock_t *s, hc_listener_t *listener); /* listener_found might eventually be allocated, and needs to be freed */ +hc_result_t *hc_listener_create_conf(hc_sock_t *s, hc_listener_t *listener); int hc_listener_get(hc_sock_t *s, hc_listener_t *listener, hc_listener_t **listener_found); int hc_listener_delete(hc_sock_t *s, hc_listener_t *listener); int hc_listener_list(hc_sock_t *s, hc_data_t **pdata); +hc_result_t *hc_listener_list_conf(hc_sock_t *s); int hc_listener_validate(const hc_listener_t *listener); int hc_listener_cmp(const hc_listener_t *l1, const hc_listener_t *l2); -int hc_listener_parse(void *in, hc_listener_t *listener); #define foreach_listener(VAR, data) foreach_type(hc_listener_t, VAR, data) #define MAXSZ_HC_LISTENER_ \ - INTERFACE_LEN + SPACE + MAXSZ_URL_ + SPACE + MAXSZ_HC_CONNECTION_TYPE_ + INTERFACE_LEN + SPACE + MAXSZ_URL_ + SPACE + MAXSZ_FACE_TYPE_ #define MAXSZ_HC_LISTENER MAXSZ_HC_LISTENER_ + NULLTERM GENERATE_FIND_HEADER(listener); @@ -506,28 +545,30 @@ int hc_listener_snprintf(char *s, size_t size, hc_listener_t *listener); /* * NOTE : - * - interface_name is mainly used to derive listeners from connections, but is - * not itself used to create connections. + * - interface_name is mainly used to derive listeners from connections, + * but is not itself used to create connections. */ typedef struct { u32 id; /* Kr. */ char name[SYMBOLIC_NAME_LEN]; /* K.w */ char interface_name[INTERFACE_LEN]; /* Kr. */ - hc_connection_type_t type; /* .rw */ + face_type_t type; /* .rw */ int family; /* .rw */ ip_address_t local_addr; /* .rw */ u16 local_port; /* .rw */ ip_address_t remote_addr; /* .rw */ u16 remote_port; /* .rw */ - hc_connection_state_t admin_state; /* .rw */ + face_state_t admin_state; /* .rw */ #ifdef WITH_POLICY - uint32_t priority; /* .rw */ - policy_tags_t tags; /* .rw */ -#endif /* WITH_POLICY */ - hc_connection_state_t state; /* .r. */ + uint32_t priority; /* .rw */ + policy_tags_t tags; /* .rw */ +#endif /* WITH_POLICY */ + face_state_t state; /* .r. */ } hc_connection_t; int hc_connection_create(hc_sock_t *s, hc_connection_t *connection); +hc_result_t *hc_connection_create_conf(hc_sock_t *s, + hc_connection_t *connection); /* connection_found will be allocated, and must be freed */ int hc_connection_get(hc_sock_t *s, hc_connection_t *connection, hc_connection_t **connection_found); @@ -536,6 +577,8 @@ int hc_connection_update_by_id(hc_sock_t *s, int hc_connection_id, int hc_connection_update(hc_sock_t *s, hc_connection_t *connection_current, hc_connection_t *connection_updated); int hc_connection_delete(hc_sock_t *s, hc_connection_t *connection); +hc_result_t *hc_connection_delete_conf(hc_sock_t *s, + hc_connection_t *connection); /* int hc_connection_remove_by_id(hc_sock_t * s, char * name); int hc_connection_remove_by_name(hc_sock_t * s, char * name); @@ -544,19 +587,21 @@ int hc_connection_list(hc_sock_t *s, hc_data_t **pdata); int hc_connection_validate(const hc_connection_t *connection); int hc_connection_cmp(const hc_connection_t *c1, const hc_connection_t *c2); -int hc_connection_parse(void *in, hc_connection_t *connection); -int hc_connection_set_admin_state(hc_sock_t * s, const char * conn_id_or_name, face_state_t state); +int hc_connection_set_admin_state(hc_sock_t *s, const char *conn_id_or_name, + face_state_t state); #ifdef WITH_POLICY -int hc_connection_set_priority(hc_sock_t * s, const char * conn_id_or_name, uint32_t priority); -int hc_connection_set_tags(hc_sock_t * s, const char * conn_id_or_name, policy_tags_t tags); +int hc_connection_set_priority(hc_sock_t *s, const char *conn_id_or_name, + uint32_t priority); +int hc_connection_set_tags(hc_sock_t *s, const char *conn_id_or_name, + policy_tags_t tags); #endif /* WITH_POLICY */ #define foreach_connection(VAR, data) foreach_type(hc_connection_t, VAR, data) -#define MAXSZ_HC_CONNECTION_ \ - MAXSZ_HC_CONNECTION_STATE_ + INTERFACE_LEN + SPACE + 2 * MAXSZ_URL_ + \ - MAXSZ_HC_CONNECTION_TYPE_ + SPACES(3) +#define MAXSZ_HC_CONNECTION_ \ + MAXSZ_FACE_STATE_ + INTERFACE_LEN + SPACE + 2 * MAXSZ_URL_ + \ + MAXSZ_FACE_TYPE_ + SPACES(3) #define MAXSZ_HC_CONNECTION MAXSZ_HC_CONNECTION_ + NULLTERM GENERATE_FIND_HEADER(connection); @@ -591,14 +636,17 @@ typedef struct { */ int hc_face_create(hc_sock_t *s, hc_face_t *face); int hc_face_get(hc_sock_t *s, hc_face_t *face, hc_face_t **face_found); -int hc_face_delete(hc_sock_t *s, hc_face_t *face); +int hc_face_delete(hc_sock_t *s, hc_face_t *face, uint8_t delete_listener); int hc_face_list(hc_sock_t *s, hc_data_t **pdata); int hc_face_list_async(hc_sock_t *s); //, hc_data_t ** pdata); -int hc_face_set_admin_state(hc_sock_t * s, const char * conn_id_or_name, face_state_t state); +int hc_face_set_admin_state(hc_sock_t *s, const char *conn_id_or_name, + face_state_t state); #ifdef WITH_POLICY -int hc_face_set_priority(hc_sock_t * s, const char * conn_id_or_name, uint32_t priority); -int hc_face_set_tags(hc_sock_t * s, const char * conn_id_or_name, policy_tags_t tags); +int hc_face_set_priority(hc_sock_t *s, const char *conn_id_or_name, + uint32_t priority); +int hc_face_set_tags(hc_sock_t *s, const char *conn_id_or_name, + policy_tags_t tags); #endif /* WITH_POLICY */ #define foreach_face(VAR, data) foreach_type(hc_face_t, VAR, data) @@ -609,7 +657,8 @@ int hc_face_set_tags(hc_sock_t * s, const char * conn_id_or_name, policy_tags_t #define MAXSZ_FACE_NAME_ SYMBOLIC_NAME_LEN #define MAXSZ_FACE_NAME MAXSZ_FACE_NAME_ + NULLTERM -#define MAXSZ_HC_FACE_ MAXSZ_FACE_ID_ + MAXSZ_FACE_NAME_ + MAXSZ_FACE_ + 5 + HOTFIXMARGIN +#define MAXSZ_HC_FACE_ \ + MAXSZ_FACE_ID_ + MAXSZ_FACE_NAME_ + MAXSZ_FACE_ + 5 + HOTFIXMARGIN #define MAXSZ_HC_FACE MAXSZ_HC_FACE_ + NULLTERM int hc_face_snprintf(char *s, size_t size, hc_face_t *face); @@ -619,20 +668,20 @@ int hc_face_snprintf(char *s, size_t size, hc_face_t *face); *----------------------------------------------------------------------------*/ typedef struct { - face_id_t face_id; /* Kr. */ - int family; /* Krw */ - ip_address_t remote_addr; /* krw */ - u8 len; /* krw */ - u16 cost; /* .rw */ - hc_face_t face; + face_id_t face_id; /* Kr. use when name == NULL */ + char name[SYMBOLIC_NAME_LEN]; /* Kr. use by default vs face_id */ + int family; /* Krw */ + ip_address_t remote_addr; /* krw */ + u8 len; /* krw */ + u16 cost; /* .rw */ + hc_face_t face; /* TODO remove, used by hicn_plugin_api */ } hc_route_t; -int hc_route_parse(void *in, hc_route_t *route); - -int hc_route_create(hc_sock_t * s, hc_route_t * route); -int hc_route_delete(hc_sock_t * s, hc_route_t * route); -int hc_route_list(hc_sock_t * s, hc_data_t ** pdata); -int hc_route_list_async(hc_sock_t * s); +int hc_route_create(hc_sock_t *s, hc_route_t *route); +hc_result_t *hc_route_create_conf(hc_sock_t *s, hc_route_t *route); +int hc_route_delete(hc_sock_t *s, hc_route_t *route); +int hc_route_list(hc_sock_t *s, hc_data_t **pdata); +int hc_route_list_async(hc_sock_t *s); #define foreach_route(VAR, data) foreach_type(hc_route_t, VAR, data) @@ -646,6 +695,7 @@ int hc_route_list_async(hc_sock_t * s); #define MAXSZ_HC_ROUTE MAXSZ_HC_ROUTE_ + NULLTERM int hc_route_snprintf(char *s, size_t size, hc_route_t *route); +int hc_route_validate(const hc_route_t *route); /*----------------------------------------------------------------------------* * Punting @@ -653,9 +703,9 @@ int hc_route_snprintf(char *s, size_t size, hc_route_t *route); typedef struct { face_id_t face_id; /* Kr. */ // XXX listener id, could be NULL for all ? - int family; /* Krw */ - ip_address_t prefix; /* krw */ - u8 prefix_len; /* krw */ + int family; /* Krw */ + ip_address_t prefix; /* krw */ + u8 prefix_len; /* krw */ } hc_punting_t; int hc_punting_create(hc_sock_t *s, hc_punting_t *punting); @@ -666,7 +716,6 @@ int hc_punting_list(hc_sock_t *s, hc_data_t **pdata); int hc_punting_validate(const hc_punting_t *punting); int hc_punting_cmp(const hc_punting_t *c1, const hc_punting_t *c2); -int hc_punting_parse(void *in, hc_punting_t *punting); #define foreach_punting(VAR, data) foreach_type(hc_punting_t, VAR, data) @@ -681,8 +730,23 @@ int hc_punting_snprintf(char *s, size_t size, hc_punting_t *punting); * Cache *----------------------------------------------------------------------------*/ -int hc_cache_set_store(hc_sock_t *s, int enabled); -int hc_cache_set_serve(hc_sock_t *s, int enabled); +typedef struct { + uint8_t serve; // 1 = on, 0 = off + uint8_t store; // 1 = on, 0 = off +} hc_cache_t; + +typedef struct { + bool store; + bool serve; + size_t cs_size; + size_t num_stale_entries; +} hc_cache_info_t; + +int hc_cache_set_store(hc_sock_t *s, hc_cache_t *cache); +int hc_cache_set_serve(hc_sock_t *s, hc_cache_t *cache); +int hc_cache_clear(hc_sock_t *s, hc_cache_t *cache); +int hc_cache_list(hc_sock_t *s, hc_data_t **pdata); +int hc_cache_snprintf(char *s, size_t size, const hc_cache_info_t *cache_info); /*----------------------------------------------------------------------------* * Strategy @@ -691,7 +755,13 @@ int hc_cache_set_serve(hc_sock_t *s, int enabled); #define MAXSZ_STRATEGY_NAME 255 typedef struct { + // The name is not set by the controller + // but populated by the daemon char name[MAXSZ_STRATEGY_NAME]; + strategy_type_t type; + ip_address_t address, local_address; + int family, local_family; + u8 len, local_len; } hc_strategy_t; int hc_strategy_list(hc_sock_t *s, hc_data_t **data); @@ -704,8 +774,11 @@ int hc_strategy_list(hc_sock_t *s, hc_data_t **data); int hc_strategy_snprintf(char *s, size_t size, hc_strategy_t *strategy); // per prefix -int hc_strategy_set(hc_sock_t *s /* XXX */); - +int hc_strategy_set(hc_sock_t *s, hc_strategy_t *strategy); +hc_result_t *hc_strategy_set_conf(hc_sock_t *s, hc_strategy_t *strategy); +int hc_strategy_add_local_prefix(hc_sock_t *s, hc_strategy_t *strategy); +hc_result_t *hc_strategy_add_local_prefix_conf(hc_sock_t *s, + hc_strategy_t *strategy); /*----------------------------------------------------------------------------* * WLDR *----------------------------------------------------------------------------*/ @@ -717,10 +790,45 @@ int hc_wldr_set(hc_sock_t *s /* XXX */); * MAP-Me *----------------------------------------------------------------------------*/ -int hc_mapme_set(hc_sock_t *s, int enabled); -int hc_mapme_set_discovery(hc_sock_t *s, int enabled); -int hc_mapme_set_timescale(hc_sock_t *s, double timescale); -int hc_mapme_set_retx(hc_sock_t *s, double timescale); +typedef enum { + MAPME_TARGET_ENABLE, + MAPME_TARGET_DISCOVERY, + MAPME_TARGET_TIMESCALE, + MAPME_TARGET_RETX, +} mapme_target_t; + +static inline mapme_target_t mapme_target_from_str(char *mapme_target_str) { + if (strcasecmp(mapme_target_str, "enable") == 0) + return MAPME_TARGET_ENABLE; + else if (strcasecmp(mapme_target_str, "discovery") == 0) + return MAPME_TARGET_DISCOVERY; + else if (strcasecmp(mapme_target_str, "timescale") == 0) + return MAPME_TARGET_TIMESCALE; + else + return MAPME_TARGET_RETX; +} + +#define MAX_MAPME_ARG_LEN 30 + +typedef struct { + mapme_target_t target; + // Command argument stored as a string + // before being parsed into 'enabled' or 'timescale' + char unparsed_arg[MAX_MAPME_ARG_LEN]; + + uint8_t enabled; // 1 = on, 0 = off + uint32_t timescale; // Milliseconds + + ip_address_t address; + int family; + u8 len; +} hc_mapme_t; + +int hc_mapme_set(hc_sock_t *s, hc_mapme_t *mapme); +int hc_mapme_set_discovery(hc_sock_t *s, hc_mapme_t *mapme); +int hc_mapme_set_timescale(hc_sock_t *s, hc_mapme_t *mapme); +int hc_mapme_set_retx(hc_sock_t *s, hc_mapme_t *mapme); +int hc_mapme_send_update(hc_sock_t *s, hc_mapme_t *mapme); /*----------------------------------------------------------------------------* * Policies @@ -732,11 +840,9 @@ typedef struct { int family; /* Krw */ ip_address_t remote_addr; /* krw */ u8 len; /* krw */ - hicn_policy_t policy; /* .rw */ + hicn_policy_t policy; /* .rw */ } hc_policy_t; -int hc_policy_parse(void *in, hc_policy_t *policy); - int hc_policy_create(hc_sock_t *s, hc_policy_t *policy); int hc_policy_delete(hc_sock_t *s, hc_policy_t *policy); int hc_policy_list(hc_sock_t *s, hc_data_t **pdata); @@ -748,7 +854,114 @@ int hc_policy_list(hc_sock_t *s, hc_data_t **pdata); #define MAXSZ_HC_POLICY MAXSZ_HC_POLICY_ + NULLTERM int hc_policy_snprintf(char *s, size_t size, hc_policy_t *policy); +int hc_policy_validate(const hc_policy_t *policy); #endif /* WITH_POLICY */ +/*----------------------------------------------------------------------------* + * Subscription + *----------------------------------------------------------------------------*/ +// Topics + +#undef PUNTING // TODO(eloparco): Undefined to avoid collisions + // Fix the collision + +// Used only to create 'hc_topic_t' +typedef struct { +#define _(x) char x; + foreach_object +#undef _ +} object_offset_t; + +// Flags for topic subscriptions +typedef enum { +#define _(x) TOPIC_##x = (1 << offsetof(object_offset_t, x)), + foreach_object +#undef _ +} hc_topic_t; + +static inline hc_object_type_t object_from_topic(hc_topic_t topic) { +#define _(x) \ + if (topic == TOPIC_##x) return OBJECT_##x; + foreach_object +#undef _ + return OBJECT_UNDEFINED; +} + +#define NUM_TOPICS OBJECT_N // Because a topic is created for each object +#define ALL_TOPICS ~0 + +// Subscriptions +typedef uint32_t hc_topics_t; +typedef struct { + hc_topics_t topics; +} hc_subscription_t; + +int hc_subscription_create(hc_sock_t *s, hc_subscription_t *subscription); +int hc_subscription_delete(hc_sock_t *s, hc_subscription_t *subscription); +hc_result_t *hc_subscription_create_conf(hc_sock_t *s, + hc_subscription_t *subscription); +hc_result_t *hc_subscription_delete_conf(hc_sock_t *s, + hc_subscription_t *subscription); + +/*----------------------------------------------------------------------------* + * Events + *----------------------------------------------------------------------------*/ +#define foreach_event_type \ + _(UNDEFINED) \ + _(INTERFACE_UPDATE) \ + _(N) +typedef enum { +#define _(x) EVENT_##x, + foreach_event_type +#undef _ +} event_type_t; + +extern const char *event_str[]; +#define event_str(x) event_str[x] + +typedef enum { + FLAG_INTERFACE_TYPE_WIRED = 0x1, + FLAG_INTERFACE_TYPE_WIFI = 0x2, + FLAG_INTERFACE_TYPE_CELLULAR = 0x4, +} flag_interface_type_t; + +typedef struct { + flag_interface_type_t interface_type; +} hc_event_interface_update_t; + +/* Result */ + +hc_msg_t *hc_result_get_msg(hc_sock_t *s, hc_result_t *result); +int hc_result_get_cmd_id(hc_sock_t *s, hc_result_t *result); +bool hc_result_get_success(hc_sock_t *s, hc_result_t *result); +void hc_result_free(hc_result_t *result); + +/* Object */ + +typedef struct { + hc_object_type_t type; + union { + hc_connection_t connection; + hc_listener_t listener; + hc_route_t route; + hc_face_t face; + // hc_data_t *data; + hc_punting_t punting; + hc_strategy_t strategy; +#ifdef WITH_POLICY + hc_policy_t policy; +#endif /* WITH_POLICY */ + hc_subscription_t subscription; + hc_cache_t cache; + hc_mapme_t mapme; + uint8_t as_uint8; + }; +} hc_object_t; + +typedef struct { + hc_action_t action; + hc_object_t object; +} hc_command_t; + #endif /* HICNTRL_API */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/face.h b/ctrl/libhicnctrl/includes/hicn/ctrl/face.h deleted file mode 100644 index 49a6a783c..000000000 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/face.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * \file face.h - * \brief Face abstraction - */ -#ifndef HICN_FACE_H -#define HICN_FACE_H - -#ifndef SPACES -#define SPACES(x) x -#endif -#ifndef SPACE -#define SPACE 1 -#endif -#ifndef NULLTERM -#define NULLTERM 1 -#endif - -#include <hicn/policy.h> - -#include <hicn/util/ip_address.h> - -//typedef unsigned int hash_t; //incompatible with vpp - -/* Netdevice type */ - -#include <net/if.h> // IFNAMSIZ - -#define foreach_netdevice_type \ - _(UNDEFINED) \ - _(LOOPBACK) \ - _(WIRED) \ - _(WIFI) \ - _(CELLULAR) \ - _(VPN) \ - _(N) - -#define MAXSZ_NETDEVICE_TYPE_ 9 -#define MAXSZ_NETDEVICE_TYPE MAXSZ_NETDEVICE_TYPE_ + NULLTERM - -typedef enum { -#define _(x) NETDEVICE_TYPE_ ## x, -foreach_netdevice_type -#undef _ -} netdevice_type_t; - -extern const char * netdevice_type_str[]; - - -/* Netdevice */ - -/** - * \brief Netdevice type - * - * NOTE - * - This struct cannot be made opaque as it is currently part of face_t - * - We recommand using the API as to keep redundant attributes consistent - */ -typedef struct { - u32 index; - char name[IFNAMSIZ]; -} netdevice_t; - -#define NETDEVICE_EMPTY (netdevice_t) { \ - .index = 0, \ - .name = {0}, \ -} - -netdevice_t * netdevice_create_from_index(u32 index); -netdevice_t * netdevice_create_from_name(const char * name); -#define netdevice_initialize_from_index netdevice_set_index -#define netdevice_initialize_from_name netdevice_set_name -void netdevice_free(netdevice_t * netdevice); -int netdevice_get_index(const netdevice_t * netdevice, u32 * index); -int netdevice_set_index(netdevice_t * netdevice, u32 index); -int netdevice_get_name(const netdevice_t * netdevice, const char ** name); -int netdevice_set_name(netdevice_t * netdevice, const char * name); -int netdevice_update_index(netdevice_t * netdevice); -int netdevice_update_name(netdevice_t * netdevice); -int netdevice_cmp(const netdevice_t * nd1, const netdevice_t * nd2); - -#define NETDEVICE_UNDEFINED_INDEX 0 - -/* Face state */ - -#define foreach_face_state \ - _(UNDEFINED) \ - _(DOWN) \ - _(UP) \ - _(N) - - -#define MAXSZ_FACE_STATE_ 9 -#define MAXSZ_FACE_STATE MAXSZ_FACE_STATE_ + 1 - -typedef enum { -#define _(x) FACE_STATE_ ## x, -foreach_face_state -#undef _ -} face_state_t; - -extern const char * face_state_str[]; - - -/* Face type */ - -#define foreach_face_type \ - _(UNDEFINED) \ - _(HICN) \ - _(HICN_LISTENER) \ - _(TCP) \ - _(TCP_LISTENER) \ - _(UDP) \ - _(UDP_LISTENER) \ - _(N) - -#define MAXSZ_FACE_TYPE_ 13 -#define MAXSZ_FACE_TYPE MAXSZ_FACE_TYPE_ + 1 - -typedef enum { -#define _(x) FACE_TYPE_ ## x, -foreach_face_type -#undef _ -} face_type_t; - -extern const char * face_type_str[]; - -#ifdef WITH_POLICY -#define MAXSZ_FACE_ MAXSZ_FACE_TYPE_ + 2 * MAXSZ_URL_ + 2 * MAXSZ_FACE_STATE_ + MAXSZ_POLICY_TAGS_ + 7 -#else -#define MAXSZ_FACE_ MAXSZ_FACE_TYPE_ + 2 * MAXSZ_URL_ + 2 * MAXSZ_FACE_STATE_ + 4 -#endif /* WITH_POLICY */ -#define MAXSZ_FACE MAXSZ_FACE_ + 1 - -/* Face */ - -typedef u32 face_id_t; - -typedef struct { - face_type_t type; - face_state_t admin_state; - face_state_t state; -#ifdef WITH_POLICY - uint32_t priority; - policy_tags_t tags; /**< \see policy_tag_t */ -#endif /* WITH_POLICY */ - - /* - * Depending on the face type, some of the following fields will be unused - */ - netdevice_t netdevice; - int family; /* To access family independently of face type */ - ip_address_t local_addr; - ip_address_t remote_addr; - u16 local_port; - u16 remote_port; -} face_t; - -int face_initialize(face_t * face); -int face_initialize_udp(face_t * face, const char * interface_name, - const ip_address_t * local_addr, u16 local_port, - const ip_address_t * remote_addr, u16 remote_port, - int family); -int face_initialize_udp_sa(face_t * face, - const char * interface_name, - const struct sockaddr * local_addr, const struct sockaddr * remote_addr); - -face_t * face_create(); -face_t * face_create_udp(const char * interface_name, - const ip_address_t * local_addr, u16 local_port, - const ip_address_t * remote_addr, u16 remote_port, int family); -face_t * face_create_udp_sa(const char * interface_name, - const struct sockaddr * local_addr, - const struct sockaddr * remote_addr); - -int face_finalize(face_t * face); - -void face_free(face_t * face); - -typedef int (*face_cmp_t)(const face_t * f1, const face_t * f2); - -int face_cmp(const face_t * f1, const face_t * f2); -unsigned int face_hash(const face_t * face); - -size_t -face_snprintf(char * s, size_t size, const face_t * face); - -policy_tags_t face_get_tags(const face_t * face); -int face_set_tags(face_t * face, policy_tags_t tags); - -#endif /* HICN_FACE_H */ - diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/hicn-light-ng.h b/ctrl/libhicnctrl/includes/hicn/ctrl/hicn-light-ng.h new file mode 100644 index 000000000..7d105a84b --- /dev/null +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/hicn-light-ng.h @@ -0,0 +1,427 @@ +/* + * Copyright (c) 2021 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. + */ + +/* + * @file commands.h + * @brief All hicn-light commands: 14 in total. + * + * Header and payload in binary format. + */ + +#ifndef HICN_CTRL_HICNLIGHTNG_H +#define HICN_CTRL_HICNLIGHTNG_H + +#ifndef _WIN32 +#include <netinet/in.h> +#include <sys/socket.h> +#endif + +#include <stdint.h> +#include <stdlib.h> + +#include <hicn/policy.h> +#include <hicn/strategy.h> +#include <hicn/util/ip_address.h> + +#define SYMBOLIC_NAME_LEN 16 + +typedef struct in6_addr ipv6_addr_t; +typedef uint32_t ipv4_addr_t; + +typedef enum { + MESSAGE_COMMAND_SUBTYPE_UNDEFINED, + REQUEST_LIGHT = 0xc0, // this is a command + RESPONSE_LIGHT, + ACK_LIGHT, + NACK_LIGHT, + NOTIFICATION_LIGHT, + MESSAGE_COMMAND_SUBTYPE_N +} message_command_subtype_t; + +#define message_type_is_valid(message_type) \ + ((message_type != MESSAGE_TYPE_UNDEFINED) && \ + (message_type != MESSAGE_COMMAND_SUBTYPE_N)) + +#define message_type_from_uchar(x) \ + (((x) < REQUEST_LIGHT) || (((x) >= MESSAGE_COMMAND_SUBTYPE_N)) \ + ? MESSAGE_COMMAND_SUBTYPE_N \ + : (message_command_subtype_t)(x)) + +#define foreach_command_type \ + _(listener_add, LISTENER_ADD) \ + _(listener_remove, LISTENER_REMOVE) \ + _(listener_list, LISTENER_LIST) \ + _(connection_add, CONNECTION_ADD) \ + _(connection_remove, CONNECTION_REMOVE) \ + _(connection_list, CONNECTION_LIST) \ + _(connection_set_admin_state, CONNECTION_SET_ADMIN_STATE) \ + _(connection_update, CONNECTION_UPDATE) \ + _(connection_set_priority, CONNECTION_SET_PRIORITY) \ + _(connection_set_tags, CONNECTION_SET_TAGS) \ + _(route_add, ROUTE_ADD) \ + _(route_remove, ROUTE_REMOVE) \ + _(route_list, ROUTE_LIST) \ + _(cache_set_store, CACHE_SET_STORE) \ + _(cache_set_serve, CACHE_SET_SERVE) \ + _(cache_clear, CACHE_CLEAR) \ + _(cache_list, CACHE_LIST) \ + _(strategy_set, STRATEGY_SET) \ + _(strategy_add_local_prefix, STRATEGY_ADD_LOCAL_PREFIX) \ + _(wldr_set, WLDR_SET) \ + _(punting_add, PUNTING_ADD) \ + _(mapme_enable, MAPME_ENABLE) \ + _(mapme_set_discovery, MAPME_SET_DISCOVERY) \ + _(mapme_set_timescale, MAPME_SET_TIMESCALE) \ + _(mapme_set_retx, MAPME_SET_RETX) \ + _(mapme_send_update, MAPME_SEND_UPDATE) \ + _(policy_add, POLICY_ADD) \ + _(policy_remove, POLICY_REMOVE) \ + _(policy_list, POLICY_LIST) \ + _(subscription_add, SUBSCRIPTION_ADD) \ + _(subscription_remove, SUBSCRIPTION_REMOVE) + +typedef enum { + COMMAND_TYPE_UNDEFINED, +#define _(l, u) COMMAND_TYPE_##u, + foreach_command_type +#undef _ + COMMAND_TYPE_N, +} command_type_t; + +extern const char *command_type_str[]; + +#define command_type_str(x) command_type_str[x] + +#define command_type_is_valid(command_type) \ + ((command_type != COMMAND_TYPE_UNDEFINED) && (command_type != COMMAND_TYPE_N)) + +#define command_type_from_uchar(x) \ + (((x) >= COMMAND_TYPE_N) ? COMMAND_TYPE_N : (command_type_t)(x)) + +/* Should be at least 8 bytes */ +typedef struct { + uint8_t message_type; + uint8_t command_id; + uint16_t length; /* Number of structures in the payload */ + uint32_t seq_num; +} cmd_header_t; + +typedef struct { + cmd_header_t header; +} msg_header_t; + +/* Listener */ + +typedef struct { + char symbolic[SYMBOLIC_NAME_LEN]; + char interface_name[SYMBOLIC_NAME_LEN]; + ip_address_t address; + uint16_t port; + uint8_t family; + uint8_t type; +} cmd_listener_add_t; + +typedef struct { + char symbolicOrListenerid[SYMBOLIC_NAME_LEN]; +} cmd_listener_remove_t; + +typedef struct { + void *_; // Otherwise empty structs result in clang build error +} cmd_listener_list_t; + +// Sync this struct with `hc_listener_t` in `api.h` +typedef struct { + char name[SYMBOLIC_NAME_LEN]; + char interface_name[SYMBOLIC_NAME_LEN]; + uint32_t id; + uint8_t type; + uint8_t family; + ip_address_t address; + uint16_t port; +} cmd_listener_list_item_t; + +/* Connection */ + +typedef struct { + char symbolic[SYMBOLIC_NAME_LEN]; + // char interface_name[SYMBOLIC_NAME_LEN]; + ip_address_t remote_ip; + ip_address_t local_ip; + uint16_t remote_port; + uint16_t local_port; + uint8_t family; + uint8_t type; + uint8_t admin_state; +#ifdef WITH_POLICY + uint32_t priority; + policy_tags_t tags; +#endif /* WITH_POLICY */ +} cmd_connection_add_t; + +typedef struct { + char symbolic_or_connid[SYMBOLIC_NAME_LEN]; +} cmd_connection_remove_t; + +typedef struct { + void *_; +} cmd_connection_list_t; + +// Sync this struct with `hc_connection_t` in `api.h` +typedef struct { + uint32_t id; + char name[SYMBOLIC_NAME_LEN]; + char interface_name[SYMBOLIC_NAME_LEN]; + uint8_t type; + uint8_t family; + ip_address_t local_addr; + uint16_t local_port; + ip_address_t remote_addr; + uint16_t remote_port; + uint8_t admin_state; +#ifdef WITH_POLICY + uint32_t priority; + policy_tags_t tags; +#endif /* WITH_POLICY */ + uint8_t state; +} cmd_connection_list_item_t; + +typedef struct { + char symbolic_or_connid[SYMBOLIC_NAME_LEN]; + uint8_t admin_state; + uint8_t pad8[3]; +} cmd_connection_set_admin_state_t; + +typedef struct { + char symbolic_or_connid[SYMBOLIC_NAME_LEN]; + uint8_t admin_state; +#ifdef WITH_POLICY + uint32_t priority; + policy_tags_t tags; +#endif /* WITH_POLICY */ +} cmd_connection_update_t; + +typedef struct { + char symbolic_or_connid[SYMBOLIC_NAME_LEN]; + uint32_t priority; +} cmd_connection_set_priority_t; + +typedef struct { + char symbolic_or_connid[SYMBOLIC_NAME_LEN]; + policy_tags_t tags; +} cmd_connection_set_tags_t; + +/* Route */ + +typedef struct { + char symbolic_or_connid[SYMBOLIC_NAME_LEN]; + ip_address_t address; + uint16_t cost; + uint8_t family; + uint8_t len; +} cmd_route_add_t; + +typedef struct { + char symbolic_or_connid[SYMBOLIC_NAME_LEN]; + ip_address_t address; + uint8_t family; + uint8_t len; +} cmd_route_remove_t; + +typedef struct { + void *_; +} cmd_route_list_t; + +// Sync this struct with `hc_route_t` in `api.h` +typedef struct { + ip_address_t address; + uint32_t connection_id; + uint16_t cost; + uint8_t family; + uint8_t len; +} cmd_route_list_item_t; + +/* Cache */ + +typedef struct { + uint8_t activate; +} cmd_cache_set_store_t; + +typedef struct { + uint8_t activate; +} cmd_cache_set_serve_t; + +typedef struct { + void *_; +} cmd_cache_clear_t; + +typedef struct { + void *_; +} cmd_cache_list_t; + +typedef struct { + uint8_t store_in_cs; + uint8_t serve_from_cs; + uint32_t cs_size; + uint32_t num_stale_entries; +} cmd_cache_list_reply_t; + +typedef struct { + cmd_header_t header; + cmd_cache_list_reply_t payload; +} msg_cache_list_reply_t; + +/* WLDR */ + +typedef struct { + char symbolic_or_connid[SYMBOLIC_NAME_LEN]; + uint8_t activate; +} cmd_wldr_set_t; + +/* Strategy */ + +typedef struct { + ip_address_t address; + uint8_t family; + uint8_t len; + uint8_t type; + uint8_t related_prefixes; + union { + struct { + ip_address_t addresses[MAX_FWD_STRATEGY_RELATED_PREFIXES]; + uint8_t lens[MAX_FWD_STRATEGY_RELATED_PREFIXES]; + uint8_t families[MAX_FWD_STRATEGY_RELATED_PREFIXES]; + } low_latency; + }; +} cmd_strategy_set_t; + +typedef struct { + uint8_t type; + ip_address_t address; + uint8_t family; + uint8_t len; + ip_address_t local_address; + uint8_t local_family; + uint8_t local_len; +} cmd_strategy_add_local_prefix_t; + +/* Punting */ + +typedef struct { + char symbolic_or_connid[SYMBOLIC_NAME_LEN]; + ip_address_t address; + uint8_t family; + uint8_t len; +} cmd_punting_add_t; + +/* MAP-Me */ + +typedef struct { + uint8_t activate; +} cmd_mapme_activator_t; + +typedef cmd_mapme_activator_t cmd_mapme_enable_t; +typedef cmd_mapme_activator_t cmd_mapme_set_discovery_t; + +typedef struct { + uint32_t timePeriod; +} cmd_mapme_timing_t; + +typedef cmd_mapme_timing_t cmd_mapme_set_timescale_t; +typedef cmd_mapme_timing_t cmd_mapme_set_retx_t; + +typedef struct { + void *_; +} cmd_mapme_send_update_t; + +/* Policy */ + +typedef struct { + ip_address_t address; + uint8_t family; + uint8_t len; + hicn_policy_t policy; +} cmd_policy_add_t; + +typedef struct { + ip_address_t address; + uint8_t family; + uint8_t len; +} cmd_policy_remove_t; + +typedef struct { + void *_; +} cmd_policy_list_t; + +typedef struct { + ip_address_t address; + uint8_t family; + uint8_t len; + hicn_policy_t policy; +} cmd_policy_list_item_t; + +/* Subscription */ + +typedef struct { + uint32_t topics; +} cmd_subscription_add_t; + +typedef struct { + uint32_t topics; +} cmd_subscription_remove_t; + +/* Full messages */ + +#define _(l, u) \ + typedef struct { \ + cmd_header_t header; \ + cmd_##l##_t payload; \ + } msg_##l##_t; +foreach_command_type +#undef _ + + typedef struct { + cmd_header_t header; + cmd_listener_list_item_t payload; +} msg_listener_list_reply_t; + +typedef struct { + cmd_header_t header; + cmd_connection_list_item_t payload; +} msg_connection_list_reply_t; + +typedef struct { + cmd_header_t header; + cmd_route_list_item_t payload; +} msg_route_list_reply_t; + +typedef struct { + cmd_header_t header; + cmd_policy_list_item_t payload; +} msg_policy_list_reply_t; + +//===== size of commands ====== +// REMINDER: when a new_command is added, the following switch has to be +// updated. +static inline int command_get_payload_len(command_type_t command_type) { + switch (command_type) { +#define _(l, u) \ + case COMMAND_TYPE_##u: \ + return sizeof(cmd_##l##_t); + foreach_command_type +#undef _ + case COMMAND_TYPE_UNDEFINED : case COMMAND_TYPE_N : return 0; + } +} +#endif /* HICN_CTRL_HICNLIGHTNG_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h b/ctrl/libhicnctrl/includes/hicn/ctrl/hicn-light.h index 3758f0f41..69ede1985 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/commands.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/hicn-light.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2021 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: @@ -20,8 +20,8 @@ * Header and payload in binary format. */ -#ifndef commands_h -#define commands_h +#ifndef HICN_CTRL_HICNLIGHT_H +#define HICN_CTRL_HICNLIGHT_H #ifndef _WIN32 #include <netinet/in.h> @@ -43,7 +43,7 @@ typedef struct in6_addr ipv6_addr_t; typedef uint32_t ipv4_addr_t; typedef enum { - REQUEST_LIGHT = 0xc0, // this is a command + REQUEST_LIGHT = 0xc0, // this is a command RESPONSE_LIGHT, ACK_LIGHT, NACK_LIGHT, @@ -133,7 +133,7 @@ typedef struct { typedef struct { char symbolic[SYMBOLIC_NAME_LEN]; - //char interfaceName[SYMBOLIC_NAME_LEN]; + // char interfaceName[SYMBOLIC_NAME_LEN]; ip_address_t remoteIp; ip_address_t localIp; uint16_t remotePort; @@ -415,7 +415,7 @@ static inline int payloadLengthDaemon(command_id id) { case ADD_POLICY: return sizeof(add_policy_command); case LIST_POLICIES: - return 0; // list policies: payload always 0 + return 0; // list policies: payload always 0 case REMOVE_POLICY: return sizeof(remove_policy_command); case UPDATE_CONNECTION: @@ -431,4 +431,4 @@ static inline int payloadLengthDaemon(command_id id) { return 0; } } -#endif +#endif /* HICN_CTRL_HICNLIGHT_H */ diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/route.h b/ctrl/libhicnctrl/includes/hicn/ctrl/route.h index d7ef6a26f..81f011d4d 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/route.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/route.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2021 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: @@ -21,7 +21,7 @@ #define HICN_ROUTE_H #include <hicn/util/ip_address.h> -#include <hicn/ctrl/face.h> +#include <hicn/face.h> typedef u16 route_cost_t; @@ -30,18 +30,23 @@ typedef struct hicn_route_s hicn_route_t; #define MAXSZ_ROUTE_ MAXSZ_PREFIX + 3 + MAXSZ_COST #define MAXSZ_ROUTE MAXSZ_ROUTE_ + NULLTERM -hicn_route_t * hicn_route_create(ip_prefix_t * prefix, face_id_t face_id, route_cost_t cost); -hicn_route_t * hicn_route_dup(const hicn_route_t * route); -void hicn_route_free(hicn_route_t * route); +#define MIN_ROUTE_COST 1 +#define MAX_ROUTE_COST 255 +#define IS_VALID_ROUTE_COST(x) ((x >= MIN_ROUTE_COST) && (x <= MAX_ROUTE_COST)) -int hicn_route_cmp(const hicn_route_t * route1, const hicn_route_t * route2); +hicn_route_t* hicn_route_create(ip_prefix_t* prefix, face_id_t face_id, + route_cost_t cost); +hicn_route_t* hicn_route_dup(const hicn_route_t* route); +void hicn_route_free(hicn_route_t* route); -int hicn_route_get_prefix(const hicn_route_t * route, ip_prefix_t * prefix); -int hicn_route_set_prefix(hicn_route_t * route, const ip_prefix_t prefix); +int hicn_route_cmp(const hicn_route_t* route1, const hicn_route_t* route2); -int hicn_route_get_cost(const hicn_route_t * route, int * cost); -int hicn_route_set_cost(hicn_route_t * route, const int cost); +int hicn_route_get_prefix(const hicn_route_t* route, ip_prefix_t* prefix); +int hicn_route_set_prefix(hicn_route_t* route, const ip_prefix_t prefix); -size_t hicn_route_snprintf(char * s, size_t size, const hicn_route_t * route); +int hicn_route_get_cost(const hicn_route_t* route, int* cost); +int hicn_route_set_cost(hicn_route_t* route, const int cost); + +size_t hicn_route_snprintf(char* s, size_t size, const hicn_route_t* route); #endif |