From 41c43fd837e82f9181bdd4685b7cd79fcfa5943d Mon Sep 17 00:00:00 2001 From: smlng Date: Wed, 19 Apr 2017 17:19:27 +0200 Subject: [PATCH] rpl: make parent lifetime consistent with other timers --- sys/net/gnrc/routing/rpl/gnrc_rpl.c | 15 +++++++-------- sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c | 3 +-- sys/shell/commands/sc_gnrc_rpl.c | 3 +-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/sys/net/gnrc/routing/rpl/gnrc_rpl.c b/sys/net/gnrc/routing/rpl/gnrc_rpl.c index d2df979023..10bd8526cc 100644 --- a/sys/net/gnrc/routing/rpl/gnrc_rpl.c +++ b/sys/net/gnrc/routing/rpl/gnrc_rpl.c @@ -252,23 +252,22 @@ static void *_event_loop(void *args) void _update_lifetime(void) { - uint32_t now = xtimer_now_usec(); - uint16_t now_sec = now / US_PER_SEC; - gnrc_rpl_parent_t *parent; gnrc_rpl_instance_t *inst; for (uint8_t i = 0; i < GNRC_RPL_PARENTS_NUMOF; ++i) { parent = &gnrc_rpl_parents[i]; if (parent->state != 0) { - if ((int32_t)(parent->lifetime - now_sec) <= GNRC_RPL_LIFETIME_UPDATE_STEP) { + if (parent->lifetime > GNRC_RPL_LIFETIME_UPDATE_STEP) { + if (parent->lifetime > (2 * GNRC_RPL_LIFETIME_UPDATE_STEP)) { + gnrc_rpl_send_DIS(parent->dodag->instance, &parent->addr); + } + parent->lifetime -= GNRC_RPL_LIFETIME_UPDATE_STEP; + } + else { gnrc_rpl_dodag_t *dodag = parent->dodag; gnrc_rpl_parent_remove(parent); gnrc_rpl_parent_update(dodag, NULL); - continue; - } - else if ((int32_t)(parent->lifetime - now_sec) <= (GNRC_RPL_LIFETIME_UPDATE_STEP * 2)) { - gnrc_rpl_send_DIS(parent->dodag->instance, &parent->addr); } } } diff --git a/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c b/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c index 3a8c1ff9c9..04cdf16cc7 100644 --- a/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c +++ b/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c @@ -265,8 +265,7 @@ void gnrc_rpl_parent_update(gnrc_rpl_dodag_t *dodag, gnrc_rpl_parent_t *parent) { /* update Parent lifetime */ if (parent != NULL) { - uint32_t now = xtimer_now_usec(); - parent->lifetime = (now / US_PER_SEC) + (dodag->default_lifetime * dodag->lifetime_unit); + parent->lifetime = dodag->default_lifetime * dodag->lifetime_unit; #ifdef MODULE_GNRC_RPL_P2P if (dodag->instance->mop != GNRC_RPL_P2P_MOP) { #endif diff --git a/sys/shell/commands/sc_gnrc_rpl.c b/sys/shell/commands/sc_gnrc_rpl.c index 67062f2f8f..a10b5f5ca8 100644 --- a/sys/shell/commands/sc_gnrc_rpl.c +++ b/sys/shell/commands/sc_gnrc_rpl.c @@ -304,8 +304,7 @@ int _gnrc_rpl_dodag_show(void) LL_FOREACH(gnrc_rpl_instances[i].dodag.parents, parent) { printf("\t\tparent [addr: %s | rank: %d | lifetime: %" PRIu32 "s]\n", ipv6_addr_to_str(addr_str, &parent->addr, sizeof(addr_str)), - parent->rank, ((int32_t) (parent->lifetime - (((uint32_t) xnow / US_PER_SEC)))) - < 0 ? 0 : (parent->lifetime - ((uint32_t) xnow / US_PER_SEC))); + parent->rank, parent->lifetime); } } return 0;