Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,14 @@
# SPDX-License-Identifier: GPL-2.0
top_srcdir = ../../../../..
TEST_PROGS := \
hsr_ping.sh \
hsr_redbox.sh \
link_faults.sh \
prp_ping.sh \
# end of TEST_PROGS
TEST_FILES += hsr_common.sh
include ../../lib.mk
@@ -0,0 +1,6 @@
CONFIG_BRIDGE=y
CONFIG_HSR=y
CONFIG_IPV6=y
CONFIG_NET_SCH_NETEM=m
CONFIG_VETH=y
CONFIG_VLAN_8021Q=m
@@ -0,0 +1,84 @@
# SPDX-License-Identifier: GPL-2.0
# Common code for HSR testing scripts
source ../lib.sh
ret=0
ksft_skip=4
# $1: IP address
is_v6()
{
[ -z "${1##*:*}" ]
}
do_ping()
{
local netns="$1"
local connect_addr="$2"
local ping_args="-q -c 2 -i 0.1"
if is_v6 "${connect_addr}"; then
$ipv6 || return 0
ping_args="${ping_args} -6"
fi
ip netns exec ${netns} ping ${ping_args} $connect_addr >/dev/null
if [ $? -ne 0 ] ; then
echo "$netns -> $connect_addr connectivity [ FAIL ]" 1>&2
ret=1
return 1
fi
return 0
}
do_ping_long()
{
local netns="$1"
local connect_addr="$2"
local ping_args="-q -c 10 -i 0.1"
if is_v6 "${connect_addr}"; then
$ipv6 || return 0
ping_args="${ping_args} -6"
fi
OUT="$(LANG=C ip netns exec ${netns} ping ${ping_args} $connect_addr | grep received)"
if [ $? -ne 0 ] ; then
echo "$netns -> $connect_addr ping [ FAIL ]" 1>&2
ret=1
return 1
fi
VAL="$(echo $OUT | cut -d' ' -f1-8)"
SED_VAL="$(echo ${VAL} | sed -r -e 's/([0-9]{2}).*([0-9]{2}).*[[:space:]]([0-9]+%).*/\1 transmitted \2 received \3 loss/')"
if [ "${SED_VAL}" != "10 transmitted 10 received 0% loss" ]
then
echo "$netns -> $connect_addr ping TEST [ FAIL ]"
echo "Expect to send and receive 10 packets and no duplicates."
echo "Full message: ${OUT}."
ret=1
return 1
fi
return 0
}
stop_if_error()
{
local msg="$1"
if [ ${ret} -ne 0 ]; then
echo "FAIL: ${msg}" 1>&2
exit ${ret}
fi
}
check_prerequisites()
{
ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
exit $ksft_skip
fi
}
+206
View File
@@ -0,0 +1,206 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ipv6=true
source ./hsr_common.sh
optstring="h4"
usage() {
echo "Usage: $0 [OPTION]"
echo -e "\t-4: IPv4 only: disable IPv6 tests (default: test both IPv4 and IPv6)"
}
while getopts "$optstring" option;do
case "$option" in
"h")
usage $0
exit 0
;;
"4")
ipv6=false
;;
"?")
usage $0
exit 1
;;
esac
done
do_ping_tests()
{
local netid="$1"
echo "INFO: Running ping tests."
echo "INFO: Initial validation ping."
# Each node has to be able to reach each one.
do_ping "$ns1" "100.64.$netid.2"
do_ping "$ns1" "100.64.$netid.3"
do_ping "$ns2" "100.64.$netid.1"
do_ping "$ns2" "100.64.$netid.3"
do_ping "$ns3" "100.64.$netid.1"
do_ping "$ns3" "100.64.$netid.2"
stop_if_error "Initial validation failed on IPv4."
do_ping "$ns1" "dead:beef:$netid::2"
do_ping "$ns1" "dead:beef:$netid::3"
do_ping "$ns2" "dead:beef:$netid::1"
do_ping "$ns2" "dead:beef:$netid::2"
do_ping "$ns3" "dead:beef:$netid::1"
do_ping "$ns3" "dead:beef:$netid::2"
stop_if_error "Initial validation failed on IPv6."
# Wait until supervisor all supervision frames have been processed and the node
# entries have been merged. Otherwise duplicate frames will be observed which is
# valid at this stage.
echo "INFO: Wait for node table entries to be merged."
WAIT=5
while [ ${WAIT} -gt 0 ]
do
grep 00:00:00:00:00:00 /sys/kernel/debug/hsr/hsr*/node_table
if [ $? -ne 0 ]
then
break
fi
sleep 1
let "WAIT = WAIT - 1"
done
# Just a safety delay in case the above check didn't handle it.
sleep 1
echo "INFO: Longer ping test."
do_ping_long "$ns1" "100.64.$netid.2"
do_ping_long "$ns1" "dead:beef:$netid::2"
do_ping_long "$ns1" "100.64.$netid.3"
do_ping_long "$ns1" "dead:beef:$netid::3"
stop_if_error "Longer ping test failed (ns1)."
do_ping_long "$ns2" "100.64.$netid.1"
do_ping_long "$ns2" "dead:beef:$netid::1"
do_ping_long "$ns2" "100.64.$netid.3"
do_ping_long "$ns2" "dead:beef:$netid::3"
stop_if_error "Longer ping test failed (ns2)."
do_ping_long "$ns3" "100.64.$netid.1"
do_ping_long "$ns3" "dead:beef:$netid::1"
do_ping_long "$ns3" "100.64.$netid.2"
do_ping_long "$ns3" "dead:beef:$netid::2"
stop_if_error "Longer ping test failed (ns3)."
}
setup_hsr_interfaces()
{
local HSRv="$1"
echo "INFO: Preparing interfaces for HSRv${HSRv}."
# Three HSR nodes. Each node has one link to each of its neighbour, two links in total.
#
# ns1eth1 ----- ns2eth1
# hsr1 hsr2
# ns1eth2 ns2eth2
# | |
# ns3eth1 ns3eth2
# \ /
# hsr3
#
# Interfaces
ip link add ns1eth1 netns "$ns1" type veth peer name ns2eth1 netns "$ns2"
ip link add ns1eth2 netns "$ns1" type veth peer name ns3eth1 netns "$ns3"
ip link add ns3eth2 netns "$ns3" type veth peer name ns2eth2 netns "$ns2"
# HSRv0/1
ip -net "$ns1" link add name hsr1 type hsr slave1 ns1eth1 \
slave2 ns1eth2 supervision 45 version "$HSRv" proto 0
ip -net "$ns2" link add name hsr2 type hsr slave1 ns2eth1 \
slave2 ns2eth2 supervision 45 version "$HSRv" proto 0
ip -net "$ns3" link add name hsr3 type hsr slave1 ns3eth1 \
slave2 ns3eth2 supervision 45 version "$HSRv" proto 0
# IP for HSR
ip -net "$ns1" addr add 100.64.0.1/24 dev hsr1
ip -net "$ns1" addr add dead:beef:0::1/64 dev hsr1 nodad
ip -net "$ns2" addr add 100.64.0.2/24 dev hsr2
ip -net "$ns2" addr add dead:beef:0::2/64 dev hsr2 nodad
ip -net "$ns3" addr add 100.64.0.3/24 dev hsr3
ip -net "$ns3" addr add dead:beef:0::3/64 dev hsr3 nodad
ip -net "$ns1" link set address 00:11:22:00:01:01 dev ns1eth1
ip -net "$ns1" link set address 00:11:22:00:01:02 dev ns1eth2
ip -net "$ns2" link set address 00:11:22:00:02:01 dev ns2eth1
ip -net "$ns2" link set address 00:11:22:00:02:02 dev ns2eth2
ip -net "$ns3" link set address 00:11:22:00:03:01 dev ns3eth1
ip -net "$ns3" link set address 00:11:22:00:03:02 dev ns3eth2
# All Links up
ip -net "$ns1" link set ns1eth1 up
ip -net "$ns1" link set ns1eth2 up
ip -net "$ns1" link set hsr1 up
ip -net "$ns2" link set ns2eth1 up
ip -net "$ns2" link set ns2eth2 up
ip -net "$ns2" link set hsr2 up
ip -net "$ns3" link set ns3eth1 up
ip -net "$ns3" link set ns3eth2 up
ip -net "$ns3" link set hsr3 up
}
setup_vlan_interfaces() {
ip -net "$ns1" link add link hsr1 name hsr1.2 type vlan id 2
ip -net "$ns2" link add link hsr2 name hsr2.2 type vlan id 2
ip -net "$ns3" link add link hsr3 name hsr3.2 type vlan id 2
ip -net "$ns1" addr add 100.64.2.1/24 dev hsr1.2
ip -net "$ns1" addr add dead:beef:2::1/64 dev hsr1.2 nodad
ip -net "$ns2" addr add 100.64.2.2/24 dev hsr2.2
ip -net "$ns2" addr add dead:beef:2::2/64 dev hsr2.2 nodad
ip -net "$ns3" addr add 100.64.2.3/24 dev hsr3.2
ip -net "$ns3" addr add dead:beef:2::3/64 dev hsr3.2 nodad
ip -net "$ns1" link set dev hsr1.2 up
ip -net "$ns2" link set dev hsr2.2 up
ip -net "$ns3" link set dev hsr3.2 up
}
run_ping_tests()
{
echo "INFO: Running ping tests."
do_ping_tests 0
}
run_vlan_tests()
{
vlan_challenged_hsr1=$(ip net exec "$ns1" ethtool -k hsr1 | grep "vlan-challenged" | awk '{print $2}')
vlan_challenged_hsr2=$(ip net exec "$ns2" ethtool -k hsr2 | grep "vlan-challenged" | awk '{print $2}')
vlan_challenged_hsr3=$(ip net exec "$ns3" ethtool -k hsr3 | grep "vlan-challenged" | awk '{print $2}')
if [[ "$vlan_challenged_hsr1" = "off" || "$vlan_challenged_hsr2" = "off" || "$vlan_challenged_hsr3" = "off" ]]; then
echo "INFO: Running VLAN ping tests"
setup_vlan_interfaces
do_ping_tests 2
else
echo "INFO: Not Running VLAN tests as the device does not support VLAN"
fi
}
check_prerequisites
trap cleanup_all_ns EXIT
setup_ns ns1 ns2 ns3
setup_hsr_interfaces 0
run_ping_tests
run_vlan_tests
setup_ns ns1 ns2 ns3
setup_hsr_interfaces 1
run_ping_tests
run_vlan_tests
exit $ret
+136
View File
@@ -0,0 +1,136 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ipv6=false
source ./hsr_common.sh
do_complete_ping_test()
{
echo "INFO: Initial validation ping (HSR-SAN/RedBox)."
# Each node has to be able to reach each one.
do_ping "${ns1}" 100.64.0.2
do_ping "${ns2}" 100.64.0.1
# Ping between SANs (test bridge)
do_ping "${ns4}" 100.64.0.51
do_ping "${ns5}" 100.64.0.41
# Ping from SANs to hsr1 (via hsr2) (and opposite)
do_ping "${ns3}" 100.64.0.1
do_ping "${ns1}" 100.64.0.3
do_ping "${ns1}" 100.64.0.41
do_ping "${ns4}" 100.64.0.1
do_ping "${ns1}" 100.64.0.51
do_ping "${ns5}" 100.64.0.1
stop_if_error "Initial validation failed."
# Wait for MGNT HSR frames being received and nodes being
# merged.
sleep 5
echo "INFO: Longer ping test (HSR-SAN/RedBox)."
# Ping from SAN to hsr1 (via hsr2)
do_ping_long "${ns3}" 100.64.0.1
# Ping from hsr1 (via hsr2) to SANs (and opposite)
do_ping_long "${ns1}" 100.64.0.3
do_ping_long "${ns1}" 100.64.0.41
do_ping_long "${ns4}" 100.64.0.1
do_ping_long "${ns1}" 100.64.0.51
do_ping_long "${ns5}" 100.64.0.1
stop_if_error "Longer ping test failed."
echo "INFO: All good."
}
setup_hsr_interfaces()
{
local HSRv="$1"
echo "INFO: preparing interfaces for HSRv${HSRv} (HSR-SAN/RedBox)."
#
# IPv4 addresses (100.64.X.Y/24), and [X.Y] is presented on below diagram:
#
#
# |NS1 | |NS4 |
# | [0.1] | | |
# | /-- hsr1 --\ | | [0.41] |
# | ns1eth1 ns1eth2 | | ns4eth1 (SAN) |
# |------------------------| |-------------------|
# | | |
# | | |
# | | |
# |------------------------| |-------------------------------|
# | ns2eth1 ns2eth2 | | ns3eth2 |
# | \-- hsr2 --/ | | / |
# | [0.2] \ | | / | |------------|
# | ns2eth3 |---| ns3eth1 -- ns3br1 -- ns3eth3--|--| ns5eth1 |
# | (interlink)| | [0.3] [0.11] | | [0.51] |
# |NS2 (RedBOX) | |NS3 (BR) | | NS5 (SAN) |
#
#
# Check if iproute2 supports adding interlink port to hsrX device
ip link help hsr | grep -q INTERLINK
[ $? -ne 0 ] && { echo "iproute2: HSR interlink interface not supported!"; exit 0; }
# Create interfaces for name spaces
ip link add ns1eth1 netns "${ns1}" type veth peer name ns2eth1 netns "${ns2}"
ip link add ns1eth2 netns "${ns1}" type veth peer name ns2eth2 netns "${ns2}"
ip link add ns2eth3 netns "${ns2}" type veth peer name ns3eth1 netns "${ns3}"
ip link add ns3eth2 netns "${ns3}" type veth peer name ns4eth1 netns "${ns4}"
ip link add ns3eth3 netns "${ns3}" type veth peer name ns5eth1 netns "${ns5}"
sleep 1
ip -n "${ns1}" link set ns1eth1 up
ip -n "${ns1}" link set ns1eth2 up
ip -n "${ns2}" link set ns2eth1 up
ip -n "${ns2}" link set ns2eth2 up
ip -n "${ns2}" link set ns2eth3 up
ip -n "${ns3}" link add name ns3br1 type bridge
ip -n "${ns3}" link set ns3br1 up
ip -n "${ns3}" link set ns3eth1 master ns3br1 up
ip -n "${ns3}" link set ns3eth2 master ns3br1 up
ip -n "${ns3}" link set ns3eth3 master ns3br1 up
ip -n "${ns4}" link set ns4eth1 up
ip -n "${ns5}" link set ns5eth1 up
ip -net "$ns1" link set address 00:11:22:00:01:01 dev ns1eth1
ip -net "$ns1" link set address 00:11:22:00:01:02 dev ns1eth2
ip -net "$ns2" link set address 00:11:22:00:02:01 dev ns2eth1
ip -net "$ns2" link set address 00:11:22:00:02:02 dev ns2eth2
ip -net "$ns2" link set address 00:11:22:00:02:03 dev ns2eth3
ip -net "$ns3" link set address 00:11:22:00:03:11 dev ns3eth1
ip -net "$ns3" link set address 00:11:22:00:03:11 dev ns3eth2
ip -net "$ns3" link set address 00:11:22:00:03:11 dev ns3eth3
ip -net "$ns3" link set address 00:11:22:00:03:11 dev ns3br1
ip -net "$ns4" link set address 00:11:22:00:04:01 dev ns4eth1
ip -net "$ns5" link set address 00:11:22:00:05:01 dev ns5eth1
ip -net "${ns1}" link add name hsr1 type hsr slave1 ns1eth1 slave2 ns1eth2 supervision 45 version ${HSRv} proto 0
ip -net "${ns2}" link add name hsr2 type hsr slave1 ns2eth1 slave2 ns2eth2 interlink ns2eth3 supervision 45 version ${HSRv} proto 0
ip -n "${ns1}" addr add 100.64.0.1/24 dev hsr1
ip -n "${ns2}" addr add 100.64.0.2/24 dev hsr2
ip -n "${ns3}" addr add 100.64.0.11/24 dev ns3br1
ip -n "${ns3}" addr add 100.64.0.3/24 dev ns3eth1
ip -n "${ns4}" addr add 100.64.0.41/24 dev ns4eth1
ip -n "${ns5}" addr add 100.64.0.51/24 dev ns5eth1
ip -n "${ns1}" link set hsr1 up
ip -n "${ns2}" link set hsr2 up
}
check_prerequisites
setup_ns ns1 ns2 ns3 ns4 ns5
trap cleanup_all_ns EXIT
setup_hsr_interfaces 1
do_complete_ping_test
exit $ret
+378
View File
@@ -0,0 +1,378 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# shellcheck disable=SC2329
source ../lib.sh
ALL_TESTS="
test_clean_hsrv0
test_cut_link_hsrv0
test_packet_loss_hsrv0
test_high_packet_loss_hsrv0
test_reordering_hsrv0
test_clean_hsrv1
test_cut_link_hsrv1
test_packet_loss_hsrv1
test_high_packet_loss_hsrv1
test_reordering_hsrv1
test_clean_prp
test_cut_link_prp
test_packet_loss_prp
test_high_packet_loss_prp
test_reordering_prp
"
# The tests are running ping for 5sec with a relatively short interval in
# different scenarios with faulty links (cut links, packet loss, delay,
# reordering) that should be recoverable by HSR/PRP. The ping interval (10ms)
# is short enough that the base delay (50ms) leads to a queue in the netem
# qdiscs which is needed for reordering.
setup_hsr_topo()
{
# Three HSR nodes in a ring, every node has a LAN A interface connected
# to the LAN B interface of the next node.
#
# node1 node2
#
# vethA -------- vethB
# hsr1 hsr2
# vethB vethA
# \ /
# vethA vethB
# hsr3
#
# node3
local ver="$1"
setup_ns node1 node2 node3
# veth links
# shellcheck disable=SC2154 # variables assigned by setup_ns
ip link add vethA netns "$node1" type veth peer name vethB netns "$node2"
# shellcheck disable=SC2154 # variables assigned by setup_ns
ip link add vethA netns "$node2" type veth peer name vethB netns "$node3"
ip link add vethA netns "$node3" type veth peer name vethB netns "$node1"
# MAC addresses (not needed for HSR operation, but helps with debugging)
ip -net "$node1" link set address 00:11:22:00:01:01 dev vethA
ip -net "$node1" link set address 00:11:22:00:01:02 dev vethB
ip -net "$node2" link set address 00:11:22:00:02:01 dev vethA
ip -net "$node2" link set address 00:11:22:00:02:02 dev vethB
ip -net "$node3" link set address 00:11:22:00:03:01 dev vethA
ip -net "$node3" link set address 00:11:22:00:03:02 dev vethB
# HSR interfaces
ip -net "$node1" link add name hsr1 type hsr proto 0 version "$ver" \
slave1 vethA slave2 vethB supervision 45
ip -net "$node2" link add name hsr2 type hsr proto 0 version "$ver" \
slave1 vethA slave2 vethB supervision 45
ip -net "$node3" link add name hsr3 type hsr proto 0 version "$ver" \
slave1 vethA slave2 vethB supervision 45
# IP addresses
ip -net "$node1" addr add 100.64.0.1/24 dev hsr1
ip -net "$node2" addr add 100.64.0.2/24 dev hsr2
ip -net "$node3" addr add 100.64.0.3/24 dev hsr3
# Set all links up
ip -net "$node1" link set vethA up
ip -net "$node1" link set vethB up
ip -net "$node1" link set hsr1 up
ip -net "$node2" link set vethA up
ip -net "$node2" link set vethB up
ip -net "$node2" link set hsr2 up
ip -net "$node3" link set vethA up
ip -net "$node3" link set vethB up
ip -net "$node3" link set hsr3 up
}
setup_prp_topo()
{
# Two PRP nodes, connected by two links (treated as LAN A and LAN B).
#
# vethA ----- vethA
# prp1 prp2
# vethB ----- vethB
#
# node1 node2
setup_ns node1 node2
# veth links
ip link add vethA netns "$node1" type veth peer name vethA netns "$node2"
ip link add vethB netns "$node1" type veth peer name vethB netns "$node2"
# MAC addresses will be copied from LAN A interface
ip -net "$node1" link set address 00:11:22:00:00:01 dev vethA
ip -net "$node2" link set address 00:11:22:00:00:02 dev vethA
# PRP interfaces
ip -net "$node1" link add name prp1 type hsr \
slave1 vethA slave2 vethB supervision 45 proto 1
ip -net "$node2" link add name prp2 type hsr \
slave1 vethA slave2 vethB supervision 45 proto 1
# IP addresses
ip -net "$node1" addr add 100.64.0.1/24 dev prp1
ip -net "$node2" addr add 100.64.0.2/24 dev prp2
# All links up
ip -net "$node1" link set vethA up
ip -net "$node1" link set vethB up
ip -net "$node1" link set prp1 up
ip -net "$node2" link set vethA up
ip -net "$node2" link set vethB up
ip -net "$node2" link set prp2 up
}
wait_for_hsr_node_table()
{
log_info "Wait for node table entries to be merged."
WAIT=5
while [ "${WAIT}" -gt 0 ]; do
nts=$(cat /sys/kernel/debug/hsr/hsr*/node_table)
# We need entries in the node tables, and they need to be merged
if (echo "$nts" | grep -qE "^([0-9a-f]{2}:){5}") && \
! (echo "$nts" | grep -q "00:00:00:00:00:00"); then
return
fi
sleep 1
((WAIT--))
done
check_err 1 "Failed to wait for merged node table entries"
}
setup_topo()
{
local proto="$1"
if [ "$proto" = "HSRv0" ]; then
setup_hsr_topo 0
wait_for_hsr_node_table
elif [ "$proto" = "HSRv1" ]; then
setup_hsr_topo 1
wait_for_hsr_node_table
elif [ "$proto" = "PRP" ]; then
setup_prp_topo
else
check_err 1 "Unknown protocol (${proto})"
fi
}
check_ping()
{
local node="$1"
local dst="$2"
local accepted_dups="$3"
local ping_args="-q -i 0.01 -c 400"
log_info "Running ping $node -> $dst"
# shellcheck disable=SC2086
output=$(ip netns exec "$node" ping $ping_args "$dst" | \
grep "packets transmitted")
log_info "$output"
dups=0
loss=0
if [[ "$output" =~ \+([0-9]+)" duplicates" ]]; then
dups="${BASH_REMATCH[1]}"
fi
if [[ "$output" =~ ([0-9\.]+\%)" packet loss" ]]; then
loss="${BASH_REMATCH[1]}"
fi
if [ "$dups" -gt "$accepted_dups" ]; then
check_err 1 "Unexpected duplicate packets (${dups})"
fi
if [ "$loss" != "0%" ]; then
check_err 1 "Unexpected packet loss (${loss})"
fi
}
test_clean()
{
local proto="$1"
RET=0
tname="${FUNCNAME[0]} - ${proto}"
setup_topo "$proto"
if ((RET != ksft_pass)); then
log_test "${tname} setup"
return
fi
check_ping "$node1" "100.64.0.2" 0
log_test "${tname}"
}
test_clean_hsrv0()
{
test_clean "HSRv0"
}
test_clean_hsrv1()
{
test_clean "HSRv1"
}
test_clean_prp()
{
test_clean "PRP"
}
test_cut_link()
{
local proto="$1"
RET=0
tname="${FUNCNAME[0]} - ${proto}"
setup_topo "$proto"
if ((RET != ksft_pass)); then
log_test "${tname} setup"
return
fi
# Cutting link from subshell, so check_ping can run in the normal shell
# with access to global variables from the test harness.
(
sleep 2
log_info "Cutting link"
ip -net "$node1" link set vethB down
) &
check_ping "$node1" "100.64.0.2" 0
wait
log_test "${tname}"
}
test_cut_link_hsrv0()
{
test_cut_link "HSRv0"
}
test_cut_link_hsrv1()
{
test_cut_link "HSRv1"
}
test_cut_link_prp()
{
test_cut_link "PRP"
}
test_packet_loss()
{
local proto="$1"
local loss="$2"
RET=0
tname="${FUNCNAME[0]} - ${proto}, ${loss}"
setup_topo "$proto"
if ((RET != ksft_pass)); then
log_test "${tname} setup"
return
fi
# Packet loss with lower delay makes sure the packets on the lossy link
# arrive first.
tc -net "$node1" qdisc add dev vethA root netem delay 50ms
tc -net "$node1" qdisc add dev vethB root netem delay 20ms loss "$loss"
check_ping "$node1" "100.64.0.2" 40
log_test "${tname}"
}
test_packet_loss_hsrv0()
{
test_packet_loss "HSRv0" "20%"
}
test_packet_loss_hsrv1()
{
test_packet_loss "HSRv1" "20%"
}
test_packet_loss_prp()
{
test_packet_loss "PRP" "20%"
}
test_high_packet_loss_hsrv0()
{
test_packet_loss "HSRv0" "80%"
}
test_high_packet_loss_hsrv1()
{
test_packet_loss "HSRv1" "80%"
}
test_high_packet_loss_prp()
{
test_packet_loss "PRP" "80%"
}
test_reordering()
{
local proto="$1"
RET=0
tname="${FUNCNAME[0]} - ${proto}"
setup_topo "$proto"
if ((RET != ksft_pass)); then
log_test "${tname} setup"
return
fi
tc -net "$node1" qdisc add dev vethA root netem delay 50ms
tc -net "$node1" qdisc add dev vethB root netem delay 50ms reorder 20%
check_ping "$node1" "100.64.0.2" 40
log_test "${tname}"
}
test_reordering_hsrv0()
{
test_reordering "HSRv0"
}
test_reordering_hsrv1()
{
test_reordering "HSRv1"
}
test_reordering_prp()
{
test_reordering "PRP"
}
cleanup()
{
cleanup_all_ns
}
trap cleanup EXIT
tests_run
exit $EXIT_STATUS
+147
View File
@@ -0,0 +1,147 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
ipv6=true
source ./hsr_common.sh
optstring="h4"
usage() {
echo "Usage: $0 [OPTION]"
echo -e "\t-4: IPv4 only: disable IPv6 tests (default: test both IPv4 and IPv6)"
}
while getopts "$optstring" option;do
case "$option" in
"h")
usage "$0"
exit 0
;;
"4")
ipv6=false
;;
"?")
usage "$0"
exit 1
;;
esac
done
setup_prp_interfaces()
{
echo "INFO: Preparing interfaces for PRP"
# Two PRP nodes, connected by two links (treated as LAN A and LAN B).
#
# vethA ----- vethA
# prp1 prp2
# vethB ----- vethB
#
# node1 node2
# Interfaces
# shellcheck disable=SC2154 # variables assigned by setup_ns
ip link add vethA netns "$node1" type veth peer name vethA netns "$node2"
ip link add vethB netns "$node1" type veth peer name vethB netns "$node2"
# MAC addresses will be copied from LAN A interface
ip -net "$node1" link set address 00:11:22:00:00:01 dev vethA
ip -net "$node2" link set address 00:11:22:00:00:02 dev vethA
# PRP
ip -net "$node1" link add name prp1 type hsr \
slave1 vethA slave2 vethB supervision 45 proto 1
ip -net "$node2" link add name prp2 type hsr \
slave1 vethA slave2 vethB supervision 45 proto 1
# IP addresses
ip -net "$node1" addr add 100.64.0.1/24 dev prp1
ip -net "$node1" addr add dead:beef:0::1/64 dev prp1 nodad
ip -net "$node2" addr add 100.64.0.2/24 dev prp2
ip -net "$node2" addr add dead:beef:0::2/64 dev prp2 nodad
# All links up
ip -net "$node1" link set vethA up
ip -net "$node1" link set vethB up
ip -net "$node1" link set prp1 up
ip -net "$node2" link set vethA up
ip -net "$node2" link set vethB up
ip -net "$node2" link set prp2 up
}
setup_vlan_interfaces()
{
# Interfaces
ip -net "$node1" link add link prp1 name prp1.2 type vlan id 2
ip -net "$node2" link add link prp2 name prp2.2 type vlan id 2
# IP addresses
ip -net "$node1" addr add 100.64.2.1/24 dev prp1.2
ip -net "$node1" addr add dead:beef:2::1/64 dev prp1.2 nodad
ip -net "$node2" addr add 100.64.2.2/24 dev prp2.2
ip -net "$node2" addr add dead:beef:2::2/64 dev prp2.2 nodad
# All links up
ip -net "$node1" link set prp1.2 up
ip -net "$node2" link set prp2.2 up
}
do_ping_tests()
{
local netid="$1"
echo "INFO: Initial validation ping"
do_ping "$node1" "100.64.$netid.2"
do_ping "$node2" "100.64.$netid.1"
stop_if_error "Initial validation failed on IPv4"
do_ping "$node1" "dead:beef:$netid::2"
do_ping "$node2" "dead:beef:$netid::1"
stop_if_error "Initial validation failed on IPv6"
echo "INFO: Longer ping test."
do_ping_long "$node1" "100.64.$netid.2"
do_ping_long "$node2" "100.64.$netid.1"
stop_if_error "Longer ping test failed on IPv4."
do_ping_long "$node1" "dead:beef:$netid::2"
do_ping_long "$node2" "dead:beef:$netid::1"
stop_if_error "Longer ping test failed on IPv6."
}
run_ping_tests()
{
echo "INFO: Running ping tests"
do_ping_tests 0
}
run_vlan_ping_tests()
{
vlan_challenged_prp1=$(ip net exec "$node1" ethtool -k prp1 | \
grep "vlan-challenged" | awk '{print $2}')
vlan_challenged_prp2=$(ip net exec "$node2" ethtool -k prp2 | \
grep "vlan-challenged" | awk '{print $2}')
if [[ "$vlan_challenged_prp1" = "off" || \
"$vlan_challenged_prp2" = "off" ]]; then
echo "INFO: Running VLAN ping tests"
setup_vlan_interfaces
do_ping_tests 2
else
echo "INFO: Not Running VLAN tests as the device does not support VLAN"
fi
}
check_prerequisites
trap cleanup_all_ns EXIT
setup_ns node1 node2
setup_prp_interfaces
run_ping_tests
run_vlan_ping_tests
exit $ret
@@ -0,0 +1 @@
timeout=180