Sliding Windows Protocol - CSU359 - Shoolini University

Sliding Windows Protocol

Sliding Window Protocol

The Sliding Window Protocol is a crucial mechanism in computer networks used for flow control and error control. It ensures efficient and reliable data transmission between two devices in a network, particularly in environments with varying delay and throughput. This protocol is widely used in Transport Layer protocols like TCP.

1. Overview of Sliding Window Protocol

The Sliding Window Protocol allows multiple frames to be sent before requiring an acknowledgment. This improves the utilization of network resources by keeping the communication channel busy.

  • Window Size: The number of frames that can be sent without receiving an acknowledgment.
  • Sender's Window: Tracks frames sent but not yet acknowledged.
  • Receiver's Window: Tracks frames received and ready for acknowledgment.

2. Key Components

The Sliding Window Protocol operates based on several essential components:

  • Sequence Numbers: Used to uniquely identify frames.
  • Acknowledgments (ACKs): Sent by the receiver to confirm receipt of frames.
  • Window Size: Determines how many frames can be sent without acknowledgment.

3. Types of Sliding Window Protocols

There are three main types of Sliding Window Protocols, each differing in how they handle acknowledgments and retransmissions:

3.1 Stop-and-Wait Protocol

A basic form of sliding window where the sender transmits one frame and waits for an acknowledgment before sending the next frame.

  • Advantages: Simple to implement.
  • Disadvantages: Inefficient as it underutilizes the communication channel.
3.2 Go-Back-N Protocol

The sender can transmit up to N frames without waiting for an acknowledgment. If an error occurs, all subsequent frames are retransmitted.

  • Advantages: Efficient for networks with low error rates.
  • Disadvantages: Retransmission of multiple frames in case of a single error.

# Example Go-Back-N Simulation
def go_back_n(frames, window_size):
    ack = 0
    for i in range(len(frames)):
        if i < ack + window_size:
            print(f"Sending frame {frames[i]}")
        else:
            print("Window full. Waiting for acknowledgment.")
        if frames[i] == "error":
            print(f"Error in frame {frames[i]}. Retransmitting from frame {ack}")
            break
        ack += 1
    print(f"All frames acknowledged up to {ack}.")
3.3 Selective Repeat Protocol

The sender retransmits only the specific frames that encountered errors while the receiver stores out-of-order frames in a buffer.

  • Advantages: Efficient as only erroneous frames are retransmitted.
  • Disadvantages: Requires more complex receiver logic.

# Example Selective Repeat Simulation
def selective_repeat(frames, window_size):
    buffer = {}
    for i in range(len(frames)):
        if i < window_size:
            print(f"Sending frame {frames[i]}")
        if frames[i] == "error":
            print(f"Error in frame {frames[i]}. Requesting retransmission.")
        else:
            buffer[i] = frames[i]
    print("Buffered frames:", buffer)

4. Advantages of Sliding Window Protocol

Key benefits include:

  • Improved Efficiency: Keeps the channel utilized by sending multiple frames before acknowledgment.
  • Error Handling: Protocol variants like Selective Repeat minimize retransmission overhead.
  • Flow Control: Dynamically adjusts to network conditions.

5. Real-World Application

The Sliding Window Protocol is extensively used in the Transmission Control Protocol (TCP). TCP implements a dynamic sliding window mechanism to optimize data flow based on network conditions, ensuring reliable transmission in diverse network environments.