diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-08-01 21:07:59 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-08-01 21:07:59 +0200 |
commit | f29e37138a190c5cb43747433d687c944b7d2efe (patch) | |
tree | 4f959cc0557150591e993bcc344b316d39272752 /src/announce.c | |
parent | 45a3ff5a4f41ca861a57fc9e14d4ac8a4905af95 (diff) | |
download | babel-f29e37138a190c5cb43747433d687c944b7d2efe.tar babel-f29e37138a190c5cb43747433d687c944b7d2efe.zip |
Simplify basic protocol, rename announces to routes, begin implementing route request handling
Diffstat (limited to 'src/announce.c')
-rw-r--r-- | src/announce.c | 203 |
1 files changed, 0 insertions, 203 deletions
diff --git a/src/announce.c b/src/announce.c deleted file mode 100644 index 9deee18..0000000 --- a/src/announce.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - Copyright (c) 2013, Matthias Schiffer <mschiffer@universe-factory.net> - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - - -#include "babel.h" -#include "neigh.h" - -#include <stdlib.h> - - -gp_babel_announce_t* gp_babel_announce_new(gmrf_context_t *ctx) { - gp_babel_announce_t *a = calloc(1, sizeof(gp_babel_announce_t)); - - a->metric.metric = a->feasibility_distance.metric = a->last_metric = GP_BABEL_INFINITY; - - a->next = ctx->announces; - ctx->announces = a; - - return a; -} - -gp_babel_announce_t* gp_babel_announce_find(gmrf_context_t *ctx, const gp_babel_node_id_t *node, uint16_t type, uint16_t key) { - gp_babel_announce_t *announce; - for (announce = ctx->announces; announce; announce = announce->next) { - if (gp_babel_node_id_equal(&announce->node, node) - && announce->type == type - && announce->key == key) - return announce; - } - - return NULL; -} - -gp_babel_announce_t* gp_babel_announce_get(gmrf_context_t *ctx, const gp_babel_node_id_t *node, uint16_t type, uint16_t key) { - gp_babel_announce_t *announce = gp_babel_announce_find(ctx, node, type, key); - - if (!announce) { - announce = gp_babel_announce_new(ctx); - announce->node = *node; - announce->type = type; - announce->key = key; - } - - return announce; -} - -void gp_babel_announce_free(gmrf_context_t *ctx, gp_babel_announce_t *announce) { - free(announce); -} - -gp_babel_nexthop_t* gp_babel_announce_nexthop_find(const gp_babel_announce_t *announce, gp_babel_neigh_t *neigh) { - gp_babel_nexthop_t *nexthop; - for (nexthop = announce->nexthops; nexthop; nexthop = nexthop->next) { - if (nexthop->neigh == neigh) - return nexthop; - } - - return NULL; -} - -gp_babel_nexthop_t* gp_babel_announce_nexthop_new(gp_babel_announce_t *announce, gp_babel_neigh_t *neigh) { - gp_babel_nexthop_t *nexthop = calloc(1, sizeof(gp_babel_nexthop_t)); - nexthop->neigh = neigh; - - nexthop->next = announce->nexthops; - announce->nexthops = nexthop; - - gp_babel_neigh_ref(neigh); - - return nexthop; -} - -static void maintain_nexthops(gmrf_context_t *ctx, gp_babel_announce_t *announce) { - gp_babel_nexthop_t **cur, **next; - for (cur = &announce->nexthops; *cur; cur = next) { - gp_babel_nexthop_t *nexthop = *cur; - next = &nexthop->next; - - if (!nexthop->neigh) /* local */ - continue; - - if (!nexthop->neigh->iface) { - if (nexthop->metric_seqno.metric != GP_BABEL_INFINITY) { - nexthop->metric_seqno.metric = GP_BABEL_INFINITY; - nexthop->last_update = gmrf_now(ctx->gmrf); - nexthop->last_update += GP_BABEL_UPDATE_TIMEOUT(nexthop->interval)*10; - } - - continue; - } - - if (gmrf_now(ctx->gmrf) > nexthop->last_update+GP_BABEL_UPDATE_TIMEOUT(nexthop->interval)*10) { - if (nexthop->metric_seqno.metric == GP_BABEL_INFINITY) { - *cur = *next; - next = cur; - - if (announce->selected == nexthop) - announce->selected = NULL; - - gp_babel_neigh_unref(nexthop->neigh); - - free(nexthop); - } - else { - nexthop->metric_seqno.metric = GP_BABEL_INFINITY; - nexthop->last_update += GP_BABEL_UPDATE_TIMEOUT(nexthop->interval)*10; - } - } - else if (gmrf_now(ctx->gmrf) > nexthop->last_update+GP_BABEL_UPDATE_REQUEST_TIMEOUT(nexthop->interval)*10 && announce->selected == nexthop) { - if (!nexthop->requested_update) { - gmrf_logf(ctx->gmrf, LOG_INFO, "announce about to expire, requesting update"); - gp_babel_send_announce_request(ctx, NULL, nexthop->neigh, &announce->node, announce->type, announce->key, false); - nexthop->requested_update = true; - } - } - } -} - -static gp_babel_nexthop_t* select_nexthop(gmrf_context_t *ctx, const gp_babel_announce_t *announce) { - uint16_t ret_metric = GP_BABEL_INFINITY; - gp_babel_nexthop_t *ret = NULL; - - gp_babel_nexthop_t *nexthop; - for (nexthop = announce->nexthops; nexthop; nexthop = nexthop->next) { - if (!nexthop->neigh) /* local */ - return nexthop; - - if (!gp_babel_is_feasible(announce, nexthop->metric_seqno)) - continue; - - uint32_t metric = nexthop->metric_seqno.metric + gp_babel_neigh_get_cost(ctx, nexthop->neigh); - - if (metric < ret_metric) { - ret = nexthop; - ret_metric = metric; - } - } - - return ret; -} - -gp_babel_metric_seqno_t get_metric(gmrf_context_t *ctx, const gp_babel_announce_t *announce) { - if (announce->selected) { - uint32_t metric = announce->selected->metric_seqno.metric + gp_babel_neigh_get_cost(ctx, announce->selected->neigh); - - if (metric < GP_BABEL_INFINITY) - return (gp_babel_metric_seqno_t){metric, announce->selected->metric_seqno.seqno}; - } - - return (gp_babel_metric_seqno_t){GP_BABEL_INFINITY, 0}; -} - -void gp_babel_announce_update(gmrf_context_t *ctx, gp_babel_announce_t *announce) { - maintain_nexthops(ctx, announce); - - announce->selected = select_nexthop(ctx, announce); - announce->metric = get_metric(ctx, announce); - - if (!announce->selected) - gp_babel_send_seqno_request_for(ctx, NULL, announce); - - /* triggered updates */ - /*int diff = announce->metric.metric - announce->last_metric; - - if (((announce->last_metric == GP_BABEL_INFINITY) != (announce->metric.metric == GP_BABEL_INFINITY)) - || diff <= -1024 || diff >= 384) { - gmrf_logf(gmrf, LOG_INFO, "announce metric has changed significantly, sending updates"); - gp_babel_update_enqueue(&announce->node, announce->type, announce->key, NULL, announce->metric.metric == GP_BABEL_INFINITY); - } */ -} - -void gp_babel_announce_update_nexthop(gmrf_context_t *ctx, gp_babel_announce_t *announce, gp_babel_nexthop_t *nexthop, gp_babel_metric_seqno_t ms, uint16_t interval) { - nexthop->metric_seqno = ms; - nexthop->interval = interval; - nexthop->requested_update = false; - - if (ms.metric != GP_BABEL_INFINITY) - nexthop->last_update = gmrf_now(ctx->gmrf); - - gp_babel_announce_update(ctx, announce); -} |