You are on page 1of 11

Selective Repeat

Selective Repeat (Protocol 5)


• Further optimization.
• Receiver has a window greater than 1.
• Don’t discard frames simply because some
earlier frames was damaged.

07/11/21 06:06 AM
Selective Repeat
Sender.
while (1)
{
If network layer got data, if current window not full yet, read data, send to physical layer with the current frame ID.
Start timer. Increment frame ID by one.
If got ACKm, if m is outside the window, don’t do anything. If m is inside the window, consider all frames in the
window with frame ID less than the m acked. Forward window to m.
If timeout for frame m, resend m.
}
Receiver
while (1)
{
Get frame from the physical layer. If it is within the receiver window and hasn’t been received before, fill in the slot,
and forward the beginning of the receiver window if necessary. Deliver to the network layer all frames between
the beginning of the old receiver window and the new receiver window – 1, inclusive. Send ACK (Expc = the
beginning of the current receiver window).
}
• Note: assuming the sequence number is the frame ID.

07/11/21 06:06 AM
The Timer
• Each packet in the sender’s window should
have a timer.
• If the window contains F0,F1,F2,F3. Could it
happen that the when the timer for F0 expires,
the timer for F1 has not expired yet? Yes, if you
do not send the frames one-by-one.
• Could it happen that the timer for F1 expires
but the timer for F0 has not? Yes, if F0 has
been retransmitted before.

07/11/21 06:06 AM
Sequence Number
• If the sequence number field is 3 bits, how
large should the sender/receiver window be?
• Should the receiver has a different window
size than the sender? No, larger --- makes no
sense, the sender is not going to send that
many outstanding frames, smaller --- wrong,
because the receiver will discard such packets.
• Window size should be 4.

07/11/21 06:06 AM
Sequence Number
• For 0 to be in my window again, I must have
forwarded to 5. When I forwarded to 5, I must
have got 4. I got 4 because the sender sent 4.
The sender sent 4 only if it got ACK for 0.

07/11/21 06:06 AM
Sequence Number
• A proof.
• Let the sequence number be log_2{N} bits. Let the
window size be W, where W <= N/2.
• Suppose the receiver gets a frame with sequence
number m. He thinks it is for frame x. Could he actually
receive frame x-N (with the same seq#)?
• No. Because when x is in his window, the window has
forwarded to x-W+1, at least. So he has got x-W. The
sender has sent x-W. The sender will do so only if it has
got ACK for x-2W+1. If W <=N/2, the sender must have
got ACK for x-N.

07/11/21 06:06 AM
Selective Repeat

07/11/21 06:06 AM
Piggybacking
• Considered only one direction. Bidirection.
• Piggybacking
– Combining ACK with data
– When no data?
• Wait some time and ACK anyway.
• Internet. PPP.

07/11/21 06:06 AM
Framing
• How does the receiver know where is the start
and where is the end of a frame?
• Counter. Tell the receiver how many bytes
there are in this frame. Problems?
• The counter part could be corrupted and you
are done.
Flag Bytes
• Add special bytes to the beginning and the
end of the frame.
• Problems?
• What if the data contains the flag bytes?
• Add ESC byte to each flag or ESC in the data.
Stuffing.

You might also like