Computer Network study notes: Chapter III data link layer.

This article is a "computer network" self-study courses, video address: https://www.bilibili.com/video/av47486689. Only do individuals learn to use, if infringement, please contact deleted


Chapter 3: Data link layer

Outline

1571750803453
The basic concept of the data link layer:

1571750903151

Data transmission model

1571750953092
From the point of view of the level of flow data

Router checks to see whether the data link layer to their own, and if so decided to take a look at the network layer which port sent out. Then the data link layer to reseal transmitted bitstream.

In this chapter we look at the data link layer

Channel model data link layer

1571751256660

Link data link

1571751307320
It refers to a physical link lines

1571751313589
NIC + = Link Data Link

frame

The data link layer is a frame transmission

1571751385667
The data link layer plus start and end, into the physical layer for transmission. Data link layer to the other nodes then start and end removed

The data link layer as a data conduit

1571751432740

Three basic problems to be solved

1571751469352

Framing package

1571751525950
MTU: Maximum Transmission Unit, not exceed 1500 bytes in Ethernet

If the receiving terminal does not receive the character start or end character frame, this frame will be discarded because it is not a complete frame.

Transparent transmission

1571751717125
If the data is not transmitted only when the composition (often occurs when transferring binary files) from the "printable characters", there will be a problem

Solution: Escape

1571751862960
Finally, data processing, then we need to be removed

Error Control

1571751962360
Error determination method:

1571752017421
Calculated as follows:

1571752043718

  1. Was added n-bit 0

  2. In addition to a (n + 1) bits, the random number is selected from

  3. Do die two division (every XOR operation, note that this is not binary division!)

  4. The last delivery is: the original data + remainder

  5. Then this number with the recipient to do the divisions of the (n + 1) bits after receipt, if the remainder is 0, it means no error data. If it is not 0, there is an error in the process of transmission, it is thrown away.

    And the divisor is the number of bits in the data link layer of the network card out of his own consultations

Here is a more detailed description of this method:

Source: https://colobu.com/2014/10/22/CRC-introduction/

CRC为校验和的一种,是两个字节数据流采用二进制除法(没有借位和进位,使用异或来代替减法)相除所得到的余数。其中被除数是需要计算校验和的信息数据流的二进制表示;除数是一个长度为(n+1)的预定义二进制数,通常用多项式的系数来表示。在做除法之前,要在信息数据之后先加上n个0. 冗余码的位数是n位。
冗余码的计算方法是,先将信息码后面补0,补0的个数是生成多项式最高次幂;将补零之后的信息码用模二除法(非二进制除法)除以G(X)对应的2进制码,注意除法过程中所用的减法是模2减法,即没有借位的减法,也就是异或运算。当被除数逐位除完时,得到比除数少一位的余数。此余数即为冗余位,将其添加在信息位后便构成CRC码字。

例如,假设信息码字为11100011,生成多项式G(X)=X^5+X^4+X+1,计算CRC码字。G(X) = X^5+X^4+X+1,也就是110011,因为最高次是5,所以,在信息码字后补5个0,变为1110001100000。用1110001100000模二除法除以110011,余数为11010,即为所求的冗余位。
因此发送出去的CRC码字为原始码字11100011末尾加上冗余位11010,即 1110001111010。接收端收到码字后,采用同样的方法验证,即将收到的码字用模二除法除以110011(是G(X)对应的二进制生成码),发现余数是0,则认为码字在传输过程中没有出错。

尽管在错误检测中非常有用,CRC并不能可靠地校验数据完整性(即数据没有发生任何变化),这是因为CRC多项式是线性结构,可以非常容易地故意改变量据而维持CRC不变。

对于有错误的帧,直接丢掉:

1571756400602
CRC只是FCS的方法之一

image-20191103135810714
接受终端会要求传输终端再重新传一遍数据包,也就是“重传”这一行为的请求是由上层的应用程序发起的

用余数判断是有概率失败的,因为比特正确不代表数据正确。但是信息码越长,判断错误的概率越小

PPP协议(点到点协议)

1571756707439
PPP协议有身份验证的功能,有账号密码,记账,家庭宽带一般就是这种

1571756912434
1571756923640
可以看到PPP协议满足了我们上面所说的三个基本问题

