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:
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.
14 """VPP util library."""
15 from resources.libraries.python.constants import Constants
16 from resources.libraries.python.DUTSetup import DUTSetup
17 from resources.libraries.python.ssh import exec_cmd_no_error
18 from resources.libraries.python.topology import NodeType
19 from resources.libraries.python.VatExecutor import VatExecutor
22 class VPPUtil(object):
23 """General class for any VPP related methods/functions."""
26 def show_vpp_settings(node, *additional_cmds):
27 """Print default VPP settings. In case others are needed, can be
28 accepted as next parameters (each setting one parameter), preferably
31 :param node: VPP node.
32 :param additional_cmds: Additional commands that the vpp should print
35 :type additional_cmds: tuple
37 def_setting_tb_displayed = {
38 'IPv6 FIB': 'ip6 fib',
40 'Interface IP': 'int addr',
47 for cmd in additional_cmds:
48 def_setting_tb_displayed['Custom Setting: {}'.format(cmd)] = cmd
50 for _, cmd in def_setting_tb_displayed.items():
51 command = 'vppctl sh {cmd}'.format(cmd=cmd)
52 exec_cmd_no_error(node, command, timeout=30, sudo=True)
55 def start_vpp_service(node):
56 """Start VPP service on the specified node.
58 :param node: VPP node.
60 :raises RuntimeError: If VPP service fails to start.
62 DUTSetup.start_service(node, Constants.VPP_UNIT)
63 DUTSetup.get_service_logs(node, Constants.VPP_UNIT)
66 def start_vpp_service_on_all_duts(nodes):
67 """Start up the VPP service on all nodes.
69 :param nodes: Nodes in the topology.
72 DUTSetup.start_service_on_all_duts(nodes, Constants.VPP_UNIT)
75 def stop_vpp_service(node):
76 """Stop VPP service on the specified node.
78 :param node: VPP node.
80 :raises RuntimeError: If VPP service fails to stop.
82 DUTSetup.stop_service(node, Constants.VPP_UNIT)
85 def verify_vpp_on_dut(node):
86 """Verify that VPP is installed on DUT node.
88 :param node: DUT node.
90 :raises RuntimeError: If failed to restart VPP, get VPP version
91 or get VPP interfaces.
93 VPPUtil.vpp_show_version_verbose(node)
94 VPPUtil.vpp_show_interfaces(node)
97 def verify_vpp_on_all_duts(nodes):
98 """Verify that VPP is installed on all DUT nodes.
100 :param nodes: Nodes in the topology.
103 for node in nodes.values():
104 if node['type'] == NodeType.DUT:
105 DUTSetup.start_service(node, Constants.VPP_UNIT)
106 VPPUtil.vpp_show_version_verbose(node)
107 VPPUtil.vpp_show_interfaces(node)
110 def vpp_show_version_verbose(node):
111 """Run "show version verbose" CLI command.
113 :param node: Node to run command on.
117 vat.execute_script("show_version_verbose.vat", node, json_out=False)
120 vat.script_should_have_passed()
121 except AssertionError:
122 raise RuntimeError('Failed to get VPP version on host: {name}'.
123 format(name=node['host']))
126 def show_vpp_version_on_all_duts(nodes):
127 """Show VPP version verbose on all DUTs.
129 :param nodes: VPP nodes.
132 for node in nodes.values():
133 if node['type'] == NodeType.DUT:
134 VPPUtil.vpp_show_version_verbose(node)
137 def vpp_show_interfaces(node):
138 """Run "show interface" CLI command.
140 :param node: Node to run command on.
144 vat.execute_script("show_interface.vat", node, json_out=False)
147 vat.script_should_have_passed()
148 except AssertionError:
149 raise RuntimeError('Failed to get VPP interfaces on host: {name}'.
150 format(name=node['host']))
153 def vpp_show_crypto_device_mapping(node):
154 """Run "show crypto device mapping" CLI command.
156 :param node: Node to run command on.
160 vat.execute_script("show_crypto_device_mapping.vat", node,
164 def vpp_api_trace_dump(node):
165 """Run "api trace custom-dump" CLI command.
167 :param node: Node to run command on.
171 vat.execute_script("api_trace_dump.vat", node, json_out=False)
174 def vpp_api_trace_save(node):
175 """Run "api trace save" CLI command.
177 :param node: Node to run command on.
181 vat.execute_script("api_trace_save.vat", node, json_out=False)
184 def vpp_enable_traces_on_dut(node):
185 """Enable vpp packet traces on the DUT node.
187 :param node: DUT node to set up.
191 vat.execute_script("enable_dpdk_traces.vat", node, json_out=False)
192 vat.execute_script("enable_vhost_user_traces.vat", node, json_out=False)
193 vat.execute_script("enable_memif_traces.vat", node, json_out=False)
196 def vpp_enable_traces_on_all_duts(nodes):
197 """Enable vpp packet traces on all DUTs in the given topology.
199 :param nodes: Nodes in the topology.
202 for node in nodes.values():
203 if node['type'] == NodeType.DUT:
204 VPPUtil.vpp_enable_traces_on_dut(node)