Generation method of analysis message class, verification method of network chip and electronic equipment

By analyzing message protocol files, the problem of network chip message class generation relies on manual writing and manual modification in the existing technology is solved, and the rapid generation of packets is realized, which improves the efficiency and accuracy of network chip verification. sex.

CN119254854APending Publication Date: 2025-01-03DAPUSTOR CORP
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411093136.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-09
Publication Date
2025-01-03

AI Technical Summary

Technical Problem

In the prior art, the message generation process of network chips relies on manual writing and manual modification, resulting in high time cost, low efficiency, and easy to cause human errors.

Method used

By acquiring message protocol files and scripts, they can be analyzed, and automatically generated parsed message classes, reducing manual intervention, and quickly generating message classes to speed up the verification progress of network chips.

Benefits of technology

It improves the efficiency of network chip verification, reduces the occurrence of human errors, and reduces time and workload costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119254854A_ABST
    Figure CN119254854A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to the technical field of communication, and discloses an analysis message class generation method, a network chip verification method and electronic equipment, and the analysis message class generation method comprises the steps: analyzing message information corresponding to a plurality of message protocols in a message protocol file through a script, and according to the message information corresponding to the message protocols, verifying a network chip according to the message information corresponding to the message protocols; according to the network chip verification method and the network chip verification device, the analysis message classes can be quickly generated, so that the network chip verification efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication technology, and in particular to a method for generating a parsed message class, a method for verifying a network chip, and an electronic device. Background Art

[0002] Network chip verification can ensure its functionality, performance, compatibility, security and reliability to ensure that it can work stably and reliably in actual applications.

[0003] In the prior art, during the generation of message classes, developers are required to learn network message protocols and master the code details of message classes to further manually write message construction classes. When a new network message format is introduced, the code needs to be manually modified. The above scheme is highly dependent on manual maintenance and is prone to human errors. Frequent manual modifications will significantly increase workload and time costs, thereby reducing the efficiency of network chip verification. Summary of the invention

[0004] The embodiments of the present application provide a method for generating a parsed message class, a method for verifying a network chip, and an electronic device, which solve the problem of increasing the time cost of manually writing a message construction class corresponding to network chip verification, and can quickly generate a message class to speed up the verification progress of the network chip.

[0005] To solve the above technical problems, the present application provides the following technical solutions:

[0006] In a first aspect, an embodiment of the present application provides a method for generating a parsed message class, the method comprising:

[0007] Obtain a message protocol file, wherein the message protocol file includes message information corresponding to multiple message protocols;

[0008] Obtain a script and execute the script to parse the message protocol file to obtain message information corresponding to multiple message protocols;

[0009] According to the parsed message information, a parsed message class corresponding to each message protocol is generated.

[0010] In some embodiments, the message information corresponding to the message protocol includes: a plurality of fields, and before generating a parsed message class corresponding to each message protocol, the method further includes:

[0011] Determine whether there are the same domain segments in the message information corresponding to different message protocols;

[0012] If the same domain segment does not exist, continue to execute the step of generating the parsed message class;

[0013] If the same domain segment exists, the name of the corresponding message protocol is added before the same domain segment.

[0014] In some embodiments, according to the parsed message information, a parsed message class corresponding to each message protocol is generated, including:

[0015] Generate the domain information corresponding to each message protocol according to the message information;

[0016] According to the field information corresponding to each message protocol, a parsing function for parsing the message class corresponding to each message protocol is generated, wherein the parsing function corresponds to a message header one by one.

[0017] In some embodiments, the method further comprises:

[0018] Add the message information corresponding to the new message protocol in the message protocol file;

[0019] Execute the script to parse the message protocol file to obtain new message protocol information;

[0020] According to the new message protocol information, a new parsing message class corresponding to the message protocol is generated.

[0021] In a second aspect, an embodiment of the present application provides a method for verifying a network chip, the method comprising:

[0022] Get network messages;

[0023] The parsing function corresponding to the parsing message class is called to parse the network message to obtain message data corresponding to the network message, wherein the parsing message class is generated by the generation method of the parsing message class of the first aspect.

[0024] In some embodiments, the message information corresponding to the message protocol includes: a plurality of domain segments;

[0025] Call the parsing function corresponding to the parsing message class to parse the network message to obtain the message data corresponding to the network message, including:

[0026] Determine the location of each domain segment in the network message;

[0027] Determine the length of each domain segment;

[0028] The data of each field segment is obtained according to the length of the field segment and the position of the field segment, wherein the message data includes the data of each field segment.

[0029] In some embodiments, the field segment includes the total length of the message and the message header. When the field segment includes a variable length field segment, determining the length of each field segment includes:

[0030] Determine the length of the variable length field, including:

[0031] The length of the variable length field segment is determined according to the total length of the message and the length of the message header, wherein the length of the variable length field segment = the length of the message header - the length of the message header.

[0032] In some embodiments, the message data includes next protocol determination data, and the method further includes:

[0033] Determine whether the next protocol determination data includes a preset value, wherein the preset value includes the network message to be parsed;

[0034] If the next protocol judgment data includes a preset value, the parsing function is called to parse the network message to be parsed according to the preset value;

[0035] If the next protocol determines that the data does not include the preset value, the parsing process of the network message is terminated.

[0036] In a third aspect, an embodiment of the present application provides an electronic device, comprising

[0037] at least one processor; and,

[0038] a memory communicatively connected to at least one processor; wherein,

