Commit 294aa6c8 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

Add square configuration

parent 334a148f
#!/bin/bash -ex
# topo square creates the following network topology:
#
#
# A --------- br0 -------- B
# | ab ba |
# |ac bd|
# | |
# | |
# | |
# br1 br3
# | |
# | |
# | |
# |ca db|
# | cd dc |
# C ---------- br2 ------- D
#
#
#
# should be run under unshare -mrun .
# use nsenter --net={A,B,C,D} to enter into network namespace of A/B/C/D.
#
# Based on https://github.com/troglobit/smcroute/tree/master/test
rm -f A B C D
touch A B C D
PID=$$
# A-br0-B
unshare --net=B --mount=B -- ip link set lo up
nsenter --net=B -- ip link add ba type veth peer BA
nsenter --net=B -- ip link set BA netns $PID
nsenter --net=B -- ip link set ba up
ip link set BA up
unshare --net=A -- ip link set lo up
nsenter --net=A -- ip link add ab type veth peer AB
nsenter --net=A -- ip link set AB netns $PID
nsenter --net=A -- ip link set ab up
ip link set AB up
ip link add br0 type bridge # vlan_filtering 1 mcast_snooping 0
ip link set BA master br0
ip link set AB master br0
ip link set br0 up
# A-br1-C
nsenter --net=A -- ip link add ac type veth peer AC
nsenter --net=A -- ip link set AC netns $PID
nsenter --net=A -- ip link set ac up
ip link set AC up
unshare --net=C -- ip link set lo up
nsenter --net=C -- ip link add ca type veth peer CA
nsenter --net=C -- ip link set CA netns $PID
nsenter --net=C -- ip link set ca up
ip link set CA up
ip link add br1 type bridge # vlan_filtering 1 mcast_snooping 0
ip link set CA master br1
ip link set AC master br1
ip link set br1 up
# C-br2-D
nsenter --net=C -- ip link add cd type veth peer CD
nsenter --net=C -- ip link set CD netns $PID
nsenter --net=C -- ip link set cd up
ip link set CD up
unshare --net=D -- ip link set lo up
nsenter --net=D -- ip link add dc type veth peer DC
nsenter --net=D -- ip link set DC netns $PID
nsenter --net=D -- ip link set dc up
ip link set DC up
ip link add br2 type bridge # vlan_filtering 1 mcast_snooping 0
ip link set CD master br2
ip link set DC master br2
ip link set br2 up
# B-br3-D
nsenter --net=B -- ip link add bd type veth peer BD
nsenter --net=B -- ip link set BD netns $PID
nsenter --net=B -- ip link set bd up
ip link set BD up
nsenter --net=D -- ip link add db type veth peer DB
nsenter --net=D -- ip link set DB netns $PID
nsenter --net=D -- ip link set db up
ip link set DB up
ip link add br3 type bridge # vlan_filtering 1 mcast_snooping 0
ip link set BD master br3
ip link set DB master br3
ip link set br3 up
# addresses
nsenter --net=B -- ip addr add 10.0.0.1/24 dev ba
nsenter --net=A -- ip addr add 10.0.0.2/24 dev ab
nsenter --net=C -- ip addr add 20.0.0.1/24 dev ca
nsenter --net=A -- ip addr add 20.0.0.2/24 dev ac
nsenter --net=B -- ip addr add 30.0.0.1/24 dev bd
nsenter --net=D -- ip addr add 30.0.0.2/24 dev db
nsenter --net=C -- ip addr add 40.0.0.1/24 dev cd
nsenter --net=D -- ip addr add 40.0.0.2/24 dev dc
# 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
#
#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
# pim-dm
sed -e 's/IF0/ab/g' -e 's/IF1/ac/g' pim-dm.yaml.tmpl > pim-dm_A.yaml
sed -e 's/IF0/ba/g' -e 's/IF1/bd/g' pim-dm.yaml.tmpl > pim-dm_B.yaml
sed -e 's/IF0/ca/g' -e 's/IF1/cd/g' pim-dm.yaml.tmpl > pim-dm_C.yaml
sed -e 's/IF0/dc/g' -e 's/IF1/db/g' pim-dm.yaml.tmpl > pim-dm_D.yaml
# we need to mount private /var/run in each namespace so that pim-dm can be started
#nsenter --net=A -- pim-dm -config pim-dm_A.yaml &
#nsenter --net=B -- pim-dm -config pim-dm_B.yaml &
#nsenter --net=C -- pim-dm -config pim-dm_C.yaml &
#nsenter --net=D -- pim-dm -config pim-dm_D.yaml &
# open terminals in A B C D for play
nsenter --net=A -- xfce4-terminal --title=A &
nsenter --net=B -- xfce4-terminal --title=B &
nsenter --net=C -- xfce4-terminal --title=C &
nsenter --net=D -- xfce4-terminal --title=D &
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