5.数据链路层
链路层的特点和功能
data-link layer has responsibility of transferring datagram from one node to physically adjacent node over a link
结点(node)和链路(link)的定义
two types of “links”:
- point-to-point
- broadcast (shared wire or medium)
奇偶校验
循环冗余校验
校验和
求下面三组数据的校验和:
首先将三组数据求和,如果最高位溢出则还要在结果上加1
0110011001100000
0101010101010101
1000111100001100
The sum of first two of these 16-bit words is
0110011001100000
0101010101010101
1011101110110101
Adding the third word to the above sum gives
1011101110110101
1000111100001100
0100101011000010
最后求反码
1011010100111101
At the receiver, all four 16-bit words are added,
including the checksum. If no errors are introduced into the packet, then clearly the
sum at the receiver will be 1111111111111111.
CSMA CSMA/CD 指数回退
用于以太网上多点接入技术
CSMA (carrier sense multiple access) :
每个站在发送数据之前,先检测信道是否空闲,空闲则发送数据,不空闲则等待放弃碰撞的传输,减少信道浪费。
CSMA/CD (collision detection) :
如果碰撞,使用二进制指数退避算法等待一段时间在发送,在短时间内检测到碰撞。
CSMA/CD 碰撞检测图:
二进制指数回退法:
Let’s look at an example. Suppose that a node attempts to transmit a frame for the first time and while transmitting it detects a collision. The node then chooses K 0 with probability 0.5 or chooses K 1 with probability 0.5. If the node chooses K0, then it immediately begins sensing the channel. If the node chooses K 1, it waits 512 bit times (e.g., 0.01 microseconds for a 100 Mbps Ethernet) before beginning
the sense-and-transmit-when-idle cycle. After a second collision, K is chosen with equal probability from {0,1,2,3}. After three collisions, K is chosen with equal probability from {0,1,2,3,4,5,6,7}. After 10 or more collisions, K is chosen with equal probability from {0,1,2, . . . , 1023}. Thus, the size of the sets from which K is chosen grows exponentially with the number of collisions; for this reason this algorithm is referred to as binary exponential backoff.
MAC地址 ARP
32-bit IP地址:
网络层地址
用于使数据报到达目的IP子网
MAC地址:
48 bit,用于使数据报从一个接口到达另一个物理连接的接口。
ARP: 地址解析协议:
- ARP为在同一个子网上的主机和路由器接口解析IP地址
- LAN上的每个IP节点(主机、路由器)都有ARP表
- ARP表: 对某些LAN节点的IP/MAC地址映射
- TTL (寿命): 地址映射将被忘记的时间长度(通常20分钟)
- ARP的查询报文是在广播帧中发送的,即发送给(FF-FF-FF-FF-FF-FF)
- ARP协议不需要管理员配制
- 将数据报发送到子网外时,帧中储存的MAC地址为下一跳路由器的地址
以太网
以太网是无连接不可靠的,MAC协议为unslotted CSMA/CD wth binary backoff
以太网帧结构:
前导码:
前同步码一共有8个字节,前7个字节都是10101010 ,第8个字节是10101011,用于同步接收方,发送方时钟速率。地址: 6字节
如果适配器接收具有匹配的目的地址或广播地址(如ARP分组)的帧, 它将帧中的数据提交给网络层协议否则, 适配器丢弃帧。类型: 指示较高层协议 (大多数为IP但也可以支持其他类型如 Novell IPX和AppleTalk)。
CRC: 在接收方核对,如果检测到差错,该帧就被丢弃。
交换机原理
交换机表:
- 交换机是不需要管理员配制的(自学习、一段固定时间后无信号则丢弃某表项)
- 交换机可以消除碰撞、隔离不同的物理链路