Abstract:
A method and system is provided for making it convenient to alter the syntax of the command-line interface, or re-write it from scratch, without resorting to the alteration of source code. This reduces the level of skill required to make these changes, and also reduces the time and effort required. In particular, the present application provides for a method and system for defining an interface syntax using the high-level generic markup language XML (eXtensible Markup Language). Since XML is a simple language it is easier and less time-consuming to edit an existing syntax or write a new one from scratch. Initially, a CLI specification is defined in XML. Subsequently, the XML CLI is translated into source code as part of a compilation process. When compiled, the translated source code can initialize data structures to be read by a parser (whose code is fixed) to thereby implement the syntax defined initially in XML.

Description:
CROSS-REFERENCE TO RELATED APPLICATIONS  
       [0001]    The present application is a non-provisional of co-pending U.S. Provisional Patent Application No. 60/319,273, filed on May 29, 2002, the entirety of which is incorporated by reference herein. 
     
    
     
       BACKGROUND OF THE INVENTION  
         [0002]    The present invention relates generally to systems for controlling embedded devices and, more particularly, to systems and methods for providing adaptable and configurable command-line interfaces to such devices.  
           [0003]    The command-line interface or ‘CLI’ is the primary user interface used for configuring, monitoring, and maintaining devices having embedded operating systems. Unlike personal computers or other systems running general operating systems (e.g., Microsoft Windows), embedded systems such as network switches and routers operate using a more specific embedded operating systems. Further unlike such general systems, embedded systems are typically provided with minimal user interface capabilities, since the majority of functions performed by the device are pre-configured during device assembly. However, in order to provide some degree of adaptability, some embedded devices may include a CLI for receiving and responding to user requests. These user interfaces allow users to directly and simply execute commands, whether using a connected console or terminal, or using remote access methods, such as TELNET.  
           [0004]    In general, most CLI&#39;s are DOS-like interfaces in which each input command has a command name followed by a string of parameters. Further, a CLI may have a variety of “looks and feels”, which are generally defined by the various commands required to interact with the system and the format of the output from the system. Unfortunately, specifying these commands typically involves changing source code or other relatively low-level definitions within the system itself. This means that a relatively high degree of skill is required to specify a relatively simple interface. Further, changes or additions to the interface will also require such high level changes, which can result in both time consuming and costly revisions.  
           [0005]    Accordingly, there is a need in the are of embedded systems command-line interfaces for a system and method for enabling CLI specification in a time-efficient and simple manner, and also requiring a significantly reduced skill level.  
         BRIEF SUMMARY OF THE INVENTION  
         [0006]    The present invention overcomes the problems noted above, and provides additional advantages, by providing a method and system for making it convenient to alter the syntax of the command-line interface, or re-write it from scratch, without resorting to the alteration of source code. This reduces the level of skill required to make these changes, and also reduces the time and effort required. In particular, the present application provides for a method and system for defining an interface syntax using the high-level generic markup language XML (eXtensible Markup Language). Since XML is a simple language it is easier and less time-consuming to edit an existing syntax or write a new one from scratch.  
           [0007]    In one embodiment of the present invention, a CLI specification is initially defined in XML. Subsequently, the XML CLI is translated into source code as part of a compilation process. When compiled, the translated source code can initialize data structures to be read by a parser (whose code is fixed) to thereby implement the syntax defined initially in XML. In an alternative embodiment, an XML CLI specification can be read by the target device and the data structures generated directly at run-time. In this manner, the XML specification is read into the device every time the device is started up. The downside of this embodiment is increased startup time of the device, however, such an embodiment may prove more convenient if the defined syntax is likely to be altered more often or if a compiling is absent from the device. 
       
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS  
       [0008]    The present invention can be understood more completely by reading the following Detailed Description of the Preferred Embodiments, in conjunction with the accompanying drawing.  
         [0009]    [0009]FIG. 1 is a flow diagram illustrating one method for providing a command-line interface in accordance with the present invention.  
         [0010]    [0010]FIG. 2 is a flow diagram illustrating one embodiment of a method for defining the command line syntax of step  100 .  
         [0011]    [0011]FIG. 3 is a flow diagram illustrating one embodiment of a method for adding additional actions in accordance with the present invention.  
         [0012]    [0012]FIG. 4 is a flow diagram illustrating one method for utilizing of an XML CLI specification produced in the manner set forth in FIGS.  1 - 3 . 
     
    
     DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS  
       [0013]    The description below covers a method of converting an XML command-line interface specification into source code at compile-time—as noted above, it would also be possible to parse the XML at run-time to save compilation complexity and potentially increase flexibility, at the expense of increasing startup time of the target hardware.  
         [0014]    Referring to the Figures and, in particular, to FIG. 1, there is shown a flow diagram illustrating one method for providing a command-line interface in accordance with the present invention. Initially, in step  100 , a command-line interface syntax is defined in a series of XML and related files, using a pre-defined syntax. Additional details regarding file content and syntax are set forth in additional detail below. Next, in step  102 , each file in the group is read by a translation program which outputs a single source code file (in the C or C++ language, for example) in step  104 .  
         [0015]    In a preferred embodiment, the CLI code is auto-generated by a cli_parser script as part of the compilation process  102  during device boot-up. This script reads in XML specifications of the CLI grammar and outputs C code containing a list of action functions, for use by a parser, and a function to build appropriate parse trees. The parser then utilizes the code in responding to user-input commands.  
         [0016]    By providing the CLI in a series of XML files, it is easily possible to exclude groups of commands within the syntax from the finished interface by removing appropriate XML files from the list of files to be translated. The following code section represents one illustration of an example XML CLI specification file:  
         [0017]    &lt;?xml version=“1.0” standalone=“yes”?&gt; 
         [0018]    &lt;!DOCTYPE clispec SYSTEM “clispec.dtd”&gt; 
         [0019]    &lt;clispec&gt; 
         [0020]    &lt;keyword id=“_dest_ip_addr_” type=“V4IpAddr”/&gt; 
         [0021]    &lt;keyword id=“_src_ip_addr_” type=“V4IpAddr”/&gt; 
         [0022]    &lt;keyword id=“_ipaddr_” type=“V4IpAddr”/&gt; 
         [0023]    &lt;keyword id=“_netmask_” type=“V4IpAddr”/&gt; 
         [0024]    &lt;keyword id=“_name_” type=“String”/&gt; 
         [0025]    &lt;keyword id=“_vci_” type=“Integer”/&gt; 
         [0026]    .  
         [0027]    .  
         [0028]    &lt;command&gt; 
         [0029]    &lt;syntax&gt;ip set interface _name_ipaddress _ipaddr_&lt;/syntax&gt; 
         [0030]    &lt;user&gt;engineer&lt;/user&gt; 
         [0031]    &lt;user&gt;developer&lt;/user&gt; 
         [0032]    &lt;action id=“set”&gt; 
         [0033]    &lt;param name=“name0” value=“_name”/&gt; 
         [0034]    &lt;param name=“type0” value=“ImIpInterface”/&gt; 
         [0035]    &lt;param name=“attribute” value=“ipaddr”/&gt; 
         [0036]    &lt;param name=“value” value=“_ipaddr_”/&gt; 
         [0037]    &lt;/action&gt; 
         [0038]    &lt;code&gt; 
         [0039]    //Can insert arbitrary C/C++ code here  
         [0040]    &lt;/code&gt; 
         [0041]    &lt;/command&gt; 
         [0042]    .  
         [0043]    .  
         [0044]    &lt;node id=“ip”&gt; 
         [0045]    &lt;summary&gt;Commands to configure the router&lt;/summary&gt; 
         [0046]    &lt;/node&gt; 
         [0047]    &lt;node id=“ip set”&gt; 
         [0048]    &lt;summary&gt;Commands to set attributes within the router&lt;/summary&gt; 
         [0049]    &lt;/node&gt; 
         [0050]    &lt;node id=“ip set interface”&gt; 
         [0051]    &lt;summary&gt;Commands to set attributes of IP interfaces&lt;/summary&gt; 
         [0052]    &lt;/node&gt; 
         [0053]    .  
         [0054]    . &lt;/clispec&gt; 
         [0055]    Referring now to FIG. 2, there is shown a flow diagram illustrating one embodiment of a method for defining the command line syntax of step  100 . As can be seen from the above examplte, the XML CLI specification file is split into three discrete sections. A first section is defined in step  200  and serves to specify a set of parameter specifiers. These are arbitrary strings which are taken to represent parameters in the commands which are then further defined later in the file. As well as the string itself these parameter lines also specify a type for each parameter defined, which must be from a fixed list of supported types. This allows some basic checking of the values entered on the command line.  
         [0056]    In step  202 , a second section in the CLI specification file is provided for specifying the commands themselves which are defined in the CLI. Each command automatically checks that the correct number of arguments has been supplied, and will fail with an appropriate message to the user if appropriate arguments are not supplied. Some commands may require arbitrary lists of arguments, however, so this behavior can be disabled by modifying the command directive to:  
         [0057]    &lt;command extraargs=“true”&gt; 
         [0058]    In defining CLI commands, the syntax of the command is initially specified in step  204 . In the syntax string any token which isn&#39;t a parameter specifier (as defined earlier in the first section of the CLI specification) is taken to be a keyword—i.e. a string which must match exactly on the command line. In a preferred embodiment, the parsing engine matches all non-keyword tokens in the same way irrespective of type. This means that the first difference between two commands must be in a keyword token. For example, it is not valid to have two unique commands specified as:  
         [0059]    ip set interface &lt;iface&gt; &lt;ipaddress&gt; 
         [0060]    and  
         [0061]    ip set interface &lt;iface&gt; &lt;mtu&gt; 
         [0062]    because during command parsing it is not possible to distinguish between an arbitrary integer and an arbitrary IP address. The only way to implement the above syntax would be to have the action function perform any necessary parsing after the interface name, and declare a single variable to represent both of the above options (ipaddress and mtu). Following the syntax definition in the command section is a set of level declarations. The level declarations specify the levels of user access to which the defined command is available.  
         [0063]    The actions to be taken upon execution of a defined command are then specified in step  206  in the order in which they are to be performed and are identified by name. The current scheme assumes that a function of the form action_foo should be called to carry out the action called “foo”. Further, a list of parameters can be declared within each action specifier introduced in step  208 . If any of the value strings match one of the parameter specifiers defined earlier in the first section, the appropriate token from the command line will be substituted in its place. Otherwise the string specified will be passed on as a verbatim string.  
         [0064]    An action in this context is a single function that has been implemented in a source file. Each action has an associated textual name and this is used to refer to the action within the XML CLI specification. Each action can take a list of parameters, specified as name/value pairs—all these values are stored as strings. Due to the scheme of parsing the CLI specification during a compilation phase, actions can simply be specified as functions with names of the form action_set( ). The compilation process will automatically generate a function associated with each CLI command and these will call the action functions directly.  
         [0065]    Next, in step  210 , a class called ParameterList is set up to store the list of name/value pairs that make up the parameters. In one embodiment, this is created by the auto-generated functions and filled with the appropriate values either specified in the XML file or extracted from the command line. The ParameterList class has a simple interface to obtain the values of various parameters—actions can call a method get Parameter as follows:  
         [0066]    const char*value=paramList→getParameter(“ipaddr”)  
         [0067]    In this manner, parameter values for actions may be easily obtained.  
         [0068]    The following description recites a plurality of exemplary actions which may be included in commands defined in an XML CLI specification, however, these actions should not be viewed as limitations to the present invention, since additional actions may be defined and utilized as required.  
         [0069]    The following actions relate generally to manipulation actions for setting attributes, adding and deleting nodes, etc. In particular, an “add” action creates a new node, whose name and type are specified by newname and newtype respectively. The newname parameter is optional. The node specified is used as the parent for adding the node to the tree. Additionally a set of parameters of the form attributex and valuex, which are used to set attributes of the newly created node. A “clear” action takes a node specification and deletes all children of that node. A “delete” action takes a node specification and deletes that node. A “get” action displays the value of the attribute specified by the parameter attribute of the specified node. A “list” action lists children of the specified node—this is included for debugging purposes. A “listall” action displays a complete report of the device state for debugging purposes. A “set” action sets the value of the attribute specified by the parameter attribute to the value specified by the parameter value for the specified node. A “set_multiple” action is similar to the “set” action, and takes a list of attribute triplets of the form cliattribute0, imattribute0, attrtype0. The action searches the list of arguments not parsed for tokens matching those specified by the cliattributex parameters. When one is found, the command-line argument following it is used as the new value for the attribute specified by the corresponding imattributex parameter. Use of this macro can cause confusion as the attribute names will not be tab-completed by the parser, so care should be used.  
         [0070]    The following actions relate to transport manipulation actions. In particular, the CLI specification presents a somewhat abstracted version of the Information Model structure, where a layer 2 session, channel and service are all created and attached together in a single operation. The combination of these three objects is known as a transport. An “add_&lt;service&gt;” action creates a service, layer 2 session and channel and attaches them together. The types supported are listed below with the parameters that must be supplied:  
         [0071]    ether—name, creator, description, port  
         [0072]    frame_relay—name, creator, description, port, dlci  
         [0073]    rfc1483—name, creator, description, rxvci, txvci, rxvpi, txvpi, port, mode  
         [0074]    ppp_pvc—name, creator, description, rxvci, txvci, rxvpi, txvpi, listener, interface  
         [0075]    ppp_svc—name, creator, description, listener, interface  
         [0076]    pppoe_pvc—name, creator, description, rxvci, txvci, rxvpi, txvpi, listener, interface  
         [0077]    pppoe_svc—name, creator, description, listener, interface  
         [0078]    ppp_hdlc—name, creator, description, listener, interface  
         [0079]    ipoa_pvc—name, creator, description, rxvci, txvci, rxvpi, txvpi  
         [0080]    ipoa_svc—name, creator, description  
         [0081]    An “attach_channel” action takes the name of a service and the txvci, rxvci, txvpi, rxvpi and port parameters. Further, the action creates an ATM channel with the specified attributes and attaches it to the specified service. This is used for creating new channels after a transport has initially been created. An “attach_service” action attaches the specified IP interface node to the transport given by the transportname parameter. A “clear_service” action is similar to the “clear” action described above, but takes a single parameter type and deletes all services of that type (and also performs any additional detaching required). A “detach_channels” action takes txvci, rxvci, txvpi, rxvpi and port parameters and destroys any channels on the specified service which match those attributes. A “detach_service” action treats the specified node as an IP interface and detaches any services attached to it.  
         [0082]    In some cases the generic manipulation actions described above are not appropriate and specialized versions which operate differently are required. Examples of such actions are set forth below. An “add_user” action creates a new user with a name specified by the username attribute. A “set_autoprov” action takes a single parameter setting which should be either opendsl, autopvc or nothing. The current autoprovisioning scheme is set accordingly. A “set_password” action prompts the current user to set their password, then verifies it and sets the value in the Information Model if the two strings match. Note that this differs from other set methods in that it does not take the new value for the password as a parameter (to avoid the user having to display it on the screen). A “set_user” action changes the current effective user without prompting for a password. It should be understood that it is important to ensure that only a sufficiently privileged user has access to a command using this action.  
         [0083]    Several actions are supported for saving the configuration. “Config_save” and “config_restore” actions save to and restore from the standard configuration.  
         [0084]    “Config_save_backup” and “config_restore_backup” actions save to and restore from the backup configuration. A “config_restore_factory” action restores the system to factory defaults.  
         [0085]    Regarding parsed output actions, the primary form of output is in the form of text files which contain macros to interrogate the state of the system and substitute values as appropriate. These are sent to the console using the actions listed below. A “display_macro” action displays the text file containing the associated macros specified by the url parameter to the console. A “display_node_macro” is similar to the “display_macro” action above, however, this also takes a node specification attribute. The path to this node is placed in the context&#39;s text buffer before the text file is displayed.  
         [0086]    Regarding traditional console access (that is, non-web access), several actions exist to provide access to the traditional console. A “do_tell” action is provided for taking a list of parameters of the form tellargx, concatenating them together and using the traditional console to parse them with any specified blacklisting. A “do_cli_tell” is similar to the “do_tell” action, but takes the arguments for the tell message from the command-line. An “old_console” action causes the CLI to drop down to the traditional console.  
         [0087]    Various actions are also provided for performing miscellaneous functions. In particular, the “calculate_netmask” action takes two parameters, addressattribute and netmaskattribute. If the attribute specified by netmaskattribute is not set, the attribute specified by addressattribute is treated as an IP address and its natural netmask is calculated. This is stored in the attribute referred to by netmaskattribute. A “check_enabled” action takes two parameters: attribute and message. If the specified attribute has the value false, then the specified message is displayed. This is typically used to remind the user that a service is not enabled if they change its configuration. An “enact” action calls the enact function on the specified node, which must conform to the ImEnactable interface. A “list_ports” action lists all the Ethernet ports in the system. A “logout” action logs the current user out, killing their TELNET connection if applicable. A “reboot” action causes a reboot. A “trace” action sets the trace level, as specified by the level attribute which should be one of LogLevelNone, LogLevelWarning, LogLevelInfo, LogLevelTrace, LogLevelEntryExitTrace or LogLevelAll.  
         [0088]    In addition to the identified and supported actions described above, the present inventions provides increased flexibility by enabling the addition of new actions. Referring now to FIG. 3, there is shown a flow diagram illustrating one embodiment of a method for adding additional actions in accordance with the present invention. In step  300 , a new function is written to implement the desired action. Next, in step  302 , the new function is made available to the parser as a shared library. Prototypes for all the functions used should then be placed in a header file as usual in step  304 . In step  306 , an &lt;extraheaders&gt; tag is inserted into the XML CLI specification files to include these header files in the output code—anything between this and its matching closing tag will be placed in the auto-generated include file. It should be noted that any other elements which are needed to support C code fragments which are to be included in the output files should also be placed in the &lt;extraheaders&gt; tag. The paths to these include files must then be manually inserted into the CLI&#39;s specification file.  
         [0089]    It is also possible to include arbitrary C/C++ code in the auto-generated functions. This can be useful for small or specialized tasks where the work of writing a new action is not justified. Any code can be included, though it is still built as part of the overall process so all functions accessed must either be part of the same process or built as a shared library. Any headers required can be included using the &lt;extraheaders&gt; tag as described above.  
         [0090]    Returning now to FIG. 2, any desired C code commands or instructions may be inserted in step  212 . This is preferably accomplished through the use of a &lt;code&gt; tag to include the C code for a CLI command. The &lt;code&gt; tag has no attributes and can be used anywhere where an &lt;action&gt; tag is used. Any code placed between this tag and its closing tag is included in the function associated with that CLI command. Actions and code sections can be mixed arbitrarily and are always included in the order they occur in the XML file. As one optimization of the present invention, if a CLI command only contains code sections and no actions, much of the initialization code is skipped for that command. This includes gaining a lock on the Information Model, so the code may potentially have to acquire a lock itself if it wishes to access the Information Model.  
         [0091]    A third section of the CLI specification file is defined in step  214  and specifies any additional information about the nodes in the parse tree that is required. In the above embodiment, this information consists of summary help for each node, generally describing the function associated with each node. In one embodiment of the present invention, the summary is a string listed with a token when it is presented as a possible completion of a command.  
         [0092]    Referring now to FIG. 4, there is shown a flow diagram illustrating one method for utilizing of an XML CLI specification produced in the manner set forth above in FIGS.  1 - 3 . Initially, in step  400 , source code generated in the manner described above is compiled to creating a parse-tree data structure in memory on the target hardware. In step  402 , a parser, whose implementation is fixed (i.e. is not generated as part of the compile process), then interprets the strings entered by the user by traversing the created parse-tree structure. Further, in step  404 , nodes are defined within the parse-tree structure corresponding to valid commands have a function associated. These functions are then called when a user enters the associated command at the interface in step  406 . These functions contain code to extract any required parameters from the input string and call into more general functions to actually implement configuration changes on the target hardware in step  408 . The translation program creates these functions by interpreting the list of actions specified in the XML file in step  410 . Further, the translation program determines, in step  412 , which arguments need to be extracted from the string entered by the user and passes them into calls to the appropriate external functions to effect the changes in step  414 . The external functions take the form of a fixed external API (applications programming interface) which is defined independently and is outside the scope of the present invention.  
         [0093]    In accordance with one embodiment of the present invention, commands may be defined in terms of user access. Accordingly, separate parse-trees may be generated for each user of the system. Therefore, each user only observes commands to which they have access.  
         [0094]    As is understood in the art, each series of XML files requires at least an associated document type definition (DTD) which defines the legal building blocks of an XML document. The DTD defines the document structure with a list of legal elements. A DTD can be declared inline in the XML document, or as an external reference typically having a .dtd extension which is referenced by the associated XML file. One embodiment of a DTD file supporting the present invention is shown below although any actual DTD files would include elements specifically related to its associated XML file.  
         [0095]    &lt;!ELEMENT clispec (scriptversion?,  
         [0096]    extraheaders?,  
         [0097]    alias?,  
         [0098]    keyword*,  
         [0099]    command*,  
         [0100]    node*)&gt; 
         [0101]    &lt;!ELEMENT scriptversion (#PCDATA)&gt; 
         [0102]    &lt;!ELEMENT extraheaders (#PCDATA)&gt; 
         [0103]    &lt;!ELEMENT alias EMPTY&gt; 
         [0104]    &lt;!ATTLIST alias from CDATA #REQUIRED&gt; 
         [0105]    &lt;!ATTLIST alias to CDATA #REQUIRED&gt; 
         [0106]    &lt;!ELEMENT keyword EMPTY&gt; 
         [0107]    &lt;!ATTLIST keyword id CDATA #REQUIRED&gt; 
         [0108]    &lt;!ATTLIST keyword type CDATA #REQUIRED&gt; 
         [0109]    &lt;!ELEMENT command (syntax,  
         [0110]    user*,  
         [0111]    (action|code)*)&gt; 
         [0112]    &lt;!ATTLIST command extraargs (true|false) “false”&gt; 
         [0113]    &lt;!ELEMENT syntax (#PCDATA)&gt; 
         [0114]    &lt;!ELEMENT user (#PCDATA)&gt; 
         [0115]    &lt;!ELEMENT action (param*)&gt; 
         [0116]    &lt;!ATTLIST action id CDATA #REQUIRED&gt; 
         [0117]    &lt;!ELEMENT code (#PCDATA)&gt; 
         [0118]    &lt;!ELEMENT param (#PCDATA)&gt; 
         [0119]    &lt;!ATTLIST param name CDATA #REQUIRED&gt; 
         [0120]    &lt;!ATTLIST param value CDATA #REQUIRED&gt; 
         [0121]    &lt;!ELEMENT node (summary?)&gt; 
         [0122]    &lt;!ATTLIST node id CDATA #REQUIRED&gt; 
         [0123]    &lt;!ELEMENT summary (#PCDATA)&gt; 
         [0124]    Additionally, a templates file is also preferably included within the series of XML files for including code which is used to build up the output source code files by substituting in strings into the CLI specification file. Preferred embodiments of both an XML CLI specification file as well as a template file are provided in Appendixes A and B, respectively.  
         [0125]    By providing the capability for easily and quickly defining and implementing a new or modified CLI, changes to an existing interface may be made at a substantially reduced cost in terms of both time and money. While the foregoing description includes many details and specificities, it is to be understood that these have been included for purposes of explanation only, and are not to be interpreted as limitations of the present invention. Many modifications to the embodiments described above can be made without departing from the spirit and scope of the invention, as is intended to be encompassed by the following claims and their legal equivalents.