[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain Drain.h, 1.5, 1.6 DrainC.nc, 1.4, 1.5 DrainLinkEstM.nc, 1.5, 1.6 DrainM.nc, 1.4, 1.5

Gilman Tolle gtolle at users.sourceforge.net
Mon Mar 14 17:19:17 PST 2005


Update of /cvsroot/tinyos/tinyos-1.x/beta/Drain
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12804

Modified Files:
	Drain.h DrainC.nc DrainLinkEstM.nc DrainM.nc 
Log Message:
- Added some retry logic to the Drain registration procedure to enable
routing messages from the base station to an individual node. This
doesn't guarantee that every node will find a home in the tree and
become routable, but increases the probability that they will do so.

- Increased the number of children per hop to 8, again to make it more
likely that every node will find a place.

This is probably as far as the basic reverse-routing system will go
for now. There are some great problems in this space, and this is just
a quick-n-dirty solution.

Also, changed the Drain tools to their own package, so they can be
referenced by the Nucleus tools and others.

The Java side of the Drain reverse-routing system still needs to be
determined. Here's the problem: one Java class has to store the child
state and dispatch messages, and other Java classes in other JVMs
should be able to use it. This suggests a software interconnection
architecture that's more flexible than TCP to the JVM and then
intra-JVM for the rest.



Index: Drain.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/Drain.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Drain.h	4 Mar 2005 23:54:44 -0000	1.5
--- Drain.h	15 Mar 2005 01:19:13 -0000	1.6
***************
*** 53,57 ****
    DRAIN_MAX_TTL = 16,
    DRAIN_INVALID_DEST = 0,
!   DRAIN_MAX_CHILDREN = 4,
    DRAIN_DIRECTION_UP = 0,
    DRAIN_DIRECTION_DOWN = 1,
--- 53,57 ----
    DRAIN_MAX_TTL = 16,
    DRAIN_INVALID_DEST = 0,
!   DRAIN_MAX_CHILDREN = 8,
    DRAIN_DIRECTION_UP = 0,
    DRAIN_DIRECTION_DOWN = 1,

Index: DrainC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainC.nc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** DrainC.nc	4 Mar 2005 03:13:56 -0000	1.4
--- DrainC.nc	15 Mar 2005 01:19:13 -0000	1.5
***************
*** 48,52 ****
  
    DrainLinkEstM.Timer -> TimerC.Timer[unique("Timer")];
-   //  DrainLinkEstM.AgingTimer -> TimerC.Timer[unique("Timer")];  
  
    DrainLinkEstM.Random -> RandomLFSR;
--- 48,51 ----

Index: DrainLinkEstM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainLinkEstM.nc,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** DrainLinkEstM.nc	4 Mar 2005 23:54:44 -0000	1.5
--- DrainLinkEstM.nc	15 Mar 2005 01:19:13 -0000	1.6
***************
*** 44,53 ****
      interface AttrList<uint16_t> as DrainChildren @nucleusAttr();
      interface Attr<uint8_t> as DrainChildrenCount @nucleusAttr();
!     interface Attr<uint16_t> as DrainMyAddr @nucleusAttr();
    }
  
    uses {
      interface Timer;
-     //    interface Timer as AgingTimer;
  
      interface Random;
--- 44,52 ----
      interface AttrList<uint16_t> as DrainChildren @nucleusAttr();
      interface Attr<uint8_t> as DrainChildrenCount @nucleusAttr();
!     interface Attr<uint16_t> as DrainToAddr @nucleusAttr();
    }
  
    uses {
      interface Timer;
  
      interface Random;
***************
*** 67,74 ****
    DrainRouteEntry routes[DRAIN_MAX_ROUTES];
  
!   uint16_t myAddr;
    uint16_t children[DRAIN_MAX_CHILDREN];
    uint8_t  childrenToNotify;
!   uint8_t  myAddrLength;
  
    bool msgBufBusy;
--- 66,81 ----
    DrainRouteEntry routes[DRAIN_MAX_ROUTES];
  
!   uint16_t toAddr;
    uint16_t children[DRAIN_MAX_CHILDREN];
    uint8_t  childrenToNotify;
!   uint8_t  toAddrLength;
! 
!   uint16_t unwantedChild;
! 
!   // STATISTICS
! 
!   uint8_t  regAttempts;
!   uint8_t  timerFires;
!   uint8_t  regFires;
  
    bool msgBufBusy;
***************
*** 142,146 ****
    void clearChildren() {
      uint8_t i;
!     myAddr = 0;
      for(i = 0; i < DRAIN_MAX_CHILDREN; i++) {
        children[i] = 0;
--- 149,156 ----
    void clearChildren() {
      uint8_t i;
!     toAddr = 0;
!     timerFires = 0;
!     regFires = 0;
!     regAttempts = 0;
      for(i = 0; i < DRAIN_MAX_CHILDREN; i++) {
        children[i] = 0;
***************
*** 183,186 ****
--- 193,198 ----
      DrainMsg *pMHMsg = (DrainMsg *)&Msg->data[0];
  
+     Msg->addr = 0;
+ 
      pMHMsg->type = id;
      pMHMsg->dir = DRAIN_DIRECTION_UP;
***************
*** 203,206 ****
--- 215,220 ----
      DrainMsg *pMHMsg = (DrainMsg *)&Msg->data[0];
  
+     Msg->addr = 0;
+ 
      pMHMsg->ttl--;
  
***************
*** 236,240 ****
      } else {
        
!       uint8_t pos = pMHMsg->dest & 0x3; // Assumes 2 bits per hop
        uint16_t dest = children[pos];
        
--- 250,254 ----
      } else {
        
!       uint8_t pos = pMHMsg->dest & 0x7; // Assumes 3 bits per hop
        uint16_t dest = children[pos];
        
***************
*** 328,333 ****
        route->treeInstance = pRP->treeInstance;
  
-       //      route->announceMissed = 0;
- 
        clearChildren();
  
--- 342,345 ----
***************
*** 368,377 ****
    event result_t Timer.fired() {
      DrainRouteEntry *route = &routes[0];
      
      if (route->sentRoute == FALSE) {
        route->sentRoute = TRUE;
        post SendRouteTask();
!       call Timer.start(TIMER_ONE_SHOT, 1024 * 2 * route->announceDelay);
      } else {
  #ifdef PLATFORM_PC
        if (TOS_LOCAL_ADDRESS != 0)
--- 380,392 ----
    event result_t Timer.fired() {
      DrainRouteEntry *route = &routes[0];
+ 
+     timerFires++;
      
      if (route->sentRoute == FALSE) {
        route->sentRoute = TRUE;
        post SendRouteTask();
!       call Timer.start(TIMER_REPEAT, 1024 * 2 * route->announceDelay);
      } else {
+       regFires++;
  #ifdef PLATFORM_PC
        if (TOS_LOCAL_ADDRESS != 0)
***************
*** 424,430 ****
  #ifndef PLATFORM_PC
        post SendRouteTask();
- #else
-       atomic msgBufBusy = FALSE;
  #endif
      }
    }
--- 439,444 ----
  #ifndef PLATFORM_PC
        post SendRouteTask();
  #endif
+       atomic msgBufBusy = FALSE;
      }
    }
***************
*** 440,444 ****
      if (msgBufBusy) {
  #ifndef PLATFORM_PC
!       post SendRouteTask();
  #endif
        return;
--- 454,458 ----
      if (msgBufBusy) {
  #ifndef PLATFORM_PC
!       post SendRegisterTask();
  #endif
        return;
***************
*** 452,464 ****
  
      if (call SendRegisterMsg.send(route->nextHop, sizeof(DrainRegisterMsg), pMsgBuf)) {
        dbg(DBG_ROUTE,"to %d, send DrainRegisterMsg(linkSource=%d,destAddr=%d,op=%d)\n",
  	  route->nextHop, pRM->linkSource, pRM->destAddr, pRM->op);
      } else {
        dbg(DBG_ROUTE, "send DrainRegisterMsg FAILED\n");
  #ifndef PLATFORM_PC
        post SendRegisterTask();
- #else
-       atomic msgBufBusy = FALSE;
  #endif
      }
    }
--- 466,481 ----
  
      if (call SendRegisterMsg.send(route->nextHop, sizeof(DrainRegisterMsg), pMsgBuf)) {
+ 
        dbg(DBG_ROUTE,"to %d, send DrainRegisterMsg(linkSource=%d,destAddr=%d,op=%d)\n",
  	  route->nextHop, pRM->linkSource, pRM->destAddr, pRM->op);
+       
+       regAttempts++;
+ 
      } else {
        dbg(DBG_ROUTE, "send DrainRegisterMsg FAILED\n");
  #ifndef PLATFORM_PC
        post SendRegisterTask();
  #endif
+       atomic msgBufBusy = FALSE;
      }
    }
***************
*** 476,480 ****
  
        for(i = 1; i < DRAIN_MAX_CHILDREN; i++) {
! 	if (children[i] == DRAIN_INVALID_DEST) {
  	  children[i] = pRM->linkSource;
  	  childrenToNotify = BIT_SET(childrenToNotify, i);
--- 493,498 ----
  
        for(i = 1; i < DRAIN_MAX_CHILDREN; i++) {
! 	if (children[i] == DRAIN_INVALID_DEST || 
! 	    children[i] == pRM->linkSource) {
  	  children[i] = pRM->linkSource;
  	  childrenToNotify = BIT_SET(childrenToNotify, i);
***************
*** 484,495 ****
  	}
        }
  
      } else if (pRM->op == DRAIN_REGISTER_OP_JOINED) {
        if (pRM->linkSource == route->nextHop) {
! 	myAddr = pRM->destAddr;
! 	myAddrLength = pRM->addrLength;
        }
-     }
  
      post NotifyChildrenTask();
  
--- 502,526 ----
  	}
        }
+       
+       // we're full. inform the child.
+ 
+       unwantedChild = pRM->linkSource;
  
      } else if (pRM->op == DRAIN_REGISTER_OP_JOINED) {
+ 
        if (pRM->linkSource == route->nextHop) {
! 	call Timer.stop();
! 	toAddr = pRM->destAddr;
! 	toAddrLength = pRM->addrLength;
        }
  
+     } else if (pRM->op == DRAIN_REGISTER_OP_FULL) {
+ 
+       if (pRM->linkSource == route->nextHop) {
+ 	call Timer.stop();
+       }      
+ 
+     }
+     
      post NotifyChildrenTask();
  
***************
*** 502,513 ****
      DrainRegisterMsg *pRM = (DrainRegisterMsg *)&pMsgBuf->data[0];
      uint8_t i;
  
      dbg(DBG_ROUTE,"DrainLinkEstM: Sending Registration Msg\n");
      
!     if (myAddr == 0) {
        return;
      }
! 
!     if (childrenToNotify == 0) {
        return;
      }
--- 533,545 ----
      DrainRegisterMsg *pRM = (DrainRegisterMsg *)&pMsgBuf->data[0];
      uint8_t i;
+     result_t result = FAIL;
  
      dbg(DBG_ROUTE,"DrainLinkEstM: Sending Registration Msg\n");
      
!     if (toAddr == DRAIN_INVALID_DEST) {
        return;
      }
!     
!     if (unwantedChild == DRAIN_INVALID_DEST && childrenToNotify == 0) {
        return;
      }
***************
*** 522,558 ****
      atomic msgBufBusy = TRUE;
  
!     for(i = 0; i < DRAIN_MAX_CHILDREN; i++) {
! 
!       if (BIT_GET(childrenToNotify, i)) {
  
  	pRM->linkSource = TOS_LOCAL_ADDRESS;
! 	//assumes 2 bits per hop
! 	pRM->destAddr = (i << myAddrLength) + myAddr;
! 	pRM->op = DRAIN_REGISTER_OP_JOINED;
  
! 	if (call SendRegisterMsg.send(children[i], 
! 				      sizeof(DrainRegisterMsg), 
! 				      pMsgBuf)) {
! 	  
! 	  dbg(DBG_ROUTE,"to %d, send DrainRegisterMsg(linkSource=%d,destAddr=%d,op=%d)\n",
! 	      children[i], pRM->linkSource, pRM->destAddr, pRM->op);
! 	  
! 	  childrenToNotify = BIT_CLEAR(childrenToNotify, i);
! 	  break;
  	  
! 	} else {
  	  
! 	  dbg(DBG_ROUTE, "send DrainRegisterMsg FAILED\n");
  	  
! #ifndef PLATFORM_PC
! 	  post NotifyChildrenTask();
! #else
! 	  atomic msgBufBusy = FALSE;
! #endif
  	}
        }
      }
! 
!     return;
    }
  
--- 554,603 ----
      atomic msgBufBusy = TRUE;
  
!     if (unwantedChild) {
  
  	pRM->linkSource = TOS_LOCAL_ADDRESS;
! 	pRM->op = DRAIN_REGISTER_OP_FULL;
! 	
! 	result = call SendRegisterMsg.send(unwantedChild, 
! 					   sizeof(DrainRegisterMsg), 
! 					   pMsgBuf);
! 	if (result == SUCCESS) {
! 	  unwantedChild = DRAIN_INVALID_DEST;
! 	}
! 	
!     } else {
  
!       for(i = 0; i < DRAIN_MAX_CHILDREN; i++) {
! 	
! 	if (BIT_GET(childrenToNotify, i)) {
  	  
! 	  pRM->linkSource = TOS_LOCAL_ADDRESS;
! 	  pRM->destAddr = (i << toAddrLength) + toAddr;
! 	  pRM->op = DRAIN_REGISTER_OP_JOINED;
  	  
! 	  result = call SendRegisterMsg.send(children[i], 
! 					     sizeof(DrainRegisterMsg), 
! 					     pMsgBuf);
  	  
! 	  if (result == SUCCESS) {
! 	    dbg(DBG_ROUTE,"to %d, send DrainRegisterMsg(linkSource=%d,destAddr=%d,op=%d)\n",
! 		children[i], pRM->linkSource, pRM->destAddr, pRM->op);
! 	    
! 	    childrenToNotify = BIT_CLEAR(childrenToNotify, i);
! 	    break;
! 	  }
  	}
        }
      }
!     
!     if (result == FAIL) {
! 	    
!       dbg(DBG_ROUTE, "send DrainRegisterMsg FAILED\n");
!       
! #ifndef PLATFORM_PC
!       post NotifyChildrenTask();
! #endif
!       atomic msgBufBusy = FALSE;
!     }
    }
  
***************
*** 586,589 ****
--- 631,635 ----
    }
  
