Linux: network: 拔插网线 interface down/up测试的痛点
文章目录
- 测试的痛点
- 网线虚插
- 频繁的拔插日志
- 从插入网线到link变成up的状态,需要~7秒的时间
测试的痛点
外企做测试的一个痛点是,设备不在国内,如果想做破坏性的测试,就需要让外国同事帮着做这种拔插网线类的操作。很麻烦,万一碰到问题,就要麻烦他来来回回的去实验室。外国人休假还那么长时间,一休休一个月。
网线虚插
最近做的这个操作,发现下面这样的日志,看着就有理由,猜想这个同事做的拔插网线有点问题。
Oct 9 11:51:24 p-b kernel: [ 2381.633072] mlx5_core 0000:00:08.0: Port module event: module 1, Cable unplugged
Oct 9 11:51:25 p-b kernel: [ 2381.666406] mlx5_core 0000:00:08.0 pr1: Link down
Oct 9 11:51:34 p-b kernel: [ 2390.838359] mlx5_core 0000:00:08.0: Port module event: module 1, Cable plugged
Oct 9 11:51:34 p-b kernel: [ 2391.434150] mlx5_core 0000:00:08.0: Port module event: module 1, Cable unplugged
Oct 9 11:51:39 p-b kernel: [ 2396.388908] mlx5_core 0000:00:08.0: Port module event: module 1, Cable plugged
Oct 9 11:51:44 p-b kernel: [ 2401.082159] mlx5_core 0000:00:08.0: Port module event: module 1, Cable unplugged
Oct 9 11:51:49 p-b kernel: [ 2405.739985] mlx5_core 0000:00:08.0: Port module event: module 1, Cable plugged
Oct 9 11:51:50 p-b kernel: [ 2406.998658] mlx5_core 0000:00:08.0: Port module event: module 1, Cable unplugged
Oct 9 11:52:06 p-b kernel: [ 2422.691875] mlx5_core 0000:00:08.0: Port module event: module 1, Cable plugged
Oct 9 11:52:06 p-b kernel: [ 2422.725911] mlx5_core 0000:00:08.0: Port module event: module 1, Cable unplugged
Oct 9 11:52:10 p-b kernel: [ 2427.292388] mlx5_core 0000:00:08.0: Port module event: module 1, Cable plugged
Oct 9 11:52:12 p-b kernel: [ 2429.572874] mlx5_core 0000:00:08.0: Port module event: module 1, Cable unplugged
Oct 9 11:52:17 p-b kernel: [ 2434.343169] mlx5_core 0000:00:08.0: Port module event: module 1, Cable plugged
Oct 9 11:52:29 p-b kernel: [ 2446.635359] mlx5_core 0000:00:08.0 pr1: Link up
Oct 9 11:52:30 p-b kernel: [ 2446.673528] mlx5_core 0000:00:08.0 pr1: Link down
Oct 9 11:52:35 p-b kernel: [ 2452.381350] mlx5_core 0000:00:08.0: Port module event: module 1, Cable unplugged
Oct 9 11:52:39 p-b kernel: [ 2455.945684] mlx5_core 0000:00:08.0: Port module event: module 1, Cable plugged
Oct 9 11:52:42 p-b kernel: [ 2459.294453] mlx5_core 0000:00:08.0: Port module event: module 1, Cable unplugged
Oct 9 11:54:24 p-b kernel: [ 2561.557582] mlx5_core 0000:00:08.0: Port module event: module 1, Cable plugged
Oct 9 11:54:30 p-b kernel: [ 2567.188845] mlx5_core 0000:00:08.0 pr1: Link up
Oct 9 11:57:05 p-b kernel: [ 2721.922978] mlx5_core 0000:00:08.0: Port module event: module 1, Cable unplugged
Oct 9 11:57:05 p-b kernel: [ 2721.954832] mlx5_core 0000:00:08.0 pr1: Link down
Oct 9 11:57:08 p-b kernel: [ 2724.976145] mlx5_core 0000:00:08.0: Port module event: module 1, Cable plugged
Oct 9 11:57:15 p-b kernel: [ 2731.956035] mlx5_core 0000:00:08.0 pr1: Link up
从这个日志可以发现
频繁的拔插日志
这个的原因猜测是没有真正拔下来,而是网口处在一个虚插的状态。才导致频繁的unplugged/plugged。
从插入网线到link变成up的状态,需要~7秒的时间
从这里也可以看懂从插入网线到link变成up的状态,需要~7秒的时间。
这种延迟是正常的,主要原因包括:
物理层协商 (Physical Layer Negotiation):
自协商 (Auto-negotiation): 网卡和交换机端口需要协商最佳的连接速度(如1Gbps、10Gbps等)和双工模式(全双工)。这个过程需要交换数据包并达成一致。
链路训练 (Link Training): 对于高速网络接口(如10Gbps及以上),物理层需要进行更复杂的“链路训练”过程,以调整信号强度、均衡和时钟恢复,确保建立稳定的物理连接。这可能需要几秒钟。
模块初始化 (Module Initialization): 如果使用的是可插拔的光模块(如SFP/QSFP),模块本身需要时间上电、初始化并稳定工作,然后才能开始链路协商。日志中的“Port module event”表明涉及到了模块。
驱动程序处理 (Driver Processing): 网卡驱动程序在检测到物理连接后,还需要进行一些内部配置和初始化,才能将链路状态报告为“up”。
这些步骤都需要一定的时间来完成,因此从物理插入到逻辑链路“up”之间存在几秒钟的延迟是预期行为。