NS2下AODV协议aodv.cc注释(6)

/* 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,                // Dest 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);
 }

}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ab5562fd35bafa4ee10b3188dd4834ce.html