preface

I have always heard about the “four-layer model” and “seven-layer model” of the network, what the heck? I happened to catch up with the recent work related to communication, so I feel a little sorry for not understanding the network layered model, which is a little stubborn in my heart! Just watched the geek time perspective on the HTTP protocol on the explanation of network layering, first write down, deep understanding and long-term memory! Day by day when good, dry is done!

TCP/IP network layered model

Or start with TCP/IP protocol, one because it is very classic, two because it is the current de facto network communication standard, the study of its practical value. Take a look at the TCP/IP protocol hierarchy diagram.

The TCP/IP protocol has four layers. Like building blocks, each layer needs support from the lower layer and supports the upper layer. If any layer is removed, the stack may collapse.

The first layer, called the Link Layer, is responsible for sending raw packets over underlying networks such as Ethernet and WiFi. It works at the network card level and uses MAC addresses to mark devices on the network, so it is sometimes called the MAC layer.

The second layer is called the Internet Layer, and the IP protocol is at this layer. Because IP protocol defines the concept of “IP address”, it can replace MAC address with IP address on the basis of “link layer”, and connect many Lans and wide area networks into a virtual huge network. When looking for devices in this network, it is ok to “translate” IP address into MAC address again.

The third layer, called the Transport layer, is responsible for ensuring the “reliable” transfer of data between two points marked by IP addresses. This layer is where TCP works, along with its sister, UDP. TCP is a stateful protocol. Data can be sent only after a connection is established with the peer party, ensuring that data is not lost or repeated. UDP is relatively simple. It is stateless and can send data arbitrarily without establishing a connection beforehand, but there is no guarantee that the data will be sent to the other party. Another important difference between the two protocols is the form of the data. TCP is a sequential byte stream, while UDP is a scattered packet that is sent sequentially and received out of order. There are many other topics that can be discussed about TCP and UDP, such as the classic “three-way handshake” and “four-way wave.”

The fourth layer is called the Application Layer, and because the bottom three layers lay the groundwork so well, a thousand flowers bloom at this layer, with various application-specific protocols. Such as Telnet, SSH, FTP, SMTP, and so on.

The transmission unit at the MAC layer is frame, the transmission unit at the IP layer is packet, the transmission unit at the TCP layer is segment, and the transmission unit at HTTP is message. But there is no essential distinction between these terms, which can be collectively referred to as data packets.

OSI network layered model

The OSI, or Open System Interconnection Reference Model, has no historical background.

The OSI model is divided into seven layers, some of which are similar to TCP/IP, from bottom to top:

  1. Layer 1: physical layer, the physical form of the network, such as cable, optical fiber, network card, hub and so on;
  2. The second layer: data link layer, which is basically equivalent to the TCP/IP link layer;
  3. Layer 3: network layer, equivalent to TCP/IP in the Internet layer;
  4. Layer 4: transport layer, equivalent to TCP/IP transport layer;
  5. The fifth layer is the session layer, which maintains the connection state in the network, that is, maintains the session and synchronization.
  6. The sixth layer is the presentation layer, which translates the data into appropriate and understandable syntax and semantics.
  7. The seventh layer is the application layer, which transmits data for specific applications.

Mapping between two hierarchical models

  1. Layer 1: physical layer, TCP/IP does not correspond;
  2. Layer 2: data link layer, corresponding to the TCP/IP link layer;
  3. Layer 3: network layer, corresponding to the TCP/IP Internet layer;
  4. The fourth layer: transport layer, corresponding to TCP/IP transport layer;
  5. Layer 5, layer 6, and Layer 7 correspond to the TCP/IP application layer.

Layer-4 load balancing refers to the load balancing of back-end servers at the transport layer based on TCP/IP features, such as IP addresses and port numbers.

Layer-7 load balancing refers to working at the application layer, viewing THE HTTP protocol, parsing data such as URIs, host names, and resource types in HTTP packets, and forwarding the data to the back-end server using appropriate policies.

conclusion

  1. TCP/IP is divided into four layers, the core is layer 2 IP and layer 3 TCP, HTTP in the fourth layer;
  2. OSI is divided into seven layers, basically corresponding to TCP/IP, TCP in the fourth layer, HTTP in the seventh layer.
  3. OSI can map to TCP/IP, but layers one, five, and six disappear in the meantime;
  4. In everyday communication we use the OSI model, with terms like four layers, seven layers, etc.
  5. HTTP uses the TCP/IP protocol stack to package and unpack the data layer by layer, but the details below are not visible.
  6. A good (but not absolute) tip to tell the difference between layer 4 and layer 7 is “two whatevers” : whatever is handled by the operating system is layer 4 or less, and otherwise, whatever is handled by the application (that is, you write your own code) is layer 7.

Welcome to scan code attention

If you like, please pay attention to my public number [program listener] and tell your story! I am here to listen! Text address