1 # Copyright (c) 2021 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 """ADL utilities library."""
16 from resources.libraries.python.PapiExecutor import PapiSocketExecutor
17 from resources.libraries.python.topology import Topology
24 def adl_add_allowlist_entry(
25 node, interface, ip_version, fib_id, default_adl=0):
26 """Add adl allowlisted entry.
28 :param node: Node to add ADL allowlist on.
29 :param interface: Interface of the node where the ADL is added.
30 :param ip_version: IP version. 'ip4' and 'ip6' are valid values.
31 :param fib_id: Specify the fib table ID.
32 :param default_adl: 1 => enable non-ip4, non-ip6 filtration,
38 :type default_adl: int
39 :raises ValueError: If parameter 'ip_version' has incorrect value.
41 if ip_version not in (u"ip4", u"ip6"):
42 raise ValueError(u"IP version is not in correct format")
44 cmd = u"adl_allowlist_enable_disable"
45 err_msg = f"Failed to add ADL allowlist on interface {interface} " \
46 f"on host {node[u'host']}"
48 sw_if_index=Topology.get_interface_sw_index(node, interface),
50 ip4=bool(ip_version == u"ip4"),
51 ip6=bool(ip_version == u"ip6"),
52 default_adl=default_adl
55 with PapiSocketExecutor(node) as papi_exec:
56 papi_exec.add(cmd, **args).get_reply(err_msg)
59 def adl_interface_enable_or_disable(node, interface, state):
60 """Enable or disable ADL on the interface.
62 :param node: Node to add ADL allowlist on.
63 :param interface: Interface of the node where the ADL is added.
64 :param state: Enable or disable ADL on the interface.
68 :raises ValueError: If parameter 'state' has incorrect value.
71 if state in (u"enable", u"disable"):
72 enable = bool(state == u"enable")
74 raise ValueError(u"Possible state values are 'enable' or 'disable'")
76 cmd = u"adl_interface_enable_disable"
77 err_msg = f"Failed to enable/disable ADL on interface {interface} " \
78 f"on host {node[u'host']}"
80 sw_if_index=Topology.get_interface_sw_index(node, interface),
84 with PapiSocketExecutor(node) as papi_exec:
85 papi_exec.add(cmd, **args).get_reply(err_msg)