CN114143268B - Message receiving method and device based on TCP, electronic equipment and storage medium - Google Patents

Message receiving method and device based on TCP, electronic equipment and storage medium Download PDF

Info

Publication number
CN114143268B
CN114143268B CN202111238367.3A CN202111238367A CN114143268B CN 114143268 B CN114143268 B CN 114143268B CN 202111238367 A CN202111238367 A CN 202111238367A CN 114143268 B CN114143268 B CN 114143268B
Authority
CN
China
Prior art keywords
message segment
message
segment
current
cached
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111238367.3A
Other languages
Chinese (zh)
Other versions
CN114143268A (en
Inventor
刘学毅
马效波
闫峥
张少真
成丹
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Space Star Technology Co Ltd
Original Assignee
Space Star Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Space Star Technology Co Ltd filed Critical Space Star Technology Co Ltd
Priority to CN202111238367.3A priority Critical patent/CN114143268B/en
Publication of CN114143268A publication Critical patent/CN114143268A/en
Application granted granted Critical
Publication of CN114143268B publication Critical patent/CN114143268B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/70Admission control; Resource allocation
    • H04L47/72Admission control; Resource allocation using reservation actions during connection setup
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/32Flow control; Congestion control by discarding or delaying data units, e.g. packets or frames
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/163In-band adaptation of TCP data exchange; In-band control procedures

Abstract

The application discloses a message receiving method and device based on TCP, electronic equipment and a storage medium, wherein the message receiving method based on TCP can comprise the following steps: if the current message segment is not the s-th sequence message segment to be received, determining that the current message segment is a current disordered message segment; wherein s is a positive integer; if two cached message segments exist, determining whether a preset condition is met between the current disordered message segment and the cached message segment, and obtaining a determination result; wherein, the cached message segment is: historical disordered message segments; the meeting of the preset conditions between the current disordered message segment and the cached message segment comprises the following steps: the current disordered message segment and the cached message segment content are continuous or have overlapped content; the N is smaller than or equal to the preset maximum number M of the message segments allowed to be cached; and determining whether to cache the current disordered message segment according to the determination result.

Description

Message receiving method and device based on TCP, electronic equipment and storage medium
Technical Field
The present invention relates to the field of network technologies, and in particular, to a method and apparatus for receiving a message based on a transmission control protocol (Transmission Control Protocol, TCP), an electronic device, and a storage medium.
Background
The receive functions of the TCP layer generally include:
receiving a segment from a network protocol (Internet Protocol, IP) layer;
analyzing the packet header information;
according to the correspondence of sequence numbers and addressesCaching the data in a cache area;
executing window control, and timely submitting the data received by the positive sequence to an application layer;
and maintaining the out-of-order message.
The maintenance mode for the out-of-order message comprises the following steps: messages all falling within the window are cached and identified by using a linked list or a data identification bit, but the adoption of the caching mode can cause extremely high storage cost.
Disclosure of Invention
The embodiment of the application provides a message receiving method and device based on TCP, electronic equipment and a storage medium.
An embodiment of the present application provides a method for receiving a message based on a transmission control protocol TCP, including:
if the current message segment is not the s-th sequence message segment to be received, determining that the current message segment is a current disordered message segment;
if N cached message segments exist, determining whether a preset condition is met between the current disordered message segment and the cached message segment, and obtaining a determination result; wherein, the cached message segment is: historical disordered message segments; the meeting of the preset conditions between the current disordered message segment and the cached message segment comprises the following steps: the current disordered message segment and the cached message segment content are continuous or have overlapped content; the N is smaller than or equal to the preset maximum number M of the message segments allowed to be cached;
And determining whether to cache the current disordered message segment according to the determination result.
Based on the above scheme, the determining whether to cache the current disordered message segment according to the determination result includes:
discarding the current disordered message segment when the determined result shows that the current disordered message segment and the cached message segment do not meet the preset condition;
or,
and caching the current message segment when the N is smaller than the M and the current message segment and the cached message segment do not meet the preset condition.
Based on the above scheme, the determining whether to cache the current disordered message segment according to the determination result further includes:
and if the current disordered message segment and the cached message segment meet the preset conditions, determining an operation executed on a first message segment according to the current disordered message segment, wherein the first message segment is any one of N cached message segments.
Based on the above scheme, if the current disordered message segment and the cached message segment meet the preset condition, determining an operation performed on the first message segment according to the current disordered message segment, where the operation includes at least one of the following:
If the message content of the current disordered message segment is contained in the first message segment, determining to maintain the first message segment;
if part of the content of the current disordered message segment is contained in the first message segment or the current disordered message segment is continuous with the content of the first message segment, updating the first message segment according to the current disordered message segment to obtain a first updated message segment, and caching the first updated message segment; wherein, the first update message segment includes: and the content which is not currently contained in the first message segment in the current disordered message segment.
Based on the above scheme, the method further comprises:
and discarding the current disordered message segment if at least part of the content of the first updated message segment is positioned outside the receiving window.
Based on the above scheme, the caching the first update segment includes:
and if the first updating message segment is positioned in the receiving window, caching the first updating message segment.
Based on the above scheme, the method further comprises:
if the preset condition is met between the first updating message segment and the second message segment, combining the first updating message segment and the second message segment to obtain a second updating message segment; wherein the second message segment is a cached message segment other than the first message segment in the N cached message segments;
And caching the second updated message segment.
Based on the above scheme, the caching the second update segment includes:
and if the second updating message segment is positioned in the receiving window, caching the second updating message segment.
Based on the above scheme, the method further comprises:
and discarding the current out-of-order message segment when the second updated message segment is at least partially outside the receiving window.
Based on the above scheme, the method further comprises:
if the current message segment is the s-th sequence message segment;
and submitting the s-th sequence message segment to an application layer.
Based on the above scheme, the method further comprises:
when the current message segment is the s-th sequence message segment, determining whether the cached message segment and the s-th sequence message segment meet the preset condition or not;
submitting the cached message segments meeting the preset conditions between the s-th sequence message segment and the application layer;
and deleting the cached message segment submitted to the application layer.
Based on the above scheme, the method further comprises:
when a message segment is submitted to the application layer, updating the information of the s-th sequence message segment to be received and a receiving window according to the submitted message segment to the application layer.
Based on the above scheme, the method further comprises:
updating at least one of the N cached message segments, and updating the boundary information of the cached message segments according to the updated cached message segments, wherein the boundary information comprises: information indicating a left boundary corresponding to the cached segment and information indicating a right boundary corresponding to the cached segment.
A second aspect of the embodiments of the present application provides a packet receiving device based on a transmission control protocol TCP, where the device includes:
the first determining module is used for determining that the current message segment is a current disordered message segment if the current message segment is not the s-th sequence message segment to be received;
the second determining module is used for determining whether the current disordered message segment and the cached message segment meet the preset condition or not if N cached message segments exist, and obtaining a determining result; wherein, the cached message segment is: historical disordered message segments; the meeting of the preset conditions between the current disordered message segment and the cached message segment comprises the following steps: the current disordered message segment and the cached message segment content are continuous or have overlapped content; the N is smaller than or equal to the preset maximum number M of the message segments allowed to be cached;
And the caching module is used for determining whether to cache the current disordered message segment according to the determination result.
A third aspect of an embodiment of the present disclosure provides an electronic device, including:
a memory;
and the processor is connected with the memory and is used for executing the computer executable instructions stored on the memory to realize the message receiving method based on the TCP provided by any technical scheme.
A fourth aspect of the disclosed embodiments provides a computer storage medium, wherein the computer storage medium stores computer-executable instructions; after the computer executable instruction is executed by the processor, the TCP-based message receiving method provided by any technical scheme is realized.
According to the technical scheme provided by the embodiment of the disclosure, firstly, the disordered messages are allowed to be cached, but the number of the cached disordered messages is N, so that on one hand, compared with the disordered messages, the subsequent re-request is directly discarded, the repeated request and the repeated transmission can be reduced, on the other hand, the number of the disordered messages is limited, the storage overhead occupied by the disordered messages can be reduced to a great extent, and the balance between the repeated transmission and the storage overhead is realized.
Drawings
Fig. 1 is a flow chart of a method for receiving a TCP-based message according to an embodiment of the present application;
fig. 2 is a flow chart of a method for receiving a TCP-based message according to an embodiment of the present application;
fig. 3 is a schematic diagram of message reception provided in an embodiment of the present application;
fig. 4 is a schematic structural diagram of a TCP-based packet receiving device according to an embodiment of the present application;
fig. 5 is a schematic diagram corresponding to a field stored in a register according to an embodiment of the disclosure;
fig. 6 is a flow chart of a method for receiving a TCP-based message according to an embodiment of the present application;
fig. 7 is a flow chart of a method for receiving a TCP-based message according to an embodiment of the present application;
fig. 8 is a flow chart of a method for receiving a TCP-based message according to an embodiment of the present application. .
Detailed Description
So that the manner in which the features and aspects of the present application can be understood in more detail, a more particular description of the invention, briefly summarized above, may be had by reference to the appended drawings, which are not intended to be limiting of the present application.
As shown in fig. 1, an embodiment of the present disclosure provides a method for receiving a TCP-based message, including:
s110: if the current message segment is not the s-th sequence message segment to be received, determining that the current message segment is a current disordered message segment;
S120: if N cached message segments exist, determining whether a preset condition is met between the current disordered message segment and the cached message segment, and obtaining a determination result; wherein, the cached message segment is: historical disordered message segments; the meeting of the preset conditions between the current disordered message segment and the cached message segment comprises the following steps: the current disordered message segment and the cached message segment content are continuous or have overlapped content; the N is smaller than or equal to the preset maximum number M of the message segments allowed to be cached;
s130: and determining whether to cache the current disordered message segment according to the determination result.
The message receiving method based on TCP provided by the embodiment of the disclosure is applied to a message receiving end. The receiving end can be any network device. The network device may be: a terminal and/or a server. The terminals include, but are not limited to: a fixed terminal and/or a mobile terminal. The fixed terminal includes: desktop computers, smart televisions, or advertisement playing devices, etc. The mobile terminal includes, but is not limited to: cell phones, tablets, wearable devices, smart home devices, smart office devices, and/or various smart robots. The intelligent robot includes, but is not limited to: including ground robots that move the chassis and/or flying robots that fly low-altitude.
The receiving end may include: and the field programmable gate array (Field Programmable Gate Array, FPGA) chip is used for submitting the message segment received by the IP layer to the TCP layer, and submitting the message segment to the application layer by the TCP layer to realize message transceiving before the application layer.
If the currently received message segment is the first message segment, if the number of the message segment is counted from 0, the s-th sequence message segment is message segment 0; if the number of the message segment is counted from 1, the s-th sequence message segment is the message segment 1. If the currently received message segment is not the first message segment, the currently received message segment is the message segment m+1 submitted to the application layer; m is any natural number.
If the sequence number of the currently received message segment is not matched with the sequence number of the s-th sequence message segment, the current message segment is indicated to be the disordered message segment, and the current message segment is the current disordered message segment because the current message segment is received at the current moment.
If N out-of-order message segments have been cached, it is necessary to determine whether to cache the current out-of-order message segment according to whether there is continuity or duplication of content between the current message segment and the cached message segment.
If the value of N is smaller than or equal to M; m may be any positive integer. For example, the value of M may be 2, 3 or 4, and the value of N may be 0, 1 or 2, which is any natural number smaller than M. If N is 0, it indicates that there is no cached segment currently.
In one embodiment, if the historical disordered message with the maximum number of segments is already cached currently and the current message segment is also a disordered message segment, whether the current message segment needs to be cached is determined by whether content is continuous or overlapping between the current disordered message segment and the cached message segment, so that the storage cost is high because the number of the cached disordered message segments is not limited, and the repeated transmission can be reduced compared with the case that the disordered message segment is not cached.
In some embodiments, the S130 may include:
s131: and when the determined result shows that the current disordered message segment and the cached message segment do not meet the preset condition and the N is equal to the M, discarding the current disordered message segment.
If the current disordered message segment and the cached message Duan Jibu are continuous message segments, and are not overlapped, the method indicates that if the current disordered message segment is cached, the cached disordered message segment exceeds the large segment number N, so that the current disordered message segment is discarded, and the problem of overlarge storage cost is reduced.
The current out-of-order message segment and the cached message segment are continuous message segments, and one of the following conditions is satisfied:
The last byte of the cached message segment is adjacent to the 1 st byte of the current disordered message segment;
the 1 st byte of the buffered segment and the last byte of the current out-of-order segment are adjacent bytes.
The overlapping of the current unordered message segment and the cached message segment includes:
the current out-of-order segment contains at least one byte within the cached segment.
According to the unpacking of the TCP protocol, a plurality of bytes within a segment are all distributed consecutively.
In other embodiments, the method further comprises:
and when the determined result shows that the current disordered message segment and the cached message segment do not meet the preset condition, discarding the message segment with the closest interval distance with the s-th sequence message segment from the current disordered message segment and the cached message segment.
If an out-of-order message segment is received, a request for requesting the s-th order message segment is sent again based on TCP, and therefore, based on the order request of the receiving end, the message segment with the current s-th order message segment being closer is requested earlier, so that the average buffer time length of a buffered message segment is reduced, the occupied buffer capacity is reduced by reducing the average buffer time length of a single buffered message segment, and the aim of reducing the buffer cost again is achieved.
In other embodiments, the S130 may further include:
s132: and caching the current message segment when the N is smaller than the M and the current message segment and the cached message segment do not meet the preset condition.
If N is smaller than M, it indicates that the current cached message segment has not reached the maximum segment number, and if the current received message segment is an unordered message segment, the current unordered message segment can be cached continuously.
In other embodiments, the S130 further includes:
S133A: if the current disordered message segment and the cached message segment meet the preset conditions, a first updated message segment is obtained according to the current disordered message segment and a first message segment, wherein the first message segment is any one of N cached message segments;
S133B: and caching the first updated message segment.
At this time, no matter whether N is less than or equal to M, the number of segments of the cached segments can be reduced by merging the segments according to the preset condition between the current disordered segment and each cached segment, and the caching of the repeated content is reduced.
In one embodiment, the S130 further includes:
and if the current disordered message segment and the cached message segment meet the preset conditions, determining an operation executed on a first message segment according to the current disordered message segment, wherein the first message segment is any one of N cached message segments.
The current out-of-order message segment may be because, during the transmission, the retransmission message segment or the carried byte appears to be lost or repeated due to the forwarding or packet dropping.
In this case, meeting the preset condition between the current out-of-order segment and the cached first segment can be divided into the following cases:
the content between the current disordered message segment and the first message segment is continuous and is not repeated;
all contents of the current disordered message segment are contained in the first message segment;
part of the content of the current disordered message segment is contained in the first message segment, and part of new content is also contained.
In some embodiments, the S130 may include at least one of:
if the current disordered message segment and the cached message segment meet the preset conditions, a first updated message segment is obtained according to the current disordered message segment and a first message segment, wherein the first message segment is any one of N cached message segments;
and caching the first updating message.
That is, the operations on the first segment are different for different situations, and the following are respectively analyzed in combination with the above cases:
case 1: if all the contents of the current disordered message segment are contained in the first message segment, the first message segment is not updated, and the current buffer status of the first message segment is maintained; the current first message segment is the first updated message segment;
Case 2: part of the content of the current disordered message section is contained in the first message section, and the content which is not contained in the first message section in the current message section is added into the first message section to obtain a first updated message section after the content is added;
case 3: and if the whole content of the current disordered message segment is not contained in the first message segment, directly combining the current message segment with the first message segment to obtain a combined first updated message segment.
The subsequent first updated segment will be the cached segment at the next time.
According to the above listed different situations, the obtaining a first updated message segment according to the current disordered message segment and the first message segment includes at least one of the following:
if the message content of the current disordered message segment is contained in the first message segment, determining that the first message segment is the first updated message segment;
if part of the content of the current disordered message section is contained in the first message section, adding the content of the current disordered message section which is not contained in the first message section to obtain the first updated message section;
and if the current disordered message segment is continuous with the first message segment, merging the first message segment and the current disordered message segment to obtain a first updated message segment.
In some embodiments, the method further comprises:
a receive window is configured that limits the maximum number of cache bytes P.
The window length of the receiving window shown in fig. 3 is 8 bytes, i.e., p=8. The first byte of the receive window is the kth byte.
The start of a specific receive window is most closely: the first byte of the s-th sequence message segment to be received;
the termination bytes of the receive window are: p bytes. P is the maximum number of cache bytes contained in the window. P may be any positive integer.
The termination byte of the receive window minus the first byte of the receive window is equal to P, which may be greater than the maximum number of bytes contained in a segment.
In the embodiment of the disclosure, in order to inhibit large overhead of a user caused by excessive number of bytes contained in a single cached message segment, a receiving window is introduced, and how to cache the message segment is further determined through the receiving window.
Illustratively, the caching the first update segment includes:
and if the first updating message segment is positioned in the receiving window, caching the first updating message segment.
The first updating message segment is positioned in the receiving window, namely the number of the last byte of the first updating message segment is smaller than or equal to the ending byte of the current receiving window.
And if the first updating message segment is positioned in the receiving window, caching the first updating message segment, otherwise, not caching the first updating message segment.
After not caching the first update segment, the method further comprises:
discarding the current disordered message segment;
or,
and discarding one or more message segments with the smallest distance between the current messy message segment and the current s-th sequence message segment, and then caching the first updated message segment. The distance here may be embodied in bytes of space.
In some embodiments, the method further comprises:
if the preset condition is met between the first updating message segment and the second message segment, obtaining a second updating message segment according to the first updating message segment and the second message segment; wherein the second message segment is a cached message segment other than the first message segment in the N cached message segments;
and caching the second updated message segment.
If the content between the generated updated message segment and the second message segment is continuous or has content repetition, the first updated message segment and the second message segment are combined to obtain the second updated message segment.
The first message segment may be a message segment meeting a preset condition with the current disordered message segment; if the current message segment and the two cached message segments meet the preset condition, after the current message segment and one of the cached message segments are combined to obtain a first updated message segment, the first updated message segment and the other cached message segment (namely the second message segment) are in full of the preset relation.
In some embodiments, if the preset condition is satisfied between the first update segment and the second segment, determining, according to the first update segment, an operation on the second segment includes one of:
deleting the second message segment if the whole content of the second message segment is contained in the first updated message segment;
if part of the content of the second message segment is contained in the first updated message segment, adding the content of the second message segment, which is not contained in the first updated message segment, to the first updated message segment to obtain the second updated message segment;
and if the content of the second message segment is continuous with that of the first updating message segment, combining the first updating message segment and the second message segment to obtain the second updating message segment.
The second message segment here is: and any one of the cached message segments with a preset relation with the current message segment is arranged among the plurality of message segments except the first message segment.
In one embodiment, the caching the second update segment includes:
and if the second updating message segment is positioned in the receiving window, caching the second updating message segment.
In another embodiment, the method further comprises:
and discarding the current out-of-order message segment when the second updated message segment is at least partially outside the receiving window.
By setting the receiving window, the maximum bytes contained in the M message segments are set, so that the maximum buffer memory is controlled.
In some embodiments, the method further comprises:
if the current message segment is the s-th sequence message segment;
and submitting the s-th sequence message segment to an application layer.
When the TCP layer determines that the received current message segment is the s-th sequence message segment, the s-th sequence message segment is directly reported to the application layer, namely the current received sequence message segment is not cached and is directly submitted to the application layer, so that the cache occupied by the current message segment is reduced.
In some embodiments, the method further comprises:
after the s-th sequence message segment is submitted to the application layer, updating the sequence number of the s-th sequence message segment, and determining the s+1-th sequence message segment;
determining whether the (s+1) -th sequential message segment exists in the cached message segment;
when the (s+1) th sequence message segment exists in the cached message segment, submitting the (s+1) th positive sequence in the cached message segment to an application layer;
And deleting the cached message segment submitted to the application layer.
Illustratively, after the s-th sequential segment is submitted to the application layer, the s+1-th sequential segment is determined. The first byte of the s+1th sequential segment is the next byte to the last byte of the s sequential segment.
If there is a cached segment that includes the first byte in the s+1th sequential segment, the cached segment is the s+1th sequential segment.
And submitting the (s+1) th sequential message segment of the cached message segments to the application layer, and deleting the cached message segments submitted to the application layer from the cache region, so that repeated submission to the application layer is reduced, and the cached message segments can be submitted to the application layer without repeated transmission.
In some embodiments, after receiving the s-th sequential message segment, the application layer transmits a request for requesting the s+1-th sequential message segment to the sender, and if the current cached message segment includes the s+1-th sequential message segment, the request may be intercepted, so that the request triggers the sender to repeatedly transmit the s+1-th sequential message segment.
In some embodiments, the method further comprises:
When a message segment is submitted to the application layer, updating the sequence number of the sequence message segment to be received according to the submitted message segment to the application layer;
and/or the number of the groups of groups,
and updating a receiving window, wherein N cached message segments are positioned in the receiving window.
The sequence number of the updated sequential message segment is the next byte of the last byte of the message segment submitted to the application layer. The first byte of the receiving window here is the first byte+p bytes of the updated sequential message segment.
In one embodiment, the method further comprises:
at least one of the N cached message segments is updated, and according to the updated cached message segment, updating the information of the boundary corresponding to the cached message segment, wherein the information of the boundary comprises: information indicating a left boundary corresponding to the cached segment and information indicating a right boundary corresponding to the cached segment.
As shown in fig. 4, an embodiment of the present disclosure provides a TCP-based message receiving apparatus, which includes:
a first determining module 110, configured to determine that the current packet is a current disordered packet if the current packet is not an s-th sequential packet to be received; wherein s is a positive integer;
The second determining module 120 is configured to determine whether a preset condition is satisfied between the current disordered message segment and the cached message segment if N cached message segments exist, so as to obtain a determination result; wherein, the cached message segment is: historical disordered message segments; the meeting of the preset conditions between the current disordered message segment and the cached message segment comprises the following steps: the current disordered message segment and the cached message segment content are continuous or have overlapped content;
and the caching module 130 is configured to determine whether to cache the current disordered message segment according to the determination result.
In some embodiments, the first determination module 110, the second determination module 120, and the cache module 130 may be program modules; the program modules may be capable of carrying out the functions described above when executed by a processor. In some embodiments, the first determining module 110, the second determining module 120, and the buffer module 130 may be soft-hard combination modules; the soft and hard combined template comprises, but is not limited to, a programmable array; the programmable array includes, but is not limited to: a field programmable array and/or a complex programmable array.
In some embodiments, the first determination module 110, the second determination module 120, and the cache module 130 may be pure hardware modules; the pure hardware modules include, but are not limited to, application specific integrated circuits.
In some embodiments, the buffering module 130 is specifically configured to discard the current disordered message segment when the determination result indicates that the current disordered message segment and the buffered message segment do not meet the preset condition and the N is equal to the M; or when the N is smaller than the M and the current message segment and the cached message segment do not meet the preset condition, caching the current message segment.
In some embodiments, the buffer module 130 specifically obtains a first updated packet segment according to the current disordered packet segment and a first packet segment if the current disordered packet segment and the buffered packet segment meet the preset condition, where the first packet segment is any one of N buffered packet segments; and caching the first updated message segment.
In some embodiments, the buffering module 130 is specifically configured to perform at least one of the following: if the message content of the current disordered message segment is contained in the first message segment, determining that the first message segment is the first updated message segment;
if part of the content of the current disordered message section is contained in the first message section, adding the content of the current disordered message section which is not contained in the first message section to obtain the first updated message section;
And if the current disordered message segment is continuous with the first message segment, merging the first message segment and the current disordered message segment to obtain a first updated message segment.
In some embodiments, the apparatus further comprises:
and the discarding module is used for discarding the current disordered message segment if at least part of the content of the first updated message segment is positioned outside the receiving window.
In some embodiments, the buffering module 130 is specifically configured to buffer the first updated message segment if the first updated message segment is located in the receiving window.
In some embodiments, the apparatus further comprises:
the obtaining module is used for obtaining a second updated message segment according to the first updated message segment and the second message segment if the preset condition is met between the first updated message segment and the second message segment; wherein the second message segment is a cached message segment other than the first message segment in the N cached message segments;
the buffer module 130 is further configured to buffer the second update segment.
In some embodiments, the deriving module is further specifically configured to perform one of:
deleting the second message segment if the whole content of the second message segment is contained in the first updated message segment;
If part of the content of the second message segment is contained in the first updated message segment, adding the content of the second message segment, which is not contained in the first updated message segment, to the first updated message segment to obtain the second updated message segment;
and if the content of the second message segment is continuous with that of the first updating message segment, combining the first updating message segment and the second message segment to obtain the second updating message segment.
In some embodiments, the buffering module 130 is further configured to buffer the second updated segment if the second updated segment is located in the receiving window.
In some embodiments, the apparatus further comprises:
and the discarding module is used for discarding the current disordered message segment when the second updated message segment is at least partially positioned outside the receiving window.
In some embodiments, the apparatus further comprises:
and the reporting module is used for submitting the s-th sequence message segment to an application layer if the current message segment is the s-th sequence message segment.
In some embodiments, the apparatus further comprises:
the updating module is used for updating the sequence number of the s-th sequence message segment after the s-th sequence message segment is submitted to the application layer, and determining the s+1-th sequence message segment;
The existence module is used for determining whether the s+1th sequence message segment exists in the cached message segment;
the reporting module is further configured to submit the s+1st positive sequence in the cached packet segment to an application layer when the s+1st sequential packet segment exists in the cached packet segment;
and the caching module 130 is configured to delete the cached packet segment submitted to the application layer.
In some embodiments, the apparatus further comprises:
the sequence number module is used for updating the sequence number of the sequence message segment to be received according to the message segment submitted to the application layer when the message segment is submitted to the application layer;
and/or the number of the groups of groups,
and the window module is used for updating a receiving window, wherein N cached message segments are positioned in the receiving window.
In some embodiments, the apparatus further comprises:
and a boundary information module, configured to update at least one of the N cached packet segments, and update information of a boundary corresponding to the cached packet segment according to the updated cached packet segment, where the boundary information includes: information indicating a left boundary corresponding to the cached segment and information indicating a right boundary corresponding to the cached segment.
The information of the boundary may be: the sequence number of the first byte and the sequence number of the last byte of the buffered segment.
If N cached message segments are cached currently, the message segments have N left boundary information and N right boundary information. The information of the left boundary indicates the first byte of the corresponding cached message segment; the information of the right boundary indicates the last byte of the corresponding buffered segment.
The embodiment of the disclosure provides a method for supporting TCP (transmission control protocol) out-of-order reception based on FPGA (field programmable gate array), and the processing capacity of the scheme is described as follows:
1) Two unordered message segments without content overlap can be received;
2) If the third segment is a sequentially received message, i.e., the currently received third segment is a sequential segment, normal processing may be performed on the sequential segment (normal processing herein includes, but is not limited to: directly submitted to the application layer), if the message segment is an unordered message segment and has no overlapping part with the first two unordered message segments, the message segment is discarded. The first two out-of-order message segments are the cached message segments. In this embodiment, an example is illustrated with m=2.
If the currently received disordered message segment and the disordered message segments of the first two caches have overlapping parts, the disordered message segment situation needs to be processed according to the situation of the overlapping parts.
The method for supporting the out-of-order receiving of the TCP protocol based on the FPGA chip is suitable for the field of realizing data interconnection communication among devices through the Ethernet TCP protocol. The FPGA chip realizes the TCP protocol and releases the load of the processing of the general processor software. The method is characterized in that: supporting a certain degree of disorder processing of TCP protocol message segments; and by adopting a pipeline processing mode, the storage resources of the FPGA chip are occupied very little.
So-called support for a degree of out-of-order processing: two unordered message segments without overlapping relation can be received; if the third message segment is received in sequence, the message segment can be processed normally, and if the message segment is an unordered message segment and has no overlapping part with the first two unordered message segments, the message segment is lost. The scheme can cover more than 95% of disorder conditions of the TCP protocol in practical application.
The method adopts a pipeline processing mode, and on the premise of guaranteeing the FPGA time sequence, the FPGA finishes receiving an out-of-order message segment in five periods, occupies little storage resource of the FPGA, and has low implementation complexity and high protocol reliability. The receive window control logic includes two parts of content:
receiving maintenance of a window pointer;
and (5) maintaining the out-of-order message segments.
(1) Maintenance of receive window pointers
A schematic view of the receive window is shown in fig. 5. The specific meaning of the identifiers appearing in the figures is shown in table 5. rx_dat points to the first byte of sequential data, rx_nxt points to the next sequential data expected to be received, and rx_wnd identifies the size of the receive window, which is not affected by out-of-order data.
Wherein the change of rx_dat is implemented in a storage management module, which uses the variable when calculating the right boundary of the receiving window. The change of rx_nxt is implemented by the present module and informs the storage management module, which uses the variable to determine the end position of the sequential data to supply the application layer read.
Table 1 register management module interface description
TABLE 1
(2) Out-of-order message segment maintenance
As shown in fig. 6 and 7, the receiving end maintains a register with two entries, each entry having a valid bit set. For a newly received message segment, the processing procedure is as follows:
kth cycle (data arrival): calculating the left boundary information (the sequence number of the first byte) and the right boundary information (the sequence number of the last byte) of the message segment according to the sequence number and the length of the current message segment; meanwhile, the information of the left boundary of the window, the information of the left and right boundaries of the disordered message segment 1 and the information of the left and right boundaries of the disordered message segment 2 are known.
Cycle k+1: six boundary values (left and right boundaries of sequential segment, out-of-order segment 1, out-of-order segment 2) are subtracted from the left boundary of the window. The boundary values may include: the boundary value is one of information of the boundary as a serial number of the edited byte.
K+2th cycle: performing boundary comparison according to the difference result calculated in the first period, including: the left boundary of the message segment is compared with the left boundary of the window, the left boundary of the message segment is compared with four disordered boundaries, the right boundary of the message segment is compared with four disordered boundaries, the left boundary of the disordered message segment 1 is compared with the right boundary of the disordered message segment 2, and the left boundary of the disordered message segment 2 is compared with the right boundary of the disordered message segment 1.
The operation of the k+2 cycle may be as follows:
if the message is a sequential message segment, the rx_nxt is modified to be the last byte sequence number plus 1, and the case includes a message segment with the sequence number smaller than the rx_nxt, but the sum of the sequence number and the length is larger than or equal to the rx_nxt.
If the message is an out-of-order message segment, comparing the sequence number of the first and last bytes of the current message segment with the sequence number in the effective list item, and modifying the list item.
The operation of the k+3 cycle may be as follows:
if the message is a sequence message segment, judging the relation between the rx_nxt and the disordered message segment 1, and if the table item connected with the rx_nxt exists, setting the table item as invalid after modifying the value of the rx_nxt;
If the message is an unordered message segment, if the unordered message segment 1 is invalid and the unordered message segment 2 is not updated, the message segment is stored in the unordered message segment 1; if the out-of-order message segment 1 is valid, the out-of-order message segment 2 is invalid, and the out-of-order message segment 1 is not updated, the data is stored in the out-of-order message segment 2.
The operation of the k+4 cycle may be as follows:
if the message is a sequence message segment, judging the relation between the rx_nxt and the disordered message segment 2, and if the table item connected with the rx_nxt exists, setting the table item as invalid after modifying the value of the rx_nxt;
if the message segment is an out-of-order message segment, the left boundary of the message segment is not equal to the left boundary of the window, and the out-of-order message segment 1 and the out-of-order message segment 2 are both valid (before updating): if the left boundary of the message segment is smaller than or equal to the right boundary of the disordered message segment 1 and the right boundary of the message segment is larger than or equal to the left boundary of the disordered message segment 2, and the left boundary of the disordered message segment 2 is larger than the right boundary of the disordered message segment 1: and assigning the right boundary of the disordered message segment 2 to the right boundary of the disordered message segment 1, wherein the disordered message segment 2 is invalid. If the left boundary of the message segment is smaller than or equal to the right boundary of the disordered message segment 2 and the right boundary of the message segment is larger than or equal to the left boundary of the disordered message segment 1, and the left boundary of the disordered message segment 1 is larger than the right boundary of the disordered message segment 2: and assigning the right boundary of the disordered message segment 1 to the right boundary of the disordered message segment 2, wherein the disordered message segment 1 is invalid.
An example of the processing of this scheme may be as shown in fig. 8. The rx_nxt (the sequence number of the first byte of the next sequential message expected to be received) has a value of 1, and three segments arrive sequentially, and the left and right boundaries of the segments are bytes (2, 3), (5, 7), and (3, 8), respectively.
And if the sequence numbers (2, 3) of the bytes contained in the first message segment are judged to be disordered message segments, storing the left and right boundaries, wherein the table entry of the disordered message segment 1 is valid (T indicates that the table entry is valid and F indicates that the table entry is invalid).
Judging that the sequence numbers (5, 7) of the bytes contained in the second message segment are disordered message segments, and storing left and right boundaries without intersection with the table items of the disordered message segment 1, wherein the table items of the disordered message segment 2 are valid; the sequence numbers (3, 8) of the bytes contained in the third message segment are disordered message segments, but the sequence numbers are intersected with the list items of the disordered message segment 1 and the disordered message segment 2, and after the disordered message segment 1 and the disordered message segment 2 are updated, the sequence numbers and the list items of the disordered message segment 1 are in a containing relationship, and finally, the list items of the disordered message segment 1 are valid, and the list items of the disordered message segment 2 are invalid.
Through verification, the scheme can cover more than 95% of message segment receiving disorder condition of TCP protocol in practical application, occupies little storage resource of FPGA chip, has low realization complexity and high protocol reliability, and can be widely used in various disorder receiving application environments. The method has the defects that the scheme cannot process the situation that the third disordered message segment is not associated with the first two disordered message segments, but the TCP protocol is provided with a retransmission mechanism, and the retransmission of a small amount of discarded messages has small influence on the protocol.
An embodiment of the present disclosure provides an electronic device, including:
a memory;
and the processor is connected with the memory and is used for executing the computer executable instructions stored on the memory to realize the message receiving method based on TCP provided by any embodiment.
The electronic device may be any receiving device that receives a message, and the receiving device may include an FPGA chip that receives a message. The processor may include the FPGA chip.
Embodiments of the present disclosure provide a computer storage medium having stored thereon computer-executable instructions; the computer executable instructions, when executed by the processor, are capable of implementing the TCP-based message receiving method provided by any of the foregoing embodiments.
The technical solutions described in the embodiments of the present application may be arbitrarily combined without any conflict.
In several embodiments provided in the present application, it should be understood that the disclosed method and intelligent device may be implemented in other manners. The above described device embodiments are only illustrative, e.g. the division of the units is only one logical function division, and there may be other divisions in practice, such as: multiple units or components may be combined or may be integrated into another system, or some features may be omitted, or not performed. In addition, the various components shown or discussed may be coupled or directly coupled or communicatively coupled to each other via some interface, whether indirectly coupled or communicatively coupled to devices or units, whether electrically, mechanically, or otherwise.
The units described as separate units may or may not be physically separate, and units displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units; some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in each embodiment of the present application may be integrated in one second processing unit, or each unit may be separately used as one unit, or N or more units may be integrated in one unit; the integrated units may be implemented in hardware or in hardware plus software functional units.
The foregoing is merely specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily think about changes or substitutions within the technical scope of the present application, and the changes and substitutions are intended to be covered by the scope of the present application.

