]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/net/4bitle/LinkEstimatorP.nc
eliminate dead code identified by Islam Hegazy
[tinyos-2.x.git] / tos / lib / net / 4bitle / LinkEstimatorP.nc
index c82c24fac6a518cef530587d4c5f5a31f7ecc51d..80360f26d4210280f26531b704b306db7ddab93b 100644 (file)
@@ -67,7 +67,7 @@ implementation {
     INVALID_NEIGHBOR_ADDR = 0xff,
     // if we don't know the link quality, we need to return a value so
     // large that it will not be used to form paths
-    VERY_LARGE_ETX_VALUE = 0xff,
+    VERY_LARGE_ETX_VALUE = 0xffff,
     // decay the link estimate using this alpha
     // we use a denominator of 10, so this corresponds to 0.2
     ALPHA = 9,
@@ -273,7 +273,7 @@ implementation {
   // called when new beacon estimate is done
   // also called when new DEETX estimate is done
   void updateETX(neighbor_table_entry_t *ne, uint16_t newEst) {
-    ne->etx = (ALPHA * ne->etx + (10 - ALPHA) * newEst + 5)/10;
+    ne->etx = (ALPHA * ne->etx + (10 - ALPHA) * newEst)/10;
   }
 
 
@@ -287,7 +287,7 @@ implementation {
       // transmissions
       estETX = ne->data_total * 10;
     } else {
-      estETX = (10 * ne->data_total + 5) / ne->data_success;
+      estETX = (10 * ne->data_total) / ne->data_success;
       ne->data_success = 0;
       ne->data_total = 0;
     }
@@ -295,16 +295,16 @@ implementation {
   }
 
 
-  // ETX (Extra Expected number of Transmission)
+  // ETX (Expected number of Transmission)
   // computeETX returns ETX*10
-  uint8_t computeETX(uint8_t q1) {
+  uint16_t computeETX(uint8_t q1) {
     uint16_t q;
     if (q1 > 0) {
       q =  2500 / q1;
       if (q > 250) {
        q = VERY_LARGE_ETX_VALUE;
       }
-      return (uint8_t)q;
+      return q;
     } else {
       return VERY_LARGE_ETX_VALUE;
     }
@@ -328,16 +328,9 @@ implementation {
          ne->flags |= MATURE_ENTRY;
          totalPkt = ne->rcvcnt + ne->failcnt;
          dbg("LI", "MinPkt: %d, totalPkt: %d\n", minPkt, totalPkt);
-         if (totalPkt < minPkt) {
-           totalPkt = minPkt;
-         }
-         if (totalPkt == 0) {
-           ne->inquality = (ALPHA * ne->inquality + 5) / 10;
-         } else {
-           newEst = (250UL * ne->rcvcnt + 5) / 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;
-         }
+         newEst = (250UL * ne->rcvcnt) / totalPkt;
+         dbg("LI,LITest", "  %hu: %hhu -> %hhu", ne->ll_addr, ne->inquality, (ALPHA * ne->inquality + (10-ALPHA) * newEst)/10);
+         ne->inquality = (ALPHA * ne->inquality + (10-ALPHA) * newEst)/10;
          ne->rcvcnt = 0;
          ne->failcnt = 0;
          updateETX(ne, computeETX(ne->inquality));
@@ -357,7 +350,6 @@ implementation {
 
     if (NeighborTable[idx].flags & INIT_ENTRY) {
       dbg("LI", "Init entry update\n");
-      NeighborTable[idx].lastseq = seq;
       NeighborTable[idx].flags &= ~INIT_ENTRY;
     }
     
@@ -370,19 +362,15 @@ implementation {
       NeighborTable[idx].failcnt += packetGap - 1;
     }
 
-    // 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;
+    } else if (((NeighborTable[idx].rcvcnt + NeighborTable[idx].failcnt) >= BLQ_PKT_WINDOW)
+              || (packetGap >= BLQ_PKT_WINDOW)) {
+      updateNeighborTableEst(NeighborTable[idx].ll_addr);
     }
+
   }