[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/net/collection ForwardingEngineP.nc, 1.1.2.14, 1.1.2.15 QueueC.nc, 1.1.2.3, 1.1.2.4 TreeCollectionC.nc, 1.1.2.9, 1.1.2.10

Phil Levis scipio at users.sourceforge.net
Wed Jun 7 16:39:05 PDT 2006


Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/net/collection
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv18549/collection

Modified Files:
      Tag: tinyos-2_0_devel-BRANCH
	ForwardingEngineP.nc QueueC.nc TreeCollectionC.nc 
Log Message:
Fix a queuing bug.


Index: ForwardingEngineP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/collection/Attic/ForwardingEngineP.nc,v
retrieving revision 1.1.2.14
retrieving revision 1.1.2.15
diff -C2 -d -r1.1.2.14 -r1.1.2.15
*** ForwardingEngineP.nc	7 Jun 2006 21:21:11 -0000	1.1.2.14
--- ForwardingEngineP.nc	7 Jun 2006 23:39:03 -0000	1.1.2.15
***************
*** 82,91 ****
    fe_queue_entry_t clientEntries[CLIENT_COUNT];
    fe_queue_entry_t* clientPtrs[CLIENT_COUNT];
    
    command error_t Init.init() {
      int i;
      for (i = 0; i < CLIENT_COUNT; i++) {
!       clientPtrs[i] = &clientEntries[i];
      }
      return SUCCESS;
    }
--- 82,97 ----
    fe_queue_entry_t clientEntries[CLIENT_COUNT];
    fe_queue_entry_t* clientPtrs[CLIENT_COUNT];
+ 
+ 
+   message_t loopbackMsg;
+   message_t* loopbackMsgPtr;
    
    command error_t Init.init() {
      int i;
      for (i = 0; i < CLIENT_COUNT; i++) {
!       clientPtrs[i] = clientEntries + i;
!       dbg("Forwarder", "clientPtrs[%hhu] = %p\n", i, clientPtrs[i]);
      }
+     loopbackMsgPtr = &loopbackMsg;
      return SUCCESS;
    }
***************
*** 137,141 ****
      network_header_t* hdr;
      fe_queue_entry_t *qe;
!     
      if (!running) {return EOFF;}
      
--- 143,147 ----
      network_header_t* hdr;
      fe_queue_entry_t *qe;
!     dbg("Forwarder", "%s: sending packet from client %hhu: %x, len %hhu\n", __FUNCTION__, client, msg, len);
      if (!running) {return EOFF;}
      
***************
*** 153,157 ****
      qe->msg = msg;
      qe->client = client;
!     
      if (call SendQueue.enqueue(qe) == SUCCESS) {
        if (radioOn && call SendQueue.size() == 1) {
--- 159,163 ----
      qe->msg = msg;
      qe->client = client;
!     dbg("Forwarder", "%s: queue entry for %hhu is %x\n", __FUNCTION__, client, qe);
      if (call SendQueue.enqueue(qe) == SUCCESS) {
        if (radioOn && call SendQueue.size() == 1) {
***************
*** 185,203 ****
    // queue until it is successfully sent.
    task void sendTask() {
!     dbg("Forwarder", "%s: Trying to send a packet.\n", __FUNCTION__);
      if (sending) {
        dbg("Forwarder", "%s: busy, don't send\n", __FUNCTION__);
        return;
      }
!     if (call SendQueue.empty()) {
        dbg("Forwarder", "%s: queue empty, don't send\n", __FUNCTION__);
        return;
      }
!     if (!call UnicastNameFreeRouting.hasRoute()) {
        dbg("Forwarder", "%s: no route, don't send, start retry timer\n", __FUNCTION__);
        call RetxmitTimer.startOneShot(10000);
        return;
      }
- 
      else {
        error_t eval;
--- 191,208 ----
    // queue until it is successfully sent.
    task void sendTask() {
!     dbg("Forwarder", "%s: Trying to send a packet. Queue size is %hhu.\n", __FUNCTION__, call SendQueue.size());
      if (sending) {
        dbg("Forwarder", "%s: busy, don't send\n", __FUNCTION__);
        return;
      }
!     else if (call SendQueue.empty()) {
        dbg("Forwarder", "%s: queue empty, don't send\n", __FUNCTION__);
        return;
      }
!     else if (!call UnicastNameFreeRouting.hasRoute()) {
        dbg("Forwarder", "%s: no route, don't send, start retry timer\n", __FUNCTION__);
        call RetxmitTimer.startOneShot(10000);
        return;
      }
      else {
        error_t eval;
***************
*** 205,208 ****
--- 210,226 ----
        uint8_t payloadLen = call SubPacket.payloadLength(qe->msg);
        am_addr_t dest = call UnicastNameFreeRouting.nextHop();
+       dbg("Forwarder", "Sending queue entry %p\n", qe);
+       if (call RootControl.isRoot()) {
+ 	collection_id_t collectid = getHeader(qe->msg)->collectid;
+ 	memcpy(loopbackMsgPtr, qe->msg, sizeof(message_t));
+ 	ackPending = FALSE;
+ 	
+ 	dbg("Forwarder", "%s: I'm a root, so loopback and signal receive.\n", __FUNCTION__);
+ 	loopbackMsgPtr = signal Receive.receive[collectid](loopbackMsgPtr,
+ 							  call Packet.getPayload(loopbackMsgPtr, NULL), 
+ 							  call Packet.payloadLength(loopbackMsgPtr));
+ 	signal SubSend.sendDone(qe->msg, SUCCESS);
+ 	return;
+       }
        
        ackPending = (call PacketAcknowledgements.requestAck(qe->msg) == SUCCESS);
***************
*** 213,223 ****
  	sending = TRUE;
  	dbg("Forwarder", "%s: subsend succeeded.\n", __FUNCTION__);
! 	if (qe >= clientEntries && qe <= clientEntries + (CLIENT_COUNT - 1)) {
! 	  dbg("Forwarder", "%s: client packet, put queue entry back in array.\n", __FUNCTION__);
! 	  clientPtrs[qe->client] = qe;
  	}
  	else {
! 	  dbg("Forwarder", "%s: forwarded packet, put queue entry back in pool.\n", __FUNCTION__);
! 	  call QEntryPool.put(qe);
  	}
          return;
--- 231,239 ----
  	sending = TRUE;
  	dbg("Forwarder", "%s: subsend succeeded.\n", __FUNCTION__);
! 	if (qe->client < CLIENT_COUNT) {
! 	  dbg("Forwarder", "%s: client packet.\n", __FUNCTION__);
  	}
  	else {
! 	  dbg("Forwarder", "%s: forwarded packet.\n", __FUNCTION__);
  	}
          return;
***************
*** 231,235 ****
        }
        else if (eval == EBUSY) {
!         // This shouldn't happen, as we sit on top of a client and
          // control our own output; it means we're trying to
          // double-send (bug). This means we expect a sendDone, so just
--- 247,251 ----
        }
        else if (eval == EBUSY) {
! 	// This shouldn't happen, as we sit on top of a client and
          // control our own output; it means we're trying to
          // double-send (bug). This means we expect a sendDone, so just
***************
*** 243,246 ****
--- 259,263 ----
    event void SubSend.sendDone(message_t* msg, error_t error) {
      fe_queue_entry_t *qe = call SendQueue.head();
+     dbg("Forwarder", "%s with %x and %hhu\n", __FUNCTION__, msg, error);
      if (qe == NULL || qe->msg != msg) {
        // Not our packet, something is very wrong...
***************
*** 254,257 ****
--- 271,275 ----
        r += 512;
        call RetxmitTimer.startOneShot(r);
+       dbg("Forwarder", "%s: send failed, retry in %hu ms\n", __FUNCTION__, r);
      }
      // AckPending is for case when DL cannot support acks
***************
*** 263,273 ****
        r += 128;
        call RetxmitTimer.startOneShot(r);
      }
!     else if (getHeader(qe->msg)->origin == TOS_NODE_ID) {
        network_header_t* hdr;
!       call SendQueue.dequeue();
        hdr = getHeader(qe->msg);
!       if (qe->client < CLIENT_COUNT)
!         signal Send.sendDone[qe->client](msg, SUCCESS);
        sending = FALSE;
        post sendTask();
--- 281,295 ----
        r += 128;
        call RetxmitTimer.startOneShot(r);
+       dbg("Forwarder", "%s: not acked, retry in %hu ms\n", __FUNCTION__, r);
      }
!     else if (qe->client < CLIENT_COUNT) {
        network_header_t* hdr;
!       uint8_t client = qe->client;
!       dbg("Forwarder", "%s: our packet for client %hhu, remove %p from queue\n", __FUNCTION__, client, qe);
!       clientPtrs[client] = qe;
        hdr = getHeader(qe->msg);
!       call SendQueue.dequeue();
!       call QEntryPool.put(qe);      
!       signal Send.sendDone[client](msg, SUCCESS);
        sending = FALSE;
        post sendTask();
***************
*** 275,282 ****
      else if (call MessagePool.size() < call MessagePool.maxSize()) {
        // A successfully forwarded packet.
        call MessagePool.put(qe->msg);
      }
      else {
!       // It's a forwarded packet, but there's no room the pool;
        // someone has double-stored a pointer somewhere and we have nowhere
        // to put this, so we have to leak it...
--- 297,310 ----
      else if (call MessagePool.size() < call MessagePool.maxSize()) {
        // A successfully forwarded packet.
+       dbg("Forwarder", "%s: successfully forwarded packet (client: %hhu).\n", __FUNCTION__, qe->client);
+       call SendQueue.dequeue();
        call MessagePool.put(qe->msg);
+       call QEntryPool.put(qe);      
+       sending = FALSE;
+       post sendTask();
      }
      else {
!       dbg("Forwarder", "%s: BUG: we have a pool entry, but the pool is full, client is %hhu.\n", __FUNCTION__, qe->client);
!     // It's a forwarded packet, but there's no room the pool;
        // someone has double-stored a pointer somewhere and we have nowhere
        // to put this, so we have to leak it...
***************
*** 292,300 ****
  
        qe->msg = m;
!       qe->client = CLIENT_COUNT;
! 
        call Packet.setPayloadLength(m, len + sizeof(network_header_t));
!       if (call SendQueue.enqueue(qe))
!         return newMsg;
        else {
          call MessagePool.put(newMsg);
--- 320,333 ----
  
        qe->msg = m;
!       qe->client = 0xff;
!       
        call Packet.setPayloadLength(m, len + sizeof(network_header_t));
!       if (call SendQueue.enqueue(qe) == SUCCESS) {
! 	dbg("Forwarder", "%s forwarding packet with queue size %hhu and entry %p\n", __FUNCTION__, call SendQueue.size(), qe);
! 	if (call SendQueue.size() == 1) {
! 	  post sendTask();
! 	}
! 	return newMsg;
!       }
        else {
          call MessagePool.put(newMsg);

Index: QueueC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/collection/Attic/QueueC.nc,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -C2 -d -r1.1.2.3 -r1.1.2.4
*** QueueC.nc	16 May 2006 17:36:42 -0000	1.1.2.3
--- QueueC.nc	7 Jun 2006 23:39:03 -0000	1.1.2.4
***************
*** 56,65 ****
--- 56,81 ----
    }
  
+   void printQueue() {
+     int i, j;
+     dbg("QueueC", "head <-");
+     for (i = head; i < head + size; i++) {
+       dbg_clear("QueueC", "[");
+       for (j = 0; j < sizeof(queue_t); j++) {
+ 	uint8_t v = ((uint8_t*)&queue[i % QUEUE_SIZE])[j];
+ 	dbg_clear("QueueC", "%0.2hhx", v);
+       }
+       dbg_clear("QueueC", "] ");
+     }
+     dbg_clear("QueueC", "<- tail\n");
+   }
+   
    command queue_t Queue.dequeue() {
      queue_t t = call Queue.head();
+     dbg("QueueC", "%s: size is %hhu\n", __FUNCTION__, size);
      if (!call Queue.empty()) {
        head++;
        head %= QUEUE_SIZE;
        size--;
+       printQueue();
      }
      return t;
***************
*** 68,74 ****
--- 84,93 ----
    command error_t Queue.enqueue(queue_t newVal) {
      if (call Queue.size() < call Queue.maxSize()) {
+       dbg("QueueC", "%s: size is %hhu\n", __FUNCTION__, size);
        queue[tail] = newVal;
        tail++;
+       tail %= QUEUE_SIZE;
        size++;
+       printQueue();
        return SUCCESS;
      }

Index: TreeCollectionC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/collection/Attic/TreeCollectionC.nc,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -C2 -d -r1.1.2.9 -r1.1.2.10
*** TreeCollectionC.nc	7 Jun 2006 21:21:11 -0000	1.1.2.9
--- TreeCollectionC.nc	7 Jun 2006 23:39:03 -0000	1.1.2.10
***************
*** 36,40 ****
    Packet = Forwarder;
    CollectionId = Forwarder;
-   MainC.SoftwareInit -> Forwarder;
    
    components new PoolC(message_t, FORWARD_COUNT) as MessagePoolP;
--- 36,39 ----
***************
*** 72,76 ****
    Router.Random -> RandomC;
    Forwarder.Random -> RandomC;
!   
    Forwarder.SubSend -> AMSenderC;
    Forwarder.SubReceive -> AMReceiverC;
--- 71,76 ----
    Router.Random -> RandomC;
    Forwarder.Random -> RandomC;
! 
!   MainC.SoftwareInit -> Forwarder;
    Forwarder.SubSend -> AMSenderC;
    Forwarder.SubReceive -> AMReceiverC;



More information about the Tinyos-2-commits mailing list