Flow control in the data link layer is a technique that controls the rate of data transmission between the sender and receiver. If the sender is on a fast and powerful computer as compared to the receiver then the receiver may get overwhelmed by the frames transmitted by the sender.
In such a scenario even if there is no error in the transmission of the frame the receiver may lose some of the frames as it is unable to process the frame with the speed at which the sender is transmitting the frame.
Further, the receiver has to process the data received from the sender at its data link layer before it delivers the data to its upper layers. For this, the receiver assigns a data buffer of a maximum length to store the data received from the sender. The receiver then picks the data from this buffering process and deliver it to the upper layer.
If there is no flow control mechanism present then after some time the data buffer at the receiver end may get full and overflow as the datalink at the receiver may be busy processing the old received data. In this process, the receiver may lose some frames or data transmitted from the receiver. To fix this problem there are two approaches to flow control.
Flow Control Approaches
1. Feedback Based Flow Control
In feedback based flow control the receiver provides feedback to the sender about whether the receiver is able to receive the packets at the rate at which the sender is sending the packets. In simple words, the receiver informs them about how it is doing and thereby permit it to send more data.
2. Rate-based Flow Control
In the rate-based flow control approach, the receiver does provide any feedback to the sender instead a limit is put on the rate at which the sender can send the packet.
Flow Control in Data Link Layer
1. Stop and Wait Protocol
In stop and wait protocol is a connection-oriented protocol which means before the communication between sender and receiver takes a connection is established between sender and receiver. When the communication is over the sender purge the connection.
Here a sender sends one data packet to the receiver and waits until it is acknowledged. The sender does not send the next packet until it receives an acknowledgement for the previously sent packet. Doing this, the protocol manages the flow control as the receiver will not be overwhelmed by the data packets.
When a sender sends a data packet to the receiver it starts the timer for the corresponding packet. If the sender does not receive the acknowledgement before the timer expires it resents that data packet.
In stop and wait protocol a checksum is added to each data packet which is verified at the receiver end. If the packet is found corrupted no acknowledgement is sent for the corresponding packet. This let the timer expire and the sender resends that data packet. This is how stop-and-wait controls error.
2. Sliding Window Protocol
Sliding window protocol is based on the concept of pipelining where while waiting for the acknowledgement the sender can transmit multiple frames. Sliding window protocol can be implemented in two ways go-back-n protocol and selective repeat protocol.
A sliding window is an imaginary box that covers the frames that are either sent by the sender or are getting ready to be sent. In sliding window protocol the frames are numbered in a sequential manner, the sequence number is used to trace which frame has been sent by the sender and also which frame is acknowledged by the receiver.
In the go-back-n protocol, the sender can sends ‘n’ frames before expecting the first acknowledgement. Here N is the sender’s window size so the sender sends the N frames while waiting for acknowledgement for the first time.
Meanwhile, the receiver starts sending the acknowledgement and the sender window slides by one or more slots covering the frames that can be sent next and leaving the one that is acknowledged.
Now if any of the frames is received corrupted at the receiver side or of the frame is lost or acknowledgement of the frame is lost the timer at the sender gets expired and the sender retransmits all the frames in the sender’s current sliding window.
b)Selective Repeat Protocol
The selective repeat overcomes the inefficiency of the go-back-n protocol. In go-back-n, if the sender does not receive acknowledgement it retransmits all the frames from the current sender sliding window. But what if there is a frequent loss of frames or if there is a lot of error in the frame a lot of bandwidth is wasted.
In selective repeat, only that frame is resent of which sender doesn’t receive the acknowledgement before the corresponding timer expires. So the selective repeat protocol is more efficient as compared to go-back-n.
So this is how data link manages flow and error control while sender and receiver are communicating.