TCP/IP study notes 1-protocol layering

TCP/IP study notes 1-protocol layering

Hierarchical concept

The network protocol is hierarchical, and the hierarchical concept is similar to function encapsulation, continuously providing more advanced and abstract interfaces, and finally providing them to customers. For layered protocols, the entire protocol completes one thing together. Each layer completes the functions of this layer based on the interface of this layer or lower layer and provides interfaces for higher layers. That is, for each layer, there are the following two The main function:

  • Provide interface for high-level: encapsulate the functions of this level for high-level call
  • Realize this layer function: realize the function in this layer, generally by calling the interface provided by the lower layer (except the lowest layer)

To give an example, to realize the function of calculator calculation, we implement a calculator protocol, which is divided into the following levels:

  1. User input layer: the highest layer, used to provide data input methods and result output methods, to achieve mutual conversion between user input and logic language
  2. Logic compilation layer: the middle layer, which converts the logic language into code that can be realized by hardware, realizes calculation, and converts the result into logic language
  3. Hardware layer: the bottom layer, which realizes the calculation of the code and the output of the result

Suppose that the manufacturer builds a handwritten calculator based on the calculator protocol. When the user needs to perform 1+1calculations, input the calculation requirements by handwriting, that is, a handwritten picture, and then the user input layer converts the handwritten picture into a logical language R=1+1and calls the logic The compilation layer is implemented; the logic compilation layer converts it into assembly code ADD R 1 1and calls the hardware layer for implementation; the hardware layer runs the assembly code to get the result R to be 2, and the result is fed back to the logic compilation layer; the logic compilation layer receives the result of the hardware layer And return it to the user input layer; the user input layer converts the result into a handwritten number 2 and feeds it back to the user.

level.png

The advantage of this layered protocol is that the layers are independent of each other, with only the connection on the interface, which can be easily replaced. Taking the above calculator protocol as an example, the user input layer can use a touch screen or a keyboard, and only need to convert the input (touch screen input or keyboard input) into a logical language in a unified format; it can also be used in the logic compilation layer Different compilation software only needs to have the same input and output format interface; the same is true for the hardware layer, you can use AMD's cpu or Intel's cpu, you only need to provide the same interface for the logic compilation layer. Layers are independent of each other, and layers of abstraction.

TCP/IP layering

The TCP/IP layering is born out of the OSI layering. The above two layers are shown in the following figure:

tcpip_level.png

The OSI layering is divided into 7 layers, and the TCP/IP model is divided into 5 layers. 1. consider the OSI layering, and take an operation in online battle as an example, which is to control a certain character to release a specified direction in a specified direction. Skills (the actual game will be different):

  • Application layer: Provide services for the application and specify the details related to the communication in the application. In the example, user A presses the skill shortcut key and clicks the mouse to release a skill in a certain direction. At the application layer, this operation is packaged as a json data packet, which is composed of the skill number and release direction.
  • Presentation layer: Mainly responsible for the conversion of data formats. Convert the information processed by the application into a format suitable for network transmission, or convert the data from the next layer into a format that can be processed by the upper layer. In the example, the json package generated by the application layer is encoded into a byte stream.
  • Session layer: Responsible for determining what to establish and disconnect the communication connection (the logical path of data flow), and the management of data transmission such as data segmentation. In the example, the session layer receives the byte stream generated by the presentation layer, calls the lower-level interface to establish a communication connection with the session layer of user B, and passes the byte stream to user B. However, if user A's skills are in a state that cannot be released, the session The layer is responsible for waiting until the skills can be released before establishing a connection to send data.
  • Transport layer: The layer that is actually established and plays a role of reliable transmission at the same time. When the session layer decides to establish a connection, the transport layer is responsible for the specific transaction of establishing the connection, which establishes the connection and ensures effective transmission. In the example, if data is missing in the byte stream during network transmission, the transport layer of user B will notify the transport layer of user A to send the data again.
  • Network layer: Transmit data to the destination address. In the example, the byte stream is sent from the host of user A to the host of user B.
  • Data link layer: Responsible for the communication and transmission between nodes that are interconnected on the physical level. In the example, it will be responsible for sending data from one node to another.
  • Physical layer: Responsible for the interchange between 0 and 1 bit streams (0, 1 sequence), voltage levels, and light flashes. In the example, if optical fiber communication is used between two nodes, they are responsible for the conversion of photoelectric signals.

For the layering of TCP/IP, the application layer, presentation layer, and session layer in OSI are unified into the application layer. Therefore, examples of layer 5 packets and corresponding protocols are:

  • Application layer: HTTPS, HTTP, FTP, SSH, etc.
  • Transport layer: TCP, UDP, etc.
  • Network layer: IPv4, IPv6, etc.
  • Data link layer and physical layer: Ethernet, IEEE 802.11, etc.

For the data link layer and the physical layer, its function is to send data from one node to an adjacent node; for the network layer, its function is to send data from one host to another host (may span many nodes, not Concerned about whether there is an error); For the transmission layer, it is necessary to ensure that the data is sent from one host to another without errors. The transmission layer protocol may call the network layer transmission multiple times in one transmission; the application layer is the protocol finally contacted by the user to achieve specific functions For example, HTTPS realizes web page access, and FTP realizes data transmission, as shown in the following figure:

tcpip_level_stream.png

Reference: https://cloud.tencent.com/developer/article/1701584 TCP/IP Study Notes 1-Protocol Layering-Cloud + Community-Tencent Cloud