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