[0039] The memory stores instructions that can be executed by at least one processor, and the instructions are executed by at least one processor so that the at least one processor can execute the method for generating the parsed message class as in the first aspect or the method for verifying the network chip as in the second aspect.

[0040] In a fourth aspect, an embodiment of the present application provides a non-volatile computer-readable storage medium, which stores a computer program. The computer program includes program instructions, which, when executed by a processor, enable the processor to execute a method for generating a parsed message class such as the first aspect or a method for verifying a network chip such as the second aspect.

[0041] The beneficial effect of the embodiment of the present application is: different from the prior art, the embodiment of the present application provides a method for generating a parsed message class, a method for verifying a network chip, and an electronic device, and the method for generating a parsed message class includes: obtaining a message protocol file, wherein the message protocol file includes message information corresponding to multiple message protocols, obtaining a script, and executing the script to parse the message protocol file to obtain message information corresponding to multiple message protocols, and generating a parsed message class corresponding to each message protocol according to the parsed message information. The present application can quickly generate a parsed message class to improve the efficiency of network chip verification. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.

[0043] Figure 1 It is a flowchart of a method for generating a parsed message class provided in an embodiment of the present application;

[0044] Figure 2 This is a flowchart of determining whether the same domain segment exists, provided in an embodiment of the present application;

[0045] Figure 3 yes Figure 1 A detailed flow chart of step S103;

[0046] Figure 4 It is a schematic diagram of a process for generating a new message class provided in an embodiment of the present application;

[0047] Figure 5 It is a flowchart of a network chip verification method provided by an embodiment of the present application;

[0048] Figure 6 yes Figure 5 A detailed flow chart of step S502;

[0049] Figure 7 yes Figure 6 A detailed flow chart of step S522;

[0050] Figure 8 It is a schematic diagram of a process of parsing a next network message provided by an embodiment of the present application;

[0051] Fig. 9 It is a schematic diagram of parsing a network message provided by an embodiment of the present application;

[0052] Fig.10 It is a structural diagram of a device for generating parsed message classes provided in an embodiment of the present application;

[0053] Fig.11 It is a structural diagram of a verification device for a network chip provided in an embodiment of the present application;

[0054] Fig.12 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application.

[0055] Description of Figure Numbers:

[0056] Label name Label name 100 Parsing message generation device 111 Message acquisition unit 10 First acquisition unit 112 Parsing Unit 20 Second acquisition unit 120 Electronic devices 30 Generate Unit 121 processor 110 Network chip verification device 122 Memory DETAILED DESCRIPTION

[0057] In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.

[0058] It should be noted that, if there is no conflict, the various features in the embodiments of the present application can be combined with each other, all within the scope of protection of the present application. In addition, although the functional module division is performed in the device schematic diagram and the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in a sequence different from the module division in the device or the flow chart. Furthermore, the words "first", "second", "third", etc. used in this application do not limit the data and execution order, but only distinguish the same items or similar items with basically the same functions and effects.

[0059] In addition, the technical features involved in each embodiment of the present application described below can be combined with each other as long as they do not conflict with each other.

[0060] Before introducing the embodiments of the present application, a method for generating a parsed message class known to the inventor of the present application is briefly introduced to facilitate subsequent understanding of the embodiments of the present application.

[0061] The existing message class generation method usually requires first learning the standard network message construction rules, then manually writing code according to the rules to generate the message class, and parsing the message according to the generated message class.

[0062] The above method requires manual learning of message construction rules and manual code writing. When a new network message is introduced, the original message class code needs to be manually modified. The above solution is highly dependent on manual maintenance. Frequent manual modifications will significantly increase the workload and time cost, and reduce the efficiency of network chip verification.

[0063] In response to the above problems, the present application parses the message information corresponding to multiple message protocols in the message protocol file through a script, and generates a one-to-one corresponding parsed message class for each message protocol according to the message information corresponding to the message protocol. The present application can quickly generate a parsed message class to improve the efficiency of network chip verification.

[0064] The technical solution of this application is described in detail below with reference to the accompanying drawings:

[0065] See also Figure 1 , Figure 1 It is a flowchart of a method for generating a parsed message class provided in an embodiment of the present application;

[0066] The method for generating the parsed message class is applied to an electronic device. Specifically, the execution subject of the method for generating the parsed message class is one or at least two processors of the electronic device.

[0067] like Figure 1 As shown, the method for generating the parsing message class includes:

[0068] Step S101: Acquire a message protocol file, wherein the message protocol file includes message information corresponding to a plurality of message protocols;

[0069] Among them, the message protocol refers to a series of rules and conventions formulated in computer networks to achieve data exchange. The rules define the format and transmission method of data packets. The message protocols include Multiple Access Control Protocol (MAC), Hypertext Transfer Protocol (HTTP), File Transfer Protocol (FTP), Transmission Control Protocol (TCP), User Datagram Protocol (Open Systems Interconnection, UDP), Simple Mail Transfer Protocol (SMTP), Domain Name System Protocol (DNS), Internet Protocol version 4 (IPv4), etc.

[0070] Specifically, the message information corresponding to multiple message protocols is collected, and the message information corresponding to the multiple message protocols is organized into a message protocol file, wherein the format of the message protocol file can be Excel format or TXT format, and the message information includes each domain name related to the message protocol, domain width, message header length, message payload length, next message header judgment condition, etc.

[0071] Among them, the structure of the data packet format of each message protocol is basically composed of two parts: a message header and data. The message header and data parts in the data packet formats of different message protocols may be different, that is, the message information corresponding to different message protocols may be different. The following is the message information corresponding to the message protocol.

