Summary of the invention
In view of this, the purpose of the embodiment of the present invention is to provide a kind of generation method of table entry operation-interface function
And device, improve the formation efficiency of interface function, reduce development cost.
For solving above-mentioned technical problem, the embodiment of the present invention provides scheme as follows:
A kind of generation method of table entry operation-interface function, is applied to network processing unit, including:
Obtain the Table Properties definition file of corresponding traffic table, this document is preserved the Table Properties of corresponding traffic table
Parameter;
Obtain the handling function template of corresponding traffic table;
Table Properties definition file according to corresponding traffic table and handling function template, generate the behaviour of corresponding traffic table
Make interface function.
Preferably, in said method, described Table Properties parameter includes at least one in following parameter:
Traffic table title, traffic table place memory interface, read-write position degree, table size, table initial address,
Handling function mark that key assignments, the traffic table of tabling look-up is corresponding and traffic table field.
Preferably, in said method, further according to the operation that the traffic table in described Table Properties parameter is corresponding
Function identification, from the template base preserving multiple handling function template, extracts the operation letter of corresponding traffic table
Digital-to-analogue plate.
Preferably, in said method, the described Table Properties definition file according to corresponding traffic table and handling function
Template, generates the operation interface function of corresponding traffic table, including:
Resolve the Table Properties definition file of corresponding traffic table, it is thus achieved that the Table Properties parameter of corresponding traffic table;
By the Table Properties parameter of corresponding traffic table, it is filled in the handling function template of corresponding traffic table, obtains
The operation interface function of corresponding traffic table, and generate the code of the operation interface function of corresponding traffic table.
Preferably, in said method, before obtaining the Table Properties definition file of corresponding traffic table, described side
Method also includes:
Receive and preserve user's amendment to the Table Properties parameter in Table Properties definition file;And/or
Receive and preserve user's amendment to handling function template.
The embodiment of the present invention additionally provides the generating means of a kind of table entry operation-interface function, is applied at network
Reason device, including:
First acquiring unit, for obtaining the Table Properties definition file of corresponding traffic table, preserves in this document
The Table Properties parameter of corresponding traffic table;
Second acquisition unit, for obtaining the handling function template of corresponding traffic table;
Function generation unit, for the Table Properties definition file according to corresponding traffic table and handling function template,
Generate the operation interface function of corresponding traffic table.
Preferably, in said apparatus, described Table Properties parameter includes at least one in following parameter:
Traffic table title, traffic table place memory interface, read-write position degree, table size, table initial address,
Handling function mark that key assignments, the traffic table of tabling look-up is corresponding and traffic table field.
Preferably, in said apparatus, described second acquisition unit, further according in described Table Properties parameter
Traffic table corresponding handling function mark, from the template base preserving multiple handling function template, extract
The handling function template of corresponding traffic table.
Preferably, in said apparatus, described function generation unit includes:
Resolution unit, for resolving the Table Properties definition file of corresponding traffic table, it is thus achieved that the table of corresponding traffic table
Property parameters;
Code obtains unit, for the Table Properties parameter by corresponding traffic table, is filled into the behaviour of corresponding traffic table
Make in function template, obtain the operation interface function of corresponding traffic table, and the operation generating corresponding traffic table connects
The code of mouth function.
Preferably, in said apparatus, also include:
User interaction unit, for receiving and preserve user to the Table Properties parameter in Table Properties definition file
Amendment;And/or receive and preserve user's amendment to handling function template.
From the above it can be seen that the generation method of table entry operation-interface function that provides of the embodiment of the present invention
And device, drive developer when needs increase, delete or revise table definition, it is only necessary to Table Properties
Definition file is modified;When needs Modification growth function framework, it is only necessary to function template is modified, because of
This method significantly reduces peopleware's workload, reduces software cost, improves software development efficiency.
Detailed description of the invention
The embodiment of the invention discloses a kind of method automatically generating table entry operation-interface function, can be the biggest
Alleviate the workload of software developer in degree, reduce software development cost, improve software development efficiency.
For making the object, technical solutions and advantages of the present invention clearer, below in conjunction with the accompanying drawings and the specific embodiments
Describe the present invention.
Inventor finds, for every a network processing unit, table entry operation-interface function structure is identical
, difference is simply that the memory interface belonging to function, read-write bit wide, table initial address and table are big
The parameter such as little.
For example, certain traffic table tableA, its list item adds function and deletion function is as follows: (for convenience
Understand, illustrate with simple version)
The traffic table association attributes part that therefore, it can to change these (as tableA, tableB,
Sram_64) being defined in a list item attribute text, constant part is then defined into function template file
In.Function Core Generator reads list item attribute text and template file simultaneously, and the attribute of change is filled into mould
In plate, thus automatic code generating.
Based on above design, embodiments provide a kind of generation method of table entry operation-interface function,
It is applied to network processing unit.As it is shown in figure 1, the method includes:
Step 11, obtains the Table Properties definition file of corresponding traffic table, preserves corresponding business in this document
The Table Properties parameter of table.
Here, described Table Properties parameter includes at least one in following parameter: traffic table title, traffic table
Place memory interface, read-write position degree, table size, table initial address, key assignments of tabling look-up, traffic table are corresponding
Handling function mark and traffic table field etc..
Step 12, obtains the handling function template of corresponding traffic table.
In the present embodiment, multiple handling function templates can be preserved in template base in advance.Then, in this step
In 12, according to the handling function mark that the traffic table in described Table Properties parameter is corresponding, multiple from preserving
In the template base of handling function template, extract the handling function template of corresponding traffic table.
Step 13, according to Table Properties definition file and the handling function template of corresponding traffic table, generates correspondence
The operation interface function of traffic table.
This step 13 specifically may include that the Table Properties definition file resolving corresponding traffic table, it is thus achieved that corresponding
The Table Properties parameter of traffic table;By the Table Properties parameter of corresponding traffic table, it is filled into the operation of corresponding traffic table
In function template, obtain the operation interface function of corresponding traffic table, and generate the operation interface of corresponding traffic table
The code of function.
As for the Table Properties definition file used in the present embodiment and handling function template, user can be in advance
Self-defining or establishment as required.Then, by receiving and preserve user in Table Properties definition file
The amendment of Table Properties parameter;And/or receiving and preserve user's amendment to handling function template, it is thus achieved that table belongs to
Property definition file and handling function template.
From the above it can be seen that after using said method, drive developer to increase at needs, delete
Or during amendment table definition, it is only necessary to Table Properties definition file is modified;At needs Modification growth function framework
Time, it is only necessary to function template is modified, therefore the method significantly reduces peopleware's workload, fall
Low software cost, improves software development efficiency.
The embodiment of the present invention additionally provides a kind of device implementing said method, and this device is as in figure 2 it is shown, be somebody's turn to do
The generating means of table entry operation-interface function includes:
First acquiring unit, for obtaining the Table Properties definition file of corresponding traffic table, preserves in this document
The Table Properties parameter of corresponding traffic table;Here, described Table Properties parameter can include in following parameter at least
A kind of: traffic table title, traffic table place memory interface, read-write position degree, table size, table initial address,
Handling function mark that key assignments, the traffic table of tabling look-up is corresponding and traffic table field.
Second acquisition unit, for obtaining the handling function template of corresponding traffic table.
Function generation unit, for the Table Properties definition file according to corresponding traffic table and handling function template,
Generate the operation interface function of corresponding traffic table.
As a kind of preferred implementation, described second acquisition unit, can be further according to described Table Properties
The handling function mark that traffic table in parameter is corresponding, from the template base preserving multiple handling function template
In, extract the handling function template of corresponding traffic table.
As a kind of preferred implementation, described function generation unit specifically may include that
Resolution unit, for resolving the Table Properties definition file of corresponding traffic table, it is thus achieved that the table of corresponding traffic table
Property parameters;
Code obtains unit, for the Table Properties parameter by corresponding traffic table, is filled into the behaviour of corresponding traffic table
Make in function template, obtain the operation interface function of corresponding traffic table, and the operation generating corresponding traffic table connects
The code of mouth function.
Said apparatus can also include a user interaction unit (not shown), is used for receiving and preserving use
The family amendment to the Table Properties parameter in Table Properties definition file;And/or receive and preserve user to operation letter
The amendment of digital-to-analogue plate.
The embodiment of the present invention additionally provides another structure implementing said method, as it is shown on figure 3, this structure bag
Include:
Table Properties data base 101, there is defined the attribute of each traffic table.Such as, defined in this example
The text formatting structure of certain traffic table attribute as follows:
Code Template storehouse 102, there is defined the template of various handling function.Certain class defined in this example
It is as follows that type table adds function template:
Wherein tableName, RAM_Type, op_width are the variablees such as Table Properties parameter, need from 101
The Table Properties data base of middle establishment extracts and is substituted in template.
Function Core Generator 103, automatically generates the function of code, specifically includes resolver 104 and maker
105 two parts.
Resolver 104, for resolution table attribute definition file, therefrom obtains each attribute of traffic table.
Maker 105, for selecting its template according to the template in traffic table attribute ID, and will be from solution
The Table Properties obtained in parser is filled in template, in the handling function that final output to this traffic table is corresponding.
Object code 106, for exporting the various handling function codes of each traffic table.
Above-mentioned modules, wherein:
Table Properties file in Table Properties data base 101 module, with relatively simple txt text in this example
Form stores.Can essentially select the most flexibly, such as csv form, the form such as XML, only
If the form that the resolver 104 in function Core Generator 103 can resolve.
Stencil-chosen in Code Template storehouse 102 has multiple.The template framework of increasing income having multiple maturation at present can
Selective.This example can use web framework bottle based on python language, is specifically referred to
httn://www.oschina.net/p/bottle?Related introduction (official website httn: //bottlepy.org) in from=rss
To sum up, network processing unit list item flexible design, list item are changeable, and therefore table handling function (adds, deletes
Remove, update) need, often according to definition amendment, to cause substantial amounts of software maintenance cost.The present invention implements
Example is by pulling out changing unit and standing part by table function code, and standing part is defined into template file
In, changing unit is defined into Table Properties definition file, extracts information by script from Table Properties file,
Automatically insert in template file, quickly generate code, thus greatly reduce software cost, improve out
Send out efficiency.
These many functional parts described in this description are all referred to as module, in order to specifically emphasize it
The independence of implementation.
In the embodiment of the present invention, module can realize with software, in order to is performed by various types of processors.
For example, the executable code module of a mark can include one or more physics of computer instruction
Or logical block, for example, it can be built as object, process or function.While it is true, marked
The executable code knowing module need not be physically located together, but can include being stored in different physically
Different instructions, when combining in these command logics, it constitutes module and realizes this module
Regulation purpose.
It practice, executable code module can be individual instructions or many bar instructions, and even may be used
To be distributed on multiple different code segment, it is distributed in the middle of distinct program, and crosses over multiple memorizer and set
Back-up cloth.Similarly, operation data can be identified in module, and can be according to any suitable shape
Formula realizes and is organized in the data structure of any suitable type.Described operation data can be as single
Data set is collected, or can be distributed on diverse location and (be included in different storage device), and
Electronic signal can be only used as at least in part be present on system or network.
When module can utilize software to realize, it is contemplated that the level of existing hardware technique, it is possible to soft
The module that part realizes, in the case of not considering cost, those skilled in the art can build the hard of correspondence
Part circuit realizes the function of correspondence, and described hardware circuit includes ultra-large integrated (VLSI) of routine
Circuit or gate array and the existing quasiconductor of such as logic chip, transistor etc or other is discrete
Element.Module can also use programmable hardware device, such as field programmable gate array, programmable array
Logic, programmable logic device etc. realize.
The above is only embodiments of the present invention, it is noted that for the ordinary skill of the art
For personnel, under the premise without departing from the principles of the invention, it is also possible to make some improvements and modifications, these
Improvements and modifications also should be regarded as protection scope of the present invention.