PPP协议可以承载多种应用层协议(TCP/IP等)

多种类型链路指的是无论是光纤、同轴电缆、双绞线等等都可以用

检测连接状态:可以汇报多种状态(常见的就是我们电脑拨号上网时如何有错,返回的状态码)

数据压缩协商:在传输之前就在数据链路层压缩数据

PPP协议的组成

1571757246599
PPP协议细分可以分为以下几部分:

链路控制协议负责身份验证

PPP协议的帧格式

1571757382722
7E开始,7E结束

FF:目标地址,但是在点对点传输中没什么用,所以就写死为FF了

C:C部分也写死为03了,也不起什么作用

FCS:帧检验序列,也包括在PPP协议传输的数据中了

协议部分:标识信息部分的类型是什么

1571757527142
特殊字符处理:

1571757653223
注意,根据第一条拆分产生的7D不需要再根据第二条再拆分了

但如果传输的是比特流而不是字节怎么办?

1571757804721
如果有连续五个1,就立即填入一个0,接受端接受后再将0删除,这样做是为了避免信息出现和表示开始和结束的7E

1571757889953
1571757906132
PPP不使用序号和确认机制:

1571758036637

PPP协议的工作状态

1571758133313
1571758381897

PPP封装的实际使用

家用宽带的带宽是通过时钟频率控制的,定义了时钟频率就定义了发信息的速度

1571758720359
路由器的口。最右面两个是以太网口,中间两个是广域网口,左面两个是光纤接口

下面是设计的网络:

1571758807631
1571759042503
将左一的路由器协议改成PPP,中间的路由器还是使用默认的协议HDLC,这时候两个路由器之间就ping不通了,因为协议不一样了。但是依然显示的是绿灯,因为绿灯只能表示物理层没问题,数据链路层是否正确不能表示。

1571759770315
IPCP和CDPCP都是OPEN的,体现了PPP协议可以支撑多个网络层协议

以太网(广播信道)

1571760137947
总线型的网两端有电阻,用来吸收信号,不能让信号再反射回来

现在的局域网基本上都是星型结构的

局域网

局域网覆盖范围和终端设备数量有限,但是带宽有保证。

广域网是花钱租用别人的线路和带宽,例如家庭宽带,公网ip都是动态的,是ISP从ip池找到的,断线重连Ip也会变,甚至这个ip还会和小区邻居共享

1571760577705
例如我们连接在同一个无线路由器下的设备就都是在一个局域网中了,可以使用内网ip相互通信

1571761153070
要为局域网中的设备划分信道(因为来去只有一路)

现在主要用动态媒体接入控制的随机接入,不用静态划分信道的方式了

认识以太网

传统的线性结构

1571761432120
优点:简单,不需要划分信道

缺点:同时只能有一个会话;安全性不好,容易被抓包

以太网(广播信道)的协议:CSMA/CD

1571761636492
1571761963905
碰撞是怎么发生的呢?

1571762125246
在A给B发送数据、但是还没有到的时候,B就给A发送数据了,这样就会造成冲突,会造成信号叠加。等到A和B收到信号时就能发现产生了冲突

载波监听和碰撞检测一起作用,用来减小冲突的影响

1571762455041
过了争用期,才能确定没有发生冲突,信息被完整地传递了

通常取51.2μs为争用期长度(因为网线的最大距离是有限的,所以可以估计)

所以在发送数据的时候,如果前64个字节没有冲突,那么后面就一定没有冲突了。

规定最短的有效帧长度为64字节,小于这个数字的都视为无效帧,因为小于这个长度就没办法检测冲突了。如果发送的数据量小于64字节,计算机会加0补上

  • 二进制指数类型退避算法

    这个算法是由CSMA/CD协议实现的,和用户没关系

    它是用来设计发生冲突时推迟时间的

1571762727787
基本退避时间设为争用期,这是保证时间至少够一方传输完的

也就是说,重传次数越多,两台计算机选择的重传范围也就越大,碰撞的概率就越小

这里为什么这么纠结,就是因为冲突的两房没办法通信来协商如何传输、谁先谁后,只能使用这种随机的方法、希望可能相互避开

总结:

1571762357598

  • 使用CSMA/CD协议的以太网不能全双工,只能半双工
  • 冲突主要发生在每个站发送数据的一小段时间内

