summaryrefslogtreecommitdiff
path: root/src/ats-tests/perf_ats.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-09-17 12:45:30 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-09-17 12:45:30 +0000
commite039055bd12606f580ba257df97187cfe82a9f67 (patch)
tree07e599b82df3a64769dea9131f6b76d295000627 /src/ats-tests/perf_ats.c
parent659b36203e9a60e61f60a0185958313b6d7bd5ac (diff)
downloadgnunet-e039055bd12606f580ba257df97187cfe82a9f67.tar.gz
gnunet-e039055bd12606f580ba257df97187cfe82a9f67.zip
fix indent
Diffstat (limited to 'src/ats-tests/perf_ats.c')
-rw-r--r--src/ats-tests/perf_ats.c797
1 files changed, 396 insertions, 401 deletions
diff --git a/src/ats-tests/perf_ats.c b/src/ats-tests/perf_ats.c
index 574ada318..e52b5f114 100644
--- a/src/ats-tests/perf_ats.c
+++ b/src/ats-tests/perf_ats.c
@@ -96,9 +96,9 @@ struct BenchmarkPeer
96 */ 96 */
97 struct ConnectOperation *connect_ops; 97 struct ConnectOperation *connect_ops;
98 98
99 /** 99 /**
100 * ATS Measurement Partner 100 * ATS Measurement Partner
101 */ 101 */
102 struct BenchmarkPeer *destination; 102 struct BenchmarkPeer *destination;
103 103
104 GNUNET_SCHEDULER_TaskIdentifier ats_task; 104 GNUNET_SCHEDULER_TaskIdentifier ats_task;
@@ -106,38 +106,38 @@ struct BenchmarkPeer
106 /* Message exchange */ 106 /* Message exchange */
107 107
108 /** 108 /**
109 * Core transmit handle 109 * Core transmit handle
110 */ 110 */
111 struct GNUNET_CORE_TransmitHandle *cth; 111 struct GNUNET_CORE_TransmitHandle *cth;
112 112
113 /** 113 /**
114 * DLL for pending messages: head 114 * DLL for pending messages: head
115 */ 115 */
116 struct PendingMessages *p_head; 116 struct PendingMessages *p_head;
117 117
118 /** 118 /**
119 * DLL for pending messages: tail 119 * DLL for pending messages: tail
120 */ 120 */
121 struct PendingMessages *p_tail; 121 struct PendingMessages *p_tail;
122 122
123 /** 123 /**
124 * Bit-mask for next partner selection 124 * Bit-mask for next partner selection
125 */ 125 */
126 uint32_t send_mask; 126 uint32_t send_mask;
127 127
128 /** 128 /**
129 * Current message for partner? 129 * Current message for partner?
130 */ 130 */
131 int partner_msg; 131 int partner_msg;
132 132
133 /** 133 /**
134 * Number of core connections 134 * Number of core connections
135 */ 135 */
136 int core_connections; 136 int core_connections;
137 137
138 /** 138 /**
139 * Number of slave connections 139 * Number of slave connections
140 */ 140 */
141 int slave_connections; 141 int slave_connections;
142 142
143 /** 143 /**
@@ -168,24 +168,24 @@ static struct BenchmarkPeer *bp_slaves;
168 168
169struct BenchmarkState 169struct BenchmarkState
170{ 170{
171 /* Are we connected to ATS service of all peers: GNUNET_YES/NO */ 171 /* Are we connected to ATS service of all peers: GNUNET_YES/NO */
172 int connected_ATS_service; 172 int connected_ATS_service;
173 173
174 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */ 174 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
175 int connected_CORE_service; 175 int connected_CORE_service;
176 176
177 /* Are we connected to all peers: GNUNET_YES/NO */ 177 /* Are we connected to all peers: GNUNET_YES/NO */
178 int connected_PEERS; 178 int connected_PEERS;
179 179
180 /* Are we connected to all slave peers on CORE level: GNUNET_YES/NO */ 180 /* Are we connected to all slave peers on CORE level: GNUNET_YES/NO */
181 int connected_CORE; 181 int connected_CORE;
182 182
183 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */ 183 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
184 int benchmarking; 184 int benchmarking;
185 185
186 int *core_connections; 186 int *core_connections;
187 187
188 uint32_t partner_map; 188 uint32_t partner_map;
189}; 189};
190 190
191static struct BenchmarkState state; 191static struct BenchmarkState state;
@@ -205,9 +205,9 @@ static int pref_val;
205 */ 205 */
206struct PendingMessages 206struct PendingMessages
207{ 207{
208 struct PendingMessages *prev; 208 struct PendingMessages *prev;
209 struct PendingMessages *next; 209 struct PendingMessages *next;
210 struct GNUNET_PeerIdentity target; 210 struct GNUNET_PeerIdentity target;
211}; 211};
212 212
213 213
@@ -236,20 +236,21 @@ core_connect_completion_cb (void *cls,
236 236
237static void evaluate () 237static void evaluate ()
238{ 238{
239 int c_p; 239 int c_p;
240 struct BenchmarkPeer *bp; 240 struct BenchmarkPeer *bp;
241 int total_out; 241 int total_out;
242 int partner_out; 242 int partner_out;
243 243
244 for (c_p = 0; c_p < c_master_peers; c_p++) 244 for (c_p = 0; c_p < c_master_peers; c_p++)
245 { 245 {
246 bp = &bp_master[c_p]; 246 bp = &bp_master[c_p];
247 total_out = (bp->messages_sent * TEST_MESSAGE_SIZE) / 10240; 247 total_out = (bp->messages_sent * TEST_MESSAGE_SIZE) / 10240;
248 partner_out = (bp->messages_sent_partner * TEST_MESSAGE_SIZE) / 10240; 248 partner_out = (bp->messages_sent_partner * TEST_MESSAGE_SIZE) / 10240;
249 fprintf (stderr, _("Peer %u: Out total: %u KiB/s, out partner %u KiB/s\n"), 249
250 bp->no, 250 fprintf (stderr, _("Master peer %u: Out total: %u KiB/s, out partner %u KiB/s\n"),
251 total_out, partner_out 251 bp->no,
252 /*partner_out / (total_out / 100)*/); 252 total_out, partner_out
253 /*partner_out / (total_out / 100)*/);
253 } 254 }
254} 255}
255 256
@@ -276,116 +277,114 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
276 277
277 for (c_p = 0; c_p < c_master_peers; c_p++) 278 for (c_p = 0; c_p < c_master_peers; c_p++)
278 { 279 {
279 next = bp_master[c_p].p_head; 280 next = bp_master[c_p].p_head;
280 for (cur = next; cur != NULL; cur = next ) 281 for (cur = next; cur != NULL; cur = next )
281 { 282 {
282 next = cur->next; 283 next = cur->next;
283 GNUNET_CONTAINER_DLL_remove (bp_master[c_p].p_head, bp_master[c_p].p_tail, cur); 284 GNUNET_CONTAINER_DLL_remove (bp_master[c_p].p_head, bp_master[c_p].p_tail, cur);
284 GNUNET_free (cur); 285 GNUNET_free (cur);
285 } 286 }
286 287
287 if (GNUNET_SCHEDULER_NO_TASK != bp_master[c_p].ats_task) 288 if (GNUNET_SCHEDULER_NO_TASK != bp_master[c_p].ats_task)
288 { 289 {
289 GNUNET_SCHEDULER_cancel (bp_master[c_p].ats_task); 290 GNUNET_SCHEDULER_cancel (bp_master[c_p].ats_task);
290 bp_master[c_p].ats_task = GNUNET_SCHEDULER_NO_TASK; 291 bp_master[c_p].ats_task = GNUNET_SCHEDULER_NO_TASK;
291 } 292 }
292 293
293 if (NULL != bp_master[c_p].cth) 294 if (NULL != bp_master[c_p].cth)
294 { 295 {
295 GNUNET_CORE_notify_transmit_ready_cancel(bp_master[c_p].cth); 296 GNUNET_CORE_notify_transmit_ready_cancel(bp_master[c_p].cth);
296 bp_master[c_p].cth = NULL; 297 bp_master[c_p].cth = NULL;
297 } 298 }
298 299
299 if (NULL != bp_master[c_p].ats_perf_op) 300 if (NULL != bp_master[c_p].ats_perf_op)
300 { 301 {
301 GNUNET_TESTBED_operation_done (bp_master[c_p].ats_perf_op); 302 GNUNET_TESTBED_operation_done (bp_master[c_p].ats_perf_op);
302 bp_master[c_p].ats_perf_op = NULL; 303 bp_master[c_p].ats_perf_op = NULL;
303 } 304 }
304 305
305 if (NULL != bp_master[c_p].core_op) 306 if (NULL != bp_master[c_p].core_op)
306 { 307 {
307 GNUNET_TESTBED_operation_done (bp_master[c_p].core_op); 308 GNUNET_TESTBED_operation_done (bp_master[c_p].core_op);
308 bp_master[c_p].core_op = NULL; 309 bp_master[c_p].core_op = NULL;
309 } 310 }
310 311
311 if (NULL != bp_master[c_p].info_op) 312 if (NULL != bp_master[c_p].info_op)
312 { 313 {
313 GNUNET_break (0); 314 GNUNET_break (0);
314 GNUNET_TESTBED_operation_done (bp_master[c_p].info_op); 315 GNUNET_TESTBED_operation_done (bp_master[c_p].info_op);
315 bp_master[c_p].info_op = NULL; 316 bp_master[c_p].info_op = NULL;
316 } 317 }
317 318
318 for (c_op = 0; c_op < c_slave_peers; c_op++) 319 for (c_op = 0; c_op < c_slave_peers; c_op++)
319 { 320 {
320 if (NULL != bp_master[c_p].connect_ops[c_op].connect_op) 321 if (NULL != bp_master[c_p].connect_ops[c_op].connect_op)
321 { 322 {
322 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect peer 0 and %u\n"), c_p); 323 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect peer 0 and %u\n"), c_p);
323 GNUNET_TESTBED_operation_done (bp_master[c_p].connect_ops[c_op].connect_op); 324 GNUNET_TESTBED_operation_done (bp_master[c_p].connect_ops[c_op].connect_op);
324 bp_master[c_p].connect_ops[c_op].connect_op = NULL; 325 bp_master[c_p].connect_ops[c_op].connect_op = NULL;
325 result = 1; 326 result = 1;
326 } 327 }
327 } 328 }
328 GNUNET_free (bp_master[c_p].connect_ops); 329 GNUNET_free (bp_master[c_p].connect_ops);
329 } 330 }
330 331
331 for (c_p = 0; c_p < c_slave_peers; c_p++) 332 for (c_p = 0; c_p < c_slave_peers; c_p++)
332 { 333 {
333 next = bp_slaves[c_p].p_head; 334 next = bp_slaves[c_p].p_head;
334 for (cur = next; cur != NULL; cur = next ) 335 for (cur = next; cur != NULL; cur = next )
335 { 336 {
336 next = cur->next; 337 next = cur->next;
337 GNUNET_CONTAINER_DLL_remove (bp_slaves[c_p].p_head, bp_slaves[c_p].p_tail, cur); 338 GNUNET_CONTAINER_DLL_remove (bp_slaves[c_p].p_head, bp_slaves[c_p].p_tail, cur);
338 GNUNET_free (cur); 339 GNUNET_free (cur);
339 } 340 }
340 341
341 if (NULL != bp_slaves[c_p].cth) 342 if (NULL != bp_slaves[c_p].cth)
342 { 343 {
343 GNUNET_CORE_notify_transmit_ready_cancel(bp_slaves[c_p].cth); 344 GNUNET_CORE_notify_transmit_ready_cancel(bp_slaves[c_p].cth);
344 bp_slaves[c_p].cth = NULL; 345 bp_slaves[c_p].cth = NULL;
345 } 346 }
346 347
347 if (NULL != bp_slaves[c_p].ats_perf_op) 348 if (NULL != bp_slaves[c_p].ats_perf_op)
348 { 349 {
349 GNUNET_TESTBED_operation_done (bp_slaves[c_p].ats_perf_op); 350 GNUNET_TESTBED_operation_done (bp_slaves[c_p].ats_perf_op);
350 bp_slaves[c_p].ats_perf_op = NULL; 351 bp_slaves[c_p].ats_perf_op = NULL;
351 } 352 }
352 353
353 if (NULL != bp_slaves[c_p].core_op) 354 if (NULL != bp_slaves[c_p].core_op)
354 { 355 {
355 GNUNET_TESTBED_operation_done (bp_slaves[c_p].core_op); 356 GNUNET_TESTBED_operation_done (bp_slaves[c_p].core_op);
356 bp_slaves[c_p].core_op = NULL; 357 bp_slaves[c_p].core_op = NULL;
357 } 358 }
358 359
359 if (NULL != bp_slaves[c_p].info_op) 360 if (NULL != bp_slaves[c_p].info_op)
360 { 361 {
361 GNUNET_break (0); 362 GNUNET_break (0);
362 GNUNET_TESTBED_operation_done (bp_slaves[c_p].info_op); 363 GNUNET_TESTBED_operation_done (bp_slaves[c_p].info_op);
363 bp_slaves[c_p].info_op = NULL; 364 bp_slaves[c_p].info_op = NULL;
364 } 365 }
365
366 } 366 }
367 367 GNUNET_SCHEDULER_shutdown();
368 GNUNET_SCHEDULER_shutdown();
369} 368}
370 369
371static struct BenchmarkPeer * 370static struct BenchmarkPeer *
372find_peer (const struct GNUNET_PeerIdentity * peer) 371find_peer (const struct GNUNET_PeerIdentity * peer)
373{ 372{
374 int c_p; 373 int c_p;
375 374
376 for (c_p = 0; c_p < c_master_peers; c_p++) 375 for (c_p = 0; c_p < c_master_peers; c_p++)
377 { 376 {
378 if (0 == memcmp (&bp_master[c_p].id, peer, sizeof (struct GNUNET_PeerIdentity))) 377 if (0 == memcmp (&bp_master[c_p].id, peer, sizeof (struct GNUNET_PeerIdentity)))
379 return &bp_master[c_p]; 378 return &bp_master[c_p];
380 } 379 }
381 380
382 for (c_p = 0; c_p < c_slave_peers; c_p++) 381 for (c_p = 0; c_p < c_slave_peers; c_p++)
383 { 382 {
384 if (0 == memcmp (&bp_slaves[c_p].id, peer, sizeof (struct GNUNET_PeerIdentity))) 383 if (0 == memcmp (&bp_slaves[c_p].id, peer, sizeof (struct GNUNET_PeerIdentity)))
385 return &bp_slaves[c_p]; 384 return &bp_slaves[c_p];
386 } 385 }
387 386
388 return NULL; 387 return NULL;
389} 388}
390 389
391 390
@@ -398,15 +397,15 @@ store_information (struct GNUNET_PeerIdentity *id,
398 const struct GNUNET_ATS_Information *ats, 397 const struct GNUNET_ATS_Information *ats,
399 uint32_t ats_count) 398 uint32_t ats_count)
400{ 399{
401 struct BenchmarkPeer *bp; 400 struct BenchmarkPeer *bp;
402 401
403 bp = find_peer (id); 402 bp = find_peer (id);
404 403
405 if (NULL == bp) 404 if (NULL == bp)
406 { 405 {
407 GNUNET_break (0); 406 GNUNET_break (0);
408 return; 407 return;
409 } 408 }
410} 409}
411 410
412static void 411static void
@@ -418,153 +417,149 @@ ats_performance_info_cb (void *cls,
418 const struct GNUNET_ATS_Information *ats, 417 const struct GNUNET_ATS_Information *ats,
419 uint32_t ats_count) 418 uint32_t ats_count)
420{ 419{
421 struct BenchmarkPeer *bp = cls; 420 struct BenchmarkPeer *bp = cls;
422 int c_a; 421 int c_a;
423 char *peer_id; 422 char *peer_id;
424 423
425 peer_id = GNUNET_strdup (GNUNET_i2s (&bp->id)); 424 peer_id = GNUNET_strdup (GNUNET_i2s (&bp->id));
426 for (c_a = 0; c_a < ats_count; c_a++) 425 for (c_a = 0; c_a < ats_count; c_a++)
427 { 426 {
428 /*GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("%c %03u: %s %s %u\n"), 427 /*GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("%c %03u: %s %s %u\n"),
429 (GNUNET_YES == p->master) ? 'M' : 'S', 428 (GNUNET_YES == p->master) ? 'M' : 'S',
430 p->no, 429 p->no,
431 GNUNET_i2s (&address->peer), 430 GNUNET_i2s (&address->peer),
432 GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)), 431 GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
433 ntohl(ats[c_a].value));*/ 432 ntohl(ats[c_a].value));*/
434 } 433 }
435 434
436 if ((GNUNET_YES == bp->master) && 435 if ((GNUNET_YES == bp->master) &&
437 (0 == memcmp (&address->peer, &bp->destination->id, 436 (0 == memcmp (&address->peer, &bp->destination->id,
438 sizeof (struct GNUNET_PeerIdentity)))) 437 sizeof (struct GNUNET_PeerIdentity))))
439 { 438 {
440 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bandwidth for master %u: %lu %lu\n", 439 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bandwidth for master %u: %lu %lu\n",
441 bp->no, 440 bp->no,
442 (long unsigned int) ntohl(bandwidth_in.value__), 441 (long unsigned int) ntohl(bandwidth_in.value__),
443 (long unsigned int) ntohl(bandwidth_in.value__)); 442 (long unsigned int) ntohl(bandwidth_in.value__));
444 } 443 }
445 444
446 store_information (&bp->id, address, address_active, 445 store_information (&bp->id, address, address_active,
447 bandwidth_in, bandwidth_out, 446 bandwidth_in, bandwidth_out,
448 ats, ats_count); 447 ats, ats_count);
449 448
450 GNUNET_free (peer_id); 449 GNUNET_free (peer_id);
451} 450}
452 451
453static size_t 452static size_t
454core_send_ready (void *cls, size_t size, void *buf) 453core_send_ready (void *cls, size_t size, void *buf)
455{ 454{
456 static char msgbuf[TEST_MESSAGE_SIZE]; 455 static char msgbuf[TEST_MESSAGE_SIZE];
457 struct BenchmarkPeer *bp = cls; 456 struct BenchmarkPeer *bp = cls;
458 struct GNUNET_MessageHeader *msg; 457 struct GNUNET_MessageHeader *msg;
459 458
460 bp->cth = NULL; 459 bp->cth = NULL;
461 460
462 bp->messages_sent ++; 461 bp->messages_sent ++;
463 if (GNUNET_YES == bp->partner_msg) 462 if (GNUNET_YES == bp->partner_msg)
464 { 463 {
465 bp->messages_sent_partner ++; 464 bp->messages_sent_partner ++;
466 bp->partner_msg = GNUNET_NO; 465 bp->partner_msg = GNUNET_NO;
467 } 466 }
468 467
469 msg = (struct GNUNET_MessageHeader *) &msgbuf; 468 msg = (struct GNUNET_MessageHeader *) &msgbuf;
470 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE); 469 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
471 msg->type = htons (TEST_MESSAGE_TYPE_PING); 470 msg->type = htons (TEST_MESSAGE_TYPE_PING);
472 msg->size = htons (TEST_MESSAGE_SIZE); 471 msg->size = htons (TEST_MESSAGE_SIZE);
473 memcpy (buf, msg, TEST_MESSAGE_SIZE); 472 memcpy (buf, msg, TEST_MESSAGE_SIZE);
474 return TEST_MESSAGE_SIZE; 473 return TEST_MESSAGE_SIZE;
475} 474}
476 475
477static struct BenchmarkPeer * 476static struct BenchmarkPeer *
478get_next (struct BenchmarkPeer *p) 477get_next (struct BenchmarkPeer *p)
479{ 478{
480 uint32_t b_index; 479 uint32_t b_index;
481 uint32_t index; 480 uint32_t index;
482 int counter; 481 int counter;
483 482
484 if (0 == p->send_mask) 483 if (0 == p->send_mask)
485 p->send_mask = (1 << c_slave_peers) - 1; /* Next round */ 484 p->send_mask = (1 << c_slave_peers) - 1; /* Next round */
486
487 GNUNET_assert (p->send_mask <= (1 << c_slave_peers) - 1);
488 counter = 0;
489 do
490 {
491 index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, c_slave_peers);
492 b_index = 1 << index;
493 counter++;
494 }
495 while ((b_index != (p->send_mask & b_index)) && (counter < c_slave_peers));
496 if ((b_index != (p->send_mask & b_index)) && (counter == c_slave_peers))
497 {
498 /* To many random attempts use fcfs */
499 for (index = 0; index < c_slave_peers - 1; index ++)
500 {
501 b_index = 1 << index;
502 if (b_index == (p->send_mask & b_index))
503 break;
504 }
505 }
506 p->send_mask ^= b_index; /* Remove bit */
507 return &bp_slaves[index];
508 485
486 GNUNET_assert (p->send_mask <= (1 << c_slave_peers) - 1);
487 counter = 0;
488 do
489 {
490 index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, c_slave_peers);
491 b_index = 1 << index;
492 counter++;
493 }
494 while ((b_index != (p->send_mask & b_index)) && (counter < c_slave_peers));
495 if ((b_index != (p->send_mask & b_index)) && (counter == c_slave_peers))
496 {
497 /* To many random attempts use fcfs */
498 for (index = 0; index < c_slave_peers - 1; index ++)
499 {
500 b_index = 1 << index;
501 if (b_index == (p->send_mask & b_index))
502 break;
503 }
504 }
505 p->send_mask ^= b_index; /* Remove bit */
506 return &bp_slaves[index];
509} 507}
510 508
511 509
512static void 510static void
513ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 511ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
514{ 512{
515 static double last = 1; 513 static double last = 1;
516 struct BenchmarkPeer *bp = cls; 514 struct BenchmarkPeer *bp = cls;
517 515
518 bp->ats_task = GNUNET_SCHEDULER_NO_TASK; 516 bp->ats_task = GNUNET_SCHEDULER_NO_TASK;
519 517
520 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Set preference for master %u: %f\n", 518 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Set preference for master %u: %f\n",
521 bp->no, last); 519 bp->no, last);
522 GNUNET_ATS_performance_change_preference (bp->p_handle, &bp->destination->id, 520 GNUNET_ATS_performance_change_preference (bp->p_handle, &bp->destination->id,
523 pref_val, (double) last, 521 pref_val, (double) last,
524 GNUNET_ATS_PREFERENCE_END); 522 GNUNET_ATS_PREFERENCE_END);
525 last++; 523 last++;
526 bp->ats_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 524 bp->ats_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
527 &ats_pref_task, bp); 525 &ats_pref_task, bp);
528} 526}
529 527
530 528
531static void 529static void
532do_benchmark () 530do_benchmark ()
533{ 531{
534 int c_m; 532 int c_m;
535 struct BenchmarkPeer *s; 533 struct BenchmarkPeer *s;
536 struct BenchmarkPeer *bp; 534 struct BenchmarkPeer *bp;
537 535
538 if ((state.connected_ATS_service == GNUNET_NO) || 536 if ((state.connected_ATS_service == GNUNET_NO) ||
539 (state.connected_CORE_service == GNUNET_NO) || 537 (state.connected_CORE_service == GNUNET_NO) ||
540 (state.connected_PEERS == GNUNET_NO) || 538 (state.connected_PEERS == GNUNET_NO) ||
541 (state.connected_CORE == GNUNET_NO)) 539 (state.connected_CORE == GNUNET_NO))
542 return; 540 return;
543
544 state.benchmarking = GNUNET_YES;
545 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
546 _("Benchmarking start\n"));
547
548 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
549 GNUNET_SCHEDULER_cancel (shutdown_task);
550 shutdown_task = GNUNET_SCHEDULER_add_delayed (BENCHMARK_DURATION, &do_shutdown, NULL);
551
552 /* Start sending test messages */
553 for (c_m = 0; c_m < c_master_peers; c_m ++)
554 {
555 bp = &bp_master[c_m];
556 s = get_next (bp);
557 if (0 == memcmp(&s->id, &bp->destination->id, sizeof (struct GNUNET_PeerIdentity)))
558 bp->partner_msg = GNUNET_YES;
559 bp->cth = GNUNET_CORE_notify_transmit_ready (bp->ch,
560 GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES,
561 &s->id,
562 TEST_MESSAGE_SIZE, &core_send_ready, bp);
563 bp->ats_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
564 &ats_pref_task, bp);
565 }
566 541
542 state.benchmarking = GNUNET_YES;
543 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
544 _("Benchmarking start\n"));
567 545
546 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
547 GNUNET_SCHEDULER_cancel (shutdown_task);
548 shutdown_task = GNUNET_SCHEDULER_add_delayed (BENCHMARK_DURATION, &do_shutdown, NULL);
549
550 /* Start sending test messages */
551 for (c_m = 0; c_m < c_master_peers; c_m ++)
552 {
553 bp = &bp_master[c_m];
554 s = get_next (bp);
555 if (0 == memcmp(&s->id, &bp->destination->id, sizeof (struct GNUNET_PeerIdentity)))
556 bp->partner_msg = GNUNET_YES;
557 bp->cth = GNUNET_CORE_notify_transmit_ready (bp->ch,
558 GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES,
559 &s->id, TEST_MESSAGE_SIZE, &core_send_ready, bp);
560 bp->ats_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
561 &ats_pref_task, bp);
562 }
568} 563}
569 564
570 565
@@ -573,84 +568,83 @@ connect_completion_callback (void *cls,
573 struct GNUNET_TESTBED_Operation *op, 568 struct GNUNET_TESTBED_Operation *op,
574 const char *emsg) 569 const char *emsg)
575{ 570{
576 struct ConnectOperation *cop = cls; 571 struct ConnectOperation *cop = cls;
577 static int ops = 0 ; 572 static int ops = 0 ;
578 int c; 573 int c;
579 if (NULL == emsg) 574 if (NULL == emsg)
580 { 575 {
581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
582 _("Connected master peer %u with peer %u\n"), cop->master->no, cop->slave->no); 577 _("Connected master peer %u with peer %u\n"), cop->master->no, cop->slave->no);
583 } 578 }
584 else 579 else
585 { 580 {
586 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 581 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
587 _("Failed to connect master peer%u with peer %u\n"), cop->master->no, cop->slave->no); 582 _("Failed to connect master peer%u with peer %u\n"), cop->master->no, cop->slave->no);
588 GNUNET_break (0); 583 GNUNET_break (0);
589 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) 584 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
590 GNUNET_SCHEDULER_cancel(shutdown_task); 585 GNUNET_SCHEDULER_cancel(shutdown_task);
591 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); 586 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
592 } 587 }
593 GNUNET_TESTBED_operation_done(op); 588 GNUNET_TESTBED_operation_done(op);
594 ops++; 589 ops++;
595 for (c = 0; c < c_slave_peers; c++) 590 for (c = 0; c < c_slave_peers; c++)
596 { 591 {
597 if (cop == &cop->master->connect_ops[c]) 592 if (cop == &cop->master->connect_ops[c])
598 cop->master->connect_ops[c].connect_op = NULL; 593 cop->master->connect_ops[c].connect_op = NULL;
599 } 594 }
600 if (ops == c_master_peers * c_slave_peers) 595 if (ops == c_master_peers * c_slave_peers)
601 { 596 {
602 state.connected_PEERS = GNUNET_YES; 597 state.connected_PEERS = GNUNET_YES;
603 GNUNET_SCHEDULER_add_now (&do_benchmark, NULL); 598 GNUNET_SCHEDULER_add_now (&do_benchmark, NULL);
604 } 599 }
605} 600}
606 601
607 602
608static void 603static void
609do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 604do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
610{ 605{
611 int c_m; 606 int c_m;
612 int c_s; 607 int c_s;
613 struct BenchmarkPeer *bp; 608 struct BenchmarkPeer *bp;
614
615 if ((state.connected_ATS_service == GNUNET_NO) ||
616 (state.connected_CORE_service == GNUNET_NO))
617 {
618 return;
619 }
620 609
621 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting peers on CORE level\n")); 610 if ((state.connected_ATS_service == GNUNET_NO) ||
611 (state.connected_CORE_service == GNUNET_NO))
612 {
613 return;
614 }
622 615
623 for (c_m = 0; c_m < c_master_peers; c_m ++) 616 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting peers on CORE level\n"));
624 {
625 bp = &bp_master[c_m];
626 bp->connect_ops = GNUNET_malloc (c_slave_peers * sizeof (struct ConnectOperation));
627 617
628 for (c_s = 0; c_s < c_slave_peers; c_s ++) 618 for (c_m = 0; c_m < c_master_peers; c_m ++)
629 { 619 {
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Connecting master peer %u with slave peer %u\n"), 620 bp = &bp_master[c_m];
631 bp->no, bp_slaves[c_s].no); 621 bp->connect_ops = GNUNET_malloc (c_slave_peers * sizeof (struct ConnectOperation));
632 622
633 bp->connect_ops[c_s].master = bp; 623 for (c_s = 0; c_s < c_slave_peers; c_s ++)
634 bp->connect_ops[c_s].slave = &bp_slaves[c_s]; 624 {
635 bp->connect_ops[c_s].connect_op = GNUNET_TESTBED_overlay_connect( NULL, 625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
636 &connect_completion_callback, 626 _("Connecting master peer %u with slave peer %u\n"),
637 &bp->connect_ops[c_s], 627 bp->no, bp_slaves[c_s].no);
638 bp_slaves[c_s].peer, 628 bp->connect_ops[c_s].master = bp;
639 bp->peer); 629 bp->connect_ops[c_s].slave = &bp_slaves[c_s];
640 630 bp->connect_ops[c_s].connect_op = GNUNET_TESTBED_overlay_connect( NULL,
641 if (NULL == bp->connect_ops[c_s].connect_op) 631 &connect_completion_callback,
642 { 632 &bp->connect_ops[c_s],
643 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 633 bp_slaves[c_s].peer,
644 _("Could not connect master peer %u and slave peer %u\n"), 634 bp->peer);
645 bp->no, bp_slaves[c_s].no); 635 if (NULL == bp->connect_ops[c_s].connect_op)
646 GNUNET_break (0); 636 {
647 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) 637 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
648 GNUNET_SCHEDULER_cancel(shutdown_task); 638 _("Could not connect master peer %u and slave peer %u\n"),
649 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); 639 bp->no, bp_slaves[c_s].no);
650 return; 640 GNUNET_break (0);
651 } 641 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
652 } 642 GNUNET_SCHEDULER_cancel(shutdown_task);
653 } 643 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
644 return;
645 }
646 }
647 }
654} 648}
655 649
656 650
@@ -943,26 +937,26 @@ core_connect_completion_cb (void *cls,
943 void *ca_result, 937 void *ca_result,
944 const char *emsg ) 938 const char *emsg )
945{ 939{
946 static int core_done = 0; 940 static int core_done = 0;
947 if ((NULL != emsg) || (NULL == ca_result)) 941 if ((NULL != emsg) || (NULL == ca_result))
948 { 942 {
949 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 943 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
950 _("Initialization failed, shutdown\n")); 944 _("Initialization failed, shutdown\n"));
951 GNUNET_break (0); 945 GNUNET_break (0);
952 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) 946 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
953 GNUNET_SCHEDULER_cancel(shutdown_task); 947 GNUNET_SCHEDULER_cancel(shutdown_task);
954 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); 948 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
955 return; 949 return;
956 } 950 }
957 core_done ++; 951 core_done ++;
958 952
959 if (core_done == c_slave_peers + c_master_peers) 953 if (core_done == c_slave_peers + c_master_peers)
960 { 954 {
961 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 955 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
962 "Connected to all CORE services\n"); 956 "Connected to all CORE services\n");
963 state.connected_CORE_service = GNUNET_YES; 957 state.connected_CORE_service = GNUNET_YES;
964 GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL); 958 GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL);
965 } 959 }
966} 960}
967 961
968 962
@@ -984,28 +978,27 @@ core_disconnect_adapter (void *cls, void *op_result)
984static void 978static void
985do_connect_core (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 979do_connect_core (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
986{ 980{
987 int c_p; 981 int c_p;
988 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 982 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
989 "Connecting to all CORE services\n"); 983 "Connecting to all CORE services\n");
990 for (c_p = 0; c_p < c_master_peers; c_p++) 984 for (c_p = 0; c_p < c_master_peers; c_p++)
991 { 985 {
992 bp_master[c_p].core_op = GNUNET_TESTBED_service_connect (NULL, 986 bp_master[c_p].core_op = GNUNET_TESTBED_service_connect (NULL,
993 bp_master[c_p].peer, "core", 987 bp_master[c_p].peer, "core",
994 core_connect_completion_cb, NULL, 988 core_connect_completion_cb, NULL,
995 &core_connect_adapter, 989 &core_connect_adapter,
996 &core_disconnect_adapter, 990 &core_disconnect_adapter,
997 &bp_master[c_p]); 991 &bp_master[c_p]);
998
999 } 992 }
1000 993
1001 for (c_p = 0; c_p < c_slave_peers; c_p++) 994 for (c_p = 0; c_p < c_slave_peers; c_p++)
1002 { 995 {
1003 bp_slaves[c_p].core_op = GNUNET_TESTBED_service_connect (NULL, 996 bp_slaves[c_p].core_op = GNUNET_TESTBED_service_connect (NULL,
1004 bp_slaves[c_p].peer, "core", 997 bp_slaves[c_p].peer, "core",
1005 core_connect_completion_cb, NULL, 998 core_connect_completion_cb, NULL,
1006 &core_connect_adapter, 999 &core_connect_adapter,
1007 &core_disconnect_adapter, 1000 &core_disconnect_adapter,
1008 &bp_slaves[c_p]); 1001 &bp_slaves[c_p]);
1009 } 1002 }
1010} 1003}
1011 1004
@@ -1064,53 +1057,53 @@ ats_connect_completion_cb (void *cls,
1064 void *ca_result, 1057 void *ca_result,
1065 const char *emsg ) 1058 const char *emsg )
1066{ 1059{
1067 static int op_done = 0; 1060 static int op_done = 0;
1068 if ((NULL != emsg) || (NULL == ca_result)) 1061 if ((NULL != emsg) || (NULL == ca_result))
1069 { 1062 {
1070 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1063 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1071 _("Initialization failed, shutdown\n")); 1064 _("Initialization failed, shutdown\n"));
1072 GNUNET_break (0); 1065 GNUNET_break (0);
1073 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) 1066 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
1074 GNUNET_SCHEDULER_cancel(shutdown_task); 1067 GNUNET_SCHEDULER_cancel(shutdown_task);
1075 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); 1068 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
1076 return; 1069 return;
1077 } 1070 }
1078 1071
1079 op_done ++; 1072 op_done ++;
1080 if (op_done == (c_slave_peers + c_master_peers)) 1073 if (op_done == (c_slave_peers + c_master_peers))
1081 { 1074 {
1082 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1075 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1083 "Connected to all ATS services\n"); 1076 "Connected to all ATS services\n");
1084 state.connected_ATS_service = GNUNET_YES; 1077 state.connected_ATS_service = GNUNET_YES;
1085 GNUNET_SCHEDULER_add_now (&do_connect_core, NULL); 1078 GNUNET_SCHEDULER_add_now (&do_connect_core, NULL);
1086 } 1079 }
1087} 1080}
1088 1081
1089static void 1082static void
1090do_connect_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1083do_connect_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1091{ 1084{
1092 int c_p; 1085 int c_p;
1093 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1086 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1094 "Connecting to all ATS services %u\n", c_slave_peers); 1087 "Connecting to all ATS services %u\n", c_slave_peers);
1095 for (c_p = 0; c_p < c_master_peers; c_p++) 1088 for (c_p = 0; c_p < c_master_peers; c_p++)
1096 { 1089 {
1097 bp_master[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, 1090 bp_master[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL,
1098 bp_master[c_p].peer, "ats", 1091 bp_master[c_p].peer, "ats",
1099 ats_connect_completion_cb, NULL, 1092 ats_connect_completion_cb, NULL,
1100 &ats_perf_connect_adapter, 1093 &ats_perf_connect_adapter,
1101 &ats_perf_disconnect_adapter, 1094 &ats_perf_disconnect_adapter,
1102 &bp_master[c_p]); 1095 &bp_master[c_p]);
1103 1096
1104 } 1097 }
1105 1098
1106 for (c_p = 0; c_p < c_slave_peers; c_p++) 1099 for (c_p = 0; c_p < c_slave_peers; c_p++)
1107 { 1100 {
1108 bp_slaves[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, 1101 bp_slaves[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL,
1109 bp_slaves[c_p].peer, "ats", 1102 bp_slaves[c_p].peer, "ats",
1110 ats_connect_completion_cb, NULL, 1103 ats_connect_completion_cb, NULL,
1111 &ats_perf_connect_adapter, 1104 &ats_perf_connect_adapter,
1112 &ats_perf_disconnect_adapter, 1105 &ats_perf_disconnect_adapter,
1113 &bp_slaves[c_p]); 1106 &bp_slaves[c_p]);
1114 } 1107 }
1115 1108
1116} 1109}
@@ -1151,10 +1144,10 @@ peerinformation_cb (void *cb_cls,
1151 1144
1152 if (done == c_master_peers + c_slave_peers) 1145 if (done == c_master_peers + c_slave_peers)
1153 { 1146 {
1154 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1147 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1155 "Retrieved all peer ID, connect to ATS\n"); 1148 "Retrieved all peer ID, connect to ATS\n");
1156 state.connected_CORE_service = GNUNET_YES; 1149 state.connected_CORE_service = GNUNET_YES;
1157 GNUNET_SCHEDULER_add_now (&do_connect_ats, NULL); 1150 GNUNET_SCHEDULER_add_now (&do_connect_ats, NULL);
1158 } 1151 }
1159} 1152}
1160 1153
@@ -1193,6 +1186,7 @@ test_main (void *cls,
1193 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1186 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1194 _("Initializing... \n")); 1187 _("Initializing... \n"));
1195 1188
1189 /* Setup master peers */
1196 for (c_p = 0; c_p < c_master_peers; c_p++) 1190 for (c_p = 0; c_p < c_master_peers; c_p++)
1197 { 1191 {
1198 GNUNET_assert (NULL != peers_[c_p]); 1192 GNUNET_assert (NULL != peers_[c_p]);
@@ -1208,6 +1202,7 @@ test_main (void *cls,
1208 bp_master[c_p].destination = &bp_slaves[c_p]; 1202 bp_master[c_p].destination = &bp_slaves[c_p];
1209 } 1203 }
1210 1204
1205 /* Setup slave peers */
1211 for (c_p = 0; c_p < c_slave_peers; c_p++) 1206 for (c_p = 0; c_p < c_slave_peers; c_p++)
1212 { 1207 {
1213 GNUNET_assert (NULL != peers_[c_p + c_master_peers]); 1208 GNUNET_assert (NULL != peers_[c_p + c_master_peers]);