From 941443878b2650eefdf5a7ed3a18cd0163fea77d Mon Sep 17 00:00:00 2001 From: joxe Date: Wed, 2 Jun 2010 16:23:08 +0000 Subject: [PATCH] fixed rank calculation bug in of-etx --- core/net/rpl/rpl-dag.c | 6 +++--- core/net/rpl/rpl-of-etx.c | 22 +++++++++++++--------- core/net/rpl/rpl.h | 9 +++++++-- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/core/net/rpl/rpl-dag.c b/core/net/rpl/rpl-dag.c index 19ae1b69c..bacd5a799 100644 --- a/core/net/rpl/rpl-dag.c +++ b/core/net/rpl/rpl-dag.c @@ -32,7 +32,7 @@ * * This file is part of the Contiki operating system. * - * $Id: rpl-dag.c,v 1.13 2010/06/02 11:59:51 joxe Exp $ + * $Id: rpl-dag.c,v 1.14 2010/06/02 16:23:08 joxe Exp $ */ /** * \file @@ -568,8 +568,8 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) if(dio->dag_rank < dag->rank) { /* Message from a node closer to the root, but we might still be out of allowed rank-range */ - if(dag->max_rankinc > 0 && - dag->min_rank + dag->max_rankinc < dag->of->increment_rank(dio->dag_rank, p)) { + if(dag->max_rankinc > 0 && dag->min_rank + dag->max_rankinc < + dag->of->increment_rank(dio->dag_rank, NULL)) { PRINTF("RPL: Could not add parent, resulting rank too high\n"); return; } diff --git a/core/net/rpl/rpl-of-etx.c b/core/net/rpl/rpl-of-etx.c index ec73933f1..d0bf78a75 100644 --- a/core/net/rpl/rpl-of-etx.c +++ b/core/net/rpl/rpl-of-etx.c @@ -32,7 +32,7 @@ * * This file is part of the Contiki operating system. * - * $Id: rpl-of-etx.c,v 1.2 2010/05/31 14:22:00 nvt-se Exp $ + * $Id: rpl-of-etx.c,v 1.3 2010/06/02 16:23:11 joxe Exp $ */ /** * \file @@ -64,9 +64,9 @@ rpl_of_t rpl_of_etx = { #define PATH_ETX_MIN 1 #define PATH_ETX_MAX 200 #define PARENT_SWITCH_ETX_THRESHOLD 0.5 -#define INFINITY 255 +#define INFINITY 0xffff -typedef unsigned char etx_t; +typedef unsigned int etx_t; static etx_t min_path_etx = INFINITY; @@ -86,7 +86,8 @@ parent_state_callback(rpl_parent_t *parent, int known, int etx) if(known) { if(min_path_etx != INFINITY) { dag->rank = min_path_etx + etx; - PRINTF("RPL: New path ETX: %u\n", (unsigned)(min_path_etx + etx)); + PRINTF("RPL: New path ETX: %u min_path_etx=%u etx=%u\n", + (unsigned)(min_path_etx + etx), min_path_etx, etx); } } else { if(RPL_PARENT_COUNT(dag) == 1) { @@ -103,15 +104,18 @@ increment_rank(rpl_rank_t rank, rpl_parent_t *parent) PRINTF("RPL: OF1 increment rank\n"); - if(parent->rank < min_path_etx) { + if(parent != NULL && parent->rank < min_path_etx) { min_path_etx = parent->rank; + PRINTF("RPL: min_path_etx updated to:%u\n", min_path_etx); } - new_rank = parent->rank + LINK_ETX_MAX; + /* calculate the rank based on the new rank information from DIO or + stored otherwise */ + new_rank = rank + LINK_ETX_MAX; - if(new_rank < rank) { - return INFINITE_RANK; - } + /* if(new_rank < rank) { */ + /* return INFINITE_RANK; */ + /* } */ PRINTF("RPL: Path ETX %u\n", (unsigned)new_rank); diff --git a/core/net/rpl/rpl.h b/core/net/rpl/rpl.h index cbbd5eda2..f8a797624 100644 --- a/core/net/rpl/rpl.h +++ b/core/net/rpl/rpl.h @@ -30,7 +30,7 @@ * * Author: Joakim Eriksson, Nicolas Tsiftes * - * $Id: rpl.h,v 1.8 2010/06/02 11:59:52 joxe Exp $ + * $Id: rpl.h,v 1.9 2010/06/02 16:23:12 joxe Exp $ */ #ifndef RPL_H @@ -165,7 +165,12 @@ struct rpl_of { void (*reset)(void *); void (*parent_state_callback)(rpl_parent_t *, int, int); rpl_parent_t *(*best_parent)(rpl_parent_t *, rpl_parent_t *); - rpl_rank_t (*increment_rank)(rpl_rank_t, rpl_parent_t *); + + /* Increment the rank - the rank that just have been received in a DIO + (or if picked from a parent) is the first argument. This is considered + the valid rank to calculate based on. The second argument is the parent + that is related to this calculation - if any (can be NULL) */ + rpl_rank_t (*increment_rank)(rpl_rank_t rank, rpl_parent_t *parent); rpl_ocp_t ocp; };