xref: /linux/tools/testing/selftests/net/forwarding/router_vid_1.sh (revision e7d759f31ca295d589f7420719c311870bb3166f)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# +--------------------+                     +----------------------+
5# | H1                 |                     |                   H2 |
6# |                    |                     |                      |
7# |            $h1.1 + |                     | + $h2.1              |
8# |     192.0.2.2/24 | |                     | | 198.51.100.2/24    |
9# | 2001:db8:1::2/64 | |                     | | 2001:db8:2::2/64   |
10# |                  | |                     | |                    |
11# |              $h1 + |                     | + $h2                |
12# |                  | |                     | |                    |
13# +------------------|-+                     +-|--------------------+
14#                    |                         |
15# +------------------|-------------------------|--------------------+
16# | SW               |                         |                    |
17# |                  |                         |                    |
18# |             $rp1 +                         + $rp2               |
19# |                  |                         |                    |
20# |           $rp1.1 +                         + $rp2.1             |
21# |     192.0.2.1/24                             198.51.100.1/24    |
22# | 2001:db8:1::1/64                             2001:db8:2::1/64   |
23# |                                                                 |
24# +-----------------------------------------------------------------+
25
26ALL_TESTS="
27	ping_ipv4
28	ping_ipv6
29"
30NUM_NETIFS=4
31source lib.sh
32
33h1_create()
34{
35	vrf_create "vrf-h1"
36	ip link set dev vrf-h1 up
37
38	ip link set dev $h1 up
39	vlan_create $h1 1 vrf-h1 192.0.2.2/24 2001:db8:1::2/64
40
41	ip route add 198.51.100.0/24 vrf vrf-h1 nexthop via 192.0.2.1
42	ip route add 2001:db8:2::/64 vrf vrf-h1 nexthop via 2001:db8:1::1
43}
44
45h1_destroy()
46{
47	ip route del 2001:db8:2::/64 vrf vrf-h1
48	ip route del 198.51.100.0/24 vrf vrf-h1
49
50	vlan_destroy $h1 1
51	ip link set dev $h1 down
52
53	ip link set dev vrf-h1 down
54	vrf_destroy "vrf-h1"
55}
56
57h2_create()
58{
59	vrf_create "vrf-h2"
60	ip link set dev vrf-h2 up
61
62	ip link set dev $h2 up
63	vlan_create $h2 1 vrf-h2 198.51.100.2/24 2001:db8:2::2/64
64
65	ip route add 192.0.2.0/24 vrf vrf-h2 nexthop via 198.51.100.1
66	ip route add 2001:db8:1::/64 vrf vrf-h2 nexthop via 2001:db8:2::1
67}
68
69h2_destroy()
70{
71	ip route del 2001:db8:1::/64 vrf vrf-h2
72	ip route del 192.0.2.0/24 vrf vrf-h2
73
74	vlan_destroy $h2 1
75	ip link set dev $h2 down
76
77	ip link set dev vrf-h2 down
78	vrf_destroy "vrf-h2"
79}
80
81router_create()
82{
83	ip link set dev $rp1 up
84	ip link add link $rp1 name $rp1.1 up type vlan id 1
85
86	ip address add 192.0.2.1/24 dev $rp1.1
87	ip address add 2001:db8:1::1/64 dev $rp1.1
88
89	ip link set dev $rp2 up
90	ip link add link $rp2 name $rp2.1 up type vlan id 1
91
92	ip address add 198.51.100.1/24 dev $rp2.1
93	ip address add 2001:db8:2::1/64 dev $rp2.1
94}
95
96router_destroy()
97{
98	ip address del 2001:db8:2::1/64 dev $rp2.1
99	ip address del 198.51.100.1/24 dev $rp2.1
100
101	ip link del dev $rp2.1
102	ip link set dev $rp2 down
103
104	ip address del 2001:db8:1::1/64 dev $rp1.1
105	ip address del 192.0.2.1/24 dev $rp1.1
106
107	ip link del dev $rp1.1
108	ip link set dev $rp1 down
109}
110
111setup_prepare()
112{
113	h1=${NETIFS[p1]}
114	rp1=${NETIFS[p2]}
115
116	rp2=${NETIFS[p3]}
117	h2=${NETIFS[p4]}
118
119	vrf_prepare
120
121	h1_create
122	h2_create
123
124	router_create
125
126	forwarding_enable
127}
128
129cleanup()
130{
131	pre_cleanup
132
133	forwarding_restore
134
135	router_destroy
136
137	h2_destroy
138	h1_destroy
139
140	vrf_cleanup
141}
142
143ping_ipv4()
144{
145	ping_test $h1.1 198.51.100.2
146}
147
148ping_ipv6()
149{
150	ping6_test $h1.1 2001:db8:2::2
151}
152
153trap cleanup EXIT
154
155setup_prepare
156setup_wait
157
158tests_run
159
160exit $EXIT_STATUS
161