Hello ~ dear audience gentlemen! First, I want to explain why I wrote this topic. It originated from a packet capture shared by my colleagues at the back end. Of course, at the time there was a lot of confusion about the terminology of network programming, and I could only laugh in embarrassment. For the most basic OSI model, only seven layers are known, but what each layer is, what it is used for, and what protocols are completely unknown. Therefore, after realizing shame, I supplemented relevant knowledge by reading books and looking up information, and this article was created.

There may be audience master will ask, the front end know what use this, usually basic use is not it? This is true, we usually only contact with the application layer OF HTTP protocol, we can not care about the underlying protocol. But some scenarios require some low-level knowledge. For example, the principle of front-end general optimization is to make as few requests as possible, so why can load optimization be made by making fewer requests, and what is the cost of it? For example, recent products hope uv hit the same computer only, but it is likely that users will use different clients to use the product, and how to develop the product face. Think about it carefully, in fact, many situations also need a little low-level knowledge, so don’t book to time square hate less ah ~

This article will introduce the protocols related to each layer of the seven-layer model, and also describe the role of each layer through the metaphor of a Courier company. I hope you found it interesting.

Basic knowledge of

Open System Interconnect (OSI) stands for Open System interconnection. Commonly known as the OSI reference model, it is a network interconnection model developed by ISO (International Organization for Standardization) in 1985. The architecture standard defines a seven-layer framework for network interconnection (physical layer, data link layer, network layer, transport layer, session layer, presentation layer, and application layer) known as the ISO Open Systems Interconnection Reference Model. In this framework, the functions of each layer are further specified to achieve interconnection, interoperability and portability of applications in an open system environment.

The above is the summary of Baidu OSI model, here just need to remember that the model has 7 layers, the first layer is the physical layer, and the last layer is the application layer. So how are the different layers organized and communicated? Take a look at the image below:

Starting at the highest level, the sender transfers data sequentially from top to bottom, and when each layer receives data processed by the upper layer, the header of that layer is added and may process the data (e.g., the presentation layer). The receiving end will reverse the order, starting from the first layer, the content of the data and the corresponding head of the layer, to the previous layer. Looks pretty convoluted, right? To put it simply, imagine that A is going to send A fragile item to B, and the express station where A is located has A packaging process consisting of seven people. Each person only receives the packed item from the previous person and puts A larger box on the outside to pass it to the next person. When the goods are sent to B’s express station, there are also seven people responsible for opening the box, each person only opens one, and finally gives the goods to B. Is that easy to understand?

At that time, WHEN I saw here, I do not know whether the reader and I have the same question: in fact, such layers, different layers must have similar processing logic, processing is also troublesome, is it necessary to layer? However, the problem is also easy to understand, after stratification, if one layer changes, it does not affect the whole system. We also know that each layer actually has a different protocol, and if the layers are mixed together, there is no way to switch protocols, and every time you change one layer, you have to change the whole system. This is the same reason why the front end uses a framework that lets us layer our code by MVC or MVVM. Clearly defining the roles of each layer contributes to the robustness of the system.

So what is the protocol at each level, and what does it do? Look down from the top.

The application layer

As a front end, the application layer is certainly the most familiar. Its role is to provide services to the application and specify the communication details of the application, that is, to provide services to the application. Common protocols include HTTP, FTP, TELNET, SMTP, etc.

In our daily development, the protocol we contact is mainly HTTP, so consider the browser as an application. When the user initiates a request, the data is obtained through HTTP protocol for the browser to use, which is the purpose of the application layer. The application layer is also responsible for handling errors that occur during requests.

This layer can be thought of as the receiver of a Courier company. When the customer (application) calls (initiate a request) to the receiver (application layer), the receiver can provide different services (different protocols) according to the different needs of the user, such as next-day delivery, designated time delivery, etc.

The presentation layer

The role of the presentation layer is to convert the information processed by the application into a format suitable for network transmission, or to convert the data from the next layer into a format that the upper layer can process. It is mainly responsible for data format conversion. Specifically, it means converting the data format inherent to the device into a network standard format. Common protocols include ASCII, SSL/TLS, etc.

The effect may seem convoluted, but it’s actually quite understandable. I can only speak Chinese, and my Japanese friend can only speak Japanese, so we can’t communicate. But if we both speak English, I will first think about what I want to say in English and then say it in English, and then my Japanese friend can understand me when he hears English and translates it into Japanese in his mind. At this time, the expression level is each other’s mental translation of language. The browser requests a bunch of data back, and it’s up to the presentation layer to parse it into text or images. Data compression, encryption, packaging and other functions are also completed in this layer.

This floor is the equivalent of a packager at a delivery company. If the delivery (data) is too bloated, he flattens (compresses) it without breaking the delivery. If customers care about security lines, all-in-one delivery companies can also package packages in SSL/TLS boxes and deliver them faster. Of course, the packer will make sure that the unpacker at the destination express station can unwrap the package and deliver it to the user without damage.

The session layer

The session layer is responsible for establishing and disconnecting communication connections (logical paths through which data flows), as well as data transmission-related management such as data partitioning. Common protocols include ADSP and RPC.

The session layer can be thought of as a dispatcher for a delivery company. He is in charge of the information related to the delivery. For example, this time the customer wants to send 100 tons of sand (data), where to send it? Should we send it by car or by ship? These are his duties. After the shipment, the relevant information (connections) can also be destroyed, which is the responsibility of the dispatcher.

The transport layer

The transport layer plays the role of reliable transport. It is processed only on the communication nodes, not on the router. This layer has two representative protocols: TCP and UDP.

TCP provides reliable communication transmission. To put it simply, data is transmitted only when the target can communicate (therefore, a three-way handshake is required). If data is lost during transmission, data is retransmitted. UDP, on the other hand, does not confirm whether the target can communicate with each other, but sends the packets to the port of the corresponding address. As for the other party received or not received, lost or not lost the bag, no matter.

The transport layer has an important role in specifying communication ports. Take the request server data for example, the server has the ability to handle a variety of protocols, such as HTTP, FTP, TELNET, etc., but what protocol do you use? The server doesn’t know. However, if you specify a port, such as 80, the server will know that you want to use HTTP and will naturally forward it to the corresponding protocol handler for processing.

As a metaphor, the transport layer can be seen as a Courier company’s merchandiser. The responsible merchandiser (using TCP protocol) ensures that the package is delivered to the customer, and if not, the company sends it again. The irresponsible merchandiser layer (using UDP protocol) simply delivers the package to the customer’s designated location, regardless of whether the package is delivered to the customer.

The network layer

The network layer is responsible for transferring data to the destination address. Destination address An address that allows multiple networks to be connected through a router. This layer is therefore responsible for addressing and routing. The protocol consists of IP and ICMP.

The network layer sends data from the host at the sending end to the host at the receiving end. There may be many data links between the two hosts, but the network layer is responsible for finding a relatively smooth path to transfer data. The transport addresses use IP addresses. The IP address is somewhat similar to our address, which can be narrowed down from province to city to street to our address. IP addresses also have the ability to reach the destination address by continuously forwarding to the nearest IP address. How to choose this path is up to the network layer.

It’s like a route planner for a delivery company. Express companies have many distribution centers, according to the situation of distribution centers (congestion), find a path through n distribution centers to transport the goods (data) along the road.

Data link layer

This layer is responsible for the transmission of communication between interconnected nodes on the physical layer. For example, communication between two nodes connected to an Ethernet. Common protocols include HDLC, PPP, SLIP, etc.

The data link layer will divide the sequence of 0 and 1 into meaningful data frames and send them to the peer end (generation and reception of data frames). A better example might be to think of the data that needs to be transferred as different sources of water, but if you pour it directly into a pool, you can’t distinguish between different sources of water. But if you put water from different sources into a bottle and mark it, you can tell the water from different sources. This is why data frames are divided into meaningful frames and sent to the peer end. Note also that the data link layer is only responsible for transporting data to the physically connected ends, not directly to the final address.

The data link layer can be thought of as a driver for a Courier company who drives a car and moves packaged goods (data frames) from one city (physical nodes) to another.

The physical layer

The physical layer is responsible for the exchange of 0 and 1 bit streams (0 and 1 sequences) with voltage levels and flashes of light. Typical protocols are RS 232C, RS 449/422/423, V.24, X.21, X.21BIS, etc.

It looks great, but it actually converts 0 and 1 of data into electrical or optical signals. Through optical fiber, twisted-pair cable or even infinite radio waves to a specified address. The hub, repeater and modem in the transmission process also belong to the transmission medium of the physical layer. The physical layer is the physical basis of the OSI seven-layer model, without which data transfer is impossible.

The physical plane is carried by physical objects, so metaphorically, roads, cars, planes and other vehicles carrying goods (data) are symbols of the physical plane.

At this point, the functions and protocols of the OSI seven layer model are simply introduced

summary

The above is just a superficial introduction to the OSI seven-layer model, which I hope will help you understand it better. However, due to the limited space and my lack of ability, many details of the seven-layer model are still not involved. If you want to have an in-depth understanding, you should also read relevant materials carefully to deepen the understanding of each layer model.

Thank you to see the adult here ~ hope this article is helpful to you. Because MY knowledge of this aspect contact is not deep, so it is inevitable that there are mistakes, I hope you dalao hit my face, let me know where the understanding is wrong, ensure that soon correct oh ~ thank you!

The resources

Diagram to TCP/IP

Introduction to Internet Protocol (1)

Open Systems Interconnection Reference model