设为首页 加入收藏

TOP

NS2下AODV协议aodv.cc注释(六)
2014-11-23 23:16:57 来源: 作者: 【 】 浏览:76
Tags:NS2 AODV 协议 aodv.cc 注释
RT_PORT);
assert(ih->dport() == RT_PORT);


/*
* Incoming Packets.
*/
switch(ah->ah_type) {


case AODVTYPE_RREQ:
recvRequest(p);
break;


case AODVTYPE_RREP:
recvReply(p);
break;


case AODVTYPE_RERR:
recvError(p);
break;


case AODVTYPE_HELLO:
recvHello(p);
break;

default:
fprintf(stderr, "Invalid AODV type (%x)\n", ah->ah_type);
exit(1);
}


}



void
AODV::recvRequest(Packet *p) {
struct hdr_ip *ih = HDR_IP(p);
struct hdr_aodv_request *rq = HDR_AODV_REQUEST(p);
aodv_rt_entry *rt;


/*
* Drop if:
* - I'm the source
* - I recently heard this request.
*/
/*如果此节点就是源节点,出现环路,丢弃路由请求报文*/
if(rq->rq_src == index) {
#ifdef DEBUG
fprintf(stderr, "%s: got my own REQUEST\n", __FUNCTION__);
#endif // DEBUG
Packet::free(p);
return;
}
/*如果已经收到了源地址和请求序列号相等的请求报文,丢弃*/
if (id_lookup(rq->rq_src, rq->rq_bcast_id)) {


#ifdef DEBUG
fprintf(stderr, "%s: discarding request\n", __FUNCTION__);
#endif // DEBUG

Packet::free(p);
return;
}


/*
* Cache the broadcast ID
*/
/*缓存此路由请求*/
id_insert(rq->rq_src, rq->rq_bcast_id);



/*
* We are either going to forward the REQUEST or generate a
* REPLY. Before we do anything, we make sure that the REVERSE
* route is in the route table.
*/
//建立反向路径
aodv_rt_entry *rt0; // rt0 is the reverse route

rt0 = rtable.rt_lookup(rq->rq_src);
if(rt0 == 0) { /* if not in the route table */
// create an entry for the reverse route.
rt0 = rtable.rt_add(rq->rq_src);
}
//更新此路由条目的生存时间
rt0->rt_expire = max(rt0->rt_expire, (CURRENT_TIME + REV_ROUTE_LIFE));
/*如果请求序列号大于路由序列号或者两者序列号相等但是跳数
比源路由跳数小,则更新*/
if ( (rq->rq_src_seqno > rt0->rt_seqno ) ||
((rq->rq_src_seqno == rt0->rt_seqno) &&
(rq->rq_hop_count < rt0->rt_hops)) ) {
// If we have a fresher seq no. or lesser #hops for the
// same seq no., update the rt entry. Else don't bother.
rt_update(rt0, rq->rq_src_seqno, rq->rq_hop_count, ih->saddr(),
max(rt0->rt_expire, (CURRENT_TIME + REV_ROUTE_LIFE)) );
/*如果此前请求过该路由条目,则更新信息*/
if (rt0->rt_req_timeout > 0.0) {
// Reset the soft state and
// Set expiry time to CURRENT_TIME + ACTIVE_ROUTE_TIMEOUT
// This is because route is used in the forward direction,
// but only sources get benefited by this change
rt0->rt_req_cnt = 0;
rt0->rt_req_timeout = 0.0;
rt0->rt_req_last_ttl = rq->rq_hop_count;
rt0->rt_expire = CURRENT_TIME + ACTIVE_ROUTE_TIMEOUT;
}


/* Find out whether any buffered packet can benefit from the
* reverse route.
* May need some change in the following code - Mahesh 09/11/99
*/
/*如果有到反向路径的分组报文,则发送*/
assert (rt0->rt_flags == RTF_UP);
Packet *buffered_pkt;
while ((buffered_pkt = rqueue.deque(rt0->rt_dst))) {
if (rt0 && (rt0->rt_flags == RTF_UP)) {
assert(rt0->rt_hops != INFINITY2);
forward(rt0, buffered_pkt, NO_DELAY);
}
}
}
// End for putting reverse route in rt table



/*
* We have taken care of the reverse route stuff.
* Now see whether we can send a route reply.
*/
//寻找到目的节点的路由
rt = rtable.rt_lookup(rq->rq_dst);


// First check if I am the destination ..
/*如果本节点就是目的节点,直接发送路由应答报文*/
if(rq->rq_dst == index) {


#ifdef DEBUG
fprintf(stderr, "%d - %s: destination sending reply\n",
index, __FUNCTION__);
#endif // DEBUG



// Just to be safe, I use the max. Somebody may have
// incremented the dst seqno.
seqno = max(seqno, rq->rq_dst_seqno)+1;
if (seqno%2) seqno++;


sendReply(rq->rq_src, // IP Destination
1, // Hop Count
index, // Des

首页 上一页 3 4 5 6 7 8 9 下一页 尾页 6/10/10
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇对NS2中aodv源文件的浅析 下一篇Objective-C中的meta-class

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: