brintos

brintos / linux-shallow public Read only

0
0
Text · 1.7 KiB · 25baca4 Raw
85 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03#4# Send packets with transmit timestamps over loopback with netem5# Verify that timestamps correspond to netem delay6 7set -e8 9setup() {10	# set 1ms delay on lo egress11	tc qdisc add dev lo root netem delay 10ms12 13	# set 2ms delay on ifb0 egress14	modprobe ifb15	ip link add ifb_netem0 type ifb16	ip link set dev ifb_netem0 up17	tc qdisc add dev ifb_netem0 root netem delay 20ms18 19	# redirect lo ingress through ifb0 egress20	tc qdisc add dev lo handle ffff: ingress21	tc filter add dev lo parent ffff: \22		u32 match mark 0 0xffff \23		action mirred egress redirect dev ifb_netem024}25 26run_test_v4v6() {27	# SND will be delayed 10ms28	# ACK will be delayed 60ms: 10 + 20 ms round-trip29	# allow +/- tolerance of 8ms30	# wait for ACK to be queued31	local -r args="$@ -v 10000 -V 60000 -t 8000 -S 80000"32 33	./txtimestamp ${args} -4 -L 127.0.0.134	./txtimestamp ${args} -6 -L ::135}36 37run_test_tcpudpraw() {38	local -r args=$@39 40	run_test_v4v6 ${args}		# tcp41	run_test_v4v6 ${args} -u	# udp42	run_test_v4v6 ${args} -r	# raw43	run_test_v4v6 ${args} -R	# raw (IPPROTO_RAW)44	run_test_v4v6 ${args} -P	# pf_packet45}46 47run_test_all() {48	setup49	run_test_tcpudpraw		# setsockopt50	run_test_tcpudpraw -C		# cmsg51	run_test_tcpudpraw -n		# timestamp w/o data52	echo "OK. All tests passed"53}54 55run_test_one() {56	setup57	./txtimestamp $@58}59 60usage() {61	echo "Usage: $0 [ -r | --run ] <txtimestamp args> | [ -h | --help ]"62	echo "  (no args)  Run all tests"63	echo "  -r|--run  Run an individual test with arguments"64	echo "  -h|--help Help"65}66 67main() {68	if [[ $# -eq 0 ]]; then69		run_test_all70	else71		if [[ "$1" = "-r" || "$1" == "--run" ]]; then72			shift73			run_test_one $@74		else75			usage76		fi77	fi78}79 80if [[ -z "$(ip netns identify)" ]]; then81	./in_netns.sh $0 $@82else83	main $@84fi85