summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-01-22 16:22:53 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-01-22 16:22:53 +0000
commit0c7aa062cb988866f9d859a7c67836707cf1041c (patch)
treedde37bec39cf05142a36d0dd40d2fb150c7fd595
parent3425604d4fa20375309ec016a6f52f5e57578fac (diff)
downloadgnunet-0c7aa062cb988866f9d859a7c67836707cf1041c.tar.gz
gnunet-0c7aa062cb988866f9d859a7c67836707cf1041c.zip
changes to traffic generation
-rw-r--r--src/ats-tests/ats-testing.c566
-rw-r--r--src/ats-tests/ats-testing.h231
-rw-r--r--src/ats-tests/gnunet-ats-sim.c107
-rw-r--r--src/ats-tests/perf_ats.c270
4 files changed, 724 insertions, 450 deletions
diff --git a/src/ats-tests/ats-testing.c b/src/ats-tests/ats-testing.c
index b93a097d9..8ed1164b3 100644
--- a/src/ats-tests/ats-testing.c
+++ b/src/ats-tests/ats-testing.c
@@ -26,8 +26,171 @@
26 */ 26 */
27#include "ats-testing.h" 27#include "ats-testing.h"
28 28
29/**
30 * Overall state of the performance benchmark
31 */
32struct BenchmarkState
33{
34 /**
35 * Are we connected to ATS service of all peers: GNUNET_YES/NO
36 */
37 int connected_ATS_service;
38
39 /**
40 * Are we connected to CORE service of all peers: GNUNET_YES/NO
41 */
42 int connected_COMM_service;
43
44 /**
45 * Are we connected to all peers: GNUNET_YES/NO
46 */
47 int connected_PEERS;
48
49 /**
50 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
51 */
52 int connected_CORE;
53
54 /**
55 * Are we connected to CORE service of all peers: GNUNET_YES/NO
56 */
57 int benchmarking;
58};
59
60
61
62
63/**
64 * Connect peers with testbed
65 */
66struct TestbedConnectOperation
67{
68 /**
69 * The benchmarking master initiating this connection
70 */
71 struct BenchmarkPeer *master;
72
73 /**
74 * The benchmarking slave to connect to
75 */
76 struct BenchmarkPeer *slave;
77
78 /**
79 * Testbed operation to connect peers
80 */
81 struct GNUNET_TESTBED_Operation *connect_op;
82};
83
84struct GNUNET_ATS_TEST_Topology
85{
86 /**
87 * Shutdown task
88 */
89 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
90
91 /**
92 * Progress task
93 */
94 GNUNET_SCHEDULER_TaskIdentifier progress_task;
95
96 /**
97 * Test result
98 */
99 int result;
100
101 /**
102 * Test result logging
103 */
104 int logging;
105
106 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
107 */
108 int test_core;
109
110 /**
111 * Solver string
112 */
113 char *solver;
114
115 /**
116 * Preference string
117 */
118 char *testname;
119
120 /**
121 * Preference string
122 */
123 char *pref_str;
124
125 /**
126 * ATS preference value
127 */
128 int pref_val;
129
130 /**
131 * Number master peers
132 */
133 unsigned int num_masters;
134
135 /**
136 * Array of master peers
137 */
138 struct BenchmarkPeer *mps;
139
140 /**
141 * Number slave peers
142 */
143 unsigned int num_slaves;
144
145 /**
146 * Array of slave peers
147 */
148 struct BenchmarkPeer *sps;
149
150 /**
151 * Benchmark duration
152 */
153 struct GNUNET_TIME_Relative perf_duration;
154
155 /**
156 * Logging frequency
157 */
158 struct GNUNET_TIME_Relative log_frequency;
159
160 /**
161 * Benchmark state
162 */
163 struct BenchmarkState state;
164
165 struct GNUNET_CORE_MessageHandler *handlers;
166
167 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
168
169 GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb;
170 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
171 void *done_cb_cls;
172};
173
174
175
29static struct GNUNET_ATS_TEST_Topology *top; 176static struct GNUNET_ATS_TEST_Topology *top;
30 177
178struct TrafficGenerator *tg_head;
179struct TrafficGenerator *tg_tail;
180
181struct TrafficGenerator
182{
183 struct TrafficGenerator *prev;
184 struct TrafficGenerator *next;
185
186 struct BenchmarkPeer *src;
187 struct BenchmarkPartner *dest;
188 unsigned int rate;
189 GNUNET_SCHEDULER_Task next_send;
190 struct GNUNET_TIME_Absolute last_sent;
191 struct GNUNET_TIME_Relative delta;
192};
193
31/** 194/**
32 * Shutdown nicely 195 * Shutdown nicely
33 * 196 *
@@ -41,6 +204,8 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
41 int c_s; 204 int c_s;
42 int c_op; 205 int c_op;
43 struct BenchmarkPeer *p; 206 struct BenchmarkPeer *p;
207 struct TrafficGenerator *cur;
208 struct TrafficGenerator *next;
44 209
45 if (GNUNET_YES == top->logging) 210 if (GNUNET_YES == top->logging)
46 GNUNET_ATS_TEST_logging_stop (); 211 GNUNET_ATS_TEST_logging_stop ();
@@ -48,6 +213,14 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
48 top->shutdown_task = GNUNET_SCHEDULER_NO_TASK; 213 top->shutdown_task = GNUNET_SCHEDULER_NO_TASK;
49 214
50 top->state.benchmarking = GNUNET_NO; 215 top->state.benchmarking = GNUNET_NO;
216
217 next = tg_head;
218 for (cur = next; NULL != cur; cur = next)
219 {
220 next = cur->next;
221 GNUNET_ATS_TEST_generate_traffic_stop(cur);
222 }
223
51 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n")); 224 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
52 225
53 for (c_m = 0; c_m < top->num_masters; c_m++) 226 for (c_m = 0; c_m < top->num_masters; c_m++)
@@ -137,8 +310,9 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
137 GNUNET_free(p->partners); 310 GNUNET_free(p->partners);
138 p->partners = NULL; 311 p->partners = NULL;
139 } 312 }
140
141 GNUNET_SCHEDULER_shutdown (); 313 GNUNET_SCHEDULER_shutdown ();
314 GNUNET_free (top);
315 top = NULL;
142} 316}
143 317
144static struct BenchmarkPartner * 318static struct BenchmarkPartner *
@@ -234,6 +408,9 @@ comm_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
234 "All master peers connected all slave peers\n", id, 408 "All master peers connected all slave peers\n", id,
235 GNUNET_i2s (peer)); 409 GNUNET_i2s (peer));
236 top->state.connected_CORE = GNUNET_YES; 410 top->state.connected_CORE = GNUNET_YES;
411 /* Notify about setup done */
412 if (NULL != top->done_cb)
413 top->done_cb (top->done_cb_cls, top->mps, top->sps);
237 } 414 }
238 } 415 }
239 GNUNET_free(id); 416 GNUNET_free(id);
@@ -297,12 +474,214 @@ core_disconnect_adapter (void *cls, void *op_result)
297} 474}
298 475
299 476
477
478static size_t
479send_ping_ready_cb (void *cls, size_t size, void *buf)
480{
481 struct BenchmarkPartner *p = cls;
482 static char msgbuf[TEST_MESSAGE_SIZE];
483 struct GNUNET_MessageHeader *msg;
484
485 if (NULL == buf)
486 {
487 GNUNET_break (0);
488 return 0;
489 }
490 if (size < TEST_MESSAGE_SIZE)
491 {
492 GNUNET_break (0);
493 return 0;
494 }
495
496 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Master [%u]: Sending PING to [%u]\n",
497 p->me->no, p->dest->no);
498
499 if (top->test_core)
500 {
501 if (NULL == p->cth)
502 {
503 GNUNET_break (0);
504 }
505 p->cth = NULL;
506 }
507 else
508 {
509 if (NULL == p->tth)
510 {
511 GNUNET_break (0);
512 }
513 p->tth = NULL;
514 }
515
516 msg = (struct GNUNET_MessageHeader *) &msgbuf;
517 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
518 msg->type = htons (TEST_MESSAGE_TYPE_PING);
519 msg->size = htons (TEST_MESSAGE_SIZE);
520 memcpy (buf, msg, TEST_MESSAGE_SIZE);
521
522 p->messages_sent++;
523 p->bytes_sent += TEST_MESSAGE_SIZE;
524 p->me->total_messages_sent++;
525 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
526
527 return TEST_MESSAGE_SIZE;
528}
529
530
531static void
532comm_schedule_send (struct BenchmarkPartner *p)
533{
534 p->last_message_sent = GNUNET_TIME_absolute_get();
535 if (GNUNET_YES == top->test_core)
536 {
537 p->cth = GNUNET_CORE_notify_transmit_ready (
538 p->me->ch, GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &p->dest->id,
539 TEST_MESSAGE_SIZE, &send_ping_ready_cb, p);
540 }
541 else
542 {
543 p->tth = GNUNET_TRANSPORT_notify_transmit_ready (
544 p->me->th, &p->dest->id, TEST_MESSAGE_SIZE, 0,GNUNET_TIME_UNIT_MINUTES,
545 &send_ping_ready_cb, p);
546 }
547}
548
549static struct TrafficGenerator *
550find_tg (struct BenchmarkPartner *p)
551{
552 struct TrafficGenerator *cur;
553 for (cur = tg_head; NULL != cur; cur = cur->next)
554 if ( (0 == memcmp (&p->me->id, &cur->dest->me, sizeof (cur->dest->me))) &&
555 (0 == memcmp (&p->dest->id, &cur->dest->dest->id, sizeof (cur->dest->dest->id))) )
556 return cur;
557
558 return NULL;
559}
560
561static int
562core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
563 const struct GNUNET_MessageHeader *message)
564{
565 struct BenchmarkPeer *me = cls;
566 struct BenchmarkPartner *p = NULL;
567 struct TrafficGenerator *tg;
568
569 if (NULL == (p = find_partner (me, other)))
570 {
571 GNUNET_break(0);
572 return GNUNET_SYSERR;
573 }
574
575 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
576 "Master [%u]: Received PONG from [%u], next message\n", me->no,
577 p->dest->no);
578
579 p->messages_received++;
580 p->bytes_received += TEST_MESSAGE_SIZE;
581 p->me->total_messages_received++;
582 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
583 p->total_app_rtt += GNUNET_TIME_absolute_get_difference(p->last_message_sent,
584 GNUNET_TIME_absolute_get()).rel_value_us;
585
586
587 tg = find_tg(p);
588/*
589 if (GNUNET_TIME_absolute_max(GNUNET_TIME_absolute_get(), tg->next_send))*/
590 comm_schedule_send (p);
591 return GNUNET_OK;
592}
593
594static size_t
595comm_send_pong_ready (void *cls, size_t size, void *buf)
596{
597 static char msgbuf[TEST_MESSAGE_SIZE];
598 struct BenchmarkPartner *p = cls;
599 struct GNUNET_MessageHeader *msg;
600
601 if (GNUNET_YES == top->test_core)
602 p->cth = NULL;
603 else
604 p->tth = NULL;
605
606 p->messages_sent++;
607 p->bytes_sent += TEST_MESSAGE_SIZE;
608 p->me->total_messages_sent++;
609 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
610
611 msg = (struct GNUNET_MessageHeader *) &msgbuf;
612 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
613 msg->type = htons (TEST_MESSAGE_TYPE_PONG);
614 msg->size = htons (TEST_MESSAGE_SIZE);
615 memcpy (buf, msg, TEST_MESSAGE_SIZE);
616
617 return TEST_MESSAGE_SIZE;
618}
619
620
621static int
622core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
623 const struct GNUNET_MessageHeader *message)
624{
625 struct BenchmarkPeer *me = cls;
626 struct BenchmarkPartner *p = NULL;
627
628 if (NULL == (p = find_partner(me, other)))
629 {
630 GNUNET_break(0);
631 return GNUNET_SYSERR;
632 }
633
634 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
635 "Slave [%u]: Received PING from [%u], sending PONG\n", me->no,
636 p->dest->no);
637
638 p->messages_received++;
639 p->bytes_received += TEST_MESSAGE_SIZE;
640 p->me->total_messages_received++;
641 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
642
643 if (GNUNET_YES == top->test_core)
644 {
645 GNUNET_assert (NULL == p->cth);
646
647 p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
648 GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
649 &comm_send_pong_ready, p);
650 }
651 else
652 {
653 GNUNET_assert (NULL == p->tth);
654 p->tth = GNUNET_TRANSPORT_notify_transmit_ready (me->th, &p->dest->id,
655 TEST_MESSAGE_SIZE, 0, GNUNET_TIME_UNIT_MINUTES, &comm_send_pong_ready,
656 p);
657 }
658 return GNUNET_OK;
659}
660
661static void
662test_recv_cb (void *cls,
663 const struct GNUNET_PeerIdentity * peer,
664 const struct GNUNET_MessageHeader * message)
665{
666 if (TEST_MESSAGE_SIZE != ntohs (message->size) ||
667 (TEST_MESSAGE_TYPE_PING != ntohs (message->type) &&
668 TEST_MESSAGE_TYPE_PONG != ntohs (message->type)))
669 {
670 return;
671 }
672 if (TEST_MESSAGE_TYPE_PING == ntohs (message->type))
673 core_handle_ping (cls, peer, message);
674 if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type))
675 core_handle_pong (cls, peer, message);
676}
677
678
300static void * 679static void *
301transport_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 680transport_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
302{ 681{
303 struct BenchmarkPeer *me = cls; 682 struct BenchmarkPeer *me = cls;
304 683
305 me->th = GNUNET_TRANSPORT_connect (cfg, &me->id, me, top->transport_recv_cb, 684 me->th = GNUNET_TRANSPORT_connect (cfg, &me->id, me, &test_recv_cb,
306 &comm_connect_cb, &comm_disconnect_cb); 685 &comm_connect_cb, &comm_disconnect_cb);
307 if (NULL == me->th) 686 if (NULL == me->th)
308 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create transport connection \n"); 687 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create transport connection \n");
@@ -352,9 +731,6 @@ connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op,
352 if (ops == top->num_masters * top->num_slaves) 731 if (ops == top->num_masters * top->num_slaves)
353 { 732 {
354 top->state.connected_PEERS = GNUNET_YES; 733 top->state.connected_PEERS = GNUNET_YES;
355 /* Notify about setup done */
356 if (NULL != top->done_cb)
357 top->done_cb (top->done_cb_cls, top->mps, top->sps);
358 } 734 }
359} 735}
360 736
@@ -463,6 +839,101 @@ do_comm_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
463 } 839 }
464} 840}
465 841
842static void
843ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
844 int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
845 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
846 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
847{
848 struct BenchmarkPeer *me = cls;
849 struct BenchmarkPartner *p;
850 int c_a;
851 int log;
852 char *peer_id;
853
854 p = find_partner (me, &address->peer);
855 if (NULL == p)
856 {
857 /* This is not one of my partners
858 * Will happen since the peers will connect to each other due to gossiping
859 */
860 return;
861 }
862 peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
863
864 log = GNUNET_NO;
865 if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
866 (p->bandwidth_out != ntohl (bandwidth_out.value__)))
867 log = GNUNET_YES;
868 p->bandwidth_in = ntohl (bandwidth_in.value__);
869 p->bandwidth_out = ntohl (bandwidth_out.value__);
870
871 for (c_a = 0; c_a < ats_count; c_a++)
872 {
873 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information: %s %s %u\n",
874 (GNUNET_YES == p->me->master) ? "Master" : "Slave",
875 p->me->no,
876 GNUNET_i2s (&p->dest->id),
877 GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
878 ntohl(ats[c_a].value));
879 switch (ntohl (ats[c_a].type ))
880 {
881 case GNUNET_ATS_ARRAY_TERMINATOR:
882 break;
883 case GNUNET_ATS_UTILIZATION_OUT:
884 if (p->ats_utilization_up != ntohl (ats[c_a].value))
885 log = GNUNET_YES;
886 p->ats_utilization_up = ntohl (ats[c_a].value);
887
888 break;
889 case GNUNET_ATS_UTILIZATION_IN:
890 if (p->ats_utilization_down != ntohl (ats[c_a].value))
891 log = GNUNET_YES;
892 p->ats_utilization_down = ntohl (ats[c_a].value);
893 break;
894 case GNUNET_ATS_NETWORK_TYPE:
895 if (p->ats_network_type != ntohl (ats[c_a].value))
896 log = GNUNET_YES;
897 p->ats_network_type = ntohl (ats[c_a].value);
898 break;
899 case GNUNET_ATS_QUALITY_NET_DELAY:
900 if (p->ats_delay != ntohl (ats[c_a].value))
901 log = GNUNET_YES;
902 p->ats_delay = ntohl (ats[c_a].value);
903 break;
904 case GNUNET_ATS_QUALITY_NET_DISTANCE:
905 if (p->ats_distance != ntohl (ats[c_a].value))
906 log = GNUNET_YES;
907 p->ats_distance = ntohl (ats[c_a].value);
908 GNUNET_break (0);
909 break;
910 case GNUNET_ATS_COST_WAN:
911 if (p->ats_cost_wan != ntohl (ats[c_a].value))
912 log = GNUNET_YES;
913 p->ats_cost_wan = ntohl (ats[c_a].value);
914 break;
915 case GNUNET_ATS_COST_LAN:
916 if (p->ats_cost_lan != ntohl (ats[c_a].value))
917 log = GNUNET_YES;
918 p->ats_cost_lan = ntohl (ats[c_a].value);
919 break;
920 case GNUNET_ATS_COST_WLAN:
921 if (p->ats_cost_wlan != ntohl (ats[c_a].value))
922 log = GNUNET_YES;
923 p->ats_cost_wlan = ntohl (ats[c_a].value);
924 break;
925 default:
926 break;
927 }
928 }
929 if ((GNUNET_YES == top->logging) && (GNUNET_YES == log))
930 GNUNET_ATS_TEST_logging_now();
931
932 top->ats_perf_cb (cls, address, address_active, bandwidth_out, bandwidth_in,
933 ats, ats_count);
934 GNUNET_free(peer_id);
935}
936
466 937
467static void * 938static void *
468ats_perf_connect_adapter (void *cls, 939ats_perf_connect_adapter (void *cls,
@@ -470,7 +941,7 @@ ats_perf_connect_adapter (void *cls,
470{ 941{
471 struct BenchmarkPeer *me = cls; 942 struct BenchmarkPeer *me = cls;
472 943
473 me->ats_perf_handle = GNUNET_ATS_performance_init (cfg, top->ats_perf_cb, me); 944 me->ats_perf_handle = GNUNET_ATS_performance_init (cfg, ats_performance_info_cb, me);
474 if (NULL == me->ats_perf_handle) 945 if (NULL == me->ats_perf_handle)
475 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 946 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
476 "Failed to create ATS performance handle \n"); 947 "Failed to create ATS performance handle \n");
@@ -662,6 +1133,7 @@ controller_event_cb (void *cls,
662 } 1133 }
663} 1134}
664 1135
1136
665void 1137void
666GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file, 1138GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
667 unsigned int num_slaves, 1139 unsigned int num_slaves,
@@ -669,11 +1141,15 @@ GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
669 int test_core, 1141 int test_core,
670 GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb, 1142 GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb,
671 void *done_cb_cls, 1143 void *done_cb_cls,
672 struct GNUNET_CORE_MessageHandler *handlers,
673 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb, 1144 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb,
674 GNUNET_ATS_AddressInformationCallback ats_perf_cb) 1145 GNUNET_ATS_AddressInformationCallback ats_perf_cb)
675{ 1146{
676 1147
1148 static struct GNUNET_CORE_MessageHandler handlers[] = {
1149 {&core_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
1150 {&core_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
1151 { NULL, 0, 0 } };
1152
677 top = GNUNET_new (struct GNUNET_ATS_TEST_Topology); 1153 top = GNUNET_new (struct GNUNET_ATS_TEST_Topology);
678 top->num_masters = num_masters; 1154 top->num_masters = num_masters;
679 top->num_slaves = num_slaves; 1155 top->num_slaves = num_slaves;
@@ -700,7 +1176,83 @@ GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
700void 1176void
701GNUNET_ATS_TEST_shutdown_topology (void) 1177GNUNET_ATS_TEST_shutdown_topology (void)
702{ 1178{
1179 if (NULL == top)
1180 return;
1181
703 GNUNET_SCHEDULER_shutdown(); 1182 GNUNET_SCHEDULER_shutdown();
704} 1183}
705 1184
1185
1186
1187struct TrafficGenerator *
1188GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
1189 struct BenchmarkPartner *dest, unsigned int rate,
1190 struct GNUNET_TIME_Relative duration)
1191{
1192 struct TrafficGenerator * tg;
1193 tg = NULL;
1194
1195 tg = GNUNET_new (struct TrafficGenerator);
1196 GNUNET_CONTAINER_DLL_insert (tg_head, tg_tail, tg);
1197 tg->src = src;
1198 tg->dest = dest;
1199 tg->rate = rate;
1200
1201 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1202 "Setting up traffic generator between master[%u] `%s' and slave [%u] `%s' sending with %u Bytes/sec\n",
1203 dest->me->no, GNUNET_i2s (&dest->me->id),
1204 dest->dest->no, GNUNET_i2s (&dest->dest->id),
1205 rate);
1206
1207 if (top->test_core)
1208 {
1209 if (NULL != dest->cth)
1210 {
1211 GNUNET_break (0);
1212 return tg;
1213 }
1214 dest->cth = GNUNET_CORE_notify_transmit_ready (src->ch, GNUNET_NO,
1215 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, &dest->dest->id,
1216 TEST_MESSAGE_SIZE, &send_ping_ready_cb, dest);
1217 }
1218 else
1219 {
1220 if (NULL != dest->tth)
1221 {
1222 GNUNET_break (0);
1223 return tg;
1224 }
1225 dest->tth = GNUNET_TRANSPORT_notify_transmit_ready (src->th, &dest->dest->id,
1226 TEST_MESSAGE_SIZE, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
1227 &send_ping_ready_cb, dest);
1228 tg->last_sent = GNUNET_TIME_absolute_get();
1229 tg->delta.rel_value_us = (GNUNET_TIME_UNIT_SECONDS.rel_value_us / (rate / TEST_MESSAGE_SIZE));
1230 }
1231 return tg;
1232}
1233
1234void
1235GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg)
1236{
1237 GNUNET_CONTAINER_DLL_remove (tg_head, tg_tail, tg);
1238
1239 if (top->test_core)
1240 {
1241 if (NULL != tg->dest->cth)
1242 {
1243 GNUNET_CORE_notify_transmit_ready_cancel (tg->dest->cth);
1244 tg->dest->cth = NULL;
1245 }
1246 }
1247 else
1248 {
1249 if (NULL != tg->dest->tth)
1250 {
1251 GNUNET_TRANSPORT_notify_transmit_ready_cancel (tg->dest->tth);
1252 tg->dest->tth = NULL;
1253 }
1254 }
1255 GNUNET_free (tg);
1256}
1257
706/* end of file ats-testing.c */ 1258/* end of file ats-testing.c */
diff --git a/src/ats-tests/ats-testing.h b/src/ats-tests/ats-testing.h
index 540f2bd8c..a3d208187 100644
--- a/src/ats-tests/ats-testing.h
+++ b/src/ats-tests/ats-testing.h
@@ -31,116 +31,18 @@
31 31
32#define TEST_ATS_PREFERENCE_DEFAULT 1.0 32#define TEST_ATS_PREFERENCE_DEFAULT 1.0
33 33
34/** 34#define TEST_MESSAGE_TYPE_PING 12345
35 * Overall state of the performance benchmark 35#define TEST_MESSAGE_TYPE_PONG 12346
36 */ 36#define TEST_MESSAGE_SIZE 1000
37struct BenchmarkState
38{
39 /**
40 * Are we connected to ATS service of all peers: GNUNET_YES/NO
41 */
42 int connected_ATS_service;
43
44 /**
45 * Are we connected to CORE service of all peers: GNUNET_YES/NO
46 */
47 int connected_COMM_service;
48
49 /**
50 * Are we connected to all peers: GNUNET_YES/NO
51 */
52 int connected_PEERS;
53 37
54 /** 38struct BenchmarkPartner;
55 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO 39struct BenchmarkPeer;
56 */ 40struct GNUNET_ATS_TEST_Topology;
57 int connected_CORE; 41struct TrafficGenerator;
58
59 /**
60 * Are we connected to CORE service of all peers: GNUNET_YES/NO
61 */
62 int benchmarking;
63};
64
65
66/**
67 * Information about a benchmarking partner
68 */
69struct BenchmarkPartner
70{
71 /**
72 * The peer itself this partner belongs to
73 */
74 struct BenchmarkPeer *me;
75
76 /**
77 * The partner peer
78 */
79 struct BenchmarkPeer *dest;
80
81 /**
82 * Core transmit handles
83 */
84 struct GNUNET_CORE_TransmitHandle *cth;
85
86 /**
87 * Transport transmit handles
88 */
89 struct GNUNET_TRANSPORT_TransmitHandle *tth;
90
91 /**
92 * Timestamp to calculate communication layer delay
93 */
94 struct GNUNET_TIME_Absolute last_message_sent;
95
96 /**
97 * Accumulated RTT for all messages
98 */
99 unsigned int total_app_rtt;
100
101 /**
102 * Number of messages sent to this partner
103 */
104 unsigned int messages_sent;
105
106 /**
107 * Number of bytes sent to this partner
108 */
109 unsigned int bytes_sent;
110
111 /**
112 * Number of messages received from this partner
113 */
114 unsigned int messages_received;
115
116 /**
117 * Number of bytes received from this partner
118 */
119 unsigned int bytes_received;
120
121 /* Current ATS properties */
122
123 uint32_t ats_distance;
124
125 uint32_t ats_delay;
126
127 uint32_t bandwidth_in;
128
129 uint32_t bandwidth_out;
130
131 uint32_t ats_utilization_up;
132
133 uint32_t ats_utilization_down;
134
135 uint32_t ats_network_type;
136
137 uint32_t ats_cost_wan;
138
139 uint32_t ats_cost_lan;
140
141 uint32_t ats_cost_wlan;
142};
143 42
43typedef void (*GNUNET_ATS_TESTING_TopologySetupDoneCallback) (void *cls,
44 struct BenchmarkPeer *masters,
45 struct BenchmarkPeer *slaves);
144 46
145/** 47/**
146 * Information we track for a peer in the testbed. 48 * Information we track for a peer in the testbed.
@@ -264,121 +166,93 @@ struct BenchmarkPeer
264 unsigned int total_bytes_received; 166 unsigned int total_bytes_received;
265}; 167};
266 168
169
267/** 170/**
268 * Connect peers with testbed 171 * Information about a benchmarking partner
269 */ 172 */
270struct TestbedConnectOperation 173struct BenchmarkPartner
271{ 174{
272 /** 175 /**
273 * The benchmarking master initiating this connection 176 * The peer itself this partner belongs to
274 */ 177 */
275 struct BenchmarkPeer *master; 178 struct BenchmarkPeer *me;
276 179
277 /** 180 /**
278 * The benchmarking slave to connect to 181 * The partner peer
279 */ 182 */
280 struct BenchmarkPeer *slave; 183 struct BenchmarkPeer *dest;
281 184
282 /** 185 /**
283 * Testbed operation to connect peers 186 * Core transmit handles
284 */ 187 */
285 struct GNUNET_TESTBED_Operation *connect_op; 188 struct GNUNET_CORE_TransmitHandle *cth;
286};
287
288typedef void (*GNUNET_ATS_TESTING_TopologySetupDoneCallback) (void *cls,
289 struct BenchmarkPeer *masters,
290 struct BenchmarkPeer *slaves);
291 189
292struct GNUNET_ATS_TEST_Topology
293{
294 /** 190 /**
295 * Shutdown task 191 * Transport transmit handles
296 */ 192 */
297 GNUNET_SCHEDULER_TaskIdentifier shutdown_task; 193 struct GNUNET_TRANSPORT_TransmitHandle *tth;
298 194
299 /** 195 /**
300 * Progress task 196 * Timestamp to calculate communication layer delay
301 */ 197 */
302 GNUNET_SCHEDULER_TaskIdentifier progress_task; 198 struct GNUNET_TIME_Absolute last_message_sent;
303 199
304 /** 200 /**
305 * Test result 201 * Accumulated RTT for all messages
306 */ 202 */
307 int result; 203 unsigned int total_app_rtt;
308 204
309 /** 205 /**
310 * Test result logging 206 * Number of messages sent to this partner
311 */
312 int logging;
313
314 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
315 */ 207 */
316 int test_core; 208 unsigned int messages_sent;
317 209
318 /** 210 /**
319 * Solver string 211 * Number of bytes sent to this partner
320 */ 212 */
321 char *solver; 213 unsigned int bytes_sent;
322 214
323 /** 215 /**
324 * Preference string 216 * Number of messages received from this partner
325 */ 217 */
326 char *testname; 218 unsigned int messages_received;
327 219
328 /** 220 /**
329 * Preference string 221 * Number of bytes received from this partner
330 */ 222 */
331 char *pref_str; 223 unsigned int bytes_received;
332 224
333 /** 225 /* Current ATS properties */
334 * ATS preference value
335 */
336 int pref_val;
337 226
338 /** 227 uint32_t ats_distance;
339 * Number master peers
340 */
341 unsigned int num_masters;
342 228
343 /** 229 uint32_t ats_delay;
344 * Array of master peers
345 */
346 struct BenchmarkPeer *mps;
347 230
348 /** 231 uint32_t bandwidth_in;
349 * Number slave peers
350 */
351 unsigned int num_slaves;
352 232
353 /** 233 uint32_t bandwidth_out;
354 * Array of slave peers
355 */
356 struct BenchmarkPeer *sps;
357 234
358 /** 235 uint32_t ats_utilization_up;
359 * Benchmark duration
360 */
361 struct GNUNET_TIME_Relative perf_duration;
362 236
363 /** 237 uint32_t ats_utilization_down;
364 * Logging frequency
365 */
366 struct GNUNET_TIME_Relative log_frequency;
367 238
368 /** 239 uint32_t ats_network_type;
369 * Benchmark state
370 */
371 struct BenchmarkState state;
372 240
373 struct GNUNET_CORE_MessageHandler *handlers; 241 uint32_t ats_cost_wan;
374 242
375 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb; 243 uint32_t ats_cost_lan;
376 244
377 GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb; 245 uint32_t ats_cost_wlan;
378 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
379 void *done_cb_cls;
380}; 246};
381 247
248struct TrafficGenerator *
249GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
250 struct BenchmarkPartner *dest, unsigned int rate,
251 struct GNUNET_TIME_Relative duration);
252
253void
254GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
255
382void 256void
383GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency, 257GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
384 char * testname, struct BenchmarkPeer *masters, int num_masters); 258 char * testname, struct BenchmarkPeer *masters, int num_masters);
@@ -396,7 +270,6 @@ GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
396 int test_core, 270 int test_core,
397 GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb, 271 GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb,
398 void *done_cb_cls, 272 void *done_cb_cls,
399 struct GNUNET_CORE_MessageHandler *handlers,
400 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb, 273 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb,
401 GNUNET_ATS_AddressInformationCallback ats_perf_cb); 274 GNUNET_ATS_AddressInformationCallback ats_perf_cb);
402 275
diff --git a/src/ats-tests/gnunet-ats-sim.c b/src/ats-tests/gnunet-ats-sim.c
index b394cb8a4..993a8a0e4 100644
--- a/src/ats-tests/gnunet-ats-sim.c
+++ b/src/ats-tests/gnunet-ats-sim.c
@@ -35,8 +35,13 @@
35#define DEFAULT_NUM_SLAVES 5 35#define DEFAULT_NUM_SLAVES 5
36#define DEFAULT_NUM_MASTERS 1 36#define DEFAULT_NUM_MASTERS 1
37 37
38#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
39
38#define TEST_MESSAGE_TYPE_PING 12345 40#define TEST_MESSAGE_TYPE_PING 12345
39#define TEST_MESSAGE_TYPE_PONG 12346 41#define TEST_MESSAGE_TYPE_PONG 1234
42
43static struct BenchmarkPeer *masters_p;
44static struct BenchmarkPeer *slaves_p;
40 45
41/** 46/**
42 * Number of master peers to use 47 * Number of master peers to use
@@ -48,18 +53,74 @@ static int c_masters;
48 */ 53 */
49static int c_slaves; 54static int c_slaves;
50 55
51static int 56static void
52core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other, 57evaluate ()
53 const struct GNUNET_MessageHeader *message)
54{ 58{
55 return 0; 59 int c_m;
60 int c_s;
61 unsigned int duration;
62 struct BenchmarkPeer *mp;
63 struct BenchmarkPartner *p;
64
65 unsigned int kb_sent_sec;
66 double kb_sent_percent;
67 unsigned int kb_recv_sec;
68 double kb_recv_percent;
69 unsigned int rtt;
70
71 duration = (TEST_TIMEOUT.rel_value_us / (1000 * 1000));
72 for (c_m = 0; c_m < c_masters; c_m++)
73 {
74 mp = &masters_p[c_m];
75 fprintf (stderr,
76 _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"),
77 mp->no, mp->total_bytes_sent / 1024, duration,
78 (mp->total_bytes_sent / 1024) / duration,
79 mp->total_bytes_received / 1024, duration,
80 (mp->total_bytes_received / 1024) / duration);
81
82 for (c_s = 0; c_s < c_slaves; c_s++)
83 {
84 p = &mp->partners[c_s];
85
86 kb_sent_sec = 0;
87 kb_recv_sec = 0;
88 kb_sent_percent = 0.0;
89 kb_recv_percent = 0.0;
90 rtt = 0;
91
92 if (duration > 0)
93 {
94 kb_sent_sec = (p->bytes_sent / 1024) / duration;
95 kb_recv_sec = (p->bytes_received / 1024) / duration;
96 }
97
98 if (mp->total_bytes_sent > 0)
99 kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent;
100 if (mp->total_bytes_received > 0)
101 kb_recv_percent = ((double) p->bytes_received * 100) / mp->total_bytes_received;
102 if (1000 * p->messages_sent > 0)
103 rtt = p->total_app_rtt / (1000 * p->messages_sent);
104 fprintf (stderr,
105 "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
106 (mp->pref_partner == p->dest) ? '*' : ' ',
107 mp->no, p->dest->no,
108 kb_sent_sec, kb_sent_percent,
109 kb_recv_sec, kb_recv_percent);
110 fprintf (stderr,
111 "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
112 (mp->pref_partner == p->dest) ? '*' : ' ',
113 mp->no, p->dest->no, rtt);
114 }
115 }
56} 116}
57 117
58static int 118static void
59core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other, 119do_shutdown ()
60 const struct GNUNET_MessageHeader *message)
61{ 120{
62 return 0; 121 /* Shutdown a topology with */
122 evaluate ();
123 GNUNET_ATS_TEST_shutdown_topology ();
63} 124}
64 125
65static void 126static void
@@ -83,21 +144,30 @@ static void topology_setup_done (void *cls,
83 struct BenchmarkPeer *masters, 144 struct BenchmarkPeer *masters,
84 struct BenchmarkPeer *slaves) 145 struct BenchmarkPeer *slaves)
85{ 146{
147 int c_m;
148 int c_s;
86 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Topology setup complete!\n"); 149 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Topology setup complete!\n");
87 150
88 151 masters_p = masters;
89 /* Shutdown a topology with */ 152 slaves_p = slaves;
90 GNUNET_ATS_TEST_shutdown_topology (); 153
154 for (c_m = 0; c_m < c_masters; c_m++)
155 {
156 for (c_s = 0; c_s < c_slaves; c_s++)
157 {
158 /* Generate maximum traffic to all peers */
159 GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
160 &masters[c_m].partners[c_s], 10000,
161 GNUNET_TIME_UNIT_FOREVER_REL);
162 }
163 }
164 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &do_shutdown, NULL);
91} 165}
92 166
167
93int 168int
94main (int argc, char *argv[]) 169main (int argc, char *argv[])
95{ 170{
96 static struct GNUNET_CORE_MessageHandler handlers[] = {
97 {&core_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
98 {&core_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
99 { NULL, 0, 0 } };
100
101 c_slaves = DEFAULT_NUM_SLAVES; 171 c_slaves = DEFAULT_NUM_SLAVES;
102 c_masters = DEFAULT_NUM_MASTERS; 172 c_masters = DEFAULT_NUM_MASTERS;
103 173
@@ -105,10 +175,9 @@ main (int argc, char *argv[])
105 GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", "perf_ats_proportional_none.conf", 175 GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", "perf_ats_proportional_none.conf",
106 c_slaves, 176 c_slaves,
107 c_masters, 177 c_masters,
108 GNUNET_YES, 178 GNUNET_NO,
109 &topology_setup_done, 179 &topology_setup_done,
110 NULL, 180 NULL,
111 handlers,
112 &transport_recv_cb, 181 &transport_recv_cb,
113 &ats_performance_info_cb); 182 &ats_performance_info_cb);
114 return 0; 183 return 0;
diff --git a/src/ats-tests/perf_ats.c b/src/ats-tests/perf_ats.c
index 9d56ab659..08b6a1518 100644
--- a/src/ats-tests/perf_ats.c
+++ b/src/ats-tests/perf_ats.c
@@ -35,9 +35,6 @@
35#define TEST_ATS_PREFRENCE_START 1.0 35#define TEST_ATS_PREFRENCE_START 1.0
36#define TEST_ATS_PREFRENCE_DELTA 1.0 36#define TEST_ATS_PREFRENCE_DELTA 1.0
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#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
42 39
43#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 40#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
@@ -150,9 +147,6 @@ evaluate ()
150 { 147 {
151 p = &mp->partners[c_s]; 148 p = &mp->partners[c_s];
152 149
153 fprintf (stderr , "%u %u %u\n", p->bytes_sent, (p->bytes_sent / 1024) / duration, duration);
154 fprintf (stderr , "%u %u %u \n", p->bytes_received, (p->bytes_sent / 1024) / duration, duration);
155
156 kb_sent_sec = 0; 150 kb_sent_sec = 0;
157 kb_recv_sec = 0; 151 kb_recv_sec = 0;
158 kb_sent_percent = 0.0; 152 kb_sent_percent = 0.0;
@@ -171,16 +165,12 @@ evaluate ()
171 kb_recv_percent = ((double) p->bytes_received * 100) / mp->total_bytes_received; 165 kb_recv_percent = ((double) p->bytes_received * 100) / mp->total_bytes_received;
172 if (1000 * p->messages_sent > 0) 166 if (1000 * p->messages_sent > 0)
173 rtt = p->total_app_rtt / (1000 * p->messages_sent); 167 rtt = p->total_app_rtt / (1000 * p->messages_sent);
174
175
176
177 fprintf (stderr, 168 fprintf (stderr,
178 "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n", 169 "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
179 (mp->pref_partner == p->dest) ? '*' : ' ', 170 (mp->pref_partner == p->dest) ? '*' : ' ',
180 mp->no, p->dest->no, 171 mp->no, p->dest->no,
181 kb_sent_sec, kb_sent_percent, 172 kb_sent_sec, kb_sent_percent,
182 kb_recv_sec, kb_recv_percent); 173 kb_recv_sec, kb_recv_percent);
183
184 fprintf (stderr, 174 fprintf (stderr,
185 "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n", 175 "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
186 (mp->pref_partner == p->dest) ? '*' : ' ', 176 (mp->pref_partner == p->dest) ? '*' : ' ',
@@ -216,63 +206,6 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
216 GNUNET_ATS_TEST_shutdown_topology(); 206 GNUNET_ATS_TEST_shutdown_topology();
217} 207}
218 208
219static size_t
220comm_send_ready (void *cls, size_t size, void *buf)
221{
222 static char msgbuf[TEST_MESSAGE_SIZE];
223 struct BenchmarkPartner *p = cls;
224 struct GNUNET_MessageHeader *msg;
225
226 if (GNUNET_YES == test_core)
227 p->cth = NULL;
228 else
229 p->tth = NULL;
230
231 if (NULL == buf)
232 {
233 GNUNET_break (0);
234 return 0;
235 }
236 if (size < TEST_MESSAGE_SIZE)
237 {
238 GNUNET_break (0);
239 return 0;
240 }
241
242 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Master [%u]: Sending PING to [%u]\n",
243 p->me->no, p->dest->no);
244
245 p->messages_sent++;
246 p->bytes_sent += TEST_MESSAGE_SIZE;
247 p->me->total_messages_sent++;
248 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
249
250 msg = (struct GNUNET_MessageHeader *) &msgbuf;
251 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
252 msg->type = htons (TEST_MESSAGE_TYPE_PING);
253 msg->size = htons (TEST_MESSAGE_SIZE);
254 memcpy (buf, msg, TEST_MESSAGE_SIZE);
255 return TEST_MESSAGE_SIZE;
256}
257
258static void
259comm_schedule_send (struct BenchmarkPartner *p)
260{
261 p->last_message_sent = GNUNET_TIME_absolute_get();
262 if (GNUNET_YES == test_core)
263 {
264 p->cth = GNUNET_CORE_notify_transmit_ready (
265 p->me->ch, GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &p->dest->id,
266 TEST_MESSAGE_SIZE, &comm_send_ready, p);
267 }
268 else
269 {
270 p->tth = GNUNET_TRANSPORT_notify_transmit_ready (
271 p->me->th, &p->dest->id, TEST_MESSAGE_SIZE, 0,GNUNET_TIME_UNIT_MINUTES,
272 &comm_send_ready, p);
273 }
274
275}
276 209
277static void 210static void
278print_progress () 211print_progress ()
@@ -306,64 +239,50 @@ ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
306} 239}
307 240
308static void 241static void
309do_benchmark (void *cls, struct BenchmarkPeer *masters, struct BenchmarkPeer *slaves) 242start_benchmark()
310{ 243{
311 int c_m; 244 int c_m;
312 int c_s; 245 int c_s;
313 246
314 mps = masters;
315 sps = slaves;
316
317 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n")); 247 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n"));
318 248
319 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) 249 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
320 GNUNET_SCHEDULER_cancel (shutdown_task); 250 GNUNET_SCHEDULER_cancel(shutdown_task);
321 shutdown_task = GNUNET_SCHEDULER_add_delayed (perf_duration, 251 shutdown_task = GNUNET_SCHEDULER_add_delayed(perf_duration, &do_shutdown,
322 &do_shutdown, NULL ); 252 NULL );
323 253
324 progress_task = GNUNET_SCHEDULER_add_now (&print_progress, NULL ); 254 progress_task = GNUNET_SCHEDULER_add_now(&print_progress, NULL );
325 255
326 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Topology connected, start benchmarking...\n"); 256 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
257 "Topology connected, start benchmarking...\n");
327 258
328 /* Start sending test messages */ 259 /* Start sending test messages */
329 for (c_m = 0; c_m < num_masters; c_m++) 260 for (c_m = 0; c_m < num_masters; c_m++)
330 { 261 {
331 for (c_s = 0; c_s < num_slaves; c_s++) 262 for (c_s = 0; c_s < num_slaves; c_s++)
332 comm_schedule_send (&masters[c_m].partners[c_s]); 263 {
333 if (pref_val != GNUNET_ATS_PREFERENCE_END) 264 GNUNET_ATS_TEST_generate_traffic_start (&mps[c_m], &mps[c_m].partners[c_s],
334 masters[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, &masters[c_m]); 265 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL);
335 } 266 }
267 if (pref_val != GNUNET_ATS_PREFERENCE_END)
268 mps[c_m].ats_task = GNUNET_SCHEDULER_add_now(&ats_pref_task, &mps[c_m]);
269 }
336 270
337 if (GNUNET_YES == logging) 271 if (GNUNET_YES == logging)
338 GNUNET_ATS_TEST_logging_start (log_frequency, testname, mps, num_masters); 272 GNUNET_ATS_TEST_logging_start(log_frequency, testname, mps, num_masters);
339} 273}
340 274
341 275static void
342static size_t 276do_benchmark (void *cls, struct BenchmarkPeer *masters, struct BenchmarkPeer *slaves)
343comm_send_pong_ready (void *cls, size_t size, void *buf)
344{ 277{
345 static char msgbuf[TEST_MESSAGE_SIZE]; 278 mps = masters;
346 struct BenchmarkPartner *p = cls; 279 sps = slaves;
347 struct GNUNET_MessageHeader *msg;
348 280
349 if (GNUNET_YES == test_core) 281 GNUNET_SCHEDULER_add_now(&start_benchmark, NULL);
350 p->cth = NULL; 282}
351 else
352 p->tth = NULL;
353 283
354 p->messages_sent++;
355 p->bytes_sent += TEST_MESSAGE_SIZE;
356 p->me->total_messages_sent++;
357 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
358 284
359 msg = (struct GNUNET_MessageHeader *) &msgbuf;
360 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
361 msg->type = htons (TEST_MESSAGE_TYPE_PONG);
362 msg->size = htons (TEST_MESSAGE_SIZE);
363 memcpy (buf, msg, TEST_MESSAGE_SIZE);
364 285
365 return TEST_MESSAGE_SIZE;
366}
367 286
368static struct BenchmarkPartner * 287static struct BenchmarkPartner *
369find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer) 288find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer)
@@ -384,91 +303,12 @@ find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer)
384 return NULL; 303 return NULL;
385} 304}
386 305
387static int
388comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
389 const struct GNUNET_MessageHeader *message)
390{
391
392 struct BenchmarkPeer *me = cls;
393 struct BenchmarkPartner *p = NULL;
394
395 if (NULL == (p = find_partner(me, other)))
396 {
397 GNUNET_break(0);
398 return GNUNET_SYSERR;
399 }
400
401 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
402 "Slave [%u]: Received PING from [%u], sending PONG\n", me->no,
403 p->dest->no);
404
405 p->messages_received++;
406 p->bytes_received += TEST_MESSAGE_SIZE;
407 p->me->total_messages_received++;
408 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
409
410 if (GNUNET_YES == test_core)
411 {
412 GNUNET_assert (NULL == p->cth);
413 p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
414 GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
415 &comm_send_pong_ready, p);
416 }
417 else
418 {
419 GNUNET_assert (NULL == p->tth);
420 p->tth = GNUNET_TRANSPORT_notify_transmit_ready (me->th, &p->dest->id,
421 TEST_MESSAGE_SIZE, 0, GNUNET_TIME_UNIT_MINUTES, &comm_send_pong_ready,
422 p);
423 }
424 return GNUNET_OK;
425}
426
427static int
428comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
429 const struct GNUNET_MessageHeader *message)
430{
431 struct BenchmarkPeer *me = cls;
432 struct BenchmarkPartner *p = NULL;
433
434 if (NULL == (p = find_partner (me, other)))
435 {
436 GNUNET_break(0);
437 return GNUNET_SYSERR;
438 }
439
440 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
441 "Master [%u]: Received PONG from [%u], next message\n", me->no,
442 p->dest->no);
443
444 p->messages_received++;
445 p->bytes_received += TEST_MESSAGE_SIZE;
446 p->me->total_messages_received++;
447 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
448 p->total_app_rtt += GNUNET_TIME_absolute_get_difference(p->last_message_sent,
449 GNUNET_TIME_absolute_get()).rel_value_us;
450
451 comm_schedule_send (p);
452 return GNUNET_OK;
453}
454
455
456static void 306static void
457test_recv_cb (void *cls, 307test_recv_cb (void *cls,
458 const struct GNUNET_PeerIdentity * peer, 308 const struct GNUNET_PeerIdentity * peer,
459 const struct GNUNET_MessageHeader * message) 309 const struct GNUNET_MessageHeader * message)
460{ 310{
461 if (TEST_MESSAGE_SIZE != ntohs (message->size) ||
462 (TEST_MESSAGE_TYPE_PING != ntohs (message->type) &&
463 TEST_MESSAGE_TYPE_PONG != ntohs (message->type)))
464 {
465 return;
466 }
467 if (TEST_MESSAGE_TYPE_PING == ntohs (message->type))
468 comm_handle_ping (cls, peer, message);
469 311
470 if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type))
471 comm_handle_pong (cls, peer, message);
472} 312}
473 313
474 314
@@ -509,61 +349,9 @@ ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
509 GNUNET_i2s (&p->dest->id), 349 GNUNET_i2s (&p->dest->id),
510 GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)), 350 GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
511 ntohl(ats[c_a].value)); 351 ntohl(ats[c_a].value));
512 switch (ntohl (ats[c_a].type ))
513 {
514 case GNUNET_ATS_ARRAY_TERMINATOR:
515 break;
516 case GNUNET_ATS_UTILIZATION_OUT:
517 if (p->ats_utilization_up != ntohl (ats[c_a].value))
518 log = GNUNET_YES;
519 p->ats_utilization_up = ntohl (ats[c_a].value);
520
521 break;
522 case GNUNET_ATS_UTILIZATION_IN:
523 if (p->ats_utilization_down != ntohl (ats[c_a].value))
524 log = GNUNET_YES;
525 p->ats_utilization_down = ntohl (ats[c_a].value);
526 break;
527 case GNUNET_ATS_NETWORK_TYPE:
528 if (p->ats_network_type != ntohl (ats[c_a].value))
529 log = GNUNET_YES;
530 p->ats_network_type = ntohl (ats[c_a].value);
531 break;
532 case GNUNET_ATS_QUALITY_NET_DELAY:
533 if (p->ats_delay != ntohl (ats[c_a].value))
534 log = GNUNET_YES;
535 p->ats_delay = ntohl (ats[c_a].value);
536 break;
537 case GNUNET_ATS_QUALITY_NET_DISTANCE:
538 if (p->ats_distance != ntohl (ats[c_a].value))
539 log = GNUNET_YES;
540 p->ats_distance = ntohl (ats[c_a].value);
541 GNUNET_break (0);
542 break;
543 case GNUNET_ATS_COST_WAN:
544 if (p->ats_cost_wan != ntohl (ats[c_a].value))
545 log = GNUNET_YES;
546 p->ats_cost_wan = ntohl (ats[c_a].value);
547 break;
548 case GNUNET_ATS_COST_LAN:
549 if (p->ats_cost_lan != ntohl (ats[c_a].value))
550 log = GNUNET_YES;
551 p->ats_cost_lan = ntohl (ats[c_a].value);
552 break;
553 case GNUNET_ATS_COST_WLAN:
554 if (p->ats_cost_wlan != ntohl (ats[c_a].value))
555 log = GNUNET_YES;
556 p->ats_cost_wlan = ntohl (ats[c_a].value);
557 break;
558 default:
559 break;
560 }
561 } 352 }
562
563 if ((GNUNET_YES == logging) && (GNUNET_YES == log))
564 GNUNET_ATS_TEST_logging_now();
565
566 GNUNET_free(peer_id); 353 GNUNET_free(peer_id);
354
567} 355}
568 356
569 357
@@ -748,21 +536,13 @@ main (int argc, char *argv[])
748 } 536 }
749 537
750 /** 538 /**
751 * Core message handler to use for PING/PONG messages
752 */
753 static struct GNUNET_CORE_MessageHandler handlers[] = {
754 {&comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
755 {&comm_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
756 { NULL, 0, 0 } };
757
758 /**
759 * Setup the topology 539 * Setup the topology
760 */ 540 */
761 GNUNET_ATS_TEST_create_topology ("perf-ats", conf_name, 541 GNUNET_ATS_TEST_create_topology ("perf-ats", conf_name,
762 num_slaves, num_masters, 542 num_slaves, num_masters,
763 test_core, 543 test_core,
764 &do_benchmark, 544 &do_benchmark,
765 NULL, handlers, 545 NULL,
766 &test_recv_cb, 546 &test_recv_cb,
767 &ats_performance_info_cb); 547 &ats_performance_info_cb);
768 548