TCP data packet sending and receiving method and system supporting out-of-order priority
By distinguishing priority processing queues and buffers in the TCP protocol and adopting out-of-order transmission mechanism, the problem of high-priority data being blocked by low-priority data in the TCP protocol is solved, efficient priority data processing is achieved, and response is reduced Delay.
Patent Information
- Application Number
- CN202211297057.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-21
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2042-10-21
AI Technical Summary
When using the TCP protocol, high-priority requests and low-priority requests are processed within the same TCP connection. Due to the order of TCP, the high-priority data is blocked by low-priority data, resulting in increased response delay. The existing technology It is not possible to effectively distinguish between requests and responses with different priorities.
By putting high-priority and low-priority packets into different processing queues and buffers, and prioritizing high-priority packets in the TCP protocol stack, an out-of-order transmission mechanism is adopted to allow high-priority packets to be skipped Low-priority data packets are sent and received, and provide out-of-order interfaces in upper-level applications to support the direct processing and transmission of high-priority data.
It effectively avoids the delay caused by low-priority data blocking, realizes priority processing of high-priority requests and responses, reduces the response time of the client, and improves the efficiency of network services.
Smart Images

Figure CN115834730B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technology, and in particular to a TCP protocol implementation method and system. Background Art
[0002] TCP (Transmission Control Protocol) is a connection-oriented, reliable, byte-stream-based transport layer communication protocol. TCP guarantees the integrity, order, and reliability of transmission. In order to ensure the order and integrity of data passed by TCP to upper-layer applications, the transport layer uses byte streams to pass data to upper-layer applications, ensuring that the order in which all bytes are received is consistent with the order in which they are sent at the sender. In the implementation of the network protocol stack, when the transport layer receives out-of-order data due to packet loss or other reasons, it will first save it in an out-of-order queue until the missing data packets are received to fill in the missing data before the out-of-order data, and then this part of the data will be sorted into a sequential data stream and passed to the upper-layer application.
[0003] With the rapid development of network technology and network applications, the network bandwidth of servers in data centers, the number of requests to be processed and the number of responses to be sent per unit time have also increased dramatically. In data centers, servers can receive millions of requests per second, causing these requests to queue up in the protocol stack processing stage and the upper application processing stage to be processed in sequence, resulting in queuing delays.
[0004] In common network applications, such as Memcached, HTTP pipeline, WeChat, IoT services, etc., they maintain a long-lived connection between the client and the server, and carry multiple requests of different types in this long connection. Some of these requests are for which users hope to get a response as soon as possible, such as the order and payment process during the shopping process; while for other requests, such as accessing the pages of other products, users are less sensitive to the response delay of these requests. Therefore, when the network service system provides services for user requests, there is usually a need to divide user requests into high-priority requests and low-priority requests, hoping to open a high-priority channel for high-priority requests and give priority to them, so as to avoid queuing them with low-priority requests and causing unnecessary delays.
[0005] However, when the transport layer uses TCP, if a low-priority request is followed by a high-priority request in the same connection, because of TCP's guarantee of sequentiality, the protocol stack needs to process the low-priority data packet first in byte order and pass the low-priority request to the upper-layer application for processing before receiving the subsequent high-priority request. When there is a burst of data that needs to be sent first after sending low-priority data in the same TCP connection, because of TCP's guarantee of sequentiality, the protocol stack also needs to send the low-priority data before sending the subsequent high-priority data.
[0006] In most standard TCP protocol stack processing (for example, operating system kernel protocol stack, etc.), only data packets within the same TCP connection can be received and sent in sequence, and it is impossible to differentiate services for requests and responses of different priorities.
[0007] In order to avoid the head-of-line blocking problem caused by TCP sequential guarantee, Minion designed TCP out-of-order transmission support based on messages. The sender can skip low-priority messages and send them out of order. The receiver can also directly submit high-priority messages that arrive out of order in advance to the upper-layer application without waiting for low-priority messages with smaller sequence numbers. However, Minion can only submit data to the upper-layer application in the order in which it is received. When the sender sends low-priority messages first and then high-priority messages, the protocol stack and upper-layer application of the receiver can only process low-priority messages first. In addition, Minion needs to modify both the sender and the receiver at the same time, which cannot be extended to the scenario where individual users are clients. LNS records the priority in the form of a label in the data packet. After being identified by the network card, the priority queue is used to give priority to high-priority requests in the protocol stack processing and upper-layer application processing of the server. LNS points out that high-priority requests need to be processed out of order at the TCP layer, but does not provide a specific solution or design for how to support priority processing of out-of-order TCP data packets. Summary of the invention
[0008] In view of the above problems, the present invention proposes a method, which specifically includes: after receiving a data packet, placing a high-priority received data packet into a first processing queue and placing a low-priority received data packet into a second processing queue; the TCP protocol stack places the high-priority received data packet into a first receiving buffer, notifies the upper-layer application to immediately perform receiving processing, and places the low-priority received data packet into a second receiving buffer, waiting for the upper-layer application to process; when data is to be sent externally, the high-priority sent data packet is placed into a first sending buffer and the low-priority sent data packet is placed into a second sending buffer, and the TCP protocol stack generates a sending order in which the high-priority sent data packet is sent first and the low-priority sent data packet is sent later to send data.
[0009] The TCP data packet receiving and sending method of the present invention, when the upper layer application processes the high priority received data packet: if the program of the upper layer application adopts the non-blocking IO programming logic based on the event framework, the high priority received data packet is immediately received for processing; if the program adopts the blocking IO programming logic, and the current connection is blocked in the high priority data receiving state, the high priority received data packet is immediately received for processing, if the current connection is blocked in the low priority data receiving state, it returns from the blocking state and enters the high priority data receiving state; if the program adopts the non-blocking IO programming logic based on select, a high priority received packet file descriptor set is constructed, and when there is the high priority received data packet to be received, the corresponding descriptor in the corresponding high priority received packet file descriptor set is set, and the upper layer application is notified to receive the high priority received data packet for processing; if the program adopts the non-blocking IO programming logic based on poll(), a parameter fds_pri for returning the socket file descriptor with high priority data to be received is added to notify the upper layer application to receive the high priority received data packet for processing.
[0010] The TCP data packet receiving and sending method described in the present invention, when receiving the high priority received data packet, if there are low priority data fragments with earlier receiving sequence numbers that have not been received, then it is recorded in the TCP stream information that the data fragments have been received out of order with high priority, and no confirmation packet of the data fragment is returned to the sending end.
[0011] The TCP data packet receiving and sending method of the present invention comprises the following steps: the upper layer application calls a high priority disorderly receiving interface read_pri (int fd, char*buff, int len, int*offset, int*rcvnxt) to receive disorderly high priority received data packets, wherein fd represents a socket for receiving data, buff represents a buffer for receiving data, len represents the length of the receiving buffer buff, offset represents the sequence number of the data fragment of the high priority received data packet returned in the TCP stream, and rcvnxt represents the sequence number of the next data fragment received in sequence by the current TCP stream returned in the TCP stream.
[0012] The TCP data packet receiving and sending method of the present invention is that the upper layer application calls the high priority disordered receiving interface read_pri (int fd, char*buff, int len, int*jump_len) to receive disordered high priority receiving data packets, wherein fd represents the socket that needs to receive data, buff represents the buffer for receiving data, len represents the length of the receiving buffer buff, and jump_len represents the byte portion skipped between the next data segment to be received in sequence by the current TCP flow and the high priority disordered data segment received by this call, and the byte portion is the unreceived low priority data segment and the received high priority data segment.
[0013] The TCP data packet sending and receiving method of the present invention, wherein when the upper layer application calls the high priority out-of-order sending interface, a high priority flag is added to the flags parameter of the socket interface send() to mark the data to be sent as high priority.
[0014] The TCP data packet sending and receiving method described in the present invention is characterized in that, for out-of-order high-priority sending data packets, the current data fragment is recorded in the sent sequence number and put into the out-of-order high-priority sending queue for sending; for the low-priority sending data confirmation packet or the selected confirmation packet returned by the receiver with the sent sequence number in front, no fast retransmission is performed until the low-priority data packet corresponding to the low-priority sending data is confirmed and released, or retransmitted after TCP timeout occurs.
[0015] The present invention also proposes a TCP data packet receiving and sending system supporting out-of-order priority, comprising: a TCP data packet receiving module, used to receive data packets and place the data packets into buffers of corresponding priorities according to the priorities of the data packets; a priority packet receiving notification module, used to notify the upper-layer application to receive the data packet according to the priority of the data packet; an upper-layer application data receiving and sending module; used to receive and send the data packet through a data interface supporting out-of-order receiving and sending of high-priority data; a TCP data packet sending module, used to send and process the data packets stored in the TCP sending buffer by the upper-layer application on the packet sending path.
[0016] The present invention also proposes a computer-readable storage medium storing computer-executable instructions, characterized in that when the computer-executable instructions are executed, the TCP data packet sending and receiving method supporting priority disorder as described above is implemented.
[0017] The present invention also proposes a data processing device, including the computer-readable storage medium as described above. When the processor of the data processing device calls and executes the computer-executable instructions in the computer-readable storage medium, the data processing device acts as a network node to perform TCP data packet sending and receiving that supports out-of-order priorities. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is a flow chart of a TCP data packet receiving and sending method supporting out-of-order priorities of the present invention.
[0019] Figure 2 The present invention is a schematic diagram of the structure of a TCP data packet receiving and sending system supporting out-of-order priorities.
[0020] Figure 3A It is a flow chart of the protocol stack packet receiving processing method of the present invention.
[0021] Figure 3B It is a schematic diagram of an example of TCP out-of-order priority reception of the present invention.
[0022] Figure 4A It is a flow chart of the protocol stack packet processing method of the present invention.
[0023] Figure 4B It is a schematic diagram of an example of TCP out-of-order priority sending of the present invention.
[0024] Figure 5 It is a schematic diagram of a data processing device of the present invention. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation method described herein is only used to explain the present invention and is not used to limit the present invention.
[0026] When the inventor was working on the problem of head-of-line blocking in a stream caused by TCP sequentiality, he found that the defect in the prior art was caused by the mixed storage of high- and low-priority data in the TCP transceiver buffer, and the socket interface facing the upper-layer application did not support out-of-order transmission and reception. In the existing TCP protocol processing, high- and low-priority received data and data to be sent are stored in a queue or buffer, resulting in the protocol stack being unable to give priority to high-priority data when performing TCP protocol processing, and unable to mark and distinguish data of different priorities during the protocol processing. The data structure of the existing protocol stack facing upper-layer applications uniformly adopts the BSD (Berkeley Software Distribution) socket interface, which does not consider the priority of data when sending and receiving data, and can only process data in sequence in the form of byte streams, and cannot give priority to high-priority data.
[0027] To this end, the present invention designs a TCP protocol processing implementation that supports out-of-order transmission and reception of priority data. During the protocol stack processing, the present invention prioritizes the data packets to be processed by the protocol stack, gives priority to the transmission and reception of high-priority data, supports the transmission and reception of out-of-order high-priority data during the protocol processing, and stores data of different priorities in TCP buffers of different priorities for distinction. On the data transmission and reception interface facing the upper-layer application, the present invention designs a socket-like interface that supports out-of-order transmission and reception of high-priority data, so that the upper-layer application can skip the low-priority data in the TCP buffer and directly transmit and receive the high-priority data.
[0028] The present invention aims to solve the problem that high-priority data in the same TCP stream may be blocked by low-priority data, and may be affected by queuing blockage during protocol stack processing and upper-layer application sending and receiving, resulting in an increase in response delay felt by customers.
[0029] First, the TCP protocol stack of the present invention receives data packets that have been identified as having a priority, and performs TCP processing that supports high-priority out-of-order processing, thereby preventing high-priority data packets from being affected by queuing delays during the protocol stack processing stage. The high-priority data packets are placed in a high-priority TCP receive buffer and their sequence numbers are recorded when they are out of order. When receiving low-priority data packets, the TCP sequence number sequentiality of the received out-of-order high-priority data is restored.
[0030] Secondly, a priority TCP buffer is set up to prepare TCP receive buffers of corresponding priorities for high-priority TCP data and low-priority TCP data respectively, so as to distinguish the priority of data when the upper-layer application sends and receives and the protocol stack processes it, and maintain the TCP sequence number sequence of each segment of data in each priority TCP buffer.
[0031] Third, an application interface that supports out-of-order sending and receiving of high-priority data enables upper-layer applications to receive and send high-priority data directly to the network protocol stack and skip low-priority data in the TCP send and receive buffer.
[0032] Fourth, the protocol stack gives priority to sending high-priority data packets. The network protocol stack gives priority to sending data in the high-priority TCP send buffer to avoid the high-priority data sent later when there is low-priority data in the TCP send buffer being affected by queuing blocking delays due to TCP sequential guarantees, and is compatible with the receiving end processed by the standard TCP protocol stack.
[0033] Finally, the TCP data packet sending and receiving method of the present invention supports multi-priority extension, which can expand the priority of TCP data from the two levels of "high-low" to more levels of priority, and give priority to data according to the priority level during application sending and receiving and network protocol stack processing.
[0034] The TCP data packet sending and receiving method supporting out-of-order priority of the present invention can, when there are requests and responses of different priorities in the same TCP connection at the same time, the high-priority requests and responses can be sent and received preferentially by the protocol stack and the upper-layer application without waiting for the low-priority data in the TCP buffer, thereby avoiding queuing delays in the sending and receiving process of high-priority data.
[0035] Figure 1 Flowchart of the TCP data packet receiving and sending method supporting out-of-order priority of the present invention. Figure 1 As shown, the TCP data packet sending and receiving method of the present invention includes:
[0036] Step S1, receiving TCP data packets with disordered priorities;
[0037] In the data packet receiving and processing path, high-priority data packets are processed preferentially through the TCP protocol stack and placed in a separate high-priority buffer, supporting out-of-order processing of high-priority data packets and ensuring the integrity and correctness of the overall transmission; among them:
[0038] After the data packet arrives at the server, the network card or driver performs a simple priority identification before the TCP protocol stack processes it, and places high-priority and low-priority data packets in different queues to be processed;
[0039] The TCP protocol stack gives priority to processing data packets in the high-priority processing queue and stores the request data in the high-priority data packets in the high-priority TCP receive buffer; after processing the high-priority data packets, it processes the low-priority data packets in the low-priority processing queue and stores the request data in the low-priority data packets in the low-priority TCP receive buffer.
[0040] Step S2, generating a packet receiving event with a priority to notify the upper layer application;
[0041] After the TCP protocol stack receives high-priority data, it notifies the upper-layer application through a priority packet receiving event that there is high-priority data to be received and needs to be processed immediately. When the upper-layer application program adopts different IO programming logic:
[0042] If the program uses non-blocking IO programming logic based on an event framework (for example, epoll or kqueue), the events are divided into different priorities. After the protocol stack receives the high-priority data, a high-priority packet receiving event is added. After the upper-layer application receives the packet receiving event, it receives the data packets of the corresponding priority for the corresponding TCP connection.
[0043] If the program uses blocking IO programming logic, if the current connection is blocked on receiving high-priority data, the TCP protocol stack will immediately return the corresponding high-priority data after receiving the high-priority data; if the current connection is blocked on receiving low-priority data, the TCP protocol stack will return from the blocking state after receiving the high-priority data, and notify the upper-layer application through the return value that there is high-priority data waiting to be received and processed;
[0044] If the program uses select-based non-blocking IO programming logic, a high-priority packet receiving file descriptor set can be added. When the socket has high-priority data to be received, the corresponding descriptor in the high-priority packet receiving file descriptor set is set to notify the upper-layer application to perform a high-priority packet receiving operation.
[0045] If the program uses non-blocking IO programming logic based on poll(), it can be extended to implement the interface poll_pri() that only returns high-priority data packets to be received, or in addition to the parameter fds used to return the socket file descriptor in the interface parameter of poll, an additional parameter fds_pri is added specifically for returning the socket file descriptor with high-priority data to be received;
[0046] In addition, notifications corresponding to low-priority data are processed in accordance with the traditional protocol stack.
[0047] Step S3, the upper layer application calls the data interface to support out-of-order priority data transmission and reception;
[0048] When receiving a data packet, the upper layer application receives the high priority data stored in the TCP high priority receiving buffer by calling the high priority out of order receiving interface; the high priority out of order receiving interface only receives high priority TCP data packets, supports out of order receiving of high priority data in the TCP stream, and returns to the upper layer application the variables such as the offset of the out of order data in the stream, the current TCP stream sequence receiving sequence number, or returns other variable combinations that can achieve the same purpose, and supports the upper layer application to sequentially restore the out of order data;
[0049] One implementation form of the high-priority out-of-order receiving interface is read_pri(int fd, char*buff, intlen, int*offset, int*rcvnxt). Among them, fd represents the socket that needs to receive data, buff represents the buffer used to receive data, len represents the length of the receiving buffer buff, offset is used to return the sequence number of the data segment in the TCP stream, and rcvnxt is used to return the sequence number of the next byte received in sequence by the current TCP stream in the stream. According to offset and rcvnxt, the upper-layer application can perform out-of-order recovery of the high-priority data received out of order at the application layer when necessary;
[0050] Another implementation form of the high-priority out-of-order receiving interface is read_pri(int fd, char*buff, intlen, int*jump_len), where fd represents the socket that needs to receive data, buff represents the buffer for receiving data, len represents the length of the receiving buffer buff, and jump_len represents how many bytes are skipped between the next data segment to be received in sequence in the current TCP stream and the high-priority out-of-order data segment received by this call. The skipped part is the unreceived low-priority data segment and the received high-priority data segment.
[0051] There are other ways to implement the high-priority out-of-order receiving interface, and other interfaces with similar functions but different forms are used to implement the out-of-order high-priority receiving function, and the present invention is not limited thereto;
[0052] The send() function of the standard socket interface is modified in the present invention. A non-enabled (idle) flag bit is selected as a high priority flag bit in the flags parameter. When the upper layer application needs to send high priority data out of order, the data to be sent is marked as high priority data for high priority out of order sending. In the process of sending data with send(), the total number of bytes sent by the current TCP connection is calculated, the sequence number of the data segment in the TCP stream is written into the data packet, and then the data packet is placed in the high priority receiving buffer.
[0053] When the upper layer application sends and receives low-priority data, it still calls the standard socket interface, such as read(), recv(), write(), send(), etc. During the data sending interface call, the data is stored in the TCP low-priority sending buffer, and the TCP sequence number is calculated according to the total number of bytes sent by the current TCP flow and recorded in the data packet.
[0054] Step S4, performing a TCP data packet sending process with disordered priorities;
[0055] The TCP protocol stack gives priority to processing data packets in the high-priority TCP send buffer, and after completing the packet header according to the network protocol, sends it to the driver's high-priority send queue. If the data packet is an out-of-order high-priority data packet, the data segment will be recorded in the sent sequence number and put into the out-of-order high-priority sent queue. When the other party returns an ACK packet (ACK packet) or a selection ACK packet (SACK packet) requesting the sending of lower-priority data with a smaller sequence number, no fast retransmission will be performed until the sent low-priority data packets are confirmed and then released uniformly, or retransmitted after TCP timeout occurs;
[0056] The TCP protocol stack then processes the low-priority data packets to be sent in the TCP low-priority send buffer, fills in the packet header according to the network protocol, and sends it to the driver low-priority send queue, records the data segment in the sent sequence number, and puts it into the sent queue to be confirmed. After receiving the confirmation packet (ACK packet) sent back by the other end, if there is out-of-order high-priority data that has been sent and is waiting to be confirmed, the confirmation packet will confirm these two data segments together, and release the confirmed sent low-priority data packet together with the high-priority data packet;
[0057] When the driver layer processes the data packets in the driver sending queue, it first sends the data packets in the high priority sending queue to the network card, and then sends the data packets in the low priority queue, or adopts other priority queue scheduling algorithms.
[0058] Figure 2 Schematic diagram of the structure of the TCP data packet receiving and sending system supporting out-of-order priority of the present invention. Figure 2 As shown, the TCP data packet transceiver system of the present invention comprises:
[0059] TCP data packet receiving module (100): In the data packet receiving and processing path, the TCP protocol stack of the present invention processes high priority data packets preferentially and puts them into a separate high priority buffer, supports out-of-order processing of high priority data packets and ensures the integrity and correctness of the overall transmission.
[0060] Data packet priority distinguishing module (101): After a data packet arrives at the server, the network card or driver performs a simple priority identification before the TCP protocol stack processes it, and places high and low priority data packets in different queues to be processed.
[0061] High priority data packet receiving module (102): The TCP protocol stack gives priority to processing data packets in the high priority processing queue in the data packet priority distinguishing module 101, and stores the request data in the high priority data packet in the high priority TCP receiving buffer. In the high priority TCP receiving buffer, the data packets are sorted and stored according to the TCP sequence number. If it is found that there is still unreceived data before the high priority data packet, it is recorded in the TCP flow information that the data of the segment sequence number has been received out of order with high priority, and no ACK (Acknowledge character) packet is returned to avoid triggering unnecessary retransmission at the sending end. In the process of transport layer data packet reception and processing in some embodiments, the data packet priority type can be identified at the same time. If the data packet is re-identified as low priority, it is processed according to the low priority data packet receiving module 103.
[0062] Low priority data packet receiving module (103): After processing the high priority data packet, the low priority data packet in the data packet priority distinguishing module 101 is processed, and the request data in the low priority data packet is stored in the low priority TCP receiving buffer. In the low priority TCP receiving buffer, the data packets are sorted and stored according to the TCP sequence number. In the process of processing the low priority data packet, if it is found that the low priority data before a certain segment of out-of-order high priority data has been completely received, the TCP flow information is updated to all the data before the end of the segment of high priority data has been received normally, and the ACK packet is uniformly returned, thereby completing the out-of-order recovery. In the process of transport layer data packet reception and processing in some embodiments, the data packet priority type can be identified at the same time. If the data packet is re-identified as high priority, it is processed according to the high priority data packet receiving module 102.
[0063] Of course, there may be other ways to divide the priority of data packet requests, such as dividing TCP data packets into high priority data packets, medium priority data packets and low priority data packets. In this way, in some other embodiments of the present invention, the TCP data packet receiving module of the TCP data packet transceiver system may also be provided with a medium priority data packet receiving module, or other priority data packet receiving modules, and the present invention is not limited thereto.
[0064] Packet receiving notification module (200): After the high priority data packet receiving module 102 of the TCP protocol stack receives the high priority data, it needs to notify the upper layer application that there is high priority data to be received and needs to be processed immediately. If the program adopts non-blocking IO programming logic based on the event framework (for example, epoll or kqueue), the events are divided into different priorities, and a high priority packet receiving event is added after the protocol stack receives the high priority data. After the upper layer application receives the packet receiving event, the corresponding TCP connection receives the data packet of the corresponding priority. If the program adopts blocking IO programming logic, if the current connection is blocked in receiving high priority data, the corresponding high priority data will be returned immediately after the TCP protocol stack receives the high priority data; if the current connection is blocked in receiving low priority data, the TCP protocol stack will return from the blocking state after receiving the high priority data, and notify the upper layer application through the return value that there is high priority data waiting to be received and processed. If the program uses non-blocking IO programming logic based on select, a high-priority packet receiving file descriptor set can be added. When the socket has high-priority data to be received, the corresponding descriptor in the high-priority packet receiving file descriptor set is set to notify the upper-layer application to perform a high-priority packet receiving operation. If the program uses non-blocking IO programming logic based on poll(), the interface poll_pri() that only returns high-priority data packets to be received can be extended to implement, or in addition to the parameter fds used to return the socket file descriptor in the interface parameter of poll, an additional parameter fds_pri is added specifically for returning the socket file descriptor with high-priority data to be received. For notifications corresponding to low-priority data, it remains consistent with the traditional protocol stack processing.
[0065] Upper layer application data transceiving interface module (300): The upper layer application transmits and receives TCP stream data through a data interface that supports out-of-order transmission and reception of high priority data.
[0066] High priority application receiving interface module (301): When the upper layer application needs to receive high priority data stored in the TCP high priority receiving buffer by the high priority data packet receiving module 102 through the notification of the priority packet receiving notification module 200, the high priority out-of-order receiving interface is called. The high priority out-of-order receiving interface only receives high priority TCP data packets, supports out-of-order receiving of high priority data in the TCP stream, and returns to the upper layer application the offset of the out-of-order data in the stream, the sequence number of the current TCP stream sequence receiving sequence, or returns other variable combinations that can achieve the same purpose, and supports the upper layer application to sequentially restore the out-of-order data. One implementation form of the high priority out-of-order receiving interface is read_pri(intfd, char*buff, int len, int*offset, int*rcvnxt). Among them, fd represents the socket that needs to receive data, buff represents the buffer for receiving data, len represents the length of the receiving buffer buff, offset is used to return the sequence number of the segment of data in the TCP stream, and rcvnxt is used to return the sequence number of the next byte received in sequence by the current TCP stream in the stream. According to offset and rcvnxt, the upper layer application can perform out-of-order recovery of the high priority data received out of order at the application layer when necessary. Another implementation form of the high priority out-of-order receiving interface is read_pri(int fd, char*buff, intlen, int*jump_len), where fd represents the socket that needs to receive data, buff represents the buffer for receiving data, len represents the length of the receiving buffer buff, and jump_len represents the number of bytes skipped between the next data segment to be received in order in the current TCP stream and the high priority out-of-order data segment received in this call. The skipped part is the unreceived low priority data segment and the received high priority data segment. There are other ways to implement the high priority out-of-order receiving interface, using other interfaces with similar functions but different forms to implement the out-of-order high priority receiving function, and the present invention is not limited to this.
[0067] High priority application sending interface module (302): When the upper layer application needs to send high priority data out of order, the send() function of the standard socket interface is modified in the present invention, and an unused (idle) flag bit is selected as the high priority flag bit in the flags parameter to mark the data to be sent as high priority data for high priority out of order sending. In the embodiment of the present invention, the high priority flag bit is called the MSG_HIGHPRI flag bit. In the process of sending data in send(), the sequence number of the data segment in the TCP stream is calculated according to the total number of bytes sent by the current TCP connection and written into the data packet, and then the data packet is placed in the high priority receiving buffer.
[0068] Low priority application transceiver interface module (303): When the upper layer application sends and receives low priority data, it still calls the standard socket interface, such as read(), recv(), write(), send(), etc. During the data transmission interface call process, the data is stored in the TCP low priority transmission buffer, and the TCP sequence number is calculated according to the total number of bytes sent by the current TCP flow in the process, and recorded in the data packet.
[0069] TCP data packet sending module (400): The network protocol stack performs sending processing on the data packet stored in the TCP sending buffer by the high priority application sending interface module 302 on the packet sending path.
[0070] High priority data packet sending module (401): The network protocol stack preferentially processes the data packets placed in the high priority TCP sending buffer by the high priority application receiving interface module 301, and sends the data packets to the driver high priority sending queue after completing the filling of the packet header according to the network protocol. If the data packet is a disordered high priority data packet, the data segment is recorded in the sent sequence number and placed in the disordered high priority sent queue. When the other party returns an acknowledgment packet (ACK packet) or a selection acknowledgment packet (SACK packet) requesting to send a lower priority data with a smaller sequence number, no fast retransmission is performed, until the low priority data packets sent by the low priority data packet sending module 402 are confirmed and then released uniformly, or retransmitted after TCP timeout occurs.
[0071] Low priority data packet sending module (402): The network protocol stack then processes the low priority data packet to be sent that is placed in the TCP low priority sending buffer by the low priority application transceiver interface module 303, fills in the header part according to the network protocol, sends it to the driver low priority sending queue, and records the data segment in the sent sequence number and puts it into the sent waiting to be confirmed queue. After receiving the confirmation packet (ACK packet) sent back by the other end, if there is out-of-order high priority data that is sent and to be confirmed by the TCP data packet sending module 401, the confirmation packet will confirm these two data segments together, and the confirmed sent low priority data packet will be released together with the high priority data packet.
[0072] Driver layer data packet priority sending module (403): When the driver layer processes the data packets placed in the driver sending queue by the TCP data packet sending module 401 and the low priority data packet sending module 402, it gives priority to sending the data packets in the high priority sending queue to the network card, and then sends the data packets in the low priority queue, or adopts other priority queue scheduling algorithms.
[0073] The following is an example of the present invention.
[0074] Figure 3A It is a flow chart of the protocol stack packet receiving processing method of the present invention. Figure 3B Schematic diagram of TCP out-of-order priority receiving example of the present invention. Figure 3A , 3B As shown:
[0075] The client needs to send a high-priority request with a length of 100. The upper-layer application passes the data to the protocol stack, which encapsulates it in a data packet A with a sequence number of 3001, marks it as a high-priority data packet, and sends it to the server. This patent processes these requests on the server side and returns a response.
[0076] After the server receives data packet A, the network card parses the protocol header and finds that it is high-priority data, and puts it into the high-priority queue. The protocol stack checks the high-priority receiving queue and finds that there is a high-priority data packet A, and processes it. The TCP connection corresponding to data packet A currently has a byte sequence number of 2000 to be received, and the low-priority data packets with sequence numbers 2001-3000 are still in the low-priority receiving queue. The protocol stack records the high-priority data 3001-3100 that have been received out of order in the TCP connection, stores the data packet in the high-priority receiving buffer, and generates a high-priority epoll packet receiving event; then, the protocol stack receives the low-priority data packet, receives the data packet with sequence number 2001 and data length 1000 in the stream, updates the byte sequence number to be received to 3001, checks the high-priority data processing information in TCP, and finds that 3001-3100 have been received out of order, then updates the byte sequence number to be received of the TCP connection to 3101, returns an ACK confirmation data packet to the client, confirms the sequence number is 3101, and generates a low-priority epoll data arrival event. After receiving the high-priority packet receiving event, the upper-layer application calls the read_pri() interface to receive the high-priority request data out of order. After receiving 100 bytes of high-priority data, it performs application logic processing on the request, and then calls the standard socket interface read() to receive the low-priority request.
[0077] Figure 4A It is a flow chart of the protocol stack packet processing method of the present invention. Figure 4B Schematic diagram of TCP out-of-order priority transmission example of the present invention. Figure 4A , 4B As shown:
[0078] After the upper-layer application processes the request, it sends a response. The current application needs to send a high-priority response data of 100 bytes in length. Through send(fd,buf,len,MSG_HIGHPRI), it marks its sequence number as 6001-6100 and stores it in the TCP high-priority send buffer. When the TCP protocol stack sends packets, there are still low-priority data with sequence numbers 4000-6000 in the low-priority buffer of the connection that have not been sent. The high-priority data packets with TCP sequence numbers 6001-6100 are sent to the high-priority send queue of the network card driver first, and their sequence numbers are recorded in the sent data and stored in the disordered high-priority sent queue. Then, the low-priority data with sequence numbers 4000-6000 are sent to the low-priority send queue of the network card driver, and their sequence numbers are recorded in the sent data and stored in the sent queue. The network card driver preferentially sends the high-priority data packets in the high-priority send queue to the network through the network card, and then sends the low-priority data packets in the low-priority send queue to the network through the network card.
[0079] After the other client receives the response from the server through the network, if it supports out-of-order priority TCP, it will directly process the high-priority data of sequence numbers 6001-6100 and submit it to the upper-layer application; if the client is a standard TCP protocol stack, it will put the data packets of sequence numbers 6001-6100 into the out-of-order queue after receiving them, and submit the data of sequence numbers 4000-6100 to the upper-layer application together after receiving the data packets of sequence numbers 4000-6000. After receiving all the data, the client returns a confirmation packet (ACK packet) to confirm that the data of byte sequence numbers 4000-6100 in the TCP stream have been received. After receiving the confirmation packet, the receiving end releases the low-priority data packets and high-priority data packets in the sent queue together.
[0080] Figure 5 Schematic diagram of the data processing device of the present invention. Figure 5As shown, an embodiment of the present invention further provides a computer-readable storage medium, and a data processing device. The computer-readable storage medium of the present invention stores computer-executable instructions. When the computer-executable instructions are executed by the processor of the data processing device, the above-mentioned TCP data packet sending and receiving method supporting priority disorder is implemented as a network node. A person of ordinary skill in the art can understand that all or part of the steps in the above method can be completed by instructing related hardware (such as a processor, FPGA, ASIC, etc.) through a program, and the program can be stored in a readable storage medium, such as a read-only memory, a disk or an optical disk, etc. All or part of the steps in the above embodiment can also be implemented using one or more integrated circuits. Accordingly, each module in the above embodiment can be implemented in the form of hardware, such as implementing its corresponding functions through an integrated circuit, or in the form of a software function module, such as implementing its corresponding functions through a processor executing a program / instruction stored in a memory. The embodiment of the present invention is not limited to any specific form of combination of hardware and software.
[0081] The above implementation modes are only used to illustrate the present invention, but not to limit the present invention. Ordinary technicians in the relevant technical field can make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, all equivalent technical solutions also belong to the scope of the present invention. The patent protection scope of the present invention should be defined by the claims.
Claims
1. A method for sending and receiving TCP data packets supporting out-of-order priorities, characterized in that: include: After receiving the data packets, the high priority received data packets are placed in the first processing queue, and the low priority received data packets are placed in the second processing queue; The TCP protocol stack places the high-priority received data packet into the first receiving buffer, notifies the upper-layer application to immediately receive and process it, and places the low-priority received data packet into the second receiving buffer, waiting for the upper-layer application to process it; the upper-layer application receives and sends the data packet through a data interface that supports out-of-order transmission and reception of high-priority data; When data is to be sent externally, a high-priority send data packet is placed in a first send buffer, and a low-priority send data packet is placed in a second send buffer, and the TCP protocol stack generates a send order in which the high-priority send data packet is first and the low-priority send data packet is later for data transmission; wherein, for out-of-order high-priority send data packets, the current data fragment is recorded in the sent sequence number and placed in an out-of-order high-priority sent queue for transmission; for the low-priority send data confirmation packet or selection confirmation packet with the sent sequence number in front returned by the receiver, no fast retransmission is performed until the low-priority data packet corresponding to the low-priority send data is confirmed and then released, or retransmitted after TCP times out.
2. The TCP data packet sending and receiving method according to claim 1, wherein: When the upper layer application processes the high priority received data packet: If the program of the upper layer application adopts non-blocking IO programming logic based on the event framework, the high priority received data packet is immediately received for processing; If the program uses blocking IO programming logic, and the current connection is blocked in the high-priority data receiving state, the high-priority receiving data packet is immediately received for processing; if the current connection is blocked in the low-priority data receiving state, it returns from the blocking state and enters the high-priority data receiving state; If the program adopts the non-blocking IO programming logic based on select, a high-priority packet receiving file descriptor set is constructed. When there is a high-priority receiving data packet to be received, the corresponding descriptor in the corresponding high-priority receiving data packet file descriptor set is set to notify the upper layer application to receive the high-priority receiving data packet for processing; If the program adopts non-blocking IO programming logic based on poll(), a parameter fds_pri is added to return the socket file descriptor with high priority data to be received, so as to notify the upper layer application to receive the high priority received data packet for processing.
3. The TCP data packet sending and receiving method according to claim 1, wherein: When receiving the high priority data packet, if there are any low priority data segments with earlier receiving sequence numbers that have not been received, the TCP stream information records that the data segments have been received out of order with high priority, and no confirmation packet for the data segments is returned to the sender.
4. The TCP data packet sending and receiving method according to claim 1, wherein: The upper-layer application calls the high-priority out-of-order receiving interface read_pri(int fd, char *buff, int len, int *offset, int *rcvnxt) to receive out-of-order high-priority receive data packets, where fd represents the socket that needs to receive data, buff represents the buffer used to receive data, len represents the length of the receive buffer buff, offset represents the sequence number of the data fragment of the high-priority receive data packet returned in the TCP stream, and rcvnxt represents the sequence number of the next data fragment received in sequence by the current TCP stream returned in the TCP stream.
5. The TCP data packet sending and receiving method according to claim 1, wherein: The upper-layer application calls the high-priority out-of-order receiving interface read_pri(int fd, char *buff, int len, int *jump_len) to receive out-of-order high-priority receive data packets, where fd represents the socket that needs to receive data, buff represents the buffer for receiving data, len represents the length of the receive buffer buff, and jump_len represents the byte portion skipped between the next data segment to be received in sequence by the current TCP stream and the high-priority out-of-order data segment received by this call, and the byte portion is the unreceived low-priority data segment and the received high-priority data segment.
6. The TCP data packet sending and receiving method according to claim 1, wherein: When the upper layer application calls the high priority out-of-order sending interface, the idle flag bit is enabled as the high priority flag bit in the flags parameter of the socket interface send() to mark the data to be sent as high priority.
7. A TCP data packet transceiving system supporting out-of-order priorities, characterized in that: include: The TCP data packet receiving module is used to receive data packets and put the data packets into buffers of corresponding priorities according to the priorities of the data packets; A packet receiving notification module is used to notify the upper layer application to receive the data packet according to the priority of the data packet; Upper layer application data transceiver module; Used to receive and send the data packet through a data interface that supports out-of-order transmission and reception of high priority data; The TCP data packet sending module is used to send and process the data packets stored in the TCP sending buffer by the upper-layer application on the packet sending path; among them, for out-of-order high-priority sending data packets, the current data fragment is recorded in the sent sequence number and put into the out-of-order high-priority sent queue for sending; for the low-priority sending data confirmation packet or selection confirmation packet with the previous sent sequence number returned by the receiver, no fast retransmission is performed until the low-priority data packet corresponding to the low-priority sending data is confirmed and then released, or retransmitted after TCP timeout occurs.
8. A computer-readable storage medium storing computer-executable instructions, characterized in that: When the computer executable instructions are executed, the TCP data packet sending and receiving method supporting priority disorder as described in any one of claims 1 to 6 is implemented.
9. A data processing device, comprising the computer-readable storage medium as described in claim 8, when the processor of the data processing device calls and executes the computer-executable instructions in the computer-readable storage medium, the data processing device acts as a network node to perform TCP data packet transmission and reception supporting out-of-order priorities.
