IEEE 802.3 Ethernet

Introduction

Ethernet 是过去30年以来最为成功的局域网(local area networking)技术。

1. First widely used LAN technology (第一次被广泛使用的局域网技术)

2. kept up with speed race: 10 Mbps – 100 Gbps

3. Connectionless: No handshaking between sending and receiving NICs(Network Interface Card,网卡)

不建立连线。

4. Unreliable: receiving NIC doesn’t send ACKs or NACKs to sending NIC

不可靠。

ACK:Acknowledgement,即确认字符,在数据通信中,接收站发给发送站的一种传输类控制字符。表示发来的数据已确认接收无误。

NACK:Nacknowledge,说明数据传输不正确,需要进行重传。

5. Ethernet’s MAC protocol: Carrier Sense Multiple Access with Collision Detection (CSMA/CD,即带冲突检测的载波监听多路访问技术)

Ethernet Topologies

1. Bus Topology

Bus topology popular through mid 90s.

IEEE 802.3 Ethernet_第1张图片

The bus is the data link in a bus network. The bus can only transmit data in one direction, and if any network segment is severed, all network transmission ceases.

A host on a bus network is called a station or workstation. In a bus network, every station receives all network traffic(流量), and the traffic generated by each station has equal transmission priority. Each network segment is, therefore, a collision domain. In order for nodes to transmit on the same cable simultaneously(同时), they use a media access control technology such as carrier sense multiple access (CSMA) or a bus master. (引用自 wikipedia )

collision domain:在以太网中,如果某个CSMA/CD网络上的两台计算机在同时通信时会发生冲突,那么这个CSMA/CD网络就是一个冲突域。

IEEE 802.3 Ethernet_第2张图片

all nodes in same collision domain (can collide with each other)

2. Ethernet (10Base5)

An Ethernet segment is implemented on a coaxial cable of up to 500 m.

Hosts connect to an Ethernet segment by tapping into it.

A transceiver (a small device directly attached to the tap) detects when the line is idle and drives signal when the host is transmitting. (transceiver 既可以接受信号,也可以发送信号)

The transceiver also receives incoming signal.

The transceiver is connected to an Ethernet adaptor(网卡) which is plugged into the host. But now most are built in into the computers.(现在大部分网卡已经做成内置,如笔电)

The protocol is implemented on the adaptor.(指 CSMA/CD 这个协议被实作在网卡内部的芯片中)

IEEE 802.3 Ethernet_第3张图片1. Cable Signaling (Manchester Encoding)

IEEE 802.3 Ethernet_第4张图片

Each bit has a transition

Allows clocks in sending and receiving nodes to synchronize to each other

之所以要采用 Manchester Encoding,是为了同步时钟。接收方利用包含有同步信号的特殊编码从信号自身提取同步信号来锁定自己的时钟脉冲频率,达到同步目的。

Manchester Encoding 将时钟和数据包含在数据流中,在传输代码信息的同时,也将时钟同步信号一起传输到对方,每位编码中有一跳变,不存在直流分量,因此具有自同步能力和良好的抗干扰性能。但每一个 bit 的 transition 都被调成两个电平。

再解释的通俗些。A和B的时钟未必是一样的,换句话说,对于真正的10000秒,可能A用了10001秒,而B只用了9999秒,两台机器的石英振荡器的频率是不一样的,导致解读一秒真正所花的时间是不一样的。假设网络带宽为10 Mbps,那么传递一个bit的所需的时间(位宽)是 1/107 秒,如果A以自己的时钟(速度)来发送资料(binary,不是0就是1,传输过程中,1是高电平,0是低电平),而B也以自身的时钟(速度)来接受资料(bianry),但是由于两者速度不一致,B会解读错误,因为对于这1/10秒来说,两者真正所花的时间是不一样的。

