aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/core
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/hicn/core')
-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
9 files changed, 70 insertions, 32 deletions
diff --git a/hicn-light/src/hicn/core/address_pair.h b/hicn-light/src/hicn/core/address_pair.h
index fae4f255f..7a08426a4 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 582e2f56f..ba56ce459 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 45d341ab8..6297e193c 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 f8e99198f..94baade94 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 0ab73b1f4..5857c0c88 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 749e9b177..ea2a5d3d8 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 4a254c701..ae4a29f13 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 c32665950..b52964e03 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 257f6b44d..4d441203e 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;