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 """COP utilities library."""
16 from resources.libraries.python.VatExecutor import VatTerminal
17 from resources.libraries.python.topology import Topology
24 def cop_add_whitelist_entry(node, interface, ip_format, fib_id):
25 """Add cop whitelisted entry.
27 :param node: Node to add COP whitelist on.
28 :param interface: Interface of the node where the COP is added.
29 :param ip_format: IP format : ip4 or ip6 are valid formats.
30 :param fib_id: Specify the fib table ID.
36 if ip_format not in ('ip4', 'ip6'):
37 raise ValueError("Ip not in correct format!")
38 sw_if_index = Topology.get_interface_sw_index(node, interface)
39 with VatTerminal(node) as vat:
40 vat.vat_terminal_exec_cmd_from_template('cop_whitelist.vat',
41 sw_if_index=sw_if_index,
46 def cop_interface_enable_or_disable(node, interface, state):
47 """Enable or disable COP on the interface.
49 :param node: Node to add COP whitelist on.
50 :param interface: Interface of the node where the COP is added.
51 :param state: disable/enable COP on the interface.
57 if state in ('enable', 'disable'):
60 sw_if_index = Topology.get_interface_sw_index(node, interface)
61 with VatTerminal(node) as vat:
62 vat.vat_terminal_exec_cmd_from_template('cop_interface.vat',
63 sw_if_index=sw_if_index,
67 "Possible values are 'enable' or 'disable'!"