Skip to content

Commit

Permalink
[tests] add ncp border routing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Irving-cl committed Oct 25, 2024
1 parent d387903 commit 725bae7
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/scripts/expect/_common.exp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ proc spawn_node {id type sim_app} {
timeout { fail "Timed out" }
}
}
otbr-docker {
spawn docker exec -it $sim_app bash
expect "app#"
}
otbr {
spawn $::env(EXP_OTBR_AGENT_PATH) -I $::env(EXP_TUN_NAME) -d7 "spinel+hdlc+forkpty://${sim_app}?forkpty-arg=${id}"
}
Expand All @@ -94,6 +98,39 @@ proc spawn_node {id type sim_app} {
return $spawn_id
}

proc create_socat {id} {
global socat_pid
spawn socat -d -d pty,raw,echo=0 pty,raw,echo=0
set socat_pid [exp_pid]
set pty1 ""
set pty2 ""
expect {
-re {PTY is (\S+).*PTY is (\S+)} {
set pty1 $expect_out(1,string)
set pty2 $expect_out(2,string)
}
timeout {
fail "Timed out"
}
}
set spawn_ids($id) $spawn_id
return [list $pty1 $pty2]
}

proc start_otbr_docker {name sim_app sim_id pty1 pty2} {
exec $sim_app $sim_id <$pty1 >$pty1 &
exec docker run -d \
--name $name \
--network backbone1 \
--cap-add=NET_ADMIN \
--privileged \
--sysctl net.ipv6.conf.all.disable_ipv6=0 \
--sysctl net.ipv4.conf.all.forwarding=1 \
--sysctl net.ipv6.conf.all.forwarding=1 \
-v $pty2:/dev/ttyUSB0 \
$::env(EXP_OTBR_DOCKER_IMAGE)
}

proc switch_node {id} {
global spawn_ids
global spawn_id
Expand All @@ -102,6 +139,29 @@ proc switch_node {id} {
set spawn_id $spawn_ids($id)
}

proc dispose_node {id} {
switch_node $id
send "\x04"
expect eof
}
proc dispose_socat {} {
global socat_pid
if { [info exists socat_pid] } {
exec kill $socat_pid
}
}
proc dispose_all {} {
global spawn_ids
set max_node [array size spawn_ids]
for {set i 1} {$i <= $max_node} {incr i} {
if { [info exists spawn_ids($i)] } {
dispose_node $i
}
}
array unset spawn_ids
dispose_socat
}

proc get_ipaddr {type} {
send "ipaddr $type\n"
expect "ipaddr $type"
Expand All @@ -110,3 +170,9 @@ proc get_ipaddr {type} {

return $rval
}

proc get_omr_addr {} {
send "ipaddr -v\r\n"
expect -re {(?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}(?= origin:slaac)}
return $expect_out(0,string)
}
70 changes: 70 additions & 0 deletions tests/scripts/expect/ncp_border_routing.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/expect -f
#
# Copyright (c) 2024, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

source "tests/scripts/expect/_common.exp"

set ptys [create_socat 1]
set pty1 [lindex $ptys 0]
set pty2 [lindex $ptys 1]

set container "otbr-ncp"

set dataset "0e080000000000010000000300001435060004001fffe002087d61eb42cdc48d6a0708fd0d07fca1b9f0500510ba088fc2bd6c3b3897f7a10f58263ff3030f4f70656e5468726561642d353234660102524f04109dc023ccd447b12b50997ef68020f19e0c0402a0f7f8"
set 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"

start_otbr_docker $container $::env(EXP_OT_NCP_PATH) 2 $pty1 $pty2

spawn_node 3 otbr-docker $container
spawn_node 4 cli $::env(EXP_OT_CLI_PATH)

send "dataset set active ${dataset}\n"
expect_line "Done"
send "ifconfig up\r\n"
expect_line "Done"
send "thread start\r\n"
expect_line "Done"
wait_for "state" "leader"

switch_node 3
send "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}\"\n"
expect "app#"
sleep 20

switch_node 4
set omr_addr [get_omr_addr]
sleep 1

# Test pinging from the host (infrastructure network) to the cli
set timeout 20
spawn ping6 -c 10 $omr_addr
expect -re {10 packets transmitted, 10 received, 0\% packet loss}

exec sudo docker stop $container
exec sudo docker rm $container
dispose_all
2 changes: 2 additions & 0 deletions tests/scripts/ncp_mode
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ test_setup()
write_syslog "AGENT: kill old"
sudo killall "${OTBR_AGENT}" || true

setup_infraif

# From now on - all exits are TRAPPED
# When they occur, we call the function: output_logs'.
trap test_teardown EXIT
Expand Down

0 comments on commit 725bae7

Please sign in to comment.