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:
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 """IPv6 utilities library."""
16 from resources.libraries.python.InterfaceUtil import InterfaceUtil
17 from resources.libraries.python.IPUtil import IPUtil
18 from resources.libraries.python.PapiExecutor import PapiSocketExecutor
19 from resources.libraries.python.topology import NodeType
26 def vpp_ra_suppress_link_layer(node, interface):
27 """Suppress ICMPv6 router advertisement message for link scope address.
29 :param node: VPP node.
30 :param interface: Interface name.
34 cmd = u"sw_interface_ip6nd_ra_config"
36 sw_if_index=InterfaceUtil.get_interface_index(node, interface),
39 err_msg = f"Failed to suppress ICMPv6 router advertisement message " \
40 f"on interface {interface}"
42 with PapiSocketExecutor(node) as papi_exec:
43 papi_exec.add(cmd, **args).get_reply(err_msg)
46 def vpp_ra_send_after_interval(node, interface, interval=2):
47 """Setup vpp router advertisement(RA) in such way it sends RA packet
48 after every interval value.
50 :param node: VPP node.
51 :param interface: Interface name.
52 :param interval: Interval in seconds for RA resend.
57 cmd = u"sw_interface_ip6nd_ra_config"
59 sw_if_index=InterfaceUtil.get_interface_index(node, interface),
60 initial_interval=int(interval)
62 err_msg = f"Failed to set router advertisement interval " \
63 f"on interface {interface}"
65 with PapiSocketExecutor(node) as papi_exec:
66 papi_exec.add(cmd, **args).get_reply(err_msg)
69 def vpp_all_ra_suppress_link_layer(nodes):
70 """Suppress ICMPv6 router advertisement message for link scope address
71 on all VPP nodes in the topology.
73 :param nodes: Nodes of the test topology.
76 for node in nodes.values():
77 if node[u"type"] == NodeType.TG:
79 for port_k in node[u"interfaces"].keys():
80 ip6_addr_list = IPUtil.vpp_get_interface_ip_addresses(
84 IPv6Util.vpp_ra_suppress_link_layer(node, port_k)