Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] net_if_stats() returns an incorrect speed value for 100GbE network cards #2096

Merged

Conversation

garrisoncarter
Copy link
Contributor

@garrisoncarter garrisoncarter commented Apr 11, 2022

Summary

Description

Properly handle the speed variable from ethtool.h to support interface speed that are greater than UINT16_MAX. Since ethtool returns the interface speed as two separate uint16_t values, in order to determine the actual interface speed, you must combine and bit-shift the two values.

Testing

All testing done on Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-100-generic x86_64) with Python 3.8.10.

System with 100GbE network interface up (eth2). Confirmed that interfaces that are down show a speed of 0, and the 100GbE interface that is up properly returns 100,000 Mb/s.

>>> import psutil
>>> psutil.net_if_stats()
{'eth1': snicstats(isup=False, duplex=<NicDuplex.NIC_DUPLEX_UNKNOWN: 0>, speed=0, mtu=1500), 'eth0': snicstats(isup=False, duplex=<NicDuplex.NIC_DUPLEX_UNKNOWN: 0>, speed=0, mtu=1500), 'eth2': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=100000, mtu=1500), 'lo': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_UNKNOWN: 0>, speed=0, mtu=65536)}
>>>

System with 10GbE network interface up (eth1)

>>> import psutil
>>> psutil.net_if_stats()
{'lo': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_UNKNOWN: 0>, speed=0, mtu=65536), 'eth0': snicstats(isup=False, duplex=<NicDuplex.NIC_DUPLEX_UNKNOWN: 0>, speed=0, mtu=1500), 'eth1': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=10000, mtu=1500)}
>>>

Signed-off-by: Garrison Carter <garrison.d.carter@gmail.com>
Signed-off-by: Garrison Carter <garrison.d.carter@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Ubuntu 20.04] net_if_stats() returns incorrect interface speed for 100GbE network cards
2 participants