[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain Drain.h, 1.2, 1.3 DrainC.nc, 1.2, 1.3 DrainLinkEst.nc, 1.1, 1.2 DrainLinkEstM.nc, 1.2, 1.3 DrainM.nc, 1.2, 1.3

Gilman Tolle gtolle at users.sourceforge.net
Wed Mar 2 18:04:15 PST 2005


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

Modified Files:
	Drain.h DrainC.nc DrainLinkEst.nc DrainLinkEstM.nc DrainM.nc 
Log Message:
Drain is now tested and working on telosb, and has its own Java tools for tree building and message reception.

Index: Drain.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/Drain.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Drain.h	15 Feb 2005 06:41:32 -0000	1.2
--- Drain.h	3 Mar 2005 02:04:12 -0000	1.3
***************
*** 40,44 ****
  enum {
    AM_DRAINMSG = 4,
!   AM_DRAINBEACONMSG = 5,
  };
  
--- 40,44 ----
  enum {
    AM_DRAINMSG = 4,
!   AM_DRAINBEACONMSG = 7,
  };
  
***************
*** 48,83 ****
    DRAIN_MAX_MISSED_BEACONS = 5,
    DRAIN_UNKNOWN_ACK_EST = 127,
  };
  
  enum {
!   MA_Drain_Parent_ATTR = 30,
!   MA_Drain_Parent_LEN = 2,
! 
!   MA_Drain_Cost_ATTR = 31,
!   MA_Drain_Cost_LEN = 2,
! 
!   MA_Drain_LinkEst_ATTR = 32,
!   MA_Drain_LinkEst_LEN = 2,
  };
  
  typedef struct DrainMsg {
-   uint16_t sourceaddr;
-   uint16_t originaddr;
-   uint8_t ttl;
    uint8_t type;
    uint8_t data[0];
  } DrainMsg;
  
  typedef struct DrainBeaconMsg {
    uint16_t parent;
-   uint16_t sourceAddr;
    uint16_t cost;
!   uint16_t treeID;
!   uint32_t timestamp;
!   uint16_t beaconPeriod;
    uint8_t  beaconSeqno;
!   uint8_t  level;
  } DrainBeaconMsg;
  
  #endif
  
--- 48,99 ----
    DRAIN_MAX_MISSED_BEACONS = 5,
    DRAIN_UNKNOWN_ACK_EST = 127,
+   DRAIN_MAX_ROUTES = 1,
+   DRAIN_MAX_TTL = 16,
+   DRAIN_OP_CREATE = 1,
+   DRAIN_OP_DESTROY = 2,
+   DRAIN_INVALID_DEST = 0,
  };
  
  enum {
!   TOS_DEFAULT_ADDR = 0,
  };
  
  typedef struct DrainMsg {
    uint8_t type;
+   uint8_t ttl;
+   uint16_t source;
+   uint16_t dest;
    uint8_t data[0];
  } DrainMsg;
  
  typedef struct DrainBeaconMsg {
+   uint16_t linkSource;
+ 
+   uint16_t source;
    uint16_t parent;
    uint16_t cost;
!   uint8_t  ttl;
! 
    uint8_t  beaconSeqno;
!   uint8_t  beaconDelay;
!   uint8_t  treeInstance;
!   uint16_t beaconOffset;
  } DrainBeaconMsg;
  
+ typedef struct DrainRouteEntry {
+   uint16_t dest;
+ 
+   uint16_t nextHop;
+   uint16_t nextHopCost;
+   uint16_t nextHopLinkEst;
+ 
+   uint8_t  destDistance;
+   uint8_t  treeInstance;
+   
+   uint8_t  announceSeqno;
+   uint8_t  announceDelay;
+   uint16_t announceOffset;
+ } DrainRouteEntry;
+ 
  #endif
  

Index: DrainC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainC.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DrainC.nc	15 Feb 2005 06:41:32 -0000	1.2
--- DrainC.nc	3 Mar 2005 02:04:13 -0000	1.3
***************
*** 6,9 ****
--- 6,10 ----
      interface StdControl;
  
+     interface SendMsg[uint8_t id];
      interface Send[uint8_t id];
      interface Receive[uint8_t id];
***************
*** 21,32 ****
      RandomLFSR,
      TimerC,
!     LedsC as Leds;
! 
! #ifdef DRAIN_INSTRUMENTED
!   components AttrsC;
! #endif
  
    StdControl = DrainM.StdControl;
    Receive = DrainM.Receive;
    Send = DrainM.Send;
    Intercept = DrainM.Intercept;
--- 22,30 ----
      RandomLFSR,
      TimerC,
!     LedsC;
  
    StdControl = DrainM.StdControl;
    Receive = DrainM.Receive;
+   SendMsg = DrainM.SendMsg;
    Send = DrainM.Send;
    Intercept = DrainM.Intercept;
***************
*** 36,48 ****
    DrainM.SubControl -> DrainLinkEstM;
  
!   DrainM.Leds -> Leds;
  
    DrainM.DrainLinkEst -> DrainLinkEstM;
  
!   DrainM.SendMsg -> GenericComm.SendMsg[AM_DRAINMSG];
!   DrainM.ReceiveMsg -> GenericComm.ReceiveMsg[AM_DRAINMSG];
  
    DrainLinkEstM.Timer -> TimerC.Timer[unique("Timer")];
!   DrainLinkEstM.AgingTimer -> TimerC.Timer[unique("Timer")];  
  
    DrainLinkEstM.Random -> RandomLFSR;
