selftests: forwarding: mirror_vlan: Uninstall trap
[linux-2.6-block.git] / tools / testing / selftests / net / forwarding / mirror_vlan.sh
CommitLineData
35388a6a
PM
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# This test uses standard topology for testing mirroring. See mirror_topo_lib.sh
5# for more details.
6#
7# Test for "tc action mirred egress mirror" that mirrors to a vlan device.
8
9ALL_TESTS="
10 test_vlan
11 test_tagged_vlan
12"
13
14NUM_NETIFS=6
15source lib.sh
16source mirror_lib.sh
17source mirror_topo_lib.sh
18
19setup_prepare()
20{
21 h1=${NETIFS[p1]}
22 swp1=${NETIFS[p2]}
23
24 swp2=${NETIFS[p3]}
25 h2=${NETIFS[p4]}
26
27 swp3=${NETIFS[p5]}
28 h3=${NETIFS[p6]}
29
30 vrf_prepare
31 mirror_topo_create
32
33 vlan_create $swp3 555
34
35 vlan_create $h3 555 v$h3
36 matchall_sink_create $h3.555
37
38 vlan_create $h1 111 v$h1 192.0.2.17/28
39 bridge vlan add dev $swp1 vid 111
40
41 vlan_create $h2 111 v$h2 192.0.2.18/28
42 bridge vlan add dev $swp2 vid 111
43}
44
45cleanup()
46{
47 pre_cleanup
48
49 vlan_destroy $h2 111
50 vlan_destroy $h1 111
51 vlan_destroy $h3 555
52 vlan_destroy $swp3 555
53
54 mirror_topo_destroy
55 vrf_cleanup
56}
57
58test_vlan_dir()
59{
60 local direction=$1; shift
61 local forward_type=$1; shift
62 local backward_type=$1; shift
63
64 RET=0
65
66 mirror_install $swp1 $direction $swp3.555 "matchall $tcflags"
67 test_span_dir "$h3.555" "$direction" "$forward_type" "$backward_type"
68 mirror_uninstall $swp1 $direction
69
70 log_test "$direction mirror to vlan ($tcflags)"
71}
72
73test_vlan()
74{
75 test_vlan_dir ingress 8 0
76 test_vlan_dir egress 0 8
77}
78
35388a6a
PM
79test_tagged_vlan_dir()
80{
81 local direction=$1; shift
82 local forward_type=$1; shift
83 local backward_type=$1; shift
84
85 RET=0
86
87 mirror_install $swp1 $direction $swp3.555 "matchall $tcflags"
88 do_test_span_vlan_dir_ips 10 "$h3.555" 111 "$direction" \
89 192.0.2.17 192.0.2.18
90 do_test_span_vlan_dir_ips 0 "$h3.555" 555 "$direction" \
91 192.0.2.17 192.0.2.18
92 mirror_uninstall $swp1 $direction
93
94 log_test "$direction mirror to vlan ($tcflags)"
95}
96
97test_tagged_vlan()
98{
99 test_tagged_vlan_dir ingress 8 0
100 test_tagged_vlan_dir egress 0 8
101}
102
103test_all()
104{
105 slow_path_trap_install $swp1 ingress
106 slow_path_trap_install $swp1 egress
107 trap_install $h3 ingress
108
109 tests_run
110
00d56229 111 trap_uninstall $h3 ingress
35388a6a
PM
112 slow_path_trap_uninstall $swp1 egress
113 slow_path_trap_uninstall $swp1 ingress
114}
115
116trap cleanup EXIT
117
118setup_prepare
119setup_wait
120
121tcflags="skip_hw"
122test_all
123
124if ! tc_offload_check; then
125 echo "WARN: Could not test offloaded functionality"
126else
127 tcflags="skip_sw"
128 test_all
129fi
130
131exit $EXIT_STATUS