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 """Macswap sample_plugin util library"""
16 from resources.libraries.python.topology import NodeType, Topology
17 from resources.libraries.python.VatExecutor import VatExecutor
19 class MacSwap(object):
20 """Macswap sample plugin API"""
23 def enable_disable_macswap_vat(node, interface):
24 """Enable/Disable macswap on interface.
26 Function can be used on a VPP node with macswap plugin.
28 :param node: Node where the interface is.
29 :param interface: Interface id.
31 :type interface: str or int
34 if node['type'] == NodeType.DUT:
35 sw_if_index = Topology.get_interface_sw_index(node, interface)
37 VatExecutor.cmd_from_template(node, 'macswap.vat',
38 sw_if_index=sw_if_index)
40 raise ValueError('Node {} has not DUT NodeType: "{}"'.
41 format(node['host'], node['type']))
44 def enable_disable_macswap_vat_exec(node, interface_name):
45 """Enable/Disable macswap on interface.
47 Function can be used on a VPP node with macswap plugin.
49 :param node: Node where the interface is.
50 :param interface_name: Interface name.
52 :type interface_name: str or int
55 if node['type'] == NodeType.DUT:
57 VatExecutor.cmd_from_template(node, 'macswap_exec.vat',
58 if_name=interface_name)
60 raise ValueError('Node {} has not DUT NodeType: "{}"'.
61 format(node['host'], node['type']))