[0072] Please refer to Table 1, which shows the message content of the MAC protocol;

[0073]

[0074] Table 1

[0075] As shown in Table 1, the message content of the MAC protocol includes multiple field names, which include the start frame delimiter (field_statement_start), destination MAC address (dmac), source MAC address (smac), MAC type length (mac_type), MAC message total length (mac_data), frame check sequence (fcs), end frame delimiter (field_statement_end), header length (header_len), data length data_len, next message header (nxt_header_fld), next message header length (nxt_header_fld), and next message header length (nxt_header_fld). Type (nxt_header_type), remark information of the next message header (nxt_header_lyr), where the MAC protocol is composed of dmac, smac, and mac_type, dmac=6B defines the bit width of dmac as 6B (i.e. 6 bytes), smac=6B defines the bit width of smac as 6B (i.e. 6 bytes), mac_type=2B defines the bit width of mac_type as 2B (i.e. 2 bytes), then the header length of the MAC protocol is header_len=6B+6B+2B=14B, and the bit widths of the remaining fields are shown in the table and will not be described one by one.

[0076] Please refer to Table 2, which shows the message content of the IPv4 protocol;

[0077]

[0078] Table 2

[0079] As shown in Table 2, the message content of the IPv4 protocol includes multiple field names, and the field names include the start frame delimiter (field_statement_start), version (version), header length (ihl), service type (tos), total length (total_len), identification (identification), flags (flags), fragment offset (fragment_ofst), life time (time_to_live), protocol (protocol), header checksum (header_checksum), source address (src_addr), destination address (dst_addr), option (option_padding), data (ipv4_data), end frame delimiter (field_statement_end), header length (header_len), data length (data_len), next message header (nxt_header_fld), next message header type (nxt_header_type), and next message header remark information (nxt_header_lyr). Among them, version=4bit indicates the bit width of the version, and the bit widths of the remaining fields are shown in the table and will not be explained one by one.

[0080] Please refer to Table 3, which shows the message content of the UDP protocol;

[0081]

[0082] Table 3

[0083] As shown in Table 3, the message content of the UDP protocol includes multiple field names, and the field names include the start frame delimiter (field_statement_start), the source port number (src_port), the destination port number (dst_port), the total message length (udp_len), the checksum (udp_chksum), the data length (udp_data), the end frame delimiter (field_statement_end), the header length (header_len), the data length (data_len), the next message header (nxt_header_fld), the type of the next message header (nxt_header_type), and the remark information of the next message header (nxt_header_lyr), among which src_port=2B indicates the bit width of the version, and the bit widths of the remaining fields are shown in the table and will not be described one by one.

[0084] Step S102: obtaining a script, and executing the script to parse the message protocol file to obtain message information corresponding to multiple message protocols;

[0085] Specifically, after the message information corresponding to various message protocols is sorted into a message protocol file, a script is obtained, and the script is executed to parse the message protocol file, and the message information corresponding to multiple message protocols in the message protocol file is extracted by the script to obtain the message information corresponding to multiple message protocols, wherein the language used by the script can be Python, Perl, or Bash. Preferably, the message protocol file is parsed by a Python script.

[0086] Specifically, executing the script to parse the message protocol file specifically includes: obtaining the message protocol specification, wherein the message protocol specification includes the message protocol format, and reading the message information corresponding to multiple message protocols in the message protocol file according to the message protocol format defined in the message protocol specification. Among them, the message format includes the domain name of the message protocol, the data type corresponding to each domain, and the meaning of the domain.

[0087] Step S103: Generate a parsed message class corresponding to each message protocol according to the parsed message information;

[0088] Specifically, the message information obtained by parsing is the message information corresponding to multiple message protocols extracted from the message protocol file through the script, and a parsing message class corresponding to each message protocol is generated according to the extracted message information, wherein the parsing message class is used to parse network messages, which are the basic units of exchange and transmission, including complete data information to be sent.

[0089] Specifically, a parsed message class corresponding to each message protocol is generated based on the extracted message information, specifically including: defining the field name, field data type and field length corresponding to each message protocol based on the field segment information in each message protocol, and defining the parsed message class corresponding to each message protocol based on the field name, field data type and field length corresponding to each message protocol.

[0090] Please refer to Figure 2 , Figure 2 This is a flowchart of determining whether the same domain segment exists, provided in an embodiment of the present application;

[0091] like Figure 2 As shown, the determination of whether the same domain segment exists includes:

[0092] Step S201: Determine whether there are the same fields in the message information corresponding to different message protocols;

[0093] In the embodiment of the present application, before generating a parsed message class corresponding to each message protocol, it is necessary to first check whether there are identical domain segments in the extracted message information, and if there are identical domain segments, the identical domain segments need to be changed. For example, there is a data domain segment in the message information corresponding to the MAC protocol, and there is also a data domain segment in the message information corresponding to the IPv4 protocol, indicating that the same domain segments exist in the extracted information.

[0094] Specifically, determine whether there are identical domain segments in the message information corresponding to different message protocols. If there are no identical domain segments, jump to step S202; if there are identical domain segments, jump to step S203.

[0095] Step S202: Continue to execute the step of generating parsed message class;

[0096] Specifically, when the same domain segments do not exist in the extracted message information corresponding to different message protocols, a parsed message class is generated according to the extracted message information to continue the step of generating the parsed message class.

[0097] Step S203: Add the name of the corresponding message protocol before the same domain segment;

