#
#  ns1 <-> nsr1 <-> nsr2 <-> ns2
#
ip netns add ns1
ip netns add nsr1
ip netns add nsr2
ip netns add ns2

ip link add veth0 netns nsr1 type veth peer name veth0 netns ns1
ip link add veth1 netns nsr1 type veth peer name veth1 netns nsr2
ip link add veth0 netns nsr2 type veth peer name veth0 netns ns2

ip -net nsr1 addr add 10.141.10.1/24 dev veth0
ip -net nsr1 addr add 192.168.10.10/24 dev veth1
ip -net nsr1 link set up dev veth0
ip -net nsr1 link set up dev veth1
#ip -net nsr1 link add name gtp0 type gtp role sgsn
ip netns exec nsr1 ./gtp-link add gtp0 ip --sgsn &
sleep 2
ip -net nsr1 link set up dev gtp0
ip -net nsr1 addr add 172.10.10.10/24 dev gtp0
#ip -net nsr1 ro add 10.141.11.0/24 dev gtp0
ip -net nsr1 ro add 10.141.11.0/24 via 172.10.10.11

ip -net nsr2 addr add 10.141.11.1/24 dev veth0
ip -net nsr2 addr add 192.168.10.11/24 dev veth1
ip -net nsr2 link set up dev veth0
ip -net nsr2 link set up dev veth1
#ip -net nsr2 link add name gtp0 type gtp role ggsn
ip netns exec nsr2 ./gtp-link add gtp0 ip &
sleep 2
ip -net nsr2 link set up dev gtp0
ip -net nsr2 addr add 172.10.10.11/24 dev gtp0
#ip -net nsr2 ro add 10.141.10.0/24 dev gtp0
ip -net nsr2 ro add 10.141.10.0/24 via 172.10.10.10

ip netns exec nsr1 sysctl net.ipv4.ip_forward=1 > /dev/null
ip netns exec nsr2 sysctl net.ipv4.ip_forward=1 > /dev/null

ip -net ns1 addr add 10.141.10.2/24 dev veth0
ip -net ns1 link set up dev veth0
ip -net ns1 ro add default via 10.141.10.1

ip -net ns2 addr add 10.141.11.2/24 dev veth0
ip -net ns2 link set up dev veth0
ip -net ns2 ro add default via 10.141.11.1

ip netns exec nsr1 ./gtp-tunnel add gtp0 v1 1 1 10.141.10.2 192.168.10.11
ip netns exec nsr2 ./gtp-tunnel add gtp0 v1 1 1 10.141.10.2 192.168.10.10

ip netns exec nsr1 nft -f - <<EOF
flush ruleset

table ip x {
	chain forward {
		type filter hook forward priority 0
		tcp flags syn tcp option maxseg size set rt mtu
		counter
	}
}
EOF

# ip netns exec ns2 iperf3 -s
# ip netns exec ns1 iperf3 -c 192.168.10.2 -n 100G
