+ :returns: SW IF INDEX of created interface.
+ :rtype: int
+ :raises RuntimeError: if it is unable to create VxLAN interface on the
+ node.
+ """
+ src_address = ip_address(unicode(source_ip))
+ dst_address = ip_address(unicode(destination_ip))
+
+ cmd = 'vxlan_add_del_tunnel'
+ args = dict(is_add=1,
+ is_ipv6=1 if src_address.version == 6 else 0,
+ instance=Constants.BITWISE_NON_ZERO,
+ src_address=src_address.packed,
+ dst_address=dst_address.packed,
+ mcast_sw_if_index=Constants.BITWISE_NON_ZERO,
+ encap_vrf_id=0,
+ decap_next_index=Constants.BITWISE_NON_ZERO,
+ vni=int(vni))
+ err_msg = 'Failed to create VXLAN tunnel interface on host {host}'.\
+ format(host=node['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, 'vxlan_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)
+
+ return sw_if_index
+
+ @staticmethod
+ def set_vxlan_bypass(node, interface=None):
+ """Add the 'ip4-vxlan-bypass' graph node for a given interface.
+
+ By adding the IPv4 vxlan-bypass graph node to an interface, the node
+ checks for and validate input vxlan packet and bypass ip4-lookup,
+ ip4-local, ip4-udp-lookup nodes to speedup vxlan packet forwarding.
+ This node will cause extra overhead to for non-vxlan packets which is
+ kept at a minimum.
+
+ :param node: Node where to set VXLAN bypass.
+ :param interface: Numeric index or name string of a specific interface.
+ :type node: dict
+ :type interface: int or str
+ :raises RuntimeError: if it failed to set VXLAN bypass on interface.
+ """
+ sw_if_index = InterfaceUtil.get_interface_index(node, interface)
+
+ cmd = 'sw_interface_set_vxlan_bypass'
+ args = dict(is_ipv6=0,
+ sw_if_index=sw_if_index,
+ enable=1)
+ err_msg = 'Failed to set VXLAN bypass on interface on host {host}'.\
+ format(host=node['host'])
+ with PapiSocketExecutor(node) as papi_exec:
+ papi_exec.add(cmd, **args).get_replies(err_msg)
+
+ @staticmethod
+ def vxlan_dump(node, interface=None):
+ """Get VxLAN data for the given interface.
+
+ :param node: VPP node to get interface data from.
+ :param interface: Numeric index or name string of a specific interface.
+ If None, information about all VxLAN interfaces is returned.
+ :type node: dict
+ :type interface: int or str
+ :returns: Dictionary containing data for the given VxLAN interface or if
+ interface=None, the list of dictionaries with all VxLAN interfaces.
+ :rtype: dict or list
+ :raises TypeError: if the data type of interface is neither basestring
+ nor int.
+ """
+ if interface is not None:
+ sw_if_index = InterfaceUtil.get_interface_index(node, interface)
+ else:
+ sw_if_index = int(Constants.BITWISE_NON_ZERO)
+
+ cmd = 'vxlan_tunnel_dump'
+ args = dict(sw_if_index=sw_if_index)
+ err_msg = 'Failed to get VXLAN dump on host {host}'.format(
+ host=node['host'])
+ with PapiSocketExecutor(node) as papi_exec:
+ details = papi_exec.add(cmd, **args).get_details(err_msg)
+
+ def process_vxlan_dump(vxlan_dump):
+ """Process vxlan dump.
+
+ :param vxlan_dump: Vxlan interface dump.
+ :type vxlan_dump: dict
+ :returns: Processed vxlan interface dump.
+ :rtype: dict
+ """
+ if vxlan_dump['is_ipv6']:
+ vxlan_dump['src_address'] = \
+ inet_ntop(AF_INET6, vxlan_dump['src_address'])
+ vxlan_dump['dst_address'] = \
+ inet_ntop(AF_INET6, vxlan_dump['dst_address'])
+ else:
+ vxlan_dump['src_address'] = \
+ inet_ntop(AF_INET, vxlan_dump['src_address'][0:4])
+ vxlan_dump['dst_address'] = \
+ inet_ntop(AF_INET, vxlan_dump['dst_address'][0:4])
+ return vxlan_dump
+
+ data = list() if interface is None else dict()
+ for vxlan_dump in details:
+ if interface is None:
+ data.append(process_vxlan_dump(vxlan_dump))
+ elif vxlan_dump['sw_if_index'] == sw_if_index:
+ data = process_vxlan_dump(vxlan_dump)
+ break
+
+ logger.debug('VXLAN data:\n{vxlan_data}'.format(vxlan_data=data))
+ return data
+
+ @staticmethod
+ def vhost_user_dump(node):
+ """Get vhost-user data for the given node.
+
+ TODO: Move to VhostUser.py
+
+ :param node: VPP node to get interface data from.
+ :type node: dict
+ :returns: List of dictionaries with all vhost-user interfaces.
+ :rtype: list
+ """
+ cmd = 'sw_interface_vhost_user_dump'
+ err_msg = 'Failed to get vhost-user dump on host {host}'.format(
+ host=node['host'])
+ with PapiSocketExecutor(node) as papi_exec:
+ details = papi_exec.add(cmd).get_details(err_msg)
+
+ def process_vhost_dump(vhost_dump):
+ """Process vhost dump.
+
+ :param vhost_dump: Vhost interface dump.
+ :type vhost_dump: dict
+ :returns: Processed vhost interface dump.
+ :rtype: dict
+ """
+ vhost_dump['interface_name'] = \
+ vhost_dump['interface_name'].rstrip('\x00')
+ vhost_dump['sock_filename'] = \
+ vhost_dump['sock_filename'].rstrip('\x00')
+ return vhost_dump
+
+ for vhost_dump in details:
+ # In-place edits.
+ process_vhost_dump(vhost_dump)
+
+ logger.debug('Vhost-user details:\n{vhost_details}'.format(
+ vhost_details=details))
+ return details
+
+ @staticmethod
+ def tap_dump(node, name=None):
+ """Get all TAP interface data from the given node, or data about
+ a specific TAP interface.
+
+ TODO: Move to Tap.py
+
+ :param node: VPP node to get data from.
+ :param name: Optional name of a specific TAP interface.
+ :type node: dict
+ :type name: str
+ :returns: Dictionary of information about a specific TAP interface, or
+ a List of dictionaries containing all TAP data for the given node.
+ :rtype: dict or list
+ """
+ cmd = 'sw_interface_tap_v2_dump'
+ err_msg = 'Failed to get TAP dump on host {host}'.format(
+ host=node['host'])
+ with PapiSocketExecutor(node) as papi_exec:
+ details = papi_exec.add(cmd).get_details(err_msg)
+
+ def process_tap_dump(tap_dump):
+ """Process tap dump.
+
+ :param tap_dump: Tap interface dump.
+ :type tap_dump: dict
+ :returns: Processed tap interface dump.
+ :rtype: dict
+ """
+ tap_dump['dev_name'] = tap_dump['dev_name'].rstrip('\x00')
+ tap_dump['host_if_name'] = tap_dump['host_if_name'].rstrip('\x00')
+ tap_dump['host_namespace'] = \
+ tap_dump['host_namespace'].rstrip('\x00')
+ tap_dump['host_mac_addr'] = \
+ L2Util.bin_to_mac(tap_dump['host_mac_addr'])
+ tap_dump['host_ip4_addr'] = \
+ inet_ntop(AF_INET, tap_dump['host_ip4_addr'])
+ tap_dump['host_ip6_addr'] = \
+ inet_ntop(AF_INET6, tap_dump['host_ip6_addr'])
+ return tap_dump
+
+ data = list() if name is None else dict()
+ for tap_dump in details:
+ if name is None:
+ data.append(process_tap_dump(tap_dump))
+ elif tap_dump.get('dev_name').rstrip('\x00') == name:
+ data = process_tap_dump(tap_dump)
+ break
+
+ logger.debug('TAP data:\n{tap_data}'.format(tap_data=data))
+ return data
+
+ @staticmethod
+ def create_subinterface(node, interface, sub_id, outer_vlan_id=None,
+ inner_vlan_id=None, type_subif=None):
+ """Create sub-interface on node. It is possible to set required
+ sub-interface type and VLAN tag(s).
+
+ :param node: Node to add sub-interface.
+ :param interface: Interface name on which create sub-interface.
+ :param sub_id: ID of the sub-interface to be created.
+ :param outer_vlan_id: Optional outer VLAN ID.
+ :param inner_vlan_id: Optional inner VLAN ID.
+ :param type_subif: Optional type of sub-interface. Values supported by
+ VPP: [no_tags] [one_tag] [two_tags] [dot1ad] [exact_match]
+ [default_sub]
+ :type node: dict
+ :type interface: str or int
+ :type sub_id: int
+ :type outer_vlan_id: int
+ :type inner_vlan_id: int
+ :type type_subif: str
+ :returns: Name and index of created sub-interface.
+ :rtype: tuple
+ :raises RuntimeError: If it is not possible to create sub-interface.
+ """
+ subif_types = type_subif.split()
+
+ 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,
+ 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)
+ err_msg = 'Failed to create sub-interface on host {host}'.format(
+ host=node['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, 'subinterface')
+ 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)
+
+ return '{ifc}.{s_id}'.format(ifc=interface, s_id=sub_id), sw_if_index
+
+ @staticmethod
+ def create_gre_tunnel_interface(node, source_ip, destination_ip):
+ """Create GRE tunnel interface on node.
+
+ :param node: VPP node to add tunnel interface.
+ :param source_ip: Source of the GRE tunnel.
+ :param destination_ip: Destination of the GRE tunnel.
+ :type node: dict
+ :type source_ip: str
+ :type destination_ip: str
+ :returns: Name and index of created GRE tunnel interface.
+ :rtype: tuple
+ :raises RuntimeError: If unable to create GRE tunnel interface.
+ """
+ cmd = 'gre_tunnel_add_del'
+ tunnel = dict(type=0,
+ instance=Constants.BITWISE_NON_ZERO,
+ src=str(source_ip),
+ dst=str(destination_ip),
+ outer_fib_id=0,
+ session_id=0)
+ args = dict(is_add=1,
+ tunnel=tunnel)
+ err_msg = 'Failed to create GRE tunnel interface on host {host}'.format(
+ host=node['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, 'gre_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)
+
+ return ifc_name, sw_if_index
+
+ @staticmethod
+ def vpp_create_loopback(node, mac=None):
+ """Create loopback interface on VPP node.
+
+ :param node: Node to create loopback interface on.
+ :param mac: Optional MAC address for Loopback interface.
+ :type node: dict
+ :type mac: str
+ :returns: SW interface index.