diff options
author | Mauro Sardara <msardara@cisco.com> | 2022-09-22 13:47:55 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@fd.io> | 2022-09-22 13:47:55 +0000 |
commit | b498b1d3fe2684e0233986551fa581a07148e22b (patch) | |
tree | 0cc5203e8be42408d9910166f479256d48523436 | |
parent | 356530fa42140a9f0ad43269125fd96ad1ced594 (diff) | |
parent | bd26d18978861b24c5707dbaa24dac76133425e2 (diff) |
Merge "fix(libhicnctrl): fix new listener validation during face or connection creation"
-rw-r--r-- | ctrl/libhicnctrl/examples/Makefile | 2 | ||||
-rw-r--r-- | ctrl/libhicnctrl/examples/create_face.c | 41 | ||||
-rw-r--r-- | ctrl/libhicnctrl/examples/update_priority.c | 2 | ||||
-rw-r--r-- | ctrl/libhicnctrl/includes/hicn/ctrl/socket.h | 7 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/api.c | 269 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/commands/command_connection.c | 8 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/commands/command_face.c | 8 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/modules/hicn_light.c | 11 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/modules/hicn_light/face.c | 307 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/modules/hicn_light/stats.h | 26 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/object.c | 6 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/objects/face.c | 10 | ||||
-rw-r--r-- | ctrl/libhicnctrl/src/socket.c | 4 | ||||
-rw-r--r-- | tests/2-nodes-hicn-light.yml | 4 | ||||
-rwxr-xr-x | tests/config.sh | 4 |
15 files changed, 87 insertions, 622 deletions
diff --git a/ctrl/libhicnctrl/examples/Makefile b/ctrl/libhicnctrl/examples/Makefile index 1c1eb64e1..a3aae11b0 100644 --- a/ctrl/libhicnctrl/examples/Makefile +++ b/ctrl/libhicnctrl/examples/Makefile @@ -1,7 +1,7 @@ EXEC = $(shell basename $$(pwd)) CC = gcc -CFLAGS = -std=gnu11 -g -Wall -Wextra -Wpedantic -Wstrict-aliasing +CFLAGS = -std=gnu11 -g -Wall -Wextra -Wpedantic -Wstrict-aliasing -DWITH_POLICY LDFLAGS = -lhicn -lhicnctrl SRC = $(wildcard *.c) diff --git a/ctrl/libhicnctrl/examples/create_face.c b/ctrl/libhicnctrl/examples/create_face.c index 2152ff1e3..a2ef3e9db 100644 --- a/ctrl/libhicnctrl/examples/create_face.c +++ b/ctrl/libhicnctrl/examples/create_face.c @@ -32,7 +32,7 @@ #include <hicn/ctrl.h> #include <hicn/util/log.h> -int get_local_info(char *if_name, ip_address_t *local_ip) { +int get_local_info(char *if_name, hicn_ip_address_t *local_ip) { struct ifaddrs *addrs; struct ifreq ifr = { .ifr_addr.sa_family = AF_INET, @@ -56,7 +56,7 @@ int get_local_info(char *if_name, ip_address_t *local_ip) { *local_ip = IP_ADDRESS_EMPTY; local_ip->v4.as_inaddr = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr; - if (ip_address_empty(local_ip)) continue; + if (hicn_ip_address_empty(local_ip)) continue; ret = 0; break; @@ -70,8 +70,8 @@ int get_local_info(char *if_name, ip_address_t *local_ip) { int main() { char remote_ip_str[INET_ADDRSTRLEN] = "1.1.1.1"; - ip_address_t local_ip; - ip_address_t remote_ip; + hicn_ip_address_t local_ip; + hicn_ip_address_t remote_ip; char if_name[IFNAMSIZ]; /* Retrieving local info */ @@ -82,40 +82,37 @@ int main() { } char local_ip_str[MAXSZ_IP_ADDRESS]; - ip_address_snprintf(local_ip_str, MAXSZ_IP_ADDRESS, &local_ip, AF_INET); + hicn_ip_address_snprintf(local_ip_str, MAXSZ_IP_ADDRESS, &local_ip); DEBUG("Local information :"); DEBUG(" - Interface name : %s", if_name); DEBUG(" - IP address : %s", local_ip_str); - if (ip_address_pton(remote_ip_str, &remote_ip) < 0) { + if (hicn_ip_address_pton(remote_ip_str, &remote_ip) < 0) { DEBUG("Error parsing remote IP address"); goto ERR_INIT; } /* Filling face information */ hc_face_t face = { - .face = - { - .type = FACE_TYPE_UDP, - .family = AF_INET, - .local_addr = local_ip, - .remote_addr = remote_ip, - .local_port = 6000, - .remote_port = 6000, - .admin_state = FACE_STATE_UNDEFINED, - .state = FACE_STATE_UNDEFINED, - .priority = 0, - .tags = POLICY_TAGS_EMPTY, - }, + .type = FACE_TYPE_UDP, + .family = AF_INET, + .local_addr = local_ip, + .remote_addr = remote_ip, + .local_port = 6000, + .remote_port = 6000, + .admin_state = FACE_STATE_UNDEFINED, + .state = FACE_STATE_UNDEFINED, + .priority = 0, + .tags = POLICY_TAGS_EMPTY, }; - if (netdevice_set_name(&face.face.netdevice, if_name) < 0) { + if (netdevice_set_name(&face.netdevice, if_name) < 0) { DEBUG("Error setting face netdevice name"); goto ERR_INIT; } /* Connecting to socket and creating face */ - hc_sock_t *socket = hc_sock_create(); + hc_sock_t *socket = hc_sock_create_forwarder(FORWARDER_TYPE_HICNLIGHT); if (!socket) { DEBUG("Error creating libhicnctrl socket"); goto ERR_SOCK; @@ -131,7 +128,7 @@ int main() { goto ERR; } - DEBUG("Face created successfully"); + INFO("Face created successfully"); ERR: hc_sock_free(socket); diff --git a/ctrl/libhicnctrl/examples/update_priority.c b/ctrl/libhicnctrl/examples/update_priority.c index bbe174c2f..6dd974067 100644 --- a/ctrl/libhicnctrl/examples/update_priority.c +++ b/ctrl/libhicnctrl/examples/update_priority.c @@ -33,7 +33,7 @@ int main(int argc, char **argv) { unsigned priority = atoi(argv[2]); char face_id_s[SYMBOLIC_NAME_LEN]; - hc_sock_t *socket = hc_sock_create(); + hc_sock_t *socket = hc_sock_create_forwarder(FORWARDER_TYPE_HICNLIGHT); if (!socket) { DEBUG("Error creating libhicnctrl socket"); goto ERR_SOCK; diff --git a/ctrl/libhicnctrl/includes/hicn/ctrl/socket.h b/ctrl/libhicnctrl/includes/hicn/ctrl/socket.h index 2503fadd0..e53032955 100644 --- a/ctrl/libhicnctrl/includes/hicn/ctrl/socket.h +++ b/ctrl/libhicnctrl/includes/hicn/ctrl/socket.h @@ -57,13 +57,6 @@ forwarder_type_t forwarder_type_from_str(const char *str); typedef struct hc_sock_s hc_sock_t; /** - * \brief Create an hICN control socket using the specified URL. - * \param [in] url - The URL to connect to. - * \return an hICN control socket - */ -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 */ diff --git a/ctrl/libhicnctrl/src/api.c b/ctrl/libhicnctrl/src/api.c index c93853dd1..c133b9123 100644 --- a/ctrl/libhicnctrl/src/api.c +++ b/ctrl/libhicnctrl/src/api.c @@ -34,47 +34,6 @@ #define ENOIMPL 42 -#if 0 -/* /!\ Please update constants in public header file upon changes */ -const char * connection_state_str[] = { -#define _(x) [HC_CONNECTION_STATE_##x] = STRINGIZE(x), -foreach_connection_state -#undef _ -}; - -/* /!\ Please update constants in public header file upon changes */ -const char * connection_type_str[] = { -#define _(x) [CONNECTION_TYPE_##x] = STRINGIZE(x), -foreach_connection_type -#undef _ -}; - -hc_connection_type_t -connection_type_from_str(const char * str) -{ - if (strcasecmp(str, "TCP") == 0) - return CONNECTION_TYPE_TCP; - else if (strcasecmp(str, "UDP") == 0) - return CONNECTION_TYPE_UDP; - else if (strcasecmp(str, "HICN") == 0) - return CONNECTION_TYPE_HICN; - else - return CONNECTION_TYPE_UNDEFINED; -} -#endif - -/****************************************************************************** - * Control Data - ******************************************************************************/ - -/*----------------------------------------------------------------------------* - * Object model - *----------------------------------------------------------------------------*/ - -/*----------------------------------------------------------------------------* - * Entry point - *----------------------------------------------------------------------------*/ - int hc_sock_on_init(hc_sock_t *s, hc_request_t *request) { int rc; ssize_t size; @@ -114,19 +73,6 @@ int hc_sock_on_receive(hc_sock_t *s, size_t count) { * time... either the state machine reaches the end, or in case of generic * requests, we mark it as such. */ -#if 0 - if (hc_request_is_complete(current_request)) { - if (!hc_request_pop(request)) { - /* Free request context */ - /* In case of error, data is NULL */ - // XXX bug if we free request XXX - // hc_sock_free_request(s, request); - if (!hc_request_is_subscription(request)) - hc_request_set_complete(request); - return 1; /* Done */ - } - } else { -#endif ON_INIT: rc = hc_sock_on_init(s, request); if (rc < 0) goto ERR_INIT; @@ -264,9 +210,6 @@ int _hc_execute(hc_sock_t *s, hc_action_t action, hc_object_type_t object_type, if (hc_sock_is_async(s)) return 0; - /* Case in which no reply is expected */ - if (!pdata) return 0; - if (hc_sock_receive_all(s, pdata) < 0) goto ERR_RECV; } else if (s->ops.prepare) { // hc_data_t *data = hc_data_create(OBJECT_TYPE_LISTENER); @@ -309,218 +252,6 @@ int hc_execute_async(hc_sock_t *s, hc_action_t action, NULL); } -/* This function has to be called after the first execute until data and - * request are complete */ -// execute is just setting things up so that we can keep on calling this -// function repeatedly until completion. -// -// in the caller, we don't know how much we will receive in advance... so in -// asio for instance, we will use async_receive rather than async_read. -// XXX the question remains about the buffers... - -/* - * request -> write command - * - * SYNC : hc_data_t - * ASYNC : provide socket-level callback - * - * socket available -> read -> parse -> populate data - * data complete -> - */ - -/****************************************************************************** - * OBJECT-SPECIFIC FUNCTIONS (backwards compatibility) - ******************************************************************************/ - -/*----------------------------------------------------------------------------* - * FACE - * - * This is an abstraction provided for when the module does not implement - *it. Alternative is to move it to hicn light - *----------------------------------------------------------------------------*/ - -#if 0 - -/* FACE -> LISTENER */ - - -/* LISTENER -> FACE */ - -int hc_listener_to_face(const hc_listener_t *listener, hc_face_t *face) { - return -1; /* XXX Not implemented */ -} - -/* FACE -> CONNECTION */ - - -/* CONNECTION -> FACE */ -/* CONNECTION -> LISTENER */ - - -/*----------------------------------------------------------------------------* - * Punting - *----------------------------------------------------------------------------*/ - -int hc_punting_create(hc_sock_t *s, hc_punting_t *punting) { - return s->hc_punting_create(s, punting); -} - -int hc_punting_get(hc_sock_t *s, hc_punting_t *punting, - hc_punting_t **punting_found) { - return s->hc_punting_get(s, punting, punting_found); -} - -int hc_punting_delete(hc_sock_t *s, hc_punting_t *punting) { - return s->hc_punting_delete(s, punting); -} - -int hc_punting_list(hc_sock_t *s, hc_data_t **pdata) { - return s->hc_punting_list(s, pdata); -} - -int hc_punting_validate(const hc_punting_t *punting) { - if (!IS_VALID_FAMILY(punting->family)) return -1; - - /* - * We might use the zero value to add punting on all faces but this is not - * (yet) implemented - */ - if (punting->face_id == 0) { - ERROR("Punting on all faces is not (yet) implemented."); - return -1; - } - - return 0; -} - -int hc_punting_cmp(const hc_punting_t *p1, const hc_punting_t *p2) { - int rc; - - rc = INT_CMP(p1->face_id, p2->face_id); - if (rc != 0) return rc; - - rc = INT_CMP(p1->family, p2->family); - if (rc != 0) return rc; - - rc = ip_address_cmp(&p1->prefix, &p2->prefix); - if (rc != 0) return rc; - - rc = INT_CMP(p1->prefix_len, p2->prefix_len); - if (rc != 0) return rc; - - return rc; -} - -#if 0 -int hc_punting_parse(void *in, hc_punting_t *punting) { - ERROR("hc_punting_parse not (yet) implemented."); - return -1; -} -#endif - -int hc_punting_snprintf(char *s, size_t size, hc_punting_t *punting) { - ERROR("hc_punting_snprintf not (yet) implemented."); - return -1; -} - -/*----------------------------------------------------------------------------* - * Cache - *----------------------------------------------------------------------------*/ - -int hc_cache_set_store(hc_sock_t *s, hc_cache_t *cache) { - return s->hc_cache_set_store(s, cache); -} - -int hc_cache_set_serve(hc_sock_t *s, hc_cache_t *cache) { - return s->hc_cache_set_serve(s, cache); -} - -int hc_cache_clear(hc_sock_t *s, hc_cache_t *cache) { - return s->hc_cache_clear(s, cache); -} - -int hc_cache_list(hc_sock_t *s, hc_data_t **pdata) { - return s->hc_cache_list(s, pdata); -} - -int hc_cache_snprintf(char *s, size_t size, const hc_cache_info_t *cache_info) { - return snprintf( - s, size, "Cache set_store=%s set_serve=%s size=%lu stale_entries=%lu", - cache_info->store ? "true" : "false", - cache_info->serve ? "true" : "false", (unsigned long)cache_info->cs_size, - (unsigned long)cache_info->num_stale_entries); -} - -int hc_stats_snprintf(char *s, size_t size, const hicn_light_stats_t *stats) { - return snprintf( - s, size, - "pkts processed: %u\n\tinterests: %u\n\t" - "data: %u\npkts from cache count: %u\npkts no pit count: " - "%u\nexpired:\n\t interests: " - "%u\n\t data: %u\ninterests aggregated: " - "%u\nlru evictions: " - "%u\ndropped: " - "%u\ninterests retx: " - "%u\npit entries: %u\ncs entries: %u", - stats->forwarder.countReceived, stats->forwarder.countInterestsReceived, - stats->forwarder.countObjectsReceived, - stats->forwarder.countInterestsSatisfiedFromStore, - stats->forwarder.countDroppedNoReversePath, - stats->forwarder.countInterestsExpired, stats->forwarder.countDataExpired, - stats->pkt_cache.n_lru_evictions, stats->forwarder.countDropped, - stats->forwarder.countInterestsAggregated, - stats->forwarder.countInterestsRetransmitted, - stats->pkt_cache.n_pit_entries, stats->pkt_cache.n_cs_entries); -} - -/*----------------------------------------------------------------------------* - * WLDR - *----------------------------------------------------------------------------*/ - -int hc_wldr_set(hc_sock_t *s /* XXX */) { return s->hc_wldr_set(s); } - -/*----------------------------------------------------------------------------* - * MAP-Me - *----------------------------------------------------------------------------*/ - -int hc_mapme_set(hc_sock_t *s, hc_mapme_t *mapme) { - return s->hc_mapme_set(s, mapme->enabled); -} - -int hc_mapme_set_discovery(hc_sock_t *s, hc_mapme_t *mapme) { - return s->hc_mapme_set_discovery(s, mapme->enabled); -} - -int hc_mapme_set_timescale(hc_sock_t *s, hc_mapme_t *mapme) { - return s->hc_mapme_set_timescale(s, mapme->timescale); -} - -int hc_mapme_set_retx(hc_sock_t *s, hc_mapme_t *mapme) { - return s->hc_mapme_set_retx(s, mapme->timescale); -} - -int hc_mapme_send_update(hc_sock_t *s, hc_mapme_t *mapme) { - return s->hc_mapme_send_update(s, mapme); -} - -/*----------------------------------------------------------------------------* - * Policy - *----------------------------------------------------------------------------*/ - - -/* POLICY SNPRINTF */ - -/* /!\ Please update constants in header file upon changes */ -int hc_policy_snprintf(char *s, size_t size, hc_policy_t *policy) { return 0; } - -int hc_policy_validate(const hc_policy_t *policy, bool allow_partial) { - if (!IS_VALID_FAMILY(policy->family)) return -1; - - return 0; -} - -#endif - /*----------------------------------------------------------------------------* * VFT *----------------------------------------------------------------------------*/ diff --git a/ctrl/libhicnctrl/src/commands/command_connection.c b/ctrl/libhicnctrl/src/commands/command_connection.c index 30b3c3bf1..1659a9860 100644 --- a/ctrl/libhicnctrl/src/commands/command_connection.c +++ b/ctrl/libhicnctrl/src/commands/command_connection.c @@ -115,8 +115,8 @@ static const command_parser_t command_connection_create6 = { .action = ACTION_CREATE, .object_type = OBJECT_TYPE_CONNECTION, .nparams = 6, - .parameters = {type_tcp_udp, symbolic, remote_address, remote_port, - local_address, local_port}, + .parameters = {type_tcp_udp, symbolic, local_address, local_port, + remote_address, remote_port}, .post_hook = (parser_hook_t)on_connection_create, }; COMMAND_REGISTER(command_connection_create6); @@ -125,8 +125,8 @@ static const command_parser_t command_connection_create7 = { .action = ACTION_CREATE, .object_type = OBJECT_TYPE_CONNECTION, .nparams = 7, - .parameters = {type_tcp_udp, symbolic, remote_address, remote_port, - local_address, local_port, interface}, + .parameters = {type_tcp_udp, symbolic, local_address, local_port, + remote_address, remote_port, interface}, .post_hook = (parser_hook_t)on_connection_create, }; COMMAND_REGISTER(command_connection_create7); diff --git a/ctrl/libhicnctrl/src/commands/command_face.c b/ctrl/libhicnctrl/src/commands/command_face.c index 68a71f9ec..2ea0f5cc3 100644 --- a/ctrl/libhicnctrl/src/commands/command_face.c +++ b/ctrl/libhicnctrl/src/commands/command_face.c @@ -89,8 +89,8 @@ static const command_parser_t command_face_create5 = { .action = ACTION_CREATE, .object_type = OBJECT_TYPE_FACE, .nparams = 5, - .parameters = {type_tcp_udp, remote_address, remote_port, local_address, - local_port}, + .parameters = {type_tcp_udp, local_address, local_port, remote_address, + remote_port}, .post_hook = (parser_hook_t)on_face_create, }; COMMAND_REGISTER(command_face_create5); @@ -99,8 +99,8 @@ static const command_parser_t command_face_create6 = { .action = ACTION_CREATE, .object_type = OBJECT_TYPE_FACE, .nparams = 6, - .parameters = {type_tcp_udp, remote_address, remote_port, local_address, - local_port, interface}, + .parameters = {type_tcp_udp, local_address, local_port, remote_address, + remote_port, interface}, .post_hook = (parser_hook_t)on_face_create, }; COMMAND_REGISTER(command_face_create6); diff --git a/ctrl/libhicnctrl/src/modules/hicn_light.c b/ctrl/libhicnctrl/src/modules/hicn_light.c index 2716eefd5..729d98f89 100644 --- a/ctrl/libhicnctrl/src/modules/hicn_light.c +++ b/ctrl/libhicnctrl/src/modules/hicn_light.c @@ -956,7 +956,7 @@ NEXT: /* Check whether listener creation succeeded */ case REQUEST_STATE_CONNECTION_CREATE_LISTENER_CHECK: - if (!data || hc_data_get_result(data)) return -1; + if (!data || !hc_data_get_result(data)) return -1; hc_request_set_state(current_request, REQUEST_STATE_CONNECTION_CREATE); goto NEXT; @@ -1212,8 +1212,13 @@ static ssize_t hicnlight_prepare(hc_sock_t *sock, hc_request_t *request, static hc_object_t object_subscribe; - DEBUG("[hicnlight_prepare] %s %s", action_str(action), - object_type_str(object_type)); + WITH_DEBUG({ + char buf[MAXSZ_HC_OBJECT]; + hc_request_state_t state = hc_request_get_state(current_request); + hc_object_snprintf(buf, sizeof(buf), object_type, object); + DEBUG("[hicnlight_prepare] %s %s [%s] %s", action_str(action), + object_type_str(object_type), hc_request_state_str(state), buf); + }); /* * Here the request is in progress and we just need to iterate through the diff --git a/ctrl/libhicnctrl/src/modules/hicn_light/face.c b/ctrl/libhicnctrl/src/modules/hicn_light/face.c index 0d9475420..46adf633d 100644 --- a/ctrl/libhicnctrl/src/modules/hicn_light/face.c +++ b/ctrl/libhicnctrl/src/modules/hicn_light/face.c @@ -173,310 +173,3 @@ int hc_face_to_listener(const hc_face_t *face, hc_listener_t *listener) { } return -1; /* XXX Not implemented */ } - -#if 0 -/*----------------------------------------------------------------------------* - * Face - * - * Face support is not directly available in hicn-light, but we can offer such - * an interface through a combination of listeners and connections. The code - * starts with some conversion functions between faces/listeners/connections. - * - * We also need to make sure that there always exist a (single) listener when - *a connection is created, and in the hICN face case, that there is a single - * connection attached to this listener. - * - *----------------------------------------------------------------------------*/ - -/* FACE CREATE */ - -static int _hcng_face_create(hc_sock_t *socket, hc_face_t *face) { -#if 0 - hc_listener_t listener; - hc_listener_t *listener_found; - - hc_connection_t connection; - hc_connection_t *connection_found; - - char face_s[MAXSZ_HC_FACE]; - int rc = hc_face_snprintf(face_s, MAXSZ_HC_FACE, face); - if (rc >= MAXSZ_HC_FACE) - WARN("[hc_face_create] Unexpected truncation of face string"); - DEBUG("[hc_face_create] face=%s", face_s); - - switch (face->face.type) { - case FACE_TYPE_HICN: - case FACE_TYPE_TCP: - case FACE_TYPE_UDP: - if (hc_face_to_connection(face, &connection, true) < 0) { - ERROR("[hc_face_create] Could not convert face to connection."); - return -1; - } - - /* Ensure we have a corresponding local listener */ - if (hc_connection_to_local_listener(&connection, &listener) < 0) { - ERROR("[hc_face_create] Could not convert face to local listener."); - return -1; - } - - if (_hcng_listener_get(socket, &listener, &listener_found) < 0) { - ERROR("[hc_face_create] Could not retrieve listener"); - return -1; - } - - if (!listener_found) { - /* We need to create the listener if it does not exist */ - if (hc_listener_create(socket, &listener) < 0) { - ERROR("[hc_face_create] Could not create listener."); - free(listener_found); - return -1; - } - } else { - free(listener_found); - } - - /* Create corresponding connection */ - if (_hcng_connection_create(socket, &connection) < 0) { - ERROR("[hc_face_create] Could not create connection."); - return -1; - } - - /* - * Once the connection is created, we need to list all connections - * and compare with the current one to find the created face ID. - */ - if (_hcng_connection_get(socket, &connection, &connection_found) < 0) { - ERROR("[hc_face_create] Could not retrieve connection"); - return -1; - } - - if (!connection_found) { - ERROR("[hc_face_create] Could not find newly created connection."); - return -1; - } - - face->id = connection_found->id; - free(connection_found); - - break; - - case FACE_TYPE_HICN_LISTENER: - case FACE_TYPE_TCP_LISTENER: - case FACE_TYPE_UDP_LISTENER: - if (hc_face_to_listener(face, &listener) < 0) { - ERROR("Could not convert face to listener."); - return -1; - } - if (hc_listener_create(socket, &listener) < 0) { - ERROR("[hc_face_create] Could not create listener."); - return -1; - } - break; - default: - ERROR("[hc_face_create] Unknwon face type."); - - return -1; - }; - -#endif - return 0; -} - -static int _hcng_face_get(hc_sock_t *socket, hc_face_t *face, - hc_face_t **face_found) { -#if 0 - hc_listener_t listener; - hc_listener_t *listener_found; - - hc_connection_t connection; - hc_connection_t *connection_found; - - char face_s[MAXSZ_HC_FACE]; - int rc = hc_face_snprintf(face_s, MAXSZ_HC_FACE, face); - if (rc >= MAXSZ_HC_FACE) - WARN("[hc_face_get] Unexpected truncation of face string"); - DEBUG("[hc_face_get] face=%s", face_s); - - switch (face->face.type) { - case FACE_TYPE_HICN: - case FACE_TYPE_TCP: - case FACE_TYPE_UDP: - if (hc_face_to_connection(face, &connection, false) < 0) return -1; - if (_hcng_connection_get(socket, &connection, &connection_found) < 0) - return -1; - if (!connection_found) { - *face_found = NULL; - return 0; - } - *face_found = malloc(sizeof(hc_face_t)); - hc_connection_to_face(connection_found, *face_found); - free(connection_found); - break; - - case FACE_TYPE_HICN_LISTENER: - case FACE_TYPE_TCP_LISTENER: - case FACE_TYPE_UDP_LISTENER: - if (hc_face_to_listener(face, &listener) < 0) return -1; - if (_hcng_listener_get(socket, &listener, &listener_found) < 0) return -1; - if (!listener_found) { - *face_found = NULL; - return 0; - } - *face_found = malloc(sizeof(hc_face_t)); - hc_listener_to_face(listener_found, *face_found); - free(listener_found); - break; - - default: - return -1; - } - -#endif - return 0; -} - -/* FACE DELETE */ - -static int _hcng_face_delete(hc_sock_t *socket, hc_face_t *face, - uint8_t delete_listener) { -#if 0 - char face_s[MAXSZ_HC_FACE]; - int rc = hc_face_snprintf(face_s, MAXSZ_HC_FACE, face); - if (rc >= MAXSZ_HC_FACE) - WARN("[hc_face_delete] Unexpected truncation of face string"); - DEBUG("[hc_face_delete] face=%s", face_s); - - hc_connection_t connection; - if (hc_face_to_connection(face, &connection, false) < 0) { - ERROR("[hc_face_delete] Could not convert face to connection."); - return -1; - } - - if (_hcng_connection_delete(socket, &connection) < 0) { - ERROR("[hc_face_delete] Error removing connection"); - return -1; - } - - if (!delete_listener) { - return 0; - } - - /* If this is the last connection attached to the listener, remove it */ - - hc_data_t *connections; - hc_listener_t listener = {{0}}; - - /* - * Ensure we have a corresponding local listener - * NOTE: hc_face_to_listener is not appropriate - */ - if (hc_connection_to_local_listener(&connection, &listener) < 0) { - ERROR("[hc_face_create] Could not convert face to local listener."); - return -1; - } -#if 1 - /* - * The name is generated to prepare listener creation, we need it to be - * empty for deletion. The id should not need to be reset though. - */ - listener.id = 0; - memset(listener.name, 0, sizeof(listener.name)); -#endif - if (_hcng_connection_list(socket, &connections) < 0) { - ERROR("[hc_face_delete] Error getting the list of listeners"); - return -1; - } - - bool delete = true; - foreach_connection(c, connections) { - if ((ip_address_cmp(&c->local_addr, &listener.local_addr, c->family) == - 0) && - (c->local_port == listener.local_port) && - (strcmp(c->interface_name, listener.interface_name) == 0)) { - delete = false; - } - } - - if (delete) { - if (_hcng_listener_delete(socket, &listener) < 0) { - ERROR("[hc_face_delete] Error removing listener"); - return -1; - } - } - - hc_data_free(connections); - -#endif - return 0; -} - -/* FACE LIST */ - -static int _hcng_face_list(hc_sock_t *socket, hc_data_t **pdata) { -#if 0 - hc_data_t *connection_data; - hc_face_t face; - - DEBUG("[hc_face_list]"); - - if (_hcng_connection_list(socket, &connection_data) < 0) { - ERROR("[hc_face_list] Could not list connections."); - return -1; - } - - hc_data_t *face_data = - hc_data_create(sizeof(hc_connection_t), sizeof(hc_face_t), NULL); - foreach_connection(c, connection_data) { - if (hc_connection_to_face(c, &face) < 0) { - ERROR("[hc_face_list] Could not convert connection to face."); - goto ERR; - } - hc_data_push(face_data, &face); - } - - *pdata = face_data; - hc_data_free(connection_data); - DEBUG("[hc_face_list] done"); - return 0; - -ERR: - hc_data_free(connection_data); - DEBUG("[hc_face_list] error"); -#endif - return -1; -} - -static int hc_connection_parse_to_face(void *in, hc_face_t *face) { - hc_connection_t connection; - - if (hcng_connection_parse(in, &connection) < 0) { - ERROR("[hc_connection_parse_to_face] Could not parse connection"); - return -1; - } - - if (hc_connection_to_face(&connection, face) < 0) { - ERROR( - "[hc_connection_parse_to_face] Could not convert connection to " - "face."); - return -1; - } - - return 0; -} - -static int _hcng_face_set_admin_state(hc_sock_t *s, const char *conn_id_or_name, - face_state_t admin_state) { - return hc_connection_set_admin_state(s, conn_id_or_name, admin_state); -} - -static int _hcng_face_set_priority(hc_sock_t *s, const char *conn_id_or_name, - uint32_t priority) { - return hc_connection_set_priority(s, conn_id_or_name, priority); -} - -static int _hcng_face_set_tags(hc_sock_t *s, const char *conn_id_or_name, - policy_tags_t tags) { - return hc_connection_set_tags(s, conn_id_or_name, tags); -} - -#endif diff --git a/ctrl/libhicnctrl/src/modules/hicn_light/stats.h b/ctrl/libhicnctrl/src/modules/hicn_light/stats.h index e69de29bb..34594bb72 100644 --- a/ctrl/libhicnctrl/src/modules/hicn_light/stats.h +++ b/ctrl/libhicnctrl/src/modules/hicn_light/stats.h @@ -0,0 +1,26 @@ + +#if 0 + +int hc_stats_snprintf(char *s, size_t size, const hicn_light_stats_t *stats) { + return snprintf( + s, size, + "pkts processed: %u\n\tinterests: %u\n\t" + "data: %u\npkts from cache count: %u\npkts no pit count: " + "%u\nexpired:\n\t interests: " + "%u\n\t data: %u\ninterests aggregated: " + "%u\nlru evictions: " + "%u\ndropped: " + "%u\ninterests retx: " + "%u\npit entries: %u\ncs entries: %u", + stats->forwarder.countReceived, stats->forwarder.countInterestsReceived, + stats->forwarder.countObjectsReceived, + stats->forwarder.countInterestsSatisfiedFromStore, + stats->forwarder.countDroppedNoReversePath, + stats->forwarder.countInterestsExpired, stats->forwarder.countDataExpired, + stats->pkt_cache.n_lru_evictions, stats->forwarder.countDropped, + stats->forwarder.countInterestsAggregated, + stats->forwarder.countInterestsRetransmitted, + stats->pkt_cache.n_pit_entries, stats->pkt_cache.n_cs_entries); +} + +#endif diff --git a/ctrl/libhicnctrl/src/object.c b/ctrl/libhicnctrl/src/object.c index 34f21509a..d9863308e 100644 --- a/ctrl/libhicnctrl/src/object.c +++ b/ctrl/libhicnctrl/src/object.c @@ -44,6 +44,12 @@ int hc_object_cmp(hc_object_type_t object_type, hc_object_t *object1, int hc_object_snprintf(char *s, size_t size, hc_object_type_t object_type, hc_object_t *object) { + if (!object) { + if (size == 0) return -1; + *s = '\0'; + return 1; + } + const hc_object_ops_t *vft = object_vft[object_type]; if (!vft) return -1; return vft->obj_snprintf(s, size, object); diff --git a/ctrl/libhicnctrl/src/objects/face.c b/ctrl/libhicnctrl/src/objects/face.c index c535ff4c5..b0dbcd7a5 100644 --- a/ctrl/libhicnctrl/src/objects/face.c +++ b/ctrl/libhicnctrl/src/objects/face.c @@ -169,6 +169,16 @@ int hc_face_list_async(hc_sock_t *s) { return hc_execute_async(s, ACTION_LIST, OBJECT_TYPE_FACE, NULL, NULL, NULL); } +int hc_face_set_priority(hc_sock_t *s, const char *conn_id_or_name, + uint32_t priority) { + return -1; // Not implemented +#if 0 + hc_object_t object; + memset(&object, 0, sizeof(hc_object_t)); + return hc_execute(s, ACTION_UPDATE, OBJECT_TYPE_FACE, &object, NULL); +#endif +} + GENERATE_FIND(face); DECLARE_OBJECT_OPS(OBJECT_TYPE_FACE, face); diff --git a/ctrl/libhicnctrl/src/socket.c b/ctrl/libhicnctrl/src/socket.c index c3636075d..956dc07c8 100644 --- a/ctrl/libhicnctrl/src/socket.c +++ b/ctrl/libhicnctrl/src/socket.c @@ -161,6 +161,10 @@ ERR_MALLOC: return NULL; } +hc_sock_t *hc_sock_create_forwarder(forwarder_type_t forwarder) { + return hc_sock_create(forwarder, NULL); +} + void hc_sock_free(hc_sock_t *s) { if (s->ops.disconnect) s->ops.disconnect(s); #ifdef ANDROID diff --git a/tests/2-nodes-hicn-light.yml b/tests/2-nodes-hicn-light.yml index be715e333..e86bbc7ee 100644 --- a/tests/2-nodes-hicn-light.yml +++ b/tests/2-nodes-hicn-light.yml @@ -16,7 +16,7 @@ services: sudo ip route add 192.168.1.2 via 192.168.1.1 dev br0 tee -a /tmp/hicn-light.conf <<EOF add listener udp local0 192.168.1.1 9199 br0 - add connection udp conn0 192.168.1.2 9199 192.168.1.1 9199 + add connection udp conn0 192.168.1.1 9199 192.168.1.2 9199 add route conn0 b002::/64 1 EOF @@ -45,7 +45,7 @@ services: tee -a /tmp/hicn-light.conf <<EOF add listener udp local0 192.168.1.2 9199 br0 - add connection udp conn0 192.168.1.1 9199 192.168.1.2 9199 + add connection udp conn0 192.168.1.2 9199 192.168.1.1 9199 add route conn0 b002::/64 1 EOF diff --git a/tests/config.sh b/tests/config.sh index 1420ef49e..b10d11204 100755 --- a/tests/config.sh +++ b/tests/config.sh @@ -358,7 +358,7 @@ function test_connections() { _=$(exec_command "${command}") command="add connection udp $CONN_NAME $ADDRESS 9695 $ADDRESS 9695 $INTERFACE" _=$(exec_command "${command}") - command="add connection udp $CONN_NAME_2 $ADDRESS 12345 $ADDRESS 9695 $INTERFACE" + command="add connection udp $CONN_NAME_2 $ADDRESS 9695 $ADDRESS 12345 $INTERFACE" assert_cmd_success "${command}" echo -n "List connections: " @@ -395,7 +395,7 @@ function test_connections() { echo -n "Add duplicated connection (same symbolic): " command="add connection udp $CONN_NAME $ADDRESS 9695 $ADDRESS 9695 $INTERFACE" _=$(exec_command "${command}") - command="add connection udp $CONN_NAME $ADDRESS 9695 $ADDRESS 12345 $INTERFACE" + command="add connection udp $CONN_NAME $ADDRESS 12345 $ADDRESS 9695 $INTERFACE" assert_cmd_failure "${command}" # This case is allowed, success code is returned and symbolic is not updated |