Skip to content

Instantly share code, notes, and snippets.

@T-X
Created May 18, 2019 19:08
Show Gist options
  • Save T-X/91a3aa37e5056adac051d767cdf4e2c2 to your computer and use it in GitHub Desktop.
Save T-X/91a3aa37e5056adac051d767cdf4e2c2 to your computer and use it in GitHub Desktop.
#!/bin/sh
PIMDEBUG="-d pim_bootstrap,pim_join_prune"
PIMD="/home/linus/dev-priv/pim6sd/src/pim6sd $PIMDEBUG"
NSR0="ip netns exec pimtest-router0"
NSR1="ip netns exec pimtest-router1"
NSR2="ip netns exec pimtest-router2"
NSC0="ip netns exec pimtest-client0"
NSC1="ip netns exec pimtest-client1"
NSC2="ip netns exec pimtest-client2"
setup() {
### Wiring
ip netns add pimtest-router0
ip netns add pimtest-router1
ip netns add pimtest-router2
ip netns add pimtest-client0
ip netns add pimtest-client1
ip netns add pimtest-client2
# router0 <-> router1 (wan0 <-> wan0)
$NSR0 ip link add wan0 type veth peer name wan1
$NSR0 ip link set addr 02:11:22:00:00:02 netns pimtest-router1 name wan0 up dev wan1
$NSR0 ip link set addr 02:11:22:00:00:01 up dev wan0
# router1 <-> router2 (wan1 <-> wan0)
$NSR1 ip link add wan1 type veth peer name wan2
$NSR1 ip link set addr 02:11:22:00:01:03 netns pimtest-router2 name wan0 up dev wan2
$NSR1 ip link set addr 02:11:22:00:01:02 up dev wan1
# lan0: router0 <-> client0
$NSC0 ip link add lan0 type veth peer name lan1
$NSC0 ip link set netns pimtest-router0 name lan0 up dev lan1
$NSC0 ip link set up dev lan0
# lan0: router1 <-> client1
$NSC1 ip link add lan0 type veth peer name lan1
$NSC1 ip link set netns pimtest-router1 name lan0 up dev lan1
$NSC1 ip link set up dev lan0
# lan0: router2 <-> client2
$NSC2 ip link add lan0 type veth peer name lan1
$NSC2 ip link set netns pimtest-router2 name lan0 up dev lan1
$NSC2 ip link set up dev lan0
# dummy interface holding the RP and BSR address
$NSR0 ip link add name pim-router-id type dummy
$NSR1 ip link add name pim-router-id type dummy
$NSR2 ip link add name pim-router-id type dummy
$NSR0 ip link set multicast on up dev pim-router-id
$NSR1 ip link set multicast on up dev pim-router-id
$NSR2 ip link set multicast on up dev pim-router-id
### Addresses
$NSR0 ip address add fd5c:725:2841:4201::2/128 dev pim-router-id
$NSR1 ip address add fd5c:725:2841:4202::2/128 dev pim-router-id
$NSR2 ip address add fd5c:725:2841:4203::2/128 dev pim-router-id
$NSR0 ip address add fd5c:725:2841::1/64 dev wan0
$NSR1 ip address add fd5c:725:2841::2/64 dev wan0
$NSR1 ip address add fd5c:725:2841:1::2/64 dev wan1
$NSR2 ip address add fd5c:725:2841:1::3/64 dev wan0
$NSR0 ip address add fd5c:725:2841:101::1/64 dev lan0
$NSR1 ip address add fd5c:725:2841:102::1/64 dev lan0
$NSR2 ip address add fd5c:725:2841:103::1/64 dev lan0
$NSC0 ip address add fd5c:725:2841:101::2/64 dev lan0
$NSC1 ip address add fd5c:725:2841:102::2/64 dev lan0
$NSC2 ip address add fd5c:725:2841:103::2/64 dev lan0
### Routing
$NSR0 /bin/bash -c "echo 1 > /proc/sys/net/ipv6/conf/all/forwarding"
$NSR1 /bin/bash -c "echo 1 > /proc/sys/net/ipv6/conf/all/forwarding"
$NSR2 /bin/bash -c "echo 1 > /proc/sys/net/ipv6/conf/all/forwarding"
# router0 -> router2
$NSR0 ip -6 r add fd5c:725:2841:1::/64 via fd5c:725:2841::2
# router2 -> router0
$NSR2 ip -6 route add fd5c:725:2841::/64 via fd5c:725:2841:1::2
# router0 -> {client1, client2}
$NSR0 ip -6 r add fd5c:725:2841:102::/64 via fd5c:725:2841::2
$NSR0 ip -6 r add fd5c:725:2841:103::/64 via fd5c:725:2841::2
# router1 -> {client0, client2}
$NSR1 ip -6 r add fd5c:725:2841:101::/64 via fd5c:725:2841::1
$NSR1 ip -6 r add fd5c:725:2841:103::/64 via fd5c:725:2841:1::3
# router2 -> {client0, client0}
$NSR2 ip -6 r add fd5c:725:2841:101::/64 via fd5c:725:2841:1::2
$NSR2 ip -6 r add fd5c:725:2841:102::/64 via fd5c:725:2841:1::2
# router0 -> router-id: {router1, router2}
$NSR0 ip -6 r add fd5c:725:2841:4202::/64 via fd5c:725:2841::2
$NSR0 ip -6 r add fd5c:725:2841:4203::/64 via fd5c:725:2841::2
# router1 -> router-id: {router0, router2}
$NSR1 ip -6 r add fd5c:725:2841:4201::/64 via fd5c:725:2841::1
$NSR1 ip -6 r add fd5c:725:2841:4203::/64 via fd5c:725:2841:1::3
# router2 -> router-id: {router0, router1}
$NSR2 ip -6 r add fd5c:725:2841:4201::/64 via fd5c:725:2841:1::2
$NSR2 ip -6 r add fd5c:725:2841:4202::/64 via fd5c:725:2841:1::2
# client* -> *
$NSC0 ip -6 route add default via fd5c:725:2841:101::1
$NSC1 ip -6 route add default via fd5c:725:2841:102::1
$NSC2 ip -6 route add default via fd5c:725:2841:103::1
}
teardown() {
$NSR0 ip address flush dev wan0
$NSR1 ip address flush dev wan0
$NSR1 ip address flush dev wan1
$NSR2 ip address flush dev wan0
$NSR0 ip link del dev wan0
$NSR1 ip link del dev wan1
$NSR0 ip link del dev lan0
$NSR1 ip link del dev lan0
$NSR2 ip link del dev lan0
ip netns delete pimtest-router0
ip netns delete pimtest-router1
ip netns delete pimtest-router2
ip netns delete pimtest-client0
ip netns delete pimtest-client1
ip netns delete pimtest-client2
}
start_services() {
mkdir /tmp/pimtest 2> /dev/null
cat > /tmp/pimtest/router0.conf <<EOF
default_phyint_status disable;
phyint pim-router-id enable;
phyint wan0 enable;
phyint lan0 enable;
EOF
cat > /tmp/pimtest/router1.conf <<EOF
default_phyint_status disable;
phyint pim-router-id enable;
phyint wan0 enable;
phyint wan1 enable;
phyint lan0 enable;
EOF
cat > /tmp/pimtest/router2.conf <<EOF
default_phyint_status disable;
phyint pim-router-id enable;
phyint wan0 enable;
phyint lan0 enable;
cand_rp pim-router-id;
group_prefix ff7e:0240:fd5c:725:2841:4203::/96;
EOF
$NSR0 $PIMD -n -f /tmp/pimtest/router0.conf > /tmp/pimtest/router0.log 2>&1 &
echo "$!" > /tmp/pimtest/router0.pid
$NSR1 $PIMD -n -f /tmp/pimtest/router1.conf > /tmp/pimtest/router1.log 2>&1 &
echo "$!" > /tmp/pimtest/router1.pid
# $NSR2 $PIMD -n -f /tmp/pimtest/router2.conf > /tmp/pimtest/router2.log 2>&1 &
$NSR2 /bin/bash -c "ulimit -c unlimited; $PIMD -n -f /tmp/pimtest/router2.conf > /tmp/pimtest/router2.log 2>&1" &
echo "$!" > /tmp/pimtest/router2.pid
$NSC0 socat -u UDP6-RECV:1234,reuseaddr,ipv6-join-group="[ff7e:0240:fd5c:725:2841:4203::123]:lan0" - &
echo "$!" > /tmp/pimtest/client0.pid
$NSC1 socat -u UDP6-RECV:1234,reuseaddr,ipv6-join-group="[ff7e:0240:fd5c:725:2841:4203::123]:lan0" - &
echo "$!" > /tmp/pimtest/client1.pid
$NSC2 ping6 -t 16 -q ff7e:0240:fd5c:725:2841:4203::123 2> /dev/null &
echo "$!" > /tmp/pimtest/client2.pid
}
stop_services() {
[ -f /tmp/pimtest/router0.pid ] && \
kill $(cat /tmp/pimtest/router0.pid)
[ -f /tmp/pimtest/router1.pid ] && \
kill $(cat /tmp/pimtest/router1.pid)
[ -f /tmp/pimtest/router2.pid ] && \
kill $(cat /tmp/pimtest/router2.pid)
[ -f /tmp/pimtest/client0.pid ] && \
kill $(cat /tmp/pimtest/client0.pid)
[ -f /tmp/pimtest/client1.pid ] && \
kill $(cat /tmp/pimtest/client1.pid)
[ -f /tmp/pimtest/client2.pid ] && \
kill $(cat /tmp/pimtest/client2.pid)
rm /tmp/pimtest/router0.pid 2> /dev/null
rm /tmp/pimtest/router1.pid 2> /dev/null
rm /tmp/pimtest/router2.pid 2> /dev/null
rm /tmp/pimtest/client0.pid 2> /dev/null
rm /tmp/pimtest/client1.pid 2> /dev/null
rm /tmp/pimtest/client2.pid 2> /dev/null
rm /tmp/pimtest/router0.conf 2> /dev/null
rm /tmp/pimtest/router1.conf 2> /dev/null
rm /tmp/pimtest/router2.conf 2> /dev/null
}
stop_services
teardown
echo "Starting setup"
sleep 3
setup
start_services
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment