1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Verify that FQ has a packet limit per band:
5#
6# 1. set the limit to 10 per band
7# 2. send 20 pkts on band A: verify that 10 are queued, 10 dropped
8# 3. send 20 pkts on band A: verify that  0 are queued, 20 dropped
9# 4. send 20 pkts on band B: verify that 10 are queued, 10 dropped
10#
11# Send packets with a 100ms delay to ensure that previously sent
12# packets are still queued when later ones are sent.
13# Use SO_TXTIME for this.
14
15die() {
16	echo "$1"
17	exit 1
18}
19
20# run inside private netns
21if [[ $# -eq 0 ]]; then
22	./in_netns.sh "$0" __subprocess
23	exit
24fi
25
26ip link add type dummy
27ip link set dev dummy0 up
28ip -6 addr add fdaa::1/128 dev dummy0
29ip -6 route add fdaa::/64 dev dummy0
30tc qdisc replace dev dummy0 root handle 1: fq quantum 1514 initial_quantum 1514 limit 10
31
32./cmsg_sender -6 -p u -d 100000 -n 20 fdaa::2 8000
33OUT1="$(tc -s qdisc show dev dummy0 | grep '^\ Sent')"
34
35./cmsg_sender -6 -p u -d 100000 -n 20 fdaa::2 8000
36OUT2="$(tc -s qdisc show dev dummy0 | grep '^\ Sent')"
37
38./cmsg_sender -6 -p u -d 100000 -n 20 -P 7 fdaa::2 8000
39OUT3="$(tc -s qdisc show dev dummy0 | grep '^\ Sent')"
40
41# Initial stats will report zero sent, as all packets are still
42# queued in FQ. Sleep for the delay period (100ms) and see that
43# twenty are now sent.
44sleep 0.1
45OUT4="$(tc -s qdisc show dev dummy0 | grep '^\ Sent')"
46
47# Log the output after the test
48echo "${OUT1}"
49echo "${OUT2}"
50echo "${OUT3}"
51echo "${OUT4}"
52
53# Test the output for expected values
54echo "${OUT1}" | grep -q '0\ pkt\ (dropped\ 10'  || die "unexpected drop count at 1"
55echo "${OUT2}" | grep -q '0\ pkt\ (dropped\ 30'  || die "unexpected drop count at 2"
56echo "${OUT3}" | grep -q '0\ pkt\ (dropped\ 40'  || die "unexpected drop count at 3"
57echo "${OUT4}" | grep -q '20\ pkt\ (dropped\ 40' || die "unexpected accept count at 4"
58