BEST_EETX = 0,
INVALID_RVAL = 0xff,
INVALID_NEIGHBOR_ADDR = 0xff,
- INFINITY = 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_EETX_VALUE = 0xff,
// decay the link estimate using this alpha
// we use a denominator of 10, so this corresponds to 0.2
- ALPHA = 2,
+ ALPHA = 9,
// number of packets to wait before computing a new
// DLQ (Data-driven Link Quality)
DLQ_PKT_WINDOW = 5,
// the packet.
uint8_t addLinkEstHeaderAndFooter(message_t *msg, uint8_t len) {
uint8_t newlen;
- linkest_header_t *hdr;
- linkest_footer_t *footer;
+ linkest_header_t * ONE hdr;
+ linkest_footer_t * ONE footer;
uint8_t i, j, k;
uint8_t maxEntries, newPrevSentIdx;
dbg("LI", "newlen1 = %d\n", len);
j = 0;
newPrevSentIdx = 0;
for (i = 0; i < NEIGHBOR_TABLE_SIZE && j < maxEntries; i++) {
+ uint8_t neighborCount;
+ neighbor_stat_entry_t * COUNT(neighborCount) neighborLists;
+ if(maxEntries <= NEIGHBOR_TABLE_SIZE)
+ neighborCount = maxEntries;
+ else
+ neighborCount = NEIGHBOR_TABLE_SIZE;
+
+ neighborLists = TCAST(neighbor_stat_entry_t * COUNT(neighborCount), footer->neighborList);
k = (prevSentIdx + i + 1) % NEIGHBOR_TABLE_SIZE;
- if (NeighborTable[k].flags & VALID_ENTRY) {
- footer->neighborList[j].ll_addr = NeighborTable[k].ll_addr;
- footer->neighborList[j].inquality = NeighborTable[k].inquality;
+ if ((NeighborTable[k].flags & VALID_ENTRY) &&
+ (NeighborTable[k].flags & MATURE_ENTRY)) {
+ neighborLists[j].ll_addr = NeighborTable[k].ll_addr;
+ neighborLists[j].inquality = NeighborTable[k].inquality;
newPrevSentIdx = k;
- dbg("LI", "Loaded on footer: %d %d %d\n", j, footer->neighborList[j].ll_addr,
- footer->neighborList[j].inquality);
+ dbg("LI", "Loaded on footer: %d %d %d\n", j, neighborLists[j].ll_addr,
+ neighborLists[j].inquality);
j++;
}
}
if (q1 > 0) {
q = 2550 / q1 - 10;
if (q > 255) {
- q = INFINITY;
+ q = VERY_LARGE_EETX_VALUE;
}
return (uint8_t)q;
} else {
- return INFINITY;
+ return VERY_LARGE_EETX_VALUE;
}
}
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, outQ=%d, outA=%d, rcv=%d, fail=%d, biQ=%d\n",
- i, ne->ll_addr, ne->inquality, ne->inage, ne->outquality, ne->outage,
- ne->rcvcnt, ne->failcnt, computeBidirEETX(ne->inquality, ne->outquality));
+ dbg("LI,LITest", "%d:%d inQ=%d, inA=%d, rcv=%d, fail=%d, Q=%d\n",
+ i, ne->ll_addr, ne->inquality, ne->inage,
+ ne->rcvcnt, ne->failcnt, computeEETX(ne->inquality));
}
}
}
}
// return bi-directional link quality to the neighbor
- command uint8_t LinkEstimator.getLinkQuality(am_addr_t neighbor) {
+ command uint16_t LinkEstimator.getLinkQuality(am_addr_t neighbor) {
uint8_t idx;
idx = findIdx(neighbor);
if (idx == INVALID_RVAL) {
- return INFINITY;
+ return VERY_LARGE_EETX_VALUE;
} else {
- return NeighborTable[idx].eetx;
- };
+ if (NeighborTable[idx].flags & MATURE_ENTRY) {
+ return NeighborTable[idx].eetx;
+ } else {
+ return VERY_LARGE_EETX_VALUE;
+ }
+ }
}
// insert the neighbor at any cost (if there is a room for it)
// 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
// called when link estimator generator packet or
// packets from upper layer that are wired to pass through
// link estimator is received
- void processReceivedMessage(message_t* msg, void* payload, uint8_t len) {
+ void processReceivedMessage(message_t* ONE msg, void* COUNT_NOK(len) payload, uint8_t len) {
uint8_t nidx;
uint8_t num_entries;
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);
+ }
}
}
}
// application payload pointer is just past the link estimation header
command void* Packet.getPayload(message_t* msg, uint8_t len) {
- linkest_header_t *hdr = getHeader(msg);
- uint8_t footerLen = (hdr->flags & NUM_ENTRIES_FLAG) * sizeof(linkest_header_t);
- void* payload = call SubPacket.getPayload(msg, len + footerLen);
+ void* payload = call SubPacket.getPayload(msg, len + sizeof(linkest_header_t));
if (payload != NULL) {
payload += sizeof(linkest_header_t);
}