Analysis of TCP packet restructuring

Source: Internet
Author: User

For the analysis of the implementation of TCP packet restructuring, refer to the detailed explanation of TCP/IP, discusses the implementation of TCP in detail, and roughly summarizes how TCP ensures the correctness and reliability of data packets to the application layer, that is, how TCP restructured data packets. First, we need to design two message queues, one for storing normal incoming packets and the other for storing out-of-order incoming packets. For example, the last packet data in the normal message queue is as follows: the length of the first byte of the packet data segment, seq1 = 100len1 = 100, may be the next packet, Which is analyzed as follows: 1) normal message seq2 = 200len2 = 200seq2 = seq1 + len1 the seq of this message shows that the packet carries the data serial number 200 ~ 399, which is the expected follow-up message of the previous packet. This packet is appended to the normal message queue. 2) completely duplicated packets: seq2 = 100len2 = 100seq2 = seq1 and len2 = len1. This packet carries the data serial number 100 ~ 199, with the data serial number carried by the previous packet 100 ~ 199 is exactly the same, that is, completely duplicated, so the packet should be discarded. 3) Duplicate submessage seq2 = 100len2 = 50seq2 = seq1 and len2 <len1 the packet carries the data serial number 100 ~ 149 indicates that this is part of the previous packet, so the packet should be discarded. Note: The second and third cases can be combined, that is, seq2 = seq1 and len2 <= len1, which are listed here to illustrate different situations. 4) for some duplicate packets, seq2 = 150len2 = 30seq2> seq1 and seq2 <seq1 + len1 and seq2 + len2 <= seq1 + len1 indicates that the packet carries the serial number 150 ~ 179. This serial number segment is included in the previous packet segment (100 ~ 199), so the packet should be discarded. 5) part of duplicate packets II. seq2 = 150len2 = 100seq2> seq1 and seq2 <seq1 + len1 and seq2 + len2> seq1 + len1: This packet carries the serial number 150 ~ 249, the first part of this serial number segment 150 ~ 199 is included in the previous packet segment (100 ~ 199), the last part is 200 ~ 249 is the new data, and the packet should be processed as follows:. calculate the number of repeated bytes (seq1 + len1)-Seq2 = 100 + 100-150 = 50. That is, the first 50 bytes of the packet segment are duplicated. B. truncate the first 50 bytes of the new data segment and then truncate the new data. That is, only the sequence segment 200 ~ 249. C. reset seqseq2 = seq2 + 50 = 150 + 50 = 200D for this packet segment. reset the length of the message segment len2 = len2-50 = 100-50 = 50E. after resetting, the packet segment is seq2 = 200len2 = 50. That is, the packet segment now carries the data serial number 200 ~ 249, which is the subsequent packet of the previous packet. Now it can be appended to the normal packet queue as a normal packet. 6) The first incoming packet seq2 = 300len2 = 100seq2> seq1 + len1 carries the serial number 300 ~ 399 of data, that is, not the last packet 100 ~ 199 of the subsequent messages, but the messages that come in advance, should be placed in the out-of-order message queue for future re-use. In this way, until tcp disconnects the socket (FIN = 1), the data in the normal message queue and the out-of-order message queue is merged to complete the reorganization. Extract the seq and len of the last packet in the normal message queue, and find the subsequent packets in the out-of-order message queue, whether the message can be used as a normal message queue. The subsequent packet processing process is the same as that of the previous 1 )~ 5) analysis.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.