Sliding Window is the method of flow control TCP uses. The algorithm basically places a buffer between the application and the network data flow. The purpose of sliding window is to prevent from the sender to send too many packets to over flow the network resource or the receiver’s buffer. The “sliding window size” is the maximum amount of data we can send without having to wait for ACK. TCP achieve the flow control by using the sliding Window algorithm which takes into consideration 2 important parameters. The first one is the receiver advertised window size which basically tells the sender what is the current buffer of TCP receiver, the second parameter is congestion window which control the number of packets a TCP flow may have in the network in any given time.
Receiver Advertised Window
The Receiver Advertised Window (adwn) is the buffer size sent in each ACK from TCP receiver to TCP sender. The TCP header uses a 16 bit field to report the receive window size to the sender. Therefore, the largest window that can be used is 2^16=65k bytes..
Congestion Window (cwnd) controls the number of packets a TCP flow may have in the network in any given time. cwnd is dynamically adapting to changing network condition Slow-start is one of the algorithms that TCP uses in its quest to control congestion inside the network and it is also known as the exponential growth phase. Slow-start works by increasing the TCP congestion window each time the ACK is received. it increases the window size by the number segments acknowledged. If a loss event occurs, TCP assume this is due to network congestion and takes step to reduce the offered load on the network.
When TCP reaches a certain threshold (also known as sstrsesh) it will enter the linear growth, Congestion avoidance. in our sliding window demo the threshold is fixed on 10. At this point, the window is increased by segmentSize*segmentsize/cwnd for each receiving ACK. Sliding Window Operation First, the sender creates a sequence number for each frame as it is transmitted. Throughout the communication, it maintains the send window size, the last acknowledgment received, and the last frame sent. To ensure that the window does not overflow, the sender ensures that the window size is greater than the sequence number of last frame sent minus the sequence number last acknowledgment received. When the sender transmits a frame, it increments the sequence number by one and starts a timer. The sequence number is sent with the frame so that the receiver can detect if a frame is received out of order. The sender continues sending frames until the buffer of unacknowledged frames is as large as the send window size.The sender then waits until it receives acknowledgments before transmitting more frames.
Whenever the sender receives an acknowledgment from the receiver, it increments the value of the last acknowledgment received, thereby sliding the “sliding window” to the right. If the timer for the frame expires before the sender receives an acknowledgment for the frame, it assumes that the frame was lost and retransmits it. The receiver holds onto three pieces of information as well: the receive window size, the last frame received, and the next frame to acknowledge. When a frame arrives, the receiver evaluates the frame to determine if it falls within the receiver’s window. The size of the receiver’s window is determined by the number of frames the receiver can buffer before overflowing. The receiver can not process frames received out of order. A frame is out of order if a gap exists between the sequence numbers of the newly received frame and that of the last frame received. If a frame is received with a sequence number that results in a gap larger than the size of the receiver’s window, the frame is determined to be outside the window and is discarded. If a frame is received with a sequence number that is lower than or equal to that of the last frame received, this frame is by definition outside the window and must be a duplicate. It is also discarded. Packets with sequence numbers that fall within the window are accepted and put into the buffer. After accepting the frame, the receiver again checks the sequence number to determine if the frame was received in the correct order. The receiver compares the incoming frame’s sequence number to next frame to acknowledge sequence number. If they match the receiver sends an acknowledgment. The next frame to acknowledge and last frame received are both incremented, thus sliding the window along. wikipedia
The demo shows a simulation of sliding window with advertised window set to 10. The sender starts to transmit in slow start mode , after it reaches the threshold it goes into congestion avoidance. The sender keep the pointer to Last Frame Sent (LFS) and Last ACK Received (LAR). The size of the sliding window is changing based on the minimum of congestion window(cwnd) and advertised window. Use the tool tip over the hot points for more details.