Newer
Older
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
if [ -z "$1" ]; then
echo "Not given the file to send"
exit 1
fi
# If the directory does not exist, we create it
if [ ! -d "tests_logs/advanced_tests/" ]; then
mkdir 'tests_logs/advanced_tests/' 2>/dev/null
fi
FILENAME=$1
BASENAME=$(basename $FILENAME)
BSN_PRE="${BASENAME%.*}"
BSN_EXT="${BASENAME##*.}"
TEST_OUTPUT_FILES="tests_logs/advanced_tests/${BSN_PRE}"
mkdir "${TEST_OUTPUT_FILES}/" 2>/dev/null
MODES=(
'with_FEC'
'without_FEC'
)
ERROR_RATE=20
CUT_RATE=30
DELAY=0
JITTER=0
LOSS_RATE=25
echo -e "The linksimulator paramateres are:
\t\t-ERROR RATE: ${ERROR_RATE}% \t-DELAY: ${DELAY}ms
\t\t-CUT RATE: ${CUT_RATE}% \t-JITTER: ${JITTER}ms
\t\t-LOSS RATE: ${LOSS_RATE}%\n"
for MODE in "${MODES[@]}"; do
mkdir "${TEST_OUTPUT_FILES}/${MODE}/" 2>/dev/null
DIR="${TEST_OUTPUT_FILES}/${MODE}"
Vany Ingenzi
a validé
touch "${DIR}/adv_${BSN_PRE}_received_file.${BSN_EXT}" \
"${DIR}/adv_valgrind_${BSN_PRE}_receiver.log" \
"${DIR}/adv_valgrind_${BSN_PRE}_sender.log" \
"${DIR}/${BSN_PRE}_receiver_stats.csv" \
"${DIR}/${BSN_PRE}_sender_stats.csv"
# The next 2 lines come from: https://unix.stackexchange.com/questions/55913/whats-the-easiest-way-to-find-an-unused-local-port
# We use this to be sure we're using unused port
port1=$(comm -23 <(seq 65000 65200 | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1)
port2=$(comm -23 <(seq 65000 65200 | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1)
##### Launching the link simulator #####
./linksimulator/link_sim -p $port2 -P $port1 -l $LOSS_RATE -d $DELAY -e $ERROR_RATE -c $CUT_RATE -j $JITTER \
&>${DIR}/adv_${BSN_PRE}_link.log & link_pid=$!
##### Launching the receiver and capturinig its output #####
valgrind --leak-check=full --log-file=${DIR}/adv_valgrind_${BSN_PRE}_receiver.log \
./receiver ::1 $port1 -s ${DIR}/${BSN_PRE}_receiver_stats.csv 1> ${DIR}/adv_${BSN_PRE}_received_file.${BSN_EXT} \
2> ${DIR}/adv_${BSN_PRE}_receiver.log & receiver_pid=$!
cleanup()
{
kill -9 $receiver_pid
kill -9 $link_pid
exit 0
}
trap cleanup SIGINT # Kill the background procces in case of ^-C
# Checking the mode (with out without FEC)
if [ $MODE = "with_FEC" ]; then
# We start the transfer
if ! valgrind --leak-check=full --log-file=${DIR}/adv_valgrind_${BSN_PRE}_sender.log \
./sender -f ${FILENAME} ::1 $port2 -c -s ${DIR}/${BSN_PRE}_sender_stats.csv 2> ${DIR}/adv_${BSN_PRE}_sender.log ; then
echo "The sender crashed!"
cat ${DIR}/adv_${BSN_PRE}_sender.log
err=1 # We record the error
fi
else
# We start the transfer
if ! valgrind --leak-check=full --log-file=${DIR}/adv_valgrind_${BSN_PRE}_sender.log \
./sender -f ${FILENAME} ::1 $port2 -s ${DIR}/${BSN_PRE}_sender_stats.csv 2> ${DIR}/adv_${BSN_PRE}_sender.log ; then
echo "The sender crashed!"
cat ${DIR}/adv_${BSN_PRE}_sender.log
err=1 # We record the error
fi
fi
sleep 5 # We wait 5s for the receiver to finish up
if kill -0 $receiver_pid &> /dev/null ; then
echo "The receiver didn't stop at the end of the transfer!"
kill -9 $receiver_pid
else # We check the return value of the receiver
if ! wait $receiver_pid ; then
echo "Crash of the receiver!"
cat ${DIR}/adv_${BSN_PRE}_receiver.log
err=1
fi
# Stop the link simulator
kill -9 $link_pid
wait $link_pid 2>/dev/null
# We verify that the transfer ran through properly
if [[ "$(md5sum ${FILENAME} | awk '{print $1}')" != "$(md5sum ${DIR}/adv_${BSN_PRE}_received_file.${BSN_EXT} | awk '{print $1}')" ]]; then
echo "The transfer corrupted the file!"
echo "Binary difference between the 2 files: (expected vs actual)"
diff -C 9 <(od -Ax -t x1z ${FILENAME}) <(od -Ax -t x1z ${DIR}/adv_${BSN_PRE}_received_file.${BSN_EXT})
if [ $MODE = "with_FEC" ]; then
echo -e "${RED}The transfer (with FEC) has failed!${NC}"
echo -e "${RED}The transfer (without FEC) has failed!${NC}"
fi
exit 1
else
if [ $MODE = "with_FEC" ]; then
echo -e "${GREEN}The transfer (with FEC) has succeeded!${NC}"
echo -e "${GREEN}The transfer (without FEC) has succeeded!${NC}"
fi
fi
done
exit ${err:-0} # In case of error, we return the error code