Click the blue “Programmer cxuan ” to follow me!
Add a “star“, feel free to chat!
Welcome to visit my Github
https://github.com/crisxuan/bestJavaer
When it comes to the protocols we encounter most in computer networking, it undoubtedly revolves around the TCP/IP protocol, which is also the most famous protocol on the Internet. Let’s talk about the TCP/IP protocol together.
Historical Background of TCP/IP
Before the TCP/IP protocol existed, in the 1960s, many countries and regions recognized the importance of communication technology. The US Department of Defense wanted to research a technology that could communicate through other routes even if communication lines were damaged. To achieve this technology, packet networks emerged.
Even during the communication process between two nodes, if several nodes are damaged, they can still communicate between the two nodes by changing the routes.
This packet network facilitated the birth of ARPANET (Advanced Research Projects Agency Network). ARPANET was the first wide-area packet-switched network with distributed control and was the predecessor of the first implementation of the TCP/IP protocol.
ARPANET was actually planned by the US Department of Defense’s Advanced Research Projects Agency.
Thus, the emergence of computer networks was initially driven by military research purposes.
In the 1990s, IOS initiated the OSI international standardization process, but did not achieve substantial progress, yet it led to the widespread use of TCP/IP protocols.
The rapid development of TCP/IP protocols may be attributed to their standardization. This means that the TCP/IP protocol involves standards that are not included in OSI, and these standards will be the main focus of our discussion next.
Let’s first understand the TCP/IP protocol. The TCP/IP protocol refers not only to the TCP and IP protocols but actually to a suite of protocols. What is a protocol suite? Simply put, it is a comprehensive set of protocols. If someone asks you what protocols are included in TCP/IP, you can show them the diagram below.
The above protocols summarized together form the TCP/IP protocol suite.
TCP/IP Standards
Compared to other protocol standards, TCP/IP emphasizes two points: openness and practicality, meaning whether standardization can be practically used.
Openness means that TCP/IP is formulated through discussions by the IETF, which is an organization that allows anyone to join discussions.
Practicality means that if a framework remains theoretical without practical application, it can never become mainstream.
The standard protocol of TCP/IP is what we know as RFC documents, which you can find online. RFC not only specifies protocol standards but also includes implementation and usage information.
For more RFC protocols, you can check the official documentation at https://www.rfc-editor.org/rfc-index.html
We will not elaborate further here; the focus of this article will be on the study of TCP/IP.
TCP/IP Protocol Suite
Next, let’s discuss the TCP/IP protocol suite.
The TCP/IP protocol is the one we programmers encounter the most. The OSI model has seven layers, from bottom to top: physical layer, data link layer, network layer, transport layer, session layer, presentation layer, and application layer. However, this is rather complex, so in the TCP/IP protocol, they are simplified into four layers.
Now, let’s start introducing these layers and the protocols between them, starting from the communication link layer.
Communication Link Layer
If we must subdivide, the communication link layer can also be divided into physical layer and data link layer.
Physical Layer
The physical layer is the lowest layer of TCP/IP, responsible for the hardware transmission, such as Ethernet or telephone lines and other physical layer devices.
Data Link Layer
The other layer is the data link layer, which is situated between the physical layer and the network layer. The data link layer defines how data is transmitted over a single link.
Network Layer
The network layer primarily uses the IP protocol, which forwards packet data based on IP addresses.
The main function of the IP protocol is to send packet data to the target host.
The functions of the Internet layer and transport layer in the TCP/IP layering are usually provided by the operating system.
IP also implicitly includes the functions of the data link layer. Through the IP protocol, hosts that communicate with each other can achieve communication regardless of the underlying data link.
Although IP is also a packet-switched protocol, it does not have a retransmission mechanism. Even if data does not reach the other end, it will not be retransmitted, so IP is considered an unreliable protocol.
Another protocol in the network layer is ICMP, which is used when an IP data packet encounters an exception during transmission. When an IP data packet cannot reach its target address due to an anomaly, it needs to send an exception notification to the sender, which is the main function of ICMP. Therefore, ICMP can also be used to diagnose network conditions.
Transport Layer
After just discussing the most important IP protocol in the TCP/IP protocol, let’s introduce the transport layer protocol, which includes the TCP protocol.
The transport layer is like a highway, connecting roads between two cities. Below is the logical channel of the Internet, which you can imagine as a highway.
The main function of the transport layer is to enable communication and data exchange between applications on the application layer. Many applications run inside a computer, each corresponding to a port number, which we generally use to differentiate these applications.
The transport layer protocols are mainly divided into connection-oriented protocol TCP and connectionless protocol UDP.
TCP
TCP is a reliable protocol that ensures the reliable delivery of data packets. TCP can correctly handle packet loss, transmission order errors, and other exceptions during transmission. In addition, TCP also provides congestion control to alleviate network congestion.
UDP
UDP is an unreliable protocol that cannot guarantee the reliable delivery of data. Compared to TCP, UDP does not check whether packets have arrived or whether the network is congested; however, UDP is more efficient.
UDP is commonly used in scenarios requiring less packet data or in video communication and multimedia fields such as broadcasting and multicasting.
Application Layer
In the TCP/IP protocol suite, the session layer and presentation layer from the OSI standard model are categorized under the application layer. The architecture of the application layer predominantly follows a client/server model, where the program providing services is called the server, and the program receiving the services is called the client. In this architecture, the server is usually deployed on a server in advance, waiting for the client to connect and provide services.
The Journey of Sending a Data Packet
Next, let’s introduce how a data packet is sent from one data packet to another through the application layer, transport layer, network layer, and communication link layer.
Data Packet Structure
First, let’s understand the structure of a data packet. Here, cxuan will give you a brief introduction; more detailed information will be provided in future articles.
In each layer above, a header is added to the data being sent, which contains necessary information for that layer. Each layer processes the data and attaches the necessary information of that layer to the data packet. Now, let’s discuss the process of sending a data packet.
Data Packet Sending Process
Assuming Host A and Host B are communicating, what peculiar operations does Host A perform to send a data packet to Host B?
Processing at the Application Layer
When Host A, the user, clicks on an application or opens a chat window and inputs cxuan, then clicks send, this cxuan travels as a data packet across the network. But wait, the application layer also needs to process this data packet, including character encoding, formatting, etc. This layer is actually the work done by the presentation layer in OSI, but in the TCP/IP protocol, it is all categorized under the application layer.
At the moment the data packet is sent, a TCP connection is established, which acts as a channel; thereafter, other data packets will also use this channel to transmit data.
Processing at the Transport Layer
To ensure that the information accurately reaches the other party, we use the TCP protocol for description. TCP is responsible for establishing connections, sending data, and disconnecting based on application instructions.
TCP will attach a TCP header field to the front of the application data, which includes source port number and destination port number. These port numbers indicate where the data packet is sent from and which application it needs to be sent to; the TCP header also contains a sequence number to indicate which byte of data this packet represents in the entire data from the sender; the TCP header also includes a checksum to check for data corruption, and then the TCP header is attached to the data packet and sent to IP.
Processing at the Network Layer
The network layer primarily handles data packets using the IP protocol. The IP protocol combines the TCP header and data received from TCP as its own data and adds its own IP header in front of the TCP header. Therefore, the IP packet is immediately followed by the TCP packet, and then the actual data follows. The IP header contains the destination and source addresses, along with information to determine whether the following data is TCP or UDP.
Once the IP packet is generated, the routing control table determines which host it should be sent to. The data packet modified by IP continues to be sent to the router or the network interface driver for actual data transmission.
If the target host’s IP address is unknown, the ARP (Address Resolution Protocol) can be used for lookup.
Processing at the Communication Link Layer
The data packet sent via IP will have an Ethernet header attached and be sent. The Ethernet header contains the MAC address of the receiving end, the MAC address of the sending end, and flags indicating the Ethernet data protocol.
Below is the complete processing and parsing process.
As shown in the image, the left side depicts the data sending process, where application data is processed layer by layer into a data packet that can be sent through physical media to the designated host.
The data packet receiving process is the reverse of the sending process, and the packet parsing similarly goes through the following steps.
Parsing at the Communication Link
When the target host receives the data packet, it first finds the MAC address in the Ethernet header to determine whether it is the intended recipient. If it is not, the data packet will be discarded.
If the received data packet is intended for itself, it will check the Ethernet type to determine which protocol it is. If it is IP, it will be passed to the IP protocol for processing; if it is ARP, it will be passed to the ARP protocol for processing. If the protocol type is unrecognized, the data packet will be discarded.
Parsing at the Network Layer
After the data packet is processed by Ethernet, it is passed to the network layer. Assuming the protocol type is IP, when IP receives the data packet, it will parse the IP header and check whether the IP address matches its own. If it matches, the data will be accepted, and it will determine whether the upper layer protocol is TCP or UDP; if not, it will be discarded directly.
Note: During routing and forwarding, sometimes the IP address may not be its own, at which point a routing table is needed to assist in processing.
Processing at the Transport Layer
In the transport layer, we default to using the TCP protocol. During the TCP processing, a checksum will be calculated to check if the data is corrupted. Then it checks whether the data is received in order, and finally checks the port number to determine which application program it corresponds to.
Once the data is completely identified, it will be passed to the application program identified by the port number for processing.
Processing by the Application Program
The specified application program on the receiving end will process the data sent by the sender, recognizing the content of the data through decoding and other operations, then storing the corresponding data on disk and returning a success message to the sender. If storing fails, an error message will be returned.
The above describes a complete data packet sending and receiving process. Throughout this process, various addresses, port numbers, protocol types, etc., are involved between different layers, so now let’s analyze this.
After passing through each layer, the protocol at that layer will attach a header to the data packet. Below is a complete diagram of the packet header.
During the data packet sending process, each layer sequentially adds header information to the data packet, with each header containing the sending and receiving addresses as well as the protocol type of the previous layer. Ethernet will use MAC addresses, IP will use IP addresses, and TCP/UDP will use port numbers to identify the addresses of both ends.
Additionally, each layer’s packet header also contains an identification bit that is used to mark the type of protocol of the previous layer.
Conclusion
In this article, cxuan is still discussing some fundamental knowledge. This foundational knowledge is a warm-up for the upcoming articles. In the next article, we will discuss the related knowledge of the data link layer. Stay tuned!
If you found this article helpful, I hope everyone can like, comment, share, and continue to support cxuan. Thank you all!
Previous Recommendations
🔗
One year of public account, cxuan’s secrets are all here.
Summary of Basic Computer Network Knowledge
This register article is quite interesting!
Sorry, after learning these Linux skills, I’m feeling a bit proud.
Additionally, cxuan has created six PDFs; reply cxuan in the public account to receive all author PDFs.