--- 34,46 ----
    DrainM.SubControl -> DrainLinkEstM;
  
!   DrainM.Leds -> LedsC;
  
    DrainM.DrainLinkEst -> DrainLinkEstM;
  
!   DrainM.LinkSendMsg -> GenericComm.SendMsg[AM_DRAINMSG];
!   DrainM.LinkReceiveMsg -> GenericComm.ReceiveMsg[AM_DRAINMSG];
  
    DrainLinkEstM.Timer -> TimerC.Timer[unique("Timer")];
!   //  DrainLinkEstM.AgingTimer -> TimerC.Timer[unique("Timer")];  
  
    DrainLinkEstM.Random -> RandomLFSR;
***************
*** 50,58 ****
    DrainLinkEstM.SendMsg -> GenericComm.SendMsg[AM_DRAINBEACONMSG];
    DrainLinkEstM.ReceiveMsg -> GenericComm.ReceiveMsg[AM_DRAINBEACONMSG];
! 
! #ifdef DRAIN_INSTRUMENTED
!   DrainLinkEstM.Parent -> AttrsC.AttrServer[MA_Drain_Parent_ATTR];
!   DrainLinkEstM.Cost -> AttrsC.AttrServer[MA_Drain_Cost_ATTR];
!   DrainLinkEstM.LinkEst -> AttrsC.AttrServer[MA_Drain_LinkEst_ATTR];
! #endif
  }
--- 48,51 ----
    DrainLinkEstM.SendMsg -> GenericComm.SendMsg[AM_DRAINBEACONMSG];
    DrainLinkEstM.ReceiveMsg -> GenericComm.ReceiveMsg[AM_DRAINBEACONMSG];
!   DrainLinkEstM.Leds -> LedsC;
  }

Index: DrainLinkEst.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainLinkEst.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DrainLinkEst.nc	14 Feb 2005 23:16:37 -0000	1.1
--- DrainLinkEst.nc	3 Mar 2005 02:04:13 -0000	1.2
***************
*** 37,47 ****
  
    /**
-    * Whether there is currently a valid route.
-    *
-    * @return Whether there is a valid route.
-    */
-   command bool isActive();
- 
-   /**
     * Given a TOS_MsgPtr, initialize its routing fields to a known
     * state, specifying that the message is originating from this node.
--- 37,40 ----
***************
*** 55,59 ****
     */
  
!   command result_t initializeFields(TOS_MsgPtr msg, uint8_t id);
    
    /**
--- 48,55 ----
     */
  
!   command result_t initializeFields(TOS_MsgPtr msg, uint8_t id, 
! 				    uint16_t dest, uint8_t length);
! 
!   command result_t forwardFields(TOS_MsgPtr msg);
    
    /**
***************
*** 68,72 ****
     */
    
!   command result_t selectRoute(TOS_MsgPtr msg, uint8_t id, bool firstTime);
  
    /**
--- 64,68 ----
     */
    