+ 
    command result_t DrainNextHop.get(uint16_t* buf) {
      memcpy(buf, &routes[0].nextHop, sizeof(uint16_t));
***************
*** 622,628 ****
    }
  
!   command result_t DrainMyAddr.get(uint16_t* buf) {
!     memcpy(buf, &myAddr, sizeof(uint16_t));
!     signal DrainMyAddr.getDone(buf);
      return SUCCESS;
    }
--- 668,674 ----
    }
  
!   command result_t DrainToAddr.get(uint16_t* buf) {
!     memcpy(buf, &toAddr, sizeof(uint16_t));
!     signal DrainToAddr.getDone(buf);
      return SUCCESS;
    }

Index: DrainM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainM.nc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** DrainM.nc	4 Mar 2005 03:13:56 -0000	1.4
--- DrainM.nc	15 Mar 2005 01:19:13 -0000	1.5
***************
*** 83,86 ****
--- 83,87 ----
    uint8_t backoff;
  
+ 
    // STATISTICS
  
***************
*** 94,97 ****
--- 95,99 ----
    uint8_t forwardDrops;
  
+ 
    task void QueueServiceTask();
  
***************
*** 300,335 ****
        pMsg = sendQueue[sendQueueOut];
  
-       call DrainLinkEst.selectRoute(pMsg);
- 
-       if (call LinkSendMsg.send(pMsg->addr, pMsg->length, pMsg) == SUCCESS) {
- 	// Wait for the sendDone.
-       } else {
- 	// The radio didn't accept our message.
- 	post QueueServiceTask();
-       }
- 
-     // Then check forward queue. 
      } else if (fwdQueueIn != fwdQueueOut || 
  	       (fwdQueueIn == fwdQueueOut && fwdQueueFull == TRUE)) {
  
        dbg(DBG_ROUTE, "Drain: queueServiceTask(servicing=forwardQueue)\n");
! 
        // We've got a message in the forward queue.
        pMsg = fwdQueue[fwdQueueOut];
  
-       call DrainLinkEst.selectRoute(pMsg);
- 
-       if (call LinkSendMsg.send(pMsg->addr, pMsg->length, pMsg) == SUCCESS) {
- 	// Wait for the sendDone.
-       } else {
- 	// The radio didn't accept our message.
- 	post QueueServiceTask();
-       }      
- 
      } else {
        dbg(DBG_ROUTE, "Drain: queueServiceTask(queuesAllEmpty)\n");
        queuesBusy = FALSE;
        return;
      }
    }
  
