• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python3
2#
3#   Copyright 2020 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17#import acts.test_utils.wifi.wifi_test_utils as wutils
18
19import time
20import re
21import logging
22import acts.controllers.packet_capture as packet_capture
23import acts_contrib.test_utils.wifi.wifi_test_utils as wutils
24
25from acts import asserts
26from acts.test_decorators import test_tracker_info
27from acts_contrib.test_utils.net import nsd_const as nconsts
28from acts_contrib.test_utils.wifi.aware import aware_const as aconsts
29from acts_contrib.test_utils.wifi.aware import aware_test_utils as autils
30from acts_contrib.test_utils.wifi.aware.AwareBaseTest import AwareBaseTest
31from acts.controllers.ap_lib.hostapd_constants import CHANNEL_MAP
32
33WifiEnums = wutils.WifiEnums
34
35
36class ProtocolsMultiCountryTest(AwareBaseTest):
37    def __init__(self, controllers):
38        AwareBaseTest.__init__(self, controllers)
39        self.basetest_name = (
40            "ping6_ib_unsolicited_passive_multicountry",
41            "ping6_ib_solicited_active_multicountry",
42        )
43
44        self.generate_tests()
45
46    def generate_testcase(self, basetest_name, country):
47        """Generates a single test case from the given data.
48
49        Args:
50            basetest_name: The name of the base test case.
51            country: The information about the country code under test.
52        """
53        base_test = getattr(self, basetest_name)
54        test_tracker_uuid = ""
55
56        testcase_name = 'test_%s_%s' % (basetest_name, country)
57        test_case = test_tracker_info(
58            uuid=test_tracker_uuid)(lambda: base_test(country))
59        setattr(self, testcase_name, test_case)
60        self.tests.append(testcase_name)
61
62    def generate_tests(self):
63        for country in self.user_params['wifi_country_code']:
64            for basetest_name in self.basetest_name:
65                self.generate_testcase(basetest_name, country)
66
67    def setup_class(self):
68        super().setup_class()
69        for ad in self.android_devices:
70            ad.droid.wakeLockAcquireBright()
71            ad.droid.wakeUpNow()
72            wutils.wifi_test_device_init(ad)
73
74        if hasattr(self, 'packet_capture'):
75            self.packet_capture = self.packet_capture[0]
76        self.channel_list_2g = WifiEnums.ALL_2G_FREQUENCIES
77        self.channel_list_5g = WifiEnums.ALL_5G_FREQUENCIES
78
79    def setup_test(self):
80        super(ProtocolsMultiCountryTest, self).setup_test()
81        for ad in self.android_devices:
82            ad.ed.clear_all_events()
83
84    def test_time(self, begin_time):
85        super(ProtocolsMultiCountryTest, self).setup_test()
86        for ad in self.android_devices:
87            ad.cat_adb_log(begin_time)
88
89    def teardown_test(self):
90        super(ProtocolsMultiCountryTest, self).teardown_test()
91        for ad in self.android_devices:
92            ad.adb.shell("cmd wifiaware reset")
93
94    """Set of tests for Wi-Fi Aware data-paths: validating protocols running on
95    top of a data-path"""
96
97    SERVICE_NAME = "GoogleTestServiceXY"
98
99    def run_ping6(self, dut, peer_ipv6):
100        """Run a ping6 over the specified device/link
101    Args:
102      dut: Device on which to execute ping6
103      peer_ipv6: Scoped IPv6 address of the peer to ping
104    """
105        cmd = "ping6 -c 3 -W 5 %s" % peer_ipv6
106        results = dut.adb.shell(cmd)
107        self.log.info("cmd='%s' -> '%s'", cmd, results)
108        if results == "":
109            asserts.fail("ping6 empty results - seems like a failure")
110
111    def get_ndp_freq(self, dut):
112        """ get aware interface status"""
113        get_nda0 = "timeout 3 logcat | grep getNdpConfirm | grep Channel"
114        out_nda01 = dut.adb.shell(get_nda0)
115        out_nda0 = re.findall("Channel = (\d+)", out_nda01)
116        return out_nda0
117
118    def conf_packet_capture(self, band, channel):
119        """Configure packet capture on necessary channels."""
120        freq_to_chan = wutils.WifiEnums.freq_to_channel[int(channel)]
121        logging.info("Capturing packets from "
122                     "frequency:{}, Channel:{}".format(channel, freq_to_chan))
123        result = self.packet_capture.configure_monitor_mode(band, freq_to_chan)
124        if not result:
125            logging.error("Failed to configure channel "
126                          "for {} band".format(band))
127        self.pcap_procs = wutils.start_pcap(self.packet_capture, band,
128                                            self.test_name)
129        time.sleep(5)
130
131    ########################################################################
132
133    @test_tracker_info(uuid="3b09e666-c526-4879-8180-77d9a55a2833")
134    def ping6_ib_unsolicited_passive_multicountry(self, country):
135        """Validate that ping6 works correctly on an NDP created using Aware
136        discovery with UNSOLICITED/PASSIVE sessions."""
137        p_dut = self.android_devices[0]
138        s_dut = self.android_devices[1]
139        wutils.set_wifi_country_code(p_dut, country)
140        wutils.set_wifi_country_code(s_dut, country)
141        #p_dut.adb.shell("timeout 12 logcat -c")
142        # create NDP
143        (p_req_key, s_req_key, p_aware_if, s_aware_if, p_ipv6,
144         s_ipv6) = autils.create_ib_ndp(
145             p_dut,
146             s_dut,
147             p_config=autils.create_discovery_config(
148                 self.SERVICE_NAME, aconsts.PUBLISH_TYPE_UNSOLICITED),
149             s_config=autils.create_discovery_config(
150                 self.SERVICE_NAME, aconsts.SUBSCRIBE_TYPE_PASSIVE),
151             device_startup_offset=self.device_startup_offset)
152        self.log.info("Interface names: P=%s, S=%s", p_aware_if, s_aware_if)
153        self.log.info("Interface addresses (IPv6): P=%s, S=%s", p_ipv6, s_ipv6)
154        ndpfreg = int(self.get_ndp_freq(p_dut)[-1])
155        ndp_channel = str(CHANNEL_MAP[ndpfreg])
156        n = int(ndp_channel)
157        if n in range(len(self.channel_list_2g)):
158            ndp_band = '2g'
159        else:
160            ndp_band = '5g'
161        p_dut.log.info('ndp frequency : {}'.format(ndpfreg))
162        p_dut.log.info('ndp channel : {}'.format(ndp_channel))
163        p_dut.log.info('ndp band : {}'.format(ndp_band))
164
165        # start-snifferlog
166        if hasattr(self, 'packet_capture'):
167            self.conf_packet_capture(ndp_band, ndpfreg)
168
169    # run ping6
170        self.run_ping6(p_dut, s_ipv6)
171        self.run_ping6(s_dut, p_ipv6)
172
173        # clean-up
174        p_dut.droid.connectivityUnregisterNetworkCallback(p_req_key)
175        s_dut.droid.connectivityUnregisterNetworkCallback(s_req_key)
176
177        # stop-snifferlog
178        if hasattr(self, 'packet_capture'):
179            wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
180        time.sleep(10)
181
182    @test_tracker_info(uuid="6b54951f-bf0b-4d26-91d6-c9b3b8452873")
183    def ping6_ib_solicited_active_multicountry(self, country):
184        """Validate that ping6 works correctly on an NDP created using Aware
185    discovery with SOLICITED/ACTIVE sessions."""
186        p_dut = self.android_devices[0]
187        s_dut = self.android_devices[1]
188        wutils.set_wifi_country_code(p_dut, country)
189        wutils.set_wifi_country_code(s_dut, country)
190
191        # create NDP
192        (p_req_key, s_req_key, p_aware_if, s_aware_if, p_ipv6,
193         s_ipv6) = autils.create_ib_ndp(
194             p_dut,
195             s_dut,
196             p_config=autils.create_discovery_config(
197                 self.SERVICE_NAME, aconsts.PUBLISH_TYPE_SOLICITED),
198             s_config=autils.create_discovery_config(
199                 self.SERVICE_NAME, aconsts.SUBSCRIBE_TYPE_ACTIVE),
200             device_startup_offset=self.device_startup_offset)
201        self.log.info("Interface names: P=%s, S=%s", p_aware_if, s_aware_if)
202        self.log.info("Interface addresses (IPv6): P=%s, S=%s", p_ipv6, s_ipv6)
203        ndpfreg = int(self.get_ndp_freq(p_dut)[-1])
204        ndp_channel = str(CHANNEL_MAP[ndpfreg])
205        n = int(ndp_channel)
206        if n in range(len(self.channel_list_2g)):
207            ndp_band = '2g'
208        else:
209            ndp_band = '5g'
210        p_dut.log.info('ndp frequency : {}'.format(ndpfreg))
211        p_dut.log.info('ndp channel : {}'.format(ndp_channel))
212        p_dut.log.info('ndp band : {}'.format(ndp_band))
213
214        # start-snifferlog
215        if hasattr(self, 'packet_capture'):
216            self.conf_packet_capture(ndp_band, ndpfreg)
217
218        # run ping6
219        self.run_ping6(p_dut, s_ipv6)
220        self.run_ping6(s_dut, p_ipv6)
221
222        # clean-up
223        p_dut.droid.connectivityUnregisterNetworkCallback(p_req_key)
224        s_dut.droid.connectivityUnregisterNetworkCallback(s_req_key)
225
226        # stop-snifferlog
227        if hasattr(self, 'packet_capture'):
228            wutils.stop_pcap(self.packet_capture, self.pcap_procs, False)
229        time.sleep(10)
230