• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3#  Copyright (c) 2022, 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
29set -euxo pipefail
30
31readonly SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
32readonly ABS_TOP_BUILDDIR="$(cd "${top_builddir:-"${SCRIPT_DIR}"/../../}" && pwd)"
33readonly OTBR_AGENT="${ABS_TOP_BUILDDIR}/src/agent/otbr-agent"
34readonly OT_RCP=$(command -v ot-rcp)
35
36at_exit()
37{
38    EXIT_CODE=$?
39
40    sudo killall otbr-agent || true
41
42    sudo ip link del ilstest0 || true
43    sudo ip link del ilstest1 || true
44    sudo ip link del ilstest2 || true
45
46    exit $EXIT_CODE
47}
48
49trap at_exit INT TERM EXIT
50
51sudo cp "${ABS_TOP_BUILDDIR}/src/agent/otbr-agent.conf" /etc/dbus-1/system.d/
52sudo chmod +r /etc/dbus-1/system.d/otbr-agent.conf
53sudo systemctl reload dbus
54
55sudo modprobe dummy
56
57prepare_infra_link()
58{
59    local netif="$1"
60    local mac="$2"
61
62    sudo ip link add "${netif}" type dummy
63    sudo ifconfig "${netif}" hw ether "${mac}"
64    sudo ifconfig "${netif}" up
65}
66
67sudo ip link del ilstest0 || true
68sudo ip link del ilstest1 || true
69sudo ip link del ilstest2 || true
70
71prepare_infra_link "ilstest0" "C8:D7:4A:4E:47:00"
72prepare_infra_link "ilstest1" "C8:D7:4A:4E:47:01"
73prepare_infra_link "ilstest2" "C8:D7:4A:4E:47:02"
74
75sleep 10
76ifconfig
77ip link list
78
79sudo "${OTBR_AGENT}" -I wpan0 -v -d7 -B ilstest0 -B ilstest1 -B ilstest2 "spinel+hdlc+forkpty://${OT_RCP}?forkpty-arg=1" 2>&1 | tee output &
80
81function check_infra_link()
82{
83    grep "\-ILS\-\-\-\-\-: Infra link \(selected\|unchanged\|switched\)" output | tail -1
84}
85
86function verify_otbr_agent_exited()
87{
88    if pgrep otbr-agent; then
89        return 1
90    fi
91}
92
93sleep 3
94# Verify ILS selects ilstest0
95check_infra_link | grep "selected: ilstest0"
96
97sudo ifconfig ilstest1 down
98sudo ifconfig ilstest2 down
99
100sleep 3
101# Verify ILS keeps using ilstest0
102check_infra_link | grep "unchanged: ilstest0"
103
104sudo ifconfig ilstest2 up
105
106sleep 3
107# Verify ILS keeps using ilstest0 because ilstest0 is still RUNNING
108check_infra_link | grep "unchanged: ilstest0"
109
110sudo ifconfig ilstest0 down
111sleep 3
112# Verify ILS keeps using ilstest0 because ilstest0 was RUNNING recently
113check_infra_link | grep "unchanged: ilstest0"
114
115sudo ifconfig ilstest0 up
116sleep 11
117
118# Verify ILS keeps using ilstest0 because ilstest0 is RUNNING again
119check_infra_link | grep "unchanged: ilstest0"
120
121sudo ifconfig ilstest0 down
122sleep 11
123# Verify ILS switches to ilstest2 after ilstest0 is DOWN for more than 10s
124check_infra_link | grep "switched from ilstest0 to ilstest2"
125verify_otbr_agent_exited
126
127# Now, only ilstest2 is RUNNING
128
129sudo "${OTBR_AGENT}" -I wpan0 -v -d7 -B ilstest0 -B ilstest1 -B ilstest2 "spinel+hdlc+forkpty://${OT_RCP}?forkpty-arg=1" 2>&1 | tee output &
130
131sleep 3
132# Verify ILS selects ilstest2 after reboot
133check_infra_link | grep "selected: ilstest2"
134
135sudo ifconfig ilstest2 down
136sleep 3
137# Verify ILS keeps using ilstest2 because ilstest2 was RUNNING recently
138check_infra_link | grep "unchanged: ilstest2"
139
140sleep 8
141sudo ifconfig ilstest1 up
142sleep 3
143# Verify ILS switches to ilstest1 because ilstest2 was not RUNNING for more than 10s
144check_infra_link | grep "switched from ilstest2 to ilstest1"
145verify_otbr_agent_exited
146