diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-20 22:16:25 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-20 22:16:25 +0000 |
commit | f6f1b9fb73dc4c7f03c70b80b94cfb2a6ce81e65 (patch) | |
tree | 96dedaab7217465eb6ad952beebd3e5d92ae92e1 /src/ats-tests/perf_ats.c | |
parent | 019338425afc502fc25aeb1896f404a6c0087a2e (diff) | |
download | gnunet-f6f1b9fb73dc4c7f03c70b80b94cfb2a6ce81e65.tar.gz gnunet-f6f1b9fb73dc4c7f03c70b80b94cfb2a6ce81e65.zip |
fix ATS testcase
Diffstat (limited to 'src/ats-tests/perf_ats.c')
-rw-r--r-- | src/ats-tests/perf_ats.c | 182 |
1 files changed, 111 insertions, 71 deletions
diff --git a/src/ats-tests/perf_ats.c b/src/ats-tests/perf_ats.c index 4c22043e5..0e4056a6c 100644 --- a/src/ats-tests/perf_ats.c +++ b/src/ats-tests/perf_ats.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010-2013 GNUnet e.V. | 3 | Copyright (C) 2010-2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -43,15 +43,16 @@ | |||
43 | #define TESTNAME_PREFIX "perf_ats_" | 43 | #define TESTNAME_PREFIX "perf_ats_" |
44 | #define DEFAULT_SLAVES_NUM 2 | 44 | #define DEFAULT_SLAVES_NUM 2 |
45 | #define DEFAULT_MASTERS_NUM 1 | 45 | #define DEFAULT_MASTERS_NUM 1 |
46 | |||
46 | /** | 47 | /** |
47 | * Shutdown task | 48 | * timeout task |
48 | */ | 49 | */ |
49 | static struct GNUNET_SCHEDULER_Task * shutdown_task; | 50 | static struct GNUNET_SCHEDULER_Task *timeout_task; |
50 | 51 | ||
51 | /** | 52 | /** |
52 | * Progress task | 53 | * Progress task |
53 | */ | 54 | */ |
54 | static struct GNUNET_SCHEDULER_Task * progress_task; | 55 | static struct GNUNET_SCHEDULER_Task *progress_task; |
55 | 56 | ||
56 | /** | 57 | /** |
57 | * Test result | 58 | * Test result |
@@ -63,7 +64,8 @@ static int result; | |||
63 | */ | 64 | */ |
64 | static int logging; | 65 | static int logging; |
65 | 66 | ||
66 | /**Test core (GNUNET_YES) or transport (GNUNET_NO) | 67 | /** |
68 | * Test core (#GNUNET_YES) or transport (#GNUNET_NO) | ||
67 | */ | 69 | */ |
68 | static int test_core; | 70 | static int test_core; |
69 | 71 | ||
@@ -119,6 +121,7 @@ static struct BenchmarkPeer *sps; | |||
119 | 121 | ||
120 | static struct LoggingHandle *l; | 122 | static struct LoggingHandle *l; |
121 | 123 | ||
124 | |||
122 | static void | 125 | static void |
123 | evaluate () | 126 | evaluate () |
124 | { | 127 | { |
@@ -138,6 +141,8 @@ evaluate () | |||
138 | for (c_m = 0; c_m < num_masters; c_m++) | 141 | for (c_m = 0; c_m < num_masters; c_m++) |
139 | { | 142 | { |
140 | mp = &mps[c_m]; | 143 | mp = &mps[c_m]; |
144 | if (NULL == mp) | ||
145 | continue; | ||
141 | fprintf (stderr, | 146 | fprintf (stderr, |
142 | _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"), | 147 | _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"), |
143 | mp->no, mp->total_bytes_sent / 1024, duration, | 148 | mp->no, mp->total_bytes_sent / 1024, duration, |
@@ -148,7 +153,8 @@ evaluate () | |||
148 | for (c_s = 0; c_s < num_slaves; c_s++) | 153 | for (c_s = 0; c_s < num_slaves; c_s++) |
149 | { | 154 | { |
150 | p = &mp->partners[c_s]; | 155 | p = &mp->partners[c_s]; |
151 | 156 | if (NULL == p) | |
157 | continue; | ||
152 | kb_sent_sec = 0; | 158 | kb_sent_sec = 0; |
153 | kb_recv_sec = 0; | 159 | kb_recv_sec = 0; |
154 | kb_sent_percent = 0.0; | 160 | kb_sent_percent = 0.0; |
@@ -168,19 +174,20 @@ evaluate () | |||
168 | if (1000 * p->messages_sent > 0) | 174 | if (1000 * p->messages_sent > 0) |
169 | rtt = p->total_app_rtt / (1000 * p->messages_sent); | 175 | rtt = p->total_app_rtt / (1000 * p->messages_sent); |
170 | fprintf (stderr, | 176 | fprintf (stderr, |
171 | "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n", | 177 | "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n", |
172 | (mp->pref_partner == p->dest) ? '*' : ' ', | 178 | (mp->pref_partner == p->dest) ? '*' : ' ', |
173 | mp->no, p->dest->no, | 179 | mp->no, p->dest->no, |
174 | kb_sent_sec, kb_sent_percent, | 180 | kb_sent_sec, kb_sent_percent, |
175 | kb_recv_sec, kb_recv_percent); | 181 | kb_recv_sec, kb_recv_percent); |
176 | fprintf (stderr, | 182 | fprintf (stderr, |
177 | "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n", | 183 | "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n", |
178 | (mp->pref_partner == p->dest) ? '*' : ' ', | 184 | (mp->pref_partner == p->dest) ? '*' : ' ', |
179 | mp->no, p->dest->no, rtt); | 185 | mp->no, p->dest->no, rtt); |
180 | } | 186 | } |
181 | } | 187 | } |
182 | } | 188 | } |
183 | 189 | ||
190 | |||
184 | /** | 191 | /** |
185 | * Shutdown nicely | 192 | * Shutdown nicely |
186 | * | 193 | * |
@@ -189,37 +196,55 @@ evaluate () | |||
189 | static void | 196 | static void |
190 | do_shutdown (void *cls) | 197 | do_shutdown (void *cls) |
191 | { | 198 | { |
192 | |||
193 | if (GNUNET_YES == logging) | 199 | if (GNUNET_YES == logging) |
194 | GNUNET_ATS_TEST_logging_clean_up(l); | 200 | GNUNET_ATS_TEST_logging_clean_up(l); |
195 | 201 | if (NULL != timeout_task) | |
196 | shutdown_task = NULL; | 202 | { |
203 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
204 | timeout_task = NULL; | ||
205 | } | ||
197 | if (NULL != progress_task) | 206 | if (NULL != progress_task) |
198 | { | 207 | { |
199 | fprintf (stderr, "0\n"); | 208 | fprintf (stderr, "0\n"); |
200 | GNUNET_SCHEDULER_cancel (progress_task); | 209 | GNUNET_SCHEDULER_cancel (progress_task); |
210 | progress_task = NULL; | ||
201 | } | 211 | } |
202 | progress_task = NULL; | 212 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
213 | "Benchmarking done\n"); | ||
214 | GNUNET_ATS_TEST_shutdown_topology (); | ||
215 | } | ||
203 | 216 | ||
204 | evaluate (); | ||
205 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n")); | ||
206 | 217 | ||
207 | GNUNET_ATS_TEST_shutdown_topology(); | 218 | /** |
219 | * Shutdown nicely | ||
220 | * | ||
221 | * @param cls NULL | ||
222 | */ | ||
223 | static void | ||
224 | do_timeout (void *cls) | ||
225 | { | ||
226 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
227 | "Terminating with timeout\n"); | ||
228 | timeout_task = NULL; | ||
229 | evaluate (); | ||
230 | GNUNET_SCHEDULER_shutdown (); | ||
208 | } | 231 | } |
209 | 232 | ||
210 | 233 | ||
211 | static void | 234 | static void |
212 | print_progress () | 235 | print_progress (void *cls) |
213 | { | 236 | { |
214 | static int calls; | 237 | static int calls; |
215 | progress_task = NULL; | ||
216 | 238 | ||
217 | fprintf (stderr, "%llu..", | 239 | progress_task = NULL; |
218 | (long long unsigned) perf_duration.rel_value_us / (1000 * 1000) - calls); | 240 | fprintf (stderr, |
241 | "%llu..", | ||
242 | (long long unsigned) perf_duration.rel_value_us / (1000 * 1000) - calls); | ||
219 | calls++; | 243 | calls++; |
220 | 244 | ||
221 | progress_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 245 | progress_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
222 | &print_progress, NULL ); | 246 | &print_progress, |
247 | NULL); | ||
223 | } | 248 | } |
224 | 249 | ||
225 | 250 | ||
@@ -240,56 +265,65 @@ ats_pref_task (void *cls) | |||
240 | &ats_pref_task, cls); | 265 | &ats_pref_task, cls); |
241 | } | 266 | } |
242 | 267 | ||
268 | |||
243 | static void | 269 | static void |
244 | start_benchmark() | 270 | start_benchmark (void *cls) |
245 | { | 271 | { |
246 | int c_m; | 272 | int c_m; |
247 | int c_s; | 273 | int c_s; |
248 | 274 | ||
249 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n")); | 275 | progress_task = GNUNET_SCHEDULER_add_now (&print_progress, |
250 | 276 | NULL); | |
251 | if (NULL != shutdown_task) | ||
252 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
253 | shutdown_task = GNUNET_SCHEDULER_add_delayed(perf_duration, &do_shutdown, | ||
254 | NULL ); | ||
255 | |||
256 | progress_task = GNUNET_SCHEDULER_add_now(&print_progress, NULL ); | ||
257 | 277 | ||
258 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 278 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
259 | "Topology connected, start benchmarking...\n"); | 279 | "Topology connected, start benchmarking...\n"); |
260 | 280 | ||
261 | /* Start sending test messages */ | 281 | /* Start sending test messages */ |
262 | for (c_m = 0; c_m < num_masters; c_m++) | 282 | for (c_m = 0; c_m < num_masters; c_m++) |
283 | { | ||
284 | for (c_s = 0; c_s < num_slaves; c_s++) | ||
263 | { | 285 | { |
264 | for (c_s = 0; c_s < num_slaves; c_s++) | 286 | GNUNET_ATS_TEST_generate_traffic_start (&mps[c_m], |
265 | { | 287 | &mps[c_m].partners[c_s], |
266 | GNUNET_ATS_TEST_generate_traffic_start (&mps[c_m], &mps[c_m].partners[c_s], | 288 | GNUNET_ATS_TEST_TG_LINEAR, |
267 | GNUNET_ATS_TEST_TG_LINEAR, UINT32_MAX, UINT32_MAX, | 289 | UINT32_MAX, |
268 | GNUNET_TIME_UNIT_MINUTES, GNUNET_TIME_UNIT_FOREVER_REL); | 290 | UINT32_MAX, |
269 | } | 291 | GNUNET_TIME_UNIT_MINUTES, |
270 | if (pref_val != GNUNET_ATS_PREFERENCE_END) | 292 | GNUNET_TIME_UNIT_FOREVER_REL); |
271 | mps[c_m].ats_task = GNUNET_SCHEDULER_add_now(&ats_pref_task, &mps[c_m]); | ||
272 | } | 293 | } |
294 | if (pref_val != GNUNET_ATS_PREFERENCE_END) | ||
295 | mps[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, | ||
296 | &mps[c_m]); | ||
297 | } | ||
273 | 298 | ||
274 | if (GNUNET_YES == logging) | 299 | if (GNUNET_YES == logging) |
275 | l = GNUNET_ATS_TEST_logging_start (log_frequency, testname, mps, | 300 | l = GNUNET_ATS_TEST_logging_start (log_frequency, |
276 | num_masters, num_slaves, GNUNET_NO); | 301 | testname, mps, |
302 | num_masters, num_slaves, | ||
303 | GNUNET_NO); | ||
277 | } | 304 | } |
278 | 305 | ||
306 | |||
279 | static void | 307 | static void |
280 | do_benchmark (void *cls, struct BenchmarkPeer *masters, struct BenchmarkPeer *slaves) | 308 | do_benchmark (void *cls, |
309 | struct BenchmarkPeer *masters, | ||
310 | struct BenchmarkPeer *slaves) | ||
281 | { | 311 | { |
282 | mps = masters; | 312 | mps = masters; |
283 | sps = slaves; | 313 | sps = slaves; |
284 | 314 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | |
285 | GNUNET_SCHEDULER_add_now(&start_benchmark, NULL); | 315 | NULL); |
316 | timeout_task = GNUNET_SCHEDULER_add_delayed (perf_duration, | ||
317 | &do_timeout, | ||
318 | NULL); | ||
319 | progress_task = GNUNET_SCHEDULER_add_now (&start_benchmark, | ||
320 | NULL); | ||
286 | } | 321 | } |
287 | 322 | ||
288 | 323 | ||
289 | |||
290 | |||
291 | static struct BenchmarkPartner * | 324 | static struct BenchmarkPartner * |
292 | find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer) | 325 | find_partner (struct BenchmarkPeer *me, |
326 | const struct GNUNET_PeerIdentity *peer) | ||
293 | { | 327 | { |
294 | int c_m; | 328 | int c_m; |
295 | GNUNET_assert (NULL != me); | 329 | GNUNET_assert (NULL != me); |
@@ -307,20 +341,23 @@ find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer) | |||
307 | return NULL; | 341 | return NULL; |
308 | } | 342 | } |
309 | 343 | ||
344 | |||
310 | static void | 345 | static void |
311 | test_recv_cb (void *cls, | 346 | test_recv_cb (void *cls, |
312 | const struct GNUNET_PeerIdentity * peer, | 347 | const struct GNUNET_PeerIdentity * peer, |
313 | const struct GNUNET_MessageHeader * message) | 348 | const struct GNUNET_MessageHeader * message) |
314 | { | 349 | { |
315 | 350 | ||
316 | } | 351 | } |
317 | 352 | ||
318 | 353 | ||
319 | static void | 354 | static void |
320 | log_request_cb (void *cls, const struct GNUNET_HELLO_Address *address, | 355 | log_request_cb (void *cls, |
321 | int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 356 | const struct GNUNET_HELLO_Address *address, |
322 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 357 | int address_active, |
323 | const struct GNUNET_ATS_Properties *ats) | 358 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
359 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
360 | const struct GNUNET_ATS_Properties *ats) | ||
324 | { | 361 | { |
325 | struct BenchmarkPeer *me = cls; | 362 | struct BenchmarkPeer *me = cls; |
326 | struct BenchmarkPartner *p; | 363 | struct BenchmarkPartner *p; |
@@ -341,12 +378,13 @@ log_request_cb (void *cls, const struct GNUNET_HELLO_Address *address, | |||
341 | p->bandwidth_in = ntohl (bandwidth_in.value__); | 378 | p->bandwidth_in = ntohl (bandwidth_in.value__); |
342 | p->bandwidth_out = ntohl (bandwidth_out.value__); | 379 | p->bandwidth_out = ntohl (bandwidth_out.value__); |
343 | 380 | ||
344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information for peers `%s'\n", | 381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
345 | (GNUNET_YES == p->me->master) ? "Master" : "Slave", | 382 | "%s [%u] received ATS information for peers `%s'\n", |
346 | p->me->no, | 383 | (GNUNET_YES == p->me->master) ? "Master" : "Slave", |
347 | GNUNET_i2s (&p->dest->id)); | 384 | p->me->no, |
385 | GNUNET_i2s (&p->dest->id)); | ||
348 | 386 | ||
349 | GNUNET_free(peer_id); | 387 | GNUNET_free (peer_id); |
350 | if (NULL != l) | 388 | if (NULL != l) |
351 | GNUNET_ATS_TEST_logging_now (l); | 389 | GNUNET_ATS_TEST_logging_now (l); |
352 | } | 390 | } |
@@ -534,7 +572,8 @@ main (int argc, char *argv[]) | |||
534 | 572 | ||
535 | if (num_slaves < num_masters) | 573 | if (num_slaves < num_masters) |
536 | { | 574 | { |
537 | fprintf (stderr, "Number of master peers is lower than slaves! exit...\n"); | 575 | fprintf (stderr, |
576 | "Number of master peers is lower than slaves! exit...\n"); | ||
538 | GNUNET_free(test_name); | 577 | GNUNET_free(test_name); |
539 | GNUNET_free(solver); | 578 | GNUNET_free(solver); |
540 | GNUNET_free(pref_str); | 579 | GNUNET_free(pref_str); |
@@ -545,13 +584,14 @@ main (int argc, char *argv[]) | |||
545 | /** | 584 | /** |
546 | * Setup the topology | 585 | * Setup the topology |
547 | */ | 586 | */ |
548 | GNUNET_ATS_TEST_create_topology ("perf-ats", conf_name, | 587 | GNUNET_ATS_TEST_create_topology ("perf-ats", |
549 | num_slaves, num_masters, | 588 | conf_name, |
550 | test_core, | 589 | num_slaves, num_masters, |
551 | &do_benchmark, | 590 | test_core, |
552 | NULL, | 591 | &do_benchmark, |
553 | &test_recv_cb, | 592 | NULL, |
554 | &log_request_cb); | 593 | &test_recv_cb, |
594 | &log_request_cb); | ||
555 | 595 | ||
556 | return result; | 596 | return result; |
557 | } | 597 | } |