Sunteți pe pagina 1din 30

Advanced Networks CC531

Week 07 TCP protocol


Transfer Control Protocol (TCP)

IP transmits data between individual computers on the Internet TCP transfers data between two actual applications running on these two computers IP address is the address only of a computer's network interface TCP uses a port number as its address

TCP is connection oriented The transferred bytes are numbered Lost or damaged data is requested again

The ends of the connection ( Source and Destination) are specified with the port number This number is two-byte, so its value can vary between 0 and 65535 Port numbers are expressed with a backslash and the protocol name tcp (i.e. 53/tcp) Port 53/tcp has nothing in common with port 53/udp

The operating system uses the target port number to recognize to which application it should deliver the TCP segment

A TCP segment is inserted into an IP datagram.

IP datagrams are inserted into a link frame. If the size of the TCP segment is too big to be entered into an IP datagram without exceeding the maximum capacity of the link frame (MTU), the IP has to perform fragmentation on the TCP datagram

TCP header is transported in the first IP fragment only

Establishing and Terminating a Connection with TCP

Establishing a Connection
A client wants to establish a connection with the server running on the Server computer on port 4433 (i.e. Server:4433) The client uses port 1458 for the connection The server port must be a well-known port

The client begins establishing a connection by sending the first TCP segment (segment 1)

A random number for the Initial Sequence Number ISN=145165778

The sequence number will always be incremented by the sent byte number so it cannot be generated again

The second segment already confirms data received; it has the ACK flag set. It confirms one byte of data received the acknowledgment number of the confirmed byte expresses the number of the next byte that the source may send. Thus the source may send ISN+1

With the third segment, connection establishment ends. Therefore we can say that TCP requires threephase handshaking for establishing a connection


Terminating a Connection
the client that establishes the connection, but either side can close the connection. The first side to send a TCP segment with the FIN (end of connection) flag carries out an active close The second side has no choice but to carry out a passive close.

Four TCP segments are required for properly closing a connection segment 6 begins the active close of the connection with the set FIN flag. Segment 7 confirms the connection closure (passive close) if segment 8 also contained the FIN flag, it would cause the entire connection to begin closing


Segment 7 does not contain the FIN flag, because the right side wants to continue the connection (i.e. it wants to use a half closed connection to transmit application data) The side that closed the connection cannot send any more data When the second party has sent what it wanted to, it sets up the FIN flag in the last segment (8) and waits till the termination of connection is confirmed (9)

Determining the Connection State

using the netstat command with the a parameter.


The Proto column contains the name of the protocol used (TCP or UDP). The Recv-Q column displays the number of bytes in the connection input queue (waiting to be processed by an application). The Send-Q column displays the number of bytes in the output queue (waiting to be sent). The Local Address column contains the address of the local network interface The Foreign Address column contains the IP address and port number of the remote side of the connection. The (state) column displays the connection state.

Window Technique
A problem arises when a client needs to send large amounts of data Example:
the client has established a connection with the server They agreed on a Maximum Segment Size (MSS) of 1 K (or 1024 B) And window size of 4 K (or 4096 B).

The client begins transmitting data and sends segments 1, 2, and 3.

The server returns a confirmation (segment 4) from the server that confirms segments 1 and 2.
The client in return sends segments 5, 6, and 7, but the server has not had enough time to process the data and its buffer has been exhausted. Segment 8 therefore confirms that segments 3, 5, 6, and 7 were received, but at the same time, it closes the window for the client.

In other words, the client cannot continue sending data.

After the server processes part of the data, it allows the client to proceed with transmitting data again.

Segment 9 does not fully open the window; it only opens 2 K because not all of the data in the buffer memory has been processed and there is no 20 space for more.



Network Congestion
A window (WIN) is the amount of data that the destination is able to receive Although the window size is determined by the destination, the problem also extends to the source
If the source is fast and the destination is slow, then the source could jam up the network with data up to the window size

Data loss is always bad and our goal is to avoid it whenever possible The source-side window is called the congestion window (CWND) The source gradually increases the CWND The threshold after which network congestion is likely to occur is called SSTHRESH

Slow Start
The source sets the CWND dynamically
it sends one segment and waits for its confirmation. If it receives confirmation, it sends two segments. If it receives a confirmation again, it sends four segments and so on.

after a few rounds, the source reaches the window size (WIN) or will flood the network and will not receive confirmation because congestion occurs. In other words, it has to send the segments again because a segment got lost. At this point, the CWND is reduced by half

This value is entered as the SSTHRESH value.

If the SSTHRESH is smaller than two segments, then its value is set to two segments.

segment got lost somewhere on route.

The destination did not receive the segment so it is still confirming the last received segment After the destination repeats its confirmation for the last received segment three times, the source decides the segment as lost and resends it.

the source does not receive any confirmation at all within the defined time limit.
In this case, the CWND is set to the size of one segment (segsize) the SSTHRESH is set to twice the size of a segment (2xsegsize) the slow start is started over from the beginning.


Congestion Avoidance
For each connection, the source keeps the actual values of the MSS, WIN, CWND, and SSTHRESH
1. If CWND is less than or equal to SSTHRESH, then we are dealing with a slow start. It is therefore possible to try to send double the amount of data.


2. If CWND is already larger than SSTHRESH, then sending double the amount of data would probably cause congestion.
In this case the CWND is only increased by segsizexsegsize/CWND+segsize/8 counted in integers. This minor increase of the CWND is called the Congestion Avoidance Algorithm.


Libor Dostalek, Alena Kabelova,Understanding TCP/IP a clear and comprehensive guide to TCP/IP protocols, Packet publishing 2006