[Computer Network] Data Link Layer—Ethernet

Insert image description here

Preface

Earlier we learned about the application layer - custom protocol, transport layer - UDP, TCP protocol, network layer - IP protocol. Today I will share with you knowledge about the data link layer - Ethernet.

What is Ethernet

  • "Ethernet" is not a specific network, but a technical standard; it includes both data link layer content and some physical layer content. For example: stipulating network topology, access control methods, transmission rates, etc.;
  • For example, the network cable in Ethernet must use twisted pair; the transmission rate is 10M, 100M, 1000M, etc.;
  • Ethernet is currently the most widely used local area network technology; alongside Ethernet are token ring networks, wireless LAN, etc.;

Ethernet is a computer local area network technology that uses the Carrier Sense Multiple Access with Collision Detection (CDMA/CD) method for media access control. Ethernet primarily refers to the physical cables over which data is transmitted, while Wi-Fi refers to a network of interconnected devices that are connected wirelessly. Ethernet is basically a cable, the connection between your computer and the Internet, it is a wired connection that connects directly to your computer via a USB cable or an Ethernet cable. Wi-Fi is more like a network technology that allows mobile devices to connect to the Internet wirelessly.

Ethernet has evolved rapidly, evolving from the typical Ethernet structure of a single long cable. The problems associated with individual cables, such as locating breaks or loose connections, drove the development of a different type of cabling model. In this model, each station has a dedicated wire connected to a central hub.

Ethernet frame format

Insert image description here

6-bit destination and source addresses

The destination address and source address refer to the sending address of the data frame and where it is to be sent. Here, the destination address and source address are not described by IP addresses, but by < a i=1>MAC address to describe.

MAC address is the media access control address, also known as MAC address and hardware address, which is used to confirm the location of network devices. It is composed of 48-bit binary numbers, usually expressed as 12-digit hexadecimal numbers. These numbers are usually written into the EPROM chip of the network card by the network card manufacturer, and the data in the chip can be erased and written by a program.
The first 6 digits of the MAC address represent the "Organizational Unique Identifier" (OUI), and the last 6 digits are assigned by the manufacturer. This numbering helps ensure that each network card has a unique MAC address.
In Ethernet, the MAC address is an identifier used for data transmission. When data is sent from one node to another, the source node sends the packet to the destination node's MAC address. Through the MAC address, the destination node can identify who the sender is and thus receive and process the data packet.

The MAC address is represented by 6 bytes, which can represent more numbers than the IP address. The current MAC address can meet people's needs. So why do we have a MAC address now that we have an IP address?

When the network first appeared, the network layer and the data link layer were invented independently, so there were IP addresses and MAC addresses used to represent addresses, although both of them were Used to represent addresses, but their usage scenarios are different. And for now, a device has a unique MAC address, which is hard-coded when the network card leaves the factory and generally cannot be modified. The IP address is used to represent the origin and destination of two hosts on the network, while the MAC address represents the address of each node between the two locations.

For example: When I travel from Wuhan to Tibet, I need to pass through Wuhan, Changsha, Chongqing, Chengdu, and Lhasa. In this process, Wuhan is the starting location and Lhasa is the destination location. The two source addresses and destination addresses are described by IP addresses. In the process of the intermediate route from Wuhan to Changsha, the source IP address is Wuhan. , the destination IP is Lhasa, the source MAC address in the Ethernet data frame is Wuhan, and the destination MAC address is Changsha; the source IP address from Changsha to Chongqing is Wuhan, the destination IP address is Chongqing, and the source MAC address is Changsha, and the destination The MAC address is Chongqing... The source IP address and destination IP address are the same from beginning to end, while the source MAC address and destination MAC address need to change continuously based on two adjacent nodes.

Insert image description here

You can use ipconfig /all in cmd under Windows to check the MAC address of your device.

Insert image description here

2 bit type

A 2-bit type field used to identify the type of data frame. This field is used to distinguish different Ethernet frame types, such as Ethernet frames, IP datagrams, ARP requests and responses, etc. Through this field, the receiving end can know what type of data is to be processed next, so as to process it correctly.

Common Ethernet types are: 0x0800, which represents IPv4; 0x86DD, which represents IPv6; 0x0806, which represents ARP; 0x8100, which represents IEEE 802.1q; and so on. Different type field values ​​can be used to distinguish different frame types.

Data length

In the Ethernet frame format, the maximum size of an IP data packet is 1500 bytes. The maximum payload length that this data link layer datagram can carry is also calledMTU. The sub-packaging and grouping of IP data packets are most likely caused by the MTU, not the upper limit of 64 kb. The MTU sizes of different data link layers are different. This is related to the medium of the physical layer, which is similar to the maximum weight that a path can bear.

Impact of MTU on IP Protocol

Due to the MTU limitation of the data link layer, larger IP data packets must be subpackaged.

  • Divide larger IP packets into multiple small packets and label each small packet;
  • The 16-bit identifier (id) of the IP protocol header of each small packet is the same;
  • In the 3-bit flag field of the IP protocol header of each packet, the second bit is 0, indicating that fragmentation is allowed, and the third bit indicates the end mark (whether this is the last small packet, if so, it is set to 1, otherwise it is set to 0 );
  • When arriving at the opposite end, these small packets will be reorganized in order, assembled together and returned to the transport layer;
  • Once any of these packets is lost, reassembly at the receiving end will fail. But the IP layer will not be responsible for retransmitting the data;

CRC checksum

Checksums are used to verify whether errors have occurred during data transmission over the network. In Ethernet, the checksum is not at the beginning of the frame, but at the end of the frame.

How data is forwarded at the data link layer

  1. Encapsulation into a frame: When the network layer protocol is encapsulated into a frame at the data link layer, two special characters, SOH and EOT, are added to the header and tail respectively. The receiver determines the beginning and end of the frame based on these two characters. .
  2. Add checksum: The link layer will add a checksum to the data part to detect errors during data transmission.
  3. Transparent transmission: In order to avoid interference with the data of the frame, an escape character ESC can be added before the SOH and EOT characters in the data part. In this way, if the SOH and EOT characters are directly received during reception, they are still represented as the start and end marks of the frame. However, if ESC is received and then SOH and EOT are received during reception, it means that these two characters are not the start and end marks of the frame. Is part of the frame data.
  4. Error control: The link layer also has an error control function, which can detect and correct errors during data transmission.
  5. Decapsulation and forwarding: When the routing device receives the message, it will first decapsulate it and find that the destination IP is not its own and is not in the same network segment. It will check whether its own routing table records routing entries that match the destination IP network segment. If this routing information exists, the data packet is handed over to the corresponding interface for forwarding.

Guess you like

Origin blog.csdn.net/m0_73888323/article/details/134094421