feat(bisect): introduce scripts for VPP bisecting
[csit.git] / resources / libraries / python / InterfaceUtil.py
index 7e645d1..c62592e 100644 (file)
 
 """Interface util library."""
 
+from json import loads
 from time import sleep
 from enum import IntEnum
 
 from ipaddress import ip_address
 from robot.api import logger
+from robot.libraries.BuiltIn import BuiltIn
 
 from resources.libraries.python.Constants import Constants
 from resources.libraries.python.DUTSetup import DUTSetup
 from resources.libraries.python.IPAddress import IPAddress
 from resources.libraries.python.L2Util import L2Util
 from resources.libraries.python.PapiExecutor import PapiSocketExecutor
-from resources.libraries.python.parsers.JsonParser import JsonParser
 from resources.libraries.python.ssh import SSH, exec_cmd, exec_cmd_no_error
 from resources.libraries.python.topology import NodeType, Topology
 from resources.libraries.python.VPPUtil import VPPUtil
@@ -358,7 +359,6 @@ class InterfaceUtil:
         :type node: dict
         :type interface: str or int
         :type mtu: int
-        :raises AsserionError: If VPP refused to change the MTU or set if state.
         """
         if isinstance(interface, str):
             sw_if_index = Topology.get_interface_sw_index(node, interface)
@@ -723,9 +723,8 @@ class InterfaceUtil:
         ret_code, stdout, _ = ssh.exec_command(cmd)
         if int(ret_code) != 0:
             raise RuntimeError(u"Get interface name and MAC failed")
-        tmp = u"{" + stdout.rstrip().replace(u"\n", u",") + u"}"
 
-        interfaces = JsonParser().parse_data(tmp)
+        interfaces = loads("{" + stdout.rstrip().replace("\n", ",") + "}")
         for interface in node[u"interfaces"].values():
             name = interfaces.get(interface[u"mac_address"])
             if name is None:
@@ -1851,7 +1850,7 @@ class InterfaceUtil:
             DUTSetup.pci_driver_bind(node, pf_pci_addr, kernel_driver)
 
         # Initialize PCI VFs.
-        DUTSetup.set_sriov_numvfs(node, pf_pci_addr, numvfs)
+        DUTSetup.set_sriov_numvfs(node, pf_pci_addr, numvfs=numvfs)
 
         if not numvfs:
             if osi_layer == u"L2":
@@ -2014,7 +2013,7 @@ class InterfaceUtil:
 
     @staticmethod
     def vpp_round_robin_rx_placement_on_all_duts(
-            nodes, prefix, workers=None):
+            nodes, prefix, use_dp_cores=False):
         """Set Round Robin interface RX placement on worker threads
         on all DUTs.
 
@@ -2025,14 +2024,18 @@ class InterfaceUtil:
 
         :param nodes: Topology nodes.
         :param prefix: Interface name prefix.
-        :param workers: Comma separated worker index numbers intended for
-            dataplane work.
+        :param use_dp_cores: Limit to dataplane cores.
         :type nodes: dict
         :type prefix: str
-        :type workers: str
+        :type use_dp_cores: bool
         """
-        for node in nodes.values():
-            if node[u"type"] == NodeType.DUT:
+        for node_name, node in nodes.items():
+            if node["type"] == NodeType.DUT:
+                workers = None
+                if use_dp_cores:
+                    workers = BuiltIn().get_variable_value(
+                        f"${{{node_name}_cpu_dp}}"
+                    )
                 InterfaceUtil.vpp_round_robin_rx_placement(
                     node, prefix, workers
                 )