#!/bin/bash if [ $UID -ne 0 ] then echo "You must be root to run this test script" exit 0 fi # / c1 # /- c2 # srv ----- br -- c3 # \- c4 start () { ip netns add srv ip netns add br ip netns add c1 ip netns add c2 ip netns add c3 ip netns add c4 ip link add veth0 netns srv type veth peer name veth0 netns br ip link add veth1 netns br type veth peer name veth0 netns c1 ip link add veth2 netns br type veth peer name veth0 netns c2 ip link add veth3 netns br type veth peer name veth0 netns c3 ip link add veth4 netns br type veth peer name veth0 netns c4 ip -net br link set up dev veth0 ip -net br link set up dev veth1 ip -net br link set up dev veth2 ip -net br link set up dev veth3 ip -net br link set up dev veth4 ip -net br link add name br0 type bridge ip -net br link set dev veth0 master br0 ip -net br link set dev veth1 master br0 ip -net br link set dev veth2 master br0 ip -net br link set dev veth3 master br0 ip -net br link set dev veth4 master br0 ip -net br link set up dev br0 ip -net srv addr add 10.141.10.1/24 dev veth0 ip -net srv link set up dev veth0 ip netns exec srv .././grepo --max-clients 1 --redirect --root . & ip -net c1 addr add 10.141.10.2/24 dev veth0 ip -net c1 link set up dev veth0 ip netns exec c1 .././tiptorrent --max-clients 1 & ip -net c2 addr add 10.141.10.3/24 dev veth0 ip -net c2 link set up dev veth0 ip netns exec c2 .././tiptorrent --max-clients 1 & ip -net c3 addr add 10.141.10.4/24 dev veth0 ip -net c3 link set up dev veth0 ip netns exec c3 .././tiptorrent --max-clients 1 & ip -net c4 addr add 10.141.10.5/24 dev veth0 ip -net c4 link set up dev veth0 ip netns exec c4 .././tiptorrent --max-clients 1 & } stop () { ip netns del srv ip netns del br ip netns del c1 ip netns del c2 ip netns del c3 ip netns del c4 killall -15 tiptorrent } case $1 in start) start ;; stop) stop ;; *) echo "$0 [start|stop]" ;; esac exit 0