t IP Address
seqno, // Dest Sequence Num
MY_ROUTE_TIMEOUT, // Lifetime
rq->rq_timestamp); // timestamp
Packet::free(p);
}
// I am not the destination, but I may have a fresh enough route.
/*如果不是目的节点,但是有到目的节点的路径,也发送路由应答报文*/
else if (rt && (rt->rt_hops != INFINITY2) &&
(rt->rt_seqno >= rq->rq_dst_seqno) ) {
//assert (rt->rt_flags == RTF_UP);
assert(rq->rq_dst == rt->rt_dst);
//assert ((rt->rt_seqno%2) == 0); // is the seqno even
sendReply(rq->rq_src,
rt->rt_hops + 1,
rq->rq_dst,
rt->rt_seqno,
(u_int32_t) (rt->rt_expire - CURRENT_TIME),
// rt->rt_expire - CURRENT_TIME,
rq->rq_timestamp);
// Insert nexthops to RREQ source and RREQ destination in the
// precursor lists of destination and source respectively
rt->pc_insert(rt0->rt_nexthop); // 加入前缀列表
rt0->pc_insert(rt->rt_nexthop); // 加入前缀列表
#ifdef RREQ_GRAT_RREP
sendReply(rq->rq_dst,
rq->rq_hop_count,
rq->rq_src,
rq->rq_src_seqno,
(u_int32_t) (rt->rt_expire - CURRENT_TIME),
// rt->rt_expire - CURRENT_TIME,
rq->rq_timestamp);
#endif
// TODO: send grat RREP to dst if G flag set in RREQ using rq->rq_src_seqno, rq->rq_hop_counT
// DONE: Included gratuitous replies to be sent as per IETF aodv draft specification. As of now, G flag has not been dynamically used and is always set or reset in aodv-packet.h --- Anant Utgikar, 09/16/02.
Packet::free(p);
}
/*
* Can't reply. So forward the Route Request
*/
//不能应答此报文,则继续广播
else {
ih->saddr() = index;
ih->daddr() = IP_BROADCAST;
rq->rq_hop_count += 1;
// Maximum sequence number seen en route
if (rt) rq->rq_dst_seqno = max(rt->rt_seqno, rq->rq_dst_seqno);
forward((aodv_rt_entry*) 0, p, DELAY);
}
}
void
AODV::recvReply(Packet *p) {
//struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_aodv_reply *rp = HDR_AODV_REPLY(p);
aodv_rt_entry *rt;
char suppress_reply = 0;
double delay = 0.0;
#ifdef DEBUG
fprintf(stderr, "%d - %s: received a REPLY\n", index, __FUNCTION__);
#endif // DEBUG
/*
* Got a reply. So reset the "soft state" maintained for
* route requests in the request table. We don't really have
* have a separate request table. It is just a part of the
* routing table itself.
*/
// Note that rp_dst is the dest of the data packets, not the
// the dest of the reply, which is the src of the data packets.
rt = rtable.rt_lookup(rp->rp_dst);//建立反向路径
/*
* If I don't have a rt entry to this host... adding
*/
if(rt == 0) {
rt = rtable.rt_add(rp->rp_dst);
}
/*
* Add a forward route table entry... here I am following
* Perkins-Royer AODV paper almost literally - SRD 5/99
*/
/*如果应答报文中目的序列号大于路由序列号或者
两者序列号相等但是跳数较小,则更新路由表*/
if ( (rt->rt_seqno < rp->rp_dst_seqno) || // newer route
((rt->rt_seqno == rp->rp_dst_seqno) &&
(rt->rt_hops > rp->rp_hop_count)) ) { // shorter or better route
// Update the rt entry
rt_update(rt, rp->rp_dst_seqno, rp->rp_hop_count,
rp->rp_src, CURRENT_TIME + rp->rp_lifetime);
// reset the soft state
rt->rt_req_cnt = 0;//路由请求次数归零
rt->rt_req_timeout = 0.0; //路由请求剩余时间归零
rt->rt_req_last_ttl = rp->rp_hop_count;
/*如果此节点是目的节点*/
if (ih->daddr() == index) { // If I am the original source
// Update the route discovery latency statistics
// rp->rp_timestamp is the time of request origination
rt->rt_disc_latency[rt->hist_indx] = (CURRENT_TIME - rp->rp_timestamp)
/ (double) rp->rp_hop_count;
//