aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/DPDK
diff options
context:
space:
mode:
authorFangyin Hu <fangyinx.hu@intel.com>2016-11-25 03:52:22 -0800
committerPeter Mikus <pmikus@cisco.com>2017-01-11 13:21:52 +0000
commitb633f4ebf7878ae968e27b71da69b6cde0265904 (patch)
treec7b8949f4fe5e56ae15e177afd0b2051266ba881 /resources/libraries/python/DPDK
parent6858eef6792e7fae60c7fe2587721e2873bd5fc3 (diff)
Add the DPDK l2fwd performance test cases.
Change-Id: I996847a4871ed994cd9b5edb459fb079ff39c86d Signed-off-by: Fangyin Hu <fangyinx.hu@intel.com>
Diffstat (limited to 'resources/libraries/python/DPDK')
-rw-r--r--resources/libraries/python/DPDK/DPDKTools.py83
-rw-r--r--resources/libraries/python/DPDK/L2fwdTest.py54
-rw-r--r--resources/libraries/python/DPDK/SetupDPDKTest.py218
-rw-r--r--resources/libraries/python/DPDK/__init__.py16
4 files changed, 371 insertions, 0 deletions
diff --git a/resources/libraries/python/DPDK/DPDKTools.py b/resources/libraries/python/DPDK/DPDKTools.py
new file mode 100644
index 0000000000..e7fa2f4e76
--- /dev/null
+++ b/resources/libraries/python/DPDK/DPDKTools.py
@@ -0,0 +1,83 @@
+# Copyright (c) 2016 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:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+"""
+This module exists to provide the init DPDK.
+"""
+
+from resources.libraries.python.ssh import SSH
+from resources.libraries.python.constants import Constants as con
+from resources.libraries.python.topology import Topology
+
+class DPDKTools(object):
+ """Test the DPDK l2fwd performance."""
+
+ @staticmethod
+ def initialize_dpdk_environment(dut_node, dut_if1, dut_if2):
+ """
+ Initialize the DPDK test environment on the dut_node.
+ Load the module uio and igb_uio, then bind the test NIC to the igb_uio.
+
+ :param dut_node: Will init the DPDK on this node.
+ :param dut_if1: DUT interface name.
+ :param dut_if2: DUT interface name.
+ :type dut_node: dict
+ :type dut_if1: str
+ :type dut_if2: str
+ :returns: none
+ """
+ pci_address1 = Topology.get_interface_pci_addr(dut_node, dut_if1)
+ pci_address2 = Topology.get_interface_pci_addr(dut_node, dut_if2)
+
+ ssh = SSH()
+ ssh.connect(dut_node)
+
+ cmd = 'cd {0}/dpdk-tests/dpdk_scripts/ && sudo ./init_dpdk.sh {1} {2}' \
+ .format(con.REMOTE_FW_DIR, pci_address1, pci_address2)
+
+ (ret_code, _, _) = ssh.exec_command(cmd, timeout=600)
+ if ret_code != 0:
+ raise Exception('Failed to bind the interfaces to igb_uio ' \
+ 'at node {0}'.format(dut_node['host']))
+
+ @staticmethod
+ def cleanup_dpdk_environment(dut_node, dut_if1, dut_if2):
+ """
+ Cleanup the DPDK test environment on the DUT node.
+ Unbind the NIC from the igb_uio and bind them to the kernel driver.
+
+ :param dut_node: Will cleanup the DPDK on this node.
+ :param dut_if1: DUT interface name.
+ :param dut_if2: DUT interface name.
+ :type dut_node: dict
+ :type dut_if1: str
+ :type dut_if2: str
+ :returns: none
+ """
+ pci_address1 = Topology.get_interface_pci_addr(dut_node, dut_if1)
+ if1_driver = Topology.get_interface_driver(dut_node, dut_if1)
+ pci_address2 = Topology.get_interface_pci_addr(dut_node, dut_if2)
+ if2_driver = Topology.get_interface_driver(dut_node, dut_if2)
+
+ ssh = SSH()
+ ssh.connect(dut_node)
+
+ cmd = 'cd {0}/dpdk-tests/dpdk_scripts/ && sudo ./cleanup_dpdk.sh ' \
+ '{1} {2} {3} {4}'.format(con.REMOTE_FW_DIR, if1_driver, \
+ pci_address1, if2_driver, pci_address2)
+
+ (ret_code, _, _) = ssh.exec_command(cmd, timeout=600)
+ if ret_code != 0:
+ raise Exception('Failed to cleanup the dpdk at node {0}'
+ .format(dut_node['host']))
diff --git a/resources/libraries/python/DPDK/L2fwdTest.py b/resources/libraries/python/DPDK/L2fwdTest.py
new file mode 100644
index 0000000000..fa2f879492
--- /dev/null
+++ b/resources/libraries/python/DPDK/L2fwdTest.py
@@ -0,0 +1,54 @@
+# Copyright (c) 2016 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:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+"""
+This module exists to provide the l2fwd test for DPDK on topology nodes.
+"""
+
+from resources.libraries.python.ssh import SSH
+from resources.libraries.python.constants import Constants as con
+
+class L2fwdTest(object):
+ """Test the DPDK l2fwd performance."""
+
+ @staticmethod
+ def start_the_l2fwd_test(dut_node, cpu_coremask, nb_cores, queue_nums,
+ jumbo_frames):
+ """
+ Execute the l2fwd on the dut_node.
+
+ :param dut_node: Will execute the l2fwd on this node.
+ :param cpu_coremask: The DPDK run core mask.
+ :param nb_cores: The cores number for the forwarding.
+ :param queue_nums: The queues number for the NIC.
+ :param jumbo_frames: Is jumbo frames or not.
+ :type dut_node: dict
+ :type cpu_coremask: str
+ :type nb_cores: str
+ :type queue_nums: str
+ :type jumbo_frames: str
+ :returns: none
+ """
+ ssh = SSH()
+ ssh.connect(dut_node)
+
+ cmd = 'cd {0}/dpdk-tests/dpdk_scripts/ && sudo ./run_l2fwd.sh ' \
+ '{1} {2} {3} {4}'.format(con.REMOTE_FW_DIR, cpu_coremask, \
+ nb_cores, queue_nums, jumbo_frames)
+
+ (ret_code, _, _) = ssh.exec_command(cmd, timeout=600)
+ if ret_code != 0:
+ raise Exception('Failed to execute l2fwd test at node {0}'
+ .format(dut_node['host']))
+
diff --git a/resources/libraries/python/DPDK/SetupDPDKTest.py b/resources/libraries/python/DPDK/SetupDPDKTest.py
new file mode 100644
index 0000000000..06bb9ee9eb
--- /dev/null
+++ b/resources/libraries/python/DPDK/SetupDPDKTest.py
@@ -0,0 +1,218 @@
+# Copyright (c) 2016 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:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""This module exists to provide setup utilities for the framework on topology
+nodes. All tasks required to be run before the actual tests are started is
+supposed to end up here.
+"""
+
+from shlex import split
+from subprocess import Popen, PIPE, call
+from multiprocessing import Pool
+from tempfile import NamedTemporaryFile
+from os.path import basename
+
+from robot.api import logger
+from robot.libraries.BuiltIn import BuiltIn
+
+from resources.libraries.python.ssh import SSH
+from resources.libraries.python.constants import Constants as con
+from resources.libraries.python.topology import NodeType
+
+__all__ = ["SetupDPDKTest"]
+
+
+def pack_framework_dir():
+ """Pack the testing WS into temp file, return its name."""
+
+ tmpfile = NamedTemporaryFile(suffix=".tgz", prefix="DPDK-testing-")
+ file_name = tmpfile.name
+ tmpfile.close()
+
+ proc = Popen(
+ split("tar --exclude-vcs -zcf {0} .".format(file_name)),
+ stdout=PIPE, stderr=PIPE)
+ (stdout, stderr) = proc.communicate()
+
+ logger.debug(stdout)
+ logger.debug(stderr)
+
+ return_code = proc.wait()
+ if return_code != 0:
+ raise Exception("Could not pack testing framework.")
+
+ return file_name
+
+
+def copy_tarball_to_node(tarball, node):
+ """Copy tarball file from local host to remote node.
+
+ :param tarball: Path to tarball to upload.
+ :param node: Dictionary created from topology.
+ :type tarball: str
+ :type node: dict
+ :returns: nothing
+ """
+ logger.console('Copying tarball to {0}'.format(node['host']))
+ ssh = SSH()
+ ssh.connect(node)
+
+ ssh.scp(tarball, "/tmp/")
+
+
+def extract_tarball_at_node(tarball, node):
+ """Extract tarball at given node.
+
+ Extracts tarball using tar on given node to specific CSIT loocation.
+
+ :param tarball: Path to tarball to upload.
+ :param node: Dictionary created from topology.
+ :type tarball: str
+ :type node: dict
+ :returns: nothing
+ """
+ logger.console('Extracting tarball to {0} on {1}'.format(
+ con.REMOTE_FW_DIR, node['host']))
+ ssh = SSH()
+ ssh.connect(node)
+
+ cmd = 'sudo rm -rf {1}; mkdir {1} ; tar -zxf {0} -C {1}; ' \
+ 'rm -f {0}'.format(tarball, con.REMOTE_FW_DIR)
+ (ret_code, _, stderr) = ssh.exec_command(cmd, timeout=30)
+ if ret_code != 0:
+ logger.error('Unpack error: {0}'.format(stderr))
+ raise Exception('Failed to unpack {0} at node {1}'.format(
+ tarball, node['host']))
+
+
+def create_env_directory_at_node(node):
+ """
+ Create fresh virtualenv to a directory, install pip requirements.
+
+ :param node: Dictionary created from topology, will only install in the TG
+ :type node: dict
+ :returns: nothing
+ """
+ logger.console('Extracting virtualenv, installing requirements.txt '
+ 'on {0}'.format(node['host']))
+ ssh = SSH()
+ ssh.connect(node)
+ (ret_code, stdout, stderr) = ssh.exec_command(
+ 'cd {0} && rm -rf env && virtualenv env && '
+ '. env/bin/activate && pip install -r requirements.txt'
+ .format(con.REMOTE_FW_DIR), timeout=100)
+ if ret_code != 0:
+ logger.error('Virtualenv creation error: {0}'.format(stdout + stderr))
+ raise Exception('Virtualenv setup failed')
+ else:
+ logger.console('Virtualenv created on {0}'.format(node['host']))
+
+def install_dpdk_test(node):
+ """
+ Prepare the DPDK test envrionment
+
+ :param node: Dictionary created from topology
+ :type node: dict
+ :returns: nothing
+ """
+ logger.console('Install the DPDK on {0}'.format(node['host']))
+
+ ssh = SSH()
+ ssh.connect(node)
+
+ (ret_code, _, stderr) = ssh.exec_command(
+ 'cd {0}/dpdk-tests/dpdk_scripts/ && ./install_dpdk.sh'
+ .format(con.REMOTE_FW_DIR), timeout=600)
+
+ if ret_code != 0:
+ logger.error('Install the DPDK error: {0}'.format(stderr))
+ raise Exception('Install the DPDK failed')
+ else:
+ logger.console('Install the DPDK on {0} success!'.format(node['host']))
+
+#pylint: disable=broad-except
+def setup_node(args):
+ """Run all set-up methods for a node.
+
+ This method is used as map_async parameter. It receives tuple with all
+ parameters as passed to map_async function.
+
+ :param args: All parameters needed to setup one node.
+ :type args: tuple
+ :returns: True - success, False - error
+ :rtype: bool
+ """
+ tarball, remote_tarball, node = args
+ try:
+ copy_tarball_to_node(tarball, node)
+ extract_tarball_at_node(remote_tarball, node)
+ if node['type'] == NodeType.DUT:
+ install_dpdk_test(node)
+ if node['type'] == NodeType.TG:
+ create_env_directory_at_node(node)
+ except Exception as exc:
+ logger.error("Node setup failed, error:'{0}'".format(exc.message))
+ return False
+ else:
+ logger.console('Setup of node {0} done'.format(node['host']))
+ return True
+
+def delete_local_tarball(tarball):
+ """Delete local tarball to prevent disk pollution.
+
+ :param tarball: Path to tarball to upload.
+ :type tarball: str
+ :returns: nothing
+ """
+ call(split('sh -c "rm {0} > /dev/null 2>&1"'.format(tarball)))
+
+
+class SetupDPDKTest(object):
+ """Setup suite run on topology nodes.
+
+ Many VAT/CLI based tests need the scripts at remote hosts before executing
+ them. This class packs the whole testing directory and copies it over
+ to all nodes in topology under /tmp/
+ """
+
+ @staticmethod
+ def setup_dpdk_test(nodes):
+ """Pack the whole directory and extract in temp on each node."""
+
+ tarball = pack_framework_dir()
+ msg = 'Framework packed to {0}'.format(tarball)
+ logger.console(msg)
+ logger.trace(msg)
+ remote_tarball = "/tmp/{0}".format(basename(tarball))
+
+ # Turn off logging since we use multiprocessing
+ log_level = BuiltIn().set_log_level('NONE')
+ params = ((tarball, remote_tarball, node) for node in nodes.values())
+ pool = Pool(processes=len(nodes))
+ result = pool.map_async(setup_node, params)
+ pool.close()
+ pool.join()
+
+ # Turn on logging
+ BuiltIn().set_log_level(log_level)
+
+ logger.info(
+ 'Executed node setups in parallel, waiting for processes to end')
+ result.wait()
+
+ logger.info('Results: {0}'.format(result.get()))
+
+ logger.trace('Test framework copied to all topology nodes')
+ delete_local_tarball(tarball)
+ logger.console('All nodes are ready')
+
diff --git a/resources/libraries/python/DPDK/__init__.py b/resources/libraries/python/DPDK/__init__.py
new file mode 100644
index 0000000000..03bc4c1006
--- /dev/null
+++ b/resources/libraries/python/DPDK/__init__.py
@@ -0,0 +1,16 @@
+# Copyright (c) 2016 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:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+__init__ file for directory resources/libraries/python/DPDK
+"""