preface
Today we are talking about a relatively basic problem, OSI seven layer model and TCP/IP four layer model.
Friends may have questions, this thing is also used to write articles, too basic, online articles are many, just a search can be found.
Sure, there’s a lot of information online, but if an interviewer asks you this question, can you answer it well?
This article is to talk about this topic in plain English, so that you have a very clear understanding of them.
Copy online profiles
Since we say that there are a lot of information on the Internet, the prince also found a form for us from the Internet, as follows:
OSI seven layer model | TCP/IP four-tier model | Corresponding network protocol |
Application Layer | The application layer | HTTP, TFTP, FTP, NFS, WAIS, SMTP |
Presentation Layer | Telnet, Rlogin, SNMP, Gopher | |
Session Layer | SMTP, DNS | |
Transport Layer | The transport layer | TCP, UDP |
Network Layer | The network layer | IP, ICMP, ARP, RARP, AKP, UUCP |
Data Link Layer | Data link layer | FDDI, Ethernet, Arpanet, PDN, SLIP, PPP |
Physical Layer | IEEE 802.1a, IEEE 802.2 to IEEE 802.11 |
After reading, do you feel that there is only so much about the seven-tier model and the four-tier model?
Just strange!
Do you know exactly what each layer does? Why the layering? Let’s talk about these issues in plain English.
Bottom-up detail model
1. The physical
First let’s look at the physical layer. What does the physical layer do? The online information is as follows:
It mainly defines the standard of physical equipment, such as the interface type of network cable, the interface type of optical fiber, and the transmission rate of various transmission media, etc. Its main function is to transmit bit stream (that is, the strong and weak class that is converted from 1 0 to current for transmission, After arriving at the big destination, the data is converted to 1, 0, which is usually referred to as digital-to-analog conversion and digital-to-analog conversion.
Read the data on the net is not a face meng force, it doesn’t matter, we use the vernacular to explain.
The physical layer is basically how computers connect to each other. For example, insert a network cable, connect wifi, optical cable and so on. We think of it as the physical layer being responsible for connecting computers together, forming a network, and we’re done. It transmits the 0 1 signal at the bottom of the computer, and anyone who has studied computers or electronics should know 0 1 signal.
2. Data link layer
Let’s take a look at the information on the Internet:
The MAC address (nic address) of the data received by the physical layer is encapsulated or unencapsulated. This layer of data is often called a frame. The devices that work on this layer are called switches, through which data is transferred.
Resolution:
We know that the physical layer connects the computers and sends 0, 1 circuit signals to each other, do we have to know what those 0, 1 signals stand for? The data link layer translates this.
In the old days, each company defined its own way of grouping circuit signals, and then Ethernet came along. A group of electrical signals is a packet, also known as a frame, which is divided into two parts, head and data. The header usually contains some description, such as sender, receiver, data type and so on.
So how do you determine the location of the sender in a packet?
The Ethernet requires that each nic must contain a MAC address, which is the ID of the NIC. All devices connected to the network must have network adapters, which are located by MAC addresses in packets. Each network adapter comes with a unique MAC address. The 48-bit binary number is usually represented by 12 hexadecimal digits. The first six hexadecimal digits are the manufacturer number and the last six hexadecimal digits are the nic serial number.
So how do Ethernet packets get from one MAC address to another? Instead of point-to-point, the packet is broadcast to all network adapters in the LAN. Each network adapter then compares the MAC address of the receiver from the packet. If the MAC address is the same, the packet is sent to itself.
Of course, this type of broadcasting is only for lans.
3. The network layer
Online Information:
Encapsulate and decapsulate the IP address (192.168.0.1) of the data received from the underlying layer. The devices that work on this layer are routers. Call this data packet.
Resolution:
Network layer is a more complex part, above we introduced the LAN to send packets through the way of broadcast, then how to determine which computers in a subnet? This relies on the network layer, which introduces IP addresses that can tell which computers are on a subnet.
At the network layer, IP addresses are defined as IPv4 and IPv6 addresses. Currently, IPv4 is commonly used, which consists of 32 binary digits but is generally expressed in four decimal digits, ranging from 0.0.0.0 to 255.255.255.255.
Each computer is assigned an IP address, with the first 24 bits (the first three in decimal) representing the network and the last 8 (the last in decimal) representing the host.
If several computers are on a subnet, the first three decimal numbers must be the same.
In fact, not only the IP address is used to judge, but also the IP address and subnet mask are used to judge.
For example, if two IP addresses 192.168.1.3 and 192.168.2.5 are one subnet, the system performs binary and arithmetic with subnet mask 255.255.255.0 respectively, and then compares the numbers on the network to see if they are the same.
So if it’s not a subnet, how do you transfer information?
This is where routing is needed to send packets.
When it comes to routing, we must think of the router we usually use. The router at home is actually connected to a subnet in your own home. If you want to visit the Internet, it is actually communicating with the subnet where the website machine is located.
A router is a special device configured with multiple network cards that can access different networks through different network cards. A gateway is a kind of router. The IP address of a router can be considered as a gateway address. Each network card on a router has an IP address and a MAC address, but it can only be addressed through IP, not MAC address.
What about network switches? It is also a device that works at the data link layer and addresses and transmits data via MAC addresses. Network switches are mainly used for LAN communication and broadcast communication through MAC addresses. Routers are generally used to connect you to the Internet.
By the way we’ll introduce a few more concepts as extensions.
A local area network is a local area network. WAN is a wide are network. WLAN is a wireless local area network.
The router at home has two functions: switch and routing. If it is connected to the device in the LAN, it will insert the network cable into the LAN interface, and if it is connected to the external network, it will insert the network cable into the WAN interface.
So how does a router access the Internet?
For example, how two lans communicate with each other through a router.
Basically, the router is configured with two network cards, each of which can be connected to a local area network.
When a computer on LAN 1 wants to send data to a computer on LAN 2, it writes its OWN IP address and the IP address of the peer in the packet. But they are not on the same LAN, so the COMPUTER on LAN 1 sends the packet to the router through the switch. This process requires that the MAC address corresponding to the IP address of one of the router’s network cards be written to the header of the packet before it is broadcast to the router through the switch.
The router then receives the packet, writes the MAC address corresponding to the IP address of the target machine to the header on LAN 2, and sends the packet to the computer on LAN 2 through the switch on LAN 2.
Each machine in a LAN has its own ARP Cache. The ARP Cache is used to let all devices in the LAN know the mapping between the IP address and MAC address of each device. So in a subnet communication, you write the MAC address of the other party in the packet, and the switch broadcast the end. The communication between subnets involves writing each other’s IP addresses and broadcasting them to the router through the MAC address of the router. The router then translates the IP address of another subnet into the MAC address of another subnet and broadcasts them through the switch. The diagram below:
4. The transport layer
Online Information:
Some protocols and port numbers (WWW port 80, etc.) for transmitting data are defined, such as TCP (Transmission Control Protocol). Low transmission efficiency, high reliability, used in high reliability requirements of large quantities of data transmit, UDP (user datagram protocol (UDP), in contrast to the TCP, user transmission reliability requirements is low, less data quantity of the data, such as QQ chat is through UDP transmission) mainly from lower level to receive the data segmentation and transmission, to the destination after restructuring.
Explanation:
Above we have learned about the communication flow of the network layer, but there is a problem, that is, many programs on the machine are using a network card for network communication, so how to distinguish which program data?
This is where the concept of a port number is introduced, where packets are actually sent to a port on the network card, and the program listening on that port on that machine can extract the data sent to that port.
The port number ranges from 0 to 65536. The port number ranges from 0 to 1023. Other applications use ports higher than 1024.
Therefore, you will find that the network layer is based on IP protocol for addressing and communication between hosts, and then the transport layer is actually the connection and communication between a port of a host to another host.
Udp and TCP are transport layer protocols that add port numbers to packets for point-to-point communication.
Udp is not reliable, sent to someone else received do not know; TCP is reliable and requires a three-way handshake to confirm receipt of a message.
TCP protocol only provides a set of port-based point-to-point communication protocol, including how to establish a connection, how to send and read messages, the actual development of the general use of socket network programming.
Speaking of which, I believe that partners have a deeper understanding of the principle of socket network programming.
5. The application layer
Online Information:
Session layer: the path through which data is transmitted through the transport layer (port number: transport port and receive port). Initiate or receive session requests primarily between your systems (devices need to know each other either by IP or by MAC address or host name)
Presentation layer: mainly for the interpretation of the received data encryption and decryption compression and decompression (that is, the computer can recognize things into things that can be recognized by adults, pictures and sounds, etc.)
Application layer: mainly terminal applications, such as FTP (various file downloads), Web browser, QQ (can be understood as we can directly see things on the computer is terminal applications)
Explanation:
In the four-layer model, the application layer consists of session layer, presentation layer and application layer. So we put it all together. This part of the online information is actually quite clear.
The most common protocol in the application layer is HTTP.
We have introduced IP addresses, subnet masks, and gateway addresses, so let’s extend the concept of DNS here.
DNS:Domain Name System. Because we usually locate by IP address + MAC address + port number, but what if from the browser type www.baidu.com?
www.baidu.com is sent to the DNS server, and the DNS server will tell you the IP address of www.baidu.com.
That’s what DNS does.
conclusion
This article is quite long, if you read it twice, I believe that you will have a great gain, that is about the OSI 7-layer model and TCP/IP 4-layer model of the common language explanation to end here, if you feel that there is a mistake in writing, welcome to the comments section of the comments.
Previous articles recommended:
Windows uses Nginx+Tomcat for load balancing
Talk about WebSocket solutions in distributed mode
Resource mapping principle from SpringBoot source code