From 1bb7d8af79a20cd1f62f6de73455d5c3f2999d61 Mon Sep 17 00:00:00 2001 From: Timofei Istomin Date: Thu, 21 May 2015 18:16:01 +0200 Subject: [PATCH] [RPL] bugfix: wrong boolean expression when searching in the parent table The original code finds an index in the parent table within the table size, which is either valid OR has infinite rank. This fix implements the correct behavior, i.e. finds an entry which is valid AND is NOT infinite rank. --- tos/lib/net/rpl/RPLOF0P.nc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tos/lib/net/rpl/RPLOF0P.nc b/tos/lib/net/rpl/RPLOF0P.nc index b95b96b1a5..94dad68fc9 100644 --- a/tos/lib/net/rpl/RPLOF0P.nc +++ b/tos/lib/net/rpl/RPLOF0P.nc @@ -134,15 +134,12 @@ implementation{ parentNode = call ParentTable.get(min); - while ((!parentNode->valid) && - (min < MAX_PARENT) && - (parentNode->rank != INFINITE_RANK)) { - min++; + while ((min < MAX_PARENT) && + ((!parentNode->valid) || (parentNode->rank == INFINITE_RANK))) { + min++; // skipping invalid entries and nodes with infinite rank parentNode = call ParentTable.get(min); } - minDesired = parentNode->etx_hop + (parentNode->rank * divideRank); - if (min == MAX_PARENT) { call RPLOF.resetRank(); call RPLRoute.inconsistency(); @@ -151,6 +148,8 @@ implementation{ return FALSE; } + minDesired = parentNode->etx_hop + (parentNode->rank * divideRank); + // printf("RPLOF: Start Compare %d %d: %d %d %d \n", // htons(prevParent), htons(parentNode->parentIP.s6_addr16[7]), // minDesired, parentNode->etx_hop, parentNode->rank);