TCP Flow Control
• Host has a receiver buffer on each side of TCP
• Data will be placed in the receive buffer only if
the received data is correct.
• Application process running on the receiver host
will read data from this buffer.
• Receiving application may be busy with
some other work.
• Data has to wait for a long time until it is read
by application process which is running on
• Sender can easily overflow the receiver
buffer by sending too much of data quickly.
• To overcome this problem ,TCP provides
flow control service to its applications.
• Flow control is a speed matching service the
rate at which sender is sending , against the rate
at the receiving application is reading.
• TCP provides flow control by having the sender
maintain a variable called the receive window.
• The receiver window is used to give the sender a
number of free buffer space is available at the
• Since TCP is full duplex, sender at each side of
the connection will maintains a receiver
File Transfer scenario
Host A Host B
• Variables used in this scenario:
• Receive window is represented by RcvWindow
• TCP is not allow the sender to overflow the allocated receiver
• LastByteRcvd-LastByteRead <=RcvBuffer.
• Spare room is changes with time, RcvWindow is dynamic.
How RcvWindow is used?
• Host B tells Host A no of spare room available in its
• By placing the current value of RcvWindow in the
receive Window field of every segment it sends to A.
• Initially , RcvWindow=RcvBuffer
• Host A keep track of two variables:
• LastByteSent - LastByteAcked=No of Unacknowledged
• By keeping the unacknowledged
data value less than the value of
RcvWindow, Host A ensure that it
does not overflow the RcvBuffer at
• LastByteSent-LastByteAcked <=
TCP Connection Management
Client- server scenario :In which process running in one host (client)
wants to connects with the process running on the other host (server).
• Client application process informs the
client TCP that it wants to establish a
connection to a process in the server.
• Client TCP proceeds to establish a
connection with TCP in the server in the
Establish a connection(1)
• Step 1: client TCP send a special segment to
server side TCP which does not contains
application layer data.
• SYN bit in client segment header will be set to 1.
• So , this segment is called as SYN segment.
• Client chooses an random sequence
number(client_isn) and placed this number in the
sequence number field of TCP client SYN
• This segment is encapsulated with IP datagram
and sent to the server.
Establish a connection(2)
• Step 2: Once TCP datagram arrives at server host , it extracts
the TCP SYN segment from the datagram allocates the TCP
buffers and variables to the connection and sends a
connection granted segment to the client TCP.
• This segment also contains no application data.
• It contains 3 important information:
1.SYN bit set to 1
2.Acknowledgement field of TCP segment
header is set to client_isn+1.
3.Own sequence number(server_isn)
Connection segment is also referred as SYNACK segment.
Establish a connection(3)
• Step 3: Once client receives the connection granted
segment , client also allocates buffers and variables to
• Client sends a host a another segment which
acknowledges the server connection granted segment
by putting the server_isn+1(server sequence
number)in the acknowledgement field of the TCP
• SYN bit is set to zero , since connection gets
• In order to establish a connection, three packets are
sent between two hosts, Therefore this connection
procedure referred as three-way hand shake.
Closing a connection
• Step 1: client end system sends TCP FIN
set to 1 control segment to server
• Step 2: server receives FIN, replies with
ACK. Closes connection, sends FIN set to
• Step 3: client receives FIN, replies with
ACK. Enters “timed wait” -will respond
with ACK to received FINs
• Step 4: server, receives ACK. Connection
Note: At this point ,all resources in the host
will be deallocated.
• How to estimate RTT?
Sample RTT for a segment is the amount
of time between when the segment is sent
and when an acknowledgement for the
segment is received.
• TCP never computes a sample RTT for a
segments that has been retransmitted ; it
only computes sample RTT for a segment
that has been transmitted.
• Sample RTT values will be fluctuate from one
segment to segment due to congestion in routers.
• Because of this fluctuation , some RTT value may
• So, in order to estimate the typical RTT ,there is a
need to take a average of all sample RTT values.
• After obtaining new sampleRTT,TCP updates
• EstimateRTT=(1- α).EstimatedRTT +
• In the above formula,
1. EstimatedRTT is the weighted combinations of the
previous value of estimated RTT and the new value for
Formula will be,
Now the EstimatedRTT is the weighted
average of the sample RTT values.
Such an average is called Exponential weighted