diff options
-rw-r--r-- | resources/api/vpp/supported_crcs.yaml | 58 | ||||
-rw-r--r-- | resources/libraries/python/IPUtil.py | 71 | ||||
-rw-r--r-- | resources/libraries/python/IPsecUtil.py | 56 | ||||
-rw-r--r-- | resources/libraries/python/InterfaceUtil.py | 140 | ||||
-rw-r--r-- | resources/libraries/python/TestConfig.py | 27 | ||||
-rw-r--r-- | resources/libraries/python/VPPUtil.py | 17 |
6 files changed, 257 insertions, 112 deletions
diff --git a/resources/api/vpp/supported_crcs.yaml b/resources/api/vpp/supported_crcs.yaml index 677efd9d98..20cfe549b3 100644 --- a/resources/api/vpp/supported_crcs.yaml +++ b/resources/api/vpp/supported_crcs.yaml @@ -45,6 +45,10 @@ avf_create_reply: '0xfda5941f' # perf # ^^ tc01-64B-1c-avf-eth-l2bdbasemaclrn-mrr # ^ l2bdmaclrnANDbaseANDdrv_avf + bond_create: '0xf19b4ad0' # perf + bond_create_reply: '0xfda5941f' # perf + bond_enslave: '0x0ded34f6' # perf + bond_enslave_reply: '0xe8d4e804' # perf bridge_domain_add_del: '0xc6360720' # dev bridge_domain_add_del_reply: '0xe8d4e804' # dev classify_add_del_session: '0x85fd79f4' # dev @@ -57,14 +61,14 @@ cop_interface_enable_disable_reply: '0xe8d4e804' # dev cop_whitelist_enable_disable: '0x8bb8f6dc' # dev cop_whitelist_enable_disable_reply: '0xe8d4e804' # dev - create_loopback: '0x3b54129c' # dev - create_loopback_reply: '0xfda5941f' # dev - create_subif: '0x86cfe408' # virl - create_subif_reply: '0xfda5941f' # virl + create_loopback: '0x16e13d38' # dev + create_loopback_reply: '0x903324db' # dev + create_subif: '0xa51a5dd3' # virl + create_subif_reply: '0x903324db' # virl create_vhost_user_if: '0xa3438cd4' # dev create_vhost_user_if_reply: '0xfda5941f' # dev - create_vlan_subif: '0x70cadeda' # virl - create_vlan_subif_reply: '0xfda5941f' # virl + create_vlan_subif: '0xbc534dd3' # virl + create_vlan_subif_reply: '0x903324db' # virl gbp_bridge_domain_add: '0x70f1069c' # perf gbp_bridge_domain_add_reply: '0xe8d4e804' # perf gbp_route_domain_add: '0x355b67c0' # perf @@ -83,7 +87,7 @@ gre_tunnel_add_del_reply: '0x903324db' # virl gpe_enable_disable: '0xeb0e943b' # virl gpe_enable_disable_reply: '0xe8d4e804' # virl - hw_interface_set_mtu: '0x132da1e7' # dev + hw_interface_set_mtu: '0xe6c533aa' # dev hw_interface_set_mtu_reply: '0xe8d4e804' # dev input_acl_set_interface: '0xe09537b0' # dev input_acl_set_interface_reply: '0xe8d4e804' # dev @@ -106,6 +110,8 @@ ipsec_spd_add_del_reply: '0xe8d4e804' # dev ipsec_spd_entry_add_del: '0x6bc6a3b5' # dev ipsec_spd_entry_add_del_reply: '0x9ffac24b' # dev + ipsec_tunnel_if_add_del: '0xaa539b47' # perf + ipsec_tunnel_if_add_del_reply: '0xfda5941f' # perf l2_interface_vlan_tag_rewrite: '0xb90be6b4' # virl l2_interface_vlan_tag_rewrite_reply: '0xe8d4e804' # virl l2_patch_add_del: '0x62506e63' # perf @@ -130,6 +136,13 @@ lisp_locator_set_dump: '0xc79e8ab0' # virl lisp_map_resolver_details: '0x60a5f5ca' # virl lisp_map_resolver_dump: '0x51077d14' # virl + macip_acl_add: '0x0c680ca5' # perf + macip_acl_add_reply: '0xac407b0c' # perf + macip_acl_details: '0xe164e69a' # perf + macip_acl_dump: '0xef34fea4' # perf + macip_acl_interface_add_del: '0x6a6be97c' # perf + macip_acl_interface_get: '0x51077d14' # perf + macip_acl_interface_get_reply: '0xaccf9b05' # perf memif_create: '0x6597cdb2' # dev memif_create_reply: '0xfda5941f' # dev memif_details: '0x4f5a3397' # dev @@ -150,28 +163,43 @@ show_threads_reply: '0xf5e0b66f' # dev show_version: '0x51077d14' # dev setup show_version_reply: '0xb9bcf6df' # dev setup - sw_interface_add_del_address: '0x7b583179' # dev + sr_localsid_add_del: '0xb30489eb' # perf + sr_localsid_add_del_reply: '0xe8d4e804' + sr_localsids_dump: '0x51077d14' # perf + sr_policies_details: '0x5087f460' # perf + sr_policies_dump: '0x51077d14' # perf + sr_policy_add: '0x4b6e2484' # perf + sr_policy_add_reply: '0xe8d4e804' # perf + sr_policy_del_reply: '0xe8d4e804' # perf + sr_set_encap_source: '0xd05bb4de' # perf + sr_steering_add_del: '0x28b5dcab' # perf + sr_steering_add_del_reply: '0xe8d4e804' # perf + sr_steering_pol_details: '0x5627d483' # perf + sr_steering_pol_dump: '0x51077d14' # perf + sw_interface_add_del_address: '0x43a487bd' # dev sw_interface_add_del_address_reply: '0xe8d4e804' # dev - sw_interface_details: '0xe4ee7eb6' # dev setup - sw_interface_dump: '0x052753c5' # dev setup + sw_interface_details: '0x156a9465' # dev setup + sw_interface_dump: '0xe116dcdc' # dev setup sw_interface_ip6nd_ra_config: '0xc3f02daa' # dev sw_interface_ip6nd_ra_config_reply: '0xe8d4e804' # dev - sw_interface_rx_placement_details: '0x0e9e33f4' # perf - sw_interface_rx_placement_dump: '0x529cb13f' # perf + sw_interface_rx_placement_details: '0x93d413ec' # perf + sw_interface_rx_placement_dump: '0xd85aab0d' # perf # ^^ tc01-64B-1c-dot1q-l2bdbasemaclrn-eth-2memif-1dcr-mrr # ^ dot1qANDl2bdmaclrnANDbaseANDmemif - sw_interface_set_flags: '0x555485f5' # dev + sw_interface_set_flags: '0xb2dc5eb2' # dev sw_interface_set_flags_reply: '0xe8d4e804' # dev sw_interface_set_l2_bridge: '0x5579f809' # dev sw_interface_set_l2_bridge_reply: '0xe8d4e804' # dev sw_interface_set_l2_xconnect: '0x95de3988' # dev sw_interface_set_l2_xconnect_reply: '0xe8d4e804' # dev - sw_interface_set_rx_placement: '0x4ef4377d' # perf + sw_interface_set_rx_placement: '0xe462d0d9' # perf sw_interface_set_rx_placement_reply: '0xe8d4e804' # perf # ^^ tc01-64B-1c-eth-l2xcbase-eth-2memif-1dcr-mrr # ^ l2xcfwdANDbaseANDlxcANDmemif - sw_interface_set_table: '0xacb25d89' # dev + sw_interface_set_table: '0x2d412a82' # dev sw_interface_set_table_reply: '0xe8d4e804' # dev + sw_interface_set_unnumbered: '0x61e660a5' # perf + sw_interface_set_unnumbered_reply: '0xe8d4e804' # perf sw_interface_set_vxlan_bypass: '0xe74ca095' # dev sw_interface_set_vxlan_bypass_reply: '0xe8d4e804' # dev sw_interface_tap_v2_dump: '0x51077d14' # dev diff --git a/resources/libraries/python/IPUtil.py b/resources/libraries/python/IPUtil.py index 2109997e99..de018b9565 100644 --- a/resources/libraries/python/IPUtil.py +++ b/resources/libraries/python/IPUtil.py @@ -149,7 +149,9 @@ class IPUtil(object): """Get dump of all IP FIB tables on a VPP node. :param node: VPP node. + :param address: IP address. :type node: dict + :type address: str """ addr = ip_address(unicode(address)) @@ -174,11 +176,11 @@ class IPUtil(object): """ sw_if_index = InterfaceUtil.get_interface_index(node, interface) - is_ipv6 = 1 if ip_version == 'ipv6' else 0 - cmd = 'sw_interface_get_table' - args = dict(sw_if_index=sw_if_index, - is_ipv6=is_ipv6) + args = dict( + sw_if_index=sw_if_index, + is_ipv6=True if ip_version == 'ipv6' else False + ) err_msg = 'Failed to get VRF id assigned to interface {ifc}'.format( ifc=interface) @@ -200,7 +202,8 @@ class IPUtil(object): args = dict( sw_if_index=InterfaceUtil.get_interface_index(node, if_name), is_add=1, - loose=0) + loose=0 + ) err_msg = 'Failed to enable source check on interface {ifc}'.format( ifc=if_name) with PapiSocketExecutor(node) as papi_exec: @@ -393,12 +396,13 @@ class IPUtil(object): cmd = 'sw_interface_add_del_address' args = dict( sw_if_index=InterfaceUtil.get_interface_index(node, interface), - is_add=1, - is_ipv6=1 if ip_addr.version == 6 else 0, - del_all=0, - address_length=int(prefix_length) if prefix_length else 128 - if ip_addr.version == 6 else 32, - address=ip_addr.packed) + is_add=True, + del_all=False, + prefix=IPUtil.create_prefix_object( + ip_addr, + prefix_length if prefix_length else 128 + if ip_addr.version == 6 else 32) + ) err_msg = 'Failed to add IP address on interface {ifc}'.format( ifc=interface) with PapiSocketExecutor(node) as papi_exec: @@ -461,6 +465,24 @@ class IPUtil(object): un=IPUtil.union_addr(ip_addr)) @staticmethod + def create_prefix_object(ip_addr, addr_len): + """Create prefix object. + + :param ip_addr: IPv4 or IPv6 address. + :para, addr_len: Length of IP address. + :type ip_addr: IPv4Address or IPv6Address + :type addr_len: int + :returns: Prefix object. + :rtype: dict + """ + addr = IPUtil.create_ip_address_object(ip_addr) + + return dict( + len=int(addr_len), + address=addr + ) + + @staticmethod def compose_vpp_route_structure(node, network, prefix_len, **kwargs): """Create route object for ip_route_add_del api call. @@ -491,17 +513,15 @@ class IPUtil(object): net_addr = ip_address(unicode(network)) - addr = IPUtil.create_ip_address_object(net_addr) - prefix = dict( - len=int(prefix_len), - address=addr) + prefix = IPUtil.create_prefix_object(net_addr, prefix_len) paths = list() n_hop = dict( address=IPUtil.union_addr(ip_address(unicode(gateway))) if gateway else 0, via_label=MPLS_LABEL_INVALID, - obj_id=Constants.BITWISE_NON_ZERO) + obj_id=Constants.BITWISE_NON_ZERO + ) path = dict( sw_if_index=InterfaceUtil.get_interface_index(node, interface) if interface else Constants.BITWISE_NON_ZERO, @@ -520,14 +540,16 @@ class IPUtil(object): else 'FIB_PATH_NH_PROTO_IP4').value, nh=n_hop, n_labels=0, - label_stack=list(0 for _ in range(16))) + label_stack=list(0 for _ in range(16)) + ) paths.append(path) route = dict( table_id=int(kwargs.get('vrf', 0)), prefix=prefix, n_paths=len(paths), - paths=paths) + paths=paths + ) return route @staticmethod @@ -578,19 +600,18 @@ class IPUtil(object): net_addr = ip_address(unicode(network)) cmd = 'ip_route_add_del' - route = IPUtil.compose_vpp_route_structure( - node, network, prefix_len, **kwargs) args = dict( is_add=1, is_multipath=int(kwargs.get('multipath', False)), - route=route) + route=None + ) err_msg = 'Failed to add route(s) on host {host}'.format( host=node['host']) with PapiSocketExecutor(node) as papi_exec: for i in xrange(kwargs.get('count', 1)): - args['route']['prefix']['address']['un'] = \ - IPUtil.union_addr(net_addr + i) + args['route'] = IPUtil.compose_vpp_route_structure( + node, net_addr + i, prefix_len, **kwargs) history = False if 1 < i < kwargs.get('count', 1) else True papi_exec.add(cmd, history=history, **args) papi_exec.get_replies(err_msg) @@ -607,7 +628,9 @@ class IPUtil(object): cmd = 'sw_interface_add_del_address' args = dict( sw_if_index=InterfaceUtil.get_interface_index(node, interface), - del_all=1) + is_add=False, + del_all=True + ) err_msg = 'Failed to flush IP address on interface {ifc}'.format( ifc=interface) with PapiSocketExecutor(node) as papi_exec: diff --git a/resources/libraries/python/IPsecUtil.py b/resources/libraries/python/IPsecUtil.py index dd6ba181e8..c109f417e5 100644 --- a/resources/libraries/python/IPsecUtil.py +++ b/resources/libraries/python/IPsecUtil.py @@ -22,7 +22,8 @@ from enum import Enum, IntEnum from ipaddress import ip_network, ip_address from resources.libraries.python.IPUtil import IPUtil -from resources.libraries.python.InterfaceUtil import InterfaceUtil +from resources.libraries.python.InterfaceUtil import InterfaceUtil, \ + InterfaceStatusFlags from resources.libraries.python.PapiExecutor import PapiSocketExecutor from resources.libraries.python.topology import Topology from resources.libraries.python.VatExecutor import VatExecutor @@ -518,11 +519,9 @@ class IPsecUtil(object): cmd1 = 'sw_interface_add_del_address' args1 = dict( sw_if_index=InterfaceUtil.get_interface_index(node, interface), - is_add=1, - is_ipv6=1 if laddr.version == 6 else 0, - del_all=0, - address_length=raddr_range, - address=None + is_add=True, + del_all=False, + prefix=None ) cmd2 = 'ip_route_add_del' args2 = dict( @@ -536,7 +535,8 @@ class IPsecUtil(object): with PapiSocketExecutor(node) as papi_exec: for i in xrange(n_tunnels): - args1['address'] = getattr(laddr + i * addr_incr, 'packed') + args1['prefix'] = IPUtil.create_prefix_object( + laddr + i * addr_incr, raddr_range) args2['route'] = IPUtil.compose_vpp_route_structure( node, taddr + i, @@ -951,7 +951,7 @@ class IPsecUtil(object): cmd1 = 'sw_interface_set_flags' args1 = dict( sw_if_index=loop_sw_if_idx, - admin_up_down=1) + flags=InterfaceStatusFlags.IF_STATUS_API_FLAG_ADMIN_UP.value) err_msg = 'Failed to set loopback interface state up on host ' \ '{host}'.format(host=nodes['DUT1']['host']) papi_exec.add(cmd1, **args1).get_reply(err_msg) @@ -960,22 +960,21 @@ class IPsecUtil(object): args1 = dict( sw_if_index=InterfaceUtil.get_interface_index( nodes['DUT1'], if1_key), - is_add=1, - is_ipv6=1 if if2_ip.version == 6 else 0, - del_all=0, - address_length=96 if if2_ip.version == 6 else 24, - address=getattr(if2_ip - 1, 'packed')) + is_add=True, + del_all=False, + prefix=IPUtil.create_prefix_object( + if2_ip - 1, 96 if if2_ip.version == 6 else 24) + ) err_msg = 'Failed to set IP address on interface {ifc} on host ' \ '{host}'.format(ifc=if1_key, host=nodes['DUT1']['host']) papi_exec.add(cmd1, **args1).get_reply(err_msg) # Configure IPsec tunnel interfaces args1 = dict( sw_if_index=loop_sw_if_idx, - is_add=1, - is_ipv6=1 if if1_ip.version == 6 else 0, - del_all=0, - address_length=128 if if1_ip.version == 6 else 32, - address='') + is_add=True, + del_all=False, + prefix=None + ) cmd2 = 'ipsec_tunnel_if_add_del' args2 = dict( is_add=1, @@ -1006,7 +1005,8 @@ class IPsecUtil(object): if integ_alg: ikeys.append( gen_key(IPsecUtil.get_integ_alg_key_len(integ_alg))) - args1['address'] = getattr(if1_ip + i * addr_incr, 'packed') + args1['prefix'] = IPUtil.create_prefix_object( + if1_ip + i * addr_incr, 128 if if1_ip.version == 6 else 32) args2['local_spi'] = spi_1 + i args2['remote_spi'] = spi_2 + i args2['local_ip'] = IPUtil.create_ip_address_object( @@ -1031,7 +1031,7 @@ class IPsecUtil(object): # Configure IP routes cmd1 = 'sw_interface_set_unnumbered' args1 = dict( - is_add=1, + is_add=True, sw_if_index=InterfaceUtil.get_interface_index( nodes['DUT1'], if1_key), unnumbered_sw_if_index=0 @@ -1039,7 +1039,7 @@ class IPsecUtil(object): cmd2 = 'sw_interface_set_flags' args2 = dict( sw_if_index=0, - admin_up_down=1) + flags=InterfaceStatusFlags.IF_STATUS_API_FLAG_ADMIN_UP.value) cmd3 = 'ip_route_add_del' args3 = dict( is_add=1, @@ -1069,11 +1069,11 @@ class IPsecUtil(object): args1 = dict( sw_if_index=InterfaceUtil.get_interface_index( nodes['DUT2'], if2_key), - is_add=1, - is_ipv6=1 if if2_ip.version == 6 else 0, - del_all=0, - address_length=96 if if2_ip.version == 6 else 24, - address=if2_ip.packed) + is_add=True, + del_all=False, + prefix=IPUtil.create_prefix_object( + if2_ip, 96 if if2_ip.version == 6 else 24) + ) err_msg = 'Failed to set IP address on interface {ifc} on host ' \ '{host}'.format(ifc=if2_key, host=nodes['DUT2']['host']) papi_exec.add(cmd1, **args1).get_reply(err_msg) @@ -1137,7 +1137,7 @@ class IPsecUtil(object): papi_exec.add(cmd1, **args1) cmd1 = 'sw_interface_set_unnumbered' args1 = dict( - is_add=1, + is_add=True, sw_if_index=InterfaceUtil.get_interface_index( nodes['DUT2'], if2_key), unnumbered_sw_if_index=0 @@ -1145,7 +1145,7 @@ class IPsecUtil(object): cmd2 = 'sw_interface_set_flags' args2 = dict( sw_if_index=0, - admin_up_down=1) + flags=InterfaceStatusFlags.IF_STATUS_API_FLAG_ADMIN_UP.value) cmd3 = 'ip_route_add_del' args3 = dict( is_add=1, diff --git a/resources/libraries/python/InterfaceUtil.py b/resources/libraries/python/InterfaceUtil.py index 982a345ef2..81dd20dc32 100644 --- a/resources/libraries/python/InterfaceUtil.py +++ b/resources/libraries/python/InterfaceUtil.py @@ -30,6 +30,61 @@ from resources.libraries.python.topology import NodeType, Topology from resources.libraries.python.VPPUtil import VPPUtil +class InterfaceStatusFlags(IntEnum): + """Interface status falgs.""" + IF_STATUS_API_FLAG_ADMIN_UP = 1 + IF_STATUS_API_FLAG_LINK_UP = 2 + + +class MtuProto(IntEnum): + """MTU protocol.""" + MTU_PROTO_API_L3 = 0 + MTU_PROTO_API_IP4 = 1 + MTU_PROTO_API_IP6 = 2 + MTU_PROTO_API_MPLS = 3 + MTU_PROTO_API_N = 4 + + +class LinkDuplex(IntEnum): + """Link duplex""" + LINK_DUPLEX_API_UNKNOWN = 0 + LINK_DUPLEX_API_HALF = 1 + LINK_DUPLEX_API_FULL = 2 + + +class SubInterfaceFlags(IntEnum): + """Sub-interface flags.""" + SUB_IF_API_FLAG_NO_TAGS = 1 + SUB_IF_API_FLAG_ONE_TAG = 2 + SUB_IF_API_FLAG_TWO_TAGS = 4 + SUB_IF_API_FLAG_DOT1AD = 8 + SUB_IF_API_FLAG_EXACT_MATCH = 16 + SUB_IF_API_FLAG_DEFAULT = 32 + SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY = 64 + SUB_IF_API_FLAG_INNER_VLAN_ID_ANY = 128 + SUB_IF_API_FLAG_DOT1AH = 256 + + +class RxMode(IntEnum): + """RX mode""" + RX_MODE_API_UNKNOWN = 0 + RX_MODE_API_POLLING = 1 + RX_MODE_API_INTERRUPT = 2 + RX_MODE_API_ADAPTIVE = 3 + RX_MODE_API_DEFAULT = 4 + + +class IfType(IntEnum): + """Interface type""" + # A hw interface + IF_API_TYPE_HARDWARE = 0 + # A sub-interface + IF_API_TYPE_SUB = 1 + IF_API_TYPE_P2P = 2 + IF_API_TYPE_PIPE = 3 + + +# pylint: disable=invalid-name class LinkBondLoadBalance(IntEnum): """Link bonding load balance.""" L2 = 0 # pylint: disable=invalid-name @@ -126,17 +181,18 @@ class InterfaceUtil(object): if node['type'] == NodeType.DUT: if state == 'up': - admin_up_down = 1 + flags = InterfaceStatusFlags.IF_STATUS_API_FLAG_ADMIN_UP.value elif state == 'down': - admin_up_down = 0 + flags = 0 else: raise ValueError('Unexpected interface state: {state}'.format( state=state)) cmd = 'sw_interface_set_flags' err_msg = 'Failed to set interface state on host {host}'.format( host=node['host']) - args = dict(sw_if_index=sw_if_index, - admin_up_down=admin_up_down) + args = dict( + sw_if_index=sw_if_index, + flags=flags) with PapiSocketExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg) elif node['type'] == NodeType.TG or node['type'] == NodeType.VM: @@ -258,13 +314,12 @@ class InterfaceUtil(object): not_ready = list() out = InterfaceUtil.vpp_get_interface_data(node) for interface in out: - if interface.get('admin_up_down') == 1: - if interface.get('link_up_down') != 1: - not_ready.append(interface.get('interface_name')) + if interface.get('flags') == 1: + not_ready.append(interface.get('interface_name')) if not not_ready: break else: - logger.debug('Interfaces still in link-down state:\n{ifs} ' + logger.debug('Interfaces still not in link-up state:\n{ifs} ' '\nWaiting...'.format(ifs=not_ready)) sleep(1) else: @@ -312,11 +367,16 @@ class InterfaceUtil(object): :returns: Processed interface dump. :rtype: dict """ - if_dump['interface_name'] = if_dump['interface_name'].rstrip('\x00') - if_dump['tag'] = if_dump['tag'].rstrip('\x00') - if_dump['l2_address'] = L2Util.bin_to_mac(if_dump['l2_address']) - if_dump['b_dmac'] = L2Util.bin_to_mac(if_dump['b_dmac']) - if_dump['b_smac'] = L2Util.bin_to_mac(if_dump['b_smac']) + if_dump['l2_address'] = str(if_dump['l2_address']) + if_dump['b_dmac'] = str(if_dump['b_dmac']) + if_dump['b_smac'] = str(if_dump['b_smac']) + if_dump['flags'] = if_dump['flags'].value + if_dump['type'] = if_dump['type'].value + if_dump['link_duplex'] = if_dump['link_duplex'].value + if_dump['sub_if_flags'] = if_dump['sub_if_flags'].value \ + if hasattr(if_dump['sub_if_flags'], 'value') \ + else int(if_dump['sub_if_flags']) + return if_dump if interface is not None: @@ -331,12 +391,15 @@ class InterfaceUtil(object): param = '' cmd = 'sw_interface_dump' - args = dict(name_filter_valid=0, - name_filter='') + args = dict( + name_filter_valid=False, + name_filter='' + ) err_msg = 'Failed to get interface dump on host {host}'.format( host=node['host']) with PapiSocketExecutor(node) as papi_exec: details = papi_exec.add(cmd, **args).get_details(err_msg) + logger.debug('Received data:\n{d!r}'.format(d=details)) data = list() if interface is None else dict() for dump in details: @@ -724,8 +787,10 @@ class InterfaceUtil(object): sw_if_index = InterfaceUtil.get_interface_index(node, interface) cmd = 'create_vlan_subif' - args = dict(sw_if_index=sw_if_index, - vlan_id=int(vlan)) + args = dict( + sw_if_index=sw_if_index, + vlan_id=int(vlan) + ) err_msg = 'Failed to create VLAN sub-interface on host {host}'.format( host=node['host']) with PapiSocketExecutor(node) as papi_exec: @@ -930,20 +995,31 @@ class InterfaceUtil(object): """ subif_types = type_subif.split() + flags = 0 + if 'no_tags' in subif_types: + flags = flags | SubInterfaceFlags.SUB_IF_API_FLAG_NO_TAGS + if 'one_tag' in subif_types: + flags = flags | SubInterfaceFlags.SUB_IF_API_FLAG_ONE_TAG + if 'two_tags' in subif_types: + flags = flags | SubInterfaceFlags.SUB_IF_API_FLAG_TWO_TAGS + if 'dot1ad' in subif_types: + flags = flags | SubInterfaceFlags.SUB_IF_API_FLAG_DOT1AD + if 'exact_match' in subif_types: + flags = flags | SubInterfaceFlags.SUB_IF_API_FLAG_EXACT_MATCH + if 'default_sub' in subif_types: + flags = flags | SubInterfaceFlags.SUB_IF_API_FLAG_DEFAULT + if type_subif == 'default_sub': + flags = flags | SubInterfaceFlags.SUB_IF_API_FLAG_INNER_VLAN_ID_ANY\ + | SubInterfaceFlags.SUB_IF_API_FLAG_OUTER_VLAN_ID_ANY + cmd = 'create_subif' args = dict( sw_if_index=InterfaceUtil.get_interface_index(node, interface), sub_id=int(sub_id), - no_tags=1 if 'no_tags' in subif_types else 0, - one_tag=1 if 'one_tag' in subif_types else 0, - two_tags=1 if 'two_tags' in subif_types else 0, - dot1ad=1 if 'dot1ad' in subif_types else 0, - exact_match=1 if 'exact_match' in subif_types else 0, - default_sub=1 if 'default_sub' in subif_types else 0, - outer_vlan_id_any=1 if type_subif == 'default_sub' else 0, - inner_vlan_id_any=1 if type_subif == 'default_sub' else 0, + sub_if_flags=flags.value if hasattr(flags, 'value') else int(flags), outer_vlan_id=int(outer_vlan_id) if outer_vlan_id else 0, - inner_vlan_id=int(inner_vlan_id) if inner_vlan_id else 0) + inner_vlan_id=int(inner_vlan_id) if inner_vlan_id else 0 + ) err_msg = 'Failed to create sub-interface on host {host}'.format( host=node['host']) with PapiSocketExecutor(node) as papi_exec: @@ -996,7 +1072,7 @@ class InterfaceUtil(object): """Create loopback interface on VPP node. :param node: Node to create loopback interface on. - :param mac: Optional MAC address for Loopback interface. + :param mac: Optional MAC address for loopback interface. :type node: dict :type mac: str :returns: SW interface index. @@ -1378,7 +1454,7 @@ class InterfaceUtil(object): cmd = 'sw_interface_set_table' args = dict( sw_if_index=InterfaceUtil.get_interface_index(node, interface), - is_ipv6=1 if ipv6 else 0, + is_ipv6=ipv6, vrf_id=int(table_id)) err_msg = 'Failed to assign interface {ifc} to FIB table'.format( ifc=interface) @@ -1567,8 +1643,12 @@ class InterfaceUtil(object): cmd = 'sw_interface_set_rx_placement' err_msg = "Failed to set interface RX placement to worker on host " \ "{host}!".format(host=node['host']) - args = dict(sw_if_index=sw_if_index, queue_id=queue_id, - worker_id=worker_id) + args = dict( + sw_if_index=sw_if_index, + queue_id=queue_id, + worker_id=worker_id, + is_main=False + ) with PapiSocketExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg) diff --git a/resources/libraries/python/TestConfig.py b/resources/libraries/python/TestConfig.py index 5887c11a9f..48f67e5a0f 100644 --- a/resources/libraries/python/TestConfig.py +++ b/resources/libraries/python/TestConfig.py @@ -17,7 +17,8 @@ from ipaddress import ip_address, AddressValueError from robot.api import logger from resources.libraries.python.Constants import Constants -from resources.libraries.python.InterfaceUtil import InterfaceUtil +from resources.libraries.python.InterfaceUtil import InterfaceUtil, \ + InterfaceStatusFlags from resources.libraries.python.IPUtil import IPUtil from resources.libraries.python.PapiExecutor import PapiSocketExecutor from resources.libraries.python.topology import Topology @@ -145,11 +146,10 @@ class TestConfig(object): cmd1 = 'sw_interface_add_del_address' args1 = dict( sw_if_index=InterfaceUtil.get_interface_index(node, node_vxlan_if), - is_add=1, - is_ipv6=1 if src_ip_addr_start.version == 6 else 0, - del_all=0, - address_length=128 if src_ip_addr_start.version == 6 else 32, - address=None) + is_add=True, + del_all=False, + prefix=None + ) cmd2 = 'vxlan_add_del_tunnel' args2 = dict( is_add=1, @@ -160,12 +160,14 @@ class TestConfig(object): mcast_sw_if_index=Constants.BITWISE_NON_ZERO, encap_vrf_id=0, decap_next_index=Constants.BITWISE_NON_ZERO, - vni=None) + vni=None + ) cmd3 = 'create_vlan_subif' args3 = dict( sw_if_index=InterfaceUtil.get_interface_index( node, node_vlan_if), - vlan_id=None) + vlan_id=None + ) with PapiSocketExecutor(node) as papi_exec: for i in xrange(0, vxlan_count): @@ -177,7 +179,8 @@ class TestConfig(object): "has been reached.") vxlan_count = i break - args1['address'] = getattr(src_ip, 'packed') + args1['prefix'] = IPUtil.create_prefix_object( + src_ip, 128 if src_ip_addr_start.version == 6 else 32) args2['src_address'] = getattr(src_ip, 'packed') args2['dst_address'] = getattr(dst_ip, 'packed') args2['vni'] = int(vni_start) + i @@ -250,10 +253,12 @@ class TestConfig(object): cmd = 'sw_interface_set_flags' args1 = dict( sw_if_index=None, - admin_up_down=1) + flags=InterfaceStatusFlags.IF_STATUS_API_FLAG_ADMIN_UP.value + ) args2 = dict( sw_if_index=None, - admin_up_down=1) + flags=InterfaceStatusFlags.IF_STATUS_API_FLAG_ADMIN_UP.value + ) with PapiSocketExecutor(node) as papi_exec: for i in xrange(0, vxlan_count): diff --git a/resources/libraries/python/VPPUtil.py b/resources/libraries/python/VPPUtil.py index 8b7b6891ac..8f9b593902 100644 --- a/resources/libraries/python/VPPUtil.py +++ b/resources/libraries/python/VPPUtil.py @@ -193,16 +193,25 @@ class VPPUtil(object): """ cmd = 'sw_interface_dump' - args = dict(name_filter_valid=0, name_filter='') + args = dict( + name_filter_valid=False, + name_filter='' + ) err_msg = 'Failed to get interface dump on host {host}'.format( host=node['host']) with PapiSocketExecutor(node) as papi_exec: details = papi_exec.add(cmd, **args).get_details(err_msg) for if_dump in details: - if_dump['interface_name'] = if_dump['interface_name'].rstrip('\x00') - if_dump['tag'] = if_dump['tag'].rstrip('\x00') - if_dump['l2_address'] = L2Util.bin_to_mac(if_dump['l2_address']) + if_dump['l2_address'] = str(if_dump['l2_address']) + if_dump['b_dmac'] = str(if_dump['b_dmac']) + if_dump['b_smac'] = str(if_dump['b_smac']) + if_dump['flags'] = if_dump['flags'].value + if_dump['type'] = if_dump['type'].value + if_dump['link_duplex'] = if_dump['link_duplex'].value + if_dump['sub_if_flags'] = if_dump['sub_if_flags'].value \ + if hasattr(if_dump['sub_if_flags'], 'value') \ + else int(if_dump['sub_if_flags']) # TODO: return only base data logger.trace('Interface data of host {host}:\n{details}'.format( host=node['host'], details=details)) |