xref: /openbmc/linux/tools/testing/selftests/net/forwarding/gre_multipath.sh (revision ac94be498f84f7327533b62faca4c3da64434904)
154818c4cSPetr Machata#!/bin/bash
254818c4cSPetr Machata# SPDX-License-Identifier: GPL-2.0
354818c4cSPetr Machata
454818c4cSPetr Machata# Test traffic distribution when a wECMP route forwards traffic to two GRE
554818c4cSPetr Machata# tunnels.
654818c4cSPetr Machata#
754818c4cSPetr Machata# +-------------------------+
854818c4cSPetr Machata# | H1                      |
954818c4cSPetr Machata# |               $h1 +     |
1054818c4cSPetr Machata# |      192.0.2.1/28 |     |
1154818c4cSPetr Machata# +-------------------|-----+
1254818c4cSPetr Machata#                     |
1354818c4cSPetr Machata# +-------------------|------------------------+
1454818c4cSPetr Machata# | SW1               |                        |
1554818c4cSPetr Machata# |              $ol1 +                        |
1654818c4cSPetr Machata# |      192.0.2.2/28                          |
1754818c4cSPetr Machata# |                                            |
1854818c4cSPetr Machata# |  + g1a (gre)          + g1b (gre)          |
1954818c4cSPetr Machata# |    loc=192.0.2.65       loc=192.0.2.81     |
2054818c4cSPetr Machata# |    rem=192.0.2.66 --.   rem=192.0.2.82 --. |
2154818c4cSPetr Machata# |    tos=inherit      |   tos=inherit      | |
2254818c4cSPetr Machata# |  .------------------'                    | |
2354818c4cSPetr Machata# |  |                    .------------------' |
2454818c4cSPetr Machata# |  v                    v                    |
2554818c4cSPetr Machata# |  + $ul1.111 (vlan)    + $ul1.222 (vlan)    |
2654818c4cSPetr Machata# |  | 192.0.2.129/28     | 192.0.2.145/28     |
2754818c4cSPetr Machata# |   \                  /                     |
2854818c4cSPetr Machata# |    \________________/                      |
2954818c4cSPetr Machata# |            |                               |
3054818c4cSPetr Machata# |            + $ul1                          |
3154818c4cSPetr Machata# +------------|-------------------------------+
3254818c4cSPetr Machata#              |
3354818c4cSPetr Machata# +------------|-------------------------------+
3454818c4cSPetr Machata# | SW2        + $ul2                          |
3554818c4cSPetr Machata# |     _______|________                       |
3654818c4cSPetr Machata# |    /                \                      |
3754818c4cSPetr Machata# |   /                  \                     |
3854818c4cSPetr Machata# |  + $ul2.111 (vlan)    + $ul2.222 (vlan)    |
3954818c4cSPetr Machata# |  ^ 192.0.2.130/28     ^ 192.0.2.146/28     |
4054818c4cSPetr Machata# |  |                    |                    |
4154818c4cSPetr Machata# |  |                    '------------------. |
4254818c4cSPetr Machata# |  '------------------.                    | |
4354818c4cSPetr Machata# |  + g2a (gre)        | + g2b (gre)        | |
4454818c4cSPetr Machata# |    loc=192.0.2.66   |   loc=192.0.2.82   | |
4554818c4cSPetr Machata# |    rem=192.0.2.65 --'   rem=192.0.2.81 --' |
4654818c4cSPetr Machata# |    tos=inherit          tos=inherit        |
4754818c4cSPetr Machata# |                                            |
4854818c4cSPetr Machata# |              $ol2 +                        |
4954818c4cSPetr Machata# |     192.0.2.17/28 |                        |
5054818c4cSPetr Machata# +-------------------|------------------------+
5154818c4cSPetr Machata#                     |
5254818c4cSPetr Machata# +-------------------|-----+
5354818c4cSPetr Machata# | H2                |     |
5454818c4cSPetr Machata# |               $h2 +     |
5554818c4cSPetr Machata# |     192.0.2.18/28       |
5654818c4cSPetr Machata# +-------------------------+
5754818c4cSPetr Machata
5854818c4cSPetr MachataALL_TESTS="
5954818c4cSPetr Machata	ping_ipv4
6054818c4cSPetr Machata	multipath_ipv4
6154818c4cSPetr Machata"
6254818c4cSPetr Machata
6354818c4cSPetr MachataNUM_NETIFS=6
6454818c4cSPetr Machatasource lib.sh
6554818c4cSPetr Machata
6654818c4cSPetr Machatah1_create()
6754818c4cSPetr Machata{
6854818c4cSPetr Machata	simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
6954818c4cSPetr Machata	ip route add vrf v$h1 192.0.2.16/28 via 192.0.2.2
7054818c4cSPetr Machata}
7154818c4cSPetr Machata
7254818c4cSPetr Machatah1_destroy()
7354818c4cSPetr Machata{
7454818c4cSPetr Machata	ip route del vrf v$h1 192.0.2.16/28 via 192.0.2.2
7554818c4cSPetr Machata	simple_if_fini $h1 192.0.2.1/28
7654818c4cSPetr Machata}
7754818c4cSPetr Machata
7854818c4cSPetr Machatasw1_create()
7954818c4cSPetr Machata{
809a2ad362SPetr Machata	simple_if_init $ol1 192.0.2.2/28
8154818c4cSPetr Machata	__simple_if_init $ul1 v$ol1
8254818c4cSPetr Machata	vlan_create $ul1 111 v$ol1 192.0.2.129/28
8354818c4cSPetr Machata	vlan_create $ul1 222 v$ol1 192.0.2.145/28
8454818c4cSPetr Machata
8554818c4cSPetr Machata	tunnel_create g1a gre 192.0.2.65 192.0.2.66 tos inherit dev v$ol1
8654818c4cSPetr Machata	__simple_if_init g1a v$ol1 192.0.2.65/32
8754818c4cSPetr Machata	ip route add vrf v$ol1 192.0.2.66/32 via 192.0.2.130
8854818c4cSPetr Machata
8954818c4cSPetr Machata	tunnel_create g1b gre 192.0.2.81 192.0.2.82 tos inherit dev v$ol1
9054818c4cSPetr Machata	__simple_if_init g1b v$ol1 192.0.2.81/32
9154818c4cSPetr Machata	ip route add vrf v$ol1 192.0.2.82/32 via 192.0.2.146
9254818c4cSPetr Machata
9354818c4cSPetr Machata	ip route add vrf v$ol1 192.0.2.16/28 \
9454818c4cSPetr Machata	   nexthop dev g1a \
9554818c4cSPetr Machata	   nexthop dev g1b
9654818c4cSPetr Machata}
9754818c4cSPetr Machata
9854818c4cSPetr Machatasw1_destroy()
9954818c4cSPetr Machata{
10054818c4cSPetr Machata	ip route del vrf v$ol1 192.0.2.16/28
10154818c4cSPetr Machata
10254818c4cSPetr Machata	ip route del vrf v$ol1 192.0.2.82/32 via 192.0.2.146
10354818c4cSPetr Machata	__simple_if_fini g1b 192.0.2.81/32
10454818c4cSPetr Machata	tunnel_destroy g1b
10554818c4cSPetr Machata
10654818c4cSPetr Machata	ip route del vrf v$ol1 192.0.2.66/32 via 192.0.2.130
10754818c4cSPetr Machata	__simple_if_fini g1a 192.0.2.65/32
10854818c4cSPetr Machata	tunnel_destroy g1a
10954818c4cSPetr Machata
11054818c4cSPetr Machata	vlan_destroy $ul1 222
11154818c4cSPetr Machata	vlan_destroy $ul1 111
11254818c4cSPetr Machata	__simple_if_fini $ul1
1139a2ad362SPetr Machata	simple_if_fini $ol1 192.0.2.2/28
11454818c4cSPetr Machata}
11554818c4cSPetr Machata
11654818c4cSPetr Machatasw2_create()
11754818c4cSPetr Machata{
1189a2ad362SPetr Machata	simple_if_init $ol2 192.0.2.17/28
11954818c4cSPetr Machata	__simple_if_init $ul2 v$ol2
12054818c4cSPetr Machata	vlan_create $ul2 111 v$ol2 192.0.2.130/28
12154818c4cSPetr Machata	vlan_create $ul2 222 v$ol2 192.0.2.146/28
12254818c4cSPetr Machata
12354818c4cSPetr Machata	tunnel_create g2a gre 192.0.2.66 192.0.2.65 tos inherit dev v$ol2
12454818c4cSPetr Machata	__simple_if_init g2a v$ol2 192.0.2.66/32
12554818c4cSPetr Machata	ip route add vrf v$ol2 192.0.2.65/32 via 192.0.2.129
12654818c4cSPetr Machata
12754818c4cSPetr Machata	tunnel_create g2b gre 192.0.2.82 192.0.2.81 tos inherit dev v$ol2
12854818c4cSPetr Machata	__simple_if_init g2b v$ol2 192.0.2.82/32
12954818c4cSPetr Machata	ip route add vrf v$ol2 192.0.2.81/32 via 192.0.2.145
13054818c4cSPetr Machata
13154818c4cSPetr Machata	ip route add vrf v$ol2 192.0.2.0/28 \
13254818c4cSPetr Machata	   nexthop dev g2a \
13354818c4cSPetr Machata	   nexthop dev g2b
134*1be79d89SIdo Schimmel
135*1be79d89SIdo Schimmel	tc qdisc add dev $ul2 clsact
136*1be79d89SIdo Schimmel	tc filter add dev $ul2 ingress pref 111 prot 802.1Q \
137*1be79d89SIdo Schimmel	   flower vlan_id 111 action pass
138*1be79d89SIdo Schimmel	tc filter add dev $ul2 ingress pref 222 prot 802.1Q \
139*1be79d89SIdo Schimmel	   flower vlan_id 222 action pass
14054818c4cSPetr Machata}
14154818c4cSPetr Machata
14254818c4cSPetr Machatasw2_destroy()
14354818c4cSPetr Machata{
144*1be79d89SIdo Schimmel	tc qdisc del dev $ul2 clsact
145*1be79d89SIdo Schimmel
14654818c4cSPetr Machata	ip route del vrf v$ol2 192.0.2.0/28
14754818c4cSPetr Machata
14854818c4cSPetr Machata	ip route del vrf v$ol2 192.0.2.81/32 via 192.0.2.145
14954818c4cSPetr Machata	__simple_if_fini g2b 192.0.2.82/32
15054818c4cSPetr Machata	tunnel_destroy g2b
15154818c4cSPetr Machata
15254818c4cSPetr Machata	ip route del vrf v$ol2 192.0.2.65/32 via 192.0.2.129
15354818c4cSPetr Machata	__simple_if_fini g2a 192.0.2.66/32
15454818c4cSPetr Machata	tunnel_destroy g2a
15554818c4cSPetr Machata
15654818c4cSPetr Machata	vlan_destroy $ul2 222
15754818c4cSPetr Machata	vlan_destroy $ul2 111
15854818c4cSPetr Machata	__simple_if_fini $ul2
1599a2ad362SPetr Machata	simple_if_fini $ol2 192.0.2.17/28
16054818c4cSPetr Machata}
16154818c4cSPetr Machata
16254818c4cSPetr Machatah2_create()
16354818c4cSPetr Machata{
1649a2ad362SPetr Machata	simple_if_init $h2 192.0.2.18/28
16554818c4cSPetr Machata	ip route add vrf v$h2 192.0.2.0/28 via 192.0.2.17
16654818c4cSPetr Machata}
16754818c4cSPetr Machata
16854818c4cSPetr Machatah2_destroy()
16954818c4cSPetr Machata{
17054818c4cSPetr Machata	ip route del vrf v$h2 192.0.2.0/28 via 192.0.2.17
1719a2ad362SPetr Machata	simple_if_fini $h2 192.0.2.18/28
17254818c4cSPetr Machata}
17354818c4cSPetr Machata
17454818c4cSPetr Machatasetup_prepare()
17554818c4cSPetr Machata{
17654818c4cSPetr Machata	h1=${NETIFS[p1]}
17754818c4cSPetr Machata	ol1=${NETIFS[p2]}
17854818c4cSPetr Machata
17954818c4cSPetr Machata	ul1=${NETIFS[p3]}
18054818c4cSPetr Machata	ul2=${NETIFS[p4]}
18154818c4cSPetr Machata
18254818c4cSPetr Machata	ol2=${NETIFS[p5]}
18354818c4cSPetr Machata	h2=${NETIFS[p6]}
18454818c4cSPetr Machata
18554818c4cSPetr Machata	vrf_prepare
18654818c4cSPetr Machata	h1_create
18754818c4cSPetr Machata	sw1_create
18854818c4cSPetr Machata	sw2_create
18954818c4cSPetr Machata	h2_create
190efa7b79fSIdo Schimmel
191efa7b79fSIdo Schimmel	forwarding_enable
19254818c4cSPetr Machata}
19354818c4cSPetr Machata
19454818c4cSPetr Machatacleanup()
19554818c4cSPetr Machata{
19654818c4cSPetr Machata	pre_cleanup
19754818c4cSPetr Machata
198efa7b79fSIdo Schimmel	forwarding_restore
199efa7b79fSIdo Schimmel
20054818c4cSPetr Machata	h2_destroy
20154818c4cSPetr Machata	sw2_destroy
20254818c4cSPetr Machata	sw1_destroy
20354818c4cSPetr Machata	h1_destroy
20454818c4cSPetr Machata	vrf_cleanup
20554818c4cSPetr Machata}
20654818c4cSPetr Machata
20754818c4cSPetr Machatamultipath4_test()
20854818c4cSPetr Machata{
20954818c4cSPetr Machata	local what=$1; shift
21054818c4cSPetr Machata	local weight1=$1; shift
21154818c4cSPetr Machata	local weight2=$1; shift
21254818c4cSPetr Machata
21354818c4cSPetr Machata	sysctl_set net.ipv4.fib_multipath_hash_policy 1
21454818c4cSPetr Machata	ip route replace vrf v$ol1 192.0.2.16/28 \
21554818c4cSPetr Machata	   nexthop dev g1a weight $weight1 \
21654818c4cSPetr Machata	   nexthop dev g1b weight $weight2
21754818c4cSPetr Machata
218*1be79d89SIdo Schimmel	local t0_111=$(tc_rule_stats_get $ul2 111 ingress)
219*1be79d89SIdo Schimmel	local t0_222=$(tc_rule_stats_get $ul2 222 ingress)
22054818c4cSPetr Machata
22154818c4cSPetr Machata	ip vrf exec v$h1 \
22254818c4cSPetr Machata	   $MZ $h1 -q -p 64 -A 192.0.2.1 -B 192.0.2.18 \
22354818c4cSPetr Machata	       -d 1msec -t udp "sp=1024,dp=0-32768"
22454818c4cSPetr Machata
225*1be79d89SIdo Schimmel	local t1_111=$(tc_rule_stats_get $ul2 111 ingress)
226*1be79d89SIdo Schimmel	local t1_222=$(tc_rule_stats_get $ul2 222 ingress)
22754818c4cSPetr Machata
22854818c4cSPetr Machata	local d111=$((t1_111 - t0_111))
22954818c4cSPetr Machata	local d222=$((t1_222 - t0_222))
23054818c4cSPetr Machata	multipath_eval "$what" $weight1 $weight2 $d111 $d222
23154818c4cSPetr Machata
23254818c4cSPetr Machata	ip route replace vrf v$ol1 192.0.2.16/28 \
23354818c4cSPetr Machata	   nexthop dev g1a \
23454818c4cSPetr Machata	   nexthop dev g1b
23554818c4cSPetr Machata	sysctl_restore net.ipv4.fib_multipath_hash_policy
23654818c4cSPetr Machata}
23754818c4cSPetr Machata
23854818c4cSPetr Machataping_ipv4()
23954818c4cSPetr Machata{
24054818c4cSPetr Machata	ping_test $h1 192.0.2.18
24154818c4cSPetr Machata}
24254818c4cSPetr Machata
24354818c4cSPetr Machatamultipath_ipv4()
24454818c4cSPetr Machata{
24554818c4cSPetr Machata	log_info "Running IPv4 multipath tests"
24654818c4cSPetr Machata	multipath4_test "ECMP" 1 1
24754818c4cSPetr Machata	multipath4_test "Weighted MP 2:1" 2 1
24854818c4cSPetr Machata	multipath4_test "Weighted MP 11:45" 11 45
24954818c4cSPetr Machata}
25054818c4cSPetr Machata
25154818c4cSPetr Machatatrap cleanup EXIT
25254818c4cSPetr Machata
25354818c4cSPetr Machatasetup_prepare
25454818c4cSPetr Machatasetup_wait
25554818c4cSPetr Machatatests_run
25654818c4cSPetr Machata
25754818c4cSPetr Machataexit $EXIT_STATUS
258