1 # Copyright (c) 2016 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.ssh import SSH
18 class VPPUtil(object):
19 """General class for any VPP related methods/functions."""
22 def show_vpp_settings(node, *additional_cmds):
23 """Print default VPP settings. In case others are needed, can be
24 accepted as next parameters (each setting one parameter), preferably
27 :param node: VPP node.
28 :param additional_cmds: Additional commands that the vpp should print
31 :type additional_cmds: tuple
33 def_setting_tb_displayed = {
34 'IPv6 FIB': 'ip6 fib',
36 'Interface IP': 'int addr',
43 for cmd in additional_cmds:
44 def_setting_tb_displayed['Custom Setting: {}'.format(cmd)] = cmd
47 for _, value in def_setting_tb_displayed.items():
48 ssh.exec_command_sudo('vppctl sh {}'.format(value))
51 def stop_vpp_service(node):
52 """Stop VPP service on the specified node.
54 :param node: VPP node.
56 :raises RuntimeError: If VPP fails to stop.
61 cmd = "service vpp stop"
62 ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=80)
63 if int(ret_code) != 0:
64 raise RuntimeError("VPP service did not shut down gracefully.")
67 def start_vpp_service(node):
68 """start VPP service on the specified node.
70 :param node: VPP node.
72 :raises RuntimeError: If VPP fails to start.
77 cmd = "service vpp start"
78 ret_code, _, _ = ssh.exec_command_sudo(cmd)
79 if int(ret_code) != 0:
80 raise RuntimeError("VPP service did not start.")