document options provided
[oweals/gnunet.git] / src / ats / test_ats_simplistic_pref_aging.c
index 9eb896ff57e452e52983cebcde36ed729aa7bc81..0dc89d8ba4690e3a0d88b785fcfe75a7400c2f02 100644 (file)
@@ -26,7 +26,7 @@
  */
 /**
  * @file ats/test_ats_api_scheduling_add_address.c
- * @brief test for ats simplistic solver preference aging:
+ * @brief test for ats proportional solver preference aging:
  *     Add 2 addresses and set high preference for one. Expect higher bw for this
  *     address, wait. Preferences should age and so bw assigned should decrease.
  * @author Christian Grothoff
@@ -103,7 +103,7 @@ static void
 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   die_task = GNUNET_SCHEDULER_NO_TASK;
-
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error! Shutting down\n");
   if (sched_ats != NULL)
   {
     GNUNET_ATS_scheduling_done (sched_ats);
@@ -169,7 +169,7 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
                /* Callback for initial suggestion */
                if (0 == memcmp (&address->peer, &p[0].id, sizeof (p[0].id)))
                {
-                               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage %u: Callback for peer 0 `%s': (in/out) %llu/%llu\n",
+                               GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stage %u: Callback for peer 0 `%s': (in/out) %llu/%llu\n",
                                                stage,
                                                GNUNET_i2s (&address->peer),
                                                ntohl (bandwidth_in.value__),
@@ -180,7 +180,7 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
                }
                if (0 == memcmp (&address->peer, &p[1].id, sizeof (p[1].id)))
                {
-                               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage %u: Callback for peer 1 `%s': (in/out) %llu/%llu\n",
+                               GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stage %u: Callback for peer 1 `%s': (in/out) %llu/%llu\n",
                                                stage,
                                                GNUNET_i2s (&address->peer),
                                                ntohl (bandwidth_in.value__),
@@ -193,7 +193,7 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
                {
                  /* Changing preference for peer 0 */
                        stage ++;
-                       GNUNET_ATS_change_preference (perf_ats, &p[0].id, GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END);
+                       GNUNET_ATS_performance_change_preference (perf_ats, &p[0].id, GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END);
                                sug_p0 = GNUNET_NO;
                                sug_p1 = GNUNET_NO;
                        return;
@@ -205,7 +205,7 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
                /* Callback due to preference change */
                if (0 == memcmp (&address->peer, &p[0].id, sizeof (p[0].id)))
                {
-                               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage %u: Callback for peer 0 `%s': (in/out) %llu/%llu\n",
+                               GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stage %u: Callback for peer 0 `%s': (in/out) %llu/%llu\n",
                                                stage,
                                                GNUNET_i2s (&address->peer),
                                                ntohl (bandwidth_in.value__),
@@ -222,7 +222,7 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
                }
                if (0 == memcmp (&address->peer, &p[1].id, sizeof (p[1].id)))
                {
-                               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage %u: Callback for peer 1 `%s': (in/out) %llu/%llu\n",
+                               GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stage %u: Callback for peer 1 `%s': (in/out) %llu/%llu\n",
                                                stage,
                                                GNUNET_i2s (&address->peer),
                                                ntohl (bandwidth_in.value__),
@@ -231,9 +231,15 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
 
                                /* Peer 1 should get less bandwidth */
                                if (cur_bandwidth_out >= p1_last_bandwidth_out)
+                               {
                                        GNUNET_break (0);
+                                       goto error;
+                               }
                                if (cur_bandwidth_in >= p1_last_bandwidth_in)
+                               {
                                        GNUNET_break (0);
+                                       goto error;
+                               }
                                p1_last_bandwidth_out = ntohl(bandwidth_out.value__);
                                p1_last_bandwidth_in = ntohl(bandwidth_in.value__);
                }
@@ -250,7 +256,7 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
                /* Callback due to preference aging */
                if (0 == memcmp (&address->peer, &p[0].id, sizeof (p[0].id)))
                {
-                               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage %u: Callback for peer 0 `%s': (in/out) %llu/%llu\n",
+                               GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stage %u: Callback for peer 0 `%s': (in/out) %llu/%llu\n",
                                                stage,
                                                GNUNET_i2s (&address->peer),
                                                ntohl (bandwidth_in.value__),
@@ -267,7 +273,7 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
                }
                if (0 == memcmp (&address->peer, &p[1].id, sizeof (p[1].id)))
                {
-                               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage %u: Callback for peer 1 `%s': (in/out) %llu/%llu\n",
+                               GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stage %u: Callback for peer 1 `%s': (in/out) %llu/%llu\n",
                                                stage,
                                                GNUNET_i2s (&address->peer),
                                                ntohl (bandwidth_in.value__),
@@ -275,17 +281,36 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
                                sug_p1 = GNUNET_YES;
                                /* Peer 1 should get more bandwidth */
                                if (cur_bandwidth_out <= p1_last_bandwidth_out)
+                               {
                                        GNUNET_break (0);
+                                       goto error;
+                               }
                                if (cur_bandwidth_in <= p1_last_bandwidth_in)
+                               {
                                        GNUNET_break (0);
+                                       goto error;
+                               }
                                p0_last_bandwidth_out = ntohl(bandwidth_out.value__);
                                p0_last_bandwidth_in = ntohl(bandwidth_in.value__);
                }
 
-               /* Done ! */
-      GNUNET_SCHEDULER_add_now (&end,NULL);
-      return;
+               if ((GNUNET_YES == sug_p0) && (GNUNET_YES == sug_p1))
+               {
+                       /* Done ! */
+                       GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n");
+                       stage ++;
+                       ret = 0;
+        GNUNET_SCHEDULER_add_now (&end,NULL);
+                       return;
+               }
   }
+  return;
+
+error:
+       /* Error ! */
+       ret = 1;
+       GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Error!\n");
+       GNUNET_SCHEDULER_add_now (&end,NULL);
 }
 
 static void
@@ -414,7 +439,7 @@ run (void *cls,
 int
 main (int argc, char *argv[])
 {
-  if (0 != GNUNET_TESTING_peer_run ("test_ats_simplistic_pref_aging",
+  if (0 != GNUNET_TESTING_peer_run ("test_ats_proportional_pref_aging",
                                     "test_ats_api.conf",
                                     &run, NULL))
     return 1;