Reliability and Flow Control (26.6)
Reliability and flow control are two of the main features of TCP, not present in UDP.
TCP Reliability—Guaranteed and Ordered Delivery (26.6.1)
The reason that TCP is the better protocol for some applications is that, unlike UDP, it resends dropped packets and numbers packets to indicate their proper order before delivery. TCP can also help maintain the flow of packets so that devices do not become overloaded. This section covers these features of TCP in detail.
Sometimes TCP segments do not arrive at their destination. Other times, TCP segments arrive out of order. For the original message to be understood by the recipient, all the data must be received and the data in these segments must be reassembled into the original order. Sequence numbers are assigned in the header of each packet to achieve this goal. The sequence number represents the first data byte of the TCP segment.
During session setup, an initial sequence number (ISN) is set. This ISN represents the starting value of the bytes that are transmitted to the receiving application. As data is transmitted during the session, the sequence number is incremented by the number of bytes that have been transmitted. This data byte tracking enables each segment to be uniquely identified and acknowledged. Missing segments can then be identified.
The ISN does not begin at 1 but is effectively a random number. This is to prevent certain types of malicious attacks. For simplicity, we will use an ISN of 1 for the examples in this chapter.
Segment sequence numbers indicate how to reassemble and reorder received segments, as shown in Figure 26-23.
Figure 26-23 TCP Segments Are Reordered at the Destination
The receiving TCP process places the data from a segment into a receiving buffer. Segments are then placed in the proper sequence order and passed to the application layer when reassembled. Any segments that arrive with sequence numbers that are out of order are held for later processing. Then, when the segments with the missing bytes arrive, these segments are processed in order.
Video—TCP Reliability—Sequence Numbers and Acknowledgments (26.6.2)
Refer to the online course to view this video.
TCP Reliability—Data Loss and Retransmission (26.6.3)
No matter how well designed a network is, data loss occasionally occurs. TCP provides methods of managing these segment losses. Among these methods is a mechanism to retransmit segments for unacknowledged data.
The sequence (SEQ) number and acknowledgement (ACK) number are used together to confirm receipt of the bytes of data contained in the transmitted segments. The SEQ number identifies the first byte of data in the segment being transmitted. TCP uses the ACK number sent back to the source to indicate the next byte that the receiver expects to receive. This is called expectational acknowledgement.
Prior to later enhancements, TCP could only acknowledge the next byte expected. For example, in Figure 26-24, using segment numbers for simplicity, Host A sends segments 1 through 10 to Host B. If all the segments arrive except for segments 3 and 4, Host B would reply with acknowledgment specifying that the next segment expected is segment 3. Host A has no idea if any other segments arrived or not. Host A would, therefore, resend segments 3 through 10. If all the resent segments arrived successfully, segments 5 through 10 would be duplicates. This can lead to delays, congestion, and inefficiencies.
Note
For simplicity, segment numbers are being used instead of the byte numbers.
Figure 26-24 Data Retransmission
Host operating systems today typically employ an optional TCP feature called selective acknowledgment (SACK), negotiated during the three-way handshake. If both hosts support SACK, the receiver can explicitly acknowledge which segments (bytes) were received, including any discontinuous segments. That way, the sending host needs to retransmit only the missing data. For example, in Figure 26-25, again using segment numbers for simplicity, Host A sends segments 1 through 10 to Host B. If all the segments arrive except for segments 3 and 4, Host B can acknowledge that it has received segments 1 and 2 (ACK 3) and selectively acknowledge that it has received segments 5 through 10 (SACK 5-10). Host A now knows that it needs to resend only segments 3 and 4.
Figure 26-25 Selective Acknowledgment
Note
TCP typically sends ACKs for every other packet, but other factors beyond the scope of this topic may alter this behavior.
Video—TCP Reliability—Data Loss and Retransmission (26.6.4)
Refer to the online course to view this video.