这种以太网的通信效率太低了

以太局域网

1571763126779
数据链路层的两个子层:

现在一般简化不谈LLC协议了

1571763141008
1571763204200
这也是刚才二进制指数类型退避算法谈到的

对丢失数据的校验是由两端的计算机的高层实现的,中间的设备不管,中间只管扔掉有问题的帧

星型拓扑

1571763364333
集线器现在已经很少见了

集线器

集线器的示意图:

1571763411363
一个设备发送数据,所有设备都能收到

1571763639344
注意,集线器是工作在物理层的!它其实就是网线的plus版,没有任何智能性的活动,就是对网线的简单模拟而已!


以太局域网的分类:

1571763748453

以太网的信道利用率

1571763884894
发送一帧的平均时间:

1571763935910
注意,不要忘了最后有τ时间用来恢复信道,T0+τ是开始发送+传输+接受完成的完整时间

1571764132840
为了最大化信道利用率,也就是最小化a:

1571764196084
理论信道利用率=发送时间/(发送时间+传输时间)

以太网MAC地址

每个网卡有全球唯一的MAC地址,计算机上有几个网卡就有几个MAC地址

1571764360430
网卡可以收到怎样的数据帧?

1571764493291
MAC地址冲突:一般是由于有人不使用网卡的MAC地址,而是修改了传输时候的MAC地址造成的,会造成网络问题、连不通

image-20191103142343825
广播时候MAC地址是全1(用十六进制表示就是FFFFFFFFFFFF)的,所有设备收到这样的数据都接收处理

MAC帧格式

image-20191103142616638
image-20191103142630559
目标MAC地址和源MAC地址都占6个字节(注意上面那一行,其实就和我们上面说的PPP协议的帧格式很像,但是目标地址和原地址、FCS的长度不一样。下面再把PPP的帧格式拿出来对比下:)

1571757889953
PPP协议的帧格式

以太网要求数据帧最小为64字节,目标地址、原地址、类型和FCS就占了18个字节,所以信息部分最小是46字节,最大是1500字节

为什么MAC帧的信息部分最长1500字节?

来源:https://zhuanlan.zhihu.com/p/21318925

以太网帧:Ethernet Frame

标准的以太网帧,我们经常说的以太网帧长度是从图中 Destination MAC开始,FCS结束。网卡对网络层数据的操作是加以太网帧头、以太网帧尾FCS,很显然上层需要提供目的MAC地址,否则接口无从完成以太网帧的封装。这需要IP层需要事先完成和ARP的交互,解析出目的IP对应的目的MAC,这显然不能由网卡来完成。

网卡对物理层接收到的二进制流成帧处理,校验FCS,去掉以太网帧头,把载荷Payload 放在接收缓存,等待网络层取走。

img

标准的以太网帧最大可以发送长度1518字节,指的就是这个。去掉以太网头14个字节,再去掉尾部的校验和FCS 4个字节,留给上层协议也就是(1518-14-4)=1500个字节,这个就是MTU的由来。上层协议加黑的原因是要引起大家的注意,这个上层协议如果是IP,那么就是IP MTU,如果是MPLS,就是MPLS MTU,如果是IPv6,那就是IPv6 MTU。

MAC帧没有结束字符:以太网使用曼彻斯特编码,看的是数据变化而不是值,只需要头部即可,只要没有数据传输了就是结束了。:

1571738413171
曼彻斯特编码

抓包实验

用抓包工具可以排除网络故障,这里用的是Ethereal

案例分析1

这里的案例是局域网中一台电脑不断发广播包来询问其他设备的MAC地址,使得占满了局域网,最后发现是104设备有病毒,会不断发广播包,病毒占满设备内存的时候就重启,网络就通一会,不重启的时候网络就中断:

image-20191103144121090

案例分析2

image-20191103144805414
抓包工具将传输的数据(未加密)抓出来了

无效的MAC帧

image-20191103145706761

帧间最小间隔

image-20191103145750914

扩展以太网

在物理层考虑

扩展以太网的最大长度:

image-20191103145913847
扩展设备数量:

image-20191103150029617
将集线器连起来就可以跨局域网访问:

