fixed rank calculation bug in of-etx

This commit is contained in:
joxe 2010-06-02 16:23:08 +00:00
parent f069320ca9
commit 941443878b
3 changed files with 23 additions and 14 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.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 * \file
@ -568,8 +568,8 @@ 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->max_rankinc > 0 && if(dag->max_rankinc > 0 && dag->min_rank + dag->max_rankinc <
dag->min_rank + dag->max_rankinc < dag->of->increment_rank(dio->dag_rank, p)) { dag->of->increment_rank(dio->dag_rank, NULL)) {
PRINTF("RPL: Could not add parent, resulting rank too high\n"); PRINTF("RPL: Could not add parent, resulting rank too high\n");
return; return;
} }

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-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 * \file
@ -64,9 +64,9 @@ rpl_of_t rpl_of_etx = {
#define PATH_ETX_MIN 1 #define PATH_ETX_MIN 1
#define PATH_ETX_MAX 200 #define PATH_ETX_MAX 200
#define PARENT_SWITCH_ETX_THRESHOLD 0.5 #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; 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(known) {
if(min_path_etx != INFINITY) { if(min_path_etx != INFINITY) {
dag->rank = min_path_etx + etx; 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 { } else {
if(RPL_PARENT_COUNT(dag) == 1) { 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"); 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; 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) { /* if(new_rank < rank) { */
return INFINITE_RANK; /* return INFINITE_RANK; */
} /* } */
PRINTF("RPL: Path ETX %u\n", (unsigned)new_rank); PRINTF("RPL: Path ETX %u\n", (unsigned)new_rank);

View File

@ -30,7 +30,7 @@
* *
* Author: Joakim Eriksson, Nicolas Tsiftes * 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 #ifndef RPL_H
@ -165,7 +165,12 @@ struct rpl_of {
void (*reset)(void *); void (*reset)(void *);
void (*parent_state_callback)(rpl_parent_t *, int, int); void (*parent_state_callback)(rpl_parent_t *, int, int);
rpl_parent_t *(*best_parent)(rpl_parent_t *, rpl_parent_t *); 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; rpl_ocp_t ocp;
}; };