From 6bd24212ee41d87a011733974bdc76bd04e60037 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 29 Jun 2013 18:40:41 -0400 Subject: Lossless UDP now works. The testclient and testserver simulate a packet loss of 33%. The only thing left to do in lossless UDP is the flow control (automatic adjustment of the data send rate) which is only needed to transfer large amounts of data. --- testing/Lossless_UDP_testclient.c | 42 +++++++++++++++++++++------------------ testing/Lossless_UDP_testserver.c | 37 +++++++++++++++++++--------------- 2 files changed, 44 insertions(+), 35 deletions(-) (limited to 'testing') diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c index 20fae86f..5790ad3b 100644 --- a/testing/Lossless_UDP_testclient.c +++ b/testing/Lossless_UDP_testclient.c @@ -1,5 +1,6 @@ /* Lossless_UDP testclient * A program that connects and sends a file using our lossless UDP algorithm. + * NOTE: this program simulates a 33% packet loss. * * Best used in combination with Lossless_UDP_testserver * @@ -44,7 +45,7 @@ void printip(IP_Port ip_port) { printf("\nIP: %u.%u.%u.%u Port: %u",ip_port.ip.c[0],ip_port.ip.c[1],ip_port.ip.c[2],ip_port.ip.c[3],ntohs(ip_port.port)); } - +/* void printpackets(Data test) { int i; @@ -80,14 +81,14 @@ void printconnection(int connection_id) } Data sendbuffer[MAX_QUEUE_NUM]; Data recvbuffer[MAX_QUEUE_NUM]; - printf("recv_num: %u, recv_sync: %u, sent_packetnum %u, send_packetnum: %u, successful_sent: %u, successful_read: %u\n", + printf("recv_num: %u, orecv_num: %u, sent_packetnum %u, osent_packetnum: %u, successful_sent: %u, successful_read: %u\n", connections[connection_id].recv_packetnum, - connections[connection_id].recv_packetnum_sync, connections[connection_id].sent_packetnum, connections[connection_id].send_packetnum, + connections[connection_id].orecv_packetnum, connections[connection_id].sent_packetnum, connections[connection_id].osent_packetnum, connections[connection_id].successful_sent, connections[connection_id].successful_read); printf("req packets: \n"); - for(i = 0; i < MAX_PACKET_NUM; i++) + for(i = 0; i < BUFFER_PACKET_NUM; i++) { printf(" %u ", connections[connection_id].req_packets[i]); } @@ -97,7 +98,7 @@ void printconnection(int connection_id) printf("--------------------END---------------------\n"); } - +*/ //recieve packets and send them to the packethandler //run doLossless_UDP(); void Lossless_UDP() @@ -107,18 +108,19 @@ void Lossless_UDP() uint32_t length; while(recievepacket(&ip_port, data, &length) != -1) { + printf("packet with length: %u\n", length); if(rand() % 3 != 1)//add packet loss - - if(LosslessUDP_handlepacket(data, length, ip_port)) - { - printpacket(data, length, ip_port); - } - else - { + { + if(LosslessUDP_handlepacket(data, length, ip_port)) + { + printpacket(data, length, ip_port); + } + else + { //printconnection(0); - printf("Received handled packet with length: %u\n", length); + printf("Received handled packet with length: %u\n", length); + } } - } doLossless_UDP(); @@ -155,6 +157,7 @@ int main(int argc, char *argv[]) uint64_t timer = current_time(); while(1) { + // printconnection(connection); Lossless_UDP(); if(is_connected(connection) == 3) { @@ -166,27 +169,28 @@ int main(int argc, char *argv[]) printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); return 1; } - c_sleep(100); + c_sleep(1); } timer = current_time(); //read first part of file - read = fread(buffer, 1, 1, file); + read = fread(buffer, 1, 128, file); while(1) { //printconnection(connection); Lossless_UDP(); - if(is_connected(connection) == 3) { if(write_packet(connection, buffer, read)) { //printf("Wrote data.\n"); - read = fread(buffer, 1, 1, file); + read = fread(buffer, 1, 128, file); + } + //printf("%u\n", sendqueue(connection)); if(sendqueue(connection) == 0) { if(read == 0) @@ -201,7 +205,7 @@ int main(int argc, char *argv[]) printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); return 0; } - c_sleep(50); + c_sleep(1); } return 0; diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c index 9a180cbb..5370da9e 100644 --- a/testing/Lossless_UDP_testserver.c +++ b/testing/Lossless_UDP_testserver.c @@ -1,5 +1,6 @@ /* Lossless_UDP testserver * A program that waits for a lossless UDP connection and then saves all the data recieved to a file. + * NOTE: this program simulates a 33% packet loss. * * Best used in combination with Lossless_UDP_testclient * @@ -40,6 +41,7 @@ void printpacket(char * data, uint32_t length, IP_Port ip_port) } printf("\n--------------------END-----------------------------\n\n\n"); } +/* void printpackets(Data test) { int i; @@ -75,14 +77,14 @@ void printconnection(int connection_id) } Data sendbuffer[MAX_QUEUE_NUM]; Data recvbuffer[MAX_QUEUE_NUM]; - printf("recv_num: %u, recv_sync: %u, sent_packetnum %u, send_packetnum: %u, successful_sent: %u, successful_read: %u\n", + printf("recv_num: %u, orecv_num: %u, sent_packetnum %u, osent_packetnum: %u, successful_sent: %u, successful_read: %u\n", connections[connection_id].recv_packetnum, - connections[connection_id].recv_packetnum_sync, connections[connection_id].sent_packetnum, connections[connection_id].send_packetnum, + connections[connection_id].orecv_packetnum, connections[connection_id].sent_packetnum, connections[connection_id].osent_packetnum, connections[connection_id].successful_sent, connections[connection_id].successful_read); printf("req packets: \n"); - for(i = 0; i < MAX_PACKET_NUM; i++) + for(i = 0; i < BUFFER_PACKET_NUM; i++) { printf(" %u ", connections[connection_id].req_packets[i]); } @@ -92,7 +94,7 @@ void printconnection(int connection_id) printf("--------------------END---------------------\n"); } - +*/ //recieve packets and send them to the packethandler //run doLossless_UDP(); void Lossless_UDP() @@ -103,14 +105,16 @@ void Lossless_UDP() while(recievepacket(&ip_port, data, &length) != -1) { if(rand() % 3 != 1)//add packet loss - if(LosslessUDP_handlepacket(data, length, ip_port)) - { - printpacket(data, length, ip_port); - } - else { - // printconnection(0); - printf("Received handled packet with length: %u\n", length); + if(LosslessUDP_handlepacket(data, length, ip_port)) + { + printpacket(data, length, ip_port); + } + else + { + //printconnection(0); + // printf("Received handled packet with length: %u\n", length); + } } } @@ -151,13 +155,14 @@ int main(int argc, char *argv[]) connection = incoming_connection(); if(connection != -1) { - if(is_connected(connection) == 3) + if(is_connected(connection) == 2) { printf("Recieved the connection.\n"); + } break; } - c_sleep(100); + c_sleep(1); } timer = current_time(); @@ -166,13 +171,13 @@ int main(int argc, char *argv[]) { //printconnection(0); Lossless_UDP(); - if(is_connected(connection) == 3) + if(is_connected(connection) >= 2) { read = read_packet(connection, buffer); if(read != 0) { - printf("Recieved data.\n"); + // printf("Recieved data.\n"); if(!fwrite(buffer, read, 1, file)) { printf("file write error\n"); @@ -185,7 +190,7 @@ int main(int argc, char *argv[]) fclose(file); return 1; } - c_sleep(50); + c_sleep(1); } return 0; -- cgit v1.2.3