You are on page 1of 21

EEC 189Q:

Computer Networks

Error Recovery
ARQ
Stop-and-Wait, Go-Back-End, Selective Repeat
Analyzing ARQ Efficiency

Reading: 5.1-5.2

Error Recovery

Reliable delivery over unreliable channel


- How to recover from corrupted/lost packets
Error detection and retransmission
- With acknowledgements and timeouts
- Also called Automatic Repeat Request (ARQ)
- Retransmission incurs round trip delay
Error correcting codes
- Also called Forward Error Correction (FEC)
- No sender retransmission required

Chuah, Fall 2004 2

Page 1
Error Control

Automatic Repeat Request (ARQ)


- Basic concept: detect error and request retransmission
of those erroneous frames
- Different retransmission strategies:
Stop-and-wait, Go-back-N, Selective repeat

Two factors:
1) Correctness
- Do we succeed in releasing each packet, once and only
once, without errors?
2) Efficiency
- How much BW is wasted by unnecessary waiting and
unnecessary retransmission

Chuah, Fall 2004 3

Assumptions
To analyze different retransmission strategies,
we make the following assumptions:
1. The receiver knows when frames start and end.
2. All frames containing transmission errors are detected
3. Each transmitted frame experiences non-zero delay
before arriving at receiver. Some frames might be
lost. Those that arrive are assumed to arrive in the
same order as transmitted (with or without errors).

1 2 3 4 5
Node A
t
Lost X

Node B
X
Error detected
Chuah, Fall 2004 4

Page 2
Stop-and-Wait

Basic idea:
- Sender A transmits a packet, then wait
- If frame is error -free, B sends acknowledgement (ACK),
else, B sends a negative acknowledgement (NACK)
- Sender A sends next packet or retransmit when it
receives ACK or NACK

Problem 1: ACK/NACK could get lost too!


- Solution: Timer at sender!
- When node A times out, it retransmits the packet

Chuah, Fall 2004 5

Potential problems with the basic scheme

Unnumbered frames have problems!


Node A times out and resends frame

P P
Node A
t
ACK
Node B
Does this frame contain packet 0 or 1?
Release 1 st packet
to higher layer

Solution: Add sequence number in the frame


header

Chuah, Fall 2004 6

Page 3
Potential problems with the basic scheme

Not good enough => Unnumbered ACKs also


have problems!

Node A times out and resends frame


Sequence Number
0 0 1 2 t
Node A

ACK ACK NACK


Node B X
Release Discard duplicate
Packet 0

Solution: Return Sequence # of the next packet


expected instead of ACK/NACK
Chuah, Fall 2004 7

Stop-and-Wait ARQ

Timeout Timeout
Sequence Number
(SN)
t
0 0 1 1
Node A

RN=1 RN=1 RN=2


Node B X
Request Number
(RN) Release Discard duplicate
Packet 0

Note:
- Node A delays retransmitting packet 1 on the second
request of it to avoid unnecessary retransmission.

Chuah, Fall 2004 8

Page 4
Alternating Bit Protocol

Stop-And-Wait principles
Uses timers, seqnos (0/1), error detection bits
Frames and Acks are numbered with
- Alternating 0 and 1
At each instant, the receiver
- Expects a particular seqno
- Discards frames with wrong/unexpected seqno

Chuah, Fall 2004 9

Stop-and-Wait ARQ

Remaining problem: SN & RN can become


arbitrarily large with increasing time
- Send number modulo an integer
- Modulo 2 is sufficient!
Timeout

1 t
0 1 0
Node A

RN=1 RN=0 RN=0 RN=1


Node B

Release Release Discard


Packet 0 Packet 1

Chuah, Fall 2004 10

Page 5
Problem with Stop-and-Wait
Sender Receiver

Cant keep the pipe full


- Utilization is low when bandwidth-delay product is large
=> not very efficient
Example
- 1.5Mbps link x 45ms RTT = 67.5Kb (8KB)
- 1KB frames implies 1/8th link utilization
Can we do something else while waiting for an ACK?

Chuah, Fall 2004 11

Pipelining

Allow multiple outstanding (un-ACKed) frames


Upper bound on un-ACKed frames, called window
Sender Receiver

Time

Chuah, Fall 2004 12

Page 6
Pipelined Protocols

Sender allows multiple, in-flight, yet-to-be-acked pkts


- Range of sequence numbers must be increased
- Buffering at sender and/or receiver

Two generic forms of pipelined (sliding window) protocols:


- Go-Back -N and Selective-Repeat

Chuah, Fall 2004 13

Window-based ARQs

Idea:
- Allow Sender to keep transmitting a window of
packets while waiting for ACKs
Another function of sliding window protocols =>
Flow Control
- What happens if the sender tries to transmit faster than
the receiver can accept?
- Data will be lost unless flow control is implemented
- We will get back to this when we talk about TCP

Chuah, Fall 2004 14

Page 7
Sliding Window Protocols: Some Definitions

Sequence Number (SN): each frame is assigned a SN that is


incremented as each frame is transmitted

Sender Window: Keeps track of SNs for frames that have been sent
but not yet acknowledged.

Receiver Window: Keeps track of sequence numbers for frames


that the receiver is allowed to accept

Maximum Sender Window Size (W S): The maximum number of


frames the sender can transmit without receiving any ACKs

Maximum Receiver Window Size (W R): The maximum number of


frames the receiver may receive before returning an ACK to the
sender

Chuah, Fall 2004 15

Maximum Sender Window Size

With maximum window size of 1, the sender


waits for an ACK before sending another frame.
With maximum window size of WS , the sender
can transmit up to WS frames before being
blocked.
- allows sender to transmit several frames before
receiving an ACK
- also a form of pipelining => keeps the link from
being idle

Chuah, Fall 2004 16

Page 8
Maximum Receiver Window Size

With a maximum window size of 1, the receiver


must receive and process every frame in
sequence.
With a maximum window size of WR, the
receiver can receive and process up to frames
before acknowledging them.
- The receiver can still accept and buffer frames received
after a frame that is lost/erroneous.
- Allow piggybacking of ACK onto the header of an
outgoing data frame in the reverse direction
Full duplex transmission

Chuah, Fall 2004 17

Sliding Window Protocol: General Remarks

The sending and receiving windows do not


necessarily have the same maximum size.
Any frame whose SN falls outside of the receiver
window is discarded by the receiver.
The sender windows size grows and shrinks as
frames are transmitted and acknowledged.
Unlike the sender window, the receiver window
always remains at its maximum size.

Chuah, Fall 2004 18

Page 9
What About Errors?

What if a data or acknowledgement frame is lost


when using a sliding window protocol?
- Go-Back-N
- Selective Repeat

Chuah, Fall 2004 19

Go-Back-N Protocol
Sender keeps copy of up to W S outstanding packets
- k-bit sequence number, SN in packet header
When the receiver notices a missing/erroneous frame
- It discards ALL frames with greater SNs and sends no ACK
Sender timeout(i):
- retransmit all the frames in its sending window (packet i and all
frames after that with higher SNs )
Cumulative ACK
- ACK(i): ACKs all packets up to, including SN # i

WS

Chuah, Fall 2004 20

Page 10
Go-Back-N: Example

Consider W S = 4
Sender keeps copy of up to 4 outstanding packets

0 0 0 0 1 2 3 4
1 1 1 2 3 4 5
2 2 3 4 5
t
Node A 3 4 5
0 1 2 3 4 5

0 1 2 3
Node B
OK OK OK OK

Chuah, Fall 2004 21

Go-Back-N: Example 1
Rule: when error occurs, retransmit packet plus
all subsequent packets
Timeout

0 0 0 0 0 0 0 0
1 1 1 1 1 1
2 2 2 2
t
Node A 3 3
0 1 2 3 0 1 2 3
X

0 1 2 3
Node B

Discard!
Receiver does not need to buffer packets
- WR = 1
Chuah, Fall 2004 22

Page 11
Go-Back-N: Example 2
Rule: when error occurs, retransmit packet plus
all subsequent packets

Timeout

0 0 0 0 1 2 2 2
1 1 1 2 3 3
2 2 3 4
t
Node A 3 4
0 1 2 3 2 3
4
X
0 1 2 3
Node B
Discard!

Chuah, Fall 2004 23

Go-Back-N with Negative ACKs

0 0 0 0 1 2 2 2
1 1 1 2 3 3
2 2 3 4 t
3 4
Node A
0 1 2 3 2 3
X 4

NACK
0 1 2 3
Node B
Discard!

Chuah, Fall 2004 24

Page 12
Remarks on Go-Back-N

Go-Back-N can recover from missing frames


But ....

It is wasteful! If there are errors, the sender will


spend time retransmitting frames the receiver has
already seen!

Chuah, Fall 2004 25

Selective Repeat

Receiver individually acknowledges all correctly received packets


- buffers all the correct frames that arrive following the bad one, for
eventual in-order delivery to upper layer
- When receiver notices a skipped SN, it keeps acknowledging the last
good SN

Sender only resends packets for which ACK not received, but not
all its successors
- Sender timer for each unACKedpacket

Sender window
- N consecutive SNs
- limits SNs of sent, unACKed pkts

Chuah, Fall 2004 26

Page 13
Selective Repeat ARQ

As in Go-Back-N
- Packet sent when available up to window limit
Unlike Go-Back-N
- Out-of-order (but otherwise correct) is ACKed
- Receiver: buffers out-of-order packets
- Sender: on timeout of packet k, retransmit just k
Comments
- More receiver buffering than Go-Back-N
- More complicated buffer management by both sides
- Saves bandwidth
no need to retransmit correctly received packets

Chuah, Fall 2004 27

Selective Repeat: Example 1


Packet n must not be sent until packet n- W S has been
acknowledged (to avoid overloading receiver buffer)

Timeout

0 0 0 0 0 0 0 0 4
1 1 1 1
2 2 2 2
t
Node A 3 3 3 3
0 1 2 3 0 4
X

1 2 3 0
Node B
OK OK OK OK
Receiver Buffer 1 1 1
2 2
3 Release packet 0,1,2,3 to upper layer

Chuah, Fall 2004 28

Page 14
Selective Repeat: Example 2

Timeout

0 0 0 0 1 2 2 2 2 6
1 1 1 2 3
2 2 3 4 4
Node A 3 4 5 5 5
0 1 2 3 2 6
4 5
X
3 4 5 2
0 1
Node B
OK OK OK OK OK OK
3 3 3
Release 4 4
5 Release 2,3,4,5

Chuah, Fall 2004 29

SW: Sender
Assign sequence number to each frame (SeqNum)
Maintain three state variables:
- send window size (SWS)
- last acknowledgment received (LAR)
- last frame sent (LFS)
Maintain invariant: LFS - LAR <= SWS
SWS

LAR LFS

Advance LAR when ACK arrives


Buffer up to SWS frames

Chuah, Fall 2004 30

Page 15
SW: Receiver
Maintain three state variables
- receive window size (RWS)
- largest frame acceptable (LAF)
- last frame received (LFR)
Maintain invariant: LAF - LFR <= RWS
RWS


LFR LAF

Frame SeqNum arrives:


- if LFR < SeqNum < = LAF accept
- if SeqNum < = LFR or SeqNum > LAF discarded
Send cumulative ACKs

Chuah, Fall 2004 31

Summary

Data Link Control (DLC) Layer takes care of:


- Framing
- Error detection
- Error correction or retransmission
ARQ Retransmission Strategies:
- Stop-and-wait, Go-Bank-N, Selective Repeat
- Two important factors:
a) Correctness (safety & liveness)
b) Efficiency

