background
This series of articles is intended for engineers in general, non-professional development roles (such as mobile) to gain a basic understanding of the basics of networking without being stranded when asked about it in an interview. The knowledge of THE TCP/IP protocol cluster is the main, there will also be a simple introduction of the application layer and data link layer.
It’s not going to be difficult, it’s not going to be too much about algorithms, it’s going to be about getting to the deepest understanding as quickly as possible. The content is certainly much richer than just searching for “TCP/IP” on Baidu and reading a random article, but not enough to qualify the reader for web development.
Admittedly, interviews are dominated by protocols such as TCP/UDP/HTTP, and IP protocols are rarely involved, let alone the data link layer. But I want to be able to understand those questions in principle, not cramming and memorizing some answers and then forgetting them after the interview. Don’t prepare for an interview, prepare for an interview. If you think this is what you need, Let’s Begin!
OSI seven-tier model and protocol
In this section, we will not talk about the specific functions of these layers and protocols. For now, just know that in the OSI model, the network is divided into seven layers. From the bottom to the top, they are: the physical layer, the data link layer, the network layer, the transport layer, the session layer, the presentation layer and the application layer.
Protocol is a word that is Big and comes up a lot. In fact, it’s easy to understand, it’s actually a standard that both parties to the communication abide by. For example, if I need to pass gender and age to another host, I can define an “A protocol “where the first four bytes of data indicate gender and the last four bytes indicate age. This way the host will know that the first four bytes are gender and will not mistake it for age.
The entire Internet world works because software and hardware vendors adhere to existing protocols. Take the IP protocol, for example. You can modify it and come up with an IP2 protocol, but no one recognizes or adheres to it, so it’s useless.
The physical layer
The physical layer is at the bottom of the OSI seven-layer model and its main task is to convert bitstreams to electronic signals.
In the computer world, everything is made up of zeros and ones. The article you are reading is also in the form of zeros and ones as it travels over the Internet to your computer. However, in the medium of network transmission (such as optical fiber, twisted-pair, radio waves, etc.) there is obviously no zero and one. In light, for example, data travels through light. 0 and 1 are represented as light on and off, where the transformation is done by the physical layer.
Without a physical layer, a bitstream of zeros and ones cannot travel through a physical medium.
Data link layer
The data link layer is the second layer of the OSI seven-layer model and defines the specification for data transfer between devices connected through the communication medium.
In the data link layer, data no longer exists as a sequence of 1s and 0s, but is split into “frames” and then transmitted.
There are two important concepts in the data link layer: MAC address and packet switching.
The MAC address
A MAC address is a 48-bit number that is burned to the ROM of a network interface card (NIC). It is unique worldwide (regardless of vm custom MAC addresses). Since MAC addresses are unique, they can be used to distinguish between nodes. Once a MAC address is specified, it is not possible to not know which device to transmit data to.
Packet switching
Packet switching is the process of splitting a large piece of data into smaller pieces and sending them in turn. Packet switching is used because each data link has its own Maximum Transmission Unit (MTU). Different data links are like different transportation channels, and a truck can carry five tons. So moving 20 tons of goods by truck would have to be divided into four parts, each weighing 5 tons. If the carrying weight of the transport plane is 30 tons, then the cargo can be pulled by one transport plane without dividing.
For example, the MTU of the Ethernet is 1500 bytes. That is, the data transmitted over the Ethernet must be divided into several frames. The length of each frame does not exceed 1500 bytes. If the length of the data sent from the upper layer exceeds this length, the data link layer needs to split the data before sending it.
Ethernet frame
Let’s use Ethernet as an example to introduce the format of Ethernet frames.
The Ethernet frame begins with “Preamble” and is 8 bytes long, which is not useful. The point is the body of the Ethernet frame.
Ontology consists of header, data and FCS:
The type part stores the number of the upper-layer protocol. For example, if the upper-layer protocol is IP, the number is 0800.
FCS is a Frame Check Sequence used to determine whether a Frame is damaged during transmission (such as electronic noise). The FCS holds the remainder of the sent frame divided by some polynomial, and the received frame does the same. If the value is the same as the FCS, then nothing has gone wrong.
switches
A switch is a network device that works at the data link layer and has multiple ports to connect different devices. The switch determines which port to send data to based on the destination MAC address in each frame. In this case, it needs to refer to the forwarding table.
The forwarding table is not manually set, but automatically learned by the switch. When a device sends a frame to a switch, the switch adds the source MAC address of the frame to the forwarding table as a record corresponding to the interface.
The following figure describes the principles of the switch self-learning process
The most important thing about the data link layer is its definition: “A specification for data transmission between devices connected through a communication medium.” This indicates that data link layer protocols are applicable to nodes at both ends of the same data link. If you don’t understand this, you can’t understand the network layer and the IP protocol.
The significance of the data link layer is that without the data link layer, the data can only exist in the form of a stream in the communication medium, without knowing where to send it, and the data flow may be too long to be transmitted in the communication medium.