- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
浅析route_table是如何工作,routetable,iproutetable,iprouteflushtable,linuxroutetable,iprouteaddtable,iproutelisttable,iprouteshowtable,linuxiproutetable,macroutetable
理解Route_table是如何工作
指导人:郭巍松
作者:王岩广
时间:2005-9-7
1 Route_table结构很重要
Dcnos中route_table这个数据结构非常重要,许多结构是通过它来实现,比如PIM-SM中的TIB,注册状态reg,nexthop cache等都其实是一个route_table。Route_table是一个二叉树(每一个节点除带有一个左儿子,一个右儿子,还有一个父指针)。一个完整的route_table,由两种结构组成,一个route_table和若干个route_node。
Struct route_table 这个结构由一个Stuct route_node指针和一个table号组成。
Struct route_node *top; U_int32_t id;//table号
Stuct route_node 这个结构其实是一个二叉树。(应为三叉树),它的内容包括:
Struct route_node *link[2];//两个儿子 Stuct prefix p;//前缀信息 Struct route_table *table;//指向一个route_table,从我们使用来看,它是回指本身所在的表 Stuct route_node *parent;//父节点 U_int32_t lock; Void *info;//这个节点真正的信息所在。注意是任意类型指针 Void *aggregate;//目前不解,聚类指针一般用于ripng中 一个Table是由若干个route_node组成,每一个route_node除了有一个父节点和两个儿子节点外,还可以指向另一个table。下图是一个route_table的例子。
一个route_table骨架(没有画出info指针)
2 Route_table表节点的插入
一个route_table是通过函数一次或多次调用route_node_get(table,prefix)来创建和查询,通过route_node_lookup()来查询(不创建)。现在通过get函数来分析一个table是如何建立起来,和如何查询的。
Get函数如下:
1 struct route_node *
2 route_node_get (struct route_table *table, struct prefix *p)
3 {
4 struct route_node *new;
5 struct route_node *node;
6 struct route_node *match; //表示被匹配到的节点,如果没有匹配到为空
7 match = NULL;
8 node = table-top;
9 while (node node-p.prefixlen = p-prefixlen
10 prefix_match (node-p, p)) //如果prefix_match(a,b), 即a的prefixlen小于等于b,并//且a的prefix中的前prefixlen跟b相同,即我们一般所//说的最短匹配
11 {
12 if (node-p.prefixlen == p-prefixlen)
13 {
14 route_lock_node (node);
return node;//查询作用
16 }
17 match = node;
18 node = node-link[check_bit(p-u.prefix, node-p.prefixlen)];
19 }
20 if (node == NULL)//创建第一个(时间顺序上的第一个,但不一定是根节点)节点,或//创建叶子节点
21 {
22 new = route_node_set (table, p);
23 if (match) //创建的是叶子节点
24 set_link (match, new);
25 else
26 table-top = new; //第一个节点
27 }
28 else//创建中间节点
29 {
30 new = route_node_create ();
31 route_common (node-p, p, new-p);//new-p尽量长的prefixlen,但要匹配//node-p
32 new-p.family = p-family;
33 new-table = table;
34 set_link (new, node);
35 if (ma
文档评论(0)