aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tests
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-29 19:43:27 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-29 19:43:27 +0000
commitc23a4218f8a59ad08c82d485db37a897cac4b358 (patch)
treedf5fb2c1ac36da2a82a0b6eadafbd10b7586a6ce /src/ats-tests
parent461f88a18bb39f3966a1aa4579224fd241b8bc5d (diff)
downloadgnunet-c23a4218f8a59ad08c82d485db37a897cac4b358.tar.gz
gnunet-c23a4218f8a59ad08c82d485db37a897cac4b358.zip
-indentation
Diffstat (limited to 'src/ats-tests')
-rw-r--r--src/ats-tests/ats-testing.c182
-rw-r--r--src/ats-tests/ats-testing.h7
2 files changed, 124 insertions, 65 deletions
diff --git a/src/ats-tests/ats-testing.c b/src/ats-tests/ats-testing.c
index 16956489d..8ed135d49 100644
--- a/src/ats-tests/ats-testing.c
+++ b/src/ats-tests/ats-testing.c
@@ -68,7 +68,8 @@ do_shutdown (void *cls)
68 68
69 top->state.benchmarking = GNUNET_NO; 69 top->state.benchmarking = GNUNET_NO;
70 70
71 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n")); 71 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
72 "Benchmarking done\n");
72 73
73 GNUNET_ATS_TEST_generate_traffic_stop_all (); 74 GNUNET_ATS_TEST_generate_traffic_stop_all ();
74 75
@@ -164,18 +165,19 @@ do_shutdown (void *cls)
164 top = NULL; 165 top = NULL;
165} 166}
166 167
168
167static struct BenchmarkPartner * 169static struct BenchmarkPartner *
168find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer) 170find_partner (struct BenchmarkPeer *me,
171 const struct GNUNET_PeerIdentity *peer)
169{ 172{
170 int c_m; 173 int c_m;
171 GNUNET_assert (NULL != me);
172 GNUNET_assert (NULL != peer);
173 174
174 for (c_m = 0; c_m < me->num_partners; c_m++) 175 for (c_m = 0; c_m < me->num_partners; c_m++)
175 { 176 {
176 /* Find a partner with other as destination */ 177 /* Find a partner with other as destination */
177 if (0 == memcmp (peer, &me->partners[c_m].dest->id, 178 if (0 == memcmp (peer,
178 sizeof(struct GNUNET_PeerIdentity))) 179 &me->partners[c_m].dest->id,
180 sizeof (struct GNUNET_PeerIdentity)))
179 { 181 {
180 return &me->partners[c_m]; 182 return &me->partners[c_m];
181 } 183 }
@@ -192,13 +194,17 @@ find_peer (const struct GNUNET_PeerIdentity * peer)
192 194
193 for (c_p = 0; c_p < top->num_masters; c_p++) 195 for (c_p = 0; c_p < top->num_masters; c_p++)
194 { 196 {
195 if (0 == memcmp (&top->mps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity))) 197 if (0 == memcmp (&top->mps[c_p].id,
198 peer,
199 sizeof(struct GNUNET_PeerIdentity)))
196 return &top->mps[c_p]; 200 return &top->mps[c_p];
197 } 201 }
198 202
199 for (c_p = 0; c_p < top->num_slaves; c_p++) 203 for (c_p = 0; c_p < top->num_slaves; c_p++)
200 { 204 {
201 if (0 == memcmp (&top->sps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity))) 205 if (0 == memcmp (&top->sps[c_p].id,
206 peer,
207 sizeof(struct GNUNET_PeerIdentity)))
202 return &top->sps[c_p]; 208 return &top->sps[c_p];
203 } 209 }
204 return NULL ; 210 return NULL ;
@@ -212,7 +218,8 @@ find_peer (const struct GNUNET_PeerIdentity * peer)
212 * @param peer peer identity this notification is about 218 * @param peer peer identity this notification is about
213 */ 219 */
214static void 220static void
215comm_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) 221comm_connect_cb (void *cls,
222 const struct GNUNET_PeerIdentity *peer)
216{ 223{
217 struct BenchmarkPeer *me = cls; 224 struct BenchmarkPeer *me = cls;
218 struct BenchmarkPeer *remote; 225 struct BenchmarkPeer *remote;
@@ -223,16 +230,19 @@ comm_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
223 remote = find_peer (peer); 230 remote = find_peer (peer);
224 if (NULL == remote) 231 if (NULL == remote)
225 { 232 {
226 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unknown peer connected: `%s'\n", GNUNET_i2s (peer)); 233 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
234 "Unknown peer connected: `%s'\n",
235 GNUNET_i2s (peer));
227 GNUNET_break(0); 236 GNUNET_break(0);
228 return; 237 return;
229 } 238 }
230 239
231 id = GNUNET_strdup (GNUNET_i2s (&me->id)); 240 id = GNUNET_strdup (GNUNET_i2s (&me->id));
232 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s [%u] `%s' connected to %s [%u] %s\n", 241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 (me->master == GNUNET_YES) ? "Master": "Slave", me->no, id, 242 "%s [%u] `%s' connected to %s [%u] %s\n",
234 (remote->master == GNUNET_YES) ? "Master": "Slave", remote->no, 243 (me->master == GNUNET_YES) ? "Master": "Slave", me->no, id,
235 GNUNET_i2s (peer)); 244 (remote->master == GNUNET_YES) ? "Master": "Slave", remote->no,
245 GNUNET_i2s (peer));
236 246
237 me->core_connections++; 247 me->core_connections++;
238 if ((GNUNET_YES == me->master) && (GNUNET_NO == remote->master) 248 if ((GNUNET_YES == me->master) && (GNUNET_NO == remote->master)
@@ -265,8 +275,10 @@ comm_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
265 GNUNET_free(id); 275 GNUNET_free(id);
266} 276}
267 277
278
268static void 279static void
269comm_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) 280comm_disconnect_cb (void *cls,
281 const struct GNUNET_PeerIdentity *peer)
270{ 282{
271 struct BenchmarkPeer *me = cls; 283 struct BenchmarkPeer *me = cls;
272 struct BenchmarkPartner *p; 284 struct BenchmarkPartner *p;
@@ -276,16 +288,21 @@ comm_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
276 return; 288 return;
277 289
278 id = GNUNET_strdup (GNUNET_i2s (&me->id)); 290 id = GNUNET_strdup (GNUNET_i2s (&me->id));
279 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s disconnected from %s \n", id, 291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
280 GNUNET_i2s (peer)); 292 "%s disconnected from %s\n",
293 id,
294 GNUNET_i2s (peer));
281 GNUNET_assert(me->core_connections > 0); 295 GNUNET_assert(me->core_connections > 0);
282 me->core_connections--; 296 me->core_connections--;
283 297
284 if ((GNUNET_YES == top->state.benchmarking) 298 if ( (GNUNET_YES == top->state.benchmarking) &&
285 && ((GNUNET_YES == me->master) || (GNUNET_YES == p->dest->master))) 299 ( (GNUNET_YES == me->master) ||
300 (GNUNET_YES == p->dest->master) ) )
286 { 301 {
287 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 302 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
288 "%s disconnected from %s while benchmarking \n", id, GNUNET_i2s (peer)); 303 "%s disconnected from %s while benchmarking\n",
304 id,
305 GNUNET_i2s (peer));
289 if (NULL != p->tth) 306 if (NULL != p->tth)
290 { 307 {
291 GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->tth); 308 GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->tth);
@@ -302,17 +319,28 @@ comm_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
302 319
303 320
304static void * 321static void *
305core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 322core_connect_adapter (void *cls,
323 const struct GNUNET_CONFIGURATION_Handle *cfg)
306{ 324{
307 struct BenchmarkPeer *me = cls; 325 struct BenchmarkPeer *me = cls;
308 326
309 me->ch = GNUNET_CORE_connect (cfg, me, NULL, comm_connect_cb, 327 me->ch = GNUNET_CORE_connect (cfg,
310 comm_disconnect_cb, NULL, GNUNET_NO, NULL, GNUNET_NO, top->handlers); 328 me,
329 NULL,
330 &comm_connect_cb,
331 &comm_disconnect_cb,
332 NULL,
333 GNUNET_NO,
334 NULL,
335 GNUNET_NO,
336 top->handlers);
311 if (NULL == me->ch) 337 if (NULL == me->ch)
312 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create core connection \n"); 338 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
339 "Failed to create core connection \n");
313 return me->ch; 340 return me->ch;
314} 341}
315 342
343
316static void 344static void
317core_disconnect_adapter (void *cls, void *op_result) 345core_disconnect_adapter (void *cls, void *op_result)
318{ 346{
@@ -323,11 +351,10 @@ core_disconnect_adapter (void *cls, void *op_result)
323} 351}
324 352
325 353
326
327
328static int 354static int
329comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other, 355comm_handle_pong (void *cls,
330 const struct GNUNET_MessageHeader *message) 356 const struct GNUNET_PeerIdentity *other,
357 const struct GNUNET_MessageHeader *message)
331{ 358{
332 struct BenchmarkPeer *me = cls; 359 struct BenchmarkPeer *me = cls;
333 struct BenchmarkPartner *p = NULL; 360 struct BenchmarkPartner *p = NULL;
@@ -343,9 +370,11 @@ comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
343 return GNUNET_OK; 370 return GNUNET_OK;
344} 371}
345 372
373
346static int 374static int
347comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other, 375comm_handle_ping (void *cls,
348 const struct GNUNET_MessageHeader *message) 376 const struct GNUNET_PeerIdentity *other,
377 const struct GNUNET_MessageHeader *message)
349{ 378{
350 struct BenchmarkPeer *me = cls; 379 struct BenchmarkPeer *me = cls;
351 struct BenchmarkPartner *p = NULL; 380 struct BenchmarkPartner *p = NULL;
@@ -359,14 +388,15 @@ comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
359 return GNUNET_OK; 388 return GNUNET_OK;
360} 389}
361 390
391
362static void 392static void
363test_recv_cb (void *cls, 393test_recv_cb (void *cls,
364 const struct GNUNET_PeerIdentity * peer, 394 const struct GNUNET_PeerIdentity *peer,
365 const struct GNUNET_MessageHeader * message) 395 const struct GNUNET_MessageHeader *message)
366{ 396{
367 if (TEST_MESSAGE_SIZE != ntohs (message->size) || 397 if ( (TEST_MESSAGE_SIZE != ntohs (message->size)) ||
368 (TEST_MESSAGE_TYPE_PING != ntohs (message->type) && 398 ( (TEST_MESSAGE_TYPE_PING != ntohs (message->type)) &&
369 TEST_MESSAGE_TYPE_PONG != ntohs (message->type))) 399 (TEST_MESSAGE_TYPE_PONG != ntohs (message->type)) ) )
370 { 400 {
371 return; 401 return;
372 } 402 }
@@ -383,10 +413,15 @@ transport_connect_adapter (void *cls,
383{ 413{
384 struct BenchmarkPeer *me = cls; 414 struct BenchmarkPeer *me = cls;
385 415
386 me->th = GNUNET_TRANSPORT_connect (cfg, &me->id, me, &test_recv_cb, 416 me->th = GNUNET_TRANSPORT_connect (cfg,
387 &comm_connect_cb, &comm_disconnect_cb); 417 &me->id,
418 me,
419 &test_recv_cb,
420 &comm_connect_cb,
421 &comm_disconnect_cb);
388 if (NULL == me->th) 422 if (NULL == me->th)
389 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create transport connection \n"); 423 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
424 "Failed to create transport connection \n");
390 return me->th; 425 return me->th;
391} 426}
392 427
@@ -582,10 +617,11 @@ ats_performance_info_cb (void *cls,
582 p->bandwidth_in = ntohl (bandwidth_in.value__); 617 p->bandwidth_in = ntohl (bandwidth_in.value__);
583 p->bandwidth_out = ntohl (bandwidth_out.value__); 618 p->bandwidth_out = ntohl (bandwidth_out.value__);
584 619
585 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information: %s\n", 620 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
586 (GNUNET_YES == p->me->master) ? "Master" : "Slave", 621 "%s [%u] received ATS information: %s\n",
587 p->me->no, 622 (GNUNET_YES == p->me->master) ? "Master" : "Slave",
588 GNUNET_i2s (&p->dest->id)); 623 p->me->no,
624 GNUNET_i2s (&p->dest->id));
589 625
590 p->props.utilization_out = ats_prop->utilization_out; 626 p->props.utilization_out = ats_prop->utilization_out;
591 p->props.utilization_in = ats_prop->utilization_in; 627 p->props.utilization_in = ats_prop->utilization_in;
@@ -605,18 +641,21 @@ ats_performance_info_cb (void *cls,
605 641
606static void * 642static void *
607ats_perf_connect_adapter (void *cls, 643ats_perf_connect_adapter (void *cls,
608 const struct GNUNET_CONFIGURATION_Handle *cfg) 644 const struct GNUNET_CONFIGURATION_Handle *cfg)
609{ 645{
610 struct BenchmarkPeer *me = cls; 646 struct BenchmarkPeer *me = cls;
611 647
612 me->ats_perf_handle = GNUNET_ATS_performance_init (cfg, 648 me->ats_perf_handle
613 &ats_performance_info_cb, me); 649 = GNUNET_ATS_performance_init (cfg,
650 &ats_performance_info_cb,
651 me);
614 if (NULL == me->ats_perf_handle) 652 if (NULL == me->ats_perf_handle)
615 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 653 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
616 "Failed to create ATS performance handle \n"); 654 "Failed to create ATS performance handle \n");
617 return me->ats_perf_handle; 655 return me->ats_perf_handle;
618} 656}
619 657
658
620static void 659static void
621ats_perf_disconnect_adapter (void *cls, void *op_result) 660ats_perf_disconnect_adapter (void *cls, void *op_result)
622{ 661{
@@ -626,9 +665,12 @@ ats_perf_disconnect_adapter (void *cls, void *op_result)
626 me->ats_perf_handle = NULL; 665 me->ats_perf_handle = NULL;
627} 666}
628 667
668
629static void 669static void
630ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op, 670ats_connect_completion_cb (void *cls,
631 void *ca_result, const char *emsg) 671 struct GNUNET_TESTBED_Operation *op,
672 void *ca_result,
673 const char *emsg)
632{ 674{
633 static int op_done = 0; 675 static int op_done = 0;
634 676
@@ -643,9 +685,11 @@ ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
643 op_done++; 685 op_done++;
644 if (op_done == (top->num_masters + top->num_slaves)) 686 if (op_done == (top->num_masters + top->num_slaves))
645 { 687 {
646 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all ATS services\n"); 688 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
689 "Connected to all ATS services\n");
647 top->state.connected_ATS_service = GNUNET_YES; 690 top->state.connected_ATS_service = GNUNET_YES;
648 GNUNET_SCHEDULER_add_now (&do_comm_connect, NULL ); 691 GNUNET_SCHEDULER_add_now (&do_comm_connect,
692 NULL);
649 } 693 }
650} 694}
651 695
@@ -656,29 +700,42 @@ do_connect_ats (void *cls)
656 int c_m; 700 int c_m;
657 int c_s; 701 int c_s;
658 702
659 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all ATS services\n"); 703 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
704 "Connecting to all ATS services\n");
660 for (c_m = 0; c_m < top->num_masters; c_m++) 705 for (c_m = 0; c_m < top->num_masters; c_m++)
661 { 706 {
662 top->mps[c_m].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, 707 top->mps[c_m].ats_perf_op
663 top->mps[c_m].peer, 708 = GNUNET_TESTBED_service_connect (NULL,
664 "ats", ats_connect_completion_cb, NULL, 709 top->mps[c_m].peer,
665 &ats_perf_connect_adapter, 710 "ats",
666 &ats_perf_disconnect_adapter, &top->mps[c_m]); 711 &ats_connect_completion_cb,
712 NULL,
713 &ats_perf_connect_adapter,
714 &ats_perf_disconnect_adapter,
715 &top->mps[c_m]);
667 } 716 }
668 717
669 for (c_s = 0; c_s < top->num_slaves; c_s++) 718 for (c_s = 0; c_s < top->num_slaves; c_s++)
670 { 719 {
671 top->sps[c_s].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, top->sps[c_s].peer, 720 top->sps[c_s].ats_perf_op
672 "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter, 721 = GNUNET_TESTBED_service_connect (NULL,
673 &ats_perf_disconnect_adapter, &top->sps[c_s]); 722 top->sps[c_s].peer,
723 "ats",
724 &ats_connect_completion_cb,
725 NULL,
726 &ats_perf_connect_adapter,
727 &ats_perf_disconnect_adapter,
728 &top->sps[c_s]);
674 } 729 }
675} 730}
676 731
677 732
678 733
679static void 734static void
680peerinformation_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op, 735peerinformation_cb (void *cb_cls,
681 const struct GNUNET_TESTBED_PeerInformation*pinfo, const char *emsg) 736 struct GNUNET_TESTBED_Operation *op,
737 const struct GNUNET_TESTBED_PeerInformation *pinfo,
738 const char *emsg)
682{ 739{
683 struct BenchmarkPeer *p = cb_cls; 740 struct BenchmarkPeer *p = cb_cls;
684 static int done = 0; 741 static int done = 0;
@@ -877,6 +934,7 @@ GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
877 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); 934 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
878 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); 935 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
879 (void) GNUNET_TESTBED_test_run (name, cfg_file, 936 (void) GNUNET_TESTBED_test_run (name, cfg_file,
937
880 num_slaves + num_masters, 938 num_slaves + num_masters,
881 event_mask, 939 event_mask,
882 &controller_event_cb, NULL, 940 &controller_event_cb, NULL,
diff --git a/src/ats-tests/ats-testing.h b/src/ats-tests/ats-testing.h
index b98988138..c6e679b0b 100644
--- a/src/ats-tests/ats-testing.h
+++ b/src/ats-tests/ats-testing.h
@@ -72,9 +72,10 @@ enum GeneratorType
72 * @param masters array of master peers 72 * @param masters array of master peers
73 * @param slaves array of master peers 73 * @param slaves array of master peers
74 */ 74 */
75typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls, 75typedef void
76 struct BenchmarkPeer *masters, 76(*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls,
77 struct BenchmarkPeer *slaves); 77 struct BenchmarkPeer *masters,
78 struct BenchmarkPeer *slaves);
78 79
79/** 80/**
80 * Callback called when logging is required for the data contained 81 * Callback called when logging is required for the data contained