[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain Drain.h, 1.9, 1.10 Drain.nc, 1.3, 1.4 DrainLinkEstM.nc, 1.16, 1.17 DrainM.nc, 1.13, 1.14

Gilman Tolle gtolle at users.sourceforge.net
Thu Jun 16 10:46:33 PDT 2005


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

Modified Files:
	Drain.h Drain.nc DrainLinkEstM.nc DrainM.nc 
Log Message:
Added support for 2 trees to Drain. When building a tree, it can be built as a default route. The default route will be used to carry messages destined for multicast groups, and whenever the TOS_DEFAULT_ADDR is used. A non-default tree will only be used for messages destined for its actual destination address. This should be enough to support the landmark+forest scheme, as long as all the roots of the forest send their tree-building messages with the same destination address.

Index: Drain.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/Drain.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** Drain.h	10 Jun 2005 19:38:03 -0000	1.9
--- Drain.h	16 Jun 2005 17:46:30 -0000	1.10
***************
*** 50,54 ****
    DRAIN_MAX_BACKOFF = 12,
    DRAIN_UNKNOWN_ACK_EST = 127,
!   DRAIN_MAX_ROUTES = 1,
    DRAIN_MAX_TTL = 16,
    DRAIN_INVALID_DEST = 0,
--- 50,54 ----
    DRAIN_MAX_BACKOFF = 12,
    DRAIN_UNKNOWN_ACK_EST = 127,
!   DRAIN_MAX_ROUTES = 2,
    DRAIN_MAX_TTL = 16,
    DRAIN_INVALID_DEST = 0,
***************
*** 85,88 ****
--- 85,90 ----
    uint8_t  treeInstance;
    uint16_t beaconOffset;
+   
+   bool     defaultRoute;
  } DrainBeaconMsg;
  
***************
*** 105,109 ****
    uint8_t  announceDelay;
    uint16_t announceOffset;
!   bool     sentRoute;
  } DrainRouteEntry;
  
--- 107,113 ----
    uint8_t  announceDelay;
    uint16_t announceOffset;
!   uint16_t announceCountdown;
!   bool     sentRoute:1;
!   bool     defaultRoute:1;
  } DrainRouteEntry;
  

Index: Drain.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/Drain.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Drain.nc	14 Jun 2005 18:16:22 -0000	1.3
--- Drain.nc	16 Jun 2005 17:46:30 -0000	1.4
***************
*** 3,6 ****
  interface Drain {
    command result_t buildTree();
!   command result_t buildTreeInstance(uint8_t instance);
  }
--- 3,7 ----
  interface Drain {
    command result_t buildTree();
!   command result_t buildTreeDefaultRoute();
!   command result_t buildTreeInstance(uint8_t instance, bool defaultRoute);
  }

Index: DrainLinkEstM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainLinkEstM.nc,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** DrainLinkEstM.nc	14 Jun 2005 18:16:22 -0000	1.16
--- DrainLinkEstM.nc	16 Jun 2005 17:46:30 -0000	1.17
***************
*** 63,67 ****
    TOS_Msg msgBuf;
  
!   uint8_t disseminateSeqno;
  
  #define MAX(a_,b_) (a_ > b_ ? a_ : b_)
--- 63,67 ----
    TOS_Msg msgBuf;
  
!   bool timerRunning;
  
  #define MAX(a_,b_) (a_ > b_ ? a_ : b_)
***************
*** 73,81 ****
    uint16_t adjustLQI(uint8_t val);
  
    void clearRoute(DrainRouteEntry* route);
    DrainRouteEntry* getRoute(uint16_t dest);
!   bool isGroup(uint16_t dest);
  
