Selective Repeat Protocol Simulation

Selective Repeat uses a receiver window so out-of-order packets are kept, not thrown away. Only the packet that was truly lost needs to be sent again.

Interactive simulation

base
0
next_seq
0
rcv_base
0
Timer
idle
Speed
1x

Sender (window of 4)

Receiver (window of 4 packets (buffers out-of-order))

Legend

  • Inside window, ready
  • Sent, waiting for ACK
  • Retransmitted
  • Acknowledged / delivered
  • Buffered out of order (receiver)
  • Packet in transit (click to select)
  • ACK in transit (click to select)
  • Selected (press Kill Selected)
  • Destroyed in transit

Event log

    How to use this simulation

    1. Press Send. The sender transmits up to 4 packets. Each one is acknowledged individually.
    2. Click a packet in transit or press Kill Packet. Notice later packets still arrive and turn indigo: they are buffered, not discarded.
    3. When the timer for the lost packet expires, only that packet is resent. Once it arrives, the receiver delivers the whole buffered run and both windows slide.
    4. Use Step, Slower, Faster and Reset to explore at your own pace. Try killing an ACK too.

    1. Both sides have a window

    The sender window works as in Go-Back-N. The receiver also has a window, starting at rcv_base, which is the lowest packet it has not yet delivered. Here both windows hold 4 packets.

    2. Packets are acknowledged one by one

    When a packet lands inside the receiver window, the receiver acknowledges that specific packet. If the packet is already delivered it is acknowledged again, because the earlier ACK may have been lost.

    3. Out-of-order packets are buffered

    If packet 2 is missing but 3 and 4 arrive, the receiver stores 3 and 4. They are not delivered to the application until the gap is filled, so data still arrives in order.

    4. Each packet has its own timer

    On timeout, the sender retransmits just that packet. When it arrives, the receiver delivers it together with everything buffered behind it, and rcv_base jumps forward.

    5. The cost of efficiency

    Selective Repeat wastes less bandwidth but needs receiver buffer memory, per-packet timers and a sequence number space at least twice the window size, so old and new packets cannot be confused.

    Go-Back-N vs Selective Repeat

    FeatureGo-Back-NSelective Repeat
    Receiver window1 packetSame size as sender window
    Out-of-order packetsDiscardedBuffered
    AcknowledgementsCumulativeIndividual
    On a lossResend the whole windowResend only the lost packet
    TimersOneOne per packet
    Receiver complexityLowHigher (buffer and reordering)

    Key takeaways

    • Receiver window equals sender window, so out-of-order packets are buffered.
    • Every packet gets its own ACK and its own timer.
    • Only lost or unacknowledged packets are retransmitted.
    • Data is still delivered to the application in order.
    • It trades extra memory and complexity for better efficiency on lossy links.

    Related topics

    Go-Back-N

    Simpler receiver, bigger retransmissions.

    Stop-and-Wait

    The simplest ARQ: one packet at a time.

    Coming soon

    Sliding Window

    The general idea behind flow control.

    Coming soon

    TCP Handshake

    How a reliable connection starts.

    Coming soon

    ARQ Protocols

    Automatic repeat request, compared.

    Coming soon