[0098] Specifically, when the same domain segment exists in the message information corresponding to different message protocols extracted, the name of the corresponding message protocol is added before the same domain segment. For example, if there is a data domain segment in the message information corresponding to the MAC protocol and there is also a data domain segment in the message information corresponding to the IPv4 protocol, MAC is added before the data domain segment in the MAC protocol to obtain MAC_data, and IPv4 is added before the data domain segment in the IPv4 protocol to obtain IPv4_data, so as to distinguish the same domain segments.

[0099] In an embodiment of the present application, when the same domain segment still exists in the extracted message information and cannot be changed, the current judgment process is exited and an exception is prompted. According to the prompted exception, the message protocol file is modified to modify the same domain segment in the message protocol file. The name of the corresponding message protocol is directly added in front of the same domain segment in the message protocol file. After the modification, the script is executed again to parse the message protocol file.

[0100] Please refer to Figure 3 , Figure 3 yes Figure 1 A detailed flow chart of step S103;

[0101] like Figure 3 As shown, step S103 includes:

[0102] Step S131: Generate field information corresponding to each message protocol according to the message information;

[0103] Specifically, according to the message information corresponding to each message protocol, the field information corresponding to each message protocol is generated, and the field information includes a field name and a length definition corresponding to the field name.

[0104] For example, referring to Table 1 again, the message information corresponding to the MAC message protocol includes the destination MAC address (dmac), the source MAC address (smac), the MAC type length (mac_type), the MAC data (mac_data) and other message information. Through the script, the destination MAC address (dmac) and the source MAC address (smac) are set to 6 bytes, the MAC type length (mac_type) is set to 2 bytes, and the MAC data (mac_data) is set to a variable length field.

[0105] In the embodiment of the present application, after generating the domain information corresponding to each message protocol, it is also necessary to determine whether there is the same field name in the domain information corresponding to different protocols. If there is the same field name, the name of the corresponding message protocol is added before the same field name. If there is no same field name, continue to generate the parsed message class. If there is still the same field name that cannot be changed, an exception is prompted and the current parsed message class generation process is exited.

[0106] In an embodiment of the present application, the message information corresponding to each message protocol is automatically extracted through a script, and the field information corresponding to each message protocol is generated. In the process of automatically generating the field information, the consistency of the field information and the message information corresponding to the message protocol can be ensured.

[0107] Step S132: Generate a parsing function for parsing a message class corresponding to each message protocol according to the field information corresponding to each message protocol, wherein each parsing function corresponds to a message header one by one;

[0108] Specifically, according to the field information corresponding to each message protocol, a parsing function of the parsing message class corresponding to each message protocol is generated, wherein the parsing function includes the parsing logic of the network message corresponding to the message protocol, and each parsing function corresponds to a message header one by one. The parsing function corresponding to the message protocol can be called through the message header corresponding to the message protocol, wherein the parsing function is used to parse the network message.

[0109] The message information in the message protocol file is automatically parsed through the script, and the parsed message class is generated according to the message information. This process is the process of automatically generating code. You only need to fill in the message information of the message protocol in the document, and the script automatically extracts and generates the code corresponding to the parsed message class. There is no need for manual writing, which reduces human errors.

[0110] In an embodiment of the present application, while generating a parsing message class, a printing function is automatically generated through a script, and the printing function is used to print the message data obtained by parsing the network message by the parsing message class to display the message data on the interface.

[0111] Please refer to Figure 4 , Figure 4 It is a schematic diagram of a process for generating a new message class provided in an embodiment of the present application;

[0112] like Figure 4 As shown, a new message class is generated, including:

[0113] Step S401: Adding message information corresponding to a new message protocol to the message protocol file;

[0114] Specifically, when a new message protocol appears, the message information corresponding to the new message protocol is added to the message protocol file.

[0115] Step S402: executing a script to parse the message protocol file to obtain message information corresponding to the new message protocol;

[0116] Specifically, the script is executed to parse the message protocol file to which the message information corresponding to the new message protocol is added, and the message information corresponding to the new message protocol in the message protocol file is extracted to obtain the message information corresponding to the new message protocol.

[0117] In an embodiment of the present application, each time after extracting message information from the message protocol file, it is necessary to execute a judgment step to see whether there are identical domain segments to check whether there are identical domain segments. If there are identical domain segments, the name of the corresponding message protocol is added before the identical domain segments.

[0118] Step S403: Generate a parsed message class that corresponds one-to-one to a new message protocol according to the message information corresponding to the new message protocol;

[0119] Specifically, based on the message information corresponding to the new message protocol, the field information corresponding to the new message protocol is generated, the field information includes the field name and the length definition corresponding to the field name, and based on the field information corresponding to the new message protocol, a parsing function of the parsing message class corresponding to the new message protocol is generated one-to-one, wherein the parsing function includes the parsing logic of the network message corresponding to the message protocol, each parsing function corresponds one-to-one to a message header, and the parsing function corresponding to the new message protocol can be called through the message header corresponding to the message protocol.

[0120] In an embodiment of the present application, after new message information is added to the message protocol file, the message protocol file of the newly added message information is parsed through a script, and then a parsed message class corresponding to the new message protocol is generated based on the newly extracted message information. There is no need to modify the parsed message class corresponding to the original message protocol, thereby avoiding the problem of multiple modifications to the code corresponding to the parsed message class, and no manual writing is required, reducing time costs.

