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_ping_tests()
31{
32 local netid="$1"
33
34 echo "INFO: Running ping tests."
35
36 echo "INFO: Initial validation ping."
37 # Each node has to be able to reach each one.
38 do_ping "$ns1" "100.64.$netid.2"
39 do_ping "$ns1" "100.64.$netid.3"
40 do_ping "$ns2" "100.64.$netid.1"
41 do_ping "$ns2" "100.64.$netid.3"
42 do_ping "$ns3" "100.64.$netid.1"
43 do_ping "$ns3" "100.64.$netid.2"
44 stop_if_error "Initial validation failed on IPv4."
45
46 do_ping "$ns1" "dead:beef:$netid::2"
47 do_ping "$ns1" "dead:beef:$netid::3"
48 do_ping "$ns2" "dead:beef:$netid::1"
49 do_ping "$ns2" "dead:beef:$netid::2"
50 do_ping "$ns3" "dead:beef:$netid::1"
51 do_ping "$ns3" "dead:beef:$netid::2"
52 stop_if_error "Initial validation failed on IPv6."
53
54# Wait until supervisor all supervision frames have been processed and the node
55# entries have been merged. Otherwise duplicate frames will be observed which is
56# valid at this stage.
57 echo "INFO: Wait for node table entries to be merged."
58 WAIT=5
59 while [ ${WAIT} -gt 0 ]
60 do
61 grep 00:00:00:00:00:00 /sys/kernel/debug/hsr/hsr*/node_table
62 if [ $? -ne 0 ]
63 then
64 break
65 fi
66 sleep 1
67 let "WAIT = WAIT - 1"
68 done
69
70# Just a safety delay in case the above check didn't handle it.
71 sleep 1
72
73 echo "INFO: Longer ping test."
74 do_ping_long "$ns1" "100.64.$netid.2"
75 do_ping_long "$ns1" "dead:beef:$netid::2"
76 do_ping_long "$ns1" "100.64.$netid.3"
77 do_ping_long "$ns1" "dead:beef:$netid::3"
78 stop_if_error "Longer ping test failed (ns1)."
79
80 do_ping_long "$ns2" "100.64.$netid.1"
81 do_ping_long "$ns2" "dead:beef:$netid::1"
82 do_ping_long "$ns2" "100.64.$netid.3"
83 do_ping_long "$ns2" "dead:beef:$netid::3"
84 stop_if_error "Longer ping test failed (ns2)."
85
86 do_ping_long "$ns3" "100.64.$netid.1"
87 do_ping_long "$ns3" "dead:beef:$netid::1"
88 do_ping_long "$ns3" "100.64.$netid.2"
89 do_ping_long "$ns3" "dead:beef:$netid::2"
90 stop_if_error "Longer ping test failed (ns3)."
91}
92
93setup_hsr_interfaces()
94{
95 local HSRv="$1"
96
97 echo "INFO: Preparing interfaces for HSRv${HSRv}."
98# Three HSR nodes. Each node has one link to each of its neighbour, two links in total.
99#
100# ns1eth1 ----- ns2eth1
101# hsr1 hsr2
102# ns1eth2 ns2eth2
103# | |
104# ns3eth1 ns3eth2
105# \ /
106# hsr3
107#
108 # Interfaces
109 ip link add ns1eth1 netns "$ns1" type veth peer name ns2eth1 netns "$ns2"
110 ip link add ns1eth2 netns "$ns1" type veth peer name ns3eth1 netns "$ns3"
111 ip link add ns3eth2 netns "$ns3" type veth peer name ns2eth2 netns "$ns2"
112
113 # HSRv0/1
114 ip -net "$ns1" link add name hsr1 type hsr slave1 ns1eth1 \
115 slave2 ns1eth2 supervision 45 version "$HSRv" proto 0
116 ip -net "$ns2" link add name hsr2 type hsr slave1 ns2eth1 \
117 slave2 ns2eth2 supervision 45 version "$HSRv" proto 0
118 ip -net "$ns3" link add name hsr3 type hsr slave1 ns3eth1 \
119 slave2 ns3eth2 supervision 45 version "$HSRv" proto 0
120
121 # IP for HSR
122 ip -net "$ns1" addr add 100.64.0.1/24 dev hsr1
123 ip -net "$ns1" addr add dead:beef:0::1/64 dev hsr1 nodad
124 ip -net "$ns2" addr add 100.64.0.2/24 dev hsr2
125 ip -net "$ns2" addr add dead:beef:0::2/64 dev hsr2 nodad
126 ip -net "$ns3" addr add 100.64.0.3/24 dev hsr3
127 ip -net "$ns3" addr add dead:beef:0::3/64 dev hsr3 nodad
128
129 ip -net "$ns1" link set address 00:11:22:00:01:01 dev ns1eth1
130 ip -net "$ns1" link set address 00:11:22:00:01:02 dev ns1eth2
131
132 ip -net "$ns2" link set address 00:11:22:00:02:01 dev ns2eth1
133 ip -net "$ns2" link set address 00:11:22:00:02:02 dev ns2eth2
134
135 ip -net "$ns3" link set address 00:11:22:00:03:01 dev ns3eth1
136 ip -net "$ns3" link set address 00:11:22:00:03:02 dev ns3eth2
137
138 # All Links up
139 ip -net "$ns1" link set ns1eth1 up
140 ip -net "$ns1" link set ns1eth2 up
141 ip -net "$ns1" link set hsr1 up
142
143 ip -net "$ns2" link set ns2eth1 up
144 ip -net "$ns2" link set ns2eth2 up
145 ip -net "$ns2" link set hsr2 up
146
147 ip -net "$ns3" link set ns3eth1 up
148 ip -net "$ns3" link set ns3eth2 up
149 ip -net "$ns3" link set hsr3 up
150}
151
152setup_vlan_interfaces() {
153 ip -net "$ns1" link add link hsr1 name hsr1.2 type vlan id 2
154 ip -net "$ns2" link add link hsr2 name hsr2.2 type vlan id 2
155 ip -net "$ns3" link add link hsr3 name hsr3.2 type vlan id 2
156
157 ip -net "$ns1" addr add 100.64.2.1/24 dev hsr1.2
158 ip -net "$ns1" addr add dead:beef:2::1/64 dev hsr1.2 nodad
159
160 ip -net "$ns2" addr add 100.64.2.2/24 dev hsr2.2
161 ip -net "$ns2" addr add dead:beef:2::2/64 dev hsr2.2 nodad
162
163 ip -net "$ns3" addr add 100.64.2.3/24 dev hsr3.2
164 ip -net "$ns3" addr add dead:beef:2::3/64 dev hsr3.2 nodad
165
166 ip -net "$ns1" link set dev hsr1.2 up
167 ip -net "$ns2" link set dev hsr2.2 up
168 ip -net "$ns3" link set dev hsr3.2 up
169
170}
171
172run_ping_tests()
173{
174 echo "INFO: Running ping tests."
175 do_ping_tests 0
176}
177
178run_vlan_tests()
179{
180 vlan_challenged_hsr1=$(ip net exec "$ns1" ethtool -k hsr1 | grep "vlan-challenged" | awk '{print $2}')
181 vlan_challenged_hsr2=$(ip net exec "$ns2" ethtool -k hsr2 | grep "vlan-challenged" | awk '{print $2}')
182 vlan_challenged_hsr3=$(ip net exec "$ns3" ethtool -k hsr3 | grep "vlan-challenged" | awk '{print $2}')
183
184 if [[ "$vlan_challenged_hsr1" = "off" || "$vlan_challenged_hsr2" = "off" || "$vlan_challenged_hsr3" = "off" ]]; then
185 echo "INFO: Running VLAN ping tests"
186 setup_vlan_interfaces
187 do_ping_tests 2
188 else
189 echo "INFO: Not Running VLAN tests as the device does not support VLAN"
190 fi
191}
192
193check_prerequisites
194trap cleanup_all_ns EXIT
195
196setup_ns ns1 ns2 ns3
197setup_hsr_interfaces 0
198run_ping_tests
199run_vlan_tests
200
201setup_ns ns1 ns2 ns3
202setup_hsr_interfaces 1
203run_ping_tests
204run_vlan_tests
205
206exit $ret