1#!/usr/bin/expect -f
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#
29
30source "tests/scripts/expect/_common.exp"
31source "tests/scripts/expect/_multinode.exp"
32
33spawn_node 3
34spawn_node 2
35spawn_node 1
36
37setup_leader
38setup_node 3 "rdn" "router"
39setup_node 2 "rdn" "router"
40
41sleep 15
42
43###########################################
44# Verify topology and commissioners
45
46switch_node 3
47send "state\n"
48expect "router"
49send "commissioner state\n"
50expect "disabled"
51
52switch_node 2
53send "state\n"
54expect "router"
55send "commissioner state\n"
56expect "disabled"
57
58switch_node 1
59send "state\n"
60expect "leader"
61send "commissioner state\n"
62expect "active"
63
64###########################################
65# Starting a commissioner on the same partition with the same ID makes
66# the active commissioner resign and become disabled.
67
68switch_node 2
69send "commissioner start\n"
70expect "Done"
71wait_for "commissioner state" "active"
72switch_node 1
73sleep 5
74wait_for "commissioner state" "disabled"
75
76switch_node 3
77send "commissioner start\n"
78expect "Done"
79wait_for "commissioner state" "active"
80sleep 5
81switch_node 2
82wait_for "commissioner state" "disabled"
83
84switch_node 1
85send "commissioner start\n"
86expect "Done"
87wait_for "commissioner state" "active"
88sleep 5
89switch_node 3
90wait_for "commissioner state" "disabled"
91
92###########################################
93# Starting another commissioner on the same partition, using a different ID avoids
94# the previous problem of overriding the active commissioner.
95
96switch_node 2
97send "commissioner id COMMISSIONER_2\n"
98expect "Done"
99send "commissioner start\n"
100expect "Done"
101wait_for "commissioner state" "petitioning"
102wait_for "commissioner state" "disabled"
103
104switch_node 1
105send "commissioner state\n"
106expect "active"
107
108switch_node 3
109send "commissioner id COMMISSIONER_3\n"
110expect "Done"
111send "commissioner start\n"
112expect "Done"
113wait_for "commissioner state" "petitioning"
114wait_for "commissioner state" "disabled"
115
116switch_node 1
117send "commissioner state\n"
118expect "active"
119
120###########################################
121# Stop active commissioner and start another one
122send "commissioner stop\n"
123
124switch_node 2
125send "commissioner id COMMISSIONER_2\n"
126expect "Done"
127send "commissioner start\n"
128expect "Done"
129wait_for "commissioner state" "petitioning"
130wait_for "commissioner state" "active"
131
132switch_node 1
133send "commissioner start\n"
134expect "Done"
135wait_for "commissioner state" "petitioning"
136wait_for "commissioner state" "disabled"
137
138###########################################
139dispose_all
140