summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/Lossless_UDP_testclient.c42
-rw-r--r--testing/Lossless_UDP_testserver.c37
2 files changed, 44 insertions, 35 deletions
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 @@
1/* Lossless_UDP testclient 1/* Lossless_UDP testclient
2 * A program that connects and sends a file using our lossless UDP algorithm. 2 * A program that connects and sends a file using our lossless UDP algorithm.
3 * NOTE: this program simulates a 33% packet loss.
3 * 4 *
4 * Best used in combination with Lossless_UDP_testserver 5 * Best used in combination with Lossless_UDP_testserver
5 * 6 *
@@ -44,7 +45,7 @@ void printip(IP_Port ip_port)
44{ 45{
45 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)); 46 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));
46} 47}
47 48/*
48void printpackets(Data test) 49void printpackets(Data test)
49{ 50{
50 int i; 51 int i;
@@ -80,14 +81,14 @@ void printconnection(int connection_id)
80 } 81 }
81 Data sendbuffer[MAX_QUEUE_NUM]; 82 Data sendbuffer[MAX_QUEUE_NUM];
82 Data recvbuffer[MAX_QUEUE_NUM]; 83 Data recvbuffer[MAX_QUEUE_NUM];
83 printf("recv_num: %u, recv_sync: %u, sent_packetnum %u, send_packetnum: %u, successful_sent: %u, successful_read: %u\n", 84 printf("recv_num: %u, orecv_num: %u, sent_packetnum %u, osent_packetnum: %u, successful_sent: %u, successful_read: %u\n",
84 connections[connection_id].recv_packetnum, 85 connections[connection_id].recv_packetnum,
85 connections[connection_id].recv_packetnum_sync, connections[connection_id].sent_packetnum, connections[connection_id].send_packetnum, 86 connections[connection_id].orecv_packetnum, connections[connection_id].sent_packetnum, connections[connection_id].osent_packetnum,
86 connections[connection_id].successful_sent, 87 connections[connection_id].successful_sent,
87 connections[connection_id].successful_read); 88 connections[connection_id].successful_read);
88 89
89 printf("req packets: \n"); 90 printf("req packets: \n");
90 for(i = 0; i < MAX_PACKET_NUM; i++) 91 for(i = 0; i < BUFFER_PACKET_NUM; i++)
91 { 92 {
92 printf(" %u ", connections[connection_id].req_packets[i]); 93 printf(" %u ", connections[connection_id].req_packets[i]);
93 } 94 }
@@ -97,7 +98,7 @@ void printconnection(int connection_id)
97 printf("--------------------END---------------------\n"); 98 printf("--------------------END---------------------\n");
98 99
99} 100}
100 101*/
101//recieve packets and send them to the packethandler 102//recieve packets and send them to the packethandler
102//run doLossless_UDP(); 103//run doLossless_UDP();
103void Lossless_UDP() 104void Lossless_UDP()
@@ -107,18 +108,19 @@ void Lossless_UDP()
107 uint32_t length; 108 uint32_t length;
108 while(recievepacket(&ip_port, data, &length) != -1) 109 while(recievepacket(&ip_port, data, &length) != -1)
109 { 110 {
111 printf("packet with length: %u\n", length);
110 if(rand() % 3 != 1)//add packet loss 112 if(rand() % 3 != 1)//add packet loss
111 113 {
112 if(LosslessUDP_handlepacket(data, length, ip_port)) 114 if(LosslessUDP_handlepacket(data, length, ip_port))
113 { 115 {
114 printpacket(data, length, ip_port); 116 printpacket(data, length, ip_port);
115 } 117 }
116 else 118 else
117 { 119 {
118 //printconnection(0); 120 //printconnection(0);
119 printf("Received handled packet with length: %u\n", length); 121 printf("Received handled packet with length: %u\n", length);
122 }
120 } 123 }
121
122 } 124 }
123 125
124 doLossless_UDP(); 126 doLossless_UDP();
@@ -155,6 +157,7 @@ int main(int argc, char *argv[])
155 uint64_t timer = current_time(); 157 uint64_t timer = current_time();
156 while(1) 158 while(1)
157 { 159 {
160 // printconnection(connection);
158 Lossless_UDP(); 161 Lossless_UDP();
159 if(is_connected(connection) == 3) 162 if(is_connected(connection) == 3)
160 { 163 {
@@ -166,27 +169,28 @@ int main(int argc, char *argv[])
166 printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); 169 printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer));
167 return 1; 170 return 1;
168 } 171 }
169 c_sleep(100); 172 c_sleep(1);
170 } 173 }
171 timer = current_time(); 174 timer = current_time();
172 175
173 176
174 //read first part of file 177 //read first part of file
175 read = fread(buffer, 1, 1, file); 178 read = fread(buffer, 1, 128, file);
176 179
177 while(1) 180 while(1)
178 { 181 {
179 //printconnection(connection); 182 //printconnection(connection);
180 Lossless_UDP(); 183 Lossless_UDP();
181
182 if(is_connected(connection) == 3) 184 if(is_connected(connection) == 3)
183 { 185 {
184 186
185 if(write_packet(connection, buffer, read)) 187 if(write_packet(connection, buffer, read))
186 { 188 {
187 //printf("Wrote data.\n"); 189 //printf("Wrote data.\n");
188 read = fread(buffer, 1, 1, file); 190 read = fread(buffer, 1, 128, file);
191
189 } 192 }
193 //printf("%u\n", sendqueue(connection));
190 if(sendqueue(connection) == 0) 194 if(sendqueue(connection) == 0)
191 { 195 {
192 if(read == 0) 196 if(read == 0)
@@ -201,7 +205,7 @@ int main(int argc, char *argv[])
201 printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); 205 printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer));
202 return 0; 206 return 0;
203 } 207 }
204 c_sleep(50); 208 c_sleep(1);
205 } 209 }
206 210
207 return 0; 211 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 @@
1/* Lossless_UDP testserver 1/* Lossless_UDP testserver
2 * A program that waits for a lossless UDP connection and then saves all the data recieved to a file. 2 * A program that waits for a lossless UDP connection and then saves all the data recieved to a file.
3 * NOTE: this program simulates a 33% packet loss.
3 * 4 *
4 * Best used in combination with Lossless_UDP_testclient 5 * Best used in combination with Lossless_UDP_testclient
5 * 6 *
@@ -40,6 +41,7 @@ void printpacket(char * data, uint32_t length, IP_Port ip_port)
40 } 41 }
41 printf("\n--------------------END-----------------------------\n\n\n"); 42 printf("\n--------------------END-----------------------------\n\n\n");
42} 43}
44/*
43void printpackets(Data test) 45void printpackets(Data test)
44{ 46{
45 int i; 47 int i;
@@ -75,14 +77,14 @@ void printconnection(int connection_id)
75 } 77 }
76 Data sendbuffer[MAX_QUEUE_NUM]; 78 Data sendbuffer[MAX_QUEUE_NUM];
77 Data recvbuffer[MAX_QUEUE_NUM]; 79 Data recvbuffer[MAX_QUEUE_NUM];
78 printf("recv_num: %u, recv_sync: %u, sent_packetnum %u, send_packetnum: %u, successful_sent: %u, successful_read: %u\n", 80 printf("recv_num: %u, orecv_num: %u, sent_packetnum %u, osent_packetnum: %u, successful_sent: %u, successful_read: %u\n",
79 connections[connection_id].recv_packetnum, 81 connections[connection_id].recv_packetnum,
80 connections[connection_id].recv_packetnum_sync, connections[connection_id].sent_packetnum, connections[connection_id].send_packetnum, 82 connections[connection_id].orecv_packetnum, connections[connection_id].sent_packetnum, connections[connection_id].osent_packetnum,
81 connections[connection_id].successful_sent, 83 connections[connection_id].successful_sent,
82 connections[connection_id].successful_read); 84 connections[connection_id].successful_read);
83 85
84 printf("req packets: \n"); 86 printf("req packets: \n");
85 for(i = 0; i < MAX_PACKET_NUM; i++) 87 for(i = 0; i < BUFFER_PACKET_NUM; i++)
86 { 88 {
87 printf(" %u ", connections[connection_id].req_packets[i]); 89 printf(" %u ", connections[connection_id].req_packets[i]);
88 } 90 }
@@ -92,7 +94,7 @@ void printconnection(int connection_id)
92 printf("--------------------END---------------------\n"); 94 printf("--------------------END---------------------\n");
93 95
94} 96}
95 97*/
96//recieve packets and send them to the packethandler 98//recieve packets and send them to the packethandler
97//run doLossless_UDP(); 99//run doLossless_UDP();
98void Lossless_UDP() 100void Lossless_UDP()
@@ -103,14 +105,16 @@ void Lossless_UDP()
103 while(recievepacket(&ip_port, data, &length) != -1) 105 while(recievepacket(&ip_port, data, &length) != -1)
104 { 106 {
105 if(rand() % 3 != 1)//add packet loss 107 if(rand() % 3 != 1)//add packet loss
106 if(LosslessUDP_handlepacket(data, length, ip_port))
107 {
108 printpacket(data, length, ip_port);
109 }
110 else
111 { 108 {
112 // printconnection(0); 109 if(LosslessUDP_handlepacket(data, length, ip_port))
113 printf("Received handled packet with length: %u\n", length); 110 {
111 printpacket(data, length, ip_port);
112 }
113 else
114 {
115 //printconnection(0);
116 // printf("Received handled packet with length: %u\n", length);
117 }
114 } 118 }
115 } 119 }
116 120
@@ -151,13 +155,14 @@ int main(int argc, char *argv[])
151 connection = incoming_connection(); 155 connection = incoming_connection();
152 if(connection != -1) 156 if(connection != -1)
153 { 157 {
154 if(is_connected(connection) == 3) 158 if(is_connected(connection) == 2)
155 { 159 {
156 printf("Recieved the connection.\n"); 160 printf("Recieved the connection.\n");
161
157 } 162 }
158 break; 163 break;
159 } 164 }
160 c_sleep(100); 165 c_sleep(1);
161 } 166 }
162 167
163 timer = current_time(); 168 timer = current_time();
@@ -166,13 +171,13 @@ int main(int argc, char *argv[])
166 { 171 {
167 //printconnection(0); 172 //printconnection(0);
168 Lossless_UDP(); 173 Lossless_UDP();
169 if(is_connected(connection) == 3) 174 if(is_connected(connection) >= 2)
170 { 175 {
171 read = read_packet(connection, buffer); 176 read = read_packet(connection, buffer);
172 177
173 if(read != 0) 178 if(read != 0)
174 { 179 {
175 printf("Recieved data.\n"); 180 // printf("Recieved data.\n");
176 if(!fwrite(buffer, read, 1, file)) 181 if(!fwrite(buffer, read, 1, file))
177 { 182 {
178 printf("file write error\n"); 183 printf("file write error\n");
@@ -185,7 +190,7 @@ int main(int argc, char *argv[])
185 fclose(file); 190 fclose(file);
186 return 1; 191 return 1;
187 } 192 }
188 c_sleep(50); 193 c_sleep(1);
189 } 194 }
190 195
191 return 0; 196 return 0;