From 5d538bb78e1820a807a8670cd3075757f2e115f0 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 7 Oct 2012 19:16:31 +0200 Subject: Periodically update selected nexthops --- ffd/announce.c | 9 ++++++--- ffd/ffd.c | 29 +++++++++++++++++++++++++++-- ffd/ffd.h | 3 ++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/ffd/announce.c b/ffd/announce.c index 8911feb..99bf1aa 100644 --- a/ffd/announce.c +++ b/ffd/announce.c @@ -34,6 +34,9 @@ static ffd_nexthop_t* select_nexthop(const ffd_announce_t *announce) { ffd_nexthop_t *nexthop; for (nexthop = announce->nexthop_list; nexthop; nexthop = nexthop->next) { + if (!nexthop->neigh) /* local */ + return nexthop; + if (!ffd_is_feasible(announce, nexthop->metric_seqno)) continue; @@ -59,19 +62,19 @@ ffd_metric_seqno_t get_metric(const ffd_announce_t *announce) { return (ffd_metric_seqno_t){0xffff, 0}; } -static inline void update_selected(ffd_announce_t *announce) { +void ffd_announce_update(ffd_announce_t *announce) { announce->selected = select_nexthop(announce); announce->metric = get_metric(announce); } -void ffd_announce_update(ffd_announce_t *announce, ffd_nexthop_t *nexthop, ffd_metric_seqno_t ms, uint16_t interval) { +void ffd_announce_update_nexthop(ffd_announce_t *announce, ffd_nexthop_t *nexthop, ffd_metric_seqno_t ms, uint16_t interval) { nexthop->metric_seqno = ms; nexthop->interval = interval; if (ms.metric != 0xffff) nexthop->last_update = now; - update_selected(announce); + ffd_announce_update(announce); } ffd_announce_t* ffd_announce_new(void) { diff --git a/ffd/ffd.c b/ffd/ffd.c index 9af9598..ee1e3ea 100644 --- a/ffd/ffd.c +++ b/ffd/ffd.c @@ -93,7 +93,7 @@ static bool init_self(void) { self.id[6] = primary_addr.d[4]; self.id[7] = primary_addr.d[5]; - ffd_announce_t *announce = announce_list = calloc(1, sizeof(ffd_announce_t)); + ffd_announce_t *announce = ffd_announce_new(); announce->node = self; announce->type = 1; @@ -222,6 +222,7 @@ static void handle_tlv_hello(const ffd_tlv_hello_t *tlv_hello, size_t len, handl if (abs((int16_t)(seqno - seqexp)) > 16) { fprintf(stderr, "info: neighbour was reset.\n"); neigh->hello_log = 0; + neigh->txcost = 0xffff; } else { int16_t seqdiff = seqno - neigh->last_seqno; @@ -376,7 +377,7 @@ static void handle_tlv_update(const ffd_tlv_update_t *tlv_update, size_t len, ha fprintf(stderr, "debug: the update was accepted.\n"); - ffd_announce_update(announce, nexthop, ms, ntohs(tlv_update->interval)); + ffd_announce_update_nexthop(announce, nexthop, ms, ntohs(tlv_update->interval)); } static void handle_tlv_announce_req(const ffd_tlv_announce_req_t *tlv_req, size_t len, handle_tlv_arg_t *arg) { @@ -482,6 +483,30 @@ static void maintenance(void) { iface->name, ffd_neigh_get_cost(neigh), ffd_neigh_get_rxcost(neigh), ffd_neigh_get_txcost(neigh)); } } + + ffd_announce_t *announce; + for (announce = announce_list; announce; announce = announce->next) { + ffd_announce_update(announce); + + fprintf(stderr, "debug: maintenance: node %04x%04x, type %04x, announce %04x: ", ntohl(*(uint32_t*)announce->node.id), ntohl(*(uint32_t*)(announce->node.id+4)), announce->type, announce->key); + + if (!announce->selected) { + fprintf(stderr, "nexthop: none\n"); + continue; + } + + ffd_neigh_t *neigh = announce->selected->neigh; + + if (!neigh) { + fprintf(stderr, "local\n"); + continue; + } + + fprintf(stderr, "nexthop: %02x:%02x:%02x:%02x:%02x:%02x (%u, seqno=%04x)\n", + neigh->addr.d[0], neigh->addr.d[1], neigh->addr.d[2], + neigh->addr.d[3], neigh->addr.d[4], neigh->addr.d[5], + announce->metric.metric, announce->metric.seqno); + } } int main() { diff --git a/ffd/ffd.h b/ffd/ffd.h index 563b472..fa2c378 100644 --- a/ffd/ffd.h +++ b/ffd/ffd.h @@ -179,7 +179,8 @@ static inline bool ffd_is_feasible(const ffd_announce_t *announce, ffd_metric_se } -void ffd_announce_update(ffd_announce_t *announce, ffd_nexthop_t *nexthop, ffd_metric_seqno_t ms, uint16_t interval); +void ffd_announce_update(ffd_announce_t *announce); +void ffd_announce_update_nexthop(ffd_announce_t *announce, ffd_nexthop_t *nexthop, ffd_metric_seqno_t ms, uint16_t interval); ffd_announce_t* ffd_announce_new(void); void ffd_send_ack(ffd_iface_t *iface, ffd_neigh_t *neigh, uint16_t nonce); -- cgit v1.2.3