[0121] In an embodiment of the present application, the message information of all message protocols is organized into a message protocol file, the message protocol file is automatically parsed by a script, and a parsed message class corresponding to the message protocol is automatically generated, thereby reducing the time for manual code writing and debugging. In addition, the message protocol file can be automatically processed by the script to adapt to the newly added message protocol without a large number of modifications to the existing code, thereby enhancing the readability and maintainability of the code and reducing the risk of errors.

[0122] Please refer to Figure 5 , Figure 5 It is a flowchart of a network chip verification method provided by an embodiment of the present application;

[0123] The verification method of the network chip is applied to an electronic device. Specifically, the execution subject of the verification method of the network chip is one or at least two processors of the electronic device.

[0124] In the embodiment of the present application, a network chip (networking processor) is a microprocessor that provides logic for sending and receiving data (including sound and video) in a communication network. It is specifically used in network devices (such as routers, switches, load balancers, etc.) and is responsible for processing, forwarding, and managing data packets.

[0125] Among them, the types of network chips mainly include network card chips and network switching chips.

[0126] Specifically, a network card chip is a network function component integrated on the motherboard, which is responsible for the transmission of data between the network and the computer, so that the computer can connect to the network for data communication. The network card chip usually supports different network protocols (such as Ethernet, Wi-Fi, etc.).

[0127] Specifically, network switching chips are mainly used in switches and are responsible for high-performance and low-latency data exchange, such as processing and managing the forwarding and switching of data packets.

[0128] like Figure 5 As shown, the verification method of the network chip includes:

[0129] Step S501: Obtain network messages;

[0130] In an embodiment of the present application, before obtaining network messages, a design specification document of the network chip is analyzed in advance, the design specification document includes information such as a functional description of the network chip and supported message formats, and then each test point (i.e., functional point) that needs to be tested is extracted according to the design specification document, the extracted test points are planned, the coverage of the test cases is determined, and a verification environment is built. The obtained network messages are subjected to regression testing in the verification environment, and coverage analysis is performed.

[0131] Specifically, the methods for obtaining network messages include:

[0132] (1) Generate network messages through message generation tools to obtain network messages, where the message generation tools include: ESB message automatic generation tool and HEX message protocol packaging generation tool. The ESB message automatic generation tool automatically generates messages according to the field definition in the document, and the HEX message protocol packaging generation tool allows users to customize the message format and rules to generate HEX format messages.

[0133] (2) Use network packet capture tools to obtain network packets. Network packet capture tools include Wireshark, tcpdump, and tshark.

[0134] (3) Obtain network messages through the API interface. Many websites and applications provide API interfaces. Network messages can be obtained by sending HTTP requests to the specified URL.

[0135] It should be noted that there are other ways to obtain network messages, which are not limited here.

[0136] Step S502: calling the parsing function corresponding to the parsing message class to parse the network message to obtain the message data corresponding to the network message;

[0137] The parsing message class is a parsing message class generated by the generation method of the parsing message class provided in this application. For the specific process of generating the parsing message class, please refer to Figure 1 The various steps in will not be repeated here.

[0138] Specifically, the message parsing class is called to parse the network message to identify the identification information of the network message, the identification information includes the protocol type, version, message length, etc., and the message protocol corresponding to the network message is determined according to the identification information of the network message.

[0139] Further, according to the message header corresponding to the message protocol corresponding to the network message, the parsing function in the parsing message class corresponding to the message header is called to parse the network message to obtain the message data corresponding to the network message, wherein the message data includes the values ​​of all fields in the message information corresponding to the message protocol corresponding to the network message. For the specific parsing process, please refer to Figure 6 .

[0140] Please refer to Figure 6 , Figure 6 yes Figure 5 A detailed flow chart of step S502;

[0141] like Figure 6 As shown, step S502 includes:

[0142] Step S521: Determine the position of each domain segment in the network message;

[0143] Specifically, the domain segments are read sequentially according to the message protocol specification to determine the position of the domain segments in the network message, wherein the message protocol specification has a clear definition of the position of the domain segments.

[0144] Step S522: Determine the length of each domain segment;

[0145] Specifically, the length of each field segment is determined according to the definition of the field segment length in the message protocol specification.

[0146] Please refer to Figure 7 , Figure 7 yes Figure 6 A detailed flow chart of step S522;

[0147] like Figure 7 As shown, step S522 includes:

[0148] Step S5221: Determine the length of the variable length field segment according to the total length of the message and the length of the message header, wherein the length of the variable length field segment = the total length of the message - the length of the message header;

[0149] Specifically, the field segment includes a variable length field segment. For example, the data field segment in the field segment is a variable length field segment. The total length of the network message and the length of the message header are obtained. The length of the message header can be found in the definition in the message protocol specification. The total length of the network message is subtracted from the length of the message header to obtain the length of the variable length field segment, that is, the length of the variable length field segment = the total length of the message - the length of the message header.

[0150] Among them, the message information corresponding to some message protocols also includes a frame check sequence, so the length of the variable length field = total length - length of the message header - length of the frame check sequence.

[0151] Step S523: acquiring data of each field segment according to the length of the field segment and the position of the field segment, wherein the message data includes the data of each field segment;

[0152] Specifically, the length and position of the domain segment are known, and according to the total length of the network message, the data in the network message is read sequentially and assigned to each domain segment defined in the parsing function.

