PapiExecutor always verifies
[csit.git] / resources / libraries / python / IPv6Util.py
1 # Copyright (c) 2019 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 """IPv6 utilities library."""
15
16 from resources.libraries.python.InterfaceUtil import InterfaceUtil
17 from resources.libraries.python.IPUtil import IPUtil
18 from resources.libraries.python.PapiExecutor import PapiExecutor
19 from resources.libraries.python.topology import NodeType
20
21
22 class IPv6Util(object):
23     """IPv6 utilities"""
24
25     @staticmethod
26     def vpp_ra_suppress_link_layer(node, interface):
27         """Suppress ICMPv6 router advertisement message for link scope address.
28
29         :param node: VPP node.
30         :param interface: Interface name.
31         :type node: dict
32         :type interface: str
33         """
34         cmd = 'sw_interface_ip6nd_ra_config'
35         args = dict(
36             sw_if_index=InterfaceUtil.get_interface_index(node, interface),
37             suppress=1)
38         err_msg = 'Failed to suppress ICMPv6 router advertisement message on ' \
39                   'interface {ifc}'.format(ifc=interface)
40
41         with PapiExecutor(node) as papi_exec:
42             papi_exec.add(cmd, **args).get_reply(err_msg)
43
44     @staticmethod
45     def vpp_ra_send_after_interval(node, interface, interval=2):
46         """Setup vpp router advertisement(RA) in such way it sends RA packet
47         after every interval value.
48
49         :param node: VPP node.
50         :param interface: Interface name.
51         :param interval: Interval in seconds for RA resend.
52         :type node: dict
53         :type interface: str
54         :type interval: int
55         """
56         cmd = 'sw_interface_ip6nd_ra_config'
57         args = dict(
58             sw_if_index=InterfaceUtil.get_interface_index(node, interface),
59             initial_interval=int(interval))
60         err_msg = 'Failed to set router advertisement interval on ' \
61                   'interface {ifc}'.format(ifc=interface)
62
63         with PapiExecutor(node) as papi_exec:
64             papi_exec.add(cmd, **args).get_reply(err_msg)
65
66     @staticmethod
67     def vpp_all_ra_suppress_link_layer(nodes):
68         """Suppress ICMPv6 router advertisement message for link scope address
69         on all VPP nodes in the topology.
70
71         :param nodes: Nodes of the test topology.
72         :type nodes: dict
73         """
74         for node in nodes.values():
75             if node['type'] == NodeType.TG:
76                 continue
77             for port_k in node['interfaces'].keys():
78                 ip6_addr_list = IPUtil.vpp_get_interface_ip_addresses(
79                     node, port_k, 'ipv6')
80                 if ip6_addr_list:
81                     IPv6Util.vpp_ra_suppress_link_layer(node, port_k)