What is the role of each layer in the computer network layered model?

2023.02.16

What is the role of each layer in the computer network layered model?


The transmission unit of the network layer is a datagram (packet), and its task is to provide communication services between different network hosts and transmit data from the source to the destination. Use  IP addresses to identify devices on a network.

1. Layering of computer network

In the computer network system, the layered thinking is adopted to layer the necessary functions in the communication protocol. Each layer receives the specific services provided by its lower layer and is responsible for providing specific services for its upper layer. Serve. The agreement followed  by The interaction between the upper and lower layers is called "interface", and the agreement followed by the interaction between the same layer is called "protocol".

  • "Interface" is the connection point for exchanging positions between adjacent two layers, and it is the entrance for the upper layer to use the lower layer services.
  • "Protocol" refers to some agreements made by the two parties in communication, such as how to start communication, the format and order of information, how to end communication, etc.  Protocols are very important. In the process of learning computer networks, we focus on understanding various protocols, such as HTTP, DNS, TCP, etc.  Communication can only take place if both communicating parties support the same protocol at the same time.  Just like the communication between human beings, if a person only knows English, then speaking Chinese to him will not make sense.

picture

Why do computer networks adopt a layered model?  The main reason is that layering has the following advantages:

  • Layering is a common routine in software design, and it is also a common idea of ​​decoupling, which can effectively reduce the situation of "one hair will affect the whole body" in the program. Each layer is used independently for greater flexibility  , Even if some layers in the system change, it will not affect the entire system.
  • Layering can also decompose complex network problems into many smaller parts with clear and simple boundaries to deal with, making it easier to implement the protocol of each layer separately and define the specific responsibilities and obligations of each layer.

Of course, the more layers, the better, that is, layering may also have some disadvantages, such as sometimes over-modularization, which makes the processing more heavy, and different modules may have to deal with similar logic, resulting in redundancy and other issues.

2. Common reference models

In the early days of computer communication, each computer manufacturer produced its own network products to realize computer communication.  However, due to the lack of standardization, the various protocols set by different manufacturers are incompatible and cannot communicate across manufacturers.

In order to solve the above problems, the International Organization for Standardization ISO has formulated an international standard OSI reference model, which divides the computer network system into 7 layers and standardizes the communication system. The concept  of this model is clear, but it is very complex and difficult to implement, and has not been popularized.

For practical purposes, ARPA proposed the TCP/IP reference model (actually earlier than the OSI model), which divides the computer network into 4 layers.  This model takes the technology that can really realize communication as the primary task in the process of standard formulation (more attention is paid to how to realize, rather than the theory), and once any problems are found, the program, protocol or corresponding documents will be revised in time, and the model is more concise , and more practical, eventually became the industry standard.  But the concept of the network interface layer at the bottom of TCP/IP is not clear, and there is no specific content.

In order to facilitate the understanding of computer network principles, in computer network tutorials, the advantages and disadvantages of the OSI 7-layer model and the TCP/IP 4-layer model are usually integrated, and the computer network is divided into 5 layers, Which is concise and can explain the concept more clearly (of course, the actual The above application is still the TCP/IP model).

The schematic diagrams of several computer network reference models are as follows:

picture

3. Introduction to the 5-layer reference model

  • Application layer The transmission unit of the application layer is a message. The task is to complete specific network applications, such as transmitting emails, transmitting files, requesting and responding to web documents and other specific network functions. This layer is directly exposed to users. Common protocols include HTTP, FTP, DNS, SMTP.
  • Transport layer The transmission unit of the transport layer is a message segment, and its task is to provide communication services between different processes.  There may be many processes running on a host (for example, a user may be listening to music while chatting, and running different processes, so it is necessary to know which process the data should be sent to), which are distinguished by port numbers.  Common protocols include TCP and UDP.
  • Network layer The transmission unit of the network layer is a datagram (packet), and its task is to provide communication services between different network hosts, and to transmit data from the source to the destination. Use IP addresses to identify devices on a network  .  In addition to addressing, route selection is also required. When transmitting data from host A to host B, there are many routes that can be selected. The network layer uses the corresponding routing algorithm to calculate a suitable route. Common protocols include IP and  ICMP .
  • Data link layer The transmission unit of the data link layer is a frame, and its task is to provide communication services between different nodes (hosts or routers) interconnected on the physical level and on the same link. For example communication between 2 nodes connected  to 1 Ethernet.  Use MAC addresses to identify devices on a network.  The data link layer also provides functions such as flow control and error control.  The network connects many computers together, and the Internet connects many networks together through routers, so the Internet is also called "network of networks".  Usually, a single network is simplified into a link, and the data link layer serves different nodes in the same link. There are many types of communication links (such as Ethernet, WIFI, cable access network) and composed of different types of physical media (such as optical fiber, twisted pair, coaxial cable). Different network hosts may be far apart and span many  links .  Just like when we go from our company in Beijing to our hometown in Nanjing, we may pass through different roads such as highways, urban roads, and country lanes.
  • Physical layer The transmission unit of the physical layer is bit, and the task is to transparently transmit the bit stream (0/1 signal).  (Transparent transmission means that no matter what kind of bit combination the transmitted data is, it should be able to be transmitted on the link)

When two computers are communicating, the data will pass through different layers of the computer network.  When the sender transmits data between layers, each layer will add a header information (encapsulation) to which the layer belongs. For example, the transport layer will add information such as source port number and destination port number, and the network layer will add Information such as source IP address and destination IP address, the data link layer will add source MAC address and destination MAC address. Conversely, when the receiving end transmits  data between layers, it will erase (decapsulate) the corresponding header every time it passes through a layer.

This is similar to sending a courier. When the merchant sends the package, he will add a packaging box, a packaging bag, a delivery information sticker, etc., and pack it layer by layer. When the consumer receives the package, he needs to remove the package layer by layer to get the final product. commodity.

picture

references:

  1. "Illustrating HTTP"
  2. "Graphic TCP/IP"
  3. Computer Networks (7th Edition)

I'm Yifeng, a non-scientific programmer. I got offers from Byte, Meituan, and Ctrip during the cold winter of the Internet. In the  process of preparing for school recruitment, I compiled a "Back-end School Recruitment Interview Guide" , which includes Java foundation, concurrency, JVM, MySQL, Redis, MQ, Spring, computer network, operating system, etc., very comprehensive!