In the previous section, we got a first look at how the data link layer works through a fictional protocol. Data link layer mainly solves the communication problem of local network composed of several hosts. Host addressing and channel multiplexing play a key role in this layer.

The data link layer has a very important protocol – Ethernet protocol. Next, let’s uncover its mystery!

Hosts that use the Ethernet protocol to communicate must be directly connected over some medium. The communication media can be physical devices, such as network cables and network adapters. It can also be a virtual device implemented by virtualization technology.

Ethernet frame

In Ethernet, the basic unit of data communication is Ethernet frame, which consists of header, data, and checksum.

Note that the units in this diagram are bytes, not bits.

The head

The Ethernet frame header contains three fields, in order:

  • The destination address, the length is6Bytes that mark which machine received the data;
  • Source addressAnd the length is also6Bytes that mark the machine from which the data was sent;
  • type, the length is2Bytes that mark how the data should be processed,0x0800Indicates that the frame data is aIPPackages (described in subsequent chapters).

Except for the field length, Ethernet frames are pretty much the same protocol we invented. By the way, we noticed a small difference — in Ethernet frames, the destination address is first. Are there any special considerations involved?

There is. When the receiver receives an Ethernet frame, the destination address field is processed first. If you find that the frame is not sent to you, the following fields and data do not need to be processed. Basic network protocol affects many aspects, processing efficiency is also a very important consideration in design.

data

The data can be any message that needs to be sent and can be anywhere from 46 to 1500 bytes in length.

Upper-layer protocol packets, such as IP packets, can be encapsulated as data in Ethernet frames and transmitted at the data link layer. So there’s another name for data, which is payload. Imagine your data traveling on a vehicle called an Ethernet frame.

The checksum

Because physical signals can be interfered with by the environment, bitstreams transmitted by network devices can be faulty. The transmission of an Ethernet frame from one host to another can also go wrong due to various factors. So when a host receives an Ethernet frame, how can it be sure that it is intact?

The answer is: checksum. We can calculate checksums for Ethernet frames using algorithms such as cyclic redundancy check (CRC). If an Ethernet frame fails during transmission, the checksum changes.

Notice that the Ethernet frame has a 4-byte field at the end that holds the checksum. The sender is responsible for calculating the checksum for each Ethernet frame and filling the result in the checksum field; After receiving the Ethernet frame, the receiver recalculates the checksum and compares it with the checksum field. If the two checksums do not match, an error occurred in the transmission of the frame.

[Xiaocai Network] series of articles first published in the public number [Xiaocai programming], please pay attention to: