diff --git a/Makefile b/Makefile index 19d84b45c1e2a42f74e9c5dc71a75d011918e931..8368ed96f7e1f8aa23e8cd14a2e204f383bccc90 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,9 @@ makelinksim: tests: debug @./tests/run_tests.sh +interop: debug + @./tests/run_interop.sh + # By default, logs are disabled. But you can enable them with the debug target. debug: CFLAGS += -D_DEBUG debug: clean aux diff --git a/interop/receivers/receiver_group38 b/interop/receivers/receiver_group38 new file mode 100755 index 0000000000000000000000000000000000000000..8c9bf698877cf94ad05c85c56f4fba565b810f68 Binary files /dev/null and b/interop/receivers/receiver_group38 differ diff --git a/interop/senders/sender_group38 b/interop/senders/sender_group38 new file mode 100755 index 0000000000000000000000000000000000000000..ef1250e998dccb1d6e63c9a5a1e727c2930a34a6 Binary files /dev/null and b/interop/senders/sender_group38 differ diff --git a/src/sender_utils.c b/src/sender_utils.c index fdb98c404cef7cf482e66facd0b92bf31e7bece6..cc8e8b53dd8575c74d1ed8bd183a6726a408868a 100644 --- a/src/sender_utils.c +++ b/src/sender_utils.c @@ -77,6 +77,9 @@ bool can_send(sender_state_t *state) /** Cautious this function is used for sending and sending back pkt ! */ int send_pkt(sender_state_t *state, pkt_t *pkt, uint8_t position, int socket_fd) { + // The next line is important for pkt that are sent back (maybe our window size has changed since the last time) + pkt_set_window(pkt, state->s_window_size); + DEBUG("Sending the pkt with seqnum: %d", pkt_get_seqnum(pkt)); char packet_to_be_sent[PKT_MAX_LEN]; size_t len = PKT_MAX_LEN; diff --git a/tests/run_interop.sh b/tests/run_interop.sh new file mode 100644 index 0000000000000000000000000000000000000000..91096ddd8ea11c34a96e840fecbe9b71ab836b2a --- /dev/null +++ b/tests/run_interop.sh @@ -0,0 +1,173 @@ +#!/bin/bash + +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' + + +FILENAME=( + 'tests_files/greetings.txt' + 'tests_files/smile.png' +) + +rm -rf ./tests_logs/* +mkdir 'tests_logs/interop_tests/' 2>/dev/null + +function run_sender_receiver { + sender=$1 + receiver=$2 + FILENAME=$3 + name_type_of_test=$4 # directory where all the output files are stored (REQUIRE "/" at the end) + + if [ ! d "${name_type_of_test}" ]; then + mkdir '${name_of_the_type_of_test}' 2>/dev/null + fi + + BASENAME=$(basename $FILENAME) + BSN_PRE="${BASENAME%.*}" + BSN_EXT="${BASENAME##*.}" + + DIR="${name_type_of_test}${BSN_PRE}/" + mkdir "${DIR}/" 2>/dev/null + + # Checking if we're using the linksimulator or not + if [ "$#" -gt 4 ]; then + + ERROR_RATE=$5 + CUT_RATE=$6 + DELAY=$7 + JITTER=$8 + LOSS_RATE=$9 + + 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" + + # 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) + + linksimulator_logs=${DIR}/adv_${BSN_PRE}_link.log + + ##### Launching the link simulator ##### + ./linksimulator/link_sim -p $port2 -P $port1 -l $LOSS_RATE -d $DELAY -e $ERROR_RATE -c $CUT_RATE -j $JITTER \ + &> $linksimulator_logs & link_pid=$! + + else + # The next line 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=$port1 + fi + + MODES=( + 'with_FEC' + 'without_FEC' + ) + + for MODE in "${MODES[@]}"; do + + SUB_DIR="${DIR}${MODE}/" + mkdir "${SUB_DIR}" 2>/dev/null + + output_file="${SUB_DIR}adv_${BSN_PRE}_received_file.${BSN_EXT}" + sender_valgrind="${SUB_DIR}valgrind_${BSN_PRE}_${sender}.log" + receiver_valgrind="${SUB_DIR}valgrind_${BSN_PRE}_${receiver}.log" + sender_stats="${SUB_DIR}${BSN_PRE}_${sender}_stats.csv" + receiver_stats="${SUB_DIR}${BSN_PRE}_${receiver}_stats.csv" + + touch output_file sender_valgrind receiver_valgrind sender_stats receiver_stats + + receiver_logs="${SUB_DIR}${BSN_PRE}_${receiver}.log" + sender_logs="${SUB_DIR}${BSN_PRE}_${sender}.log" + + ##### Launching the receiver and capturinig its output ##### + valgrind --leak-check=full --log-file=${receiver_valgrind} \ + ./receiver ::1 $port1 \ + -s ${receiver_stats} \ + 1> ${output_file} \ + 2> ${receiver_logs} & 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 + err=1 + 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 + 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}" + else + 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}" + else + 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 + +} + + +### Testing our sender with a receiver from another group ### + + +### Testing our receiver with a sender from another group ### + + + + + + \ No newline at end of file