aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tests/ats-testing-traffic.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-29 20:32:23 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-29 20:32:23 +0000
commit0cd2efeadb67206c0b3e8f1ba743ff342b18926b (patch)
treeee5e46113366e26a25b9691ebdb3e49666dc8ddd /src/ats-tests/ats-testing-traffic.c
parent1e2d3aaecc2a4130e35d46a7c03b9d80d34d6673 (diff)
downloadgnunet-0cd2efeadb67206c0b3e8f1ba743ff342b18926b.tar.gz
gnunet-0cd2efeadb67206c0b3e8f1ba743ff342b18926b.zip
-migrating ATS tests to new transport (and core) API; core tests disabled as new core API doesn't exist yet
Diffstat (limited to 'src/ats-tests/ats-testing-traffic.c')
-rw-r--r--src/ats-tests/ats-testing-traffic.c265
1 files changed, 99 insertions, 166 deletions
diff --git a/src/ats-tests/ats-testing-traffic.c b/src/ats-tests/ats-testing-traffic.c
index fade09554..760c050c8 100644
--- a/src/ats-tests/ats-testing-traffic.c
+++ b/src/ats-tests/ats-testing-traffic.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
@@ -100,51 +100,12 @@ get_delay (struct TrafficGenerator *tg)
100} 100}
101 101
102 102
103static size_t 103static void
104send_ping_ready_cb (void *cls, size_t size, void *buf) 104update_ping_data (void *cls)
105{ 105{
106 struct BenchmarkPartner *p = cls; 106 struct BenchmarkPartner *p = cls;
107 static char msgbuf[TEST_MESSAGE_SIZE];
108 struct GNUNET_MessageHeader *msg;
109 struct GNUNET_TIME_Relative delay; 107 struct GNUNET_TIME_Relative delay;
110 108
111 if (NULL == buf)
112 {
113 GNUNET_break (0);
114 return 0;
115 }
116 if (size < TEST_MESSAGE_SIZE)
117 {
118 GNUNET_break (0);
119 return 0;
120 }
121
122 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
123 "Master [%u]: Sending PING to [%u]\n",
124 p->me->no, p->dest->no);
125 if (top->test_core)
126 {
127 if (NULL == p->cth)
128 {
129 GNUNET_break (0);
130 }
131 p->cth = NULL;
132 }
133 else
134 {
135 if (NULL == p->tth)
136 {
137 GNUNET_break (0);
138 }
139 p->tth = NULL;
140 }
141
142 msg = (struct GNUNET_MessageHeader *) &msgbuf;
143 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
144 msg->type = htons (TEST_MESSAGE_TYPE_PING);
145 msg->size = htons (TEST_MESSAGE_SIZE);
146 GNUNET_memcpy (buf, msg, TEST_MESSAGE_SIZE);
147
148 p->messages_sent++; 109 p->messages_sent++;
149 p->bytes_sent += TEST_MESSAGE_SIZE; 110 p->bytes_sent += TEST_MESSAGE_SIZE;
150 p->me->total_messages_sent++; 111 p->me->total_messages_sent++;
@@ -153,16 +114,16 @@ send_ping_ready_cb (void *cls, size_t size, void *buf)
153 if (NULL == p->tg) 114 if (NULL == p->tg)
154 { 115 {
155 GNUNET_break (0); 116 GNUNET_break (0);
156 return TEST_MESSAGE_SIZE; 117 return;
157 } 118 }
158 delay = get_delay (p->tg); 119 delay = get_delay (p->tg);
159 120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
160 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Delay for next transmission %llu ms\n", 121 "Delay for next transmission %s\n",
161 (long long unsigned int) delay.rel_value_us / 1000); 122 GNUNET_STRINGS_relative_time_to_string (delay,
162 p->tg->next_ping_transmission = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), 123 GNUNET_YES));
163 delay); 124 p->tg->next_ping_transmission
164 125 = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
165 return TEST_MESSAGE_SIZE; 126 delay);
166} 127}
167 128
168 129
@@ -170,86 +131,66 @@ static void
170comm_schedule_send (void *cls) 131comm_schedule_send (void *cls)
171{ 132{
172 struct BenchmarkPartner *p = cls; 133 struct BenchmarkPartner *p = cls;
134 struct TestMessage *msg;
135 struct GNUNET_MQ_Envelope *env;
173 136
174 p->tg->send_task = NULL; 137 p->tg->send_task = NULL;
175 p->last_message_sent = GNUNET_TIME_absolute_get(); 138 p->last_message_sent = GNUNET_TIME_absolute_get();
176 if (GNUNET_YES == top->test_core) 139 env = GNUNET_MQ_msg (msg,
177 { 140 TEST_MESSAGE_TYPE_PING);
178 p->cth = GNUNET_CORE_notify_transmit_ready (p->me->ch, GNUNET_NO, 141 memset (msg->padding,
179 GNUNET_CORE_PRIO_BEST_EFFORT, 142 'a',
180 GNUNET_TIME_UNIT_MINUTES, 143 sizeof (msg->padding));
181 &p->dest->id, 144 GNUNET_MQ_notify_sent (env,
182 TEST_MESSAGE_SIZE, 145 &update_ping_data,
183 &send_ping_ready_cb, p); 146 p);
184 } 147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
185 else 148 "Master [%u]: Sending PING to [%u]\n",
186 { 149 p->me->no,
187 p->tth = GNUNET_TRANSPORT_notify_transmit_ready (p->me->th, 150 p->dest->no);
188 &p->dest->id, 151 GNUNET_MQ_send (p->mq,
189 TEST_MESSAGE_SIZE, 152 env);
190 GNUNET_TIME_UNIT_MINUTES,
191 &send_ping_ready_cb, p);
192 }
193} 153}
194 154
195 155
196static size_t 156static void
197comm_send_pong_ready (void *cls, size_t size, void *buf) 157update_pong_data (void *cls)
198{ 158{
199 static char msgbuf[TEST_MESSAGE_SIZE];
200 struct BenchmarkPartner *p = cls; 159 struct BenchmarkPartner *p = cls;
201 struct GNUNET_MessageHeader *msg;
202
203 if (GNUNET_YES == top->test_core)
204 p->cth = NULL;
205 else
206 p->tth = NULL;
207 160
208 p->messages_sent++; 161 p->messages_sent++;
209 p->bytes_sent += TEST_MESSAGE_SIZE; 162 p->bytes_sent += TEST_MESSAGE_SIZE;
210 p->me->total_messages_sent++; 163 p->me->total_messages_sent++;
211 p->me->total_bytes_sent += TEST_MESSAGE_SIZE; 164 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
212
213 msg = (struct GNUNET_MessageHeader *) &msgbuf;
214 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
215 msg->type = htons (TEST_MESSAGE_TYPE_PONG);
216 msg->size = htons (TEST_MESSAGE_SIZE);
217 GNUNET_memcpy (buf, msg, TEST_MESSAGE_SIZE);
218
219 return TEST_MESSAGE_SIZE;
220} 165}
221 166
222 167
223void 168void
224GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p) 169GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p)
225{ 170{
226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 171 struct TestMessage *msg;
227 "Slave [%u]: Received PING from [%u], sending PONG\n", p->me->no, 172 struct GNUNET_MQ_Envelope *env;
228 p->dest->no);
229 173
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "Slave [%u]: Received PING from [%u], sending PONG\n",
176 p->me->no,
177 p->dest->no);
230 p->messages_received++; 178 p->messages_received++;
231 p->bytes_received += TEST_MESSAGE_SIZE; 179 p->bytes_received += TEST_MESSAGE_SIZE;
232 p->me->total_messages_received++; 180 p->me->total_messages_received++;
233 p->me->total_bytes_received += TEST_MESSAGE_SIZE; 181 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
234 182
235 if (GNUNET_YES == top->test_core) 183
236 { 184 env = GNUNET_MQ_msg (msg,
237 GNUNET_assert (NULL == p->cth); 185 TEST_MESSAGE_TYPE_PING);
238 186 memset (msg->padding,
239 p->cth 187 'a',
240 = GNUNET_CORE_notify_transmit_ready (p->me->ch, GNUNET_NO, 188 sizeof (msg->padding));
241 GNUNET_CORE_PRIO_BEST_EFFORT, 189 GNUNET_MQ_notify_sent (env,
242 GNUNET_TIME_UNIT_MINUTES, 190 &update_pong_data,
243 &p->dest->id, TEST_MESSAGE_SIZE, 191 p);
244 &comm_send_pong_ready, p); 192 GNUNET_MQ_send (p->mq,
245 } 193 env);
246 else
247 {
248 GNUNET_assert (NULL == p->tth);
249 p->tth = GNUNET_TRANSPORT_notify_transmit_ready (p->me->th, &p->dest->id,
250 TEST_MESSAGE_SIZE, GNUNET_TIME_UNIT_MINUTES, &comm_send_pong_ready,
251 p);
252 }
253} 194}
254 195
255 196
@@ -258,8 +199,9 @@ GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p)
258{ 199{
259 struct GNUNET_TIME_Relative left; 200 struct GNUNET_TIME_Relative left;
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
261 "Master [%u]: Received PONG from [%u], next message\n", p->me->no, 202 "Master [%u]: Received PONG from [%u], next message\n",
262 p->dest->no); 203 p->me->no,
204 p->dest->no);
263 205
264 p->messages_received++; 206 p->messages_received++;
265 p->bytes_received += TEST_MESSAGE_SIZE; 207 p->bytes_received += TEST_MESSAGE_SIZE;
@@ -325,7 +267,9 @@ GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
325 } 267 }
326 268
327 tg = GNUNET_new (struct TrafficGenerator); 269 tg = GNUNET_new (struct TrafficGenerator);
328 GNUNET_CONTAINER_DLL_insert (tg_head, tg_tail, tg); 270 GNUNET_CONTAINER_DLL_insert (tg_head,
271 tg_tail,
272 tg);
329 tg->type = type; 273 tg->type = type;
330 tg->src = src; 274 tg->src = src;
331 tg->dest = dest; 275 tg->dest = dest;
@@ -336,50 +280,53 @@ GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
336 tg->next_ping_transmission = GNUNET_TIME_UNIT_FOREVER_ABS; 280 tg->next_ping_transmission = GNUNET_TIME_UNIT_FOREVER_ABS;
337 281
338 switch (type) { 282 switch (type) {
339 case GNUNET_ATS_TEST_TG_CONSTANT: 283 case GNUNET_ATS_TEST_TG_CONSTANT:
340 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 284 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
341 "Setting up constant traffic generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n", 285 "Setting up constant traffic generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
342 dest->me->no, GNUNET_i2s (&dest->me->id), 286 dest->me->no,
343 dest->dest->no, GNUNET_i2s (&dest->dest->id), 287 GNUNET_i2s (&dest->me->id),
344 base_rate); 288 dest->dest->no,
345 break; 289 GNUNET_i2s (&dest->dest->id),
346 case GNUNET_ATS_TEST_TG_LINEAR: 290 base_rate);
347 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 291 break;
348 "Setting up linear traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n", 292 case GNUNET_ATS_TEST_TG_LINEAR:
349 dest->me->no, GNUNET_i2s (&dest->me->id), 293 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
350 dest->dest->no, GNUNET_i2s (&dest->dest->id), 294 "Setting up linear traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
351 base_rate, 295 dest->me->no,
352 max_rate); 296 GNUNET_i2s (&dest->me->id),
353 break; 297 dest->dest->no,
354 case GNUNET_ATS_TEST_TG_SINUS: 298 GNUNET_i2s (&dest->dest->id),
355 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 299 base_rate,
356 "Setting up sinus traffic generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n", 300 max_rate);
357 dest->me->no, GNUNET_i2s (&dest->me->id), 301 break;
358 dest->dest->no, GNUNET_i2s (&dest->dest->id), 302 case GNUNET_ATS_TEST_TG_SINUS:
359 base_rate, max_rate); 303 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
360 break; 304 "Setting up sinus traffic generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
361 case GNUNET_ATS_TEST_TG_RANDOM: 305 dest->me->no,
362 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 306 GNUNET_i2s (&dest->me->id),
363 "Setting up random traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n", 307 dest->dest->no,
364 dest->me->no, GNUNET_i2s (&dest->me->id), 308 GNUNET_i2s (&dest->dest->id),
365 dest->dest->no, GNUNET_i2s (&dest->dest->id), 309 base_rate,
366 base_rate, max_rate); 310 max_rate);
311 break;
312 case GNUNET_ATS_TEST_TG_RANDOM:
313 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
314 "Setting up random traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
315 dest->me->no,
316 GNUNET_i2s (&dest->me->id),
317 dest->dest->no,
318 GNUNET_i2s (&dest->dest->id),
319 base_rate,
320 max_rate);
367 break; 321 break;
368 default: 322 default:
369 break; 323 break;
370 } 324 }
371 325
372 if ( ((GNUNET_YES == top->test_core) && (NULL != dest->cth)) ||
373 ((GNUNET_NO == top->test_core) && (NULL != dest->tth)) )
374 {
375 GNUNET_break (0);
376 GNUNET_CONTAINER_DLL_remove (tg_head, tg_tail, tg);
377 GNUNET_free (tg);
378 return NULL;
379 }
380
381 dest->tg = tg; 326 dest->tg = tg;
382 tg->send_task = GNUNET_SCHEDULER_add_now (&comm_schedule_send, dest); 327 tg->send_task
328 = GNUNET_SCHEDULER_add_now (&comm_schedule_send,
329 dest);
383 return tg; 330 return tg;
384} 331}
385 332
@@ -387,30 +334,15 @@ GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
387void 334void
388GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg) 335GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg)
389{ 336{
390 GNUNET_CONTAINER_DLL_remove (tg_head, tg_tail, tg); 337 GNUNET_CONTAINER_DLL_remove (tg_head,
338 tg_tail,
339 tg);
391 tg->dest->tg = NULL; 340 tg->dest->tg = NULL;
392
393 if (NULL != tg->send_task) 341 if (NULL != tg->send_task)
394 { 342 {
395 GNUNET_SCHEDULER_cancel (tg->send_task); 343 GNUNET_SCHEDULER_cancel (tg->send_task);
396 tg->send_task = NULL; 344 tg->send_task = NULL;
397 } 345 }
398 if (top->test_core)
399 {
400 if (NULL != tg->dest->cth)
401 {
402 GNUNET_CORE_notify_transmit_ready_cancel (tg->dest->cth);
403 tg->dest->cth = NULL;
404 }
405 }
406 else
407 {
408 if (NULL != tg->dest->tth)
409 {
410 GNUNET_TRANSPORT_notify_transmit_ready_cancel (tg->dest->tth);
411 tg->dest->tth = NULL;
412 }
413 }
414 GNUNET_free (tg); 346 GNUNET_free (tg);
415} 347}
416 348
@@ -423,11 +355,12 @@ GNUNET_ATS_TEST_generate_traffic_stop_all ()
423{ 355{
424 struct TrafficGenerator *cur; 356 struct TrafficGenerator *cur;
425 struct TrafficGenerator *next; 357 struct TrafficGenerator *next;
358
426 next = tg_head; 359 next = tg_head;
427 for (cur = next; NULL != cur; cur = next) 360 for (cur = next; NULL != cur; cur = next)
428 { 361 {
429 next = cur->next; 362 next = cur->next;
430 GNUNET_ATS_TEST_generate_traffic_stop(cur); 363 GNUNET_ATS_TEST_generate_traffic_stop(cur);
431 } 364 }
432} 365}
433 366