fast_retry_test.py (3656B)
1 #!/usr/bin/python3 2 3 import unittest 4 import sys 5 6 sys.path.append('../util') 7 import iwd 8 from iwd import IWD 9 from iwd import PSKAgent 10 from iwd import NetworkType 11 12 import testutil 13 14 from hostapd import HostapdCLI 15 from hwsim import Hwsim 16 17 class Test(unittest.TestCase): 18 # Normally the time between a failed roam attempt and the next roam attempt 19 # is 60 seconds (default RoamRetryInterval). Test that we retry roaming 20 # faster if the transition looks like this: LOW [roam] [same bss] HIGH LOW. 21 def test_fast_retry(self): 22 hwsim = Hwsim() 23 24 bss_hostapd = [ HostapdCLI(config='ssid1.conf'), 25 HostapdCLI(config='ssid2.conf') ] 26 bss_radio = [ hwsim.get_radio('rad0'), 27 hwsim.get_radio('rad1') ] 28 29 rule0 = hwsim.rules.create() 30 rule0.source = bss_radio[0].addresses[0] 31 rule0.bidirectional = True 32 rule0.enabled = True 33 34 rule1 = hwsim.rules.create() 35 rule1.source = bss_radio[1].addresses[0] 36 rule1.bidirectional = True 37 rule1.enabled = True 38 39 HostapdCLI.group_neighbors(*bss_hostapd) 40 41 # Start in the vicinity of BSS 0, check that iwd connects to BSS 0 42 rule0.signal = -2000 43 rule1.signal = -8500 44 45 wd = IWD() 46 47 psk_agent = PSKAgent("secret123") 48 wd.register_psk_agent(psk_agent) 49 50 devices = wd.list_devices(1) 51 device = devices[0] 52 53 ordered_network = device.get_ordered_network('TestRoamRetry', full_scan=True) 54 55 self.assertEqual(ordered_network.type, NetworkType.psk) 56 57 condition = 'not obj.connected' 58 wd.wait_for_object_condition(ordered_network.network_object, condition) 59 60 ordered_network.network_object.connect() 61 62 condition = 'obj.state == DeviceState.connected' 63 wd.wait_for_object_condition(device, condition) 64 65 bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address) 66 67 wd.wait(5) 68 69 # Now push the signal LOW, wait for iwd to attempt a roam, fail, and 70 # schedule another attempt 71 rule0.signal = -8000 72 73 device.wait_for_event('no-roam-candidates') 74 75 self.assertEqual(device.state, iwd.DeviceState.connected) 76 77 self.assertTrue(bss_hostapd[0].list_sta()) 78 self.assertFalse(bss_hostapd[1].list_sta()) 79 80 testutil.test_iface_operstate(device.name) 81 testutil.test_ifaces_connected(bss_hostapd[0].ifname, device.name) 82 83 # Assert high signal for BSS 0 again. This clears the way for a faster 84 # roam attempt on LOW again 85 rule0.signal = -5000 86 87 # Wait a little for signal recognition 88 wd.wait(1) 89 90 # Assert low signal for BSS 0, check that iwd starts transition to BSS 1 91 rule0.signal = -8000 92 rule1.signal = -2000 93 94 # Check that iwd is on BSS 1 once out of roaming state and doesn't 95 # go through 'disconnected', 'autoconnect', 'connecting' in between 96 from_condition = 'obj.state == DeviceState.roaming' 97 to_condition = 'obj.state == DeviceState.connected' 98 wd.wait_for_object_change(device, from_condition, to_condition) 99 100 bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % device.address) 101 102 device.disconnect() 103 104 condition = 'not obj.connected' 105 wd.wait_for_object_condition(ordered_network.network_object, condition) 106 107 wd.unregister_psk_agent(psk_agent) 108 109 rule0.remove() 110 rule1.remove() 111 112 @classmethod 113 def setUpClass(cls): 114 pass 115 116 @classmethod 117 def tearDownClass(cls): 118 IWD.clear_storage() 119 120 if __name__ == '__main__': 121 unittest.main(exit=True)