AODV::recv(Packet *p, Handler*) {
//HDR_CMN HDR_IP均在ip.cc中定义
struct hdr_cmn *ch = HDR_CMN(p); //查看cmn头struct hdr_ip *ih = HDR_IP(p);//查看ip头
//确保初始化
assert(initialized());//断言
//assert(p->incoming == 0);
// XXXXX NOTE: use of incoming flag has been depracated; In order to track direction of pkt flow, direction_ in hdr_cmn is used instead. see packet.h for details.
//从cmn头的信息里对接收分组进行处理,判断是否是aodv包,如果是,调用recvAODV(p)
if(ch->ptype() == PT_AODV) { //ptype是包头类型
ih->ttl_ -= 1;//如果是,time to leave-1
recvAODV(p);//调用recvAODV(p)
return;
}
/*
* Must be a packet I'm originating...
*/
//若从ip头看出是本节点产生的数据包,并且没有loop,添加IP头
if((ih->saddr() == index) && (ch->num_forwards() == 0)) {
/*
* Add the IP Header.
* TCP adds the IP header too, so to avoid setting it twice, we check if
* this packet is not a TCP or ACK segment.
*/
if (ch->ptype() != PT_TCP && ch->ptype() != PT_ACK) { //如果包头类型不是TCP,也不是ACK类型,加上ip头
ch->size() += IP_HDR_LEN;
}
// Added by Parag Dadhania && John Novatnack to handle broadcasting
//如果不是broadcast分组
if ( (u_int32_t)ih->daddr() != IP_BROADCAST) {
//前面定义time to leave=30
ih->ttl_ = NETWORK_DIAMETER;//等待时间30
}
}
/*
* I received a packet that I sent. Probably
* a routing loop.
*/
//收到本节点发送的包,说明有路由环路,丢包
else if(ih->saddr() == index) {
drop(p, DROP_RTR_ROUTE_LOOP);
return;
}
/*
* Packet I'm forwarding...
*/
//我转发过的分组
else {
/*
* Check the TTL. If it is zero, then discard.
*/
//TTL分组最多转发次数
if(--ih->ttl_ == 0) {
//如果time to leave=0丢弃分组,因为超时
drop(p, DROP_RTR_TTL);
return;
}
}
// Added by Parag Dadhania && John Novatnack to handle broadcasting
//收到的不是广播分组,解析分组
if ( (u_int32_t)ih->daddr() != IP_BROADCAST)
//如果不是broadcast分组则解析分组
rt_resolve(p);
else
//转发,不等待
forward((aodv_rt_entry*) 0, p, NO_DELAY);
}