From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.linux.dev
Cc: James Prestwood <prestwoj@gmail.com>
Subject: [PATCH v4 8/8] auto-t: add tests for Affinities behavior
Date: Fri, 23 Aug 2024 15:23:39 -0700 [thread overview]
Message-ID: <20240823222339.328006-8-prestwoj@gmail.com> (raw)
In-Reply-To: <20240823222339.328006-1-prestwoj@gmail.com>
---
autotests/testAffinity/TestFT.psk | 2 +
autotests/testAffinity/ft-psk-ccmp-1.conf | 41 ++++
autotests/testAffinity/ft-psk-ccmp-2.conf | 41 ++++
autotests/testAffinity/hw.conf | 8 +
autotests/testAffinity/main.conf | 5 +
autotests/testAffinity/test_set_affinity.py | 216 ++++++++++++++++++++
6 files changed, 313 insertions(+)
create mode 100644 autotests/testAffinity/TestFT.psk
create mode 100644 autotests/testAffinity/ft-psk-ccmp-1.conf
create mode 100644 autotests/testAffinity/ft-psk-ccmp-2.conf
create mode 100644 autotests/testAffinity/hw.conf
create mode 100644 autotests/testAffinity/main.conf
create mode 100644 autotests/testAffinity/test_set_affinity.py
diff --git a/autotests/testAffinity/TestFT.psk b/autotests/testAffinity/TestFT.psk
new file mode 100644
index 00000000..e82d1295
--- /dev/null
+++ b/autotests/testAffinity/TestFT.psk
@@ -0,0 +1,2 @@
+[Security]
+Passphrase=EasilyGuessedPassword
diff --git a/autotests/testAffinity/ft-psk-ccmp-1.conf b/autotests/testAffinity/ft-psk-ccmp-1.conf
new file mode 100644
index 00000000..839eb496
--- /dev/null
+++ b/autotests/testAffinity/ft-psk-ccmp-1.conf
@@ -0,0 +1,41 @@
+hw_mode=g
+channel=1
+ssid=TestFT
+utf8_ssid=1
+ctrl_interface=/var/run/hostapd
+
+r1_key_holder=120000000001
+nas_identifier=dummy1
+
+wpa=2
+# Can support WPA-PSK and FT-PSK (space separated list) and/or EAP at the same
+# time but we want to force FT
+wpa_key_mgmt=FT-PSK
+wpa_pairwise=CCMP
+wpa_passphrase=EasilyGuessedPassword
+ieee80211w=0
+rsn_preauth=1
+rsn_preauth_interfaces=lo
+disable_pmksa_caching=0
+# Allow PMK cache to be shared opportunistically among configured interfaces
+# and BSSes (i.e., all configurations within a single hostapd process).
+okc=1
+mobility_domain=1234
+reassociation_deadline=60000
+r0kh=12:00:00:00:00:01 dummy1 000102030405060708090a0b0c0d0e0f
+r0kh=12:00:00:00:00:02 dummy2 000102030405060708090a0b0c0d0e0f
+r1kh=12:00:00:00:00:01 00:00:00:00:00:01 000102030405060708090a0b0c0d0e0f
+r1kh=12:00:00:00:00:02 00:00:00:00:00:02 000102030405060708090a0b0c0d0e0f
+# Push mode only needed for 8021x, not PSK mode since msk already known
+pmk_r1_push=0
+# Allow locally generated FT response so we don't have to configure push/pull
+# between BSSes running as separate hostapd processes as in the test-runner
+# case. Only works with FT-PSK, otherwise brctl needs to be installed and
+# CONFIG_BRIDGE enabled in the kernel.
+ft_psk_generate_local=1
+rkh_pull_timeout=50
+ft_over_ds=0
+ap_table_expiration_time=36000
+ap_table_max_size=10
+rrm_neighbor_report=1
+ocv=1
diff --git a/autotests/testAffinity/ft-psk-ccmp-2.conf b/autotests/testAffinity/ft-psk-ccmp-2.conf
new file mode 100644
index 00000000..2ffd7262
--- /dev/null
+++ b/autotests/testAffinity/ft-psk-ccmp-2.conf
@@ -0,0 +1,41 @@
+hw_mode=g
+channel=2
+ssid=TestFT
+utf8_ssid=1
+ctrl_interface=/var/run/hostapd
+
+r1_key_holder=120000000002
+nas_identifier=dummy2
+
+wpa=2
+# Can support WPA-PSK and FT-PSK (space separated list) and/or EAP at the same
+# time but we want to force FT
+wpa_key_mgmt=FT-PSK
+wpa_pairwise=CCMP
+wpa_passphrase=EasilyGuessedPassword
+ieee80211w=0
+rsn_preauth=1
+rsn_preauth_interfaces=lo
+disable_pmksa_caching=0
+# Allow PMK cache to be shared opportunistically among configured interfaces
+# and BSSes (i.e., all configurations within a single hostapd process).
+okc=1
+mobility_domain=1234
+reassociation_deadline=60000
+r0kh=12:00:00:00:00:01 dummy1 000102030405060708090a0b0c0d0e0f
+r0kh=12:00:00:00:00:02 dummy2 000102030405060708090a0b0c0d0e0f
+r1kh=12:00:00:00:00:01 00:00:00:00:00:01 000102030405060708090a0b0c0d0e0f
+r1kh=12:00:00:00:00:02 00:00:00:00:00:02 000102030405060708090a0b0c0d0e0f
+# Push mode only needed for 8021x, not PSK mode since msk already known
+pmk_r1_push=0
+# Allow locally generated FT response so we don't have to configure push/pull
+# between BSSes running as separate hostapd processes as in the test-runner
+# case. Only works with FT-PSK, otherwise brctl needs to be installed and
+# CONFIG_BRIDGE enabled in the kernel.
+ft_psk_generate_local=1
+rkh_pull_timeout=50
+ft_over_ds=0
+ap_table_expiration_time=36000
+ap_table_max_size=10
+rrm_neighbor_report=1
+ocv=1
diff --git a/autotests/testAffinity/hw.conf b/autotests/testAffinity/hw.conf
new file mode 100644
index 00000000..c2b35d6e
--- /dev/null
+++ b/autotests/testAffinity/hw.conf
@@ -0,0 +1,8 @@
+[SETUP]
+num_radios=3
+start_iwd=0
+hwsim_medium=yes
+
+[HOSTAPD]
+rad0=ft-psk-ccmp-1.conf
+rad1=ft-psk-ccmp-2.conf
diff --git a/autotests/testAffinity/main.conf b/autotests/testAffinity/main.conf
new file mode 100644
index 00000000..3d93ff57
--- /dev/null
+++ b/autotests/testAffinity/main.conf
@@ -0,0 +1,5 @@
+[Scan]
+DisableMacAddressRandomization=true
+
+[General]
+RoamRetryInterval=1
diff --git a/autotests/testAffinity/test_set_affinity.py b/autotests/testAffinity/test_set_affinity.py
new file mode 100644
index 00000000..5754aee0
--- /dev/null
+++ b/autotests/testAffinity/test_set_affinity.py
@@ -0,0 +1,216 @@
+#! /usr/bin/python3
+
+import unittest
+import sys, os
+import dbus
+
+sys.path.append('../util')
+from config import ctx
+import iwd
+from iwd import IWD, IWDDBusAbstract
+from iwd import NetworkType
+from hwsim import Hwsim
+from hostapd import HostapdCLI
+
+#
+# Separate client used to test DBus disconnects so we don't bring down the
+# entire IWD python library
+#
+class AffinityClient(IWDDBusAbstract):
+ def __init__(self, device_path):
+ self._bus = dbus.bus.BusConnection(address_or_type=ctx.dbus_address)
+ self._station_prop_if = dbus.Interface(
+ self._bus.get_object(iwd.IWD_SERVICE, device_path),
+ iwd.DBUS_PROPERTIES)
+
+ def set(self, values):
+ self._station_prop_if.Set(iwd.IWD_STATION_INTERFACE, 'Affinities', dbus.Array([dbus.ObjectPath(v) for v in values], signature="o"))
+
+ def close(self):
+ self._bus.close()
+
+class Test(unittest.TestCase):
+ def connect(self, device, hapd):
+ ordered_network = device.get_ordered_network('TestFT', full_scan=True)
+
+ self.assertEqual(ordered_network.type, NetworkType.psk)
+
+ condition = 'not obj.connected'
+ self.wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+ device.connect_bssid(hapd.bssid)
+
+ condition = 'obj.state == DeviceState.connected'
+ self.wd.wait_for_object_condition(device, condition)
+
+ def test_set_affinity(self):
+ device = self.wd.list_devices(1)[0]
+
+ self.connect(device, self.bss_hostapd[0])
+
+ print(device.connected_bss)
+
+ device.affinities = [device.connected_bss]
+
+ # IWD should not attempt to roam
+ with self.assertRaises(TimeoutError):
+ device.wait_for_event("roam-scan-triggered")
+
+ device.affinities = []
+ device.wait_for_event("roam-scan-triggered")
+
+ def test_roam_below_critical(self):
+ device = self.wd.list_devices(1)[0]
+
+ self.connect(device, self.bss_hostapd[0])
+
+ device.affinities = [device.connected_bss]
+
+ # IWD should not attempt to roam
+ with self.assertRaises(TimeoutError):
+ device.wait_for_event("roam-scan-triggered")
+
+ # Lower signal past critical level
+ self.bss0_rule.signal = -9000
+
+ device.wait_for_event("roam-scan-triggered")
+
+ def test_error_conditions(self):
+ device = self.wd.list_devices(1)[0]
+
+ # Calling set while disconnected should fail
+ with self.assertRaises(iwd.NotConnectedEx):
+ device.affinities = ["/some/path"]
+
+ self.connect(device, self.bss_hostapd[0])
+
+ device.affinities = [device.connected_bss]
+
+ # An invalid path should fail
+ with self.assertRaises(iwd.InvalidArgumentsEx):
+ device.affinities = [device.connected_bss, "/an/invalid/path"]
+
+ def test_affinity_client_disconnect(self):
+ device = self.wd.list_devices(1)[0]
+
+ client = AffinityClient(device.device_path)
+
+ self.connect(device, self.bss_hostapd[0])
+
+ client.set([device.connected_bss])
+
+ with self.assertRaises(TimeoutError):
+ device.wait_for_event("roam-scan-triggered")
+
+ client._bus.close()
+
+ device.wait_for_event("roam-scan-triggered")
+
+ def test_affinity_client_reconnect_during_roam(self):
+ device = self.wd.list_devices(1)[0]
+
+ client = AffinityClient(device.device_path)
+
+ self.connect(device, self.bss_hostapd[0])
+
+ client.set([device.connected_bss])
+
+ # Lower signal past critical level
+ self.bss0_rule.signal = -9000
+
+ device.wait_for_event("roam-scan-triggered")
+
+ client.close()
+ del client
+ client = AffinityClient(device.device_path)
+ # setting here should get cleared after connecting
+ client.set([device.connected_bss])
+
+ device.wait_for_event("ft-authenticating")
+ device.wait_for_event("associating")
+ device.wait_for_event("connected")
+
+ # Affinity should be reset, and IWD should be trying to roam
+ device.wait_for_event("roam-scan-triggered")
+
+ def test_cleanup_with_connected_client(self):
+ device = self.wd.list_devices(1)[0]
+
+ client = AffinityClient(device.device_path)
+
+ self.connect(device, self.bss_hostapd[0])
+
+ client.set([device.connected_bss])
+ self.wd.stop()
+
+ def test_affinity_removed_after_roam(self):
+ device = self.wd.list_devices(1)[0]
+
+ self.connect(device, self.bss_hostapd[0])
+
+ device.affinities = [device.connected_bss]
+
+ # Lower signal past critical level
+ self.bss0_rule.signal = -9000
+
+ device.wait_for_event("roam-scan-triggered")
+
+ device.wait_for_event("ft-authenticating")
+ device.wait_for_event("associating")
+ device.wait_for_event("connected")
+
+ self.assertEqual(device.affinities, [])
+
+ def tearDown(self):
+ os.system('ip link set "' + self.bss_hostapd[0].ifname + '" down')
+ os.system('ip link set "' + self.bss_hostapd[1].ifname + '" down')
+ os.system('ip link set "' + self.bss_hostapd[0].ifname + '" up')
+ os.system('ip link set "' + self.bss_hostapd[1].ifname + '" up')
+
+ self.wd.stop()
+ self.wd = None
+
+ def setUp(self):
+ self.bss0_rule.signal = -8000
+ self.bss1_rule.signal = -8000
+
+ self.wd = IWD(True)
+
+ @classmethod
+ def setUpClass(cls):
+ hwsim = Hwsim()
+
+ IWD.copy_to_storage('TestFT.psk')
+
+ cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'),
+ HostapdCLI(config='ft-psk-ccmp-2.conf') ]
+
+ rad0 = hwsim.get_radio('rad0')
+ rad1 = hwsim.get_radio('rad1')
+
+ cls.bss0_rule = hwsim.rules.create()
+ cls.bss0_rule.source = rad0.addresses[0]
+ cls.bss0_rule.bidirectional = True
+ cls.bss0_rule.signal = -8000
+ cls.bss0_rule.enabled = True
+
+ cls.bss1_rule = hwsim.rules.create()
+ cls.bss1_rule.source = rad1.addresses[0]
+ cls.bss1_rule.bidirectional = True
+ cls.bss1_rule.signal = -8000
+ cls.bss1_rule.enabled = True
+
+ cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
+ cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
+
+ HostapdCLI.group_neighbors(*cls.bss_hostapd)
+
+ @classmethod
+ def tearDownClass(cls):
+ IWD.clear_storage()
+ cls.bss_hostapd = None
+ cls.bss0_rule.remove()
+ cls.bss1_rule.remove()
+
+if __name__ == '__main__':
+ unittest.main(exit=True)
--
2.34.1
next prev parent reply other threads:[~2024-08-23 22:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-23 22:23 [PATCH v4 1/8] doc: Document station Affinities property James Prestwood
2024-08-23 22:23 ` [PATCH v4 2/8] netdev: define netdev settings in netdev.h James Prestwood
2024-08-28 2:44 ` Denis Kenzior
2024-08-23 22:23 ` [PATCH v4 3/8] netdev: store signal threshold in netdev object, not globally James Prestwood
2024-08-23 22:23 ` [PATCH v4 4/8] netdev: add critical signal threshold level James Prestwood
2024-08-23 22:23 ` [PATCH v4 5/8] station: add Affinities DBus property James Prestwood
2024-08-28 2:57 ` Denis Kenzior
2024-08-23 22:23 ` [PATCH v4 6/8] station: Use Affinities property to change roaming threshold James Prestwood
2024-08-23 22:23 ` [PATCH v4 7/8] auto-t: add affinities property for station, and extended_service_set James Prestwood
2024-08-23 22:23 ` James Prestwood [this message]
2024-08-28 2:39 ` [PATCH v4 1/8] doc: Document station Affinities property Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240823222339.328006-8-prestwoj@gmail.com \
--to=prestwoj@gmail.com \
--cc=iwd@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox