diff options
Diffstat (limited to 'src/transport/test_quota_compliance.c')
-rw-r--r-- | src/transport/test_quota_compliance.c | 447 |
1 files changed, 165 insertions, 282 deletions
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index 59dbd45e0..87833ff83 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2011 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -41,39 +41,18 @@ | |||
41 | 41 | ||
42 | #define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 42 | #define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
43 | 43 | ||
44 | static char *test_source; | ||
45 | 44 | ||
46 | static char *test_plugin; | 45 | static struct GNUNET_SCHEDULER_Task *measure_task; |
47 | |||
48 | static char *test_name; | ||
49 | |||
50 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
51 | |||
52 | static struct GNUNET_SCHEDULER_Task * measure_task; | ||
53 | |||
54 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | ||
55 | |||
56 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | ||
57 | |||
58 | struct GNUNET_TRANSPORT_TESTING_PeerContext *sender; | ||
59 | |||
60 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver; | ||
61 | 46 | ||
62 | struct GNUNET_TRANSPORT_TransmitHandle *th; | 47 | struct GNUNET_TRANSPORT_TransmitHandle *th; |
63 | 48 | ||
64 | char *cfg_file_p1; | 49 | static char *gen_cfgs[2]; |
65 | char *gen_cfg_p2; | ||
66 | unsigned long long quota_in_p1; | ||
67 | unsigned long long quota_out_p1; | ||
68 | 50 | ||
69 | char *cfg_file_p2; | 51 | static unsigned long long quota_in[] = { 10000, 10000 }; |
70 | char *gen_cfg_p1; | ||
71 | unsigned long long quota_in_p2; | ||
72 | unsigned long long quota_out_p2; | ||
73 | 52 | ||
74 | struct GNUNET_TRANSPORT_TESTING_Handle *tth; | 53 | static unsigned long long quota_out[] = { 10000, 10000 }; |
75 | 54 | ||
76 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; | 55 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
77 | 56 | ||
78 | 57 | ||
79 | /* | 58 | /* |
@@ -100,9 +79,6 @@ GNUNET_NETWORK_STRUCT_END | |||
100 | static int msg_scheduled; | 79 | static int msg_scheduled; |
101 | static int msg_sent; | 80 | static int msg_sent; |
102 | 81 | ||
103 | static int test_failed; | ||
104 | static int test_connected; | ||
105 | |||
106 | static unsigned long long total_bytes_sent; | 82 | static unsigned long long total_bytes_sent; |
107 | 83 | ||
108 | static struct GNUNET_TIME_Absolute start_time; | 84 | static struct GNUNET_TIME_Absolute start_time; |
@@ -119,82 +95,59 @@ static struct GNUNET_TIME_Absolute start_time; | |||
119 | 95 | ||
120 | 96 | ||
121 | static void | 97 | static void |
122 | end () | 98 | report () |
123 | { | 99 | { |
124 | unsigned long long delta; | 100 | unsigned long long delta; |
125 | unsigned long long datarate; | 101 | unsigned long long datarate; |
126 | 102 | ||
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | ||
128 | |||
129 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; | 103 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; |
130 | datarate = (total_bytes_sent * 1000 * 1000) / delta; | 104 | datarate = (total_bytes_sent * 1000 * 1000) / delta; |
131 | 105 | ||
132 | FPRINTF (stderr, "Throughput was %llu b/s\n", datarate); | 106 | FPRINTF (stderr, |
107 | "Throughput was %llu b/s\n", | ||
108 | datarate); | ||
133 | 109 | ||
134 | test_failed = GNUNET_NO; | 110 | if (datarate > quota_in[1]) |
135 | if (datarate > quota_in_p2) | ||
136 | { | 111 | { |
137 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 112 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
138 | "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n", | 113 | "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n", |
139 | datarate, quota_in_p2); | 114 | datarate, |
140 | test_failed = GNUNET_YES; | 115 | quota_in[1]); |
116 | ccc->global_ret = GNUNET_SYSERR; | ||
141 | } | 117 | } |
142 | if (datarate > quota_out_p1) | 118 | if (datarate > quota_out[0]) |
143 | { | 119 | { |
144 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
145 | "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n", | 121 | "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n", |
146 | datarate, quota_out_p1); | 122 | datarate, |
147 | test_failed = GNUNET_YES; | 123 | quota_out[0]); |
124 | ccc->global_ret = GNUNET_SYSERR; | ||
148 | } | 125 | } |
149 | if (test_failed == GNUNET_NO) | 126 | if (GNUNET_OK == ccc->global_ret) |
150 | { | 127 | { |
151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
152 | "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n", | 129 | "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n", |
153 | datarate, quota_out_p1, quota_in_p2); | 130 | datarate, |
131 | quota_out[0], | ||
132 | quota_in[1]); | ||
154 | } | 133 | } |
155 | |||
156 | if (die_task != NULL) | ||
157 | GNUNET_SCHEDULER_cancel (die_task); | ||
158 | |||
159 | if (th != NULL) | ||
160 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
161 | th = NULL; | ||
162 | |||
163 | if (cc != NULL) | ||
164 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
165 | |||
166 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
167 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
168 | |||
169 | } | 134 | } |
170 | 135 | ||
136 | |||
171 | static void | 137 | static void |
172 | end_badly () | 138 | custom_shutdown (void *cls) |
173 | { | 139 | { |
174 | die_task = NULL; | 140 | if (NULL != measure_task) |
175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | 141 | { |
176 | |||
177 | if (measure_task != NULL) | ||
178 | GNUNET_SCHEDULER_cancel (measure_task); | 142 | GNUNET_SCHEDULER_cancel (measure_task); |
179 | 143 | measure_task = NULL; | |
180 | if (test_connected == GNUNET_YES) | 144 | } |
181 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got connected\n"); | 145 | if (NULL != th) |
182 | else | 146 | { |
183 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n"); | ||
184 | |||
185 | if (th != NULL) | ||
186 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 147 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
187 | th = NULL; | 148 | th = NULL; |
188 | 149 | } | |
189 | if (cc != NULL) | 150 | report (); |
190 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
191 | |||
192 | if (p1 != NULL) | ||
193 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
194 | if (p2 != NULL) | ||
195 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
196 | |||
197 | test_failed = GNUNET_YES; | ||
198 | } | 151 | } |
199 | 152 | ||
200 | 153 | ||
@@ -210,33 +163,35 @@ get_size (unsigned int iter) | |||
210 | 163 | ||
211 | static void | 164 | static void |
212 | notify_receive (void *cls, | 165 | notify_receive (void *cls, |
213 | const struct GNUNET_PeerIdentity *peer, | 166 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
167 | const struct GNUNET_PeerIdentity *sender, | ||
214 | const struct GNUNET_MessageHeader *message) | 168 | const struct GNUNET_MessageHeader *message) |
215 | { | 169 | { |
216 | const struct TestMessage *hdr; | 170 | const struct TestMessage *hdr; |
217 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
218 | 171 | ||
219 | hdr = (const struct TestMessage *) message; | 172 | hdr = (const struct TestMessage *) message; |
220 | if (MTYPE != ntohs (message->type)) | 173 | if (MTYPE != ntohs (message->type)) |
221 | return; | 174 | return; |
222 | 175 | ||
223 | { | 176 | { |
224 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 177 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
225 | 178 | ||
226 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 179 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
227 | "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", | 180 | "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", |
228 | p->no, | 181 | receiver->no, |
229 | ps, | 182 | ps, |
230 | ntohl (hdr->num), | 183 | ntohl (hdr->num), |
231 | ntohs (message->size), | 184 | ntohs (message->size), |
232 | GNUNET_i2s (peer)); | 185 | GNUNET_i2s (sender)); |
233 | GNUNET_free (ps); | 186 | GNUNET_free (ps); |
234 | } | 187 | } |
235 | } | 188 | } |
236 | 189 | ||
237 | 190 | ||
238 | static size_t | 191 | static size_t |
239 | notify_ready (void *cls, size_t size, void *buf) | 192 | notify_ready (void *cls, |
193 | size_t size, | ||
194 | void *buf) | ||
240 | { | 195 | { |
241 | static int n; | 196 | static int n; |
242 | char *cbuf = buf; | 197 | char *cbuf = buf; |
@@ -245,15 +200,13 @@ notify_ready (void *cls, size_t size, void *buf) | |||
245 | unsigned int ret; | 200 | unsigned int ret; |
246 | 201 | ||
247 | th = NULL; | 202 | th = NULL; |
248 | if (buf == NULL) | 203 | if (NULL == buf) |
249 | { | 204 | { |
250 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 205 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
251 | "Timeout occurred while waiting for transmit_ready for message %u of %u\n", | 206 | "Timeout occurred while waiting for transmit_ready for message %u of %u\n", |
252 | msg_scheduled, TOTAL_MSGS); | 207 | msg_scheduled, TOTAL_MSGS); |
253 | if (NULL != die_task) | 208 | GNUNET_SCHEDULER_shutdown (); |
254 | GNUNET_SCHEDULER_cancel (die_task); | 209 | ccc->global_ret = GNUNET_SYSERR; |
255 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
256 | test_failed = 1; | ||
257 | return 0; | 210 | return 0; |
258 | } | 211 | } |
259 | 212 | ||
@@ -276,11 +229,14 @@ notify_ready (void *cls, size_t size, void *buf) | |||
276 | if (n % 5000 == 0) | 229 | if (n % 5000 == 0) |
277 | { | 230 | { |
278 | #endif | 231 | #endif |
279 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 232 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); |
280 | 233 | ||
281 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 234 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
282 | "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", | 235 | "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", |
283 | n, s, sender->no, GNUNET_i2s (&sender->id), receiver->no, | 236 | n, s, |
237 | ccc->p[1]->no, | ||
238 | GNUNET_i2s (&ccc->p[1]->id), | ||
239 | ccc->p[0]->no, | ||
284 | receiver_s); | 240 | receiver_s); |
285 | GNUNET_free (receiver_s); | 241 | GNUNET_free (receiver_s); |
286 | #if 0 | 242 | #if 0 |
@@ -295,60 +251,56 @@ notify_ready (void *cls, size_t size, void *buf) | |||
295 | if (n < TOTAL_MSGS) | 251 | if (n < TOTAL_MSGS) |
296 | { | 252 | { |
297 | if (th == NULL) | 253 | if (th == NULL) |
298 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, s, | 254 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, |
255 | &ccc->p[0]->id, | ||
256 | s, | ||
299 | TIMEOUT_TRANSMIT, | 257 | TIMEOUT_TRANSMIT, |
300 | ¬ify_ready, NULL); | 258 | ¬ify_ready, |
259 | NULL); | ||
301 | msg_scheduled = n; | 260 | msg_scheduled = n; |
302 | } | 261 | } |
303 | if (n % 5000 == 0) | 262 | if (n % 5000 == 0) |
304 | { | 263 | { |
305 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
306 | "Returning total message block of size %u\n", ret); | 265 | "Returning total message block of size %u\n", |
266 | ret); | ||
307 | } | 267 | } |
308 | total_bytes_sent += ret; | 268 | total_bytes_sent += ret; |
309 | if (n == TOTAL_MSGS) | 269 | if (n == TOTAL_MSGS) |
310 | { | 270 | { |
311 | FPRINTF (stderr, "%s", "\n"); | 271 | FPRINTF (stderr, "%s", "\n"); |
312 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages sent\n"); | 272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
273 | "All messages sent\n"); | ||
313 | } | 274 | } |
314 | return ret; | 275 | return ret; |
315 | } | 276 | } |
316 | 277 | ||
317 | 278 | ||
318 | static void | 279 | static void |
319 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 280 | notify_disconnect (void *cls, |
320 | { | 281 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
321 | 282 | const struct GNUNET_PeerIdentity *other) | |
322 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
323 | |||
324 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
325 | "Peer %u (`%4s') connected to us!\n", | ||
326 | p->no, | ||
327 | GNUNET_i2s (peer)); | ||
328 | } | ||
329 | |||
330 | |||
331 | static void | ||
332 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
333 | { | 283 | { |
334 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 284 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, |
335 | 285 | me, | |
336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 286 | other); |
337 | "Peer %u (`%4s') disconnected!\n", | ||
338 | p->no, | ||
339 | GNUNET_i2s (peer)); | ||
340 | if (th != NULL) | 287 | if (th != NULL) |
288 | { | ||
341 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 289 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
342 | th = NULL; | 290 | th = NULL; |
343 | 291 | } | |
344 | } | 292 | } |
345 | 293 | ||
294 | |||
346 | static void | 295 | static void |
347 | sendtask () | 296 | sendtask () |
348 | { | 297 | { |
349 | start_time = GNUNET_TIME_absolute_get (); | 298 | start_time = GNUNET_TIME_absolute_get (); |
350 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), | 299 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, |
351 | TIMEOUT_TRANSMIT, ¬ify_ready, | 300 | &ccc->p[0]->id, |
301 | get_size (0), | ||
302 | TIMEOUT_TRANSMIT, | ||
303 | ¬ify_ready, | ||
352 | NULL); | 304 | NULL); |
353 | } | 305 | } |
354 | 306 | ||
@@ -359,86 +311,54 @@ measure (void *cls) | |||
359 | static int counter; | 311 | static int counter; |
360 | 312 | ||
361 | measure_task = NULL; | 313 | measure_task = NULL; |
362 | |||
363 | counter++; | 314 | counter++; |
364 | if ((DURATION.rel_value_us / 1000 / 1000LL) < counter) | 315 | if ((DURATION.rel_value_us / 1000 / 1000LL) < counter) |
365 | { | 316 | { |
366 | FPRINTF (stderr, "%s", ".\n"); | 317 | FPRINTF (stderr, "%s", ".\n"); |
367 | GNUNET_SCHEDULER_add_now (&end, NULL); | 318 | GNUNET_SCHEDULER_shutdown (); |
368 | } | 319 | return; |
369 | else | ||
370 | { | ||
371 | FPRINTF (stderr, "%s", "."); | ||
372 | measure_task = | ||
373 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL); | ||
374 | } | 320 | } |
321 | FPRINTF (stderr, "%s", "."); | ||
322 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
323 | &measure, | ||
324 | NULL); | ||
375 | } | 325 | } |
376 | 326 | ||
377 | 327 | ||
378 | static void | 328 | static void |
379 | testing_connect_cb (void *cls) | 329 | start_task (void *cls) |
380 | { | ||
381 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
382 | |||
383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", | ||
384 | p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); | ||
385 | GNUNET_free (p1_c); | ||
386 | |||
387 | cc = NULL; | ||
388 | test_connected = GNUNET_YES; | ||
389 | |||
390 | measure_task = | ||
391 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL); | ||
392 | GNUNET_SCHEDULER_add_now (&sendtask, NULL); | ||
393 | |||
394 | } | ||
395 | |||
396 | |||
397 | static void | ||
398 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | ||
399 | { | 330 | { |
400 | static int started; | 331 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
401 | 332 | &measure, | |
402 | started++; | ||
403 | |||
404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, | ||
405 | GNUNET_i2s (&p->id)); | ||
406 | |||
407 | if (started != 2) | ||
408 | return; | ||
409 | |||
410 | test_connected = GNUNET_NO; | ||
411 | |||
412 | sender = p2; | ||
413 | receiver = p1; | ||
414 | |||
415 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&sender->id)); | ||
416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
417 | "Test tries to send from %u (%s) -> peer %u (%s)\n", sender->no, | ||
418 | sender_c, receiver->no, GNUNET_i2s (&receiver->id)); | ||
419 | GNUNET_free (sender_c); | ||
420 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, | ||
421 | NULL); | 333 | NULL); |
422 | 334 | GNUNET_SCHEDULER_add_now (&sendtask, | |
335 | NULL); | ||
423 | } | 336 | } |
424 | 337 | ||
338 | |||
425 | static char * | 339 | static char * |
426 | generate_config (char *cfg_file, unsigned long long quota_in, | 340 | generate_config (const char *cfg_file, |
341 | unsigned long long quota_in, | ||
427 | unsigned long long quota_out) | 342 | unsigned long long quota_out) |
428 | { | 343 | { |
429 | char *in_name; | 344 | char *in_name; |
430 | char *out_name; | 345 | char *out_name; |
431 | char *fname = NULL; | 346 | char *fname = NULL; |
432 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | 347 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); |
433 | int c; | ||
434 | 348 | ||
435 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file)); | 349 | GNUNET_assert (GNUNET_OK == |
436 | GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out, | 350 | GNUNET_CONFIGURATION_load (cfg, |
351 | cfg_file)); | ||
352 | GNUNET_asprintf (&fname, | ||
353 | "q_in_%llu_q_out_%llu_%s", | ||
354 | quota_in, | ||
355 | quota_out, | ||
437 | cfg_file); | 356 | cfg_file); |
438 | 357 | GNUNET_CONFIGURATION_set_value_string (cfg, | |
439 | GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", fname); | 358 | "PATHS", |
440 | 359 | "DEFAULTCONFIG", | |
441 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) | 360 | fname); |
361 | for (int c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) | ||
442 | { | 362 | { |
443 | GNUNET_asprintf (&in_name, | 363 | GNUNET_asprintf (&in_name, |
444 | "%s_QUOTA_IN", | 364 | "%s_QUOTA_IN", |
@@ -446,138 +366,101 @@ generate_config (char *cfg_file, unsigned long long quota_in, | |||
446 | GNUNET_asprintf (&out_name, | 366 | GNUNET_asprintf (&out_name, |
447 | "%s_QUOTA_OUT", | 367 | "%s_QUOTA_OUT", |
448 | GNUNET_ATS_print_network_type (c)); | 368 | GNUNET_ATS_print_network_type (c)); |
449 | GNUNET_CONFIGURATION_set_value_number (cfg, "ats", in_name, quota_in); | 369 | GNUNET_CONFIGURATION_set_value_number (cfg, |
450 | GNUNET_CONFIGURATION_set_value_number (cfg, "ats", out_name, quota_out); | 370 | "ats", |
371 | in_name, | ||
372 | quota_in); | ||
373 | GNUNET_CONFIGURATION_set_value_number (cfg, | ||
374 | "ats", | ||
375 | out_name, | ||
376 | quota_out); | ||
451 | GNUNET_free (in_name); | 377 | GNUNET_free (in_name); |
452 | GNUNET_free (out_name); | 378 | GNUNET_free (out_name); |
453 | } | 379 | } |
454 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write (cfg, fname)); | 380 | GNUNET_assert (GNUNET_OK == |
381 | GNUNET_CONFIGURATION_write (cfg, | ||
382 | fname)); | ||
455 | GNUNET_CONFIGURATION_destroy (cfg); | 383 | GNUNET_CONFIGURATION_destroy (cfg); |
456 | return fname; | 384 | return fname; |
457 | } | 385 | } |
458 | 386 | ||
459 | static void | ||
460 | run_measurement (unsigned long long p1_quota_in, | ||
461 | unsigned long long p1_quota_out, | ||
462 | unsigned long long p2_quota_in, | ||
463 | unsigned long long p2_quota_out) | ||
464 | { | ||
465 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
466 | |||
467 | /* setting ATS quota */ | ||
468 | quota_out_p1 = p1_quota_out; | ||
469 | gen_cfg_p1 = generate_config (cfg_file_p1, p1_quota_in, p1_quota_out); | ||
470 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n", | ||
471 | gen_cfg_p1); | ||
472 | |||
473 | quota_in_p2 = p2_quota_in; | ||
474 | gen_cfg_p2 = generate_config (cfg_file_p2, p2_quota_in, p2_quota_out); | ||
475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n", | ||
476 | gen_cfg_p2); | ||
477 | |||
478 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p1, 1, ¬ify_receive, | ||
479 | ¬ify_connect, ¬ify_disconnect, | ||
480 | &start_cb, NULL); | ||
481 | |||
482 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p2, 2, ¬ify_receive, | ||
483 | ¬ify_connect, ¬ify_disconnect, | ||
484 | &start_cb, NULL); | ||
485 | |||
486 | if ((p1 == NULL) || (p2 == NULL)) | ||
487 | { | ||
488 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | ||
489 | if (die_task != NULL) | ||
490 | GNUNET_SCHEDULER_cancel (die_task); | ||
491 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
492 | return; | ||
493 | } | ||
494 | } | ||
495 | |||
496 | 387 | ||
497 | static void | 388 | static int |
498 | run (void *cls, char *const *args, const char *cfgfile, | 389 | check (void *cls, |
499 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 390 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, |
391 | const char *test_plugin_, | ||
392 | const char *test_name_, | ||
393 | unsigned int num_peers, | ||
394 | char *cfg_files[]) | ||
500 | { | 395 | { |
501 | unsigned long long p1_quota_in = 10000; | 396 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
502 | unsigned long long p1_quota_out = 10000; | 397 | .connect_continuation = &start_task, |
503 | unsigned long long p2_quota_in = 10000; | 398 | .config_file = "test_quota_compliance_data.conf", |
504 | unsigned long long p2_quota_out = 10000; | 399 | .rec = ¬ify_receive, |
400 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, | ||
401 | .nd = ¬ify_disconnect, | ||
402 | .shutdown_task = &custom_shutdown, | ||
403 | .timeout = TIMEOUT | ||
404 | }; | ||
405 | ccc = &my_ccc; | ||
505 | 406 | ||
506 | if (NULL != strstr (test_name, "asymmetric")) | 407 | if (NULL != strstr (test_name_, |
408 | "asymmetric")) | ||
507 | { | 409 | { |
508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
509 | "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n", | 411 | "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n", |
510 | p2_quota_in, p2_quota_out); | 412 | quota_in[1], |
511 | p1_quota_out = 1024 * 1024 * 1024; | 413 | quota_out[1]); |
512 | p1_quota_in = 1024 * 1024 * 1024; | 414 | quota_out[0] = 1024 * 1024 * 1024; |
415 | quota_in[0] = 1024 * 1024 * 1024; | ||
513 | } | 416 | } |
514 | else | 417 | else |
515 | { | 418 | { |
516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 419 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
517 | "Running symmetric test with (in/out) %llu/%llu b/s \n", | 420 | "Running symmetric test with (in/out) %llu/%llu b/s \n", |
518 | p2_quota_in, p2_quota_out); | 421 | quota_in[1], |
422 | quota_out[1]); | ||
423 | } | ||
424 | for (unsigned int i=0;i<2;i++) | ||
425 | { | ||
426 | gen_cfgs[i] = generate_config (cfg_files[i], | ||
427 | quota_in[i], | ||
428 | quota_out[i]); | ||
429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
430 | "Generated config file `%s'\n", | ||
431 | gen_cfgs[i]); | ||
519 | } | 432 | } |
520 | run_measurement (p1_quota_in, p1_quota_out, p2_quota_in, p2_quota_out); | ||
521 | } | ||
522 | |||
523 | static int | ||
524 | check () | ||
525 | { | ||
526 | static char *argv[] = { "test_transport-quota-compliance", | ||
527 | "-c", | ||
528 | "test_quota_compliance_data.conf", | ||
529 | NULL | ||
530 | }; | ||
531 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
532 | GNUNET_GETOPT_OPTION_END | ||
533 | }; | ||
534 | 433 | ||
535 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, | 434 | return GNUNET_TRANSPORT_TESTING_connect_check (&my_ccc, |
536 | "nohelp", options, &run, NULL); | 435 | tth_, |
537 | return test_failed; | 436 | test_plugin_, |
437 | test_name_, | ||
438 | num_peers, | ||
439 | gen_cfgs); | ||
538 | } | 440 | } |
539 | 441 | ||
442 | |||
540 | int | 443 | int |
541 | main (int argc, char *argv[]) | 444 | main (int argc, char *argv[]) |
542 | { | 445 | { |
543 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]); | 446 | if (GNUNET_OK != |
544 | 447 | GNUNET_TRANSPORT_TESTING_main (2, | |
545 | GNUNET_log_setup (test_name, | 448 | &check, |
546 | "WARNING", | 449 | NULL)) |
547 | NULL); | ||
548 | |||
549 | test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__); | ||
550 | test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source); | ||
551 | |||
552 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
553 | |||
554 | cfg_file_p1 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 1); | ||
555 | cfg_file_p2 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 2); | ||
556 | |||
557 | check (); | ||
558 | |||
559 | GNUNET_free (cfg_file_p1); | ||
560 | GNUNET_free (cfg_file_p2); | ||
561 | |||
562 | if (GNUNET_YES == GNUNET_DISK_file_test (gen_cfg_p1)) | ||
563 | { | 450 | { |
564 | GNUNET_DISK_directory_remove (gen_cfg_p1); | 451 | GNUNET_break (0); |
565 | GNUNET_free (gen_cfg_p1); | 452 | return 1; |
566 | } | 453 | } |
567 | 454 | for (unsigned int i=0;i<2;i++) | |
568 | if (GNUNET_YES == GNUNET_DISK_file_test (gen_cfg_p2)) | ||
569 | { | 455 | { |
570 | GNUNET_DISK_directory_remove (gen_cfg_p2); | 456 | if ( (NULL != gen_cfgs[0]) && |
571 | GNUNET_free (gen_cfg_p2); | 457 | (GNUNET_YES == GNUNET_DISK_file_test (gen_cfgs[0])) ) |
458 | { | ||
459 | GNUNET_DISK_directory_remove (gen_cfgs[0]); | ||
460 | GNUNET_free (gen_cfgs[0]); | ||
461 | } | ||
572 | } | 462 | } |
573 | 463 | return 0; | |
574 | GNUNET_free (test_source); | ||
575 | GNUNET_free (test_plugin); | ||
576 | GNUNET_free (test_name); | ||
577 | |||
578 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
579 | |||
580 | return test_failed; | ||
581 | } | 464 | } |
582 | 465 | ||
583 | 466 | ||