1*cfb92d14SAndroid Build Coastguard Worker#!/usr/bin/env python3 2*cfb92d14SAndroid Build Coastguard Worker# 3*cfb92d14SAndroid Build Coastguard Worker# Copyright (c) 2020, The OpenThread Authors. 4*cfb92d14SAndroid Build Coastguard Worker# All rights reserved. 5*cfb92d14SAndroid Build Coastguard Worker# 6*cfb92d14SAndroid Build Coastguard Worker# Redistribution and use in source and binary forms, with or without 7*cfb92d14SAndroid Build Coastguard Worker# modification, are permitted provided that the following conditions are met: 8*cfb92d14SAndroid Build Coastguard Worker# 1. Redistributions of source code must retain the above copyright 9*cfb92d14SAndroid Build Coastguard Worker# notice, this list of conditions and the following disclaimer. 10*cfb92d14SAndroid Build Coastguard Worker# 2. Redistributions in binary form must reproduce the above copyright 11*cfb92d14SAndroid Build Coastguard Worker# notice, this list of conditions and the following disclaimer in the 12*cfb92d14SAndroid Build Coastguard Worker# documentation and/or other materials provided with the distribution. 13*cfb92d14SAndroid Build Coastguard Worker# 3. Neither the name of the copyright holder nor the 14*cfb92d14SAndroid Build Coastguard Worker# names of its contributors may be used to endorse or promote products 15*cfb92d14SAndroid Build Coastguard Worker# derived from this software without specific prior written permission. 16*cfb92d14SAndroid Build Coastguard Worker# 17*cfb92d14SAndroid Build Coastguard Worker# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18*cfb92d14SAndroid Build Coastguard Worker# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*cfb92d14SAndroid Build Coastguard Worker# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*cfb92d14SAndroid Build Coastguard Worker# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21*cfb92d14SAndroid Build Coastguard Worker# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22*cfb92d14SAndroid Build Coastguard Worker# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23*cfb92d14SAndroid Build Coastguard Worker# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24*cfb92d14SAndroid Build Coastguard Worker# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25*cfb92d14SAndroid Build Coastguard Worker# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26*cfb92d14SAndroid Build Coastguard Worker# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27*cfb92d14SAndroid Build Coastguard Worker# POSSIBILITY OF SUCH DAMAGE. 28*cfb92d14SAndroid Build Coastguard Worker 29*cfb92d14SAndroid Build Coastguard Workerfrom wpan import verify 30*cfb92d14SAndroid Build Coastguard Workerimport wpan 31*cfb92d14SAndroid Build Coastguard Worker 32*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 33*cfb92d14SAndroid Build Coastguard Worker# Test description: Test MLE discover scan with nodes supporting different radios 34*cfb92d14SAndroid Build Coastguard Worker# 35*cfb92d14SAndroid Build Coastguard Worker 36*cfb92d14SAndroid Build Coastguard Workertest_name = __file__[:-3] if __file__.endswith('.py') else __file__ 37*cfb92d14SAndroid Build Coastguard Workerprint('-' * 120) 38*cfb92d14SAndroid Build Coastguard Workerprint('Starting \'{}\''.format(test_name)) 39*cfb92d14SAndroid Build Coastguard Worker 40*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 41*cfb92d14SAndroid Build Coastguard Worker# Creating `wpan.Nodes` instances 42*cfb92d14SAndroid Build Coastguard Worker 43*cfb92d14SAndroid Build Coastguard Workerspeedup = 1 44*cfb92d14SAndroid Build Coastguard Workerwpan.Node.set_time_speedup_factor(speedup) 45*cfb92d14SAndroid Build Coastguard Worker 46*cfb92d14SAndroid Build Coastguard Workern1 = wpan.Node(wpan.NODE_15_4) 47*cfb92d14SAndroid Build Coastguard Workern2 = wpan.Node(wpan.NODE_TREL) 48*cfb92d14SAndroid Build Coastguard Workern3 = wpan.Node(wpan.NODE_15_4_TREL) 49*cfb92d14SAndroid Build Coastguard Workers1 = wpan.Node(wpan.NODE_15_4) 50*cfb92d14SAndroid Build Coastguard Workers2 = wpan.Node(wpan.NODE_TREL) 51*cfb92d14SAndroid Build Coastguard Workers3 = wpan.Node(wpan.NODE_15_4_TREL) 52*cfb92d14SAndroid Build Coastguard Worker 53*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 54*cfb92d14SAndroid Build Coastguard Worker# Init all nodes 55*cfb92d14SAndroid Build Coastguard Worker 56*cfb92d14SAndroid Build Coastguard Workerwpan.Node.init_all_nodes() 57*cfb92d14SAndroid Build Coastguard Worker 58*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 59*cfb92d14SAndroid Build Coastguard Worker# Build network topology 60*cfb92d14SAndroid Build Coastguard Worker 61*cfb92d14SAndroid Build Coastguard Workern1.form("n1", channel='20') 62*cfb92d14SAndroid Build Coastguard Workern2.form("n2", channel='21') 63*cfb92d14SAndroid Build Coastguard Workern3.form("n3", channel='22') 64*cfb92d14SAndroid Build Coastguard Worker 65*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 66*cfb92d14SAndroid Build Coastguard Worker# Test implementation 67*cfb92d14SAndroid Build Coastguard Worker 68*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 69*cfb92d14SAndroid Build Coastguard Worker# Scan by scanner nodes (no network) 70*cfb92d14SAndroid Build Coastguard Worker 71*cfb92d14SAndroid Build Coastguard Worker# Scan by s1 (15.4 only), expect to see n1(15.4) and n3(15.4+trel) 72*cfb92d14SAndroid Build Coastguard Workerresult = wpan.parse_scan_result(s1.discover_scan()) 73*cfb92d14SAndroid Build Coastguard Workerverify(n1.is_in_scan_result(result)) 74*cfb92d14SAndroid Build Coastguard Workerverify(not n2.is_in_scan_result(result)) 75*cfb92d14SAndroid Build Coastguard Workerverify(n3.is_in_scan_result(result)) 76*cfb92d14SAndroid Build Coastguard Worker 77*cfb92d14SAndroid Build Coastguard Worker# Scan by s2 (trel only), expect to see n2(trel) and n3(15.4+trel) 78*cfb92d14SAndroid Build Coastguard Workerresult = wpan.parse_scan_result(s2.discover_scan()) 79*cfb92d14SAndroid Build Coastguard Workerverify(not n1.is_in_scan_result(result)) 80*cfb92d14SAndroid Build Coastguard Workerverify(n2.is_in_scan_result(result)) 81*cfb92d14SAndroid Build Coastguard Workerverify(n3.is_in_scan_result(result)) 82*cfb92d14SAndroid Build Coastguard Worker 83*cfb92d14SAndroid Build Coastguard Worker# Scan by s3 (trel+15.4), expect to see all nodes 84*cfb92d14SAndroid Build Coastguard Workerresult = wpan.parse_scan_result(s3.discover_scan()) 85*cfb92d14SAndroid Build Coastguard Workerverify(n1.is_in_scan_result(result)) 86*cfb92d14SAndroid Build Coastguard Workerverify(n2.is_in_scan_result(result)) 87*cfb92d14SAndroid Build Coastguard Workerverify(n3.is_in_scan_result(result)) 88*cfb92d14SAndroid Build Coastguard Worker 89*cfb92d14SAndroid Build Coastguard Worker# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 90*cfb92d14SAndroid Build Coastguard Worker# Scan by the nodes 91*cfb92d14SAndroid Build Coastguard Worker 92*cfb92d14SAndroid Build Coastguard Worker# Scan by n1 (15.4 only), expect to see only n3(15.4+trel) 93*cfb92d14SAndroid Build Coastguard Workerresult = wpan.parse_scan_result(n1.discover_scan()) 94*cfb92d14SAndroid Build Coastguard Workerverify(not n1.is_in_scan_result(result)) 95*cfb92d14SAndroid Build Coastguard Workerverify(not n2.is_in_scan_result(result)) 96*cfb92d14SAndroid Build Coastguard Workerverify(n3.is_in_scan_result(result)) 97*cfb92d14SAndroid Build Coastguard Worker 98*cfb92d14SAndroid Build Coastguard Worker# Scan by n2 (trel only), expect to see only n3(15.4+trel) 99*cfb92d14SAndroid Build Coastguard Workerresult = wpan.parse_scan_result(n2.discover_scan()) 100*cfb92d14SAndroid Build Coastguard Workerverify(not n1.is_in_scan_result(result)) 101*cfb92d14SAndroid Build Coastguard Workerverify(not n2.is_in_scan_result(result)) 102*cfb92d14SAndroid Build Coastguard Workerverify(n3.is_in_scan_result(result)) 103*cfb92d14SAndroid Build Coastguard Worker 104*cfb92d14SAndroid Build Coastguard Worker# Scan by n3 (15.4+trel), expect to see n1(15.4) and n2(trel) 105*cfb92d14SAndroid Build Coastguard Workerresult = wpan.parse_scan_result(n3.discover_scan()) 106*cfb92d14SAndroid Build Coastguard Workerverify(n1.is_in_scan_result(result)) 107*cfb92d14SAndroid Build Coastguard Workerverify(n2.is_in_scan_result(result)) 108*cfb92d14SAndroid Build Coastguard Workerverify(not n3.is_in_scan_result(result)) 109*cfb92d14SAndroid Build Coastguard Worker 110*cfb92d14SAndroid Build Coastguard Worker# ----------------------------------------------------------------------------------------------------------------------- 111*cfb92d14SAndroid Build Coastguard Worker# Test finished 112*cfb92d14SAndroid Build Coastguard Worker 113*cfb92d14SAndroid Build Coastguard Workerwpan.Node.finalize_all_nodes() 114*cfb92d14SAndroid Build Coastguard Worker 115*cfb92d14SAndroid Build Coastguard Workerprint('\'{}\' passed.'.format(test_name)) 116