A Protocol Using Selective Repeat
The Go-Back-N protocol is effective when errors are rare, but it can waste significant bandwidth on retransmitted frames in poor line conditions. An alternative strategy, the Selective Repeat Protocol, allows the receiver to accept and buffer frames that arrive after a damaged or lost frame. This approach enhances efficiency by minimizing unnecessary retransmissions.
Protocol Overview
In the Selective Repeat Protocol, both the sender and receiver maintain a window of outstanding and acceptable sequence numbers, respectively. The sender’s window size starts at 0 and can grow to a predefined maximum, while the receiver’s window is fixed in size and equal to this maximum. The receiver has a buffer for each sequence number within its fixed window, and each buffer is associated with a bit indicating whether it is full or empty.
When a frame arrives, its sequence number is checked to see if it falls within the receiver’s window. If it does and has not already been received, the frame is accepted and stored. However, the frame is not passed to the network layer until all lower-numbered frames have been delivered in the correct order.
Example Scenario
Consider a scenario with a 3-bit sequence number, allowing the sender to transmit up to seven frames before waiting for an acknowledgment. Initially, both the sender’s and receiver’s windows are set to allow frames 0 through 6. If all frames arrive correctly, the receiver acknowledges them and advances its window.
However, if all acknowledgments are lost due to an error (e.g., a lightning strike), the sender will time out and retransmit frame 0. If frame 0 is within the receiver’s window, it will be accepted, but this can lead to confusion if the receiver has already advanced its window and accepted new frames.
To avoid this overlap and confusion, the maximum window size should be at most half the range of the sequence numbers. This ensures that the sender and receiver can distinguish between new frames and retransmissions.
illustrating the initial situation with a window of size 7.
Buffer and Timer Management
The number of buffers required at the receiver is equal to the window size, not the range of sequence numbers. For example, with a 3-bit sequence number, four buffers are needed. Each buffer corresponds to a sequence number modulo the number of buffers.
Each buffer also has an associated timer. When the timer expires, only the frame associated with that timer is retransmitted, rather than all outstanding frames, as in the Go-Back-N protocol.
Auxiliary Timer for Acknowledgments
To handle situations where reverse traffic is light, an auxiliary timer is started after an in-sequence data frame arrives. If no reverse traffic is detected before this timer expires, a separate acknowledgment frame is sent. This mechanism allows the protocol to function effectively even when traffic is unidirectional.
The timeout for the auxiliary timer should be shorter than the timeout for data frames to ensure timely acknowledgment and prevent unnecessary retransmissions.
Error Handling with NAKs
The Selective Repeat Protocol uses negative acknowledgments (NAKs) to request retransmission of specific frames. The receiver sends a NAK when it detects a damaged frame or receives a frame that is not the expected one. To avoid multiple requests for the same frame, the protocol tracks whether a NAK has already been sent for a given frame.
If a NAK is lost, the sender will eventually time out and retransmit the missing frame. If a wrong frame arrives after a NAK has been sent, the sender will be resynchronized with the receiver’s current status through an acknowledgment.
Code Implementation
Below is a simplified implementation of the Selective Repeat Protocol in pseudocode:Selective Repeat Protocol in pseudocode: click here
Conclusion
The Selective Repeat Protocol enhances the efficiency of data transmission by allowing out-of-order frame acceptance and minimizing unnecessary retransmissions. By managing buffers and timers effectively, it ensures that the receiver can handle frames without confusion, even in the presence of errors. This protocol is particularly useful in environments where the likelihood of frame loss is higher, as it optimizes bandwidth usage and improves overall communication reliability.