aboutsummaryrefslogtreecommitdiff
path: root/src/ats/perf_ats.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-08-22 14:14:03 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-08-22 14:14:03 +0000
commit74bc80c0b5dc7206724d459a2a65552143af8d73 (patch)
treeef4ca051a57bf55715fc8c8189ca359b57e3fede /src/ats/perf_ats.c
parent3003feb0b391420b403654d840d3c67404fab048 (diff)
downloadgnunet-74bc80c0b5dc7206724d459a2a65552143af8d73.tar.gz
gnunet-74bc80c0b5dc7206724d459a2a65552143af8d73.zip
basic communications
Diffstat (limited to 'src/ats/perf_ats.c')
-rw-r--r--src/ats/perf_ats.c187
1 files changed, 162 insertions, 25 deletions
diff --git a/src/ats/perf_ats.c b/src/ats/perf_ats.c
index d97fd76dc..2b8a51d8b 100644
--- a/src/ats/perf_ats.c
+++ b/src/ats/perf_ats.c
@@ -35,6 +35,10 @@
35#define DEFAULT_SLAVES_NUM 3 35#define DEFAULT_SLAVES_NUM 3
36#define DEFAULT_MASTERS_NUM 1 36#define DEFAULT_MASTERS_NUM 1
37 37
38#define TEST_MESSAGE_TYPE_PING 12345
39#define TEST_MESSAGE_TYPE_PONG 12346
40#define TEST_MESSAGE_SIZE 1000
41#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
38 42
39 43
40/** 44/**
@@ -77,6 +81,11 @@ struct BenchmarkPeer
77 81
78 struct ConnectOperation *connect_ops; 82 struct ConnectOperation *connect_ops;
79 83
84 /* Message exchange */
85 struct GNUNET_CORE_TransmitHandle *cth;
86
87 int last_slave;
88
80 int core_connections; 89 int core_connections;
81 90
82 int slave_connections; 91 int slave_connections;
@@ -108,9 +117,13 @@ struct BenchmarkState
108 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */ 117 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
109 int connected_CORE_service; 118 int connected_CORE_service;
110 119
111 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */ 120 /* Are we connected to all peers: GNUNET_YES/NO */
112 int connected_PEERS; 121 int connected_PEERS;
122
123 /* Are we connected to all slave peers on CORE level: GNUNET_YES/NO */
113 int connected_CORE; 124 int connected_CORE;
125
126 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
114 int benchmarking; 127 int benchmarking;
115 128
116 int *core_connections; 129 int *core_connections;
@@ -226,6 +239,50 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
226 GNUNET_SCHEDULER_shutdown(); 239 GNUNET_SCHEDULER_shutdown();
227} 240}
228 241
242static struct BenchmarkPeer *
243find_peer (const struct GNUNET_PeerIdentity * peer)
244{
245 int c_p;
246
247 for (c_p = 0; c_p < c_master_peers; c_p++)
248 {
249 if (0 == memcmp (&bp_master[c_p].id, peer, sizeof (struct GNUNET_PeerIdentity)))
250 return &bp_master[c_p];
251 }
252
253 for (c_p = 0; c_p < c_slave_peers; c_p++)
254 {
255 if (0 == memcmp (&bp_slaves[c_p].id, peer, sizeof (struct GNUNET_PeerIdentity)))
256 return &bp_slaves[c_p];
257 }
258
259 return NULL;
260}
261
262
263static void
264store_information (struct GNUNET_PeerIdentity *id,
265 const struct GNUNET_HELLO_Address *address,
266 int address_active,
267 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
268 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
269 const struct GNUNET_ATS_Information *ats,
270 uint32_t ats_count)
271{
272 struct BenchmarkPeer *bp;
273
274 bp = find_peer (id);
275
276 if (NULL == bp)
277 {
278 GNUNET_break (0);
279 return;
280 }
281
282
283
284
285}
229 286
230static void 287static void
231ats_performance_info_cb (void *cls, 288ats_performance_info_cb (void *cls,
@@ -243,20 +300,46 @@ ats_performance_info_cb (void *cls,
243 peer_id = GNUNET_strdup (GNUNET_i2s (&p->id)); 300 peer_id = GNUNET_strdup (GNUNET_i2s (&p->id));
244 for (c_a = 0; c_a < ats_count; c_a++) 301 for (c_a = 0; c_a < ats_count; c_a++)
245 { 302 {
246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("%c %03u: %s %s %u\n"), 303 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("%c %03u: %s %s %u\n"),
247 (GNUNET_YES == p->master) ? 'M' : 'S', 304 (GNUNET_YES == p->master) ? 'M' : 'S',
248 p->no, 305 p->no,
249 GNUNET_i2s (&address->peer), 306 GNUNET_i2s (&address->peer),
250 GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)), 307 GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
251 ntohl(ats[c_a].value)); 308 ntohl(ats[c_a].value));
252 } 309 }
310
311 store_information (&p->id, address, address_active,
312 bandwidth_in, bandwidth_out,
313 ats, ats_count);
314
253 GNUNET_free (peer_id); 315 GNUNET_free (peer_id);
254} 316}
255 317
318static size_t
319core_send_ready (void *cls, size_t size, void *buf)
320{
321 static char msgbuf[TEST_MESSAGE_SIZE];
322 struct BenchmarkPeer *bp = cls;
323 struct GNUNET_MessageHeader *msg;
324
325 bp->cth = NULL;
326
327 msg = (struct GNUNET_MessageHeader *) &msgbuf;
328 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
329 msg->type = htons (TEST_MESSAGE_TYPE_PING);
330 msg->size = htons (TEST_MESSAGE_SIZE);
331 memcpy (buf, msg, TEST_MESSAGE_SIZE);
332 /* GNUNET_break (0); */
333 return TEST_MESSAGE_SIZE;
334}
335
256 336
257static void 337static void
258do_benchmark () 338do_benchmark ()
259{ 339{
340 int c_m;
341 int c_s;
342
260 if ((state.connected_ATS_service == GNUNET_NO) || 343 if ((state.connected_ATS_service == GNUNET_NO) ||
261 (state.connected_CORE_service == GNUNET_NO) || 344 (state.connected_CORE_service == GNUNET_NO) ||
262 (state.connected_PEERS == GNUNET_NO) || 345 (state.connected_PEERS == GNUNET_NO) ||
@@ -271,6 +354,17 @@ do_benchmark ()
271 GNUNET_SCHEDULER_cancel (shutdown_task); 354 GNUNET_SCHEDULER_cancel (shutdown_task);
272 shutdown_task = GNUNET_SCHEDULER_add_delayed (BENCHMARK_DURATION, &do_shutdown, NULL); 355 shutdown_task = GNUNET_SCHEDULER_add_delayed (BENCHMARK_DURATION, &do_shutdown, NULL);
273 356
357 /* Start sending test messages */
358 for (c_m = 0; c_m < c_master_peers; c_m ++)
359 {
360 bp_master[c_m].last_slave = 0;
361 bp_master[c_m].cth = GNUNET_CORE_notify_transmit_ready (bp_master[c_m].ch,
362 GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES,
363 &bp_slaves[bp_master[c_m].last_slave].id,
364 TEST_MESSAGE_SIZE, &core_send_ready, &bp_master[c_m]);
365 }
366
367
274} 368}
275 369
276 370
@@ -383,26 +477,6 @@ controller_event_cb (void *cls,
383 } 477 }
384} 478}
385 479
386static struct BenchmarkPeer *
387find_peer (const struct GNUNET_PeerIdentity * peer)
388{
389 int c_p;
390
391 for (c_p = 0; c_p < c_master_peers; c_p++)
392 {
393 if (0 == memcmp (&bp_master[c_p].id, peer, sizeof (struct GNUNET_PeerIdentity)))
394 return &bp_master[c_p];
395 }
396
397 for (c_p = 0; c_p < c_slave_peers; c_p++)
398 {
399 if (0 == memcmp (&bp_slaves[c_p].id, peer, sizeof (struct GNUNET_PeerIdentity)))
400 return &bp_slaves[c_p];
401 }
402
403 return NULL;
404}
405
406/** 480/**
407 * Method called whenever a given peer connects. 481 * Method called whenever a given peer connects.
408 * 482 *
@@ -499,6 +573,64 @@ core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
499} 573}
500 574
501 575
576static size_t
577core_send_echo_ready (void *cls, size_t size, void *buf)
578{
579 static char msgbuf[TEST_MESSAGE_SIZE];
580 struct BenchmarkPeer *bp = cls;
581 struct GNUNET_MessageHeader *msg;
582
583 bp->cth = NULL;
584
585 msg = (struct GNUNET_MessageHeader *) &msgbuf;
586 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
587 msg->type = htons (TEST_MESSAGE_TYPE_PONG);
588 msg->size = htons (TEST_MESSAGE_SIZE);
589 memcpy (buf, msg, TEST_MESSAGE_SIZE);
590 /* GNUNET_break (0); */
591 return TEST_MESSAGE_SIZE;
592}
593
594
595static int
596core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
597 const struct GNUNET_MessageHeader *message)
598{
599 struct BenchmarkPeer *me = cls;
600 struct BenchmarkPeer *remote;
601
602 remote = find_peer (other);
603
604 if (NULL == remote)
605 {
606 GNUNET_break (0);
607 return GNUNET_SYSERR;
608 }
609
610 if (NULL != me->cth)
611 {
612 GNUNET_break (0);
613 }
614
615 /* send echo */
616 me->cth = GNUNET_CORE_notify_transmit_ready (me->ch,
617 GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES,
618 &remote->id,
619 TEST_MESSAGE_SIZE, &core_send_echo_ready, me);
620
621 return GNUNET_OK;
622}
623
624
625static int
626core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
627 const struct GNUNET_MessageHeader *message)
628{
629 /* GNUNET_break (0); */
630 return GNUNET_OK;
631}
632
633
502/** 634/**
503 * Called to open a connection to the peer's ATS performance 635 * Called to open a connection to the peer's ATS performance
504 * 636 *
@@ -514,10 +646,15 @@ core_connect_adapter (void *cls,
514{ 646{
515 struct BenchmarkPeer *peer = cls; 647 struct BenchmarkPeer *peer = cls;
516 648
649 static const struct GNUNET_CORE_MessageHandler handlers[] = {
650 {&core_handle_ping, TEST_MESSAGE_TYPE_PING, 0},
651 {&core_handle_pong, TEST_MESSAGE_TYPE_PONG, 0},
652 {NULL, 0, 0}
653 };
654
517 peer->ch = GNUNET_CORE_connect(cfg, peer, NULL, 655 peer->ch = GNUNET_CORE_connect(cfg, peer, NULL,
518 core_connect_cb, 656 core_connect_cb, core_disconnect_cb,
519 core_disconnect_cb, 657 NULL, GNUNET_NO, NULL, GNUNET_NO, handlers);
520 NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
521 if (NULL == peer->ch) 658 if (NULL == peer->ch)
522 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 659 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
523 "Failed to create core connection \n"); 660 "Failed to create core connection \n");