aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tests/ats-testing.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-01-23 10:31:31 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-01-23 10:31:31 +0000
commitfa6b31337f6a83bb14586f7afa0335e559454e9e (patch)
treeeabb95f7a80690084b04bf773b95bf3dc6eb2893 /src/ats-tests/ats-testing.c
parent722f875a3021d076a1068e5a9522afaf54f92282 (diff)
downloadgnunet-fa6b31337f6a83bb14586f7afa0335e559454e9e.tar.gz
gnunet-fa6b31337f6a83bb14586f7afa0335e559454e9e.zip
traffic generation
Diffstat (limited to 'src/ats-tests/ats-testing.c')
-rw-r--r--src/ats-tests/ats-testing.c387
1 files changed, 11 insertions, 376 deletions
diff --git a/src/ats-tests/ats-testing.c b/src/ats-tests/ats-testing.c
index 8ed1164b3..3d090c237 100644
--- a/src/ats-tests/ats-testing.c
+++ b/src/ats-tests/ats-testing.c
@@ -26,39 +26,6 @@
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 29
63/** 30/**
64 * Connect peers with testbed 31 * Connect peers with testbed
@@ -81,115 +48,8 @@ struct TestbedConnectOperation
81 struct GNUNET_TESTBED_Operation *connect_op; 48 struct GNUNET_TESTBED_Operation *connect_op;
82}; 49};
83 50
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 51
96 /** 52struct GNUNET_ATS_TEST_Topology *top;
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
176static struct GNUNET_ATS_TEST_Topology *top;
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 53
194/** 54/**
195 * Shutdown nicely 55 * Shutdown nicely
@@ -204,25 +64,17 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
204 int c_s; 64 int c_s;
205 int c_op; 65 int c_op;
206 struct BenchmarkPeer *p; 66 struct BenchmarkPeer *p;
207 struct TrafficGenerator *cur;
208 struct TrafficGenerator *next;
209 67
210 if (GNUNET_YES == top->logging) 68 if (GNUNET_YES == top->logging)
211 GNUNET_ATS_TEST_logging_stop (); 69 GNUNET_ATS_TEST_logging_stop ();
212 70
213 top->shutdown_task = GNUNET_SCHEDULER_NO_TASK; 71 top->shutdown_task = GNUNET_SCHEDULER_NO_TASK;
214
215 top->state.benchmarking = GNUNET_NO; 72 top->state.benchmarking = GNUNET_NO;
216 73
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
224 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n")); 74 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
225 75
76 GNUNET_ATS_TEST_generate_traffic_stop_all ();
77
226 for (c_m = 0; c_m < top->num_masters; c_m++) 78 for (c_m = 0; c_m < top->num_masters; c_m++)
227 { 79 {
228 p = &top->mps[c_m]; 80 p = &top->mps[c_m];
@@ -475,96 +327,13 @@ core_disconnect_adapter (void *cls, void *op_result)
475 327
476 328
477 329
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 330
561static int 331static int
562core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other, 332comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
563 const struct GNUNET_MessageHeader *message) 333 const struct GNUNET_MessageHeader *message)
564{ 334{
565 struct BenchmarkPeer *me = cls; 335 struct BenchmarkPeer *me = cls;
566 struct BenchmarkPartner *p = NULL; 336 struct BenchmarkPartner *p = NULL;
567 struct TrafficGenerator *tg;
568 337
569 if (NULL == (p = find_partner (me, other))) 338 if (NULL == (p = find_partner (me, other)))
570 { 339 {
@@ -572,54 +341,13 @@ core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
572 return GNUNET_SYSERR; 341 return GNUNET_SYSERR;
573 } 342 }
574 343
575 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 344 GNUNET_ATS_TEST_traffic_handle_pong (p);
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 345
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; 346 return GNUNET_OK;
592} 347}
593 348
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 349static int
622core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other, 350comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
623 const struct GNUNET_MessageHeader *message) 351 const struct GNUNET_MessageHeader *message)
624{ 352{
625 struct BenchmarkPeer *me = cls; 353 struct BenchmarkPeer *me = cls;
@@ -630,31 +358,7 @@ core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
630 GNUNET_break(0); 358 GNUNET_break(0);
631 return GNUNET_SYSERR; 359 return GNUNET_SYSERR;
632 } 360 }
633 361 GNUNET_ATS_TEST_traffic_handle_ping (p);
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; 362 return GNUNET_OK;
659} 363}
660 364
@@ -670,9 +374,9 @@ test_recv_cb (void *cls,
670 return; 374 return;
671 } 375 }
672 if (TEST_MESSAGE_TYPE_PING == ntohs (message->type)) 376 if (TEST_MESSAGE_TYPE_PING == ntohs (message->type))
673 core_handle_ping (cls, peer, message); 377 comm_handle_ping (cls, peer, message);
674 if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type)) 378 if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type))
675 core_handle_pong (cls, peer, message); 379 comm_handle_pong (cls, peer, message);
676} 380}
677 381
678 382
@@ -1146,8 +850,8 @@ GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
1146{ 850{
1147 851
1148 static struct GNUNET_CORE_MessageHandler handlers[] = { 852 static struct GNUNET_CORE_MessageHandler handlers[] = {
1149 {&core_handle_ping, TEST_MESSAGE_TYPE_PING, 0 }, 853 {&comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
1150 {&core_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 }, 854 {&comm_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
1151 { NULL, 0, 0 } }; 855 { NULL, 0, 0 } };
1152 856
1153 top = GNUNET_new (struct GNUNET_ATS_TEST_Topology); 857 top = GNUNET_new (struct GNUNET_ATS_TEST_Topology);
@@ -1184,75 +888,6 @@ GNUNET_ATS_TEST_shutdown_topology (void)
1184 888
1185 889
1186 890
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 891
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 892
1258/* end of file ats-testing.c */ 893/* end of file ats-testing.c */