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 stop_vpp_service_on_all_duts(nodes):
86 """Stop VPP service on all nodes.
88 :param nodes: Nodes in the topology.
91 DUTSetup.stop_service_on_all_duts(nodes, Constants.VPP_UNIT)
94 def verify_vpp_on_dut(node):
95 """Verify that VPP is installed on DUT node.
97 :param node: DUT node.
99 :raises RuntimeError: If failed to restart VPP, get VPP version
100 or get VPP interfaces.
102 VPPUtil.vpp_show_version_verbose(node)
103 VPPUtil.vpp_show_interfaces(node)
106 def verify_vpp_on_all_duts(nodes):
107 """Verify that VPP is installed on all DUT nodes.
109 :param nodes: Nodes in the topology.
112 for node in nodes.values():
113 if node['type'] == NodeType.DUT:
114 DUTSetup.start_service(node, Constants.VPP_UNIT)
115 VPPUtil.vpp_show_version_verbose(node)
116 VPPUtil.vpp_show_interfaces(node)
119 def vpp_show_version_verbose(node):
120 """Run "show version verbose" CLI command.
122 :param node: Node to run command on.
126 vat.execute_script("show_version_verbose.vat", node, json_out=False)
129 vat.script_should_have_passed()
130 except AssertionError:
131 raise RuntimeError('Failed to get VPP version on host: {name}'.
132 format(name=node['host']))
135 def show_vpp_version_on_all_duts(nodes):
136 """Show VPP version verbose on all DUTs.
138 :param nodes: VPP nodes.
141 for node in nodes.values():
142 if node['type'] == NodeType.DUT:
143 VPPUtil.vpp_show_version_verbose(node)
146 def vpp_show_interfaces(node):
147 """Run "show interface" CLI command.
149 :param node: Node to run command on.
153 vat.execute_script("show_interface.vat", node, json_out=False)
156 vat.script_should_have_passed()
157 except AssertionError:
158 raise RuntimeError('Failed to get VPP interfaces on host: {name}'.
159 format(name=node['host']))
162 def vpp_show_crypto_device_mapping(node):
163 """Run "show crypto device mapping" CLI command.
165 :param node: Node to run command on.
169 vat.execute_script("show_crypto_device_mapping.vat", node,
173 def vpp_api_trace_dump(node):
174 """Run "api trace custom-dump" CLI command.
176 :param node: Node to run command on.
180 vat.execute_script("api_trace_dump.vat", node, json_out=False)
183 def vpp_api_trace_save(node):
184 """Run "api trace save" CLI command.
186 :param node: Node to run command on.
190 vat.execute_script("api_trace_save.vat", node, json_out=False)
193 def vpp_enable_traces_on_dut(node):
194 """Enable vpp packet traces on the DUT node.
196 :param node: DUT node to set up.
200 vat.execute_script("enable_dpdk_traces.vat", node, json_out=False)
201 vat.execute_script("enable_vhost_user_traces.vat", node, json_out=False)
202 vat.execute_script("enable_memif_traces.vat", node, json_out=False)
205 def vpp_enable_traces_on_all_duts(nodes):
206 """Enable vpp packet traces on all DUTs in the given topology.
208 :param nodes: Nodes in the topology.
211 for node in nodes.values():
212 if node['type'] == NodeType.DUT:
213 VPPUtil.vpp_enable_traces_on_dut(node)
216 def vpp_enable_elog_traces_on_dut(node):
217 """Enable API/CLI/Barrier traces on the DUT node.
219 :param node: DUT node to set up.
223 vat.execute_script("elog_trace_api_cli_barrier.vat", node,
227 def vpp_enable_elog_traces_on_all_duts(nodes):
228 """Enable API/CLI/Barrier traces on all DUTs in the given topology.
230 :param nodes: Nodes in the topology.
233 for node in nodes.values():
234 if node['type'] == NodeType.DUT:
235 VPPUtil.vpp_enable_elog_traces_on_dut(node)
238 def show_event_logger_on_dut(node):
239 """Show event logger on the DUT node.
241 :param node: DUT node to show traces on.
245 vat.execute_script("show_event_logger.vat", node, json_out=False)
248 def show_event_logger_on_all_duts(nodes):
249 """Show event logger on all DUTs in the given topology.
251 :param nodes: Nodes in the topology.
254 for node in nodes.values():
255 if node['type'] == NodeType.DUT:
256 VPPUtil.show_event_logger_on_dut(node)