image-20191103150115453
大的冲突域效率其实是降低的:用集线器连接的网络不宜超过30台机器,否则效率就太低了

image-20191103150303026

在数据链路层考虑

集线器表现不佳,网桥出现了

image-20191103150333070
image-20191103150347388
当发现表上没有记录的未知设备时对所有端口发送广播,当发现在表上时,如果源地址和目标地址都在网桥的同一个端口上,那么数据包就不会发往其他端口;只有在不同的端口时才会往不同端口发数据包——网桥隔断冲突域

网桥只会从数据包的来源记录设备所在的端口,不会根据目标做记录

image-20191103151314841
image-20191103150914985
例如上图,B1左侧的端口对应A和B的MAC地址,而右侧对应的是C、D、E、F四台设备的MAC地址

image-20191103151011335

拓展:广播风暴

来源:https://www.zhihu.com/question/51715471

image-20191103152304763>
image-20191103152314085>
image-20191103152323211>
image-20191103152332605

透明网桥

image-20191103151222495
透明网桥不影响计算机通信

透明网桥使用了生成树算法,以避免环的产生:

image-20191103154303526
生成树上每一个节点都有一个优先级,默认优先级都一样

选择一个交换机做树根(一般是优先级数值小或者MAC地址小的),和树根相连的设备的、离更最近的端口叫根端口

再根据带宽选择指定端口(比较复杂),没选上的就是非指定端口,就不再使用了。这样就能去掉原有的环状结构。

在交换机开机时都要生成这样的树才能判断哪些端口是在使用中的

交换机

交换机其实就是高速的网桥。上面说的网桥一般是和集线器相连的,但如果用网桥直接和设备连接,其实就是交换机。交换机可以使得设备之间两两建立数据链路,将冲突域控制在了最小范围,也防止了被抓包(设备之间两两通信,其他设备不参与,得不到数据包)

交换机的端口有“排队”机制,如果一个端口正在发送数据,其他的数据包先排队等候

交换机说的带宽值得是单个端口的交换带宽,总的带宽是单个端口带宽*端口数(带宽独享),这样就大大提高了最大带宽

虚拟局域网

image-20191103160914080
使用虚拟局域网(VLAN)的原因:

image-20191103161055346
原本按物理位置划分网段,一个交换机对应一个网段,但是现在由于业务需要,要跨网段组建新的网段,所以就要用到虚拟局域网。

这种虽然不是课程的重点,但是其实是实际生产中用到的最多的情况。

从最简单的角度去理解:

image-20191103195653007
Corresponding to each of the plurality of switch into direct communication can not (can not see each other directly shared resources), the collision domain becomes small again

Note that this is the switch has the function, no additional hardware.

You can see, by default, all ports are in a vlan inside

image-20191103200055936
Create a new port and placed in a new vlan vlan:

image-20191103200223394
After that, and then put together to form between vlan switch:

image-20191103200443227
But in fact, even with a line between the switches can be up, a line may run data (trunk interface) to a plurality vlan, add to the packet a marker can be done - this is the statistical time division multiplexing when the label is added in the original data packet, the transmission destination device to the flag has been removed:

image-20191103201153917
ISL is a Cisco technology used

image-20191103200629363

Fast Ethernet

image-20191103201309822
100BASE-T does not use CDMA / CD protocol : there is a conflict on the line in the switch. But the frame format is the same. ** interframe time interval 10 times smaller *

image-20191103201405507
If the rate of two devices to communicate is not the same, there is no way communication, although this time the display is connected. It is generally set to automatically detect

image-20191103201647485
image-20191103201801560
"Fast to the desktop and to gigabit backbone"

LAN network building three-tier model

image-20191103201935171
Convergence layer traffic to be aggregated building

case analysis

image-20191103202441791
He has told an interesting case: enterprise network equipment upgrade, but the actual use of gigabit switches only megabytes, and finally found the old optical fiber does not support Gigabit auto-negotiation to a hundred. The solution is to re-fiber cloth. "Originally, the project data link layer, and finally do the physical layer" - apply their knowledge.

Data security on the switch

We can achieve on the switch:

  1. Only specific MAC addresses access port device
  2. Devices only allow a certain number of access ports

This is called the "data link layer security"

Guess you like

Origin www.cnblogs.com/jiading/p/11808290.html