go.ligato.io/vpp-agent/v3@v3.5.0/tests/robot/libraries/interface/vxlan_utils.py (about) 1 import vpp_api 2 3 from robot.api import logger 4 5 6 def check_vxlan_tunnel_presence_from_api(data, src, dst, vni): 7 8 for iface in data: 9 if iface["src_address"] == src and iface["dst_address"] == dst and iface["vni"] == int(vni): 10 logger.trace("matched interface: {interface}".format(interface=iface)) 11 return True, iface["sw_if_index"] 12 else: 13 logger.debug( 14 "interface with:\n" 15 "src_addr: {src_address}\n" 16 "dst_addr: {dst_address}\n" 17 "vni: {vni}\n" 18 "not found in dump. Full dump:\n" 19 "{data}".format( 20 src_address=src, dst_address=dst, vni=vni, data=data)) 21 22 23 def vxlan_tunnel_dump(host, username, password, node): 24 25 # Use max uint32 value to dump all tunnels 26 int_max = 4294967295 27 28 data = vpp_api.vpp_api.execute_api( 29 host, username, password, node, "vxlan_tunnel_dump", sw_if_index=int_max) 30 31 interfaces = [] 32 for interface in data[0]["api_reply"]: 33 interfaces.append(process_vxlan_dump(interface)) 34 35 return interfaces 36 37 38 def process_vxlan_dump(data): 39 """ 40 Process API reply acl_dump and return dictionary of usable values. 41 42 :param data: API reply from acl_dump call, 43 :type data: dict 44 :return: Values ready for comparison with Agent or ETCD values. 45 :rtype: dict 46 """ 47 48 if len(data) > 1: 49 logger.debug(len(data)) 50 logger.trace(data) 51 raise RuntimeError("Data contains more than one API reply.") 52 53 data = data["vxlan_tunnel_details"] 54 55 index = int(data["sw_if_index"]) 56 mcast_index = int(data["mcast_sw_if_index"]) 57 58 ipv6 = int(data["is_ipv6"]) 59 60 if ipv6: 61 destination_address = data["dst_address"]["ipv6"] 62 source_address = data["src_address"]["ipv6"] 63 else: 64 destination_address = data["dst_address"]["ipv4"] 65 source_address = data["src_address"]["ipv4"] 66 67 vrf_id = int(data["encap_vrf_id"]) 68 vni = int(data["vni"]) 69 70 next_index = int(data["decap_next_index"]) 71 72 instance = int(data["instance"]) 73 74 output = { 75 "sw_if_index": index, 76 "ipv6": ipv6, 77 "vrf": vrf_id, 78 "vni": vni, 79 "dst_address": destination_address, 80 "src_address": source_address, 81 "next_index": next_index, 82 "mcast_index": mcast_index, 83 "instance": instance 84 } 85 86 return output 87 88 89 def filter_vxlan_tunnel_dump_by_index(data, index): 90 for item in data: 91 if int(item["sw_if_index"]) == int(index): 92 return item 93 else: 94 raise RuntimeError("ACL not found by sw_if_index {index}.".format(index=index))