aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tests/ats-testing-traffic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats-tests/ats-testing-traffic.c')
-rw-r--r--src/ats-tests/ats-testing-traffic.c412
1 files changed, 213 insertions, 199 deletions
diff --git a/src/ats-tests/ats-testing-traffic.c b/src/ats-tests/ats-testing-traffic.c
index 01462980c..14a8fe327 100644
--- a/src/ats-tests/ats-testing-traffic.c
+++ b/src/ats-tests/ats-testing-traffic.c
@@ -33,7 +33,7 @@ static struct TrafficGenerator *tg_tail;
33extern struct GNUNET_ATS_TEST_Topology *top; 33extern struct GNUNET_ATS_TEST_Topology *top;
34 34
35static struct GNUNET_TIME_Relative 35static struct GNUNET_TIME_Relative
36get_delay(struct TrafficGenerator *tg) 36get_delay (struct TrafficGenerator *tg)
37{ 37{
38 struct GNUNET_TIME_Relative delay; 38 struct GNUNET_TIME_Relative delay;
39 struct GNUNET_TIME_Relative time_delta; 39 struct GNUNET_TIME_Relative time_delta;
@@ -44,69 +44,78 @@ get_delay(struct TrafficGenerator *tg)
44 44
45 /* Calculate the current transmission rate based on the type of traffic */ 45 /* Calculate the current transmission rate based on the type of traffic */
46 switch (tg->type) 46 switch (tg->type)
47 {
48 case GNUNET_ATS_TEST_TG_CONSTANT:
49 if (UINT32_MAX == tg->base_rate)
50 return GNUNET_TIME_UNIT_ZERO;
51 cur_rate = tg->base_rate;
52 break;
53
54 case GNUNET_ATS_TEST_TG_LINEAR:
55 time_delta = GNUNET_TIME_absolute_get_duration (tg->time_start);
56 /* Calculate point of time in the current period */
57 time_delta.rel_value_us = time_delta.rel_value_us
58 % tg->duration_period.rel_value_us;
59 delta_rate = ((double) time_delta.rel_value_us
60 / tg->duration_period.rel_value_us)
61 * (tg->max_rate - tg->base_rate);
62 if ((tg->max_rate < tg->base_rate) && ((tg->max_rate - tg->base_rate) >
63 tg->base_rate))
47 { 64 {
48 case GNUNET_ATS_TEST_TG_CONSTANT: 65 /* This will cause an underflow */
49 if (UINT32_MAX == tg->base_rate) 66 GNUNET_break (0);
50 return GNUNET_TIME_UNIT_ZERO;
51 cur_rate = tg->base_rate;
52 break;
53
54 case GNUNET_ATS_TEST_TG_LINEAR:
55 time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start);
56 /* Calculate point of time in the current period */
57 time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us;
58 delta_rate = ((double)time_delta.rel_value_us / tg->duration_period.rel_value_us) *
59 (tg->max_rate - tg->base_rate);
60 if ((tg->max_rate < tg->base_rate) && ((tg->max_rate - tg->base_rate) > tg->base_rate))
61 {
62 /* This will cause an underflow */
63 GNUNET_break(0);
64 }
65 cur_rate = tg->base_rate + delta_rate;
66 break;
67
68 case GNUNET_ATS_TEST_TG_RANDOM:
69 cur_rate = tg->base_rate + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
70 tg->max_rate - tg->base_rate);
71 break;
72
73 case GNUNET_ATS_TEST_TG_SINUS:
74 time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start);
75 /* Calculate point of time in the current period */
76 time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us;
77 if ((tg->max_rate - tg->base_rate) > tg->base_rate)
78 {
79 /* This will cause an underflow for second half of sinus period,
80 * will be detected in general when experiments are loaded */
81 GNUNET_break(0);
82 }
83 delta_rate = (tg->max_rate - tg->base_rate) *
84 sin((2 * M_PI) / ((double)tg->duration_period.rel_value_us) * time_delta.rel_value_us);
85 cur_rate = tg->base_rate + delta_rate;
86 break;
87
88 default:
89 return delay;
90 break;
91 } 67 }
92 68 cur_rate = tg->base_rate + delta_rate;
93 if (cur_rate < 0) 69 break;
70
71 case GNUNET_ATS_TEST_TG_RANDOM:
72 cur_rate = tg->base_rate + GNUNET_CRYPTO_random_u32 (
73 GNUNET_CRYPTO_QUALITY_WEAK,
74 tg->max_rate
75 - tg->base_rate);
76 break;
77
78 case GNUNET_ATS_TEST_TG_SINUS:
79 time_delta = GNUNET_TIME_absolute_get_duration (tg->time_start);
80 /* Calculate point of time in the current period */
81 time_delta.rel_value_us = time_delta.rel_value_us
82 % tg->duration_period.rel_value_us;
83 if ((tg->max_rate - tg->base_rate) > tg->base_rate)
94 { 84 {
95 cur_rate = 1; 85 /* This will cause an underflow for second half of sinus period,
86 * will be detected in general when experiments are loaded */
87 GNUNET_break (0);
96 } 88 }
89 delta_rate = (tg->max_rate - tg->base_rate)
90 * sin ((2 * M_PI)
91 / ((double) tg->duration_period.rel_value_us)
92 * time_delta.rel_value_us);
93 cur_rate = tg->base_rate + delta_rate;
94 break;
95
96 default:
97 return delay;
98 break;
99 }
100
101 if (cur_rate < 0)
102 {
103 cur_rate = 1;
104 }
97 /* Calculate the delay for the next message based on the current delay */ 105 /* Calculate the delay for the next message based on the current delay */
98 delay.rel_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us * TEST_MESSAGE_SIZE / cur_rate; 106 delay.rel_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us
107 * TEST_MESSAGE_SIZE / cur_rate;
99 108
100 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
101 "Current rate is %lld, calculated delay is %llu\n", 110 "Current rate is %lld, calculated delay is %llu\n",
102 cur_rate, 111 cur_rate,
103 (unsigned long long)delay.rel_value_us); 112 (unsigned long long) delay.rel_value_us);
104 return delay; 113 return delay;
105} 114}
106 115
107 116
108static void 117static void
109update_ping_data(void *cls) 118update_ping_data (void *cls)
110{ 119{
111 struct BenchmarkPartner *p = cls; 120 struct BenchmarkPartner *p = cls;
112 struct GNUNET_TIME_Relative delay; 121 struct GNUNET_TIME_Relative delay;
@@ -117,49 +126,49 @@ update_ping_data(void *cls)
117 p->me->total_bytes_sent += TEST_MESSAGE_SIZE; 126 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
118 127
119 if (NULL == p->tg) 128 if (NULL == p->tg)
120 { 129 {
121 GNUNET_break(0); 130 GNUNET_break (0);
122 return; 131 return;
123 } 132 }
124 delay = get_delay(p->tg); 133 delay = get_delay (p->tg);
125 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
126 "Delay for next transmission %s\n", 135 "Delay for next transmission %s\n",
127 GNUNET_STRINGS_relative_time_to_string(delay, 136 GNUNET_STRINGS_relative_time_to_string (delay,
128 GNUNET_YES)); 137 GNUNET_YES));
129 p->tg->next_ping_transmission 138 p->tg->next_ping_transmission
130 = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), 139 = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
131 delay); 140 delay);
132} 141}
133 142
134 143
135static void 144static void
136comm_schedule_send(void *cls) 145comm_schedule_send (void *cls)
137{ 146{
138 struct BenchmarkPartner *p = cls; 147 struct BenchmarkPartner *p = cls;
139 struct TestMessage *msg; 148 struct TestMessage *msg;
140 struct GNUNET_MQ_Envelope *env; 149 struct GNUNET_MQ_Envelope *env;
141 150
142 p->tg->send_task = NULL; 151 p->tg->send_task = NULL;
143 p->last_message_sent = GNUNET_TIME_absolute_get(); 152 p->last_message_sent = GNUNET_TIME_absolute_get ();
144 env = GNUNET_MQ_msg(msg, 153 env = GNUNET_MQ_msg (msg,
145 TEST_MESSAGE_TYPE_PING); 154 TEST_MESSAGE_TYPE_PING);
146 memset(msg->padding, 155 memset (msg->padding,
147 'a', 156 'a',
148 sizeof(msg->padding)); 157 sizeof(msg->padding));
149 GNUNET_MQ_notify_sent(env, 158 GNUNET_MQ_notify_sent (env,
150 &update_ping_data, 159 &update_ping_data,
151 p); 160 p);
152 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "Master [%u]: Sending PING to [%u]\n", 162 "Master [%u]: Sending PING to [%u]\n",
154 p->me->no, 163 p->me->no,
155 p->dest->no); 164 p->dest->no);
156 GNUNET_MQ_send(p->mq, 165 GNUNET_MQ_send (p->mq,
157 env); 166 env);
158} 167}
159 168
160 169
161static void 170static void
162update_pong_data(void *cls) 171update_pong_data (void *cls)
163{ 172{
164 struct BenchmarkPartner *p = cls; 173 struct BenchmarkPartner *p = cls;
165 174
@@ -171,74 +180,79 @@ update_pong_data(void *cls)
171 180
172 181
173void 182void
174GNUNET_ATS_TEST_traffic_handle_ping(struct BenchmarkPartner *p) 183GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p)
175{ 184{
176 struct TestMessage *msg; 185 struct TestMessage *msg;
177 struct GNUNET_MQ_Envelope *env; 186 struct GNUNET_MQ_Envelope *env;
178 187
179 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
180 "Slave [%u]: Received PING from [%u], sending PONG\n", 189 "Slave [%u]: Received PING from [%u], sending PONG\n",
181 p->me->no, 190 p->me->no,
182 p->dest->no); 191 p->dest->no);
183 p->messages_received++; 192 p->messages_received++;
184 p->bytes_received += TEST_MESSAGE_SIZE; 193 p->bytes_received += TEST_MESSAGE_SIZE;
185 p->me->total_messages_received++; 194 p->me->total_messages_received++;
186 p->me->total_bytes_received += TEST_MESSAGE_SIZE; 195 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
187 196
188 197
189 env = GNUNET_MQ_msg(msg, 198 env = GNUNET_MQ_msg (msg,
190 TEST_MESSAGE_TYPE_PING); 199 TEST_MESSAGE_TYPE_PING);
191 memset(msg->padding, 200 memset (msg->padding,
192 'a', 201 'a',
193 sizeof(msg->padding)); 202 sizeof(msg->padding));
194 GNUNET_MQ_notify_sent(env, 203 GNUNET_MQ_notify_sent (env,
195 &update_pong_data, 204 &update_pong_data,
196 p); 205 p);
197 GNUNET_MQ_send(p->mq, 206 GNUNET_MQ_send (p->mq,
198 env); 207 env);
199} 208}
200 209
201 210
202void 211void
203GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p) 212GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p)
204{ 213{
205 struct GNUNET_TIME_Relative left; 214 struct GNUNET_TIME_Relative left;
206 215
207 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
208 "Master [%u]: Received PONG from [%u], next message\n", 217 "Master [%u]: Received PONG from [%u], next message\n",
209 p->me->no, 218 p->me->no,
210 p->dest->no); 219 p->dest->no);
211 220
212 p->messages_received++; 221 p->messages_received++;
213 p->bytes_received += TEST_MESSAGE_SIZE; 222 p->bytes_received += TEST_MESSAGE_SIZE;
214 p->me->total_messages_received++; 223 p->me->total_messages_received++;
215 p->me->total_bytes_received += TEST_MESSAGE_SIZE; 224 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
216 p->total_app_rtt += GNUNET_TIME_absolute_get_difference(p->last_message_sent, 225 p->total_app_rtt += GNUNET_TIME_absolute_get_difference (p->last_message_sent,
217 GNUNET_TIME_absolute_get()).rel_value_us; 226 GNUNET_TIME_absolute_get ())
227 .rel_value_us;
218 228
219 /* Schedule next send event */ 229 /* Schedule next send event */
220 if (NULL == p->tg) 230 if (NULL == p->tg)
221 return; 231 return;
222 232
223 left = GNUNET_TIME_absolute_get_remaining(p->tg->next_ping_transmission); 233 left = GNUNET_TIME_absolute_get_remaining (p->tg->next_ping_transmission);
224 if (UINT32_MAX == p->tg->base_rate) 234 if (UINT32_MAX == p->tg->base_rate)
225 { 235 {
226 p->tg->send_task = GNUNET_SCHEDULER_add_now(&comm_schedule_send, p); 236 p->tg->send_task = GNUNET_SCHEDULER_add_now (&comm_schedule_send, p);
227 } 237 }
228 else if (0 == left.rel_value_us) 238 else if (0 == left.rel_value_us)
229 { 239 {
230 p->tg->send_task = GNUNET_SCHEDULER_add_now(&comm_schedule_send, p); 240 p->tg->send_task = GNUNET_SCHEDULER_add_now (&comm_schedule_send, p);
231 } 241 }
232 else 242 else
233 { 243 {
234 /* Enforce minimum transmission rate 1 msg / sec */ 244 /* Enforce minimum transmission rate 1 msg / sec */
235 if (GNUNET_TIME_UNIT_SECONDS.rel_value_us == (left = GNUNET_TIME_relative_min(left, GNUNET_TIME_UNIT_SECONDS)).rel_value_us) 245 if (GNUNET_TIME_UNIT_SECONDS.rel_value_us == (left =
236 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 246 GNUNET_TIME_relative_min (
237 "Enforcing minimum send rate between master [%u] and slave [%u]\n", 247 left,
238 p->me->no, p->dest->no); 248 GNUNET_TIME_UNIT_SECONDS))
239 p->tg->send_task = GNUNET_SCHEDULER_add_delayed(left, 249 .rel_value_us)
240 &comm_schedule_send, p); 250 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
241 } 251 "Enforcing minimum send rate between master [%u] and slave [%u]\n",
252 p->me->no, p->dest->no);
253 p->tg->send_task = GNUNET_SCHEDULER_add_delayed (left,
254 &comm_schedule_send, p);
255 }
242} 256}
243 257
244 258
@@ -256,105 +270,105 @@ GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p)
256 * @return the traffic generator 270 * @return the traffic generator
257 */ 271 */
258struct TrafficGenerator * 272struct TrafficGenerator *
259GNUNET_ATS_TEST_generate_traffic_start(struct BenchmarkPeer *src, 273GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
260 struct BenchmarkPartner *dest, 274 struct BenchmarkPartner *dest,
261 enum GeneratorType type, 275 enum GeneratorType type,
262 unsigned int base_rate, 276 unsigned int base_rate,
263 unsigned int max_rate, 277 unsigned int max_rate,
264 struct GNUNET_TIME_Relative period, 278 struct GNUNET_TIME_Relative period,
265 struct GNUNET_TIME_Relative duration) 279 struct GNUNET_TIME_Relative duration)
266{ 280{
267 struct TrafficGenerator *tg; 281 struct TrafficGenerator *tg;
268 282
269 if (NULL != dest->tg) 283 if (NULL != dest->tg)
270 { 284 {
271 GNUNET_break(0); 285 GNUNET_break (0);
272 return NULL; 286 return NULL;
273 } 287 }
274 288
275 tg = GNUNET_new(struct TrafficGenerator); 289 tg = GNUNET_new (struct TrafficGenerator);
276 GNUNET_CONTAINER_DLL_insert(tg_head, 290 GNUNET_CONTAINER_DLL_insert (tg_head,
277 tg_tail, 291 tg_tail,
278 tg); 292 tg);
279 tg->type = type; 293 tg->type = type;
280 tg->src = src; 294 tg->src = src;
281 tg->dest = dest; 295 tg->dest = dest;
282 tg->base_rate = base_rate; 296 tg->base_rate = base_rate;
283 tg->max_rate = max_rate; 297 tg->max_rate = max_rate;
284 tg->duration_period = period; 298 tg->duration_period = period;
285 tg->time_start = GNUNET_TIME_absolute_get(); 299 tg->time_start = GNUNET_TIME_absolute_get ();
286 tg->next_ping_transmission = GNUNET_TIME_UNIT_FOREVER_ABS; 300 tg->next_ping_transmission = GNUNET_TIME_UNIT_FOREVER_ABS;
287 301
288 switch (type) 302 switch (type)
289 { 303 {
290 case GNUNET_ATS_TEST_TG_CONSTANT: 304 case GNUNET_ATS_TEST_TG_CONSTANT:
291 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 305 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
292 "Setting up constant traffic generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n", 306 "Setting up constant traffic generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
293 dest->me->no, 307 dest->me->no,
294 GNUNET_i2s(&dest->me->id), 308 GNUNET_i2s (&dest->me->id),
295 dest->dest->no, 309 dest->dest->no,
296 GNUNET_i2s(&dest->dest->id), 310 GNUNET_i2s (&dest->dest->id),
297 base_rate); 311 base_rate);
298 break; 312 break;
299 313
300 case GNUNET_ATS_TEST_TG_LINEAR: 314 case GNUNET_ATS_TEST_TG_LINEAR:
301 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 315 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
302 "Setting up linear traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n", 316 "Setting up linear traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
303 dest->me->no, 317 dest->me->no,
304 GNUNET_i2s(&dest->me->id), 318 GNUNET_i2s (&dest->me->id),
305 dest->dest->no, 319 dest->dest->no,
306 GNUNET_i2s(&dest->dest->id), 320 GNUNET_i2s (&dest->dest->id),
307 base_rate, 321 base_rate,
308 max_rate); 322 max_rate);
309 break; 323 break;
310 324
311 case GNUNET_ATS_TEST_TG_SINUS: 325 case GNUNET_ATS_TEST_TG_SINUS:
312 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 326 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
313 "Setting up sinus traffic generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n", 327 "Setting up sinus traffic generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
314 dest->me->no, 328 dest->me->no,
315 GNUNET_i2s(&dest->me->id), 329 GNUNET_i2s (&dest->me->id),
316 dest->dest->no, 330 dest->dest->no,
317 GNUNET_i2s(&dest->dest->id), 331 GNUNET_i2s (&dest->dest->id),
318 base_rate, 332 base_rate,
319 max_rate); 333 max_rate);
320 break; 334 break;
321 335
322 case GNUNET_ATS_TEST_TG_RANDOM: 336 case GNUNET_ATS_TEST_TG_RANDOM:
323 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 337 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
324 "Setting up random traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n", 338 "Setting up random traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
325 dest->me->no, 339 dest->me->no,
326 GNUNET_i2s(&dest->me->id), 340 GNUNET_i2s (&dest->me->id),
327 dest->dest->no, 341 dest->dest->no,
328 GNUNET_i2s(&dest->dest->id), 342 GNUNET_i2s (&dest->dest->id),
329 base_rate, 343 base_rate,
330 max_rate); 344 max_rate);
331 break; 345 break;
332 346
333 default: 347 default:
334 break; 348 break;
335 } 349 }
336 350
337 dest->tg = tg; 351 dest->tg = tg;
338 tg->send_task 352 tg->send_task
339 = GNUNET_SCHEDULER_add_now(&comm_schedule_send, 353 = GNUNET_SCHEDULER_add_now (&comm_schedule_send,
340 dest); 354 dest);
341 return tg; 355 return tg;
342} 356}
343 357
344 358
345void 359void
346GNUNET_ATS_TEST_generate_traffic_stop(struct TrafficGenerator *tg) 360GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg)
347{ 361{
348 GNUNET_CONTAINER_DLL_remove(tg_head, 362 GNUNET_CONTAINER_DLL_remove (tg_head,
349 tg_tail, 363 tg_tail,
350 tg); 364 tg);
351 tg->dest->tg = NULL; 365 tg->dest->tg = NULL;
352 if (NULL != tg->send_task) 366 if (NULL != tg->send_task)
353 { 367 {
354 GNUNET_SCHEDULER_cancel(tg->send_task); 368 GNUNET_SCHEDULER_cancel (tg->send_task);
355 tg->send_task = NULL; 369 tg->send_task = NULL;
356 } 370 }
357 GNUNET_free(tg); 371 GNUNET_free (tg);
358} 372}
359 373
360 374
@@ -362,17 +376,17 @@ GNUNET_ATS_TEST_generate_traffic_stop(struct TrafficGenerator *tg)
362 * Stop all traffic generators 376 * Stop all traffic generators
363 */ 377 */
364void 378void
365GNUNET_ATS_TEST_generate_traffic_stop_all() 379GNUNET_ATS_TEST_generate_traffic_stop_all ()
366{ 380{
367 struct TrafficGenerator *cur; 381 struct TrafficGenerator *cur;
368 struct TrafficGenerator *next; 382 struct TrafficGenerator *next;
369 383
370 next = tg_head; 384 next = tg_head;
371 for (cur = next; NULL != cur; cur = next) 385 for (cur = next; NULL != cur; cur = next)
372 { 386 {
373 next = cur->next; 387 next = cur->next;
374 GNUNET_ATS_TEST_generate_traffic_stop(cur); 388 GNUNET_ATS_TEST_generate_traffic_stop (cur);
375 } 389 }
376} 390}
377 391
378/* end of file ats-testing-traffic.c */ 392/* end of file ats-testing-traffic.c */