TCP provides flow control between a sender and receiver to prevent buffer overflows. It works by having the sender maintain a receive window size, which indicates the available free buffer space at the receiver. The sender ensures it doesn't send more data than the receive window size allows. TCP also uses a three-way handshake to establish connections between a client and server. This involves the client sending a SYN packet, the server responding with a SYN-ACK, and the client replying with an ACK to open the connection. Connections are closed using a four-step process where each side sends a FIN packet and acknowledges the other's FIN.
3. TCP Flow Control
• Host has a receiver buffer on each side of TCP
connection.
• 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.
4. Problem arises……
• 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
host(receiver).
• 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.
5. Continues….
• 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
receiver.
• Since TCP is full duplex, sender at each side of
the connection will maintains a receiver
window.
7. • Variables used in this scenario:
1.LastByteRead
2.LastByteRcvd
• Receive window is represented by RcvWindow
• RcvWindow=RcvBuffer-[LastByteRcvd-LastByteRead]
• TCP is not allow the sender to overflow the allocated receiver
buffer.
• LastByteRcvd-LastByteRead <=RcvBuffer.
• Spare room is changes with time, RcvWindow is dynamic.
8. How RcvWindow is used?
• Host B tells Host A no of spare room available in its
connection buffer.
• 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:
1.LastByteSent
2.LastByteAcked
• LastByteSent - LastByteAcked=No of Unacknowledged
data
9. Continues….
• By keeping the unacknowledged
data value less than the value of
RcvWindow, Host A ensure that it
does not overflow the RcvBuffer at
Host B.
• LastByteSent-LastByteAcked <=
RcvWindow
10. TCP Connection Management
Client Server
Client- server scenario :In which process running in one host (client)
wants to connects with the process running on the other host (server).
11. Connection………
• 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
following manner.
12. 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
segment.
• This segment is encapsulated with IP datagram
and sent to the server.
13. 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.
14. Establish a connection(3)
• Step 3: Once client receives the connection granted
segment , client also allocates buffers and variables to
the connection.
• 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
segment header.
• SYN bit is set to zero , since connection gets
established.
• In order to establish a connection, three packets are
sent between two hosts, Therefore this connection
procedure referred as three-way hand shake.
15. 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
1.
• Step 3: client receives FIN, replies with
ACK. Enters “timed wait” -will respond
with ACK to received FINs
• Step 4: server, receives ACK. Connection
closed.
Note: At this point ,all resources in the host
will be deallocated.
18. RTT Estimation
• 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.
19. Continues ……
• Sample RTT values will be fluctuate from one
segment to segment due to congestion in routers.
• Because of this fluctuation , some RTT value may
be atypical.
• 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 by
• EstimateRTT=(1- α).EstimatedRTT +
α.sampleRTT
20. Continues…….
• In the above formula,
1. EstimatedRTT is the weighted combinations of the
previous value of estimated RTT and the new value for
sample RTT.
2. α=0.125
Formula will be,
EstimateRTT=0.875.EstimatedRTT +
0.125.sampleRTT.
Now the EstimatedRTT is the weighted
average of the sample RTT values.
Such an average is called Exponential weighted
moving average