1# SPDX-License-Identifier: GPL-2.0
2
3# This is the standard topology for testing mirroring. The tests that use it
4# tweak it in one way or another--typically add more devices to the topology.
5#
6#   +---------------------+                             +---------------------+
7#   | H1                  |                             |                  H2 |
8#   |     + $h1           |                             |           $h2 +     |
9#   |     | 192.0.2.1/28  |                             |  192.0.2.2/28 |     |
10#   +-----|---------------+                             +---------------|-----+
11#         |                                                             |
12#   +-----|-------------------------------------------------------------|-----+
13#   | SW  o--> mirror                                                   |     |
14#   | +---|-------------------------------------------------------------|---+ |
15#   | |   + $swp1                    BR                           $swp2 +   | |
16#   | +---------------------------------------------------------------------+ |
17#   |                                                                         |
18#   |     + $swp3                                                             |
19#   +-----|-------------------------------------------------------------------+
20#         |
21#   +-----|-------------------------------------------------------------------+
22#   | H3  + $h3                                                               |
23#   |                                                                         |
24#   +-------------------------------------------------------------------------+
25
26mirror_topo_h1_create()
27{
28	simple_if_init $h1 192.0.2.1/28
29}
30
31mirror_topo_h1_destroy()
32{
33	simple_if_fini $h1 192.0.2.1/28
34}
35
36mirror_topo_h2_create()
37{
38	simple_if_init $h2 192.0.2.2/28
39}
40
41mirror_topo_h2_destroy()
42{
43	simple_if_fini $h2 192.0.2.2/28
44}
45
46mirror_topo_h3_create()
47{
48	simple_if_init $h3
49	tc qdisc add dev $h3 clsact
50}
51
52mirror_topo_h3_destroy()
53{
54	tc qdisc del dev $h3 clsact
55	simple_if_fini $h3
56}
57
58mirror_topo_switch_create()
59{
60	ip link set dev $swp3 up
61
62	ip link add name br1 type bridge vlan_filtering 1
63	ip link set dev br1 addrgenmode none
64	ip link set dev br1 up
65
66	ip link set dev $swp1 master br1
67	ip link set dev $swp1 up
68
69	ip link set dev $swp2 master br1
70	ip link set dev $swp2 up
71
72	tc qdisc add dev $swp1 clsact
73}
74
75mirror_topo_switch_destroy()
76{
77	tc qdisc del dev $swp1 clsact
78
79	ip link set dev $swp1 down
80	ip link set dev $swp2 down
81	ip link del dev br1
82
83	ip link set dev $swp3 down
84}
85
86mirror_topo_create()
87{
88	mirror_topo_h1_create
89	mirror_topo_h2_create
90	mirror_topo_h3_create
91
92	mirror_topo_switch_create
93}
94
95mirror_topo_destroy()
96{
97	mirror_topo_switch_destroy
98
99	mirror_topo_h3_destroy
100	mirror_topo_h2_destroy
101	mirror_topo_h1_destroy
102}
103