Claims (17)

1. A message receiving method based on a transmission control protocol TCP, comprising:
If the current message segment is not the s-th sequence message segment to be received, determining that the current message segment is a current disordered message segment; wherein s is a positive integer;
if N cached message segments exist, determining whether a preset condition is met between the current disordered message segment and the cached message segment, and obtaining a determination result; wherein, the cached message segment is: historical disordered message segments; the meeting of the preset conditions between the current disordered message segment and the cached message segment comprises the following steps: the current disordered message segment and the cached message segment content are continuous or have overlapped content; the N is smaller than or equal to the preset maximum number M of the message segments allowed to be cached;
determining whether to cache the current disordered message segment according to the determination result; and determining whether to cache the current disordered message segment according to the determination result, wherein the determining comprises the following steps: and when the determined result shows that the current disordered message segment and the cached message segment do not meet the preset condition, discarding the message segment with the closest interval distance between the current disordered message segment and the cached message segment and the s-th sequence message segment.
2. The method according to claim 1, wherein determining whether to cache the current out-of-order segment according to the determination result comprises:
discarding the current disordered message segment when the determined result shows that the current disordered message segment and the cached message segment do not meet the preset condition and the N is equal to the M;
or,
and caching the current message segment when the N is smaller than the M and the current message segment and the cached message segment do not meet the preset condition.
3. The method according to claim 1 or 2, wherein determining whether to cache the current out-of-order segment according to the determination result further comprises:
if the current disordered message segment and the cached message segment meet the preset conditions, a first updated message segment is obtained according to the current disordered message segment and a first message segment, wherein the first message segment is any one of N cached message segments;
and caching the first updated message segment.
4. The method of claim 3, wherein the obtaining a first updated segment from the current out-of-order segment and the first segment comprises at least one of:
If the message content of the current disordered message segment is contained in the first message segment, determining that the first message segment is the first updated message segment;
if part of the content of the current disordered message section is contained in the first message section, adding the content of the current disordered message section which is not contained in the first message section to obtain the first updated message section;
and if the current disordered message segment is continuous with the first message segment, merging the first message segment and the current disordered message segment to obtain a first updated message segment.
5. The method according to claim 4, wherein the method further comprises:
and discarding the current disordered message segment if at least part of the content of the first updated message segment is positioned outside the receiving window.
6. The method of claim 5, wherein the buffering the first update segment comprises:
and if the first updating message segment is positioned in the receiving window, caching the first updating message segment.
7. The method of claim 5, wherein the method further comprises:
if the preset condition is met between the first updating message segment and the second message segment, obtaining a second updating message segment according to the first updating message segment and the second message segment; wherein the second message segment is a cached message segment other than the first message segment in the N cached message segments;
And caching the second updated message segment.
8. The method of claim 7, wherein if the preset condition is satisfied between the first updated segment and the second segment, determining the operation on the second segment according to the first updated segment comprises one of:
deleting the second message segment if the whole content of the second message segment is contained in the first updated message segment;
if part of the content of the second message segment is contained in the first updated message segment, adding the content of the second message segment, which is not contained in the first updated message segment, to the first updated message segment to obtain the second updated message segment;
and if the content of the second message segment is continuous with that of the first updating message segment, combining the first updating message segment and the second message segment to obtain the second updating message segment.
9. The method of claim 7, wherein the buffering the second update segment comprises:
and if the second updating message segment is positioned in the receiving window, caching the second updating message segment.
10. The method according to claim 9, wherein the method further comprises:
And discarding the current out-of-order message segment when the second updated message segment is at least partially outside the receiving window.
11. The method according to claim 1, wherein the method further comprises:
and if the current message segment is the s-th sequence message segment, submitting the s-th sequence message segment to an application layer.
12. The method of claim 11, wherein the method further comprises:
after the s-th sequence message segment is submitted to the application layer, updating the sequence number of the s-th sequence message segment, and determining the s+1-th sequence message segment;
determining whether the (s+1) -th sequential message segment exists in the cached message segment;
when the (s+1) th sequence message segment exists in the cached message segment, submitting the (s+1) th positive sequence in the cached message segment to an application layer;
and deleting the cached message segment submitted to the application layer.
13. The method according to claim 11 or 12, characterized in that the method further comprises:
when a message segment is submitted to the application layer, updating the sequence number of the sequence message segment to be received according to the submitted message segment to the application layer;
and/or the number of the groups of groups,
And updating a receiving window, wherein N cached message segments are positioned in the receiving window.
14. The method according to any one of claims 1 to 2 or 4 to 12, further comprising:
at least one of the N cached message segments is updated, and according to the updated cached message segment, updating the information of the boundary corresponding to the cached message segment, wherein the information of the boundary comprises: information indicating a left boundary corresponding to the cached segment and information indicating a right boundary corresponding to the cached segment;
the information of the boundary may be: the sequence number of the first byte and the sequence number of the last byte of the cached message segment;
if N cached message segments are cached currently, the message segments have N left boundary information and N right boundary information; the information of the left boundary indicates the first byte of the corresponding cached message segment; the information of the right boundary indicates the last byte of the corresponding buffered segment.
15. A message receiving apparatus based on a transmission control protocol TCP, the apparatus comprising:
the first determining module is used for determining that the current message segment is a current disordered message segment if the current message segment is not the s-th sequence message segment to be received; wherein s is a positive integer;
The second determining module is used for determining whether the current disordered message segment and the cached message segment meet the preset condition or not if N cached message segments exist, and obtaining a determining result; wherein, the cached message segment is: historical disordered message segments; the meeting of the preset conditions between the current disordered message segment and the cached message segment comprises the following steps: the current disordered message segment and the cached message segment content are continuous or have overlapped content;
the caching module is used for determining whether to cache the current disordered message segment according to the determination result; the cache module is specifically configured to: and when the determined result shows that the current disordered message segment and the cached message segment do not meet the preset condition, discarding the message segment with the closest interval distance between the current disordered message segment and the cached message segment and the s-th sequence message segment.
16. An electronic device, the electronic device comprising:
a memory;
a processor, coupled to the memory, for enabling the implementation of the method provided in any of claims 1 to 14 by executing computer-executable instructions stored on the memory.
17. A computer storage medium having stored thereon computer executable instructions; the computer-executable instructions, when executed by a processor, are capable of carrying out the method provided in any one of claims 1 to 14.
CN202111238367.3A 2021-10-25 2021-10-25 Message receiving method and device based on TCP, electronic equipment and storage medium Active CN114143268B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111238367.3A CN114143268B (en) 2021-10-25 2021-10-25 Message receiving method and device based on TCP, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111238367.3A CN114143268B (en) 2021-10-25 2021-10-25 Message receiving method and device based on TCP, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN114143268A CN114143268A (en) 2022-03-04
CN114143268B true CN114143268B (en) 2024-02-06

