summaryrefslogtreecommitdiff
path: root/testing/Lossless_UDP_testserver.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/Lossless_UDP_testserver.c')
-rw-r--r--testing/Lossless_UDP_testserver.c71
1 files changed, 65 insertions, 6 deletions
diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c
index 5ae35574..9a180cbb 100644
--- a/testing/Lossless_UDP_testserver.c
+++ b/testing/Lossless_UDP_testserver.c
@@ -40,6 +40,58 @@ void printpacket(char * data, uint32_t length, IP_Port ip_port)
40 } 40 }
41 printf("\n--------------------END-----------------------------\n\n\n"); 41 printf("\n--------------------END-----------------------------\n\n\n");
42} 42}
43void printpackets(Data test)
44{
45 int i;
46 if(test.size == 0)
47 return;
48 printf("SIZE: %u\n", test.size);
49 for(i =0; i < test.size; i++)
50 {
51 printf("%hhX", test.data[i]);
52 }
53 printf("\n");
54}
55
56void printconnection(int connection_id)
57{
58 printf("--------------------BEGIN---------------------\n");
59 IP_Port ip_port = connections[connection_id].ip_port;
60 printf("IP: %u.%u.%u.%u Port: %u\n",ip_port.ip.c[0],ip_port.ip.c[1],ip_port.ip.c[2],ip_port.ip.c[3],ntohs(ip_port.port));
61 printf("status: %u, inbound: %u, SYNC_rate: %u\n", connections[connection_id].status,
62 connections[connection_id].inbound, connections[connection_id].SYNC_rate);
63 printf("data rate: %u, last sync: %llu, last sent: %llu, last recv: %llu \n", connections[connection_id].data_rate,
64 connections[connection_id].last_SYNC, connections[connection_id].last_sent, connections[connection_id].last_recv);
65 int i;
66 for(i =0; i < MAX_QUEUE_NUM; i++)
67 {
68 printf(" %u ",i);
69 printpackets(connections[connection_id].sendbuffer[i]);
70 }
71 for(i =0; i < MAX_QUEUE_NUM; i++)
72 {
73 printf(" %u ",i);
74 printpackets(connections[connection_id].recvbuffer[i]);
75 }
76 Data sendbuffer[MAX_QUEUE_NUM];
77 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",
79 connections[connection_id].recv_packetnum,
80 connections[connection_id].recv_packetnum_sync, connections[connection_id].sent_packetnum, connections[connection_id].send_packetnum,
81 connections[connection_id].successful_sent,
82 connections[connection_id].successful_read);
83
84 printf("req packets: \n");
85 for(i = 0; i < MAX_PACKET_NUM; i++)
86 {
87 printf(" %u ", connections[connection_id].req_packets[i]);
88 }
89 printf("\nNumber: %u recv_counter: %u, send_counter: %u\n", connections[connection_id].num_req_paquets,
90 connections[connection_id].recv_counter, connections[connection_id].send_counter);
91
92 printf("--------------------END---------------------\n");
93
94}
43 95
44//recieve packets and send them to the packethandler 96//recieve packets and send them to the packethandler
45//run doLossless_UDP(); 97//run doLossless_UDP();
@@ -50,12 +102,14 @@ void Lossless_UDP()
50 uint32_t length; 102 uint32_t length;
51 while(recievepacket(&ip_port, data, &length) != -1) 103 while(recievepacket(&ip_port, data, &length) != -1)
52 { 104 {
105 if(rand() % 3 != 1)//add packet loss
53 if(LosslessUDP_handlepacket(data, length, ip_port)) 106 if(LosslessUDP_handlepacket(data, length, ip_port))
54 { 107 {
55 printpacket(data, length, ip_port); 108 printpacket(data, length, ip_port);
56 } 109 }
57 else 110 else
58 { 111 {
112 // printconnection(0);
59 printf("Received handled packet with length: %u\n", length); 113 printf("Received handled packet with length: %u\n", length);
60 } 114 }
61 } 115 }
@@ -76,7 +130,7 @@ int main(int argc, char *argv[])
76 char buffer[128]; 130 char buffer[128];
77 int read; 131 int read;
78 132
79 FILE *file = fopen(argv[3], "rb"); 133 FILE *file = fopen(argv[1], "wb");
80 if ( file==NULL ){return 1;} 134 if ( file==NULL ){return 1;}
81 135
82 136
@@ -99,23 +153,26 @@ int main(int argc, char *argv[])
99 { 153 {
100 if(is_connected(connection) == 3) 154 if(is_connected(connection) == 3)
101 { 155 {
102 printf("Recieved the connection."); 156 printf("Recieved the connection.\n");
103 } 157 }
104 break; 158 break;
105 } 159 }
106 c_sleep(1); 160 c_sleep(100);
107 } 161 }
108 162
109 timer = current_time(); 163 timer = current_time();
110 164
111 while(1) 165 while(1)
112 { 166 {
167 //printconnection(0);
113 Lossless_UDP(); 168 Lossless_UDP();
114 if(is_connected(connection) == 1) 169 if(is_connected(connection) == 3)
115 { 170 {
116 read = read_packet(connection, buffer); 171 read = read_packet(connection, buffer);
172
117 if(read != 0) 173 if(read != 0)
118 { 174 {
175 printf("Recieved data.\n");
119 if(!fwrite(buffer, read, 1, file)) 176 if(!fwrite(buffer, read, 1, file))
120 { 177 {
121 printf("file write error\n"); 178 printf("file write error\n");
@@ -124,9 +181,11 @@ int main(int argc, char *argv[])
124 } 181 }
125 else 182 else
126 { 183 {
127 printf("Connecting Lost after: %llu us", (unsigned long long)(current_time() - timer)); 184 printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer));
185 fclose(file);
186 return 1;
128 } 187 }
129 c_sleep(1); 188 c_sleep(50);
130 } 189 }
131 190
132 return 0; 191 return 0;