aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light')
-rw-r--r--hicn-light/src/hicn/cli/hicnc.c28
-rw-r--r--hicn-light/src/hicn/config/configuration.c44
-rw-r--r--hicn-light/src/hicn/config/configuration.h5
-rw-r--r--hicn-light/src/hicn/config/controlListConnections.c4
-rw-r--r--hicn-light/src/hicn/config/controlListListeners.c4
-rw-r--r--hicn-light/src/hicn/config/controlListPolicies.c4
-rw-r--r--hicn-light/src/hicn/config/controlListRoutes.c4
-rw-r--r--hicn-light/src/hicn/core/connection.c26
-rw-r--r--hicn-light/src/hicn/core/connection_vft.c6
-rw-r--r--hicn-light/src/hicn/core/forwarder.c16
-rw-r--r--hicn-light/src/hicn/core/listener.c46
-rw-r--r--hicn-light/src/hicn/core/listener.h2
-rw-r--r--hicn-light/src/hicn/core/listener_vft.c6
-rw-r--r--hicn-light/src/hicn/core/msgbuf.h1
-rw-r--r--hicn-light/src/hicn/core/test/test-msgbuf_pool.cc2
-rw-r--r--hicn-light/src/hicn/io/base.c5
-rw-r--r--hicn-light/src/hicn/io/tcp.c4
-rw-r--r--hicn-light/src/hicn/io/udp.c15
-rw-r--r--hicn-light/src/hicn/utils/utils.c10
19 files changed, 123 insertions, 109 deletions
diff --git a/hicn-light/src/hicn/cli/hicnc.c b/hicn-light/src/hicn/cli/hicnc.c
index d6c7c4180..2c1c3500e 100644
--- a/hicn-light/src/hicn/cli/hicnc.c
+++ b/hicn-light/src/hicn/cli/hicnc.c
@@ -123,9 +123,6 @@ main(int argc, char * const * argv)
goto ERR_PARSE;
}
-
- hc_data_t * data;
-
hc_sock_t * s;
if (server_ip) {
if (server_port == 0)
@@ -147,28 +144,13 @@ main(int argc, char * const * argv)
goto ERR_CONNECT;
}
- /* XXX connection list */
- if (hc_connection_list(s, &data) < 0) {
- fprintf(stderr, "Error running command");
- goto ERR_CMD;
- }
-
- char buf[MAXSZ_HC_CONNECTION]; // XXX
- foreach_connection(c, data) {
- /* XXX connection print */
- int rc = hc_connection_snprintf(buf, MAXSZ_HC_CONNECTION, c);
- if (rc < 0) {
- strncpy(buf, "(Error)", MAXSZ_HC_CONNECTION);
- } else if (rc >= MAXSZ_HC_CONNECTION) {
- buf[MAXSZ_HC_CONNECTION-1] = '\0';
- buf[MAXSZ_HC_CONNECTION-2] = '.';
- buf[MAXSZ_HC_CONNECTION-3] = '.';
- buf[MAXSZ_HC_CONNECTION-4] = '.';
+ // TODO: handle all commands
+ if (command.action == ACTION_CREATE && command.object.type == OBJECT_LISTENER) {
+ if (hc_listener_create(s, &command.object.listener) < 0) {
+ fprintf(stderr, "Error running command");
+ goto ERR_CMD;
}
- printf("%s\n", buf);
}
-
- hc_data_free(data);
exit(EXIT_SUCCESS);
ERR_CMD:
diff --git a/hicn-light/src/hicn/config/configuration.c b/hicn-light/src/hicn/config/configuration.c
index fed9d95ed..f5ed231b2 100644
--- a/hicn-light/src/hicn/config/configuration.c
+++ b/hicn-light/src/hicn/config/configuration.c
@@ -21,6 +21,8 @@
* @endcode
*/
+#include <hicn/ctrl/commands.h>
+
#ifndef _WIN32
#include <arpa/inet.h>
#include <unistd.h>
@@ -41,7 +43,7 @@
#include <hicn/core/listener.h> //the listener list
#include <hicn/core/listener_table.h>
-#include <hicn/utils/commands.h>
+#include <hicn/ctrl/commands.h>
#include <hicn/utils/utils.h>
#include <hicn/utils/punting.h>
#include <hicn/util/log.h>
@@ -210,13 +212,11 @@ configuration_on_listener_add(configuration_t * config, uint8_t * packet,
}
// NOTE: interface_name is expected NULL for hICN listener
- face_type_t face_type;
- if (!face_type_is_defined(control->listener_type))
+ face_type_t face_type = get_face_type_from_listener_type((hc_connection_type_t) control->listenerType);
+ if (!face_type_is_defined(face_type))
goto NACK;
- face_type = (face_type_t)control->listener_type;
-
- listener = listener_create(face_type, &address, control->interface_name, control->symbolic, forwarder);
+ listener = listener_create(face_type, &address, control->interfaceName, control->symbolic, forwarder);
if (!listener)
goto NACK;
@@ -1061,10 +1061,11 @@ uint8_t *
configuration_on_punting_add(configuration_t * config, uint8_t * packet,
unsigned ingress_id)
{
-#if !defined(__APPLE__) && !defined(_WIN32) && defined(PUNTING)
+// #if !defined(__APPLE__) && !defined(_WIN32) && defined(PUNTING)
msg_punting_add_t * msg = (msg_punting_add_t *)packet;
- cmd_punting_add_t * control = &msg->payload;
+#if !defined(__APPLE__) && !defined(_WIN32) && defined(PUNTING)
+ cmd_punting_add_t * control = &msg->payload;
if (ip_address_empty(&control->address))
goto NACK;
@@ -1409,9 +1410,11 @@ configuration_receive_command(configuration_t * config, msgbuf_t * msgbuf)
break;
}
- connection_table_t * table = forwarder_get_connection_table(config->forwarder);
- const connection_t *connection = connection_table_at(table, ingress_id);
- connection_send_packet(connection, reply, false);
+ if (connection_id_is_valid(msgbuf->connection_id)) {
+ connection_table_t * table = forwarder_get_connection_table(config->forwarder);
+ const connection_t *connection = connection_table_at(table, ingress_id);
+ connection_send_packet(connection, reply, sizeof(cmd_header_t));
+ }
switch (msgbuf->command.type) {
case COMMAND_TYPE_LISTENER_LIST:
@@ -1429,3 +1432,22 @@ configuration_receive_command(configuration_t * config, msgbuf_t * msgbuf)
// XXX only if we consumed the whole packet.
return (ssize_t)msgbuf_get_len(msgbuf);
}
+
+face_type_t get_face_type_from_listener_type(hc_connection_type_t listener_type) {
+ face_type_t face_type;
+ switch (listener_type) {
+ case CONNECTION_TYPE_TCP:
+ face_type = FACE_TYPE_TCP_LISTENER;
+ break;
+ case CONNECTION_TYPE_UDP:
+ face_type = FACE_TYPE_UDP_LISTENER;
+ break;
+ case CONNECTION_TYPE_HICN:
+ face_type = FACE_TYPE_HICN_LISTENER;
+ break;
+ default:
+ face_type = FACE_TYPE_UNDEFINED;
+ }
+ return face_type;
+}
+
diff --git a/hicn-light/src/hicn/config/configuration.h b/hicn-light/src/hicn/config/configuration.h
index fa1b0410c..1cf772b42 100644
--- a/hicn-light/src/hicn/config/configuration.h
+++ b/hicn-light/src/hicn/config/configuration.h
@@ -27,7 +27,8 @@
#define configuration_h
#include "../core/msgbuf.h"
-#include "../utils/commands.h"
+#include "../core/strategy.h"
+#include <hicn/ctrl/api.h>
typedef struct configuration_s configuration_t;
@@ -126,4 +127,6 @@ uint8_t *
configuration_dispatch_command(configuration_t * config, command_type_t command_type,
uint8_t * packet, unsigned ingress_id);
+face_type_t get_face_type_from_listener_type(hc_connection_type_t listener_type);
+
#endif // configuration_h
diff --git a/hicn-light/src/hicn/config/controlListConnections.c b/hicn-light/src/hicn/config/controlListConnections.c
index c47431726..fedc99868 100644
--- a/hicn-light/src/hicn/config/controlListConnections.c
+++ b/hicn-light/src/hicn/config/controlListConnections.c
@@ -98,8 +98,8 @@ static CommandReturn _controlListConnections_Execute(CommandParser *parser,
}
// Process/Print message
- header_control_message *receivedHeader =
- (header_control_message *)response[0].iov_base;
+ cmd_header_t *receivedHeader =
+ (cmd_header_t *)response[0].iov_base;
uint8_t *receivedPayload = (uint8_t *)response[1].iov_base;
char *sourceString = NULL;
diff --git a/hicn-light/src/hicn/config/controlListListeners.c b/hicn-light/src/hicn/config/controlListListeners.c
index f0ab820f5..e8909fc7c 100644
--- a/hicn-light/src/hicn/config/controlListListeners.c
+++ b/hicn-light/src/hicn/config/controlListListeners.c
@@ -79,8 +79,8 @@ static CommandReturn _controlListListeners_Execute(CommandParser *parser,
}
// Process/Print message
- header_control_message *receivedHeader =
- (header_control_message *)response[0].iov_base;
+ cmd_header_t *receivedHeader =
+ (cmd_header_t *)response[0].iov_base;
uint8_t *receivedPayload = (uint8_t *)response[1].iov_base;
// Allocate output to pass to the main function if the call is not interactive
diff --git a/hicn-light/src/hicn/config/controlListPolicies.c b/hicn-light/src/hicn/config/controlListPolicies.c
index 9ea3bae75..424893a3d 100644
--- a/hicn-light/src/hicn/config/controlListPolicies.c
+++ b/hicn-light/src/hicn/config/controlListPolicies.c
@@ -92,8 +92,8 @@ static CommandReturn _controlListPolicies_Execute(CommandParser *parser,
}
// Process/Print message
- header_control_message *receivedHeader =
- (header_control_message *)response[0].iov_base;
+ cmd_header_t *receivedHeader =
+ (cmd_header_t *)response[0].iov_base;
uint8_t *receivedPayload = (uint8_t *)response[1].iov_base;
if (!receivedPayload) {
printf("No payload!\n");
diff --git a/hicn-light/src/hicn/config/controlListRoutes.c b/hicn-light/src/hicn/config/controlListRoutes.c
index 33a1ac6f5..df1c24334 100644
--- a/hicn-light/src/hicn/config/controlListRoutes.c
+++ b/hicn-light/src/hicn/config/controlListRoutes.c
@@ -91,8 +91,8 @@ static CommandReturn _controlListRoutes_Execute(CommandParser *parser,
}
// Process/Print message
- header_control_message *receivedHeader =
- (header_control_message *)response[0].iov_base;
+ cmd_header_t *receivedHeader =
+ (cmd_header_t *)response[0].iov_base;
uint8_t *receivedPayload = (uint8_t *)response[1].iov_base;
// Allocate output to pass to the main function if the call is not interactive
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
diff --git a/hicn-light/src/hicn/io/base.c b/hicn-light/src/hicn/io/base.c
index 35d8915a8..bd5904ccb 100644
--- a/hicn-light/src/hicn/io/base.c
+++ b/hicn-light/src/hicn/io/base.c
@@ -115,11 +115,16 @@ ssize_t io_read_batch_socket(int fd, msgbuf_t ** msgbuf,
}
/* Assign size to msgbuf, and build address pair */
+ // TODO: local (in pair) is not initialized
for (int i = 0; i < n; i++) {
struct mmsghdr *msg = &msghdr[i];
msgbuf[i]->length = msg->msg_hdr.msg_iovlen;
**address = *(address_t*)msg->msg_hdr.msg_name;
+
+ struct sockaddr_in *src = msghdr[i].msg_hdr.msg_name;
+ DEBUG("msg received from port %u", ntohs(src->sin_port));
}
+ break;
}
return n;
diff --git a/hicn-light/src/hicn/io/tcp.c b/hicn-light/src/hicn/io/tcp.c
index e4e2b06af..e4f5d196f 100644
--- a/hicn-light/src/hicn/io/tcp.c
+++ b/hicn-light/src/hicn/io/tcp.c
@@ -391,14 +391,14 @@ connection_tcp_read_message(connection_t * connection, msgbuf_t * msgbuf)
size_t n = evbuffer_get_length(data->evbuffer);
// XXX this check was wrong
- // parcAssertTrue(n >= sizeof(header_control_message),
+ // parcAssertTrue(n >= sizeof(cmd_header_t),
"Called with too short an input: %zu", n);
// XXX WTF
if (stream->next_len == 0) {
// this linearizes the first messageHandler_GetIPv6HeaderLength() bytes of the
// input buffer's iovecs and returns a pointer to it.
- uint8_t *fh = parcEventBuffer_Pullup(data->evbuffer, sizeof(header_control_message));
+ uint8_t *fh = parcEventBuffer_Pullup(data->evbuffer, sizeof(cmd_header_t));
// Calculate the total message size based on the fixed header
stream->next_len = messageHandler_GetTotalPacketLength(fh);
diff --git a/hicn-light/src/hicn/io/udp.c b/hicn-light/src/hicn/io/udp.c
index 38d643838..edff902de 100644
--- a/hicn-light/src/hicn/io/udp.c
+++ b/hicn-light/src/hicn/io/udp.c
@@ -215,15 +215,6 @@ listener_udp_initialize(listener_t * listener)
listener_udp_data_t * data = listener->data;
assert(data);
#endif
-
- // XXX Socket creation should be a function per-se and not be called in
- // initialize !
- listener->fd = listener_get_socket(listener, &listener->address, NULL,
- listener->interface_name);
- if (listener->fd < 0) {
- ERROR("Error creating UDP socket: (%d) %s", errno, strerror(errno));
- return -1;
- }
return 0;
}
@@ -249,7 +240,7 @@ int
listener_udp_get_socket(const listener_t * listener, const address_t * local,
const address_t * remote, const char * interface_name)
{
- int fd = socket(address_family(remote), SOCK_DGRAM, 0);
+ int fd = socket(address_family(local), SOCK_DGRAM, 0);
if (fd < 0)
goto ERR_SOCKET;
@@ -257,7 +248,7 @@ listener_udp_get_socket(const listener_t * listener, const address_t * local,
goto ERR;
}
- if (bind(fd, address_sa(local), address_socklen(remote)) < 0) {
+ if (bind(fd, address_sa(local), address_socklen(local)) < 0) {
perror("bind");
goto ERR;
}
@@ -313,7 +304,7 @@ connection_udp_initialize(connection_t * connection)
{
assert(connection);
- assert(connection->type == FACE_TYPE_UDP);
+ assert(connection->type == FACE_TYPE_UDP || connection->type == FACE_TYPE_UDP_LISTENER);
assert(connection->interface_name);
connection_udp_data_t * data = connection->data;
diff --git a/hicn-light/src/hicn/utils/utils.c b/hicn-light/src/hicn/utils/utils.c
index 42bcb7f87..2bfd8dc94 100644
--- a/hicn-light/src/hicn/utils/utils.c
+++ b/hicn-light/src/hicn/utils/utils.c
@@ -128,8 +128,8 @@ bool utils_IsNumber(const char *string) {
//uint32_t currentSeqNum = utils_GetNextSequenceNumber();
//
//// Allocate and fill the header
-//header_control_message *headerControlMessage =
-// parcMemory_AllocateAndClear(sizeof(header_control_message));
+//cmd_header_t *headerControlMessage =
+// parcMemory_AllocateAndClear(sizeof(cmd_header_t));
//headerControlMessage->messageType = REQUEST_LIGHT;
//headerControlMessage->commandID = command;
//headerControlMessage->seqNum = currentSeqNum;
@@ -139,14 +139,14 @@ bool utils_IsNumber(const char *string) {
//
//struct iovec msg[2];
//msg[0].iov_base = headerControlMessage;
-//msg[0].iov_len = sizeof(header_control_message);
+//msg[0].iov_len = sizeof(cmd_header_t);
//msg[1].iov_base = payload;
//msg[1].iov_len = payloadLen;
//
//struct iovec *response = controlState_WriteRead(state, msg);
//
-//header_control_message *receivedHeader =
-// (header_control_message *)response[0].iov_base;
+//cmd_header_t *receivedHeader =
+// (cmd_header_t *)response[0].iov_base;
//if (receivedHeader->seqNum != currentSeqNum) {
//printf("Seq number is NOT correct: expected %d got %d \n", currentSeqNum,
// receivedHeader->seqNum);