Family

ID=80394783

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111238367.3A Active CN114143268B (en) 2021-10-25 2021-10-25 Message receiving method and device based on TCP, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114143268B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105939297A (en) * 2015-10-26 2016-09-14 杭州迪普科技有限公司 TCP message reassembling method and TCP message reassembling device
CN106230744A (en) * 2016-07-26 2016-12-14 京信通信系统(中国)有限公司 A kind of method of out of order restructuring of data stream and forwarding unit
CN112165457A (en) * 2020-09-04 2021-01-01 苏州浪潮智能科技有限公司 Method, system and device for file rearrangement and readable storage medium

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7346701B2 (en) * 2002-08-30 2008-03-18 Broadcom Corporation System and method for TCP offload
JP4872952B2 (en) * 2008-03-06 2012-02-08 日本電気株式会社 TCP buffer copy distributed parallel processing apparatus, method and program

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105939297A (en) * 2015-10-26 2016-09-14 杭州迪普科技有限公司 TCP message reassembling method and TCP message reassembling device
CN106230744A (en) * 2016-07-26 2016-12-14 京信通信系统(中国)有限公司 A kind of method of out of order restructuring of data stream and forwarding unit
CN112165457A (en) * 2020-09-04 2021-01-01 苏州浪潮智能科技有限公司 Method, system and device for file rearrangement and readable storage medium

