注:机翻,未校对。
以太网协议的工作原理指南
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 字节
。连同帧的其他字段,以太网帧的最小长度
总共为 64 字节
。
Why would we need a minimum frame length? We will discuss this in a subsequent section.
为什么需要最小帧长度?将在下一节中对此进行讨论。
For now, given that we have a minimum length for an Ethernet frame, what happens if the sender wants to send a very short message, let’s say just one byte?
现在,鉴于有一个以太网帧的最小长度,如果发送方想要发送一条非常短的消息,比如说只有一个字节,会发生什么?
In that case, the sender has to pad the message, for instance with 0
s until reaching the minimum length. For example, if the sender wants to send only 1 byte of data, such as the letter A
, they will have to add 45 bytes of 0
s.
在这种情况下,发送者必须填充消息,例如用 0
填充消息,直到达到最小长度。例如,如果发送方只想发送 1 字节的数据,例如字母 A
,则必须添加 45 字节的 0
。
46-1500 bytes of data, with padding if needed
校验和 – CRC32(4 字节)
Checksum – CRC32 (4 bytes)
Last but not least, we have a Checksum. This is a 32-bit CRC checksum used to determine whether the bits of the frame have been received correctly. In case of an error, the frame is dropped.
最后但并非最不重要的一点是,有一个校验和。这是一个 32 位 CRC 校验和,用于确定帧的位是否被正确接收。如果出现错误,帧将被丢弃。
The CRC is computed on the entire frame – that is, including the header. Notice that it doesn’t include the preamble, as it is not really a part of the frame.
CRC 是在整个帧(即包括标头)上计算的。请注意,它不包括前导码,因为它实际上不是框架的一部分。
When we use CRC-32 for the checksum, we set a fixed overhead of 32 bits, or 4 bytes, regardless of the length of the data. In other words, if we send only 1 byte of data, we get a 32-bit checksum, and if we send a thousand bytes of data – we still get 32-bits of checksum.
当使用 CRC-32 作为校验和时,无论数据长度如何,都会设置 32 位或 4 个字节的固定开销
。换句话说,如果只发送 1 字节的数据,得到一个 32 位的校验和,如果发送 1000 字节的数据,仍然得到 32 位的校验和。
类型/长度字段的问题
The Problem with the Type / Length Field
Earlier, we mentioned that the Data field has to be at least 46 bytes long, and if not, we pad it. For simplicity’s sake, let’s assume we pad with 0
s, as the standard indicates.
前面提到过,Data 字段的长度必须至少为 46 个字节,如果不是,就填充它。为了简单起见,假设用 0
填充,如标准所示。
Well, we actually have a problem here.
这里实际上有一个问题。
Let’s say the sender wants to send a single byte, consisting of the character A
. So they will send an A
followed by 45 0
s.
假设发送方想要发送一个由字符 A
组成的字节。所以他们会发送一个 A
,然后是 45 个 0
。
What happens in case the sender wants to send A
and zero? That is, the data actually consists of A0
. In this case, they would also send an A
, followed by 45 0
s. But this time, the first zero is actually part of the data, and not the padding.
如果发件人想要发送 A
和 0,会发生什么?也就是说,数据实际上由 A0
组成。在这种情况下,他们还将发送一个 A
,然后是 45 个 0
。但这一次,第一个零实际上是数据的一部分,而不是填充。
Whether the sender would like to send A
as data or A0
as the data, due to padding the frame consists of A
and 45 0
s
As a receiver, you’d need a way to differentiate these cases, and understand which bytes belong to the padding, and which bytes belong to the data, in case of a short frame.
作为接收方,您需要一种方法来区分这些情况,并了解哪些字节属于填充,哪些字节属于数据,以防帧较短。
Ethernet II dealt with this problem by… Well, not handling it. That is, the third layer will receive the data and the padding, which would be an A
followed by 45 0
s in this example. It will then have to figure out on its own which bytes belong to the data and which don’t.
Ethernet II 通过以下方式解决了这个问题:不处理它。也就是说,第三层将接收数据和填充,在本例中,填充为 A
后跟 45 0
。然后,它必须自己弄清楚哪些字节属于数据,哪些不属于数据。
This is doable, of course, if the third layer includes a length field. However, this solution is far from elegant – why would the third layer deal with a padding problem that should be dealt with by the second layer?
当然,如果第三层包含长度字段,这是可行的。然而,这个解决方案远非优雅——为什么第三层要处理一个应该由第二层处理的填充问题?
This is a clear violation of our layers model (if you would like to see an overview about the Layers Model.
这明显违反了层模型。
For this reason, IEEE decided to change the Type field into a Length field in IEEE 802.3 . So, for example, a frame carrying a single byte of data, A
, will have the Length field set to 1
, whereas a fame carrying two bytes of data, A0
, will have the Length field set to 2
.
因此,IEEE 决定在IEEE 802.3中将“类型”字段更改为“长度”字段。因此,例如,携带单个字节数据 A
的帧将 Length 字段设置为 1
,而携带两个字节数据 A0
的 fame 将 Length 字段设置为 2
。
In 802.3, the Length field sets the data apart from the padding
在 802.3 中,Length 字段将数据与填充区分开
This is an elegant solution, but now two issues arise:
这是一个优雅的解决方案,但现在出现了两个问题:
First, if you receive an Ethernet frame, how do you know if it’s an Ethernet II frame, where this field means Type, or an IEEE 802.3 frame, where this field means length?
首先,如果您收到以太网帧,您如何知道它是 Ethernet II 帧(此字段表示类型)还是 IEEE 802.3 帧(此字段表示长度)?
Second, what happens with the Type field? How would the receiver know what protocol is carried inside the frame?
其次,“类型”字段会发生什么情况?接收器如何知道帧内携带的协议是什么?
Let’s start with the first question. Just to clarify, by the time IEEE 802.3 was published, many Ethernet cards had already been in use. People didn’t want to replace their network cards just because a new standard was published.
让我们从第一个问题开始。澄清一下,在 IEEE 802.3 发布时,许多以太网卡已经在使用中。人们不想仅仅因为新标准的发布而更换他们的网卡。
Think about it, would you want to buy a new network card? Or perhaps your friends who are not programmers – would they get a new card as someone told them that “the internet geeks” decided that there was “a new standard” (whatever that means?).
想想看,要不要买一张新的网卡?或者,也许你的朋友不是程序员——他们会得到一张新卡,因为有人告诉他们“互联网极客”决定有“新标准”(不管这意味着什么?)
The solution was to allow both Ethernet II and IEEE 802.3 to operate on the same network.
解决方案是允许 Ethernet II 和 IEEE 802.3 在同一网络上运行。
Fortunately, all the Type values used at that time had greater values than 1500
. The solution is thus straightforward: in case this field has a value less than or equal to 1500
, it actually means Length. In case it has a value greater than or equal to 1536
, it means Type. The values in between currently have no meaning.
幸运的是,当时使用的所有 Type 值都大于 1500
。因此,解决方案很简单:如果此字段的值小于或等于 1500 ,则表示 Length 。如果它的值大于或等于 1536 ,则表示 Type 。介于两者之间的值目前没有意义。
The Type/Length field is divided: values equal to or lower than 1500 are Length values, and values equal to or greater than 1536 are Type values.
Type/Length 字段分为:小于等于 1500 的值为 Length 值,大于等于 1536 的值为 Type 值。
For example, if we see a frame where the value of this field is 400
, it is clear that we have an IEEE 802.3 frame, which is 400
bytes long.
例如,如果看到一个帧,其中该字段的值为 400
,则很明显有一个 IEEE 802.3 帧,其长度为 400
字节。
Now you try: in case we see a frame where this field is set to 20
, is it an Ethernet II frame or IEEE 802.3 frame?
现在你试试:如果看到一个帧,这个字段设置为 20
,它是 Ethernet II 帧还是 IEEE 802.3 帧?
Indeed, this is an IEEE 802.3 frame, which has 20
bytes of data, and thus 26
bytes of padding. And… in case we see a frame where this field is set to 2000
?
事实上,这是一个 IEEE 802.3 帧,它有 20
字节的数据,因此有 26
字节的填充。和。。。如果看到此字段设置为 2000
的帧?
In this case we know that this is an Ethernet II frame, and 2000
is the Type.
在本例中,我们知道这是一个 Ethernet II 帧,而 2000
是 Type。
So this is how we know whether we are dealing with an Ethernet 2 or an IEEE 802.3 frame.
因此,这就是我们如何知道处理的是 Ethernet II 还是 IEEE 802.3 帧。
Next, how does an IEEE 802.3 frame contain the Type information? That is, given that IEEE 802.3 overrode the Type field, there was no way for the receiver to figure out what to do with an incoming frame. Thus, IEEE 802.3 adds another header of the [802.2 LLC (Logical Link Control) protocol) right before the data. This header conveys the type information.
接下来,IEEE 802.3 帧如何包含类型信息?也就是说,鉴于 IEEE 802.3 覆盖了 Type 字段,接收器无法确定如何处理传入帧。因此,IEEE 802.3 在数据之前添加了 802.2 LLC(逻辑链路控制)协议的另一个标头。此标头传达类型信息。
So an IEEE 802.3 frame will have a destination address field, then a source field, then a length field, and then an LLC header, followed by the data and the checksum.
因此,IEEE 802.3 帧将具有目标地址字段,然后是源字段,然后是长度字段,然后是 LLC 标头,然后是数据和校验和。
IEEE 802.3 不是在 1983 年发布的吗?为什么它很重要?
Wait, wasn’t IEEE 802.3 published in 1983? Why is it relevant?
As mentioned beforehand, in 1978, Ethernet II was published. Not so long later, in 1983, a new format came out – and its authors allowed for backward compatibility, probably believing that in a few years, all devices would be upgraded to the new standard.
如前所述,1978 年,Ethernet II 发布。不久之后,在1983年,一种新格式问世了,它的作者允许向后兼容,可能认为几年后,所有设备都将升级到新标准。
Oh, were they wrong.
哦,他们错了。
If you check your own network (given that you are connected to an Ethernet one), I bet you will see Ethernet II frames.
如果您检查自己的网络(假设您连接到以太网网络),我敢打赌您会看到 Ethernet II 帧。
Your device probably supports both versions, but by default it will transmit Ethernet II frames, rather than 802.3. After all, it is guaranteed that any device connected to an Ethernet network can read Ethernet II frames, and it’s not guaranteed that the device can read 802.3 ones. If Ethernet II works, why not use it?
您的设备可能支持这两个版本,但默认情况下它将传输 Ethernet II 帧,而不是 802.3
。毕竟,可以保证连接到以太网网络的任何设备都可以读取 Ethernet II 帧,并且不能保证设备可以读取 802.3 帧
。如果 Ethernet II 有效,为什么不使用它呢?
All third-layer protocols had to account for the fact that Ethernet doesn’t solve the problem of differentiating data from padding. So if all protocols already deal with that, why don’t we just…keep things the way they are?
所有第三层协议都必须考虑到以太网无法解决区分数据和填充的问题。因此,如果所有协议都已经处理了这个问题,为什么不直接…保持原样?
Endpoint devices (such as personal computers) almost always communicate over Ethernet II. IEEE 802.3 is also very common, though, and it’s used by default on most modern network devices (such as switches).
端点设备(如个人计算机)几乎总是通过 Ethernet II 进行通信。不过,IEEE 802.3 也很常见,默认情况下,它在大多数现代网络设备(如交换机)上使用。
This story actually entails a really important lesson.
这个故事实际上需要一个非常重要的教训。
It is very, very hard to replace protocols after the fact, especially when they are implemented on hardware devices (such as network cards).
事后替换协议是非常非常困难的,尤其是当它们在硬件设备(如网卡)上实现时。
数据包间隙
What’s an Interpacket Gap?
After an Ethernet frame is sent, transmitters wait a very short period of time before transmitting the next frame, in order to allow the receiver to know that the transmission of a frame is over. This idle time between frames is called the “Interpacket gap”.
在以太网帧发送后,发射器在传输下一帧之前会等待很短的时间,以便让接收器知道帧的传输已经结束。帧之间的空闲时间称为“数据包间间隙”。
以太网地址如何工作的
How Ethernet Addresses Work
Every Ethernet frame carries two addresses – first, the destination, and second, the source. We mentioned that the destination address appears first so the receiver will be able to tell whether the frame is relevant for it. If not, the frame will be discarded.
每个以太网帧都带有两个地址——第一个是目标地址,第二个是源地址。我们提到,目标地址首先出现,因此接收方将能够判断该帧是否与它相关。否则,帧将被丢弃。
Ethernet addresses within the Ethernet Frame
以太网帧内的以太网地址
What does an Ethernet address look like?
以太网地址是什么样子的?
An Ethernet address consists of 6 bytes – that is, 48 bits. Usually, they are presented in hexadecimal base, delimited either by dashes or colons, as you can see in these examples:
以太网地址由 6 个字节组成,即 48 位。通常,它们以十六进制为基数,用破折号或冒号分隔,如以下示例所示:
Two representations of the same Ethernet Address
同一以太网地址的两种表示形式
00:01:42:a9:c2:dd
00-01-42-a9-c2-dd
These are two representations of the exact same Ethernet address, and there is no real difference between the two.
这是完全相同的以太网地址的两种表示形式,两者之间没有真正的区别
。
In general, Ethernet addresses are supposed to be globally unique. That is, no two Ethernet devices share the same address (at least, in theory).
通常,以太网地址应该是全局唯一的。也就是说,没有两个以太网设备共享相同的地址(至少在理论上是这样)。
The first 3 bytes of any address is called the OUI – Organizationally Unique Identifier. To make sure the addresses are unique, IEEE assigns these OUIs to various manufacturers, such as Dell, HP or IBM.
任何地址的前 3 个字节称为 OUI – 组织唯一标识符。为了确保地址是唯一的,IEEE将这些 OUI 分配给不同的制造商,如戴尔、惠普或IBM。
This part of the address is also called the Vendor ID (with the exception of the two least significant bits, as we will see). Then, the manufacturers assign the remaining 3 bytes to specific hosts. This part is also called the Host ID.
地址的这一部分也称为供应商 ID(除了两个最低有效位,如我们所见)。然后,制造商将剩余的 3 个字节分配给特定主机。这部分也称为主机 ID。
The most significant 3 bytes are the Vendor ID, and the least significant 3 bytes are the Host ID
最大的 3 个字节是 Vendor ID,最小的 3 个字节是 Host ID
For example, the OUI 00:01:42
belongs to Cisco. Now, Cisco can manufacture a network card and assign it the address 00:01:42:00:00:01
. Next, it can manufacture another card and assign it the address 00:01:42:00:00:02
, and so on. These two addresses share the same Vendor ID, but have different Host IDs.
例如,OUI 00:01:42
属于 Cisco。现在,思科可以制造网卡并为其分配地址00:01:42:00:00:01
。接下来,它可以制造另一张卡并为其分配地址 00:01:42:00:00:02
,依此类推。这两个地址共享相同的供应商 ID,但具有不同的主机 ID。
Since a single OUI leaves 3 bytes to be used for the host IDs, we have 2^24
host IDs per OUI – that is, 16,777,216 host IDs. Of course, big manufacturers need many more addresses, and thus they are assigned additional OUIs. For example, 00:01:64
is another OUI that belongs to Cisco.
由于单个 OUI 会留下 3 个字节用于主机 ID,因此每个 OUI 有 2^24
个主机 ID,即 16,777,216 个主机 ID。当然,大型制造商需要更多的地址,因此他们被分配了额外的 OUI。例如,00:01:64
是属于 Cisco 的另一个 OUI。
单播和组播位
Unicast and Multicast Bits
Ethernet addresses also consist of two special bits.
以太网地址也由两个特殊位组成。
The first special bit indicates whether the address is a unicast or a multicast address. Unicast means that the address represents a single device. Multicast addresses represent a group of devices – such as all printers on the network, or all devices in the same local network.
第一个特殊位指示地址是单播地址还是组播地址。单播表示该地址代表单个设备。组播地址表示一组设备,例如网络上的所有打印机或同一本地网络中的所有设备。
The bit representing whether the address is unicast or multicast is the least significant bit within the most significant byte. Wait, what?
表示地址是单播还是多播的位是最高有效字节中的最低有效位。等等,什么?
Consider the following Ethernet address:
请考虑以下以太网地址:
06:b2:d9:a2:32:9e
The most significant byte is 06
.
最高有效字节是 06
。
Let’s convert this to binary:
将其转换为二进制:
00000110
Now we look at the least significant bit – that is, this 0
:
现在看一下最低有效位,即这个 0
:
When the least significant bit within the most significant byte is set to 0
, this is a Unicast address
当最高位字节中的最低位设置为 0 时
,这是一个单播地址
。
This bit is off. This means that this is a unicast address. In other words, it belongs to a single device, such as a computer’s network card.
此位已关闭。这意味着这是一个单播地址。换句话说,它属于单个设备,例如计算机的网卡。
Let’s consider another address:
让我们考虑另一个地址:
11:c0:ff:ee:d8:ab
The most significant byte is 11
(in hexadecimal base).
最高有效字节是 11
(以十六进制为基数)。
Let’s convert this to binary:
将其转换为二进制:
00010001
When the least significant bit within the most significant byte is set to 1
, this is a Multicast address
当最高位字节中的最低位设置为 1 时
,这是一个多播地址
。
The least significant bit is this one. Since it is on, we can tell that this is a multicast address. That is, it’s an address of a group. You can send a frame to this address, and all devices that belong to this group will consider the frame as sent to them.
最低有效位是这个。由于它被置位,可以确定这是一个多播地址。也就是说,这是一个组的地址。你可以将帧发送到这个地址,而属于这个组的所有设备都会将该帧视为发送给它们的。
One very famous multicast address is called the broadcast address, that is – the group that contains all machines. The address of this group is:
一个非常著名的组播地址称为广播地址,即包含所有计算机的组
。该组的地址是:
FF:FF:FF:FF:FF:FF
In other words, the address where all bits are on.
FF:FF:FF:FF:FF:FF
换句话说,所有比特位都是开启状态的地址。
All the machines are part of the broadcast group.
所有机器都是广播组的一部分。
全局唯一 / 本地管理的位
Globally Unique / Locally Administered Bit
The second special bit indicates whether the address is indeed globally unique. This bit is the second least significant bit within the most significant byte. Um, what?
第二个特殊位指示地址
是否确实是全局唯一的。此位是最高有效字节中第二低有效位
。
Well, again, consider the first address from before:
再次考虑之前的第一个地址:
06:b2:d9:a2:32:9e
The first byte is 06
.
第一个字节是 06
。
Converted to binary, we get:
转换为二进制,得到:
00000110
So the second least significant bit is the one right here:
所以第二个指示位就是这里:
When the second least significant bit within the most significant byte is set to 1
, this address is not globally unique
当最高位字节中的第二低位设置为 1 时
,该地址不是全局唯一
的
This bit is on, and thus we know that this address is actually not globally unique. IEEE will never assign this address to any vendor. So what is this address? Well, in this case it’s just one that I’ve made up. If I wanted to, I could assign it to a specific device. The fact that this bit is on declares that it is not globally unique.
这个比特位是开启的,因此我们知道这个地址实际上不是全局唯一的。IEEE 绝不会将这个地址分配给任何供应商。那么这个地址是什么呢?嗯,在这种情况下,它只是我随意编造的一个地址。如果我想,我可以将其分配给特定的设备。这个比特位的开启表明它不是全局唯一的。
Consider another address:
探讨另一个地址:
00:01:42:a9:c2:dd
The first byte is 00
, so the second least significant bit is 0
.
第一个字节是 00
,因此第二个最低有效位是 0
。
This is indeed a globally unique address, assigned to Cisco.
这确实是分配给思科的全球唯一地址。
以太网地址 – 回顾
Ethernet Addresses – Recap
So, all in all, an Ethernet address has two main parts: The vendor ID, and the host ID.
因此,总而言之,以太网地址有两个主要部分:供应商 ID 和主机 ID
。
Most significant byte | 取值 | 含义 |
---|---|---|
least significant bit (IG) | 0 | 单播 |
1 | 组播 | |
second least significant bit (UL) | 1 | 本地管理 |
0 | 全球唯一 |
为什么以太网帧有最小长度?
Why Does an Ethernet Frame Have a Minimum Length?
This is more of a “bonus” part of this post, and concerns collisions. Collisions is a very interesting topic, but since this post focuses on the Ethernet protocol, collisions will not be of our focus. I will therefore address this issue just briefly. While it’s not crucial to understand in order to understand Ethernet frames, I promised a complete overview of the Ethernet protocol.
这更像是这篇文章的“奖励”部分,涉及碰撞。碰撞是一个非常有趣的话题,但由于这篇文章的重点是以太网协议,因此碰撞不会成为我们的重点。因此,我将简要地谈谈这个问题。虽然理解以太网帧并不重要,但我承诺对以太网协议进行全面概述。
In the overview, I mentioned that an Ethernet frame consists of minimum 46 bytes of data and maximum 1500 of data. I already explained why we have that maximum limit, but what about the minimum?
在概述中,我提到以太网帧由最少 46 字节的数据和最多 1500 字节的数据组成。我已经解释了为什么有这个最大限制,但是最小限制呢?
To simplify our discussion, let’s consider a network using classic Ethernet where all computers are attached to a single cable.
为了简化讨论,让我们考虑一个使用经典以太网的网络,其中所有计算机都连接到一根电缆上。
A “classic Ethernet” network with four devices connected via a single cable
一个“经典以太网”网络,四台设备通过一根电缆连接在一起
Let’s say A wants to send a message to B, and C wants to send a message to D. Let’s say that while A is transmitting its frame, C is also transmitting its frame. In this case, the frames will collide.
假设 A 想向 B 发送消息,C 想向 D 发送消息。假设 A 在传输其帧的同时,C 也在传输其帧。在这种情况下,帧将发生碰撞。
In case two devices transmit data on the same time - their frames will collide
When this happens, we get errors – much like the case where two people start to speak in the same time, and it is impossible to understand either of them.
当这种情况发生时,我们会得到错误——就像两个人同时开始说话的情况一样,不可能理解他们中的任何一个。
如何在以太网中处理冲突?CSMA/CD
How are collisions handled in Ethernet?
Ethernet uses two main mechanisms to deal with collisions. The first is called CSMA, which stands for Carrier Sense Multiple Access. This basically means that when a station wants to transmit data, it first senses the channel to see if anyone else is transmitting by checking the signal level of the line. If the channel is in use, the station will wait and try again.
以太网使用两种主要机制来处理冲突。第一个称为 CSMA,它代表载波检测多址
。这基本上意味着,当一个站点想要传输数据时,它首先通过检查线路的信号电平来感知通道,看看是否有其他人在传输。如果通道正在使用中,站点将等待并重试。
So, if A is transmitting, and C wants to send data, C will wait until A finishes its transmission before starting to transmit.
因此,如果 A 正在传输,而 C 想要发送数据,则 C 将等到 A 完成传输后再开始传输。
This is just like the case in a human conversation, where one person waits until the other stops talking, and only then does that person talk.
这就像人类对话中的情况一样,一个人等到另一个人停止说话,然后这个人才会说话。
Yet, just like the case where two people might start talking at the same time, two Ethernet machines might start transmitting data at the same time. In this case, CD – Collision Detection – comes into play. Collision Detection means that the transmitting devices detect the fact that a collision has occurred. This is achieved by listening to the channel while transmitting.
然而,就像两个人可能同时开始交谈一样,两台以太网设备可能同时开始传输数据。在这种情况下,**冲突检测(CD)**就会发挥作用。冲突检测意味着传输设备会检测到发生了冲突的事实。这是通过在传输时监听通道来实现的。
For example, assume that station A transmits the bit stream 11001010
. While transmitting, A is also listening to the channel. If no collision occurred, A would also read the signal 11001010
from the line.
例如,假设工作站 A 传输比特流 11001010
。在传输时,A 也在监听通道。如果没有发生碰撞,A 也会从线路中读取信号 11001010
。
With Collision Detection, A is listening to the channel while transmitting data. In case no collision occurred, A will sense exactly the bitstream it has sent
使用碰撞检测时,A 在发送数据的同时监听通道。在没有发生碰撞的情况下,A 将准确地感知它发送的比特流
If, however, a collision occurred, say with a frame sent by C, then A would read something different from the line – for instance, 11011010
. This way, machine A realizes that its frame has collided.
但是,如果发生了碰撞,比如站点 C 发送了一帧数据,那么站点 A 会在线路上读取到与预期不同的信号,例如 11011010
。这样,站点 A 就意识到发生了帧碰撞。
With Collision Detection, A is listening to the channel while transmitting data. In case of a collision, A reads a different bitstream than that it has sent
使用碰撞检测时,A 在发送数据的同时监听信道。在发生碰撞的情况下,A 读取的比特流与其发送的比特流不同
Machine A can realize that a collision has occurred even before it finished transmitting the frame. Then, machine A stops transmitting and issues a JAM signal to tell the other station that a collision has occurred. As a result, both stations stop transmitting and wait a random interval of time before trying to submit again.
机器 A 可以在完成帧的发送之前就意识到发生了碰撞。接着,机器 A 停止发送,并发送一个 JAM 信号通知其他站点发生了碰撞。因此,两个站点都停止发送,并等待随机的时间间隔后再次尝试发送。
The amount of time that the stations wait increases with the number of collisions in the network. So on the first collision, A and C wait for a relatively short amount of time before transmitting again. If another collision occurs, they might wait longer.
站点等待的时间量随着网络中碰撞次数的增加而增加。因此,在第一次碰撞时,A 和 C 等待相对较短的时间,然后再次传输。如果发生另一次碰撞,他们可能会等待更长的时间。
After a collision occurs, the amount of time that the stations wait increases with the number of collisions in the network
碰撞发生后,站点等待的时间随着网络中碰撞次数的增加而增加
Now, back to Ethernet. Ethernet requires that valid frames must be at least 64 bytes long, from destination address to checksum, including both. So, that data has to be at least 46 bytes long. If the frame is too short, then it must be padded.
现在,回到以太网。以太网要求有效帧的长度必须至少为 64 个字节,从目标地址到校验和,包括两者。因此,该数据的长度必须至少为 46 个字节。如果框架太短,则必须填充。
The minimum length of an Ethernet frame consists of 46 bytes of data, or 64 bytes overall
以太网帧的最小长度为46字节,总长度为64字节
One reason for having this minimum is directly related to the collision detection mechanism stated above.
具有此最小值的一个原因与上述碰撞检测机制直接相关。
Let’s consider the following scenario. Host A wants to transmit a really really short frame to B, a frame that is only 1 byte long. I am exaggerating of course, this can’t really happen in Ethernet, but it will be helpful for the explanation.
让我们考虑以下场景。主机 A 希望向 B 传输一个非常非常短的帧,该帧只有 1 个字节长。当然,我夸大其词了,这在以太网中不可能真正发生,但它对解释很有帮助。
Host A transmits this frame, which consists of 8 1
s. Then, A listens to the channel while transmitting, and also reads 8 1
s from it, reaching the conclusion that the frame has been transmitted successfully.
主机 A 发送了一个包含 8 个 1
的帧。在发送过程中,A 同时监听通道,并从中读取到 8 个 1
,得出帧已成功发送的结论。
However, before the frame reaches the other end of the network, D starts transmitting a very short frame, one byte long, consisting of 8 0
s. D listens to the channel while transmitting, and also reads 8 0
s from it, concluding that the frame has been transmitted successfully.
然而,在帧到达网络的另一端之前,主机 D 开始发送一个非常短的帧,只有一个字节长,包含 8 个 0
。D 在发送过程中也监听通道,并从中读取到 8 个 0
,得出帧已成功发送的结论。
Both A and D send a really short frame, and they finish transmitting without realizing a collision is liable to take place
A 和 D 都发送了一个非常短的帧,它们在没有意识到可能发生碰撞的情况下完成了传输
Now, these two really short frames collide. Yet, neither A nor D are aware of this collision, as they have already concluded that the frame has been successfully delivered.
现在,这两个非常短的帧发生了碰撞。然而,A 和 D 都没有意识到这次碰撞,因为他们已经得出结论,框架已经成功交付。
In order to avoid such cases, the frame must be long enough to prevent a station from completing its transmission before the first bit of the frame reaches the far end of the line. Having a minimum length for Ethernet frames solves this issue.
为了避免这种情况发生,帧的长度必须足够长,以防止某个站点在帧的第一个比特到达线路远端之前完成传输。设置以太网帧的最小长度可以解决这个问题。
This was a very short discussion of collisions. If you’d like to know more about this topic, refer to the “additional resources” section below.
这是关于碰撞的非常简短的讨论。如果您想了解有关此主题的更多信息,请参阅下面的“其他资源”部分。
Additional References 其他参考
-
Carrier-sense multiple access with collision detection - Wikipedia
-
Carrier Sense Multiple Access Collision Detect (CSMA/CD) Explained - ITPRC
via: Omer Rosenbaum OCTOBER, 2022