brintos

brintos / linux-shallow public Read only

0
0
Text · 4.8 KiB · f5d207f Raw
192 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4ipv6=true5 6source ./hsr_common.sh7 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;do15	case "$option" in16	"h")17		usage $018		exit 019		;;20	"4")21		ipv6=false22		;;23	"?")24		usage $025		exit 126		;;27esac28done29 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.235	do_ping "$ns2" 100.64.0.136	do_ping "$ns3" 100.64.0.137	stop_if_error "Initial validation failed."38 39	do_ping "$ns1" 100.64.0.340	do_ping "$ns2" 100.64.0.341	do_ping "$ns3" 100.64.0.242 43	do_ping "$ns1" dead:beef:1::244	do_ping "$ns1" dead:beef:1::345	do_ping "$ns2" dead:beef:1::146	do_ping "$ns2" dead:beef:1::247	do_ping "$ns3" dead:beef:1::148	do_ping "$ns3" dead:beef:1::249 50	stop_if_error "Initial validation failed."51 52# Wait until supervisor all supervision frames have been processed and the node53# entries have been merged. Otherwise duplicate frames will be observed which is54# valid at this stage.55	WAIT=556	while [ ${WAIT} -gt 0 ]57	do58		grep 00:00:00:00:00:00 /sys/kernel/debug/hsr/hsr*/node_table59		if [ $? -ne 0 ]60		then61			break62		fi63		sleep 164		let "WAIT = WAIT - 1"65	done66 67# Just a safety delay in case the above check didn't handle it.68	sleep 169 70	echo "INFO: Longer ping test."71	do_ping_long "$ns1" 100.64.0.272	do_ping_long "$ns1" dead:beef:1::273	do_ping_long "$ns1" 100.64.0.374	do_ping_long "$ns1" dead:beef:1::375 76	stop_if_error "Longer ping test failed."77 78	do_ping_long "$ns2" 100.64.0.179	do_ping_long "$ns2" dead:beef:1::180	do_ping_long "$ns2" 100.64.0.381	do_ping_long "$ns2" dead:beef:1::282	stop_if_error "Longer ping test failed."83 84	do_ping_long "$ns3" 100.64.0.185	do_ping_long "$ns3" dead:beef:1::186	do_ping_long "$ns3" 100.64.0.287	do_ping_long "$ns3" dead:beef:1::288	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 394	ip -net "$ns3" link set ns3eth1 down95	wait96 97	ip -net "$ns3" link set ns3eth1 up98 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 50ms103	tc -net "$ns2" qdisc add dev ns2eth1 root netem delay 5ms loss 25%104 105	do_ping_long "$ns1" 100.64.0.2106	do_ping_long "$ns1" 100.64.0.3107 108	stop_if_error "Failed with delay and packetloss."109 110	do_ping_long "$ns2" 100.64.0.1111	do_ping_long "$ns2" 100.64.0.3112 113	stop_if_error "Failed with delay and packetloss."114 115	do_ping_long "$ns3" 100.64.0.1116	do_ping_long "$ns3" 100.64.0.2117	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 ----- ns2eth1130#      hsr1         hsr2131#    ns1eth2       ns2eth2132#       |            |133#    ns3eth1      ns3eth2134#           \    /135#            hsr3136#137	# Interfaces138	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/1143	ip -net "$ns1" link add name hsr1 type hsr slave1 ns1eth1 slave2 ns1eth2 supervision 45 version $HSRv proto 0144	ip -net "$ns2" link add name hsr2 type hsr slave1 ns2eth1 slave2 ns2eth2 supervision 45 version $HSRv proto 0145	ip -net "$ns3" link add name hsr3 type hsr slave1 ns3eth1 slave2 ns3eth2 supervision 45 version $HSRv proto 0146 147	# IP for HSR148	ip -net "$ns1" addr add 100.64.0.1/24 dev hsr1149	ip -net "$ns1" addr add dead:beef:1::1/64 dev hsr1 nodad150	ip -net "$ns2" addr add 100.64.0.2/24 dev hsr2151	ip -net "$ns2" addr add dead:beef:1::2/64 dev hsr2 nodad152	ip -net "$ns3" addr add 100.64.0.3/24 dev hsr3153	ip -net "$ns3" addr add dead:beef:1::3/64 dev hsr3 nodad154 155	ip -net "$ns1" link set address 00:11:22:00:01:01 dev ns1eth1156	ip -net "$ns1" link set address 00:11:22:00:01:02 dev ns1eth2157 158	ip -net "$ns2" link set address 00:11:22:00:02:01 dev ns2eth1159	ip -net "$ns2" link set address 00:11:22:00:02:02 dev ns2eth2160 161	ip -net "$ns3" link set address 00:11:22:00:03:01 dev ns3eth1162	ip -net "$ns3" link set address 00:11:22:00:03:02 dev ns3eth2163 164	# All Links up165	ip -net "$ns1" link set ns1eth1 up166	ip -net "$ns1" link set ns1eth2 up167	ip -net "$ns1" link set hsr1 up168 169	ip -net "$ns2" link set ns2eth1 up170	ip -net "$ns2" link set ns2eth2 up171	ip -net "$ns2" link set hsr2 up172 173	ip -net "$ns3" link set ns3eth1 up174	ip -net "$ns3" link set ns3eth2 up175	ip -net "$ns3" link set hsr3 up176}177 178check_prerequisites179setup_ns ns1 ns2 ns3180 181trap cleanup_all_ns EXIT182 183setup_hsr_interfaces 0184do_complete_ping_test185 186setup_ns ns1 ns2 ns3187 188setup_hsr_interfaces 1189do_complete_ping_test190 191exit $ret192