The physical layer is responsible for converting the 0 and 1 digital signals in the computer into physical signals of specific transmission media (voltage level, electric wave strength, light flash out).

The data link layer protocol defines the data transmission specification (between devices interconnected by communication media) (common communication media are coaxial cable, twisted-pair cable, optical fiber, radio wave)

Related technologies

The MAC address

Data link layer Machine node identification, no matter what kind of data link network (such as Ethernet, Bluetooth, etc.), etc., do not have the same MAC address

6 bytes (48 bits)

Shared media network

Shared-media network refers to a network in which multiple devices share a communication medium.

Multiple devices use the same carrier channel to send and receive data, so that when one device sends or receives data, other devices can only wait in line.

Basically, half-duplex communication [full-duplex communication means that data can be sent and received at the same time, but half-duplex does not]

Media access control mode

A shared network shares communication channels. When one device is in use, other devices cannot transmit data. Therefore, it is necessary to control the use of transmission channels

There are mainly two media access control methods: contention and token passing

Contention (first come, first served)

Also CSMA/CD (Carrier Sense Multiple Access/Collision Detection)

The algorithm is as follows:

All sites can send data frames when there is no data transfer over the channel

When a conflict occurs, the sending of a data frame is abandoned and the channel is immediately released

After giving up sending, it waits for a random period of time, and then recontests the channel and resends the frame. (Wait a random amount of time to avoid collisions when sending data again)

Token passing mode

Tokens travel along the entire network ring, and data frames cannot be sent until the token is acquired.

Because only one device can acquire a token at a time, you can guarantee that there will be no conflicts.

However, channel utilization will not be high (because even if no other device is transmitting data frames at the moment, the data will not be transmitted until the token is passed to the current device).

Unshared media network

Each site in the network is directly connected to a switch port, so the sender and receiver do not share the transport media

Can realize full duplex communication

Hub

The Hub works at the physical layer, shaping and expanding the received signals to expand the transmission distance of the network. It does not have a switchlike MAC address table, so it broadcasts data to all nodes connected to it.

switches

Switches work at the data link layer or network layer (with routing capabilities)

MAC address translation table Self-learning process

When a switch receives a data frame from a site, it writes the source address and port to the conversion table if the source address and port are not in the conversion table

Then look up the destination MAC address in the translation table.

If found, the data frame is forwarded to that port, otherwise broadcast to all ports.

Way forward

There are two modes: store and forward and direct forward:

Store-and-forward checks the FCS field of a frame and discards it if it detects that the frame is corrupted

Straight-through forwarding starts after the MAC address is known, and does not verify data frames

The straight-through forwarding delay is lower.

Loop detection technology

If the network is looped, data frames can be forwarded over and over again, causing the network to crash.

There are two algorithms of raw tree and source routing:

Tree mode: Disable certain ports to form the entire network into a tree, avoiding ring formation.

Source routing algorithm: Writes the source bridge MAC address of the sending frame to the data frame

VLAN(Virtual LOCAL area Network)

The switch is divided into multiple network segments according to ports, thus differentiating the range of broadcast data transmission

Reduces network load and provides network security

Of course, the entire network has multiple network segments, and switches (L3) or routers with routing function are required to connect multiple network segments

Ethernet (IEEE802.3)

Ethernet is a computer LAN technology

When the network is popular, multiple terminals use the same coaxial cable shared medium type connection.

However, Ethernet communication is generally realized through an exclusive cable between terminals and switches (as shown below).

Ethernet frame

Lead code + frame body

The portion of the front end with a leading code that indicates the beginning of an Ethernet frame and is used for synchronization with the peer network card.

The frame body:

6-byte target MAC address: used for data link layer addressing (switch lookup forwarding port)

Type: upper-layer protocol type (such as IP)

FCS (Frame check sequence) : Used to check if a frame is corrupted in transit

MTU = 1500

For channel utilization and transmission time, Ethernet data transmission range is limited to (46 to 1500 bytes).

Channel utilization rate: Assuming that X bytes of data are actually transmitted, the utilization rate is X/(X + 18) [actual data bytes/total frame bytes, 18 is 14 bytes of frame header + 4 bytes of frame tail FCS]. The larger X, the higher the channel utilization rate will be

At least 46 bytes of data: channel utilization at 46 is 71%[46 / (46 + 18)], which is not too low (among other reasons)

Maximum data size: 1500 bytes:

We know that the larger the transmission, the longer the transmission time

Assuming a 100Mbps network, the maximum data transmission time of the network layer datagram is 65535 / (100 *1024 *1024/8) * 1000 = 4.99ms

If you use a shared media network, you cannot receive data within 5ms, and other devices cannot receive and send data.

Therefore, we need to split the upper-layer datagrams at the link layer. The transmission time of 1500 bytes of data in the 100Mbps network only needs about 0.11ms, which is OK.