“ Hii! How are you? It has been so long since we met. 🤝” This can be one way of meeting someone. Humans communicate in this way. But how do the network devices communicate? Of course by handshake!! But how do they shake their hands and how do they speak? We will see their method of developing conversation.
If I am not wrong we have already discussed networking models such as TCP/IP and OSI. There are layers through which the information passes from one device to the other. Not remembering? Take a quick look at one of the models and come back! Now we shall look at the Transport Layer. As the name suggests it transports. How does it transport? Is that required? Well, yes!
Basic Introduction:
TCP or Transmission Control Protocol works at the transport layer along with the IP: Internet Protocol in the Network layer. TCP defines how the connection to be established between the two devices in a network and maintain them so that the applications at the application layer (the layer above the Transport layer in the TCP/IP Model) can exchange data. TCP works with Positive Acknowledgment with Retransmission (PAR) also known as Automatic Repeat ReQuest (ARQ). TCP is a connection-oriented and reliable protocol. It determines how the data should be broken down into packets and send over a network. Let us start with how all this procedure begins!
The dependency of TCP on IP and vice versa:
Let us assume a riddle or puzzle was broken down into pieces and the individual pieces were sent on the mail. This procedure best describes the TCP/IP relation. The mail has both the sender and receiver address written on it. It helps in delivering the mails to the destination address. The mail can travel through numerous paths and reach the target. Some might take longer than expected and some may reach earlier. This delivery system can be assumed as IP. Now, taking the analogy of mail to data packets, once the data is reached to the target address there is no acknowledgment that the data has been received. This is what makes the IP connection-less protocol. IP is the address system of the Internet. It is the primary way through which the connections are made, and it establishes the basis of the Internet.
IP doesn’t ensure the packet order. This is where TCP comes into the picture. It can be assumed as an assembler of the puzzle on the receiver side and asks for a resend if any of the pieces are missing. The data packets that are transmitted on a network are ordered according to their sequence numbers that are present in each segment. TCP and IP work together to maintain the connection and ensure the packet order. When a message is sent over a TCP, a connection is established and a three-way handshake is made. Why and how here we go!
Three-Way Handshake:
This is a process through which the connection in TCP/IP is established between two devices, basically a client and server.
Step 1: To establish a connection, the client sends a segment with an SYN (Synchronize) message stating that they should begin communication. This segment also consists of the Sequence number from which the segments start.
Step 2: Then the server replies with a segment containing ACK (Acknowledgment) increased by 1 for SYN of client + SYN message along with its sequence number.
Step 3: Again the client sends a segment containing ACK message with a sequence number of the server increased by 1.
Suppose we have the initial segment as SYN=100 from the client. Then the server responds with SYN=500 and ACK=100+1=101. As an acknowledgment of the SYN=100, the client responds with ACK=101 to the server. In this way, the Three-way handshake is performed between the two end devices. Steps 1 and 2 establish the connection in one direction and is acknowledged. Steps 2 and 3 establish a connection in the other direction and are acknowledged. Hence, a full-duplex connection is established.
The ACK in steps 2 and 3 are increased by 1 even though there is no payload transmission from either end. This is because the presence of SYN or FIN in the received packet increases the sequence number by one. The sequence number signifies the beginning numbers of the data transmitted by the host or the server. The incremented number also depicts that the receiver has received the packet with the earlier sequence number.
TCP Header Format:
The header of a TCP segment can vary between 20-60 bytes. 40 bytes are for options. In the absence of options field, the header is of only 20 bytes long. Here are the details.
Source Port: It is a 16-bit long field that holds the port address of the source or sender application.
Destination Port: It is a 16-bit long field that holds the port address of the destination or the receiver application.
Sequence Number: It is a 32-bit field. It is a unique number assigned by TCP to each byte contained in the TCP segment. It contains the sequence number of the first data byte. It is used to reassemble the packets or the segments in order at the receiver’s end.
Acknowledgment Number: It is a 32-bit field. It contains the sequence number of the data byte that the receiver expects from the receiver. It is always the sequence number of the last received data byte incremented by “1”. It is also an acknowledgment that the previous byte has been received.
Header Length or Data Offset (Acc to RFC 793 and RFC 4413): It is a 4-bit field that has the length of the TCP header. It helps in knowing where the actual data begins. If the header length is 20 (minimum), then this field holds the value 5 (5*4=20) as it is a 4-bit field. If the header length is 60 (maximum), then this field holds the value 15 (15*4=60). Hence the value ranges from 5 (minimum) to 15 (maximum). So, the scaling factor of header length is 4.
Reserved bits: These are 6-bits reserved for further use. All these are set to zero and are not used.
Control Flags: These are 6 1-bit control bits that control connection establishment, flow controls, connection termination, etc. The details of the flags are as follows:
URG: If this field is set to “1”, then it signifies that a certain amount of data in the segment should reach the destination on an urgent basis. The urgent data is pointed out by setting an urgent field and the receiver sends this data on a separate channel to the receiver.
ACK: It says if the acknowledgment number in the TCP header is valid or not. This field is set to 1 if the acknowledgment number is valid. Except for the case of the request segment, this field is always set to 1.
PSH: The data packets are stored in a queue and are put on the transmission line. The packet or the segment has to wait until its turn. This is more technically buffer. If the PSH field is set to 1, then the segments in the buffer are immediately put on the transmission line so that they will be sent to the receiver.
The difference between the URG and PSH fields is that the PSH doesn’t prioritize the segments as the URG does. It just pushes the segments from the buffer to the receiver immediately. The order is maintained the same and hence the same channel. It is not recommended to set PSH to 1 as it forces the receiver’s CPU to take action immediately thus disrupting the normal routine.
RST: It is used only when there are unrecoverable errors and if the connection cannot be closed normally. If it is set to “1”, it indicates that the connection should be terminated from both the ends and release all its resources abnormally. This might cause data loss of that in transit.
SYN: When it is set to “1”, it indicates that the sequence number present in the TCP header is the initial sequence number. It is set to “1” in the request segment sent for connection establishment during the three-way handshake.
FIN: If the connection has to be terminated between the two devices on a TCP connection, this field is set to “1”.
These are all about flags. All flags are 1-bit each. There are several references that tell there are 9 flags in the TCP header. Hence the references are added to the “References” section.
Window: It is a 16-bit field. It contains the size of the receiving window of the sender. It shows how much data can be sent by the sender without acknowledgment from the receiver. The window size changes dynamically. The size increases up to a point where the congestion is not detected. Once the congestion is detected, the window size decreases to avoid packet loss.
Checksum: It is a 16-bit field and maintains error control. It protects the integrity of the TCP payload. It ensures that the data is not lost. The Cyclical Redundancy Check (CRC) is added to the checksum (more information in the reference section) field before sending the data. If the CRC is not matched, the receiver rejects the data.
Urgent Pointer: It is a 16-bit field. It indicates how many bytes starting from the first byte are urgent. Urgent pointer added to the sequence number signifies the end of the urgent data byte. This field is only validated if the URG flag is set to “1”.
Options: This field can vary from 0 to 40 bytes. This field is used for several purposes. They are:
Timestamp: When the wrap-around time is less than the lifetime of a segment, the receiver may encounter packets with the same sequence numbers. In this scenario, it would be difficult at the receiver side to identify the correct segment. If the timestamp is used, it marks the age of TCP segments. Based on this timestamp, the receiver can identify the correct segment.
Window size extension: If the receiver wants to receive more data, then it can use the options field to communicate its greater window size. If only the windows field of TCP header is used, only 16-bits can be represented. The extra bits can be appended in the options field.
Parameter Negotiation: If the receiver or the sender wants to communicate their maximum segment size, there is no field in the TCP header. So, the size is appended in the options field.
Padding: If the size of the transmission unit is not matched with the standard size, then dummy data is filled in the unused space to make it to the mark. It is known as padding.
Let the total header length is 21 bytes which is not a multiple of 4. To make it to the standard length, 3 bytes are added to the options field. This is the worst case. Commonly, 1 or 2 bytes are added to the options field as padding.
Properties of TCP:
Session Multiplexing: It is the process of multiplexing multiple message streams into one and keeping track of which message belongs to which session. This session multiplexing is provided by the transport layer. The device with a single IP address can communicate with multiple servers at the same time. For example, a browser can access multiple websites that are on multiple servers. The requested data will be sent to the specific page/session from where the request is sent. To this to happen, TCP establishes a connection between the server and the client via the three-way handshake.
Segmentation: This is a process of breaking down the data into chunks to make the transmission easier. The Maximum Transmission Unit (MTU) of high-speed Ethernet is 1500 bytes. There exists one more term Maximum Segment Size (MSS) that signifies the total payload excluding the TCP, IP, and other headers. If the size of MTU is 1500 bytes and the TCP, IP headers are 20 bytes each, then the MSS would be 1460 bytes.
When a host initiates a connection with the server, the host negotiates the IP segment size by including the MSS value in the option field of TCP in the TCP SYN packet. This is similar to the parameter negotiation discussed in the Options field.
Flow control: There will be a wastage of time in retransmission if the sender sends the packets faster than what the receiver can process. TCP provides end-to-end flow control.
Connection-oriented: The connection is established before the actual transmission starts and the connection is terminated once the transmission ends.
Reliability: When a packet is lost or corrupted, then the receiver requests retransmission. In this way, TCP ensures complete packet delivery and hence the reliable protocol.
Neologism and Related Terms:
- Positive Acknowledgment and Retransmission (PAR) or Automatic Repeat Request (ARQ): This is a group of error-control protocols that are used to transmit data over noisy networks. They provide automatic transmission of frames if any of them are corrupted earlier. Read More!
- Maximum Transmission Unit (MTU): It is the largest packet size that can be transmitted on a network.
- Maximum Segment Size (MSS): It is a parameter of the Options field of the TCP header that specifies the largest amount of data, specified in bytes, that a computer or communications device can receive in a single TCP segment.
- Wrap-around Time: It is the time required to read all the sequence numbers that are transmitted.
- Protocol Data Unit (PDU): It is a specific block of the information transferred over a network. At different layers, these blocks are termed differently. Physical layer (raw bits 0s and 1s), Data Link Layer (Frames), Network Layer (Packets), Transport Layer (Segments), Session (the data passed to the network connection), Presentation Layer (data formatted for presentation) and Application Layer (the data transmitted or received by the software application). These are with reference to the OSI Model.
- Cyclical Redundancy Check (CRC): It is one of the error-detection methods based on binary division. The CRC generator is a polynomial where the coefficients give the value of the bits and the powers give the position of the bit. Read more!
7 thoughts on “TCP: Transmission Control Protocol”