[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/net/lqi
LqiForwardingEngineP.nc, 1.1, 1.2 LqiRoutingEngineP.nc, 1.1,
1.2 MultiHopLqiP.nc, 1.1, 1.2
Phil Levis
scipio at users.sourceforge.net
Thu Apr 12 15:42:04 PDT 2007
Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/net/lqi
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv26429
Modified Files:
LqiForwardingEngineP.nc LqiRoutingEngineP.nc MultiHopLqiP.nc
Log Message:
Fix queueing and sequence numbers.
Index: LqiForwardingEngineP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/lqi/LqiForwardingEngineP.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LqiForwardingEngineP.nc 7 Apr 2007 01:58:05 -0000 1.1
--- LqiForwardingEngineP.nc 12 Apr 2007 22:42:02 -0000 1.2
***************
*** 95,98 ****
--- 95,99 ----
interface Receive as SubReceive;
interface AMSend as SubSend;
+ interface AMSend as SubSendMine;
interface RouteControl as RouteSelectCntl;
interface RouteSelect;
***************
*** 101,104 ****
--- 102,106 ----
interface AMPacket;
interface RootControl;
+ interface Random;
interface PacketAcknowledgements;
}
***************
*** 119,123 ****
uint16_t sendFailures = 0;
uint8_t fail_count = 0;
!
lqi_header_t* getHeader(message_t* msg) {
return (lqi_header_t*) call SubPacket.getPayload(msg, NULL);
--- 121,126 ----
uint16_t sendFailures = 0;
uint8_t fail_count = 0;
! int fwdbusy = 0;
!
lqi_header_t* getHeader(message_t* msg) {
return (lqi_header_t*) call SubPacket.getPayload(msg, NULL);
***************
*** 167,171 ****
}
call PacketAcknowledgements.requestAck(pMsg);
! if (call SubSend.send(call AMPacket.destination(pMsg), pMsg, len) != SUCCESS) {
sendFailures++;
return FAIL;
--- 170,174 ----
}
call PacketAcknowledgements.requestAck(pMsg);
! if (call SubSendMine.send(call AMPacket.destination(pMsg), pMsg, len) != SUCCESS) {
sendFailures++;
return FAIL;
***************
*** 200,233 ****
return -1;
}
static message_t* mForward(message_t* msg) {
- message_t* newMsg = msg;
int8_t buf = get_buff();
call Leds.led2Toggle();
!
if (buf == -1) {
! dbg("LQI", "Dropped packet due to no space in queue.\n");
return msg;
}
-
if ((call RouteSelect.selectRoute(msg, 0)) != SUCCESS) {
FwdBufBusy[(uint8_t)buf] = 0;
return msg;
}
!
// Failures at the send level do not cause the seq. number space to be
// rolled back properly. This is somewhat broken.
! call PacketAcknowledgements.requestAck(msg);
! if (call SubSend.send(call AMPacket.destination(msg),
! msg,
! call SubPacket.payloadLength(msg) == SUCCESS)) {
! newMsg = FwdBufList[(uint8_t)buf];
! FwdBufList[(uint8_t)buf] = msg;
}
! else{
! FwdBufBusy[(uint8_t)buf] = 0;
! sendFailures++;
}
- return newMsg;
}
--- 203,253 ----
return -1;
}
+
+ static char* fields(message_t* msg) {
+ static char mbuf[1024];
+ lqi_header_t* hdr = getHeader(msg);
+ sprintf(mbuf, "origin = %hu, seqno = %hu, oseqno = %hu, hopcount =%hu", hdr->originaddr, hdr->seqno, hdr->originseqno, hdr->hopcount);
+ return mbuf;
+ }
+
+ static void forward(message_t* msg);
static message_t* mForward(message_t* msg) {
int8_t buf = get_buff();
call Leds.led2Toggle();
! dbg("LQI", " Asked to forward packet @%s:\t%s\n", sim_time_string(), fields(msg));
if (buf == -1) {
! dbg("LQI", "%s Dropped packet due to no space in queue.\n", __FUNCTION__);
return msg;
}
if ((call RouteSelect.selectRoute(msg, 0)) != SUCCESS) {
FwdBufBusy[(uint8_t)buf] = 0;
+ dbg("LQI", "%s Dropped packet due to no route.\n", __FUNCTION__);
return msg;
}
! else {
! message_t* newMsg = FwdBufList[(uint8_t)buf];
! FwdBufList[(uint8_t)buf] = msg;
! forward(msg);
! return newMsg;
! }
! }
!
! static void forward(message_t* msg) {
// Failures at the send level do not cause the seq. number space to be
// rolled back properly. This is somewhat broken.
! if (fwdbusy) {
! dbg("LQI", "%s forwarding busy, wait for later.\n", __FUNCTION__);
! return;
}
! else {
! call PacketAcknowledgements.requestAck(msg);
! if (call SubSend.send(call AMPacket.destination(msg),
! msg,
! call SubPacket.payloadLength(msg)) == SUCCESS) {
! dbg("LQI", "%s: Send to %hu success.\n", __FUNCTION__, call AMPacket.destination(msg));
! }
! fwdbusy = TRUE;
}
}
***************
*** 238,244 ****
--- 258,266 ----
if (call RootControl.isRoot()) {
+ dbg("LQI", "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 (signal Intercept.forward[id](msg, payload, len)) {
+ dbg("LQI", "LQI fwd is forwarding packet from node %hu @%s\n", getHeader(msg)->originaddr, sim_time_string());
return mForward(msg);
}
***************
*** 248,276 ****
}
!
event void SubSend.sendDone(message_t* msg, error_t success) {
int8_t buf;
if (!call PacketAcknowledgements.wasAcked(msg) &&
call AMPacket.destination(msg) != TOS_BCAST_ADDR &&
fail_count < 5){
call RouteSelect.selectRoute(msg, 1);
if (call SubSend.send(call AMPacket.destination(msg),
msg,
call SubPacket.payloadLength(msg)) == SUCCESS) {
fail_count ++;
} else {
sendFailures++;
}
}
fail_count = 0;
-
buf = is_ours(msg);
!
! if (buf != -1) { // Msg was from forwarding queue
FwdBufBusy[(uint8_t)buf] = 0;
! } else {
! signal Send.sendDone(msg, success);
! }
}
--- 270,345 ----
}
! message_t* nextMsg() {
! int i;
! int inc = call Random.rand16();
! for (i = 0; i < FWD_QUEUE_SIZE; i++) {
! int pindex = (i + inc) % FWD_QUEUE_SIZE;
! if (FwdBufBusy[pindex]) {
! return FwdBufList[pindex];
! }
! }
! return NULL;
! }
!
event void SubSend.sendDone(message_t* msg, error_t success) {
int8_t buf;
+ message_t* nextToSend;
if (!call PacketAcknowledgements.wasAcked(msg) &&
call AMPacket.destination(msg) != TOS_BCAST_ADDR &&
fail_count < 5){
call RouteSelect.selectRoute(msg, 1);
+ call PacketAcknowledgements.requestAck(msg);
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));
fail_count ++;
} else {
+ dbg("LQI", "Packet not acked, retransmit fail:\t%s\n", fields(msg));
sendFailures++;
}
}
+ else if (fail_count >= 5) {
+ dbg("LQI", "Packet failed:\t%s\n", fields(msg));
+ }
+ else if (call PacketAcknowledgements.wasAcked(msg)) {
+ dbg("LQI", "Packet acked:\t%s\n", fields(msg));
+ }
fail_count = 0;
buf = is_ours(msg);
! if (buf != -1) {
FwdBufBusy[(uint8_t)buf] = 0;
! }
!
! nextToSend = nextMsg();
! fwdbusy = FALSE;
!
! if (nextToSend != NULL) {
! forward(nextToSend);
! }
!
! dbg("LQI", "Packet not longer busy:\t%s\n", fields(msg));
! }
!
! 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){
! 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:\t%s\n", fields(msg));
! fail_count ++;
! } else {
! dbg("LQI", "Packet not acked, retransmit fail:\t%s\n", fields(msg));
! sendFailures++;
! }
! }
!
! fail_count = 0;
! signal Send.sendDone(msg, success);
}
***************
*** 351,355 ****
command void* Packet.getPayload(message_t* msg, uint8_t* len) {
void* rval = call SubPacket.getPayload(msg, len);
! *len -= sizeof(lqi_header_t);
rval += sizeof(lqi_header_t);
return rval;
--- 420,426 ----
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);
! }
rval += sizeof(lqi_header_t);
return rval;
Index: LqiRoutingEngineP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/lqi/LqiRoutingEngineP.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** LqiRoutingEngineP.nc 7 Apr 2007 01:58:05 -0000 1.1
--- LqiRoutingEngineP.nc 12 Apr 2007 22:42:02 -0000 1.2
***************
*** 120,124 ****
if (gbCurrentParent != TOS_BCAST_ADDR) {
! dbg("LQO","MultiHopRSSI: Parent = %d\n", gbCurrentParent);
}
--- 120,124 ----
if (gbCurrentParent != TOS_BCAST_ADDR) {
! dbg("LQI","MultiHopRSSI: Parent = %d\n", gbCurrentParent);
}
***************
*** 230,234 ****
return FAIL;
}
!
if (hdr->originaddr != TOS_NODE_ID && resend == 0) {
// supress duplicate packets
--- 230,234 ----
return FAIL;
}
!
if (hdr->originaddr != TOS_NODE_ID && resend == 0) {
// supress duplicate packets
***************
*** 236,239 ****
--- 236,240 ----
if ((gRecentPacketSender[i] == call AMPacket.source(msg)) &&
(gRecentPacketSeqNo[i] == hdr->seqno)) {
+ dbg("LQI", "%s no route as this is a duplicate!\n", __FUNCTION__);
return FAIL;
}
***************
*** 252,255 ****
--- 253,257 ----
gbCurrentParent = TOS_BCAST_ADDR;
gbCurrentHopCount = ROUTE_INVALID;
+ dbg("LQI", "%s no route as we are in a cycle!\n", __FUNCTION__);
return FAIL;
}
***************
*** 259,267 ****
gRecentOriginIndex = (gRecentOriginIndex + 1) % MHOP_HISTORY_SIZE;
}
!
if (resend == 0) {
hdr->seqno = gCurrentSeqNo++;
}
call AMPacket.setDestination(msg, gbCurrentParent);
--- 261,270 ----
gRecentOriginIndex = (gRecentOriginIndex + 1) % MHOP_HISTORY_SIZE;
}
!
if (resend == 0) {
hdr->seqno = gCurrentSeqNo++;
}
+ dbg("LQI", "LQI setting destination to %hu and link quality ?\n", gbCurrentParent);
call AMPacket.setDestination(msg, gbCurrentParent);
***************
*** 274,278 ****
header->originaddr = TOS_NODE_ID;
header->originseqno = gCurrentSeqNo;
!
if (isRoot) {
header->hopcount = 0;
--- 277,282 ----
header->originaddr = TOS_NODE_ID;
header->originseqno = gCurrentSeqNo;
! header->seqno = gCurrentSeqNo;
!
if (isRoot) {
header->hopcount = 0;
***************
*** 282,285 ****
--- 286,290 ----
}
+ dbg("LQI", "LQI setting hopcount to %hhu\n", gbCurrentHopCount);
return SUCCESS;
}
***************
*** 331,335 ****
am_addr_t source = call AMPacket.source(msg);
uint8_t lqi = call CC2420Packet.getLqi(msg);
!
if (source == gbCurrentParent) {
// try to prevent cycles
--- 336,340 ----
am_addr_t source = call AMPacket.source(msg);
uint8_t lqi = call CC2420Packet.getLqi(msg);
! dbg("LQI,LQIRoute", "LQI receiving routing beacon from %hu with LQI %hhu that advertises %hu.\n", source, lqi, bMsg->cost);
if (source == gbCurrentParent) {
// try to prevent cycles
***************
*** 339,342 ****
--- 344,348 ----
gbCurrentLinkEst = adjustLQI(lqi);
gbCurrentHopCount = bMsg->hopcount + 1;
+ dbg("LQI,LQIRoute", " -- Not a loop\n");
}
else {
***************
*** 346,349 ****
--- 352,356 ----
gbCurrentParent = TOS_BCAST_ADDR;
gbCurrentHopCount = ROUTE_INVALID;
+ dbg("LQI,LQIRoute", " -- Detected a loop\n");
}
***************
*** 366,372 ****
--- 373,384 ----
gbCurrentLinkEst = adjustLQI(lqi);
gbCurrentHopCount = bMsg->hopcount + 1;
+ dbg("LQI,LQIRoute", " -- Not a cycle.\n");
+ }
+ else {
+ dbg("LQI,LQIRoute", " -- CYCLE.\n");
}
}
}
+ dbg("LQI,LQIRoute", "Set my count to %hhu, my link to %hu and my cost to %hu.\n", gbCurrentHopCount, gbCurrentLinkEst, gbCurrentParentCost);
return msg;
***************
*** 378,380 ****
}
!
--- 390,392 ----
}
!
Index: MultiHopLqiP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/net/lqi/MultiHopLqiP.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MultiHopLqiP.nc 7 Apr 2007 01:58:05 -0000 1.1
--- MultiHopLqiP.nc 12 Apr 2007 22:42:02 -0000 1.2
***************
*** 88,91 ****
--- 88,92 ----
new AMReceiverC(AM_LQI_BEACON_MSG) as BeaconReceiver,
new AMSenderC(AM_LQI_DATA_MSG) as DataSender,
+ new AMSenderC(AM_LQI_DATA_MSG) as DataSenderMine,
new AMReceiverC(AM_LQI_DATA_MSG) as DataReceiver,
new TimerMilliC(),
***************
*** 115,118 ****
--- 116,120 ----
Forwarder.RouteSelect -> Router;
Forwarder.SubSend -> DataSender;
+ Forwarder.SubSendMine -> DataSenderMine;
Forwarder.SubReceive -> DataReceiver;
Forwarder.Leds -> LedsC;
***************
*** 121,124 ****
--- 123,127 ----
Forwarder.PacketAcknowledgements -> ActiveMessageC;
Forwarder.RootControl -> Router;
+ Forwarder.Random -> RandomC;
Router.AMSend -> BeaconSender;
More information about the Tinyos-2-commits
mailing list