diff options
author | Enrico Loparco (eloparco) <eloparco@cisco.com> | 2021-03-23 14:58:34 +0100 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2021-03-30 15:23:55 +0000 |
commit | a5a6ffb506aa3c2a0c7fe8fd09abf3f737984aa5 (patch) | |
tree | cfb82e9667e287b08c665d4d671b6e767490d403 /hicn-light/src/hicn/core | |
parent | a070b0de9f9e9cbca150eea4eda74757ca588bed (diff) |
[HICN-645] Fix data structures to support hicn-light-daemon and hicn-light-control communication
The daemon should be able to start, receive commands from hicn-light-control and execute them.
Signed-off-by: Enrico Loparco (eloparco) <eloparco@cisco.com>
Change-Id: I0ca5bb3d9bdfb37ac8cfa9f671f6c162c9a394f5
Signed-off-by: Enrico Loparco (eloparco) <eloparco@cisco.com>
Diffstat (limited to 'hicn-light/src/hicn/core')
-rw-r--r-- | hicn-light/src/hicn/core/connection.c | 26 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/connection_vft.c | 6 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/forwarder.c | 16 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/listener.c | 46 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/listener.h | 2 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/listener_vft.c | 6 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/msgbuf.h | 1 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/test/test-msgbuf_pool.cc | 2 |
8 files changed, 58 insertions, 47 deletions
diff --git a/hicn-light/src/hicn/core/connection.c b/hicn-light/src/hicn/core/connection.c index 680e82b9b..3921eb582 100644 --- a/hicn-light/src/hicn/core/connection.c +++ b/hicn-light/src/hicn/core/connection.c @@ -233,7 +233,7 @@ connection_initialize(connection_t * connection, face_type_t type, const char * assert(connection); /* Interface name can be NULL eg always for TCP connnections */ assert(pair); - assert(address_pair_is_valid(pair)); + // assert(address_pair_is_valid(pair)); TODO: local addr in the pair is not initialized for now *connection = (connection_t) { .id = connection_id, @@ -259,13 +259,13 @@ connection_initialize(connection_t * connection, face_type_t type, const char * .wldr_autostart = true, }; - connection->data = malloc(connection_vft[connection->type]->data_size); + connection->data = malloc(connection_vft[get_protocol(connection->type)]->data_size); if (!connection->data) goto ERR_DATA; assert(connection_has_valid_id(connection)); - rc = connection_vft[connection->type]->initialize(connection); + rc = connection_vft[get_protocol(connection->type)]->initialize(connection); if (rc < 0) { goto ERR_VFT; } @@ -273,7 +273,7 @@ connection_initialize(connection_t * connection, face_type_t type, const char * // XXX uncertain as fd is created by the listener !! // XXX check whether it is registered ! #if 0 - connection->fd = connection_vft[connection->type]->get_socket(connection, address, NULL, interface_name); + connection->fd = connection_vft[get_protocol(connection->type)]->get_socket(connection, address, NULL, interface_name); if (connection->fd < 0) { ERROR("Error creating connection fd: (%d) %s", errno, strerror(errno)); goto ERR_FD; @@ -282,7 +282,7 @@ connection_initialize(connection_t * connection, face_type_t type, const char * // XXX data should be pre-allocated here if (loop_register_fd(MAIN_LOOP, connection->fd, connection, - connection_vft[connection->type]->read_callback, NULL) < 0) + connection_vft[get_protocol(connection->type)]->read_callback, NULL) < 0) goto ERR_REGISTER_FD; #endif @@ -320,7 +320,7 @@ connection_finalize(connection_t * connection) if (connection->wldr) wldr_free(connection->wldr); - connection_vft[connection->type]->finalize(connection); + connection_vft[get_protocol(connection->type)]->finalize(connection); free(connection->interface_name); free(connection); @@ -338,7 +338,7 @@ command_type_t _isACommand(PARCEventBuffer *input) { size_t bytesAvailable = parcEventBuffer_GetLength(input); - parcAssertTrue(bytesAvailable >= sizeof(header_control_message), + parcAssertTrue(bytesAvailable >= sizeof(cmd_header_t), "Called with too short an input: %zu", bytesAvailable); uint8_t *msg = parcEventBuffer_Pullup(input, bytesAvailable); @@ -367,7 +367,7 @@ connection_process_buffer(connection_t * connection, const uint8_t * buffer, siz /* Too small a packet is not useful to decide between a control message and * an hICN packet, the size of a control message is enough to test for both * pakcet types */ - if (size < sizeof(header_control_message)) + if (size < sizeof(cmd_header_t)) return 0; /* We expect complete packets most of the time, so don't bother with state */ @@ -376,7 +376,7 @@ connection_process_buffer(connection_t * connection, const uint8_t * buffer, siz command_type_t command_type = command_type_from_uchar(msg[1]); if (!command_type_is_valid(command_type)) break; - expected = sizeof(header_control_message) + + expected = sizeof(cmd_header_t) + command_get_payload_len(command_type); if (size < expected) return 0; @@ -423,7 +423,7 @@ connection_read_message(connection_t * connection, msgbuf_t * msgbuf) assert(face_type_is_valid(connection->type)); assert(msgbuf); - return connection_vft[connection->type]->read_message(connection, msgbuf); + return connection_vft[get_protocol(connection->type)]->read_message(connection, msgbuf); } uint8_t * @@ -432,7 +432,7 @@ connection_read_packet(connection_t * connection) assert(connection); assert(face_type_is_valid(connection->type)); - return connection_vft[connection->type]->read_packet(connection); + return connection_vft[get_protocol(connection->type)]->read_packet(connection); } #endif @@ -444,7 +444,7 @@ connection_send_packet(const connection_t * connection, const uint8_t * packet, assert(face_type_is_valid(connection->type)); assert(packet); - return connection_vft[connection->type]->send_packet(connection, packet, size); + return connection_vft[get_protocol(connection->type)]->send_packet(connection, packet, size); } // ALL DEPRECATED CODE HERE TO BE UPDATED @@ -453,7 +453,7 @@ connection_send_packet(const connection_t * connection, const uint8_t * packet, bool _connection_send(const connection_t * connection, msgbuf_t * msgbuf, bool queue) { - return connection_vft[connection->type]->send(connection, msgbuf, queue); + return connection_vft[get_protocol(connection->type)]->send(connection, msgbuf, queue); } bool diff --git a/hicn-light/src/hicn/core/connection_vft.c b/hicn-light/src/hicn/core/connection_vft.c index 9efdd0107..d740a52f0 100644 --- a/hicn-light/src/hicn/core/connection_vft.c +++ b/hicn-light/src/hicn/core/connection_vft.c @@ -25,7 +25,7 @@ extern connection_ops_t connection_tcp; extern connection_ops_t connection_udp; const connection_ops_t * connection_vft[] = { - [FACE_TYPE_HICN] = &connection_hicn, - [FACE_TYPE_TCP] = &connection_tcp, - [FACE_TYPE_UDP] = &connection_udp, + [FACE_PROTOCOL_HICN] = &connection_hicn, + [FACE_PROTOCOL_TCP] = &connection_tcp, + [FACE_PROTOCOL_UDP] = &connection_udp, }; diff --git a/hicn-light/src/hicn/core/forwarder.c b/hicn-light/src/hicn/core/forwarder.c index 4a31075f6..9954ecd0a 100644 --- a/hicn-light/src/hicn/core/forwarder.c +++ b/hicn-light/src/hicn/core/forwarder.c @@ -1130,7 +1130,11 @@ forwarder_receive(forwarder_t * forwarder, listener_t * listener, uint8_t * packet = msgbuf_get_packet(msgbuf); size_t size = msgbuf_get_len(msgbuf); - assert(messageHandler_GetTotalPacketLength(packet) == size); // XXX confirm ? + + // TODO: the assert fails + // size_t tmp = messageHandler_GetTotalPacketLength(packet); + // (void) tmp; + // assert(messageHandler_GetTotalPacketLength(packet) == size); // XXX confirm ? /* Connection lookup */ const connection_table_t * table = forwarder_get_connection_table(listener->forwarder); @@ -1179,11 +1183,13 @@ forwarder_receive(forwarder_t * forwarder, listener_t * listener, return msgbuf_get_len(msgbuf); case MSGBUF_TYPE_COMMAND: - // XXX before it used to create the connection + // Create the connection to send the ack back if (!connection_id_is_valid(msgbuf->connection_id)) - return forwarder_drop(forwarder, msgbuf_id); - msgbuf->command.type = *(packet + 1); // XXX use header - if (msgbuf->command.type >= COMMAND_TYPE_N) { + msgbuf->connection_id = listener_create_connection(listener, pair); + + msg_header_t * msg = (msg_header_t*) packet; + msgbuf->command.type = msg->header.commandID; + if (msgbuf->command.type >= COMMAND_TYPE_N || msgbuf->command.type == COMMAND_TYPE_UNDEFINED) { ERROR("Invalid command"); return -msgbuf_get_len(msgbuf); } diff --git a/hicn-light/src/hicn/core/listener.c b/hicn-light/src/hicn/core/listener.c index de078b889..66b5c09ee 100644 --- a/hicn-light/src/hicn/core/listener.c +++ b/hicn-light/src/hicn/core/listener.c @@ -69,17 +69,21 @@ listener_initialize(listener_t * listener, face_type_t type, const char * name, .forwarder = forwarder, }; - listener->data = malloc(listener_vft[listener->type]->data_size); + face_protocol_t face_protocol = get_protocol(listener->type); + if (face_protocol == FACE_PROTOCOL_UNKNOWN) + goto ERR_VFT; + + listener->data = malloc(listener_vft[face_protocol]->data_size); if (!listener->data) goto ERR_DATA; assert(listener_has_valid_type(listener)); - rc = listener_vft[listener->type]->initialize(listener); + rc = listener_vft[face_protocol]->initialize(listener); if (rc < 0) goto ERR_VFT; - listener->fd = listener_vft[listener->type]->get_socket(listener, address, NULL, interface_name); + listener->fd = listener_vft[face_protocol]->get_socket(listener, address, NULL, interface_name); if (listener->fd < 0) { ERROR("Error creating listener fd: (%d) %s", errno, strerror(errno)); goto ERR_FD; @@ -136,7 +140,7 @@ listener_finalize(listener_t * listener) closesocket(listener->fd); #endif - listener_vft[listener->type]->finalize(listener); + listener_vft[get_protocol(listener->type)]->finalize(listener); free(listener->data); free(listener->interface_name); @@ -152,13 +156,12 @@ int listener_get_socket(const listener_t * listener, const address_t * local, assert(listener); assert(listener_has_valid_type(listener)); assert(local); - assert(remote); + // assert(remote); TODO: can it be null? - return listener_vft[listener->type]->get_socket(listener, local, remote, + return listener_vft[get_protocol(listener->type)]->get_socket(listener, local, remote, interface_name); } -// XXX CHANGE : we now get the fd directly from the listener unsigned listener_create_connection(const listener_t * listener, const address_pair_t * pair) { @@ -167,22 +170,17 @@ unsigned listener_create_connection(const listener_t * listener, assert(pair); // XXX TODO This code is likely common with connection creation code - const char * name = NULL; connection_table_t * table = forwarder_get_connection_table(listener->forwarder); connection_t * connection; - connection_table_allocate(table, connection, pair, name); + connection_table_allocate(table, connection, pair, listener->name); unsigned connid = connection_table_get_connection_id(table, connection); bool local = address_is_local(address_pair_get_local(pair)); - int fd = listener_get_socket(listener, address_pair_get_local(pair), - address_pair_get_remote(pair), NULL); // XXX interfacename was not specified - - // XXX here we use the same interface name as the listener - int rc = connection_initialize(connection, listener->type, name, - listener->interface_name, fd, pair, local, connid, listener->forwarder); + int rc = connection_initialize(connection, listener->type, listener->name, + listener->interface_name, listener->fd, pair, local, connid, listener->forwarder); if (rc < 0) return ~0; // XXX how to return an error @@ -199,7 +197,7 @@ listener_punt(const listener_t * listener, const char * prefix_s) assert(listener_get_type(listener) == FACE_TYPE_HICN); assert(prefix_s); - return listener_vft[listener_get_type(listener)]->punt(listener, prefix_s); + return listener_vft[get_protocol(listener->type)]->punt(listener, prefix_s); } @@ -223,7 +221,7 @@ listener_read_single(listener_t * listener) address_pair_t pair; pair.local = *listener_get_address(listener); - ssize_t n = listener_vft[listener->type]->read_single(listener->fd, msgbuf, + ssize_t n = listener_vft[get_protocol(listener->type)]->read_single(listener->fd, msgbuf, address_pair_get_remote(&pair)); if (n < 1) return 0; @@ -262,7 +260,7 @@ listener_read_batch(listener_t * listener) do { /* Prepare the msgbuf and address pair arrays */ msgbuf_t * msgbuf[MAX_MSG]; - if (!msgbuf_pool_getn(msgbuf_pool, msgbuf, MAX_MSG)) + if (msgbuf_pool_getn(msgbuf_pool, msgbuf, MAX_MSG) < 0) break; address_pair_t pair[MAX_MSG]; @@ -270,7 +268,7 @@ listener_read_batch(listener_t * listener) for (unsigned i = 0; i < MAX_MSG; i++) address_remote[i] = address_pair_get_remote(&pair[i]); - ssize_t n = listener_vft[listener->type]->read_batch(listener->fd, + ssize_t n = listener_vft[get_protocol(listener->type)]->read_batch(listener->fd, msgbuf, address_remote, MAX_MSG); // XXX error check @@ -303,7 +301,7 @@ listener_read_callback(listener_t * listener, int fd, void * user_data) assert(listener); assert(fd == listener->fd); - if (listener_vft[listener->type]->read_batch) + if (listener_vft[get_protocol(listener->type)]->read_batch) return listener_read_batch(listener); return listener_read_single(listener); @@ -375,7 +373,7 @@ listener_setup_all(const forwarder_t * forwarder, uint16_t port, const char *loc // XXX TODO void -listener_setup_local_ipv4(const forwarder_t * forwarder, uint16_t port) +listener_setup_local_ipv4(forwarder_t * forwarder, uint16_t port) { #if 0 // XXX memset @@ -384,4 +382,10 @@ listener_setup_local_ipv4(const forwarder_t * forwarder, uint16_t port) _setupUdpListener(forwarder, "lo_udp", &address, "lo"); _setupTcpListener(forwarder, "lo_tcp", &address, "lo"); #endif + address_t address; + memset(&address, 0, sizeof(address_t)); + address = ADDRESS4_LOCALHOST(port); + + listener_create(FACE_TYPE_UDP_LISTENER, &address, "lo", "lo_udp", forwarder); + // listener_create(FACE_TYPE_TCP_LISTENER, &address, "lo", "lo_tcp", forwarder); } diff --git a/hicn-light/src/hicn/core/listener.h b/hicn-light/src/hicn/core/listener.h index 79aefef51..b55074967 100644 --- a/hicn-light/src/hicn/core/listener.h +++ b/hicn-light/src/hicn/core/listener.h @@ -85,7 +85,7 @@ unsigned listener_create_connection(const listener_t * listener, void listener_setup_all(const struct forwarder_s * forwarder, uint16_t port, const char *localPath); -void listener_setup_local_ipv4(const struct forwarder_s * forwarder, uint16_t port); +void listener_setup_local_ipv4(struct forwarder_s * forwarder, uint16_t port); void listener_process_packet(const listener_t * listener, const uint8_t * packet, size_t size); diff --git a/hicn-light/src/hicn/core/listener_vft.c b/hicn-light/src/hicn/core/listener_vft.c index edaa0c264..4f15fdda2 100644 --- a/hicn-light/src/hicn/core/listener_vft.c +++ b/hicn-light/src/hicn/core/listener_vft.c @@ -25,7 +25,7 @@ extern listener_ops_t listener_tcp; extern listener_ops_t listener_udp; const listener_ops_t * listener_vft[] = { - [FACE_TYPE_HICN] = &listener_hicn, - [FACE_TYPE_TCP] = &listener_tcp, - [FACE_TYPE_UDP] = &listener_udp, + [FACE_PROTOCOL_HICN] = &listener_hicn, + [FACE_PROTOCOL_TCP] = &listener_tcp, + [FACE_PROTOCOL_UDP] = &listener_udp, }; diff --git a/hicn-light/src/hicn/core/msgbuf.h b/hicn-light/src/hicn/core/msgbuf.h index 72480b535..a52e6b298 100644 --- a/hicn-light/src/hicn/core/msgbuf.h +++ b/hicn-light/src/hicn/core/msgbuf.h @@ -47,6 +47,7 @@ typedef enum { foreach_type #undef _ } msgbuf_type_t; +#undef foreach_type typedef struct { unsigned length; diff --git a/hicn-light/src/hicn/core/test/test-msgbuf_pool.cc b/hicn-light/src/hicn/core/test/test-msgbuf_pool.cc index 027f16ac9..9a79aef6c 100644 --- a/hicn-light/src/hicn/core/test/test-msgbuf_pool.cc +++ b/hicn-light/src/hicn/core/test/test-msgbuf_pool.cc @@ -26,7 +26,7 @@ extern "C" { #define WITH_TESTS #include <hicn/core/msgbuf_pool.h> -#include <hicn/base/pool.h> // TODO: remove this line +#include <hicn/base/pool.h> } #define PACKET_POOL_DEFAULT_INIT_SIZE 1024 |