summaryrefslogtreecommitdiffstats
path: root/src/babel.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-03-24 03:45:16 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-03-24 03:45:16 +0100
commit47bd032564a4812a607cbe9f5a44ef2b2f93278d (patch)
tree3069f48157989175a51584897ed338c01b58d2bc /src/babel.c
parent0af36311e10c0dd480bcfca5774db738e165066d (diff)
downloadbabel-47bd032564a4812a607cbe9f5a44ef2b2f93278d.tar
babel-47bd032564a4812a607cbe9f5a44ef2b2f93278d.zip
Initial nexthop maintenance implementation
Mostly taken from the FFD project, and quite incomplete.
Diffstat (limited to 'src/babel.c')
-rw-r--r--src/babel.c56
1 files changed, 51 insertions, 5 deletions
diff --git a/src/babel.c b/src/babel.c
index 4177100..7e5e003 100644
--- a/src/babel.c
+++ b/src/babel.c
@@ -52,9 +52,7 @@ static void send_updates(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);
-
+static void maintain_neighbours(gmrf_t *gmrf, gmrf_context_t *ctx) {
gp_babel_iface_t *iface;
for (iface = ctx->interfaces; iface; iface = iface->next) {
gp_babel_neigh_t **cur, **next;
@@ -62,7 +60,7 @@ static void maintenance(gmrf_t *gmrf, gmrf_context_t *ctx, void *arg) {
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) {
+ if (gp_babel_neigh_get_rxcost(gmrf, neigh) == GP_BABEL_INFINITY && gp_babel_neigh_get_txcost(gmrf, neigh) == GP_BABEL_INFINITY && !neigh->ref) {
*cur = *next;
next = cur;
free(neigh);
@@ -79,12 +77,58 @@ static void maintenance(gmrf_t *gmrf, gmrf_context_t *ctx, void *arg) {
}
}
+static void maintain_announces(gmrf_t *gmrf, gmrf_context_t *ctx) {
+ gp_babel_announce_t **cur, **next;
+ for (cur = &ctx->announces; *cur; cur = next) {
+ gp_babel_announce_t *announce = *cur;
+ next = &announce->next;
+
+ gp_babel_announce_update(gmrf, announce);
+
+ if (!announce->nexthops) {
+ *cur = *next;
+ next = cur;
+ gp_babel_announce_free(gmrf, ctx, announce);
+
+ continue;
+ }
+
+ gmrf_logf(gmrf, LOG_DEBUG, "node %04x%04x, type %04x, announce %04x (%u, seqno=%04x):",
+ ntohl(*(uint32_t*)announce->node.id), ntohl(*(uint32_t*)(announce->node.id+4)),
+ announce->type, announce->key, announce->metric.metric, announce->metric.seqno);
+
+ gp_babel_nexthop_t *nexthop;
+ for (nexthop = announce->nexthops; nexthop; nexthop = nexthop->next) {
+ gp_babel_neigh_t *neigh = nexthop->neigh;
+
+ if (!neigh) {
+ gmrf_logf(gmrf, LOG_DEBUG, " local");
+ continue;
+ }
+
+ gmrf_logf(gmrf, LOG_DEBUG, " nexthop: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x[%s] (%u, seqno=%04x, cost=%u%s)",
+ 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],
+ neigh->iface ? gmrf_iface_get_name(gmrf, neigh->iface->gmrf_iface) : NULL,
+ nexthop->metric_seqno.metric, nexthop->metric_seqno.seqno, gp_babel_neigh_get_cost(gmrf, neigh),
+ (nexthop == announce->selected) ? ", selected" : "");
+ }
+ }
+}
+
+static void maintenance(gmrf_t *gmrf, gmrf_context_t *ctx, void *arg) {
+ gmrf_schedule(gmrf, maintenance, NULL, GP_BABEL_MAINTENANCE_INTERVAL*10);
+
+ maintain_neighbours(gmrf, ctx);
+ maintain_announces(gmrf, ctx);
+}
+
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, send_updates, NULL, GP_BABEL_UPDATE_INTERVAL*10);
- gmrf_schedule(gmrf, maintenance, NULL, GP_BABEL_MAINTENANCE_INTERVAL*10);
+ gmrf_schedule(gmrf, maintenance, NULL, 0);
gmrf_context_t *ctx = calloc(1, sizeof(gmrf_context_t));
gmrf_random_bytes(gmrf, &ctx->self, sizeof(gp_babel_node_id_t));
@@ -94,6 +138,8 @@ gmrf_context_t* gmrf_protocol_init(gmrf_t *gmrf) {
announce->type = 1;
announce->key = 1337;
+ announce->nexthops = announce->selected = calloc(1, sizeof(gp_babel_nexthop_t));
+
return ctx;
}