diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-01-21 16:27:55 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-01-21 16:27:55 +0000 |
commit | f15624031417464fa72c659be7e0be8db55a909b (patch) | |
tree | 431a51f38b9516f56dc6d38e347fef0abade1b51 /src | |
parent | 1f3f45c08b82899a5350633dc6f1030216a1e150 (diff) | |
download | gnunet-f15624031417464fa72c659be7e0be8db55a909b.tar.gz gnunet-f15624031417464fa72c659be7e0be8db55a909b.zip |
not yet finished: moving perf_ats to testing
Diffstat (limited to 'src')
-rw-r--r-- | src/ats-tests/Makefile.am | 4 | ||||
-rw-r--r-- | src/ats-tests/ats-testing.c | 23 | ||||
-rw-r--r-- | src/ats-tests/ats-testing.h | 15 | ||||
-rw-r--r-- | src/ats-tests/gnunet-ats-sim.c | 33 | ||||
-rw-r--r-- | src/ats-tests/perf_ats.c | 766 |
5 files changed, 113 insertions, 728 deletions
diff --git a/src/ats-tests/Makefile.am b/src/ats-tests/Makefile.am index 8a90c6994..f6fed4ced 100644 --- a/src/ats-tests/Makefile.am +++ b/src/ats-tests/Makefile.am | |||
@@ -91,10 +91,14 @@ perf_ats_proportional_transport_none_SOURCES = \ | |||
91 | perf_ats.c perf_ats_logging.c | 91 | perf_ats.c perf_ats_logging.c |
92 | perf_ats_proportional_transport_none_LDADD = \ | 92 | perf_ats_proportional_transport_none_LDADD = \ |
93 | $(top_builddir)/src/util/libgnunetutil.la \ | 93 | $(top_builddir)/src/util/libgnunetutil.la \ |
94 | $(top_builddir)/src/ats-tests/libgnunetatstesting.la \ | ||
94 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | 95 | $(top_builddir)/src/testbed/libgnunettestbed.la \ |
95 | $(top_builddir)/src/ats/libgnunetats.la \ | 96 | $(top_builddir)/src/ats/libgnunetats.la \ |
96 | $(top_builddir)/src/core/libgnunetcore.la \ | 97 | $(top_builddir)/src/core/libgnunetcore.la \ |
97 | $(top_builddir)/src/transport/libgnunettransport.la | 98 | $(top_builddir)/src/transport/libgnunettransport.la |
99 | gnunet_ats_sim_DEPENDENCIES = \ | ||
100 | $(top_builddir)/src/ats-tests/libgnunetatstesting.la \ | ||
101 | $(top_builddir)/src/util/libgnunetutil.la | ||
98 | 102 | ||
99 | perf_ats_proportional_core_bandwidth_SOURCES = \ | 103 | perf_ats_proportional_core_bandwidth_SOURCES = \ |
100 | perf_ats.c perf_ats_logging.c | 104 | perf_ats.c perf_ats_logging.c |
diff --git a/src/ats-tests/ats-testing.c b/src/ats-tests/ats-testing.c index 5289c4ae7..5da7e0999 100644 --- a/src/ats-tests/ats-testing.c +++ b/src/ats-tests/ats-testing.c | |||
@@ -250,8 +250,6 @@ comm_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) | |||
250 | "All master peers connected all slave peers\n", id, | 250 | "All master peers connected all slave peers\n", id, |
251 | GNUNET_i2s (peer)); | 251 | GNUNET_i2s (peer)); |
252 | top->state.connected_CORE = GNUNET_YES; | 252 | top->state.connected_CORE = GNUNET_YES; |
253 | GNUNET_break (0); | ||
254 | //GNUNET_SCHEDULER_add_now (&do_benchmark, NULL ); | ||
255 | } | 253 | } |
256 | } | 254 | } |
257 | GNUNET_free(id); | 255 | GNUNET_free(id); |
@@ -370,8 +368,9 @@ connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
370 | if (ops == top->num_masters * top->num_slaves) | 368 | if (ops == top->num_masters * top->num_slaves) |
371 | { | 369 | { |
372 | top->state.connected_PEERS = GNUNET_YES; | 370 | top->state.connected_PEERS = GNUNET_YES; |
373 | GNUNET_break (0); | 371 | /* Notify about setup done */ |
374 | //GNUNET_SCHEDULER_add_now (&do_benchmark, NULL ); | 372 | if (NULL != top->done_cb) |
373 | top->done_cb (top->done_cb_cls, top->mps, top->sps); | ||
375 | } | 374 | } |
376 | } | 375 | } |
377 | 376 | ||
@@ -440,7 +439,6 @@ comm_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
440 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all %s services\n", | 439 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all %s services\n", |
441 | (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT"); | 440 | (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT"); |
442 | top->state.connected_COMM_service = GNUNET_YES; | 441 | top->state.connected_COMM_service = GNUNET_YES; |
443 | GNUNET_break (0); | ||
444 | GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL ); | 442 | GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL ); |
445 | } | 443 | } |
446 | } | 444 | } |
@@ -778,17 +776,24 @@ controller_event_cb (void *cls, | |||
778 | } | 776 | } |
779 | } | 777 | } |
780 | 778 | ||
781 | struct GNUNET_ATS_TEST_Topology * | 779 | void |
782 | GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file, | 780 | GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file, |
783 | unsigned int num_slaves, | 781 | unsigned int num_slaves, |
784 | unsigned int num_masters, | 782 | unsigned int num_masters, |
783 | int test_core, | ||
784 | GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb, | ||
785 | void *done_cb_cls, | ||
785 | struct GNUNET_CORE_MessageHandler *handlers, | 786 | struct GNUNET_CORE_MessageHandler *handlers, |
786 | GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb) | 787 | GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb) |
787 | { | 788 | { |
789 | |||
788 | top = GNUNET_new (struct GNUNET_ATS_TEST_Topology); | 790 | top = GNUNET_new (struct GNUNET_ATS_TEST_Topology); |
789 | top->num_masters = num_masters; | 791 | top->num_masters = num_masters; |
790 | top->num_slaves = num_slaves; | 792 | top->num_slaves = num_slaves; |
791 | top->handlers = handlers; | 793 | top->handlers = handlers; |
794 | top->done_cb = done_cb; | ||
795 | top->done_cb_cls = done_cb_cls; | ||
796 | top->test_core = test_core; | ||
792 | 797 | ||
793 | top->mps = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer)); | 798 | top->mps = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer)); |
794 | top->sps = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer)); | 799 | top->sps = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer)); |
@@ -801,14 +806,12 @@ GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file, | |||
801 | (void) GNUNET_TESTBED_test_run (name, cfg_file, | 806 | (void) GNUNET_TESTBED_test_run (name, cfg_file, |
802 | num_slaves + num_masters, event_mask, &controller_event_cb, NULL, | 807 | num_slaves + num_masters, event_mask, &controller_event_cb, NULL, |
803 | &main_run, NULL); | 808 | &main_run, NULL); |
804 | |||
805 | return NULL; | ||
806 | } | 809 | } |
807 | 810 | ||
808 | void | 811 | void |
809 | GNUNET_ATS_TEST_destroy_topology (struct GNUNET_ATS_TEST_Topology *top) | 812 | GNUNET_ATS_TEST_shutdown_topology (void) |
810 | { | 813 | { |
811 | 814 | GNUNET_SCHEDULER_shutdown(); | |
812 | } | 815 | } |
813 | 816 | ||
814 | /* end of file perf_ats.c */ | 817 | /* end of file perf_ats.c */ |
diff --git a/src/ats-tests/ats-testing.h b/src/ats-tests/ats-testing.h index 37fc94da7..7dd05bb21 100644 --- a/src/ats-tests/ats-testing.h +++ b/src/ats-tests/ats-testing.h | |||
@@ -45,7 +45,6 @@ | |||
45 | #define TEST_MESSAGE_SIZE 1000 | 45 | #define TEST_MESSAGE_SIZE 1000 |
46 | #define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 46 | #define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) |
47 | 47 | ||
48 | |||
49 | /** | 48 | /** |
50 | * Overall state of the performance benchmark | 49 | * Overall state of the performance benchmark |
51 | */ | 50 | */ |
@@ -300,6 +299,9 @@ struct TestbedConnectOperation | |||
300 | struct GNUNET_TESTBED_Operation *connect_op; | 299 | struct GNUNET_TESTBED_Operation *connect_op; |
301 | }; | 300 | }; |
302 | 301 | ||
302 | typedef void (*GNUNET_ATS_TESTING_TopologySetupDoneCallback) (void *cls, | ||
303 | struct BenchmarkPeer *masters, | ||
304 | struct BenchmarkPeer *slaves); | ||
303 | 305 | ||
304 | struct GNUNET_ATS_TEST_Topology | 306 | struct GNUNET_ATS_TEST_Topology |
305 | { | 307 | { |
@@ -386,17 +388,22 @@ struct GNUNET_ATS_TEST_Topology | |||
386 | 388 | ||
387 | GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb; | 389 | GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb; |
388 | 390 | ||
389 | }; | 391 | GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb; |
390 | 392 | ||
393 | void *done_cb_cls; | ||
394 | }; | ||
391 | 395 | ||
392 | struct GNUNET_ATS_TEST_Topology * | 396 | void |
393 | GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file, | 397 | GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file, |
394 | unsigned int num_slaves, | 398 | unsigned int num_slaves, |
395 | unsigned int num_masters, | 399 | unsigned int num_masters, |
400 | int test_core, | ||
401 | GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb, | ||
402 | void *done_cb_cls, | ||
396 | struct GNUNET_CORE_MessageHandler *handlers, | 403 | struct GNUNET_CORE_MessageHandler *handlers, |
397 | GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb); | 404 | GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb); |
398 | 405 | ||
399 | void | 406 | void |
400 | GNUNET_ATS_TEST_destroy_topology (struct GNUNET_ATS_TEST_Topology *top); | 407 | GNUNET_ATS_TEST_shutdown_topology (void); |
401 | 408 | ||
402 | /* end of file perf_ats.c */ | 409 | /* end of file perf_ats.c */ |
diff --git a/src/ats-tests/gnunet-ats-sim.c b/src/ats-tests/gnunet-ats-sim.c index 0bd970a8f..7a7508503 100644 --- a/src/ats-tests/gnunet-ats-sim.c +++ b/src/ats-tests/gnunet-ats-sim.c | |||
@@ -36,15 +36,19 @@ | |||
36 | #define TEST_MESSAGE_TYPE_PING 12345 | 36 | #define TEST_MESSAGE_TYPE_PING 12345 |
37 | #define TEST_MESSAGE_TYPE_PONG 12346 | 37 | #define TEST_MESSAGE_TYPE_PONG 12346 |
38 | 38 | ||
39 | static int c_masters; | ||
40 | |||
41 | static int c_slaves; | ||
42 | |||
39 | static int | 43 | static int |
40 | comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other, | 44 | core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other, |
41 | const struct GNUNET_MessageHeader *message) | 45 | const struct GNUNET_MessageHeader *message) |
42 | { | 46 | { |
43 | return 0; | 47 | return 0; |
44 | } | 48 | } |
45 | 49 | ||
46 | static int | 50 | static int |
47 | comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other, | 51 | core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other, |
48 | const struct GNUNET_MessageHeader *message) | 52 | const struct GNUNET_MessageHeader *message) |
49 | { | 53 | { |
50 | return 0; | 54 | return 0; |
@@ -58,16 +62,33 @@ transport_recv_cb (void *cls, | |||
58 | 62 | ||
59 | } | 63 | } |
60 | 64 | ||
65 | static void topology_setup_done (void *cls, | ||
66 | struct BenchmarkPeer *masters, | ||
67 | struct BenchmarkPeer *slaves) | ||
68 | { | ||
69 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Topology setup complete!\n"); | ||
70 | GNUNET_ATS_TEST_shutdown_topology (); | ||
71 | } | ||
72 | |||
61 | int | 73 | int |
62 | main (int argc, char *argv[]) | 74 | main (int argc, char *argv[]) |
63 | { | 75 | { |
64 | static struct GNUNET_CORE_MessageHandler handlers[] = { { | 76 | static struct GNUNET_CORE_MessageHandler handlers[] = { |
65 | &comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 }, { &comm_handle_pong, | 77 | {&core_handle_ping, TEST_MESSAGE_TYPE_PING, 0 }, |
66 | TEST_MESSAGE_TYPE_PONG, 0 }, { NULL, 0, 0 } }; | 78 | {&core_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 }, |
79 | { NULL, 0, 0 } }; | ||
67 | 80 | ||
81 | c_slaves = DEFAULT_NUM_SLAVES; | ||
82 | c_masters = DEFAULT_NUM_MASTERS; | ||
68 | 83 | ||
69 | GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", "perf_ats_proportional_none.conf", | 84 | GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", "perf_ats_proportional_none.conf", |
70 | DEFAULT_NUM_SLAVES, DEFAULT_NUM_MASTERS, handlers, &transport_recv_cb); | 85 | c_slaves, |
86 | c_masters, | ||
87 | GNUNET_YES, | ||
88 | &topology_setup_done, | ||
89 | NULL, | ||
90 | handlers, | ||
91 | &transport_recv_cb); | ||
71 | return 0; | 92 | return 0; |
72 | } | 93 | } |
73 | /* end of file perf_ats_topogy.c */ | 94 | /* end of file perf_ats_topogy.c */ |
diff --git a/src/ats-tests/perf_ats.c b/src/ats-tests/perf_ats.c index f52bcfb25..daffb9f28 100644 --- a/src/ats-tests/perf_ats.c +++ b/src/ats-tests/perf_ats.c | |||
@@ -28,7 +28,7 @@ | |||
28 | #include "gnunet_testbed_service.h" | 28 | #include "gnunet_testbed_service.h" |
29 | #include "gnunet_ats_service.h" | 29 | #include "gnunet_ats_service.h" |
30 | #include "gnunet_core_service.h" | 30 | #include "gnunet_core_service.h" |
31 | #include "perf_ats.h" | 31 | #include "ats-testing.h" |
32 | 32 | ||
33 | 33 | ||
34 | #define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 34 | #define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) |
@@ -40,58 +40,6 @@ | |||
40 | #define TEST_MESSAGE_SIZE 1000 | 40 | #define TEST_MESSAGE_SIZE 1000 |
41 | #define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 41 | #define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) |
42 | 42 | ||
43 | /** | ||
44 | * Connect peers with testbed | ||
45 | */ | ||
46 | struct TestbedConnectOperation | ||
47 | { | ||
48 | /** | ||
49 | * The benchmarking master initiating this connection | ||
50 | */ | ||
51 | struct BenchmarkPeer *master; | ||
52 | |||
53 | /** | ||
54 | * The benchmarking slave to connect to | ||
55 | */ | ||
56 | struct BenchmarkPeer *slave; | ||
57 | |||
58 | /** | ||
59 | * Testbed operation to connect peers | ||
60 | */ | ||
61 | struct GNUNET_TESTBED_Operation *connect_op; | ||
62 | }; | ||
63 | |||
64 | /** | ||
65 | * Overall state of the performance benchmark | ||
66 | */ | ||
67 | struct BenchmarkState | ||
68 | { | ||
69 | /** | ||
70 | * Are we connected to ATS service of all peers: GNUNET_YES/NO | ||
71 | */ | ||
72 | int connected_ATS_service; | ||
73 | |||
74 | /** | ||
75 | * Are we connected to CORE service of all peers: GNUNET_YES/NO | ||
76 | */ | ||
77 | int connected_COMM_service; | ||
78 | |||
79 | /** | ||
80 | * Are we connected to all peers: GNUNET_YES/NO | ||
81 | */ | ||
82 | int connected_PEERS; | ||
83 | |||
84 | /** | ||
85 | * Are we connected to all slave peers on CORE level: GNUNET_YES/NO | ||
86 | */ | ||
87 | int connected_CORE; | ||
88 | |||
89 | /** | ||
90 | * Are we connected to CORE service of all peers: GNUNET_YES/NO | ||
91 | */ | ||
92 | int benchmarking; | ||
93 | }; | ||
94 | |||
95 | 43 | ||
96 | /** | 44 | /** |
97 | * Shutdown task | 45 | * Shutdown task |
@@ -138,6 +86,16 @@ static char *pref_str; | |||
138 | static int pref_val; | 86 | static int pref_val; |
139 | 87 | ||
140 | /** | 88 | /** |
89 | * Benchmark duration | ||
90 | */ | ||
91 | static struct GNUNET_TIME_Relative perf_duration; | ||
92 | |||
93 | /** | ||
94 | * Logging frequency | ||
95 | */ | ||
96 | static struct GNUNET_TIME_Relative log_frequency; | ||
97 | |||
98 | /** | ||
141 | * Number master peers | 99 | * Number master peers |
142 | */ | 100 | */ |
143 | static unsigned int num_masters; | 101 | static unsigned int num_masters; |
@@ -153,25 +111,10 @@ static struct BenchmarkPeer *mps; | |||
153 | static unsigned int num_slaves; | 111 | static unsigned int num_slaves; |
154 | 112 | ||
155 | /** | 113 | /** |
156 | * Array of slave peers | 114 | * Array of master peers |
157 | */ | 115 | */ |
158 | static struct BenchmarkPeer *sps; | 116 | static struct BenchmarkPeer *sps; |
159 | 117 | ||
160 | /** | ||
161 | * Benchmark duration | ||
162 | */ | ||
163 | static struct GNUNET_TIME_Relative perf_duration; | ||
164 | |||
165 | /** | ||
166 | * Logging frequency | ||
167 | */ | ||
168 | static struct GNUNET_TIME_Relative log_frequency; | ||
169 | |||
170 | /** | ||
171 | * Benchmark state | ||
172 | */ | ||
173 | static struct BenchmarkState state; | ||
174 | |||
175 | static void | 118 | static void |
176 | evaluate () | 119 | evaluate () |
177 | { | 120 | { |
@@ -221,14 +164,10 @@ evaluate () | |||
221 | static void | 164 | static void |
222 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 165 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
223 | { | 166 | { |
224 | int c_m; | 167 | /* |
225 | int c_s; | ||
226 | int c_op; | ||
227 | struct BenchmarkPeer *p; | ||
228 | |||
229 | if (GNUNET_YES == logging) | 168 | if (GNUNET_YES == logging) |
230 | perf_logging_stop(); | 169 | perf_logging_stop(); |
231 | 170 | */ | |
232 | shutdown_task = GNUNET_SCHEDULER_NO_TASK; | 171 | shutdown_task = GNUNET_SCHEDULER_NO_TASK; |
233 | if (GNUNET_SCHEDULER_NO_TASK != progress_task) | 172 | if (GNUNET_SCHEDULER_NO_TASK != progress_task) |
234 | { | 173 | { |
@@ -238,142 +177,9 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
238 | progress_task = GNUNET_SCHEDULER_NO_TASK; | 177 | progress_task = GNUNET_SCHEDULER_NO_TASK; |
239 | 178 | ||
240 | evaluate (); | 179 | evaluate (); |
241 | state.benchmarking = GNUNET_NO; | ||
242 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n")); | 180 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n")); |
243 | 181 | ||
244 | for (c_m = 0; c_m < num_masters; c_m++) | 182 | GNUNET_ATS_TEST_shutdown_topology(); |
245 | { | ||
246 | p = &mps[c_m]; | ||
247 | if (NULL != mps[c_m].peer_id_op) | ||
248 | { | ||
249 | GNUNET_TESTBED_operation_done (p->peer_id_op); | ||
250 | p->peer_id_op = NULL; | ||
251 | } | ||
252 | |||
253 | if (GNUNET_SCHEDULER_NO_TASK != p->ats_task) | ||
254 | GNUNET_SCHEDULER_cancel (p->ats_task); | ||
255 | p->ats_task = GNUNET_SCHEDULER_NO_TASK; | ||
256 | |||
257 | for (c_op = 0; c_op < p->num_partners; c_op++) | ||
258 | { | ||
259 | if (NULL != p->partners[c_op].cth) | ||
260 | { | ||
261 | GNUNET_CORE_notify_transmit_ready_cancel (p->partners[c_op].cth); | ||
262 | p->partners[c_op].cth = NULL; | ||
263 | } | ||
264 | if (NULL != p->partners[c_op].tth) | ||
265 | { | ||
266 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->partners[c_op].tth); | ||
267 | p->partners[c_op].tth = NULL; | ||
268 | } | ||
269 | if (NULL != p->core_connect_ops[c_op].connect_op) | ||
270 | { | ||
271 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
272 | _("Failed to connect peer 0 and %u\n"), c_op); | ||
273 | GNUNET_TESTBED_operation_done ( | ||
274 | p->core_connect_ops[c_op].connect_op); | ||
275 | p->core_connect_ops[c_op].connect_op = NULL; | ||
276 | result = 1; | ||
277 | } | ||
278 | } | ||
279 | |||
280 | if (NULL != p->ats_perf_op) | ||
281 | { | ||
282 | GNUNET_TESTBED_operation_done (p->ats_perf_op); | ||
283 | p->ats_perf_op = NULL; | ||
284 | } | ||
285 | |||
286 | if (NULL != p->comm_op) | ||
287 | { | ||
288 | GNUNET_TESTBED_operation_done (p->comm_op); | ||
289 | p->comm_op = NULL; | ||
290 | } | ||
291 | GNUNET_free(p->core_connect_ops); | ||
292 | GNUNET_free(p->partners); | ||
293 | p->partners = NULL; | ||
294 | } | ||
295 | |||
296 | for (c_s = 0; c_s < num_slaves; c_s++) | ||
297 | { | ||
298 | p = &sps[c_s]; | ||
299 | if (NULL != p->peer_id_op) | ||
300 | { | ||
301 | GNUNET_TESTBED_operation_done (p->peer_id_op); | ||
302 | p->peer_id_op = NULL; | ||
303 | } | ||
304 | |||
305 | for (c_op = 0; c_op < p->num_partners; c_op++) | ||
306 | { | ||
307 | if (NULL != p->partners[c_op].cth) | ||
308 | { | ||
309 | GNUNET_CORE_notify_transmit_ready_cancel (p->partners[c_op].cth); | ||
310 | p->partners[c_op].cth = NULL; | ||
311 | } | ||
312 | if (NULL != p->partners[c_op].tth) | ||
313 | { | ||
314 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->partners[c_op].tth); | ||
315 | p->partners[c_op].tth = NULL; | ||
316 | } | ||
317 | } | ||
318 | if (NULL != p->ats_perf_op) | ||
319 | { | ||
320 | GNUNET_TESTBED_operation_done (p->ats_perf_op); | ||
321 | p->ats_perf_op = NULL; | ||
322 | } | ||
323 | if (NULL != p->comm_op) | ||
324 | { | ||
325 | GNUNET_TESTBED_operation_done (p->comm_op); | ||
326 | p->comm_op = NULL; | ||
327 | } | ||
328 | GNUNET_free(p->partners); | ||
329 | p->partners = NULL; | ||
330 | } | ||
331 | |||
332 | GNUNET_SCHEDULER_shutdown (); | ||
333 | } | ||
334 | |||
335 | static struct BenchmarkPeer * | ||
336 | find_peer (const struct GNUNET_PeerIdentity * peer) | ||
337 | { | ||
338 | int c_p; | ||
339 | |||
340 | for (c_p = 0; c_p < num_masters; c_p++) | ||
341 | { | ||
342 | if (0 == memcmp (&mps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity))) | ||
343 | return &mps[c_p]; | ||
344 | } | ||
345 | |||
346 | for (c_p = 0; c_p < num_slaves; c_p++) | ||
347 | { | ||
348 | if (0 == memcmp (&sps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity))) | ||
349 | return &sps[c_p]; | ||
350 | } | ||
351 | return NULL ; | ||
352 | } | ||
353 | |||
354 | /** | ||
355 | * Controller event callback | ||
356 | * | ||
357 | * @param cls NULL | ||
358 | * @param event the controller event | ||
359 | */ | ||
360 | static void | ||
361 | controller_event_cb (void *cls, | ||
362 | const struct GNUNET_TESTBED_EventInformation *event) | ||
363 | { | ||
364 | //struct BenchmarkPeer *p = cls; | ||
365 | switch (event->type) | ||
366 | { | ||
367 | case GNUNET_TESTBED_ET_CONNECT: | ||
368 | break; | ||
369 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
370 | break; | ||
371 | default: | ||
372 | GNUNET_break(0); | ||
373 | result = 2; | ||
374 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
375 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL ); | ||
376 | } | ||
377 | } | 183 | } |
378 | 184 | ||
379 | static size_t | 185 | static size_t |
@@ -399,7 +205,7 @@ comm_send_ready (void *cls, size_t size, void *buf) | |||
399 | return 0; | 205 | return 0; |
400 | } | 206 | } |
401 | 207 | ||
402 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Master [%u]: Sending PING to [%u]\n", | 208 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Master [%u]: Sending PING to [%u]\n", |
403 | p->me->no, p->dest->no); | 209 | p->me->no, p->dest->no); |
404 | 210 | ||
405 | p->messages_sent++; | 211 | p->messages_sent++; |
@@ -466,18 +272,14 @@ ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
466 | } | 272 | } |
467 | 273 | ||
468 | static void | 274 | static void |
469 | do_benchmark () | 275 | do_benchmark (void *cls, struct BenchmarkPeer *masters, struct BenchmarkPeer *slaves) |
470 | { | 276 | { |
471 | int c_m; | 277 | int c_m; |
472 | int c_s; | 278 | int c_s; |
473 | 279 | ||
474 | if ((state.connected_ATS_service == GNUNET_NO) | 280 | mps = masters; |
475 | || (state.connected_COMM_service == GNUNET_NO) | 281 | sps = slaves; |
476 | || (state.connected_PEERS == GNUNET_NO) | ||
477 | || (state.connected_CORE == GNUNET_NO)) | ||
478 | return; | ||
479 | 282 | ||
480 | state.benchmarking = GNUNET_YES; | ||
481 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n")); | 283 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n")); |
482 | 284 | ||
483 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | 285 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) |
@@ -487,154 +289,48 @@ do_benchmark () | |||
487 | 289 | ||
488 | progress_task = GNUNET_SCHEDULER_add_now (&print_progress, NULL ); | 290 | progress_task = GNUNET_SCHEDULER_add_now (&print_progress, NULL ); |
489 | 291 | ||
292 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Topology connected, start benchmarking...\n"); | ||
293 | |||
490 | /* Start sending test messages */ | 294 | /* Start sending test messages */ |
491 | for (c_m = 0; c_m < num_masters; c_m++) | 295 | for (c_m = 0; c_m < num_masters; c_m++) |
492 | { | 296 | { |
493 | for (c_s = 0; c_s < num_slaves; c_s++) | 297 | for (c_s = 0; c_s < num_slaves; c_s++) |
494 | comm_schedule_send (&mps[c_m].partners[c_s]); | 298 | comm_schedule_send (&masters[c_m].partners[c_s]); |
495 | if (pref_val != GNUNET_ATS_PREFERENCE_END) | 299 | if (pref_val != GNUNET_ATS_PREFERENCE_END) |
496 | mps[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, &mps[c_m]); | 300 | masters[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, &masters[c_m]); |
497 | } | 301 | } |
302 | |||
303 | /* | ||
498 | if (GNUNET_YES == logging) | 304 | if (GNUNET_YES == logging) |
499 | perf_logging_start (log_frequency, testname, mps, num_masters); | 305 | perf_logging_start (log_frequency, testname, mps, num_masters); |
500 | 306 | */ | |
501 | } | 307 | } |
502 | 308 | ||
503 | static void | ||
504 | connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op, | ||
505 | const char *emsg) | ||
506 | { | ||
507 | struct TestbedConnectOperation *cop = cls; | ||
508 | static int ops = 0; | ||
509 | int c; | ||
510 | if (NULL == emsg) | ||
511 | { | ||
512 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
513 | _("Connected master [%u] with slave [%u]\n"), cop->master->no, | ||
514 | cop->slave->no); | ||
515 | } | ||
516 | else | ||
517 | { | ||
518 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
519 | _("Failed to connect master peer [%u] with slave [%u]\n"), | ||
520 | cop->master->no, cop->slave->no); | ||
521 | GNUNET_break(0); | ||
522 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
523 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
524 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL ); | ||
525 | } | ||
526 | GNUNET_TESTBED_operation_done (op); | ||
527 | ops++; | ||
528 | for (c = 0; c < num_slaves; c++) | ||
529 | { | ||
530 | if (cop == &cop->master->core_connect_ops[c]) | ||
531 | cop->master->core_connect_ops[c].connect_op = NULL; | ||
532 | } | ||
533 | if (ops == num_masters * num_slaves) | ||
534 | { | ||
535 | state.connected_PEERS = GNUNET_YES; | ||
536 | GNUNET_SCHEDULER_add_now (&do_benchmark, NULL ); | ||
537 | } | ||
538 | } | ||
539 | |||
540 | static void | ||
541 | do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
542 | { | ||
543 | int c_m; | ||
544 | int c_s; | ||
545 | struct BenchmarkPeer *p; | ||
546 | |||
547 | if ((state.connected_ATS_service == GNUNET_NO) | ||
548 | || (state.connected_COMM_service == GNUNET_NO)) | ||
549 | return; | ||
550 | |||
551 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Connecting peers on CORE level\n")); | ||
552 | |||
553 | for (c_m = 0; c_m < num_masters; c_m++) | ||
554 | { | ||
555 | p = &mps[c_m]; | ||
556 | p->core_connect_ops = GNUNET_malloc (num_slaves * | ||
557 | sizeof (struct TestbedConnectOperation)); | ||
558 | 309 | ||
559 | for (c_s = 0; c_s < num_slaves; c_s++) | 310 | static size_t |
560 | { | 311 | comm_send_pong_ready (void *cls, size_t size, void *buf) |
561 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
562 | _("Connecting master [%u] with slave [%u]\n"), p->no, sps[c_s].no); | ||
563 | p->core_connect_ops[c_s].master = p; | ||
564 | p->core_connect_ops[c_s].slave = &sps[c_s]; | ||
565 | p->core_connect_ops[c_s].connect_op = GNUNET_TESTBED_overlay_connect ( | ||
566 | NULL, &connect_completion_callback, &p->core_connect_ops[c_s], | ||
567 | sps[c_s].peer, p->peer); | ||
568 | if (NULL == p->core_connect_ops[c_s].connect_op) | ||
569 | { | ||
570 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
571 | _("Could not connect master [%u] and slave [%u]\n"), p->no, | ||
572 | sps[c_s].no); | ||
573 | GNUNET_break(0); | ||
574 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
575 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
576 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL ); | ||
577 | return; | ||
578 | } | ||
579 | } | ||
580 | } | ||
581 | } | ||
582 | |||
583 | /** | ||
584 | * Method called whenever a given peer connects. | ||
585 | * | ||
586 | * @param cls closure | ||
587 | * @param peer peer identity this notification is about | ||
588 | */ | ||
589 | static void | ||
590 | comm_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) | ||
591 | { | 312 | { |
592 | struct BenchmarkPeer *me = cls; | 313 | static char msgbuf[TEST_MESSAGE_SIZE]; |
593 | struct BenchmarkPeer *remote; | 314 | struct BenchmarkPartner *p = cls; |
594 | char *id; | 315 | struct GNUNET_MessageHeader *msg; |
595 | int c; | ||
596 | int completed; | ||
597 | 316 | ||
598 | remote = find_peer (peer); | 317 | if (GNUNET_YES == test_core) |
599 | if (NULL == remote) | 318 | p->cth = NULL; |
600 | { | 319 | else |
601 | GNUNET_break(0); | 320 | p->tth = NULL; |
602 | return; | ||
603 | } | ||
604 | 321 | ||
605 | id = GNUNET_strdup (GNUNET_i2s (&me->id)); | 322 | p->messages_sent++; |
606 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s [%u] `%s' connected to %s [%u] %s\n", | 323 | p->bytes_sent += TEST_MESSAGE_SIZE; |
607 | (me->master == GNUNET_YES) ? "Master": "Slave", me->no, id, | 324 | p->me->total_messages_sent++; |
608 | (remote->master == GNUNET_YES) ? "Master": "Slave", remote->no, | 325 | p->me->total_bytes_sent += TEST_MESSAGE_SIZE; |
609 | GNUNET_i2s (peer)); | ||
610 | 326 | ||
611 | me->core_connections++; | 327 | msg = (struct GNUNET_MessageHeader *) &msgbuf; |
612 | if ((GNUNET_YES == me->master) && (GNUNET_NO == remote->master) | 328 | memset (&msgbuf, 'a', TEST_MESSAGE_SIZE); |
613 | && (GNUNET_NO == state.connected_CORE)) | 329 | msg->type = htons (TEST_MESSAGE_TYPE_PONG); |
614 | { | 330 | msg->size = htons (TEST_MESSAGE_SIZE); |
615 | me->core_slave_connections++; | 331 | memcpy (buf, msg, TEST_MESSAGE_SIZE); |
616 | 332 | ||
617 | if (me->core_slave_connections == num_slaves) | 333 | return TEST_MESSAGE_SIZE; |
618 | { | ||
619 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Master [%u] connected all slaves\n", | ||
620 | me->no); | ||
621 | } | ||
622 | completed = GNUNET_YES; | ||
623 | for (c = 0; c < num_masters; c++) | ||
624 | { | ||
625 | if (mps[c].core_slave_connections != num_slaves) | ||
626 | completed = GNUNET_NO; | ||
627 | } | ||
628 | if (GNUNET_YES == completed) | ||
629 | { | ||
630 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
631 | "All master peers connected all slave peers\n", id, | ||
632 | GNUNET_i2s (peer)); | ||
633 | state.connected_CORE = GNUNET_YES; | ||
634 | GNUNET_SCHEDULER_add_now (&do_benchmark, NULL ); | ||
635 | } | ||
636 | } | ||
637 | GNUNET_free(id); | ||
638 | } | 334 | } |
639 | 335 | ||
640 | static struct BenchmarkPartner * | 336 | static struct BenchmarkPartner * |
@@ -657,67 +353,6 @@ find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer) | |||
657 | return NULL; | 353 | return NULL; |
658 | } | 354 | } |
659 | 355 | ||
660 | static void | ||
661 | comm_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) | ||
662 | { | ||
663 | struct BenchmarkPeer *me = cls; | ||
664 | struct BenchmarkPartner *p; | ||
665 | char *id; | ||
666 | |||
667 | if (NULL == (p = find_partner (me, peer))) | ||
668 | return; | ||
669 | |||
670 | id = GNUNET_strdup (GNUNET_i2s (&me->id)); | ||
671 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s disconnected from %s \n", id, | ||
672 | GNUNET_i2s (peer)); | ||
673 | GNUNET_assert(me->core_connections > 0); | ||
674 | me->core_connections--; | ||
675 | |||
676 | if ((GNUNET_YES == state.benchmarking) | ||
677 | && ((GNUNET_YES == me->master) || (GNUNET_YES == p->dest->master))) | ||
678 | { | ||
679 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
680 | "%s disconnected from %s while benchmarking \n", id, GNUNET_i2s (peer)); | ||
681 | if (NULL != p->tth) | ||
682 | { | ||
683 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->tth); | ||
684 | p->tth = NULL; | ||
685 | } | ||
686 | if (NULL != p->cth) | ||
687 | { | ||
688 | GNUNET_CORE_notify_transmit_ready_cancel (p->cth); | ||
689 | p->cth = NULL; | ||
690 | } | ||
691 | } | ||
692 | GNUNET_free(id); | ||
693 | } | ||
694 | |||
695 | static size_t | ||
696 | comm_send_pong_ready (void *cls, size_t size, void *buf) | ||
697 | { | ||
698 | static char msgbuf[TEST_MESSAGE_SIZE]; | ||
699 | struct BenchmarkPartner *p = cls; | ||
700 | struct GNUNET_MessageHeader *msg; | ||
701 | |||
702 | if (GNUNET_YES == test_core) | ||
703 | p->cth = NULL; | ||
704 | else | ||
705 | p->tth = NULL; | ||
706 | |||
707 | p->messages_sent++; | ||
708 | p->bytes_sent += TEST_MESSAGE_SIZE; | ||
709 | p->me->total_messages_sent++; | ||
710 | p->me->total_bytes_sent += TEST_MESSAGE_SIZE; | ||
711 | |||
712 | msg = (struct GNUNET_MessageHeader *) &msgbuf; | ||
713 | memset (&msgbuf, 'a', TEST_MESSAGE_SIZE); | ||
714 | msg->type = htons (TEST_MESSAGE_TYPE_PONG); | ||
715 | msg->size = htons (TEST_MESSAGE_SIZE); | ||
716 | memcpy (buf, msg, TEST_MESSAGE_SIZE); | ||
717 | |||
718 | return TEST_MESSAGE_SIZE; | ||
719 | } | ||
720 | |||
721 | static int | 356 | static int |
722 | comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other, | 357 | comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other, |
723 | const struct GNUNET_MessageHeader *message) | 358 | const struct GNUNET_MessageHeader *message) |
@@ -732,7 +367,7 @@ comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other, | |||
732 | return GNUNET_SYSERR; | 367 | return GNUNET_SYSERR; |
733 | } | 368 | } |
734 | 369 | ||
735 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 370 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
736 | "Slave [%u]: Received PING from [%u], sending PONG\n", me->no, | 371 | "Slave [%u]: Received PING from [%u], sending PONG\n", me->no, |
737 | p->dest->no); | 372 | p->dest->no); |
738 | 373 | ||
@@ -771,7 +406,7 @@ comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other, | |||
771 | return GNUNET_SYSERR; | 406 | return GNUNET_SYSERR; |
772 | } | 407 | } |
773 | 408 | ||
774 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 409 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
775 | "Master [%u]: Received PONG from [%u], next message\n", me->no, | 410 | "Master [%u]: Received PONG from [%u], next message\n", me->no, |
776 | p->dest->no); | 411 | p->dest->no); |
777 | 412 | ||
@@ -786,61 +421,14 @@ comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other, | |||
786 | return GNUNET_OK; | 421 | return GNUNET_OK; |
787 | } | 422 | } |
788 | 423 | ||
789 | static void * | ||
790 | core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
791 | { | ||
792 | struct BenchmarkPeer *me = cls; | ||
793 | 424 | ||
794 | static const struct GNUNET_CORE_MessageHandler handlers[] = { { | ||
795 | &comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 }, { &comm_handle_pong, | ||
796 | TEST_MESSAGE_TYPE_PONG, 0 }, { NULL, 0, 0 } }; | ||
797 | |||
798 | me->ch = GNUNET_CORE_connect (cfg, me, NULL, comm_connect_cb, | ||
799 | comm_disconnect_cb, NULL, GNUNET_NO, NULL, GNUNET_NO, handlers); | ||
800 | if (NULL == me->ch) | ||
801 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create core connection \n"); | ||
802 | return me->ch; | ||
803 | } | ||
804 | |||
805 | static void | ||
806 | core_disconnect_adapter (void *cls, void *op_result) | ||
807 | { | ||
808 | struct BenchmarkPeer *me = cls; | ||
809 | |||
810 | GNUNET_CORE_disconnect (me->ch); | ||
811 | me->ch = NULL; | ||
812 | } | ||
813 | |||
814 | static void | ||
815 | comm_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | ||
816 | void *ca_result, const char *emsg) | ||
817 | { | ||
818 | static int comm_done = 0; | ||
819 | if ((NULL != emsg) || (NULL == ca_result)) | ||
820 | { | ||
821 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n")); | ||
822 | GNUNET_break(0); | ||
823 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
824 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
825 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL ); | ||
826 | return; | ||
827 | } | ||
828 | comm_done++; | ||
829 | |||
830 | if (comm_done == num_slaves + num_masters) | ||
831 | { | ||
832 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all %s services\n", | ||
833 | (GNUNET_YES == test_core) ? "CORE" : "TRANSPORT"); | ||
834 | state.connected_COMM_service = GNUNET_YES; | ||
835 | GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL ); | ||
836 | } | ||
837 | } | ||
838 | 425 | ||
839 | static void | 426 | static void |
840 | transport_recv_cb (void *cls, | 427 | transport_recv_cb (void *cls, |
841 | const struct GNUNET_PeerIdentity * peer, | 428 | const struct GNUNET_PeerIdentity * peer, |
842 | const struct GNUNET_MessageHeader * message) | 429 | const struct GNUNET_MessageHeader * message) |
843 | { | 430 | { |
431 | GNUNET_break (0); | ||
844 | if (TEST_MESSAGE_SIZE != ntohs (message->size) || | 432 | if (TEST_MESSAGE_SIZE != ntohs (message->size) || |
845 | (TEST_MESSAGE_TYPE_PING != ntohs (message->type) && | 433 | (TEST_MESSAGE_TYPE_PING != ntohs (message->type) && |
846 | TEST_MESSAGE_TYPE_PONG != ntohs (message->type))) | 434 | TEST_MESSAGE_TYPE_PONG != ntohs (message->type))) |
@@ -855,62 +443,8 @@ transport_recv_cb (void *cls, | |||
855 | } | 443 | } |
856 | 444 | ||
857 | 445 | ||
858 | static void * | ||
859 | transport_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
860 | { | ||
861 | struct BenchmarkPeer *me = cls; | ||
862 | |||
863 | me->th = GNUNET_TRANSPORT_connect (cfg, &me->id, me, &transport_recv_cb, | ||
864 | &comm_connect_cb, &comm_disconnect_cb); | ||
865 | if (NULL == me->th) | ||
866 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create transport connection \n"); | ||
867 | return me->th; | ||
868 | } | ||
869 | 446 | ||
870 | static void | ||
871 | transport_disconnect_adapter (void *cls, void *op_result) | ||
872 | { | ||
873 | struct BenchmarkPeer *me = cls; | ||
874 | 447 | ||
875 | GNUNET_TRANSPORT_disconnect (me->th); | ||
876 | me->th = NULL; | ||
877 | } | ||
878 | |||
879 | static void | ||
880 | do_comm_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
881 | { | ||
882 | int c_s; | ||
883 | int c_m; | ||
884 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all %s services\n", | ||
885 | (GNUNET_YES == test_core) ? "CORE" : "TRANSPORT"); | ||
886 | for (c_m = 0; c_m < num_masters; c_m++) | ||
887 | { | ||
888 | if (GNUNET_YES == test_core) | ||
889 | mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer, | ||
890 | "core", &comm_connect_completion_cb, NULL, &core_connect_adapter, | ||
891 | &core_disconnect_adapter, &mps[c_m]); | ||
892 | else | ||
893 | { | ||
894 | mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer, | ||
895 | "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter, | ||
896 | &transport_disconnect_adapter, &mps[c_m]); | ||
897 | } | ||
898 | } | ||
899 | |||
900 | for (c_s = 0; c_s < num_slaves; c_s++) | ||
901 | { | ||
902 | if (GNUNET_YES == test_core) | ||
903 | sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer, | ||
904 | "core", &comm_connect_completion_cb, NULL, &core_connect_adapter, | ||
905 | &core_disconnect_adapter, &sps[c_s]); | ||
906 | else | ||
907 | { | ||
908 | sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer, | ||
909 | "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter, | ||
910 | &transport_disconnect_adapter, &sps[c_s]); | ||
911 | } | ||
912 | } | ||
913 | } | ||
914 | 448 | ||
915 | static void | 449 | static void |
916 | ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address, | 450 | ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address, |
@@ -999,182 +533,16 @@ ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address, | |||
999 | break; | 533 | break; |
1000 | } | 534 | } |
1001 | } | 535 | } |
536 | /* | ||
1002 | if ((GNUNET_YES == logging) && (GNUNET_YES == log)) | 537 | if ((GNUNET_YES == logging) && (GNUNET_YES == log)) |
1003 | collect_log_now(); | 538 | collect_log_now(); |
539 | */ | ||
1004 | GNUNET_free(peer_id); | 540 | GNUNET_free(peer_id); |
1005 | } | 541 | } |
1006 | 542 | ||
1007 | static void * | ||
1008 | ats_perf_connect_adapter (void *cls, | ||
1009 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
1010 | { | ||
1011 | struct BenchmarkPeer *me = cls; | ||
1012 | |||
1013 | me->ats_perf_handle = GNUNET_ATS_performance_init (cfg, | ||
1014 | &ats_performance_info_cb, me); | ||
1015 | if (NULL == me->ats_perf_handle) | ||
1016 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1017 | "Failed to create ATS performance handle \n"); | ||
1018 | return me->ats_perf_handle; | ||
1019 | } | ||
1020 | |||
1021 | static void | ||
1022 | ats_perf_disconnect_adapter (void *cls, void *op_result) | ||
1023 | { | ||
1024 | struct BenchmarkPeer *me = cls; | ||
1025 | |||
1026 | GNUNET_ATS_performance_done (me->ats_perf_handle); | ||
1027 | me->ats_perf_handle = NULL; | ||
1028 | } | ||
1029 | |||
1030 | static void | ||
1031 | ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | ||
1032 | void *ca_result, const char *emsg) | ||
1033 | { | ||
1034 | static int op_done = 0; | ||
1035 | |||
1036 | if ((NULL != emsg) || (NULL == ca_result)) | ||
1037 | { | ||
1038 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n")); | ||
1039 | GNUNET_break(0); | ||
1040 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
1041 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
1042 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL ); | ||
1043 | return; | ||
1044 | } | ||
1045 | op_done++; | ||
1046 | if (op_done == (num_masters + num_slaves)) | ||
1047 | { | ||
1048 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all ATS services\n"); | ||
1049 | state.connected_ATS_service = GNUNET_YES; | ||
1050 | GNUNET_SCHEDULER_add_now (&do_comm_connect, NULL ); | ||
1051 | } | ||
1052 | } | ||
1053 | |||
1054 | static void | ||
1055 | do_connect_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1056 | { | ||
1057 | int c_m; | ||
1058 | int c_s; | ||
1059 | |||
1060 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all ATS services\n"); | ||
1061 | for (c_m = 0; c_m < num_masters; c_m++) | ||
1062 | { | ||
1063 | mps[c_m].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer, | ||
1064 | "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter, | ||
1065 | &ats_perf_disconnect_adapter, &mps[c_m]); | ||
1066 | |||
1067 | } | ||
1068 | |||
1069 | for (c_s = 0; c_s < num_slaves; c_s++) | ||
1070 | { | ||
1071 | sps[c_s].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer, | ||
1072 | "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter, | ||
1073 | &ats_perf_disconnect_adapter, &sps[c_s]); | ||
1074 | } | ||
1075 | |||
1076 | } | ||
1077 | |||
1078 | static void | ||
1079 | peerinformation_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op, | ||
1080 | const struct GNUNET_TESTBED_PeerInformation*pinfo, const char *emsg) | ||
1081 | { | ||
1082 | struct BenchmarkPeer *p = cb_cls; | ||
1083 | static int done = 0; | ||
1084 | |||
1085 | GNUNET_assert(pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY); | ||
1086 | 543 | ||
1087 | p->id = *pinfo->result.id; | ||
1088 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%s [%u] has peer id `%s'\n", | ||
1089 | (p->master == GNUNET_YES) ? "Master" : "Slave", p->no, | ||
1090 | GNUNET_i2s (&p->id)); | ||
1091 | 544 | ||
1092 | GNUNET_TESTBED_operation_done (op); | ||
1093 | p->peer_id_op = NULL; | ||
1094 | done++; | ||
1095 | 545 | ||
1096 | if (done == num_slaves + num_masters) | ||
1097 | { | ||
1098 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1099 | "Retrieved all peer ID, connect to ATS\n"); | ||
1100 | GNUNET_SCHEDULER_add_now (&do_connect_ats, NULL ); | ||
1101 | } | ||
1102 | } | ||
1103 | |||
1104 | /** | ||
1105 | * Signature of a main function for a testcase. | ||
1106 | * | ||
1107 | * @param cls closure | ||
1108 | * @param num_peers number of peers in 'peers' | ||
1109 | * @param peers_ handle to peers run in the testbed | ||
1110 | * @param links_succeeded the number of overlay link connection attempts that | ||
1111 | * succeeded | ||
1112 | * @param links_failed the number of overlay link connection attempts that | ||
1113 | * failed | ||
1114 | */ | ||
1115 | static void | ||
1116 | main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, | ||
1117 | unsigned int num_peers, | ||
1118 | struct GNUNET_TESTBED_Peer **peers_, | ||
1119 | unsigned int links_succeeded, | ||
1120 | unsigned int links_failed) | ||
1121 | { | ||
1122 | int c_m; | ||
1123 | int c_s; | ||
1124 | GNUNET_assert(NULL == cls); | ||
1125 | GNUNET_assert(num_masters + num_slaves == num_peers); | ||
1126 | GNUNET_assert(NULL != peers_); | ||
1127 | |||
1128 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1129 | _("Benchmarking solver `%s' on preference `%s' with %u master and %u slave peers\n"), | ||
1130 | solver, pref_str, num_masters, num_slaves); | ||
1131 | |||
1132 | shutdown_task = GNUNET_SCHEDULER_add_delayed ( | ||
1133 | GNUNET_TIME_relative_multiply (TEST_TIMEOUT, num_masters + num_slaves), | ||
1134 | &do_shutdown, NULL ); | ||
1135 | |||
1136 | /* Setup master peers */ | ||
1137 | for (c_m = 0; c_m < num_masters; c_m++) | ||
1138 | { | ||
1139 | GNUNET_assert(NULL != peers_[c_m]); | ||
1140 | mps[c_m].peer = peers_[c_m]; | ||
1141 | mps[c_m].no = c_m; | ||
1142 | mps[c_m].master = GNUNET_YES; | ||
1143 | mps[c_m].pref_partner = &sps[c_m]; | ||
1144 | mps[c_m].pref_value = TEST_ATS_PREFRENCE_START; | ||
1145 | mps[c_m].partners = | ||
1146 | GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPartner)); | ||
1147 | mps[c_m].num_partners = num_slaves; | ||
1148 | /* Initialize partners */ | ||
1149 | for (c_s = 0; c_s < num_slaves; c_s++) | ||
1150 | { | ||
1151 | mps[c_m].partners[c_s].me = &mps[c_m]; | ||
1152 | mps[c_m].partners[c_s].dest = &sps[c_s]; | ||
1153 | } | ||
1154 | mps[c_m].peer_id_op = GNUNET_TESTBED_peer_get_information (mps[c_m].peer, | ||
1155 | GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &mps[c_m]); | ||
1156 | } | ||
1157 | |||
1158 | /* Setup slave peers */ | ||
1159 | for (c_s = 0; c_s < num_slaves; c_s++) | ||
1160 | { | ||
1161 | GNUNET_assert(NULL != peers_[c_s + num_masters]); | ||
1162 | sps[c_s].peer = peers_[c_s + num_masters]; | ||
1163 | sps[c_s].no = c_s + num_masters; | ||
1164 | sps[c_s].master = GNUNET_NO; | ||
1165 | sps[c_s].partners = | ||
1166 | GNUNET_malloc (num_masters * sizeof (struct BenchmarkPartner)); | ||
1167 | sps[c_s].num_partners = num_masters; | ||
1168 | /* Initialize partners */ | ||
1169 | for (c_m = 0; c_m < num_masters; c_m++) | ||
1170 | { | ||
1171 | sps[c_s].partners[c_m].me = &sps[c_s]; | ||
1172 | sps[c_s].partners[c_m].dest = &mps[c_m]; | ||
1173 | } | ||
1174 | sps[c_s].peer_id_op = GNUNET_TESTBED_peer_get_information (sps[c_s].peer, | ||
1175 | GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &sps[c_s]); | ||
1176 | } | ||
1177 | } | ||
1178 | 546 | ||
1179 | int | 547 | int |
1180 | main (int argc, char *argv[]) | 548 | main (int argc, char *argv[]) |
@@ -1353,32 +721,14 @@ main (int argc, char *argv[]) | |||
1353 | return GNUNET_SYSERR; | 721 | return GNUNET_SYSERR; |
1354 | } | 722 | } |
1355 | 723 | ||
1356 | state.connected_ATS_service = GNUNET_NO; | 724 | static struct GNUNET_CORE_MessageHandler handlers[] = { |
1357 | state.connected_COMM_service = GNUNET_NO; | 725 | {&comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 }, |
1358 | state.connected_PEERS = GNUNET_NO; | 726 | {&comm_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 }, |
1359 | state.benchmarking = GNUNET_NO; | 727 | { NULL, 0, 0 } }; |
1360 | state.connected_PEERS = GNUNET_NO; | 728 | |
1361 | 729 | GNUNET_ATS_TEST_create_topology ("perf-ats", conf_name, | |
1362 | mps = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer)); | 730 | num_slaves, num_masters, test_core, |
1363 | sps = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer)); | 731 | &do_benchmark, NULL, handlers, &transport_recv_cb); |
1364 | |||
1365 | /* Start topology */ | ||
1366 | uint64_t event_mask; | ||
1367 | event_mask = 0; | ||
1368 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | ||
1369 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | ||
1370 | (void) GNUNET_TESTBED_test_run ("perf-ats", conf_name, | ||
1371 | num_slaves + num_masters, event_mask, &controller_event_cb, NULL, | ||
1372 | &main_run, NULL ); | ||
1373 | |||
1374 | GNUNET_free(solver); | ||
1375 | GNUNET_free(pref_str); | ||
1376 | GNUNET_free(conf_name); | ||
1377 | GNUNET_free(test_name); | ||
1378 | GNUNET_free(testname); | ||
1379 | GNUNET_free (comm_name); | ||
1380 | GNUNET_free(mps); | ||
1381 | GNUNET_free(sps); | ||
1382 | 732 | ||
1383 | return result; | 733 | return result; |
1384 | } | 734 | } |