1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Test for DSCP prioritization and rewrite. Packets ingress $swp1 with a DSCP
# tag and are prioritized according to the map at $swp1. They egress $swp2 and
# the DSCP value is updated to match the map at that interface. The updated DSCP
# tag is verified at $h2.
#
# ICMP responses are produced with the same DSCP tag that arrived at $h2. They
# go through prioritization at $swp2 and DSCP retagging at $swp1. The tag is
# verified at $h1--it should match the original tag.
#
# +----------------------+ +----------------------+
# | H1 | | H2 |
# | + $h1 | | $h2 + |
# | | 192.0.2.1/28 | | 192.0.2.2/28 | |
# +----|-----------------+ +----------------|-----+
# | |
# +----|----------------------------------------------------------------|-----+
# | SW | | |
# | +-|----------------------------------------------------------------|-+ |
# | | + $swp1 BR $swp2 + | |
# | | APP=0,5,10 .. 7,5,17 APP=0,5,20 .. 7,5,27 | |
# | +--------------------------------------------------------------------+ |
# +---------------------------------------------------------------------------+
ALL_TESTS="
ping_ipv4
test_dscp
"
lib_dir=$(dirname $0)/../../../net/forwarding
NUM_NETIFS=4
source $lib_dir/lib.sh
__dscp_capture_add_del()
{
local add_del=$1; shift
local dev=$1; shift
local base=$1; shift
local dscp;
for prio in {0..7}; do
dscp=$((base + prio))
__icmp_capture_add_del $add_del $dscp "" $dev \
"ip_tos $((dscp << 2))"
done
}
dscp_capture_install()
{
local dev=$1; shift
local base=$1; shift
__dscp_capture_add_del add $dev $base
}
dscp_capture_uninstall()
{
local dev=$1; shift
local base=$1; shift
__dscp_capture_add_del del $dev $base
}
h1_create()
{
local dscp;
simple_if_init $h1 192.0.2.1/28
tc qdisc add dev $h1 clsact
dscp_capture_install $h1 10
}
h1_destroy()
{
dscp_capture_uninstall $h1 10
tc qdisc del dev $h1 clsact
simple_if_fini $h1 192.0.2.1/28
}
h2_create()
{
simple_if_init $h2 192.0.2.2/28
tc qdisc add dev $h2 clsact
dscp_capture_install $h2 20
}
h2_destroy()
{
dscp_capture_uninstall $h2 20
tc qdisc del dev $h2 clsact
simple_if_fini $h2 192.0.2.2/28
}
dscp_map()
{
local base=$1; shift
for prio in {0..7}; do
echo app=$prio,5,$((base + prio))
done
}
lldpad_wait()
{
local dev=$1; shift
while lldptool -t -i $dev -V APP -c app | grep -q pending; do
echo "$dev: waiting for lldpad to push pending APP updates"
sleep 5
done
}
switch_create()
{
ip link add name br1 type bridge vlan_filtering 1
ip link set dev br1 up
ip link set dev $swp1 master br1
ip link set dev $swp1 up
ip link set dev $swp2 master br1
ip link set dev $swp2 up
lldptool -T -i $swp1 -V APP $(dscp_map 10) >/dev/null
lldptool -T -i $swp2 -V APP $(dscp_map 20) >/dev/null
lldpad_wait $swp1
lldpad_wait $swp2
}
switch_destroy()
{
lldptool -T -i $swp2 -V APP -d $(dscp_map 20) >/dev/null
lldptool -T -i $swp1 -V APP -d $(dscp_map 10) >/dev/null
# Give lldpad a chance to push down the changes. If the device is downed
# too soon, the updates will be left pending, but will have been struck
# off the lldpad's DB already, and we won't be able to tell. Then on
# next test iteration this would cause weirdness as newly-added APP
# rules conflict with the old ones, sometimes getting stuck in an
# "unknown" state.
sleep 5
ip link set dev $swp2 nomaster
ip link set dev $swp1 nomaster
ip link del dev br1
}
setup_prepare()
{
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}
vrf_prepare
h1_create
h2_create
switch_create
}
cleanup()
{
pre_cleanup
switch_destroy
h2_destroy
h1_destroy
vrf_cleanup
}
dscp_fetch_stats()
{
local dev=$1; shift
local base=$1; shift
for prio in {0..7}; do
local dscp=$((base + prio))
local t=$(tc_rule_stats_get $dev $dscp)
echo "[$dscp]=$t "
done
}
ping_ipv4()
{
ping_test $h1 192.0.2.2
}
dscp_ping_test()
{
local vrf_name=$1; shift
local sip=$1; shift
local dip=$1; shift
local prio=$1; shift
local dev_10=$1; shift
local dev_20=$1; shift
local dscp_10=$(((prio + 10) << 2))
local dscp_20=$(((prio + 20) << 2))
RET=0
local -A t0s
eval "t0s=($(dscp_fetch_stats $dev_10 10)
$(dscp_fetch_stats $dev_20 20))"
ip vrf exec $vrf_name \
${PING} -Q $dscp_10 ${sip:+-I $sip} $dip \
-c 10 -i 0.1 -w 2 &> /dev/null
local -A t1s
eval "t1s=($(dscp_fetch_stats $dev_10 10)
$(dscp_fetch_stats $dev_20 20))"
for key in ${!t0s[@]}; do
local expect
if ((key == prio+10 || key == prio+20)); then
expect=10
else
expect=0
fi
local delta=$((t1s[$key] - t0s[$key]))
((expect == delta))
check_err $? "DSCP $key: Expected to capture $expect packets, got $delta."
done
log_test "DSCP rewrite: $dscp_10-(prio $prio)-$dscp_20"
}
test_dscp()
{
for prio in {0..7}; do
dscp_ping_test v$h1 192.0.2.1 192.0.2.2 $prio $h1 $h2
done
}
trap cleanup EXIT
setup_prepare
setup_wait
tests_run
exit $EXIT_STATUS
|