From 34126173b4581b988c22938867be4b3f245bd979 Mon Sep 17 00:00:00 2001 From: Laurent Deru Date: Wed, 30 Sep 2015 09:39:44 +0200 Subject: [PATCH] Add DAG lifetime --- core/net/rpl/rpl-conf.h | 12 ++++++++++++ core/net/rpl/rpl-dag.c | 6 ++++++ core/net/rpl/rpl-private.h | 1 + core/net/rpl/rpl-timers.c | 1 + core/net/rpl/rpl.c | 28 ++++++++++++++++++++++++++++ core/net/rpl/rpl.h | 1 + 6 files changed, 49 insertions(+) diff --git a/core/net/rpl/rpl-conf.h b/core/net/rpl/rpl-conf.h index 69199f9ac..f4b2a14fe 100644 --- a/core/net/rpl/rpl-conf.h +++ b/core/net/rpl/rpl-conf.h @@ -121,6 +121,18 @@ #define RPL_DEFAULT_ROUTE_INFINITE_LIFETIME 0 #endif /* RPL_CONF_DEFAULT_ROUTE_INFINITE_LIFETIME */ +/* + * Maximum lifetime of a DAG + * When a DODAG is not updated since RPL_CONF_DAG_LIFETIME times the DODAG + * maximum DIO interval the DODAG is removed from the list of DODAGS of the + * related instance, except if it is the currently joined DODAG. + */ +#ifdef RPL_CONF_DAG_LIFETIME +#define RPL_DAG_LIFETIME RPL_CONF_DAG_LIFETIME +#else +#define RPL_DAG_LIFETIME 3 +#endif /* RPL_CONF_DAG_LIFETIME */ + /* * */ diff --git a/core/net/rpl/rpl-dag.c b/core/net/rpl/rpl-dag.c index 9d140fbd4..dc6393e6c 100644 --- a/core/net/rpl/rpl-dag.c +++ b/core/net/rpl/rpl-dag.c @@ -1334,6 +1334,12 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) return; } + /* The DIO comes from a valid DAG, we can refresh its lifetime */ + dag->lifetime = (1UL << (instance->dio_intmin + instance->dio_intdoubl)) / 1000; + PRINTF("Set dag "); + PRINT6ADDR(&dag->dag_id); + PRINTF(" lifetime to %ld\n", dag->lifetime); + /* * At this point, we know that this DIO pertains to a DAG that * we are already part of. We consider the sender of the DIO to be diff --git a/core/net/rpl/rpl-private.h b/core/net/rpl/rpl-private.h index a1adc0d6f..6f4764b27 100644 --- a/core/net/rpl/rpl-private.h +++ b/core/net/rpl/rpl-private.h @@ -284,6 +284,7 @@ rpl_dag_t *rpl_alloc_dag(uint8_t, uip_ipaddr_t *); rpl_instance_t *rpl_alloc_instance(uint8_t); void rpl_free_dag(rpl_dag_t *); void rpl_free_instance(rpl_instance_t *); +void rpl_purge_dags(void); /* DAG parent management function. */ rpl_parent_t *rpl_add_parent(rpl_dag_t *, rpl_dio_t *dio, uip_ipaddr_t *); diff --git a/core/net/rpl/rpl-timers.c b/core/net/rpl/rpl-timers.c index 27fff0ddf..c0d6c2850 100644 --- a/core/net/rpl/rpl-timers.c +++ b/core/net/rpl/rpl-timers.c @@ -66,6 +66,7 @@ static uint8_t dio_send_ok; static void handle_periodic_timer(void *ptr) { + rpl_purge_dags(); rpl_purge_routes(); rpl_recalculate_ranks(); diff --git a/core/net/rpl/rpl.c b/core/net/rpl/rpl.c index e4724408e..82b11721a 100644 --- a/core/net/rpl/rpl.c +++ b/core/net/rpl/rpl.c @@ -300,6 +300,34 @@ rpl_ipv6_neighbor_callback(uip_ds6_nbr_t *nbr) } /*---------------------------------------------------------------------------*/ void +rpl_purge_dags(void) +{ + rpl_instance_t *instance; + rpl_instance_t *end; + int i; + + for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES; + instance < end; ++instance) { + if(instance->used) { + for(i = 0; i < RPL_MAX_DAG_PER_INSTANCE; i++) { + if(instance->dag_table[i].used) { + if(instance->dag_table[i].lifetime == 0) { + if(!instance->dag_table[i].joined) { + PRINTF("Removing dag "); + PRINT6ADDR(&instance->dag_table[i].dag_id); + PRINTF("\n"); + rpl_free_dag(&instance->dag_table[i]); + } + } else { + instance->dag_table[i].lifetime--; + } + } + } + } + } +} +/*---------------------------------------------------------------------------*/ +void rpl_init(void) { uip_ipaddr_t rplmaddr; diff --git a/core/net/rpl/rpl.h b/core/net/rpl/rpl.h index 70c877aeb..3b3c99f9f 100644 --- a/core/net/rpl/rpl.h +++ b/core/net/rpl/rpl.h @@ -142,6 +142,7 @@ struct rpl_dag { rpl_rank_t rank; struct rpl_instance *instance; rpl_prefix_t prefix_info; + uint32_t lifetime; }; typedef struct rpl_dag rpl_dag_t; typedef struct rpl_instance rpl_instance_t;