// If the eetx estimate is below this threshold
// do not evict a link
EVICT_EETX_THRESHOLD = 55,
- // maximum link update rounds before we expire the link
- MAX_AGE = 6,
// if received sequence number if larger than the last sequence
// number by this gap, we reinitialize the link
MAX_PKT_GAP = 10,
ne->rcvcnt = 0;
ne->failcnt = 0;
ne->flags = (INIT_ENTRY | VALID_ENTRY);
- ne->inage = MAX_AGE;
ne->inquality = 0;
ne->eetx = 0;
}
// called when new beacon estimate is done
// also called when new DEETX estimate is done
void updateEETX(neighbor_table_entry_t *ne, uint16_t newEst) {
- ne->eetx = (ALPHA * ne->eetx + (10 - ALPHA) * newEst)/10;
+ ne->eetx = (ALPHA * ne->eetx + (10 - ALPHA) * newEst + 5)/10;
}
ne = &NeighborTable[i];
if (ne->ll_addr == n) {
if (ne->flags & VALID_ENTRY) {
- if (ne->inage > 0)
- ne->inage--;
-
- if (ne->inage == 0) {
- ne->flags ^= VALID_ENTRY;
- ne->inquality = 0;
+ dbg("LI", "Making link: %d mature\n", i);
+ 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) / 10;
} else {
- dbg("LI", "Making link: %d mature\n", i);
- 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) / 10;
- } else {
- newEst = (255 * 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;
+ 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;
}
+ ne->rcvcnt = 0;
+ ne->failcnt = 0;
updateEETX(ne, computeEETX(ne->inquality));
- }
- else {
+ } else {
dbg("LI", " - entry %i is invalid.\n", (int)i);
}
}
NeighborTable[idx].lastseq, seq, packetGap);
NeighborTable[idx].lastseq = seq;
NeighborTable[idx].rcvcnt++;
- NeighborTable[idx].inage = MAX_AGE;
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 (NeighborTable[idx].rcvcnt >= 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;
+ }
}
for (i = 0; i < NEIGHBOR_TABLE_SIZE; i++) {
ne = &NeighborTable[i];
if (ne->flags & VALID_ENTRY) {
- dbg("LI,LITest", "%d:%d inQ=%d, inA=%d, rcv=%d, fail=%d, Q=%d\n",
- i, ne->ll_addr, ne->inquality, ne->inage,
+ dbg("LI,LITest", "%d:%d inQ=%d, rcv=%d, fail=%d, Q=%d\n",
+ i, ne->ll_addr, ne->inquality,
ne->rcvcnt, ne->failcnt, computeEETX(ne->inquality));
}
}
// done sending the message that originated by
// the user of this component
event void AMSend.sendDone(message_t* msg, error_t error ) {
- return signal Send.sendDone(msg, error);
+ signal Send.sendDone(msg, error);
}
// cascade the calls down
initNeighborIdx(nidx, ll_addr);
} else {
dbg("LI", "No room in the table\n");
- if (signal CompareBit.shouldInsert(msg,
- call Packet.getPayload(msg, call Packet.payloadLength(msg)),
- call Packet.payloadLength(msg),
- call LinkPacketMetadata.highChannelQuality(msg))) {
- nidx = findRandomNeighborIdx();
- if (nidx != INVALID_RVAL) {
- signal LinkEstimator.evicted(NeighborTable[nidx].ll_addr);
- initNeighborIdx(nidx, ll_addr);
+
+ /* if the white bit is set, lets ask the router if the path through
+ this link is better than at least one known path - if so
+ lets insert this link into the table.
+ */
+ if (call LinkPacketMetadata.highChannelQuality(msg)) {
+ if (signal CompareBit.shouldInsert(msg,
+ call Packet.getPayload(msg, call Packet.payloadLength(msg)),
+ call Packet.payloadLength(msg))) {
+ nidx = findRandomNeighborIdx();
+ if (nidx != INVALID_RVAL) {
+ signal LinkEstimator.evicted(NeighborTable[nidx].ll_addr);
+ initNeighborIdx(nidx, ll_addr);
+ }
}
}
}