Flow Control in TCP
TCP uses a sliding window to handle flow control. The sliding window protocol used by TCP, however, is something between the Go-Back-N and Selective Repeat sliding window.
There are two big differences between this sliding window and the one we used at the data link layer. First, the sliding window of TCP is byte-oriented but data link layer sliding window is frame-oriented. Second, the TCP's sliding window is of variable size and the data link layer was of fixed size.
The following figure shows the sliding window in TCP.
The window spans a portion of the buffer containing bytes received from the process. The bytes inside the window are the bytes that can be in transit; they can be sent without worrying about acknowledgment. The imaginary window has two walls: one left and one right.
The window is opened, closed, or shrunk. These three activities, as we will see, are in the control of the receiver (and depend on congestion in the network), not the sender. The sender must obey the commands of the receiver in this matter.
Opening a window means moving the right wall to the right. This allows more new bytes in the buffer that are eligible for sending. Closing the window means moving the left wall to the right. This means that some bytes have been acknowledged and the sender need not worry about them anymore. Shrinking the window means moving the right wall to the left. This is not allowed in some implementations because it means revoking the eligibility of some bytes for sending.
The size of the window at one end is determined by the lesser of two values: receiver window (rwnd) or congestion window (cwnd). The receiver window is the value advertised by the opposite end in a segment containing acknowledgment. It is the number of bytes the other end can accept before its buffer overflows and data are discarded. The congestion window is a value determined by the network to avoid congestion.
The following figure shows an unrealistic example of a sliding window.
The sender has sent bytes up to 202. We assume that cwnd is 20 (in reality this value is thousands of bytes). The receiver has sent an acknowledgment number of 200 with an rwnd of 9 bytes (in reality this value is thousands of bytes).
The size of the sender window is the minimum of rwnd and cwnd, or 9 bytes. Bytes 200 to 202 are sent, but not acknowledged. Bytes 203 to 208 can be sent without worrying about acknowledgment. Bytes 209 and above cannot be sent.
Features of TCP sliding window are as follows:
• The size of the window is the lesser of rwnd and cwnd.
• The source does not have to send a full window's worth of data.
• The window can be opened or closed by the receiver, but should not be shrunk.
• The destination can send an acknowledgment at any time as long as it does not result in a shrinking window.
• The receiver can temporarily shut down the window; the sender, however, can always send a segment of 1 byte after the window is shut down.
For Further Reading: