Add DAG lifetime

This commit is contained in:
Laurent Deru 2015-09-30 09:39:44 +02:00
parent 0a648df3c3
commit 34126173b4
6 changed files with 49 additions and 0 deletions

View File

@ -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 */
/*
*
*/

View File

@ -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

View File

@ -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 *);

View File

@ -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();

View File

@ -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;

View File

@ -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;