Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4ipv6=true
5
6source ./hsr_common.sh
7
8optstring="h4"
9usage() {
10 echo "Usage: $0 [OPTION]"
11 echo -e "\t-4: IPv4 only: disable IPv6 tests (default: test both IPv4 and IPv6)"
12}
13
14while getopts "$optstring" option;do
15 case "$option" in
16 "h")
17 usage $0
18 exit 0
19 ;;
20 "4")
21 ipv6=false
22 ;;
23 "?")
24 usage $0
25 exit 1
26 ;;
27esac
28done
29
30do_complete_ping_test()
31{
32 echo "INFO: Initial validation ping."
33 # Each node has to be able each one.
34 do_ping "$ns1" 100.64.0.2
35 do_ping "$ns2" 100.64.0.1
36 do_ping "$ns3" 100.64.0.1
37 stop_if_error "Initial validation failed."
38
39 do_ping "$ns1" 100.64.0.3
40 do_ping "$ns2" 100.64.0.3
41 do_ping "$ns3" 100.64.0.2
42
43 do_ping "$ns1" dead:beef:1::2
44 do_ping "$ns1" dead:beef:1::3
45 do_ping "$ns2" dead:beef:1::1
46 do_ping "$ns2" dead:beef:1::2
47 do_ping "$ns3" dead:beef:1::1
48 do_ping "$ns3" dead:beef:1::2
49
50 stop_if_error "Initial validation failed."
51
52# Wait until supervisor all supervision frames have been processed and the node
53# entries have been merged. Otherwise duplicate frames will be observed which is
54# valid at this stage.
55 WAIT=5
56 while [ ${WAIT} -gt 0 ]
57 do
58 grep 00:00:00:00:00:00 /sys/kernel/debug/hsr/hsr*/node_table
59 if [ $? -ne 0 ]
60 then
61 break
62 fi
63 sleep 1
64 let "WAIT = WAIT - 1"
65 done
66
67# Just a safety delay in case the above check didn't handle it.
68 sleep 1
69
70 echo "INFO: Longer ping test."
71 do_ping_long "$ns1" 100.64.0.2
72 do_ping_long "$ns1" dead:beef:1::2
73 do_ping_long "$ns1" 100.64.0.3
74 do_ping_long "$ns1" dead:beef:1::3
75
76 stop_if_error "Longer ping test failed."
77
78 do_ping_long "$ns2" 100.64.0.1
79 do_ping_long "$ns2" dead:beef:1::1
80 do_ping_long "$ns2" 100.64.0.3
81 do_ping_long "$ns2" dead:beef:1::2
82 stop_if_error "Longer ping test failed."
83
84 do_ping_long "$ns3" 100.64.0.1
85 do_ping_long "$ns3" dead:beef:1::1
86 do_ping_long "$ns3" 100.64.0.2
87 do_ping_long "$ns3" dead:beef:1::2
88 stop_if_error "Longer ping test failed."
89
90 echo "INFO: Cutting one link."
91 do_ping_long "$ns1" 100.64.0.3 &
92
93 sleep 3
94 ip -net "$ns3" link set ns3eth1 down
95 wait
96
97 ip -net "$ns3" link set ns3eth1 up
98
99 stop_if_error "Failed with one link down."
100
101 echo "INFO: Delay the link and drop a few packages."
102 tc -net "$ns3" qdisc add dev ns3eth1 root netem delay 50ms
103 tc -net "$ns2" qdisc add dev ns2eth1 root netem delay 5ms loss 25%
104
105 do_ping_long "$ns1" 100.64.0.2
106 do_ping_long "$ns1" 100.64.0.3
107
108 stop_if_error "Failed with delay and packetloss."
109
110 do_ping_long "$ns2" 100.64.0.1
111 do_ping_long "$ns2" 100.64.0.3
112
113 stop_if_error "Failed with delay and packetloss."
114
115 do_ping_long "$ns3" 100.64.0.1
116 do_ping_long "$ns3" 100.64.0.2
117 stop_if_error "Failed with delay and packetloss."
118
119 echo "INFO: All good."
120}
121
122setup_hsr_interfaces()
123{
124 local HSRv="$1"
125
126 echo "INFO: preparing interfaces for HSRv${HSRv}."
127# Three HSR nodes. Each node has one link to each of its neighbour, two links in total.
128#
129# ns1eth1 ----- ns2eth1
130# hsr1 hsr2
131# ns1eth2 ns2eth2
132# | |
133# ns3eth1 ns3eth2
134# \ /
135# hsr3
136#
137 # Interfaces
138 ip link add ns1eth1 netns "$ns1" type veth peer name ns2eth1 netns "$ns2"
139 ip link add ns1eth2 netns "$ns1" type veth peer name ns3eth1 netns "$ns3"
140 ip link add ns3eth2 netns "$ns3" type veth peer name ns2eth2 netns "$ns2"
141
142 # HSRv0/1
143 ip -net "$ns1" link add name hsr1 type hsr slave1 ns1eth1 slave2 ns1eth2 supervision 45 version $HSRv proto 0
144 ip -net "$ns2" link add name hsr2 type hsr slave1 ns2eth1 slave2 ns2eth2 supervision 45 version $HSRv proto 0
145 ip -net "$ns3" link add name hsr3 type hsr slave1 ns3eth1 slave2 ns3eth2 supervision 45 version $HSRv proto 0
146
147 # IP for HSR
148 ip -net "$ns1" addr add 100.64.0.1/24 dev hsr1
149 ip -net "$ns1" addr add dead:beef:1::1/64 dev hsr1 nodad
150 ip -net "$ns2" addr add 100.64.0.2/24 dev hsr2
151 ip -net "$ns2" addr add dead:beef:1::2/64 dev hsr2 nodad
152 ip -net "$ns3" addr add 100.64.0.3/24 dev hsr3
153 ip -net "$ns3" addr add dead:beef:1::3/64 dev hsr3 nodad
154
155 ip -net "$ns1" link set address 00:11:22:00:01:01 dev ns1eth1
156 ip -net "$ns1" link set address 00:11:22:00:01:02 dev ns1eth2
157
158 ip -net "$ns2" link set address 00:11:22:00:02:01 dev ns2eth1
159 ip -net "$ns2" link set address 00:11:22:00:02:02 dev ns2eth2
160
161 ip -net "$ns3" link set address 00:11:22:00:03:01 dev ns3eth1
162 ip -net "$ns3" link set address 00:11:22:00:03:02 dev ns3eth2
163
164 # All Links up
165 ip -net "$ns1" link set ns1eth1 up
166 ip -net "$ns1" link set ns1eth2 up
167 ip -net "$ns1" link set hsr1 up
168
169 ip -net "$ns2" link set ns2eth1 up
170 ip -net "$ns2" link set ns2eth2 up
171 ip -net "$ns2" link set hsr2 up
172
173 ip -net "$ns3" link set ns3eth1 up
174 ip -net "$ns3" link set ns3eth2 up
175 ip -net "$ns3" link set hsr3 up
176}
177
178check_prerequisites
179setup_ns ns1 ns2 ns3
180
181trap cleanup_all_ns EXIT
182
183setup_hsr_interfaces 0
184do_complete_ping_test
185
186setup_ns ns1 ns2 ns3
187
188setup_hsr_interfaces 1
189do_complete_ping_test
190
191exit $ret