|
| 1 | +#!/bin/bash |
| 2 | +# SPDX-License-Identifier: GPL-2.0 |
| 3 | + |
| 4 | +ipv6=true |
| 5 | + |
| 6 | +source ./hsr_common.sh |
| 7 | + |
| 8 | +optstring="h4" |
| 9 | +usage() { |
| 10 | + echo "Usage: $0 [OPTION]" |
| 11 | + echo -e "\t-4: IPv4 only: disable IPv6 tests (default: test both IPv4 and IPv6)" |
| 12 | +} |
| 13 | + |
| 14 | +while 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 | + ;; |
| 27 | +esac |
| 28 | +done |
| 29 | + |
| 30 | +setup_prp_interfaces() |
| 31 | +{ |
| 32 | + echo "INFO: Preparing interfaces for PRP" |
| 33 | +# Two PRP nodes, connected by two links (treated as LAN A and LAN B). |
| 34 | +# |
| 35 | +# vethA ----- vethA |
| 36 | +# prp1 prp2 |
| 37 | +# vethB ----- vethB |
| 38 | +# |
| 39 | +# node1 node2 |
| 40 | + |
| 41 | + # Interfaces |
| 42 | + # shellcheck disable=SC2154 # variables assigned by setup_ns |
| 43 | + ip link add vethA netns "$node1" type veth peer name vethA netns "$node2" |
| 44 | + ip link add vethB netns "$node1" type veth peer name vethB netns "$node2" |
| 45 | + |
| 46 | + # MAC addresses will be copied from LAN A interface |
| 47 | + ip -net "$node1" link set address 00:11:22:00:00:01 dev vethA |
| 48 | + ip -net "$node2" link set address 00:11:22:00:00:02 dev vethA |
| 49 | + |
| 50 | + # PRP |
| 51 | + ip -net "$node1" link add name prp1 type hsr \ |
| 52 | + slave1 vethA slave2 vethB supervision 45 proto 1 |
| 53 | + ip -net "$node2" link add name prp2 type hsr \ |
| 54 | + slave1 vethA slave2 vethB supervision 45 proto 1 |
| 55 | + |
| 56 | + # IP addresses |
| 57 | + ip -net "$node1" addr add 100.64.0.1/24 dev prp1 |
| 58 | + ip -net "$node1" addr add dead:beef:0::1/64 dev prp1 nodad |
| 59 | + ip -net "$node2" addr add 100.64.0.2/24 dev prp2 |
| 60 | + ip -net "$node2" addr add dead:beef:0::2/64 dev prp2 nodad |
| 61 | + |
| 62 | + # All links up |
| 63 | + ip -net "$node1" link set vethA up |
| 64 | + ip -net "$node1" link set vethB up |
| 65 | + ip -net "$node1" link set prp1 up |
| 66 | + |
| 67 | + ip -net "$node2" link set vethA up |
| 68 | + ip -net "$node2" link set vethB up |
| 69 | + ip -net "$node2" link set prp2 up |
| 70 | +} |
| 71 | + |
| 72 | +setup_vlan_interfaces() |
| 73 | +{ |
| 74 | + # Interfaces |
| 75 | + ip -net "$node1" link add link prp1 name prp1.2 type vlan id 2 |
| 76 | + ip -net "$node2" link add link prp2 name prp2.2 type vlan id 2 |
| 77 | + |
| 78 | + # IP addresses |
| 79 | + ip -net "$node1" addr add 100.64.2.1/24 dev prp1.2 |
| 80 | + ip -net "$node1" addr add dead:beef:2::1/64 dev prp1.2 nodad |
| 81 | + |
| 82 | + ip -net "$node2" addr add 100.64.2.2/24 dev prp2.2 |
| 83 | + ip -net "$node2" addr add dead:beef:2::2/64 dev prp2.2 nodad |
| 84 | + |
| 85 | + # All links up |
| 86 | + ip -net "$node1" link set prp1.2 up |
| 87 | + ip -net "$node2" link set prp2.2 up |
| 88 | +} |
| 89 | + |
| 90 | +do_ping_tests() |
| 91 | +{ |
| 92 | + local netid="$1" |
| 93 | + |
| 94 | + echo "INFO: Initial validation ping" |
| 95 | + |
| 96 | + do_ping "$node1" "100.64.$netid.2" |
| 97 | + do_ping "$node2" "100.64.$netid.1" |
| 98 | + stop_if_error "Initial validation failed on IPv4" |
| 99 | + |
| 100 | + do_ping "$node1" "dead:beef:$netid::2" |
| 101 | + do_ping "$node2" "dead:beef:$netid::1" |
| 102 | + stop_if_error "Initial validation failed on IPv6" |
| 103 | + |
| 104 | + echo "INFO: Longer ping test." |
| 105 | + |
| 106 | + do_ping_long "$node1" "100.64.$netid.2" |
| 107 | + do_ping_long "$node2" "100.64.$netid.1" |
| 108 | + stop_if_error "Longer ping test failed on IPv4." |
| 109 | + |
| 110 | + do_ping_long "$node1" "dead:beef:$netid::2" |
| 111 | + do_ping_long "$node2" "dead:beef:$netid::1" |
| 112 | + stop_if_error "Longer ping test failed on IPv6." |
| 113 | +} |
| 114 | + |
| 115 | +run_ping_tests() |
| 116 | +{ |
| 117 | + echo "INFO: Running ping tests" |
| 118 | + do_ping_tests 0 |
| 119 | +} |
| 120 | + |
| 121 | +run_vlan_ping_tests() |
| 122 | +{ |
| 123 | + vlan_challenged_prp1=$(ip net exec "$node1" ethtool -k prp1 | \ |
| 124 | + grep "vlan-challenged" | awk '{print $2}') |
| 125 | + vlan_challenged_prp2=$(ip net exec "$node2" ethtool -k prp2 | \ |
| 126 | + grep "vlan-challenged" | awk '{print $2}') |
| 127 | + |
| 128 | + if [[ "$vlan_challenged_prp1" = "off" || \ |
| 129 | + "$vlan_challenged_prp2" = "off" ]]; then |
| 130 | + echo "INFO: Running VLAN ping tests" |
| 131 | + setup_vlan_interfaces |
| 132 | + do_ping_tests 2 |
| 133 | + else |
| 134 | + echo "INFO: Not Running VLAN tests as the device does not support VLAN" |
| 135 | + fi |
| 136 | +} |
| 137 | + |
| 138 | +check_prerequisites |
| 139 | +trap cleanup_all_ns EXIT |
| 140 | + |
| 141 | +setup_ns node1 node2 |
| 142 | +setup_prp_interfaces |
| 143 | + |
| 144 | +run_ping_tests |
| 145 | +run_vlan_ping_tests |
| 146 | + |
| 147 | +exit $ret |
0 commit comments