Embodiment
For making object of the present invention, technical scheme and advantage clearer,, scheme of the present invention is described in further detail referring to accompanying drawing also in conjunction with the embodiments.
Referring to Fig. 1, for the embodiment of the present invention is converted to network configuration protocol response message the method flow diagram of order line.This method is mainly used in, in NETCONF agency, comprising the steps:
Step 101, in advance according to modeling file, by the capable shell defined file that is converted to XML form of the shell-command of the network equipment.
In this step, the shell-command of the network equipment is defined by configuration module, generate the shell defined file of XML form.The relevant shell-command of a plurality of configuration modules can be defined in same shell defined file, if Shell defined file is larger, also can generate a plurality of shell defined files by configuration module.Modeling (Schema) file, is for describing the file of XML data constraint rule, and the content layer of NETCONF agreement and operation layer are carried out to abstract, modeling; When system starts, be loaded in NETCONF agency and NETCONF server memory.Due to the generation of modeling file with obtain, belong to prior art, repeat no more herein.
In Shell defined file, having two category nodes is command keyword (cmd-key) node and command parameter (cmd-param) node, cmd-key node represents that this is a keyword in order, and cmd-param node represents a parameter in order.Cmd-key node and cmd-param node mainly comprise name attribute, help attribute, the name of node under described name attribute representation, this node of name attribute representation of command keyword node the name of the capable component part of corresponding shell-command, the name attribute of command parameter node is consistent with the node name in Schema file; The help information of the affiliated node that help attribute representation can view by the command format of setting.In addition, can also be as required node definition xpath path attribute, filter path attribute and the type type attribute of shell defined file; Xpath attribute and filter attribute all represent path, consistent with the path of affiliated node in modeling file, the path of the command parameter node of xpath attribute representation configuration order in modeling file, the storing path of the relevant information that filter attribute representation obtains configuration information order in modeling file; The type of type attribute representation parameter.Can also define target-mode attribute, generally appear in leaf node, represent that this order is a configuration mode switching command, carries out the target configuration pattern being switched to after this order.
In the present embodiment, by the capable method that is converted to the shell defined file of XML form of the shell-command of the network equipment, specifically comprise:
A1. by function, be divided into configuration module by the shell-command of the network equipment is capable.
A2. be defined in same shell defined file all shell-commands that belong to same configuration module are capable.
A3. in described shell defined file, when the capable composition node of shell-command has definition in Schema file, by this node definition, be the command parameter node of shell defined file, otherwise be defined as the command keyword node of shell defined file; Described command parameter node and command keyword node are in the hierarchical relationship of shell defined file, and the ordinal relation by it in shell-command is capable is determined.
In this step, capable for many shell-commands in same configuration module in first node identical, as shell-command " show run " and " show ospf ", only define a show node; Identical and its all ancestor node identical a plurality of nodes all for the brother of node in many shell-commands, in described shell defined file, described node is only defined to a node, for example Show interface carriage return, Show interface name, only need to define show node and interface node.
A4. specify name attribute and the help attribute of each node in described shell defined file.
According to above formula, the Shell defined file that the orders such as interface name, ip address ip subnetmask under the configuration module of module interfaces by name, mtu mtu, exit are generated is as follows:
The Shell defined file that show interface, show interface name under the configuration module of module show by name, show running-config order are generated is as follows:
The shell-command of above-mentioned interfaces and two configuration modules of show is capable has generated respectively a shell defined file, and certain two configuration modules can become a shell defined file.
Step 102, when system starts, is loaded into described shell defined file in internal memory, to generate shell binary tree.
When system starts, Shell defined file is loaded into internal memory, generate Shell binary tree.During loading, different configuration modules, is loaded into different shell binary trees.The present embodiment provides following two kinds of implementations.
Described shell defined file is loaded into the scheme one that generates shell binary tree in internal memory, specific implementation step is as follows: by the naming of described shell binary tree, be the name property value of configuration module node in described shell defined file; First child node of configuration module node in described shell defined file is loaded as to the root node of described shell binary tree, all the other child nodes of configuration module node in described shell defined file are loaded as to the brotgher of node of its previous child node, and the father node pointer of the above-mentioned node loading in shell binary tree is set to sky; First child node of non-configuration module node in described shell defined file is loaded as to the left child node of node described in shell binary tree, all the other child nodes of non-configuration module node described in shell defined file are loaded as to the brotgher of node of its previous child node corresponding node in described shell binary tree, and the father node pointer of the above-mentioned node loading in shell binary tree is set to its father node in described shell defined file corresponding node in described shell binary tree.
Described shell defined file is loaded into the scheme two that generates shell binary tree in internal memory, specific implementation step is as follows: by the naming of described shell binary tree, be the name property value of configuration module node in described shell defined file; Configuration module node in described shell defined file is loaded as to the root node of described shell binary tree; By first child node of configuration module node in described shell defined file, be loaded as the left child node of root node in described shell binary tree, by all the other child nodes of configuration module node described in described shell defined file, be loaded as the brotgher of node of its previous child node corresponding node in described shell binary tree, and the father node pointer of the above-mentioned node loading in shell binary tree is set to sky; By first child node of non-configuration module node in described shell defined file, be loaded as the left child node of non-configuration module node described in described shell binary tree, by all the other child nodes of non-configuration module node described in described shell defined file, be loaded as the brotgher of node of its previous child node corresponding node in described shell binary tree, and the father node pointer of the above-mentioned node loading in shell binary tree is set to its father node in described shell defined file corresponding node in described shell binary tree.The Shell defined file that is shown as being configuration module interfaces is loaded into the shell binary tree that internal memory forms.Its loading procedure is as follows:
The name property value that is configuration module node in described shell defined file by the naming of the corresponding shell binary tree of configuration module interfaces is interfaces; Then interfaces is loaded as to the root node of described shell binary tree; The child node interface and the child node thereof that load interfaces node, because the father node of interface child node is root node interfaces, be set to sky by the father node pointer of interface child node; Load the child node name of interface child node;
In like manner load the next brother node i p of interface node, it in binary tree, is the right child node of interface node, the father node pointer of ip node is set to sky, load the child node address of ip node, load the child node ip of address child node, reload the child node subnetmask of ip child node; Here two ip child nodes have been there are, previous type is cmd-key, then the type of is cmd-param, in the same command, there will not be two types is all the child node of the same name of cmd-key, even if but the type of two child nodes of the same name is all cmd-param, also can be distinguished according to its xpath, because can not there are two child nodes of the same name in schema file under same path; In like manner load next brother node mtu and all child nodes thereof of ip child node; In like manner load the node exit of next brother again and all child nodes thereof of mtu child node; All node loadeds, finally form the binary tree of interfaces configuration module, see Fig. 3.
In like manner load the shell binary tree that show configuration module shell defined file generates, as shown in Figure 4.
Step 103, according to the information in shell binary tree in internal memory, by receive from NETCONF server obtain the corresponding response message of configuration information order with user, be converted to shell-command capable.
When user is when the configuration information of network equipment total interface is obtained in CLI terminal execution Shell order " show interface ", NETCONF agency is converted to show interface request command the get-config request message of NETCONF agreement according to the Shell binary tree and the modeling file that are loaded in Installed System Memory, and in session, sends to NETCONF server.NETCONF server receives after this get-config request message, collects the configuration information relevant to interfaces in running database, and is packaged as rpc-reply message and returns to NETCONF and act on behalf of, and this process is prior art, repeats no more herein.
As NETCONF agency, from NETCONF server, receive XML form obtain rpc-reply response message corresponding to the order " show interface " of configuration information with user, can find the request message that this message is corresponding according to the Message ID in message, obtain user's the configuration order of obtaining, thereby judgement needs this response message to be converted to Shell order line to facilitate user to check, according to the Shell binary tree in internal memory, the data in XML response message is converted to Shell order line.
According to the information in shell binary tree in internal memory, by what receive, from NETCONF server, obtain the corresponding response message of configuration information order with user, be converted to the detailed process that shell-command is capable as follows: C1. resolution response message, removes XML header and obtains data division;
C2. the configuration module name represented according to top-level node, finds the shell binary tree that described configuration module is corresponding;
C3. shell binary tree described in inorder traversal, while traversing leaf node, from this leaf node, search successively its father node, and the father node of father node, until find ancestor node for empty, obtain a sequence node, described sequence node inverted order is arranged, if there is command parameter node in sequence node, by the value of this command parameter node in described response message, replace, thereby it is capable to obtain a shell-command;
C4. the leaf node from C3 starts, and continues to press shell binary tree described in the step inorder traversal of C3, until traveled through described shell binary tree;
If C5. also there is the brotgher of node of top-level node described in step C2, get the next brotgher of node, continue circulation execution step C2-C4, otherwise this flow process finishes.
Below in conjunction with the Shell binary tree of configuration module interfaces, concrete in explanation the data in the XML response message corresponding with shell-command " show interface " are converted to the process of Shell order line:
First resolve rpc-reply response message, remove header, obtain data division;
The configuration module name representing according to the top-level node interfaces of XML, finds the shell binary tree that described interfaces configuration module is corresponding;
Inorder traversal interfaces binary tree, obtain first node i nterface, for cmd-key node, but non-leaf node, continue again traversal, obtain name node, for cmd-param, it is leaf node, get successively name node, the father node interface of name node (frontly addresses, the father node pointer of interface node is empty), obtain a sequence node name interface, after inverted order, obtain interface name, because name node is cmd-param type, so replace by the value of node name in response message, obtain Shell order line: interface eth0.
From the target-mode attribute of name node, this order is a configuration mode switching command, need carry out pattern switching, so the order being parsed by interface node below will increase indentation, shows;
Continue this interfaces binary tree of inorder traversal, obtain successively ip, address, ip node, these three nodes are not leaf nodes, continue again traversal, obtain subnetmask node, it has been leaf node, so get subnetmask node, the father node ip of subnetmask node, the father node address of ip node, the father node ip of address node, the father node pointer of ip node is empty, finally obtain a sequence: subnetmask ip address ip, after inverted order, obtain ip address ip subnetmask, in this sequence, the node i p of cmd-param type is replaced with 192.168.1.1, node subnetmask replaces with 255.255.252.0, obtain Shell order: ip address 192.168.1.1255.255.252.0,
Continue traversal, in like manner can obtain Shell order: mtu 1500;
Continue traversal, in like manner can obtain Shell order: exit;
Because exit is a configuration mode switching command, so will reduce indentation demonstration to order below;
Now traversal of binary tree is complete, obtains following command sequence:
interface?eth0
ip?address?192.168.1.1255.255.252.0
mtu?1500
exit
Although traversal of binary tree is complete, also have the child node of <interfaces> node after XML, therefore again binary tree is traveled through; In like manner resolve XML message below, NETCONF agency finally parses corresponding Shell order behavior:
interface?eth0
ip?address?192.168.1.1255.255.252.0
mtu?1500
exit
interface?eth1
ip?address?128.255.41.209255.255.255.0
mtu?1500
exit
Referring to Fig. 5, be that the embodiment of the present invention is converted to network configuration protocol response message the structured flowchart of the device of order line, specifically comprise:
Shell defined file generation module, in advance according to modeling file, by the capable shell defined file that is converted to XML form of the shell-command of the network equipment;
Shell defined file load-on module, for when system starts, is loaded into described shell defined file in internal memory, to generate Shell binary tree; Also, for after changing at shell defined file, again shell defined file is loaded;
Shell order line modular converter, for after receiving the response message of NETCONF server, is converted to Shell order line according to Shell binary tree in internal memory by the data in response message.
The above, be only preferred embodiment of the present invention, is not intended to limit protection scope of the present invention.Within the spirit and principles in the present invention all, any modification of doing, be equal to replacement, improvement etc., within all should being included in protection scope of the present invention.