因此,我们需要B以A的clock来解释这部分资料,但是我们又不知道A的clock,因此需要对A发送的资料先进行采样(以B的角度来看,一段时间内,传递了多少个bit,之后就可以以这个速度来解释资料)。这个时候就会出现一个问题,如果A发的大段资料都是连续的1或者连续的0,那么我们就没有办法分清在某段时间内,到底有多少个bit了,从而无法进行采样了。因此,曼彻斯特编码使得每一位都有一个跃迁(Each bit has a transition),例如,从低电位跃迁到高电位表示1,从高电位跃迁到低电位表示0,如此一来,就可以完成采样了。

2. repeaters

Multiple Ethernet segments can be joined together by repeaters. 多个网段可以通过 repeaters 连接在一起。

A repeater is a device that forwards digital signals. 10Base5 Ethernet 一个网段500米, 数字信号传送500米后会减弱不少,repeater 可以起到放大信号的作用。

No more than four repeaters may be positioned between any pair of hosts.(An Ethernet has a total reach of only 2500 m.

下图示例了两个网段通过 repeater 来连接:

IEEE 802.3 Ethernet_第5张图片

下图示例了5个网段的连接:

IEEE 802.3 Ethernet_第6张图片

3. Ethernet (10Base2)

Ethernet 的第二代技术

Instead of using coax cable, an Ethernet can be constructed from a thinner cable known as 10Base2 (the original was 10Base5)

10 means the network operates at 10 Mbps

Base means the cable is used in a baseband system

2 means that a given segment can be no longer than 200 m

10Base2 使用更细的电缆。

IEEE 802.3 Ethernet_第7张图片

4. Ethernet (10BaseT)

New Technologies in Ethernet

-> Another cable technology is 10BaseT

T stands for twisted pair (使用双绞线)

Limited to 100 m in length

-> With 10BaseT, the common configuration is to have several point to point segments coming out of a multiway repeater, called Hub

之前使用 10Base5 或者 10Base2 技术时,我们通常直接把 cable 是放地上的,这样只要有一个网段不小心断开了,那么所有的网络就瘫痪了。为了管理线路,我们在 10BaseT 技术中可以使用一个 Hub 来管理双绞线。

IEEE 802.3 Ethernet_第8张图片

注意使用 Hub ,采用的仍然是广播的方式。只要有一台电脑发送讯号了,那么所有电脑都会收到。

5. Star Topology

相对于 Bus Topology,今天我们盛行的是 Star Topology。

active switch in center

each “spoke” runs a (separate) Ethernet protocol (nodes do not collide with each other)

IEEE 802.3 Ethernet_第9张图片

注意:Switch 的每一个端口相当于一个网卡,每一台电脑与交换机连接,都是 point to point ,也就是网卡与网卡相连接,因此每个网段相当于只有两台电脑。Switch的每个端口是可以处理内容,它可以选择将其滤掉或者选择性的转送到某一台机器,而 Hub 同 Repeater 一样,只可以将讯号进行转送,而没有处理内容的能力。

当使用 Hub 时,其采用广播机制,某个时间只可以有一台电脑发送消息(如果两台电脑均发送消息,那么讯号会相互干扰),而使用 Switch 时,可以多台电脑同时发送消息,因为 Switch 的端口相当于一个网卡,可以单独处理消息的内容。

小结,如今对于Ethernet (10BaseT):

(a) The common network configuration is like “star” with many point-to-point segments

(b) Hub is used to connect the point-to-point segments.

(c) Switch can also be used to connect the point-to-point segments.

Ethernet Frame Format

1. Frame format

Preamble (64bits): allows the receiver to synchronize with the signal (sequence of alternating 0s and 1s).

Source and Destination MAC Addresses (48bits each).

Packet type (16bits): acts as demux key to identify the higher level protocol.

Data (up to 1500 bytes)
Minimally a frame must contain at least 46 bytes of data.
Frame must be long enough to detect collision.

FCS: CRC (32bit)

IEEE 802.3 Ethernet_第10张图片

Preamble: (101010...1010) for Synchronization

SFD: Start Frame Delimiter (10101011)

DA: Destination MAC Address

SA: Source MAC Address

Packet type (16bits): acts as demux key to identify the higher level protocol.

LLC-Frame: Up to 1500 bytes

PAD: Padding when LLC-Frame < 46 bytes

FCS: Frame Check Sequence (CRC-32)

MAC-frame size -- from DA to FCS

Min 64 bytes to distinguish from collision

Max 1518 bytes to prevent dominating bandwidth

2. Ethernet Addresses

1. Each host on an Ethernet (in fact, every Ethernet host in the world) has a unique Ethernet Address.

2. The address belongs to the adaptor, not the host.

It is usually burnt into ROM.

3. Ethernet addresses are typically printed in a human readable format

As a sequence of six numbers separated by colons.(6个字节用冒号分开)

Each number corresponds to 1 byte of the 6 byte address and is given by a pair of hexadecimal digits, one for each of the 4-bit nibbles in the byte(每一个字节采用16进制表示)

Leading 0s are dropped.

For example, 8:0:2b:e4:b1:2 is
00001000 00000000 00101011 11100100 10110001 00000010

4. To ensure that every adaptor gets a unique address, each manufacturer of Ethernet devices is allocated a different
prefix that must be prepended to the address on every adaptor they build

AMD has been assigned the 24bit prefix 8:0:20

5. Each frame transmitted on an Ethernet is received by every adaptor connected to that Ethernet.(实际上在Ethernet上传输的每一个 frame 都可以被连接在网络上的网卡收到,但是我们只接收发给自己的,而滤掉不是发给自己的)

6. Each adaptor recognizes those frames addressed to its address and passes only those frames on to the host.(每个网卡只收给自己的 frame,而 drop 掉并非发给自己的 frame )

7. In addition to unicast address(单播地址), an Ethernet address consisting of all 1s is treated as a broadcast address.(与 unicast 区分开来,如果 Destination MAC Address 48位全部填1,那么这就是一个 broadcsst )

All adaptors pass frames addressed to the broadcast address up to the host.

8. Similarly, an address that has the first bit set to 1 but is not the broadcast address is called a multicast address.(第一位是1,剩余47位只要不是全为1,就是一个 multicst address )

A given host can program its adaptor to accept some set of multicast addresses.(我们可以为网卡设定特定的群组)

9. To summarize, an Ethernet adaptor receives all frames and accepts

Frames addressed to its own address

Frames addressed to the broadcast address

Frames addressed to a multicast address if it has been instructed

Ethernet MAC Protocol -- CSMA/CD

1. Background

Any signal placed on the Ethernet by a host is broadcast over the entire network

Signal is propagated in both directions.

Repeaters forward the signal on all outgoing segments. (注意 Repeater 只是将讯号恢复成更漂亮的样子,并不会处理讯号)

Terminators attached to the end of each segment absorb the signal.

IEEE 802.3 Ethernet_第11张图片

2. CSMA (Carrier Sense Multiple Access) 载波侦听多路访问

CSMA: listen before transmit

If channel sensed idle: transmit entire frame

If channel sensed busy, defer transmission

缺陷是,在 sence 的结果是 idle 的前提下发送 frame,并且即使中途 collision ,也一定得将 frame 传送完,严重浪费资源。

3. CSMA collisions

1. collisions can still occur(仍然有可能发生 collision ,因为 frame 的传送也需要时间,可能只是当时的状态是 idle)

propagation delay(传播需要时间,因此会有延迟) means two nodes may not hear each other’s transmission

2. collision:

entire packet transmission time wasted

正如刚刚提到的,遇到 collision ,CSMA 这个 protocal 仍然会将整个 frame 传送完毕,因此会严重浪费资源。

可以参看以下这张示意图,纵轴代表时间:

IEEE 802.3 Ethernet_第12张图片

4. CSMA/CD (Collision Detection) 带冲突检测的载波监听多路访问

CSMA/CD: carrier sensing, deferral as in CSMA

collisions detected within short time 在一个较短的时间片内检测信道是否有 collision

colliding transmissions aborted, reducing channel wastage 如果讯号传送发生 collision,会立即中断传送,减少无谓的资源浪费

1. Collision detection

Measure signal strengths, compare transmitted, received signals

IEEE 802.3 Ethernet_第13张图片

2. Carrier Sense Multiple Access with Collision Detection (CSMA/CD).

A set of nodes send and receive frames over a shared link.

Carrier sense means that all nodes can distinguish between an idle and a busy link.

Collision detection means that a node listens as it transmits and can therefore detect when a frame it is transmitting has collided with a frame transmitted by another node.(一个 node 在 transmit 的同时可以监听,因此,当该 node 正在传送的 frame 与另一个 node 正在传送的 frame 发生 collision 时,该 node 是可以 detect 到的)

3. When the adaptor has a frame to send and the line is idle, it transmits the frame immediately.

4. When the adaptor has a frame to send and the line is busy, it waits for the line to go idle and then transmits immediately.

5. The Ethernet is said to be 1-persistent protocol because an adaptor with a frame to send transmits with probability 1 whenever a busy line goes idle.(只要信道为 idle 状态,那么 adaptor 一定会 transmit frame)

6. Since there is no centralized control it is possible for two (or more) adaptors to begin transmitting at the same time,

Either because both found the line to be idle,

Or, both had been waiting for a busy line to become idle.

When this happens, the two (or more) frames are said to be collide on the network.

7. Since Ethernet supports collision detection, each sender is able to determine that a collision is in progress.(Ethernet 支持 collision detection,因此每一个 sender transmit frame 后是可以确定是否发生了 collision 的 )

8. At the moment an adaptor detects that its frame is colliding with another, it first makes sure to transmit a 32-bit jamming sequence and then stops transmission.(如果网卡检测到了 collision ,那么它会发送一个32位的 jamming sequence 来把讯号冲击的更混乱些,确保网络上的每一个网卡都可以确定这个 frame 发生了碰撞,是要被丢弃的)

Thus, a transmitter will minimally send 96 bits in the case of collision
( 64-bit preamble + 32-bit jamming sequence )

ps:Preamble is 7 bytes + 1 byte SDF start frame delimiter = 8 bytes.

IEEE 802.3 Ethernet_第14张图片

One way that an adaptor will send only 96 bits(called a runt frame 过小帧) is if the two hosts are close to each other.(显然只有当两个网卡相距十分近的情况下,才可以立即检测到 collision ,此时仅仅发送 96 个bit)

In case the two hosts are farther apart, they would have had to transmit longer, and thus send more bits, before detecting the collision.(当两个网卡相距很远的时候,那么在检测到 collision 之前,讯号会传送的相对更久一些,因此会传送更多的bit)

5. Collision Window 碰撞窗口或者冲撞视窗

1. The worst case scenario happens when the two hosts are at opposite ends of the Ethernet.

举个例子来说,加入分别位于网络两端的 adapter A 与 adapter B,当 B 发送 frame 快到 A 门口时,A 正好也发送 frame ,此时讯号发生 collision ,等 B 检测到 collision 时,实际上讯号已经走了两个 A 到 B 之间的距离。

2. To know for sure that the frame its just sent did not collide with another frame, the transmitter may need to send as many as 512 bits.(想要知道发送的 frame 是否与网络上的其他 frame 发生collision,那么至少得发送 512 个bit才能知道结果)

why?看以下例子:

Consider that a maximally configured Ethernet is 2500 m long, and there may be up to four repeaters between any two hosts, the round trip delay has been determined to be 51.2 μs. For 10Mbps Ethernet (such as 10base5), what is the minimum length of a frame in order to detect all possible collisions ?

Answer:    1 * 107 bit/s * 51.2 * 10-6 s =  512 bit

Every Ethernet frame must be at least 512 bits (64 bytes) long. (因此一个 frame 最小的长度不能小于 512 bit,如果小于512 个bit,那么我们无法得知该 frame 是否与其他 frame 发生了 collision 。我们必须确保发送每一个 frame 时,都知道其是否发生了 collision。换句话说,如果一个 frame 长度小于 512 bit,那么如果后面发生了 collision ,我们并不知道具体是哪一个 frame 发生了碰撞)

14 bytes of header + 46 bytes of data + 4 bytes of CRC

IEEE 802.3 Ethernet_第15张图片

Tip:Frames shorter than 64 bytes will be treated as “collided” frames and will be dropped directly.

6. 阶段小结

每个封包的长度至少为512 bits,以10Mbps 的网络来说,就是传送时间​​为51.2us。网络最远两端信号来回时间为51.2us (collision window)。换句话说, 一个 Node(实际上是 Adapter) 传送到 256 bits 时,他的信号已经到达(或者说是) 最远端,在这之后所有其他 Nodes(实际上是 Adapter) 都不会再传送(carrier sense = busy)。在这时间之前发生的 collision (可能不同距离), 都会在 Sender 传送到 512 bits 之前传到 sender 被 detect 出来。 一个 Node 传送到 512 bits 如果还未侦测到 collision , 就表示此封包不会发生 collision , 因为传送到256 bits 时,他的信号已经布满整个网络。

每一台电脑的网路端口(Adapter 的 Port)都有多条电线,其中有一条电线用于将资料送进网路(如 10base5 的同轴电缆线),有一条是接收的,另外还有一条就是用来监听的。

监听是针对网路段的信号(10base5 的同轴电缆线上信号)。 对于 Sender 来说,transmit 出去的信号立刻就会由监听线上回来。 如果没有发生 collision , 就会 listen 到自己送出去的信号, 如果发生 collision , 信号会彼此重叠或是抵销,导致出现混乱信号,无法辨识。

7. Exponential Backoff Algorithm 指数回归(后退)算法

1. Once an adaptor has detected a collision, and stopped its transmission, it waits a certain amount of time and tries again.

2. Each time the adaptor tries to transmit but fails, it doubles the amount of time it waits before trying again.

3. This strategy of doubling the delay interval between each retransmission attempt is known as Exponential Backoff.

The adaptor first delays either 0 or 51.2 μs, selected at random.

If this effort fails, it then waits 0, 51.2, 102.4, 153.6
μs (selected randomly) before trying again;
This is k * 51.2 for k = 0, 1, 2, 3

After the third collision, it waits k * 51.2 for k = 0…23 – 1 (again selected at random).

In general, the algorithm randomly selects a k between 0 and 2n – 1 and waits for k * 51.2 μs, where n is the number of collisions experienced so far.

8. Summary

1. CSMA/CD Protocol

Carrier Sense before transmission

Carrier Sense while transmission

Collision: Two or more stations transmitting simultaneously

Backoff: Random delay after collision

Deference: Defers transmission if channel is sensed busy

Collision Window (Slot time): Round-trip propagation delay time plus some carrier sense time. In IEEE 802.3, this value is defined to be 51.2 us.

2. CSMA/CD Collision Handling

Collision Signal is generated by Physical layer.

Jam signal (collision enforcement): To make sure that all stations involved in the collision will detect collision. A pattern of 32 bits.

Collision backoff and retransmission method(Truncated Binary Exponential BackoffAlgorithm, BEBA):
n : number of collisions experienced (n <= 16)
k : Min (n,10) -- Truncation
r : Random delay time (unit: slot time), 0 <= r < 2k

Slot time = 51.2 us

Disadvantage of BEBA:
Last-in-First-out effect: Stations with no or few collisions will have a better chance to transmit before stations that have waited longer.

转载于:https://www.cnblogs.com/jianxinzhou/p/4007941.html

你可能感兴趣的:(IEEE 802.3 Ethernet)