I put together my previous articles to become Github, welcome everyone big guy star github.com/crisxuan/be… This article has been submitted
TCP/IP is one of the most popular protocols on the Internet.
Historical background of TCP/IP
In the early days before TCP/IP, that is, in the 1960s, many countries and regions realized the importance of communication technology. The U.S. Department of Defense wants to develop a technology that would allow communication over other routes even if a communication line is destroyed. To implement this technique, packet networks emerged.
Even if several nodes are damaged in the process of communication between the two nodes, the communication between the two nodes can still be achieved by changing the line and other ways.
This grouping Network promoted the birth of ARPANET(Advanced Research Projects Agency Network). ARPANET is the first wide-area packet-divided T group switching network with distributed control, and also the predecessor of TCP/IP protocol.
ARPANET was actually planned by the U.S. Defense Advanced Research Projects Agency.
So, computer networks started out as military research.
In the 1990s, IOS initiated the international standardization process of OSI, which made no real progress, but enabled the widespread use of TCP/IP.
This rapid development of TCP/IP may be due to the standardization of TCP/IP. That is, TCP/IP involves standards that OSI does not, and that will be the focus of our discussion.
TCP/IP is more than just TCP and IP. In fact, TCP/IP refers to a protocol cluster. What is a protocol cluster? In short, it’s a collection of protocols, and the next time you ask what TCP/IP is, you can show them this diagram
The TCP/IP protocol cluster is the summary of the above protocols.
TCP/IP standard
Compared with other protocol standards, TCP/IP pays more attention to two aspects: openness and practicality, that is, whether the standardization can be used in practice.
Openness means that TCP/IP is discussed by the IETF, and the IETF itself is an organization that allows anyone to join the discussion.
Practicality is to take the framework for example, if only floating in theory, but not the practice of the ground, then it will never become the mainstream.
The standard protocol for TCP/IP is known as the RFC document, which you can see on the web. RFC not only regulates protocol standards, but also includes the implementation and use of protocols.
For more information about the RFC protocol, you can check out the official documentation www.rfc-editor.org/rfc-index.h…
Instead of going into detail, we will focus on TCP/IP in this article.
TCP/IP protocol suite
Let’s start with the TCP/IP protocol cluster.
TCP/IP is the protocol we programmers are most exposed to, OSI model has seven layers, from bottom to top are the physical layer, data link layer, network layer, transport layer, session layer, presentation layer and application layer respectively. But this is obviously a bit complicated, so in TCP/IP they are reduced to four levels
Next we introduce these layers and the protocols between them, starting with the communication link layer.
Communication link layer
Communication link layer can also be divided into physical layer and data link layer if necessary.
The physical layer
The physical layer is TCP/IP and the lowest layer is the hardware responsible for transmission, which is the physical layer equivalent of Ethernet or telephone lines.
Data link layer
The other layer is the data link layer, located between the physical layer and the network layer. The data link layer defines how data is transmitted over a single link.
The network layer
The network layer mainly uses IP protocol, which forwards subcontracted data based on IP addresses.
The main function of THE IP protocol is to send packets to the target host
The functions of the Internet layer and transport layer in the TCP/IP layer are usually provided by the operating system.
IP also implies the function of the data link layer. Through IP protocol, hosts that communicate with each other can communicate with each other regardless of the underlying data link.
Although IP is also a packet switching protocol, it does not have a retransmission mechanism. Even if the data does not reach the other end, it is not retransmitted. Therefore, IP is a non-reliability protocol.
Another protocol at the network layer is ICMP. When an IP packet fails to reach the destination address due to an exception, ICMP sends an exception notification to the sender. This is the main function of ICMP. Because of this, ICMP can also be used to diagnose network conditions.
The transport layer
We have just introduced TCP/IP, the most important IP protocol, now let’s introduce the transport layer protocol, TCP is a transport layer protocol.
The transport layer is like a highway that connects the two cities. Here is the logical path of the Internet, which you can think of as a highway.
The main function of the transport layer is to enable communication and data exchange between applications at the application layer. There are many applications running inside the computer, and each application has a port number. We usually use the port number to distinguish these applications.
Protocols at the transport layer are 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 and transmission order disorder during transmission. TCP also provides congestion control to ease network congestion.
UDP
UDP is an unreliable protocol that cannot ensure reliable data delivery. Compared with TCP, UDP does not check whether data packets arrive or whether the network is blocked. However, UDP is more efficient.
UDP is used for video communication and multimedia fields such as broadcasting and multicast with little packet data.
The application layer
In TCP/IP protocol cluster, the session layer and presentation layer in OSI standard model are classified as application layer. The architecture of the application layer mostly belongs to the client/server model. The program that provides the service is called the server, and the program that receives the service is called the server. In this architecture, the server is typically deployed to the server in advance, waiting for the client to connect to the server to provide the service.
Packet sending process
Let’s take a look at how a packet sends one packet to another through the application layer, transport layer, network layer and communication link layer.
Packet structure
Let’s first get to know the structure of packet. Here CXuan only gives you a brief introduction, which will be introduced in more detail in the following articles.
In each of the above layers, a header is added to the data being sent that contains the necessary information for that layer. Each layer processes the data and encloses the packet with the necessary information for that layer. Let’s talk about the packet sending process.
Packet sending history
Suppose host A and host B are communicating, and host A wants to send A packet to host B, what strange operations will it undergo?
Application layer processing
Host A means that the user clicks an application or opens A chat window to input CXuan, and then clicks send. Then the CXuan will travel in the network as A packet. There is more to wait. This layer is the work of the OSI presentation layer, but in TCP/IP it all falls into the application layer.
At the moment a packet is sent, it establishes a TCP connection, which acts as a channel, after which other packets use the channel to transmit data.
Transport layer processing
In order to describe the information can accurately reach the other party, we use TCP protocol to describe. TCP is responsible for establishing connections, sending data, and disconnecting connections according to the instructions of the application.
TCP adds a TCP header field to the front end of the application data layer. The TCP header contains the source port number and destination port number. These two port numbers are used to indicate where packets are sent and to which application. The TCP header also contains serial number, which is used to indicate that the data in the packet is the serial number of the number of bytes in the whole data of the sender. The TCP header also contains a checksum to determine whether data is corrupted. The TCP header is then appended to the header of the packet and sent to the IP address.
Network layer processing
The network layer is mainly responsible for the processing of data packets is the IP protocol, IP protocol TCP transmitted from the TCP head and data combined as their own data, and in the TCP head front add their OWN IP head. Therefore, IP packets are followed by TCP packets, followed by the data itself. The IP header contains the destination and source addresses, followed by information to determine whether TCP or UDP follows.
After the IP packet is generated, the routing control table determines which host it should be sent to. The IP modified packet is sent to the router or the driver of the network interface to realize real data transmission.
If you do not know the IP Address of the target host, you can use the Address Resolution Protocol (ARP) to search for it.
Communication link layer processing
When packets are sent through IP, the Ethernet attaches the Ethernet header to the data and sends it. The Ethernet header contains the MAC address of the receiving end, the MAC address of the sending end, and the Ethernet data protocol that identifies the Ethernet type.
The following is the complete processing and parsing process.
As shown in the figure above, data is sent on the left. After layer upon layer processing, data at the application layer is turned into data packets that can be sent to the specified host through physical media.
The packet receiving process is the reverse process of the packet sending process, and the packet parsing also goes through the following steps.
Communication link resolution
After receiving a packet, the destination host checks the MAC address of the Ethernet header to determine whether the packet is destined for itself. If the packet is not destined for itself, the destination host discards the packet.
If the packet is sent to the device, the device checks the Ethernet type and protocol. If the packet is IP, the device throws it to the IP protocol for processing. If the packet is ARP, the device throws it to the ARP protocol for processing. If the protocol type is an unrecognized protocol, the packet is discarded.
Network layer resolution
The packet processed by Ethernet is thrown to the network layer for processing. We assume that the protocol type is IP. Then, after receiving the packet, THE IP address in the IP header is parsed to determine whether the IP address in the IP header matches its own IP address. If yes, the device receives the data and determines whether the protocol of the upper layer is TCP or UDP. If no match is found, the packet is discarded.
Note: In the process of routing and forwarding, sometimes the IP address is not its own. In this case, the routing table is required to assist in processing.
Transport layer processing
In the transport layer, we use TCP by default. During TCP processing, the checksum is calculated first to determine whether the data is corrupted. Then check whether the data is received by serial number, and finally check the port number to determine which application it is.
Once the data is fully identified, it is passed to the application identified by the port number for processing.
Application processing
The application program designated by the receiver will process the data transmitted by the sender, identify the content of the data through decoding operations, and then store the corresponding data on the disk. The application program will return a message indicating that the data is saved successfully to the sender. If the data fails to be saved, an error message will be returned.
The above is a complete packet sending and receiving process, in the above data sending and receiving process, involves the address, port number, protocol type, etc., between different layers, so we will analyze it now.
After the packet passes through each layer, the layer protocol attaches the packet header to the packet. A complete packet header is shown below
In the packet sending process, each layer adds header information to the packet. Each header contains the address of sender and receiver and the protocol type of the upper layer. Ethernet uses MAC addresses, IP uses IP addresses, and TCP/UDP uses port numbers to identify hosts at both ends.
In addition, packets in each layer also contain an identifier bit at the head, which identifies the type of protocol at the previous layer.
conclusion
In this article, Cxuan is still talking with you about some basic knowledge, which is prepared for the following article in advance. In the next article, we will talk about relevant knowledge of data link layer, please look forward to it.
Hello, I’m Cxuan, a technical person. I wrote a total of six PDFS
Summary of Java Core Technology, Summary of HTTP Core, Basic Knowledge programmers must know, Summary of Operating System Core, Java Core Foundation 2.0, Summary of Java Interview Questions
Now I put out the Baidu link to you, you can click the link below to get
Link: pan.baidu.com/s/1mYAeS9hI… Password: p9rs