我目前正在为 TinyOS 实现 AODV 协议,当网络层向应用程序发送有关收到消息的信号时,我看到了奇怪的行为。
下面是相关的应用程序和 AODV 库代码 + 一些调试输出,以显示正在发生的事情。
测试应用
配置
configuration BasicTestAppC{
}
implementation{
components MainC, BasicTestC, AODV, LedsC;
BasicTestC.Boot->MainC.Boot;
BasicTestC.SplitControl->AODV.SplitControl;
BasicTestC.AMSend->AODV.AMSend[1];
BasicTestC.Receive->AODV.Receive[1];
...
}
执行
#include "BasicTest.h"
module BasicTestC {
uses {
interface Boot;
interface SplitControl;
interface Timer<TMilli> as MilliTimer;
interface AMSend;
interface Receive;
interface Leds;
interface Packet;
}
}
implementation {
message_t pkt;
message_t * p_pkt;
uint16_t src = 0x0007;
uint16_t dest = 0x000A;
uint16_t ctr = 0;
test_msg* test_pkt;
test_msg* rcv_pkt;
...
//Send counter value to node 10 on every timer tick
event void MilliTimer.fired() {
call Leds.led0Toggle();
ctr = ctr + 1;
test_pkt = (test_msg*)(call Packet.getPayload(p_pkt, sizeof (test_msg)));
test_pkt->counter = ctr;
call AMSend.send(dest, p_pkt, sizeof(test_msg));
}
event void AMSend.sendDone(message_t * bufPtr, error_t error) {
test_pkt = (test_msg*)(call Packet.getPayload(p_pkt, sizeof (test_msg)));
dbg("APPS", "%s\t APPS: sendDone!! (error=%d) ctr=%u\n", sim_time_string(), error, test_pkt->counter);
}
event message_t* Receive.receive(message_t * bufPtr, void * payload, uint8_t len) {
rcv_pkt = (test_msg * ) payload;
dbg("APPS", "%s\t APPS: receive!! %u\n", sim_time_string(), rcv_pkt->counter);
return bufPtr;
}
}
AODV 模块
处理来自 AMReceiverC 组件的接收事件:
event message_t* SubReceive.receive( message_t* p_msg, void* payload, uint8_t len ) {
uint8_t i;
aodv_msg_hdr* aodv_hdr = (aodv_msg_hdr*)(p_msg->data);
test_msg_y* tmp;
uint16_t ctr;
dbg("AODV", "%s\t AODV: SubReceive.receive() dest: %d src:%d\n", sim_time_string(), aodv_hdr->dest, aodv_hdr->src);
if( aodv_hdr->dest == call AMPacket.address() ) {
for( i=0;i<len;i++ ) {
p_app_msg_->data[i] = aodv_hdr->data[i];
}
tmp = (test_msg_y*) p_app_msg_->data;
ctr = tmp->counter;
//Send signal to application layer
p_msg = signal Receive.receive[aodv_hdr->app]( p_app_msg_, p_app_msg_->data, len - AODV_MSG_HEADER_LEN );
dbg("AODV", "%s\t AODV: SubReceive.receive() delivered to upper layer - %u\n", sim_time_string(), ctr);
} else {
am_addr_t nexthop = get_next_hop( aodv_hdr->dest );
dbg("AODV", "%s\t AODV: SubReceive.receive() deliver to next hop:%x\n", sim_time_string(), nexthop);
/* If there is a next-hop for the destination of the message,
the message will be forwarded to the next-hop. */
if (nexthop != INVALID_NODE_ID) {
forwardMSG( p_msg, nexthop, len );
}
}
return p_msg;
}
调试输出
DEBUG (7): 0:0:2.006653503 APPS: sendDone!! (error=0) ctr=2
DEBUG (10): 0:0:2.019577622 AODV: SubReceive.receive() dest: 10 src:7
DEBUG (10): 0:0:2.019577622 AODV: SubReceive.receive() delivered to upper layer - 2
DEBUG (10): 0:0:2.019577622 APPS: receive!! 2
DEBUG (7): 0:0:3.010407143 APPS: sendDone!! (error=0) ctr=3
DEBUG (10): 0:0:3.021820651 AODV: SubReceive.receive() dest: 10 src:7
DEBUG (10): 0:0:3.021820651 AODV: SubReceive.receive() delivered to upper layer - 3
DEBUG (7): 0:0:4.005264961 APPS: sendDone!! (error=0) ctr=4
DEBUG (10): 0:0:4.023239710 AODV: SubReceive.receive() dest: 10 src:7
DEBUG (10): 0:0:4.023239710 AODV: SubReceive.receive() delivered to upper layer - 4
DEBUG (7): 0:0:5.010010417 APPS: sendDone!! (error=0) ctr=5
DEBUG (10): 0:0:5.024780838 AODV: SubReceive.receive() dest: 10 src:7
DEBUG (10): 0:0:5.024780838 AODV: SubReceive.receive() delivered to upper layer - 5
DEBUG (7): 0:0:6.003983230 APPS: sendDone!! (error=0) ctr=6
DEBUG (10): 0:0:6.010147745 AODV: SubReceive.receive() dest: 10 src:7
DEBUG (10): 0:0:6.010147745 AODV: SubReceive.receive() delivered to upper layer - 6
DEBUG (7): 0:0:7.008331960 APPS: sendDone!! (error=0) ctr=7
DEBUG (10): 0:0:7.020187970 AODV: SubReceive.receive() dest: 10 src:7
DEBUG (10): 0:0:7.020187970 AODV: SubReceive.receive() delivered to upper layer - 7
DEBUG (7): 0:0:8.004013748 APPS: sendDone!! (error=0) ctr=8
DEBUG (10): 0:0:8.013474142 AODV: SubReceive.receive() dest: 10 src:7
DEBUG (10): 0:0:8.013474142 AODV: SubReceive.receive() delivered to upper layer - 8
DEBUG (7): 0:0:9.009140671 APPS: sendDone!! (error=0) ctr=9
DEBUG (10): 0:0:9.020233746 AODV: SubReceive.receive() dest: 10 src:7
DEBUG (10): 0:0:9.020233746 AODV: SubReceive.receive() delivered to upper layer - 9
DEBUG (7): 0:0:10.010391884 APPS: sendDone!! (error=0) ctr=10
DEBUG (10): 0:0:10.018341667 AODV: SubReceive.receive() dest: 10 src:7
DEBUG (10): 0:0:10.018341667 AODV: SubReceive.receive() delivered to upper layer - 10
如您所见 - 应用层的接收事件仅触发/执行一次。以下所有消息都到达目标节点,但未到达网络层之上。
关于这里可能发生的事情有什么想法吗?