Add gp_babel_since helper

This commit is contained in:
Matthias Schiffer 2013-08-03 03:08:04 +02:00
parent 8ca5dead7f
commit 48f77c26dc
4 changed files with 12 additions and 5 deletions

View file

@ -152,6 +152,13 @@ static inline bool gp_babel_less(uint16_t a, uint16_t b) {
return (diff < 0);
}
static inline int64_t gp_babel_since(gmrf_context_t *ctx, gmrf_time_t t) {
if (t == gmrf_time_unspec)
return INT64_MAX;
return (gmrf_now(ctx->gmrf) - t)/10;
}
static inline bool gp_babel_is_metric_better(gp_babel_metric_seqno_t ms1, gp_babel_metric_seqno_t ms2) {
if (ms1.metric == GP_BABEL_INFINITY)
return false;

View file

@ -68,7 +68,7 @@ uint16_t gp_babel_neigh_get_rxcost(gmrf_context_t *ctx, const gp_babel_neigh_t *
if (!neigh->hello_log || !neigh->hello_interval || !neigh->iface)
return GP_BABEL_INFINITY;
int timediff = (gmrf_now(ctx->gmrf) - neigh->last_hello)/10;
int timediff = gp_babel_since(ctx, neigh->last_hello);
int shift = (timediff - neigh->hello_interval/2)/neigh->hello_interval;
if (shift >= 16)
@ -83,7 +83,7 @@ uint16_t gp_babel_neigh_get_rxcost(gmrf_context_t *ctx, const gp_babel_neigh_t *
}
uint16_t gp_babel_neigh_get_txcost(gmrf_context_t *ctx, const gp_babel_neigh_t *neigh) {
if ((gmrf_now(ctx->gmrf) - neigh->last_ihu)/10 > GP_BABEL_IHU_TIMEOUT(neigh->ihu_interval) || !neigh->iface)
if (gp_babel_since(ctx, neigh->last_ihu) > GP_BABEL_IHU_TIMEOUT(neigh->ihu_interval) || !neigh->iface)
return GP_BABEL_INFINITY;
else
return neigh->txcost;

View file

@ -109,7 +109,7 @@ static void maintain_nexthops(gmrf_context_t *ctx, gp_babel_route_t *route) {
continue;
}
if (gmrf_now(ctx->gmrf) > nexthop->last_update+GP_BABEL_UPDATE_TIMEOUT(nexthop->interval)*10) {
if (gp_babel_since(ctx, nexthop->last_update) > GP_BABEL_UPDATE_TIMEOUT(nexthop->interval)) {
if (nexthop->metric_seqno.metric == GP_BABEL_INFINITY) {
*cur = *next;
next = cur;
@ -126,7 +126,7 @@ static void maintain_nexthops(gmrf_context_t *ctx, gp_babel_route_t *route) {
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 && route->selected == nexthop) {
else if (gp_babel_since(ctx, nexthop->last_update) > GP_BABEL_UPDATE_REQUEST_TIMEOUT(nexthop->interval)*10 && route->selected == nexthop) {
if (!nexthop->requested_update) {
gmrf_logf(ctx->gmrf, LOG_INFO, "route about to expire, requesting update");
gp_babel_send_route_request(ctx, NULL, nexthop->neigh, &route->node);

View file

@ -77,7 +77,7 @@ static void handle_tlv_hello(gmrf_context_t *ctx, const gp_babel_tlv_hello_t *tl
uint16_t seqno = ntohs(tlv->seqno);
if (neigh->last_hello != gmrf_time_unspec) {
int timediff = (gmrf_now(ctx->gmrf) - neigh->last_hello)/10;
int timediff = gp_babel_since(ctx, neigh->last_hello);
uint16_t seqexp = neigh->last_seqno + (timediff - neigh->hello_interval/2)/neigh->hello_interval;
/* cast to int16_t to ensure correct handling of seqno wrapping */