Commit 9e784c62 authored by Kirill Smelkov's avatar Kirill Smelkov

B-A-C: Also organized dedicated mount namespace for each host

So that smcrouted could be run separately on each.
parent 975a462a
......@@ -9,25 +9,41 @@
#
#
# should be run under unshare -mrun .
# use nsenter --net={A,B,C} to enter into network namespace of A/B/C.
# use xnsenter {A,B,C} to enter into namespaces of A/B/C.
#
# Based on https://github.com/troglobit/smcroute/tree/master/test
rm -f A B C
touch A B C
rm -rf A B C
mkdir A B C
PID=$$
# `xunshare <dir> ...` -- unshare net/mount/... namespaces to be referenced by dir
xunshare() {
ref=$1
shift
touch $ref/mnt $ref/net
unshare --mount=$ref/mnt --net=$ref/net "$@"
}
# `xnsenter <dir> ...` -- nsenter net/mount/... namespaces to be referenced by dir
xnsenter() {
ref=$1
shift
nsenter --mount=$ref/mnt --net=$ref/net --wd=. "$@"
}
# B-br0-A
unshare --net=B -- ip link set lo up
nsenter --net=B -- ip link add b1 type veth peer B1
nsenter --net=B -- ip link set B1 netns $PID
nsenter --net=B -- ip link set b1 up
xunshare B -- ip link set lo up
xnsenter B -- ip link add b1 type veth peer B1
xnsenter B -- ip link set B1 netns $PID
xnsenter B -- ip link set b1 up
ip link set B1 up
unshare --net=A -- ip link set lo up
nsenter --net=A -- ip link add a1 type veth peer A1
nsenter --net=A -- ip link set A1 netns $PID
nsenter --net=A -- ip link set a1 up
xunshare A -- ip link set lo up
xnsenter A -- ip link add a1 type veth peer A1
xnsenter A -- ip link set A1 netns $PID
xnsenter A -- ip link set a1 up
ip link set A1 up
ip link add br0 type bridge # vlan_filtering 1 mcast_snooping 0
......@@ -36,15 +52,15 @@ ip link set A1 master br0
ip link set br0 up
# A-br1-C
nsenter --net=A -- ip link add a2 type veth peer A2
nsenter --net=A -- ip link set A2 netns $PID
nsenter --net=A -- ip link set a2 up
xnsenter A -- ip link add a2 type veth peer A2
xnsenter A -- ip link set A2 netns $PID
xnsenter A -- ip link set a2 up
ip link set A2 up
unshare --net=C -- ip link set lo up
nsenter --net=C -- ip link add c1 type veth peer C1
nsenter --net=C -- ip link set C1 netns $PID
nsenter --net=C -- ip link set c1 up
xunshare C -- ip link set lo up
xnsenter C -- ip link add c1 type veth peer C1
xnsenter C -- ip link set C1 netns $PID
xnsenter C -- ip link set c1 up
ip link set C1 up
ip link add br1 type bridge # vlan_filtering 1 mcast_snooping 0
......@@ -54,27 +70,32 @@ ip link set br1 up
# addresses
nsenter --net=B -- ip addr add 10.0.0.1/24 dev b1
nsenter --net=A -- ip addr add 10.0.0.2/24 dev a1
nsenter --net=C -- ip addr add 20.0.0.1/24 dev c1
nsenter --net=A -- ip addr add 20.0.0.2/24 dev a2
xnsenter B -- ip addr add 10.0.0.1/24 dev b1
xnsenter A -- ip addr add 10.0.0.2/24 dev a1
xnsenter C -- ip addr add 20.0.0.1/24 dev c1
xnsenter A -- ip addr add 20.0.0.2/24 dev a2
# multicast routing
nsenter --net=B -- ip route add 224.0.0.0/4 dev b1
nsenter --net=C -- ip route add 224.0.0.0/4 dev c1
xnsenter B -- ip route add 224.0.0.0/4 dev b1
xnsenter C -- ip route add 224.0.0.0/4 dev c1
nsenter --net=A -- ip route add 224.0.0.0/4 dev a1 # NOTE on A 224.0.0.0/4 is routed
nsenter --net=A -- ip route append 224.0.0.0/4 dev a2 # to _both_ a1 and a2
xnsenter A -- ip route add 224.0.0.0/4 dev a1 # NOTE on A 224.0.0.0/4 is routed
xnsenter A -- ip route append 224.0.0.0/4 dev a2 # to _both_ a1 and a2
# mount private /var/run so that smcrouted can be started
# we start will start it only in A, so keeping /var/run shared to everywhere,
# even if dirty, is ok.
mount -t tmpfs none /var/run
xnsenter A -- mount -t tmpfs none /var/run
xnsenter B -- mount -t tmpfs none /var/run
xnsenter C -- mount -t tmpfs none /var/run
echo
echo
echo
xnsenter B -- pwd
# open terminals in A B C for play
nsenter --net=B -- xfce4-terminal --title=B &
nsenter --net=C -- xfce4-terminal --title=C &
nsenter --net=A -- xfce4-terminal --title=A &
nsenter --net=A -- xfce4-terminal --title=A2 &
xnsenter B -- xfce4-terminal --title=B &
xnsenter C -- xfce4-terminal --title=C &
xnsenter A -- xfce4-terminal --title=A &
xnsenter A -- xfce4-terminal --title=A2 &
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment