A kind of method for generating analysis source code of signaling message
Technical field
The present invention relates to the communication protocol analytic method of the communications field, specially refer to method for generating analysis source code of signaling message in communication protocol parsing.
Background technology
Communication protocol definition the specification that must observe in the time intercoming mutually of communication system, signaling is the nerve center that takes the form of communication system in communication network as communication protocol. and signaling message is generally used for controlling the equipment in communication network, and its correctness is directly connected to the normal operation of communication system.For quick diagnosis network failure, guarantee the normal work of communication network, provide reliable service to user, be necessary the signaling message in communication network to communicate protocol analysis.So-called communication protocol is resolved the signaling message being actually receiving and is resolved one by one, with reference to communication protocol standard specification, signaling message is carried out to the word for word decoding of section, also write out this signaling message and resolve required source code, and complete the parsing to signaling message on the basis of decoding.
At present, the communication protocol of prior art resolve in signaling message resolve required source code and mostly adopt artificial mode to write, manually with reference to protocol specification document to signaling message word for word section analyze and write out each field and resolve required source code, the set that each field is resolved required source code is this analysis source code of signaling message.But due to the numerous and most of protocol comparison complexity of communication protocol, the workload of manual compiling source code is larger, the duplication of labour is more.In addition, the later stage of resolving in communication protocol also needs the reliability and stability of all source codes to carry out a large amount of tests, many drawbacks such as obviously, the write method of prior art communication protocol analysis source code exists flexibility low, and inefficiency and product development cycle are long.
Summary of the invention
For solving the problems such as the flexibility of prior art communication protocol analysis source code write method existence is low, and inefficiency and product development cycle are long, the present invention proposes a kind of method for generating analysis source code of signaling message.The method adopts field rule to define the each field information needed of signaling message and field value implication; Employing Code Template is mated each field rule and is generated the analysis source code of respective field; Source code generation module generates analysis source code of signaling message according to field rule and corresponding Code Template.Adopt method for generating analysis source code of signaling message of the present invention can generate fast signaling message and resolve required source code, in the time that needs are resolved new agreement, the field rule that only need to write this agreement, can generate the source code of resolving this agreement fast, and development efficiency is provided greatly.
Method for generating analysis source code of signaling message of the present invention adopts field rule to define the each field information needed of signaling message and field value implication, comprising: adopt field initial rules to define the each field information needed of signaling message to be resolved and parsing order; Adopt the each field value implication of field value implication rule definition signaling message, the field attribute of field value implication rule dependency in field initial rules, explains according to the field in field attribute whether this field of instruction judgement needs defined word segment value; Wherein: described field information needed comprises: protocol fields name, field another name and field attribute; Described field parsing order refers to according to the signaling message field sending order defining in protocol specification lists the each field of signaling message including reserved field successively; Described field value implication is followed the definition of consensus standard specification, and lists order according to field value order from small to large.
Field attribute in the field information needed of method for generating analysis source code of signaling message field initial rules definition of the present invention, comprise: the instruction of value type, the instruction of length value type, length value and field are explained instruction, wherein: the instruction of value type represents that the data that this field is carried are numeral or character; The instruction of length value type represents that the span of this field is bit or byte; Length value represents the shared number of bits of this field or byte number; Field explains that instruction represents whether this field has field value to explain.
Method for generating analysis source code of signaling message employing Code Template of the present invention is mated each field rule and is generated the analysis source code of respective field, comprising: define an initialization source code block and one group of rule source code block; Described initialization source code block is used for obtaining initialized decoded information from decoding interface, as: protocol Data Unit PDU data head pointer and the required contextual information of decoding; The parsing source generation that described regular source code block is used for mating each field rule and generates respective field; A field rule of a regular source code block coupling, each regular source code block comprises: bit field analysis source code piece, one-byte field analysis source code piece, double byte field analysis source code piece and random length field analysis source code piece, wherein: bit field analysis source code piece is for obtaining the field value that span is bit field; One-byte field analysis source code piece is for obtaining the field value that span is one-byte field; Double byte field analysis source code piece is for obtaining the field value that span is double byte field; The value of the field that random length field analysis source code piece is character string for the value of acquisition type.
Method for generating analysis source code of signaling message source code generation module of the present invention generates analysis source code of signaling message according to field rule and corresponding Code Template, comprise: the attribute information that obtains line by line successively the each field of signaling message to be resolved, from code module, select the regular code module matching with this field attribute and generate this field analysis source code according to the attribute information of each field again, the set of each field analysis source code is this analysis source code of signaling message.
Method for generating analysis source code of signaling message source code generation module of the present invention generates analysis source code of signaling message according to field rule and corresponding Code Template, comprises the following steps:
1, read initialization source code block;
2, read line by line the each field information needed of signaling message of field initial rules;
3, judging whether to need to inquire about and read field value implication rule, is to perform step 9, otherwise, continue execution step 4;
4, judgment value type indicates whether for numeral, is to perform step 5, otherwise execution step 6;
5, be digital field for value type, obtain corresponding regular source code block according to the instruction of length value type and length value, generate this field analysis source code, execution step 7;
6, the field that is character for value type, obtains corresponding regular source code block according to length value, generates this field analysis source code;
7, this field analysis source code generating is write to analysis source code of signaling message file;
8, the field analysis source code that judges whether to generate all fields, is to finish, otherwise continues execution step 2;
9, the field value implication rule of inquiring about and read this field according to field another name, turns back to step 4.
Brief description of the drawings
Fig. 1 is the frame structure schematic diagram of method for generating analysis source code of signaling message embodiment of the present invention;
Fig. 2 is the field Sample Rules figure of the base transceiver station management BTSM agreement out-hole run Uplink Measurements information element part of method for generating analysis source code of signaling message embodiment of the present invention;
Fig. 3 is the Code Template composition schematic diagram of method for generating analysis source code of signaling message embodiment of the present invention;
Fig. 4 is the flow chart that the analysis source code of signaling message of method for generating analysis source code of signaling message embodiment of the present invention generates.
Below in conjunction with the drawings and the specific embodiments, method for generating analysis source code of signaling message of the present invention is further described.
Embodiment
Fig. 1 is the frame structure schematic diagram of method for generating analysis source code of signaling message embodiment of the present invention.As seen from the figure, method for generating analysis source code of signaling message of the present invention, comprising: adopt 101 pairs of each field information needed of signaling message of field rule and field value implication to define; Employing Code Template 102 is mated each fields rule and is generated the analysis source code of respective field; Source code generation module 103 generates analysis source code of signaling message according to field rule and corresponding Code Template.Wherein, field rule 101 is for defining field name to be decoded, field another name, field attribute, field parsing order and the corresponding implication of field value; Code Template 102 is for matching field rule 101 and generate the analysis source code of respective field; Source code generation module 103 is for generating the source code of resolving field according to field rule 101 and Code Template 102.
Fig. 2 is the field Sample Rules figure of the base transceiver station management BTSM agreement out-hole run Uplink Measurements information element part of method for generating analysis source code of signaling message embodiment of the present invention.As seen from the figure, the field rule 101 in Fig. 1 comprises again field initial rules 201 and field value implication rule 202, and wherein, field initial rules 201 defines the each field information needed of signaling message to be resolved and parsing order; The each field value implication of field value implication rule 202 definition signaling message, field value implication rule 202 explains according to the field in field attribute whether this field of instruction judgement needs defined word segment value.The field information needed that field initial rules 201 defines comprises: protocol fields name, field another name and field attribute; The field parsing order that field initial rules 201 defines refers to the order of the each field of signaling message including reserved field of listing successively according to the signaling message field sending order defining in protocol specification; The field value implication of field value implication rule 202 definition is followed the definition of consensus standard specification, and lists order according to field value order from small to large.
In embodiment shown in accompanying drawing 2, in field initial rules 201, the implication of each several part is respectively:
Element identifier, represents field name;
EI, represents field another name; | 01, represent that field accounts for 1 byte, wherein " | " is the instruction of length value type, indication field span is byte, can represent byte span with the symbol that is different from " | ", as ": ".The first bit digital immediately following the instruction of length value type is the instruction of value type, and " 0 " expression value type is numeral, and " 1 " expression value type is character; Second-order digit is length value, as unfixing in length, represents with " u ";-d, represents this field explanation mark, lists in field value implication information 202, does not have field to explain, this mark can be empty.
Fig. 3 is the Code Template composition schematic diagram of method for generating analysis source code of signaling message embodiment of the present invention.As seen from the figure, the Code Template 102 in accompanying drawing 1 is for matching field rule 101, and Code Template 102 comprises an initialization source code block 301 and one group of rule source code block 302.Wherein, initialization source code block 301 is for obtain initialized decoded information from decoding interface, as: protocol Data Unit PDU data head pointer, the required contextual information etc. of decoding; Rule source code block 302 is for mating each field rule and generating corresponding field analysis source code, and a regular source code block 302 is mated a field rule 101.For each matched rule of corresponding field rule 101 definition, regular source code block 302 is divided into again: bit field analysis source code piece, one-byte field analysis source code piece, double byte field analysis source code piece and random length field analysis source code piece.Wherein, bit field analysis source code piece is for obtaining the field value that length mark is bit, one-byte field analysis source code piece is for obtaining the field value that length mark is byte, double byte field analysis source code piece is for obtaining the field value that length mark is double byte, and random length field analysis source code piece is used for the value of the field that the value of acquisition type is character string.
Fig. 4 is the flow chart that the analysis source code of signaling message of method for generating analysis source code of signaling message embodiment of the present invention generates.As seen from the figure, source code generation module 103 generates analysis source code of signaling message according to field rule 101 and corresponding Code Template 102, comprise: the attribute information that obtains line by line successively the each field of signaling message to be resolved, from code module, select the regular code module matching with this field attribute and automatically generate this field analysis source code according to the attribute information of each field again, the set of each field analysis source code is this analysis source code of signaling message.Method for generating analysis source code of signaling message of the present invention, in the time carrying out analysis source code of signaling message generation, comprises the following steps:
Step S401: read initialization source code block, obtain initialized decoded information from decoding interface, as protocol Data Unit PDU data head pointer, the required contextual information etc. of decoding;
Step S402: the each field information needed of signaling message and the field parsing order that read line by line field initial rules, its each field information needed comprises: protocol fields name, field another name and field attribute, wherein, field attribute comprises again: the instruction of value type, the instruction of length value type, length value and field are explained instruction; Described value type instruction represents that the data that this field is carried are numeral or character, described length value type instruction represents that the span of this field is bit or byte, described length value represents the shared number of bits of this field or byte number, and described field explains that instruction represents whether this field has field value to explain;
Step S403: explaining that according to field instruction judges whether to need to inquire about and read field value implication rule, is to perform step S409, otherwise, execution step S404 continued;
Step S404: judgment value type indicates whether for numeral, is to perform step S405, otherwise execution step S406;
Step S405: be digital field for value type, the instruction of length value type and the length value that extract according to step S402, obtain corresponding rule match source code block, generates this field analysis source code, execution step S407;
Step S406: the field that is character for value type, obtain corresponding rule match source code block, the length value extracting according to step S402, generates this field analysis source code;
Step S407: this field analysis source code generating is write to analysis source code of signaling message file;
Step S408: judging whether to generate the field analysis source code of all fields, is to finish, otherwise continue execution step S402;
Step S409: the field value implication rule of this field is inquired about and read to the field another name obtaining according to step S402, obtains the corresponding all fields of field value of this field and explain and generate the branch statement such as switch, then turns back to step S404.
As seen from the above description, method for generating analysis source code of signaling message of the present invention, in communication protocol resolving, generates this field analysis source code according to field rule and the corresponding Code Template of this field.And field rule and Code Template are relatively independent, in the time that needs increase or revise protocol specification, only need to write or revise the corresponding field rule of this protocol specification, can reach the object of increase or amendment analysis protocol.Obviously, method for generating analysis source code of signaling message of the present invention can generate the source code that communication protocol is resolved fast, can generate fast the source code of resolving this agreement, and development efficiency is provided greatly.