date: 2024-03-19
title: 03-Data Link Layer
status: DONE
tags:
- Data-Link-Layer
- NOTE
- Network
- Lec3
author:
- AllenYGY
created: 2024-03-19T10:17
updated: 2024-04-09T11:30
publish: True
Data Link Layer
The data link layer needs to pack bits into frames, so that each frame is distinguishable from another.
Use a field in the header to specify the number of the characters in the frame.
Check Each data frame is correct?
奇偶校验
Append a parity bit to the end of a block of data (e.g., there are d bits in a block).
分为偶数校验和奇数校验
Two-dimensional parity is a generalization of single-bit ParityCheck.png
让我们通过一个具体的例子来说明二维奇偶校验(2D Parity Check)是如何工作的。假设我们有一个由二进制数据组成的3x3矩阵,我们想要通过添加行校验位和列校验位,以及一个额外的校验位来确保数据的完整性。
假设初始数据矩阵如下:
1 0 1
0 1 0
1 1 0
我们的目标是添加校验位,使得每行和每列的总和都是偶数(这里我们选择偶校验作为例子)。
首先,对于每一行,我们计算一个校验位,使得包括校验位在内的每一行的总位数(即1的数量)是偶数。
1 0 1
有两个1,已经是偶数,所以校验位是0
。0 1 0
有一个1,不是偶数,所以校验位是1
。1 1 0
有两个1,已经是偶数,所以校验位是0
。添加行校验位后的矩阵:
1 0 1 | 0
0 1 0 | 1
1 1 0 | 0
然后,对于每一列(包括新添加的行校验位),我们也计算一个校验位,以确保每列的1的数量是偶数。
1 0 1
有两个1,校验位是0
。0 1 1
有两个1,校验位是0
。1 0 0
有一个1,校验位是1
。0 1 0
有一个1,校验位是1
。添加列校验位后的矩阵:
1 0 1 | 0
0 1 0 | 1
1 1 0 | 0
------+---
0 0 1 | 1
最终,我们得到一个包含行校验位和列校验位的矩阵,还有一个右下角的额外校验位,用于整个矩阵的校验:
1 0 1 | 0
0 1 0 | 1
1 1 0 | 0
------+---
0 0 1 | 1
在这个例子中,每行和每列的1的数量都是偶数,包括最后添加的校验位行和校验位列。这样,在数据传输或存储过程中,如果任何单一位发生变化(变成错误),接收方可以通过检查行和列的校验位来发现并确定错误的具体位置。如果只有一位出错,那么错误可以被精确地定位和纠正。然而,如果有多个错误,这种方法可能只能检测到错误存在,而无法精确定位或纠正所有错误。
CRC treats bit streams as representations of polynomials with coefficients of 0 and 1 only.
To compute the checksum for some frame with m bits, corresponding to the polynomial
To detect the error, the receiver divides the checksummed frame by . If there is a remainder, there has been a transmission error.
1 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |
---|---|---|---|---|---|---|---|
0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 |
--- | --- | --- | --- | --- | --- | --- | --- |
1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 |
When transmission, each m-bits sequence is mapped into n-bit codeword. For example,
Data block | Codeword |
---|---|
00 | 00000 |
01 | 00111 |
10 | 11001 |
11 | 11110 |
When the receiver receives an invalid codeword (detects an error), then the valid codeword that is closest to it (minimum hamming distance) is selected.
Design to correct single bit errors.
Consists of two kinds of bits: check-bit and data-bit.
The check-bits are in the positions which are power of 2 (i.e., 1, 2, 4, 8, etc);
The data-bits are in the rest position (3, 5, 6, 7, 9, etc)
Each check bit forces the parity of some collection of bits, including itself, to be even (or odd). 每个检验位对一组特定 位数进行包括其本身 进行奇偶检验
The number of check bits can be obtained by:
c is the number of check bit
d is the number of data bit
Position | 3 | 5 | 6 | 7 | 9 | 10 | 11 | ||||
---|---|---|---|---|---|---|---|---|---|---|---|
Value | 1 | 0 | 0 | 1 | 0 | 0 | 0 |