CN116455991B - Tunnel encapsulation message checksum calculation method and related device - Google Patents

Tunnel encapsulation message checksum calculation method and related device Download PDF

Info

Publication number
CN116455991B
CN116455991B CN202310691741.8A CN202310691741A CN116455991B CN 116455991 B CN116455991 B CN 116455991B CN 202310691741 A CN202310691741 A CN 202310691741A CN 116455991 B CN116455991 B CN 116455991B
Authority
CN
China
Prior art keywords
message
calculation result
value set
accumulation sum
header
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202310691741.8A
Other languages
Chinese (zh)
Other versions
CN116455991A (en
Inventor
战永超
王天建
顾荣豪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhuhai Xingyun Zhilian Technology Co Ltd
Original Assignee
Zhuhai Xingyun Zhilian Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhuhai Xingyun Zhilian Technology Co Ltd filed Critical Zhuhai Xingyun Zhilian Technology Co Ltd
Priority to CN202310691741.8A priority Critical patent/CN116455991B/en
Publication of CN116455991A publication Critical patent/CN116455991A/en
Application granted granted Critical
Publication of CN116455991B publication Critical patent/CN116455991B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/164Adaptation or special uses of UDP protocol
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/46Interconnection of networks
    • H04L12/4633Interconnection of networks using encapsulation techniques, e.g. tunneling
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/50Reducing energy consumption in communication networks in wire-line communication networks, e.g. low power modes or reduced link rate

Abstract

The application discloses a method for calculating a checksum of a tunnel encapsulation message and a related device, wherein the method comprises the following steps: acquiring a first message; accumulating all bytes in the first message to obtain a first message accumulation sum; determining a message domain segment of the first message, and identifying a new value set and an old value set in the message domain segment; performing operation according to the new value set to obtain a first calculation result; performing operation according to the old value set to obtain a second calculation result; determining a second message accumulation sum according to the first message accumulation sum, the first calculation result and the second calculation result; acquiring an original message of the first message, acquiring a tunnel header according to the original message, and extracting a pseudo header from the tunnel header to obtain k parts of the pseudo header; and determining UDP checksum according to the second message accumulation sum and k parts of the pseudo header. The application can improve the UDP layer checksum calculation efficiency under the condition of saving calculation resources.

Description

Tunnel encapsulation message checksum calculation method and related device
Technical Field
The application relates to the technical field of intelligent network cards, in particular to a tunnel encapsulation message checksum calculation method and a related device.
Background
At present, one method of the intelligent network card in communication with the external network is network tunneling technology, which is technology of packaging a message into a header, thereby realizing the replacement of network protocol and breaking through IP domain segment for communication. When tunnel encapsulation is performed, the user datagram protocol (User Datagram Protocol, UDP) layer checksum contained in the tunnel header requires a calculated checksum. Based on the requirement, the UDP layer checksum involves the calculation of the comprehensive whole message result, the calculated amount is large, the calculated result is complex, the obtained calculated result is slow, and the calculation resource is consumed, so the problem of how to improve the UDP layer checksum calculation efficiency under the condition of saving the calculation resource is needed to be solved.
Disclosure of Invention
The application provides a tunnel encapsulation message checksum calculation method and a related device, which can improve UDP layer checksum calculation efficiency under the condition of saving calculation resources.
In a first aspect, the present application provides a method for calculating a checksum of a tunnel encapsulation packet, where the method includes:
acquiring a first message;
accumulating all bytes in the first message to obtain a first message accumulation sum;
in the process of editing the message, determining a message domain segment of the first message, and identifying a new value set and an old value set in the message domain segment, wherein the new value set comprises n new values, and the old value set comprises m old values; the new value is used for indicating that the value of the position where the new value is located in the current calculation is different from the value of the position calculated last time; the old value is used for indicating that the value of the position where the old value is located in the current calculation is the same as the value of the position calculated last time; n is a natural number, m is a natural number;
Performing operation according to the new value set to obtain a first calculation result;
performing operation according to the old value set to obtain a second calculation result;
determining a second message accumulation sum according to the first message accumulation sum, the first calculation result and the second calculation result;
acquiring an original message of the first message, acquiring a tunnel header according to the original message, and extracting a pseudo header from the tunnel header to obtain k parts of the pseudo header, wherein k is a positive integer;
and determining UDP checksum according to the second message accumulation sum and k parts of the pseudo header, and placing the UDP checksum into a UDP checksum field section in the tunnel header.
In a second aspect, the present application provides a tunnel encapsulation packet checksum calculation apparatus, where the apparatus includes: an acquisition unit, an operation unit and a determination unit, wherein,
the acquisition unit is used for acquiring a first message;
the operation unit is used for accumulating all bytes in the first message to obtain a first message accumulation sum;
the determining unit is configured to determine a message field of the first message and identify a new value set and an old value set in the message field in a message editing process, where the new value set includes n new values and the old value set includes m old values; the new value is used for indicating that the value of the position where the new value is located in the current calculation is different from the value of the position calculated last time; the old value is used for indicating that the value of the position where the old value is located in the current calculation is the same as the value of the position calculated last time; n is a natural number, m is a natural number;
The operation unit is further used for performing operation according to the new value set to obtain a first calculation result; performing operation according to the old value set to obtain a second calculation result; determining a second message accumulation sum according to the first message accumulation sum, the first calculation result and the second calculation result;
the acquisition unit is further configured to acquire an original message of the first message, acquire a tunnel header according to the original message, and extract a pseudo header from the tunnel header to obtain k parts of the pseudo header, where k is a positive integer;
the determining unit is further configured to determine a UDP checksum according to the second packet accumulation sum and the k portions of the pseudo header, and place the UDP checksum into a UDP checksum field in the tunnel header.
In a third aspect, the present application provides an electronic device comprising a processor, a memory, a communication interface and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the processor, the programs comprising instructions for performing the steps of the first aspect of the application.
In a fourth aspect, the present application provides a computer-readable storage medium storing a computer program for electronic data exchange, wherein the computer program causes a computer to execute some or all of the steps as described in the first aspect of the present application.
In a fifth aspect, the present application provides a computer program product, wherein the computer program product comprises a non-transitory computer readable storage medium storing a computer program operable to cause a computer to perform part or all of the steps described in the first aspect of the application. The computer program product may be a software installation package.
The implementation of the application has the following beneficial effects:
it can be seen that, according to the tunnel encapsulation message checksum calculation method and the related device described in the present application, a first message is obtained, all bytes in the first message are accumulated to obtain a first message accumulation sum, a message domain segment of the first message is determined in a message editing process, and a new value set and an old value set in the message domain segment are identified, wherein the new value set comprises n new values, and the old value set comprises m old values; the new value is used for indicating that the value of the position where the new value is located in the current calculation is different from the value of the position calculated last time; the old value is used for indicating that the value of the position where the old value is located in the current calculation is the same as the value of the position calculated last time; n is a natural number, m is a natural number, an operation is performed according to a new value set to obtain a first calculation result, an operation is performed according to an old value set to obtain a second calculation result, a second message accumulation sum is determined according to the first message accumulation sum, the first calculation result and the second calculation result, an original message of the first message is obtained, a tunnel header is obtained according to the original message, a pseudo header is extracted from the tunnel header to obtain k parts of the pseudo header, k is a positive integer, a UDP checksum is determined according to the second message accumulation sum and k parts of the pseudo header, the UDP checksum is put into a UDP checksum field in the tunnel header, the whole packet accumulation sum calculation of the original message and the partial recalculation of the original message accumulation sum in the editing process are performed in advance in a message identification stage, and therefore saving of cache resources can be achieved in the tunnel encapsulation process, meanwhile, the uncertainty of communication delay and communication delay is reduced, namely under the condition of saving calculation resources, the UDP layer checksum calculation efficiency is improved.
Drawings
In order to more clearly illustrate the application or the technical solutions of the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it being obvious that the drawings in the description below are only some embodiments of the application, and that other drawings can be obtained from them without inventive effort for a person skilled in the art.
Fig. 1 is a schematic diagram of a communication system corresponding to a network tunneling technique for communication between an intelligent network card and an external network;
FIG. 2 is a schematic flow chart of another method for calculating the checksum of the tunnel encapsulation message provided by the application;
FIG. 3 is a schematic diagram of a communication system corresponding to another network tunneling technique for communicating between an intelligent network card and an external network according to the present application
Fig. 4 is a schematic structural diagram of an electronic device according to the present application;
fig. 5 is a functional unit composition block diagram of a tunnel encapsulation message checksum calculation device provided by the application.
Detailed Description
In order that the manner in which the application may be better understood, a more particular description of the application will be rendered by reference to specific embodiments thereof which are illustrated in the appended drawings. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
The terms first, second and the like in the description and in the claims and in the above-described figures are used for distinguishing between different objects and not necessarily for describing a sequential or chronological order. Furthermore, the terms "comprise" and "have," as well as any variations thereof, are intended to cover a non-exclusive inclusion. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those listed steps or elements but may include other steps or elements not listed or inherent to such process, method, article, or apparatus.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the application. The appearances of such phrases in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments.
In a specific implementation, the electronic device related to the present application may be any electronic device with tunnel encapsulation message checksum calculation, where the electronic device may include, but is not limited to: smart cards, routers, switches, UDP, smartphones, tablet computers, smart robots, smart projectors, conferencing equipment, in-vehicle equipment, wearable equipment, servers, video transmission cameras, wireless or wired live broadcast equipment, voice communication equipment, multi-person online conferencing equipment, network equipment, computing equipment, or other processing equipment connected to wireless modems, as well as various forms of User Equipment (UE), mobile Stations (MS), terminal equipment (terminal device), and the like, without limitation. The electronic device may also include a server.
In the related art, as shown in fig. 1, fig. 1 is a schematic diagram of a communication system corresponding to a network tunneling technique in which an intelligent network card communicates with an external network. I.e. the intelligent network card may comprise one network port (first network port) and the external network may correspond to one network port (second network port). The communication system can comprise a message identification module, a tunnel encapsulation module, a message buffer module and a checksum calculation module. The message identification module is used for realizing the message identification function. The tunnel encapsulation module is used for realizing the encapsulation function. The message buffer module is used for realizing message buffer and the checksum calculation module is used for realizing checksum calculation function.
In a specific implementation, after the tunnel header is encapsulated, the whole message is cached, and a pseudo header and a message payload are extracted for calculation. After the tunnel header is packaged, the whole message is cached for calculation, and in practical application, the whole message needs to be cached for calculation, so that the communication delay is large, and the cache resources are consumed. Especially in the case of uncertain message length, the delay also becomes uncertain with various application scenarios.
In order to solve the defects in the related art, the application provides a method for calculating a tunnel encapsulation message checksum, which comprises the following steps:
Acquiring a first message;
accumulating all bytes in the first message to obtain a first message accumulation sum;
in the process of editing the message, determining a message domain segment of the first message, and identifying a new value set and an old value set in the message domain segment, wherein the new value set comprises n new values, and the old value set comprises m old values; the new value is used for indicating that the value of the position where the new value is located in the current calculation is different from the value of the position calculated last time; the old value is used for indicating that the value of the position where the old value is located in the current calculation is the same as the value of the position calculated last time; n is a natural number, m is a natural number;
performing operation according to the new value set to obtain a first calculation result;
performing operation according to the old value set to obtain a second calculation result;
determining a second message accumulation sum according to the first message accumulation sum, the first calculation result and the second calculation result;
acquiring an original message of the first message, acquiring a tunnel header according to the original message, and extracting a pseudo header from the tunnel header to obtain k parts of the pseudo header;
and determining UDP checksum according to the second message accumulation sum and k parts of the pseudo header, and placing the UDP checksum into a UDP checksum field section in the tunnel header.
In the application, by carrying out the whole packet accumulation and calculation of the original message in advance and the partial recalculation of the original message accumulation and in the editing process, compared with the scheme in the related art, namely, caching the whole message and then calculating the checksum, the application realizes saving of cache resources in the tunnel encapsulation process and reduces the communication delay and the uncertainty of the communication delay.
Taking a message as a C byte as an example, in each clock cycle/instruction execution cycle, the present module is designed to fix and receive a message h byte (h is less than or equal to C) in each clock cycle/instruction execution cycle, if the present module performs whole packet accumulation and calculation, the present module needs to buffer after receiving the whole message, and performs calculation according to the buffered result, the present module at least needs to prepare to buffer as (C/h+1) h, namely, integer multiple of h, and rounding up under the condition of non-integer multiple; the delay of the module of this stage is (C/h+1) clock cycle/instruction execution cycle. Since C varies from message to message in practical application, the buffer space and delay are reserved for preparation, which is a great waste of storage resources. According to the calculation method in the application, the buffer space of (C/h+1) h can be saved, and the communication delay of (C/h+1) clock cycle/instruction execution cycle can be reduced.
The present application will be described in detail below.
Referring to fig. 2, fig. 2 is a schematic flow chart of a method for calculating a checksum of a tunnel encapsulation message, which is provided by the application and is applied to an electronic device; as shown in the figure, the method for calculating the checksum of the tunnel encapsulation message comprises the following steps:
201. and acquiring a first message.
In a specific implementation, a first message may be acquired in a message identification stage, where the first message may be one or more messages. That is, the first message may be one complete message, or the first message may be a plurality of complete messages.
The present application may be applied to various tunneling techniques, for example, ipv6.
The first message may be any message, or the first message may be specified by a user or default by the system.
202. And accumulating all bytes in the first message to obtain a first message accumulation sum.
In the application, all bytes in the first message can be directly accumulated to obtain the accumulated sum of the first message.
203. In the process of editing the message, determining a message domain segment of the first message, and identifying a new value set and an old value set in the message domain segment, wherein the new value set comprises n new values, and the old value set comprises m old values; the new value is used for indicating that the value of the position where the new value is located in the current calculation is different from the value of the position calculated last time; the old value is used for indicating that the value of the position where the old value is located in the current calculation is the same as the value of the position calculated last time; n is a natural number, and m is a natural number.
In the application, in the process of editing the message, a message domain segment of a first message can be determined, the message domain segment can be an address segment, the address segment can be a plurality of addresses, each address can correspond to a value, a new value set and an old value set in the message domain segment are identified, the new value set can comprise n new values, and the old value set can comprise m old values; n is a natural number, i.e., n is an integer greater than or equal to 0, and m is a natural number, i.e., m is an integer greater than or equal to 0.
The new value is used for indicating that the value of the position where the new value is located in the current calculation is different from the value of the position calculated last time; the old value is used to indicate that the value of the position where the old value is located at the time of the present calculation is the same as the value of the position calculated last time.
In a specific implementation, the step 203 may be performed multiple times, so that multiple new value sets and multiple old value sets may be obtained.
204. And carrying out operation according to the new value set to obtain a first calculation result.
In the application, the new values can be accumulated, so that a first calculation result is obtained.
Optionally, in the step 204, the operation is performed according to the new value set to obtain a first calculation result, which may be implemented as follows:
And accumulating and operating the new value set to obtain the first calculation result.
In a specific implementation, the new value set may include one or more new values, and the new value set may be accumulated and calculated to obtain the first calculation result.
205. And carrying out operation according to the old value set to obtain a second calculation result.
In a specific implementation, the old value set may include one or more old values, that is, the one or more old values may be accumulated to obtain a second calculation result; alternatively, one or more old values may be accumulated first, and then the inverse operation may be performed to obtain the second calculation result.
206. And determining a second message accumulation sum according to the first message accumulation sum, the first calculation result and the second calculation result.
In a specific implementation, the second calculation result may be inverted, and then the inverted result is accumulated with the first message and the first calculation result to obtain the second message.
In a specific implementation, the steps 202-206 can be repeated for a plurality of times, and partial recalculation in the editing process is performed, so that the buffer resource in the tunnel encapsulation process is saved, and meanwhile, the communication delay and the uncertainty of the communication delay are reduced.
Optionally, in step 205, the calculation is performed according to the old value set to obtain a second calculation result, which may be implemented as follows:
accumulating and operating the old value set to obtain the second calculation result;
the step 206 of determining a second packet accumulation sum according to the first packet accumulation sum, the first calculation result and the second calculation result may include the following steps:
performing inverse operation on the second calculation result to obtain a target second calculation result; and accumulating the first message accumulation sum, the first calculation result and the target second calculation result to obtain the second message accumulation sum.
In a specific implementation, the old value set may be accumulated and calculated to obtain a second calculation result, then the second calculation result may be inverted to obtain a target second calculation result, and then the first message accumulation sum, the first calculation result and the target second calculation result are accumulated to obtain a second message accumulation sum.
In the specific implementation, the first calculation result and the second calculation result are approximately the same in algorithm and are all 16bit accumulated, and the same calculation module can be reused in engineering implementation, so that agile development and calculation resource saving are realized. The calculation method for accumulating the first message accumulation sum, the first calculation result and the target second calculation result is specified by a standard checksum calculation method.
Optionally, in step 205, the calculation is performed according to the old value set to obtain a second calculation result, which may be implemented as follows:
performing accumulation and inversion operation on the old value set to obtain the second calculation result;
the step 206 of determining a second packet accumulation sum according to the first packet accumulation sum, the first calculation result and the second calculation result may be implemented as follows:
and accumulating the first message accumulation sum, the first calculation result and the second calculation result to obtain the second message accumulation sum.
In a specific implementation, the old value set can be subjected to accumulation and operation to obtain a value, the value is subjected to inverse operation to obtain a second calculation result, and the first message accumulation and sum, the first calculation result and the second calculation result are accumulated to obtain a second message accumulation and sum.
In the specific implementation, the first calculation result and the second calculation result are approximately the same in algorithm and are all 16bit accumulated, and the same calculation module can be reused in engineering implementation, so that agile development and calculation resource saving are realized. The calculation method for accumulating the first message accumulation sum, the first calculation result and the target second calculation result is specified by a standard checksum calculation method.
207. Obtaining an original message of the first message, obtaining a tunnel header according to the original message, and extracting a pseudo header from the tunnel header to obtain k parts of the pseudo header, wherein k is a positive integer.
In the application, an original message of the first message can be obtained, namely the original message comprises the first message, or the first message is a part of the original message or all of the original message, or the first message is a message obtained by certain processing of the original message, then a tunnel header corresponding to the original message is obtained, a pseudo header is extracted from the tunnel header, k parts of the pseudo header are obtained, and k is a positive integer.
208. And determining UDP checksum according to the second message accumulation sum and k parts of the pseudo header, and placing the UDP checksum into a UDP checksum field section in the tunnel header.
In the application, the k parts of the pseudo header can be subjected to summation operation to obtain an accumulation sum, then the accumulation sum and the second message accumulation sum are subjected to summation operation to obtain a UDP checksum, and the UDP checksum is put into a UDP checksum field section in the tunnel header.
Of course, in a specific implementation, the UDP checksum may be implemented in such a manner that the UDP checksum may be a value obtained by adding the tunnel header pseudo header sum+the new value sum+the old value sum and inverting the old value sum+the original whole packet checksum, and the value is inverted.
Optionally, the step 208 of determining a UDP checksum according to the second packet accumulated sum and k portions of the pseudo header may include the following steps:
accumulating k parts of the pseudo header to obtain a pseudo header accumulation sum; summing the second message accumulation sum and the pseudo header accumulation sum to obtain a third calculation result; and carrying out inverse operation on the third calculation result to obtain the UDP checksum.
In the application, k parts of the pseudo header can be accumulated to obtain a pseudo header accumulated sum, then the second message accumulated sum and the pseudo header accumulated sum are summed to obtain a third calculation result, and the third calculation result is subjected to inverse operation to obtain the UDP checksum.
For example, as shown in fig. 3, fig. 3 is a schematic diagram of a communication system corresponding to another network tunneling technique for performing communication between the intelligent network card and the external network. I.e. the intelligent network card may comprise one network port (first network port) and the external network may correspond to one network port (second network port). The communication system can comprise a message identification module, a first message editing module, a second message editing module, a tunnel encapsulation module and a tunnel head storage module.
The message identification module is used for realizing message identification functions, such as identifying and calculating the whole packet accumulation sum. The functions of the first message editing module and the second message editing module can be the same or different, and the first message editing module and the second message editing module realize message editing functions, such as message editing actions and updating whole packet accumulation sums. The tunnel encapsulation module is used for realizing encapsulation functions, such as integrating the sum of whole packets and integrating the sum of pseudo-header of the tunnel header to calculate the checksum of the tunnel header. The tunnel head storage module is used for storing the tunnel head.
In a specific implementation, the message identification module accumulates all bytes of the whole message in the process of identifying the message, so as to obtain message accumulation and information to be transmitted to a later stage. When the first message editing module edits the message, the new value is accumulated independently, and the old value is accumulated independently, and the original message accumulation, the new value accumulation sum and the inverted old value accumulation sum are summed together, so that the whole packet accumulation sum edited by the first message editing module is obtained. The second message editing module has the same calculation method as the first message editing module. The tunnel encapsulation module acquires the original message, acquires the tunnel header from the tunnel header storage module, extracts the pseudo header from the tunnel header, adds the integral packet accumulation sum and the pseudo header accumulation sum and then inverts the integral packet accumulation sum, so that the UDP checksum in the tunnel header can be obtained, and the checksum is put into the UDP checksum field section in the tunnel header.
Before the tunnel header is packaged, the front-stage message identification module calculates the accumulated sum of the whole message as a part of UDP checksum in the tunnel header when the message is identified, and transmits the accumulated sum to the tunnel packaging module, and the accumulated sum is refreshed along with the message editing process in various editing processes of the message. After the editing action of the original message, tunnel encapsulation operation is carried out on the original message, at the moment, a tunnel message header which is stored in advance is obtained, a pseudo header field section is extracted, the accumulated sum of the pseudo header is calculated, and the accumulated sum and the original message are added and then are inverted, so that the UDP checksum of the tunnel header is obtained. The checksum is obtained in this way, so that the utilization of cache resources can be effectively reduced, and the delay is reduced.
Compared with the scheme in the related art, namely, the scheme of caching the whole message and then calculating the checksum, the application saves the cache resources in the tunnel packaging process and reduces the communication delay and the uncertainty of the communication delay simultaneously by carrying out the whole packet accumulation and calculation of the original message in advance and the partial recalculation of the original message accumulation and in the editing process.
It can be seen that, according to the tunnel encapsulation message checksum calculation method described in the present application, a first message is obtained, all bytes in the first message are accumulated to obtain a first message accumulation sum, a message domain segment of the first message is determined in a message editing process, and a new value set and an old value set in the message domain segment are identified, wherein the new value set comprises n new values, and the old value set comprises m old values; the new value is used for indicating that the value of the position where the new value is located in the current calculation is different from the value of the position calculated last time; the old value is used for indicating that the value of the position where the old value is located in the current calculation is the same as the value of the position calculated last time; n is a natural number, m is a natural number, an operation is performed according to a new value set to obtain a first calculation result, an operation is performed according to an old value set to obtain a second calculation result, a second message accumulation sum is determined according to the first message accumulation sum, the first calculation result and the second calculation result, an original message of the first message is obtained, a tunnel header is obtained according to the original message, a pseudo header is extracted from the tunnel header to obtain k parts of the pseudo header, k is a positive integer, a UDP checksum is determined according to the second message accumulation sum and k parts of the pseudo header, the UDP checksum is put into a UDP checksum field in the tunnel header, the whole packet accumulation sum calculation of the original message and the partial recalculation of the original message accumulation sum in the editing process are performed in advance in a message identification stage, and therefore saving of cache resources can be achieved in the tunnel encapsulation process, meanwhile, the uncertainty of communication delay and communication delay is reduced, namely under the condition of saving calculation resources, the UDP layer checksum calculation efficiency is improved.
In accordance with the above embodiment, referring to fig. 4, fig. 4 is a schematic structural diagram of an electronic device provided by the present application, as shown in the fig. 4, the electronic device includes a processor, a memory, a communication interface, and one or more programs, where the one or more programs are stored in the memory and configured to be executed by the processor, and in the present application, the programs include instructions for performing the following steps:
acquiring a first message;
accumulating all bytes in the first message to obtain a first message accumulation sum;
in the process of editing the message, determining a message domain segment of the first message, and identifying a new value set and an old value set in the message domain segment, wherein the new value set comprises n new values, and the old value set comprises m old values; the new value is used for indicating that the value of the position where the new value is located in the current calculation is different from the value of the position calculated last time; the old value is used for indicating that the value of the position where the old value is located in the current calculation is the same as the value of the position calculated last time; n is a natural number, m is a natural number;
performing operation according to the new value set to obtain a first calculation result;
performing operation according to the old value set to obtain a second calculation result;
Determining a second message accumulation sum according to the first message accumulation sum, the first calculation result and the second calculation result;
acquiring an original message of the first message, acquiring a tunnel header according to the original message, and extracting a pseudo header from the tunnel header to obtain k parts of the pseudo header, wherein k is a positive integer;
and determining UDP checksum according to the second message accumulation sum and k parts of the pseudo header, and placing the UDP checksum into a UDP checksum field section in the tunnel header.
Optionally, in said determining a UDP checksum based on said second packet accumulation sum and k portions of said pseudo header, said program comprises instructions for:
accumulating k parts of the pseudo header to obtain a pseudo header accumulation sum;
summing the second message accumulation sum and the pseudo header accumulation sum to obtain a third calculation result;
and carrying out inverse operation on the third calculation result to obtain the UDP checksum.
Optionally, in the aspect of performing the operation according to the new value set to obtain a first calculation result, the program includes instructions for performing the following steps:
and accumulating and operating the new value set to obtain the first calculation result.
Optionally, in the aspect of performing the operation according to the old value set to obtain a second calculation result, the program includes instructions for performing the following steps:
accumulating and operating the old value set to obtain the second calculation result;
in the aspect of determining a second message accumulation sum according to the first message accumulation sum, the first calculation result and the second calculation result, the program includes instructions for executing the following steps:
performing inverse operation on the second calculation result to obtain a target second calculation result;
and accumulating the first message accumulation sum, the first calculation result and the target second calculation result to obtain the second message accumulation sum.
Optionally, in the aspect of performing the operation according to the old value set to obtain a second calculation result, the program includes instructions for performing the following steps:
performing accumulation and inversion operation on the old value set to obtain the second calculation result;
in the aspect of determining a second message accumulation sum according to the first message accumulation sum, the first calculation result and the second calculation result, the program includes instructions for executing the following steps:
And accumulating the first message accumulation sum, the first calculation result and the second calculation result to obtain the second message accumulation sum.
It can be seen that, in the electronic device described in the present application, a first message is obtained, all bytes in the first message are accumulated to obtain a first message accumulation sum, a message domain segment of the first message is determined in a message editing process, and a new value set and an old value set in the message domain segment are identified, where the new value set includes n new values, and the old value set includes m old values; the new value is used for indicating that the value of the position where the new value is located in the current calculation is different from the value of the position calculated last time; the old value is used for indicating that the value of the position where the old value is located in the current calculation is the same as the value of the position calculated last time; n is a natural number, m is a natural number, an operation is performed according to a new value set to obtain a first calculation result, an operation is performed according to an old value set to obtain a second calculation result, a second message accumulation sum is determined according to the first message accumulation sum, the first calculation result and the second calculation result, an original message of the first message is obtained, a tunnel header is obtained according to the original message, a pseudo header is extracted from the tunnel header to obtain k parts of the pseudo header, k is a positive integer, a UDP checksum is determined according to the second message accumulation sum and k parts of the pseudo header, the UDP checksum is put into a UDP checksum field in the tunnel header, the whole packet accumulation sum calculation of the original message and the partial recalculation of the original message accumulation sum in the editing process are performed in advance in a message identification stage, and therefore saving of cache resources can be achieved in the tunnel encapsulation process, meanwhile, the uncertainty of communication delay and communication delay is reduced, namely under the condition of saving calculation resources, the UDP layer checksum calculation efficiency is improved.
Fig. 5 is a block diagram illustrating functional units of a tunnel encapsulation message checksum calculation apparatus 500 according to the present application. The tunnel encapsulation message checksum calculation apparatus 500 includes: an acquisition unit 501, an operation unit 502 and a determination unit 503, wherein,
the acquiring unit 501 is configured to acquire a first packet;
the operation unit 502 is configured to accumulate all bytes in the first packet to obtain a first packet accumulation sum;
the determining unit 503 is configured to determine a field segment of the first message and identify a new value set and an old value set in the field segment, where the new value set includes n new values and the old value set includes m old values in a message editing process; the new value is used for indicating that the value of the position where the new value is located in the current calculation is different from the value of the position calculated last time; the old value is used for indicating that the value of the position where the old value is located in the current calculation is the same as the value of the position calculated last time; n is a natural number, m is a natural number;
the operation unit is further used for performing operation according to the new value set to obtain a first calculation result; performing operation according to the old value set to obtain a second calculation result; determining a second message accumulation sum according to the first message accumulation sum, the first calculation result and the second calculation result;
The acquisition unit is further configured to acquire an original message of the first message, acquire a tunnel header according to the original message, and extract a pseudo header from the tunnel header to obtain k parts of the pseudo header, where k is a positive integer;
the determining unit is further configured to determine a UDP checksum according to the second packet accumulation sum and the k portions of the pseudo header, and place the UDP checksum into a UDP checksum field in the tunnel header.
Optionally, in the aspect of determining the UDP checksum according to the second packet accumulation sum and the k portions of the pseudo header, the determining unit 503 is specifically configured to:
accumulating k parts of the pseudo header to obtain a pseudo header accumulation sum;
summing the second message accumulation sum and the pseudo header accumulation sum to obtain a third calculation result;
and carrying out inverse operation on the third calculation result to obtain the UDP checksum.
Optionally, in the aspect of performing the operation according to the new value set to obtain a first calculation result, the operation unit 502 is specifically configured to:
and accumulating and operating the new value set to obtain the first calculation result.
Optionally, in the aspect of performing the operation according to the old value set to obtain a second calculation result, the operation unit 502 is specifically configured to:
Accumulating and operating the old value set to obtain the second calculation result;
in the aspect of determining a second packet accumulation sum according to the first packet accumulation sum, the first calculation result, and the second calculation result, the operation unit 502 is specifically configured to:
performing inverse operation on the second calculation result to obtain a target second calculation result;
and accumulating the first message accumulation sum, the first calculation result and the target second calculation result to obtain the second message accumulation sum.
Optionally, in the aspect of performing the operation according to the old value set to obtain a second calculation result, the operation unit 502 is specifically configured to:
performing accumulation and inversion operation on the old value set to obtain the second calculation result;
in the aspect of determining a second packet accumulation sum according to the first packet accumulation sum, the first calculation result, and the second calculation result, the operation unit 502 is specifically configured to:
and accumulating the first message accumulation sum, the first calculation result and the second calculation result to obtain the second message accumulation sum.
It can be seen that, in the tunnel encapsulation message checksum calculation method and device described in the present application, a first message is obtained, all bytes in the first message are accumulated to obtain a first message accumulation sum, in the process of editing a message, a message domain segment of the first message is determined, and a new value set and an old value set in the message domain segment are identified, wherein the new value set includes n new values, and the old value set includes m old values; the new value is used for indicating that the value of the position where the new value is located in the current calculation is different from the value of the position calculated last time; the old value is used for indicating that the value of the position where the old value is located in the current calculation is the same as the value of the position calculated last time; n is a natural number, m is a natural number, an operation is performed according to a new value set to obtain a first calculation result, an operation is performed according to an old value set to obtain a second calculation result, a second message accumulation sum is determined according to the first message accumulation sum, the first calculation result and the second calculation result, an original message of the first message is obtained, a tunnel header is obtained according to the original message, a pseudo header is extracted from the tunnel header to obtain k parts of the pseudo header, k is a positive integer, a UDP checksum is determined according to the second message accumulation sum and k parts of the pseudo header, the UDP checksum is put into a UDP checksum field in the tunnel header, the whole packet accumulation sum calculation of the original message and the partial recalculation of the original message accumulation sum in the editing process are performed in advance in a message identification stage, and therefore saving of cache resources can be achieved in the tunnel encapsulation process, meanwhile, the uncertainty of communication delay and communication delay is reduced, namely under the condition of saving calculation resources, the UDP layer checksum calculation efficiency is improved.
It may be understood that the functions of each program module of the tunnel encapsulation packet checksum calculation apparatus of the present embodiment may be specifically implemented according to the method in the foregoing method embodiment, and the specific implementation process may refer to the relevant description of the foregoing method embodiment, which is not repeated herein.
The present application also provides a computer storage medium storing a computer program for electronic data exchange, the computer program causing a computer to execute part or all of the steps of any one of the methods described in the above method embodiments, the computer including an electronic device.
The present application also provides a computer program product comprising a non-transitory computer readable storage medium storing a computer program operable to cause a computer to perform part or all of the steps of any one of the methods described in the method embodiments above. The computer program product may be a software installation package, said computer comprising an electronic device.
It should be noted that, for simplicity of description, the foregoing method embodiments are all described as a series of acts, but it should be understood by those skilled in the art that the present application is not limited by the order of acts described, as some steps may be performed in other orders or concurrently in accordance with the present application. Further, those skilled in the art will also appreciate that the embodiments described in the specification are all preferred embodiments, and that the acts and modules referred to are not necessarily required for the present application.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and for parts of one embodiment that are not described in detail, reference may be made to related descriptions of other embodiments.
In the several embodiments provided by the present application, it should be understood that the disclosed apparatus may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, such as the above-described division of units, merely a division of logic functions, and there may be additional manners of dividing in actual implementation, such as multiple units or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, or may be in electrical or other forms.
The units described above as separate components may or may not be physically separate, and components shown as units may or may not be physical units, may be located in one place, or may be distributed over a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units described above, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable memory. Based on such understanding, the technical solution of the present application may be embodied in essence or a part contributing to the prior art or all or part of the technical solution in the form of a software product stored in a memory, comprising several instructions for causing a computer device (which may be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the above-mentioned method of the various embodiments of the present application. And the aforementioned memory includes: a U-disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a removable hard disk, a magnetic disk, or an optical disk, or other various media capable of storing program codes.
Those of ordinary skill in the art will appreciate that all or a portion of the steps in the various methods of the above embodiments may be implemented by a program that instructs associated hardware, and the program may be stored in a computer readable memory, which may include: flash disk, read-Only Memory (ROM), random access Memory (Random Access Memory, RAM), magnetic disk or optical disk.
The foregoing has outlined rather broadly the more detailed description of the application in order that the detailed description of the principles and embodiments of the application may be implemented in conjunction with the detailed description of the application that follows, the examples being merely intended to facilitate an understanding of the method of the application and its core concepts; meanwhile, as those skilled in the art will have variations in the specific embodiments and application scope in accordance with the ideas of the present application, the present description should not be construed as limiting the present application in view of the above.

Claims (10)

1. The method for calculating the checksum of the tunnel encapsulation message is characterized by comprising the following steps:
acquiring a first message;
accumulating all bytes in the first message to obtain a first message accumulation sum;
in the process of editing the message, determining a message domain segment of the first message, and identifying a new value set and an old value set in the message domain segment, wherein the new value set comprises n new values, and the old value set comprises m old values; the new value is used for indicating that the value of the position where the new value is located in the current calculation is different from the value of the position calculated last time; the old value is used for indicating that the value of the position where the old value is located in the current calculation is the same as the value of the position calculated last time; n is a natural number, m is a natural number;
Performing operation according to the new value set to obtain a first calculation result;
performing operation according to the old value set to obtain a second calculation result;
determining a second message accumulation sum according to the first message accumulation sum, the first calculation result and the second calculation result;
acquiring an original message of the first message, acquiring a tunnel header according to the original message, and extracting a pseudo header from the tunnel header to obtain k parts of the pseudo header, wherein k is a positive integer;
and determining UDP checksum according to the second message accumulation sum and k parts of the pseudo header, and placing the UDP checksum into a UDP checksum field section in the tunnel header.
2. The method of claim 1, wherein said determining a UDP checksum from said second message accumulated sum and k portions of said pseudo header comprises:
accumulating k parts of the pseudo header to obtain a pseudo header accumulation sum;
summing the second message accumulation sum and the pseudo header accumulation sum to obtain a third calculation result;
and carrying out inverse operation on the third calculation result to obtain the UDP checksum.
3. The method according to claim 1 or 2, wherein said performing an operation according to said new value set, to obtain a first calculation result, comprises:
And accumulating and operating the new value set to obtain the first calculation result.
4. The method according to claim 1 or 2, wherein said performing an operation according to said old value set to obtain a second calculation result comprises:
accumulating and operating the old value set to obtain the second calculation result;
the determining a second message accumulation sum according to the first message accumulation sum, the first calculation result and the second calculation result includes:
performing inverse operation on the second calculation result to obtain a target second calculation result;
and accumulating the first message accumulation sum, the first calculation result and the target second calculation result to obtain the second message accumulation sum.
5. The method according to claim 1 or 2, wherein said performing an operation according to said old value set to obtain a second calculation result comprises:
performing accumulation and inversion operation on the old value set to obtain the second calculation result;
the determining a second message accumulation sum according to the first message accumulation sum, the first calculation result and the second calculation result includes:
and accumulating the first message accumulation sum, the first calculation result and the second calculation result to obtain the second message accumulation sum.
6. A tunnel encapsulation message checksum calculation apparatus, the apparatus comprising: an acquisition unit, an operation unit and a determination unit, wherein,
the acquisition unit is used for acquiring a first message;
the operation unit is used for accumulating all bytes in the first message to obtain a first message accumulation sum;
the determining unit is configured to determine a message field of the first message and identify a new value set and an old value set in the message field in a message editing process, where the new value set includes n new values and the old value set includes m old values; the new value is used for indicating that the value of the position where the new value is located in the current calculation is different from the value of the position calculated last time; the old value is used for indicating that the value of the position where the old value is located in the current calculation is the same as the value of the position calculated last time; n is a natural number, m is a natural number;
the operation unit is further used for performing operation according to the new value set to obtain a first calculation result; performing operation according to the old value set to obtain a second calculation result; determining a second message accumulation sum according to the first message accumulation sum, the first calculation result and the second calculation result;
The acquisition unit is further configured to acquire an original message of the first message, acquire a tunnel header according to the original message, and extract a pseudo header from the tunnel header to obtain k parts of the pseudo header, where k is a positive integer;
the determining unit is further configured to determine a UDP checksum according to the second packet accumulation sum and the k portions of the pseudo header, and place the UDP checksum into a UDP checksum field in the tunnel header.
7. The apparatus according to claim 6, wherein said determining unit is configured to, in said determining a UDP checksum based on said second message accumulation sum and k portions of said pseudo header:
accumulating k parts of the pseudo header to obtain a pseudo header accumulation sum;
summing the second message accumulation sum and the pseudo header accumulation sum to obtain a third calculation result;
and carrying out inverse operation on the third calculation result to obtain the UDP checksum.
8. The apparatus according to claim 6 or 7, wherein, in terms of said calculating according to said new value set, obtaining a first calculation result, said calculating unit is specifically configured to:
and accumulating and operating the new value set to obtain the first calculation result.
9. An electronic device comprising a processor, a memory for storing one or more programs and configured to be executed by the processor, the programs comprising instructions for performing the steps in the method of any of claims 1-5.
10. A computer-readable storage medium, characterized in that a computer program for electronic data exchange is stored, wherein the computer program causes a computer to perform the method according to any one of claims 1-5.
CN202310691741.8A 2023-06-13 2023-06-13 Tunnel encapsulation message checksum calculation method and related device Active CN116455991B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310691741.8A CN116455991B (en) 2023-06-13 2023-06-13 Tunnel encapsulation message checksum calculation method and related device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310691741.8A CN116455991B (en) 2023-06-13 2023-06-13 Tunnel encapsulation message checksum calculation method and related device

Publications (2)

Publication Number Publication Date
CN116455991A CN116455991A (en) 2023-07-18
CN116455991B true CN116455991B (en) 2023-08-22

Family

ID=87130518

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310691741.8A Active CN116455991B (en) 2023-06-13 2023-06-13 Tunnel encapsulation message checksum calculation method and related device

Country Status (1)

Country Link
CN (1) CN116455991B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117714233B (en) * 2024-02-04 2024-04-19 珠海星云智联科技有限公司 Method, computer equipment and medium for tunnel message encapsulation

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102447552A (en) * 2011-11-08 2012-05-09 盛科网络(苏州)有限公司 Method and system for realizing checksum updating of 1588UDP (User Datagram Protocol) packet in multiple MAC (Media Access Control)
WO2016086670A1 (en) * 2014-12-04 2016-06-09 中兴通讯股份有限公司 Vxlan packet transmission method and apparatus, and storage medium
CN108599907A (en) * 2018-03-30 2018-09-28 上海兆芯集成电路有限公司 Network interface controller
CN110852391A (en) * 2019-11-13 2020-02-28 中国人民解放军91977部队 Ethernet message classification method and device based on multiple classifiers
WO2022152231A1 (en) * 2021-01-15 2022-07-21 华为技术有限公司 Network configuration rule processing method and related device
CN115037814A (en) * 2022-08-13 2022-09-09 湖北微源卓越科技有限公司 TCP/UDP checksum determination method based on FPGA hardware acceleration

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9281990B2 (en) * 2012-02-17 2016-03-08 Viavi Solutions Inc. Ethernet UDP checksum compensation

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102447552A (en) * 2011-11-08 2012-05-09 盛科网络(苏州)有限公司 Method and system for realizing checksum updating of 1588UDP (User Datagram Protocol) packet in multiple MAC (Media Access Control)
WO2016086670A1 (en) * 2014-12-04 2016-06-09 中兴通讯股份有限公司 Vxlan packet transmission method and apparatus, and storage medium
CN108599907A (en) * 2018-03-30 2018-09-28 上海兆芯集成电路有限公司 Network interface controller
CN110852391A (en) * 2019-11-13 2020-02-28 中国人民解放军91977部队 Ethernet message classification method and device based on multiple classifiers
WO2022152231A1 (en) * 2021-01-15 2022-07-21 华为技术有限公司 Network configuration rule processing method and related device
CN115037814A (en) * 2022-08-13 2022-09-09 湖北微源卓越科技有限公司 TCP/UDP checksum determination method based on FPGA hardware acceleration

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
报文检测与发送相关算法设计;王旸;信息技术;全文 *

Also Published As

Publication number Publication date
CN116455991A (en) 2023-07-18

Similar Documents

Publication Publication Date Title
CN116455991B (en) Tunnel encapsulation message checksum calculation method and related device
CN110708393A (en) Method, device and system for transmitting data
US20210160353A1 (en) Data sending method and device, data receiving method and device, and system
CN104022922B (en) Mobile terminal, heartbeat forwarding server and heartbeat message sending method and system
CN108449409B (en) Animation pushing method, device, equipment and storage medium
CN111970353A (en) Data processing method and device for heterogeneous equipment in Internet of things of cloud computing platform
CN103188042B (en) A kind of matching process of IP packet and coupling accelerator
CN104348680A (en) Method and device for detecting network speed
CN110740481A (en) Data processing method, apparatus and computer storage medium based on quality of service
CN111294235A (en) Data processing method, device, gateway and readable storage medium
CN114157607A (en) Media stream transmission method and system
CN115484322A (en) Data packet decapsulation and uninstallation method and device, electronic device and storage medium
CN110858790B (en) Data packet transmission method and device, storage medium and electronic device
CN104717257A (en) Method and device for transmitting data messages
CN107483369B (en) Message processing method and virtual switch
US20230106217A1 (en) Web-end video playing method and apparatus, and computer device
CN115277553B (en) Stream table storage method, device, equipment and computer readable storage medium
CN116055762A (en) Video synthesis method and device, electronic equipment and storage medium
CN113890897B (en) Message processing method and related device
CN113204683B (en) Information reconstruction method and device, storage medium and electronic equipment
KR20200088409A (en) Synchronization method and device
CN108170493A (en) A kind of loading method of system module, system and device
CN108200604A (en) Data transmission method and device
CN111277449B (en) Safety testing method and device for voice service equipment
CN113872886B (en) Message encapsulation method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant