uu-aodv框架分析

首先,有三个路由表,一个uuaodv模块维护的路由信息,用struct expl_entry表示。uuaodv用户空间程序维护的路由表,相对比较复杂,用rt_table表示。linux内核维护的路由表用struct rtable表示,当系统发送数据包时,查找的就是这个路由表。前两个路由表用于对系统路由表的更新。具体结构的不同,参见附录。
aodv当然要维护一个路由表,至于为什么要分成内核空间和用户空间两部分,源于linux的一个思想,功能尽可能在用户空间实现。内核空间的一个小bug,会导致系统的崩溃。内核
空间的路由表只做一些简单的判断,复杂的工作都留给用户空间了。看看expl_entry和rt_table的不同就知道他们的差异了。


uuaodv从功能上分成两部分
1,内核模块。主要负责维护一个expl_entry结构的数组,其中包括目的地,下一条,超时时间等。类似于路由表。
下面是怎么维护这个结构:
在NFHOOK的三个挂载点(NF_IP_PRE_ROUTING,NF_IP_LOCAL_OUT,NF_IP_POST_ROUTING,)处挂载kaodv_hook函数。关于NFHOOK的挂载点请参照附图中IP处理流程。也就是当ip数据包经过这三个挂载点时,会调用kaodv_hook函数,检查数据包的源ip,目的ip信息,调用kaodv_update_route_timeouts()更新expl_entry结构和通知用户进程更新用户空间的维护的路由表。例如,节点A给B发数据,A有B的路由,但B里没有A的路由,A发送后,节点B中aodv模块在NF_IP_PRE_ROUTING那儿对数据作一个检查,发现数据是从A来的,而又没有A的路由信息(expl_entry中没有),把A的路由信息添加到一个expl_entry结构中,并通过aodvnl(见下)这个socket告诉用户空间进程,用户空间检查修改维护的路由表,如果有改动通过rtnl通知linux更改系统的路由表。



2,用户空间部分,

它首先会建立四个socket:
1,用于接受和发送aodv控制命令(rreq,rrep,rerr,hello)的socket,such as,if rreq,查找路由表,如果有到dest的路由,返回rrep.更新到源节点的路由表(用户空间维护的,和系统路由表)
2,aodv内核模块和用户空间程序通信的netlink socket, aodvnl  内核模块将一些新的路由信息告诉用户进程。    
3,linux内核路由模块和用户进程通信的netlink socket, rtnl   主要负责更改系统路由
4,llf socket   ---待知

通过select函数监控它们,如果有数据到达,就接收数据,根据情况对维护的路由表进行更新,如果必要更改系统的路由表(发现新路由,路由挂了等)。


附录:
struct rtable
{
union
{
struct dst_entry dst;
struct rtable *rt_next;
} u;

struct in_device *idev;
unsigned rt_flags;
__u16 rt_type;
__u16 rt_multipath_alg;

__u32 rt_dst; /* Path destination */
__u32 rt_src; /* Path source */
int rt_iif;

/* Info on neighbour */
__u32 rt_gateway;

/* Cache lookup keys */
struct flowi fl;

/* Miscellaneous cached information */
__u32 rt_spec_dst; /* RFC1122 specific destination */
struct inet_peer *peer; /* long-living peer info */
};

struct expl_entry {
struct list_head l;   //把这个结构连接起来的链表
unsigned long expires;   //超时时间,如果超时就cut
unsigned short flags;    
__u32 daddr;               //destinion address
__u32 nhop;                //next hop
int ifindex;               //对应一个网络接口
};


/* Route table entries */
struct rt_table {
    list_t l;
    struct in_addr dest_addr;   /* IP address of the destination */
    u_int32_t dest_seqno;
    unsigned int ifindex;       /* Network interface index... */
    struct in_addr next_hop;    /* IP address of the next hop to the dest */
    u_int8_t hcnt;              /* Distance (in hops) to the destination */
    u_int16_t flags;            /* Routing flags */
    u_int8_t state;             /* The state of this entry */
    struct timer rt_timer;      /* The timer associated with this entry */
    struct timer ack_timer;     /* RREP_ack timer for this destination */
    struct timer hello_timer;
    struct timeval last_hello_time;
    u_int8_t hello_cnt;
    hash_value hash;
    int nprec;                  /* Number of precursors */
    list_t precursors;          /* List of neighbors using the route */
};



  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值