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 """SPAN setup library"""
16 from resources.libraries.python.topology import Topology
17 from resources.libraries.python.PapiExecutor import PapiSocketExecutor
21 """Class contains methods for setting up SPAN mirroring on DUTs."""
28 def vpp_get_span_configuration(node, is_l2=False):
29 """Get full SPAN configuration from VPP node.
33 :param node: DUT node.
36 :returns: Full SPAN configuration as list. One list entry for every
37 source/destination interface pair.
40 cmd = "sw_interface_span_dump"
42 is_l2=1 if is_l2 else 0
44 with PapiSocketExecutor(node) as papi_exec:
45 details = papi_exec.add(cmd, **args).get_details()
50 def vpp_get_span_configuration_by_interface(node, dst_interface,
51 ret_format="sw_if_index"):
52 """Get a list of all interfaces currently being mirrored
53 to the specified interface.
57 :param node: DUT node.
58 :param dst_interface: Name, sw_if_index or key of interface.
59 :param ret_format: Optional. Desired format of returned interfaces.
61 :type dst_interface: str or int
62 :type ret_format: string
63 :returns: List of SPAN source interfaces for the provided destination
68 data = SPAN.vpp_get_span_configuration(node)
70 dst_int = Topology.convert_interface_reference(
71 node, dst_interface, "sw_if_index")
74 if item["sw_if_index_to"] == dst_int:
75 src_interfaces.append(item["sw_if_index_from"])
77 if ret_format != "sw_if_index":
79 Topology.convert_interface_reference(
80 node, interface, ret_format
81 ) for interface in src_interfaces]