eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

failed_roam_test.py (9102B)


      1 #! /usr/bin/python3
      2 
      3 import unittest
      4 import os, sys
      5 
      6 sys.path.append('../util')
      7 from iwd import IWD
      8 from iwd import NetworkType, DeviceState
      9 from hwsim import Hwsim
     10 from hostapd import HostapdCLI
     11 import testutil
     12 
     13 class Test(unittest.TestCase):
     14     def connect(self, wd, device, hostapd):
     15         ordered_network = device.get_ordered_network('TestFT', full_scan=True)
     16 
     17         self.assertEqual(ordered_network.type, NetworkType.psk)
     18 
     19         condition = 'not obj.connected'
     20         wd.wait_for_object_condition(ordered_network.network_object, condition)
     21 
     22         device.connect_bssid(hostapd.bssid)
     23 
     24         condition = 'obj.state == DeviceState.connected'
     25         wd.wait_for_object_condition(device, condition)
     26 
     27         hostapd.wait_for_event('AP-STA-CONNECTED %s' % device.address)
     28 
     29         testutil.test_iface_operstate(device.name)
     30         testutil.test_ifaces_connected(hostapd.ifname, device.name)
     31 
     32     def verify_roam(self, wd, device, prev, new):
     33         from_condition = 'obj.state == DeviceState.roaming'
     34         to_condition = 'obj.state == DeviceState.connected'
     35         wd.wait_for_object_change(device, from_condition, to_condition)
     36 
     37         new.wait_for_event('AP-STA-CONNECTED %s' % device.address)
     38 
     39         testutil.test_iface_operstate(device.name)
     40         testutil.test_ifaces_connected(new.ifname, device.name)
     41         self.assertRaises(Exception, testutil.test_ifaces_connected,
     42                           (prev.ifname, device.name, True, True))
     43 
     44     # FT-over-Air failure, should stay connected
     45     def test_ft_over_air_failure(self):
     46         self.rule2.enabled = True
     47         self.rule3.enabled = True
     48 
     49         device = self.wd.list_devices(1)[0]
     50 
     51         self.connect(self.wd, device, self.bss_hostapd[0])
     52 
     53         self.rule0.enabled = True
     54 
     55         # IWD should connect, then attempt a roam to BSS 1, which should fail...
     56         device.wait_for_event('ft-roam-failed', timeout=60)
     57         # ... but IWD should remain connected
     58         self.assertTrue(device.state == DeviceState.connected)
     59 
     60         self.rule0.enabled = False
     61 
     62         # IWD should then try BSS 2, and succeed
     63         device.wait_for_event('ft-roaming', timeout=60)
     64         self.verify_roam(self.wd, device, self.bss_hostapd[0], self.bss_hostapd[2])
     65 
     66         self.bss_hostapd[2].deauthenticate(device.address)
     67 
     68     # Tests that an associate even should cause a disconnect
     69     def test_ft_over_air_assoc_timeout(self):
     70         self.rule2.enabled = True
     71         self.rule3.enabled = True
     72         self.assoc_rule.enabled = True
     73 
     74         device = self.wd.list_devices(1)[0]
     75 
     76         self.connect(self.wd, device, self.bss_hostapd[0])
     77 
     78         device.wait_for_event('ft-roaming', timeout=60)
     79 
     80         condition = 'obj.state == DeviceState.disconnected'
     81         self.wd.wait_for_object_condition(device, condition)
     82 
     83     # FT-over-Air failure with Invalid PMKID, should reassociate
     84     def test_ft_over_air_fallback(self):
     85         self.rule_bss0.signal = -8000
     86         self.rule_bss0.enabled = True
     87         self.rule_bss1.signal = -7500
     88         self.rule_bss1.enabled = True
     89         self.rule_bss2.signal = -6000
     90         self.rule_bss2.enabled = True
     91 
     92         # This will cause this BSS to reject any FT roams as its unable to
     93         # get keys from other APs
     94         self.bss_hostapd[2].set_value('ft_psk_generate_local', '0')
     95         self.bss_hostapd[2].reload()
     96 
     97         device = self.wd.list_devices(1)[0]
     98 
     99         self.connect(self.wd, device, self.bss_hostapd[0])
    100 
    101         # IWD should connect, then attempt a roam to BSS 1, which should
    102         # fail and cause a fallback to reassociation
    103         device.wait_for_event('ft-fallback-to-reassoc', timeout=60)
    104         device.wait_for_event('roaming', timeout=60)
    105 
    106         self.verify_roam(self.wd, device, self.bss_hostapd[0], self.bss_hostapd[2])
    107 
    108         # Trigger another roam
    109         self.rule_bss2.signal = -8000
    110 
    111         device.wait_for_event('ft-roaming', timeout=60)
    112 
    113         # Ensure an FT roam back to a properly configured AP works.
    114         self.verify_roam(self.wd, device, self.bss_hostapd[2], self.bss_hostapd[1])
    115 
    116         self.bss_hostapd[1].deauthenticate(device.address)
    117         condition = 'obj.state == DeviceState.disconnected'
    118         self.wd.wait_for_object_condition(device, condition)
    119 
    120     # FT-over-Air failure with Invalid PMKID. The ranking is such that other
    121     # FT candidates are available so it should FT elsewhere rather than
    122     # retry with reassociation
    123     def test_ft_over_air_fallback_retry_ft(self):
    124         self.rule_bss0.signal = -8000
    125         self.rule_bss0.enabled = True
    126         self.rule_bss1.signal = -7300
    127         self.rule_bss1.enabled = True
    128         self.rule_bss2.signal = -7100
    129         self.rule_bss2.enabled = True
    130 
    131         # This will cause this BSS to reject any FT roams as its unable to
    132         # get keys from other APs
    133         self.bss_hostapd[2].set_value('ft_psk_generate_local', '0')
    134         self.bss_hostapd[2].reload()
    135 
    136         device = self.wd.list_devices(1)[0]
    137 
    138         self.connect(self.wd, device, self.bss_hostapd[0])
    139 
    140         # IWD should connect, then attempt a roam to BSS 1, which should
    141         # fail and cause the rank to be re-computed. This should then put
    142         # bss 1 as the next candidate (since the FT factor is removed)
    143         device.wait_for_event('ft-fallback-to-reassoc', timeout=60)
    144         device.wait_for_event('ft-roaming', timeout=60)
    145 
    146         self.verify_roam(self.wd, device, self.bss_hostapd[0], self.bss_hostapd[1])
    147 
    148         self.bss_hostapd[1].deauthenticate(device.address)
    149         condition = 'obj.state == DeviceState.disconnected'
    150         self.wd.wait_for_object_condition(device, condition)
    151 
    152     def test_ft_deauth_before_association(self):
    153         self.rule2.enabled = True
    154         self.rule3.enabled = True
    155 
    156         device = self.wd.list_devices(1)[0]
    157 
    158         self.connect(self.wd, device, self.bss_hostapd[0])
    159 
    160         device.wait_for_event('ft-authenticating', timeout=60)
    161 
    162         self.bss_hostapd[1].deauthenticate(device.address)
    163 
    164         condition = 'obj.state == DeviceState.disconnected'
    165         self.wd.wait_for_object_condition(device, condition)
    166 
    167     def setUp(self):
    168         self.wd = IWD(True)
    169 
    170     def tearDown(self):
    171         os.system('ip link set "' + self.bss_hostapd[0].ifname + '" down')
    172         os.system('ip link set "' + self.bss_hostapd[1].ifname + '" down')
    173         os.system('ip link set "' + self.bss_hostapd[0].ifname + '" up')
    174         os.system('ip link set "' + self.bss_hostapd[1].ifname + '" up')
    175 
    176         self.rule0.enabled = False
    177         self.rule1.enabled = False
    178         self.rule2.enabled = False
    179         self.rule3.enabled = False
    180         self.rule_bss0.enabled = False
    181         self.rule_bss1.enabled = False
    182         self.rule_bss2.enabled = False
    183         self.assoc_rule.enabled = False
    184 
    185         for hapd in self.bss_hostapd:
    186             hapd.default()
    187 
    188         self.wd.stop()
    189         self.wd = None
    190 
    191     @classmethod
    192     def setUpClass(cls):
    193         hwsim = Hwsim()
    194 
    195         IWD.copy_to_storage('TestFT.psk')
    196 
    197         cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'),
    198                             HostapdCLI(config='ft-psk-ccmp-2.conf'),
    199                             HostapdCLI(config='ft-psk-ccmp-3.conf') ]
    200 
    201         cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
    202         cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
    203         cls.bss_hostapd[2].set_address('12:00:00:00:00:03')
    204 
    205         # Drop Authenticate frames
    206         cls.rule0 = hwsim.rules.create()
    207         cls.rule0.source = hwsim.get_radio('rad1').addresses[0]
    208         cls.rule0.prefix = 'b0'
    209         cls.rule0.drop = True
    210 
    211         # Drop Associate frames
    212         cls.assoc_rule = hwsim.rules.create()
    213         cls.assoc_rule.prefix = '20'
    214         cls.assoc_rule.drop = True
    215 
    216         # Drop Action frames
    217         cls.rule1 = hwsim.rules.create()
    218         cls.rule1.bidirectional = True
    219         cls.rule1.prefix = 'd0'
    220         cls.rule1.drop = True
    221 
    222         # Causes IWD to immediately roam away from BSS 0
    223         cls.rule2 = hwsim.rules.create()
    224         cls.rule2.source = hwsim.get_radio('rad0').addresses[0]
    225         cls.rule2.signal = -8000
    226 
    227         # Causes IWD to first prefer BSS 1 to roam, then BSS 2.
    228         cls.rule3 = hwsim.rules.create()
    229         cls.rule3.source = hwsim.get_radio('rad2').addresses[0]
    230         cls.rule3.signal = -7000
    231 
    232         cls.rule_bss0 = hwsim.rules.create()
    233         cls.rule_bss0.source = hwsim.get_radio('rad0').addresses[0]
    234         cls.rule_bss1 = hwsim.rules.create()
    235         cls.rule_bss1.source = hwsim.get_radio('rad1').addresses[0]
    236         cls.rule_bss2 = hwsim.rules.create()
    237         cls.rule_bss2.source = hwsim.get_radio('rad2').addresses[0]
    238 
    239         HostapdCLI.group_neighbors(*cls.bss_hostapd)
    240 
    241     @classmethod
    242     def tearDownClass(cls):
    243         IWD.clear_storage()
    244         cls.bss_hostapd = None
    245         cls.rule0.remove()
    246         cls.rule1.remove()
    247         cls.rule2.remove()
    248         cls.rule3.remove()
    249         cls.assoc_rule.remove()
    250         cls.rule_bss0.remove()
    251         cls.rule_bss1.remove()
    252         cls.rule_bss2.remove()
    253 
    254 if __name__ == '__main__':
    255     unittest.main(exit=True)