Hi, all~
I am implementing ETX metric into AODV, and change sendHello(), recvHello() to 
calculate the ETX of a link between neighbors. 
I want to send a Hello packet with the information of the neighbor list this 
node maintians, using sendHello() function by adding 
 lp->lp_nb = nbhead.lh_first;  // point to the head of the neighbor list of 
this node. 
but when i debugs, result is as follows:
 
Breakpoint 1, AODV::sendHello (this=0x8801cc8) at aodv/aodv.cc:1326
1326  lp->lp_nb = nbhead.lh_first;  // point to the head of the neighbor list 
of this node
2: lp->lp_dst = 0
1: lp->lp_nb = (AODV_Neighbor *) 0x0
(gdb) 
Continuing.
Breakpoint 2, AODV::recvHello (this=0x8828090, p=0x88aa9c8)
    at aodv/aodv.cc:1356
1356  if(nb == 0) {
6: nb->nb_link_probe_count = 98
5: index = 1
4: lp->lp_dst = 0
3: lp->lp_nb = (AODV_Neighbor *) 0x8889998


In the sendHello() , lp->lp_nb is always 0x0, can anybody tell me why?  
Best regards.
 

Follows is the change I have made.
First, in aodv_packet.h, i add a probe packet.(a RREP packet with a pointer)
struct hdr_aodv_link_probe {
        u_int8_t        lp_type;        // Packet Type
        u_int8_t        reserved[2];
        u_int8_t        lp_hop_count;           // Hop Count
        nsaddr_t        lp_dst;                 // Destination IP Address
        u_int32_t       lp_dst_seqno;           // Destination Sequence Number
        nsaddr_t        lp_src;                 // Source IP Address
        double         lp_lifetime;            // Lifetime
        double          lp_timestamp;           // when corresponding REQ sent;
      // used to compute route discovery latency
        AODV_Neighbor * lp_nb;            // point to the head of the neighbor 
list of this node    
  inline int size() { 
  int sz = 0;
  /*
   sz = sizeof(u_int8_t)  // lp_type
      + 2*sizeof(u_int8_t)  // lp_flags + reserved
      + sizeof(u_int8_t)  // lp_hop_count
      + sizeof(double)  // lp_timestamp
      + sizeof(nsaddr_t)  // lp_dst
      + sizeof(u_int32_t) // lp_dst_seqno
      + sizeof(nsaddr_t)  // lp_src
      + sizeof(u_int32_t) // lp_lifetime
             + sizeof(AODV_Neighbor *); // lp_nb
  */
   sz = 6*sizeof(u_int32_t) + sizeof(AODV_Neighbor *);
   assert (sz >= 0);
 return sz;
  }
};
 
sendHello():
 void
AODV::sendHello() {
Packet *p = Packet::alloc();
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_aodv_link_probe * lp = HDR_AODV_LINK_PROBE(p); // specified link 
probe packet
#ifdef DEBUG
fprintf(stderr, "sending Hello from %d at %.2f\n", index, 
Scheduler::instance().clock());
#endif // DEBUG
 lp->lp_type = AODVTYPE_HELLO;
 //lp->lp_flags = 0x00;
 lp->lp_hop_count = 1;
 lp->lp_dst = index;
 lp->lp_dst_seqno = seqno;
 lp->lp_lifetime = (1 + ALLOWED_HELLO_LOSS) * HELLO_INTERVAL;
 lp->lp_nb = nbhead.lh_first;  // point to the head of the neighbor list of 
this node 
 // ch->uid() = 0;
 ch->ptype() = PT_AODV;
 ch->size() = IP_HDR_LEN + lp->size();
 ch->iface() = -2;
 ch->error() = 0;
 ch->addr_type() = NS_AF_NONE;
 ch->prev_hop_ = index;          // AODV hack
 ih->saddr() = index;
 ih->daddr() = IP_BROADCAST;
 ih->sport() = RT_PORT;
 ih->dport() = RT_PORT;
 ih->ttl_ = 1;         
 Scheduler::instance().schedule(target_, p, 0.0);
}

recvHello():
 void
AODV::recvHello(Packet *p) {
//struct hdr_ip *ih = HDR_IP(p);
struct hdr_aodv_link_probe * lp = HDR_AODV_LINK_PROBE(p); // specified link 
probe packet
AODV_Neighbor *nb; 
double now = CURRENT_TIME; // use to check whether has time out, if time out 
,calculate the etx and reset link_probe_count
 nb = nb_lookup(lp->lp_dst);  // the term of the sender node in this receiving 
node's neighbor list
 if(nb == 0) {
   nb_insert(lp->lp_dst);   //  
 }
 else { 
   nb->nb_expire = CURRENT_TIME +
                   (1.5 * ALLOWED_HELLO_LOSS * HELLO_INTERVAL);   
   // timeout, calculate the ETX of this link, reset timestart and 
link_probe_count
   if((nb->timestart + COUNT_INTERVAL) < now){
     AODV_Neighbor *temp = lp->lp_nb; 
     for(; temp; temp = temp->nb_link.le_next) {
       if(temp->nb_addr == index) break;
     }
     // the according term of this node in the sender node's neighbor list
     AODV_Neighbor * myself = temp;       
     // the probes sender received from this node
     u_int16_t sender_recv_count = myself->nb_link_probe_count;
 
     nb->nb_link_etx = 1.0/ ((sender_recv_count / 100.0) * 
(nb->nb_link_probe_count / 100.0));
     nb->timestart = CURRENT_TIME;
     nb->nb_link_probe_count = 0;
   }
   else{
     nb->nb_link_probe_count++;
   }
 }
 Packet::free(p);
}
 
/*
 * nb_inset(nsaddr_t)函数用于将首次检测到的邻居节点插入邻居节点链表中;同时要完成初始化该新增邻居节点
 * 的寿命域,本节点从其接收到的探测分组数,链路的etx值以及计数器启动时间。
 */
void
AODV::nb_insert(nsaddr_t id) {   
AODV_Neighbor *nb = new AODV_Neighbor(id);
 assert(nb);
/* add by lee */
 nb->nb_link_etx = 0.0;           // initial the ETX of this link (sender 
->receiver)
 nb->nb_link_probe_count = 0;     // initial the count field, records the 
probes sender received from the receiver
 nb->timestart = CURRENT_TIME;    // initial when to start counting
 nb->nb_expire = CURRENT_TIME +
                (1.5 * ALLOWED_HELLO_LOSS * HELLO_INTERVAL);
 LIST_INSERT_HEAD(&nbhead, nb, nb_link);
 seqno += 2;             // set of neighbors changed
 assert ((seqno%2) == 0);
}
 
 
 
 
 
 







聊天+搜索+邮箱 想要轻松出游,手机MSN帮你搞定! 立刻下载!
                                          
_________________________________________________________________
想知道明天天气如何?必应告诉你!
http://cn.bing.com/search?q=%E5%A4%A9%E6%B0%94%E9%A2%84%E6%8A%A5&form=MICHJ2

Reply via email to