Commit 58707f40 authored by Kirill Smelkov's avatar Kirill Smelkov

topo-BAC: Factor out link-establishment into xlink

parent 83e1d02a
# lib.sh is library of common shell functions for topo-* # lib.sh is library of common shell functions for topo-*
PID=$$
# `xunshare <dir> ...` -- unshare net/mount/... namespaces to be referenced by dir # `xunshare <dir> ...` -- unshare net/mount/... namespaces to be referenced by dir
xunshare() { xunshare() {
ref=$1 ref=$1
...@@ -16,3 +18,30 @@ xnsenter() { ...@@ -16,3 +18,30 @@ xnsenter() {
shift shift
nsenter --mount=$ref/mnt --net=$ref/net --wd=. "$@" nsenter --mount=$ref/mnt --net=$ref/net --wd=. "$@"
} }
# `xlink A B` sets up veth links in between nodes A and B going through bridge brAB:
#
# A ------- brAB ------- B
# a-b brAB.a brAB.b b-a
xlink() {
A=$1
B=$2
a="${A,,}" # A -> a
b="${B,,}" # B -> b
xnsenter $A -- ip link add $a-$b type veth peer br$A$B.$a
xnsenter $A -- ip link set br$A$B.$a netns $PID
xnsenter $A -- ip link set $a-$b up
ip link set br$A$B.$a up
xnsenter $B -- ip link add $b-$a type veth peer br$A$B.$b
xnsenter $B -- ip link set br$A$B.$b netns $PID
xnsenter $B -- ip link set $b-$a up
ip link set br$A$B.$b up
ip link add br$A$B type bridge # vlan_filtering 1 mcast_snooping 0
ip link set br$A$B.$a master br$A$B
ip link set br$A$B.$b master br$A$B
ip link set br$A$B up
}
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
# topo B-A-C creates the following network topology: # topo B-A-C creates the following network topology:
# #
# #
# ns:B tns:A ns:C # ns:B ns:A ns:C
# #
# B --- br0 --- A --- br1 --- C # B --- br0 --- A --- br1 --- C
# b1 B1 A1 a1 a2 A2 C1 c1 # b-a a-b a-c c-a
# #
# #
# should be run under unshare -mrun . # should be run under unshare -mrun .
...@@ -15,56 +15,29 @@ ...@@ -15,56 +15,29 @@
. lib.sh . lib.sh
PID=$$
# B-br0-A
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
# lo on everything
xunshare A -- ip link set lo up xunshare A -- ip link set lo up
xnsenter A -- ip link add a1 type veth peer A1 xunshare B -- ip link set lo up
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
ip link set B1 master br0
ip link set A1 master br0
ip link set br0 up
# A-br1-C
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
xunshare C -- ip link set lo 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 # links
ip link set C1 master br1 xlink B A # B-A
ip link set A2 master br1 xlink A C # A-C
ip link set br1 up
# addresses # addresses
xnsenter B -- ip addr add 10.0.0.1/24 dev b1 xnsenter B -- ip addr add 10.0.0.1/24 dev b-a
xnsenter A -- ip addr add 10.0.0.2/24 dev a1 xnsenter A -- ip addr add 10.0.0.2/24 dev a-b
xnsenter C -- ip addr add 20.0.0.1/24 dev c1 xnsenter C -- ip addr add 20.0.0.1/24 dev c-a
xnsenter A -- ip addr add 20.0.0.2/24 dev a2 xnsenter A -- ip addr add 20.0.0.2/24 dev a-c
# multicast routing # multicast routing
xnsenter B -- ip route add 224.0.0.0/4 dev b1 xnsenter B -- ip route add 224.0.0.0/4 dev b-a
xnsenter C -- ip route add 224.0.0.0/4 dev c1 xnsenter C -- ip route add 224.0.0.0/4 dev c-a
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 add 224.0.0.0/4 dev a-b # 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 xnsenter A -- ip route append 224.0.0.0/4 dev a-c # to _both_ a-b and a-c
# mount private /var/run so that smcrouted can be started # mount private /var/run so that smcrouted can be started
......
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