注:机翻,未校。
以太网协议工作原理指南
How the Ethernet Protocol Works
Whether you’ve been aware of it or not, you’ve probably used the Ethernet in the past. Does this cable look familiar?
无论您是否意识到这一点,使用过以太网的您,这条网线看起来很眼熟。
Ethernet is extremely popular, and is the most widely used Data Link Layer protocol, at least where the devices are linked by physical cables (rather than wireless).
以太网非常流行,并且是使用最广泛的数据链路层协议,至少在设备通过物理电缆(而不是无线)连接的情况下是这样。
In this tutorial, you will learn everything about Ethernet – its history, as well as every bit and byte of the Ethernet frame. You will also get to know how protocols are formed, why it is so hard to change them after they are published, and what lessons can be learned for other protocols.
在本教程中,您将了解有关以太网的所有信息——它的历史以及以太网帧的每个比特和字节。您还将了解协议是如何形成的,为什么在发布后很难更改它们,以及可以从其他协议中吸取哪些经验教训。
Here’s what we’ll cover 以下是我们将介绍的内容
一些以太网历史
Some Ethernet History
The first version of Ethernet was implemented in 1976. In 1978 a second version was published by DEC, Intel, and Xerox who worked together to publish DIX (which stands for DEC, Intel and Xerox). This was also called “Ethernet II”.
以太网的第一个版本
于 1976
年实现。1978
年,DEC、Intel 和 Xerox 共同出版了第二个版本
,共同发布了 DIX(代表 DEC、Intel 和 Xerox)。这也被称为“以太网 II
”。
In 1983, with a change that we will discuss soon, a new Ethernet version was released – the IEEE 802.3 standard, by the IEEE standards association.
1983
年,随着我们即将讨论的变化,IEEE 标准协会发布了一个新的以太网版本——IEEE 802.3 标准
。
Both Ethernet II and IEEE 802.3 are widely used, so we will cover them both. As you will see, they are almost identical. Usually, both are simply referred to as “Ethernet”.
Ethernet II 和 IEEE 802.3
都得到了广泛的应用,因此我们都将介绍它们。正如你所看到的,它们几乎是相同的。通常,两者都简称为“以太网”
。
For this tutorial, in order to be precise about what we mean, I will explicitly state whether I’m talking about Ethernet II or IEEE 802.3.
在本教程中,为确保所说的意思精准,我将明确地指出我是在谈论 Ethernet II 还是 IEEE 802.3。
The versions of Ethernet
以太网帧概述
Ethernet Frame Overview
Let’s consider the Ethernet Frame format:
让我们探讨一下以太网帧格式:
Ethernet Frame Header and Trailer
开始帧前导码(8 字节)
Before the Frame – Preamble (8 bytes)
First comes a Preamble consisting of 8 bytes, each containing the bit pattern of alternating 1
s and 0
s, that is, 10101010
. In Ethernet II, all 8 bytes had this pattern.
首先是由 8 个字节组成的前导码,每个字节包含交替的 1
和 0
的位模式,即 10101010
。在 Ethernet II 中,所有 8 个字节都具有此模式。
In 802.3, the seven first bytes carry the value 10101010
, yet the last bit of the last byte is set to 1, so the byte carries the value of 10101011
.
在 802.3 中,前 7 个字节的数值为 10101010
,但最后一个字节的最后一位设置为 1
,因此该字节的数值为 10101011
。
This last byte is called the Start of Frame. The last two 1
bits tell the receiver that the rest of the frame is about to start.
最后一个字节称为帧的开始。最后两 1
位告诉接收器帧的其余部分即将启动。
Sending this bit pattern before a new frame allows devices on the network to easily synchronize their receiver clocks. Note that the preamble is not really a part of the actual frame – it only precedes every frame, and thus you won’t see it on many diagrams of the Ethernet protocol.
在新帧之前发送此位模式可使网络上的设备轻松同步其接收器时钟。请注意,前导码并不是实际帧的一部分——它只出现在每一帧之前,因此你不会在以太网协议的许多图表上看到它。
Ethernet Preamble
目标地址和源地址(各 6 个字节)
Destination Address and Source Address (6 bytes each)
Next, we have two addresses, each consisting of 6 bytes. I’ll describe Ethernet Addresses in more detail later on in this post, but for now, let’s notice that a frame starts with a destination address, followed by the source address.
接下来,有两个地址,每个地址由 6 个字节组成。我稍后会详细描述以太网地址,但现在注意到一个帧以 目标 地址开始,然后是 源 地址。
Why would the frame start with the destination address? Is there a reason for that?
为什么帧会以目标地址开头?这是有原因的吗?
Well, there is. The very first thing a device is likely to do with a frame it has received is to check whether this frame is destined to it, or not. If the frame is not destined to this device, it can be simply dropped. Therefore, the destination address comes in first.
设备可能对它收到的帧做的第一件事就是检查这个帧是否发给它。如果不是,则可以直接丢弃。因此,目标地址首先出现在帧中。
Why is the source address important? Well, to know to whom the receiver should send a reply, if necessary. This source address also plays a role in the way some network devices are implemented.
为什么源地址很重要?如有必要,为了让接收者应该向谁发送回复。这个源地址在某些网络设备的实现方式中也起着作用。
类型/长度字段 – Ethernet II(类型)(2 字节)
Type / Length field – Ethernet II (Type) (2 bytes)
Next comes a quite problematic field, called the Type or Length field.
接下来是一个非常有问题的字段,称为“类型”或“长度”字段。
In Ethernet II, this field is called Type, and tells the receiver what payload this frame carries.
在 Ethernet II 中,此字段称为 Type,并告诉接收器该帧携带的有效载荷。
For instance, if this frame carries an IP layer (that is, the data of the Ethernet layer is an IP packet), then the receiving network card should forward the frame’s payload to the IP handler. If the frame’s payload is ARP, then the ARP handler should deal with it.
例如,如果此帧携带 IP 层(即以太网层的数据是 IP 数据包),则接收网卡应将帧的有效负载转发到 IP 处理程序。如果帧的有效负载是 ARP,则 ARP 处理程序应处理它。
By handler I mean the code that handles this protocol, for instance the code that parses ARP.
我所说的处理程序是指处理此协议的代码,例如解析 ARP 的代码。
We will come back to the need for Length and how it is dealt within IEEE 802.3 shortly.
稍后将回到对长度的需求以及如何在 IEEE 802.3 中处理它。
In Ethernet II, the Type field carries the type of the payload
数据和填充(46-1500 字节)
Data and Pad (46-1500 bytes)
After this field, we get up to 1500 bytes of Data. This number was chosen because RAM was expensive back in 1978, and a receiver would have needed more RAM if the frame had been bigger.
在此字段之后,最多可以获得 1500 字节的数据。之所以选择这个数字,是因为 RAM 在 1978 年很昂贵
,如果帧更大,接收器将需要更多的 RAM。
This means that if the third layer wants to send more than 1500 bytes of data over Ethernet, it must be sent across multiple frames.
这意味着,如果第三层想要通过以太网发送超过 1500 字节的数据,则必须跨多个帧发送。
There is also a minimum length of data, which is 46 bytes. Together with the other fields of the frame, the minimum length of an Ethernet frame is 64 bytes in total.
数据的最小长度
是 46 字节
。连同帧的其他字段,以太网帧的最小长度
总共为<