免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1081 | 回复: 0
打印 上一主题 下一主题

Zebra Codes Framework Analysis(1) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-03-04 17:05 |只看该作者 |倒序浏览
. Descriptions
    Zebra is the most powerful and famous open source routing software toolkits in the *nix world under the GPL!
    Zebra is multi-processes based, asynchronous routing
toolkits. Each routing protocol has its own process in Zebra and all of
these routing processes can communicate common each other through *nix
IPC.
    The Zebra process(Zebra daemon) is the 'main
process' in the whole system, it responsible for communicating with the
linux kernel. All of the other protocol processes can not communicate
with kernel directly. Zebra daemon is responsible for the kernel
routing table update and its redistribution between different protocols.
    Each protocol process(daemon) has its own routing
table(just like OSPF, RIP,ISIS etc), while they MUST first exchange the
routing information with Zebra process and then Zebra should do the
kernel routing table updating work.
2. Software Framework
    Zebra is based on the multi-threads mechanism and its kernel is the scheduling.
    Zebra operations are comprised of some function
calls and each function call is stored in a thread structure in Zebra
sitting inside scheduling queue.
    The main codes are in : thread.c and workqueue.c
    There are 7 queues now : read, write, timer, event,
ready, unuse, background. And the scheduling priority in Zebra
scheduling is : signal > event > ready > timer > read >
write > background. The unuse queue is the thread cache pool.
    The main function in thread.c and workqueue.c are :
        thread.c :     thread_fetch()
                 thread_run();
        workqueue.c : work_queue_schedule()
                 work_queue_run()
    The main calling function is a forever loop :
        while (thread_fetch())
            thread_run();
3. Routing Tables
    Routing tables design is the most sophisticated part
in the Zebra routing software, there are several very important data
structs in the Zebra.
   
3.1 The global routing table entrance
    The global routing table entrance name is : vrf_vector. Virtual Routing Forwarding Vector.
    This variable is the global routing table entrance
pointer. The whole routing table is a dynamic growing table identified
by vrf_vector's 'index' pointer.
    The codes of this part is mainly in : vector.c.
    And the main function about the global routin operations are : vector_init();
3.2 The routing tables
    The routing table in Zebra is described by the
struct : struct vrf. This is the real routing table struct, and its
defition is here :
        struct vrf {
            u_int32_id id; # the VRF ID
            char *name;    # the routing table's name
            char *desc; # the description of this routing table
            u_char fib_id; # the FIB identifier
            struct
route_table *table[AFI_MAX][SAFI_MAX]; # the dynamic routing table
            struct
route_table *stable[AFI_MAX][SAFI_MAX]; # the static routing
configuration
        }
    The 'table' and 'stable' is the routing nodes in the table, and the struct route_table's definition is here :
        struct route_table {
            struct route_node *top;
        }
    So, we can see that the basic nodes in the routing table is the 'struct route_node' instances.
        /* Each routing entry. */
        struct route_node
        {
          /* Actual prefix of this radix. */
          struct prefix p;
          /* Tree link. */
          struct route_table *table;
          struct route_node *parent;
          struct route_node *link[2];
        #define l_left   link[0]
        #define l_right  link[1]
          /* Lock of this radix */
          unsigned int lock;
          /* Each node of route. */
          void *info;
          /* Aggregation. */
          void *aggregate;
        };
    We can see that the 'struct route_node' is a TREE,
and its main and most important member is 'void *info', it cotains the
whole routing informations of a route.
    The main function operations for a route table is defined in zebra_rib.c and table.c.
    Aand the functions are below here :   
        vrf_init();
        vrf_create();
        vrf_table();
        vrf_lookup();
        vrf_alloc() ;
        route_node_lookup();
        route_node_get();
        route_node_delete();
        route_node_until();
        route_node_match();
        .....
3.3 The prefix
    The 'struct prefix' is another very important struct in Zebra.
    The 'prefix' struct contains an address family, a
prefix length and an address. It can represent either a 'network
prefix' as defined by CIDR or an address and netmask such as might be
configured on an interface.
    The 'prefix' struct usually used to find the the route_node struct in a routing table(route_table).
    The main function about the prefix is mainly defined
in prefix.c, and the functions about the prefix is also defined in
prefix.c.
     
            
    The functions defined in table.c and prefix.c are
the basic functions of the routing table oerations, they are very
important and we MUST first understand these functions.
3.4 The RIB and NEXTHOP
    The RIB is Routing Information Base, it is the basic
struct in Zebra, its definition is 'struct rib'. The RIB is the basic
operation unit in Zebra, all the routing operations is based on RIB
struct. RIB is stored by the route_node's infor pointer.
    The NEXTHOP struct is used to represent the next hop
routing's gate information. It is stored by the RIB's nexthop pointer.
     


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/26397/showart_489338.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP