Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn TCP: Flow Control and Congestion Control | Transport Layer Protocols: TCP and UDP
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Network Protocols Deep Theory

bookTCP: Flow Control and Congestion Control

TCP uses flow control and congestion control mechanisms to manage the rate and reliability of data transmission. Flow control ensures that a sender does not overwhelm a receiver with more data than it can process, while congestion control prevents excess traffic from saturating the network, which could lead to packet loss and reduced performance.

The core of TCP's flow control is the sliding window mechanism. Each TCP segment contains a window size value, which is communicated by the receiver to the sender. This value, known as the receiver window (rwnd), indicates how many more bytes the receiver's buffer can accept. The sender must respect this limit, never sending more unacknowledged data than the window allows.

As data is acknowledged by the receiver, the window "slides" forward, allowing the sender to transmit additional data. If the receiver's buffer becomes full, it advertises a window size of zero, temporarily pausing the sender until space becomes available.

Managing the sliding window efficiently is crucial for maintaining high throughput without risking buffer overflow at the receiver.

To better understand how the sliding window mechanism works, consider the following pseudo code that outlines the management of the window and its adjustment based on acknowledgments and advertised receiver window:

initialize send_base = 0
initialize next_seq_num = 0
initialize window_size = receiver_window

while data_to_send:
    if next_seq_num < send_base + window_size:
        send_segment(data[next_seq_num])
        next_seq_num += segment_length
    if ACK_received:
        send_base = ACK_number
        window_size = updated_receiver_window
    if receiver_window == 0:
        pause_sending()
        wait_for_nonzero_window_advertisement()

This process ensures that the sender only transmits data within the bounds set by the receiver, dynamically adjusting the window size as the receiver's buffer availability changes.

TCP's congestion control algorithms are designed to detect and react to signs of network congestion, maximizing throughput while minimizing packet loss and delay. The four primary algorithms are:

  • Slow Start: When a connection begins or after a timeout, TCP starts with a small congestion window (cwnd), usually one or two segments. For each acknowledged segment, cwnd increases exponentially, doubling every round-trip time. This allows TCP to quickly probe the available bandwidth;
  • Congestion Avoidance: Once the congestion window reaches a threshold (ssthresh), growth becomes linear rather than exponential. This phase is more cautious, increasing cwnd by one segment per round-trip time to avoid overloading the network;
  • Fast Retransmit: If three duplicate acknowledgments are received, TCP assumes a segment was lost (without waiting for a timeout) and retransmits the missing segment immediately. This speeds up recovery from isolated losses;
  • Fast Recovery: After fast retransmit, TCP does not return to slow start. Instead, it reduces cwnd (typically to half its previous value) and enters congestion avoidance, allowing for faster recovery and more efficient use of network capacity.

These algorithms enable TCP to adaptively balance aggressiveness and caution, responding to network feedback to maintain efficient and reliable data transfer.

The following pseudo code illustrates the state transitions and window updates involved in TCP congestion control:

initialize cwnd = initial_value
initialize ssthresh = threshold_value

on ACK_received:
    if cwnd < ssthresh:
        // Slow Start
        cwnd += MSS
    else:
        // Congestion Avoidance
        cwnd += MSS * (MSS / cwnd)

on three_duplicate_ACKs:
    // Fast Retransmit and Fast Recovery
    ssthresh = cwnd / 2
    cwnd = ssthresh + 3 * MSS
    retransmit_lost_segment()

on timeout:
    // Timeout event
    ssthresh = cwnd / 2
    cwnd = MSS

This logic ensures that TCP dynamically adjusts its sending rate based on network conditions, increasing throughput when possible and backing off when congestion is detected.

1. Which of the following best describes the difference between TCP flow control and congestion control?

2. What is the main purpose of the sliding window in TCP?

3. Which event triggers TCP’s fast retransmit algorithm?

question mark

Which of the following best describes the difference between TCP flow control and congestion control?

Select the correct answer

question mark

What is the main purpose of the sliding window in TCP?

Select the correct answer

question mark

Which event triggers TCP’s fast retransmit algorithm?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 2

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

bookTCP: Flow Control and Congestion Control

Swipe to show menu

TCP uses flow control and congestion control mechanisms to manage the rate and reliability of data transmission. Flow control ensures that a sender does not overwhelm a receiver with more data than it can process, while congestion control prevents excess traffic from saturating the network, which could lead to packet loss and reduced performance.

The core of TCP's flow control is the sliding window mechanism. Each TCP segment contains a window size value, which is communicated by the receiver to the sender. This value, known as the receiver window (rwnd), indicates how many more bytes the receiver's buffer can accept. The sender must respect this limit, never sending more unacknowledged data than the window allows.

As data is acknowledged by the receiver, the window "slides" forward, allowing the sender to transmit additional data. If the receiver's buffer becomes full, it advertises a window size of zero, temporarily pausing the sender until space becomes available.

Managing the sliding window efficiently is crucial for maintaining high throughput without risking buffer overflow at the receiver.

To better understand how the sliding window mechanism works, consider the following pseudo code that outlines the management of the window and its adjustment based on acknowledgments and advertised receiver window:

initialize send_base = 0
initialize next_seq_num = 0
initialize window_size = receiver_window

while data_to_send:
    if next_seq_num < send_base + window_size:
        send_segment(data[next_seq_num])
        next_seq_num += segment_length
    if ACK_received:
        send_base = ACK_number
        window_size = updated_receiver_window
    if receiver_window == 0:
        pause_sending()
        wait_for_nonzero_window_advertisement()

This process ensures that the sender only transmits data within the bounds set by the receiver, dynamically adjusting the window size as the receiver's buffer availability changes.

TCP's congestion control algorithms are designed to detect and react to signs of network congestion, maximizing throughput while minimizing packet loss and delay. The four primary algorithms are:

  • Slow Start: When a connection begins or after a timeout, TCP starts with a small congestion window (cwnd), usually one or two segments. For each acknowledged segment, cwnd increases exponentially, doubling every round-trip time. This allows TCP to quickly probe the available bandwidth;
  • Congestion Avoidance: Once the congestion window reaches a threshold (ssthresh), growth becomes linear rather than exponential. This phase is more cautious, increasing cwnd by one segment per round-trip time to avoid overloading the network;
  • Fast Retransmit: If three duplicate acknowledgments are received, TCP assumes a segment was lost (without waiting for a timeout) and retransmits the missing segment immediately. This speeds up recovery from isolated losses;
  • Fast Recovery: After fast retransmit, TCP does not return to slow start. Instead, it reduces cwnd (typically to half its previous value) and enters congestion avoidance, allowing for faster recovery and more efficient use of network capacity.

These algorithms enable TCP to adaptively balance aggressiveness and caution, responding to network feedback to maintain efficient and reliable data transfer.

The following pseudo code illustrates the state transitions and window updates involved in TCP congestion control:

initialize cwnd = initial_value
initialize ssthresh = threshold_value

on ACK_received:
    if cwnd < ssthresh:
        // Slow Start
        cwnd += MSS
    else:
        // Congestion Avoidance
        cwnd += MSS * (MSS / cwnd)

on three_duplicate_ACKs:
    // Fast Retransmit and Fast Recovery
    ssthresh = cwnd / 2
    cwnd = ssthresh + 3 * MSS
    retransmit_lost_segment()

on timeout:
    // Timeout event
    ssthresh = cwnd / 2
    cwnd = MSS

This logic ensures that TCP dynamically adjusts its sending rate based on network conditions, increasing throughput when possible and backing off when congestion is detected.

1. Which of the following best describes the difference between TCP flow control and congestion control?

2. What is the main purpose of the sliding window in TCP?

3. Which event triggers TCP’s fast retransmit algorithm?

question mark

Which of the following best describes the difference between TCP flow control and congestion control?

Select the correct answer

question mark

What is the main purpose of the sliding window in TCP?

Select the correct answer

question mark

Which event triggers TCP’s fast retransmit algorithm?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 2
some-alt