drm/atomic-helper: document drm_atomic_helper_check() restrictions
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / tc_flower_cfm.sh
blob3ca20df952ebf0e20c300f551c5df9f3a77b6dae
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS="match_cfm_opcode match_cfm_level match_cfm_level_and_opcode"
5 NUM_NETIFS=2
6 source tc_common.sh
7 source lib.sh
9 h1_create()
11 simple_if_init $h1
14 h1_destroy()
16 simple_if_fini $h1
19 h2_create()
21 simple_if_init $h2
22 tc qdisc add dev $h2 clsact
25 h2_destroy()
27 tc qdisc del dev $h2 clsact
28 simple_if_fini $h2
31 u8_to_hex()
33 local u8=$1; shift
35 printf "%02x" $u8
38 generate_cfm_hdr()
40 local mdl=$1; shift
41 local op=$1; shift
42 local flags=$1; shift
43 local tlv_offset=$1; shift
45 local cfm_hdr=$(:
46 )"$(u8_to_hex $((mdl << 5))):"$( : MD level and Version
47 )"$(u8_to_hex $op):"$( : OpCode
48 )"$(u8_to_hex $flags):"$( : Flags
49 )"$(u8_to_hex $tlv_offset)"$( : TLV offset
52 echo $cfm_hdr
55 match_cfm_opcode()
57 local ethtype="89 02"; readonly ethtype
58 RET=0
60 tc filter add dev $h2 ingress protocol cfm pref 1 handle 101 \
61 flower cfm op 47 action drop
62 tc filter add dev $h2 ingress protocol cfm pref 1 handle 102 \
63 flower cfm op 43 action drop
65 pkt="$ethtype $(generate_cfm_hdr 7 47 0 32)"
66 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
67 pkt="$ethtype $(generate_cfm_hdr 6 5 0 4)"
68 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
70 tc_check_packets "dev $h2 ingress" 101 1
71 check_err $? "Did not match on correct opcode"
73 tc_check_packets "dev $h2 ingress" 102 0
74 check_err $? "Matched on the wrong opcode"
76 pkt="$ethtype $(generate_cfm_hdr 0 43 0 12)"
77 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
79 tc_check_packets "dev $h2 ingress" 101 1
80 check_err $? "Matched on the wrong opcode"
82 tc_check_packets "dev $h2 ingress" 102 1
83 check_err $? "Did not match on correct opcode"
85 tc filter del dev $h2 ingress protocol cfm pref 1 handle 101 flower
86 tc filter del dev $h2 ingress protocol cfm pref 1 handle 102 flower
88 log_test "CFM opcode match test"
91 match_cfm_level()
93 local ethtype="89 02"; readonly ethtype
94 RET=0
96 tc filter add dev $h2 ingress protocol cfm pref 1 handle 101 \
97 flower cfm mdl 5 action drop
98 tc filter add dev $h2 ingress protocol cfm pref 1 handle 102 \
99 flower cfm mdl 3 action drop
100 tc filter add dev $h2 ingress protocol cfm pref 1 handle 103 \
101 flower cfm mdl 0 action drop
103 pkt="$ethtype $(generate_cfm_hdr 5 42 0 12)"
104 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
105 pkt="$ethtype $(generate_cfm_hdr 6 1 0 70)"
106 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
107 pkt="$ethtype $(generate_cfm_hdr 0 1 0 70)"
108 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
110 tc_check_packets "dev $h2 ingress" 101 1
111 check_err $? "Did not match on correct level"
113 tc_check_packets "dev $h2 ingress" 102 0
114 check_err $? "Matched on the wrong level"
116 tc_check_packets "dev $h2 ingress" 103 1
117 check_err $? "Did not match on correct level"
119 pkt="$ethtype $(generate_cfm_hdr 3 0 0 4)"
120 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
122 tc_check_packets "dev $h2 ingress" 101 1
123 check_err $? "Matched on the wrong level"
125 tc_check_packets "dev $h2 ingress" 102 1
126 check_err $? "Did not match on correct level"
128 tc_check_packets "dev $h2 ingress" 103 1
129 check_err $? "Matched on the wrong level"
131 tc filter del dev $h2 ingress protocol cfm pref 1 handle 101 flower
132 tc filter del dev $h2 ingress protocol cfm pref 1 handle 102 flower
133 tc filter del dev $h2 ingress protocol cfm pref 1 handle 103 flower
135 log_test "CFM level match test"
138 match_cfm_level_and_opcode()
140 local ethtype="89 02"; readonly ethtype
141 RET=0
143 tc filter add dev $h2 ingress protocol cfm pref 1 handle 101 \
144 flower cfm mdl 5 op 41 action drop
145 tc filter add dev $h2 ingress protocol cfm pref 1 handle 102 \
146 flower cfm mdl 7 op 42 action drop
148 pkt="$ethtype $(generate_cfm_hdr 5 41 0 4)"
149 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
150 pkt="$ethtype $(generate_cfm_hdr 7 3 0 4)"
151 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
152 pkt="$ethtype $(generate_cfm_hdr 3 42 0 12)"
153 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
155 tc_check_packets "dev $h2 ingress" 101 1
156 check_err $? "Did not match on correct level and opcode"
158 tc_check_packets "dev $h2 ingress" 102 0
159 check_err $? "Matched on the wrong level and opcode"
161 pkt="$ethtype $(generate_cfm_hdr 7 42 0 12)"
162 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
164 tc_check_packets "dev $h2 ingress" 101 1
165 check_err $? "Matched on the wrong level and opcode"
167 tc_check_packets "dev $h2 ingress" 102 1
168 check_err $? "Did not match on correct level and opcode"
170 tc filter del dev $h2 ingress protocol cfm pref 1 handle 101 flower
171 tc filter del dev $h2 ingress protocol cfm pref 1 handle 102 flower
173 log_test "CFM opcode and level match test"
176 setup_prepare()
178 h1=${NETIFS[p1]}
179 h2=${NETIFS[p2]}
180 h1mac=$(mac_get $h1)
181 h2mac=$(mac_get $h2)
183 vrf_prepare
185 h1_create
186 h2_create
189 cleanup()
191 pre_cleanup
193 h2_destroy
194 h1_destroy
196 vrf_cleanup
199 trap cleanup EXIT
201 setup_prepare
202 setup_wait
204 tests_run
206 exit $EXIT_STATUS