1#!/usr/bin/expect -f 2# 3# Copyright (c) 2020, The OpenThread Authors. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are met: 8# 1. Redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer. 10# 2. Redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution. 13# 3. Neither the name of the copyright holder nor the 14# names of its contributors may be used to endorse or promote products 15# derived from this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27# POSSIBILITY OF SUCH DAMAGE. 28# 29 30source "tests/scripts/expect/_common.exp" 31source "tests/scripts/expect/_multinode.exp" 32 33setup_two_nodes 34 35switch_node 1 36send "dataset active\n" 37expect -re {Active Timestamp: \d+} 38expect -re {Channel: (\d+)} 39set channel $expect_out(1,string) 40expect -re {Channel Mask: 0x[0-9a-f]{8}} 41expect -re {Ext PAN ID: [0-9a-f]{16}} 42expect -re {Mesh Local Prefix: ([0-9a-f]{1,4}:){3}[0-9a-f]{1,4}::\/64} 43expect -re {Network Key: [0-9a-f]{32}} 44expect -re {Network Name: [^\r\n]+} 45expect -re {PAN ID: 0x[0-9a-f]{4}} 46expect -re {PSKc: [0-9a-f]{32}} 47expect -re {Security Policy: \d+ o?n?r?c?b?} 48send "dataset pending\n" 49expect "Error 23: NotFound" 50send "dataset init active\n" 51expect_line "Done" 52send "dataset activetimestamp 100\n" 53expect_line "Done" 54send "dataset activetimestamp\n" 55expect "100" 56expect_line "Done" 57if {$channel == 11} { 58 send "dataset channel 18\n" 59 expect_line "Done" 60 send "dataset channel\n" 61 expect "18" 62 expect_line "Done" 63} else { 64 send "dataset channel 11\n" 65 expect_line "Done" 66 send "dataset channel\n" 67 expect "11" 68 expect_line "Done" 69} 70send "dataset channelmask 0x03fff800\n" 71expect_line "Done" 72send "dataset channelmask\n" 73expect "0x03fff800" 74expect_line "Done" 75send "dataset extpanid aabbccddeeff0011\n" 76expect_line "Done" 77send "dataset extpanid\n" 78expect "aabbccddeeff0011" 79expect_line "Done" 80send "dataset networkkey aabbccddeeff00112233445566778899\n" 81expect_line "Done" 82send "dataset networkkey\n" 83expect "aabbccddeeff00112233445566778899" 84expect_line "Done" 85send "dataset meshlocalprefix fdde:4860::\n" 86expect_line "Done" 87send "dataset meshlocalprefix\n" 88expect "fdde:4860:0:0::/64" 89expect_line "Done" 90send "dataset networkname OT-network\n" 91expect_line "Done" 92send "dataset networkname\n" 93expect "OT-network" 94expect_line "Done" 95send "dataset panid 0xface\n" 96expect_line "Done" 97send "dataset panid\n" 98expect "0xface" 99expect_line "Done" 100send "dataset pskc 00112233445566778899aabbccddeeff\n" 101expect_line "Done" 102send "dataset pskc\n" 103expect "00112233445566778899aabbccddeeff" 104expect_line "Done" 105send "dataset securitypolicy 678 onrc\n" 106expect_line "Done" 107send "dataset securitypolicy\n" 108expect "678 onrc" 109expect_line "Done" 110send "dataset pendingtimestamp 100\n" 111expect_line "Done" 112send "dataset pendingtimestamp\n" 113expect "100" 114expect_line "Done" 115send "dataset delay 30000\n" 116expect_line "Done" 117send "dataset delay\n" 118expect "30000" 119expect_line "Done" 120send "dataset commit pending\n" 121expect_line "Done" 122send "dataset pending\n" 123expect "Pending Timestamp: 100" 124expect "Active Timestamp: 100" 125if {$channel == 11} { 126 expect "Channel: 18" 127} else { 128 expect "Channel: 11" 129} 130expect "Channel Mask: 0x03fff800" 131expect -re {Delay: \d+} 132expect "Ext PAN ID: aabbccddeeff0011" 133expect "Mesh Local Prefix: fdde:4860:0:0::/64" 134expect "Network Key: aabbccddeeff00112233445566778899" 135expect "Network Name: OT-network" 136expect "PAN ID: 0xface" 137expect "PSKc: 00112233445566778899aabbccddeeff" 138expect "Security Policy: 678 onrc" 139expect_line "Done" 140send "dataset pending -x\n" 141expect "dataset pending -x" 142set dataset_tlvs [expect_line {([0-9a-f]+)}] 143expect_line "Done" 144send "dataset clear\n" 145expect_line "Done" 146send "dataset init tlvs $dataset_tlvs\n" 147expect_line "Done" 148send "dataset\n" 149expect "Pending Timestamp: 100" 150expect "Active Timestamp: 100" 151if {$channel == 11} { 152 expect "Channel: 18" 153} else { 154 expect "Channel: 11" 155} 156expect "Channel Mask: 0x03fff800" 157expect -re {Delay: \d+} 158expect "Ext PAN ID: aabbccddeeff0011" 159expect "Mesh Local Prefix: fdde:4860:0:0::/64" 160expect "Network Key: aabbccddeeff00112233445566778899" 161expect "Network Name: OT-network" 162expect "PAN ID: 0xface" 163expect "PSKc: 00112233445566778899aabbccddeeff" 164expect "Security Policy: 678 onrc" 165expect_line "Done" 166 167sleep 30 168 169switch_node 2 170wait_for "dataset active" "Active Timestamp: 100" 171expect_line "Done" 172send "dataset active\n" 173expect "Active Timestamp: 100" 174if {$channel == 11} { 175 expect "Channel: 18" 176} else { 177 expect "Channel: 11" 178} 179expect "Channel Mask: 0x03fff800" 180expect "Ext PAN ID: aabbccddeeff0011" 181expect "Mesh Local Prefix: fdde:4860:0:0::/64" 182expect "Network Key: aabbccddeeff00112233445566778899" 183expect "Network Name: OT-network" 184expect "PAN ID: 0xface" 185expect "PSKc: 00112233445566778899aabbccddeeff" 186expect "Security Policy: 678 onrc" 187expect_line "Done" 188send "dataset clear\n" 189expect_line "Done" 190send "dataset init active\n" 191expect_line "Done" 192send "dataset\n" 193expect "Active Timestamp: 100" 194if {$channel == 11} { 195 expect "Channel: 18" 196} else { 197 expect "Channel: 11" 198} 199expect "Channel Mask: 0x03fff800" 200expect "Ext PAN ID: aabbccddeeff0011" 201expect "Mesh Local Prefix: fdde:4860:0:0::/64" 202expect "Network Key: aabbccddeeff00112233445566778899" 203expect "Network Name: OT-network" 204expect "PAN ID: 0xface" 205expect "PSKc: 00112233445566778899aabbccddeeff" 206expect "Security Policy: 678 onrc" 207expect_line "Done" 208send "dataset init pending\n" 209expect "Error 23: NotFound" 210 211switch_node 1 212set addr [get_ipaddr mleid] 213 214switch_node 2 215send "dataset mgmtgetcommand active \ 216activetimestamp pendingtimestamp networkkey networkname extpanid \ 217localprefix delaytimer panid channel \ 218-x 000102030405060708090a0b0e0f0c333435 \ 219address $addr\n" 220expect_line "Done" 221send "dataset mgmtgetcommand pending \ 222activetimestamp pendingtimestamp networkkey networkname extpanid \ 223localprefix delaytimer panid channel \ 224-x 000102030405060708090a0b0e0f0c333435 \ 225address $addr\n" 226expect_line "Done" 227 228switch_node 1 229send "dataset init active\n" 230expect_line "Done" 231send "dataset networkname Thread\\ 网络\n" 232expect_line "Done" 233send "dataset commit active\n" 234expect_line "Done" 235send "dataset active -x\n" 236expect "54687265616420e7bd91e7bb9c" ;# UTF-8 of "Thread 网络" 237expect_line "Done" 238send "dataset active -x\n" 239expect "dataset active -x" 240expect -re {([0-9a-f]+)[\r\n]+Done} 241set binary $expect_out(1,string) 242send "dataset set pending $binary\n" 243expect_line "Done" 244send "dataset pending -x\n" 245expect $binary 246expect_line "Done" 247send "dataset pending\n" 248expect "Network Name: Thread 网络" 249expect_line "Done" 250send "dataset set active $binary\n" 251expect_line "Done" 252send "dataset mgmtsetcommand active activetimestamp 200 -x 030d54687265616420e7bd91e7bb9c\n" 253expect_line "Done" 254send "dataset active\n" 255expect "Network Name: Thread 网络" 256expect_line "Done" 257send "dataset mgmtsetcommand active activetimestamp 210 -x 0301ff\n" 258expect_line "Done" 259send "dataset active\n" 260expect "Active Timestamp: 200" 261expect "Network Name: Thread 网络" 262expect_line "Done" 263send "dataset set active 03023432\n" 264expect_line "Done" 265send "dataset active\n" 266expect "Network Name: 42" 267expect_line "Done" 268send "dataset set active 0301bf\n" 269expect "Error 7: InvalidArgs" 270send "dataset help\n" 271expect_line "Done" 272send "dataset\n" 273expect_line "Done" 274send "dataset init something_invalid\n" 275expect "Error 7: InvalidArgs" 276send "dataset active something_invalid\n" 277expect "Error 7: InvalidArgs" 278send "dataset pending something_invalid\n" 279expect "Error 7: InvalidArgs" 280send "dataset commit something_invalid\n" 281expect "Error 7: InvalidArgs" 282send "dataset mgmtsetcommand something_invalid\n" 283expect "Error 7: InvalidArgs" 284send "dataset mgmtsetcommand active something_invalid\n" 285expect "Error 7: InvalidArgs" 286send "dataset mgmtgetcommand something_invalid\n" 287expect "Error 7: InvalidArgs" 288send "dataset mgmtgetcommand active something_invalid\n" 289expect "Error 7: InvalidArgs" 290send "dataset pskc -p 123456\n" 291expect_line "Done" 292send "dataset securitypolicy 678 something_invalid\n" 293expect "Error 7: InvalidArgs" 294send "dataset set something_invalid 00\n" 295expect "Error 7: InvalidArgs" 296send "dataset init tlvs something_invalid\n" 297expect "Error 7: InvalidArgs" 298 299dispose_all 300