1a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley# Use of this source code is governed by a BSD-style license that can be
3a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley# found in the LICENSE file.
4a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley
599e9c4a2011cce9eb32750cb0f99fc8daeb2fdb0Christopher Wileyfrom autotest_lib.client.common_lib.cros.network import iw_runner
6a51258ec1a2018d67ee36799454983dde304130bChristopher Wileyfrom autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes
799d42c95fa5c12285fb129b50445a60c9a145dd3Christopher Wileyfrom autotest_lib.server.cros.network import hostap_config
84961e848f54cb64f911c3ce03b3c377d171b35e5Christopher Wileyfrom autotest_lib.server.cros.network import wifi_cell_test_base
9a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley
10a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley
11e740d58afe535827ec234d02f23b2baa4c720928Christopher Wileyclass network_WiFi_DTIMPeriod(wifi_cell_test_base.WiFiCellTestBase):
12a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley    """Test that we understand the routers negotiated DTIM period."""
13a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley    version = 1
14a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley
15a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley
163e016dfc43799d47b6de12b9c4c98ab83b2a64d4Christopher Wiley    def run_once(self):
17a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        """DTIM period test.
18a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley
19a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        DTIM stands for delivery traffic information message and refers to
20a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        the number of beacons between DTIMS.  For instance, a DTIM period
21a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        of 1 would indicate that every beacon should have a DTIM element.
22a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        The default DTIM period value is 2.
23a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley
24a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        This flag is used in combination with powersave mode as follows:
25a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        1) A client goes into powersave mode and notifies the router.
26a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        2) While in powersave mode, the client turns off as much as possible;
27a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley           the AP is supposed to buffer unicast traffic.
28a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        3) The client wakes up to receive beacons, which may include a DTIM
29a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley           notification.
30a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        4) On receiving such a notification, the client should
31a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley           stay up to recieve the pending frames.
32a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley
33a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        """
34a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        dtim_val = 5
35a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        configuration = hostap_config.HostapConfig(
36a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley                frequency=2437,
37a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley                mode=hostap_config.HostapConfig.MODE_11G,
38a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley                dtim_period=dtim_val)
39a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        self.context.configure(configuration)
40a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        assoc_params = xmlrpc_datatypes.AssociationParameters()
41a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        assoc_params.ssid = self.context.router.get_ssid()
42a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        self.context.client.powersave_switch(True)
433e016dfc43799d47b6de12b9c4c98ab83b2a64d4Christopher Wiley        self.context.assert_connect_wifi(assoc_params)
44a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        self.context.client.check_iw_link_value(
4599e9c4a2011cce9eb32750cb0f99fc8daeb2fdb0Christopher Wiley                iw_runner.IW_LINK_KEY_DTIM_PERIOD,
46a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley                dtim_val)
473e016dfc43799d47b6de12b9c4c98ab83b2a64d4Christopher Wiley        self.context.assert_ping_from_dut()
48a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        self.context.client.shill.disconnect(assoc_params.ssid)
49a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        self.context.client.powersave_switch(False)
50a51258ec1a2018d67ee36799454983dde304130bChristopher Wiley        self.context.router.deconfig()
51