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:
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 """This module implements initialization and cleanup of DPDK environment."""
17 from resources.libraries.python.ssh import SSH
18 from resources.libraries.python.constants import Constants as con
19 from resources.libraries.python.topology import Topology
22 class DPDKTools(object):
23 """This class implements:
24 - Initialization of DPDK environment,
25 - Cleanup of DPDK environment.
29 def initialize_dpdk_environment(dut_node, dut_if1, dut_if2):
31 Initialize the DPDK test environment on the dut_node.
32 Load the module uio and igb_uio, then bind the test NIC to the igb_uio.
34 :param dut_node: Will init the DPDK on this node.
35 :param dut_if1: DUT interface name.
36 :param dut_if2: DUT interface name.
41 :raises RuntimeError: If it fails to bind the interfaces to igb_uio.
43 pci_address1 = Topology.get_interface_pci_addr(dut_node, dut_if1)
44 pci_address2 = Topology.get_interface_pci_addr(dut_node, dut_if2)
49 cmd = 'cd {0}/dpdk-tests/dpdk_scripts/ && sudo ./init_dpdk.sh {1} {2}' \
50 .format(con.REMOTE_FW_DIR, pci_address1, pci_address2)
52 (ret_code, _, _) = ssh.exec_command(cmd, timeout=600)
54 raise RuntimeError('Failed to bind the interfaces to igb_uio at '
55 'node {0}'.format(dut_node['host']))
58 def cleanup_dpdk_environment(dut_node, dut_if1, dut_if2):
60 Cleanup the DPDK test environment on the DUT node.
61 Unbind the NIC from the igb_uio and bind them to the kernel driver.
63 :param dut_node: Will cleanup the DPDK on this node.
64 :param dut_if1: DUT interface name.
65 :param dut_if2: DUT interface name.
70 :raises RuntimeError: If it fails to cleanup the dpdk.
72 pci_address1 = Topology.get_interface_pci_addr(dut_node, dut_if1)
73 if1_driver = Topology.get_interface_driver(dut_node, dut_if1)
74 pci_address2 = Topology.get_interface_pci_addr(dut_node, dut_if2)
75 if2_driver = Topology.get_interface_driver(dut_node, dut_if2)
80 cmd = 'cd {0}/dpdk-tests/dpdk_scripts/ && sudo ./cleanup_dpdk.sh ' \
81 '{1} {2} {3} {4}'.format(con.REMOTE_FW_DIR, if1_driver,
82 pci_address1, if2_driver, pci_address2)
84 (ret_code, _, _) = ssh.exec_command(cmd, timeout=600)
86 raise RuntimeError('Failed to cleanup the dpdk at node {0}'
87 .format(dut_node['host']))