cfaa39991dbfefce8f83f5d3a59ee6004ea36a8b
[csit.git] / resources / libraries / python / DPDK / L2fwdTest.py
1 # Copyright (c) 2018 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
20 from resources.libraries.python.topology import NodeType, Topology
21
22
23 class L2fwdTest(object):
24     """Setup the DPDK for l2fwd performance test."""
25
26     @staticmethod
27     def start_the_l2fwd_test(dut_node, cpu_cores, nb_cores, queue_nums,
28                              jumbo_frames):
29         """
30         Execute the l2fwd on the dut_node.
31
32         :param dut_node: Will execute the l2fwd on this node.
33         :param cpu_cores: The DPDK run cores.
34         :param nb_cores: The cores number for the forwarding.
35         :param queue_nums: The queues number for the NIC.
36         :param jumbo_frames: Are jumbo frames used or not.
37         :type dut_node: dict
38         :type cpu_cores: str
39         :type nb_cores: str
40         :type queue_nums: str
41         :type jumbo_frames: str
42         :returns: none
43         :raises RuntimeError: If the script "run_l2fwd.sh" fails.
44         """
45         if dut_node['type'] == NodeType.DUT:
46             ssh = SSH()
47             ssh.connect(dut_node)
48
49             arch = Topology.get_node_arch(dut_node)
50             cmd = '{fwdir}/tests/dpdk/dpdk_scripts/run_l2fwd.sh {cpu_cores} ' \
51                   '{nb_cores} {queues} {jumbo} {arch}'.\
52                   format(fwdir=Constants.REMOTE_FW_DIR, cpu_cores=cpu_cores,
53                          nb_cores=nb_cores, queues=queue_nums,
54                          jumbo=jumbo_frames, arch=arch)
55
56             ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=600)
57             if ret_code != 0:
58                 raise RuntimeError('Failed to execute l2fwd test at node '
59                                    '{name}'.format(name=dut_node['host']))