6cd723d3274c0139780579c114efcb1c19988ed3
[csit.git] / resources / libraries / python / ProxyArp.py
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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 """Proxy ARP library"""
15
16 from resources.libraries.python.InterfaceUtil import InterfaceUtil
17 from resources.libraries.python.PapiExecutor import PapiExecutor
18 from resources.libraries.python.VatExecutor import VatTerminal
19
20
21 class ProxyArp(object):
22     """Proxy ARP utilities."""
23
24     @staticmethod
25     def vpp_add_proxy_arp(node, lo_ip4_addr, hi_ip4_addr):
26         """Enable proxy ARP for a range of IP addresses.
27
28         :param node: VPP node to enable proxy ARP.
29         :param lo_ip4_addr: The lower limit of the IP addresses.
30         :param hi_ip4_addr: The upper limit of the IP addresses.
31         :type node: dict
32         :type lo_ip4_addr: str
33         :type hi_ip4_addr: str
34         """
35         with VatTerminal(node) as vat:
36             vat.vat_terminal_exec_cmd_from_template("add_proxy_arp.vat",
37                                                     lo_ip4_addr=lo_ip4_addr,
38                                                     hi_ip4_addr=hi_ip4_addr)
39
40     @staticmethod
41     def vpp_proxy_arp_interface_enable(node, interface):
42         """Enable proxy ARP on interface.
43
44         :param node: VPP node to enable proxy ARP on interface.
45         :param interface: Interface to enable proxy ARP.
46         :type node: dict
47         :type interface: str or int
48         """
49
50         cmd = 'proxy_arp_intfc_enable_disable'
51         args = dict(
52             sw_if_index=InterfaceUtil.get_interface_index(node, interface),
53             enable_disable=1)
54         err_msg = 'Failed to enable proxy ARP on interface {ifc}'.format(
55             ifc=interface)
56         with PapiExecutor(node) as papi_exec:
57             papi_exec.add(cmd, **args).get_replies(err_msg). \
58                 verify_reply(err_msg=err_msg)