10. Principles of Reliable Data Transport – Part 2 Basic concepts Stop-and-wait protocol Go-Back-N protocol Selective Repeat protocol Roch Guerin (with adaptations from Jon Turner and John DeHart, and material from Kurose and Ross)
Improving RDT 3.0 Basic goal is to be able to transmit non-stop under normal (no errors) operation first ack must arrive before the sender finishes transmission of Nth packet To enable more efficient operation, we want a protocol that can keep transmitting while waiting for acks, i.e., one that pipelines transmissions sender can transmit up to N packets while waiting for acks each packet labeled with sequence # from set of S>N sequence #s receiver sends acks with sequence numbers Two major variants go-back-N (cumulative ack) and selective repeat (specific ack)
Go-back-N with N=4 lost packet selective lost packet go-back repeat ✕ A0 A2 A3 timeout A1 lost packet go-back normal case P0 P0 P1 P1 P2 ✕ P2 P3 timeout P3 A0 A0 A0 A1 A0 A2 P1 A3 P2 P3 A1 A2 A3
Go-Back-N Operation Allow pkt transmissions as long as LPS-LAR ≤ SWS Sender variables Send window size: SWS=N Last pkt sent: LPS Last ack received: LAR Allow pkt transmissions as long as LPS-LAR ≤ SWS If LPS-LAR ≤ SWS, send next pkt with SN = LPS+1 ACK for pkt number X>LAR updates LAR to X (slides the window) Note that X ≠ LAR+1 is OK (cumulative ACKs acknowledge all pkts up to X) Receiver variables Receive window size: RWS (= 1) Last pkt received: LPR Latest acceptable pkt: LAP Need: LAP-LPR ≤ RWS i.e., LAP = RWS +LPR (RWS=1 only one acceptable pkt) When pkt SN arrives (with RWS=1) If SN !=LPR+1, discard pkt Only accepts packets in order Else accept pkt and set LPR = SN Send (cumulative) ACK for LPR It is a cumulative ACK but it is always just 1 more than last ACK sent!
Go-Back-N – Sender & Receiver SWS LAR LPS LPS - LAR ≤ SWS RECEIVER RWS LPR LAP LAP- LPR ≤ RWS LAR: Last Ack Received, LPS: Last Packet Sent, SWS=N: Send Window Size LPR: Last Packet Received, LAP: Latest Acceptable Packet, RWS: Receive Window Size
Buffering & Numbering Packets Sender How big should S be? Obviously) S ≥ SWS Suppose S=4 (Seq. Num. field {0,…,3}) and SWS = 4 Sender transmit frames 0,…,3 Arrive successfully, but all ACKs are lost Sender retransmits 0,…,3 (after timeout) Receiver expects new 0,…,3, gets second incarnation of old 0,…,3, incorrectly accepts as new In general, we need S ≥ RWS + SWS 7 1 copies of unacked packets 6 2 5 3 4 ready to send 4 Protocol uses sequence numbers 0…S–1=2m-1 Re-use sequence numbers in circular fashion all sequence number arithmetic is modulo S Window size SWS specifies number of pkts that can be unacknowledged Sequence numbers 0 – N-1 =( 2^m) - 1 , What is m? Number of bits in Sequence number.
Go-Back-N State Machines Receiver (start in state 0) state i expecting packet i receive packet i deliver packet and send ack i state i+1 receive packet k≠i send ack i–1 mod S mod S state (i,j) oldest unacked packet is i, next packet to send gets seq#j packet available and j–i<SWS send packet j, save copy, start timer state (i,j+1) state (k+1,j) receive ack k if k in i..j–1 discard packet copies i..k, for k≤j stop timers mod S timeout resend packets i..j–1, restart timers Sender (start in (0,0))
Go-Back-N Performance Performance depends on Time-out value (timer starts when last bit of packet is sent) Assume tout = ( - 1)tpkt ≥ RTT As RTT increases, tout would increase tpkt : transmission time of packet Value of window size N Assume N is large enough to keep the pipe full in the absence of losses, i.e., (N–1)tpkt > RTT Impact and frequency of retransmissions Expected Time for a Successful Packet Transmission: Tsucc We need to know: Time for the initial transmission: tpkt Expected number of retransmissions: E[R] Time for a single retransmission: Tr Tsucc = E[R] Tr + tpkt
Go-Back-N Performance Let Tr be the time spent for one retransmission Tr = tpkt + tout = tpkt Time spent per packet: T = RTr + tpkt R is number of retransmissions (geometrically distributed) E[R]=q/(1-q), where q is the pkt loss probability Expected time for successful packet transmission Next pages show how we get to the above equation 100% throughput if tpkt = Tsucc Achievable when q=0 (no pkt or ACK losses) For a given value of q, throughput decreases as , i.e., RTT, increases
Retransmissions as a Geometrically Distributed Random Variable Packet loss probability: q (we can ignore ack losses) R retransmissions means that packet transmissions fail R times before succeeding P(R retransmissions) = qR(1–q) E[R] = {R=0 to ∞}RqR(1–q) = q(1–q){R=0 to ∞}RqR-1 = q(1–q)/(1–q)2 =q/(1–q) So a successful transmission requires one original transmission plus R retransmissions, for a total time of tpkt + R (tout + tpkt), or on average tpkt + tpkt x q/(1–q) = tpktx(1 + (–1)q)/(1–q)
Go-Back-N Performance (continued) Derivation of Tsucc Tsucc = E[R] Ttotal + tpkt E[R] = q/(1-q) and Ttotal = tpkt Tsucc = (q/(1-q)) tpkt + tpkt Tsucc = (q/(1-q)) tpkt + tpkt (1-q)/(1-q) Tsucc = (qtpkt /(1-q)) + (tpkt - qtpkt )/(1-q) Tsucc = (qtpkt + tpkt - qtpkt )/(1-q) Tsucc = tpkt (q+ 1 - q)/(1-q) Tsucc = (1 + ( - 1)q) tpkt /(1-q)
Receive Buffer in Selective Repeat 1 2 4 3 6 5 7 waiting for packet 1 Receiver maintains buffer of up to RWS=SWS=N packets On receiving packet i, send ack i If arriving packet is in window range and no previous copy is in buffer, store new packet If arriving packet is next one expected deliver it and all other packets up until the first “hole” in buffer advance window to location of first hole Correct operation calls for in-order packet delivery and S≥2N (S is the number of sequence numbers) Why? If the windows size is greater than half the sequence number space, then if an ACK is lost, the sender may send new packets that the receiver believes are retransmissions. For example, assume SWS=RWS=2 and S=3 (0, 1, 2). Sender A sends packets 0 and 1, receiver B acks both, but ack for 1 is lost. When receiving the ack for 0, A sends 2 that is also correctly received by B. After a time-out, A resends 1 that is interpreted by B as being packet #4 with #3 having been lost (or delayed).
Selective Repeat State Machines Receiver (start in state 0) state i expecting packet i receive packet i send ack i, let j be index of first “hole”, deliver packets i..j–1 state j receive packet k≠i send ack k, if k in i..i+W–1 and no copy of k in buffer, store k in buffer Sender (start in (0,0)) state (i,j) oldest unacked packet is i, next packet to send gets seq# j packet available and j–i<W send packet j, save copy, start timer Tj state (i,j+1) state (i’,j) receive ack k in i..j–1 discard packet k, clear timer Tk, let i’ be seq# of oldest unacked packet, or j receive ack k not in i..j–1 do nothing timer Tk times out resend packet k, restart Tk
Exercises Draw a time-space diagram for the go-back-N protocol with N=3, S=6, assuming that five packets are sent, and the second and fifth packets are lost the first time they are sent. Show the states of the sender and receiver.
Go-back-N with N=3, S=6 (0,0) (0,1) (0,2) P0 P1 (0,3) Draw a time-space diagram for the go-back-N protocol with N=3, S=6, assuming that five packets are sent, and the second and fifth packets are lost the first time they are sent. Show the states of the sender and receiver. Sender: (ack-waiting, nxt_pkt) Receiver: (expecting_pkt) Sender state starts at (0,0) and eventually ends at (5,5) when ack for P4 is received. Receiver state starts at 0 and ends at 5 P2 ✕ timeout A0 1 (1,4) A0 P1 P3 P2 P3 2 A0 3 (1,4) A1 (2,5) A2 (3,5) A3 (4,5) P4 ✕ timeout 4 P4 A4 5 (5,5)
Exercises Consider a link that uses go-back-N with S=10, N=5. Suppose 4 packets have been sent and 2 acks have been received. What is the smallest possible number of packets that could still be in the send buffer? What is the largest number?
Exercises Consider a link that uses go-back-N with S=10, N=5. Suppose 4 packets have been sent and 2 acks have been received. What is the smallest possible number of packets that could still be in the send buffer? What is the largest number? Consider a scenario, where the first and second packets are lost. This will trigger ACKs when the third and fourth packets arrive, acknowledging receipt of the packet before the first (or the SYN packet). Under such a scenario, the two acks will not be for any of the four packets that have been sent, so that the sender will still have all four in its send buffer. In the best case, the two acks are for the 3rd and 4th packets and there are zero packets left in the send buffer (acks for packets 1 and 2 were lost).
Exercises Draw a time-space diagram for the selective repeat protocol with N=3, S=6, assuming that five packets are sent, and the second and fifth packets are lost the first time they are sent. Show when each packet is delivered and the states of the sender and receiver at each step.
Selective Repeat with N=3, S=6 (0,1) Selective Repeat with N=3, S=6 (0,2) P0 P1 P2 ✕ (0,3) timeout A0 A2 Draw a time-space diagram for the selective repeat protocol with N=3, S=6, assuming that five packets are sent, and the second and fifth packets are lost the first time they are sent. Show when each packet is delivered and the states of the sender and receiver at each step. State starts at (0,0) and eventually ends at (5,5) when ack for P4 is received 1 P3 P1 (1,4) 1,2,3 4 A3 A1 (4,5) P4 ✕ 4 timeout P4 4 5
Exercises Consider a link that uses selective repeat with S=10, N=5. Suppose 4 packets have been sent and 2 acks have been received. What is the smallest possible number of packets that could still be in the send buffer? What is the largest number?
Exercises Consider a link that uses selective repeat with S=10, N=5. Suppose 4 packets have been sent and 2 acks have been received. What is the smallest possible number of packets that could still be in the send buffer? What is the largest number? With selective repeat, packets are acked individually. So in all cases, the receipt of two ACKs identifies two packets (out of four) that have been received. Hence, there will then be two packets in the sender’s send buffer (even if all four packets were successfully received). Note that in practice, selective acknowledgments are used in combination with cumulative ACKs, e.g., through the use of a SACK option as in TCP (see RFC 2018). This helps overcome the fragility problem caused by requiring that each packet be individually acked. In particular, TCP’s SACK option allows the receiver to inform the sender of multiple (up to 4) non-contiguous blocks of data it received. It is used in combination with regular ACKs.