+ if test_type == 'L2':
+ if1_adj_mac = if2_mac
+ if2_adj_mac = if1_mac
+ elif test_type == 'L3':
+ if1_adj_mac = topo.get_interface_mac(tg_if1_adj_node,
+ tg_if1_adj_if)
+ if2_adj_mac = topo.get_interface_mac(tg_if2_adj_node,
+ tg_if2_adj_if)
+ else:
+ raise ValueError("test_type unknown")
+
+ if tg_if1_dst_mac is not None and tg_if2_dst_mac is not None:
+ if1_adj_mac = tg_if1_dst_mac
+ if2_adj_mac = tg_if2_dst_mac
+
+ if min(if1_pci, if2_pci) != if1_pci:
+ if1_mac, if2_mac = if2_mac, if1_mac
+ if1_pci, if2_pci = if2_pci, if1_pci
+ if1_adj_mac, if2_adj_mac = if2_adj_mac, if1_adj_mac
+ self._ifaces_reordered = True
+
+ if1_mac_hex = "0x"+if1_mac.replace(":", ",0x")
+ if2_mac_hex = "0x"+if2_mac.replace(":", ",0x")
+ if1_adj_mac_hex = "0x"+if1_adj_mac.replace(":", ",0x")
+ if2_adj_mac_hex = "0x"+if2_adj_mac.replace(":", ",0x")
+
+ (ret, stdout, stderr) = ssh.exec_command(
+ "sudo sh -c 'cat << EOF > /etc/trex_cfg.yaml\n"
+ "- port_limit : 2\n"
+ " version : 2\n"
+ " interfaces : [\"{}\",\"{}\"]\n"
+ " port_info :\n"
+ " - dest_mac : [{}]\n"
+ " src_mac : [{}]\n"
+ " - dest_mac : [{}]\n"
+ " src_mac : [{}]\n"
+ "EOF'"\
+ .format(if1_pci, if2_pci,
+ if1_adj_mac_hex, if1_mac_hex,
+ if2_adj_mac_hex, if2_mac_hex))
+ if int(ret) != 0:
+ logger.error("failed to create t-rex config: {}"\
+ .format(stdout + stderr))
+ raise RuntimeError('trex config generation error')
+
+ max_startup_retries = 3
+ while max_startup_retries > 0:
+ # kill T-rex only if it is already running
+ (ret, _, _) = ssh.exec_command(
+ "sh -c 'pgrep t-rex && sudo pkill t-rex && sleep 3'")
+
+ # configure T-rex
+ (ret, stdout, stderr) = ssh.exec_command(
+ "sh -c 'cd {0}/scripts/ && sudo ./trex-cfg'"\
+ .format(trex_path))
+ if int(ret) != 0:
+ logger.error('trex-cfg failed: {0}'.format(stdout + stderr))
+ raise RuntimeError('trex-cfg failed')
+
+ # start T-rex
+ (ret, _, _) = ssh.exec_command(
+ "sh -c 'cd {0}/scripts/ && "
+ "sudo nohup ./t-rex-64 -i -c 7 --iom 0 > /dev/null 2>&1 &'"
+ "> /dev/null"\
+ .format(trex_path))
+ if int(ret) != 0:
+ raise RuntimeError('t-rex-64 startup failed')
+
+ # get T-rex server info
+ (ret, _, _) = ssh.exec_command(
+ "sh -c 'sleep 3; "
+ "{0}/resources/tools/trex/trex_server_info.py'"\
+ .format(Constants.REMOTE_FW_DIR),
+ timeout=120)
+ if int(ret) == 0:
+ # If we get info T-rex is running
+ return
+ # try again
+ max_startup_retries -= 1
+ # after max retries T-rex is still not responding to API
+ # critical error occurred
+ raise RuntimeError('t-rex-64 startup failed')
+
+ @staticmethod
+ def teardown_traffic_generator(node):
+ """TG teardown.
+
+ :param node: Traffic generator node.
+ :type node: dict
+ :returns: nothing
+ :raises: RuntimeError if T-rex teardown failed.
+ :raises: RuntimeError if node type is not a TG.
+ """
+ if node['type'] != NodeType.TG:
+ raise RuntimeError('Node type is not a TG')
+ if node['subtype'] == NodeSubTypeTG.TREX:
+ ssh = SSH()
+ ssh.connect(node)
+ (ret, stdout, stderr) = ssh.exec_command(
+ "sh -c 'sudo pkill t-rex && sleep 3'")
+ if int(ret) != 0:
+ logger.error('pkill t-rex failed: {0}'.format(stdout + stderr))
+ raise RuntimeError('pkill t-rex failed')
+
+ @staticmethod
+ def trex_stl_stop_remote_exec(node):
+ """Execute script on remote node over ssh to stop running traffic.
+
+ :param node: T-REX generator node.
+ :type node: dict
+ :returns: Nothing
+ :raises: RuntimeError if stop traffic script fails.
+ """