!   command result_t selectRoute(TOS_MsgPtr msg);
  
    /**

Index: DrainLinkEstM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainLinkEstM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DrainLinkEstM.nc	15 Feb 2005 06:41:32 -0000	1.2
--- DrainLinkEstM.nc	3 Mar 2005 02:04:13 -0000	1.3
***************
*** 29,33 ****
  
  
- 
  /*
   * Authors:          Gilman Tolle
--- 29,32 ----
***************
*** 40,48 ****
      interface StdControl;
      interface DrainLinkEst;
    }
  
    uses {
      interface Timer;
!     interface Timer as AgingTimer;
  
      interface Random;
--- 39,50 ----
      interface StdControl;
      interface DrainLinkEst;
+     interface Attr<uint16_t> as DrainNextHop @nucleusAttr();
+     interface Attr<uint16_t> as DrainNextHopCost @nucleusAttr();
+     interface Attr<uint16_t> as DrainNextHopLinkEst @nucleusAttr();
    }
  
    uses {
      interface Timer;
!     //    interface Timer as AgingTimer;
  
      interface Random;
***************
*** 50,59 ****
      interface SendMsg;
      interface ReceiveMsg;
! 
! #ifdef DRAIN_INSTRUMENTED
!     interface AttrServer as Parent;
!     interface AttrServer as Cost;
!     interface AttrServer as LinkEst;
! #endif
    }
  }
--- 52,56 ----
      interface SendMsg;
      interface ReceiveMsg;
!     interface Leds;
    }
  }
***************
*** 61,80 ****
  implementation {
  
!   int8_t   beaconSeqno;
!   uint8_t  missedBeacons;
!   uint16_t beaconPeriod;
! 
!   uint16_t currentTreeID;
!   uint16_t currentParentAddr;
!   uint16_t currentParentCost;
!   uint16_t currentParentLinkEst;
!   uint16_t currentParentLQI;
!   uint16_t currentParentAckEst;
!   uint8_t  currentDepth;
!   uint16_t successCounter;
!   uint16_t failCounter;
  
    bool msgBufBusy;
!   TOS_Msg buf;
  
  #define MAX(a_,b_) (a_ > b_ ? a_ : b_)
--- 58,65 ----
  implementation {
  
!   DrainRouteEntry routes[DRAIN_MAX_ROUTES];
  
    bool msgBufBusy;
!   TOS_Msg msgBuf;
  
  #define MAX(a_,b_) (a_ > b_ ? a_ : b_)
***************
*** 82,142 ****
  
    uint16_t adjustLQI(uint8_t val);
    task void SendRouteTask();
  
    command result_t StdControl.init() {
      
      msgBufBusy = FALSE;
      
! #ifdef PLATFORM_PC
!     currentParentAddr = TOS_LOCAL_ADDRESS-1; // For debugging.
! #else
!     currentParentAddr = TOS_BCAST_ADDR;
! #endif
!     currentParentCost = 0xffff;
!     currentParentLinkEst = 0xffff;
!     currentParentAckEst = DRAIN_UNKNOWN_ACK_EST;
!     currentParentLQI = 0x0;
!     currentTreeID = 0;
!     currentDepth = 0;
  
!     beaconSeqno = 1;
!     missedBeacons = 0;
  
!     successCounter = failCounter = 0;
  
!     return SUCCESS;
    }
  
    command result_t StdControl.start() {
      return SUCCESS;
    }
  
    command result_t StdControl.stop() {
-     call AgingTimer.stop();
      call Timer.stop();
      return SUCCESS;
    }
  
!   command result_t DrainLinkEst.initializeFields(TOS_MsgPtr Msg, uint8_t id) {
      DrainMsg *pMHMsg = (DrainMsg *)&Msg->data[0];
  
-     pMHMsg->sourceaddr = TOS_LOCAL_ADDRESS;
-     pMHMsg->originaddr = TOS_LOCAL_ADDRESS;
-     pMHMsg->ttl = 16;
      pMHMsg->type = id;
  
      return SUCCESS;
    }
  
!   command result_t DrainLinkEst.selectRoute(TOS_MsgPtr Msg, uint8_t id, 
! 					    bool firstTime) {
      DrainMsg *pMHMsg = (DrainMsg *)&Msg->data[0];
-     
-     Msg->addr = currentParentAddr;
-     pMHMsg->sourceaddr = TOS_LOCAL_ADDRESS;
  
!     if (firstTime) {
!       pMHMsg->ttl--;
!     }
  
      if (pMHMsg->ttl == 0) {
--- 67,181 ----
  
    uint16_t adjustLQI(uint8_t val);
+ 
+   void clearRoute(DrainRouteEntry* route);
+   DrainRouteEntry* getRoute(uint16_t dest);
+ 
    task void SendRouteTask();
  
    command result_t StdControl.init() {
      
+     uint8_t i;
+ 
      msgBufBusy = FALSE;
+ 
+     for(i = 0; i < DRAIN_MAX_ROUTES; i++) {
+       clearRoute(&routes[i]);
+     }
+ 
+     return SUCCESS;
+   }
+ 
+   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;
  
!     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;
    }
  
    command result_t StdControl.start() {
+ #ifdef PLATFORM_PC
+     if (TOS_LOCAL_ADDRESS == 0) {
+       DrainRouteEntry* route = &routes[0];
+       
+       route->dest = TOS_BCAST_ADDR;
+       route->nextHop = TOS_BCAST_ADDR;
+       
+       route->nextHopCost = 0;
+       route->nextHopLinkEst = 0;
+       
+       route->destDistance = 0;
+       route->treeInstance = 128;
+       
+       route->announceSeqno = 0;
+       route->announceDelay = 4;
+       
+       call Timer.start(TIMER_REPEAT, 16384);
+     }
+ #endif
      return SUCCESS;
    }
  
    command result_t StdControl.stop() {
      call Timer.stop();
      return SUCCESS;
    }
  
!   command result_t DrainLinkEst.initializeFields(TOS_MsgPtr Msg, 
! 						 uint8_t id, 
! 						 uint16_t dest, 
! 						 uint8_t length) {
!     
      DrainMsg *pMHMsg = (DrainMsg *)&Msg->data[0];
  
      pMHMsg->type = id;
+     pMHMsg->ttl = DRAIN_MAX_TTL - 1;
+     pMHMsg->source = TOS_LOCAL_ADDRESS;
+ 
+     if (dest == TOS_DEFAULT_ADDR) {
+       pMHMsg->dest = routes[0].dest;
+     } else {
+       pMHMsg->dest = dest;
+     }
+ 
+     Msg->length = offsetof(DrainMsg,data) + length;
  
      return SUCCESS;
    }
  
!   command result_t DrainLinkEst.forwardFields(TOS_MsgPtr Msg) {
! 
      DrainMsg *pMHMsg = (DrainMsg *)&Msg->data[0];
  
!     pMHMsg->ttl--;
  
      if (pMHMsg->ttl == 0) {
***************
*** 147,242 ****
    }
  
    event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr Msg) {
  
      DrainBeaconMsg *pRP = (DrainBeaconMsg *)&Msg->data[0];
  
!     /* 
!        If we already belong to the newest tree we know of, consider
!        the beacon seqno.  If it is newer, send out our own beacon.
!     */
!     
!     if ((int8_t)(pRP->beaconSeqno - beaconSeqno) > 0 
  	|| pRP->beaconSeqno == 0) {
        
        if (pRP->beaconSeqno == 0) {
! 	beaconSeqno++;
! 	if (beaconSeqno == 0)
! 	  beaconSeqno++;
!       }	else {
! 	beaconSeqno = pRP->beaconSeqno;
        }
!       
!       if (pRP->beaconPeriod != beaconPeriod) {
! 	beaconPeriod = pRP->beaconPeriod;
  	call AgingTimer.stop();
! 	call AgingTimer.start(TIMER_ONE_SHOT,
! 			      1024 * beaconPeriod);
        }
        call Timer.start(TIMER_ONE_SHOT, 
! 		       (call Random.rand() % (1024 * beaconPeriod)) + 1);
      }
