2 # SPDX-License-Identifier: GPL-2.0
10 echo "Usage: $0 [OPTION]"
11 echo -e "\t-4: IPv4 only: disable IPv6 tests (default: test both IPv4 and IPv6)"
14 while getopts "$optstring" option;do
31 rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
39 for netns in "$ns1" "$ns2" "$ns3" ;do
44 ip -Version > /dev/null 2>&1
46 echo "SKIP: Could not run test without ip tool"
52 for i in "$ns1" "$ns2" "$ns3" ;do
53 ip netns add $i || exit $ksft_skip
54 ip -net $i link set lo up
57 echo "INFO: preparing interfaces."
58 # Three HSR nodes. Each node has one link to each of its neighbour, two links in total.
60 # ns1eth1 ----- ns2eth1
69 ip link add ns1eth1 netns "$ns1" type veth peer name ns2eth1 netns "$ns2"
70 ip link add ns1eth2 netns "$ns1" type veth peer name ns3eth1 netns "$ns3"
71 ip link add ns3eth2 netns "$ns3" type veth peer name ns2eth2 netns "$ns2"
74 ip -net "$ns1" link add name hsr1 type hsr slave1 ns1eth1 slave2 ns1eth2 supervision 45 version 0 proto 0
75 ip -net "$ns2" link add name hsr2 type hsr slave1 ns2eth1 slave2 ns2eth2 supervision 45 version 0 proto 0
76 ip -net "$ns3" link add name hsr3 type hsr slave1 ns3eth1 slave2 ns3eth2 supervision 45 version 0 proto 0
79 ip -net "$ns1" addr add 100.64.0.1/24 dev hsr1
80 ip -net "$ns1" addr add dead:beef:1::1/64 dev hsr1 nodad
81 ip -net "$ns2" addr add 100.64.0.2/24 dev hsr2
82 ip -net "$ns2" addr add dead:beef:1::2/64 dev hsr2 nodad
83 ip -net "$ns3" addr add 100.64.0.3/24 dev hsr3
84 ip -net "$ns3" addr add dead:beef:1::3/64 dev hsr3 nodad
87 ip -net "$ns1" link set ns1eth1 up
88 ip -net "$ns1" link set ns1eth2 up
89 ip -net "$ns1" link set hsr1 up
91 ip -net "$ns2" link set ns2eth1 up
92 ip -net "$ns2" link set ns2eth2 up
93 ip -net "$ns2" link set hsr2 up
95 ip -net "$ns3" link set ns3eth1 up
96 ip -net "$ns3" link set ns3eth2 up
97 ip -net "$ns3" link set hsr3 up
108 local connect_addr="$2"
109 local ping_args="-q -c 2"
111 if is_v6 "${connect_addr}"; then
113 ping_args="${ping_args} -6"
116 ip netns exec ${netns} ping ${ping_args} $connect_addr >/dev/null
117 if [ $? -ne 0 ] ; then
118 echo "$netns -> $connect_addr connectivity [ FAIL ]" 1>&2
129 local connect_addr="$2"
130 local ping_args="-q -c 10"
132 if is_v6 "${connect_addr}"; then
134 ping_args="${ping_args} -6"
137 OUT="$(LANG=C ip netns exec ${netns} ping ${ping_args} $connect_addr | grep received)"
138 if [ $? -ne 0 ] ; then
139 echo "$netns -> $connect_addr ping [ FAIL ]" 1>&2
144 VAL="$(echo $OUT | cut -d' ' -f1-8)"
145 if [ "$VAL" != "10 packets transmitted, 10 received, 0% packet loss," ]
147 echo "$netns -> $connect_addr ping TEST [ FAIL ]"
148 echo "Expect to send and receive 10 packets and no duplicates."
149 echo "Full message: ${OUT}."
161 if [ ${ret} -ne 0 ]; then
162 echo "FAIL: ${msg}" 1>&2
168 echo "INFO: Initial validation ping."
169 # Each node has to be able each one.
170 do_ping "$ns1" 100.64.0.2
171 do_ping "$ns2" 100.64.0.1
172 do_ping "$ns3" 100.64.0.1
173 stop_if_error "Initial validation failed."
175 do_ping "$ns1" 100.64.0.3
176 do_ping "$ns2" 100.64.0.3
177 do_ping "$ns3" 100.64.0.2
179 do_ping "$ns1" dead:beef:1::2
180 do_ping "$ns1" dead:beef:1::3
181 do_ping "$ns2" dead:beef:1::1
182 do_ping "$ns2" dead:beef:1::2
183 do_ping "$ns3" dead:beef:1::1
184 do_ping "$ns3" dead:beef:1::2
186 stop_if_error "Initial validation failed."
188 # Wait until supervisor all supervision frames have been processed and the node
189 # entries have been merged. Otherwise duplicate frames will be observed which is
190 # valid at this stage.
192 while [ ${WAIT} -gt 0 ]
194 grep 00:00:00:00:00:00 /sys/kernel/debug/hsr/hsr*/node_table
203 # Just a safety delay in case the above check didn't handle it.
206 echo "INFO: Longer ping test."
207 do_ping_long "$ns1" 100.64.0.2
208 do_ping_long "$ns1" dead:beef:1::2
209 do_ping_long "$ns1" 100.64.0.3
210 do_ping_long "$ns1" dead:beef:1::3
212 stop_if_error "Longer ping test failed."
214 do_ping_long "$ns2" 100.64.0.1
215 do_ping_long "$ns2" dead:beef:1::1
216 do_ping_long "$ns2" 100.64.0.3
217 do_ping_long "$ns2" dead:beef:1::2
218 stop_if_error "Longer ping test failed."
220 do_ping_long "$ns3" 100.64.0.1
221 do_ping_long "$ns3" dead:beef:1::1
222 do_ping_long "$ns3" 100.64.0.2
223 do_ping_long "$ns3" dead:beef:1::2
224 stop_if_error "Longer ping test failed."
226 echo "INFO: Cutting one link."
227 do_ping_long "$ns1" 100.64.0.3 &
230 ip -net "$ns3" link set ns3eth1 down
233 ip -net "$ns3" link set ns3eth1 up
235 stop_if_error "Failed with one link down."
237 echo "INFO: Delay the link and drop a few packages."
238 tc -net "$ns3" qdisc add dev ns3eth1 root netem delay 50ms
239 tc -net "$ns2" qdisc add dev ns2eth1 root netem delay 5ms loss 25%
241 do_ping_long "$ns1" 100.64.0.2
242 do_ping_long "$ns1" 100.64.0.3
244 stop_if_error "Failed with delay and packetloss."
246 do_ping_long "$ns2" 100.64.0.1
247 do_ping_long "$ns2" 100.64.0.3
249 stop_if_error "Failed with delay and packetloss."
251 do_ping_long "$ns3" 100.64.0.1
252 do_ping_long "$ns3" 100.64.0.2
253 stop_if_error "Failed with delay and packetloss."
255 echo "INFO: All good."