/* Tracks our parent's congestion state. */
bool parentCongested = FALSE;
+ /* Threshold for congestion */
+ uint8_t congestionThreshold;
+
/* Keeps track of whether the routing layer is running; if not,
* it will not send packets. */
bool running = FALSE;
clientPtrs[i] = clientEntries + i;
dbg("Forwarder", "clientPtrs[%hhu] = %p\n", i, clientPtrs[i]);
}
+ congestionThreshold = (call SendQueue.maxSize()) >> 1;
loopbackMsgPtr = &loopbackMsg;
lastParent = call AMPacket.address();
seqno = 0;
}
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));
}
/*
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);
}
/*
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;
}
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;
}
call CollectionDebug.logEvent(NET_C_FE_PUT_QEPOOL_ERR);
sending = FALSE;
startRetxmitTimer(SENDDONE_OK_WINDOW, SENDDONE_OK_OFFSET);
- call Leds.led2Toggle();
}
else {
dbg("Forwarder", "%s: BUG: we have a pool entry, but the pool is full, client is %hhu.\n", __FUNCTION__, qe->client);
// 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,
*/
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;
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;
}
// 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);
}
}
- 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();
command bool CtpCongestion.isCongested() {
// A simple predicate for now to determine congestion state of
// this node.
- bool congested = (call SendQueue.size() + 2 >= call SendQueue.maxSize()) ?
+ bool congested = (call SendQueue.size() > congestionThreshold) ?
TRUE : FALSE;
return ((congested || clientCongested)?TRUE:FALSE);
}
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;}