Chuah, Fall 2004 32

Page 16
Analyzing Efficiency of ARQ
Protocols
Let
t proc = time to process a packet ~ 0 at a node
t prop = one way propagation time
t pkt = transmission time of a packet

Efficiency or Utilization:
E= time spent transmitting useful data _
total time spent (incl. waiting & retransmissions)

Efficiency Without Errors

S Proc
TransP Trans_P
Node A

Node B
TransA
Prop Proc Prop

Efficiency = ________________TransP________________
TransP + 2(Prop + Proc) + TransA

= TransP
S

Chuah, Fall 2004 34

Page 17
Efficiency with Error
Timeout, T

p
S

A 1-p B

Let p = Prob (error) & = time to send a packet


E[] = (1-p)S + p (T+E[])

E[] = p/(1-p)T + S

Efficiency = __TransP_
E[]
Choose T ~ S => Efficiency = (1-p)TransP
S
Chuah, Fall 2004 35

Efficiency of Stop-and-Wait ARQ

Without error,
E = ___tpkt_____
tpkt + 2 tprop
Let a = tprop / t pkt , E = 1/(1+2a)

With Error p, E = ___t pkt_____


Nr (t pkt + 2 tprop )
where Nr = expected # of transmission for a frame.
Nr = 1/(1-p)

So, E (stop-and-wait, p) = _1-p_


1+2a

Chuah, Fall 2004 36

Page 18
Selective Repeat Protocol: Efficiency Analysis

S
W
Node A

Node B

Without error:
Efficiency = min { (W x TransP)/S , 1 }

Chuah, Fall 2004 37

Analysis (Contd)

S
W = infinity

Node A

Node B

Let p = Prob(error), W = infinity


_1__
Expected number of attempts to send a packet =? 1-p
Efficiency = ? ____TransP_____ = 1 - p
TransP/(1-p)

Chuah, Fall 2004 38

Page 19
Efficiency of Sliding Window Protocol

Let
W = window size
S = timeout, and assume S > tpkt + 2 tprop
So, if W. t pkt > t pkt + 2 t prop , the link is always full with packets.

Without error,
- E=1 if W > 2a+1
- E = __W_ if W < 2a+1
2a+1

Chuah, Fall 2004 39

Efficiency of Selective Repeat (SR)

With Error p, the error free equation needs to be


divided by N r which is 1/(1-p):

- E (SR, p) = (1-P) if W > 2a+1


- E (SR, p) = _W(1-p_) if W < 2a+1
2a+1

Chuah, Fall 2004 40

Page 20
Efficiency of Go-Back-N
Similar to the case of SR, except that we have to be careful
in approximating Nr. Each error requires a retransmission
of K frames rather than just one frame.

Nr = f ( i) p i1 (1 p )
i =1

where f(i) = total # of frames transmitted if original frame


must be transmitted i times f (i ) = 1 + (i 1) K = (1 K ) + Ki

So,
Nr = (1+ K + Ki) pi 1 (1 p)
i=1
= (1+ K )(1 p) pi 1 + K (1 p) ipi 1
i =1 i =1
1 1
= (1+ K )(1 p ) + K (1 p )
1 p (1 p) 2
1 p + Kp
=
(1 p)

Chuah, Fall 2004 41

Efficiency of Go-Back-N
K depends on the window size!
- K = 2a+1 if W > 2a+1
- K=W if W<2a+1
Efficiency of Go-Back-N with probability of error p:
- E (GBN, p) = 1/N r if W > 2a+1
- E (GBN, p) = _ W if W < 2a+1
N r ( 2a+1)

1 p 1 p
If W > 2a+1, E (GBN, p) = =
1 p + ( 2a + 1) p 1+ 2ap

W W (1 p)
If W < 2a+1, E (GBN, p) = =
1 p + Wp (1 p + Wp )( 2a + 1)
( 2a + 1)
1 p

Chuah, Fall 2004 42

Page 21

You might also like