X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FTrafficGenerator.py;h=2a28896e6346d3cc89b8f861a53347fc9c8ef469;hb=d07f6cae7f18c1513650d4cb690115d60201e704;hp=03e389095989018d6566e0e1cd1a341e8eebf139;hpb=1daa6fdc0bae284dee1b61f34534e59b60b7526a;p=csit.git diff --git a/resources/libraries/python/TrafficGenerator.py b/resources/libraries/python/TrafficGenerator.py index 03e3890959..2a28896e63 100644 --- a/resources/libraries/python/TrafficGenerator.py +++ b/resources/libraries/python/TrafficGenerator.py @@ -252,7 +252,38 @@ class TrafficGenerator(AbstractMeasurer): f"{self._node[u'subtype']} not running in {expected_mode} mode!" ) - # TODO: pylint says disable=too-many-locals. + @staticmethod + def get_tg_type(tg_node): + """Log and return the installed traffic generator type. + + :param tg_node: Node from topology file. + :type tg_node: dict + :returns: Traffic generator type string. + :rtype: str + :raises RuntimeError: If command returns nonzero return code. + """ + return str(check_subtype(tg_node)) + + @staticmethod + def get_tg_version(tg_node): + """Log and return the installed traffic generator version. + + :param tg_node: Node from topology file. + :type tg_node: dict + :returns: Traffic generator version string. + :rtype: str + :raises RuntimeError: If command returns nonzero return code. + """ + subtype = check_subtype(tg_node) + if subtype == NodeSubTypeTG.TREX: + command = f"cat {Constants.TREX_INSTALL_DIR}/VERSION" + message = u"Get T-Rex version failed!" + stdout, _ = exec_cmd_no_error(tg_node, command, message=message) + return stdout.strip() + else: + return "none" + + # TODO: pylint disable=too-many-locals. def initialize_traffic_generator( self, tg_node, tg_if1, tg_if2, tg_if1_adj_node, tg_if1_adj_if, tg_if2_adj_node, tg_if2_adj_if, osi_layer, tg_if1_dst_mac=None, @@ -392,18 +423,37 @@ class TrafficGenerator(AbstractMeasurer): tg_node, cmd, sudo=True, message=u"Kill TRex failed!" ) - # Configure TRex. - ports = '' + # Prepare interfaces for TRex. + mlx_ports = u"" + mlx_driver = u"" + itl_ports = u"" for port in tg_node[u"interfaces"].values(): - if u'Mellanox' not in port.get(u'model'): - ports += f" {port.get(u'pci_address')}" - - cmd = f"sh -c \"cd {Constants.TREX_INSTALL_DIR}/scripts/ && " \ - f"./dpdk_nic_bind.py -u {ports} || true\"" - exec_cmd_no_error( - tg_node, cmd, sudo=True, - message=u"Unbind PCI ports from driver failed!" - ) + 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!" + ) # Start TRex. cd_cmd = f"cd '{Constants.TREX_INSTALL_DIR}/scripts/'"