eiwd

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

connection_test.py (2869B)


      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 from hwsim import Hwsim
     12 import testutil
     13 from hostapd import HostapdCLI
     14 
     15 class Test(unittest.TestCase):
     16     def do_connect(self, wd, device, hostapd):
     17         #
     18         # Scanning must be explicitly done to get updated RSSI values. Therefore
     19         # full_scan is set.
     20         #
     21         ordered_network = device.get_ordered_network('testSSID', full_scan=True)
     22 
     23         self.assertEqual(ordered_network.type, NetworkType.psk)
     24 
     25         condition = 'not obj.connected'
     26         wd.wait_for_object_condition(ordered_network.network_object, condition)
     27 
     28         ordered_network.network_object.connect()
     29 
     30         condition = 'obj.state == DeviceState.connected'
     31         wd.wait_for_object_condition(device, condition)
     32 
     33         testutil.test_iface_operstate()
     34         testutil.test_ifaces_connected(device.name, hostapd.ifname)
     35 
     36         device.disconnect()
     37 
     38         condition = 'not obj.connected'
     39         wd.wait_for_object_condition(ordered_network.network_object, condition)
     40 
     41     def test_connection_success(self):
     42         hwsim = Hwsim()
     43         non_ht_hostapd = HostapdCLI(config='non-ht-vht.conf')
     44         ht_hostapd = HostapdCLI(config='ht.conf')
     45         vht_hostapd = HostapdCLI(config='vht.conf')
     46         non_ht_radio = hwsim.get_radio('rad0')
     47         ht_radio = hwsim.get_radio('rad1')
     48         vht_radio = hwsim.get_radio('rad2')
     49 
     50         self.assertIsNotNone(non_ht_hostapd)
     51         self.assertIsNotNone(ht_hostapd)
     52         self.assertIsNotNone(vht_hostapd)
     53 
     54         rule0 = hwsim.rules.create()
     55         rule0.source = vht_radio.addresses[0]
     56         rule0.bidirectional = True
     57         rule0.signal = -5100
     58         rule0.enabled = True
     59 
     60         rule1 = hwsim.rules.create()
     61         rule1.source = ht_radio.addresses[0]
     62         rule1.bidirectional = True
     63         rule1.signal = -5200
     64         rule1.enabled = True
     65 
     66         rule2 = hwsim.rules.create()
     67         rule2.source = non_ht_radio.addresses[0]
     68         rule2.bidirectional = True
     69         rule2.signal = -5300
     70         rule2.enabled = True
     71 
     72         wd = IWD()
     73 
     74         psk_agent = PSKAgent("secret123")
     75         wd.register_psk_agent(psk_agent)
     76 
     77         device = wd.list_devices(1)[0]
     78 
     79         self.do_connect(wd, device, vht_hostapd)
     80 
     81         # lower VHT BSS signal, HT should now be preferred
     82         rule0.signal = -8200
     83 
     84         self.do_connect(wd, device, ht_hostapd)
     85 
     86         # lower HT BSS signal, basic rate BSS should now be preferred
     87         rule1.signal = -7600
     88 
     89         self.do_connect(wd, device, non_ht_hostapd)
     90 
     91         wd.unregister_psk_agent(psk_agent)
     92 
     93     @classmethod
     94     def setUpClass(cls):
     95         pass
     96 
     97     @classmethod
     98     def tearDownClass(cls):
     99         IWD.clear_storage()
    100 
    101 if __name__ == '__main__':
    102     unittest.main(exit=True)