diff --git a/Makefile b/Makefile index e96ac90eeb313fc61506c9a147802d8d74f65992..2e5aabb1e5fe2ce0a3820b4ca918ac4bcc3c05ea 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,8 @@ HEADERS_DIR = -Iheaders LDFLAGS = -lz # Adapt these as you want to fit with your project -SENDER_SOURCES = $(wildcard src/sender.c src/log.c src/our_utils.c src/packet_interface.c src/sender_utils.c) -RECEIVER_SOURCES = $(wildcard src/receiver.c src/log.c src/our_utils.c src/packet_interface.c src/receiver_utils.c) +SENDER_SOURCES = $(wildcard src/sender.c src/log.c src/utils.c src/packet_interface.c src/sender_utils.c) +RECEIVER_SOURCES = $(wildcard src/receiver.c src/log.c src/utils.c src/packet_interface.c src/receiver_utils.c) SENDER_OBJECTS = $(SENDER_SOURCES:.c=.o) RECEIVER_OBJECTS = $(RECEIVER_SOURCES:.c=.o) diff --git a/src/log.c b/src/log.c index 25874a85e483f67b32d15a94547d30ba7ee6684a..e73784e105bf809c2fad0489348988d3e51dd2cd 100644 --- a/src/log.c +++ b/src/log.c @@ -4,6 +4,7 @@ #include "log.h" + /* Prints `len` bytes starting from `bytes` to stderr */ void dump(const uint8_t *bytes, size_t len) { for (size_t i = 0; i < len;) { diff --git a/src/receiver_utils.c b/src/receiver_utils.c index c140b08fa5d152d68b19e8a4c6dfb4b8272d8f73..7a0f85d848b418bf60dc47bdfa7584afbf4fa591 100644 --- a/src/receiver_utils.c +++ b/src/receiver_utils.c @@ -1,5 +1,6 @@ #include "receiver_utils.h" + /** * @brief The function is going to check if we need to send an ACK or NACK on the @pfd, * and will send at most one packet [either an ACK or NACK or nothing]. diff --git a/src/receiver_utils.h b/src/receiver_utils.h index ea7f499fa7ad1d4882316475da2bf44c9c49b540..1f77b62006483afcfa2f59ea326724f3ae2a1a43 100644 --- a/src/receiver_utils.h +++ b/src/receiver_utils.h @@ -21,7 +21,7 @@ #include <unistd.h> #include "log.h" -#include "our_utils.h" +#include "utils.h" #include "packet_interface.h" diff --git a/src/sender.c b/src/sender.c index d1134d503bc6560d960b3ebb8b4132d328139480..4a809651f2bb5476072fccc9bb1ac4f35899f1b9 100644 --- a/src/sender.c +++ b/src/sender.c @@ -173,7 +173,7 @@ int main(int argc, char **argv) { if (state->last_pkt_sent == CLOSING_PKT) { gettimeofday(&closing_pkt_sent_time, NULL); - DEBUG("A timer of -> %dms <- has started after sending the last FEC pkt !", SENDER_INACTIVE_TIMEOUT); + DEBUG("A timer of -> %dms <- has started after sending the last PTYPE_DATA pkt !", SENDER_INACTIVE_TIMEOUT); } } else if (pfd->revents & POLLOUT) diff --git a/src/sender_utils.h b/src/sender_utils.h index 51faccb84f46f62d0c22b2c99d487946c4ea04e4..4013d8b54294ce0d4898ee2eb5763cec5445c765 100644 --- a/src/sender_utils.h +++ b/src/sender_utils.h @@ -13,7 +13,7 @@ #include <unistd.h> #include "log.h" -#include "our_utils.h" +#include "utils.h" #include "packet_interface.h" diff --git a/src/test.c b/src/test.c deleted file mode 100644 index 7ba56388dc88091c8738bc7fd085b6de874f57fc..0000000000000000000000000000000000000000 --- a/src/test.c +++ /dev/null @@ -1,19 +0,0 @@ -#include <arpa/inet.h> -#include <zlib.h> -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> - -#include "packet_interface.h" - - -int main(int argc, char const *argv[]) -{ - if (argc < 2) - return 1; - pkt_t * pkt = pkt_new(); - int err = pkt_decode(argv[1], 10, pkt); - printf("Returned %d\n", err); - return 0; -} diff --git a/src/our_utils.c b/src/utils.c similarity index 95% rename from src/our_utils.c rename to src/utils.c index 545d398dfb4c070b5d0994bf57a6ea06476b6675..435fe402c2030ea21878c5dabceba6823af36347 100644 --- a/src/our_utils.c +++ b/src/utils.c @@ -1,19 +1,5 @@ -#include <arpa/inet.h> -#include <errno.h> -#include <fcntl.h> -#include <netdb.h> -#include <netinet/in.h> -#include <poll.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <unistd.h> - -#include "log.h" -#include "our_utils.h" +#include "utils.h" + const char * real_address(const char *address, struct sockaddr_in6 *rval) { diff --git a/src/our_utils.h b/src/utils.h similarity index 94% rename from src/our_utils.h rename to src/utils.h index 9e51517ca90aef6165310000462f895741d79805..4d07cc142cc7f67fb7b42b10931d56dbdcccf150 100644 --- a/src/our_utils.h +++ b/src/utils.h @@ -1,24 +1,23 @@ -/** - * @file our_utils.h - * @brief This header contains utils that were coded for the packet sending on inginious - * @date 2022-03-17 - */ -#ifndef __OUR_UTILS_H_ -#define __OUR_UTILS_H_ +#ifndef __UTILS_H_ +#define __UTILS_H_ #include <arpa/inet.h> #include <errno.h> +#include <fcntl.h> #include <netdb.h> #include <netinet/in.h> +#include <poll.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/time.h> #include <sys/types.h> #include <sys/socket.h> #include <unistd.h> +#include "log.h" + + typedef struct __attribute__((__packed__)) { unsigned long long int data_sent; diff --git a/tests/advanced_test.sh b/tests/advanced_test.sh index 2138e327037d0ccf1b5b3a067e772b1bccf36df4..92dfd19a8e06cd45dd4d8ac729a3633747ac09fd 100755 --- a/tests/advanced_test.sh +++ b/tests/advanced_test.sh @@ -27,6 +27,17 @@ MODES=( '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 @@ -45,11 +56,12 @@ for MODE in "${MODES[@]}"; do 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) - # We first launch the link simulator - ./linksimulator/link_sim -p $port2 -P $port1 -l 25 -d 0 -e 20 -c 30 \ + + ##### 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=$! - # We launch the receiver and capture its output + ##### 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=$! @@ -105,16 +117,16 @@ for MODE in "${MODES[@]}"; do 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 activated has failed!${NC}" + echo -e "${RED}The transfer (with FEC) has failed!${NC}" else - echo -e "${RED}The transfer without FEC being activated 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 activated has succeeded!${NC}" + echo -e "${GREEN}The transfer (with FEC) has succeeded!${NC}" else - echo -e "${GREEN}The transfer without FEC being activated has succeeded!${NC}" + echo -e "${GREEN}The transfer (without FEC) has succeeded!${NC}" fi fi done diff --git a/tests/run_tests.sh b/tests/run_tests.sh index ca2d764aad0c696d1417f662e54745e3bac11958..e3317a9a2a1b760f5bd31b05013337a5b27fa908 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1,5 +1,8 @@ #!/bin/bash +BROWN='\033[0;33m' +NC='\033[0m' + # Note that this assumes to be called from the Makefile, you may want to adapt it. FILESIZE="" TEST_FILES_DIR=./tests_files/ @@ -14,35 +17,49 @@ if [ -d ./unwanted_logs/ ]; then rm -rdf ./unwanted_logs fi -# We want our tests to always use valgrind -#echo -e "\nStarting simple tests ...\n" -#for FILENAME in "$TEST_FILES_DIR"/* -#do -# FILESIZE=$(stat -c%s "$FILENAME") -# echo -e "Sending $FILENAME \t\t [$FILESIZE bytes], \t\t with Valgrind" -# ./tests/simple_test.sh $FILENAME +simple_test_files=( + 'tests_files/greeting.txt' + 'tests_files/long_message.txt' + 'tests_files/smile.png' + 'tests_files/thumbs-up-nod.gif' +) + +advanced_test_files=( + 'tests_files/greeting.txt' + 'tests_files/long_message.txt' + 'tests_files/noice.gif' +) + +# echo -e "\nStarting simple tests ...\n" +# i=1 +# for FILENAME in "${simple_test_files[@]}"; do +# FILESIZE=$(stat -c%s "$FILENAME") +# echo -e "${BROWN}($i/${#simple_test_files[@]}) Sending \"$FILENAME\" \t[$FILESIZE bytes] with Valgrind${NC}" +# ./tests/simple_test.sh $FILENAME -# if [ $? -ne 0 ]; then -# echo "Tests terminated cause of a failed test" -# exit 0 -# fi +# if [ $? -ne 0 ]; then +# echo "Tests terminated cause of a failed test" +# exit 0 +# fi +# let i++ -#done -#echo -e "Finished Simple tests." +# done +echo -e "Finished Simple tests." if [ -d linksimulator/ ]; then echo -e "\nStarting advanced tests ...\n" # Now we ran the advanced tests - for FILENAME in "$TEST_FILES_DIR"/* - do + i=1 + for FILENAME in "${advanced_test_files[@]}"; do FILESIZE=$(stat -c%s "$FILENAME") - echo -e "Sending $FILENAME \t\t [$FILESIZE bytes], \t\t with linksimulator and Valgrind" + echo -e "\n${BROWN}($i/${#advanced_test_files[@]}) Sending the file \"$FILENAME\" \t[$FILESIZE bytes] with linksimulator and Valgrind${NC}" ./tests/advanced_test.sh $FILENAME if [ $? -ne 0 ]; then echo "Tests terminated cause of a failed test" exit 0 - fi + fi + let i++ done echo "Finished Advanced tests." else diff --git a/tests_files/long_message.txt b/tests_files/long_message.txt index 9a4178c362cdafd845cf5179691e0f1c6dccca0e..a18b03ec08fdc53c1f0a5e0fc9187b5a0f18568f 100644 --- a/tests_files/long_message.txt +++ b/tests_files/long_message.txt @@ -6,14 +6,14 @@ ahead. So good luck have a nice day of testing and remember : Tough Times Never PS: Drink a beer when you pass the test. Share your knowledge to others, computer science isn't a field for selfishness. If you want to switch to Law, Economy, some shit -Hi Vany I love reading from you. As you know I'm working sometime a bit late in the night. -In a few hour you'll be in the famous "Salle Intel" to be really productive as you are. +Hi Vany I'm pleased to read some news from you. As you know I work sometime a bit late in the night. +In a few hour you'll show up in the famous "Salle Intel" to be really productive as you are. Best regards, Samuel -Sorry to be lazy but I'll past down what is above +Sorry to be lazy but I'll past down what is above :') Hello I'm a good friend, I've seen that you are writing a protocol named TRTP. How is it going ? Hard ? Good for you. See life is full of hard things just like your @@ -23,9 +23,7 @@ ahead. So good luck have a nice day of testing and remember : Tough Times Never PS: Drink a beer when you pass the test. Share your knowledge to others, computer science isn't a field for selfishness. If you want to switch to Law, Economy, some shit -Hi Vany I love reading from you. As you know I'm working sometime a bit late in the night. -In a few hour you'll be in the famous "Salle Intel" to be really productive as you are. +Hi Vany I'm pleased to read some news from you. As you know I work sometime a bit late in the night. +In a few hour you'll show up in the famous "Salle Intel" to be really productive as you are. Best regards, - -Samuel