]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/net/lqi/LqiForwardingEngineP.nc
The big interface switchover for Packet, Send, Receive, and AMSend.
[tinyos-2.x.git] / tos / lib / net / lqi / LqiForwardingEngineP.nc
index 2029bb9672203d4454650d0024ebf337db6914a1..45cba9dc0816c7eab1961f746ce9982dacbf13d1 100644 (file)
@@ -1,6 +1,5 @@
 // $Id$
 
-
 /* Copyright (c) 2007 Stanford University.
  * All rights reserved.
  *
@@ -125,7 +124,7 @@ implementation {
   int fwdbusy = 0;
   
   lqi_header_t* getHeader(message_t* msg) {
-    return (lqi_header_t*) call SubPacket.getPayload(msg, NULL);
+    return (lqi_header_t*) call SubPacket.getPayload(msg, sizeof(lqi_header_t));
   }
   
   /***********************************************************************
@@ -249,6 +248,10 @@ implementation {
       if (call SubSend.send(call AMPacket.destination(msg),
                            msg,
                            call SubPacket.payloadLength(msg)) == SUCCESS) {
+       call CollectionDebug.logEventMsg(NET_C_DBG_1, 
+                                        call CollectionPacket.getSequenceNumber(msg), 
+                                        call CollectionPacket.getOrigin(msg), 
+                                        call AMPacket.destination(msg));
        dbg("LQI", "%s: Send to %hu success.\n", __FUNCTION__, call AMPacket.destination(msg));
       }
       fwdbusy = TRUE;
@@ -260,10 +263,17 @@ implementation {
     payload += sizeof(lqi_header_t);
     len -= sizeof(lqi_header_t);
 
+    call CollectionDebug.logEventMsg(NET_C_FE_RCV_MSG, 
+                                    call CollectionPacket.getSequenceNumber(msg), 
+                                    call CollectionPacket.getOrigin(msg), 
+                                    call AMPacket.destination(msg));
     if (call RootControl.isRoot()) {
       dbg("LQI,LQIDeliver", "LQI Root is receiving packet from node %hu @%s\n", getHeader(msg)->originaddr, sim_time_string());
       return signal Receive.receive[id](msg, payload, len);
     }
+    else if (call AMPacket.destination(msg) != call AMPacket.address()) {
+      return msg;
+    }
     else if (signal Intercept.forward[id](msg, payload, len)) {
       dbg("LQI,LQIDeliver", "LQI fwd is forwarding packet from node %hu @%s\n", getHeader(msg)->originaddr, sim_time_string());
       return mForward(msg);
@@ -275,7 +285,7 @@ implementation {
   
   message_t* nextMsg() {
     int i;
-    int inc = call Random.rand16();
+    uint16_t inc = call Random.rand16() & 0xfff;
     for (i = 0; i < FWD_QUEUE_SIZE; i++) {
       int pindex = (i + inc) % FWD_QUEUE_SIZE;
       if (FwdBufBusy[pindex]) {
@@ -296,19 +306,21 @@ implementation {
       if (call SubSend.send(call AMPacket.destination(msg),
                            msg,
                            call SubPacket.payloadLength(msg)) == SUCCESS) {
-       dbg("LQI", "Packet not acked, retransmit:\t%s\n", fields(msg));
+       dbg("LQI", "Packet not acked, retransmit @%s:\n\t%s\n", sim_time_string(), fields(msg));
         call CollectionDebug.logEventMsg(NET_C_FE_SENDDONE_WAITACK, 
                                         call CollectionPacket.getSequenceNumber(msg), 
                                         call CollectionPacket.getOrigin(msg), 
                                          call AMPacket.destination(msg));
        fail_count ++;
+       return;
       } else {
        call CollectionDebug.logEventMsg(NET_C_FE_SENDDONE_FAIL, 
                                         call CollectionPacket.getSequenceNumber(msg), 
                                         call CollectionPacket.getOrigin(msg), 
                                          call AMPacket.destination(msg));
-       dbg("LQI", "Packet not acked, retransmit fail:\t%s\n", fields(msg));
+       dbg("LQI", "Packet not acked, retransmit fail @%s:\n\t%s\n", sim_time_string(), fields(msg));
        sendFailures++;
+       return;
       }
     }
     else if (fail_count >= 5) {
@@ -351,19 +363,21 @@ implementation {
       if (call SubSendMine.send(call AMPacket.destination(msg),
                            msg,
                            call SubPacket.payloadLength(msg)) == SUCCESS) {
-       dbg("LQI", "Packet not acked, retransmit:\t%s\n", fields(msg));
+       dbg("LQI", "Packet not acked, retransmit (%hhu) @%s:\n\t%s\n", fail_count, sim_time_string(), fields(msg));
        call CollectionDebug.logEventMsg(NET_C_FE_SENDDONE_WAITACK, 
                                         call CollectionPacket.getSequenceNumber(msg), 
                                         call CollectionPacket.getOrigin(msg), 
                                          call AMPacket.destination(msg));
        fail_count ++;
+       return;
       } else {
        call CollectionDebug.logEventMsg(NET_C_FE_SENDDONE_FAIL, 
                                         call CollectionPacket.getSequenceNumber(msg), 
                                         call CollectionPacket.getOrigin(msg), 
                                          call AMPacket.destination(msg));
-       dbg("LQI", "Packet not acked, retransmit fail:\t%s\n", fields(msg));
+       dbg("LQI", "Packet not acked, retransmit fail @%s:\n\t%s\n", sim_time_string(), fields(msg));
        sendFailures++;
+       return;
       }
     }
     else if (fail_count >= 5) {
@@ -421,8 +435,8 @@ implementation {
     
   }
 
-  command void* Send.getPayload(message_t* m) {
-    return call Packet.getPayload(m, NULL);
+  command void* Send.getPayload(message_t* m, uint8_t len) {
+    return call Packet.getPayload(m, len);
   }
 
   command uint8_t Send.maxPayloadLength() {
@@ -434,22 +448,6 @@ implementation {
   }
 
   
-  command void* Receive.getPayload[collection_id_t id](message_t* msg, uint8_t* len) {
-    return call Packet.getPayload(msg, len);
-  }
-  
-  command uint8_t Receive.payloadLength[collection_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-
-  command void* Snoop.getPayload[collection_id_t id](message_t* msg, uint8_t* len) {
-    return call Packet.getPayload(msg, len);
-  }
-  
-  command uint8_t Snoop.payloadLength[collection_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-  
   command uint8_t Packet.payloadLength(message_t* msg) {
     return call SubPacket.payloadLength(msg) - sizeof(lqi_header_t);
   }
@@ -459,12 +457,11 @@ implementation {
   command uint8_t Packet.maxPayloadLength() {
     return (call SubPacket.maxPayloadLength() - sizeof(lqi_header_t));
   }
-  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-    void* rval = call SubPacket.getPayload(msg, len);
-    if (len != NULL) {
-      *len -= sizeof(lqi_header_t);
+  command void* Packet.getPayload(message_t* msg, uint8_t len) {
+    void* rval = call SubPacket.getPayload(msg, len + sizeof(lqi_header_t));
+    if (rval != NULL) {
+      rval += sizeof(lqi_header_t);
     }
-    rval += sizeof(lqi_header_t);
     return rval;
   }
 
@@ -495,6 +492,8 @@ implementation {
     lqi_header_t* hdr = getHeader(msg);
     hdr->originseqno = seqno;
   }
+
+
   
  default event void Send.sendDone(message_t* pMsg, error_t success) {}
  default event message_t* Snoop.receive[collection_id_t id](message_t* pMsg, void* payload, uint8_t len) {return pMsg;}
@@ -504,5 +503,25 @@ implementation {
  default event bool Intercept.forward[collection_id_t id](message_t* pMsg, void* payload, uint16_t len) {
    return 1;
  }
+
+  /* Default implementations for CollectionDebug calls.
+   * These allow CollectionDebug not to be wired to anything if debugging
+   * is not desired. */
+    
+  default command error_t CollectionDebug.logEvent(uint8_t type) {
+    return SUCCESS;
+  }
+  default command error_t CollectionDebug.logEventSimple(uint8_t type, uint16_t arg) {
+    return SUCCESS;
+  }
+  default command error_t CollectionDebug.logEventDbg(uint8_t type, uint16_t arg1, uint16_t arg2, uint16_t arg3) {
+    return SUCCESS;
+  }
+  default command error_t CollectionDebug.logEventMsg(uint8_t type, uint16_t msg, am_addr_t origin, am_addr_t node) {
+    return SUCCESS;
+  }
+  default command error_t CollectionDebug.logEventRoute(uint8_t type, am_addr_t parent, uint8_t hopcount, uint16_t metric) {
+    return SUCCESS;
+  }
 }