summaryrefslogtreecommitdiffstats
path: root/tests/network-setup.sh
blob: 3e28c9618f69f9833d1fefb8a1aa5ff6a7509ff1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/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 .././tiptorrent --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