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 (6509B)


      1 #! /usr/bin/python3
      2 
      3 import unittest
      4 import sys, os
      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 from hostapd import HostapdCLI
     13 import testutil
     14 
     15 class Test(unittest.TestCase):
     16     def validate_connection(self, wd, over_ds=False, pkt_loss=False):
     17         device = wd.list_devices(1)[0]
     18 
     19         ordered_network = device.get_ordered_network('TestFT', full_scan=True)
     20 
     21         self.assertEqual(ordered_network.type, NetworkType.psk)
     22 
     23         condition = 'not obj.connected'
     24         wd.wait_for_object_condition(ordered_network.network_object, condition)
     25 
     26         self.assertFalse(self.bss_hostapd[0].list_sta())
     27         self.assertFalse(self.bss_hostapd[1].list_sta())
     28 
     29         device.connect_bssid(self.bss_hostapd[0].bssid)
     30 
     31         condition = 'obj.state == DeviceState.connected'
     32         wd.wait_for_object_condition(device, condition)
     33 
     34         self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address)
     35 
     36         testutil.test_iface_operstate(device.name)
     37         testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name)
     38         self.assertRaises(Exception, testutil.test_ifaces_connected,
     39                           (self.bss_hostapd[1].ifname, device.name, True, True))
     40 
     41         if over_ds:
     42             self.rule0.enabled = True
     43 
     44         if pkt_loss:
     45             # Drop all data frames
     46             self.rule1.enabled = True
     47             # Set the current BSS signal lower so we have roam candidates
     48             self.rule2.enabled = True
     49             # Send 100 packets (to be dropped), should trigger beacon loss
     50             testutil.tx_packets(device.name, self.bss_hostapd[0].ifname, 100)
     51             device.wait_for_event('packet-loss-roam', timeout=60)
     52         else:
     53             device.roam(self.bss_hostapd[1].bssid)
     54 
     55         # Check that iwd is on BSS 1 once out of roaming state and doesn't
     56         # go through 'disconnected', 'autoconnect', 'connecting' in between
     57         from_condition = 'obj.state == DeviceState.roaming'
     58         to_condition = 'obj.state == DeviceState.connected'
     59         wd.wait_for_object_change(device, from_condition, to_condition)
     60 
     61         if pkt_loss:
     62             self.rule1.enabled = False
     63             self.rule2.enabled = False
     64 
     65         self.bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % device.address)
     66 
     67         testutil.test_iface_operstate(device.name)
     68         testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name)
     69         self.assertRaises(Exception, testutil.test_ifaces_connected,
     70                           (self.bss_hostapd[0].ifname, device.name, True, True))
     71 
     72         self.bss_hostapd[1].rekey(device.address)
     73 
     74         device.roam(self.bss_hostapd[0].bssid)
     75 
     76         # Check that iwd is on BSS 0 once out of roaming state and doesn't
     77         # go through 'disconnected', 'autoconnect', 'connecting' in between
     78         from_condition = 'obj.state == DeviceState.roaming'
     79         to_condition = 'obj.state == DeviceState.connected'
     80         wd.wait_for_object_change(device, from_condition, to_condition)
     81 
     82         self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address)
     83 
     84         testutil.test_iface_operstate(device.name)
     85         testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name)
     86         self.assertRaises(Exception, testutil.test_ifaces_connected,
     87                           (self.bss_hostapd[1].ifname, device.name, True, True))
     88 
     89         self.bss_hostapd[0].deauthenticate(device.address)
     90         condition = 'obj.state == DeviceState.disconnected'
     91         wd.wait_for_object_condition(device, condition)
     92 
     93     def test_ft_psk(self):
     94         self.validate_connection(self.wd)
     95 
     96     def test_ft_psk_over_ds(self):
     97         self.bss_hostapd[0].set_value('ft_over_ds', '1')
     98         self.bss_hostapd[0].reload()
     99         self.bss_hostapd[0].wait_for_event("AP-ENABLED")
    100 
    101         self.bss_hostapd[1].set_value('ft_over_ds', '1')
    102         self.bss_hostapd[1].reload()
    103         self.bss_hostapd[1].wait_for_event("AP-ENABLED")
    104 
    105         self.validate_connection(self.wd, over_ds=True)
    106 
    107     def test_reassociate_psk(self):
    108         self.bss_hostapd[0].set_value('wpa_key_mgmt', 'WPA-PSK')
    109         self.bss_hostapd[0].reload()
    110         self.bss_hostapd[0].wait_for_event("AP-ENABLED")
    111 
    112         self.bss_hostapd[1].set_value('wpa_key_mgmt', 'WPA-PSK')
    113         self.bss_hostapd[1].reload()
    114         self.bss_hostapd[1].wait_for_event("AP-ENABLED")
    115 
    116         self.validate_connection(self.wd)
    117 
    118     def test_roam_packet_loss(self):
    119         self.validate_connection(self.wd, pkt_loss=True)
    120 
    121     def tearDown(self):
    122         os.system('ip link set "' + self.bss_hostapd[0].ifname + '" down')
    123         os.system('ip link set "' + self.bss_hostapd[1].ifname + '" down')
    124         os.system('ip link set "' + self.bss_hostapd[0].ifname + '" up')
    125         os.system('ip link set "' + self.bss_hostapd[1].ifname + '" up')
    126 
    127         self.rule0.enabled = False
    128         self.rule1.enabled = False
    129         self.rule2.enabled = False
    130 
    131         for hapd in self.bss_hostapd:
    132             hapd.default()
    133 
    134         self.wd.stop()
    135         self.wd = None
    136 
    137     def setUp(self):
    138         self.wd = IWD(True)
    139 
    140     @classmethod
    141     def setUpClass(cls):
    142         hwsim = Hwsim()
    143 
    144         IWD.copy_to_storage('TestFT.psk')
    145 
    146         cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'),
    147                             HostapdCLI(config='ft-psk-ccmp-2.conf') ]
    148 
    149         unused = HostapdCLI(config='ft-psk-ccmp-3.conf')
    150         unused.disable()
    151 
    152         rad0 = hwsim.get_radio('rad0')
    153         rad3 = hwsim.get_radio('rad3')
    154 
    155         cls.rule0 = hwsim.rules.create()
    156         cls.rule0.source = rad3.addresses[0]
    157         cls.rule0.bidirectional = True
    158         cls.rule0.signal = -2000
    159         cls.rule0.prefix = 'b0'
    160         cls.rule0.drop = True
    161 
    162         cls.rule1 = hwsim.rules.create()
    163         cls.rule1.source = rad3.addresses[0]
    164         cls.rule1.prefix = '08'
    165         cls.rule1.drop = True
    166 
    167         cls.rule2 = hwsim.rules.create()
    168         cls.rule2.source = rad0.addresses[0]
    169         cls.rule2.signal = -7000
    170 
    171         cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
    172         cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
    173 
    174         HostapdCLI.group_neighbors(*cls.bss_hostapd)
    175 
    176     @classmethod
    177     def tearDownClass(cls):
    178         IWD.clear_storage()
    179         cls.bss_hostapd = None
    180         cls.rule0.remove()
    181         cls.rule1.remove()
    182         cls.rule2.remove()
    183 
    184 if __name__ == '__main__':
    185     unittest.main(exit=True)