def set_nat44_interfaces(node, int_in, int_out): """Set inside and outside interfaces for NAT44. :param node: DUT node. :param int_in: Inside interface. :param int_out: Outside interface. :type node: dict :type int_in: str :type int_out: str """ cmd = u"nat44_interface_add_del_feature" int_in_idx = InterfaceUtil.get_sw_if_index(node, int_in) err_msg = f"Failed to set inside interface {int_in} for NAT44 " \ f"on host {node[u'host']}" args_in = dict(sw_if_index=int_in_idx, is_add=1, flags=getattr(NATConfigFlags, u"NAT_IS_INSIDE").value) with PapiSocketExecutor(node) as papi_exec: papi_exec.add(cmd, **args_in).get_reply(err_msg) int_out_idx = InterfaceUtil.get_sw_if_index(node, int_out) err_msg = f"Failed to set outside interface {int_out} for NAT44 " \ f"on host {node[u'host']}" args_in = dict(sw_if_index=int_out_idx, is_add=1, flags=getattr(NATConfigFlags, u"NAT_IS_OUTSIDE").value) with PapiSocketExecutor(node) as papi_exec: papi_exec.add(cmd, **args_in).get_reply(err_msg)
def add_geneve_tunnel(node, local_address, remote_address, vni, multicast_if=None, encap_vrf=0, l3_mode=False, next_index=None): """Add GENEVE tunnel on the specified VPP node. :param node: Topology node. :param local_address: Local IP address. :param remote_address: Remote IP address. :param vni: Virtual network ID. :param multicast_if: Interface key of multicast interface; used only if remote is multicast. (Default value = None) :param encap_vrf: The FIB ID for sending unicast GENEVE encap packets or receiving multicast packets. (Default value = 0) :param l3_mode: Use geneve tunnel in L3 mode (ip routing) if Tue else in L2 mode (L2 switching). (Default value = False) :param next_index: The index of the next node. :type node: dict :type local_address: str :type remote_address: str :type vni: int :type multicast_if: str :type encap_vrf: int :type l3_mode: bool :type next_index: int :returns: SW interface index of created geneve tunnel. :rtype: int """ cmd = u"geneve_add_del_tunnel2" args = dict(is_add=True, local_address=IPAddress.create_ip_address_object( ip_address(local_address)), remote_address=IPAddress.create_ip_address_object( ip_address(remote_address)), mcast_sw_if_index=Topology.get_interface_sw_index( node, multicast_if) if multicast_if else Constants.BITWISE_NON_ZERO, encap_vrf_id=int(encap_vrf), decap_next_index=next_index if l3_mode else Constants.BITWISE_NON_ZERO, vni=int(vni), l3_mode=l3_mode) err_msg = f"Failed to configure GENEVE tunnel on host {node[u'host']}!" with PapiSocketExecutor(node) as papi_exec: sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg) if_key = Topology.add_new_port(node, u"geneve_tunnel") Topology.update_interface_sw_if_index(node, if_key, sw_if_index) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_index) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_index) Topology.update_interface_mac_address(node, if_key, ifc_mac) return sw_if_index
def vpp_create_vhost_user_interface(node, socket): """Create Vhost-user interface on VPP node. :param node: Node to create Vhost-user interface on. :param socket: Vhost-user interface socket path. :type node: dict :type socket: str :returns: SW interface index. :rtype: int :raises RuntimeError: If Vhost-user interface creation failed. """ out = VatExecutor.cmd_from_template(node, 'create_vhost_user_if.vat', sock=socket) if out[0].get('retval') == 0: sw_if_idx = int(out[0].get('sw_if_index')) if_key = Topology.add_new_port(node, 'vhost') Topology.update_interface_sw_if_index(node, if_key, sw_if_idx) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_idx) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_idx) Topology.update_interface_mac_address(node, if_key, ifc_mac) Topology.update_interface_vhost_socket(node, if_key, socket) return sw_if_idx else: raise RuntimeError('Create Vhost-user interface failed on node ' '"{}"'.format(node['host']))
def vpp_create_vhost_user_interface(node, socket): """Create Vhost-user interface on VPP node. :param node: Node to create Vhost-user interface on. :param socket: Vhost-user interface socket path. :type node: dict :type socket: str :returns: SW interface index. :rtype: int """ cmd = 'create_vhost_user_if' err_msg = 'Failed to create Vhost-user interface on host {host}'.format( host=node['host']) args = dict(sock_filename=str(socket)) with PapiExecutor(node) as papi_exec: sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg) # Update the Topology: if_key = Topology.add_new_port(node, 'vhost') Topology.update_interface_sw_if_index(node, if_key, sw_if_index) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_index) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_index) Topology.update_interface_mac_address(node, if_key, ifc_mac) Topology.update_interface_vhost_socket(node, if_key, socket) return sw_if_index
def set_nat44_interfaces(node, int_in, int_out): """Set inside and outside interfaces for NAT44. :param node: DUT node. :param int_in: Inside interface. :param int_out: Outside interface. :type node: dict :type int_in: str :type int_out: str """ cmd = 'nat44_interface_add_del_feature' int_in_idx = InterfaceUtil.get_sw_if_index(node, int_in) err_msg = 'Failed to set inside interface {int} for NAT44 on host ' \ '{host}'.format(int=int_in, host=node['host']) args_in = dict(sw_if_index=int_in_idx, is_add=1, flags=getattr(NATConfigFlags, "NAT_IS_INSIDE").value) with PapiExecutor(node) as papi_exec: papi_exec.add(cmd, **args_in).get_reply(err_msg) int_out_idx = InterfaceUtil.get_sw_if_index(node, int_out) err_msg = 'Failed to set outside interface {int} for NAT44 on host ' \ '{host}'.format(int=int_out, host=node['host']) args_in = dict(sw_if_index=int_out_idx, is_add=1, flags=getattr(NATConfigFlags, "NAT_IS_OUTSIDE").value) with PapiExecutor(node) as papi_exec: papi_exec.add(cmd, **args_in).get_reply(err_msg)
def all_tgs_set_interface_default_driver(nodes): """Setup interfaces default driver for all TGs in given topology. :param nodes: Nodes in topology. :type nodes: dict """ for node in nodes.values(): if node['type'] == NodeType.TG: InterfaceUtil.tg_set_interfaces_default_driver(node)
def configure_vpp_nsim(node, vpp_nsim_attr, interface0, interface1=None): """Configure nsim on the specified VPP node. :param node: Topology node. :param vpp_nsim_attr: VPP NSIM configuration attributes :param interface0: Interface name. :param interface1: 2nd Interface name for cross-connect feature :type node: dict :type vpp_nsim_attr: dict :type interface0: str or int :type interface1: str or int :raises RuntimeError: if no NSIM features are enabled or vpp papi command fails. """ host = node[u"host"] if not vpp_nsim_attr[u"output_nsim_enable"] \ and not vpp_nsim_attr[u"xc_nsim_enable"]: raise RuntimeError(f"No NSIM features enabled on host {host}:\n" f"vpp_nsim_attr = {vpp_nsim_attr}") cmd = u"nsim_configure2" args = dict(delay_in_usec=vpp_nsim_attr[u"delay_in_usec"], average_packet_size=vpp_nsim_attr[u"average_packet_size"], bandwidth_in_bits_per_second=vpp_nsim_attr[ u"bw_in_bits_per_second"], packets_per_drop=vpp_nsim_attr[u"packets_per_drop"], packets_per_reorder=vpp_nsim_attr.get( u"packets_per_reorder", 0)) err_msg = f"Failed to configure NSIM on host {host}" with PapiSocketExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg) if vpp_nsim_attr[u"output_nsim_enable"]: cmd = u"nsim_output_feature_enable_disable" args = dict( enable_disable=vpp_nsim_attr[u"output_nsim_enable"], sw_if_index=InterfaceUtil.get_interface_index( node, interface0), ) err_msg = f"Failed to enable NSIM output feature on " \ f"host {host} interface {interface0}" with PapiSocketExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg) elif vpp_nsim_attr[u"xc_nsim_enable"]: cmd = u"nsim_cross_connect_feature_enable_disable" args = dict( enable_disable=vpp_nsim_attr[u"xc_nsim_enable"], sw_if_index0=InterfaceUtil.get_interface_index( node, interface0), sw_if_index1=InterfaceUtil.get_interface_index( node, interface1), ) err_msg = f"Failed to enable NSIM output feature on " \ f"host {host} interface {interface0}" with PapiSocketExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg)
def get_interface_vrf_table(node, interface, ip_version='ipv4'): """Get vrf ID for the given interface. :param node: VPP node. :param interface: Name or sw_if_index of a specific interface. :type node: dict :param ip_version: IP protocol version (ipv4 or ipv6). :type interface: str or int :type ip_version: str :returns: vrf ID of the specified interface. :rtype: int """ sw_if_index = InterfaceUtil.get_interface_index(node, interface) cmd = u"sw_interface_get_table" args = dict( sw_if_index=sw_if_index, is_ipv6=bool(ip_version == u"ipv6") ) err_msg = f"Failed to get VRF id assigned to interface {interface}" with PapiSocketExecutor(node) as papi_exec: reply = papi_exec.add(cmd, **args).get_reply(err_msg) return reply[u"vrf_id"]
def vpp_interface_set_ip_address(node, interface, address, prefix_length=None): """Set IP address to VPP interface. :param node: VPP node. :param interface: Interface name. :param address: IP address. :param prefix_length: Prefix length. :type node: dict :type interface: str :type address: str :type prefix_length: int """ ip_addr = ip_address(unicode(address)) 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) err_msg = 'Failed to add IP address on interface {ifc}'.format( ifc=interface) with PapiExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg)
def get_interface_vrf_table(node, interface, ip_version='ipv4'): """Get vrf ID for the given interface. :param node: VPP node. :param interface: Name or sw_if_index of a specific interface. :type node: dict :param ip_version: IP protocol version (ipv4 or ipv6). :type interface: str or int :type ip_version: str :returns: vrf ID of the specified interface. :rtype: int """ 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) err_msg = 'Failed to get VRF id assigned to interface {ifc}'.format( ifc=interface) with PapiExecutor(node) as papi_exec: reply = papi_exec.add(cmd, **args).get_reply(err_msg) return reply['vrf_id']
def vpp_get_interface_ip_addresses(node, interface, ip_version): """Get list of IP addresses from an interface on a VPP node. :param node: VPP node. :param interface: Name of an interface on the VPP node. :param ip_version: IP protocol version (ipv4 or ipv6). :type node: dict :type interface: str :type ip_version: str :returns: List of dictionaries, each containing IP address, subnet prefix length and also the subnet mask for ipv4 addresses. Note: A single interface may have multiple IP addresses assigned. :rtype: list """ sw_if_index = InterfaceUtil.get_interface_index(node, interface) if not sw_if_index: return list() cmd = u"ip_address_dump" args = dict(sw_if_index=sw_if_index, is_ipv6=bool(ip_version == u"ipv6")) err_msg = f"Failed to get L2FIB dump on host {node[u'host']}" with PapiSocketExecutor(node) as papi_exec: details = papi_exec.add(cmd, **args).get_details(err_msg) # TODO: CSIT currently looks only whether the list is empty. # Add proper value processing if values become important. return details
def vpp_interface_set_ip_address(node, interface, address, prefix_length=None): """Set IP address to VPP interface. :param node: VPP node. :param interface: Interface name. :param address: IP address. :param prefix_length: Prefix length. :type node: dict :type interface: str :type address: str :type prefix_length: int """ ip_addr = ip_address(address) cmd = u"sw_interface_add_del_address" args = dict(sw_if_index=InterfaceUtil.get_interface_index( node, interface), 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 = f"Failed to add IP address on interface {interface}" with PapiSocketExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg)
def vpp_create_vhost_user_interface(node, socket, is_server=False, virtio_feature_mask=None): """Create Vhost-user interface on VPP node. :param node: Node to create Vhost-user interface on. :param socket: Vhost-user interface socket path. :param is_server: Server side of connection. Default: False :param virtio_feature_mask: Mask of virtio features to be enabled. :type node: dict :type socket: str :type is_server: bool :type virtio_feature_mask: int :returns: SW interface index. :rtype: int """ cmd = u"create_vhost_user_if" err_msg = f"Failed to create Vhost-user interface " \ f"on host {node[u'host']}" if virtio_feature_mask is None: enable_gso = False else: enable_gso = VirtioFeatureMask.is_feature_enabled( virtio_feature_mask, VirtioFeaturesFlags.VIRTIO_NET_F_API_GSO) args = dict(is_server=bool(is_server), sock_filename=str(socket), enable_gso=bool(enable_gso)) with PapiSocketExecutor(node) as papi_exec: sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg) # Update the Topology: if_key = Topology.add_new_port(node, u"vhost") Topology.update_interface_sw_if_index(node, if_key, sw_if_index) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_index) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_index) Topology.update_interface_mac_address(node, if_key, ifc_mac) Topology.update_interface_vhost_socket(node, if_key, socket) return sw_if_index
def vpp_get_tap_interface_mac(node, interface_name): """Get tap interface MAC address from interfaces dump. :param node: DUT node. :param interface_name: Tap interface name. :type node: dict :type interface_name: str :returns: Tap interface MAC address. :rtype: str """ return InterfaceUtil.vpp_get_interface_mac(node, interface_name)
def get_vhost_user_mac_by_sw_index(node, sw_if_index): """Get Vhost-user l2_address for the given interface from actual interface dump. :param node: VPP node to get interface data from. :param sw_if_index: SW index of the specific interface. :type node: dict :type sw_if_index: str :returns: l2_address of the given interface. :rtype: str """ return InterfaceUtil.vpp_get_interface_mac(node, sw_if_index)
def get_pci_interface_irqs(node, pci_addr): """Get IRQs for interface in linux specified by PCI address. :param node: Topology node. :param pci_addr: Linux interface PCI address. :type node: dict :type pci_addr: str :returns: List of IRQs attached to specified interface. :rtype: list """ interface = InterfaceUtil.pci_to_eth(node, pci_addr) return IrqUtil.get_interface_irqs(node, interface)
def vpp_create_vhost_user_interface( node, socket, is_server=False, enable_gso=False): """Create Vhost-user interface on VPP node. :param node: Node to create Vhost-user interface on. :param socket: Vhost-user interface socket path. :param is_server: Server side of connection. Default: False :param enable_gso: Generic segmentation offloading. Default: False :type node: dict :type socket: str :type is_server: bool :type enable_gso: bool :returns: SW interface index. :rtype: int """ cmd = u"create_vhost_user_if" err_msg = f"Failed to create Vhost-user interface " \ f"on host {node[u'host']}" args = dict( is_server=bool(is_server), sock_filename=str(socket), enable_gso=bool(enable_gso) ) with PapiSocketExecutor(node) as papi_exec: sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg) # Update the Topology: if_key = Topology.add_new_port(node, u"vhost") Topology.update_interface_sw_if_index(node, if_key, sw_if_index) ifc_name = InterfaceUtil.vpp_get_interface_name(node, sw_if_index) Topology.update_interface_name(node, if_key, ifc_name) ifc_mac = InterfaceUtil.vpp_get_interface_mac(node, sw_if_index) Topology.update_interface_mac_address(node, if_key, ifc_mac) Topology.update_interface_vhost_socket(node, if_key, socket) return sw_if_index
def check_tap_present(node, tap_name): """Check whether specific tap interface exists. :param node: Node to check tap on. :param tap_name: Tap interface name for linux tap. :type node: dict :type tap_name: str :raises RuntimeError: Specified interface was not found. """ tap_if = InterfaceUtil.tap_dump(node, tap_name) if len(tap_if) == 0: raise RuntimeError( 'Tap interface :{} does not exist'.format(tap_name))
def _get_sr_steer_policy_args(node, mode, interface=None, ip_addr=None, prefix=None): """Return values of sw_if_index, mask_width, prefix_addr and traffic_type for sr_steering_add_del API. :param node: Given node to create/delete steering policy on. :param mode: Mode of operation - L2 or L3. :param interface: Interface name (Optional, required in case of L2 mode). :param ip_addr: IPv4/IPv6 address (Optional, required in case of L3 mode). :param prefix: IP address prefix (Optional, required in case of L3 mode). :type node: dict :type mode: str :type interface: str :type ip_addr: str :type prefix: int :returns: Values for sw_if_index, prefix and traffic_type :rtype: tuple :raises ValueError: If unsupported mode used or required parameter is missing. """ if mode.lower() == u"l2": if interface is None: raise ValueError(f"Required data missing.\n" f"interface: {interface}") sw_if_index = InterfaceUtil.get_interface_index(node, interface) prefix = 0 traffic_type = getattr(SRv6PolicySteeringTypes, u"SR_STEER_L2").value elif mode.lower() == u"l3": if ip_addr is None or prefix is None: raise ValueError(f"Required data missing.\n" f"IP address:{ip_addr}\n" f"mask:{prefix}") sw_if_index = Constants.BITWISE_NON_ZERO ip_addr = ip_address(ip_addr) prefix = IPUtil.create_prefix_object(ip_addr, int(prefix)) traffic_type = getattr( SRv6PolicySteeringTypes, u"SR_STEER_IPV4").value if ip_addr.version == 4 else getattr( SRv6PolicySteeringTypes, u"SR_STEER_IPV6").value else: raise ValueError(f"Unsupported mode: {mode}") return sw_if_index, prefix, traffic_type
def vpp_ip_source_check_setup(node, if_name): """Setup Reverse Path Forwarding source check on interface. :param node: VPP node. :param if_name: Interface name to setup RPF source check. :type node: dict :type if_name: str """ cmd = u"ip_source_check_interface_add_del" args = dict(sw_if_index=InterfaceUtil.get_interface_index( node, if_name), is_add=1, loose=0) err_msg = f"Failed to enable source check on interface {if_name}" with PapiSocketExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg)
def flush_ip_addresses(node, interface): """Flush all IP addresses from specified interface. :param node: VPP node. :param interface: Interface name. :type node: dict :type interface: str """ cmd = 'sw_interface_add_del_address' args = dict(sw_if_index=InterfaceUtil.get_interface_index( node, interface), del_all=1) err_msg = 'Failed to flush IP address on interface {ifc}'.format( ifc=interface) with PapiExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg)
def vpp_proxy_arp_interface_enable(node, interface): """Enable proxy ARP on interface. :param node: VPP node to enable proxy ARP on interface. :param interface: Interface to enable proxy ARP. :type node: dict :type interface: str or int """ cmd = 'proxy_arp_intfc_enable_disable' args = dict( sw_if_index=InterfaceUtil.get_interface_index(node, interface), enable_disable=1) err_msg = 'Failed to enable proxy ARP on interface {ifc}'.format( ifc=interface) with PapiExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg)
def vpp_ra_suppress_link_layer(node, interface): """Suppress ICMPv6 router advertisement message for link scope address. :param node: VPP node. :param interface: Interface name. :type node: dict :type interface: str """ cmd = u"sw_interface_ip6nd_ra_config" args = dict(sw_if_index=InterfaceUtil.get_interface_index( node, interface), suppress=1) err_msg = f"Failed to suppress ICMPv6 router advertisement message " \ f"on interface {interface}" with PapiSocketExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg)
def flush_ip_addresses(node, interface): """Flush all IP addresses from specified interface. :param node: VPP node. :param interface: Interface name. :type node: dict :type interface: str """ cmd = u"sw_interface_add_del_address" args = dict(sw_if_index=InterfaceUtil.get_interface_index( node, interface), is_add=False, del_all=True) err_msg = f"Failed to flush IP address on interface {interface}" with PapiSocketExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg)
def vpp_ra_suppress_link_layer(node, interface): """Suppress ICMPv6 router advertisement message for link scope address. :param node: VPP node. :param interface: Interface name. :type node: dict :type interface: str """ cmd = 'sw_interface_ip6nd_ra_config' args = dict(sw_if_index=InterfaceUtil.get_interface_index( node, interface), suppress=1) err_msg = 'Failed to suppress ICMPv6 router advertisement message on ' \ 'interface {ifc}'.format(ifc=interface) with PapiExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg)
def vpp_interface_ra_suppress(node, interface): """Disable sending ICMPv6 router-advertisement messages on an interface on a VPP node. :param node: VPP node. :param interface: Interface name. :type node: dict :type interface: str """ cmd = u"sw_interface_ip6nd_ra_config" args = dict(sw_if_index=InterfaceUtil.get_interface_index( node, interface), suppress=1) err_msg = f"Failed to disable sending ICMPv6 router-advertisement " \ f"messages on interface {interface}" with PapiSocketExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg)
def vpp_ip_probe(node, interface, addr): """Run ip probe on VPP node. :param node: VPP node. :param interface: Interface key or name. :param addr: IPv4/IPv6 address. :type node: dict :type interface: str :type addr: str """ cmd = u"ip_probe_neighbor" args = dict(sw_if_index=InterfaceUtil.get_interface_index( node, interface), dst=str(addr)) err_msg = f"VPP ip probe {interface} {addr} failed on {node[u'host']}" with PapiSocketExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg)
def vpp_ip_source_check_setup(node, if_name): """Setup Reverse Path Forwarding source check on interface. :param node: VPP node. :param if_name: Interface name to setup RPF source check. :type node: dict :type if_name: str """ cmd = 'ip_source_check_interface_add_del' args = dict( sw_if_index=InterfaceUtil.get_interface_index(node, if_name), is_add=1, loose=0) err_msg = 'Failed to enable source check on interface {ifc}'.format( ifc=if_name) with PapiExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_replies(err_msg). \ verify_reply(err_msg=err_msg)
def vpp_get_interface_ip_addresses(node, interface, ip_version): """Get list of IP addresses from an interface on a VPP node. :param node: VPP node. :param interface: Name of an interface on the VPP node. :param ip_version: IP protocol version (ipv4 or ipv6). :type node: dict :type interface: str :type ip_version: str :returns: List of dictionaries, each containing IP address, subnet prefix length and also the subnet mask for ipv4 addresses. Note: A single interface may have multiple IP addresses assigned. :rtype: list """ sw_if_index = InterfaceUtil.get_interface_index(node, interface) data = list() if sw_if_index: is_ipv6 = 1 if ip_version == 'ipv6' else 0 cmd = 'ip_address_dump' cmd_reply = 'ip_address_details' args = dict(sw_if_index=sw_if_index, is_ipv6=is_ipv6) err_msg = 'Failed to get L2FIB dump on host {host}'.format( host=node['host']) with PapiExecutor(node) as papi_exec: papi_resp = papi_exec.add(cmd, **args).get_dump(err_msg) for item in papi_resp.reply[0]['api_reply']: item[cmd_reply]['ip'] = item[cmd_reply]['prefix'].split('/')[0] item[cmd_reply]['prefix_length'] = int( item[cmd_reply]['prefix'].split('/')[1]) item[cmd_reply]['is_ipv6'] = is_ipv6 item[cmd_reply]['netmask'] = \ str(IPv6Network(unicode('::/{pl}'.format( pl=item[cmd_reply]['prefix_length']))).netmask) \ if is_ipv6 \ else str(IPv4Network(unicode('0.0.0.0/{pl}'.format( pl=item[cmd_reply]['prefix_length']))).netmask) data.append(item[cmd_reply]) return data
def vpp_ip_probe(node, interface, addr): """Run ip probe on VPP node. :param node: VPP node. :param interface: Interface key or name. :param addr: IPv4/IPv6 address. :type node: dict :type interface: str :type addr: str """ cmd = 'ip_probe_neighbor' args = dict(sw_if_index=InterfaceUtil.get_interface_index( node, interface), dst=str(addr)) err_msg = 'VPP ip probe {dev} {ip} failed on {h}'.format( dev=interface, ip=addr, h=node['host']) with PapiExecutor(node) as papi_exec: papi_exec.add(cmd, **args).get_reply(err_msg)