Chinaunix首页 | 论坛 | 博客
  • 博客访问: 131942
  • 博文数量: 24
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 280
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-14 15:19
文章分类

全部博文(24)

文章存档

2014年(6)

2008年(3)

2007年(15)

我的朋友

分类: LINUX

2008-03-04 17:05:13

. 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.
    
阅读(1863) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~