[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain DrainM.nc, 1.19, 1.20

Gilman Tolle gtolle at users.sourceforge.net
Fri Aug 12 13:07:19 PDT 2005


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

Modified Files:
	DrainM.nc 
Log Message:
Drain turned out to be vulnerable to the same radio stack bug as TOSBase, because it used a buffer-swapping queue. It now uses a similar copying queue to TOSBase.

Index: DrainM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainM.nc,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** DrainM.nc	28 Jul 2005 20:31:18 -0000	1.19
--- DrainM.nc	12 Aug 2005 20:07:17 -0000	1.20
***************
*** 89,100 ****
     */
    TOS_MsgPtr sendQueue[DRAIN_SEND_QUEUE_SIZE];
!   uint8_t sendQueueIn, sendQueueOut;
  
    TOS_Msg fwdBuffers[DRAIN_FWD_QUEUE_SIZE];
!   TOS_MsgPtr fwdQueue[DRAIN_FWD_QUEUE_SIZE];
!   uint8_t fwdQueueIn, fwdQueueOut;
  
-   bool sendQueueFull;
-   bool fwdQueueFull;
    bool queuesBusy;
  
--- 89,97 ----
     */
    TOS_MsgPtr sendQueue[DRAIN_SEND_QUEUE_SIZE];
!   uint8_t sendQueueIn, sendQueueOut, sendQueueCount;
  
    TOS_Msg fwdBuffers[DRAIN_FWD_QUEUE_SIZE];
!   uint8_t fwdQueueIn, fwdQueueOut, fwdQueueCount;
  
    bool queuesBusy;
  
***************
*** 116,119 ****
--- 113,117 ----
    uint16_t linkSendPackets;
    uint16_t linkAckedPackets;
+   uint16_t linkBackoffExpires;
  
    task void QueueServiceTask();
***************
*** 139,151 ****
      int n;
  
      for (n=0; n < DRAIN_FWD_QUEUE_SIZE; n++) {
        fwdQueue[n] = &fwdBuffers[n];
      }
  
!     fwdQueueIn = fwdQueueOut = 0;
!     fwdQueueFull = FALSE;
! 
!     sendQueueIn = sendQueueOut = 0;
!     sendQueueFull = FALSE;
  
      queuesBusy = FALSE;
--- 137,148 ----
      int n;
  
+ /*
      for (n=0; n < DRAIN_FWD_QUEUE_SIZE; n++) {
        fwdQueue[n] = &fwdBuffers[n];
      }
+ */
  
!     fwdQueueIn = fwdQueueOut = fwdQueueCount = 0;
!     sendQueueIn = sendQueueOut = fwdQueueCount = 0;
  
      queuesBusy = FALSE;
***************
*** 193,197 ****
      
      if (tooBig(pMsg, length) || cantSend(pMsg, length)) {
-       sendDrops++;
        return FAIL;
      }
--- 190,193 ----
***************
*** 213,217 ****
    bool cantSend(TOS_MsgPtr pMsg, uint8_t payloadLen) {
  
!     if (sendQueueFull) {
        dbg(DBG_ROUTE, "Drain: sendQueueFull(pMsg=0x%x,len=%d)\n",
  	  pMsg, payloadLen);
--- 209,214 ----
    bool cantSend(TOS_MsgPtr pMsg, uint8_t payloadLen) {
  
!     if (sendQueueCount >= DRAIN_SEND_QUEUE_SIZE) {
!       sendDrops++;
        dbg(DBG_ROUTE, "Drain: sendQueueFull(pMsg=0x%x,len=%d)\n",
  	  pMsg, payloadLen);
***************
*** 239,247 ****
  
      sendQueue[sendQueueIn] = pMsg;
!     sendQueueIn = (sendQueueIn + 1) % DRAIN_SEND_QUEUE_SIZE;
!     if (sendQueueIn == sendQueueOut)
!       sendQueueFull = TRUE;
      return SUCCESS;
- 
    }
  
--- 236,243 ----
  
      sendQueue[sendQueueIn] = pMsg;
!     sendQueueCount++;
!     if (++sendQueueIn >= DRAIN_SEND_QUEUE_SIZE) 
!       sendQueueIn = 0;
      return SUCCESS;
    }
  
***************
*** 286,290 ****
  	
  	// Enqueue it for forwarding if necessary.
! 	if (!fwdQueueFull) {
  	  dbg(DBG_ROUTE, "Drain: netForward(pMsg=0x%x,src=0x%02x,dst=0x%02x)\n", 
  	      pMsg, drainMsg->source, drainMsg->dest);
--- 282,286 ----
  	
  	// Enqueue it for forwarding if necessary.
! 	if (fwdQueueCount < DRAIN_FWD_QUEUE_SIZE) {
  	  dbg(DBG_ROUTE, "Drain: netForward(pMsg=0x%x,src=0x%02x,dst=0x%02x)\n", 
  	      pMsg, drainMsg->source, drainMsg->dest);
***************
*** 317,325 ****
  #endif
  
!     pNewBuf = fwdQueue[fwdQueueIn];
!     fwdQueue[fwdQueueIn] = pMsg;
!     fwdQueueIn = (fwdQueueIn + 1) % DRAIN_FWD_QUEUE_SIZE;
!     if (fwdQueueIn == fwdQueueOut)
!       fwdQueueFull = TRUE;
      
      return pNewBuf;
--- 313,320 ----
  #endif
  
!     memcpy(&fwdBuffers[fwdQueueIn], pMsg, sizeof(TOS_Msg));
!     fwdQueueCount++;
!     if (++fwdQueueIn >= DRAIN_FWD_QUEUE_SIZE) 
!       fwdQueueIn = 0;
      
      return pNewBuf;
***************
*** 335,340 ****
  
      // First check send queue. 
!     if (sendQueueIn != sendQueueOut || 
! 	(sendQueueIn == sendQueueOut && sendQueueFull == TRUE)) {
  
  #if DRAIN_DEBUG_DETAILED
--- 330,334 ----
  
      // First check send queue. 
!     if (sendQueueCount > 0) {
  
  #if DRAIN_DEBUG_DETAILED
***************
*** 345,350 ****
        pMsg = sendQueue[sendQueueOut];
  
!     } else if (fwdQueueIn != fwdQueueOut || 
! 	       (fwdQueueIn == fwdQueueOut && fwdQueueFull == TRUE)) {
  
  #if DRAIN_DEBUG_DETAILED
--- 339,343 ----
        pMsg = sendQueue[sendQueueOut];
  
!     } else if (fwdQueueCount > 0) {
  
  #if DRAIN_DEBUG_DETAILED
***************
*** 353,357 ****
  
        // We've got a message in the forward queue.
!       pMsg = fwdQueue[fwdQueueOut];
  
      } else {
--- 346,350 ----
  
        // We've got a message in the forward queue.
!       pMsg = &fwdBuffers[fwdQueueOut];
  
      } else {
***************
*** 380,387 ****
        dbg(DBG_ROUTE, "Drain: LinkSendMsg failed\n");
  #endif
!       //#ifndef PLATFORM_PC
!       //      post QueueServiceTask();
!       //#endif
!       call Timer.start(TIMER_ONE_SHOT, 50);
      }      
    }
--- 373,377 ----
        dbg(DBG_ROUTE, "Drain: LinkSendMsg failed\n");
  #endif
!       call Timer.start(TIMER_ONE_SHOT, 10);
      }      
    }
***************
*** 403,407 ****
  
      if (pMsg != sendQueue[sendQueueOut] && 
! 	pMsg != fwdQueue[fwdQueueOut]) {
        // THIS IS A BUG, IF IT HAPPENS.
        return SUCCESS;
--- 393,397 ----
  
      if (pMsg != sendQueue[sendQueueOut] && 
! 	pMsg != &fwdBuffers[fwdQueueOut]) {
        // THIS IS A BUG, IF IT HAPPENS.
        return SUCCESS;
***************
*** 446,449 ****
--- 436,441 ----
  	} else {
  	  // We seem to have hit max backoff.
+ 	  linkBackoffExpires++;
+ 	  forwardResultVal = FAIL;
  	}
        } 
***************
*** 463,482 ****
      if (pMsg == sendQueue[sendQueueOut]) {
  
!       sendPackets++;
  
        signal SendMsg.sendDone[mhMsg->type](pMsg, forwardResultVal);
  
!       sendQueueOut = (sendQueueOut + 1) % DRAIN_SEND_QUEUE_SIZE;
!       if (sendQueueFull)
! 	sendQueueFull = FALSE;
        post QueueServiceTask();
  
!     } else if (pMsg == fwdQueue[fwdQueueOut]) {
  
!       forwardPackets++;
  
-       fwdQueueOut = (fwdQueueOut + 1) % DRAIN_FWD_QUEUE_SIZE;
-       if (fwdQueueFull)
- 	fwdQueueFull = FALSE;
        post QueueServiceTask();
  
--- 455,480 ----
      if (pMsg == sendQueue[sendQueueOut]) {
  
!       if (forwardResultVal == SUCCESS) {
! 	sendPackets++;
!       }
  
        signal SendMsg.sendDone[mhMsg->type](pMsg, forwardResultVal);
  
!       sendQueueCount--;
!       if (++sendQueueOut >= DRAIN_SEND_QUEUE_SIZE)
! 	sendQueueOut = 0;
! 
        post QueueServiceTask();
  
!     } else if (pMsg == &fwdBuffers[fwdQueueOut]) {
  
!       if (forwardResultVal == SUCCESS) {
! 	forwardPackets++;
!       }
! 
!       fwdQueueCount--;
!       if (++fwdQueueOut >= DRAIN_FWD_QUEUE_SIZE)
! 	fwdQueueOut = 0;
  
        post QueueServiceTask();
  



More information about the Tinyos-beta-commits mailing list