82 lines
1.8 KiB
Bash
82 lines
1.8 KiB
Bash
#!/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
|
|
|
|
TOTAL_CLIENTS=18
|
|
|
|
start () {
|
|
NUM_CLIENTS=4
|
|
SERVER_LINK=10000
|
|
CLIENT_LINK=1000
|
|
NUM_REDIRECT=1
|
|
LATENCY=20
|
|
|
|
ip netns add srv
|
|
ip netns add br
|
|
for ((i=1; i<=TOTAL_CLIENTS; i++)); do
|
|
ip netns add c$i
|
|
done
|
|
|
|
ip link add veth0 netns srv type veth peer name veth0 netns br
|
|
for ((i=1; i<=TOTAL_CLIENTS; i++)); do
|
|
ip link add veth$i netns br type veth peer name veth0 netns c$i
|
|
done
|
|
|
|
for ((i=0; i<=TOTAL_CLIENTS; i++)); do
|
|
ip -net br link set up dev veth$i
|
|
done
|
|
|
|
ip -net br link add name br0 type bridge
|
|
for ((i=0; i<=TOTAL_CLIENTS; i++)); do
|
|
ip -net br link set dev veth$i master br0
|
|
done
|
|
|
|
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 tc qdisc add dev veth0 handle 10: root tbf rate "$SERVER_LINK"mbit burst 5kb latency "$LATENCY"ms
|
|
ip netns exec srv tc qdisc add dev veth0 parent 10:1 handle 100: sfq
|
|
ip netns exec srv .././tiptorrent --max-clients $NUM_CLIENTS --redirect $NUM_REDIRECT --root . &
|
|
|
|
for ((i=1; i<=TOTAL_CLIENTS; i++)); do
|
|
ip -net c$i addr add 10.141.10.$((i+1))/24 dev veth0
|
|
ip -net c$i link set up dev veth0
|
|
ip netns exec c$i tc qdisc add dev veth0 handle 10: root tbf rate "$CLIENT_LINK"mbit burst 5kb latency "$LATENCY"ms
|
|
ip netns exec c$i tc qdisc add dev veth0 parent 10:1 handle 100: sfq
|
|
ip netns exec c$i .././tiptorrent --max-clients $NUM_REDIRECT &
|
|
done
|
|
}
|
|
|
|
stop () {
|
|
ip netns del srv
|
|
ip netns del br
|
|
for ((i=1; i<=TOTAL_CLIENTS; i++)); do
|
|
ip netns del c$i
|
|
done
|
|
killall -15 tiptorrent
|
|
}
|
|
|
|
case $1 in
|
|
start)
|
|
start
|
|
;;
|
|
stop)
|
|
stop
|
|
;;
|
|
*)
|
|
echo "$0 [start|stop]"
|
|
;;
|
|
esac
|
|
|
|
exit 0
|