aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tests/ats-testing-traffic.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-02-03 09:58:18 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-02-03 09:58:18 +0000
commitc25e21e16f0079b94b4ee71240013e16b425240d (patch)
treecceded3c132bd620c4b8ae3c8532e6a8fcc889cd /src/ats-tests/ats-testing-traffic.c
parent2debb60e6a2c3cafab0c9095944d316672a8b4a0 (diff)
downloadgnunet-c25e21e16f0079b94b4ee71240013e16b425240d.tar.gz
gnunet-c25e21e16f0079b94b4ee71240013e16b425240d.zip
safety checks
Diffstat (limited to 'src/ats-tests/ats-testing-traffic.c')
-rw-r--r--src/ats-tests/ats-testing-traffic.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/ats-tests/ats-testing-traffic.c b/src/ats-tests/ats-testing-traffic.c
index 1bd31cc26..0938f79f4 100644
--- a/src/ats-tests/ats-testing-traffic.c
+++ b/src/ats-tests/ats-testing-traffic.c
@@ -54,9 +54,13 @@ get_delay (struct TrafficGenerator *tg)
54 time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start); 54 time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start);
55 /* Calculate point of time in the current period */ 55 /* Calculate point of time in the current period */
56 time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us; 56 time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us;
57
58 delta_rate = ((double) time_delta.rel_value_us / tg->duration_period.rel_value_us) * 57 delta_rate = ((double) time_delta.rel_value_us / tg->duration_period.rel_value_us) *
59 (tg->max_rate - tg->base_rate); 58 (tg->max_rate - tg->base_rate);
59 if ((tg->max_rate - tg->base_rate) > tg->base_rate)
60 {
61 /* This will cause an underflow */
62 GNUNET_break (0);
63 }
60 cur_rate = tg->base_rate + delta_rate; 64 cur_rate = tg->base_rate + delta_rate;
61 break; 65 break;
62 case GNUNET_ATS_TEST_TG_RANDOM: 66 case GNUNET_ATS_TEST_TG_RANDOM:
@@ -67,7 +71,7 @@ get_delay (struct TrafficGenerator *tg)
67 time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start); 71 time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start);
68 /* Calculate point of time in the current period */ 72 /* Calculate point of time in the current period */
69 time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us; 73 time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us;
70 if ((tg->max_rate - tg->base_rate) < tg->base_rate) 74 if ((tg->max_rate - tg->base_rate) > tg->base_rate)
71 { 75 {
72 /* This will cause an underflow for second half of sinus period, 76 /* This will cause an underflow for second half of sinus period,
73 * will be detected in general when experiments are loaded */ 77 * will be detected in general when experiments are loaded */
@@ -82,6 +86,11 @@ get_delay (struct TrafficGenerator *tg)
82 break; 86 break;
83 } 87 }
84 88
89 if (cur_rate < 0)
90 {
91 cur_rate = 0;
92 }
93
85 /* Calculate the delay for the next message based on the current delay */ 94 /* Calculate the delay for the next message based on the current delay */
86 delay.rel_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us * TEST_MESSAGE_SIZE / cur_rate; 95 delay.rel_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us * TEST_MESSAGE_SIZE / cur_rate;
87 96