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 93do_link_problem_tests() 94{ 95 echo "INFO: Running link problem tests." 96 97 echo "INFO: Delay the link and drop a few packages." 98 tc -net "$ns3" qdisc add dev ns3eth1 root netem delay 50ms 99 tc -net "$ns2" qdisc add dev ns2eth1 root netem delay 5ms loss 25% 100 101 do_ping_long "$ns1" 100.64.0.2 102 do_ping_long "$ns1" 100.64.0.3 103 stop_if_error "Failed with delay and packetloss (ns1)." 104 105 do_ping_long "$ns2" 100.64.0.1 106 do_ping_long "$ns2" 100.64.0.3 107 stop_if_error "Failed with delay and packetloss (ns2)." 108 109 do_ping_long "$ns3" 100.64.0.1 110 do_ping_long "$ns3" 100.64.0.2 111 stop_if_error "Failed with delay and packetloss (ns3)." 112} 113 114setup_hsr_interfaces() 115{ 116 local HSRv="$1" 117 118 echo "INFO: Preparing interfaces for HSRv${HSRv}." 119# Three HSR nodes. Each node has one link to each of its neighbour, two links in total. 120# 121# ns1eth1 ----- ns2eth1 122# hsr1 hsr2 123# ns1eth2 ns2eth2 124# | | 125# ns3eth1 ns3eth2 126# \ / 127# hsr3 128# 129 # Interfaces 130 ip link add ns1eth1 netns "$ns1" type veth peer name ns2eth1 netns "$ns2" 131 ip link add ns1eth2 netns "$ns1" type veth peer name ns3eth1 netns "$ns3" 132 ip link add ns3eth2 netns "$ns3" type veth peer name ns2eth2 netns "$ns2" 133 134 # HSRv0/1 135 ip -net "$ns1" link add name hsr1 type hsr slave1 ns1eth1 \ 136 slave2 ns1eth2 supervision 45 version "$HSRv" proto 0 137 ip -net "$ns2" link add name hsr2 type hsr slave1 ns2eth1 \ 138 slave2 ns2eth2 supervision 45 version "$HSRv" proto 0 139 ip -net "$ns3" link add name hsr3 type hsr slave1 ns3eth1 \ 140 slave2 ns3eth2 supervision 45 version "$HSRv" proto 0 141 142 # IP for HSR 143 ip -net "$ns1" addr add 100.64.0.1/24 dev hsr1 144 ip -net "$ns1" addr add dead:beef:0::1/64 dev hsr1 nodad 145 ip -net "$ns2" addr add 100.64.0.2/24 dev hsr2 146 ip -net "$ns2" addr add dead:beef:0::2/64 dev hsr2 nodad 147 ip -net "$ns3" addr add 100.64.0.3/24 dev hsr3 148 ip -net "$ns3" addr add dead:beef:0::3/64 dev hsr3 nodad 149 150 ip -net "$ns1" link set address 00:11:22:00:01:01 dev ns1eth1 151 ip -net "$ns1" link set address 00:11:22:00:01:02 dev ns1eth2 152 153 ip -net "$ns2" link set address 00:11:22:00:02:01 dev ns2eth1 154 ip -net "$ns2" link set address 00:11:22:00:02:02 dev ns2eth2 155 156 ip -net "$ns3" link set address 00:11:22:00:03:01 dev ns3eth1 157 ip -net "$ns3" link set address 00:11:22:00:03:02 dev ns3eth2 158 159 # All Links up 160 ip -net "$ns1" link set ns1eth1 up 161 ip -net "$ns1" link set ns1eth2 up 162 ip -net "$ns1" link set hsr1 up 163 164 ip -net "$ns2" link set ns2eth1 up 165 ip -net "$ns2" link set ns2eth2 up 166 ip -net "$ns2" link set hsr2 up 167 168 ip -net "$ns3" link set ns3eth1 up 169 ip -net "$ns3" link set ns3eth2 up 170 ip -net "$ns3" link set hsr3 up 171} 172 173setup_vlan_interfaces() { 174 ip -net "$ns1" link add link hsr1 name hsr1.2 type vlan id 2 175 ip -net "$ns2" link add link hsr2 name hsr2.2 type vlan id 2 176 ip -net "$ns3" link add link hsr3 name hsr3.2 type vlan id 2 177 178 ip -net "$ns1" addr add 100.64.2.1/24 dev hsr1.2 179 ip -net "$ns1" addr add dead:beef:2::1/64 dev hsr1.2 nodad 180 181 ip -net "$ns2" addr add 100.64.2.2/24 dev hsr2.2 182 ip -net "$ns2" addr add dead:beef:2::2/64 dev hsr2.2 nodad 183 184 ip -net "$ns3" addr add 100.64.2.3/24 dev hsr3.2 185 ip -net "$ns3" addr add dead:beef:2::3/64 dev hsr3.2 nodad 186 187 ip -net "$ns1" link set dev hsr1.2 up 188 ip -net "$ns2" link set dev hsr2.2 up 189 ip -net "$ns3" link set dev hsr3.2 up 190 191} 192 193run_complete_ping_tests() 194{ 195 echo "INFO: Running complete ping tests." 196 do_ping_tests 0 197 do_link_problem_tests 198} 199 200run_vlan_tests() 201{ 202 vlan_challenged_hsr1=$(ip net exec "$ns1" ethtool -k hsr1 | grep "vlan-challenged" | awk '{print $2}') 203 vlan_challenged_hsr2=$(ip net exec "$ns2" ethtool -k hsr2 | grep "vlan-challenged" | awk '{print $2}') 204 vlan_challenged_hsr3=$(ip net exec "$ns3" ethtool -k hsr3 | grep "vlan-challenged" | awk '{print $2}') 205 206 if [[ "$vlan_challenged_hsr1" = "off" || "$vlan_challenged_hsr2" = "off" || "$vlan_challenged_hsr3" = "off" ]]; then 207 echo "INFO: Running VLAN tests" 208 setup_vlan_interfaces 209 do_ping_tests 2 210 else 211 echo "INFO: Not Running VLAN tests as the device does not support VLAN" 212 fi 213} 214 215check_prerequisites 216trap cleanup_all_ns EXIT 217 218setup_ns ns1 ns2 ns3 219setup_hsr_interfaces 0 220run_complete_ping_tests 221run_vlan_tests 222 223setup_ns ns1 ns2 ns3 224setup_hsr_interfaces 1 225run_complete_ping_tests 226run_vlan_tests 227 228exit $ret 229