Add the DPDK l2fwd performance test cases.
[csit.git] / resources / libraries / python / DPDK / DPDKTools.py
1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14
15 """
16 This module exists to provide the init DPDK.
17 """
18
19 from resources.libraries.python.ssh import SSH
20 from resources.libraries.python.constants import Constants as con
21 from resources.libraries.python.topology import Topology
22
23 class DPDKTools(object):
24     """Test the DPDK l2fwd performance."""
25
26     @staticmethod
27     def initialize_dpdk_environment(dut_node, dut_if1, dut_if2):
28         """
29         Initialize the DPDK test environment on the dut_node.
30         Load the module uio and igb_uio, then bind the test NIC to the igb_uio.
31
32         :param dut_node: Will init the DPDK on this node.
33         :param dut_if1: DUT interface name.
34         :param dut_if2: DUT interface name.
35         :type dut_node: dict
36         :type dut_if1: str
37         :type dut_if2: str
38         :returns: none
39         """
40         pci_address1 = Topology.get_interface_pci_addr(dut_node, dut_if1)
41         pci_address2 = Topology.get_interface_pci_addr(dut_node, dut_if2)
42
43         ssh = SSH()
44         ssh.connect(dut_node)
45
46         cmd = 'cd {0}/dpdk-tests/dpdk_scripts/ && sudo ./init_dpdk.sh {1} {2}' \
47               .format(con.REMOTE_FW_DIR, pci_address1, pci_address2)
48
49         (ret_code, _, _) = ssh.exec_command(cmd, timeout=600)
50         if ret_code != 0:
51             raise Exception('Failed to bind the interfaces to igb_uio ' \
52                             'at node {0}'.format(dut_node['host']))
53
54     @staticmethod
55     def cleanup_dpdk_environment(dut_node, dut_if1, dut_if2):
56         """
57         Cleanup the DPDK test environment on the DUT node.
58         Unbind the NIC from the igb_uio and bind them to the kernel driver.
59
60         :param dut_node: Will cleanup the DPDK on this node.
61         :param dut_if1: DUT interface name.
62         :param dut_if2: DUT interface name.
63         :type dut_node: dict
64         :type dut_if1: str
65         :type dut_if2: str
66         :returns: none
67         """
68         pci_address1 = Topology.get_interface_pci_addr(dut_node, dut_if1)
69         if1_driver = Topology.get_interface_driver(dut_node, dut_if1)
70         pci_address2 = Topology.get_interface_pci_addr(dut_node, dut_if2)
71         if2_driver = Topology.get_interface_driver(dut_node, dut_if2)
72
73         ssh = SSH()
74         ssh.connect(dut_node)
75
76         cmd = 'cd {0}/dpdk-tests/dpdk_scripts/ && sudo ./cleanup_dpdk.sh ' \
77               '{1} {2} {3} {4}'.format(con.REMOTE_FW_DIR, if1_driver, \
78               pci_address1, if2_driver, pci_address2)
79
80         (ret_code, _, _) = ssh.exec_command(cmd, timeout=600)
81         if ret_code != 0:
82             raise Exception('Failed to cleanup the dpdk at node {0}'
83                             .format(dut_node['host']))