physical layer (the first layer of the seven layers)
physical layer: similar to saying, you have a computer, and now you want to connect to the Internet, how to connect? A few years ago, everyone remembered that they plugged a root cable into the computer, and then they could access the Internet, but now it is enough to connect to a wifi connection, and China and the United States used to rely on submarine optical cables to connect to the Internet. So the physical layer refers to this, which is how to connect various computers to form a network. This is the meaning of the physical layer. The physical layer is responsible for transmitting circuit signals of 0 and 1. The logic level often used in chip is TTL level or CMOS level of 5v, generally positive logic, that is: logic 0 means low voltage, logic 1 means high voltage; different types of logic levels indicate The specific voltage values are different;
1. The data link layer
We already have the transmission medium through the physical layer, and also said how the 0 and 1 in the network are represented, but how to pass it, to whom it is now I don't know yet. So then came out Ethernet protocol , Ethernet. A set of telecom number is a data packet, called a frame, each frame is divided into two parts, the header (head) and the data (data), the header contains some descriptive things, such as sending receivers, receivers, and data types.
Ethernet stipulates that all devices in the access network must have a network card , each network card must contain a mac address, and the mac address is the unique identifier of the network card.
mac address: 48-bit binary, but generally represented by 12 hexadecimal numbers, the first 6 hexadecimals are the manufacturer's number, and the last 6 hexadecimals are the network card serial number.
How can Ethernet packets be sent from one mac address to another?
This is not an accurate push,In the Ethernet, if a computer sends a data packet out, it will broadcast to the network cards of all computer devices in the local area network, and then each computer obtains the recipient's mac address from the data packet, and compares it with its own mac address, if The same, it means that this is a data packet sent to itself.
However, the above broadcast method is only for computers in a subnet (LAN), and it will broadcast. A computer cannot broadcast data packets to all other computers in the world, but only broadcasts to computers in a subnet. .
Second, the network layer
The computer in thesubnet sends a data packet through the Ethernet, which is broadcast to the computer in the LAN. So how do you know which computers are in a subnet ? This depends on the network layer.
There is an IP protocol in the network layer, and the address defined by the IP protocol is called an IP address. There are two versions of IP addresses, IPv4 and IPv6 . Currently, IPv4 is widely used, which is composed of 32 binary digits, but is generally represented by 4 decimal digits, ranging from 0.0.0.0 to 255.255.255.255.
Each computer will be assigned an IP address. The first 24 digits of the IP address (the first 3 decimal digits) represent the network, and the last 8 digits (the last 1 decimal digits) represent the host. If several computers are on a subnet, the first three decimal numbers must be the same.
ARP : Address Resolution Protocol ( Address Resolution Protocol ), its basic function is to query the MAC address of the target device through the IP address of the target device to ensure smooth communication. In fact, it is to broadcast the relationship between the mac address and ip of the machine in the subnet. Each machine in the subnet knows the correspondence between the mac address and ip of all machines in its subnet. It is an indispensable protocol of the network layer in IPv4.However, it is no longer applicable in IPv6 and replaced by Neighbor Discovery Protocol (NDP).
ARP workflow:
- Host A first checks its own ARP table to determine whether it contains ARP entries corresponding to host B. If the corresponding MAC address is found, host A directly uses the MAC address in the ARP table to frame the IP data packet, and sends the data packet to host B.
- If host A cannot find the corresponding MAC address in the ARP table, it will cache the data packet and then send an ARP request packet in broadcast mode. The sender IP address and sender MAC address in the ARP request packet are the IP address and MAC address of host A, and the destination IP address and destination MAC address are the IP address and the MAC address of all 0s of host B. Since the ARP request message is sent in broadcast mode, all hosts on the network segment can receive the request, but only the requested host (ie, host B) will process the request.
- Host B compares its own IP address with the target IP address in the ARP request message, and if the two are the same, the following processing is performed: save the IP address and MAC address of the sender (that is, host A) in the ARP request message. into its own ARP table. Then send an ARP response packet to host A in unicast mode, which contains its own MAC address.
- After receiving the ARP response message, host A adds the MAC address of host B to its ARP table for forwarding subsequent messages, and encapsulates the IP data packet and sends it out.
Each computer can have multiple network cards, not just one network card. Generally, laptops have Ethernet network cards and wifi network cards. When sending data packets, you need to decide which network card to go. There is a key device router also has multiple network cards;
router ( Router ): is used to connect multiple logically separated networks,The so-called logical network represents a single network or a subnet. When data is transferred from one subnet to another, it can be done through routers. Therefore, the router has the function of judging the network address and selecting the path. It can establish flexible connections in a multi-network interconnection environment, and can connect various subnets with completely different data packets and media access methods. The router only accepts source stations or other Router information, which is an interconnected device at the network layer.
The main job of the router is to find an optimal transmission path for each data frame passing through the router, and transmit the data to the destination site efficiently. It can be seen that the strategy of selecting the best path, that is, the routing algorithm, is the key to the router. In order to complete this work, the relevant data of various transmission paths - routing table (RoutingTable) is saved in the router for use in routing. The path table stores the information of the subnet flag, the number of routers on the network, and the name of the next router. The path table can be fixed by the system administrator , or it can be dynamically modified by the system, automatically adjusted by the router, or controlled by the host.
routing table is an optimal path for sending messages to the target machine, which will go through some routers to reach the target machine. is shown in the figure below, taking three routers in the middle as an example, take a look Routing table generation:
Network layer flow chart
We know through the data link layer that data transmission needs to know that the mac address is broadcasting, if you need to broadcast to different subnets When the machine sends a message, it needs to know its ip;
1. Find the mac address corresponding to the router through the ARP table, which is actually the mac address of the gateway, because it is sent to other subnets,Therefore, the message needs to be sent to the router first, and the router will calculate an optimal path according to the current IP address, and then pass the message to the next router;
2. The router also transmits the message through broadcast, so it is necessary to send the Ethernet packet to the next router. The target mac address in is modified to the mac address of the next router. After broadcasting the message through another network card of the router, the next router will receive the message when it finds that the mac address is itself;
3. Determine whether the target ip machine is in its own In the subnet, if it is not, modify the mac address to the mac address of the next router, and continue broadcasting. If it is in its own subnet, it will broadcast within the subnet. After the target machine receives it and judges that it is for itself, it will parse it;
3. Transport layer
On a machine, many programs use a network card for network communication , such as browsers, QQ , live video, these software all use a network card to send to the outside data, and then receive data from the network card, so there is actually a concept of a port, the system will listen to a port at startup, and if the port is occupied, it will switch the port;
transport layer protocol_ span2span mainly has two
- TCP (Transmission Control: Protocol )
- UDP (User Datagram Protocol)
TCPIs a reliable, connection-oriented protocol. It allows error-free information transfer between two hosts on a network. The TCP protocol also performs flow control to avoid congestion caused by sending too fast. But all this is transparent to the user.
UDP is the user datagram protocol, which transmits data in a connectionless manner, that is to say, the sender does not care whether the sent data reaches the target host, whether the data is wrong, and so on. The host that receives the data will not tell the sender whether it has received the data, and its reliability is guaranteed by the upper-layer protocol.
Fourth, the application layer
The application layer combines the session layer, the presentation layer and the application layer into one layer. The common protocol of the application layer is the http protocol, which carries out network communication and specifies the format of data parsing, such as: text Data, web page data, mail data, etc.;
http When data is transmitted, the data is sometimes transmitted through the domain name, but before the network layer used the IP protocol for address resolution to transmit data, how to deal with the domain name? The domain name will be resolved into ip through DNS for subsequent processing;
What is DNS?
DNS full name is Domain Name Server , commonly known as "domain name server" in Chinese, between the domain name and the IP address on the Internet There is a one-to-one correspondence. Although the domain name is easy for people to remember, the machines can only know each other's IP addresses. The conversion work between them is called domain name resolution. Domain name resolution needs to be completed by a special domain name resolution server. DNS It is the server that performs domain name resolution. DNS is a distributed database that provides services for converting between hostnames and IP addresses. The distributed database here means that each site only keeps its own part of the data.
Summary
Layer 4: Data Link Layer (Ethernet Protocol),Network layer (ip protocol), transport layer (tcp protocol), application layer (http protocol)
7 layers: physical layer (network cable, submarine cable , passing 0/1 circuit signals), session layer, presentation layer, Application Layer -> Application Layer
.