[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain Drain.h, 1.11,
1.12 DrainLinkEst.nc, 1.3, 1.4 DrainLinkEstM.nc, 1.18,
1.19 DrainM.nc, 1.16, 1.17
Gilman Tolle
gtolle at users.sourceforge.net
Fri Jul 15 15:40:15 PDT 2005
Update of /cvsroot/tinyos/tinyos-1.x/beta/Drain
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21920
Modified Files:
Drain.h DrainLinkEst.nc DrainLinkEstM.nc DrainM.nc
Log Message:
Added a next-hop packet success rate tracker that resets to 0 whenever
the next-hop changes. 256 is 100%, 0 is 0%. This is very useful for
correlating the link cost estimate with the actual link quality.
Added a counter for the number of times the parent changes after the
initial tree is built.
Put the sequence number "inside" of the tree instance, so it resets
whenever the tree is rebuilt from scratch.
Improved the handling of the routing table, so that new non-default
entries don't replace the default route, while new default entries do.
Index: Drain.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/Drain.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** Drain.h 5 Jul 2005 21:10:21 -0000 1.11
--- Drain.h 15 Jul 2005 22:40:12 -0000 1.12
***************
*** 45,49 ****
enum drainConsts {
! DRAIN_QUEUE_SIZE = 3,
DRAIN_MAX_RETRANSMITS = 0, // does nothing, for now.
DRAIN_MAX_MISSED_BEACONS = 5,
--- 45,50 ----
enum drainConsts {
! DRAIN_SEND_QUEUE_SIZE = 3,
! DRAIN_FWD_QUEUE_SIZE = 6,
DRAIN_MAX_RETRANSMITS = 0, // does nothing, for now.
DRAIN_MAX_MISSED_BEACONS = 5,
***************
*** 53,56 ****
--- 54,58 ----
DRAIN_MAX_TTL = 16,
DRAIN_INVALID_DEST = 0,
+ DRAIN_INVALID_SLOT = 0xFF,
DRAIN_MAX_CHILDREN = 8,
};
***************
*** 105,110 ****
uint16_t announceOffset;
uint16_t announceCountdown;
! bool sentRoute:1;
bool defaultRoute:1;
} DrainRouteEntry;
--- 107,119 ----
uint16_t announceOffset;
uint16_t announceCountdown;
! bool sendWaiting:1;
bool defaultRoute:1;
+ bool pad:6;
+
+ uint16_t sentPackets;
+ uint16_t successPackets;
+ uint16_t successRate;
+ uint8_t parentSwitches;
+
} DrainRouteEntry;
Index: DrainLinkEst.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainLinkEst.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DrainLinkEst.nc 10 Jun 2005 19:38:03 -0000 1.3
--- DrainLinkEst.nc 15 Jul 2005 22:40:12 -0000 1.4
***************
*** 72,76 ****
*/
! command result_t messageSent(TOS_MsgPtr msg, uint8_t id, result_t success);
command bool isRoot();
--- 72,76 ----
*/
! command result_t messageSent(TOS_MsgPtr msg, result_t success);
command bool isRoot();
Index: DrainLinkEstM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainLinkEstM.nc,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** DrainLinkEstM.nc 8 Jul 2005 21:04:43 -0000 1.18
--- DrainLinkEstM.nc 15 Jul 2005 22:40:12 -0000 1.19
***************
*** 40,43 ****
--- 40,45 ----
interface AttrList<uint16_t> as DrainNextHopCost @nucleusAttr("DrainNextHopCost");
interface AttrList<uint16_t> as DrainNextHopLinkEst @nucleusAttr("DrainNextHopLinkEst");
+ interface AttrList<uint16_t> as DrainNextHopSuccessRate @nucleusAttr("DrainNextHopSuccessRate");
+ interface AttrList<uint16_t> as DrainNextHopSwitches @nucleusAttr("DrainNextHopSwitches");
}
***************
*** 76,79 ****
--- 78,82 ----
void clearRoute(DrainRouteEntry* route);
DrainRouteEntry* getRoute(uint16_t dest);
+ DrainRouteEntry* getDefaultRoute(uint16_t dest);
DrainRouteEntry* getReadyRoute();
void sendRoute(DrainRouteEntry* route);
***************
*** 159,164 ****
} else {
! route = getRoute(pMHMsg->dest);
!
if (route != NULL) {
Msg->addr = route->nextHop;
--- 162,175 ----
} else {
! if (isGroup(pMHMsg->dest)) {
!
! route = getDefaultRoute(pMHMsg->dest);
!
! } else {
!
! route = getRoute(pMHMsg->dest);
!
! }
!
if (route != NULL) {
Msg->addr = route->nextHop;
***************
*** 205,209 ****
route->destDistance = 0;
! route->sentRoute = FALSE;
sendRoute(route);
--- 216,220 ----
route->destDistance = 0;
! route->sendWaiting = TRUE;
sendRoute(route);
***************
*** 218,222 ****
route = getReadyRoute();
! sendRoute(route);
startTimer();
--- 229,235 ----
route = getReadyRoute();
! if (route != NULL) {
! sendRoute(route);
! }
startTimer();
***************
*** 236,240 ****
dbg(DBG_ROUTE, "DrainLinkEstM: couldn't send route (dest=%d, destDistance=%d)\n",
route->dest, route->destDistance);
! route->sentRoute = TRUE;
return;
}
--- 249,253 ----
dbg(DBG_ROUTE, "DrainLinkEstM: couldn't send route (dest=%d, destDistance=%d)\n",
route->dest, route->destDistance);
! route->sendWaiting = FALSE;
return;
}
***************
*** 264,268 ****
pRP->beaconSeqno, pRP->beaconDelay, pRP->treeInstance);
! route->sentRoute = TRUE;
} else {
--- 277,281 ----
pRP->beaconSeqno, pRP->beaconDelay, pRP->treeInstance);
! route->sendWaiting = FALSE;
} else {
***************
*** 276,282 ****
DrainBeaconMsg *pRP = (DrainBeaconMsg *)&Msg->data[0];
! DrainRouteEntry *route = getRoute(pRP->source);
uint16_t linkEst = 0;
uint32_t curCost, newCost;
#if defined(_CC2420CONST_H)
--- 289,296 ----
DrainBeaconMsg *pRP = (DrainBeaconMsg *)&Msg->data[0];
! DrainRouteEntry *route;
uint16_t linkEst = 0;
uint32_t curCost, newCost;
+ bool retransmit = FALSE;
#if defined(_CC2420CONST_H)
***************
*** 293,329 ****
#endif
- if (route == NULL) {
- route = newRoute(pRP->source, pRP->defaultRoute);
- }
-
dbg(DBG_ROUTE,"DrainLinkEstM: receive DrainBeaconMsg(linkSource=%d,source=%d,parent=%d,cost=%d,ttl=%d,seqno=%d,delay=%d,instance=%d,linkEst=%d)\n",
pRP->linkSource, pRP->source, pRP->parent, pRP->cost, pRP->ttl,
pRP->beaconSeqno, pRP->beaconDelay, pRP->treeInstance, linkEst);
/*** Retransmission stuff (check for new, set the retransmit timer) ***/
! if (route->dest != TOS_LOCAL_ADDRESS &&
! ((int8_t)(pRP->beaconSeqno - route->announceSeqno) > 0
! || pRP->beaconSeqno == 0)) {
!
if (pRP->beaconSeqno == 0) {
!
! route->announceSeqno++;
! if (route->announceSeqno == 0)
! route->announceSeqno++;
!
} else {
route->announceSeqno = pRP->beaconSeqno;
}
! route->announceDelay = pRP->beaconDelay;
! route->announceOffset =
! (call Random.rand() %
! (1024 * route->announceDelay)) + 1;
! route->sentRoute = FALSE;
! route->announceCountdown = pRP->beaconOffset + route->announceOffset;
! startTimer();
}
--- 307,369 ----
#endif
dbg(DBG_ROUTE,"DrainLinkEstM: receive DrainBeaconMsg(linkSource=%d,source=%d,parent=%d,cost=%d,ttl=%d,seqno=%d,delay=%d,instance=%d,linkEst=%d)\n",
pRP->linkSource, pRP->source, pRP->parent, pRP->cost, pRP->ttl,
pRP->beaconSeqno, pRP->beaconDelay, pRP->treeInstance, linkEst);
+ if (pRP->source == TOS_LOCAL_ADDRESS) {
+ return Msg;
+ }
+
+ route = getRoute(pRP->source);
+
+ if (route == NULL) {
+ route = newRoute(pRP->source, pRP->defaultRoute);
+ if (route == NULL) {
+ dbg(DBG_ROUTE, "DrainLinkEstM: no slot for new route to dest=%d\n", pRP->source);
+ return Msg;
+ }
+ dbg(DBG_ROUTE, "DrainLinkEstM: new route 0x%x to dest=%d\n", route, route->dest);
+ }
+
/*** Retransmission stuff (check for new, set the retransmit timer) ***/
! // If it's a new tree instance, discard the old sequence numbering
! // Always retransmit
! if (pRP->treeInstance != route->treeInstance) {
!
if (pRP->beaconSeqno == 0) {
!
! // reset the sequence number to 1
! route->announceSeqno = 1;
!
} else {
+
+ // always take the sequence number
route->announceSeqno = pRP->beaconSeqno;
}
! retransmit = TRUE;
! } else {
! // If it's a refinement of my current tree instance, only
! // retransmit if it has a newer sequence number
! // If it wants me to bump my sequence number, do it.
! if (pRP->beaconSeqno == 0) {
!
! // increment the sequence number
! route->announceSeqno++;
! if (route->announceSeqno == 0)
! route->announceSeqno++;
!
! retransmit = TRUE;
!
! } else if ((int8_t)(pRP->beaconSeqno - route->announceSeqno) > 0) {
!
! // if it's newer, take the sequence number
! route->announceSeqno = pRP->beaconSeqno;
!
! retransmit = TRUE;
! }
}
***************
*** 342,349 ****
newCost < curCost )) {
dbg(DBG_ROUTE, "DrainLinkEstM: route update(dest=%d, treeInstance=%d, oldNextHop=%d, nextHop=%d, oldCost=%d, newCost=%d, distance=%d)\n",
pRP->source, pRP->treeInstance, route->nextHop, pRP->linkSource,
curCost, newCost, DRAIN_MAX_TTL - pRP->ttl);
!
route->dest = pRP->source;
route->destDistance = DRAIN_MAX_TTL - pRP->ttl;
--- 382,402 ----
newCost < curCost )) {
+ if (pRP->treeInstance != route->treeInstance) {
+ route->parentSwitches = 0;
+ } else {
+ if (route->nextHop != pRP->linkSource) {
+ route->parentSwitches++;
+ }
+ }
+
dbg(DBG_ROUTE, "DrainLinkEstM: route update(dest=%d, treeInstance=%d, oldNextHop=%d, nextHop=%d, oldCost=%d, newCost=%d, distance=%d)\n",
pRP->source, pRP->treeInstance, route->nextHop, pRP->linkSource,
curCost, newCost, DRAIN_MAX_TTL - pRP->ttl);
!
! if (route->nextHop != pRP->linkSource) {
! route->sentPackets = 0;
! route->successPackets = 0;
! }
!
route->dest = pRP->source;
route->destDistance = DRAIN_MAX_TTL - pRP->ttl;
***************
*** 356,359 ****
--- 409,426 ----
}
+ if (retransmit) {
+ dbg(DBG_ROUTE, "DrainLinkEstM: Preparing to retransmit beacon:dest=%d,instance=%d,seqno=%d\n", route->dest, route->treeInstance, route->announceSeqno);
+
+ route->announceDelay = pRP->beaconDelay;
+ route->announceOffset =
+ (call Random.rand() %
+ (1024 * route->announceDelay)) + 1;
+
+ route->sendWaiting = TRUE;
+ route->announceCountdown = pRP->beaconOffset + route->announceOffset;
+
+ startTimer();
+ }
+
return Msg;
}
***************
*** 362,370 ****
uint16_t result = (80 - (val - 50));
result = (((result * result) >> 3) * result) >> 3;
! return result;
}
! command result_t DrainLinkEst.messageSent(TOS_MsgPtr msg, uint8_t id,
result_t success) {
return SUCCESS;
}
--- 429,450 ----
uint16_t result = (80 - (val - 50));
result = (((result * result) >> 3) * result) >> 3;
!
! /* experimenting with alternate scalings for LQI */
! // uint16_t result = 110 - val;
! // result = result * result;
!
! return result;
}
! command result_t DrainLinkEst.messageSent(TOS_MsgPtr msg,
result_t success) {
+
+ DrainMsg* drainMsg = (DrainMsg*) &msg->data[0];
+ DrainRouteEntry* route = getRoute(drainMsg->dest);
+
+ route->sentPackets++;
+ if (success) {
+ route->successPackets++;
+ }
return SUCCESS;
}
***************
*** 396,406 ****
DrainRouteEntry* newRoute(uint16_t dest, bool defaultRoute) {
DrainRouteEntry* route;
!
if (defaultRoute) {
! route = &routes[0];
! } else {
! route = &routes[1];
}
clearRoute(route);
route->dest = dest;
--- 476,522 ----
DrainRouteEntry* newRoute(uint16_t dest, bool defaultRoute) {
DrainRouteEntry* route;
! uint8_t i;
! uint8_t slot = DRAIN_INVALID_SLOT;
!
if (defaultRoute) {
! for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
! route = &routes[i];
! if (route->dest != DRAIN_INVALID_DEST &&
! route->defaultRoute == TRUE) {
! slot = i;
! break;
! }
! }
}
+ if (slot == DRAIN_INVALID_SLOT) {
+ for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
+ route = &routes[i];
+ if (route->dest == DRAIN_INVALID_DEST) {
+ slot = i;
+ break;
+ }
+ }
+ }
+
+ if (slot == DRAIN_INVALID_SLOT) {
+ for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
+ route = &routes[i];
+ if (route->dest != DRAIN_INVALID_DEST &&
+ route->defaultRoute == FALSE) {
+ slot = i;
+ break;
+ }
+ }
+ }
+
+ if (slot == DRAIN_INVALID_SLOT) {
+ return NULL;
+ }
+
+ dbg(DBG_ROUTE, "DrainLinkEstM: new route in slot %d 0x%x\n", slot, &routes[slot]);
+
+ route = &routes[slot];
+
clearRoute(route);
route->dest = dest;
***************
*** 413,423 ****
uint8_t i;
! if (routes[0].dest != DRAIN_INVALID_DEST && isGroup(dest)) {
! return &routes[0];
}
for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
route = &routes[i];
! if (route->dest != DRAIN_INVALID_DEST && route->dest == dest) {
return route;
}
--- 529,549 ----
uint8_t i;
! for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
! route = &routes[i];
! if (route->dest != DRAIN_INVALID_DEST && route->dest == dest) {
! return route;
! }
}
+ return NULL;
+ }
+
+ DrainRouteEntry* getDefaultRoute(uint16_t dest) {
+ DrainRouteEntry* route;
+ uint8_t i;
for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
route = &routes[i];
! if (route->dest != DRAIN_INVALID_DEST &&
! route->defaultRoute == TRUE) {
return route;
}
***************
*** 433,437 ****
route = &routes[i];
if (route->dest != DRAIN_INVALID_DEST &&
! route->sentRoute == FALSE &&
route->announceCountdown == 0) {
return route;
--- 559,563 ----
route = &routes[i];
if (route->dest != DRAIN_INVALID_DEST &&
! route->sendWaiting == TRUE &&
route->announceCountdown == 0) {
return route;
***************
*** 456,461 ****
for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
route = &routes[i];
if (route->dest != DRAIN_INVALID_DEST &&
! route->sentRoute == FALSE) {
dbg(DBG_ROUTE, "route[%d] fires in %d ms\n", i, route->announceCountdown);
if (route->announceCountdown < minCountdown) {
--- 582,591 ----
for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
route = &routes[i];
+
+ dbg(DBG_ROUTE, "route[%d] 0x%x - dest=%d, sendWaiting=%d\n", i, route, route->dest, route->sendWaiting);
+
if (route->dest != DRAIN_INVALID_DEST &&
! route->sendWaiting == TRUE) {
!
dbg(DBG_ROUTE, "route[%d] fires in %d ms\n", i, route->announceCountdown);
if (route->announceCountdown < minCountdown) {
***************
*** 472,476 ****
route = &routes[i];
if (route->dest != DRAIN_INVALID_DEST &&
! route->sentRoute == FALSE) {
route->announceCountdown -= minCountdown;
}
--- 602,606 ----
route = &routes[i];
if (route->dest != DRAIN_INVALID_DEST &&
! route->sendWaiting == TRUE) {
route->announceCountdown -= minCountdown;
}
***************
*** 523,530 ****
command result_t DrainNextHopCost.get(uint16_t* buf, uint8_t idx) {
if (idx >= DRAIN_MAX_ROUTES) {
return FAIL;
}
! memcpy(buf, &routes[idx].nextHopCost, sizeof(uint16_t));
signal DrainNextHopCost.getDone(buf);
return SUCCESS;
--- 653,665 ----
command result_t DrainNextHopCost.get(uint16_t* buf, uint8_t idx) {
+ uint32_t curCost;
+
if (idx >= DRAIN_MAX_ROUTES) {
return FAIL;
}
! curCost = (uint16_t)((uint32_t) routes[idx].nextHopCost +
! (uint32_t) routes[idx].nextHopLinkEst);
!
! memcpy(buf, &curCost, sizeof(uint16_t));
signal DrainNextHopCost.getDone(buf);
return SUCCESS;
***************
*** 539,542 ****
--- 674,705 ----
return SUCCESS;
}
+
+ command result_t DrainNextHopSwitches.get(uint16_t* buf, uint8_t idx) {
+ if (idx >= DRAIN_MAX_ROUTES) {
+ return FAIL;
+ }
+ memcpy(buf, &routes[idx].parentSwitches, sizeof(uint16_t));
+ signal DrainNextHopSwitches.getDone(buf);
+ return SUCCESS;
+ }
+
+ command result_t DrainNextHopSuccessRate.get(uint16_t* buf, uint8_t idx) {
+ uint16_t successRate;
+ DrainRouteEntry* route;
+ if (idx >= DRAIN_MAX_ROUTES) {
+ return FAIL;
+ }
+ route = &routes[idx];
+ if (route->sentPackets == 0) {
+ successRate = 0;
+ } else {
+ successRate =
+ (((uint32_t)route->successPackets) << 8) /
+ ((uint32_t)route->sentPackets);
+ }
+ memcpy(buf, &successRate, sizeof(uint16_t));
+ signal DrainNextHopSuccessRate.getDone(buf);
+ return SUCCESS;
+ }
}
Index: DrainM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainM.nc,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** DrainM.nc 7 Jul 2005 06:10:22 -0000 1.16
--- DrainM.nc 15 Jul 2005 22:40:13 -0000 1.17
***************
*** 64,72 ****
implementation {
- enum {
- DRAIN_SEND_QUEUE_SIZE = DRAIN_QUEUE_SIZE, // Send Queue
- DRAIN_FWD_QUEUE_SIZE = DRAIN_QUEUE_SIZE, // Forwarding Queue
- };
-
/**
* Drain includes its own queueing, for both sent and forwarded messages.
--- 64,67 ----
***************
*** 98,103 ****
uint16_t unackedPackets;
! uint8_t sendDrops;
! uint8_t forwardDrops;
task void QueueServiceTask();
--- 93,98 ----
uint16_t unackedPackets;
! uint16_t sendDrops;
! uint16_t forwardDrops;
task void QueueServiceTask();
***************
*** 411,415 ****
// It wasn't acked. Try again, up to DRAIN_MAX_BACKOFF
! call DrainLinkEst.messageSent(pMsg, pMsg->type, FAIL);
if (backoff < DRAIN_MAX_BACKOFF) {
--- 406,410 ----
// It wasn't acked. Try again, up to DRAIN_MAX_BACKOFF
! call DrainLinkEst.messageSent(pMsg, FAIL);
if (backoff < DRAIN_MAX_BACKOFF) {
***************
*** 425,429 ****
{
// It was acked.
! call DrainLinkEst.messageSent(pMsg, pMsg->type, SUCCESS);
}
}
--- 420,424 ----
{
// It was acked.
! call DrainLinkEst.messageSent(pMsg, SUCCESS);
}
}
***************
*** 449,453 ****
forwardPackets++;
! fwdQueueOut = (fwdQueueOut + 1) % DRAIN_SEND_QUEUE_SIZE;
if (fwdQueueFull)
fwdQueueFull = FALSE;
--- 444,448 ----
forwardPackets++;
! fwdQueueOut = (fwdQueueOut + 1) % DRAIN_FWD_QUEUE_SIZE;
if (fwdQueueFull)
fwdQueueFull = FALSE;
More information about the Tinyos-beta-commits
mailing list