[0153] For example: the currently parsed network message is a MAC message. Referring to the definition of the message information corresponding to the MAC protocol in Table 1, field_statement_start is used to indicate the starting position of the field segment reading, and field_statement_end is used to indicate the end position of the field segment reading. Each field segment is read sequentially from field_statement_start to field_statement_end. The bit width of dmac is 6B, the bit width of smac is 6B, mac_type is 2B, dmac, smac, and mac_type are the header fields of the MAC message, and the total length of the MAC message mac_data is 46 to 15. 00B, the frame check sequence fcs is 4B, fcs is usually placed at the tail, then the data length of the MAC message is frame_size-message header length-fcs length=frame_size-14B-4B=frame_size-18B, frame_size represents the actual total length of the MAC message, frame_size is set at 46~1500B, the field sequence of the MAC message is known, that is, the position of the field segments of the MAC message is known, and the length of each field segment is known. Since the network message will follow a specific protocol format during transmission, the data of the field segments are read from the MAC message in sequence and filled into the corresponding field segments to parse and obtain the data of each field segment of the MAC message.

[0154] Please refer to Figure 8 , Figure 8 It is a schematic diagram of a process of parsing a next network message provided by an embodiment of the present application;

[0155] like Figure 8 As shown, the next network message is parsed, including:

[0156] Step S801: Determine whether the next protocol determination data includes a preset value;

[0157] In an embodiment of the present application, the protocol type field in the message header of the message protocol is used to determine the next network message that needs to be parsed. For example, the value corresponding to the mac_type field in the MAC message is used to indicate the next network message that needs to be parsed.

[0158] Specifically, the data of the protocol type field corresponding to the currently parsed network message is obtained, and the data of the protocol type field is the next protocol judgment data. It is judged whether the next protocol judgment data includes a preset value. If it includes the preset value, it jumps to step S802, and if it does not include the preset value, it jumps to step S803. The preset value is used to identify the message protocol type, for example: the preset value is 0x0800, indicating that the next network message to be parsed is an IPv4 message, the preset value is 0x0806, indicating that the next network message to be parsed is an ARP message, and the preset value is 0x86dd, indicating that the next network message to be parsed is an IPv6 message.

[0159] Step S802: according to the preset value, calling the parsing function to parse the network message to be parsed;

[0160] Specifically, when the next protocol judgment data includes a preset value, the message header of the message protocol corresponding to the next network message to be parsed corresponding to the preset value is determined according to the preset value, and the parsing function is called to parse the network message to be parsed according to the message header corresponding to the determined message protocol.

[0161] Step S803: End the network message parsing process;

[0162] Specifically, when the next protocol determines that the data does not include the preset value, the current network message parsing process ends.

[0163] For example, when the preset value is 0x0800, it means that the next network message to be parsed is an IPv4 message, then the parsing function corresponding to the IPv4 protocol is called to parse the IPv4 message, and the protocol field in the IPv4 protocol is used to store the next protocol judgment data. When the value of the protocol field in the IPv4 protocol is 7, it means that the next network message to be parsed is a UDP message, then the parsing function corresponding to the UDP protocol is called to parse the UDP message. When dst_port!=4789 used to store the next protocol judgment data in the UDP protocol, it means that there is no next network message to be parsed, and the current network message parsing process ends.

[0164] Please refer to Fig. 9 , Fig. 9 It is a schematic diagram of a process of parsing a network message provided by an embodiment of the present application;

[0165] like Fig. 9As shown, assuming that A is a MAC message, B is an IPv4 message, C is a UDP message, and the MAC message is the currently acquired network message. Assuming that the total length of the MAC message is 1518B, call the parsing message class corresponding to the MAC protocol to parse the MAC message. At the same time, refer to Table 1. It is known that the message header length A.header of the MAC message is 14B, and the frame sequence length fcs of the MAC message is 4B. Then the data length A.data of the MAC message is 1500B. Specifically, according to the order of each field segment in the message header of the MAC message, they are dmac, smac, and mac_type respectively. Assign 0B to 5B in the MAC message to the dmac field segment, assign 6B to 11B in the MAC message to the smac field segment, assign 12B to 13B in the MAC message to the mac_type field segment, and assign 14B to 1513B in the MAC message to mac_da ta field segment, assigns 1514B to 1517B in the MAC message to the fcs field segment, further, judges whether the value of mac_type is 0x0800, if so, determines that the next network message to be parsed is a B message, that is, an IPv4 message, calls the parsing message class corresponding to the IPv4 protocol, parses the IPv4 message, and obtains the message header B.header and message data B.data of the IPv4 message, further, judges that the value of the protocol field segment in the IPv4 protocol is 7, if so, determines that the next network message to be parsed is a C message, that is, a UDP message, calls the parsing message class corresponding to the UDP protocol to parse the UDP message, and obtains the message header C.header and message data C.data of the UDP message, further, when the value of the dst_port field segment in the UDP protocol is not 4789, it means that there is no next message header, and the current message parsing process ends.

[0166] In the embodiment of the present application, the network message is parsed by calling the parsing message class, and the next network message to be parsed is automatically identified without manual instruction, so that the network message can be parsed quickly and the efficiency of network chip verification is improved.

[0167] See also Fig.10 , Fig.10 It is a structural diagram of a device for generating parsed message classes provided in an embodiment of the present application;

[0168] like Fig.10 As shown, the generating device 100 for parsing message class includes:

[0169] A first acquisition unit 10 acquires a message protocol file, wherein the message protocol file includes message information corresponding to a plurality of message protocols;

[0170] The first acquisition unit 20 acquires a script and executes the script to parse the message protocol file to obtain message information corresponding to multiple message protocols;

[0171] The generating unit 30 generates a parsed message class corresponding to each message protocol according to the parsed message information.

