获取 USB 以太网的链接速度

获取 USB 以太网的链接速度

如何获取USB以太网的链路速度?

$ sudo ethtool enp0s20u2c2
Settings for enp0s20u2c2:
    Current message level: 0x00000007 (7)
                           drv probe link
    Link detected: yes

$ sudo mii-tool enp0s20u2c2
SIOCGMIIPHY on 'enp0s20u2c2' failed: Operation not supported

$ ifconfig
enp0s20u2c2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 10.0.0.6  netmask 255.0.0.0  broadcast 10.255.255.255
    inet6 fe80::f6f2:6dff:fe18:fb0b  prefixlen 64  scopeid 0x20<link>
    ether f4:f2:6d:18:fb:0b  txqueuelen 1000  (Ethernet)
    RX packets 91635  bytes 108661674 (103.6 MiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 82066  bytes 20398670 (19.4 MiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp3s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
    ether 8c:89:a5:0e:da:e2  txqueuelen 1000  (Ethernet)
    RX packets 274813965  bytes 281606620432 (262.2 GiB)
    RX errors 2  dropped 0  overruns 0  frame 2
    TX packets 307772449  bytes 202115845888 (188.2 GiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    device interrupt 18

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
    inet 127.0.0.1  netmask 255.0.0.0
    inet6 ::1  prefixlen 128  scopeid 0x10<host>
    loop  txqueuelen 1  (Local Loopback)
    RX packets 4778773  bytes 1711054659 (1.5 GiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 4778773  bytes 1711054659 (1.5 GiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp4s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
    ether 70:18:8b:82:51:79  txqueuelen 1000  (Ethernet)
    RX packets 171104  bytes 101660534 (96.9 MiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 140287  bytes 59377507 (56.6 MiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

有关的dmesg

[1281750.433715] usb 3-2: new high-speed USB device number 24 using xhci_hcd
[1281751.213885] cdc_ether 3-2:2.0 eth0: register 'cdc_ether' at usb-0000:00:14.0-2, CDC Ethernet Device, f4:f2:6d:18:fb:0b
[1281751.213910] usbcore: registered new interface driver cdc_ether
[1281751.348703] cdc_ether 3-2:2.0 enp0s20u2c2: renamed from eth0
[1281751.705115] IPv6: ADDRCONF(NETDEV_UP): enp0s20u2c2: link is not ready
[1281751.705235] cdc_ether 3-2:2.0 enp0s20u2c2: kevent 12 may have been dropped
[1281751.705241] cdc_ether 3-2:2.0 enp0s20u2c2: kevent 12 may have been dropped
[1281751.706719] cdc_ether 3-2:2.0 enp0s20u2c2: kevent 12 may have been dropped
[1281751.706925] cdc_ether 3-2:2.0 enp0s20u2c2: kevent 12 may have been dropped
[1281751.706934] cdc_ether 3-2:2.0 enp0s20u2c2: kevent 12 may have been dropped
[1281761.835095] cdc_ether 3-2:2.0 enp0s20u2c2: kevent 12 may have been dropped
[1281761.835106] cdc_ether 3-2:2.0 enp0s20u2c2: kevent 12 may have been dropped
[1281761.960577] cdc_ether 3-2:2.0 enp0s20u2c2: kevent 12 may have been dropped
[1281761.960593] cdc_ether 3-2:2.0 enp0s20u2c2: kevent 12 may have been dropped

我使用的是 64 位 archlinux。

答案1

我将从源代码编译 ethtool 并针对您的内核重新编译 cdc_ether 和 usbnet。

来自 David Brownell(cdc_ether 的作者)

http://www.linux-usb.org/usbnet/

以太网工具

使用 ethtool 版本 1.5 或更高版本以及足够新的 usbnet 驱动程序版本,您可以从驱动程序获取其他信息。不同的设备可能有不同的可用信息;例如,链接可用性并不总是已知的。 Linux 为“消息级别”位定义了一些标准解释,这些位并未广泛使用……但该框架将它们用于其所有设备,让您可以屏蔽将看到哪些消息。 (除非启用调试,否则许多消息将不可用。)

sh# ethtool usb0
Settings for usb0:
    Current message level: 0x00000001 (1)
sh# ethtool -i usb0
driver: usbnet
version: 17-Jul-2002
firmware-version: Prolific PL-2301/PL-2302
bus-info: usb-00:02.0-1.2
sh#
sh# ethtool usb1
Settings for usb1:
    Current message level: 0x00000001 (1)
    Link detected: no
sh# ethtool -i usb1
driver: usbnet
version: 17-Jul-2002
firmware-version: NetChip TurboCONNECT
bus-info: usb-00:02.0-1.4
sh#

如果您的路由配置需要的话,您可能希望使用稳定的总线信息值来确定要分配给给定链路的网络地址。您可以使用 ip link set usbN name newname 或类似工具。 (注意:不幸的是,nameif 工具在这里没有帮助,因为它假设以太网地址可以解决这个问题。对于动态分配的以太网地址,这是行不通的;使用“bus-info”是合适的解决方案。)

也可以看看https://hewlettpackard.github.io/wireless-tools/HOTPLUG.txt关于处理此类热插拔问题,主要是 Debian 和无线。)

相关内容