TCP Reliable Transmission Mechanism

TCP Reliable Transmission Mechanism

Description
The TCP reliable transmission mechanism ensures that data can reach the receiving end in an unreliable IP network without errors, loss, duplication, and in the correct order. Its core relies on technologies such as sequence numbers and acknowledgment mechanisms, timeout retransmission, and sliding window protocol to achieve reliability. The following will gradually analyze how these mechanisms work together.

Step One: Data Numbering and Acknowledgment Mechanism

  1. Sequence Number:

    • The sender assigns a unique sequence number to each byte of data. For example, if the first byte sent has a sequence number of 1000 and the data segment contains 100 bytes, the starting sequence number for the next segment will be 1100.
    • The role of the sequence number: identifies the order of data, facilitating the receiver's reassembly and detection of loss or out-of-order delivery.
  2. Acknowledgment Number:

    • The receiver informs the sender via the acknowledgment number that "all data before this sequence number has been correctly received." For example, if the receiver receives a data segment with sequence numbers 1000-1099, it returns an acknowledgment number of 1100 (the sequence number of the next byte it expects to receive).
    • Cumulative Acknowledgment: Acknowledgment number 1100 indicates that all data before 1100 has been received, eliminating the need for individual acknowledgments for each data segment and reducing network overhead.

Step Two: Timeout Retransmission (RTO)

  1. Retransmission Trigger Conditions:

    • A timer is started after sending data; if no acknowledgment is received within the timeout period (RTO), the data is retransmitted.
    • The RTO value is dynamically calculated: based on a weighted average of historical round-trip times (RTT) to avoid premature or delayed retransmissions due to network fluctuations.
  2. Duplicate Acknowledgments and Fast Retransmission:

    • If the receiver receives out-of-order data (e.g., data with sequence number 1100 arrives before sequence number 1000), it will repeatedly send the most recent valid acknowledgment (e.g., repeatedly sending acknowledgment number 1000).
    • When the sender receives three duplicate acknowledgments, it immediately retransmits the suspected lost data segment (e.g., sequence number 1000) without waiting for a timeout, known as fast retransmission.

Step Three: Sliding Window Protocol

  1. Window Function:

    • Sending window: Allows the sender to continuously send multiple data segments without waiting for acknowledgments, improving throughput.
    • Receiving window: Limits the sender's rate to prevent receiver buffer overflow (flow control).
  2. Window Sliding Process:

    • The sender maintains data segments within the window; upon receiving an acknowledgment number, the window slides forward. For example:
      • Initial window range [1000, 2000), after sending 1000-1499, wait for acknowledgment.
      • Upon receiving acknowledgment number 1500, the window slides to [1500, 2500), allowing new data to be sent.
    • The receiver dynamically adjusts the sender's window size via the advertised window size (Win field).

Step Four: Comprehensive Example
Assume the sender wants to transmit 300 bytes of data (sequence numbers 1000-1299), divided into 3 segments (100 bytes each):

  1. Send segment 1 (1000-1099), retain a copy of this segment within the window, and start the timer.
  2. The receiver receives segment 1, returns acknowledgment number 1100, and the sender slides the window and clears the copy of segment 1.
  3. If segment 2 (1100-1199) is lost, the receiver will repeatedly send acknowledgment number 1100 upon receiving segment 3 (1200-1299).
  4. After receiving three duplicate acknowledgments, the sender quickly retransmits segment 2 to ensure data integrity.

Summary
TCP ensures data order and integrity through sequence numbers/acknowledgment numbers, addresses loss issues via timeout retransmission and fast retransmission, and balances efficiency and flow control with the sliding window. These mechanisms together form the foundation of reliable transmission and are the core features that distinguish TCP from UDP.