Data processing method and device, equipment and storage medium
By processing TCP packets at the hardware level using an FPGA system, the problem of CPU resource exhaustion was solved, and the stable operation of the business system and the reliability of data transmission were achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 深圳华云信息系统科技股份有限公司
- Filing Date
- 2026-03-09
- Publication Date
- 2026-05-08
AI Technical Summary
In scenarios with massive network traffic, CPU computing resources are exhausted by the TCP packet parsing and processing process, leading to instability in the business system.
By implementing data processing logic at the hardware level through an FPGA system, some CPU software processing work can be replaced. The orderly reading and storage of TCP packets can be performed using the packet storage area and isolated table entries, reducing the CPU processing pressure.
This reduces the CPU's processing load, ensures the stable operation of the business system, and improves the reliability and efficiency of data transmission.
Smart Images

Figure CN121814867B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a data processing method, apparatus, device, and storage medium. Background Technology
[0002] As a connection-oriented reliable transmission protocol, TCP is the core foundational protocol for network data interaction. During data transmission, TCP abnormal message scenarios such as out-of-order messages and message loss inevitably occur. Identifying and orderly restoring TCP abnormal messages is a key step in ensuring reliable network data transmission.
[0003] Currently, all received packets, including normal and ordered TCP packets as well as out-of-order, missing, or other abnormal TCP packets, are uniformly submitted to the operating system kernel protocol stack. Subsequent processing steps, such as TCP packet parsing, packet sequence number status tracking, sorting and restoring out-of-order packets, and waiting for matching of missing packets, are all completed by software programs running on the CPU.
[0004] Each TCP packet processed by the software program requires a CPU computation cycle. In scenarios with massive network traffic, the CPU's computing resources can easily be exhausted by the parsing and processing of TCP packets, resulting in excessive CPU processing pressure and instability of the entire business system. Summary of the Invention
[0005] This application provides a data processing method, apparatus, device, and storage medium capable of data processing.
[0006] In a first aspect, this application provides a data processing method applied to an FPGA system, comprising:
[0007] In the storage area of the first packet corresponding to the target TCP, obtain the current position to be read;
[0008] Detect whether a TCP packet has been read at the current location;
[0009] When a TCP packet is read at the current position, the next position of the current position is updated to the current position to be read;
[0010] If no TCP packet is read at the current position, the target first byte sequence number corresponding to the current position is determined based on the first byte sequence number of the previously successfully read TCP packet. In the second packet storage area corresponding to the target TCP, the existence of the target TCP packet is checked based on the target first byte sequence number. If the target TCP packet exists, it is read as the TCP packet to be read at the current position, and the current position to be read is updated. If the target TCP packet does not exist, the reading process is paused until the TCP packet corresponding to the current position is detected and the reading is completed, and then the next position of the current position is updated to the current position to be read.
[0011] Based on the updated current position to be read, the detection steps are re-executed.
[0012] Optionally, detecting whether a target TCP packet exists in the second packet storage area corresponding to the target TCP packet based on the target first byte sequence number includes:
[0013] Detect whether the island entry corresponding to the target TCP exists in the target table, wherein the starting byte sequence number of the target entry is the target first byte sequence number or the corresponding sequence number range covers the target first byte sequence number;
[0014] When the target entry exists in the island entry, it is determined that the target TCP packet exists in the second packet storage area;
[0015] When the target entry does not exist in the island entry, it is determined that the target TCP packet does not exist in the second packet storage area.
[0016] Optionally, when the end-of-byte sequence number corresponding to the target entry is inconsistent with the end-of-byte sequence number corresponding to the target TCP packet, after reading the target TCP packet as the TCP packet to be read at the current position, the method further includes:
[0017] Based on the starting byte sequence number and ending byte sequence number corresponding to the target entry, and the fixed byte length corresponding to the TCP packet, it is determined that at least one TCP packet's starting byte sequence number can be read after reading the target TCP packet.
[0018] At least one TCP packet is read sequentially in the second packet storage area according to the sequence of first byte numbers.
[0019] Optionally, updating the current position to be read includes:
[0020] Determine the target number of TCP packets that can be read consecutively in the second packet storage area based on the first byte sequence number;
[0021] Based on the current position and the target number, determine the target position corresponding to the last TCP packet read, and determine the next position of the target position as the current position.
[0022] Optionally, when the end-of-byte sequence number corresponding to the target entry is the end-of-byte sequence number of the target TCP packet, updating the current position to be read includes:
[0023] In the first message storage area, determine the next position of the current position and update the next position to the current position to be read.
[0024] Optionally, the method further includes:
[0025] Receive a TCP packet transmitted through the target TCP connection, the TCP packet including the current first byte sequence number;
[0026] When the current first byte sequence number and the target first byte sequence number meet a preset relationship, the TCP packet is stored based on the first packet storage area;
[0027] When the current first byte sequence number and the target first byte sequence number do not conform to a preset relationship, the TCP packet is stored based on the second packet storage area.
[0028] Optionally, the method further includes:
[0029] Obtain the storage capacity corresponding to the first message storage area;
[0030] The sequence number difference is determined based on the current first byte sequence number and the target first byte sequence number;
[0031] When the difference is less than the storage capacity, it is determined that the current first byte sequence number and the target first byte sequence number conform to a preset relationship;
[0032] When the difference is greater than or equal to the storage capacity, it is determined that the current first byte sequence number and the target first byte sequence number do not conform to a preset relationship.
[0033] Optionally, the method further includes:
[0034] When the remaining capacity of the first message storage area is greater than the first capacity threshold and the remaining capacity of the second message storage area is less than the second capacity threshold, a shared storage area is selected in the first message storage area, and the received TCP messages are stored in the shared storage area. The shared storage area is a storage area shared by the first message storage area and the second message storage area.
[0035] Optionally, storing the TCP packets based on the first packet storage area includes:
[0036] The storage location of the TCP packet is detected based on the sequence number of the first byte corresponding to the TCP packet, indicating whether it is within the shared storage area.
[0037] When the storage location of the TCP packet is not in the shared storage area, or when the storage location of the TCP packet is in the shared storage area but there is no stored TCP packet at the storage location, the TCP packet is stored in the storage location.
[0038] When the storage location of the TCP packet is within the shared storage area and there are already stored TCP packets at the storage location, the TCP packets stored at the storage location are transferred to other locations within the shared storage area, and the TCP packets are stored at the storage location.
[0039] Optionally, storing the TCP packets based on the second packet storage area includes:
[0040] Within the shared storage area, determine the last free storage location, and store the TCP packet based on the last storage location.
[0041] Optionally, the method further includes:
[0042] When the remaining capacity of the second message storage area is greater than the third capacity threshold, a TCP message to be transferred is determined in the shared storage area, the TCP message to be transferred is transferred to the second message storage area, and the shared storage area is restored to the first message storage area.
[0043] Optionally, selecting a shared storage area in the first message storage area includes:
[0044] In the first message storage area, a storage area of a preset length prior to the current position is determined; the storage area of the preset length is determined as a shared storage area.
[0045] Optionally, before a TCP packet is read at the current location, the method further includes:
[0046] Based on the sequence number of the first byte of the previously successfully read TCP packet, determine the theoretical sequence number of the first byte of the TCP packet to be read;
[0047] When the theoretical first byte sequence number is equal to the actual first byte sequence number corresponding to the TCP packet read at the current position, the TCP packet stored at the current position is read.
[0048] Optionally, the method further includes:
[0049] When there is a first island entry and a second island entry in the islanded entry, the first island entry and the second island entry are merged to obtain a merged entry. The starting byte number corresponding to the first island entry is determined as the starting byte number corresponding to the merged entry, and the ending byte number corresponding to the second island entry is determined as the ending byte number corresponding to the merged entry. The ending byte number corresponding to the first island entry and the starting byte number corresponding to the second island entry are the same.
[0050] Optionally, the method further includes:
[0051] Detect whether the current position to be read is the last storage position in the first message storage area;
[0052] If the current position is the last storage position of the first message storage area, then the first storage position of the first message storage area is determined as the next position of the current position and updated to the new current position to be read.
[0053] Secondly, this application provides a data processing apparatus, the apparatus comprising:
[0054] The acquisition unit is used to acquire the current position to be read in the first packet storage area corresponding to the target TCP;
[0055] The first detection unit is used to detect whether a TCP packet is read at the current location;
[0056] An update unit is used to update the next position of the current position to the current position to be read when a TCP packet is read at the current position;
[0057] The processing unit is configured to, when no TCP packet is read at the current position, determine the target first byte sequence number corresponding to the current position based on the first byte sequence number of the previously successfully read TCP packet, and check whether a target TCP packet exists in the second packet storage area corresponding to the target TCP packet based on the target first byte sequence number; if the target TCP packet exists, the target TCP packet is read as the TCP packet to be read at the current position, and the current position to be read is updated; if the target TCP packet does not exist, the reading process is paused until the TCP packet corresponding to the current position is detected and the reading is completed, and then the next position of the current position is updated to the current position to be read.
[0058] The execution unit is used to re-execute the detection steps based on the updated current position to be read.
[0059] Optionally, the processing unit is used for:
[0060] Detect whether the island entry corresponding to the target TCP exists in the target table, and the starting byte sequence number of the target entry is the target first byte sequence number;
[0061] When the target entry exists in the island entry, it is determined that the target TCP packet exists in the second packet storage area;
[0062] When the target entry does not exist in the island entry, it is determined that the target TCP packet does not exist in the second packet storage area.
[0063] Optionally, when the end-of-time byte sequence number corresponding to the target entry is inconsistent with the end-of-time byte sequence number corresponding to the target TCP packet, after reading the target TCP packet as the TCP packet to be read at the current position, the device further includes a data reading unit, the data reading unit being used for:
[0064] Based on the starting byte sequence number and ending byte sequence number corresponding to the target entry and the fixed byte length corresponding to the TCP packet, it is determined that after reading the target TCP packet, at least one TCP packet's corresponding starting byte sequence number can be read.
[0065] At least one TCP packet is read sequentially in the second packet storage area according to the sequence of first byte numbers.
[0066] Optional, processing unit, used for:
[0067] Determine the target number of TCP packets that can be read consecutively in the second packet storage area based on the first byte sequence number;
[0068] Based on the current position and the target number, determine the target position corresponding to the last TCP packet read, and determine the next position of the target position as the current position.
[0069] Optionally, when the end-of-byte sequence number corresponding to the target entry is the end-of-byte sequence number of the target TCP packet, the processing unit is configured to:
[0070] In the first message storage area, determine the next position of the current position and update the next position to the current position to be read.
[0071] Optionally, the device further includes a receiving unit, the receiving unit being configured to:
[0072] Receive a TCP packet transmitted through the target TCP connection, the TCP packet including the current first byte sequence number;
[0073] When the current first byte sequence number and the target first byte sequence number meet a preset relationship, the TCP packet is stored based on the first packet storage area;
[0074] When the current first byte sequence number and the target first byte sequence number do not conform to a preset relationship, the TCP packet is stored based on the second packet storage area.
[0075] Optionally, the apparatus further includes a determining unit, the determining unit being configured to:
[0076] Obtain the storage capacity corresponding to the first message storage area;
[0077] The sequence number difference is determined based on the current first byte sequence number and the target first byte sequence number;
[0078] When the difference is less than the storage capacity, it is determined that the current first byte sequence number and the target first byte sequence number conform to a preset relationship;
[0079] When the difference is greater than or equal to the storage capacity, it is determined that the current first byte sequence number and the target first byte sequence number do not conform to a preset relationship.
[0080] Optionally, the device further includes a selection unit, the selection unit being configured to:
[0081] When the remaining capacity of the first message storage area is greater than the first capacity threshold and the remaining capacity of the second message storage area is less than the second capacity threshold, a shared storage area is selected in the first message storage area, and the received TCP messages are stored in the shared storage area. The shared storage area is a storage area shared by the first message storage area and the second message storage area.
[0082] Optionally, the selection unit is used for:
[0083] The storage location of the TCP packet is detected based on the sequence number of the first byte corresponding to the TCP packet, indicating whether it is within the shared storage area.
[0084] When the storage location of the TCP packet is not in the shared storage area, or when the storage location of the TCP packet is in the shared storage area but there is no stored TCP packet at the storage location, the TCP packet is stored in the storage location.
[0085] When the storage location of the TCP packet is within the shared storage area and there are already stored TCP packets at the storage location, the TCP packets stored at the storage location are transferred to other locations within the shared storage area, and the TCP packets are stored at the storage location.
[0086] Optionally, the receiving unit is used for:
[0087] Within the shared storage area, determine the last free storage location, and store the TCP packet based on the last storage location.
[0088] Optionally, the device further includes a recovery unit, the recovery unit being configured to:
[0089] When the remaining capacity of the second message storage area is greater than the third capacity threshold, a TCP message to be transferred is determined in the shared storage area, the TCP message to be transferred is transferred to the second message storage area, and the shared storage area is restored to the first message storage area.
[0090] Optionally, the selection unit is used for:
[0091] In the first message storage area, a storage area of a preset length prior to the current position is determined; the storage area of the preset length is determined as a shared storage area.
[0092] Optionally, before a TCP packet is read at the current location, the apparatus further includes a reading unit, the reading unit being configured to:
[0093] Based on the sequence number of the first byte of the previously successfully read TCP packet, determine the theoretical sequence number of the first byte of the TCP packet to be read;
[0094] When the theoretical first byte sequence number is equal to the actual first byte sequence number corresponding to the TCP packet read at the current position, the TCP packet stored at the current position is read.
[0095] Optionally, the apparatus further includes a merging unit, the merging unit being configured to:
[0096] When there is a first island entry and a second island entry in the islanded entry, the first island entry and the second island entry are merged to obtain a merged entry. The starting byte number corresponding to the first island entry is determined as the starting byte number corresponding to the merged entry, and the ending byte number corresponding to the second island entry is determined as the ending byte number corresponding to the merged entry. The ending byte number corresponding to the first island entry and the starting byte number corresponding to the second island entry are the same.
[0097] Optionally, the device further includes a second detection unit, the second detection unit being used for:
[0098] Detect whether the current position to be read is the last storage position in the first message storage area;
[0099] If the current position is the last storage position of the first message storage area, then the first storage position of the first message storage area is determined as the next position of the current position and updated to the new current position to be read.
[0100] Thirdly, this application provides a data processing device, comprising: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; and at least one memory connected to the at least one bus, wherein the processor is configured to:
[0101] In the storage area of the first packet corresponding to the target TCP, obtain the current position to be read;
[0102] Detect whether a TCP packet has been read at the current location;
[0103] When a TCP packet is read at the current position, the next position of the current position is updated to the current position to be read;
[0104] If no TCP packet is read at the current position, the target first byte sequence number corresponding to the current position is determined based on the first byte sequence number of the previously successfully read TCP packet. In the second packet storage area corresponding to the target TCP, the existence of the target TCP packet is checked based on the target first byte sequence number. If the target TCP packet exists, it is read as the TCP packet to be read at the current position, and the current position to be read is updated. If the target TCP packet does not exist, the reading process is paused until the TCP packet corresponding to the current position is detected and the reading is completed, and then the next position of the current position is updated to the current position to be read.
[0105] Based on the updated current position to be read, the detection steps are re-executed.
[0106] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described data processing method.
[0107] Compared with the prior art, the technical solution provided in this application has the following advantages: In this application embodiment, in the first message storage area corresponding to the target TCP, the current position to be read is obtained, and the first message storage area stores ordered TCP messages received through the target TCP; it is detected whether a TCP message is read at the current position; when a TCP message is read at the current position, the next position of the current position is updated to the current position to be read; when no TCP message is read at the current position, the target first byte sequence number corresponding to the current position is determined according to the first byte sequence number corresponding to the previously successfully read TCP message, and in the second message storage area corresponding to the target TCP, it is detected whether a target TCP message exists according to the target first byte sequence number; if the target TCP message exists, the target TCP message is read as the TCP message to be read at the current position, and the current position to be read is updated; if the target TCP message does not exist, the reading process is paused until the TCP message corresponding to the current position is detected and the reading is completed, and then the next position of the current position is updated to the current position to be read; based on the updated current position to be read, the detection step is re-executed. This method replaces some of the CPU's software processing work with independent processing logic at the hardware level, reducing the CPU's processing pressure and ensuring the stable operation of the entire business system. Attached Figure Description
[0108] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0109] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0110] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.
[0111] Figure 1 A flowchart illustrating a data processing method provided in an embodiment of this application;
[0112] Figure 2 This is a schematic flowchart of a data processing apparatus provided in an embodiment of this application;
[0113] Figure 3 This is a schematic diagram of a data processing device provided in an embodiment of this application. Detailed Implementation
[0114] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0115] The following disclosure provides numerous different embodiments or examples for implementing various structures of the invention. To simplify the disclosure, specific examples of components and arrangements are described below. These are merely examples and are not intended to limit the scope of the invention. Furthermore, reference numerals and / or letters may be repeated in different examples. Such repetition is for simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or arrangements discussed.
[0116] As a connection-oriented reliable transmission protocol, TCP is the core foundational protocol for network data interaction. During data transmission, TCP abnormal message scenarios such as out-of-order messages and message loss inevitably occur. Identifying and orderly restoring TCP abnormal messages is a key step in ensuring reliable network data transmission.
[0117] Currently, all received packets, including normal and ordered TCP packets as well as out-of-order, missing, or other abnormal TCP packets, are uniformly submitted to the operating system kernel protocol stack. Subsequent processing steps, such as TCP packet parsing, packet sequence number status tracking, sorting and restoring out-of-order packets, and waiting for matching of missing packets, are all completed by software programs running on the CPU.
[0118] Each TCP packet processed by the software program requires a CPU computation cycle. In scenarios with massive network traffic, the CPU's computing resources can easily be exhausted by the parsing and processing of TCP packets, resulting in excessive CPU processing pressure and instability of the entire business system.
[0119] To address the aforementioned problems, embodiments of this application provide a data processing method. This method can replace some of the CPU's software processing work through independent processing logic at the hardware level, reducing the CPU's processing load and ensuring the stable operation of the entire business system. Figure 1 As shown, the specific steps include:
[0120] Step 101: Obtain the current position to be read in the first packet storage area corresponding to the target TCP.
[0121] The target TCP connection refers to the currently established and used TCP connection. The corresponding first packet storage area is specifically designed to store TCP packets transmitted through this target TCP connection and deemed normal by the system. All TCP packets in this area originate from this target TCP connection. Furthermore, the first packet storage area employs a one-to-one correspondence between location and packet; that is, each storage location within the area stores only one TCP packet. The current location is the specific storage location marked within this storage area corresponding to the TCP packet to be read.
[0122] In this step, the FPGA system performs data writing operations, which involve writing TCP packets to the storage area. In practice, since the TCP packets received by the FPGA system are not received in order, these TCP packets that are unlikely to overwrite unread TCP packets are written to the first packet storage area. Furthermore, to facilitate reading consecutive TCP packets, the positions corresponding to the first byte of each TCP packet are assigned to a specific position. TCP packets that might overwrite unread TCP packets are written to the second packet storage area. Simultaneously, the FPGA system also performs data reading operations, which read data sequentially and perform subsequent operations on this data. TCP packets are read sequentially in the first packet storage area. As soon as a TCP packet is read at a certain position, the process continues to read TCP packets at the next position. If no TCP packet is read at a certain position, the process first checks whether the required TCP packet is not stored in the second packet storage area. If so, the required TCP packet is read in the second packet storage area, and the process continues to read TCP packets at the next position. If no TCP packet is read, it means that the TCP packet has not been received yet, and the reading process is paused until the required TCP packet is received, and then the process continues to read TCP packets at the next position.
[0123] It should be noted that before writing TCP packets sequentially into the first packet storage area, the FPGA receives the raw network data stream from the network interface in real time, strips the Ethernet frame header, and identifies the IP packets. Further parsing of the IP header reveals that if the protocol type is TCP, the process proceeds to the TCP packet parsing unit. This unit extracts multiple key fields of the TCP packet in parallel, including but not limited to: source / destination port number, sequence number, acknowledgment number, data offset, reserved bits, all control flags (URG, ACK, PSH, RST, SYN, FIN), window size, checksum, and optional options.
[0124] The current input message status is checked based on the sequence number of the first byte in the TCP protocol to determine if the message is out of order, a retransmitted message, a partially retransmitted message, a duplicate message, and whether there are any abnormalities in the control flags. Based on this determination, the current message is stored in an appropriate location in memory, and its storage address in RAM is recorded. This application calculates the starting address of RAM storage based on the message's sequence number, since the RAM is designed with a 4-byte width. The application then calculates which byte to store the message from based on the sequence number. As RAM is continuously written to, the RAM readable address is updated. Sorted messages are output, while unsorted messages are stored in RAM until sorting is complete. After sorting, the readable address is updated, and these unsorted messages are read out.
[0125] Taking a 32KB RAM storage area as an example (this can be applied to different capacities or different memory types), the method for writing TCP packets sequentially into the first packet storage area is as follows: The starting address of the packet stored in RAM is: start_seq%32k / 4; the ending address of the packet stored in RAM is: (next_seq-1)%32k / 4; the start address write enable calculation is: start_seq%32k%4 (0 is 4'b1111; 1 is 4'b1110; 2 is 4'b1100; 3 is 4'b1000); the ending address write enable calculation is: (next_seq-1)%32k%4 (0 is 4'b1111; 1 is 4'b0001; 2 is 4'b0011; 3 is 4'b0111). Using the above method, the address of the packet stored in RAM can be calculated. Due to this storage method, packets with adjacent first byte sequence numbers are also adjacent in position. Where start_seq is the sequence number of the first byte of the TCP segment, and next_seq is the sequence number of the first byte of the next TCP segment.
[0126] Step 102: Check whether a TCP packet has been read at the current location.
[0127] In this step, if a TCP packet is stored at the current location, it will be read at the current location; otherwise, it will not be read at the current location.
[0128] Step 103: When a TCP packet is read at the current position, update the next position of the current position to the current position to be read.
[0129] In this step, when a TCP packet is read at the current position, the next position can be read, which means updating the next position to the current position to be read.
[0130] Step 104: When no TCP packet is read at the current position, determine the target first byte sequence number corresponding to the current position based on the first byte sequence number of the previously successfully read TCP packet. In the second packet storage area corresponding to the target TCP, check whether the target TCP packet exists based on the target first byte sequence number. If the target TCP packet exists, read it as the TCP packet to be read at the current position and update the current position to be read. If the target TCP packet does not exist, pause the reading process until the TCP packet corresponding to the current position is detected and the reading is completed, and then update the next position of the current position to the current position to be read.
[0131] The previously successfully read TCP packet could be a TCP packet successfully read from the previous position in the first packet storage area, or it could be a TCP packet successfully read from the second packet storage area.
[0132] In this step, whenever a TCP segment is successfully read, its corresponding first byte sequence number is recorded. If no TCP segment is read at the current position, the first byte sequence number of the previously successfully read TCP segment is obtained. This first byte sequence number is then added to the fixed-length TCP segment to obtain the last byte sequence number of the previously successfully read TCP segment. For example: the TCP segment's start_seq (first byte sequence number) = sequence number; the TCP segment's last byte sequence number = the TCP segment's next_seq (first byte sequence number of the next segment) = sequence number + length; where length is the fixed-length TCP segment.
[0133] After obtaining the tail byte sequence number of the previously successfully read TCP packet, this tail byte sequence number becomes the target first byte sequence number for the current position. Next, the system checks the second packet storage area corresponding to the target TCP packet to see if a target TCP packet with the corresponding target first byte sequence number exists. If it exists, it means that the TCP packet was received a long time ago. To avoid overwriting useful data in the first packet storage area, it was stored in the second packet storage area. Therefore, the target TCP packet can be read directly from the second packet storage area, and then the system can continue reading data from the next position. If it does not exist, it means that the target TCP packet has not been received yet. The reading process is paused until the TCP packet corresponding to the current position is detected and read, then the system continues reading data from the next position.
[0134] It should be noted that before detecting and reading the TCP packet corresponding to the current position, the FPGA system will wait to receive the TCP packet corresponding to the current position, i.e., the target TCP packet. When the FPGA system receives the target TCP packet, it stores it in the current position and then reads the TCP packet corresponding to the current position.
[0135] In addition, an FPGA system is a dedicated processing system implemented based on FPGA hardware circuits. Unlike the flexible calling logic of software, the hard logic processing of FPGA has strict timing and storage access rules. Therefore, in the process of TCP packet processing, the received TCP packets must first be written into the preset packet storage area (such as on-chip RAM or registers), and then the packet data must be retrieved from the storage area according to the established reading rules to ensure the stable operation of the hardware logic and the accuracy of data processing.
[0136] During the location reading process, it is also necessary to determine in real time whether the current location is the last location of the first message storage area. When the current location is the last location of the first message storage area, the first location of the first message storage area is determined as the next location of the current location.
[0137] Step 105: Based on the updated current position to be read, re-execute the detection steps.
[0138] In this embodiment, to fundamentally ensure the continuous and complete sequence number of the output data and avoid data parsing errors caused by sequence number breaks or misalignments, a sequence number consistency verification step is added before reading the TCP packet to be read. The specific verification process is as follows: extract the actual first byte sequence number carried in the TCP packet to be read; retrieve the first byte sequence number corresponding to the previously successfully read TCP packet, and combine it with the fixed byte length of a single TCP packet to obtain the theoretical first byte sequence number that the current packet to be read should possess through hardware logic operations; compare the calculated theoretical first byte sequence number with the actual first byte sequence number of the packet to be read, and only when the two match completely will the reading and output process of the TCP packet to be read be triggered. Through this sequence number verification mechanism, packets with misaligned sequence numbers caused by table entry matching errors, storage address offsets, etc., can be effectively filtered, further ensuring the orderliness and integrity of the output TCP byte stream.
[0139] In this embodiment, in the first message storage area corresponding to the target TCP, the current position to be read is obtained. The first message storage area stores ordered TCP messages received through the target TCP. It is detected whether a TCP message is read at the current position. When a TCP message is read at the current position, the next position of the current position is updated to the current position to be read. When no TCP message is read at the current position, the target first byte sequence number corresponding to the current position is determined based on the first byte sequence number of the previously successfully read TCP message. In the second message storage area corresponding to the target TCP, it is detected whether a target TCP message exists based on the target first byte sequence number. If the target TCP message exists, it is read as the TCP message to be read at the current position, and the current position to be read is updated. If the target TCP message does not exist, the reading process is paused until a TCP message corresponding to the current position is detected and read, then the next position of the current position is updated to the current position to be read. Based on the updated current position to be read, the detection step is re-executed. This method replaces some of the CPU's software processing work with independent processing logic at the hardware level, reducing the CPU's processing pressure and ensuring the stable operation of the entire business system.
[0140] In this embodiment, directly searching based on the target's first byte sequence number within the second message storage area often consumes a large amount of FPGA on-chip resources. Therefore, before storing the TCP message in the second message storage area, the first byte sequence number corresponding to the TCP message is also stored in an isolated entry. This way, after obtaining the target's first byte sequence number at the current position, the first byte sequence number stored in the isolated entry is matched and compared with the target's first byte sequence number to determine whether a corresponding target TCP message exists in the second message storage area, avoiding the resource consumption caused by directly performing a full search of the second message storage area. Therefore, this embodiment provides a data detection method, specifically including: detecting whether a target entry exists in the isolated entry corresponding to the target TCP; when a target entry exists in the isolated entry, determining that a target TCP message exists in the second message storage area; when a target entry does not exist in the isolated entry, determining that a target TCP message does not exist in the second message storage area.
[0141] The isolated entry stores the sequence number of the first byte of the TCP packet stored in the corresponding second packet storage area. The starting sequence number of the target entry is the target first byte sequence number or the corresponding sequence number range covers the target first byte sequence number. This sequence number range is composed of the starting sequence number and the ending sequence number.
[0142] In this step, the first byte sequence number of the island entry corresponding to the target TCP is compared with the first byte sequence number of the target. If they match, the island entry corresponding to the matched first byte sequence number is identified as the target entry, confirming that the target TCP packet exists in the second packet storage area. If they do not match at all, it means that the target entry does not exist in the island entries, confirming that the target TCP packet does not exist in the second packet storage area.
[0143] In this embodiment, the target entry stores not only the start byte sequence number of the TCP packet but also the corresponding end byte sequence number. The end byte sequence number is generated in two ways: the first is for a single TCP packet, where the end byte sequence number equals the start byte sequence number of the packet plus the fixed byte length of the single TCP packet; the second is for multiple consecutively stored TCP packets, where the end byte sequence number equals the start byte sequence number plus the total number of bytes in these TCP packets.
[0144] It should be noted that the second scenario mentioned above occurs because, in actual processing, when the end byte number of one entry is detected to be equal to the start byte number of another entry, the two entries will be merged into one entry to save on-chip resources of the FPGA.
[0145] When the end-of-byte sequence number is generated in the first manner, it means that only one TCP packet needs to be read in the second packet storage area. Therefore, after reading the target TCP packet, the next position of the current position can be determined directly in the first packet storage area, and the next position can be updated to the current position to be read.
[0146] When the end-of-byte sequence number is generated using the second method, it can be determined that the target entry corresponds to a set of consecutive TCP packets in the second packet storage area. At this point, there is no need to perform multiple searches in the second packet storage area. Only the start-of-byte sequence number, the end-of-byte sequence number, and the byte size of a single TCP packet are used as calculation parameters. Hardware logic operations can then generate the sequence of start-of-byte sequence numbers for the subsequent TCP packets to be read consecutively. Based on the order of the start-of-byte sequence numbers in this sequence, at least one TCP packet can be read consecutively in the second packet storage area at once, effectively improving reading efficiency. Therefore, this application provides a data reading method. The specific steps of this method include: determining the sequence of start-of-byte sequence numbers for at least one TCP packet that can be read after reading the target TCP packet based on the start-of-byte sequence number, the end-of-byte sequence number, and the fixed byte length of the TCP packet corresponding to the target entry; and reading at least one TCP packet sequentially in the second packet storage area based on the sequence of start-of-byte sequence numbers.
[0147] In this step, the starting byte sequence number corresponding to the target entry is added to the fixed byte length of the TCP segment to obtain the first starting byte sequence number. Then, the fixed byte length of the TCP segment is added to obtain the second starting byte sequence number. This process is repeated until the Nth starting byte sequence number equals the ending byte sequence number. A sequence of starting byte sequence numbers is then generated based on the first, second, ..., (N-1)th starting byte sequence numbers. Finally, based on the sequence of starting byte sequence numbers, at least one TCP segment is read sequentially from the second segment storage area.
[0148] If, after reading the target TCP packet, multiple TCP packets can still be read consecutively in the second packet storage area, there is no need to update the next position of the current location to the current location to be read. Instead, based on the number of consecutively read TCP packets, determine the target location corresponding to the last read TCP packet, and update the next position of the target location to the new current location to be read, thus continuing the subsequent data reading process. The specific steps include: determining the target number of TCP packets that can be consecutively read in the second packet storage area based on the first byte sequence number; determining the target location corresponding to the last read TCP packet based on the current location and the target number, and setting the next position of the target location as the current location.
[0149] In this step, the TCP packets that can be read consecutively in the second packet storage area based on the sequence number of their first bytes are identified, and the target number corresponding to these TCP packets is determined. Then, the current position is shifted forward by the target number of positions, and this position is designated as the target position. The next position after the target position is designated as the current position.
[0150] In this embodiment, after receiving a TCP packet transmitted through the target TCP connection, it is checked whether the TCP packet will overwrite other unread TCP packets. If it will not overwrite, it is stored normally in the first packet storage area; if it will overwrite, it is stored in the first packet storage area. Specific steps include: receiving a TCP packet transmitted through the target TCP connection; storing the TCP packet in the first packet storage area when the current first byte sequence number and the target first byte sequence number meet a preset relationship; and storing the TCP packet in the second packet storage area when the current first byte sequence number and the target first byte sequence number do not meet the preset relationship.
[0151] The preset relationship is that the difference between the current first byte sequence number and the current first byte sequence number is less than the storage capacity corresponding to the first message storage area.
[0152] In this embodiment, if the difference between the current first byte sequence number and the target first byte sequence number is greater than or equal to the storage capacity corresponding to the first message storage area, it indicates that the TCP message will overwrite the data not read after the current position; otherwise, the TCP message will not overwrite the data not stored after the current position. The specific steps are: obtaining the storage capacity corresponding to the first message storage area; determining the sequence number difference based on the current first byte sequence number and the target first byte sequence number; when the difference is less than the storage capacity, determining that the current first byte sequence number and the target first byte sequence number conform to a preset relationship; when the difference is greater than or equal to the storage capacity, determining that the current first byte sequence number and the target first byte sequence number do not conform to the preset relationship.
[0153] In this embodiment, when the remaining capacity of the first message storage area is higher than a first capacity threshold and the remaining capacity of the second message storage area is lower than a second capacity threshold, a shared storage area is selected within the first message storage area, and the received TCP packets are stored in this area; the shared storage area is a shared storage area for both the first and second message storage areas. This method uses the remaining capacity thresholds of the two storage areas as a trigger for judgment, achieving dynamic and elastic scheduling of storage resources, specifically utilizing idle storage resources to handle stored packets, and improving the overall resource utilization of the storage areas. Specifically, when the remaining capacity of the first message storage area is greater than the first capacity threshold and the remaining capacity of the second message storage area is less than the second capacity threshold, a shared storage area is selected within the first message storage area, and the received TCP packets are stored in the shared storage area.
[0154] The shared storage area is a storage area shared by the first and second packet storage areas. The first and second capacity thresholds are set based on the experience of technical personnel. When the remaining capacity of the first packet storage area is greater than the first capacity threshold, it indicates that the first packet storage area stores relatively few TCP packets. When the remaining capacity of the second packet storage area is less than the second capacity threshold, it indicates that the second packet storage area is full or nearly full.
[0155] The steps for selecting a shared storage area within the first message storage area are as follows: A storage area of a specified length is randomly selected from the first message storage area and designated as the shared storage area. This specified length can be a preset length, a length set according to the size of the first message storage area, or a length set by other methods.
[0156] In this embodiment, when storing TCP packets based on the first packet storage area, the system first checks whether the target storage location of the packet is within the shared storage area based on the first byte sequence number of the TCP packet. Differential storage logic is executed for different detection results: if the storage location is not within the shared storage area, or is within the shared storage area but no stored TCP packets exist, the TCP packet is directly stored in that storage location; if the storage location is within the shared storage area and already contains stored TCP packets, the existing TCP packets are first migrated to other locations within the shared storage area, and then the TCP packet to be stored is stored in the target storage location. This method accurately detects the storage location based on the first byte sequence number and formulates migration strategies for occupancy scenarios within the shared storage area, effectively resolving storage location conflicts within the shared storage area and preventing TCP packets from being unstorable or lost due to location occupancy. The specific steps include: checking whether the storage location of the TCP packet is within the shared storage area based on the sequence number of the first byte corresponding to the TCP packet; if the storage location of the TCP packet is not within the shared storage area, or if the storage location of the TCP packet is within the shared storage area but there is no stored TCP packet at the storage location, storing the TCP packet at the storage location; if the storage location of the TCP packet is within the shared storage area and there is a stored TCP packet at the storage location, transferring the TCP packet stored at the storage location to another location in the shared storage area, and storing the TCP packet at the storage location.
[0157] In this embodiment, considering the sequential reception of data, the storage locations preceding and adjacent to the current location are areas that have just been read, and the probability of receiving new data thereafter is low. Therefore, the last free storage location in the shared storage area can be used to store the TCP packets stored in the second packet storage area. The specific steps include: determining the last free storage location within the shared storage area, and storing the TCP packets based on that last storage location.
[0158] In this embodiment, when the remaining capacity of the second message storage area is higher than the third capacity threshold, the TCP packets to be transferred are first identified in the shared storage area and migrated to the second message storage area. After the packet transfer is completed, the shared storage area is restored to a normal storage area belonging only to the first message storage area. The message migration logic is triggered based on the capacity threshold of the second message storage area, realizing the dynamic reclamation and reuse of the shared storage area. This avoids the long-term occupation of the shared storage area leading to the squeezing of the available space in the first message storage area, thus improving the recycling efficiency of storage resources. Specific steps include: when the remaining capacity of the second message storage area is greater than the third capacity threshold, in the shared storage area, the TCP packets to be transferred are identified, the TCP packets to be transferred are transferred to the second message storage area, and the shared storage area is restored to the first message storage area.
[0159] The third capacity threshold is set by technicians based on experience. When the remaining capacity of the second message storage area is greater than the third capacity threshold, it indicates that the second message storage area can still store data.
[0160] In the shared storage area, the specific steps to determine the TCP packet to be transferred are as follows: The shared storage area begins to detect TCP packets. If the storage location of the TCP packet is determined based on the corresponding first byte sequence and last byte sequence, the TCP packet is not the TCP packet to be transferred; otherwise, the TCP packet is the TCP packet to be transferred.
[0161] The storage location of the aforementioned TCP packet is determined based on its corresponding first byte sequence number and last byte sequence number. This determination rule corresponds to the relevant settings in step 101 for writing the TCP packet into a 32K byte capacity storage RAM.
[0162] In this embodiment, considering the sequential reception of data, the storage locations preceding and adjacent to the current position are areas that have just been read, and the probability of receiving new data thereafter is low. Therefore, a storage area of a preset length can be defined before the current position, and this preset length storage area can be designated as a shared storage area. Specifically, the steps are: within the first message storage area, determine a storage area of a preset length preceding the current position; and designate this preset length storage area as a shared storage area.
[0163] In this embodiment, before reading a TCP packet at the current position, the theoretical first byte sequence number of the TCP packet to be read is calculated based on the first byte sequence number of the most recently successfully read TCP packet. The TCP packet read operation at the current position is only performed if the theoretical first byte sequence number is exactly the same as the actual first byte sequence number of the TCP packet at the current reading position. This sequential verification of the TCP packet's first byte sequence number strictly ensures the correctness of the TCP packet reading order, aligning with the core characteristic of ordered transmission in the TCP protocol and avoiding data concatenation errors caused by reading out-of-order or skipped-number packets. The specific steps include: determining the theoretical first byte sequence number of the TCP packet to be read based on the first byte sequence number of the previously successfully read TCP packet; and reading the TCP packet stored at the current position when the theoretical first byte sequence number is equal to the actual first byte sequence number of the TCP packet at the current position.
[0164] The specific steps to determine the theoretical first byte sequence number of the TCP packet to be read, based on the first byte sequence number of the previously successfully read TCP packet, are as follows: add the first byte sequence number of the previously successfully read TCP packet to a fixed byte to obtain the theoretical first byte sequence number of the TCP packet to be read.
[0165] In this embodiment, when a first isolated entry and a second isolated entry exist in the isolated entry set with consecutive first and last byte numbers, a merge operation is performed on these two isolated entries to generate a merged entry. The starting byte number of the merged entry is inherited from the starting byte number of the first isolated entry, and the ending byte number of the merged entry is inherited from the ending byte number of the second isolated entry. This method achieves automated merging of isolated entries, eliminates redundant isolated entries with consecutive byte numbers, effectively reduces the overall number of isolated entries, lowers the hardware / software resources occupied by entry storage, and reduces the number of entry retrievals and traversals, thereby improving entry management efficiency. The specific steps include: when there is a first island entry and a second island entry in the island entry, the first island entry and the second island entry are merged to obtain a merged entry. The starting byte number corresponding to the first island entry is determined as the starting byte number corresponding to the merged entry, and the ending byte number corresponding to the second island entry is determined as the ending byte number corresponding to the merged entry. The ending byte number corresponding to the first island entry is the same as the starting byte number corresponding to the second island entry.
[0166] In this embodiment of the application, in order to enable the reuse of the first message storage area, it is also possible to detect whether the current position to be read is the last storage position of the first message storage area; if the current position is the last storage position of the first message storage area, the first storage position of the first message storage area is determined as the next position of the current position and updated to the new current position to be read.
[0167] like Figure 2 As shown, this application provides a data processing apparatus, which corresponds to the method embodiment, and specifically includes:
[0168] The acquisition unit 201 is used to acquire the current position to be read in the first packet storage area corresponding to the target TCP;
[0169] The first detection unit 202 is used to detect whether a TCP packet is read at the current location;
[0170] The update unit 203 is used to update the next position of the current position to the current position to be read when a TCP packet is read at the current position;
[0171] The processing unit 204 is configured to, when no TCP packet is read at the current position, determine the target first byte sequence number corresponding to the current position based on the first byte sequence number of the previously successfully read TCP packet, and check whether a target TCP packet exists in the second packet storage area corresponding to the target TCP packet based on the target first byte sequence number; if the target TCP packet exists, the target TCP packet is read as the TCP packet to be read at the current position, and the current position to be read is updated; if the target TCP packet does not exist, the reading process is paused until the TCP packet corresponding to the current position is detected and the reading is completed, and then the next position of the current position is updated to the current position to be read.
[0172] The execution unit 205 is used to re-execute the detection steps based on the updated current position to be read.
[0173] Optionally, the processing unit 204 is used for:
[0174] Detect whether the island entry corresponding to the target TCP exists in the target table, and the starting byte sequence number of the target entry is the target first byte sequence number;
[0175] When the target entry exists in the island entry, it is determined that the target TCP packet exists in the second packet storage area;
[0176] When the target entry does not exist in the island entry, it is determined that the target TCP packet does not exist in the second packet storage area.
[0177] Optionally, when the end-of-time byte sequence number corresponding to the target entry is inconsistent with the end-of-time byte sequence number corresponding to the target TCP packet, after reading the target TCP packet as the TCP packet to be read at the current position, the device further includes a data reading unit 206, which is used for:
[0178] Based on the starting byte sequence number and ending byte sequence number corresponding to the target entry and the fixed byte length corresponding to the TCP packet, it is determined that after reading the target TCP packet, at least one TCP packet's corresponding starting byte sequence number can be read.
[0179] At least one TCP packet is read sequentially in the second packet storage area according to the sequence of first byte numbers.
[0180] Optionally, processing unit 204 is used for:
[0181] Determine the target number of TCP packets that can be read consecutively in the second packet storage area based on the first byte sequence number;
[0182] Based on the current position and the target number, determine the target position corresponding to the last TCP packet read, and determine the next position of the target position as the current position.
[0183] Optionally, when the end-of-byte sequence number corresponding to the target entry is the end-of-byte sequence number of the target TCP packet, the processing unit 204 is configured to:
[0184] In the first message storage area, determine the next position of the current position and update the next position to the current position to be read.
[0185] Optionally, the device further includes a receiving unit 207, the receiving unit 207 being configured to:
[0186] Receive a TCP packet transmitted through the target TCP connection, the TCP packet including the current first byte sequence number;
[0187] When the current first byte sequence number and the target first byte sequence number meet a preset relationship, the TCP packet is stored based on the first packet storage area;
[0188] When the current first byte sequence number and the target first byte sequence number do not conform to a preset relationship, the TCP packet is stored based on the second packet storage area.
[0189] Optionally, the device further includes a determining unit 208, the determining unit 208 being configured to:
[0190] Obtain the storage capacity corresponding to the first message storage area;
[0191] The sequence number difference is determined based on the current first byte sequence number and the target first byte sequence number;
[0192] When the difference is less than the storage capacity, it is determined that the current first byte sequence number and the target first byte sequence number conform to a preset relationship;
[0193] When the difference is greater than or equal to the storage capacity, it is determined that the current first byte sequence number and the target first byte sequence number do not conform to a preset relationship.
[0194] Optionally, the device further includes a selection unit 209, the selection unit 209 being used for:
[0195] When the remaining capacity of the first message storage area is greater than the first capacity threshold and the remaining capacity of the second message storage area is less than the second capacity threshold, a shared storage area is selected in the first message storage area, and the received TCP messages are stored in the shared storage area. The shared storage area is a storage area shared by the first message storage area and the second message storage area.
[0196] Optionally, the selection unit 209 is used for:
[0197] The storage location of the TCP packet is detected based on the sequence number of the first byte corresponding to the TCP packet, indicating whether it is within the shared storage area.
[0198] When the storage location of the TCP packet is not in the shared storage area, or when the storage location of the TCP packet is in the shared storage area but there is no stored TCP packet at the storage location, the TCP packet is stored in the storage location.
[0199] When the storage location of the TCP packet is within the shared storage area and there are already stored TCP packets at the storage location, the TCP packets stored at the storage location are transferred to other locations within the shared storage area, and the TCP packets are stored at the storage location.
[0200] Optionally, the receiving unit 207 is used for:
[0201] Within the shared storage area, determine the last free storage location, and store the TCP packet based on the last storage location.
[0202] Optionally, the device further includes a recovery unit 210, the recovery unit 210 being configured to:
[0203] When the remaining capacity of the second message storage area is greater than the third capacity threshold, a TCP message to be transferred is determined in the shared storage area, the TCP message to be transferred is transferred to the second message storage area, and the shared storage area is restored to the first message storage area.
[0204] Optionally, the selection unit 209 is used for:
[0205] In the first message storage area, a storage area of a preset length prior to the current position is determined; the storage area of the preset length is determined as a shared storage area.
[0206] Optionally, before reading a TCP packet at the current location, the device further includes a reading unit 210, the reading unit 210 being configured to:
[0207] Based on the sequence number of the first byte of the previously successfully read TCP packet, determine the theoretical sequence number of the first byte of the TCP packet to be read;
[0208] When the theoretical first byte sequence number is equal to the actual first byte sequence number corresponding to the TCP packet read at the current position, the TCP packet stored at the current position is read.
[0209] Optionally, the device further includes a merging unit 211, the merging unit 211 being configured to:
[0210] When there is a first island entry and a second island entry in the islanded entry, the first island entry and the second island entry are merged to obtain a merged entry. The starting byte number corresponding to the first island entry is determined as the starting byte number corresponding to the merged entry, and the ending byte number corresponding to the second island entry is determined as the ending byte number corresponding to the merged entry. The ending byte number corresponding to the first island entry and the starting byte number corresponding to the second island entry are the same.
[0211] Optionally, the device further includes a second detection unit 212, the second detection unit 212 being used for:
[0212] Detect whether the current position to be read is the last storage position in the first message storage area;
[0213] If the current position is the last storage position of the first message storage area, then the first storage position of the first message storage area is determined as the next position of the current position and updated to the new current position to be read.
[0214] like Figure 3 As shown in the figure, this application provides a data processing device, including a processor 301, a communication interface 302, a memory 303, and a communication bus 304, wherein the processor 301, the communication interface 302, and the memory 303 communicate with each other through the communication bus 304.
[0215] Memory 303 is used to store computer programs;
[0216] In one embodiment of this application, when the processor 301 executes a program stored in the memory 303, it implements the data processing method provided in any of the foregoing method embodiments, including:
[0217] In the storage area of the first packet corresponding to the target TCP, obtain the current position to be read;
[0218] Detect whether a TCP packet has been read at the current location;
[0219] When a TCP packet is read at the current position, the next position of the current position is updated to the current position to be read;
[0220] If no TCP packet is read at the current position, the target first byte sequence number corresponding to the current position is determined based on the first byte sequence number of the previously successfully read TCP packet. In the second packet storage area corresponding to the target TCP, the existence of the target TCP packet is checked based on the target first byte sequence number. If the target TCP packet exists, it is read as the TCP packet to be read at the current position, and the current position to be read is updated. If the target TCP packet does not exist, the reading process is paused until the TCP packet corresponding to the current position is detected and the reading is completed, and then the next position of the current position is updated to the current position to be read.
[0221] Based on the updated current position to be read, the detection steps are re-executed.
[0222] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the data processing steps provided in any of the foregoing method embodiments.
[0223] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0224] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented using software plus a general-purpose hardware platform, or of course, using hardware. Based on this understanding, the above technical solutions, in essence or the parts that contribute to the related technology, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0225] It should be understood that the terminology used herein is for the purpose of describing particular exemplary embodiments only and is not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms “a,” “an,” and “described” as used herein may also include the plural forms. The terms “comprising,” “including,” “containing,” and “having” are inclusive and therefore indicate the presence of the stated features, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, elements, components, and / or combinations thereof. The method steps, processes, and operations described herein are not construed as requiring them to be performed in a particular order described or illustrated unless the order of performance is explicitly indicated. It should also be understood that additional or alternative steps may be used.
[0226] The above description is merely a specific embodiment of the present invention, enabling those skilled in the art to understand or implement the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the present invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A data processing method, characterized in that, The method is applied to an FPGA system and includes: In the storage area of the first packet corresponding to the target TCP, obtain the current position to be read; Detect whether a TCP packet has been read at the current location; When a TCP packet is read at the current position, the next position of the current position is updated to the current position to be read; If no TCP packet is read at the current position, the target first byte sequence number corresponding to the current position is determined based on the first byte sequence number of the previously successfully read TCP packet. In the second packet storage area corresponding to the target TCP, the existence of the target TCP packet is checked based on the target first byte sequence number. If the target TCP packet exists, it is read as the TCP packet to be read at the current position, and the current position to be read is updated. If the target TCP packet does not exist, the reading process is paused until the TCP packet corresponding to the current position is detected and the reading is completed, and then the next position of the current position is updated to the current position to be read. Based on the updated current position to be read, the detection steps are re-executed.
2. The method according to claim 1, characterized in that, The step of detecting whether a target TCP packet exists in the second packet storage area corresponding to the target TCP packet based on the target first byte sequence number includes: Detect whether the island entry corresponding to the target TCP exists in the target table, wherein the starting byte sequence number of the target entry is the target first byte sequence number or the corresponding sequence number range covers the target first byte sequence number; When the target entry exists in the island entry, it is determined that the target TCP packet exists in the second packet storage area; When the target entry does not exist in the island entry, it is determined that the target TCP packet does not exist in the second packet storage area.
3. The method according to claim 2, characterized in that, When the end-of-byte sequence number corresponding to the target entry is inconsistent with the end-of-byte sequence number corresponding to the target TCP packet, after reading the target TCP packet as the TCP packet to be read at the current position, the method further includes: Based on the starting byte sequence number and ending byte sequence number corresponding to the target entry, and the fixed byte length corresponding to the TCP packet, it is determined that at least one TCP packet's starting byte sequence number can be read after reading the target TCP packet. At least one TCP packet is read sequentially in the second packet storage area according to the sequence of first byte numbers.
4. The method according to claim 3, characterized in that, The updating of the current position to be read includes: Determine the target number of TCP packets that can be read consecutively in the second packet storage area based on the first byte sequence number; Based on the current position and the target number, determine the target position corresponding to the last TCP packet read, and determine the next position of the target position as the current position.
5. The method according to claim 2, characterized in that, When the end-of-byte sequence number corresponding to the target entry is the end-of-byte sequence number of the target TCP packet, updating the current position to be read includes: In the first message storage area, determine the next position of the current position and update the next position to the current position to be read.
6. The method according to claim 1, characterized in that, The method further includes: Receive a TCP packet transmitted through the target TCP connection, the TCP packet including the current first byte sequence number; When the current first byte sequence number and the target first byte sequence number meet a preset relationship, the TCP packet is stored based on the first packet storage area; When the current first byte sequence number and the target first byte sequence number do not conform to a preset relationship, the TCP packet is stored based on the second packet storage area.
7. The method according to claim 6, characterized in that, The method further includes: Obtain the storage capacity corresponding to the first message storage area; The sequence number difference is determined based on the current first byte sequence number and the target first byte sequence number; When the difference is less than the storage capacity, it is determined that the current first byte sequence number and the target first byte sequence number conform to a preset relationship; When the difference is greater than or equal to the storage capacity, it is determined that the current first byte sequence number and the target first byte sequence number do not conform to a preset relationship.
8. The method according to claim 7, characterized in that, The method further includes: When the remaining capacity of the first message storage area is greater than the first capacity threshold and the remaining capacity of the second message storage area is less than the second capacity threshold, a shared storage area is selected in the first message storage area, and the received TCP messages are stored in the shared storage area. The shared storage area is a storage area shared by the first message storage area and the second message storage area.
9. The method according to claim 8, characterized in that, The storage of the TCP packets based on the first packet storage area includes: The storage location of the TCP packet is detected based on the sequence number of the first byte corresponding to the TCP packet, indicating whether it is within the shared storage area. When the storage location of the TCP packet is not in the shared storage area, or when the storage location of the TCP packet is in the shared storage area but there is no stored TCP packet at the storage location, the TCP packet is stored in the storage location. When the storage location of the TCP packet is within the shared storage area and there are already stored TCP packets at the storage location, the TCP packets stored at the storage location are transferred to other locations within the shared storage area, and the TCP packets are stored at the storage location.
10. The method according to claim 8, characterized in that, The storage of the TCP packets based on the second packet storage area includes: Within the shared storage area, determine the last free storage location, and store the TCP packet based on the last storage location.
11. The method according to claim 8, characterized in that, The method further includes: When the remaining capacity of the second message storage area is greater than the third capacity threshold, a TCP message to be transferred is determined in the shared storage area, the TCP message to be transferred is transferred to the second message storage area, and the shared storage area is restored to the first message storage area.
12. The method according to claim 8, characterized in that, The step of selecting a shared storage area in the first message storage area includes: In the first message storage area, a storage area of a preset length prior to the current position is determined; the storage area of the preset length is determined as a shared storage area.
13. The method according to claim 1, characterized in that, Before a TCP packet is read at the current location, the method further includes: Based on the sequence number of the first byte of the previously successfully read TCP packet, determine the theoretical sequence number of the first byte of the TCP packet to be read; When the theoretical first byte sequence number is equal to the actual first byte sequence number corresponding to the TCP packet read at the current position, the TCP packet stored at the current position is read.
14. The method according to claim 2, characterized in that, The method further includes: When there is a first island entry and a second island entry in the islanded entry, the first island entry and the second island entry are merged to obtain a merged entry. The starting byte number corresponding to the first island entry is determined as the starting byte number corresponding to the merged entry, and the ending byte number corresponding to the second island entry is determined as the ending byte number corresponding to the merged entry. The ending byte number corresponding to the first island entry and the starting byte number corresponding to the second island entry are the same.
15. The method according to claim 1, characterized in that, The method further includes: Detect whether the current position to be read is the last storage position in the first message storage area; If the current position is the last storage position of the first message storage area, then the first storage position of the first message storage area is determined as the next position of the current position and updated to the new current position to be read.
16. A data processing apparatus, characterized in that, The device includes: The acquisition unit is used to acquire the current position to be read in the first packet storage area corresponding to the target TCP; The detection unit is used to detect whether a TCP packet has been read at the current location; An update unit is used to update the next position of the current position to the current position to be read when a TCP packet is read at the current position; The processing unit is configured to, when no TCP packet is read at the current position, determine the target first byte sequence number corresponding to the current position based on the first byte sequence number of the previously successfully read TCP packet, and check whether a target TCP packet exists in the second packet storage area corresponding to the target TCP packet based on the target first byte sequence number; if the target TCP packet exists, the target TCP packet is read as the TCP packet to be read at the current position, and the current position to be read is updated; if the target TCP packet does not exist, the reading process is paused until the TCP packet corresponding to the current position is detected and the reading is completed, and then the next position of the current position is updated to the current position to be read. The execution unit is used to re-execute the detection steps based on the updated current position to be read.
17. The apparatus according to claim 16, characterized in that, The processing unit is used for: Detect whether the island entry corresponding to the target TCP exists in the target table, and the starting byte sequence number of the target entry is the target first byte sequence number; When the target entry exists in the island entry, it is determined that the target TCP packet exists in the second packet storage area; When the target entry does not exist in the island entry, it is determined that the target TCP packet does not exist in the second packet storage area.
18. The apparatus according to claim 17, characterized in that, When the end-of-byte sequence number corresponding to the target entry is inconsistent with the end-of-byte sequence number corresponding to the target TCP packet, after reading the target TCP packet as the TCP packet to be read at the current position, the device further includes a data reading unit, which is used for: Based on the starting byte sequence number and ending byte sequence number corresponding to the target entry and the fixed byte length corresponding to the TCP packet, it is determined that after reading the target TCP packet, at least one TCP packet's corresponding starting byte sequence number can be read. At least one TCP packet is read sequentially in the second packet storage area according to the sequence of first byte numbers.
19. A data processing device, characterized in that, include: At least one communication interface; At least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; At least one memory connected to the at least one bus, wherein the processor is configured to: In the storage area of the first packet corresponding to the target TCP, obtain the current position to be read; Detect whether a TCP packet has been read at the current location; When a TCP packet is read at the current position, the next position of the current position is updated to the current position to be read; If no TCP packet is read at the current position, the target first byte sequence number corresponding to the current position is determined based on the first byte sequence number of the previously successfully read TCP packet. In the second packet storage area corresponding to the target TCP, the existence of the target TCP packet is checked based on the target first byte sequence number. If the target TCP packet exists, it is read as the TCP packet to be read at the current position, and the current position to be read is updated. If the target TCP packet does not exist, the reading process is paused until the TCP packet corresponding to the current position is detected and the reading is completed, and then the next position of the current position is updated to the current position to be read. Based on the updated current position to be read, the detection steps are re-executed.
20. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the data processing method according to any one of claims 1 to 15.
Citation Information
Patent Citations
Message receiving method and device based on TCP, electronic equipment and storage medium
CN114143268A
Method and device for recombining IP message fragments, electronic equipment and storage medium
CN116886652A