Title: Flow Control and Buffering
1Flow Control and Buffering
- In this section
- Buffer organization
- Flow control
- Go-back-N
- Selective repeat/reject
- Deadlock avoidance
- Examples
2Flow Control and Buffering
- Flow control keep a fast transmitter from
overrunning a slow receiver. - Buffering by the sender, if network is
unreliable - Sender must store frames that are sent in a
buffer until they are acknowledged by receiver. - Frames that are lost (that is, they are not
acknowledged within a timeout) are retrieved from
buffer and resent. - When the network is reliable
- If sender knows that receiver always has
available buffer space, and can accept all
incoming frames, the sender may not need a buffer.
3Buffer Organization
- Chained, fixed-size buffers
- Best for protocols where frames are of similar
size
Frame
Frame
Frame
Unused
- Single, large circular buffer
- Good for heavily loadedconnections, with
variablesized frames - For lightly loadedconnections, much ofbuffer
may remainunused
Frame 1
Frame 2
Frame 3
Unused
4Buffering at Sender versus Receiver
- Depends on the type of traffic carried by the
connection. - Low bandwidth, bursty traffic
- Example interactive terminal session with
occasional key strokes. - Avoid allocating buffers in advance.
- Dynamic allocation as needed
- Sender cannot be sure that receiver can always
allocate a buffer, so sender must retain frame
until acknowledged. - Buffer at sender.
- High bandwidth, continuous traffic flow
- Example audio, video, large file transfer
- Receiver should allocate a full set of buffers to
keep flow at maximum speed.
5Adjusting Buffer Allocation
- Sender and receiver should be able to dynamically
adjust to changes in traffic flow. - Sender may be able to request receiver to
allocate an amount of buffer space. - Receiver can inform sender of how much buffer
space is available. - Buffers can be allocated separately per
connection, or for all communication between the
two hosts. - General method for dynamic buffer allocation
- Use a sliding window protocol, but decouple
buffer allocation from acknowledgments.
6Flow control methods
- Simple Stop-and-wait
- Sender sends frame, and must receive positive
acknowledgement from receiver before sending next
frame. - Automatic Repeat reQuest (ARQ)
- Frames sent with a sequence number to identify
frames - Receiver will inform sender if
- There is no more buffer space.
- A damaged frame is detected.
- On request, sender must
- Stop transmission.
- Re-send frames.
7Go-back-N ARQ
- Frames transmitted continuously (when available)
up to window size N. - (Logically) different timer associated with each
frame not yet acknowledged. - Receiver
- Acknowledge (ACK) frame if correctly received and
in order pass to higher layer. - Negative acknowledge (NACK), or ignore (possibly
discard) corrupt, or out-of-order frame. - Sender
- If NACK received, or timer expires, for frame n,
begin resending from frame n all over again - ACK of frame n implicitly acknowledges up to n
8Selective Repeat ARQ
- As in Go-Back-N
- Frames transmitted when available up to limit.
- Timer associated with each unacknowledged frame.
- Receiver NACKs or ignores corrupted frames.
- Differences
- Out of order, but otherwise correct, frame is
ACKd. - Receiver buffers out of order frames.
- Sender on timeout or NACK of frame n, resend
only single frame n
sequence number
x 1
x
x 1
x 2
x 3
x 4
x 5
x 6
received and delivered to user
received and buffered
not yet received
9Comparison
- Go-back-N ARQ
- Simplicity in buffering and protocol processing
at sender and receiver. - If receiver discards bad or out of order
messages, no receiver buffering is required. - More retransmission traffic with unreliable
network. - Selective repeat ARQ
- More receiver buffering required.
- More complex buffer management for both sender
and receiver. - Saves bandwidth avoids retransmission of
correct frames.
10Sliding Window, Go-Back-N (1)
- Assumption Frames contain a k bit sequence
number - Sequence numbers cycle modulo 2k
- Next sequence number after 2k 1 is 0.
- More on this later!
- Initially, sender requests a certain number of
frame buffers from receiver, using a special
control message. - Receiver replies with number of buffers granted
- This defines a window size for sender.
- Each time sender sends a frame, it increments its
sequence number, starts a timer, and decrements
its buffer allocation. - If timeout occurs, frame is assumed to be lost
and must be re-sent, followed by all subsequent
frames.
11Sliding Window, Go-Back-N (2)
- If senders buffer allocation reaches zero, it
must stop sending until more buffers are granted
by receiver. - Receiver sends acknowledgments that include
- Highest sequence number of consecutively numbered
frames that have been successfully received (the
Go-Back-N rule). - Number of buffers available.
- Based on acknowledgment number, sender knows how
many frames can be discarded from sending buffer.
12Go-Back-N Example (1)
Assumption sequence number is 4 bits
A Message B Comment
- ? ltack 15, win 4gt ? B grants window size 4
A sets window to 0-3 - ? ltseq 0, data m0gt ? A adjusts window to
1-3 - ? ltseq 1, data m1gt ? A adjusts window to
2-3 - ? ltseq 2, data m2gt ... Message lost, but
A thinks window is 3 - ? ltack 1, win 3gt ? B grants window size 3,
following message 1 2-4 A adjusts
window to 3-4 - ? ltseq 3, data m3gt ? A adjusts window to
4
13Go-Back-N Example (2)
A Message B Comment
.
- ? ltseq 4, data m4gt ? A has to stop sending
new frames window - ? ltseq 2, data m2gt ? A times out for
acknowledging frame 2 and resends - ? ltseq 3, data m3gt ? Resend of frame 3
- ? ltseq 4, data m4gt ? Resend of frame 4
- ? ltack 4, win 0gt ? B acknowledges up
to frame 4, but has no buffers yet, so
A is still blocked with window
14Go-Back-N Example (3)
A Message B Comment
.
- ? ltack 4, win 1gt ? B grants window size
1 after message 4 A sets window to 5 - ? ltack 4, win 2gt ? B grants window size
2 after message 4 A sets window to
5-6 - ? ltseq 5, data m5gt ? A adjust window to
6 - ? ltseq 6, data m6gt ? A adjust window to
- ? ltack 6, win 0gt ? Both messages
received by B, but A is still blocked - ... ltack 6, win 4gt ? B grants window size
4 7-10 but message never arrives at A
15Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
ack 15, win 4
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
16Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
0
m0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
17Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
18Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
19Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
0
m0
ack 1, win 3
1
1
m1
1
1
m1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
4
4
m4
4
4
m4
20Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
m3
3
3
m3
3
3
m3
4
4
m4
4
4
m4
21Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
m3
2
m4
3
2
2
m2
4
3
m3
3
3
m3
4
4
4
m4
4
4
m4
22Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
2
2
2
m2
2
m2
3
3
3
m3
4
4
4
m4
23Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
3
m3
3
m3
4
4
4
m4
24Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
3
m3
3
m3
4
4
4
m4
4
m4
25Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
ack 4, win 0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
2
m2
3
3
m3
3
3
m3
3
m3
4
4
m4
4
4
m4
4
m4
26Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
ack 4, win 1
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
4
4
m4
4
4
m4
5
5
m5
5
5
m5
27Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
ack 4, win 2
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
4
4
m4
4
4
m4
5
5
m5
5
5
m5
6
6
m6
6
6
m6
28Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
4
4
m4
4
4
m4
5
5
m5
5
5
m5
5
m5
6
6
m6
6
6
m6
29Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
4
4
m4
4
4
m4
5
5
m5
5
5
m5
6
6
m6
6
6
m6
6
m6
30Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
4
4
m4
4
4
m4
5
5
m5
5
5
m5
5
m5
ack 6, win 0
6
6
m6
6
6
m6
6
m6
7
7
m7
7
7
m7
8
8
m8
8
8
m8
9
9
m9
9
9
m9
10
10
m10
10
10
m10
31Go-Back-N Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
4
4
m4
4
4
m4
ack 6, win 4
5
5
m5
5
5
m5
6
6
m6
6
6
m6
7
7
m7
7
7
m7
8
8
m8
8
8
m8
9
9
m9
9
9
m9
10
10
m10
10
10
m10
32Avoiding deadlocks
- Note that control frames (the acknowledgments /
buffer allocations) are not themselves sequenced,
timed out, or confirmed. - As seen at point 19 in previous example,
deadlocks are possible if buffer allocations may
be lost. - To avoid this, both hosts should periodically
send status updates - In previous example, B would not be receiving new
frames. - B would send ltstatus, ack 6, win 4gt
periodically. - Hopefully, one of these messages will get
through, and A will restart. - A may also send ltstatus, ack 6, win 0gt
periodically while blocked. - On receiving inconsistent status message, B would
retransmitltack 6, win 4gt.
33Window size versus Sequence Numbers
- A sequence number consisting of m bits allows for
n 2m sequence numbers - Suppose we allow a window of size n 1
- example m 2, n 4, window 5
- Ensure that the sequence number range is much
larger than potential window sizes
1 ? ltack 3, win 5gt ? B grants 5
buffers 2 ? ltseq 0, data m0gt ? Message
received 3 ? ltseq 1, data m1gt ? Message
lost 4 ? ltseq 2, data m2gt ? Message
lost 5 ? ltseq 3, data m3gt ? Message
lost 6 ? ltseq 0, data m4gt ?? A thinks it is
out of buffers 7 ? ltack 0, win 4gt ? Was it
line 2 or line 6 that this refers to?
34Selective Repeat
- Here is the same example, but using selective
Repeat - In particular
- Frame 2 will be lost on the first send attempt
- Receiver will NACK frame 2 after frame 3 arrives
- However, frame 3 is kept at receiver
- Sender will resend frame 2 after NACK arrives
- Receiver should not adjust window size with a
NACK message
35Selective Repeat Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
ack 15, win 4
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
36Selective Repeat Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
0
m0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
37Selective Repeat Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
38Selective Repeat Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
39Selective Repeat Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
0
m0
ack 1, win 3
1
1
m1
1
1
m1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
4
4
m4
4
4
m4
40Selective Repeat Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
3
m3
4
4
m4
4
4
m4
41Selective Repeat Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
nack 2
2
2
m2
2
2
m2
3
3
m3
3
3
m3
3
m3
4
4
m4
4
4
m4
42Selective Repeat Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
m3
2
m2
3
2
2
m2
2
3
m3
3
3
m3
4
3
m3
4
4
m4
4
4
m4
43Selective Repeat Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
1
1
m1
1
1
m1
m3
2
m2
3
2
2
m2
2
3
m3
3
3
m3
4
3
m3
4
4
m4
4
4
m4
m4
4
44Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
ack 4, win 0
1
1
m1
1
1
m1
2
2
m2
2
2
m2
2
m2
3
3
m3
3
3
m3
3
m3
4
4
m4
4
4
m4
4
m4
45Example
B
A
seq.
data
seq.
data
0
0
m0
0
0
m0
ack 4, win 1
1
1
m1
1
1
m1
2
2
m2
2
2
m2
3
3
m3
3
3
m3
4
4
m4
4
4
m4
5
5
m5
5
5
m5