+ sw_if_index = interface
+
+ cmd = u"classify_table_by_interface"
+ args = dict(
+ sw_if_index=sw_if_index
+ )
+ err_msg = f"Failed to get classify table name by interface {interface}"
+ with PapiSocketExecutor(node) as papi_exec:
+ reply = papi_exec.add(cmd, **args).get_reply(err_msg)
+
+ return reply
+
+ @staticmethod
+ def get_sw_if_index(node, interface_name):
+ """Get sw_if_index for the given interface from actual interface dump.
+
+ :param node: VPP node to get interface data from.
+ :param interface_name: Name of the specific interface.
+ :type node: dict
+ :type interface_name: str
+ :returns: sw_if_index of the given interface.
+ :rtype: str
+ """
+ interface_data = InterfaceUtil.vpp_get_interface_data(
+ node, interface=interface_name
+ )
+ return interface_data.get(u"sw_if_index")
+
+ @staticmethod
+ def vxlan_gpe_dump(node, interface_name=None):
+ """Get VxLAN GPE data for the given interface.
+
+ :param node: VPP node to get interface data from.
+ :param interface_name: Name of the specific interface. If None,
+ information about all VxLAN GPE interfaces is returned.
+ :type node: dict
+ :type interface_name: str
+ :returns: Dictionary containing data for the given VxLAN GPE interface
+ or if interface=None, the list of dictionaries with all VxLAN GPE
+ interfaces.
+ :rtype: dict or list
+ """
+ def process_vxlan_gpe_dump(vxlan_dump):
+ """Process vxlan_gpe dump.
+
+ :param vxlan_dump: Vxlan_gpe nterface dump.
+ :type vxlan_dump: dict
+ :returns: Processed vxlan_gpe interface dump.
+ :rtype: dict
+ """
+ if vxlan_dump[u"is_ipv6"]:
+ vxlan_dump[u"local"] = ip_address(vxlan_dump[u"local"])
+ vxlan_dump[u"remote"] = ip_address(vxlan_dump[u"remote"])
+ else:
+ vxlan_dump[u"local"] = ip_address(vxlan_dump[u"local"][0:4])
+ vxlan_dump[u"remote"] = ip_address(vxlan_dump[u"remote"][0:4])
+ return vxlan_dump
+
+ if interface_name is not None:
+ sw_if_index = InterfaceUtil.get_interface_index(
+ node, interface_name
+ )
+ else:
+ sw_if_index = int(Constants.BITWISE_NON_ZERO)
+
+ cmd = u"vxlan_gpe_tunnel_dump"
+ args = dict(
+ sw_if_index=sw_if_index
+ )
+ err_msg = f"Failed to get VXLAN-GPE dump on host {node[u'host']}"
+ with PapiSocketExecutor(node) as papi_exec:
+ details = papi_exec.add(cmd, **args).get_details(err_msg)
+
+ data = list() if interface_name is None else dict()
+ for dump in details:
+ if interface_name is None:
+ data.append(process_vxlan_gpe_dump(dump))
+ elif dump[u"sw_if_index"] == sw_if_index:
+ data = process_vxlan_gpe_dump(dump)
+ break
+
+ logger.debug(f"VXLAN-GPE data:\n{data}")
+ return data
+
+ @staticmethod
+ def assign_interface_to_fib_table(node, interface, table_id, ipv6=False):
+ """Assign VPP interface to specific VRF/FIB table.
+
+ :param node: VPP node where the FIB and interface are located.
+ :param interface: Interface to be assigned to FIB.
+ :param table_id: VRF table ID.
+ :param ipv6: Assign to IPv6 table. Default False.
+ :type node: dict
+ :type interface: str or int
+ :type table_id: int
+ :type ipv6: bool
+ """
+ cmd = u"sw_interface_set_table"
+ args = dict(
+ sw_if_index=InterfaceUtil.get_interface_index(node, interface),
+ is_ipv6=ipv6,
+ vrf_id=int(table_id)
+ )
+ err_msg = f"Failed to assign interface {interface} to FIB table"
+ with PapiSocketExecutor(node) as papi_exec:
+ papi_exec.add(cmd, **args).get_reply(err_msg)
+
+ @staticmethod
+ def set_linux_interface_mac(
+ node, interface, mac, namespace=None, vf_id=None):
+ """Set MAC address for interface in linux.
+
+ :param node: Node where to execute command.
+ :param interface: Interface in namespace.
+ :param mac: MAC to be assigned to interface.
+ :param namespace: Execute command in namespace. Optional
+ :param vf_id: Virtual Function id. Optional
+ :type node: dict
+ :type interface: str
+ :type mac: str
+ :type namespace: str
+ :type vf_id: int
+ """
+ mac_str = f"vf {vf_id} mac {mac}" if vf_id is not None \
+ else f"address {mac}"
+ ns_str = f"ip netns exec {namespace}" if namespace else u""
+
+ cmd = f"{ns_str} ip link set {interface} {mac_str}"
+ exec_cmd_no_error(node, cmd, sudo=True)
+
+ @staticmethod
+ def set_linux_interface_trust_on(
+ node, interface, namespace=None, vf_id=None):
+ """Set trust on (promisc) for interface in linux.
+
+ :param node: Node where to execute command.
+ :param interface: Interface in namespace.
+ :param namespace: Execute command in namespace. Optional
+ :param vf_id: Virtual Function id. Optional
+ :type node: dict
+ :type interface: str
+ :type namespace: str
+ :type vf_id: int
+ """
+ trust_str = f"vf {vf_id} trust on" if vf_id is not None else u"trust on"
+ ns_str = f"ip netns exec {namespace}" if namespace else u""
+
+ cmd = f"{ns_str} ip link set dev {interface} {trust_str}"
+ exec_cmd_no_error(node, cmd, sudo=True)
+
+ @staticmethod
+ def set_linux_interface_spoof_off(
+ node, interface, namespace=None, vf_id=None):
+ """Set spoof off for interface in linux.
+
+ :param node: Node where to execute command.
+ :param interface: Interface in namespace.
+ :param namespace: Execute command in namespace. Optional
+ :param vf_id: Virtual Function id. Optional
+ :type node: dict
+ :type interface: str
+ :type namespace: str
+ :type vf_id: int
+ """
+ spoof_str = f"vf {vf_id} spoof off" if vf_id is not None \
+ else u"spoof off"
+ ns_str = f"ip netns exec {namespace}" if namespace else u""
+
+ cmd = f"{ns_str} ip link set dev {interface} {spoof_str}"
+ exec_cmd_no_error(node, cmd, sudo=True)
+
+ @staticmethod
+ def init_avf_interface(node, ifc_key, numvfs=1, osi_layer=u"L2"):
+ """Init PCI device by creating VIFs and bind them to vfio-pci for AVF
+ driver testing on DUT.
+
+ :param node: DUT node.
+ :param ifc_key: Interface key from topology file.
+ :param numvfs: Number of VIFs to initialize, 0 - disable the VIFs.
+ :param osi_layer: OSI Layer type to initialize TG with.
+ Default value "L2" sets linux interface spoof off.
+ :type node: dict
+ :type ifc_key: str
+ :type numvfs: int
+ :type osi_layer: str
+ :returns: Virtual Function topology interface keys.
+ :rtype: list
+ :raises RuntimeError: If a reason preventing initialization is found.
+ """
+ # Read PCI address and driver.
+ pf_pci_addr = Topology.get_interface_pci_addr(node, ifc_key)
+ pf_mac_addr = Topology.get_interface_mac(node, ifc_key).split(":")
+ uio_driver = Topology.get_uio_driver(node)
+ kernel_driver = Topology.get_interface_driver(node, ifc_key)
+ if kernel_driver not in (u"i40e", u"i40evf"):
+ raise RuntimeError(
+ f"AVF needs i40e-compatible driver, not {kernel_driver} "
+ f"at node {node[u'host']} ifc {ifc_key}"
+ )
+ current_driver = DUTSetup.get_pci_dev_driver(
+ node, pf_pci_addr.replace(u":", r"\:"))
+
+ VPPUtil.stop_vpp_service(node)
+ if current_driver != kernel_driver:
+ # PCI device must be re-bound to kernel driver before creating VFs.
+ DUTSetup.verify_kernel_module(node, kernel_driver, force_load=True)
+ # Stop VPP to prevent deadlock.
+ # Unbind from current driver.
+ DUTSetup.pci_driver_unbind(node, pf_pci_addr)
+ # Bind to kernel driver.
+ DUTSetup.pci_driver_bind(node, pf_pci_addr, kernel_driver)
+
+ # Initialize PCI VFs.
+ DUTSetup.set_sriov_numvfs(node, pf_pci_addr, numvfs)
+
+ vf_ifc_keys = []
+ # Set MAC address and bind each virtual function to uio driver.
+ for vf_id in range(numvfs):
+ vf_mac_addr = u":".join(
+ [pf_mac_addr[0], pf_mac_addr[2], pf_mac_addr[3], pf_mac_addr[4],
+ pf_mac_addr[5], f"{vf_id:02x}"
+ ]
+ )
+
+ pf_dev = f"`basename /sys/bus/pci/devices/{pf_pci_addr}/net/*`"
+ InterfaceUtil.set_linux_interface_trust_on(node, pf_dev,
+ vf_id=vf_id)
+ if osi_layer == u"L2":
+ InterfaceUtil.set_linux_interface_spoof_off(
+ node, pf_dev, vf_id=vf_id
+ )
+ InterfaceUtil.set_linux_interface_mac(
+ node, pf_dev, vf_mac_addr, vf_id=vf_id
+ )
+
+ DUTSetup.pci_vf_driver_unbind(node, pf_pci_addr, vf_id)
+ DUTSetup.pci_vf_driver_bind(node, pf_pci_addr, vf_id, uio_driver)
+
+ # Add newly created ports into topology file
+ vf_ifc_name = f"{ifc_key}_vif"
+ vf_pci_addr = DUTSetup.get_virtfn_pci_addr(node, pf_pci_addr, vf_id)
+ vf_ifc_key = Topology.add_new_port(node, vf_ifc_name)
+ Topology.update_interface_name(
+ node, vf_ifc_key, vf_ifc_name+str(vf_id+1)
+ )
+ Topology.update_interface_mac_address(node, vf_ifc_key, vf_mac_addr)
+ Topology.update_interface_pci_address(node, vf_ifc_key, vf_pci_addr)
+ vf_ifc_keys.append(vf_ifc_key)
+
+ return vf_ifc_keys
+
+ @staticmethod
+ def vpp_sw_interface_rx_placement_dump(node):
+ """Dump VPP interface RX placement on node.
+
+ :param node: Node to run command on.
+ :type node: dict
+ :returns: Thread mapping information as a list of dictionaries.
+ :rtype: list
+ """
+ cmd = u"sw_interface_rx_placement_dump"
+ err_msg = f"Failed to run '{cmd}' PAPI command on host {node[u'host']}!"
+ with PapiSocketExecutor(node) as papi_exec:
+ for ifc in node[u"interfaces"].values():
+ if ifc[u"vpp_sw_index"] is not None:
+ papi_exec.add(cmd, sw_if_index=ifc[u"vpp_sw_index"])
+ details = papi_exec.get_details(err_msg)
+ return sorted(details, key=lambda k: k[u"sw_if_index"])
+
+ @staticmethod
+ def vpp_sw_interface_set_rx_placement(
+ node, sw_if_index, queue_id, worker_id):
+ """Set interface RX placement to worker on node.
+
+ :param node: Node to run command on.
+ :param sw_if_index: VPP SW interface index.
+ :param queue_id: VPP interface queue ID.
+ :param worker_id: VPP worker ID (indexing from 0).
+ :type node: dict
+ :type sw_if_index: int
+ :type queue_id: int
+ :type worker_id: int
+ :raises RuntimeError: If failed to run command on host or if no API
+ reply received.
+ """
+ cmd = u"sw_interface_set_rx_placement"
+ err_msg = f"Failed to set interface RX placement to worker " \
+ f"on host {node[u'host']}!"
+ 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)
+
+ @staticmethod
+ def vpp_round_robin_rx_placement(node, prefix):
+ """Set Round Robin interface RX placement on all worker threads
+ on node.
+
+ :param node: Topology nodes.
+ :param prefix: Interface name prefix.
+ :type node: dict
+ :type prefix: str
+ """
+ worker_id = 0
+ worker_cnt = len(VPPUtil.vpp_show_threads(node)) - 1
+ if not worker_cnt:
+ return
+ for placement in InterfaceUtil.vpp_sw_interface_rx_placement_dump(node):
+ for interface in node[u"interfaces"].values():
+ if placement[u"sw_if_index"] == interface[u"vpp_sw_index"] \
+ and prefix in interface[u"name"]:
+ InterfaceUtil.vpp_sw_interface_set_rx_placement(
+ node, placement[u"sw_if_index"], placement[u"queue_id"],
+ worker_id % worker_cnt
+ )
+ worker_id += 1
+
+ @staticmethod
+ def vpp_round_robin_rx_placement_on_all_duts(nodes, prefix):
+ """Set Round Robin interface RX placement on all worker threads
+ on all DUTs.
+
+ :param nodes: Topology nodes.
+ :param prefix: Interface name prefix.
+ :type nodes: dict
+ :type prefix: str
+ """
+ for node in nodes.values():
+ if node[u"type"] == NodeType.DUT:
+ InterfaceUtil.vpp_round_robin_rx_placement(node, prefix)