80a91e2ff6253be18561effeb67b7e02a7550122
[csit.git] / resources / libraries / python / DPDK / L2fwdTest.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 """This module implements functionality which sets L2 forwarding for DPDK on
15 DUT nodes.
16 """
17
18 from resources.libraries.python.ssh import SSH
19 from resources.libraries.python.constants import Constants as con
20
21
22 class L2fwdTest(object):
23     """Setup the DPDK for l2fwd performance test."""
24
25     @staticmethod
26     def start_the_l2fwd_test(dut_node, cpu_cores, nb_cores, queue_nums,
27                              jumbo_frames):
28         """
29         Execute the l2fwd on the dut_node.
30
31         :param dut_node: Will execute the l2fwd on this node.
32         :param cpu_cores: The DPDK run cores.
33         :param nb_cores: The cores number for the forwarding.
34         :param queue_nums: The queues number for the NIC.
35         :param jumbo_frames: Are jumbo frames used or not.
36         :type dut_node: dict
37         :type cpu_cores: str
38         :type nb_cores: str
39         :type queue_nums: str
40         :type jumbo_frames: str
41         :returns: none
42         :raises RuntimeError: If the script "run_l2fwd.sh" fails.
43         """
44
45         ssh = SSH()
46         ssh.connect(dut_node)
47
48         cmd = 'cd {0}/dpdk-tests/dpdk_scripts/ && sudo ./run_l2fwd.sh {1} ' \
49               '{2} {3} {4}'.format(con.REMOTE_FW_DIR, cpu_cores, nb_cores,
50                                    queue_nums, jumbo_frames)
51
52         (ret_code, _, _) = ssh.exec_command(cmd, timeout=600)
53         if ret_code != 0:
54             raise RuntimeError('Failed to execute l2fwd test at node {0}'.
55                                format(dut_node['host']))