Also Published As

Publication number Publication date
CN114143268A (en) 2022-03-04

Similar Documents

Publication Publication Date Title
US7603429B2 (en) Network adapter with shared database for message context information
US10015117B2 (en) Header replication in accelerated TCP (transport control protocol) stack processing
US8719456B2 (en) Shared memory message switch and cache
US20030172169A1 (en) Method and apparatus for caching protocol processing data
US6781990B1 (en) Method and system for managing traffic in a packet network environment
EP2074756B1 (en) Method, system, and computer program product for resequencing of data segments received over a bonding channel set
US7631106B2 (en) Prefetching of receive queue descriptors
US9465662B2 (en) Processor with efficient work queuing
US5864680A (en) Method and system for distributing data in a real time data imaging network
US8694701B2 (en) Recovering dropped instructions in a network interface controller
US7032073B2 (en) Cache system for network and multi-tasking applications
CN108092908A (en) Control the method and sending ending equipment of flow
US8539089B2 (en) System and method for vertical perimeter protection
US20060004933A1 (en) Network interface controller signaling of connection event
CN113094392A (en) Data caching method and device
CN114143268B (en) Message receiving method and device based on TCP, electronic equipment and storage medium
US7292593B1 (en) Arrangement in a channel adapter for segregating transmit packet data in transmit buffers based on respective virtual lanes
US7822051B1 (en) Method and system for transmitting packets
US11055222B2 (en) Prefetching of completion notifications and context
US20040240388A1 (en) System and method for dynamic assignment of timers in a network transport engine
US7480739B1 (en) Segregated caching of linked lists for USB
CN115993942B (en) Data caching method, device, electronic equipment and computer readable medium
CN115344192A (en) Data processing method and device and electronic equipment
US20070055956A1 (en) Data transfer management method, software and system
CN115580587A (en) Message information processing method and device, computer equipment and storage medium

Legal Events

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