TCP

tcp-3-way-handshake

Transmission Control Protocol (TCP)

TCP (Transmission Control Protocol) is the most important Transport Layer Protocol. It is also one of the important Protocols of network world and Cisco CCNA Certification.  The other Transmission protocols are UDP and SCTP. We will talk about these protocols in another lessons like TCP vs UDP lesson. TCP Protocol is used in many cases in the computer networks. Here, we will focus on an overview of this important Protocol.

 

First of all, TCP is a Connection Oriented Transport Protocol. A TCP session must be established to use TCP. This TCP Session is established with a Three-way Handshake mechanism. And it can be terminated with Four-way Handshake mechanism. So how does these two important mechanism work? Let’s firstly check these mechanisms.

 


Three-Way Handshake

Three-way Handshake mechanism consists of three messages as its name implies. These messages are:

  • SYN
  • SYN-ACK
  • ACK

 

In these segments, related TCP Header Flags are set to 1. If it is a SYN message, SYN bit is set to 1. If it is a SYN-ACK message, SYN and ACK bits are set to 1. Or if it is an ACK message, ACK bit is set to 1.

 

tcp-3-way-handshake


 

Four-Way Handshake

Four-Way Handshake mechanism is used to terminate the TCP Sesssion. In Four-Way Handshake, both ends send two messages. Total 4 messages are sent. So what are the messages used in TCP Four-Way Handshake mechanism? These messages are given below:

  • FIN
  • ACK

 

In FIN message, FIN bit is set to 1. In ACK message, ACK bit is set to 1.

 

tcp-4-way-handshake

As you can see above, there are two different messages and these messages are sent from both ends to terminate the TCP sessions.

 


TCP Sequence Numbering & ACK Mechanism

Transmission Control Protocol is a Secure and Reliable Protocol. It guarantees the transport of the data. TCP Protocol controls the bits with Sequence Numbering and ACK mechanism. By using this mechanism, if are there any missing bits in the transmission, it retransmits these missing bits and it prevents data loss. So, TCP can be used for the critical applications that require high reliability.

 

Below, you can check Ack mechanism used by Transmission Control Protocol. Here, firstly the data which has sequence number 1 is sent. In our example, this is 10 bits data. After first 10 bit transmission, receiver sends forward  acknowledgement which means that you can send 11. bit. The sources sends another ten bits with sequence number 11 and then the destination sends forward acknowledgement for this transmission. With this ACK, it says, you can send 21. bit.


tcp-ack-mechanism

 

By the way, this is a basic explanation of TCP ACK Mechanism. In real life, certainly this transmission is done with more bits.
What if a packet is not recevied by the destination? This time the sender waits for a certain time and if it do not receive any ACK within this time, it sends the same segments with the same sequence number again. For the below example, after Sequence 1, there is no ACK, so, it retransmits the same data with the same sequence nubmer again. And then, the ACK is sent by the destination. With this mechanism, TCP provides a reliable data transfer.
tcp-ack-mechanism-2

TCP Flow Control and Window Scaling

TCP has also a Flow Control Mechanims. It controls the sent data with Window scaling. Here, a window size is used and the data is sent with this fixed size. The sender send data with a window size and it increase it every transmisssion. If the sender exceed a certain value, the destination sends an Acknowledgement that request to decrease window size. This is TCP Window Scaling mechanism.

 

For the below example, sender send the data with a window size 32768. The maximum segment size of this data is 1460, so, the sender sends 22 segments before receiving any ACK. After the receiver receives this data, it needs to decrease window size. So, it sends an Acknowledgement which sends the new window size as 16384. Then, the sender gets this message and this time sends 11 segments which has totally 16384 window size. This is basically how TCP Window Scaling works.

tcp-windowing

 


TCP Reordering Mechanism

In data transmission, sometimes bits can send out of order. The sender sends the data packets in different times and at the receiver side, this data must be reordered to create a meaningfull data. Transmission Control Protocol has this reordering mechanism. The packets that are sent unordered, are reordered at the destination

 

Below, after Sequence 1, Sequence 11 is sent. But for any reason like delay, the receiver receives Sequence 11, later than Sequence 21. At the receiver end,  this out of order data needs to be reordered. And TCP Reordering Mechanism do this job for a meaningful data.

 

tcp-reordering-mechanism-ipcisco

 


 

Well-known TCP Ports

Some protocols and applications uses TCP well-known ports. Below, you can find the protocols and the applications use only TCP  ports:

  • FTP Data (Port 20)
  • FTP Control (Port 21)
  • SSH (Port 22)
  • Telnet (Port 23)
  • SMTP (Port 25)
  • TACACS (Port 49)
  • HTTP (Port 80)
  • POP3  (Port 110)
  • SFTP (Port 115)
  • HTTPS (Port 443)

Beside, DNS uses both TCP and UDP port 53.

 

tcp-ports-tcp-vs-udp

 


 

TCP Header

TCP Header is a little complex if you compare with UDP Header. The total TCP Header length can 20 and 60 Bytes long in total.

 

What are the fields in a TCP Header? These TCP Header fields are given below:

  • Source Port (16 bits)
  • Destination Port (16 bits)
  • Sequence Number (32 bits)
  • Acknowledge Number (32 bits)
  • Length (4 bits)
  • Reserved Bits (3 bits)
  • Flags (9 bits)
  • Window Size(16 bits)
  • Checksum (16 bits)
  • Urgent Pointer (16 bits)
  • Options (0 to 320 bits.)

 

Below, you can find an example TCP header that resides between IP Header and Data.

 

tcp-header
 

In the following lessons, we will  talk about TCP Header fields and their roles detailly.

 

Lesson tags: tcp
Back to: CCIE Enterprise Infrastructure > TCP

Leave a Reply

Your email address will not be published. Required fields are marked *

CCIE Enterprise Infrastructure

Collapse
Expand
Latest Blog Posts