diff options
Diffstat (limited to 'testing/Lossless_UDP_testclient.c')
-rw-r--r-- | testing/Lossless_UDP_testclient.c | 91 |
1 files changed, 79 insertions, 12 deletions
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c index d092125b..20fae86f 100644 --- a/testing/Lossless_UDP_testclient.c +++ b/testing/Lossless_UDP_testclient.c | |||
@@ -40,6 +40,64 @@ void printpacket(char * data, uint32_t length, IP_Port ip_port) | |||
40 | printf("\n--------------------END-----------------------------\n\n\n"); | 40 | printf("\n--------------------END-----------------------------\n\n\n"); |
41 | } | 41 | } |
42 | 42 | ||
43 | void printip(IP_Port ip_port) | ||
44 | { | ||
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 | } | ||
47 | |||
48 | void printpackets(Data test) | ||
49 | { | ||
50 | int i; | ||
51 | if(test.size == 0) | ||
52 | return; | ||
53 | printf("SIZE: %u\n", test.size); | ||
54 | for(i =0; i < test.size; i++) | ||
55 | { | ||
56 | printf("%hhX", test.data[i]); | ||
57 | } | ||
58 | printf("\n"); | ||
59 | } | ||
60 | |||
61 | void printconnection(int connection_id) | ||
62 | { | ||
63 | printf("--------------------BEGIN---------------------\n"); | ||
64 | IP_Port ip_port = connections[connection_id].ip_port; | ||
65 | 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)); | ||
66 | printf("status: %u, inbound: %u, SYNC_rate: %u\n", connections[connection_id].status, | ||
67 | connections[connection_id].inbound, connections[connection_id].SYNC_rate); | ||
68 | printf("data rate: %u, last sync: %llu, last sent: %llu, last recv: %llu \n", connections[connection_id].data_rate, | ||
69 | connections[connection_id].last_SYNC, connections[connection_id].last_sent, connections[connection_id].last_recv); | ||
70 | int i; | ||
71 | for(i =0; i < MAX_QUEUE_NUM; i++) | ||
72 | { | ||
73 | printf(" %u ",i); | ||
74 | printpackets(connections[connection_id].sendbuffer[i]); | ||
75 | } | ||
76 | for(i =0; i < MAX_QUEUE_NUM; i++) | ||
77 | { | ||
78 | printf(" %u ",i); | ||
79 | printpackets(connections[connection_id].recvbuffer[i]); | ||
80 | } | ||
81 | Data sendbuffer[MAX_QUEUE_NUM]; | ||
82 | 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 | 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].successful_sent, | ||
87 | connections[connection_id].successful_read); | ||
88 | |||
89 | printf("req packets: \n"); | ||
90 | for(i = 0; i < MAX_PACKET_NUM; i++) | ||
91 | { | ||
92 | printf(" %u ", connections[connection_id].req_packets[i]); | ||
93 | } | ||
94 | printf("\nNumber: %u recv_counter: %u, send_counter: %u\n", connections[connection_id].num_req_paquets, | ||
95 | connections[connection_id].recv_counter, connections[connection_id].send_counter); | ||
96 | |||
97 | printf("--------------------END---------------------\n"); | ||
98 | |||
99 | } | ||
100 | |||
43 | //recieve packets and send them to the packethandler | 101 | //recieve packets and send them to the packethandler |
44 | //run doLossless_UDP(); | 102 | //run doLossless_UDP(); |
45 | void Lossless_UDP() | 103 | void Lossless_UDP() |
@@ -49,14 +107,18 @@ void Lossless_UDP() | |||
49 | uint32_t length; | 107 | uint32_t length; |
50 | while(recievepacket(&ip_port, data, &length) != -1) | 108 | while(recievepacket(&ip_port, data, &length) != -1) |
51 | { | 109 | { |
110 | if(rand() % 3 != 1)//add packet loss | ||
111 | |||
52 | if(LosslessUDP_handlepacket(data, length, ip_port)) | 112 | if(LosslessUDP_handlepacket(data, length, ip_port)) |
53 | { | 113 | { |
54 | printpacket(data, length, ip_port); | 114 | printpacket(data, length, ip_port); |
55 | } | 115 | } |
56 | else | 116 | else |
57 | { | 117 | { |
118 | //printconnection(0); | ||
58 | printf("Received handled packet with length: %u\n", length); | 119 | printf("Received handled packet with length: %u\n", length); |
59 | } | 120 | } |
121 | |||
60 | } | 122 | } |
61 | 123 | ||
62 | doLossless_UDP(); | 124 | doLossless_UDP(); |
@@ -85,8 +147,10 @@ int main(int argc, char *argv[]) | |||
85 | ip.i = 0; | 147 | ip.i = 0; |
86 | init_networking(ip, PORT); | 148 | init_networking(ip, PORT); |
87 | perror("Initialization"); | 149 | perror("Initialization"); |
88 | 150 | IP_Port serverip; | |
89 | IP_Port serverip = {{{inet_addr(argv[1])}}, htons(atoi(argv[2]))}; | 151 | serverip.ip.i = inet_addr(argv[1]); |
152 | serverip.port = htons(atoi(argv[2])); | ||
153 | printip(serverip); | ||
90 | int connection = new_connection(serverip); | 154 | int connection = new_connection(serverip); |
91 | uint64_t timer = current_time(); | 155 | uint64_t timer = current_time(); |
92 | while(1) | 156 | while(1) |
@@ -94,47 +158,50 @@ int main(int argc, char *argv[]) | |||
94 | Lossless_UDP(); | 158 | Lossless_UDP(); |
95 | if(is_connected(connection) == 3) | 159 | if(is_connected(connection) == 3) |
96 | { | 160 | { |
97 | printf("Connecting took: %llu us", (unsigned long long)(current_time() - timer)); | 161 | printf("Connecting took: %llu us\n", (unsigned long long)(current_time() - timer)); |
98 | break; | 162 | break; |
99 | } | 163 | } |
100 | if(is_connected(connection) == 0) | 164 | if(is_connected(connection) == 0) |
101 | { | 165 | { |
102 | printf("Connection timeout after: %llu us", (unsigned long long)(current_time() - timer)); | 166 | printf("Connection timeout after: %llu us\n", (unsigned long long)(current_time() - timer)); |
103 | break; | 167 | return 1; |
104 | } | 168 | } |
105 | c_sleep(1); | 169 | c_sleep(100); |
106 | } | 170 | } |
107 | timer = current_time(); | 171 | timer = current_time(); |
108 | 172 | ||
109 | 173 | ||
110 | //read first part of file | 174 | //read first part of file |
111 | read = fread(buffer, 1, 128, file); | 175 | read = fread(buffer, 1, 1, file); |
112 | 176 | ||
113 | while(1) | 177 | while(1) |
114 | { | 178 | { |
179 | //printconnection(connection); | ||
115 | Lossless_UDP(); | 180 | Lossless_UDP(); |
116 | 181 | ||
117 | if(is_connected(connection) == 1) | 182 | if(is_connected(connection) == 3) |
118 | { | 183 | { |
119 | 184 | ||
120 | if(write_packet(connection, buffer, read)) | 185 | if(write_packet(connection, buffer, read)) |
121 | { | 186 | { |
122 | read = fread(buffer, 1, 128, file); | 187 | //printf("Wrote data.\n"); |
188 | read = fread(buffer, 1, 1, file); | ||
123 | } | 189 | } |
124 | if(sendqueue(connection) == 0) | 190 | if(sendqueue(connection) == 0) |
125 | { | 191 | { |
126 | if(read == 0) | 192 | if(read == 0) |
127 | { | 193 | { |
128 | printf("Sent file successfully in: %llu us", (unsigned long long)(current_time() - timer)); | 194 | printf("Sent file successfully in: %llu us\n", (unsigned long long)(current_time() - timer)); |
129 | break; | 195 | break; |
130 | } | 196 | } |
131 | } | 197 | } |
132 | } | 198 | } |
133 | else | 199 | else |
134 | { | 200 | { |
135 | printf("Connecting Lost after: %llu us", (unsigned long long)(current_time() - timer)); | 201 | printf("Connecting Lost after: %llu us\n", (unsigned long long)(current_time() - timer)); |
202 | return 0; | ||
136 | } | 203 | } |
137 | c_sleep(1); | 204 | c_sleep(50); |
138 | } | 205 | } |
139 | 206 | ||
140 | return 0; | 207 | return 0; |