]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/net/ctp/CtpForwardingEngineP.nc
Update git tag release_tinyos_2_1_0_0 for consistency with CVS tag of same name.
[tinyos-2.x.git] / tos / lib / net / ctp / CtpForwardingEngineP.nc
index b436c668d87b45df449e95ef94f92c5cb1c6c5e6..16c1803cc4173593671f793623acb9e0360ab830 100644 (file)
@@ -220,7 +220,7 @@ implementation {
      its queue entry is pointed to by clientPtrs. */
 
   fe_queue_entry_t clientEntries[CLIENT_COUNT];
-  fe_queue_entry_t* clientPtrs[CLIENT_COUNT];
+  fe_queue_entry_t* ONE_NOK clientPtrs[CLIENT_COUNT];
 
   /* The loopback message is for when a collection roots calls
      Send.send. Since Send passes a pointer but Receive allows
@@ -229,7 +229,7 @@ implementation {
      See sendTask(). */
      
   message_t loopbackMsg;
-  message_t* loopbackMsgPtr;
+  message_t* ONE_NOK loopbackMsgPtr;
 
   command error_t Init.init() {
     int i;
@@ -292,7 +292,7 @@ implementation {
   }
 
   ctp_data_header_t* getHeader(message_t* m) {
-    return (ctp_data_header_t*)call SubPacket.getPayload(m, NULL);
+    return (ctp_data_header_t*)call SubPacket.getPayload(m, sizeof(ctp_data_header_t));
   }
  
   /*
@@ -358,8 +358,8 @@ implementation {
     return call Packet.maxPayloadLength();
   }
 
-  command void* Send.getPayload[uint8_t client](message_t* msg) {
-    return call Packet.getPayload(msg, NULL);
+  command void* Send.getPayload[uint8_t client](message_t* msg, uint8_t len) {
+    return call Packet.getPayload(msg, len);
   }
 
   /*
@@ -440,6 +440,10 @@ implementation {
       if (call SentCache.lookup(qe->msg)) {
         call CollectionDebug.logEvent(NET_C_FE_DUPLICATE_CACHE_AT_SEND);
         call SendQueue.dequeue();
+       if (call MessagePool.put(qe->msg) != SUCCESS)
+         call CollectionDebug.logEvent(NET_C_FE_PUT_MSGPOOL_ERR);
+       if (call QEntryPool.put(qe) != SUCCESS)
+         call CollectionDebug.logEvent(NET_C_FE_PUT_QEPOOL_ERR);
         post sendTask();
         return;
       }
@@ -459,8 +463,8 @@ implementation {
        
         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));
+                                                          call Packet.getPayload(loopbackMsgPtr, call Packet.payloadLength(loopbackMsgPtr)), 
+                                                          call Packet.payloadLength(loopbackMsgPtr));
         signal SubSend.sendDone(qe->msg, SUCCESS);
         return;
       }
@@ -638,7 +642,7 @@ implementation {
    * message in the pool, it returns the passed message and does not
    * put it on the send queue.
    */
-  message_t* forward(message_t* m) {
+  message_t* ONE forward(message_t* ONE m) {
     if (call MessagePool.empty()) {
       dbg("Route", "%s cannot forward, message pool empty.\n", __FUNCTION__);
       // send a debug message to the uart
@@ -680,9 +684,11 @@ implementation {
         // Loop-detection code:
         if (call CtpInfo.getEtx(&gradient) == SUCCESS) {
           // We only check for loops if we know our own metric
-          if (call CtpPacket.getEtx(m) < gradient) {
-            // The incoming packet's metric (gradient) is less than our
-            // own gradient.  Trigger a route update and backoff.
+          if (call CtpPacket.getEtx(m) <= gradient) {
+            // If our etx metric is less than or equal to the etx value
+           // on the packet (etx of the previous hop node), then we believe
+           // we are in a loop.
+           // Trigger a route update and backoff.
             call CtpInfo.triggerImmediateRouteUpdate();
             startRetxmitTimer(LOOPY_WINDOW, LOOPY_OFFSET);
             call CollectionDebug.logEventMsg(NET_C_FE_LOOP_DETECTED,
@@ -710,9 +716,9 @@ implementation {
     }
 
     // NB: at this point, we have a resource acquistion problem.
-    // Trigger an immediate route update, log the event, and drop the
+    // Log the event, and drop the
     // packet on the floor.
-    call CtpInfo.triggerImmediateRouteUpdate();
+
     call CollectionDebug.logEvent(NET_C_FE_SEND_QUEUE_FULL);
     return m;
   }
@@ -727,7 +733,6 @@ implementation {
    */ 
   event message_t* 
   SubReceive.receive(message_t* msg, void* payload, uint8_t len) {
-    uint8_t netlen;
     collection_id_t collectid;
     bool duplicate = FALSE;
     fe_queue_entry_t* qe;
@@ -745,7 +750,7 @@ implementation {
     call CollectionDebug.logEventMsg(NET_C_FE_RCV_MSG,
                                         call CollectionPacket.getSequenceNumber(msg), 
                                         call CollectionPacket.getOrigin(msg), 
-                                         call AMPacket.destination(msg));
+                                    thl--);
     if (len > call SubSend.maxPayloadLength()) {
       return msg;
     }
@@ -775,13 +780,13 @@ implementation {
     // If I'm the root, signal receive. 
     else if (call RootControl.isRoot())
       return signal Receive.receive[collectid](msg, 
-                        call Packet.getPayload(msg, &netlen), 
-                        call Packet.payloadLength(msg));
+                                              call Packet.getPayload(msg, call Packet.payloadLength(msg)), 
+                                              call Packet.payloadLength(msg));
     // I'm on the routing path and Intercept indicates that I
     // should not forward the packet.
     else if (!signal Intercept.forward[collectid](msg, 
-                        call Packet.getPayload(msg, &netlen), 
-                        call Packet.payloadLength(msg)))
+                                                 call Packet.getPayload(msg, call Packet.payloadLength(msg)), 
+                                                 call Packet.payloadLength(msg)))
       return msg;
     else {
       dbg("Route", "Forwarding packet from %hu.\n", getHeader(msg)->origin);
@@ -789,25 +794,6 @@ implementation {
     }
   }
 
-  command void* 
-  Receive.getPayload[collection_id_t id](message_t* msg, uint8_t* len) {
-    return call Packet.getPayload(msg, NULL);
-  }
-
-  command uint8_t
-  Receive.payloadLength[collection_id_t id](message_t *msg) {
-    return call Packet.payloadLength(msg);
-  }
-
-  command void *
-  Snoop.getPayload[collection_id_t id](message_t *msg, uint8_t *len) {
-    return call Packet.getPayload(msg, NULL);
-  }
-
-  command uint8_t Snoop.payloadLength[collection_id_t id](message_t *msg) {
-    return call Packet.payloadLength(msg);
-  }
-
   event message_t* 
   SubSnoop.receive(message_t* msg, void *payload, uint8_t len) {
     //am_addr_t parent = call UnicastNameFreeRouting.nextHop();
@@ -815,8 +801,9 @@ implementation {
 
     // Check for the pull bit (P) [TEP123] and act accordingly.  This
     // check is made for all packets, not just ones addressed to us.
-    if (call CtpPacket.option(msg, CTP_OPT_PULL))
+    if (call CtpPacket.option(msg, CTP_OPT_PULL)) {
       call CtpInfo.triggerRouteUpdate();
+    }
 
     call CtpInfo.setNeighborCongested(proximalSrc, call CtpPacket.option(msg, CTP_OPT_ECN));
     return signal Snoop.receive[call CtpPacket.getType(msg)] 
@@ -870,12 +857,12 @@ implementation {
     return call SubPacket.maxPayloadLength() - sizeof(ctp_data_header_t);
   }
 
-  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-    uint8_t* payload = call SubPacket.getPayload(msg, len);
-    if (len != NULL) {
-      *len -= sizeof(ctp_data_header_t);
+  command void* Packet.getPayload(message_t* msg, uint8_t len) {
+    uint8_t* payload = call SubPacket.getPayload(msg, len + sizeof(ctp_data_header_t));
+    if (payload != NULL) {
+      payload += sizeof(ctp_data_header_t);
     }
-    return payload + sizeof(ctp_data_header_t);
+    return payload;
   }
 
   command am_addr_t       CollectionPacket.getOrigin(message_t* msg) {return getHeader(msg)->origin;}
@@ -935,7 +922,7 @@ implementation {
 
   default event bool
   Intercept.forward[collection_id_t collectid](message_t* msg, void* payload, 
-                                               uint16_t len) {
+                                               uint8_t len) {
     return TRUE;
   }