1 # Copyright (c) 2017 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 """Memif interface library."""
16 from resources.libraries.python.ssh import SSH
17 from resources.libraries.python.VatExecutor import VatExecutor, VatTerminal
21 """Memif interface class."""
27 def create_memif_interface(node, socket, mid, role="master"):
28 """Create Memif interface on the given node.
30 :param node: Given node to create Memif interface on.
31 :param socket: Memif interface socket path.
32 :param mid: Memif interface ID.
33 :param role: Memif interface role [master|slave]. Default is master.
38 :returns: SW interface index.
40 :raises ValueError: If command 'create memif' fails.
43 with VatTerminal(node, json_param=False) as vat:
44 vat.vat_terminal_exec_cmd_from_template(
46 socket=socket, id=mid, role=role)
47 if 'sw_if_index' in vat.vat_stdout:
49 return int(vat.vat_stdout.split()[4])
51 raise ValueError('Create Memif interface failed on node '
52 '{}"'.format(node['host']))
54 raise ValueError('Create Memif interface failed on node '
55 '{}"'.format(node['host']))
59 """Show Memif data for the given node.
61 :param node: Given node to show Memif data on.
65 vat.execute_script("memif_dump.vat", node, json_out=False)
68 def clear_memif_socks(node, *socks):
69 """Clear Memif sockets for the given node.
71 :param node: Given node to clear Memif sockets on.
72 :param socks: Memif sockets.
80 ssh.exec_command_sudo('rm -f {}'.format(sock))