ms_parse.h File Reference

Daemon command parsing APIs. More...

Data Structures

struct  parse_menu_s
 Tokens entries in parse tree. More...


typedef parse_status_s parse_status_t
typedef int(* parse_func_t )(mgmt_sock_t *, parse_status_t *, char *)
 Command handler.
typedef parse_menu_s parse_menu_t
 Tokens entries in parse tree.


int ms_parse_get_subcode (const parse_status_t *csb)
 Gets the parsing subcode from the status structure.

Detailed Description

Daemon command parsing APIs.

This file contains the data structures used to handle commands sent from mgd to a daemon.

Life of a command:

1. User types 'show version brief' into the cli.

2. cli sends the command to mgd

3. The MGD validates the command, figures out which daemon should deal with the command, and sends the string 'show version brief' to the right daemon. Note that the MGD may insert/rearrange/delete tokens from the command to the daemon. In this case it may broadcast the command to several daemons.

3. The stream 'show version brief' shows up in your daemon.

4. First token is 'show', The first level array should have a string entry 'show', if there is a function mp_function field it's called, if there is a 'next' array, it's followed for the next token 'version', then 'brief'.

Your daemon should have a file name <daemon>_ui.c which contain several parse_menu_t arrays (AKA mgmtParseInfo). These arrays are used to build a tree of tokens used to respond to commands sent over from the MGD to your daemon.

acme_main - this is the first level of tokens. This daemon expects 'quit' or 'show ...' or 'clear ...'.

 parse_menu_t acme_menu_main[] = {
    { "quit",        0,    NULL,                acme_quit },
    { "show",        0,    acme_menu_show,    NULL },
    { "clear",       0,    acme_menu_clear,   NULL },
    { NULL,          0,    NULL,                NULL }

acme_menu_show - This is the 'show' level, it has the tokens that are available at 'show ?' level. In this case 'show spanning-tree' and 'show version' are options.

 parse_menu_t acme_menu_show[] = {
    { "spanning-tree",  0, acme_menu_show_stp,            NULL },
    { "version",       0,  acme_menu_show_version,        NULL },
    { NULL,            0,  NULL,                          NULL }

Finally we have some leaf nodes that do something. 'show version brief' and 'show version detail' will call acme_version(). DISP_BRIEF or DISP_DETAIL are set at the 'subcode' field in the passed in parse_status_t arg.

 parse_menu_t acme_menu_show_version[] = {
     { "brief",        DISP_BRIEF,    NULL,        acme_version },
     { "detail",       DISP_DETAIL,   NULL,        acme_version },
     { NULL,                0,        NULL,          NULL }

 acme_version (mgmt_sock_t *msp, parse_status_t *pstatus, char *rest)
        int detail_level;

        detail_level = pstatus->subcode;

Function Documentation

int ms_parse_get_subcode const parse_status_t *  csb  ) 

Gets the parsing subcode from the status structure.

This is typically used to get the detail level information in an operational command.
csb Pointer to the parse status structure
Parsing subcode

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:24:32 2010 for libjuniper by Doxygen 1.4.5