Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: server/site_linux_router.py

Issue 3148006: Correctly auto-detect 2GHz and 5GHz phy devices (Closed) Base URL: ssh://gitrw.chromium.org/autotest.git
Patch Set: Changed comment Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import logging, re 5 import logging, re
6 from autotest_lib.client.common_lib import error
6 7
7 def isLinuxRouter(router): 8 def isLinuxRouter(router):
8 router_uname = router.run('uname').stdout 9 router_uname = router.run('uname').stdout
9 return re.search('Linux', router_uname) 10 return re.search('Linux', router_uname)
10 11
11 class LinuxRouter(object): 12 class LinuxRouter(object):
12 """ 13 """
13 Linux/mac80211-style WiFi Router support for WiFiTest class. 14 Linux/mac80211-style WiFi Router support for WiFiTest class.
14 15
15 This class implements test methods/steps that communicate with a 16 This class implements test methods/steps that communicate with a
16 router implemented with Linux/mac80211. The router must 17 router implemented with Linux/mac80211. The router must
17 be pre-configured to enable ssh access and have a mac80211-based 18 be pre-configured to enable ssh access and have a mac80211-based
18 wireless device. We also assume hostapd 0.7.x and iw are present 19 wireless device. We also assume hostapd 0.7.x and iw are present
19 and any necessary modules are pre-loaded. 20 and any necessary modules are pre-loaded.
20 """ 21 """
21 22
22 23
23 def __init__(self, host, params, defssid): 24 def __init__(self, host, params, defssid):
24 # Command locations. 25 # Command locations.
25 self.cmd_iw = "/usr/sbin/iw" 26 self.cmd_iw = "/usr/sbin/iw"
26 self.cmd_ip = "/usr/sbin/ip" 27 self.cmd_ip = "/usr/sbin/ip"
27 self.cmd_brctl = "/usr/sbin/brctl" 28 self.cmd_brctl = "/usr/sbin/brctl"
28 self.cmd_hostapd = "/usr/sbin/hostapd" 29 self.cmd_hostapd = "/usr/sbin/hostapd"
29 30
30 # Router host. 31 # Router host.
31 self.router = host 32 self.router = host
32 33
33 # Network interfaces. 34 # Network interfaces.
34 self.bridgeif = params.get('bridgedev', "br-lan") 35 self.bridgeif = params.get('bridgedev', "br-lan")
35 self.wiredif = params.get('wiredev', "eth1") 36 self.wiredif = params.get('wiredev', "eth0")
36 self.wlanif2 = "wlan2" 37 self.wlanif2 = "wlan2"
37 self.wlanif5 = "wlan5" 38 self.wlanif5 = "wlan5"
38 39
39 # Default to 1st available wireless phy. 40 # Parse the output of 'iw phy' and find a device for each frequency
40 if "phydev2" not in params: 41 if "phydev2" not in params:
41 output = self.router.run("%s list" % self.cmd_iw).stdout 42 output = self.router.run("%s list" % self.cmd_iw).stdout
42 test = re.compile("Wiphy (.*)") 43 re_wiphy = re.compile("Wiphy (.*)")
44 re_mhz = re.compile("(\d+) MHz")
45 in_phy = False
46 self.phydev2 = None
47 self.phydev5 = None
43 for line in output.splitlines(): 48 for line in output.splitlines():
44 m = test.match(line) 49 match_wiphy = re_wiphy.match(line)
45 if m: 50 if match_wiphy:
46 self.phydev2 = m.group(1) 51 in_phy = True
47 self.phydev5 = self.phydev2 52 widevname = match_wiphy.group(1)
48 break 53 elif in_phy:
54 if line[0] == '\t':
55 match_mhz = re_mhz.search(line)
56 if match_mhz:
57 mhz = int(match_mhz.group(1))
58 if self.phydev2 is None and \
59 mhz in range(2402,2472,5):
60 self.phydev2 = widevname
61 elif self.phydev5 is None and \
62 mhz in range(5100,6000,20):
63 self.phydev5 = widevname
64 if None not in (self.phydev2, self.phydev5):
65 break
66 else:
67 in_phy = False
49 else: 68 else:
50 raise error.TestFail("No Wireless NIC detected on the device") 69 raise error.TestFail("No Wireless NIC detected on the device")
51 else: 70 else:
52 self.phydev2 = params['phydev2'] 71 self.phydev2 = params['phydev2']
53 self.phydev5 = params.get('phydev5', self.phydev2) 72 self.phydev5 = params.get('phydev5', self.phydev2)
54 73
55 74
56 # hostapd configuration persists throughout the test, subsequent 75 # hostapd configuration persists throughout the test, subsequent
57 # 'config' commands only modify it. 76 # 'config' commands only modify it.
58 self.defssid = defssid 77 self.defssid = defssid
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 self.router.run("%s link set %s down" % (self.cmd_ip, self.bridgeif), 312 self.router.run("%s link set %s down" % (self.cmd_ip, self.bridgeif),
294 ignore_status=True) 313 ignore_status=True)
295 self.router.run("%s delbr %s" % (self.cmd_brctl, self.bridgeif), 314 self.router.run("%s delbr %s" % (self.cmd_brctl, self.bridgeif),
296 ignore_status=True) 315 ignore_status=True)
297 316
298 self.hostapd['configured'] = False 317 self.hostapd['configured'] = False
299 318
300 319
301 def get_ssid(self): 320 def get_ssid(self):
302 return self.hostapd['conf']['ssid'] 321 return self.hostapd['conf']['ssid']
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698