1#!/usr/bin/expect -f 2# 3# Copyright (c) 2024, 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# 29source "tests/scripts/expect/_common.exp" 30 31# Dataset 32# Mesh Local Prefix: fd0d:7fc:a1b9:f050::/64 33set dataset_dbus "0x0e,0x08,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0x00,0x14,0x35,0x06,0x00,0x04,0x00,0x1f,0xff,0xe0,0x02,0x08,0x7d,0x61,0xeb,0x42,0xcd,0xc4,0x8d,0x6a,0x07,0x08,0xfd,0x0d,0x07,0xfc,0xa1,0xb9,0xf0,0x50,0x05,0x10,0xba,0x08,0x8f,0xc2,0xbd,0x6c,0x3b,0x38,0x97,0xf7,0xa1,0x0f,0x58,0x26,0x3f,0xf3,0x03,0x0f,0x4f,0x70,0x65,0x6e,0x54,0x68,0x72,0x65,0x61,0x64,0x2d,0x35,0x32,0x34,0x66,0x01,0x02,0x52,0x4f,0x04,0x10,0x9d,0xc0,0x23,0xcc,0xd4,0x47,0xb1,0x2b,0x50,0x99,0x7e,0xf6,0x80,0x20,0xf1,0x9e,0x0c,0x04,0x02,0xa0,0xf7,0xf8" 34 35# Step 1. Start otbr-agent with a NCP and join the network by dbus join method. 36spawn_node 2 otbr $::env(EXP_OT_NCP_PATH) 37sleep 1 38 39spawn dbus-send --system --dest=io.openthread.BorderRouter.wpan0 --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 io.openthread.BorderRouter.Join "array:byte:${dataset_dbus}" 40expect eof 41 42# Step 2. Wait 10 seconds for it becomes a leader. 43sleep 10 44spawn dbus-send --system --dest=io.openthread.BorderRouter.wpan0 --print-reply --reply-timeout=1000 /io/openthread/BorderRouter/wpan0 org.freedesktop.DBus.Properties.Get string:io.openthread.BorderRouter string:DeviceRole 45expect -re {leader} { 46} timeout { 47 puts "timeout!" 48 exit 1 49} 50expect eof 51 52# Step 3. Verify the addresses on wpan. 53# There should be: 54# 1. ml eid 55# 2. ml anycast 56# 3. ml rloc 57# 4. link local 58spawn ip addr show wpan0 59expect -re {fd0d:7fc:a1b9:f050(:[0-9a-f]{1,4}){4,4}} 60expect -re {fd0d:7fc:a1b9:f050(:[0-9a-f]{1,4}){4,4}} 61expect -re {fd0d:7fc:a1b9:f050(:[0-9a-f]{1,4}){4,4}} 62expect -re {fe80:(:[0-9a-f]{1,4}){4,4}} 63expect eof 64 65# Multicast addresses should contain: 66# 1. ff01::1 67# 2. ff02::1 68# 3. ff02::2 69# 4. ff03::1 70# 5. ff03::2 71spawn ip maddr show dev wpan0 72expect eof 73set maddr_output $expect_out(buffer) 74if {![string match "*ff01::1*" $maddr_output]} { fail "No multicast address ff01::1" } 75if {![string match "*ff02::1*" $maddr_output]} { fail "No multicast address ff02::1" } 76if {![string match "*ff02::2*" $maddr_output]} { fail "No multicast address ff02::2" } 77if {![string match "*ff03::1*" $maddr_output]} { fail "No multicast address ff03::1" } 78if {![string match "*ff03::2*" $maddr_output]} { fail "No multicast address ff03::2" } 79 80# Step 4. Verify the wpan isUp state 81spawn ip link show wpan0 82expect -re {UP} 83expect eof 84 85# Step 5. Use dbus leave method to let the node leave the network 86spawn dbus-send --system --dest=io.openthread.BorderRouter.wpan0 --type=method_call --print-reply /io/openthread/BorderRouter/wpan0 io.openthread.BorderRouter.LeaveNetwork 87expect eof 88 89# Step 6. Verify the addresses on wpan. 90# There should be: 91# 1. link local 92spawn ip addr show wpan0 93expect -re {fe80:(:[0-9a-f]{1,4}){4,4}} 94expect eof 95