Read before thinking
The best way to learn a skill or read an article is to study with questions, so that in the process, you will have a sense of clarity, lights out, and memory will be more profound.
- What are the architectures of five layer network protocols? What are the protocols for each layer?
- Why have a MAC address but also an IP address?
Five layer model of network protocol
As for the layers of the network, some are divided into seven layers, some into four layers, and I think the five-layer model is the easiest network model to understand.
As shown in the figure above, the application layer, transport layer, network layer, link layer and entity layer are successively from top to bottom. The higher up, the closer it is to the user; The further down you go, the closer you get to the hardware.
agreement
Rules that everyone follows are called protocols.
At every layer of the Internet, there are many protocols defined. Collectively, these protocols are called the Internet Protocol Suite, and they are at the heart of the Internet.
Physical Layer
So let’s start with the bottom layer, what’s the first thing you do when you connect your computer to the Internet? Is to use cable, optical cable, twisted-pair and other means to connect the computer, this is the entity layer.
The physical layer is the physical means that connect computers together. It mainly defines some electrical characteristics of the network, the role is responsible for the transmission of 0 and 1 electrical signals.
Link Layer
The “link layer” above the “entity layer” determines how zeros and ones are grouped. How many electrical signals are in a group? What does each signal bit mean?
Ethernet protocol
Ethernet states that a group of electrical signals constitutes a packet, called a Frame. Each frame is divided into two parts: Head and Data.
The “header” contains some description of the packet, such as sender, receiver, data type, etc. “Data” is the specific content of the packet.
The length of the “header” is fixed to 18 bytes. The length of “data” ranges from 46 bytes to 1500 bytes. Therefore, the entire “frame” has a minimum of 64 bytes and a maximum of 1518 bytes. If the data is long, it must be split into multiple frames and sent.
The MAC address
Ethernet stipulates that all devices connected to the network must have a “nic” interface. Packets have to go from one network card to another. The address of the nic is the address for sending and receiving packets, which is called the MAC address.
Each NIC is delivered with a MAC address unique in the world. The length of the ADDRESS is 48 bits, usually represented by 12 hexadecimal numbers.
The first six hexadecimal numbers are manufacturer ids, and the last six are nic serial numbers of the manufacturer. With a MAC address, you can locate the path of the network card and the packet.
radio
Ethernet takes a very “crude” approach. Instead of sending packets exactly to the receiver, it sends them to all the computers on the network, leaving each computer to decide for itself whether it is the receiver or not.
All computers in the same subnetwork receive this packet. They read the packet’s “header,” find the MAC address of the recipient, compare it to their own MAC address, and if they are the same, accept the packet for further processing or discard it. This mode of transmission is called broadcasting.
With a packet definition, a MAC address for the network card, and a way to send the broadcast, the “link layer” can transmit data between multiple computers.
Network Layer
Ethernet protocol that relies on MAC addresses to send data. There is one major drawback to this. Ethernet uses broadcast to send data packets. If two computers are not on the same subnetwork, the broadcast cannot be transmitted. This design makes sense, otherwise every computer on the Internet would receive all the packets and that would be a disaster.
Therefore, a way must be found to tell which MAC addresses belong to the same subnetwork and which do not. If it is the same subnetwork, send it in broadcast mode; otherwise, send it in “routing” mode. (” Routing “means how packets are distributed to different subnetworks.)
role
The role of the network layer is to introduce a new set of addresses that allow us to distinguish whether different computers belong to the same subnetwork. This set of addresses is called “network addresses”, or “web addresses” for short.
With the advent of the “network layer”, every computer has two kinds of addresses, one is a MAC address, the other is a network address. Network addresses help us determine which subnetwork the computer is on, and MAC addresses send packets to the destination network card in that subnetwork. Therefore, it is logical to assume that the network address must be processed first and then the MAC address.
TCP/IP protocol
The protocol for specifying network addresses is called the IP protocol. The address it defines is called an IP address. Traditionally, IP addresses are represented by four decimal numbers, ranging from 0.0.0.0 to 255.255.255.255.
The first part of the IP address represents the network and the second part represents the host. For example, if the IP address 172.16.254.1, which is a 32-bit address, assumes that the network part is the first 24 bits (172.16.254), then the host part is the last 8 bits (the last 1). Computers in the same subnetwork must have the same network part of their IP addresses. That is, 172.16.254.2 and 172.16.254.1 must be in the same subnetwork.
The problem, however, is that we can’t judge the network from the IP address alone. Take 172.16.254.1 as an example. The IP address cannot tell whether the network has the first 24 bits, 16 bits, or even 28 bits.
The “subnet mask” is a parameter that represents the characteristics of the subnetwork. Formally equivalent to an IP address, it is also a 32-bit binary number with all 1s in the network part and all 0s in the host part. 172.16.254.1, for example, IP address, if known network part is the first 24 bits, the host part is eight, after the subnet mask is 11111111.11111111.11111111.00000000, written in a decimal is 255.255.255.0.
By knowing the “subnet mask”, we can determine whether any two IP addresses are in the same subnetwork. The method is to perform an AND operation (1 for both digits, 0 for none) on the two IP addresses AND subnet masks respectively, AND then compare whether the results are the same. If so, they are in the same subnetwork; otherwise, they are not.
ARP protocol
Because IP packets are sent in Ethernet packets, we must know both the MAC address and IP address of the other party. Usually, the IP address of the other party is known (as explained later), but we do not know its MAC address.
So, we need a mechanism to get MAC addresses from IP addresses.
Again, there are two cases. In the first case, if two hosts are not on the same subnetwork, there is virtually no way to get the MAC address of the other host. Instead, the packet is sent to a “gateway” at the connection point of the two subnetworks for processing.
In the second case, if two hosts are in the same subnetwork, we can use ARP to obtain the MAC address of the other host. ARP also sends a packet (contained in an Ethernet packet) that contains the IP address of the host to be queried. In the MAC address field, the packet is FF:FF:FF:FF:FF. Each host in its subnetwork receives the packet, extracts its IP address, and compares it with its own IP address. If they are the same, both reply with their MAC addresses. Otherwise, the packet is discarded.
With ARP, we can get MAC addresses of hosts in the same subnetwork and send packets to any host.
Transport Layer
**” port “(port) ** indicates which program (process) the packet is intended to use. The function of the transport layer is to establish port-to-port communication. In contrast, the function of the “network layer” is to establish host-to-host communication. As long as we identify the host and port, we can implement communication between programs.
UDP protocol.
Adding port information to packets requires a new protocol. The simplest implementation is called UDP, and the format is almost nothing more than a port number in front of the data.
A UDP packet consists of header and data.
The “header” section mainly defines the sending and receiving ports, and the “data” section is the concrete content.
UDP packets are very simple. The “header” section is only 8 bytes long, and the total length is no more than 65,535 bytes, which fits into an IP packet.
TCP protocol
The ADVANTAGE of UDP is that it is simple and easy to implement. However, the disadvantage is that the reliability is poor. Once a packet is sent, you cannot know whether the packet has been received.
In order to solve this problem, improve network reliability, TCP protocol was born. This protocol is very complex, but can be approximated as UDP protocol with acknowledgement mechanism, each packet sent requires confirmation. If a packet is missing, no acknowledgement is received and the sender knows it is necessary to resend the packet.
Therefore, TCP ensures that data is not lost. Its disadvantages are complicated process, difficult implementation and consuming more resources.
Like UDP packets, TCP packets are embedded in the “data” part of IP packets. The length of a TCP packet is unlimited. However, to ensure network efficiency, the length of a TCP packet does not exceed that of an IP packet, so that a single TCP packet does not need to be split.
Application Layer
The role of the application layer is to dictate the data format of the application.
For example, TCP can transfer data for a variety of applications, such as Email, WWW, FTP, and so on. Then, different protocols must dictate the format of E-mail, web pages, and FTP data, and these application protocols constitute the “application layer.”
So far, the entire five-tier structure of the Internet, from the bottom up, all finished.
The article has read to the end, do you know the first few questions? If not? You can read intensively for problems you won’t have! The answer is in the text, I believe you can certainly solve!