-     
-     /* Now evaluate whether we should reparent to the beacon. */
-       
-     if (pRP->sourceAddr == currentParentAddr) {
  
!       uint16_t newLinkEst; 
!      
!       currentTreeID = pRP->treeID;
!       currentParentCost = pRP->cost;
! 
! #ifdef PLATFORM_TELOS
!       newLinkEst = adjustLQI(Msg->lqi);
!       currentParentLQI = Msg->lqi;
! #else
!       newLinkEst = Msg->strength;
  #endif
  
!       currentParentLinkEst = newLinkEst;
! 
!       missedBeacons = 0;
  
!       currentDepth = pRP->level + 1;
  
!     } else {
  
!       /* if the message is not from my parent, 
! 	 compare the message's cost + link estimate to my current cost,
! 	 switch if necessary */
  
!       uint32_t currentQuality = 
! 	(uint32_t) currentParentCost + (uint32_t) currentParentLinkEst; 
!       uint16_t newLinkEst;
!       uint32_t newQuality = pRP->cost;
        
! #ifdef PLATFORM_TELOS
!       newLinkEst = adjustLQI(Msg->lqi);
!       newQuality += (uint32_t) adjustLQI(Msg->lqi);
! #else
!       newLinkEst = Msg->strength;
!       newQuality += (uint32_t) Msg->strength;
! #endif
        
! #ifdef NO_ACK_EST
!       // do nothing
! #else
!       currentQuality += (uint32_t) currentParentAckEst;
!       newQuality += (uint32_t) DRAIN_UNKNOWN_ACK_EST;
! #endif
  
-       if (newQuality < currentQuality && pRP->parent != TOS_LOCAL_ADDRESS) {
- 	
- 	currentTreeID = pRP->treeID;
- 	currentParentAddr = pRP->sourceAddr;
- 	currentParentCost = pRP->cost;
- 	currentParentLinkEst = newLinkEst;
- 	currentParentAckEst = DRAIN_UNKNOWN_ACK_EST;
- #ifdef PLATFORM_TELOS
- 	currentParentLQI = Msg->lqi;
- #endif
- 	currentDepth = pRP->level + 1;
- 	successCounter = 0;
- 	failCounter = 0;
-       }
      }
  
--- 186,331 ----
    }
  
+   command result_t DrainLinkEst.selectRoute(TOS_MsgPtr Msg) {
+ 					    
+     DrainMsg* pMHMsg = (DrainMsg *)&Msg->data[0];
+     DrainRouteEntry* route;
+     
+     if (pMHMsg->dest == TOS_BCAST_ADDR) {
+       Msg->addr = TOS_BCAST_ADDR;
+ 
+     } else {
+ 
+       route = getRoute(pMHMsg->dest);
+ 
+       if (route != NULL) {
+ 	Msg->addr = route->nextHop;
+       } else {
+ 	Msg->addr = TOS_BCAST_ADDR;
+       }
+       
+     }
+ 
+     Msg->ack = 0;
+ 
+     return SUCCESS;
+   }
+ 
+   
    event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr Msg) {
  
      DrainBeaconMsg *pRP = (DrainBeaconMsg *)&Msg->data[0];
+     DrainRouteEntry *route = getRoute(pRP->source);
+     uint16_t linkEst = 0;
  
! #if defined(CC2420_DEF_CHANNEL)
!     linkEst = adjustLQI(Msg->lqi);
! #elif defined(PLATFORM_PC)
!     if (pRP->linkSource >= TOS_LOCAL_ADDRESS) {
!       linkEst = pRP->linkSource - TOS_LOCAL_ADDRESS;
!     } else {
!       linkEst = TOS_LOCAL_ADDRESS - pRP->linkSource;
!     }
! #else
!     linkEst = Msg->strength;
! #endif
! 
!     if (route == NULL) {
!       route = newRoute(pRP->source);
!     }
! 
! #if 0
!     dbg(DBG_ROUTE,"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);
! #endif
! 
! #ifdef PLATFORM_PC
!     if (TOS_LOCAL_ADDRESS != 0) {
! #endif
! 
!     if ((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;
        }
! 
!       /*      
!       if (pRP->beaconPeriod != route->announcePeriod) {
! 	
! 	route->announcePeriod = pRP->beaconPeriod;
! 	
  	call AgingTimer.stop();
! 	
! 	if (route->announcePeriod > 0) {
! 	  call AgingTimer.start(TIMER_ONE_SHOT,
! 				1024 * route->announcePeriod);
! 	}
        }
+       */
+       
+       route->announceDelay = pRP->beaconDelay;
+       route->announceOffset = 
+ 	(call Random.rand() % 
+ 	 (1024 * route->announceDelay)) + 1;
+       
        call Timer.start(TIMER_ONE_SHOT, 
! 		       pRP->beaconOffset + route->announceOffset);
      }
  
! #ifdef PLATFORM_PC
!     }
  #endif
  
!     if (route == NULL || 
! 	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.
!       */
!       
!       route->dest = pRP->source;
!       route->destDistance = DRAIN_MAX_TTL - pRP->ttl;
  
!       route->nextHop = pRP->linkSource;
!       route->nextHopCost = pRP->cost;
!       route->nextHopLinkEst = linkEst;
  
!       route->treeInstance = pRP->treeInstance;
  
!       //      route->announceMissed = 0;
        
!     } 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;
! 	}
  
      }
  
