Chapter 5 - Retreiving Data From JUNOS Configuration Database

UI Infrastructure Programmer's Guide

Chapter 5 - Retreiving Data From JUNOS Configuration Database

5.1. DDL Access API (DAX)

The dax_ api provides the routines used to access the configurations in the UI database. Daemons use the routines for checking the configurations provided by the user and to configure internal state once the configuration is accepted by the daemon. It deprecates the previous ddl_access_ api.

The purpose of the DAX is to access the settings in the configuration database. It is mainly used during commit time.

The following is taken from the DAX documentations and it shows what dax_ does.

Example 1: Setting up daemon to open, read, and close the UI database

#include <feature/jexample_sequence.h>
#include <feature/jexample_out.h>

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;
}

Example 2: Fetching values using the dax_get_* api

/*                                                               */
/* Reads configuration under [system knobs1], if do_check is     */
/* TRUE, we simply do a check, otherwise we configure the knobs. */
/*                                                               */
boolean
mydaemon_config_knobs (boolean do_check)
{
    int knob_int;
    char knob_str[KNOB_STR_SZ];
    const char *knob_path[] = { "system", "knobs", NULL };
    ddl_handle_t *dop;

    if (!dax_get_object_by_path(NULL, knob_path, &dop, FALSE)) {
        if (!do_check) {
            /*
 knobs not configured, do something about it.
             */
        }

        return TRUE;
    }
    
    knob_int = DEFAULT_KNOB_INT;
    dax_get_int_by_name(dop, "knob-int", &knob_int);

    strncpy(knob_str, DEFAULT_KNOB_STR, sizeof(knob_str));
    dax_get_stringr_by_name(dop, "knob-str", &knob_str, sizeof(knob_str));

    dax_release_object(&dop);

    if (do_check)
        return TRUE;

    /*
 Not a check set internal state.
     */
    mydaemon_set_knob(knob_int, knob_str);

    return TRUE;
}

Example 3: Walking container items

Containers are defined in the ddl as 'type setof foo_object' for by the flag "setof' statement. Note the 'delta-list' flag. This is required if you want mgd to store 'delete' information. Otherwise the UI will treat a delete as if you deleted the entire list and recreated it. ie. it'll send a DAX_ITEM_DELETE_ALL message, then a DAX_ITEM_CHANGED message for all configured items.

Example knob.cnf.ddl file

  object knob-keys {
      flag autosort list delta-list;

      attirbute knob-key-name {
          flag nokeyword identifier;
          type string;
      }

      attribute key-string-value {
          type string;
      }
  }

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:23:10 2010 for JUNOS UI Programmer's Guide by Doxygen 1.4.5