Lecture 18:TCP Flow Control
Lecture 18
TCP Flow Control
Lecture 18:TCP Flow Control
TCP Send/Receive buffers
Lecture 18:TCP Flow Control
TCP Send/Receive buffers
• The received bytes over a TCP connection are
placed in the receive buffer.
• App process will read data from this buffer,
– not necessarily at the instant the data arrives.
– It may be busy with some other task
• If app process is relatively slow at reading data,
– the sender can very easily overflow the buffer
Lecture 18:TCP Flow Control
TCP Flow-Control
• TCP provides flow-control to eliminate the
possibility of the sender overflowing the
receiver’s buffer.
• It is a speed-matching service
– matching the rate at which the sender is sending
against the rate at which the receiving application is
reading.
Lecture 18:TCP Flow Control
TCP Flow-Control
• TCP sender maintains a variable called the
receive window.
– TCP is full-duplex, sender at each side of connection
maintains distinct receive window.
• It gives sender an idea of how much free buffer
space is available at the receiver
Lecture 18:TCP Flow Control
TCP Flow-Control
• Suppose that Host A is sending a large file to Host B
over a TCP connection.
• Host B allocates a receive buffer to this connection;
denote its size by RcvBuffer.
– The app reads from this buffer
Lecture 18:TCP Flow Control
TCP Flow-Control – Receiver
Side
• We define following variables
–LastByteRead: the number of the last byte in the data stream
read from the buffer by the application process in B
–LastByteRcvd: the number of the last byte in the data stream that
has arrived from the network and has been placed in the receive
buffer at B
Lecture 18:TCP Flow Control
TCP Flow-Control – Receiver
Side
• Because TCP is not permitted to overflow the allocated
buffer, we must have
– LastByteRcvd – LastByteRead <= RcvBuffer
• The receive window, denoted rwnd is set to the amount
of spare room in the buffer:
– rwnd = RcvBuffer – [LastByteRcvd – LastByteRead]
• Because the spare room changes with time, rwnd is
dynamic.
Lecture 18:TCP Flow Control
TCP Flow-Control – Receiver
Side
LastByteRcvd LastByteRead
Lecture 18:TCP Flow Control
TCP Flow-Control – Receiver
Side
• How does the connection use the variable rwnd to
provide the flow-control service?
• Host B tells Host A how much spare room it has in the
connection buffer by placing its current value of rwnd in
the receive window field of every segment it sends to A.
• Initially, Host B sets rwnd = RcvBuffer.
• How many rwnd variables should the Host B keep?
– One for each connection
Lecture 18:TCP Flow Control
TCP Flow-Control – Sender
Side
• What variables Host A should keep?
–LastByteSent and LastByteAcked
–LastByteSent – LastByteAcked, is the amount of unacknowledged
data that A has sent into the connection
• For flow control, Host A keeps the amount of
unacknowledged data less than the value of rwnd
–LastByteSent – LastByteAcked <= rwnd
Lecture 18:TCP Flow Control
TCP Flow-Control – Sender
Side
LastByteAcked LastByteSent
window
Sent and acked Sent but not acked Not yet sent
Next to be sent
12
Lecture 18:TCP Flow Control
Window Flow Control: Send Side
Packet Sent Packet Received
Source
SourcePort
Port Dest.
Dest.Port
Port Source
SourcePort
Port Dest.
Dest.Port
Port
Sequence
SequenceNumber
Number Sequence
SequenceNumber
Number
Acknowledgment
Acknowledgment Acknowledgment
Acknowledgment
HL/Flags
HL/Flags Window
Window HL/Flags
HL/Flags Window
Window
D.
D.Checksum
Checksum Urgent
UrgentPointer
Pointer D.
D.Checksum
Checksum Urgent
UrgentPointer
Pointer
Options…
Options… Options...
Options...
acknowledged sent to be sent outside window
13
Lecture 18:TCP Flow Control
One special case …
• Host B’s receive buffer becomes full so that rwnd = 0
• After advertising rwnd = 0 to Host A, also suppose that B
has nothing to send to A
• When buffer empties, how would A know?
Lecture 18:TCP Flow Control
Solution
• Host A continues to send segments with one data byte
when B’s receive window is zero.
• These segments will be acknowledged by the receiver.
Eventually the buffer will begin to empty and the
acknowledgments will contain a nonzero rwnd value.
Lecture 18:TCP Flow Control
Computer Networking: A Top Down Approach
6th edition
Jim Kurose, Keith Ross
Addison-Wesley
March 2012
A note on the origin of these ppt slides:
These slides are freely provided by the book authors and it represents a lot of work on their part.
We would like to thank J.F Kurose and K.W. Ross.