--- 302,328 ----
        pMsg = sendQueue[sendQueueOut];
  
      } else if (fwdQueueIn != fwdQueueOut || 
  	       (fwdQueueIn == fwdQueueOut && fwdQueueFull == TRUE)) {
  
        dbg(DBG_ROUTE, "Drain: queueServiceTask(servicing=forwardQueue)\n");
!     
        // We've got a message in the forward queue.
        pMsg = fwdQueue[fwdQueueOut];
  
      } else {
+ 
        dbg(DBG_ROUTE, "Drain: queueServiceTask(queuesAllEmpty)\n");
        queuesBusy = FALSE;
        return;
      }
+     
+     call DrainLinkEst.selectRoute(pMsg);
+     
+     if (call LinkSendMsg.send(pMsg->addr, pMsg->length, pMsg) == SUCCESS) {
+       // Wait for the sendDone.
+     } else {
+       // The radio didn't accept our message.
+       post QueueServiceTask();
+     }      
    }
  
***************
*** 380,406 ****
  
        // It did have a destination. Consider retransmitting.
-       
-       if (pMsg->ack == 0) {
  
! 	// It wasn't acked.
  	call DrainLinkEst.messageSent(pMsg, pMsg->type, FAIL);
  
  	if (backoff < DRAIN_MAX_BACKOFF) {
  	  backoff++;
  	}
- 
- 	call Timer.start(TIMER_ONE_SHOT, 1 << backoff);
- 
- 	return SUCCESS;
  	
        } else {
  	
  	// It was acked.
- 
- 	backoff = 0;
- 
  	call DrainLinkEst.messageSent(pMsg, pMsg->type, SUCCESS);
        }
      }
      
      dbg(DBG_ROUTE, "Drain: sendComplete(pMsg=0x%x,result=%d)\n", 
--- 373,396 ----
  
        // It did have a destination. Consider retransmitting.
  
!       if (pMsg->ack == 0) {
! 	
! 	// It wasn't acked. Try again, up to DRAIN_MAX_BACKOFF
  	call DrainLinkEst.messageSent(pMsg, pMsg->type, FAIL);
  
  	if (backoff < DRAIN_MAX_BACKOFF) {
  	  backoff++;
+ 	  call Timer.start(TIMER_ONE_SHOT, 1 << backoff);
+ 	  return SUCCESS;
  	}
  	
        } else {
  	
  	// It was acked.
  	call DrainLinkEst.messageSent(pMsg, pMsg->type, SUCCESS);
        }
      }
+ 
+     backoff = 0;
      
      dbg(DBG_ROUTE, "Drain: sendComplete(pMsg=0x%x,result=%d)\n", 



More information about the Tinyos-beta-commits mailing list