Author: MobMsg, a senior full-stack engineer and partner at the architect community!
TCP/IP Protocol Family
The core protocol of the Internet is TCP/IP, which is widely used in both local and wide area networks and has a development history of over 20 years, making it the current international standard. TCP/IP is a protocol family that includes various protocols, network models, and layers as shown in the diagram.
Family portrait of the TCP/IP protocol family.
TCP/IP Five-Layer Network Model
Application Layer: Applications send and receive data over the TCP/IP interconnected network. They select the required service type and organize data according to the transport layer’s requirements, passing down either message sequences or byte streams.
Transport Layer: Provides communication services between application layers, also known as end-to-end communication. It offers reliable data transmission services, ensuring data is accurately and orderly delivered to its destination. After data is sent, a confirmation message must be returned by the recipient, and any lost data must be retransmitted by the sender. The object of transmission is transport layer packets.
Internet Layer: Also known as IP Layer, it is responsible for communication between machines. Upon receiving a request from the transport layer, it transmits information packets to the destination. These packets are encapsulated in IP datagrams, with routing algorithms determining whether to send them directly to the destination or pass them to a router, then passing the data down to the network interface layer. Upon receiving a datagram, it checks for correctness, with routing algorithms deciding whether to process locally or forward. If the destination belongs to the local network, it strips the header from the datagram and chooses the appropriate transport layer protocol to pass the packet up.
Network Interface Layer: Also known as Data Link Layer, it is located below the TCP/IP protocol layers and is responsible for receiving IP datagrams and sending them through the selected network.
Hardware Layer: Handles the hardware part of the network connection, including operating system control, device drivers, NIC (Network Interface Card), and physical visible parts like fiber optics (including connectors and all transmission media).
Responsibilities of TCP/IP Internal Protocols
Application Layer Protocol Functions
TCP Protocol Data Transmission Process
The Transmission Control Protocol (TCP) is the transport layer protocol for the Internet, providing a connection-oriented reliable transmission service, with reliability ensured by retransmission techniques. The size of the TCP header must be a multiple of 4 bytes, with a fixed header size of 20 bytes that remains unchanged.
Illustration of a TCP data packet.
ACK: Acknowledgment bit. When its value is 1, the acknowledgment number is valid. SYN: Synchronization request, used in TCP connections to negotiate the initial sequence number between the two parties. RST: Reset, used when an exception occurs during data transmission in a TCP connection and requires retransmission. FIN: Communication ends. When its value is 1, the connection is torn down.
TCP Three-Way Handshake to Establish Connection
First handshake: During connection establishment, the client sends a SYN packet (syn=i) to the server and enters the SYN_SEND state, waiting for server confirmation. SYN stands for Synchronize Sequence Numbers.
Second handshake: The server receives the SYN packet and must confirm the client’s SYN (ack=i+1), while also sending its own SYN packet (seq=j), which is the SYN+ACK packet. At this point, the server enters the SYN_RECV state.
Third handshake: The client receives the server’s SYN+ACK packet and sends an acknowledgment packet ACK(j+1) back to the server. After this packet is sent, both the client and server enter the ESTABLISHED state, completing the three-way handshake.
Illustration of the three-way handshake to establish a connection.
TCP Normal Data Transmission Process
This diagram illustrates the process of transmitting 2 data packets. Host A sends the first N bytes of data to Host B, with SEQ set to i. After Host B receives it, it must immediately send an acknowledgment ACK packet back to Host A, with ACK = i + N + 1, so that Host A can confirm the data transmission was successful. During the transmission of the second data packet, SEQ value = R, and after Host B receives it, it immediately returns ACK, with ACK = R + N + 1. This process continues, and it is important to note that the sender only clears the data in the buffer after receiving the acknowledgment from the recipient.
ACK acknowledgment bit = SEQ data number + transmitted byte count N + 1. The first byte’s SEQ number is randomly generated locally. The purpose of SEQ+N is to allow Host A to confirm whether all data sent to Host B was received or if there were any losses.
Illustration of normal data transmission.
TCP Data Retransmission and Fast Retransmission
-
Data Retransmission: Host A sends data to Host B, but an error occurs in between, and Host B fails to receive it. After a period of time, Host A does not receive the ACK confirmation packet from Host B, so it retransmits the data packet. Host A starts a timer each time it sends data; if no response is received within a specified time, it initiates retransmission.
-
Fast Retransmission: Retransmission occurs after a timeout, but when Host A receives more than 3 duplicate ACKs, it indicates that data has been lost and needs to be retransmitted. At this point, the retransmission timer has not expired, so it is called fast retransmission.
Illustration of data retransmission.
TCP Four-Way Handshake to End Connection
First handshake: The client sends a FIN to close the data transmission from the client to the server, entering the FIN_WAIT_1 state.
Second handshake: The server receives the FIN and sends an ACK to the client, with the acknowledgment number being the received sequence number + 1 (similar to SYN, one FIN occupies one sequence number). The server enters the CLOSE_WAIT state.
Third handshake: The server sends a FIN to close the data transmission from the server to the client, entering the LAST_ACK state.
Fourth handshake: The client receives the FIN and enters the TIME_WAIT state, then sends an ACK to the server, with the acknowledgment number being the received sequence number + 1, and the server enters the CLOSED state, completing the four-way handshake.
Illustration of the four-way handshake to end a connection.
TCP Sliding Window and Congestion Control
IP Protocol Data Transmission Process
The Internet Protocol (IP) is usually considered to provide a connectionless and unreliable service. However, in cases of good network performance, the data transmitted by IP can reach its destination intact.
Connectionless means that data is sent without confirming whether the target system is ready to receive it. Unreliable means that the destination system does not acknowledge the successful receipt of the packets.
Illustration of IP datagrams.
Sending Data via IP
When sending data, the IP protocol on the source computer needs to determine whether the destination is on the same network. If it is, direct communication is used; if not, communication must be completed via a gateway or router:
Host A assembles the destination IP address for Host B’s datagram, then performs routing selection, and sends the datagram to the default router (the router is determined by ARP address resolution, obtaining the mapping of the next default router’s IP address and MAC address, then forming a frame with that MAC address as the destination address, encapsulating the IP datagram in the frame’s data area, and finally completing the actual transmission of the datagram via a specific physical network (Ethernet)).
IP Forwarding Data
When the router receives the data frame from Host A, it removes the frame header and processes it, finding that the destination of this datagram is not local, so it needs to forward it. The next hop router address is determined by routing algorithms and the local routing table, and after determining the mapping of the next hop router’s IP address and MAC address through ARP address resolution, it uses that MAC address as the destination for the data frame, encapsulating the datagram into a data frame, and forwarding the data through Ethernet. This step is repeated until the Nth router is directly connected to the destination, at which point ARP address resolution determines the IP address and MAC address mapping of the destination host, using that MAC address as the destination address for the frame, encapsulating the IP datagram into a frame, and the actual transmission of data is achieved via Ethernet.
Receiving Data via IP
When Host B receives the data frame, it unpacks the frame and processes it, confirming that it is the destination address, then hands the encapsulated data in the datagram to the upper layer protocol for processing, and continues processing layer by layer until it reaches the application layer, completing the communication.
Five Important Features of TCP/IP
Logical Addressing: Ensures computers can be located through IP address + host ID.
Routing: Ensures data packets reach their destination through network path selection protocols.
Domain Name Resolution: Maps domain names to IP addresses, making them easier to remember and relatively stable.
Error Detection: Ensures the reliability of packet-switched transmission and confirms normal data reception.
Flow Control: Monitors network traffic to prevent congestion.
Long press to subscribe for more exciting content ▼
If you found this helpful, please give it a thumbs up. Thank you sincerely!