#!/bin/sh # vrf0 sends out packets with mpls labels # vrf1 receives the labelled packets, pops the labels, and forwards to vrf2 # vrf2 receives the unlabelled packets and replies to vrf0 vrf add vrf0 table 1001 vrf add vrf1 table 1002 vrf add vrf2 table 1003 ip link add virt01 type veth peer name virt10 ip link set virt01 master vrf0 ip link set virt10 master vrf1 ip link add virt12 type veth peer name virt21 ip link set virt12 master vrf1 ip link set virt21 master vrf2 ip addr add 172.16.20.20/24 dev virt01 ip link set virt01 up ip addr add 172.16.20.21/24 dev virt10 ip link set virt10 up ip addr add 172.16.21.21/24 dev virt12 ip link set virt12 up ip addr add 172.16.21.22/24 dev virt21 ip link set virt21 up modprobe mpls_iptunnel ip route add vrf vrf0 10.10.10.10/32 encap mpls 100 via inet 172.16.20.21 ip route add vrf vrf0 172.16.21.0/24 via 172.16.20.21 sysctl -w net.mpls.conf.virt10.input=1 sysctl -w net.mpls.platform_labels=1000 ip -f mpls route add 100 via inet 172.16.21.22 dev virt12 ip addr add 10.10.10.10/32 dev vrf2 ip route add vrf vrf2 172.16.20.0/24 via 172.16.21.21 ping -c 1 -I vrf0 10.10.10.10 netserver cat <