Purge all routes related to a DAG being freed. Do not send no-DAOs when doing a global repair.

This commit is contained in:
nvt-se 2010-06-03 15:20:56 +00:00
parent ba2bf31c20
commit c201058325
3 changed files with 33 additions and 37 deletions

View file

@ -32,7 +32,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: rpl-dag.c,v 1.16 2010/06/03 12:55:09 nvt-se Exp $ * $Id: rpl-dag.c,v 1.17 2010/06/03 15:20:56 nvt-se Exp $
*/ */
/** /**
* \file * \file
@ -130,10 +130,13 @@ rpl_dag_t *
rpl_set_root(uip_ipaddr_t *dag_id) rpl_set_root(uip_ipaddr_t *dag_id)
{ {
rpl_dag_t *dag; rpl_dag_t *dag;
int version;
version = -1;
dag = rpl_get_dag(RPL_DEFAULT_OCP); dag = rpl_get_dag(RPL_DEFAULT_OCP);
if(dag != NULL) { if(dag != NULL) {
PRINTF("RPL: Dropping a joined DAG when setting this node as root"); PRINTF("RPL: Dropping a joined DAG when setting this node as root");
version = dag->version;
rpl_free_dag(dag); rpl_free_dag(dag);
} }
@ -144,6 +147,7 @@ rpl_set_root(uip_ipaddr_t *dag_id)
} }
dag->joined = 1; dag->joined = 1;
dag->version = version + 1;
dag->grounded = RPL_GROUNDED; dag->grounded = RPL_GROUNDED;
dag->rank = ROOT_RANK; dag->rank = ROOT_RANK;
dag->of = rpl_find_of(RPL_DEFAULT_OCP); dag->of = rpl_find_of(RPL_DEFAULT_OCP);
@ -227,23 +231,20 @@ rpl_alloc_dag(void)
void void
rpl_free_dag(rpl_dag_t *dag) rpl_free_dag(rpl_dag_t *dag)
{ {
uip_ds6_route_t *rep;
PRINTF("RPL: Leaving the DAG "); PRINTF("RPL: Leaving the DAG ");
PRINT6ADDR(&dag->dag_id); PRINT6ADDR(&dag->dag_id);
PRINTF("\n"); PRINTF("\n");
rep = uip_ds6_route_lookup(&dag->dag_id); /* Remove routes installed by DAOs. */
if(rep != NULL) { rpl_remove_routes(dag);
uip_ds6_route_rm(rep);
}
rpl_set_default_route(dag, NULL);
/* Remove parents and the default route. */
remove_parents(dag, NULL, !POISON_ROUTES); remove_parents(dag, NULL, !POISON_ROUTES);
rpl_set_default_route(dag, NULL);
ctimer_stop(&dag->dio_timer); ctimer_stop(&dag->dio_timer);
ctimer_stop(&dag->dao_timer); ctimer_stop(&dag->dao_timer);
dag->used = 0; dag->used = 0;
dag->joined = 0; dag->joined = 0;
} }
@ -301,7 +302,10 @@ rpl_preferred_parent(rpl_dag_t *dag)
best = dag->of->best_parent(best, p); best = dag->of->best_parent(best, p);
} }
} }
if(dag->best_parent != best) {
dag->best_parent = best; /* Cache the value. */ dag->best_parent = best; /* Cache the value. */
rpl_set_default_route(dag, &best->addr);
}
return best; return best;
} }
/************************************************************************/ /************************************************************************/
@ -346,19 +350,6 @@ rpl_get_dag(int instance_id)
return NULL; return NULL;
} }
/************************************************************************/ /************************************************************************/
rpl_dag_t *
rpl_find_dag(unsigned char aucIndex)
{
int i;
for(i = aucIndex; i < RPL_MAX_DAG_ENTRIES; i++) {
if(dag_table[i].joined ) {
return &dag_table[i];
}
}
return NULL;
}
/************************************************************************/
rpl_of_t * rpl_of_t *
rpl_find_of(rpl_ocp_t ocp) rpl_find_of(rpl_ocp_t ocp)
{ {
@ -373,14 +364,6 @@ rpl_find_of(rpl_ocp_t ocp)
return NULL; return NULL;
} }
/************************************************************************/ /************************************************************************/
void
rpl_join_dag(rpl_dag_t *dag)
{
dag->joined = 1;
rpl_reset_dio_timer(dag, 1);
}
/************************************************************************/
static void static void
join_dag(uip_ipaddr_t *from, rpl_dio_t *dio) join_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
{ {
@ -415,6 +398,7 @@ join_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
return; return;
} }
dag->joined = 1;
dag->used = 1; dag->used = 1;
dag->of = of; dag->of = of;
dag->preference = dio->preference; dag->preference = dio->preference;
@ -435,13 +419,12 @@ join_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
/* copy prefix information into the dag */ /* copy prefix information into the dag */
memcpy(&dag->prefix_info, &dio->prefix_info, sizeof(rpl_prefix_t)); memcpy(&dag->prefix_info, &dio->prefix_info, sizeof(rpl_prefix_t));
rpl_join_dag(dag);
PRINTF("RPL: Joined DAG with instance ID %u, rank %hu, DAG ID ", PRINTF("RPL: Joined DAG with instance ID %u, rank %hu, DAG ID ",
dio->instance_id, dag->rank); dio->instance_id, dag->rank);
PRINT6ADDR(&dag->dag_id); PRINT6ADDR(&dag->dag_id);
PRINTF("\n"); PRINTF("\n");
rpl_reset_dio_timer(dag, 1);
rpl_set_default_route(dag, from); rpl_set_default_route(dag, from);
if(dio->dst_adv_supported && dio->dst_adv_trigger) { if(dio->dst_adv_supported && dio->dst_adv_trigger) {
@ -562,10 +545,10 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
preferred_parent = rpl_preferred_parent(dag); preferred_parent = rpl_preferred_parent(dag);
if(p == preferred_parent) { if(p == preferred_parent) {
new_rank = dag->of->increment_rank(dio->dag_rank, p); new_rank = dag->of->increment_rank(dio->dag_rank, p);
PRINTF("RPL: New rank is %hu, max is %hu\n",
dag->rank, dag->min_rank + dag->max_rankinc);
rpl_set_default_route(dag, &p->addr); rpl_set_default_route(dag, &p->addr);
dag->rank = new_rank; dag->rank = new_rank;
PRINTF("RPL: New rank is %hu, max is %hu\n",
dag->rank, dag->min_rank + dag->max_rankinc);
} }
} else { } else {
PRINTF("RPL: Cannot find an acceptable preferred parent\n"); PRINTF("RPL: Cannot find an acceptable preferred parent\n");

View file

@ -32,7 +32,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: rpl.c,v 1.5 2010/05/29 22:23:21 nvt-se Exp $ * $Id: rpl.c,v 1.6 2010/06/03 15:20:56 nvt-se Exp $
*/ */
/** /**
* \file * \file
@ -77,6 +77,18 @@ rpl_purge_routes(void)
} }
} }
/************************************************************************/ /************************************************************************/
void
rpl_remove_routes(rpl_dag_t *dag)
{
int i;
for(i = 0; i < UIP_DS6_ROUTE_NB; i++) {
if(uip_ds6_routing_table[i].state.dag == dag) {
uip_ds6_route_rm(&uip_ds6_routing_table[i]);
}
}
}
/************************************************************************/
uip_ds6_route_t * uip_ds6_route_t *
rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, int prefix_len, rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, int prefix_len,
uip_ipaddr_t *next_hop) uip_ipaddr_t *next_hop)

View file

@ -30,7 +30,7 @@
* *
* Author: Joakim Eriksson, Nicolas Tsiftes * Author: Joakim Eriksson, Nicolas Tsiftes
* *
* $Id: rpl.h,v 1.11 2010/06/03 14:49:16 joxe Exp $ * $Id: rpl.h,v 1.12 2010/06/03 15:20:56 nvt-se Exp $
*/ */
#ifndef RPL_H #ifndef RPL_H
@ -289,6 +289,7 @@ rpl_dag_t *rpl_get_dag(int instance_id);
rpl_dag_t *rpl_find_dag(unsigned char aucIndex); rpl_dag_t *rpl_find_dag(unsigned char aucIndex);
/* RPL routing table functions. */ /* RPL routing table functions. */
void rpl_remove_routes(rpl_dag_t *dag);
uip_ds6_route_t *rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, uip_ds6_route_t *rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix,
int prefix_len, uip_ipaddr_t *next_hop); int prefix_len, uip_ipaddr_t *next_hop);
void rpl_purge_routes(void); void rpl_purge_routes(void);