[0172] In an embodiment of the present application, the device for generating the parsed message class can be a software module, which includes a number of instructions stored in a memory. The processor can access the memory and call the instructions for execution to complete the method for generating the parsed message class of the above-mentioned embodiments.

[0173] In the embodiments of the present application, the generation device of the parsed message class can also be constructed by hardware devices. For example, the generation device of the parsed message class can be constructed by one or more chips, and each chip can work in coordination with each other to complete the generation method of the parsed message class described in the above embodiments. For another example, the generation device of the parsed message class can also be constructed by various logic devices, such as a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISC Machine) or other programmable logic device, a discrete gate or transistor logic, a discrete hardware component, or any combination of these components.

[0174] The generating device of the parsed message class in the embodiment of the present application can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, an in-vehicle electronic device, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and the non-mobile electronic device can be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.

[0175] The device for generating the parsed message class in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.

[0176] The generation device of the parsed message class provided in the embodiment of the present application can achieve Figure 1 To avoid repetition, the various processes implemented by the method embodiment are not described here.

[0177] It should be noted that the above device can execute the generation method of the parsed message class provided in the embodiment of the present application, and has the corresponding functional modules and beneficial effects of the execution method. For technical details not described in detail in the device embodiment, please refer to the generation method of the parsed message class provided in the embodiment of the present application.

[0178] In the embodiment of the present application, the various units of the device for generating the parsed message class cooperate with each other to solve the problem of being able to quickly generate the parsed message class, so as to improve the efficiency of network chip verification.

[0179] See also Fig.11 , Fig.11 It is a structural diagram of a verification device for a network chip provided in an embodiment of the present application;

[0180] like Fig.11 As shown, the verification device 110 of the network chip includes:

[0181] A message acquisition unit 111, used to acquire network messages;

[0182] The parsing unit 112 is used to call the parsing function corresponding to the parsing message class to parse the network message to obtain the message data corresponding to the network message, wherein the parsing message class is generated by the generation method of the parsing message class.

[0183] In an embodiment of the present application, the verification device of the network chip can be a software module, which includes several instructions stored in a memory. The processor can access the memory and call the instructions for execution to complete the verification method of the network chip in the above-mentioned embodiments.

[0184] In the embodiments of the present application, the verification device of the network chip can also be constructed by hardware devices. For example, the verification device of the network chip can be constructed by one or more chips, and each chip can work in coordination with each other to complete the verification method of the network chip described in the above embodiments. For another example, the verification device of the network chip can also be constructed by various logic devices, such as a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISC Machine) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination of these components.

[0185] The verification device of the network chip in the embodiment of the present application can be a device, or a component, an integrated circuit, or a chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, an in-vehicle electronic device, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and the non-mobile electronic device can be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.

[0186] The verification device of the network chip in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.

[0187] The network chip verification device provided in the embodiment of the present application can achieve Figure 5 To avoid repetition, the various processes implemented by the method embodiment are not described here.

[0188] It should be noted that the above device can execute the network chip verification method provided in the embodiment of the present application, and has the corresponding functional modules and beneficial effects of the execution method. For technical details not fully described in the device embodiment, please refer to the network chip verification method provided in the embodiment of the present application.

[0189] In the embodiment of the present application, the various units of the verification device of the network chip cooperate with each other to automatically identify the next network message to be parsed without manual instructions, so as to quickly parse the network message and improve the efficiency of network chip verification.

[0190] See also Fig.12 , Fig.12 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application.

[0191] like Fig.12 As shown, the electronic device 120 includes one or more processors 121 and a memory 122. Fig.12 A processor 121 is taken as an example.

[0192] The processor 121 and the memory 122 may be connected via a bus or other means. Fig.12The example of connecting through bus is taken in the following.

[0193] The processor 121 is used to provide computing and control capabilities to control the electronic device 120 to perform corresponding tasks, for example, to control the electronic device 120 to perform the generation method of the parsed message class or the verification method of the network chip in any of the above method embodiments.

[0194] Among them, the method for generating a parsed message class includes: obtaining a message protocol file, wherein the message protocol file includes message information corresponding to multiple message protocols; obtaining a script, and executing the script to parse the message protocol file to obtain message information corresponding to multiple message protocols; based on the parsed message information, generating a parsed message class corresponding to each message protocol.

[0195] Among them, the verification method of the network chip includes: obtaining a network message; calling a parsing function corresponding to a parsing message class to parse the network message to obtain message data corresponding to the network message, wherein the parsing message class is generated by a generation method of the parsing message class.

[0196] The processor 121 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), a hardware chip or any combination thereof; it may also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a programmable logic device (PLD) or a combination thereof. The above-mentioned PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.

[0197] The memory 122, as a non-transient computer-readable storage medium, can be used to store non-transient software programs, non-transient computer executable programs and modules, such as the program instructions / modules corresponding to the generation method of the parsing message class or the verification method of the network chip in the embodiment of the present application. The processor 121 can implement the generation method of the parsing message class or the verification method of the network chip in any of the above method embodiments by running the non-transient software programs, instructions and modules stored in the memory 122. Specifically, the memory 122 may include a volatile memory (volatile memory, VM), such as a random access memory (random access memory, RAM); the memory 122 may also include a non-volatile memory (non-volatile memory, NVM), such as a read-only memory (read-only memory, ROM), a flash memory (flash memory), a hard disk drive (hard disk drive, HDD) or a solid-state drive (solid-state drive, SSD) or other non-transient solid-state storage devices; the memory 122 may also include a combination of the above types of memories.

