Created
November 4, 2019 13:35
-
-
Save upa/94be4865ca9f4df233e396c1072acaf9 to your computer and use it in GitHub Desktop.
Testing End.AM with PSP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ip=/sbin/ip | |
ipns="$ip netns exec" | |
function make_netns() { | |
ns=$1 | |
echo create netns $ns | |
if [ -e /var/run/netns/$ns ]; then | |
$ip netns del $ns | |
fi | |
sleep 0.5 | |
$ip netns add $ns | |
$ipns $ns $ip link set dev lo up | |
} | |
function make_patch() { | |
va=$1 | |
vb=$2 | |
nsb=$3 | |
echo create patch between $va and $vb in ns $nsb | |
if [ -e /sys/class/net/$va ]; then | |
$ip link del dev $va | |
fi | |
$ip link add $va type veth peer name $vb | |
$ip link set dev $vb netns $nsb | |
$ip link set dev $va up | |
$ipns $nsb $ip link set dev $vb up | |
} | |
function make_br0_on_ns() { | |
ns=$1 | |
la=$2 | |
lb=$3 | |
$ipns $ns $ip link add br0 type bridge | |
$ipns $ns $ip link set dev $la master br0 | |
$ipns $ns $ip link set dev $lb master br0 | |
$ipns $ns $ip link set dev br0 up | |
$ipns $ns $ip link set dev $la up | |
$ipns $ns $ip link set dev $lb up | |
} | |
function get_mac() { | |
link=$1 | |
echo `ip a s dev $link | grep ether | cut -d ' ' -f 6` | |
} | |
function get_ip6() { | |
link=$1 | |
echo `ip -6 a s $link | grep inet6 | grep -v fe80 | cut -d ' ' -f 6 | cut -d '/' -f 1` | |
} | |
# Test Topology | |
# | |
# +-----------+ +-----------+ | |
# | nf2 | | nf1 | | |
# | | | | | |
# | br0 | | br0 | | |
# | +---+ | | +---+ | | |
# | | | | | | | | | |
# +-----------+ +-----------+ | |
# f22b| |f21b f12b| |f11b | |
# | | | | | |
# f22a| |f21a f12a| |f11a | |
# +-------------------------------+ | |
# | | | |
# | default netns | | |
# | End.AM proxy | | |
# | | | |
# +-------------------------------+ | |
# e2a| |e1a | |
# | | | |
# |fc00:e2::/64 |fc00:e1::/64 | |
# | | | |
# e2b| |e1b | |
# +-----------+ +-----------+ | |
# | | | | | |
# | edge2 | | edge1 | | |
# | | | | | |
# +-----------+ +-----------+ | |
# | |
# from edge1 to edge2, segment list is fc00:1::,fc00:2:: | |
# fc00:1:: is End.AM for f11a | |
# fc00:2:: is End.AM for f21a | |
for ns in edge1 edge2 nf1 nf2; do | |
make_netns $ns | |
done | |
make_patch e1a e1b edge1 | |
make_patch e2a e2b edge2 | |
make_patch f11a f11b nf1 | |
make_patch f12a f12b nf1 | |
make_br0_on_ns nf1 f11b f12b | |
make_patch f21a f21b nf2 | |
make_patch f22a f22b nf2 | |
make_br0_on_ns nf2 f21b f22b | |
vrfa=vrfa | |
vrfb=vrfb | |
echo setup VRF $vrfa and $vrfb for IFACE-IN and End.AM route | |
if [ -e /sys/class/net/$vrfa ]; then | |
$ip link del dev $vrfa | |
sleep 0.5 | |
fi | |
if [ -e /sys/class/net/$vrfb ]; then | |
$ip link del dev $vrfb | |
sleep 0.5 | |
fi | |
$ip link add dev $vrfa type vrf table 10 | |
$ip link add dev $vrfb type vrf table 11 | |
$ip link set dev $vrfa up | |
$ip link set dev $vrfb up | |
$ip link set dev f11a master $vrfa | |
$ip link set dev f21a master $vrfa | |
$ip link set dev f12a master $vrfb | |
$ip link set dev f22a master $vrfb | |
echo setup ip adderss for edge namespaces | |
$ip -6 addr add dev e1a fc00:e1::1/64 | |
$ip -6 addr add dev e2a fc00:e2::1/64 | |
$ipns edge1 $ip -6 addr add dev e1b fc00:e1::2/64 | |
$ipns edge1 $ip -6 route add to default via fc00:e1::1 | |
$ipns edge2 $ip -6 addr add dev e2b fc00:e2::2/64 | |
$ipns edge2 $ip -6 route add to default via fc00:e2::1 | |
echo setup ip address for nf1 and nf2 links | |
$ip -6 addr add dev f11a fc00:f1::1/64 | |
$ip -6 addr add dev f12a fc00:f1::2/64 | |
$ip -6 addr add dev f21a fc00:f2::1/64 | |
$ip -6 addr add dev f22a fc00:f2::2/64 | |
echo setup End.AM routes | |
f12a_mac=`get_mac f12a` | |
f22a_mac=`get_mac f22a` | |
#$ip -6 route add to fc00:1:: encap seg6local action End.AM oif f11a mac $f12a_mac dev f11a | |
#$ip -6 route add to f22:: encap seg6local action End.AM oif f21a mac $f22a_mac dev f21a | |
# NH6 mode | |
f12a_ip6=`get_ip6 f12a` | |
f22a_ip6=`get_ip6 f22a` | |
$ip -6 route add to fc00:1:: encap seg6local action End.AM \ | |
nh6 $f12a_ip6 table 10 dev f11a | |
$ip -6 route add to fc00:2:: encap seg6local action End.AM \ | |
nh6 $f22a_ip6 table 10 dev f21a | |
echo setup End.T route on both $vrfa and $vrfb | |
$ip -6 route add vrf $vrfa to default encap seg6local action End.T \ | |
table 254 flavors PSP dev f12a | |
$ip -6 route add vrf $vrfb to default encap seg6local action End.T \ | |
table 254 flavors PSP dev f12a | |
echo setup T.insert on edge2 | |
$ipns edge2 ip -6 route add to fc00:e1::2 encap seg6 mode inline \ | |
segs fc00:1::,fc00:2:: dev e2b | |
echo do sudo ip netns exec edge2 ping6 fc00:e1::2, and tcpdump fXXa,b links |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment