from lib.py import ksft_setup, wait_file
from lib.py import cmd, ethtool, ip, CmdExitFailure
from lib.py import NetNS, NetdevSimDev
+from lib.py import NetdevFamily, EthtoolFamily
from .remote import Remote
from . import bpftool
between the physical interface and a network namespace.
"""
- def __init__(self, src_path, nk_rxqueues=1, **kwargs):
+ def __init__(self, src_path, lease=False, **kwargs):
super().__init__(src_path, **kwargs)
self.require_ipver("6")
if not local_prefix:
raise KsftSkipEx("LOCAL_PREFIX_V6 required")
+ self.netdevnl = NetdevFamily()
+ self.ethnl = EthtoolFamily()
+
local_prefix = local_prefix.rstrip("/64").rstrip("::").rstrip(":")
self.ipv6_prefix = f"{local_prefix}::"
self.nk_host_ipv6 = f"{local_prefix}::2:1"
self._tc_attached = False
self._bpf_prog_pref = None
self._bpf_prog_id = None
+ self._leased = False
+ nk_rxqueues = 1
+ if lease:
+ nk_rxqueues = 2
ip(f"link add type netkit mode l2 forward peer forward numrxqueues {nk_rxqueues}")
all_links = ip("-d link show", json=True)
self.nk_host_ifindex = netkit_links[1]['ifindex']
self.nk_guest_ifindex = netkit_links[0]['ifindex']
+ if lease:
+ self._lease_queues()
+
self._setup_ns()
self._attach_bpf()
del self.netns
self.netns = None
+ if self._leased:
+ self.ethnl.rings_set({'header': {'dev-index': self.ifindex},
+ 'tcp-data-split': 'unknown',
+ 'hds-thresh': self._hds_thresh,
+ 'rx': self._rx_rings})
+ self._leased = False
+
super().__del__()
+ def _lease_queues(self):
+ channels = self.ethnl.channels_get({'header': {'dev-index': self.ifindex}})
+ channels = channels['combined-count']
+ if channels < 2:
+ raise KsftSkipEx('Test requires NETIF with at least 2 combined channels')
+
+ rings = self.ethnl.rings_get({'header': {'dev-index': self.ifindex}})
+ self._rx_rings = rings['rx']
+ self._hds_thresh = rings.get('hds-thresh', 0)
+ self.ethnl.rings_set({'header': {'dev-index': self.ifindex},
+ 'tcp-data-split': 'enabled',
+ 'hds-thresh': 0,
+ 'rx': 64})
+ self.src_queue = channels - 1
+ bind_result = self.netdevnl.queue_create(
+ {
+ "ifindex": self.nk_guest_ifindex,
+ "type": "rx",
+ "lease": {
+ "ifindex": self.ifindex,
+ "queue": {"id": self.src_queue, "type": "rx"},
+ },
+ }
+ )
+ self.nk_queue = bind_result['id']
+ self._leased = True
+
def _setup_ns(self):
self.netns = NetNS()
ip(f"link set dev {self._nk_guest_ifname} netns {self.netns.name}")