additional check for sinus generator
authorMatthias Wachs <wachs@net.in.tum.de>
Mon, 3 Feb 2014 09:10:13 +0000 (09:10 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Mon, 3 Feb 2014 09:10:13 +0000 (09:10 +0000)
src/ats-tests/ats-testing-traffic.c

index 67f85eb3ceeed55b1a0fe364936dee38a6d18838..1bd31cc269df51c0b3fcde566d2c2f6d47318c67 100644 (file)
@@ -52,7 +52,9 @@ get_delay (struct TrafficGenerator *tg)
       break;
     case GNUNET_ATS_TEST_TG_LINEAR:
       time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start);
+      /* Calculate point of time in the current period */
       time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us;
+
       delta_rate = ((double) time_delta.rel_value_us  / tg->duration_period.rel_value_us) *
           (tg->max_rate - tg->base_rate);
       cur_rate = tg->base_rate + delta_rate;
@@ -63,7 +65,14 @@ get_delay (struct TrafficGenerator *tg)
       break;
     case GNUNET_ATS_TEST_TG_SINUS:
       time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start);
+      /* Calculate point of time in the current period */
       time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us;
+      if ((tg->max_rate - tg->base_rate) < tg->base_rate)
+      {
+        /* This will cause an underflow for second half of sinus period,
+         * will be detected in general when experiments are loaded */
+        GNUNET_break (0);
+      }
       delta_rate = (tg->max_rate - tg->base_rate) *
           sin ( (2 * M_PI) / ((double) tg->duration_period.rel_value_us) * time_delta.rel_value_us);
       cur_rate = tg->base_rate + delta_rate;