***************
*** 256,267 ****
  
    task void SendRouteTask() {
-     TOS_MsgPtr pMsgBuf = &buf;
-     DrainBeaconMsg *pRP = (DrainBeaconMsg *)&pMsgBuf->data[0];
-     uint8_t length = sizeof(DrainBeaconMsg);
  
      dbg(DBG_ROUTE,"MultiHopRSSI Sending route update msg.\n");
! 
!     if (currentParentAddr != TOS_BCAST_ADDR) {
!       dbg(DBG_ROUTE,"MultiHopRSSI: Parent = %d\n", currentParentAddr);
      }
  
--- 345,358 ----
  
    task void SendRouteTask() {
  
+     TOS_MsgPtr pMsgBuf = &msgBuf;
+     DrainBeaconMsg *pRP = (DrainBeaconMsg *)&pMsgBuf->data[0];
+     DrainRouteEntry *route = &routes[0];
+     
      dbg(DBG_ROUTE,"MultiHopRSSI Sending route update msg.\n");
!     
!     if (route->dest == DRAIN_INVALID_DEST ||
! 	route->destDistance == DRAIN_MAX_TTL) {
!       return;
      }
  
***************
*** 274,293 ****
      
      atomic msgBufBusy = TRUE;
! 
!     dbg(DBG_ROUTE,"MultiHopRSSI: Current cost: %d.\n", 
! 	currentParentCost + currentParentLinkEst);
! 
!     pRP->parent = currentParentAddr;
!     pRP->sourceAddr = TOS_LOCAL_ADDRESS;
!     pRP->cost = currentParentCost + currentParentLinkEst;
! #ifndef NO_ACK_EST
!     pRP->cost += currentParentAckEst;
! #endif
!     pRP->treeID = currentTreeID;
!     pRP->beaconSeqno = beaconSeqno;
!     pRP->beaconPeriod = beaconPeriod;
!     pRP->level = currentDepth;
! 
!     if (!call SendMsg.send(TOS_BCAST_ADDR, length, pMsgBuf)) {
  #ifndef PLATFORM_PC
        post SendRouteTask();
--- 365,386 ----
      
      atomic msgBufBusy = TRUE;
!     
!     pRP->linkSource = TOS_LOCAL_ADDRESS;
!     
!     pRP->source = route->dest;
!     pRP->parent = route->nextHop;
!     pRP->cost = route->nextHopCost + route->nextHopLinkEst;
!     pRP->ttl = DRAIN_MAX_TTL - route->destDistance - 1;
!     pRP->treeInstance = route->treeInstance;
!     pRP->beaconSeqno = route->announceSeqno;
!     pRP->beaconDelay = route->announceDelay;
!     pRP->beaconOffset = (route->announceDelay * 1024) - route->announceOffset;
!     
!     if (call SendMsg.send(TOS_BCAST_ADDR, 12, pMsgBuf)) {
!       dbg(DBG_ROUTE,"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();
***************
*** 298,334 ****
    }
  
    event result_t AgingTimer.fired() {
! #ifndef NO_ACK_EST
      if (successCounter + failCounter > 0) {
        currentParentAckEst = (255 - (255 * successCounter) / (successCounter + failCounter));
        successCounter = failCounter = 0;
      }
- #endif
  
!     if (missedBeacons > DRAIN_MAX_MISSED_BEACONS) {
!       if (currentParentLinkEst << 1 < 0xffff) {
! 	currentParentLinkEst <<= 1;
        } else {
! 	currentParentLinkEst = 0xffff;
        }
      }
!     if (missedBeacons != 0xff) {
!       missedBeacons++;
      }
  
-     call AgingTimer.start(TIMER_ONE_SHOT, (1024 * beaconPeriod));
      return SUCCESS;
    }
  
-   command bool DrainLinkEst.isActive() {
-     if (currentParentAddr == TOS_BCAST_ADDR) {
-       return FALSE;
-     } else {
-       return TRUE;
-     }
-   }
-   
    command result_t DrainLinkEst.messageSent(TOS_MsgPtr msg, uint8_t id, 
  					    result_t success) {
      if (success) {
        successCounter++; 
--- 391,426 ----
    }
  
+ #if 0
    event result_t AgingTimer.fired() {
! 
!     DrainRouteEntry *route = &routes[0];
!     
      if (successCounter + failCounter > 0) {
        currentParentAckEst = (255 - (255 * successCounter) / (successCounter + failCounter));
        successCounter = failCounter = 0;
      }
  
!     if (route->announceMissed > DRAIN_MAX_MISSED_BEACONS) {
!       if (route->nextHopLinkEst << 1 < 0xffff) {
! 	route->nextHopLinkEst <<= 1;
        } else {
! 	clearRoute(route);
        }
      }
! 
!     if (route->announceMissed < 0xff) {
!       route->announceMissed++;
      }
+     
+     call AgingTimer.start(TIMER_ONE_SHOT, (1024 * route->announcePeriod));
  
      return SUCCESS;
    }
+ #endif
  
    command result_t DrainLinkEst.messageSent(TOS_MsgPtr msg, uint8_t id, 
  					    result_t success) {
+ 
+ #if 0
      if (success) {
        successCounter++; 
***************
*** 336,344 ****
        failCounter++;
      }
      return SUCCESS;
    }
  
    event result_t SendMsg.sendDone(TOS_MsgPtr pMsg, result_t success) {
!     if (pMsg == &buf) {
        atomic msgBufBusy = FALSE;
      }
--- 428,438 ----
        failCounter++;
      }
+ #endif
+ 
      return SUCCESS;
    }
  
    event result_t SendMsg.sendDone(TOS_MsgPtr pMsg, result_t success) {
!     if (pMsg == &msgBuf) {
        atomic msgBufBusy = FALSE;
      }
***************
*** 346,368 ****
    }
  
! #ifdef DRAIN_INSTRUMENTED
!   event uint8_t Parent.length() { return sizeof(TOS_LOCAL_ADDRESS); }
!   event result_t Parent.get(void* buf) {
!     memcpy(buf, &currentParentAddr, sizeof(TOS_LOCAL_ADDRESS));
      return SUCCESS;
    }
  
!   event uint8_t Cost.length() { return sizeof(currentParentCost); }
!   event result_t Cost.get(void* buf) {
!     memcpy(buf, &currentParentCost, sizeof(TOS_LOCAL_ADDRESS));
      return SUCCESS;
    }
  
!   event uint8_t LinkEst.length() { return sizeof(currentParentLinkEst); }
!   event result_t LinkEst.get(void* buf) {
!     memcpy(buf, &currentParentLinkEst, sizeof(TOS_LOCAL_ADDRESS));
      return SUCCESS;
    }
- #endif
  }
  
--- 440,460 ----
    }
  
!   command result_t DrainNextHop.get(uint16_t* buf) {
!     memcpy(buf, &routes[0].nextHop, sizeof(uint16_t));
!     signal DrainNextHop.getDone(buf);
      return SUCCESS;
    }
  
!   command result_t DrainNextHopCost.get(uint16_t* buf) {
!     memcpy(buf, &routes[0].nextHopCost, sizeof(uint16_t));
!     signal DrainNextHopCost.getDone(buf);
      return SUCCESS;
    }
  
!   command result_t DrainNextHopLinkEst.get(uint16_t* buf) {
!     memcpy(buf, &routes[0].nextHopLinkEst, sizeof(uint16_t));
!     signal DrainNextHopLinkEst.getDone(buf);
      return SUCCESS;
    }
  }
  

Index: DrainM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/DrainM.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DrainM.nc	15 Feb 2005 06:41:32 -0000	1.2
--- DrainM.nc	3 Mar 2005 02:04:13 -0000	1.3
***************
*** 36,41 ****
    provides {
      interface StdControl;
!     interface Receive[uint8_t id];
      interface Send[uint8_t id];
      interface Intercept[uint8_t id];
      interface Intercept as Snoop[uint8_t id];
--- 36,43 ----
    provides {
      interface StdControl;
! 
!     interface SendMsg[uint8_t id];
      interface Send[uint8_t id];
+     interface Receive[uint8_t id];
      interface Intercept[uint8_t id];
      interface Intercept as Snoop[uint8_t id];
***************
*** 46,51 ****
      interface Leds;
  
!     interface ReceiveMsg;
!     interface SendMsg;
  
      interface DrainLinkEst;
--- 48,53 ----
      interface Leds;
  
!     interface ReceiveMsg as LinkReceiveMsg;
!     interface SendMsg as LinkSendMsg;
  
      interface DrainLinkEst;
***************
*** 76,83 ****
    uint8_t currentFailCount;
  
    task void QueueServiceTask();
  
    void initializeBufs();
!   TOS_MsgPtr mForward(TOS_MsgPtr pMsg, uint8_t id);
  
    void inc(uint16_t *val);
--- 78,94 ----
    uint8_t currentFailCount;
  
+   uint8_t sendDrops;
+   uint8_t forwardDrops;
+ 
+   uint16_t sendPackets;
+   uint16_t forwardPackets;
+ 
    task void QueueServiceTask();
  
    void initializeBufs();
! 
!   bool cantSend(TOS_MsgPtr pMsg, uint8_t payloadLen);
!   result_t enqueueSend(TOS_MsgPtr pMsg);
!   TOS_MsgPtr enqueueForward(TOS_MsgPtr pMsg);
  
    void inc(uint16_t *val);
***************
*** 137,170 ****
  
    command result_t Send.send[uint8_t id](TOS_MsgPtr pMsg, uint16_t payloadLen) {
!     uint16_t usMHLength = offsetof(DrainMsg,data) + payloadLen;
  
      dbg(DBG_ROUTE, "Drain: send(pMsg=0x%x,id=%d,len=%d)\n",
! 	pMsg, id, payloadLen);
  
!     if (usMHLength > TOSH_DATA_LENGTH) {
        return FAIL;
      }
  
!     if (sendQueueFull) {
!       dbg(DBG_ROUTE, "Drain: sendQueueFull(pMsg=0x%x,id=%d,len=%d)\n",
! 	  pMsg, id, payloadLen);
!       return FAIL;
!     }
  
!     call DrainLinkEst.initializeFields(pMsg, id);
  
!     if (call DrainLinkEst.selectRoute(pMsg, id, TRUE) != SUCCESS) {
!       dbg(DBG_ROUTE, "Drain: sendSelectRouteFail(pMsg=0x%x,id=%d,len=%d)\n",
! 	  pMsg, id, payloadLen);
!       return FAIL;
!     }
  
!     dbg(DBG_ROUTE, "Drain: sendEnterQueue(pMsg=0x%x,id=%d,len=%d)\n",
! 	pMsg, id, payloadLen);
  
!     pMsg->length = usMHLength;
  
      if (!queuesBusy) {
        if (post QueueServiceTask() == FAIL) {
  	return FAIL;
        } else {
--- 148,195 ----
  
    command result_t Send.send[uint8_t id](TOS_MsgPtr pMsg, uint16_t payloadLen) {
!     // Please send with a destination address, or TOS_DEFAULT_ADDR
!     // if you don't care. 
!     // This may be temporary...
! 
!     return FAIL;
!   } 
!   
!   command result_t SendMsg.send[uint8_t id](uint16_t dest, uint8_t length, TOS_MsgPtr pMsg) {
  
      dbg(DBG_ROUTE, "Drain: send(pMsg=0x%x,id=%d,len=%d)\n",
! 	pMsg, id, length);
  
!     if (cantSend(pMsg, length)) {
!       sendDrops++;
        return FAIL;
      }
  
!     call DrainLinkEst.initializeFields(pMsg, id, dest, length);
  
!     return enqueueSend(pMsg);
!   }
  
!   bool cantSend(TOS_MsgPtr pMsg, uint8_t payloadLen) {
  
!     uint16_t usMHLength = offsetof(DrainMsg,data) + payloadLen;
  
!     if (usMHLength > TOSH_DATA_LENGTH) {
!       return TRUE;
!     }
! 
!     if (sendQueueFull) {
!       dbg(DBG_ROUTE, "Drain: sendQueueFull(pMsg=0x%x,len=%d)\n",
! 	  pMsg, payloadLen);
!       return TRUE;
!     }
!     
!     return FALSE;
!   }
  
+   result_t enqueueSend(TOS_MsgPtr pMsg) {
+     
      if (!queuesBusy) {
        if (post QueueServiceTask() == FAIL) {
+ 	sendDrops++;
  	return FAIL;
        } else {
***************
*** 172,185 ****
        }
      }
!       
      sendQueue[sendQueueIn] = pMsg;
      sendQueueIn = (sendQueueIn + 1) % DRAIN_SEND_QUEUE_SIZE;
      if (sendQueueIn == sendQueueOut)
        sendQueueFull = TRUE;
- 
      return SUCCESS;
-   } 
  
!   event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr pMsg) {
      
      DrainMsg *pMHMsg = (DrainMsg *)pMsg->data;
--- 197,213 ----
        }
      }
! 
!     dbg(DBG_ROUTE, "Drain: sendEnterQueue(pMsg=0x%x)\n",
! 	pMsg);
!     
      sendQueue[sendQueueIn] = pMsg;
      sendQueueIn = (sendQueueIn + 1) % DRAIN_SEND_QUEUE_SIZE;
      if (sendQueueIn == sendQueueOut)
        sendQueueFull = TRUE;
      return SUCCESS;
  
!   }
! 
!   event TOS_MsgPtr LinkReceiveMsg.receive(TOS_MsgPtr pMsg) {
      
      DrainMsg *pMHMsg = (DrainMsg *)pMsg->data;
***************
*** 187,192 ****
      uint8_t id = pMHMsg->type;
      
!     dbg(DBG_ROUTE, "Drain: receive(pMsg=0x%x,src=0x%02x,org=0x%02x)\n", 
!         pMsg, pMHMsg->sourceaddr, pMHMsg->originaddr);
  
      signal Snoop.intercept[id](pMsg, &pMHMsg->data[0], payloadLen);
--- 215,220 ----
      uint8_t id = pMHMsg->type;
      
!     dbg(DBG_ROUTE, "Drain: receive(pMsg=0x%x,src=0x%02x,dst=0x%02x)\n", 
!         pMsg, pMHMsg->source, pMHMsg->dest);
  
      signal Snoop.intercept[id](pMsg, &pMHMsg->data[0], payloadLen);
***************
*** 198,205 ****
  					  payloadLen)) == SUCCESS) {
  
! 	dbg(DBG_ROUTE, "Drain: forward(pMsg=0x%x,src=0x%02x,org=0x%02x)\n", 
! 	    pMHMsg->sourceaddr, pMHMsg->originaddr);
  
!         pMsg = mForward(pMsg, id);
        }
      }
