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