aboutsummaryrefslogtreecommitdiff
path: root/src/ats/perf_ats.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-08-21 12:31:00 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-08-21 12:31:00 +0000
commit930616b13bb3e58464501afffbc178d39e6222d6 (patch)
tree2939a11cadde1fefd501bd58d0b3385737e6095b /src/ats/perf_ats.c
parent5c9178d1e7e8ce5d6a75b85d06fcd8549c2cb781 (diff)
downloadgnunet-930616b13bb3e58464501afffbc178d39e6222d6.tar.gz
gnunet-930616b13bb3e58464501afffbc178d39e6222d6.zip
supporting multi master/slave approach
Diffstat (limited to 'src/ats/perf_ats.c')
-rw-r--r--src/ats/perf_ats.c225
1 files changed, 164 insertions, 61 deletions
diff --git a/src/ats/perf_ats.c b/src/ats/perf_ats.c
index 1b79636af..05e2789b0 100644
--- a/src/ats/perf_ats.c
+++ b/src/ats/perf_ats.c
@@ -31,7 +31,10 @@
31 31
32#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 32#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
33#define TESTNAME_PREFIX "perf_ats_" 33#define TESTNAME_PREFIX "perf_ats_"
34#define DEFAULT_NUM 5 34#define DEFAULT_SLAVES_NUM 3
35#define DEFAULT_MASTERS_NUM 1
36
37
35 38
36/** 39/**
37 * Information we track for a peer in the testbed. 40 * Information we track for a peer in the testbed.
@@ -45,6 +48,8 @@ struct BenchmarkPeer
45 48
46 int no; 49 int no;
47 50
51 int master; /* master: GNUNET_YES/NO */
52
48 struct GNUNET_PeerIdentity id; 53 struct GNUNET_PeerIdentity id;
49 54
50 struct GNUNET_CORE_Handle *ch; 55 struct GNUNET_CORE_Handle *ch;
@@ -77,12 +82,33 @@ struct BenchmarkPeer
77 int core_connections; 82 int core_connections;
78}; 83};
79 84
80struct BenchmarkPeer *ph; 85
86static int c_master_peers;
87
88/**
89 * Array of master peers
90 * Preferences to be set for
91 */
92static struct BenchmarkPeer *bp_master;
93
94static int c_slave_peers;
95
96/**
97 * Array of slave peers
98 * Peer used for measurements
99 */
100static struct BenchmarkPeer *bp_slaves;
101
81 102
82struct BenchmarkState 103struct BenchmarkState
83{ 104{
84 int connected_ATS_SRV; 105 /* Are we connected to ATS service of all peers: GNUNET_YES/NO */
85 int connected_CORE_SRV; 106 int connected_ATS_service;
107
108 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
109 int connected_CORE_service;
110
111 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
86 int connected_PEERS; 112 int connected_PEERS;
87 int connected_CORE; 113 int connected_CORE;
88 114
@@ -100,7 +126,7 @@ static int result;
100static char *solver; 126static char *solver;
101static char *preference; 127static char *preference;
102 128
103static int peers; 129
104 130
105static void 131static void
106core_connect_completion_cb (void *cls, 132core_connect_completion_cb (void *cls,
@@ -121,32 +147,63 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
121 shutdown_task = GNUNET_SCHEDULER_NO_TASK; 147 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
122 148
123 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n")); 149 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
124 for (c_p = 0; c_p < peers; c_p++) 150
151 for (c_p = 0; c_p < c_master_peers; c_p++)
152 {
153 if (NULL != bp_master[c_p].ats_perf_op)
154 {
155 GNUNET_TESTBED_operation_done (bp_master[c_p].ats_perf_op);
156 bp_master[c_p].ats_perf_op = NULL;
157 }
158
159 if (NULL != bp_master[c_p].core_op)
160 {
161 GNUNET_TESTBED_operation_done (bp_master[c_p].core_op);
162 bp_master[c_p].core_op = NULL;
163 }
164
165 if (NULL != bp_master[c_p].info_op)
166 {
167 GNUNET_break (0);
168 GNUNET_TESTBED_operation_done (bp_master[c_p].info_op);
169 bp_master[c_p].info_op = NULL;
170 }
171 if (NULL != bp_master[c_p].connect_op)
172 {
173 GNUNET_break (0);
174 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect peer 0 and %u\n"), c_p);
175 GNUNET_TESTBED_operation_done (bp_master[c_p].connect_op);
176 bp_master[c_p].connect_op = NULL;
177 result = 1;
178 }
179 }
180
181 for (c_p = 0; c_p < c_slave_peers; c_p++)
125 { 182 {
126 if (NULL != ph[c_p].ats_perf_op) 183 if (NULL != bp_slaves[c_p].ats_perf_op)
127 { 184 {
128 GNUNET_TESTBED_operation_done (ph[c_p].ats_perf_op); 185 GNUNET_TESTBED_operation_done (bp_slaves[c_p].ats_perf_op);
129 ph[c_p].ats_perf_op = NULL; 186 bp_slaves[c_p].ats_perf_op = NULL;
130 } 187 }
131 188
132 if (NULL != ph[c_p].core_op) 189 if (NULL != bp_slaves[c_p].core_op)
133 { 190 {
134 GNUNET_TESTBED_operation_done (ph[c_p].core_op); 191 GNUNET_TESTBED_operation_done (bp_slaves[c_p].core_op);
135 ph[c_p].core_op = NULL; 192 bp_slaves[c_p].core_op = NULL;
136 } 193 }
137 194
138 if (NULL != ph[c_p].info_op) 195 if (NULL != bp_slaves[c_p].info_op)
139 { 196 {
140 GNUNET_break (0); 197 GNUNET_break (0);
141 GNUNET_TESTBED_operation_done (ph[c_p].info_op); 198 GNUNET_TESTBED_operation_done (bp_slaves[c_p].info_op);
142 ph[c_p].info_op = NULL; 199 bp_slaves[c_p].info_op = NULL;
143 } 200 }
144 if (NULL != ph[c_p].connect_op) 201 if (NULL != bp_slaves[c_p].connect_op)
145 { 202 {
146 GNUNET_break (0); 203 GNUNET_break (0);
147 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect peer 0 and %u\n"), c_p); 204 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect peer 0 and %u\n"), c_p);
148 GNUNET_TESTBED_operation_done (ph[c_p].connect_op); 205 GNUNET_TESTBED_operation_done (bp_slaves[c_p].connect_op);
149 ph[c_p].connect_op = NULL; 206 bp_slaves[c_p].connect_op = NULL;
150 result = 1; 207 result = 1;
151 } 208 }
152 } 209 }
@@ -167,7 +224,7 @@ ats_performance_info_cb (void *cls,
167 struct BenchmarkPeer *p = cls; 224 struct BenchmarkPeer *p = cls;
168 int c_a; 225 int c_a;
169 char *peer_id; 226 char *peer_id;
170 if (p != &ph[0]) 227 if (p != &bp_slaves[0])
171 return; /* print only master peer */ 228 return; /* print only master peer */
172 peer_id = GNUNET_strdup (GNUNET_i2s (&p->id)); 229 peer_id = GNUNET_strdup (GNUNET_i2s (&p->id));
173 for (c_a = 0; c_a < ats_count; c_a++) 230 for (c_a = 0; c_a < ats_count; c_a++)
@@ -185,8 +242,8 @@ ats_performance_info_cb (void *cls,
185static void 242static void
186do_benchmark () 243do_benchmark ()
187{ 244{
188 if ((state.connected_ATS_SRV == GNUNET_NO) || 245 if ((state.connected_ATS_service == GNUNET_NO) ||
189 (state.connected_CORE_SRV == GNUNET_NO) || 246 (state.connected_CORE_service == GNUNET_NO) ||
190 (state.connected_PEERS == GNUNET_NO) || 247 (state.connected_PEERS == GNUNET_NO) ||
191 (state.connected_CORE == GNUNET_NO)) 248 (state.connected_CORE == GNUNET_NO))
192 return; 249 return;
@@ -221,7 +278,7 @@ connect_completion_callback (void *cls,
221 GNUNET_TESTBED_operation_done(op); 278 GNUNET_TESTBED_operation_done(op);
222 p->connect_op = NULL; 279 p->connect_op = NULL;
223 connections++; 280 connections++;
224 if (connections == peers -1) 281 if (connections == c_slave_peers -1)
225 { 282 {
226 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 283 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
227 "All peers connected, start benchmarking \n"); 284 "All peers connected, start benchmarking \n");
@@ -236,15 +293,15 @@ do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
236{ 293{
237 int c_p; 294 int c_p;
238 295
239 if ((state.connected_ATS_SRV == GNUNET_NO) || 296 if ((state.connected_ATS_service == GNUNET_NO) ||
240 (state.connected_CORE_SRV == GNUNET_NO)) 297 (state.connected_CORE_service == GNUNET_NO))
241 return; 298 return;
242 299
243 for (c_p = 1; c_p < peers; c_p ++) 300 for (c_p = 1; c_p < c_slave_peers; c_p ++)
244 { 301 {
245 ph[c_p].connect_op = GNUNET_TESTBED_overlay_connect( NULL, 302 bp_slaves[c_p].connect_op = GNUNET_TESTBED_overlay_connect( NULL,
246 &connect_completion_callback, &ph[c_p], ph[0].peer, ph[c_p].peer); 303 &connect_completion_callback, &bp_slaves[c_p], bp_slaves[0].peer, bp_slaves[c_p].peer);
247 if (NULL == ph[c_p].connect_op) 304 if (NULL == bp_slaves[c_p].connect_op)
248 { 305 {
249 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 306 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
250 _("Could not connect peer 0 and peer %u\n"), c_p); 307 _("Could not connect peer 0 and peer %u\n"), c_p);
@@ -350,11 +407,11 @@ ats_connect_completion_cb (void *cls,
350 } 407 }
351 408
352 op_done ++; 409 op_done ++;
353 if (op_done == peers) 410 if (op_done == c_slave_peers)
354 { 411 {
355 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 412 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
356 _("Initialization done, connecting peers\n")); 413 _("Initialization done, connecting peers\n"));
357 state.connected_ATS_SRV = GNUNET_YES; 414 state.connected_ATS_service = GNUNET_YES;
358 GNUNET_SCHEDULER_add_now (&do_connect, NULL); 415 GNUNET_SCHEDULER_add_now (&do_connect, NULL);
359 } 416 }
360} 417}
@@ -377,13 +434,13 @@ core_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
377 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 434 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
378 "%s connected to %s \n", 435 "%s connected to %s \n",
379 id, GNUNET_i2s (peer)); 436 id, GNUNET_i2s (peer));
380 if (p->core_connections == peers) 437 if (p->core_connections == c_slave_peers)
381 { 438 {
382 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 439 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
383 "%s connected all peers\n", 440 "%s connected all peers\n",
384 id); 441 id);
385 } 442 }
386 if ((p->core_connections == peers) && (p == &ph[0])) 443 if ((p->core_connections == c_slave_peers) && (p == &bp_slaves[0]))
387 { 444 {
388 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 445 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
389 "Master peer %s connected all peers on CORE level\n", id, GNUNET_i2s (peer)); 446 "Master peer %s connected all peers on CORE level\n", id, GNUNET_i2s (peer));
@@ -466,11 +523,11 @@ core_connect_completion_cb (void *cls,
466 return; 523 return;
467 } 524 }
468 core_done ++; 525 core_done ++;
469 if (core_done == peers) 526 if (core_done == c_slave_peers)
470 { 527 {
471 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 528 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
472 "Connected to all CORE services\n"); 529 "Connected to all CORE services\n");
473 state.connected_CORE_SRV = GNUNET_YES; 530 state.connected_CORE_service = GNUNET_YES;
474 GNUNET_SCHEDULER_add_now (&do_connect, NULL); 531 GNUNET_SCHEDULER_add_now (&do_connect, NULL);
475 } 532 }
476} 533}
@@ -513,8 +570,8 @@ peerinformation_cb (void *cb_cls,
513 { 570 {
514 p->id = *pinfo->result.id; 571 p->id = *pinfo->result.id;
515 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 572 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
516 "[%3u] Peers %s\n", 573 "[%c %03u] Peers %s\n",
517 p->no, GNUNET_i2s (&p->id)); 574 (p->master == GNUNET_YES) ? 'M' : 'S', p->no, GNUNET_i2s (&p->id));
518 } 575 }
519 else 576 else
520 { 577 {
@@ -545,43 +602,72 @@ test_main (void *cls, unsigned int num_peers,
545 int c_p; 602 int c_p;
546 603
547 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 604 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
548 _("Benchmarking solver `%s' on preference `%s' with %u peers\n"), 605 _("Benchmarking solver `%s' on preference `%s' with %u master and %u slave peers\n"),
549 solver, preference, peers); 606 solver, preference, c_master_peers, c_slave_peers);
550 607
551 shutdown_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &do_shutdown, NULL); 608 shutdown_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &do_shutdown, NULL);
552 609
553 GNUNET_assert (NULL == cls); 610 GNUNET_assert (NULL == cls);
554 GNUNET_assert (peers == num_peers); 611 GNUNET_assert (c_slave_peers + c_master_peers == num_peers);
555 GNUNET_assert (NULL != peers_); 612 GNUNET_assert (NULL != peers_);
556 613
557 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 614 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
558 _("Initializing... \n")); 615 _("Initializing... \n"));
559 616
560 for (c_p = 0; c_p < num_peers; c_p++) 617 for (c_p = 0; c_p < c_master_peers; c_p++)
561 { 618 {
562 GNUNET_assert (NULL != peers_[c_p]); 619 GNUNET_assert (NULL != peers_[c_p]);
563 ph[c_p].no = c_p; 620 bp_master[c_p].no = c_p;
621 bp_master[c_p].master = GNUNET_YES;
564 /* Connect to ATS performance service */ 622 /* Connect to ATS performance service */
565 ph[c_p].peer = peers_[c_p]; 623 bp_master[c_p].peer = peers_[c_p];
624 bp_master[c_p].info_op = GNUNET_TESTBED_peer_get_information (bp_master[c_p].peer,
625 GNUNET_TESTBED_PIT_IDENTITY,
626 &peerinformation_cb, &bp_master[c_p]);
627/*
628 bp_master[c_p].core_op = GNUNET_TESTBED_service_connect (NULL,
629 peers_[c_p], "ats",
630 core_connect_completion_cb, NULL,
631 &core_connect_adapter,
632 &core_disconnect_adapter,
633 &bp_master[c_p]);
566 634
567 ph[c_p].info_op = GNUNET_TESTBED_peer_get_information (ph[c_p].peer, 635 bp_master[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL,
568 GNUNET_TESTBED_PIT_IDENTITY, 636 peers_[c_p], "ats",
569 &peerinformation_cb, &ph[c_p]); 637 ats_connect_completion_cb, NULL,
638 &ats_perf_connect_adapter,
639 &ats_perf_disconnect_adapter,
640 &bp_master[c_p]);
641*/
642 }
570 643
571 ph[c_p].core_op = GNUNET_TESTBED_service_connect (NULL, 644 for (c_p = 0; c_p < c_slave_peers; c_p++)
645 {
646 GNUNET_assert (NULL != peers_[c_p + c_master_peers]);
647 bp_slaves[c_p].no = c_p + c_master_peers;
648 bp_slaves[c_p].master = GNUNET_NO;
649 /* Connect to ATS performance service */
650 bp_slaves[c_p].peer = peers_[c_p + c_master_peers];
651 bp_slaves[c_p].info_op = GNUNET_TESTBED_peer_get_information (bp_slaves[c_p].peer,
652 GNUNET_TESTBED_PIT_IDENTITY,
653 &peerinformation_cb, &bp_slaves[c_p]);
654/*
655 bp_slaves[c_p].core_op = GNUNET_TESTBED_service_connect (NULL,
572 peers_[c_p], "ats", 656 peers_[c_p], "ats",
573 core_connect_completion_cb, NULL, 657 core_connect_completion_cb, NULL,
574 &core_connect_adapter, 658 &core_connect_adapter,
575 &core_disconnect_adapter, 659 &core_disconnect_adapter,
576 &ph[c_p]); 660 &bp_slaves[c_p]);
577 661
578 ph[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, 662 bp_slaves[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL,
579 peers_[c_p], "ats", 663 peers_[c_p], "ats",
580 ats_connect_completion_cb, NULL, 664 ats_connect_completion_cb, NULL,
581 &ats_perf_connect_adapter, 665 &ats_perf_connect_adapter,
582 &ats_perf_disconnect_adapter, 666 &ats_perf_disconnect_adapter,
583 &ph[c_p]); 667 &bp_slaves[c_p]);
668*/
584 } 669 }
670
585} 671}
586 672
587 673
@@ -594,8 +680,7 @@ main (int argc, char *argv[])
594 char *conf_name; 680 char *conf_name;
595 char *dotexe; 681 char *dotexe;
596 int c; 682 int c;
597 683
598 peers = 0;
599 result = 0; 684 result = 0;
600 685
601 /* figure out testname */ 686 /* figure out testname */
@@ -625,30 +710,48 @@ main (int argc, char *argv[])
625 710
626 for (c = 0; c < (argc -1); c++) 711 for (c = 0; c < (argc -1); c++)
627 { 712 {
628 if (0 == strcmp(argv[c], "-c")) 713 if (0 == strcmp(argv[c], "-s"))
714 break;
715 }
716 if (c < argc-1)
717 {
718 if ((0L != (c_slave_peers = strtol (argv[c + 1], NULL, 10))) && (c_slave_peers >= 2))
719 fprintf (stderr, "Starting %u slave peers\n", c_slave_peers);
720 else
721 c_slave_peers = DEFAULT_SLAVES_NUM;
722 }
723 else
724 c_slave_peers = DEFAULT_SLAVES_NUM;
725
726 for (c = 0; c < (argc -1); c++)
727 {
728 if (0 == strcmp(argv[c], "-m"))
629 break; 729 break;
630 } 730 }
631 if (c < argc-1) 731 if (c < argc-1)
632 { 732 {
633 if ((0L != (peers = strtol (argv[c + 1], NULL, 10))) && (peers >= 2)) 733 if ((0L != (c_slave_peers = strtol (argv[c + 1], NULL, 10))) && (c_slave_peers >= 2))
634 fprintf (stderr, "Starting %u peers\n", peers); 734 fprintf (stderr, "Starting %u master peers\n", c_slave_peers);
635 else 735 else
636 peers = DEFAULT_NUM; 736 c_master_peers = DEFAULT_MASTERS_NUM;
637 } 737 }
638 else 738 else
639 peers = DEFAULT_NUM; 739 c_master_peers = DEFAULT_MASTERS_NUM;
640 740
641 ph = GNUNET_malloc (peers * sizeof (struct BenchmarkPeer)); 741 bp_slaves = GNUNET_malloc (c_slave_peers * sizeof (struct BenchmarkPeer));
642 state.connected_ATS_SRV = GNUNET_NO; 742 bp_master = GNUNET_malloc (c_master_peers * sizeof (struct BenchmarkPeer));
643 state.connected_CORE_SRV = GNUNET_NO; 743
744 state.connected_ATS_service = GNUNET_NO;
745 state.connected_CORE_service = GNUNET_NO;
644 state.connected_PEERS = GNUNET_NO; 746 state.connected_PEERS = GNUNET_NO;
747
645 /* Start topology */ 748 /* Start topology */
646 uint64_t event_mask; 749 uint64_t event_mask;
647 event_mask = 0; 750 event_mask = 0;
648 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); 751 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
649 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 752 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
650 (void) GNUNET_TESTBED_test_run (test_name, 753 (void) GNUNET_TESTBED_test_run (test_name,
651 conf_name, peers, 754 conf_name, c_slave_peers + c_master_peers,
652 event_mask, &controller_event_cb, NULL, 755 event_mask, &controller_event_cb, NULL,
653 &test_main, NULL); 756 &test_main, NULL);
654 757
@@ -656,7 +759,7 @@ main (int argc, char *argv[])
656 GNUNET_free (preference); 759 GNUNET_free (preference);
657 GNUNET_free (conf_name); 760 GNUNET_free (conf_name);
658 GNUNET_free (test_name); 761 GNUNET_free (test_name);
659 GNUNET_free (ph); 762 GNUNET_free (bp_slaves);
660 763
661 return result; 764 return result;
662} 765}