eiwd

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

roam_blacklist_test.py (6676B)


      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, IWD_CONFIG_DIR
      9 from iwd import NetworkType
     10 
     11 from hostapd import HostapdCLI
     12 from hwsim import Hwsim
     13 
     14 class Test(unittest.TestCase):
     15     def validate_connected(self, hostapd):
     16         ordered_network = self.device.get_ordered_network('TestAPRoam')
     17 
     18         self.assertEqual(ordered_network.type, NetworkType.psk)
     19 
     20         condition = 'not obj.connected'
     21         self.wd.wait_for_object_condition(ordered_network.network_object, condition)
     22 
     23         self.device.connect_bssid(hostapd.bssid)
     24 
     25         condition = 'obj.state == DeviceState.connected'
     26         self.wd.wait_for_object_condition(self.device, condition)
     27 
     28         hostapd.wait_for_event('AP-STA-CONNECTED')
     29 
     30     def validate_ap_roamed(self, from_hostapd, to_hostapd):
     31         from_hostapd.send_bss_transition(
     32             self.device.address, self.neighbor_list, disassoc_imminent=True
     33         )
     34 
     35         from_condition = 'obj.state == DeviceState.roaming'
     36         to_condition = 'obj.state == DeviceState.connected'
     37         self.wd.wait_for_object_change(self.device, from_condition, to_condition)
     38 
     39         to_hostapd.wait_for_event('AP-STA-CONNECTED %s' % self.device.address)
     40 
     41         self.device.wait_for_event("ap-roam-blacklist-added")
     42 
     43     def test_roam_to_optimal_candidates(self):
     44         # In this test IWD will naturally transition down the list after each
     45         # BSS gets roam blacklisted. All BSS's are above the RSSI thresholds.
     46         self.rule_ssid1.signal = -5000
     47         self.rule_ssid2.signal = -6500
     48         self.rule_ssid3.signal = -6900
     49 
     50         # Connect to BSS0
     51         self.validate_connected(self.bss_hostapd[0])
     52 
     53         # AP directed roam to BSS1
     54         self.validate_ap_roamed(self.bss_hostapd[0], self.bss_hostapd[1])
     55 
     56         # AP directed roam to BSS2
     57         self.validate_ap_roamed(self.bss_hostapd[1], self.bss_hostapd[2])
     58 
     59     def test_avoiding_under_threshold_bss(self):
     60         # In this test IWD will blacklist BSS0, then roam the BSS1. BSS1 will
     61         # then tell IWD to roam, but it should go back to BSS0 since the only
     62         # non-blacklisted BSS is under the roam threshold.
     63         self.rule_ssid1.signal = -5000
     64         self.rule_ssid2.signal = -6500
     65         self.rule_ssid3.signal = -7300
     66 
     67         # Connect to BSS0
     68         self.validate_connected(self.bss_hostapd[0])
     69 
     70         # AP directed roam to BSS1
     71         self.validate_ap_roamed(self.bss_hostapd[0], self.bss_hostapd[1])
     72 
     73         # AP directed roam, but IWD should choose BSS0 since BSS2 is -73dB
     74         self.validate_ap_roamed(self.bss_hostapd[1], self.bss_hostapd[0])
     75 
     76     def test_connect_to_roam_blacklisted_bss(self):
     77         # In this test a BSS will be roam blacklisted, but all other options are
     78         # below the RSSI threshold so IWD should roam back to the blacklisted
     79         # BSS.
     80         self.rule_ssid1.signal = -5000
     81         self.rule_ssid2.signal = -8000
     82         self.rule_ssid3.signal = -8500
     83 
     84         # Connect to BSS0
     85         self.validate_connected(self.bss_hostapd[0])
     86 
     87         # AP directed roam, should connect to BSS1 as its the next best
     88         self.validate_ap_roamed(self.bss_hostapd[0], self.bss_hostapd[1])
     89 
     90         # Connected to BSS1, but the signal is bad, so IWD should try to roam
     91         # again. BSS0 is still blacklisted, but its the only reasonable option
     92         # since both BSS1 and BSS2 are below the set RSSI threshold (-72dB)
     93 
     94         from_condition = 'obj.state == DeviceState.roaming'
     95         to_condition = 'obj.state == DeviceState.connected'
     96         self.wd.wait_for_object_change(self.device, from_condition, to_condition)
     97 
     98         # IWD should have connected to BSS0, even though its roam blacklisted
     99         self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % self.device.address)
    100 
    101     def test_blacklist_during_roam_scan(self):
    102         # Tests that an AP roam request mid-roam results in the AP still being
    103         # blacklisted even though the request itself doesn't directly trigger
    104         # a roam.
    105         self.rule_ssid1.signal = -7300
    106         self.rule_ssid2.signal = -7500
    107         self.rule_ssid3.signal = -8500
    108 
    109         # Connect to BSS0 under the roam threshold so IWD will immediately try
    110         # roaming elsewhere
    111         self.validate_connected(self.bss_hostapd[0])
    112 
    113         self.device.wait_for_event("roam-scan-triggered")
    114 
    115         self.bss_hostapd[0].send_bss_transition(
    116             self.device.address, self.neighbor_list, disassoc_imminent=True
    117         )
    118         self.device.wait_for_event("ap-roam-blacklist-added")
    119 
    120         # BSS0 should have gotten blacklisted even though IWD was mid-roam,
    121         # causing IWD to choose BSS1 when it gets is results.
    122 
    123         from_condition = 'obj.state == DeviceState.roaming'
    124         to_condition = 'obj.state == DeviceState.connected'
    125         self.wd.wait_for_object_change(self.device, from_condition, to_condition)
    126 
    127         self.bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % self.device.address)
    128 
    129     def setUp(self):
    130         self.wd = IWD(True)
    131 
    132         devices = self.wd.list_devices(1)
    133         self.device = devices[0]
    134 
    135 
    136     def tearDown(self):
    137         self.wd = None
    138         self.device = None
    139 
    140 
    141     @classmethod
    142     def setUpClass(cls):
    143         IWD.copy_to_storage("main.conf.roaming", IWD_CONFIG_DIR, "main.conf")
    144         IWD.copy_to_storage('TestAPRoam.psk')
    145         hwsim = Hwsim()
    146 
    147         cls.bss_hostapd = [ HostapdCLI(config='ssid1.conf'),
    148                             HostapdCLI(config='ssid2.conf'),
    149                             HostapdCLI(config='ssid3.conf') ]
    150         HostapdCLI.group_neighbors(*cls.bss_hostapd)
    151 
    152         rad0 = hwsim.get_radio('rad0')
    153         rad1 = hwsim.get_radio('rad1')
    154         rad2 = hwsim.get_radio('rad2')
    155 
    156         cls.neighbor_list = [
    157             (cls.bss_hostapd[0].bssid, "8f0000005101060603000000"),
    158             (cls.bss_hostapd[1].bssid, "8f0000005102060603000000"),
    159             (cls.bss_hostapd[2].bssid, "8f0000005103060603000000"),
    160         ]
    161 
    162 
    163         cls.rule_ssid1 = hwsim.rules.create()
    164         cls.rule_ssid1.source = rad0.addresses[0]
    165         cls.rule_ssid1.bidirectional = True
    166         cls.rule_ssid1.enabled = True
    167 
    168         cls.rule_ssid2 = hwsim.rules.create()
    169         cls.rule_ssid2.source = rad1.addresses[0]
    170         cls.rule_ssid2.bidirectional = True
    171         cls.rule_ssid2.enabled = True
    172 
    173         cls.rule_ssid3 = hwsim.rules.create()
    174         cls.rule_ssid3.source = rad2.addresses[0]
    175         cls.rule_ssid3.bidirectional = True
    176         cls.rule_ssid3.enabled = True
    177 
    178     @classmethod
    179     def tearDownClass(cls):
    180         IWD.clear_storage()
    181 
    182 if __name__ == '__main__':
    183     unittest.main(exit=True)