!   task void SendRouteTask();
  
    command result_t StdControl.init() {
--- 73,84 ----
    uint16_t adjustLQI(uint8_t val);
  
+   DrainRouteEntry* newRoute(uint16_t dest, bool defaultRoute);
    void clearRoute(DrainRouteEntry* route);
    DrainRouteEntry* getRoute(uint16_t dest);
!   DrainRouteEntry* getReadyRoute();
!   void sendRoute(DrainRouteEntry* route);
  
!   bool isGroup(uint16_t dest);
!   void startTimer();
  
    command result_t StdControl.init() {
***************
*** 92,140 ****
    }
  
-   void clearRoute(DrainRouteEntry* route) {
- 
-     route->dest = DRAIN_INVALID_DEST;
-     route->nextHop = TOS_BCAST_ADDR;
-     
-     route->nextHopCost = 0xFFFF;
-     route->nextHopLinkEst = 0xFFFF;
-     
-     route->destDistance = 0;
-     route->treeInstance = 0;
- 
-     route->announceSeqno = 1;
-     route->announceDelay = 0;
-   }
- 
-   DrainRouteEntry* getRoute(uint16_t dest) {
-     DrainRouteEntry* route;
-     uint8_t i;
- 
-     if (isGroup(dest)) {
-       return &routes[0];
-     }
- 
-     for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
-       route = &routes[i];
-       if (route->dest != 0 && route->dest == dest) {
- 	return route;
-       }
-     }
-     return NULL;
-   }
- 
-   DrainRouteEntry* newRoute(uint16_t dest) {
-     DrainRouteEntry* route;    
-     route = &routes[0];
-     
-     clearRoute(route);
-     route->dest = dest;
-     return route;
-   }
- 
-   bool isGroup(uint16_t dest) {
-     return (dest >= 0xFE00 && dest <= 0xFEFF);
-   }
- 
    command result_t StdControl.start() {
      return SUCCESS;
--- 95,98 ----
***************
*** 163,167 ****
        }
      }
! 
      pMHMsg->type = id;
      pMHMsg->ttl = DRAIN_MAX_TTL - 1;
--- 121,125 ----
        }
      }
!     
      pMHMsg->type = id;
      pMHMsg->ttl = DRAIN_MAX_TTL - 1;
***************
*** 216,238 ****
  
    command bool DrainLinkEst.isRoot() {
!     return (routes[0].nextHop == TOS_LOCAL_ADDRESS);
    }
  
    command result_t Drain.buildTree() {
!     return call Drain.buildTreeInstance(call Random.rand() & 0xFF);
    }
  
!   command result_t Drain.buildTreeInstance(uint8_t instance) {
  
!     DrainRouteEntry* route = newRoute(TOS_LOCAL_ADDRESS);
  
      if (route == NULL) 
        return FAIL;
  
      route->treeInstance = instance;
  
-     dbg(DBG_ROUTE, "DrainLinkEstM: buildTree(instance=%d)\n",
- 	route->treeInstance);
- 
      route->announceSeqno = 0;
      route->announceDelay = 1;
--- 174,200 ----
  
    command bool DrainLinkEst.isRoot() {
!     return (getRoute(TOS_LOCAL_ADDRESS) != NULL);
    }
  
    command result_t Drain.buildTree() {
!     return call Drain.buildTreeInstance(call Random.rand() & 0xFF, FALSE);
    }
  
!   command result_t Drain.buildTreeDefaultRoute() {
!     return call Drain.buildTreeInstance(call Random.rand() & 0xFF, TRUE);
!   }
  
!   command result_t Drain.buildTreeInstance(uint8_t instance, bool defaultRoute) {
! 
!     DrainRouteEntry* route = newRoute(TOS_LOCAL_ADDRESS, defaultRoute);
  
      if (route == NULL) 
        return FAIL;
+     
+     dbg(DBG_ROUTE, "DrainLinkEstM: buildTree(instance=%d,defaultRoute=%d)\n", 
+ 	instance, defaultRoute);
  
      route->treeInstance = instance;
  
      route->announceSeqno = 0;
      route->announceDelay = 1;
***************
*** 245,249 ****
      route->sentRoute = FALSE;
  
!     post SendRouteTask();
  
      return SUCCESS;
--- 207,211 ----
      route->sentRoute = FALSE;
  
!     sendRoute(route);
  
      return SUCCESS;
***************
*** 251,269 ****
  
    event result_t Timer.fired() {
!     DrainRouteEntry *route = &routes[0];
  
-     if (route->sentRoute == FALSE) {
-       route->sentRoute = TRUE;
-       post SendRouteTask();
-     }
-     
      return SUCCESS;
    }
  
!   task void SendRouteTask() {
  
      TOS_MsgPtr pMsgBuf = &msgBuf;
      DrainBeaconMsg *pRP = (DrainBeaconMsg *)&pMsgBuf->data[0];
-     DrainRouteEntry *route = &routes[0];
  
      dbg(DBG_ROUTE, "DrainLinkEstM: sending route update\n");
--- 213,232 ----
  
    event result_t Timer.fired() {
!     DrainRouteEntry *route;
! 
!     timerRunning = FALSE;
! 
!     route = getReadyRoute();
!     sendRoute(route);
! 
!     startTimer();
  
      return SUCCESS;
    }
  
!   void sendRoute(DrainRouteEntry* route) {
  
      TOS_MsgPtr pMsgBuf = &msgBuf;
      DrainBeaconMsg *pRP = (DrainBeaconMsg *)&pMsgBuf->data[0];
  
      dbg(DBG_ROUTE, "DrainLinkEstM: sending route update\n");
***************
*** 271,282 ****
      if (route->dest == DRAIN_INVALID_DEST ||
  	route->destDistance == DRAIN_MAX_TTL) {
!       dbg(DBG_ROUTE, "DrainLinkEstM: couldn't send route (dest=%d, destDistance=%d)\n", route->dest, route->destDistance);
        return;
      }
  
      if (msgBufBusy) {
- #ifndef PLATFORM_PC
-       post SendRouteTask();
- #endif
        return;
      }
--- 234,244 ----
      if (route->dest == DRAIN_INVALID_DEST ||
  	route->destDistance == DRAIN_MAX_TTL) {
!       dbg(DBG_ROUTE, "DrainLinkEstM: couldn't send route (dest=%d, destDistance=%d)\n", 
! 	  route->dest, route->destDistance);
!       route->sentRoute = TRUE;
        return;
      }
  
      if (msgBufBusy) {
        return;
      }
***************
*** 294,307 ****
      pRP->beaconDelay = route->announceDelay;
      pRP->beaconOffset = (route->announceDelay * 1024) - route->announceOffset;
  
      if (call SendMsg.send(TOS_BCAST_ADDR, sizeof(DrainBeaconMsg), pMsgBuf)) {
        dbg(DBG_ROUTE,"DrainLinkEstM: send DrainBeaconMsg(linkSource=%d,source=%d,parent=%d,cost=%d,ttl=%d,seqno=%d,delay=%d,instance=%d)\n",
  	  pRP->linkSource, pRP->source, pRP->parent, pRP->cost, pRP->ttl,
  	  pRP->beaconSeqno, pRP->beaconDelay, pRP->treeInstance);
      } else {
        dbg(DBG_ROUTE, "send DrainBeaconMsg FAILED\n");
! #ifndef PLATFORM_PC
!       post SendRouteTask();
! #endif
        atomic msgBufBusy = FALSE;
      }
--- 256,272 ----
      pRP->beaconDelay = route->announceDelay;
      pRP->beaconOffset = (route->announceDelay * 1024) - route->announceOffset;
+     pRP->defaultRoute = route->defaultRoute;
  
      if (call SendMsg.send(TOS_BCAST_ADDR, sizeof(DrainBeaconMsg), pMsgBuf)) {
+ 
        dbg(DBG_ROUTE,"DrainLinkEstM: send DrainBeaconMsg(linkSource=%d,source=%d,parent=%d,cost=%d,ttl=%d,seqno=%d,delay=%d,instance=%d)\n",
  	  pRP->linkSource, pRP->source, pRP->parent, pRP->cost, pRP->ttl,
  	  pRP->beaconSeqno, pRP->beaconDelay, pRP->treeInstance);
+ 
+       route->sentRoute = TRUE;
+ 
      } else {
        dbg(DBG_ROUTE, "send DrainBeaconMsg FAILED\n");
!       // how to handle the retries if the radio is busy?
        atomic msgBufBusy = FALSE;
      }
***************
*** 313,316 ****
--- 278,282 ----
      DrainRouteEntry *route = getRoute(pRP->source);
      uint16_t linkEst = 0;
+     uint32_t curCost, newCost;
  
  #if defined(_CC2420CONST_H)
***************
*** 323,334 ****
  //    dbg(DBG_ROUTE, "DrainLinkEstM: source=%d, dest=%d, est=%d\n",
  //	pRP->linkSource, TOS_LOCAL_ADDRESS, linkEst);
- 
- /*      
-     if (pRP->linkSource >= TOS_LOCAL_ADDRESS) {
-       linkEst = pRP->linkSource - TOS_LOCAL_ADDRESS;
-     } else {
-       linkEst = TOS_LOCAL_ADDRESS - pRP->linkSource;
-     }
- */
  #else
      linkEst = Msg->strength;
--- 289,292 ----
***************
*** 336,340 ****
  
      if (route == NULL) {
!       route = newRoute(pRP->source);
      }
  
--- 294,298 ----
  
      if (route == NULL) {
!       route = newRoute(pRP->source, pRP->defaultRoute);
      }
  
***************
*** 343,348 ****
  	pRP->beaconSeqno, pRP->beaconDelay, pRP->treeInstance, linkEst);
  
!     if ((int8_t)(pRP->beaconSeqno - route->announceSeqno) > 0 
! 	|| pRP->beaconSeqno == 0) {
        
        if (pRP->beaconSeqno == 0) {
--- 301,309 ----
  	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) {
***************
*** 362,384 ****
  
        route->sentRoute = FALSE;
!       call Timer.start(TIMER_ONE_SHOT, 
! 		       pRP->beaconOffset + route->announceOffset);
      }
  
      if (pRP->treeInstance != route->treeInstance ||
! 	pRP->linkSource == route->nextHop) {
!       
!       /* 
! 	 if no route exists, 
! 	 it's from a newly constructed tree,
! 	 or the message is from my parent, 
! 	 just copy the cost and link est. (why just copy from parent?)
!       */
  
!       if (pRP->treeInstance != route->treeInstance) {
! 	dbg(DBG_ROUTE, "DrainLinkEstM: joined tree instance %d\n", pRP->treeInstance);
!       } else {
! 	dbg(DBG_ROUTE, "DrainLinkEstM: updated parent cost in tree instance %d\n", pRP->treeInstance);
!       }
        
        route->dest = pRP->source;
--- 323,348 ----
  
        route->sentRoute = FALSE;
!       route->announceCountdown = pRP->beaconOffset + route->announceOffset;
! 
!       startTimer();
      }
  
+     /*** Routing stuff ***/
+     curCost = (uint32_t) route->nextHopCost + (uint32_t) route->nextHopLinkEst;
+     newCost = (uint32_t) pRP->cost + (uint32_t) linkEst;
+ 
+     /* When to update my route:
+      * - If it's a new tree.
+      * - If it's from my parent.
+      * - If it's from a lower-cost node that's not my child.
+      */
      if (pRP->treeInstance != route->treeInstance ||
! 	pRP->linkSource == route->nextHop ||
! 	( pRP->parent != TOS_LOCAL_ADDRESS &&
! 	  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;
***************
*** 390,427 ****
        
        route->treeInstance = pRP->treeInstance;
-       
-       dbg(DBG_ROUTE, "DrainLinkEstM: nextHop=%d, pathCost=%d, distance=%d\n",
- 	  route->nextHop,
- 	  route->nextHopCost + route->nextHopLinkEst,
- 	  route->destDistance);
-       
-     } else {
-       
-       /* 
- 	 this may be a better parent
- 	 compare the message's cost + link estimate to my current cost
- 	 switch if necessary 
-       */
-       
-       uint32_t curQuality = 
- 	(uint32_t) route->nextHopCost + (uint32_t) route->nextHopLinkEst;
-       uint32_t newQuality = 
- 	(uint32_t) pRP->cost + (uint32_t) linkEst;
-       
-       if (newQuality < curQuality && 
- 	  pRP->parent != TOS_LOCAL_ADDRESS) {
- 	
- 	route->nextHop = pRP->linkSource;
- 	route->nextHopCost = pRP->cost;
- 	route->nextHopLinkEst = linkEst;
- 	route->destDistance = DRAIN_MAX_TTL - pRP->ttl;
- 
- 	dbg(DBG_ROUTE, "DrainLinkEstM: parent switch in tree instance %d: nextHop=%d, pathCost=%d, distance=%d\n",
- 	    route->treeInstance, route->nextHop,
- 	    route->nextHopCost + route->nextHopLinkEst,
- 	    route->destDistance);
-       } else {
- 	dbg(DBG_ROUTE, "DrainLinkEstM: keeping current next hop\n");
-       }
      }
  
--- 354,357 ----
***************
*** 447,450 ****
--- 377,488 ----
    }
  
+   void clearRoute(DrainRouteEntry* route) {
+ 
+     route->dest = DRAIN_INVALID_DEST;
+     route->nextHop = TOS_BCAST_ADDR;
+     
+     route->nextHopCost = 0xFFFF;
+     route->nextHopLinkEst = 0xFFFF;
+     
+     route->destDistance = 0;
+     route->treeInstance = 0;
+ 
+     route->announceSeqno = 1;
+     route->announceDelay = 0;
+ 
+     route->defaultRoute = 0;
+   }
+ 
+   DrainRouteEntry* newRoute(uint16_t dest, bool defaultRoute) {
+     DrainRouteEntry* route;    
+     
+     if (defaultRoute) {
+       route = &routes[0];
+     } else {
+       route = &routes[1];
+     }
+     
+     clearRoute(route);
+     route->dest = dest;
+     route->defaultRoute = defaultRoute;
+     return route;
+   }
+ 
+   DrainRouteEntry* getRoute(uint16_t dest) {
+     DrainRouteEntry* route;
+     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;
+       }
+     }
+     return NULL;
+   }
+ 
+   DrainRouteEntry* getReadyRoute() {
+     DrainRouteEntry* route;
+     uint8_t i;
+ 
+     for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
+       route = &routes[i];
+       if (route->dest != DRAIN_INVALID_DEST && 
+ 	  route->sentRoute == FALSE &&
+ 	  route->announceCountdown == 0) {
+ 	return route;
+       }
+     }
+     return NULL;
+   }
+ 
+   bool isGroup(uint16_t dest) {
+     return (dest >= 0xFE00 && dest <= 0xFEFF);
+   }
+ 
+   void startTimer() {
+     DrainRouteEntry* route;
+     uint16_t minCountdown = 0xFFFF;
+     uint8_t i;
+ 
+     if (timerRunning) {
+       return;
+     }
+ 
+     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) {
+ 	  minCountdown = route->announceCountdown;
+ 	}
+       }
+     }
+ 
+     if (minCountdown < 0xFFFF) {
+ 
+       timerRunning = TRUE;
+       
+       for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
+ 	route = &routes[i];
+ 	if (route->dest != DRAIN_INVALID_DEST &&
+ 	    route->sentRoute == FALSE) {
+ 	  route->announceCountdown -= minCountdown;
+ 	}
+       }
+       
+       if (minCountdown == 0) {
+ 	minCountdown = 5;
+       }
+ 
+       call Timer.start(TIMER_ONE_SHOT, minCountdown);
+     }
+   }
+ 
    command uint16_t RouteControl.getParent() {
      return routes[0].nextHop;

Index: DrainM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainM.nc,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** DrainM.nc	14 Jun 2005 18:16:22 -0000	1.13
--- DrainM.nc	16 Jun 2005 17:46:30 -0000	1.14
***************
*** 166,171 ****
  					    TOS_MsgPtr pMsg) {
  
!     dbg(DBG_ROUTE, "Drain: netSend(pMsg=0x%x,id=%d,len=%d)\n",
! 	pMsg, id, length);
      
      if (tooBig(pMsg, length) || cantSend(pMsg, length)) {
--- 166,171 ----
  					    TOS_MsgPtr pMsg) {
  
!     dbg(DBG_ROUTE, "Drain: netSend(pMsg=0x%x,dest=%d,id=%d,len=%d)\n",
! 	pMsg, dest, id, length);
      
      if (tooBig(pMsg, length) || cantSend(pMsg, length)) {



More information about the Tinyos-beta-commits mailing list