remove dpdk_nic_bind.py dependency 99/38599/3
authorYulong Pei <yulong.pei@intel.com>
Fri, 31 Mar 2023 09:50:17 +0000 (09:50 +0000)
committerPeter Mikus <peter.mikus@protonmail.ch>
Mon, 3 Apr 2023 06:31:03 +0000 (06:31 +0000)
dpdk_nic_bind.py from <trex>/scripts/ is out of date, often bumped into
errors when using it to bind nic port, e.g.

/usr/bin/python3 dpdk_nic_bind.py --bind=vfio-pci 0000:ca:00.0
/opt/trex-core-3.00/scripts/dpdk_nic_bind.py:40: DeprecationWarning:
The distutils package is deprecated and slated for removal in Python 3.12.
Use setuptools or check PEP 632 for potential alternatives
  from distutils.util import strtobool
Error: bind failed for 0000:ca:00.0 - Cannot bind to driver vfio-pci

so remove dpdk_nic_bind.py dependency in csit.

Signed-off-by: Yulong Pei <yulong.pei@intel.com>
Change-Id: I5a3f641cd77d339aa7a213f410ce2efe7c322b8a
Signed-off-by: Yulong Pei <yulong.pei@intel.com>
resources/libraries/python/Constants.py
resources/libraries/python/TrafficGenerator.py

index eda94fe..1049e47 100644 (file)
@@ -216,6 +216,10 @@ class Constants:
     TREX_EXTRA_CMDLINE = get_str_from_env(
         u"TREX_EXTRA_CMDLINE", u"--mbuf-factor 32")
 
+    # TRex port driver default vfio-pci or set to igb_uio
+    TREX_PORT_DRIVER = get_str_from_env(
+        u"TREX_PORT_DRIVER", u"vfio-pci")
+
     # Graph node variant value
     GRAPH_NODE_VARIANT = get_str_from_env(u"GRAPH_NODE_VARIANT", u"")
 
index 2a28896..2e03b4b 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2022 Cisco and/or its affiliates.
+# Copyright (c) 2023 Cisco and/or its affiliates.
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at:
@@ -31,6 +31,7 @@ from .ssh import exec_cmd_no_error, exec_cmd
 from .topology import NodeType
 from .topology import NodeSubTypeTG
 from .topology import Topology
+from .DUTSetup import DUTSetup as DS
 
 __all__ = [u"TGDropRateSearchImpl", u"TrafficGenerator", u"OptimizedSearch"]
 
@@ -424,36 +425,26 @@ class TrafficGenerator(AbstractMeasurer):
                 )
 
                 # Prepare interfaces for TRex.
-                mlx_ports = u""
+                tg_port_drv = Constants.TREX_PORT_DRIVER
                 mlx_driver = u""
-                itl_ports = u""
                 for port in tg_node[u"interfaces"].values():
                     if u"Mellanox" in port.get(u"model"):
-                        mlx_ports += f" {port.get(u'pci_address')}"
                         mlx_driver = port.get(u"driver")
-                    if u"Intel" in port.get(u"model"):
-                        itl_ports += f" {port.get(u'pci_address')}"
-
-                if itl_ports:
-                    cmd = (
-                        f"sh -c \"cd {Constants.TREX_INSTALL_DIR}/scripts/ && ",
-                        f"./dpdk_nic_bind.py -u {itl_ports} || ",
-                        f"true\""
-                    )
-                    exec_cmd_no_error(
-                        tg_node, cmd, sudo=True,
-                        message=u"Unbind PCI ports from driver failed!"
-                    )
-                if mlx_ports:
-                    cmd = (
-                        f"sh -c \"cd {Constants.TREX_INSTALL_DIR}/scripts/ && ",
-                        f"./dpdk_nic_bind.py -b {mlx_driver} {mlx_ports} || ",
-                        f"true\""
-                    )
-                    exec_cmd_no_error(
-                        tg_node, cmd, sudo=True,
-                        message=u"Bind PCI ports from driver failed!"
-                    )
+                        pci_addr = port.get(u'pci_address')
+                        cur_driver = DS.get_pci_dev_driver(tg_node, pci_addr)
+                        if cur_driver == mlx_driver:
+                            pass
+                        elif not cur_driver:
+                            DS.pci_driver_bind(tg_node, pci_addr, mlx_driver)
+                        else:
+                            DS.pci_driver_unbind(tg_node, pci_addr)
+                            DS.pci_driver_bind(tg_node, pci_addr, mlx_driver)
+                    else:
+                        pci_addr = port.get(u'pci_address')
+                        cur_driver = DS.get_pci_dev_driver(tg_node, pci_addr)
+                        if cur_driver:
+                            DS.pci_driver_unbind(tg_node, pci_addr)
+                        DS.pci_driver_bind(tg_node, pci_addr, tg_port_drv)
 
                 # Start TRex.
                 cd_cmd = f"cd '{Constants.TREX_INSTALL_DIR}/scripts/'"