Renamed neighbors to parents. Removed redundant code. Corrected the logic for max rank increase.

This commit is contained in:
nvt-se 2010-05-25 21:58:54 +00:00
parent 97fc9d2ee8
commit 320fa820ca
6 changed files with 136 additions and 154 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.8 2010/05/25 19:19:43 joxe Exp $ * $Id: rpl-dag.c,v 1.9 2010/05/25 21:58:54 nvt-se Exp $
*/ */
/** /**
* \file * \file
@ -70,11 +70,11 @@ extern rpl_of_t rpl_of0;
#define RPL_MAX_DAG_ENTRIES RPL_CONF_MAX_DAG_ENTRIES #define RPL_MAX_DAG_ENTRIES RPL_CONF_MAX_DAG_ENTRIES
#endif /* !RPL_CONF_MAX_DAG_ENTRIES */ #endif /* !RPL_CONF_MAX_DAG_ENTRIES */
#ifndef RPL_CONF_MAX_NEIGHBORS #ifndef RPL_CONF_MAX_PARENTS
#define RPL_MAX_NEIGHBORS 10 #define RPL_MAX_PARENTS 8
#else #else
#define RPL_MAX_NEIGHBORS RPL_CONF_MAX_NEIGHBORS #define RPL_MAX_PARENTS RPL_CONF_MAX_PARENTS
#endif /* !RPL_CONF_MAX_NEIGHBORS */ #endif /* !RPL_CONF_MAX_PARENTS */
/************************************************************************/ /************************************************************************/
/* RPL definitions. */ /* RPL definitions. */
@ -96,27 +96,27 @@ extern rpl_of_t rpl_of0;
#define RPL_DIO_INTERVAL_DOUBLINGS RPL_CONF_DIO_INTERVAL_DOUBLINGS #define RPL_DIO_INTERVAL_DOUBLINGS RPL_CONF_DIO_INTERVAL_DOUBLINGS
#endif /* !RPL_CONF_DIO_INTERVAL_DOUBLINGS */ #endif /* !RPL_CONF_DIO_INTERVAL_DOUBLINGS */
/************************************************************************/ /************************************************************************/
/* Allocate neighbors from the same static MEMB chunk to reduce memory waste. */ /* Allocate parents from the same static MEMB chunk to reduce memory waste. */
MEMB(neighbor_memb, struct rpl_neighbor, RPL_MAX_NEIGHBORS); MEMB(parent_memb, struct rpl_parent, RPL_MAX_PARENTS);
static rpl_dag_t dag_table[RPL_MAX_DAG_ENTRIES]; static rpl_dag_t dag_table[RPL_MAX_DAG_ENTRIES];
/************************************************************************/ /************************************************************************/
static void static void
poison_routes(rpl_dag_t *dag, rpl_neighbor_t *exception) poison_routes(rpl_dag_t *dag, rpl_parent_t *exception)
{ {
rpl_neighbor_t *p, *p2; rpl_parent_t *p, *p2;
PRINTF("RPL: Poisoning routes\n"); PRINTF("RPL: Poisoning routes\n");
for(p = list_head(dag->neighbors); p != NULL;) { for(p = list_head(dag->parents); p != NULL;) {
if(p != exception && RPL_NEIGHBOR_IS_PARENT(dag, p)) { if(p != exception) {
ANNOTATE("#L %u 0\n", p->addr.u8[sizeof(p->addr) - 1]); ANNOTATE("#L %u 0\n", p->addr.u8[sizeof(p->addr) - 1]);
/* Send no-DAOs to old parents. */ /* Send no-DAOs to old parents. */
dao_output(p, ZERO_LIFETIME); dao_output(p, ZERO_LIFETIME);
p2 = p->next; p2 = p->next;
rpl_remove_neighbor(dag, p); rpl_remove_parent(dag, p);
p = p2; p = p2;
} else { } else {
p = p->next; p = p->next;
@ -213,9 +213,9 @@ rpl_alloc_dag(void)
for(i = 0; i < RPL_MAX_DAG_ENTRIES; i++) { for(i = 0; i < RPL_MAX_DAG_ENTRIES; i++) {
if(dag_table[i].used == 0) { if(dag_table[i].used == 0) {
memset(&dag_table[i], 0, sizeof(dag_table[0])); memset(&dag_table[i], 0, sizeof(dag_table[0]));
dag_table[i].neighbors = &dag_table[i].neighbor_list; dag_table[i].parents = &dag_table[i].parent_list;
list_init(dag_table[i].parents);
dag_table[i].def_route = NULL; dag_table[i].def_route = NULL;
list_init(dag_table[i].neighbors);
return &dag_table[i]; return &dag_table[i];
} }
} }
@ -246,37 +246,37 @@ rpl_free_dag(rpl_dag_t *dag)
dag->joined = 0; dag->joined = 0;
} }
/************************************************************************/ /************************************************************************/
rpl_neighbor_t * rpl_parent_t *
rpl_add_neighbor(rpl_dag_t *dag, uip_ipaddr_t *addr) rpl_add_parent(rpl_dag_t *dag, uip_ipaddr_t *addr)
{ {
rpl_neighbor_t *n; rpl_parent_t *p;
n = memb_alloc(&neighbor_memb); p = memb_alloc(&parent_memb);
if(n == NULL) { if(p == NULL) {
return NULL; return NULL;
} }
memcpy(&n->addr, addr, sizeof(n->addr)); memcpy(&p->addr, addr, sizeof(p->addr));
n->local_confidence = 0; p->local_confidence = 0;
n->dag = dag; p->dag = dag;
list_add(dag->neighbors, n); list_add(dag->parents, p);
/* Draw a line between the node and its parent in Cooja. */ /* Draw a line between the node and its parent in Cooja. */
ANNOTATE("#L %u 1\n", ANNOTATE("#L %u 1\n",
addr->u8[sizeof(*addr) - 1]); addr->u8[sizeof(*addr) - 1]);
return n; return p;
} }
/************************************************************************/ /************************************************************************/
rpl_neighbor_t * rpl_parent_t *
rpl_find_neighbor(rpl_dag_t *dag, uip_ipaddr_t *addr) rpl_find_parent(rpl_dag_t *dag, uip_ipaddr_t *addr)
{ {
rpl_neighbor_t *n; rpl_parent_t *p;
for(n = list_head(dag->neighbors); n != NULL; n = n->next) { for(p = list_head(dag->parents); p != NULL; p = p->next) {
if(uip_ipaddr_cmp(&n->addr, addr)) { if(uip_ipaddr_cmp(&p->addr, addr)) {
return n; return p;
} }
} }
@ -284,48 +284,33 @@ rpl_find_neighbor(rpl_dag_t *dag, uip_ipaddr_t *addr)
} }
/************************************************************************/ /************************************************************************/
rpl_neighbor_t * rpl_parent_t *
rpl_first_parent(rpl_dag_t *dag) rpl_preferred_parent(rpl_dag_t *dag)
{ {
rpl_neighbor_t *n; rpl_parent_t *p;
rpl_parent_t *best;
for(n = list_head(dag->neighbors); n != NULL; n = n->next) {
if(RPL_NEIGHBOR_IS_PARENT(dag, n)) {
return n;
}
}
return n;
}
/************************************************************************/
rpl_neighbor_t *
rpl_find_best_parent(rpl_dag_t *dag)
{
rpl_neighbor_t *n;
rpl_neighbor_t *best;
best = NULL; best = NULL;
for(n = list_head(dag->neighbors); n != NULL; n = n->next) { for(p = list_head(dag->parents); p != NULL; p = p->next) {
if(RPL_NEIGHBOR_IS_PARENT(dag, n)) { if(best == NULL) {
if(best == NULL) { best = p;
best = n; } else {
} else { best = dag->of->best_parent(best, p);
best = dag->of->best_parent(best, n);
}
} }
} }
dag->best_parent = best; /* Cached value. */ dag->best_parent = best; /* Cache the value. */
return best; return best;
} }
/************************************************************************/ /************************************************************************/
int int
rpl_remove_neighbor(rpl_dag_t *dag, rpl_neighbor_t *parent) rpl_remove_parent(rpl_dag_t *dag, rpl_parent_t *parent)
{ {
uip_ds6_defrt_t *defrt; uip_ds6_defrt_t *defrt;
ANNOTATE("#L %u 0\n", ANNOTATE("#L %u 0\n",
parent->addr.u8[sizeof(parent->addr) - 1]); parent->addr.u8[sizeof(parent->addr) - 1]);
/* Remove uIPv6 routes that have this neighbor as the next hop. **/ /* Remove uIPv6 routes that have this parent as the next hop. **/
uip_ds6_route_rm_by_nexthop(&parent->addr); uip_ds6_route_rm_by_nexthop(&parent->addr);
defrt = uip_ds6_defrt_lookup(&parent->addr); defrt = uip_ds6_defrt_lookup(&parent->addr);
if(defrt != NULL) { if(defrt != NULL) {
@ -336,12 +321,12 @@ rpl_remove_neighbor(rpl_dag_t *dag, rpl_neighbor_t *parent)
dag->def_route = NULL; dag->def_route = NULL;
} }
PRINTF("RPL: Removing neighbor "); PRINTF("RPL: Removing parent ");
PRINT6ADDR(&parent->addr); PRINT6ADDR(&parent->addr);
PRINTF("\n"); PRINTF("\n");
list_remove(dag->neighbors, parent); list_remove(dag->parents, parent);
memb_free(&neighbor_memb, parent); memb_free(&parent_memb, parent);
return 0; return 0;
} }
/************************************************************************/ /************************************************************************/
@ -392,7 +377,7 @@ static void
join_dag(uip_ipaddr_t *from, rpl_dio_t *dio) join_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
{ {
rpl_dag_t *dag; rpl_dag_t *dag;
rpl_neighbor_t *n; rpl_parent_t *p;
rpl_of_t *of; rpl_of_t *of;
dag = rpl_alloc_dag(); dag = rpl_alloc_dag();
@ -401,18 +386,18 @@ join_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
return; return;
} }
n = rpl_add_neighbor(dag, from); p = rpl_add_parent(dag, from);
PRINTF("RPL: Adding "); PRINTF("RPL: Adding ");
PRINT6ADDR(from); PRINT6ADDR(from);
PRINTF(" as a parent: "); PRINTF(" as a parent: ");
if(n == NULL) { if(p == NULL) {
PRINTF("failed\n"); PRINTF("failed\n");
return; return;
} }
PRINTF("succeeded\n"); PRINTF("succeeded\n");
n->local_confidence = 0; /* The lowest confidence for new parents. */ p->local_confidence = 0; /* The lowest confidence for new parents. */
n->rank = dio->dag_rank; p->rank = dio->dag_rank;
/* Determine the objective function by using the /* Determine the objective function by using the
objective code point of the DIO. */ objective code point of the DIO. */
@ -428,7 +413,7 @@ join_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
dag->preference = dio->preference; dag->preference = dio->preference;
dag->grounded = dio->grounded; dag->grounded = dio->grounded;
dag->instance_id = dio->instance_id; dag->instance_id = dio->instance_id;
dag->rank = dag->of->increment_rank(dio->dag_rank, n); dag->rank = dag->of->increment_rank(dio->dag_rank, p);
dag->min_rank = dag->rank; /* So far this is the lowest rank we know */ dag->min_rank = dag->rank; /* So far this is the lowest rank we know */
dag->sequence_number = dio->sequence_number; dag->sequence_number = dio->sequence_number;
dag->dio_intdoubl = dio->dag_intdoubl; dag->dio_intdoubl = dio->dag_intdoubl;
@ -463,16 +448,16 @@ join_dag(uip_ipaddr_t *from, rpl_dio_t *dio)
static void static void
global_repair(uip_ipaddr_t *from, rpl_dag_t *dag, rpl_dio_t *dio) global_repair(uip_ipaddr_t *from, rpl_dag_t *dag, rpl_dio_t *dio)
{ {
rpl_neighbor_t *n; rpl_parent_t *p;
poison_routes(dag, NULL); poison_routes(dag, NULL);
dag->sequence_number = dio->sequence_number; dag->sequence_number = dio->sequence_number;
if((n = rpl_add_neighbor(dag, from)) == NULL) { if((p = rpl_add_parent(dag, from)) == NULL) {
PRINTF("RPL: Failed to add a parent during the global repair\n"); PRINTF("RPL: Failed to add a parent during the global repair\n");
dag->rank = INFINITE_RANK; dag->rank = INFINITE_RANK;
} else { } else {
rpl_set_default_route(dag, from); rpl_set_default_route(dag, from);
dag->rank = dag->of->increment_rank(dio->dag_rank, n); dag->rank = dag->of->increment_rank(dio->dag_rank, p);
rpl_reset_dio_timer(dag, 1); rpl_reset_dio_timer(dag, 1);
} }
PRINTF("RPL: Participating in a global DAG repair. New DAG sequence number: %u, new rank: %hu\n", PRINTF("RPL: Participating in a global DAG repair. New DAG sequence number: %u, new rank: %hu\n",
@ -495,7 +480,7 @@ void
rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
{ {
rpl_dag_t *dag; rpl_dag_t *dag;
rpl_neighbor_t *n; rpl_parent_t *p;
uint8_t new_rank; uint8_t new_rank;
uint8_t new_parent; uint8_t new_parent;
@ -524,38 +509,38 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
} }
/* This DIO pertains to a DAG that we are already part of. */ /* This DIO pertains to a DAG that we are already part of. */
n = rpl_find_neighbor(dag, from); p = rpl_find_parent(dag, from);
if(n != NULL) { if(p != NULL) {
if(dio->dst_adv_trigger) { if(dio->dst_adv_trigger) {
rpl_schedule_dao(dag); rpl_schedule_dao(dag);
} else { } else {
PRINTF("RPL: dst_adv_trigger is not set in incoming DIO\n"); PRINTF("RPL: dst_adv_trigger is not set in incoming DIO\n");
} }
if(n->rank > dio->dag_rank) { if(p->rank > dio->dag_rank) {
n->rank = dio->dag_rank; p->rank = dio->dag_rank;
rpl_reset_dio_timer(dag, 1); rpl_reset_dio_timer(dag, 1);
} else if(n->rank < dio->dag_rank) { } else if(p->rank < dio->dag_rank) {
PRINTF("RPL: Existing parent "); PRINTF("RPL: Existing parent ");
PRINT6ADDR(from); PRINT6ADDR(from);
PRINTF(" got a higher rank (%hu -> %hu)\n", PRINTF(" got a higher rank (%hu -> %hu)\n",
n->rank, dio->dag_rank); p->rank, dio->dag_rank);
n->rank = dio->dag_rank; p->rank = dio->dag_rank;
if(RPL_PARENT_COUNT(dag) > 1) { if(RPL_PARENT_COUNT(dag) > 1) {
/* Since we have alternative parents, we can simply drop this one. */ /* Since we have alternative parents, we can simply drop this one. */
rpl_remove_neighbor(dag, n); rpl_remove_parent(dag, p);
n = rpl_find_best_parent(dag); p = rpl_preferred_parent(dag);
if(n != NULL) { if(p != NULL) {
rpl_set_default_route(dag, &n->addr); rpl_set_default_route(dag, &p->addr);
} }
return; return;
} else if(dag->of->increment_rank(dio->dag_rank, n) <= dag->min_rank + dag->max_rankinc) { } else if(dag->of->increment_rank(dio->dag_rank, p) <= dag->min_rank + dag->max_rankinc) {
dag->rank = dag->of->increment_rank(dio->dag_rank, n); dag->rank = dag->of->increment_rank(dio->dag_rank, p);
PRINTF("RPL: New rank is %hu, max is %hu\n", PRINTF("RPL: New rank is %hu, max is %hu\n",
dag->rank, dag->min_rank + dag->max_rankinc); dag->rank, dag->min_rank + dag->max_rankinc);
rpl_set_default_route(dag, &n->addr); rpl_set_default_route(dag, &p->addr);
} else { } else {
PRINTF("RPL: Cannot find acceptable best neighbor\n"); PRINTF("RPL: Cannot find an acceptable preferred parent\n");
/* do local repair - jump down the DAG */ /* do local repair - jump down the DAG */
poison_routes(dag, NULL); poison_routes(dag, NULL);
dag->rank = INFINITE_RANK; dag->rank = INFINITE_RANK;
@ -570,26 +555,27 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
if(dio->dag_rank < dag->rank) { if(dio->dag_rank < dag->rank) {
/* Message from a node closer to the root, but we might still be out of allowed rank-range */ /* Message from a node closer to the root, but we might still be out of allowed rank-range */
if(dag->min_rank + dag->max_rankinc < dag->of->increment_rank(dio->dag_rank, n)) { if(dag->max_rankinc > 0 &&
dag->min_rank + dag->max_rankinc < dag->of->increment_rank(dio->dag_rank, p)) {
PRINTF("RPL: Could not add parent, resulting rank too high\n"); PRINTF("RPL: Could not add parent, resulting rank too high\n");
return; return;
} }
new_parent = 0; new_parent = 0;
if(n == NULL) { if(p == NULL) {
n = rpl_add_neighbor(dag, from); p = rpl_add_parent(dag, from);
if(n == NULL) { if(p == NULL) {
PRINTF("RPL: Could not add parent\n"); PRINTF("RPL: Could not add parent\n");
return; return;
} }
n->rank = dio->dag_rank; p->rank = dio->dag_rank;
PRINTF("RPL: New parent with rank %hu ", n->rank); PRINTF("RPL: New parent with rank %hu ", p->rank);
PRINT6ADDR(from); PRINT6ADDR(from);
PRINTF("\n"); PRINTF("\n");
new_parent = 1; new_parent = 1;
} }
new_rank = dag->of->increment_rank(dio->dag_rank, n); new_rank = dag->of->increment_rank(dio->dag_rank, p);
if(new_rank < dag->rank) { if(new_rank < dag->rank) {
PRINTF("RPL: Moving up within the DAG from rank %hu to %hu\n", PRINTF("RPL: Moving up within the DAG from rank %hu to %hu\n",
dag->rank, new_rank); dag->rank, new_rank);
@ -599,12 +585,10 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
/* Remove old def-route and add the new */ /* Remove old def-route and add the new */
/* fix handling of destination prefix */ /* fix handling of destination prefix */
if(dag->grounded) { rpl_set_default_route(dag, from);
rpl_set_default_route(dag, from);
}
if(new_parent) { if(new_parent) {
poison_routes(dag, n); poison_routes(dag, p);
} }
} }
} else if(dio->dag_rank == dag->rank) { } else if(dio->dag_rank == dag->rank) {
@ -612,12 +596,12 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio)
} else { } else {
/* Message from a node at a longer distance from the root. If the /* Message from a node at a longer distance from the root. If the
node is in the parent list, we just remove it. */ node is in the parent list, we just remove it. */
if(n != NULL && n->rank < dio->dag_rank) { if(p != NULL && p->rank < dio->dag_rank) {
PRINTF("RPL: Parent "); PRINTF("RPL: Parent ");
PRINT6ADDR(&n->addr); PRINT6ADDR(&n->addr);
PRINTF(" has increased in rank from %hu to %hu. Removing it.\n", PRINTF(" has increased in rank from %hu to %hu. Removing it.\n",
n->rank, dio->dag_rank); p->rank, dio->dag_rank);
rpl_remove_neighbor(dag, n); rpl_remove_parent(dag, p);
if(RPL_PARENT_COUNT(dag) == 0) { if(RPL_PARENT_COUNT(dag) == 0) {
dag->rank = INFINITE_RANK; dag->rank = INFINITE_RANK;
} }
@ -634,8 +618,10 @@ rpl_ds6_neighbor_callback(uip_ds6_nbr_t *nbr)
PRINTF("\n"); PRINTF("\n");
} else { } else {
rpl_dag_t *dag; rpl_dag_t *dag;
rpl_neighbor_t *n; rpl_parent_t *p;
n = NULL; char acceptable_rank_increase;
p = NULL;
PRINTF("RPL: Removed neighbor "); PRINTF("RPL: Removed neighbor ");
PRINT6ADDR(&nbr->ipaddr); PRINT6ADDR(&nbr->ipaddr);
@ -643,24 +629,27 @@ rpl_ds6_neighbor_callback(uip_ds6_nbr_t *nbr)
dag = rpl_get_dag(RPL_ANY_INSTANCE); dag = rpl_get_dag(RPL_ANY_INSTANCE);
if(dag != NULL) { if(dag != NULL) {
n = rpl_find_neighbor(dag, &nbr->ipaddr); p = rpl_find_parent(dag, &nbr->ipaddr);
if(n != NULL) { if(p != NULL) {
rpl_remove_neighbor(dag, n); rpl_remove_parent(dag, p);
} }
} }
if(dag != NULL && dag->def_route != NULL && if(dag != NULL && dag->def_route != NULL &&
uip_ipaddr_cmp(&dag->def_route->ipaddr, &n->addr)) { uip_ipaddr_cmp(&dag->def_route->ipaddr, &p->addr)) {
n = rpl_find_best_parent(dag); p = rpl_preferred_parent(dag);
if(n != NULL && dag->of->increment_rank(n->rank, n) <= dag->min_rank + dag->max_rankinc) { acceptable_rank_increase = !dag->max_rankinc ||
dag->rank = dag->of->increment_rank(n->rank, n); dag->of->increment_rank(p->rank, p) <= dag->min_rank + dag->max_rankinc;
if(p != NULL && acceptable_rank_increase) {
dag->rank = dag->of->increment_rank(p->rank, p);
if(dag->rank < dag->min_rank) { if(dag->rank < dag->min_rank) {
dag->min_rank = dag->rank; dag->min_rank = dag->rank;
} }
PRINTF("RPL: New rank is %hu, max is %hu\n", PRINTF("RPL: New rank is %hu, max is %hu\n",
dag->rank, dag->min_rank + dag->max_rankinc); dag->rank, dag->min_rank + dag->max_rankinc);
rpl_set_default_route(dag, &n->addr); rpl_set_default_route(dag, &p->addr);
} else { } else {
PRINTF("RPL: Cannot find the best neighbor\n"); PRINTF("RPL: Cannot select the preferred parent\n");
/* do local repair - jump down the DAG */ /* do local repair - jump down the DAG */
poison_routes(dag, NULL); poison_routes(dag, NULL);
dag->rank = INFINITE_RANK; dag->rank = INFINITE_RANK;

View File

@ -33,7 +33,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: rpl-icmp6.c,v 1.10 2010/05/25 19:19:43 joxe Exp $ * $Id: rpl-icmp6.c,v 1.11 2010/05/25 21:58:54 nvt-se Exp $
*/ */
/** /**
* \file * \file
@ -388,7 +388,7 @@ dao_input(void)
uint32_t route_tag; uint32_t route_tag;
uip_ipaddr_t prefix; uip_ipaddr_t prefix;
uip_ds6_route_t *rep; uip_ds6_route_t *rep;
rpl_neighbor_t *n; rpl_parent_t *n;
int pos; int pos;
/* Destination Advertisement Object */ /* Destination Advertisement Object */
@ -462,7 +462,7 @@ dao_input(void)
rep->state.learned_from = RPL_ROUTE_FROM_MULTICAST_DAO; rep->state.learned_from = RPL_ROUTE_FROM_MULTICAST_DAO;
} else { } else {
rep->state.learned_from = RPL_ROUTE_FROM_UNICAST_DAO; rep->state.learned_from = RPL_ROUTE_FROM_UNICAST_DAO;
if((n = rpl_find_best_parent(dag)) != NULL) { if((n = rpl_preferred_parent(dag)) != NULL) {
PRINTF("RPL: Forwarding DAO to parent "); PRINTF("RPL: Forwarding DAO to parent ");
PRINT6ADDR(&n->addr); PRINT6ADDR(&n->addr);
PRINTF("\n"); PRINTF("\n");
@ -473,7 +473,7 @@ dao_input(void)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
dao_output(rpl_neighbor_t *n, uint32_t lifetime) dao_output(rpl_parent_t *n, uint32_t lifetime)
{ {
rpl_dag_t *dag; rpl_dag_t *dag;
unsigned char *buffer; unsigned char *buffer;

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-of0.c,v 1.1 2010/04/30 13:43:53 joxe Exp $ * $Id: rpl-of0.c,v 1.2 2010/05/25 21:58:54 nvt-se Exp $
*/ */
/** /**
* \file * \file
@ -46,8 +46,8 @@
#define DEBUG DEBUG_ANNOTATE #define DEBUG DEBUG_ANNOTATE
#include "net/uip-debug.h" #include "net/uip-debug.h"
static rpl_neighbor_t *best_parent(rpl_neighbor_t *, rpl_neighbor_t *); static rpl_parent_t *best_parent(rpl_parent_t *, rpl_parent_t *);
static rpl_rank_t increment_rank(rpl_rank_t, rpl_neighbor_t *); static rpl_rank_t increment_rank(rpl_rank_t, rpl_parent_t *);
rpl_of_t rpl_of0 = { rpl_of_t rpl_of0 = {
best_parent, best_parent,
@ -61,7 +61,7 @@ rpl_of_t rpl_of0 = {
#define MAXIMUM_RANK_STRETCH 4 #define MAXIMUM_RANK_STRETCH 4
static rpl_rank_t static rpl_rank_t
increment_rank(rpl_rank_t rank, rpl_neighbor_t *parent) increment_rank(rpl_rank_t rank, rpl_parent_t *parent)
{ {
if((rpl_rank_t)(rank + DEFAULT_RANK_INCREMENT) < rank) { if((rpl_rank_t)(rank + DEFAULT_RANK_INCREMENT) < rank) {
PRINTF("RPL: OF0 rank %d incremented to infinite rank due to wrapping\n", PRINTF("RPL: OF0 rank %d incremented to infinite rank due to wrapping\n",
@ -71,8 +71,8 @@ increment_rank(rpl_rank_t rank, rpl_neighbor_t *parent)
return rank + DEFAULT_RANK_INCREMENT; return rank + DEFAULT_RANK_INCREMENT;
} }
static rpl_neighbor_t * static rpl_parent_t *
best_parent(rpl_neighbor_t *p1, rpl_neighbor_t *p2) best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
{ {
PRINTF("RPL: Comparing parent "); PRINTF("RPL: Comparing parent ");
PRINT6ADDR(&p1->addr); PRINT6ADDR(&p1->addr);

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-timers.c,v 1.5 2010/05/24 16:38:56 nvt-se Exp $ * $Id: rpl-timers.c,v 1.6 2010/05/25 21:58:54 nvt-se Exp $
*/ */
/** /**
* \file * \file
@ -181,7 +181,8 @@ static void
handle_dao_timer(void *ptr) handle_dao_timer(void *ptr)
{ {
rpl_dag_t *dag; rpl_dag_t *dag;
rpl_neighbor_t *n; rpl_parent_t *n;
dag = (rpl_dag_t *)ptr; dag = (rpl_dag_t *)ptr;
if (!dio_send_ok && uip_ds6_get_link_local(ADDR_PREFERRED) == NULL) { if (!dio_send_ok && uip_ds6_get_link_local(ADDR_PREFERRED) == NULL) {
@ -192,7 +193,7 @@ handle_dao_timer(void *ptr)
/* Send the DAO to the best parent. rpl-07 section C.2 lists the /* Send the DAO to the best parent. rpl-07 section C.2 lists the
fan-out as being under investigation. */ fan-out as being under investigation. */
n = rpl_find_best_parent(dag); n = rpl_preferred_parent(dag);
if(n != NULL) { if(n != NULL) {
PRINTF("RPL: handle_dao_timer - sending DAO\n"); PRINTF("RPL: handle_dao_timer - sending DAO\n");
dao_output(n, DEFAULT_ROUTE_LIFETIME); dao_output(n, DEFAULT_ROUTE_LIFETIME);

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.3 2010/05/24 16:38:56 nvt-se Exp $ * $Id: rpl.c,v 1.4 2010/05/25 21:58:54 nvt-se Exp $
*/ */
/** /**
* \file * \file
@ -116,7 +116,7 @@ neighbor_callback(const rimeaddr_t *addr, int known, int etx)
{ {
uip_ipaddr_t ipaddr; uip_ipaddr_t ipaddr;
rpl_dag_t *dag; rpl_dag_t *dag;
rpl_neighbor_t *parent; rpl_parent_t *parent;
uip_ip6addr(&ipaddr, 0xfe80, 0, 0, 0, 0, 0, 0, 0); uip_ip6addr(&ipaddr, 0xfe80, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, (uip_lladdr_t *)addr); uip_ds6_set_addr_iid(&ipaddr, (uip_lladdr_t *)addr);
@ -125,7 +125,7 @@ neighbor_callback(const rimeaddr_t *addr, int known, int etx)
PRINTF(" is %sknown. ETX = %d\n", known ? "" : "no longer ", etx); PRINTF(" is %sknown. ETX = %d\n", known ? "" : "no longer ", etx);
dag = rpl_get_dag(RPL_DEFAULT_INSTANCE); dag = rpl_get_dag(RPL_DEFAULT_INSTANCE);
if(dag == NULL || (parent = rpl_find_neighbor(dag, &ipaddr)) == NULL) { if(dag == NULL || (parent = rpl_find_parent(dag, &ipaddr)) == NULL) {
return; return;
} }
@ -133,19 +133,19 @@ neighbor_callback(const rimeaddr_t *addr, int known, int etx)
PRINTF("RPL: Removing parent "); PRINTF("RPL: Removing parent ");
PRINT6ADDR(&parent->addr); PRINT6ADDR(&parent->addr);
PRINTF(" because of bad connectivity (ETX %d)\n", etx); PRINTF(" because of bad connectivity (ETX %d)\n", etx);
rpl_remove_neighbor(dag, parent); rpl_remove_parent(dag, parent);
if(RPL_PARENT_COUNT(dag) == 0) { if(RPL_PARENT_COUNT(dag) == 0) {
rpl_free_dag(dag); rpl_free_dag(dag);
} else { } else {
/* Select a new default route. */ /* Select a new default route. */
parent = rpl_find_best_parent(dag); parent = rpl_preferred_parent(dag);
if(parent != NULL) { if(parent != NULL) {
rpl_set_default_route(dag, &parent->addr); rpl_set_default_route(dag, &parent->addr);
} }
} }
} else { } else {
parent->local_confidence = ~0 - etx; parent->local_confidence = ~0 - etx;
PRINTF("RPL: Updating the local confidence value for this neighbor to %d\n", PRINTF("RPL: Updating the local confidence value for this parent to %d\n",
parent->local_confidence); parent->local_confidence);
if(parent != dag->best_parent && if(parent != dag->best_parent &&
dag->of->best_parent(parent, dag->best_parent) == parent) { dag->of->best_parent(parent, dag->best_parent) == parent) {

View File

@ -30,7 +30,7 @@
* *
* Author: Joakim Eriksson, Nicolas Tsiftes * Author: Joakim Eriksson, Nicolas Tsiftes
* *
* $Id: rpl.h,v 1.3 2010/05/25 19:19:43 joxe Exp $ * $Id: rpl.h,v 1.4 2010/05/25 21:58:54 nvt-se Exp $
*/ */
#ifndef RPL_H #ifndef RPL_H
@ -127,19 +127,19 @@
typedef uint16_t rpl_rank_t; typedef uint16_t rpl_rank_t;
typedef uint16_t rpl_ocp_t; typedef uint16_t rpl_ocp_t;
struct rpl_neighbor { struct rpl_parent {
struct rpl_neighbor *next; struct rpl_parent *next;
void *dag; void *dag;
uip_ipaddr_t addr; uip_ipaddr_t addr;
rpl_rank_t rank; rpl_rank_t rank;
uint8_t local_confidence; uint8_t local_confidence;
}; };
typedef struct rpl_neighbor rpl_neighbor_t; typedef struct rpl_parent rpl_parent_t;
struct rpl_of { struct rpl_of {
rpl_neighbor_t *(*best_parent)(rpl_neighbor_t *, rpl_neighbor_t *); rpl_parent_t *(*best_parent)(rpl_parent_t *, rpl_parent_t *);
rpl_rank_t (*increment_rank)(rpl_rank_t, rpl_neighbor_t *); rpl_rank_t (*increment_rank)(rpl_rank_t, rpl_parent_t *);
rpl_ocp_t ocp; rpl_ocp_t ocp;
}; };
@ -186,7 +186,7 @@ struct rpl_dag {
/* this is the current def-router that is set - used for routing "upwards" */ /* this is the current def-router that is set - used for routing "upwards" */
uip_ds6_defrt_t *def_route; uip_ds6_defrt_t *def_route;
rpl_rank_t rank; rpl_rank_t rank;
rpl_rank_t min_rank; /* should be nullified per dodag iteration! */ rpl_rank_t min_rank; /* should be reset per DODAG iteration! */
uint8_t dtsn; uint8_t dtsn;
uint8_t instance_id; uint8_t instance_id;
uint8_t sequence_number; uint8_t sequence_number;
@ -212,9 +212,9 @@ struct rpl_dag {
uint16_t dio_next_delay; /* delay for completion of dio interval */ uint16_t dio_next_delay; /* delay for completion of dio interval */
struct ctimer dio_timer; struct ctimer dio_timer;
struct ctimer dao_timer; struct ctimer dao_timer;
rpl_neighbor_t *best_parent; rpl_parent_t *best_parent;
void *neighbor_list; void *parent_list;
list_t neighbors; list_t parents;
rpl_prefix_t destination_prefix; rpl_prefix_t destination_prefix;
}; };
@ -222,19 +222,12 @@ typedef struct rpl_dag rpl_dag_t;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* RPL macro functions. */ /* RPL macro functions. */
#define RPL_PARENT_COUNT(dag) \ #define RPL_PARENT_COUNT(dag) list_length((dag)->parents)
list_length((dag)->neighbors)
#define RPL_NEIGHBOR_IS_CHILD(dag, neighbor) \
((neighbor)->rank > (dag)->rank)
#define RPL_NEIGHBOR_IS_SIBLING(dag, neighbor) \
((neighbor)->rank == (dag)->rank)
#define RPL_NEIGHBOR_IS_PARENT(dag, neighbor) \
((neighbor)->rank < (dag)->rank)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* ICMPv6 functions for RPL. */ /* ICMPv6 functions for RPL. */
void dis_output(uip_ipaddr_t *addr); void dis_output(uip_ipaddr_t *addr);
void dio_output(rpl_dag_t *, uip_ipaddr_t *uc_addr); void dio_output(rpl_dag_t *, uip_ipaddr_t *uc_addr);
void dao_output(rpl_neighbor_t *, uint32_t lifetime); void dao_output(rpl_parent_t *, uint32_t lifetime);
void uip_rpl_input(void); void uip_rpl_input(void);
/* RPL logic functions. */ /* RPL logic functions. */
@ -249,11 +242,10 @@ rpl_dag_t *rpl_alloc_dag(void);
void rpl_free_dag(rpl_dag_t *); void rpl_free_dag(rpl_dag_t *);
/* DAG parent management function. */ /* DAG parent management function. */
rpl_neighbor_t *rpl_add_neighbor(rpl_dag_t *, uip_ipaddr_t *); rpl_parent_t *rpl_add_parent(rpl_dag_t *, uip_ipaddr_t *);
rpl_neighbor_t *rpl_find_neighbor(rpl_dag_t *, uip_ipaddr_t *); rpl_parent_t *rpl_find_parent(rpl_dag_t *, uip_ipaddr_t *);
int rpl_remove_neighbor(rpl_dag_t *, rpl_neighbor_t *); int rpl_remove_parent(rpl_dag_t *, rpl_parent_t *);
rpl_neighbor_t *rpl_first_parent(rpl_dag_t *dag); rpl_parent_t *rpl_preferred_parent(rpl_dag_t *dag);
rpl_neighbor_t *rpl_find_best_parent(rpl_dag_t *dag);
void rpl_join_dag(rpl_dag_t *); void rpl_join_dag(rpl_dag_t *);
rpl_dag_t *rpl_get_dag(int instance_id); rpl_dag_t *rpl_get_dag(int instance_id);
@ -273,7 +265,7 @@ void rpl_reset_dio_timer(rpl_dag_t *, uint8_t);
void rpl_reset_periodic_timer(void); void rpl_reset_periodic_timer(void);
/* Route poisoning. */ /* Route poisoning. */
void rpl_poison_routes(rpl_dag_t *, rpl_neighbor_t *); void rpl_poison_routes(rpl_dag_t *, rpl_parent_t *);
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void rpl_init(void); void rpl_init(void);