summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-06-28 22:58:46 -0400
committerirungentoo <irungentoo@gmail.com>2013-06-28 22:58:46 -0400
commitc9d0c208a5c1c67a0514c01a6c4a3ac360767bfd (patch)
tree4a2df1a97734d50389cadafeb1d4c313b07b65c2 /testing
parentfd44c68801205eeece6495a641db50467ee4ece5 (diff)
Test programs updated. (I'm gonna wait until I finish Lossless_UDP before pushing it.)
Diffstat (limited to 'testing')
-rw-r--r--testing/Lossless_UDP_testclient.c91
-rw-r--r--testing/Lossless_UDP_testserver.c71
-rw-r--r--testing/rect.py10
3 files changed, 153 insertions, 19 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
43void 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
48void 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
61void 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();
45void Lossless_UDP() 103void 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;
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;
diff --git a/testing/rect.py b/testing/rect.py
index 816e6e8c..59d6c158 100644
--- a/testing/rect.py
+++ b/testing/rect.py
@@ -14,7 +14,7 @@ sock.bind((UDP_IP, UDP_PORT))
14client_id = str(''.join(random.choice("abcdefghijklmnopqrstuvwxyz") for x in range(32))) 14client_id = str(''.join(random.choice("abcdefghijklmnopqrstuvwxyz") for x in range(32)))
15 15
16print client_id 16print client_id
17 17a = 1;
18#send ping request to our DHT on localhost. 18#send ping request to our DHT on localhost.
19sock.sendto("0012345678".decode("hex") + client_id, ('127.0.0.1', 33445)) 19sock.sendto("0012345678".decode("hex") + client_id, ('127.0.0.1', 33445))
20 20
@@ -34,4 +34,12 @@ while True:
34 #send send nodes packet with a couple 127.0.0.1 ips and ports. 34 #send send nodes packet with a couple 127.0.0.1 ips and ports.
35 #127.0.0.1:5000, 127.0.0.1:5001, 127.0.0.1:5002 35 #127.0.0.1:5000, 127.0.0.1:5001, 127.0.0.1:5002
36 sock.sendto("03".decode('hex') + data[1:5] + client_id + ("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113880000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113890000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F000001138A0000".decode('hex')), addr) 36 sock.sendto("03".decode('hex') + data[1:5] + client_id + ("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113880000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F00000113890000".decode('hex') + "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" + "7F000001138A0000".decode('hex')), addr)
37
38 if data[0] == "10".decode('hex'):
39 print "Sending handshake resp"
40 sock.sendto("10".decode('hex') + data[1:5] + client_id[:4], addr)
41 if data[0] == "11".decode('hex'):
42 print "Sending SYNC resp"
43 a+=1
44 sock.sendto("11".decode('hex') + chr(a) + data[1:9], addr)
37 45