173 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# This test sends traffic from H1 to H2. Either on ingress of $swp1, or on5# egress of $swp2, the traffic is acted upon by an action skbedit priority. The6# new priority should be taken into account when classifying traffic on the PRIO7# qdisc at $swp2. The test verifies that for different priority values, the8# traffic ends up in expected PRIO band.9#10# +----------------------+ +----------------------+11# | H1 | | H2 |12# | + $h1 | | $h2 + |13# | | 192.0.2.1/28 | | 192.0.2.2/28 | |14# +----|-----------------+ +----------------|-----+15# | |16# +----|----------------------------------------------------------------|-----+17# | SW | | |18# | +-|----------------------------------------------------------------|-+ |19# | | + $swp1 BR $swp2 + | |20# | | PRIO | |21# | +--------------------------------------------------------------------+ |22# +---------------------------------------------------------------------------+23 24ALL_TESTS="25 ping_ipv426 test_ingress27 test_egress28"29 30NUM_NETIFS=431source lib.sh32 33: ${HIT_TIMEOUT:=2000} # ms34 35h1_create()36{37 simple_if_init $h1 192.0.2.1/2838}39 40h1_destroy()41{42 simple_if_fini $h1 192.0.2.1/2843}44 45h2_create()46{47 simple_if_init $h2 192.0.2.2/2848}49 50h2_destroy()51{52 simple_if_fini $h2 192.0.2.2/2853}54 55switch_create()56{57 ip link add name br1 type bridge vlan_filtering 158 ip link set dev br1 addrgenmode none59 ip link set dev br1 up60 ip link set dev $swp1 master br161 ip link set dev $swp1 up62 ip link set dev $swp2 master br163 ip link set dev $swp2 up64 65 tc qdisc add dev $swp1 clsact66 tc qdisc add dev $swp2 clsact67 tc qdisc add dev $swp2 root handle 10: \68 prio bands 8 priomap 7 6 5 4 3 2 1 069}70 71switch_destroy()72{73 tc qdisc del dev $swp2 root74 tc qdisc del dev $swp2 clsact75 tc qdisc del dev $swp1 clsact76 77 ip link set dev $swp2 down78 ip link set dev $swp2 nomaster79 ip link set dev $swp1 down80 ip link set dev $swp1 nomaster81 ip link del dev br182}83 84setup_prepare()85{86 h1=${NETIFS[p1]}87 swp1=${NETIFS[p2]}88 89 swp2=${NETIFS[p3]}90 h2=${NETIFS[p4]}91 92 h2mac=$(mac_get $h2)93 94 vrf_prepare95 h1_create96 h2_create97 switch_create98}99 100cleanup()101{102 pre_cleanup103 104 switch_destroy105 h2_destroy106 h1_destroy107 vrf_cleanup108}109 110ping_ipv4()111{112 ping_test $h1 192.0.2.2113}114 115test_skbedit_priority_one()116{117 local locus=$1; shift118 local prio=$1; shift119 local classid=$1; shift120 121 RET=0122 123 tc filter add $locus handle 101 pref 1 \124 flower action skbedit priority $prio125 126 local pkt0=$(qdisc_parent_stats_get $swp2 $classid .packets)127 local pkt2=$(tc_rule_handle_stats_get "$locus" 101)128 $MZ $h1 -t udp "sp=54321,dp=12345" -c 10 -d 20msec -p 100 \129 -a own -b $h2mac -A 192.0.2.1 -B 192.0.2.2 -q130 131 local pkt1132 pkt1=$(busywait "$HIT_TIMEOUT" until_counter_is ">= $((pkt0 + 10))" \133 qdisc_parent_stats_get $swp2 $classid .packets)134 check_err $? "Expected to get 10 packets on class $classid, but got $((pkt1 - pkt0))."135 136 local pkt3=$(tc_rule_handle_stats_get "$locus" 101)137 ((pkt3 >= pkt2 + 10))138 check_err $? "Expected to get 10 packets on skbedit rule but got $((pkt3 - pkt2))."139 140 log_test "$locus skbedit priority $prio -> classid $classid"141 142 tc filter del $locus pref 1143}144 145test_ingress()146{147 local prio148 149 for prio in {0..7}; do150 test_skbedit_priority_one "dev $swp1 ingress" \151 $prio 10:$((8 - prio))152 done153}154 155test_egress()156{157 local prio158 159 for prio in {0..7}; do160 test_skbedit_priority_one "dev $swp2 egress" \161 $prio 10:$((8 - prio))162 done163}164 165trap cleanup EXIT166 167setup_prepare168setup_wait169 170tests_run171 172exit $EXIT_STATUS173