Programmatic Access to Configurations

Applications need to access the system configuration to read the configuration values that have been set by the administrative user and to configure internal state once the configuration is accepted by the daemon.

The DDL Access (DAX) and patricia tree functions allow let you do this.

JUNOS applications use the DAX library to read the tree that stores the router configuration database (see System and User Interface Configuration). They then build a local data structure (which is often, but does not have to be, a patricia tree) to store the data locally. Applications can also transform the data to suit their particular needs before storing it; for example, you might want to sort the data differently or to add more information to certain data items.

Storing the data locally optimizes performance by avoiding the necessity of returning to the main configuration database for data required by the application. Whenever relevant data changes, the application can return to the system database, use DAX APIs to fetch the new information, and update the local data.

The DAX API

The mydaemon_read_config() function shown next uses DAX calls to open the UI database:

boolean
mydaemon_read_config (boolean do_check) 
{
    const char *err;
    boolean status;
    int myint;

    err = dax_open_db(NULL, DAE_MYDAE, PACKAGE_NAME, SEQUENCE_NUMBER,
                      do_check);
    if (err) {
        dax_error(NULL, "Opening configuration database: %s", error);
        return FALSE;
    }

    status = mydaemon_config_knobs(do_check);

    err = dax_close_db());
    if (err) {
        dax_error(NULL, "Closing configuration database: %s", err);
    }

    return status;
}

For more information about using DAX, see Using DAX to Read Configurations.

The Patricia Tree

Whenever JUNOS creates a database from your CLI configuration, it uses a patricia tree structure to store the data. The patricia tree is a data structure commonly used in networking applications to facilitate lookups with keys that are strings. This structure has the ability to contain large ranges of values, and is especially suited to the hierarchical organization of IP addresses and other configuration values.

The patricia tree functions are contained in libjuniper, in the file patricia.h.

How Patricia Trees Work

The patricia tree allows you to group together common parts of strings, something that occurs commonly in Juniper configuration databases.

The next figure illustrates how a simple patricia tree works. Suppose you want to store the following strings: grey, gray, group, groups, grouping, groupings, gosh. The tree for this would look like the following:

patricia-tree-g016879.gif

A Simple Patricia Tree

In networking applications, a sample tree starts with no configured value (that is, with 0) and is at the leftmost position of the binary IP address. This is shown as 0 /0, which is often referred to as the default route.

The first position of the IP address can have only one of two possible values: 0 or 1. Moving down the left branch represents a value of 0, while moving to the right represents a value of 1. At the first position, the first octet of the IP address has a value of 00000000 or 10000000: a 0 or 128, respectively. This is represented in the next figure by the values 0 /1 and 128 /1.

patricia-tree-beginning-g016880.gif

Beginning of a Patricia Tree

This second level of the tree has four possible binary values for the first octet: 00000000, 01000000, 10000000, and 11000000. These decimal values of 0, 64, 128, and 192 are represented by the IP addresses of 0 /2, 64 /2, 128 /2, and 192 /2 on the tree, as the following figure shows.

patricia-tree-two-g016882.gif

Patricia Tree with a New Level

This step-by-step process continues on for 33 total levels. In the end, we effectively represent every possible IP address.

The patricia tree structure lets you pinpoint a group of routes that all share the same most significant bits. The next figure represents the point in the tree that represents the 192.168.0.0 /16 network. All of the routes that are more specific than 192.168.0.0 /16 are shown in the highlighted section.

patricia-tree-routes-g016881.gif

Locating a Group of Routes

For details about using the patricia tree APIs, see Using the Patricia Tree Library.

Next topic in TOC: Libraries in the SDK


2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:26:47 2010 for Juniper Networks Partner Solution Development Platform JUNOS SDK 10.2R1 by Doxygen 1.4.5