--- 226,241 ----
  					  payloadLen)) == SUCCESS) {
  
! 	dbg(DBG_ROUTE, "Drain: forward(pMsg=0x%x,src=0x%02x,dst=0x%02x)\n", 
! 	    pMHMsg->source, pMHMsg->dest);
! 	
! 	if (fwdQueueFull) {
! 	  dbg(DBG_ROUTE, "Drain: forwardQueueFull(pMsg=0x%x)\n", pMsg);
! 	  forwardDrops++;
! 	  return pMsg;
! 	}
  
! 	if (call DrainLinkEst.forwardFields(pMsg)) {
! 	  pMsg = enqueueForward(pMsg);
! 	}
        }
      }
***************
*** 208,225 ****
    }
  
!   TOS_MsgPtr mForward(TOS_MsgPtr pMsg, uint8_t id) {
  
!     TOS_MsgPtr	pNewBuf = pMsg;
  
!     if (fwdQueueFull) {
!       dbg(DBG_ROUTE, "Drain: forwardQueueFull(pMsg=0x%x)\n", pMsg);
!       return pMsg;
      }
  
!     if (call DrainLinkEst.selectRoute(pMsg, id, TRUE) != SUCCESS) {
!       dbg(DBG_ROUTE, "Drain: forwardSelectRouteFail(pMsg=0x%x)\n", pMsg);
!       return pMsg;
!     }
!     
      pNewBuf = fwdQueue[fwdQueueIn];
      fwdQueue[fwdQueueIn] = pMsg;
--- 244,262 ----
    }
  