[0198] The memory 122 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 122 may optionally include a memory remotely arranged relative to the processor 121, and these remote memories may be connected to the processor 121 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0199] One or more modules are stored in the memory 122, and when executed by one or more processors 121, the generation method of the parsed message class and the verification method of the network chip in any of the above method embodiments are executed, for example, the above described Figure 1 or Figure 5 The steps shown.

[0200] In an embodiment of the present application, a script is used to parse the message information corresponding to multiple message protocols in a message protocol file, and a parsing message class corresponding to each message protocol is generated according to the message information corresponding to the message protocol. The parsing message class is called to automatically parse the message, thereby realizing the automatic generation of the parsing message class and the automatic parsing process of the network message, thereby improving the efficiency of network chip verification.

[0201] The embodiment of the present application also provides a non-volatile computer-readable storage medium, such as a memory including a program code, and the program code can be executed by a processor to complete the generation method of the parsed message class or the verification method of the network chip in the above embodiment. For example, the non-volatile computer-readable storage medium can be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CDROM), a magnetic tape, a floppy disk, and an optical data storage device.

[0202] The embodiment of the present application also provides a computer program product, which includes one or more program codes, and the program codes are stored in a non-volatile computer-readable storage medium. The processor of the electronic device reads the program code from the non-volatile computer-readable storage medium, and the processor executes the program code to complete the method steps of the generation method of the parsed message class or the verification method of the network chip provided in the above embodiment.

[0203] A person skilled in the art will appreciate that all or part of the steps for implementing the above embodiments may be accomplished by hardware or by hardware associated with a program code, and the program may be stored in a non-volatile computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.

[0204] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution can be essentially or in other words, the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute various embodiments or certain parts of the embodiments.

[0205] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Under the concept of the present application, the technical features in the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other changes in different aspects of the present application as above, which are not provided in detail for the sake of simplicity. Although the present application has been described in detail with reference to the aforementioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the aforementioned embodiments can still be modified, or some of the technical features can be replaced by equivalents. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for generating a parsed message class, characterized in that: The method comprises: Obtain a message protocol file, wherein the message protocol file includes message information corresponding to multiple message protocols; Obtain a script, and execute the script to parse the message protocol file to obtain message information corresponding to multiple message protocols; According to the message information obtained by parsing, a parsed message class corresponding to each message protocol is generated.

2. The method according to claim 1, characterized in that The message information corresponding to the message protocol includes: a plurality of domain segments. Before generating a parsed message class corresponding to each message protocol, the method further includes: Determine whether there are the same domain segments in the message information corresponding to different message protocols; If the same domain segment does not exist, continue to execute the step of generating the parsed message class; If the same domain segment exists, the name of the corresponding message protocol is added before the same domain segment.

3. The method according to claim 1, characterized in that: The step of generating a parsed message class corresponding to each message protocol according to the message information obtained by parsing includes: Generate domain information corresponding to each message protocol according to the message information; According to the field information corresponding to each of the message protocols, a parsing function for parsing the message class corresponding to each message protocol is generated, wherein the parsing function corresponds to a message header one by one.

4. The method according to claim 3, characterized in that The method further comprises: Adding message information corresponding to the new message protocol in the message protocol file; Execute the script to parse the message protocol file to obtain the new message protocol information; According to the new message protocol information, a parsed message class corresponding to the new message protocol is generated.

5. A network chip verification method, characterized in that: The method comprises: Get network messages; The parsing function corresponding to the parsing message class is called to parse the network message to obtain message data corresponding to the network message, wherein the parsing message class is generated by the generation method of the parsing message class described in any one of claims 1-4.

6. The method according to claim 5, characterized in that The message information corresponding to the message protocol includes: multiple domain segments; The calling of the parsing function corresponding to the parsing message class to parse the network message to obtain message data corresponding to the network message includes: Determine the position of each of the domain segments in the network message; Determining the length of each of the domain segments; According to the length of the field segment and the position of the field segment, the data of each field segment is obtained, wherein the message data includes the data of each field segment.

7. The method according to claim 6, characterized in that The field segment includes the total length of the message and the message header. When the field segment includes a variable length field segment, determining the length of each field segment includes: Determining the length of the variable-length field segment specifically includes: The length of the variable length field segment is determined according to the total length of the message and the length of the message header, wherein the length of the variable length field segment = the total length of the message - the length of the message header.

8. The method according to claim 7, characterized in that The message data includes next protocol determination data, and the method further includes: Determine whether the next protocol determination data includes a preset value, wherein the preset value includes a network message to be parsed; If the next protocol judgment data includes the preset value, calling a parsing function to parse the network message to be parsed according to the preset value; If the next protocol judgment data does not include the preset value, the parsing process of the network message is terminated.

9. An electronic device, characterized in that: include at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method for generating a parsed message class as described in any one of claims 1-4 or the method for verifying a network chip as described in any one of claims 5-8.

10. A non-volatile computer-readable storage medium, characterized in that: The non-volatile computer-readable storage medium stores a computer program, which includes program instructions. When the program instructions are executed by a processor, the processor executes the method for generating a parsed message class as described in any one of claims 1 to 4 or the method for verifying a network chip as described in any one of claims 5 to 8.

Citation Information

Cited By

  • Method and device for generating function coverage rate based on variable-length data packet and medium

    CN120562354A

  • Method, apparatus, and medium for generating functional coverage based on indefinite length packet

    CN120562354B