File modules/rx/rxroutines.h

  $Revision: 1.25 $

Radix tree (rx). rxroutines.h - header file for radix tree handling module.
Status: NOT REVUED, TESTED
Design and implementation by: marek

Included Files


Preprocessor definitions

#define _RX_H

#define RX_ANS_ALL 1

#define RX_ALL_DEPTHS 255


Typedef rx_fam_t

typedef enum {...} rx_fam_t
enum 
   { 
     RX_FAM_RT; 
     RX_FAM_IN; 
     RX_FAM_IP; 
   } 

Typedef rx_oper_mt

the node operation modes

typedef enum {...} rx_oper_mt
enum 
   { 
     RX_OPER_CRE; 
     RX_OPER_DEL; 
   } 


Typedef rx_stk_mt

stack building modes

typedef enum {...} rx_stk_mt
enum 
   { 
     RX_STK_CREAT; - creation = all glue nodes, stop at first non-glue
     RX_STK_QUERY_ALLNOD; - query = all glue nodes, stop when deep enough
     RX_STK_QUERY_NOGLUE; - query = no glue nodes, stop when deep enough
   } 


Typedef rx_srch_mt

the search modes

typedef enum {...} rx_srch_mt
enum 
   { 
     RX_SRCH_CREAT; special search - does not skip glue nodes
     RX_SRCH_EXLESS; the default search
     RX_SRCH_EXACT; 
     RX_SRCH_LESS; 
     RX_SRCH_MORE; more specific search
     RX_SRCH_DBLS; special more spec: return only nodes with more than one data leaves
     RX_SRCH_RANG; more specific range search, RPSL style : ^n-m
   } 


Typedef rx_mem_mt

radix tree's memory modes -- not yet implemented

typedef enum {...} rx_mem_mt
enum 
   { 
     RX_MEM_RAMONLY; 
     RX_MEM_RAMSQL; 
     RX_MEM_SQLONLY; 
   } 


Typedef rx_subtree_mt

subtree modes -- not yet implemented

typedef enum {...} rx_subtree_mt
enum 
   { 
     RX_SUB_NONE; 
     RX_SUB_AUTO; 
     RX_SUB_HAND; 
   } 


Typedef rx_walk_mt

typedef enum {...} rx_walk_mt
enum 
   { 
     RX_WALK_CNTGLU; default: count also glue nodes and make the level checking aware of them
     RX_WALK_SKPGLU; only real nodes counted & watched in level checks
     RX_WALK_PRFLEN; make level check a check for prefix length; still only non-glue nodes are counted
     RX_WALK_REVERS; reverse the order of traversing the tree (first link 1 then 0)
   } 

Typedef rx_dataleaf_t

A struct for data hooked via a double linked list at a radix node. Must uniquely define the object for lookups in the SQL tables and/or memory. Must also contain enough info to let the delete_node choose (and remove) the proper object from the (linked) list

typedef struct {...} rx_dataleaf_t
struct 
   { 
     ip_range_t iprange; filled for all trees. Used in rp_search for determining exact matches (all trees) and to see if an address is in range (only IPv4 inetnum trees)
     unsigned char preflen; 
     char composed; non-zero for composed inetnums equal to: the number of prefixes composing the range - minus 1
     void* data_ptr; to in-memory immediate data
     unsigned data_len; and its length
     sql_key_t data_key; key to the SQL full-text data record
     sql_key_t leaf_key; pointer to the SQL data leaf record
   } 


Typedef rx_node_t

The struct for radix nodes.
Must contain prefix, parent, left/right child links in memory and sql, link to the sql version of the node. And of course data: pointer to a double linked list of rx_data_t's.

typedef struct _rx_node_str rx_node_t
struct _rx_node_str 
   { 
     ip_prefix_t prefix; who am i.
     char glue; 
     GList* leaves_ptr; a double-linked list of rx_data_t structs the data leaves can be multiple at each node (due to a user error the inetnum ranges can overlap, due to multihoming or error routes can be duplicated ). So we link a dynamic thing here
     struct _rx_node_str* parent_ptr; radix links in memory
     struct _rx_node_str* child_ptr[2]; NULL means empty
     sql_key_t parent_key; radix links in SQL
     sql_key_t child_key[2]; zero means empty
     sql_key_t node_key; key of the corresponding SQL radix node
   } 


Typedef rx_tree_t

rx_tree_t - defines a radix tree.
includes a pointer(key) to the top node,
names of the corresponding SQL tables (they can be generated automatically, but this is the place to store the result) Data_table is for data_key. Radix_table is for parent_id, right_id, left_id, node_id. Leaves_table is for leaves_key (double linked list in SQL).

typedef struct _rx_tree_str rx_tree_t
struct _rx_tree_str 
   { 
     ip_space_t space; one of IPv4, IPv6
     rx_fam_t family; one of RT, IN
     rx_subtree_mt subtrees; one of NONE, AUTO, HAND
     rx_mem_mt mem_mode; where the tree will sit - SQL or RAM
     struct rx_tree_str* parent_tree; pointer to the parent tree
     ip_prefix_t prefix; of the IP space this tree covers
     int maxbits; max depth of this tree (depends on the space, so it is redundant)
     sql_tblnam_t data_table; 
     sql_tblnam_t radix_table; 
     sql_tblnam_t leaves_table; 
     int num_nodes; number of nodes in tree - for assertions
     rx_node_t* top_ptr; pointer to the top node
     long top_key; the same in SQL
     rw_lock_t rwlock; per-tree reader/writer lock
   } 


Typedef rx_nodcpy_t

this is a definition of a node copy used for:
* stack elements returned from rx_stack_build,
* answer elements from an rx_nod_search.
It *must* hold pointers to the original locations of it (in terms of memory and SQL) so that one could actually modify the node... In SQL tree mode it holds also a copy of a node. This seems to be unnecessary for in-memory radix trees but is a must for sql ones.
WARNING!!!!! The fact that pointers to tree and memory / SQL nodes are here is a subject to race condition. The location of the tree in the forest list and the node in memory must not change.

typedef struct {...} rx_nodcpy_t
struct 
   { 
     rx_tree_t* tree; contains registry_id, space_id, sql table names
     rx_node_t* srcptr; 
     sql_key_t srckey; 
     rx_node_t cpy; filled in if the tree is kept in SQL only mode
   } 


Typedef rx_datref_t

This represents one data leaf (by reference). It's used for returning data from rx_bin_search() to rx_asc_search().

typedef struct {...} rx_datref_t
struct 
   { 
     sql_key_t srckey; 
     rx_dataleaf_t* leafptr; 
   } 


Typedef rx_datcpy_t

this is a structure used for returning the data from the search. It contains a copy of the dataleaf and a pointer to the source

typedef struct {...} rx_datcpy_t
struct 
   { 
     sql_key_t srckey; 
     rx_dataleaf_t leafcpy; 
   } 


Typedef rx_treecheck_t

typedef struct {...} rx_treecheck_t
struct 
   { 
     rx_node_t* node; 
     int code; 
     int datatoo; 
     rx_tree_t* tree; 
   } 

Typedef rx_sqlobj_t

typedef struct {...} rx_sqlobj_t
struct 
   { 
     sql_tblnam_t name; 
     sql_key_t key; 
   } 

Typedef hook_addnode_userdat_t

typedef struct {...} hook_addnode_userdat_t
struct 
   { 
     GList** nodlist; 
     rx_tree_t* tree; 
     ip_prefix_t* prefix; 
   }