From 415606c73661aa9788a6a16dfc8a75b305246992 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 19 Mar 2013 00:20:02 +0100 Subject: Add maintenance function --- src/babel.c | 28 ++++++++++++++++++++++++++++ src/babel.h | 2 ++ 2 files changed, 30 insertions(+) (limited to 'src') diff --git a/src/babel.c b/src/babel.c index 39cd6c8..4002df2 100644 --- a/src/babel.c +++ b/src/babel.c @@ -86,10 +86,38 @@ static void send_hellos(gmrf_t *gmrf, gmrf_context_t *ctx, void *arg) { } } +static void maintenance(gmrf_t *gmrf, gmrf_context_t *ctx, void *arg) { + gmrf_schedule(gmrf, maintenance, NULL, GP_BABEL_MAINTENANCE_INTERVAL*10); + + gp_babel_iface_t *iface; + for (iface = ctx->interfaces; iface; iface = iface->next) { + gp_babel_neigh_t **cur, **next; + for (cur = &iface->neighbours; *cur; cur = next) { + gp_babel_neigh_t *neigh = *cur; + next = &neigh->next; + + if (gp_babel_neigh_get_rxcost(gmrf, neigh) == 0xffff && gp_babel_neigh_get_txcost(gmrf, neigh) == 0xffff && !neigh->ref) { + *cur = *next; + next = cur; + free(neigh); + + continue; + } + + gmrf_logf(gmrf, LOG_DEBUG, "maintenance: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x[%s]: %u (rx %u/tx %u)", + neigh->addr.d[0], neigh->addr.d[1], neigh->addr.d[2], neigh->addr.d[3], + neigh->addr.d[4], neigh->addr.d[5], neigh->addr.d[6], neigh->addr.d[7], + gmrf_iface_get_name(gmrf, iface->gmrf_iface), gp_babel_neigh_get_cost(gmrf, neigh), + gp_babel_neigh_get_rxcost(gmrf, neigh), gp_babel_neigh_get_txcost(gmrf, neigh)); + } + } +} + gmrf_context_t* gmrf_protocol_init(gmrf_t *gmrf) { gmrf_logf(gmrf, LOG_INFO, "initalizing..."); gmrf_schedule(gmrf, send_hellos, NULL, GP_BABEL_HELLO_INTERVAL*10); + gmrf_schedule(gmrf, maintenance, NULL, GP_BABEL_MAINTENANCE_INTERVAL*10); gmrf_context_t *ctx = calloc(1, sizeof(gmrf_context_t)); gmrf_random_bytes(gmrf, &ctx->self, sizeof(gp_babel_node_id_t)); diff --git a/src/babel.h b/src/babel.h index 7ad5450..4e521cc 100644 --- a/src/babel.h +++ b/src/babel.h @@ -37,6 +37,8 @@ #define GP_BABEL_HELLO_TIMEOUT(interval) (16*(interval)) #define GP_BABEL_IHU_TIMEOUT(interval) ((interval)*7/2) +#define GP_BABEL_MAINTENANCE_INTERVAL GP_BABEL_HELLO_INTERVAL + struct gmrf_context { gp_babel_node_id_t self; -- cgit v1.2.3