]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/net/4bitle/LinkEstimatorP.nc
if root is unplugged and plugged back in, the network does not route to the root...
[tinyos-2.x.git] / tos / lib / net / 4bitle / LinkEstimatorP.nc
index 6738a9f8e6093af01c2b2d12f8f81d0aa81c1c1c..fd4ddf302b38e3ea5b01b2833ecb7e43b0e30df0 100644 (file)
@@ -335,7 +335,7 @@ implementation {
          if (totalPkt == 0) {
            ne->inquality = (ALPHA * ne->inquality) / 10;
          } else {
-           newEst = (255 * ne->rcvcnt) / totalPkt;
+           newEst = (255UL * ne->rcvcnt) / totalPkt;
            dbg("LI,LITest", "  %hu: %hhu -> %hhu", ne->ll_addr, ne->inquality, (ALPHA * ne->inquality + (10-ALPHA) * newEst + 5)/10);
            ne->inquality = (ALPHA * ne->inquality + (10-ALPHA) * newEst + 5)/10;
          }
@@ -370,16 +370,20 @@ implementation {
     if (packetGap > 0) {
       NeighborTable[idx].failcnt += packetGap - 1;
     }
-    if (packetGap > MAX_PKT_GAP) {
-      NeighborTable[idx].failcnt = 0;
-      NeighborTable[idx].rcvcnt = 1;
-      NeighborTable[idx].inquality = 0;
-    }
 
-    if (packetGap >= BLQ_PKT_WINDOW) {
+    // The or with packetGap >= BLQ_PKT_WINDOW is needed in case
+    // failcnt gets reset above
+
+    if (((NeighborTable[idx].rcvcnt + NeighborTable[idx].failcnt) >= BLQ_PKT_WINDOW)
+       || (packetGap >= BLQ_PKT_WINDOW)) {
       updateNeighborTableEst(NeighborTable[idx].ll_addr);
     }
 
+    if (packetGap > MAX_PKT_GAP) {
+      initNeighborIdx(idx, NeighborTable[idx].ll_addr);
+      NeighborTable[idx].lastseq = seq;
+      NeighborTable[idx].rcvcnt = 1;
+    }
   }