Python3: resources and libraries
[csit.git] / resources / libraries / python / DPDK / L2fwdTest.py
1 # Copyright (c) 2019 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.Constants import Constants
19 from resources.libraries.python.ssh import SSH
20 from resources.libraries.python.topology import NodeType, Topology
21
22
23 class L2fwdTest:
24     """Setup the DPDK for l2fwd performance test."""
25
26     @staticmethod
27     def start_the_l2fwd_test(
28             dut_node, cpu_cores, nb_cores, queue_nums, 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: Indication if the jumbo frames are used (True) or
37                              not (False).
38         :type dut_node: dict
39         :type cpu_cores: str
40         :type nb_cores: str
41         :type queue_nums: str
42         :type jumbo_frames: bool
43         :raises RuntimeError: If the script "run_l2fwd.sh" fails.
44         """
45         if dut_node[u"type"] == NodeType.DUT:
46             ssh = SSH()
47             ssh.connect(dut_node)
48
49             arch = Topology.get_node_arch(dut_node)
50             jumbo = u"yes" if jumbo_frames else u"no"
51             cmd = f"{Constants.REMOTE_FW_DIR}/tests/dpdk/dpdk_scripts" \
52                 f"/run_l2fwd.sh {cpu_cores} {nb_cores} {queue_nums} {jumbo} " \
53                 f"{arch}"
54
55             ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=600)
56             if ret_code != 0:
57                 raise RuntimeError(
58                     f"Failed to execute l2fwd test at node {dut_node['host']}"
59                 )