1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# +-----------------------+
5# | H1 (v$h1)             |
6# | 192.0.2.1/24          |
7# | 2001:db8::1/124       |
8# |                 + $h1 |
9# +-----------------|-----+
10#                   |
11#                   | (Plain Ethernet traffic)
12#                   |
13# +-----------------|-----------------------------------------+
14# | LER1            + $edge1                                  |
15# |                     -ingress:                             |
16# |                       -encapsulate Ethernet into MPLS     |
17# |                       -add outer Ethernet header          |
18# |                       -redirect to $mpls1 (egress)        |
19# |                                                           |
20# |                 + $mpls1                                  |
21# |                 |   -ingress:                             |
22# |                 |     -remove outer Ethernet header       |
23# |                 |     -remove MPLS header                 |
24# |                 |     -redirect to $edge1 (egress)        |
25# +-----------------|-----------------------------------------+
26#                   |
27#                   | (Ethernet over MPLS traffic)
28#                   |
29# +-----------------|-----------------------------------------+
30# | LER2            + $mpls2                                  |
31# |                     -ingress:                             |
32# |                       -remove outer Ethernet header       |
33# |                       -remove MPLS header                 |
34# |                       -redirect to $edge2 (egress)        |
35# |                                                           |
36# |                 + $edge2                                  |
37# |                 |   -ingress:                             |
38# |                 |     -encapsulate Ethernet into MPLS     |
39# |                 |     -add outer Ethernet header          |
40# |                 |     -redirect to $mpls2 (egress)        |
41# +-----------------|-----------------------------------------|
42#                   |
43#                   | (Plain Ethernet traffic)
44#                   |
45# +-----------------|-----+
46# | H2 (v$h2)       |     |
47# |                 + $h2 |
48# | 192.0.2.2/24          |
49# | 2001:db8::2/124       |
50# +-----------------------+
51#
52# LER1 and LER2 logically represent two different routers. However, no VRF is
53# created for them, as they don't do any IP routing.
54
55ALL_TESTS="mpls_forward_eth"
56NUM_NETIFS=6
57source lib.sh
58
59h1_create()
60{
61	simple_if_init $h1 192.0.2.1/24 2001:db8::1/124
62}
63
64h1_destroy()
65{
66	simple_if_fini $h1 192.0.2.1/24 2001:db8::1/124
67}
68
69h2_create()
70{
71	simple_if_init $h2 192.0.2.2/24 2001:db8::2/124
72}
73
74h2_destroy()
75{
76	simple_if_fini $h2 192.0.2.2/24 2001:db8::2/124
77}
78
79ler1_create()
80{
81	tc qdisc add dev $edge1 ingress
82	tc filter add dev $edge1 ingress                            \
83	   matchall                                                 \
84	   action mpls mac_push label 102                           \
85	   action vlan push_eth dst_mac $mpls2mac src_mac $mpls1mac \
86	   action mirred egress redirect dev $mpls1
87	ip link set dev $edge1 up
88
89	tc qdisc add dev $mpls1 ingress
90	tc filter add dev $mpls1 ingress            \
91	   protocol mpls_uc                         \
92	   flower mpls_label 101                    \
93	   action vlan pop_eth                      \
94	   action mpls pop protocol teb             \
95	   action mirred egress redirect dev $edge1
96	ip link set dev $mpls1 up
97}
98
99ler1_destroy()
100{
101	ip link set dev $mpls1 down
102	tc qdisc del dev $mpls1 ingress
103
104	ip link set dev $edge1 down
105	tc qdisc del dev $edge1 ingress
106}
107
108ler2_create()
109{
110	tc qdisc add dev $edge2 ingress
111	tc filter add dev $edge2 ingress                            \
112	   matchall                                                 \
113	   action mpls mac_push label 101                           \
114	   action vlan push_eth dst_mac $mpls1mac src_mac $mpls2mac \
115	   action mirred egress redirect dev $mpls2
116	ip link set dev $edge2 up
117
118	tc qdisc add dev $mpls2 ingress
119	tc filter add dev $mpls2 ingress            \
120	   protocol mpls_uc                         \
121	   flower mpls_label 102                    \
122	   action vlan pop_eth                      \
123	   action mpls pop protocol teb             \
124	   action mirred egress redirect dev $edge2
125	ip link set dev $mpls2 up
126}
127
128ler2_destroy()
129{
130	ip link set dev $mpls2 down
131	tc qdisc del dev $mpls2 ingress
132
133	ip link set dev $edge2 down
134	tc qdisc del dev $edge2 ingress
135}
136
137mpls_forward_eth()
138{
139	ping_test $h1 192.0.2.2
140	ping6_test $h1 2001:db8::2
141}
142
143setup_prepare()
144{
145	h1=${NETIFS[p1]}
146	edge1=${NETIFS[p2]}
147
148	mpls1=${NETIFS[p3]}
149	mpls2=${NETIFS[p4]}
150
151	edge2=${NETIFS[p5]}
152	h2=${NETIFS[p6]}
153
154	mpls1mac=$(mac_get $mpls1)
155	mpls2mac=$(mac_get $mpls2)
156
157	vrf_prepare
158
159	h1_create
160	h2_create
161	ler1_create
162	ler2_create
163}
164
165cleanup()
166{
167	pre_cleanup
168
169	ler2_destroy
170	ler1_destroy
171	h2_destroy
172	h1_destroy
173
174	vrf_cleanup
175}
176
177trap cleanup EXIT
178
179setup_prepare
180setup_wait
181
182tests_run
183
184tc_offload_check
185if [[ $? -ne 0 ]]; then
186	log_info "Could not test offloaded functionality"
187else
188	tcflags="skip_sw"
189	tests_run
190fi
191
192exit $EXIT_STATUS
193