+ self._node = None
+ # T-REX interface order mapping
+ self._ifaces_reordered = 0
+
+ def get_loss(self):
+ """Return number of lost packets.
+
+ :return: Number of lost packets.
+ :rtype: str
+ """
+ return self._loss
+
+ def get_sent(self):
+ """Return number of sent packets.
+
+ :return: Number of sent packets.
+ :rtype: str
+ """
+ return self._sent
+
+ def get_received(self):
+ """Return number of received packets.
+
+ :return: Number of received packets.
+ :rtype: str
+ """
+ return self._received
+
+ #pylint: disable=too-many-arguments, 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,
+ test_type):
+ """TG initialization.
+
+ :param tg_node: Traffic generator node.
+ :param tg_if1: TG - name of first interface.
+ :param tg_if2: TG - name of second interface.
+ :param tg_if1_adj_node: TG if1 adjecent node.
+ :param tg_if1_adj_if: TG if1 adjecent interface.
+ :param tg_if2_adj_node: TG if2 adjecent node.
+ :param tg_if2_adj_if: TG if2 adjecent interface.
+ :test_type: 'L2' or 'L3' - src/dst MAC address.
+ :type tg_node: dict
+ :type tg_if1: str
+ :type tg_if2: str
+ :type tg_if1_adj_node: dict
+ :type tg_if1_adj_if: str
+ :type tg_if2_adj_node: dict
+ :type tg_if2_adj_if: str
+ :type test_type: str
+ :return: nothing
+ """
+
+ topo = Topology()
+
+ if tg_node['type'] != NodeType.TG:
+ raise Exception('Node type is not a TG')
+ self._node = tg_node
+
+ if tg_node['subtype'] == NodeSubTypeTG.TREX:
+ trex_path = "/opt/trex-core-2.03"
+
+ ssh = SSH()
+ ssh.connect(tg_node)
+
+ (ret, stdout, stderr) = ssh.exec_command(
+ "sudo sh -c '{}/resources/tools/t-rex/"
+ "t-rex-installer.sh'".format(Constants.REMOTE_FW_DIR),
+ timeout=1800)
+ if int(ret) != 0:
+ logger.error('trex installation failed: {0}'.format(
+ stdout + stderr))
+ raise RuntimeError('Installation of TG failed')
+
+ if1_pci = topo.get_interface_pci_addr(tg_node, tg_if1)
+ if2_pci = topo.get_interface_pci_addr(tg_node, tg_if2)
+ if1_mac = topo.get_interface_mac(tg_node, tg_if1)
+ if2_mac = topo.get_interface_mac(tg_node, tg_if2)
+
+ 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 Exception("test_type unknown")
+
+ 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 = 1
+
+ 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_bandwidth_gb : 10\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')
+
+ (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')