-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathdpdk_resource.py
More file actions
executable file
·88 lines (72 loc) · 2.48 KB
/
dpdk_resource.py
File metadata and controls
executable file
·88 lines (72 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
# This file is part of Checkbox.
#
# Copyright 2025 Canonical Ltd.
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# Checkbox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
import socket
from collections import defaultdict
from pathlib import Path
from typing import List, Dict
# Dictionary with supported DPDK drivers per vendor
DPDK_SUPPORTED_DRIVERS = {
"Nvidia": ["mlx4_core", "mlx5_core"],
"Intel": [
"cpfl",
"e1000",
"fm10k",
"i40e",
"ice",
"idpf",
"ifc",
"igc",
"ipn3ke",
"ixgbe",
],
"Broadcom": ["bnxt"],
}
def get_dpdk_supported_drivers() -> Dict[str, List[str]]:
"""Get a list of DPDK supported drivers available from network adapters.
:return: dpdk supported drivers and interfaces using them
"""
dpdk_drivers = defaultdict(list)
# Get all network interfaces
interfaces = socket.if_nameindex()
# Iterate over interfaces to get dpdk supported drivers if any
for _, iface in interfaces:
device_path = Path("/sys/class/net/{}/device/driver".format(iface))
if device_path.exists() and device_path.is_symlink():
driver_name = device_path.resolve().name
if any(
driver_name in drivers
for drivers in DPDK_SUPPORTED_DRIVERS.values()
):
dpdk_drivers[driver_name].append(iface)
return dpdk_drivers
def print_drivers(drivers: Dict[str, List[str]]):
"""Display DPDK supported drivers information
:param drivers: DPDK supported drivers and interfaces using them
"""
for driver, interfaces in drivers.items():
print("name: {}".format(driver))
print("interfaces: {}".format(" ".join(iface for iface in interfaces)))
print()
def main():
supported_drivers = get_dpdk_supported_drivers()
if supported_drivers:
print("dpdk_supported: yes\n")
print_drivers(supported_drivers)
else:
print("dpdk_supported: no\n")
if __name__ == "__main__":
main()