1 # Copyright (c) 2021 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 framework."""
17 from robot.api import logger
19 from resources.libraries.python.Constants import Constants
20 from resources.libraries.python.ssh import exec_cmd_no_error
21 from resources.libraries.python.topology import NodeType, Topology
25 """This class implements:
26 - Initialization of DPDK environment,
27 - Cleanup of DPDK environment.
31 def initialize_dpdk_framework(node, if1, if2, nic_driver):
33 Initialize the DPDK framework on the DUT node. Bind interfaces to
36 :param node: DUT node.
37 :param if1: DUT first interface name.
38 :param if2: DUT second interface name.
39 :param nic_driver: Interface driver.
44 :raises RuntimeError: If it fails to bind the interfaces to driver.
46 if node[u"type"] == NodeType.DUT:
47 pci_address1 = Topology.get_interface_pci_addr(node, if1)
48 pci_address2 = Topology.get_interface_pci_addr(node, if2)
50 command = f"{Constants.REMOTE_FW_DIR}/{Constants.RESOURCES_LIB_SH}"\
51 f"/entry/init_dpdk.sh " \
52 f"{nic_driver} {pci_address1} {pci_address2}"
53 message = u"Initialize the DPDK failed!"
54 exec_cmd_no_error(node, command, timeout=600, message=message)
57 def cleanup_dpdk_framework(node, if1, if2):
59 Cleanup the DPDK framework on the DUT node. Bind interfaces to
60 default driver specified in topology.
62 :param node: Will cleanup the DPDK on this node.
63 :param if1: DUT first interface name.
64 :param if2: DUT second interface name.
68 :raises RuntimeError: If it fails to cleanup the dpdk.
70 if node[u"type"] == NodeType.DUT:
71 pci_address1 = Topology.get_interface_pci_addr(node, if1)
72 pci_address2 = Topology.get_interface_pci_addr(node, if2)
73 # We are not supporting more than one driver yet.
74 nic_driver = Topology.get_interface_driver(node, if1)
76 command = f"{Constants.REMOTE_FW_DIR}/{Constants.RESOURCES_LIB_SH}"\
77 f"/entry/cleanup_dpdk.sh " \
78 f"{nic_driver} {pci_address1} {pci_address2}"
79 message = u"Cleanup the DPDK failed!"
80 exec_cmd_no_error(node, command, timeout=1200, message=message)
83 def install_dpdk_framework(node):
85 Prepare the DPDK framework on the DUT node.
87 :param node: Node from topology file.
89 :raises RuntimeError: If command returns nonzero return code.
91 command = f"{Constants.REMOTE_FW_DIR}/{Constants.RESOURCES_LIB_SH}" \
92 f"/entry/install_dpdk.sh"
93 message = u"Install the DPDK failed!"
94 exec_cmd_no_error(node, command, timeout=600, message=message)
96 command = f"cat {Constants.REMOTE_FW_DIR}/dpdk*/VERSION"
97 message = u"Get DPDK version failed!"
98 stdout, _ = exec_cmd_no_error(node, command, message=message)
100 logger.info(f"DPDK Version: {stdout}")
103 def install_dpdk_framework_on_all_duts(nodes):
105 Prepare the DPDK framework on all DUTs.
107 :param nodes: Nodes from topology file.
110 for node in list(nodes.values()):
111 if node[u"type"] == NodeType.DUT:
112 DPDKTools.install_dpdk_framework(node)