]>
Commit | Line | Data |
---|---|---|
26d9f0cd PM |
1 | #!/bin/bash |
2 | # SPDX-License-Identifier: GPL-2.0 | |
3 | ||
4 | # This test sends traffic from H1 to H2. Either on ingress of $swp1, or on | |
5 | # egress of $swp2, the traffic is acted upon by an action skbedit priority. The | |
6 | # new priority should be taken into account when classifying traffic on the PRIO | |
7 | # qdisc at $swp2. The test verifies that for different priority values, the | |
8 | # 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 | ||
24 | ALL_TESTS=" | |
25 | ping_ipv4 | |
26 | test_ingress | |
27 | test_egress | |
28 | " | |
29 | ||
30 | NUM_NETIFS=4 | |
31 | source lib.sh | |
32 | ||
33 | : ${HIT_TIMEOUT:=2000} # ms | |
34 | ||
35 | h1_create() | |
36 | { | |
37 | simple_if_init $h1 192.0.2.1/28 | |
38 | } | |
39 | ||
40 | h1_destroy() | |
41 | { | |
42 | simple_if_fini $h1 192.0.2.1/28 | |
43 | } | |
44 | ||
45 | h2_create() | |
46 | { | |
47 | simple_if_init $h2 192.0.2.2/28 | |
48 | } | |
49 | ||
50 | h2_destroy() | |
51 | { | |
52 | simple_if_fini $h2 192.0.2.2/28 | |
53 | } | |
54 | ||
55 | switch_create() | |
56 | { | |
57 | ip link add name br1 up type bridge vlan_filtering 1 | |
58 | ip link set dev $swp1 master br1 | |
59 | ip link set dev $swp1 up | |
60 | ip link set dev $swp2 master br1 | |
61 | ip link set dev $swp2 up | |
62 | ||
63 | tc qdisc add dev $swp1 clsact | |
64 | tc qdisc add dev $swp2 clsact | |
65 | tc qdisc add dev $swp2 root handle 10: \ | |
66 | prio bands 8 priomap 7 6 5 4 3 2 1 0 | |
67 | } | |
68 | ||
69 | switch_destroy() | |
70 | { | |
71 | tc qdisc del dev $swp2 root | |
72 | tc qdisc del dev $swp2 clsact | |
73 | tc qdisc del dev $swp1 clsact | |
74 | ||
75 | ip link set dev $swp2 nomaster | |
76 | ip link set dev $swp1 nomaster | |
77 | ip link del dev br1 | |
78 | } | |
79 | ||
80 | setup_prepare() | |
81 | { | |
82 | h1=${NETIFS[p1]} | |
83 | swp1=${NETIFS[p2]} | |
84 | ||
85 | swp2=${NETIFS[p3]} | |
86 | h2=${NETIFS[p4]} | |
87 | ||
88 | h2mac=$(mac_get $h2) | |
89 | ||
90 | vrf_prepare | |
91 | h1_create | |
92 | h2_create | |
93 | switch_create | |
94 | } | |
95 | ||
96 | cleanup() | |
97 | { | |
98 | pre_cleanup | |
99 | ||
100 | switch_destroy | |
101 | h2_destroy | |
102 | h1_destroy | |
103 | vrf_cleanup | |
104 | } | |
105 | ||
106 | ping_ipv4() | |
107 | { | |
108 | ping_test $h1 192.0.2.2 | |
109 | } | |
110 | ||
111 | test_skbedit_priority_one() | |
112 | { | |
113 | local locus=$1; shift | |
114 | local prio=$1; shift | |
115 | local classid=$1; shift | |
116 | ||
117 | RET=0 | |
118 | ||
119 | tc filter add $locus handle 101 pref 1 \ | |
120 | flower action skbedit priority $prio | |
121 | ||
122 | local pkt0=$(qdisc_parent_stats_get $swp2 $classid .packets) | |
2a0b1307 | 123 | local pkt2=$(tc_rule_handle_stats_get "$locus" 101) |
26d9f0cd PM |
124 | $MZ $h1 -t udp "sp=54321,dp=12345" -c 10 -d 20msec -p 100 \ |
125 | -a own -b $h2mac -A 192.0.2.1 -B 192.0.2.2 -q | |
2a0b1307 | 126 | |
26d9f0cd PM |
127 | local pkt1 |
128 | pkt1=$(busywait "$HIT_TIMEOUT" until_counter_is ">= $((pkt0 + 10))" \ | |
129 | qdisc_parent_stats_get $swp2 $classid .packets) | |
2a0b1307 PM |
130 | check_err $? "Expected to get 10 packets on class $classid, but got $((pkt1 - pkt0))." |
131 | ||
132 | local pkt3=$(tc_rule_handle_stats_get "$locus" 101) | |
133 | ((pkt3 >= pkt2 + 10)) | |
134 | check_err $? "Expected to get 10 packets on skbedit rule but got $((pkt3 - pkt2))." | |
26d9f0cd | 135 | |
26d9f0cd PM |
136 | log_test "$locus skbedit priority $prio -> classid $classid" |
137 | ||
138 | tc filter del $locus pref 1 | |
139 | } | |
140 | ||
141 | test_ingress() | |
142 | { | |
143 | local prio | |
144 | ||
145 | for prio in {0..7}; do | |
146 | test_skbedit_priority_one "dev $swp1 ingress" \ | |
147 | $prio 10:$((8 - prio)) | |
148 | done | |
149 | } | |
150 | ||
151 | test_egress() | |
152 | { | |
153 | local prio | |
154 | ||
155 | for prio in {0..7}; do | |
156 | test_skbedit_priority_one "dev $swp2 egress" \ | |
157 | $prio 10:$((8 - prio)) | |
158 | done | |
159 | } | |
160 | ||
161 | trap cleanup EXIT | |
162 | ||
163 | setup_prepare | |
164 | setup_wait | |
165 | ||
166 | tests_run | |
167 | ||
168 | exit $EXIT_STATUS |