// $Id$
-
/* Copyright (c) 2007 Stanford University.
* All rights reserved.
*
enum {
FWD_QUEUE_SIZE = MHOP_QUEUE_SIZE, // Forwarding Queue
- EMPTY = 0xff
+ EMPTY = 0xff,
+ MAX_RETRIES = 5
};
/* Internal storage and scheduling state */
uint8_t FwdBufBusy[FWD_QUEUE_SIZE];
uint8_t iFwdBufHead, iFwdBufTail;
uint16_t sendFailures = 0;
- uint8_t fail_count = 0;
+ uint8_t fwd_fail_count = 0;
+ uint8_t my_fail_count = 0;
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));
}
/***********************************************************************
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;
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);
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]) {
message_t* nextToSend;
if (!call PacketAcknowledgements.wasAcked(msg) &&
call AMPacket.destination(msg) != TOS_BCAST_ADDR &&
- fail_count < 5){
+ fwd_fail_count < MAX_RETRIES){
call RouteSelect.selectRoute(msg, 1);
call PacketAcknowledgements.requestAck(msg);
if (call SubSend.send(call AMPacket.destination(msg),
call CollectionPacket.getSequenceNumber(msg),
call CollectionPacket.getOrigin(msg),
call AMPacket.destination(msg));
- fail_count ++;
+ fwd_fail_count ++;
return;
} else {
call CollectionDebug.logEventMsg(NET_C_FE_SENDDONE_FAIL,
return;
}
}
- else if (fail_count >= 5) {
+ else if (fwd_fail_count >= MAX_RETRIES) {
call CollectionDebug.logEventMsg(NET_C_FE_SENDDONE_FAIL_ACK_FWD,
call CollectionPacket.getSequenceNumber(msg),
call CollectionPacket.getOrigin(msg),
call AMPacket.destination(msg));
}
- fail_count = 0;
+ fwd_fail_count = 0;
buf = is_ours(msg);
if (buf != -1) {
FwdBufBusy[(uint8_t)buf] = 0;
event void SubSendMine.sendDone(message_t* msg, error_t success) {
if (!call PacketAcknowledgements.wasAcked(msg) &&
call AMPacket.destination(msg) != TOS_BCAST_ADDR &&
- fail_count < 5){
+ my_fail_count < MAX_RETRIES){
call RouteSelect.selectRoute(msg, 1);
call PacketAcknowledgements.requestAck(msg);
if (call SubSendMine.send(call AMPacket.destination(msg),
msg,
call SubPacket.payloadLength(msg)) == SUCCESS) {
- dbg("LQI", "Packet not acked, retransmit (%hhu) @%s:\n\t%s\n", fail_count, sim_time_string(), fields(msg));
+ dbg("LQI", "Packet not acked, retransmit (%hhu) @%s:\n\t%s\n", my_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 ++;
+ my_fail_count ++;
return;
} else {
call CollectionDebug.logEventMsg(NET_C_FE_SENDDONE_FAIL,
return;
}
}
- else if (fail_count >= 5) {
+ else if (my_fail_count >= MAX_RETRIES) {
call CollectionDebug.logEventMsg(NET_C_FE_SENDDONE_FAIL_ACK_SEND,
call CollectionPacket.getSequenceNumber(msg),
call CollectionPacket.getOrigin(msg),
call AMPacket.destination(msg));
}
- fail_count = 0;
+ my_fail_count = 0;
signal Send.sendDone(msg, success);
}
}
- 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() {
}
- 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);
}
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;
}
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;}
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;
+ }
}