aodv协议/rtable

每个节点都会带一个路由表,详细如下:

 1 /*
 2   路由表
 3 */
 4 
 5 class aodv_rtable {
 6  public:
 7     aodv_rtable() { LIST_INIT(&rthead); }
 8             //对路由条目的操作
 9         aodv_rt_entry*       head() { return rthead.lh_first; }
10 
11         aodv_rt_entry*       rt_add(nsaddr_t id);
12         void                 rt_delete(nsaddr_t id);
13         aodv_rt_entry*       rt_lookup(nsaddr_t id);
14 
15  private:
16         LIST_HEAD(aodv_rthead, aodv_rt_entry) rthead;    //表头
17 };
 1 /*
 2   路由表里的条目,记录一条路由
 3 */
 4 
 5 class aodv_rt_entry {
 6         friend class aodv_rtable;    //声明友元
 7         friend class AODV;
 8     friend class LocalRepairTimer;
 9  public:
10         aodv_rt_entry();
11         ~aodv_rt_entry();
12                             //对邻居表的插入、查询操作
13         void            nb_insert(nsaddr_t id);
14         AODV_Neighbor*  nb_lookup(nsaddr_t id);
15                             //对前驱表的插入、查询操作等
16         void            pc_insert(nsaddr_t id);
17         AODV_Precursor* pc_lookup(nsaddr_t id);
18         void         pc_delete(nsaddr_t id);
19         void         pc_delete(void);
20         bool         pc_empty(void);
21 
22         double          rt_req_timeout;         // when I can send another req
23         u_int8_t        rt_req_cnt;             // number of route requests
24     
25  protected:
26         LIST_ENTRY(aodv_rt_entry) rt_link;    //含有next指针 和 它前驱节点的next指针的地址
27 
28         nsaddr_t        rt_dst;                //目的地ip地址
29         u_int32_t       rt_seqno;            //目的地序列号?
30     
31         u_int16_t       rt_hops;               // 跳数
32     int         rt_last_hop_count;        // last valid hop count
33         nsaddr_t        rt_nexthop;            // 下一跳IP地址
34     /* list of precursors */ 
35         aodv_precursors rt_pclist;            //前驱表表头
36         double          rt_expire;             // when entry expires过期
37         u_int8_t        rt_flags;
38 
39 #define RTF_DOWN 0        //由应用层往传输,网络层传为向下传
40 #define RTF_UP 1
41 #define RTF_IN_REPAIR 2
42 
43 #define MAX_HISTORY    3
44     double         rt_disc_latency[MAX_HISTORY];
45     char         hist_indx;
46         int         rt_req_last_ttl;        // last ttl value used(time to live,ttl为0则失效)
47         /*
48          * a list of neighbors that are using this route.
49          */
50         aodv_ncache          rt_nblist;    //邻居表表头
51 };
 1 /*
 2    邻居表
 3 */
 4 class AODV_Neighbor {
 5         friend class AODV;
 6         friend class aodv_rt_entry;
 7  public:
 8         AODV_Neighbor(u_int32_t a) { nb_addr = a; }
 9 
10  protected:
11         LIST_ENTRY(AODV_Neighbor) nb_link;
12         nsaddr_t        nb_addr;
13         double          nb_expire;      // ALLOWED_HELLO_LOSS * HELLO_INTERVAL
14 };
 1 /*
 2   前驱表
 3 */
 4 class AODV_Precursor {
 5         friend class AODV;
 6         friend class aodv_rt_entry;
 7  public:
 8         AODV_Precursor(u_int32_t a) { pc_addr = a; }
 9 
10  protected:
11         LIST_ENTRY(AODV_Precursor) pc_link;
12         nsaddr_t        pc_addr;    // precursor address
13 };

猜你喜欢

转载自www.cnblogs.com/lnu161403214/p/10029484.html