aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2020-07-29 09:05:08 +0200
committerMauro Sardara <msardara@cisco.com>2020-09-09 11:08:44 +0200
commitaba0a8ce4aeae0392b71658e9afaedc0d857a1a7 (patch)
tree739c9b88fd6696a992893c4f4d1c2af7c100032d
parentd5071d0c80e1da5e28c2430ba4b579b886373cd2 (diff)
[HICN-555] Reworked loop
Signed-off-by: Mauro Sardara <msardara@cisco.com> Change-Id: Ia837da43b797a3f4d30d832e7ad2b0ec8cc3fefe Signed-off-by: Mauro Sardara <msardara@cisco.com>
-rw-r--r--CMakeLists.txt1
-rw-r--r--hicn-light/CMakeLists.txt2
-rw-r--r--hicn-light/src/hicn/base/loop.c341
-rw-r--r--hicn-light/src/hicn/base/loop.h88
-rw-r--r--hicn-light/src/hicn/core/address_pair.h6
-rw-r--r--hicn-light/src/hicn/core/connection.c4
-rw-r--r--hicn-light/src/hicn/core/connection.h2
-rw-r--r--hicn-light/src/hicn/core/forwarder.c4
-rw-r--r--hicn-light/src/hicn/core/listener.c16
-rw-r--r--hicn-light/src/hicn/core/listener.h2
-rw-r--r--hicn-light/src/hicn/core/mapme.c39
-rw-r--r--hicn-light/src/hicn/core/prefix_stats.c25
-rw-r--r--hicn-light/src/hicn/core/prefix_stats.h4
-rw-r--r--hicn-light/src/hicn/io/hicn.c4
-rw-r--r--hicn-light/src/hicn/io/tcp.c8
-rw-r--r--hicn-light/src/hicn/io/udp.c5
-rw-r--r--hicn-plugin/src/faces/ip/face_ip.c2
-rw-r--r--scripts/build-packages.sh4
18 files changed, 236 insertions, 321 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index afbd45f..c76d89e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -80,7 +80,6 @@ set(BUILD_UTILS_DIR utils)
set(BUILD_APPS_DIR apps)
set(BUILD_CTRL_DIR ctrl)
set(BUILD_HICNPLUGIN_DIR hicn-plugin)
-set(BUILD_SYSREPOPLUGIN_DIR ctrl/sysrepo-plugins)
set(BUILD_EXTRAS_DIR extras/)
set(BUILD_TELEMETRY_DIR telemetry)
diff --git a/hicn-light/CMakeLists.txt b/hicn-light/CMakeLists.txt
index 4a61505..dd7d7fc 100644
--- a/hicn-light/CMakeLists.txt
+++ b/hicn-light/CMakeLists.txt
@@ -60,7 +60,7 @@ if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
find_package_wrapper(Libhicn REQUIRED)
else()
if (DISABLE_SHARED_LIBRARIES)
- if (WIN32)
+ if (WIN32)
set(HICN_LIBRARIES ${LIBEVENT_STATIC} ${LIBHICN_STATIC})
else ()
set(HICN_LIBRARIES ${LIBEVENT_STATIC} ${LIBHICN_STATIC} log)
diff --git a/hicn-light/src/hicn/base/loop.c b/hicn-light/src/hicn/base/loop.c
index fecab9c..34aa94d 100644
--- a/hicn-light/src/hicn/base/loop.c
+++ b/hicn-light/src/hicn/base/loop.c
@@ -20,51 +20,57 @@
#include <assert.h>
#include <event2/event.h>
+#include <event2/event_struct.h>
#include <event2/thread.h>
-#include <fcntl.h> // fcntl
+#include <fcntl.h> // fcntl
#ifdef WITH_THREAD
#include <pthread.h>
#endif /* WITH_THREAD */
-#include <stdlib.h>
-#include <sys/timerfd.h>
-#include <unistd.h> // fcntl
-
#include <hicn/util/log.h>
-#include <hicn/util/map.h>
+#include <stdlib.h>
+#include <unistd.h> // fcntl
#include "loop.h"
-loop_t * MAIN_LOOP = NULL;
+loop_t *MAIN_LOOP = NULL;
/**
* \brief Holds all callback parameters
*/
typedef struct {
- void * owner;
+ void *owner;
fd_callback_t callback;
- void * data;
+ void *data;
} cb_wrapper_args_t;
-TYPEDEF_MAP_H(event_map, int, struct event *);
-TYPEDEF_MAP(event_map, int, struct event *, int_cmp, int_snprintf, generic_snprintf);
-
-/* Map that associates timer fds with their associated cb_wrapper_args_t */
-TYPEDEF_MAP_H(timer_fd_map, int, cb_wrapper_args_t *);
-TYPEDEF_MAP(timer_fd_map, int, cb_wrapper_args_t *, int_cmp, int_snprintf, generic_snprintf);
+typedef enum {
+ EVTYPE_TIMER,
+ EVTYPE_FD,
+} event_type_t;
struct loop_s {
- struct event_base * event_base;
- event_map_t * event_map;
- timer_fd_map_t * timer_fd_map;
-#ifdef WITH_THREAD
- pthread_t thread;
-#endif /* WITH_THREAD */
+ /* Libevent-based implementation */
+ struct event_base *event_base;
+};
+
+struct event_s {
+ /* Reference to loop */
+ loop_t *loop;
+
+ /* Event type*/
+ event_type_t event_type;
+
+ /* Raw event */
+ struct event raw_event;
+
+ /* Callback on event */
+ cb_wrapper_args_t callback;
};
-loop_t *
-loop_create()
+loop_t *loop_create()
{
- loop_t * loop = malloc(sizeof(loop_t));
+ loop_t *loop = malloc(sizeof(loop_t));
+
if (!loop) {
ERROR("[loop_create] Failed to allocate memory");
goto ERR_MALLOC;
@@ -75,281 +81,128 @@ loop_create()
#endif /* WITH_THREAD */
loop->event_base = event_base_new();
- if (!loop)
- goto ERR_EVENT;
-
- loop->event_map = event_map_create();
- if (!loop->event_map) {
- ERROR("[loop_create] Failed to create event_map");
- goto ERR_EVENT_MAP;
- }
-
- loop->timer_fd_map = timer_fd_map_create();
- if (!loop->timer_fd_map) {
- ERROR("[loop_create] Failed to create timer_fd_map");
- goto ERR_TIMER_FD_MAP;
- }
+ if (!loop->event_base) goto ERR_EVENT;
event_set_log_callback(NULL);
return loop;
- timer_fd_map_free(loop->timer_fd_map);
-ERR_TIMER_FD_MAP:
- event_map_free(loop->event_map);
-ERR_EVENT_MAP:
- event_base_free(loop->event_base);
ERR_EVENT:
- free(loop);
ERR_MALLOC:
return NULL;
}
-void
-loop_free(loop_t * loop)
-{
- /*
- * Release all timer cb_wrapper_args_t
- *
- * We need to stop all timers, this should release associated fd events at
- * the same time... for that reason, this code has to be called before
- * releasing events
- */
-
- int * timer_fd_map_array;
- int n = timer_fd_map_get_key_array(loop->timer_fd_map, &timer_fd_map_array);
- if (n < 0) {
- ERROR("[loop_free] Could not get event map array");
- } else {
- for (unsigned i = 0; i < n; i++) {
- int fd = timer_fd_map_array[i];
- if (loop_unregister_timer(loop, fd) < 0) {
- ERROR("[loop_free] Could not unregister timer");
- }
- }
- free(timer_fd_map_array);
- }
- timer_fd_map_free(loop->timer_fd_map);
-
- /* Release all events */
+void loop_free(loop_t *loop) { event_base_free(loop->event_base); }
- int * event_map_array;
- n = event_map_get_key_array(loop->event_map, &event_map_array);
- if (n < 0) {
- ERROR("[loop_free] Could not get event map array");
- } else {
- for (unsigned i = 0; i < n; i++) {
- int fd = event_map_array[i];
- if (loop_unregister_fd(loop, fd) < 0) {
- ERROR("[loop_free] Could not unregister fd");
- }
- }
- free(event_map_array);
- }
- event_map_free(loop->event_map);
-
- event_base_free(loop->event_base);
-
- free(loop);
-}
-
-int
-loop_dispatch(loop_t * loop)
+int loop_dispatch(loop_t *loop)
{
-#ifdef WITH_THREAD
- if (pthread_create(&loop->thread, NULL, (void * (*)(void *))event_base_dispatch, loop->event_base)) {
- fprintf(stderr, "Error creating thread\n");
- return -1;
- }
-#else
- event_base_dispatch(loop->event_base);
-#endif /* WITH_THREAD */
+ event_base_loop(loop->event_base, 0);
return 0;
}
-int
-loop_undispatch(loop_t * loop)
-{
-#ifdef WITH_THREAD
- DEBUG("Waiting for loop to terminate...");
- if(pthread_join(loop->thread, NULL)) {
- fprintf(stderr, "Error joining thread\n");
- return -1;
- }
- DEBUG("Loop terminated !");
-#endif /* WITH_THREAD */
- return 0;
-}
+int loop_undispatch(loop_t *loop) { return 0; }
-void
-loop_break(loop_t * loop)
-{
- event_base_loopbreak(loop->event_base);
-}
+void loop_break(loop_t *loop) { event_base_loopbreak(loop->event_base); }
-void cb_wrapper(evutil_socket_t fd, short what, void * arg) {
- cb_wrapper_args_t * cb_wrapper_args = arg;
- cb_wrapper_args->callback(cb_wrapper_args->owner, fd, cb_wrapper_args->data);
+void cb_wrapper(evutil_socket_t fd, short what, void *arg)
+{
+ cb_wrapper_args_t *cb_wrapper_args = arg;
+ cb_wrapper_args->callback(cb_wrapper_args->owner, fd,
+ cb_wrapper_args->data);
}
-int
-loop_register_fd(loop_t * loop, int fd, void * callback_owner,
- fd_callback_t callback, void * callback_data)
+static inline void _event_create(event_t **event, loop_t *loop,
+ event_type_t type, void *callback_owner,
+ fd_callback_t callback, void *callback_data)
{
- /* This will be freed with the event */
- cb_wrapper_args_t * cb_wrapper_args = malloc(sizeof(cb_wrapper_args_t));
- *cb_wrapper_args = (cb_wrapper_args_t) {
+ *event = malloc(sizeof(event_t));
+ (*event)->callback = (cb_wrapper_args_t){
.owner = callback_owner,
.callback = callback,
.data = callback_data,
};
+ (*event)->event_type = type;
+ (*event)->loop = loop;
+}
+
+int loop_fd_event_create(event_t **event, loop_t *loop, int fd,
+ void *callback_owner, fd_callback_t callback,
+ void *callback_data)
+{
+ _event_create(event, loop, EVTYPE_FD, callback_owner, callback,
+ callback_data);
evutil_make_socket_nonblocking(fd);
- struct event * event = event_new(loop->event_base, fd, EV_READ | EV_PERSIST, cb_wrapper, cb_wrapper_args);
- if (!event) {
- ERROR("[loop_register_fd] event_new");
- goto ERR_EVENT_NEW;
- }
+ event_assign(&(*event)->raw_event, loop->event_base, fd,
+ EV_READ | EV_PERSIST, cb_wrapper, &(*event)->callback);
+
+ return 0;
+}
+
+int loop_fd_event_register(event_t *event)
+{
+ assert(event->event_type == EVTYPE_FD);
- if (event_add(event, NULL) < 0) {
+ if (event_add(&event->raw_event, NULL) < 0) {
ERROR("[loop_register_fd] event_add");
goto ERR_EVENT_ADD;
}
- if (event_map_add(loop->event_map, fd, event) < 0) {
- ERROR("[loop_register_fd] event_map_add");
- goto ERR_EVENT_MAP;
- }
-
return 0;
-ERR_EVENT_MAP:
ERR_EVENT_ADD:
- event_free(event);
-ERR_EVENT_NEW:
return -1;
}
-int
-loop_unregister_fd(loop_t * loop, int fd)
+int loop_event_unregister(event_t *event)
{
- struct event * event = NULL;
-
- if (event_map_remove(loop->event_map, fd, &event) < 0) {
- ERROR("[loop_unregister_fd] Error removing event associated to fd");
- return -1;
- }
-
- assert(event);
-
- cb_wrapper_args_t * cb_wrapper_args = event_get_callback_arg(event);
- free(cb_wrapper_args);
-
- event_del(event);
- event_free(event);
-
+ assert(event->event_type == EVTYPE_FD);
+ event_del(&event->raw_event);
return 0;
}
-int
-loop_timer_callback(loop_t * loop, int fd, void * data)
+int loop_timer_create(event_t **timer, loop_t *loop, void *callback_owner,
+ fd_callback_t callback, void *callback_data)
{
- char buf[1024]; /* size is not important */
- cb_wrapper_args_t * cb_wrapper_args = data;
- while (read(fd, &buf, sizeof(buf)) > 0)
- ;
+ _event_create(timer, loop, EVTYPE_TIMER, callback_owner, callback,
+ callback_data);
- int rc = cb_wrapper_args->callback(cb_wrapper_args->owner, fd,
- cb_wrapper_args->data);
+ evtimer_assign(&(*timer)->raw_event, loop->event_base, cb_wrapper,
+ &(*timer)->callback);
- return rc;
+ return 0;
}
-int
-_loop_register_timer(loop_t * loop, unsigned delay_ms, void * owner,
- fd_callback_t callback, void * data)
+static inline void _ms_to_timeval(unsigned delay_ms, struct timeval *tv)
{
- int fd = timerfd_create(CLOCK_MONOTONIC, 0);
- if (fd == -1) {
- perror("timerfd_create");
- return -1;
- }
-
- if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
- perror("fcntl");
- return -1;
- }
-
- struct itimerspec ts = {
- .it_interval = {
- .tv_sec = delay_ms / 1000,
- .tv_nsec = (delay_ms % 1000) * 1000000,
- },
- .it_value = {
- .tv_sec = delay_ms / 1000,
- .tv_nsec = (delay_ms % 1000) * 1000000,
- }
- };
-
- if (timerfd_settime(fd, 0, &ts, NULL) == -1) {
- perror("timerfd_settime");
- return -1;
- }
+ tv->tv_sec = delay_ms / 1000;
+ tv->tv_usec = (delay_ms % 1000) * 1000;
+}
- /* This should be freed together with the timer release */
- cb_wrapper_args_t * cb_wrapper_args = malloc(sizeof(cb_wrapper_args_t));
- *cb_wrapper_args = (cb_wrapper_args_t) {
- .owner = owner,
- .callback = callback,
- .data = data,
- };
+int loop_timer_register(event_t *timer, unsigned delay_ms)
+{
+ assert(timer->event_type == EVTYPE_TIMER);
- if (timer_fd_map_add(loop->timer_fd_map, fd, cb_wrapper_args) < 0) {
- ERROR("[loop_register_timer] Could not add cb_wrapper to timer map");
- return -1;
- }
+ struct timeval tv;
+ _ms_to_timeval(delay_ms, &tv);
- if (loop_register_fd(loop, fd, loop,
- (fd_callback_t) loop_timer_callback, cb_wrapper_args) < 0) {
- ERROR("[loop_register_timer] Error registering fd to event loop");
- return -1;
+ if (tv.tv_sec == 0 && tv.tv_usec == 0) {
+ event_active(&timer->raw_event, EV_TIMEOUT, 0);
+ } else {
+ event_add(&timer->raw_event, &tv);
}
- return fd;
+ return 0;
}
-int
-loop_unregister_timer(loop_t * loop, int fd)
+int loop_timer_is_enabled(event_t *timer)
{
- struct itimerspec ts = {
- .it_interval = {
- .tv_sec = 0,
- .tv_nsec = 0,
- },
- .it_value = { /* This value disables the timer */
- .tv_sec = 0,
- .tv_nsec = 0,
- }
- };
- ts.it_value.tv_sec = 0;
-
- if (timerfd_settime(fd, 0, &ts, NULL) == -1) {
- perror("timerfd_settime");
- return -1;
- }
-
- cb_wrapper_args_t * cb_wrapper_args;
- if (timer_fd_map_remove(loop->timer_fd_map, fd, &cb_wrapper_args) < 0) {
- ERROR("[loop_unregister_timer] Could not remove cb_wrapper from timer map");
- return -1;
- }
- assert(cb_wrapper_args);
- free(cb_wrapper_args);
-
- if (loop_unregister_fd(loop, fd) < 0) {
- ERROR("[loop_unregister_timer] Error unregistering fd from event loop");
- return -1;
- }
+ return evtimer_pending(&timer->raw_event, NULL) != 0;
+}
+int loop_event_free(event_t *event)
+{
+ loop_event_unregister(event);
+ free(event);
return 0;
}
diff --git a/hicn-light/src/hicn/base/loop.h b/hicn-light/src/hicn/base/loop.h
index b73d917..6970211 100644
--- a/hicn-light/src/hicn/base/loop.h
+++ b/hicn-light/src/hicn/base/loop.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2020 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:
@@ -18,87 +18,117 @@
* \brief Face manager main loop
*/
-#ifndef FACEMGR_LOOP_H
-#define FACEMGR_LOOP_H
+#ifndef UTIL_LOOP_H
+#define UTIL_LOOP_H
/* fd & timer callbacks */
-typedef int (*fd_callback_t)(void * owner, int fd, void * data);
+typedef int (*fd_callback_t)(void *owner, int fd, void *data);
typedef struct {
int fd;
void *owner;
fd_callback_t callback;
- //int (*callback)(void * owner, int fd, void * data);
void *data;
} fd_callback_data_t;
/* loop */
typedef struct loop_s loop_t;
+typedef struct event_s event_t;
-/* Global loop to be used in single threaded applications */
-extern loop_t * MAIN_LOOP;
+extern loop_t *MAIN_LOOP;
/**
* \brief Creates a main loop
* \return Pointer to the newly created loop, or NULL in case of error
*/
-loop_t * loop_create();
+loop_t *loop_create();
/**
* \brief Releases a loop instance and frees all associated memory
* \param [in] loop - Pointer to the loop instance to free
*/
-void loop_free(loop_t * loop);
+void loop_free(loop_t *loop);
/**
* \brief Runs the loop instance to process events
* \param [in] loop - Pointer to the loop instance
* \return 0 if successful, -1 otherwise
*/
-int loop_dispatch(loop_t * loop);
+int loop_dispatch(loop_t *loop);
/**
* \brief Terminates the dispatching of events
* \param [in] loop - Pointer to the loop instance
*/
-int loop_undispatch(loop_t * loop);
+int loop_undispatch(loop_t *loop);
/**
* \brief Breaks out of the loop
* \param [in] loop - Pointer to the loop instance
*/
-void loop_break(loop_t * loop);
+void loop_break(loop_t *loop);
-/**
- * \brief Registers a new file descriptor to the event loop
- * \param [in] fd - File descriptor to register
+/** Create new event associated with given fd.
+ * \param [out] event - Struct representing new fd event
+ * \param [in] loop - Loop running events
+ * \param [in] fd - fd to register
* \param [in] callback_owner - Pointer to the owner of the callack (first
* parameter of callback function)
* \param [in] callback - Callback function
* \param [in] callback_data - User data to pass alongside callback invocation
* \return 0 in case of success, -1 otherwise
*/
-int
-loop_register_fd(loop_t * loop, int fd, void * callback_owner,
- fd_callback_t callback, void * callback_data);
+int loop_fd_event_create(event_t **event, loop_t *loop, int fd,
+ void *callback_owner, fd_callback_t callback,
+ void *callback_data);
+
+/**
+ * Register event in corresponding event loop.
+ * \param [in] event - Struct representing fd event
+ * \return 0 in case of success, -1 otherwise
+ */
+int loop_fd_event_register(event_t *event);
/**
- * \brief Unregisters a file descriptor from the event loop
- * \param [in] fd - File descriptor to unregister
+ * Unregister event from corresponding event loop.
+ * \param [in] event - Struct representing fd event
* \return 0 in case of success, -1 otherwise
*/
-int
-loop_unregister_fd(loop_t * loop, int fd);
+int loop_event_unregister(event_t *event);
-int _loop_register_timer(loop_t * loop, unsigned delay_ms, void * owner,
- fd_callback_t callback, void * data);
+/**
+ * Free event object.
+ * \param [in] event - Struct representing the event
+ * \return 0 in case of success, -1 otherwise
+ */
+int loop_event_free(event_t *event);
+
+/** Create new timer event.
+ * \param [out] event - Struct representing new timer event
+ * \param [in] loop - Loop running events
+ * \param [in] callback_owner - Pointer to the owner of the callack (first
+ * parameter of callback function)
+ * \param [in] callback - Callback function
+ * \param [in] callback_data - User data to pass alongside callback invocation
+ * \return 0 in case of success, -1 otherwise
+ */
+int loop_timer_create(event_t **timer, loop_t *loop, void *callback_owner,
+ fd_callback_t callback, void *callback_data);
-#define loop_register_timer(loop, delay_ms, owner, callback, data) \
- _loop_register_timer(loop, delay_ms, owner, (fd_callback_t) callback, data)
+/**
+ * Register event in corresponding event loop.
+ * \param [in] timer - Struct representing timer event
+ * \return 0 in case of success, -1 otherwise
+ */
+int loop_timer_register(event_t *timer, unsigned delay_ms);
-int
-loop_unregister_timer(loop_t * loop, int fd);
+/**
+ * Check if timer is enabled.
+ * \param [in] timer - Struct representing timer event
+ * \return 1 if enabled, 0 otherwise
+ */
+int loop_timer_is_enabled(event_t *timer);
-#endif /* FACEMGR_LOOP_H */
+#endif /* UTIL_LOOP_H */
diff --git a/hicn-light/src/hicn/core/address_pair.h b/hicn-light/src/hicn/core/address_pair.h
index fae4f25..7a08426 100644
--- a/hicn-light/src/hicn/core/address_pair.h
+++ b/hicn-light/src/hicn/core/address_pair.h
@@ -37,12 +37,12 @@ int address_pair_from_ip_port(address_pair_t * pair, int family,
#define address_pair_get_remote(pair) (&(pair)->remote)
#define address_pair_get_local_family(pair) \
- (address_family(address_pair_local(pair)))
+ (address_family(address_pair_get_local(pair)))
#define address_pair_get_remote_family(pair) \
- (address_family(address_pair_remote(pair)))
+ (address_family(address_pair_get_remote(pair)))
#define address_pair_get_family(pair) address_pair_local_family(pair)
#define address_pair_is_valid(pair) \
- (address_pair_local_family(pair) == address_pair_remote_family(pair))
+ (address_pair_get_local_family(pair) == address_pair_get_remote_family(pair))
#endif /* HICN_ADDRESS_PAIR_H */
diff --git a/hicn-light/src/hicn/core/connection.c b/hicn-light/src/hicn/core/connection.c
index 582e2f5..ba56ce4 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_valid(pair));
+ assert(address_pair_is_valid(pair));
*connection = (connection_t) {
.id = connection_id,
@@ -263,7 +263,7 @@ connection_initialize(connection_t * connection, face_type_t type, const char *
if (!connection->data)
goto ERR_DATA;
- assert(connection_has_valid_type(connection));
+ assert(connection_has_valid_id(connection));
rc = connection_vft[connection->type]->initialize(connection);
if (rc < 0) {
diff --git a/hicn-light/src/hicn/core/connection.h b/hicn-light/src/hicn/core/connection.h
index 45d341a..6297e19 100644
--- a/hicn-light/src/hicn/core/connection.h
+++ b/hicn-light/src/hicn/core/connection.h
@@ -86,7 +86,7 @@ typedef struct {
#define connection_id_is_valid(ID) (ID != CONNECTION_ID_UNDEFINED)
#define connection_get_name(C) ((C)->name)
#define connection_get_type(C) ((C)->type)
-#define connection_has_valid_id(C) (connection_id_is_valid(connection_get_id(C))
+#define connection_has_valid_id(C) (connection_id_is_valid(connection_get_id(C)))
#define connection_get_pair(C) (&(C)->pair)
#define connection_get_local(C) (address_pair_local(connection_get_pair(C)))
#define connection_get_remote(C) (address_pair_remote(connection_get_pair(C)))
diff --git a/hicn-light/src/hicn/core/forwarder.c b/hicn-light/src/hicn/core/forwarder.c
index f8e9919..94baade 100644
--- a/hicn-light/src/hicn/core/forwarder.c
+++ b/hicn-light/src/hicn/core/forwarder.c
@@ -664,7 +664,7 @@ bool
_satisfy_from_content_store(forwarder_t * forwarder, msgbuf_t *interest_msgbuf)
{
assert(forwarder);
- assert(msgbuf_get_type(msgbuf) == MESSAGE_TYPE_INTEREST);
+ assert(msgbuf_get_type(interest_msgbuf) == MESSAGE_TYPE_INTEREST);
if (msgbuf_get_interest_lifetime(interest_msgbuf) == 0)
return false;
@@ -1006,7 +1006,7 @@ forwarder_set_strategy(forwarder_t * forwarder, Name * name_prefix,
{
assert(forwarder);
assert(name_prefix);
- assert(strategy_type_valid(strategy_type));
+ // assert(strategy_type_is_valid(strategy_type));
/* strategy_options might be NULL */
fib_entry_t * entry = fib_contains(forwarder->fib, name_prefix);
diff --git a/hicn-light/src/hicn/core/listener.c b/hicn-light/src/hicn/core/listener.c
index 0ab73b1..5857c0c 100644
--- a/hicn-light/src/hicn/core/listener.c
+++ b/hicn-light/src/hicn/core/listener.c
@@ -88,9 +88,16 @@ listener_initialize(listener_t * listener, face_type_t type, const char * name,
// XXX data should be pre-allocated here
- if (loop_register_fd(MAIN_LOOP, listener->fd, listener,
- (fd_callback_t)listener_vft[listener->type]->read_callback, NULL) < 0)
+ loop_fd_event_create(&listener->event_data, MAIN_LOOP, listener->fd, listener,
+ (fd_callback_t)listener_vft[listener->type]->read_callback, NULL);
+
+ if (!listener->event_data) {
+ goto ERR_REGISTER_FD;
+ }
+
+ if (loop_fd_event_register(listener->event_data) < 0) {
goto ERR_REGISTER_FD;
+ }
// XXX TODO
//char *str = addressToString(listener->local_addr);
@@ -121,7 +128,7 @@ listener_finalize(listener_t * listener)
assert(listener);
assert(listener_has_valid_type(listener));
- loop_unregister_fd(MAIN_LOOP, listener->fd);
+ loop_event_unregister(listener->event_data);
#ifndef _WIN32
close(listener->fd);
@@ -134,6 +141,7 @@ listener_finalize(listener_t * listener)
free(listener->data);
free(listener->interface_name);
free(listener->name);
+ loop_event_free(listener->event_data);
return 0;
}
@@ -143,7 +151,7 @@ int listener_get_socket(const listener_t * listener, const address_t * local,
{
assert(listener);
assert(listener_has_valid_type(listener));
- assert(pair);
+ // assert(pair);
return listener_vft[listener->type]->get_socket(listener, local, remote,
interface_name);
diff --git a/hicn-light/src/hicn/core/listener.h b/hicn-light/src/hicn/core/listener.h
index 749e9b1..ea2a5d3 100644
--- a/hicn-light/src/hicn/core/listener.h
+++ b/hicn-light/src/hicn/core/listener.h
@@ -23,6 +23,7 @@
#include <hicn/core/address_pair.h>
#include <hicn/face.h>
+#include <hicn/base/loop.h>
struct forwarder_s;
struct batch_buffer_s;
@@ -48,6 +49,7 @@ typedef struct {
unsigned interface_index;
unsigned family;
int fd;
+ event_t *event_data;
void * data; /* Listener specific data */
struct forwarder_s * forwarder;
} listener_t;
diff --git a/hicn-light/src/hicn/core/mapme.c b/hicn-light/src/hicn/core/mapme.c
index 4a254c7..ae4a29f 100644
--- a/hicn-light/src/hicn/core/mapme.c
+++ b/hicn-light/src/hicn/core/mapme.c
@@ -116,6 +116,7 @@
#include <hicn/core/mapme.h>
#include <stdio.h> // printf
+#include <hicn/base/loop.h>
#include <hicn/core/connection.h>
#include <hicn/core/forwarder.h>
#include <hicn/core/msgbuf.h>
@@ -187,7 +188,7 @@ struct mapme_s {
* Retransmissions
* Lite calendar queue with NUM_RETX_SLOT slots
*/
- int timer_fd;
+ event_t *timer;
mapme_retx_t retx_array[NUM_RETX_SLOT][NUM_RETX_ENTRIES];
uint8_t retx_len[NUM_RETX_SLOT];
uint8_t cur;
@@ -208,7 +209,7 @@ static mapme_t mapme_default = {
.discovery = MAPME_DEFAULT_DISCOVERY,
.protocol = MAPME_DEFAULT_PROTOCOL,
- .timer_fd = -1,
+ .timer = NULL,
// .retx_array = {{ 0 }}, // memset
.retx_len = { 0 },
.cur = 0, /* current slot */
@@ -217,6 +218,9 @@ static mapme_t mapme_default = {
/******************************************************************************/
+int
+mapme_on_timeout(void * mapme_arg, int fd, void * data);
+
mapme_t *
mapme_create(void * forwarder)
{
@@ -229,12 +233,19 @@ mapme_create(void * forwarder)
memset(mapme->retx_array, 0, NUM_RETX_SLOT * NUM_RETX_ENTRIES);
mapme->forwarder = forwarder;
+ loop_timer_create(&mapme->timer, MAIN_LOOP, mapme, mapme_on_timeout, NULL);
+ if (!mapme->timer) {
+ ERROR("Error allocating mapme timer.");
+ free(mapme);
+ return NULL;
+ }
return mapme;
}
void mapme_free(mapme_t * mapme)
{
+ loop_event_free(mapme->timer);
free(mapme);
}
@@ -518,9 +529,10 @@ mapme_create_fib_entry(const mapme_t * mapme, const Name * name, unsigned ingres
#endif
-void
-mapme_on_timeout(mapme_t * mapme, int fd, void * data)
+int
+mapme_on_timeout(void * mapme_arg, int fd, void * data)
{
+ mapme_t *mapme = mapme_arg;
assert(mapme);
assert(!data);
/* Timeout occurred, we have to retransmit IUs for all pending
@@ -580,9 +592,10 @@ mapme_on_timeout(mapme_t * mapme, int fd, void * data)
/* After two empty slots, we disable the timer */
if (mapme->idle > 1) {
- loop_unregister_timer(MAIN_LOOP, mapme->timer_fd);
- mapme->timer_fd = -1;
+ loop_event_unregister(mapme->timer);
}
+
+ return 0;
}
static
@@ -668,9 +681,12 @@ mapme_on_event(mapme_t * mapme, mapme_event_t event, fib_entry_t * entry,
.retx_count = 0,
};
- if (mapme->timer_fd == -1)
- mapme->timer_fd = loop_register_timer(MAIN_LOOP,
- mapme->retx, mapme, mapme_on_timeout, NULL);
+ if (!loop_timer_is_enabled(mapme->timer)) {
+ if (loop_timer_register(mapme->timer, mapme->retx) < 0) {
+ ERROR("Error setting mapme timer.");
+ break;
+ }
+ }
mapme->idle = 0;
break;
@@ -701,9 +717,8 @@ mapme_on_event(mapme_t * mapme, mapme_event_t event, fib_entry_t * entry,
mapme_send_to_nexthop(mapme, entry, ingress_id);
mapme->idle = 0;
- if (mapme->timer_fd == -1)
- mapme->timer_fd = loop_register_timer(MAIN_LOOP,
- mapme->retx, mapme, mapme_on_timeout, NULL);
+ if (!loop_timer_is_enabled(mapme->timer))
+ loop_timer_register(mapme->timer, mapme->retx);
break;
case MAPME_EVENT_PH_DEL:
diff --git a/hicn-light/src/hicn/core/prefix_stats.c b/hicn-light/src/hicn/core/prefix_stats.c
index c326659..b52964e 100644
--- a/hicn-light/src/hicn/core/prefix_stats.c
+++ b/hicn-light/src/hicn/core/prefix_stats.c
@@ -5,6 +5,7 @@
#include <hicn/core/connection_table.h>
#include <hicn/base/loop.h>
+#include <hicn/util/log.h>
#include <hicn/core/ticks.h>
#include <hicn/policy.h>
#include <hicn/core/fib.h>
@@ -15,10 +16,10 @@
#define STATS_INTERVAL 1000 /* ms */
static
-void
-prefix_stats_mgr_tick(prefix_stats_mgr_t * mgr, int fd, void * data)
+int
+prefix_stats_mgr_tick(void * mgr_arg, int fd, void * data)
{
-
+ prefix_stats_mgr_t * mgr = mgr_arg;
assert(mgr);
assert(!data);
@@ -31,15 +32,25 @@ prefix_stats_mgr_tick(prefix_stats_mgr_t * mgr, int fd, void * data)
fib_foreach_entry(fib, entry, {
prefix_stats_update(&entry->prefix_stats, &entry->prefix_counters, now);
});
+
+ return 0;
}
int
prefix_stats_mgr_initialize(prefix_stats_mgr_t * mgr, void * forwarder)
{
mgr->forwarder = forwarder;
- mgr->timer_fd = loop_register_timer(MAIN_LOOP, STATS_INTERVAL, mgr, prefix_stats_mgr_tick, NULL);
- if (mgr->timer_fd < 0)
+
+ loop_timer_create(&mgr->timer, MAIN_LOOP, mgr, prefix_stats_mgr_tick, NULL);
+ if (!mgr->timer) {
+ ERROR("Error allocating prefix stats mgr timer.");
+ return -1;
+ }
+
+ if (loop_timer_register(mgr->timer, STATS_INTERVAL) < 0) {
+ ERROR("Error registering prefix stats mgr timer.");
return -1;
+ }
return 0;
}
@@ -47,10 +58,10 @@ prefix_stats_mgr_initialize(prefix_stats_mgr_t * mgr, void * forwarder)
void
prefix_stats_mgr_finalize(prefix_stats_mgr_t * mgr)
{
- loop_unregister_timer(MAIN_LOOP, mgr->timer_fd);
+ loop_event_unregister(mgr->timer);
+ loop_event_free(mgr->timer);
}
-
void
prefix_stats_on_retransmission(const prefix_stats_mgr_t * mgr, prefix_counters_t * counters,
const nexthops_t * nexthops)
diff --git a/hicn-light/src/hicn/core/prefix_stats.h b/hicn-light/src/hicn/core/prefix_stats.h
index 257f6b4..4d44120 100644
--- a/hicn-light/src/hicn/core/prefix_stats.h
+++ b/hicn-light/src/hicn/core/prefix_stats.h
@@ -4,9 +4,11 @@
#ifdef WITH_PREFIX_STATS
+#include <hicn/base/loop.h>
+
typedef struct prefix_stats_mgr_s {
void * forwarder;
- int timer_fd;
+ event_t * timer;
} prefix_stats_mgr_t;
diff --git a/hicn-light/src/hicn/io/hicn.c b/hicn-light/src/hicn/io/hicn.c
index a239dc7..26c641e 100644
--- a/hicn-light/src/hicn/io/hicn.c
+++ b/hicn-light/src/hicn/io/hicn.c
@@ -426,7 +426,7 @@ listener_hicn_get_socket(const listener_t * listener, const address_t * local,
{
assert(listener);
assert(listener_get_type(listener) == FACE_TYPE_HICN);
- assert(pair);
+ // assert(pair);
/* ... */
@@ -503,7 +503,7 @@ static
int
connection_hicn_send_packet(const connection_t * connection, const uint8_t * packet, size_t size)
{
- assert(ops);
+ // assert(ops);
assert(packet);
/* ... */
diff --git a/hicn-light/src/hicn/io/tcp.c b/hicn-light/src/hicn/io/tcp.c
index 03911e5..0ed9b46 100644
--- a/hicn-light/src/hicn/io/tcp.c
+++ b/hicn-light/src/hicn/io/tcp.c
@@ -224,7 +224,7 @@ int
connection_tcp_initialize(connection_t * connection)
{
assert(connection);
- assert(connection->type = FACE_TYPE_TCP);
+ assert(connection->type == FACE_TYPE_TCP);
connection_tcp_data_t * data = connection->data;
assert(data);
@@ -328,7 +328,7 @@ connection_tcp_send(const connection_t * connection, //const address_t * address
msgbuf_t * msgbuf, bool queue)
{
assert(connection);
- assert(address);
+ // assert(address);
/* msgbuf can be NULL */
/* No need to flush */
@@ -463,8 +463,8 @@ static
void
connection_tcp_read_callback(connection_t * connection, int fd, void * user_data)
{
- assert(!!(what & PARCEventType_Read));
- assert(connection_void);
+ // assert(!!(what & PARCEventType_Read));
+ assert(connection);
connection_tcp_data_t * data = connection->data;
assert(RECV_BUFLEN - data->woff > MTU);
diff --git a/hicn-light/src/hicn/io/udp.c b/hicn-light/src/hicn/io/udp.c
index 2baae1e..f0eaf8f 100644
--- a/hicn-light/src/hicn/io/udp.c
+++ b/hicn-light/src/hicn/io/udp.c
@@ -318,8 +318,7 @@ connection_udp_initialize(connection_t * connection)
assert(connection);
assert(connection->type == FACE_TYPE_UDP);
- assert(interface_name);
- assert(address_pair);
+ assert(connection->interface_name);
connection_udp_data_t * data = connection->data;
assert(data);
@@ -454,7 +453,7 @@ static
int
connection_udp_send_packet(const connection_t * connection, const uint8_t * packet, size_t size)
{
- assert(ops);
+ assert(connection);
assert(packet);
if(connection_is_local(connection))
diff --git a/hicn-plugin/src/faces/ip/face_ip.c b/hicn-plugin/src/faces/ip/face_ip.c
index a2fe069..72599f3 100644
--- a/hicn-plugin/src/faces/ip/face_ip.c
+++ b/hicn-plugin/src/faces/ip/face_ip.c
@@ -300,7 +300,7 @@ hicn_face_ip_add (const ip46_address_t * local_addr,
hicn_face_ip_input_faces_t in_faces_temp;
hicn_face_ip_vec_t *vec;
pool_get (hicn_vec_pool, vec);
- *vec = vec_new (hicn_face_ip_vec_t, 0);
+ *vec = vec_new (hicn_face_id_t, 0);
u32 index = vec - hicn_vec_pool;
in_faces_temp.vec_id = index;
vec_add1 (*vec, *pfaceid);
diff --git a/scripts/build-packages.sh b/scripts/build-packages.sh
index a027d05..77c1b94 100644
--- a/scripts/build-packages.sh
+++ b/scripts/build-packages.sh
@@ -40,8 +40,6 @@ DEPS_UBUNTU="libparc-dev \
libvppinfra=${VPP_VERSION_DEB} \
libvppinfra-dev=${VPP_VERSION_DEB} \
vpp-plugin-core=${VPP_VERSION_DEB} \
- libyang \
- sysrepo \
python3-ply"
@@ -56,8 +54,6 @@ DEPS_UBUNTU_NOVERSION="libparc-dev \
libvppinfra \
libvppinfra-dev \
vpp-plugin-core \
- libyang \
- sysrepo \
python3-ply \
python3-setuptools \
python3-pip"