!   TOS_MsgPtr enqueueForward(TOS_MsgPtr pMsg) {
  
!     TOS_MsgPtr pNewBuf;
  
!     if (!queuesBusy) {
!       if (post QueueServiceTask() == FAIL) {
! 	forwardDrops++;
! 	return pMsg;
!       } else {
! 	queuesBusy = TRUE;
!       }
      }
  
!     dbg(DBG_ROUTE, "Drain: forwardEnterQueue(pMsg=0x%x)\n", pMsg);
!         
      pNewBuf = fwdQueue[fwdQueueIn];
      fwdQueue[fwdQueueIn] = pMsg;
***************
*** 227,239 ****
      if (fwdQueueIn == fwdQueueOut)
        fwdQueueFull = TRUE;
- 
-     dbg(DBG_ROUTE, "Drain: forwardEnterQueue(pMsg=0x%x)\n", pMsg);
      
-     if (!queuesBusy) {
-       if (post QueueServiceTask()) {
- 	queuesBusy = TRUE;
-       }
-     }
- 
      return pNewBuf;
    }
--- 264,268 ----
***************
*** 254,260 ****
        pMsg = sendQueue[sendQueueOut];
  
!       pMsg->ack = 0;
  
!       if (call SendMsg.send(pMsg->addr, pMsg->length, pMsg) == SUCCESS) {
  	// Wait for the sendDone.
        } else {
--- 283,289 ----
        pMsg = sendQueue[sendQueueOut];
  
!       call DrainLinkEst.selectRoute(pMsg);
  
!       if (call LinkSendMsg.send(pMsg->addr, pMsg->length, pMsg) == SUCCESS) {
  	// Wait for the sendDone.
        } else {
***************
*** 272,278 ****
        pMsg = fwdQueue[fwdQueueOut];
  
!       pMsg->ack = 0;
  
!       if (call SendMsg.send(pMsg->addr, pMsg->length, pMsg) == SUCCESS) {
  	// Wait for the sendDone.
        } else {
--- 301,307 ----
        pMsg = fwdQueue[fwdQueueOut];
  
!       call DrainLinkEst.selectRoute(pMsg);
  
!       if (call LinkSendMsg.send(pMsg->addr, pMsg->length, pMsg) == SUCCESS) {
  	// Wait for the sendDone.
        } else {
***************
*** 282,286 ****
  
      } else {
-       
        dbg(DBG_ROUTE, "Drain: queueServiceTask(queuesAllEmpty)\n");
        queuesBusy = FALSE;
--- 311,314 ----
***************
*** 289,293 ****
    }
  
!   event result_t SendMsg.sendDone(TOS_MsgPtr pMsg, result_t success) {
  
      result_t forwardResultVal = SUCCESS;
--- 317,321 ----
    }
  
!   event result_t LinkSendMsg.sendDone(TOS_MsgPtr pMsg, result_t success) {
  
      result_t forwardResultVal = SUCCESS;
***************
*** 298,303 ****
  
      if (pMsg != sendQueue[sendQueueOut] && 
! 	pMsg != fwdQueue[fwdQueueOut]) 
        return SUCCESS;
  
      if (!success) {
--- 326,333 ----
  
      if (pMsg != sendQueue[sendQueueOut] && 
! 	pMsg != fwdQueue[fwdQueueOut]) {
!       // THIS IS A BUG, IF IT HAPPENS.
        return SUCCESS;
+     }
  
      if (!success) {
***************
*** 325,334 ****
  	if (currentFailCount < maxRetransmits) {
  
! 	  // See if we should retransmit
! 	  if (call DrainLinkEst.selectRoute(pMsg, pMsg->type, FALSE) == SUCCESS) {
! 	    post QueueServiceTask();
! 	    return SUCCESS;
! 	  }
! 
  	} else {
  
--- 355,361 ----
  	if (currentFailCount < maxRetransmits) {
  
! 	  post QueueServiceTask();
! 	  return SUCCESS;
! 	  
  	} else {
  
***************
*** 349,353 ****
      if (pMsg == sendQueue[sendQueueOut]) {
  
!       signal Send.sendDone[mhMsg->type](pMsg, forwardResultVal);
  
        sendQueueOut = (sendQueueOut + 1) % DRAIN_SEND_QUEUE_SIZE;
--- 376,382 ----
      if (pMsg == sendQueue[sendQueueOut]) {
  
!       sendPackets++;
! 
!       signal SendMsg.sendDone[mhMsg->type](pMsg, forwardResultVal);
  
        sendQueueOut = (sendQueueOut + 1) % DRAIN_SEND_QUEUE_SIZE;
***************
*** 359,362 ****
--- 388,393 ----
      } else if (pMsg == fwdQueue[fwdQueueOut]) {
  
+       forwardPackets++;
+ 
        fwdQueueOut = (fwdQueueOut + 1) % DRAIN_SEND_QUEUE_SIZE;
        if (fwdQueueFull)
***************
*** 378,381 ****
--- 409,417 ----
    }
  
+   default event result_t SendMsg.sendDone[uint8_t id](TOS_MsgPtr pMsg, 
+ 						      result_t success) {
+     return SUCCESS;
+   }
+ 
    default event result_t Intercept.intercept[uint8_t id](TOS_MsgPtr pMsg, 
  							 void* payload, 



More information about the Tinyos-beta-commits mailing list