2019-07-31 13:13:31 +00:00
#!/bin/bash
## EXPERIMENT RUNNER
2019-09-14 17:15:22 +00:00
# exemple: sudo ./scripts/run-3 2 . orig-client 100 100 100, orig-client 100 100 100 . orig-server, orig-server
2019-07-31 13:13:31 +00:00
die() { echo "$*" 1>&2 ; exit 1; }
2020-01-19 19:43:02 +00:00
DOCKNAME=`mktemp -u XXXXX`
2020-01-13 16:48:35 +00:00
WAITFOR=7200 # 2 hours
2019-07-31 13:13:31 +00:00
# SPLIT CLIENT AND SERVER TARGETS
OLD_IFS=$IFS; IFS="."
read -a PARTS <<< "$@"
IFS=$OLD_IFS
2019-09-04 08:01:00 +00:00
[[ ${#PARTS[@]} == 5 ]] || die "Separate count, clients, servers experiments and tor daemon command by dots. I expect 5 parts but got ${#PARTS[@]}"
2019-07-31 13:13:31 +00:00
# EXTRACT DATA
OLD_IFS=$IFS; IFS=","
read -a CONFIG <<< "${PARTS[0]}"
read -a CLIENT_TARGETS <<< "${PARTS[1]}"
read -a SERVER_TARGETS <<< "${PARTS[2]}"
2019-09-04 08:01:00 +00:00
read -a TOR_DAEMON_CLIENT <<< "${PARTS[3]}"
read -a TOR_DAEMON_SERVER <<< "${PARTS[4]}"
2019-07-31 13:13:31 +00:00
IFS=$OLD_IFS
[[ ${#CLIENT_TARGETS[@]} == ${#SERVER_TARGETS[@]} ]] \
2019-09-04 08:01:00 +00:00
&& [[ ${#SERVER_TARGETS[@]} == ${#TOR_DAEMON_CLIENT[@]} ]] \
&& [[ ${#TOR_DAEMON_CLIENT[@]} == ${#TOR_DAEMON_SERVER[@]} ]] \
|| die "Same number of declaration is required. Got ${#CLIENT_TARGETS[@]} clients, ${#SERVER_TARGETS[@]} servers, ${#TOR_DAEMON_CLIENT[@]} Tor daemon clients and ${#TOR_DAEMON_SERVER[@]} Tor daemon servers"
2019-07-31 13:13:31 +00:00
instances=${#CLIENT_TARGETS[@]}
REPEAT=${CONFIG[0]}
2019-09-05 08:06:14 +00:00
IDENTIFIER=${CONFIG[1]}
2019-07-31 13:13:31 +00:00
echo ":: Configuration Summary"
2019-09-05 08:06:14 +00:00
echo "repeat=$REPEAT, identifier=$IDENTIFIER"
2019-07-31 13:13:31 +00:00
for i in $(seq 0 $(expr $instances - 1)); do
2019-09-04 08:01:00 +00:00
echo " instance=$i - server=${SERVER_TARGETS[$i]} - client=${CLIENT_TARGETS[$i]} - tor server=${TOR_DAEMON_SERVER[$i]} - tor client=${TOR_DAEMON_CLIENT[$i]}"
2019-07-31 13:13:31 +00:00
done
echo ":: Bootstrap"
echo "Create output folder..."
docker run \
--rm \
--user root \
2019-09-05 08:06:14 +00:00
-v `pwd`/out:/home/donar/out \
2019-07-31 13:13:31 +00:00
registry.gitlab.inria.fr/qdufour/donar \
2019-07-31 13:32:47 +00:00
chown -R 1000:1000 /home/donar
2019-07-31 13:13:31 +00:00
echo ":: Start experiment..."
for j in $(seq 1 $REPEAT); do
2019-09-05 08:06:14 +00:00
run_fold=`mktemp -up ./out XXXXXXXXXXXXXXXX`
echo "start - batch_count=$j - folder=$run_fold"
2019-07-31 13:13:31 +00:00
2019-09-15 07:18:09 +00:00
echo "__reset containers"
2019-07-31 13:13:31 +00:00
for i in $(seq 0 $(expr $instances - 1)); do
2019-09-06 15:03:51 +00:00
2019-09-15 07:18:09 +00:00
echo "____clear $i"
2020-01-19 19:43:02 +00:00
docker container inspect ${DOCKNAME}_donarxp_server_${i} > /dev/null 2>&1 && docker kill ${DOCKNAME}_donarxp_server_${i}
docker container inspect ${DOCKNAME}_donarxp_client_${i} > /dev/null 2>&1 && docker kill ${DOCKNAME}_donarxp_client_${i}
2019-09-15 07:18:09 +00:00
echo "____spawning container for instance=$i..."
docker run \
--rm \
-d \
2020-01-19 19:43:02 +00:00
--name "${DOCKNAME}_donarxp_server_${i}" \
2019-09-16 14:01:40 +00:00
--privileged \
--cap-add=SYS_PTRACE \
--security-opt seccomp=unconfined \
2019-09-15 07:18:09 +00:00
-e HOME='/tmp' \
-v `pwd`/out:/home/donar/out \
registry.gitlab.inria.fr/qdufour/donar \
${TOR_DAEMON_SERVER[$i]}
docker run \
--rm \
-d \
2019-09-16 14:01:40 +00:00
--privileged \
--cap-add=SYS_PTRACE \
--security-opt seccomp=unconfined \
2020-01-19 19:43:02 +00:00
--name "${DOCKNAME}_donarxp_client_${i}" \
2019-09-15 07:18:09 +00:00
-e HOME='/tmp' \
-v `pwd`/out:/home/donar/out \
registry.gitlab.inria.fr/qdufour/donar \
${TOR_DAEMON_CLIENT[$i]}
echo "____create folder struct..."
2020-01-19 19:43:02 +00:00
docker exec ${DOCKNAME}_donarxp_client_${i} sh -c "mkdir -p $run_fold-$i; echo repeat=$REPEAT,identifier=$IDENTIFIER > $run_fold-$i/info.txt"
docker exec ${DOCKNAME}_donarxp_client_${i} sh -c "echo instance=$i - server=${SERVER_TARGETS[$i]} - client=${CLIENT_TARGETS[$i]} - tor server=${TOR_DAEMON_SERVER[$i]} - tor client=${TOR_DAEMON_CLIENT[$i]}>> $run_fold-$i/info.txt"
2019-07-31 13:13:31 +00:00
done
2019-09-15 07:18:09 +00:00
sleep 10
echo "__launch servers"
2019-07-31 13:13:31 +00:00
for i in $(seq 0 $(expr $instances - 1)); do
echo " instance=$i - exec=${SERVER_TARGETS[$i]}"
2020-01-19 19:43:02 +00:00
docker exec ${DOCKNAME}_donarxp_server_$i ${SERVER_TARGETS[$i]} ${run_fold}-$i &
2019-10-24 14:48:58 +00:00
sleep 1
2019-07-31 13:13:31 +00:00
done
2019-10-24 14:48:58 +00:00
sleep 2
2019-09-15 07:18:09 +00:00
echo "__launch clients"
2019-07-31 13:13:31 +00:00
(subshellpid=$BASHPID
(sleep $WAITFOR; echo " timeout"; kill -9 $subshellpid) &
(for i in $(seq 0 $(expr $instances - 1)); do
echo " instance=$i - exec=${CLIENT_TARGETS[$i]}"
2020-01-19 19:43:02 +00:00
docker exec ${DOCKNAME}_donarxp_client_$i ${CLIENT_TARGETS[$i]} ${run_fold}-$i &
2019-10-24 14:48:58 +00:00
sleep 1
2019-09-14 17:15:22 +00:00
done;
wait;
echo " ok";
for i in $(seq 0 $(expr $instances - 1)); do
2020-01-19 19:43:02 +00:00
docker exec ${DOCKNAME}_donarxp_client_${i} killall -15 donar;
docker exec ${DOCKNAME}_donarxp_server_${i} killall -15 donar;
2019-09-14 17:15:22 +00:00
done;
kill -15 $subshellpid
)) 2>/dev/null
2019-07-31 13:13:31 +00:00
2019-09-06 15:03:51 +00:00
echo "done"
2019-07-31 13:13:31 +00:00
done
echo ":: Clear Resources"
for i in $(seq 0 $(expr $instances - 1)); do
echo "clear $i"
2020-01-19 19:43:02 +00:00
docker kill "${DOCKNAME}_donarxp_server_${i}"
docker kill "${DOCKNAME}_donarxp_client_${i}"
2019-07-31 13:13:31 +00:00
done