gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r30816 - gnunet/src/ats


From: gnunet
Subject: [GNUnet-SVN] r30816 - gnunet/src/ats
Date: Tue, 19 Nov 2013 17:42:03 +0100

Author: wachs
Date: 2013-11-19 17:42:03 +0100 (Tue, 19 Nov 2013)
New Revision: 30816

Modified:
   gnunet/src/ats/gnunet-service-ats_addresses.c
   gnunet/src/ats/gnunet-service-ats_normalization.c
   gnunet/src/ats/gnunet-service-ats_normalization.h
   gnunet/src/ats/test_ats_solver_preferences.c
Log:
evaluation


Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c       2013-11-19 16:38:25 UTC 
(rev 30815)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c       2013-11-19 16:42:03 UTC 
(rev 30816)
@@ -1342,6 +1342,7 @@
     return GNUNET_YES;
 }
 
+
 /**
  * Summary context
  */
@@ -1401,34 +1402,21 @@
   struct GAS_Addresses_Handle *ah;
 };
 
-#if 0
 static int
-eval_preference_relativity (void *cls, const struct GNUNET_PeerIdentity *id, 
void *obj)
+find_active_address (void *cls, const struct GNUNET_PeerIdentity *id, void 
*obj)
 {
-  struct RelativityContext *rc = cls;
+  struct ATS_Address **res = cls;
   struct ATS_Address *addr = obj;
-  int prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceType ;
-  int c;
-  const double *preferences;
 
   if (GNUNET_YES == addr->active)
-  {
-    preferences = get_preferences_cb (rc->ah->env.get_preference_cls, id);
-    for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
-    {
-      if (prefs[c] == GNUNET_ATS_PREFERENCE_END)
-        continue;
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preference for peer `%s' type %s: 
%f\n",
-          GNUNET_i2s (id), GNUNET_ATS_print_preference_type(prefs[c]),
-          preferences[c]);
-    }
-  }
+    (*res) = addr;
 
-  return GNUNET_OK;
+  if (NULL != (*res))
+    return GNUNET_NO;
+  else
+    return GNUNET_YES;
 }
-#endif
 
-
 /**
  * Evaluate current bandwidth assignment
  *
@@ -1458,11 +1446,17 @@
 
   /* Variable related to utilization */
   struct SummaryContext sum;
+  struct ATS_Address *active_address;
   int network_count;
 
   /* Variables for preferences */
   int prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceType;
   double pref_val;
+  double prop_val;
+  const double *norm_values;
+  double prefs_fulfill[GNUNET_ATS_PreferenceCount];
+  int prefs_clients[GNUNET_ATS_PreferenceCount];
+  int rels;
 
   GNUNET_assert (NULL != ah);
   GNUNET_assert (NULL != ah->addresses);
@@ -1540,25 +1534,80 @@
   }
   else
   {
-    for (pcur = ah->preference_clients_head; NULL != pcur; pcur = pcur->next)
+    for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
     {
-      /* V metrics*/
-      for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
+      prefs_fulfill[c] = 0.0;
+      prefs_clients[c] = 0;
+    }
+
+    for (cur = ah->pending_requests_head; NULL != cur; cur = cur->next)
+    {
+      active_address = NULL;
+      GNUNET_CONTAINER_multipeermap_get_multiple (ah->addresses,
+          &cur->id, &find_active_address, &active_address);
+
+      for (pcur = ah->preference_clients_head; NULL != pcur; pcur = pcur->next)
       {
+        for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
+        {
+          if (prefs[c] == GNUNET_ATS_PREFERENCE_END)
+            continue;
+          pref_val = -1.0;
+          pref_val = GAS_normalization_get_preferences_by_client 
(pcur->client, &cur->id, prefs[c]);
+          if (-1.0 == pref_val)
+          {
+            GNUNET_break (0);
+            continue;
+          }
 
-        if (prefs[c] == GNUNET_ATS_PREFERENCE_END)
-          continue;
-        pref_val = -1.0;
-        pref_val = GAS_normalization_get_preferences_by_client (pcur->client, 
prefs[c]);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "normalized pref for client %p == 
%.3f\n",
-            pcur->client, pref_val);
-        if (-1.0 == pref_val)
-        {
-          GNUNET_break (0);
-          continue;
+          if (DEFAULT_REL_PREFERENCE == pref_val)
+          {
+            /* Default preference value */
+            continue;
+          }
+
+          if (NULL != active_address)
+          {
+            norm_values = GAS_normalization_get_properties (active_address);
+            prop_val = norm_values[c];
+            if ((norm_values[c] <= 1.0) || (norm_values[c] >= 2.0))
+                prop_val = DEFAULT_REL_QUALITY;
+          }
+          else
+          {
+            prop_val = DEFAULT_REL_QUALITY;
+          }
+
+          /* We now have preference values [1..2] and properties [1..2] */
+
+          GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u Client %p, Peer %s Property 
%s: pref: %.3f prop %.3f \n",
+              c,
+              pcur->client,
+              GNUNET_i2s (&cur->id),
+              GNUNET_ATS_print_preference_type(prefs[c]),
+              pref_val,
+              prop_val);
+
+          prefs_fulfill[c] += (pref_val * prop_val) / 2;
+          prefs_clients[c] ++;
         }
       }
     }
+    rels = 0;
+    for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
+    {
+      if (0 < prefs_clients[c])
+      {
+        prefs_fulfill[c] /= prefs_clients[c];
+        rels ++;
+        quality_application_requirements += prefs_fulfill[c];
+      }
+    }
+    if (rels > 0)
+      quality_application_requirements /= rels;
+    else
+      quality_application_requirements = 0.0;
+
     include_requirements = GNUNET_YES;
   }
   /* GUQ */

Modified: gnunet/src/ats/gnunet-service-ats_normalization.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_normalization.c   2013-11-19 16:38:25 UTC 
(rev 30815)
+++ gnunet/src/ats/gnunet-service-ats_normalization.c   2013-11-19 16:42:03 UTC 
(rev 30816)
@@ -220,9 +220,7 @@
       "%u clients have a total relative preference for peer `%s''s `%s' of 
%.3f\n",
       count, GNUNET_i2s (id), GNUNET_ATS_print_preference_type (kind),
       f_rel_total);
-  if (NULL
-      != (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers,
-                                                 id)))
+  if (NULL != (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, id)))
   {
     backup = rp->f_rel[kind];
     if (0 < count)
@@ -330,7 +328,7 @@
   case GNUNET_ATS_PREFERENCE_BANDWIDTH:
   case GNUNET_ATS_PREFERENCE_LATENCY:
     p->f_abs[kind] = (p->f_abs[kind] + score) / 2;
-    p->next_aging[kind] = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
+    p->next_aging[kind] = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get 
(),
         PREF_AGING_INTERVAL);
     break;
   case GNUNET_ATS_PREFERENCE_END:
@@ -367,24 +365,26 @@
       /* Aging absolute values: */
       for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
       {
-        if (0 == 
GNUNET_TIME_absolute_get_remaining(p->next_aging[i]).rel_value_us)
+        if (0
+            == GNUNET_TIME_absolute_get_remaining 
(p->next_aging[i]).rel_value_us)
         {
-          GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Aging preference for peer 
`%s'\n",
-              GNUNET_i2s (&p->id));
+          GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+              "Aging preference for peer `%s'\n", GNUNET_i2s (&p->id));
           backup = p->f_abs[i];
           if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE)
             p->f_abs[i] *= PREF_AGING_FACTOR;
           if (p->f_abs[i] <= DEFAULT_ABS_PREFERENCE + PREF_EPSILON)
             p->f_abs[i] = DEFAULT_ABS_PREFERENCE;
-          if ((p->f_abs[i] != DEFAULT_ABS_PREFERENCE) && (backup != 
p->f_abs[i]))
+          if ((p->f_abs[i] != DEFAULT_ABS_PREFERENCE)
+              && (backup != p->f_abs[i]))
           {
             GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
                 "Aged preference for peer `%s' from %.3f to %.3f\n",
                 GNUNET_i2s (&p->id), backup, p->f_abs[i]);
             recalculate_rel_preferences (p->client, p, i);
-            p->next_aging[i] = 
GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
-                PREF_AGING_INTERVAL);
-            values_to_update ++;
+            p->next_aging[i] = GNUNET_TIME_absolute_add (
+                GNUNET_TIME_absolute_get (), PREF_AGING_INTERVAL);
+            values_to_update++;
           }
         }
       }
@@ -393,18 +393,18 @@
 
   if (values_to_update > 0)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-        "Rescheduling aging task due to %u elements to age\n", 
values_to_update);
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+        "Rescheduling aging task due to %u elements to age\n",
+        values_to_update);
     aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
-        &preference_aging, NULL);
+        &preference_aging, NULL );
   }
   else
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
         "No values to age left, not rescheduling aging task\n");
 
 }
 
-
 /**
  * Normalize an updated preference value
  *
@@ -415,8 +415,7 @@
  */
 void
 GAS_normalization_normalize_preference (void *src,
-    const struct GNUNET_PeerIdentity *peer,
-    enum GNUNET_ATS_PreferenceKind kind,
+    const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind 
kind,
     float score_abs)
 {
   struct PreferenceClient *c_cur;
@@ -448,9 +447,8 @@
   {
     c_cur = GNUNET_malloc (sizeof (struct PreferenceClient));
     c_cur->client = src;
-    GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, c_cur);
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-        "Adding new client %p \n", c_cur);
+    GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, c_cur);
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding new client %p \n", c_cur);
   }
 
   /* Find entry for peer */
@@ -476,20 +474,19 @@
     GNUNET_CONTAINER_DLL_insert(c_cur->p_head, c_cur->p_tail, p_cur);
   }
 
-  if (NULL == GNUNET_CONTAINER_multipeermap_get (preference_peers,
-                                                peer))
+  if (NULL == GNUNET_CONTAINER_multipeermap_get (preference_peers, peer))
   {
     r_cur = GNUNET_malloc (sizeof (struct PeerRelative));
     r_cur->id = (*peer);
     for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
       r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
-    GNUNET_CONTAINER_multipeermap_put (preference_peers, &r_cur->id,
-        r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+    GNUNET_CONTAINER_multipeermap_put (preference_peers, &r_cur->id, r_cur,
+        GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
   }
 
   if (GNUNET_SCHEDULER_NO_TASK == aging_task)
     aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
-        &preference_aging, NULL);
+        &preference_aging, NULL );
 
   update_preference (c_cur, p_cur, kind, score_abs);
 }
@@ -509,9 +506,7 @@
   GNUNET_assert(NULL != id);
 
   struct PeerRelative *rp;
-  if (NULL
-      == (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers,
-                                                 id)))
+  if (NULL == (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, id)))
   {
     return defvalues.f_rel;
   }
@@ -519,17 +514,19 @@
 }
 
 /**
- * Get the normalized preference values for a specific peer or
- * the default values if
+ * Get the normalized preference values for a specific client and peer
  *
  * @param id the peer
- * @return pointer to the values, can be indexed with 
GNUNET_ATS_PreferenceKind,
- * default preferences if peer does not exist
+ * @param the peer
+ * @return the value
  */
 const double
-GAS_normalization_get_preferences_by_client (const void *client, enum 
GNUNET_ATS_PreferenceKind pref)
+GAS_normalization_get_preferences_by_client (const void *client,
+    struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind pref)
 {
   struct PreferenceClient *c_cur;
+  struct PreferencePeer *p_cur;
+
   /* Find preference client */
   for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
   {
@@ -537,9 +534,17 @@
       break;
   }
   if (NULL == c_cur)
-    return -1;
+    return -1.0;
 
-  return 1.0;
+  for (p_cur = c_cur->p_head; NULL != p_cur; p_cur = p_cur->next)
+  {
+    if (0 == memcmp (peer, &p_cur->id, sizeof (struct GNUNET_PeerIdentity)))
+      break;
+  }
+  if (NULL == p_cur)
+    return DEFAULT_REL_PREFERENCE; /* Not found, return default */
+
+  return p_cur->f_rel[pref];
 }
 
 /**
@@ -651,7 +656,6 @@
   return res;
 }
 
-
 struct FindMinMaxCtx
 {
   struct Property *p;
@@ -659,11 +663,8 @@
   uint32_t max;
 };
 
-
 static int
-find_min_max_it (void *cls,
-                const struct GNUNET_PeerIdentity *h,
-                void *k)
+find_min_max_it (void *cls, const struct GNUNET_PeerIdentity *h, void *k)
 {
   struct FindMinMaxCtx *find_res = cls;
   struct ATS_Address *a = k;
@@ -677,11 +678,8 @@
   return GNUNET_OK;
 }
 
-
 static int
-normalize_address (void *cls,
-                  const struct GNUNET_PeerIdentity *h,
-                  void *k)
+normalize_address (void *cls, const struct GNUNET_PeerIdentity *h, void *k)
 {
   struct Property *p = cls;
   struct ATS_Address *address = k;
@@ -706,7 +704,6 @@
   return GNUNET_OK;
 }
 
-
 /**
  * Normalize avg_value to a range of values between [1.0, 2.0]
  * based on min max values currently known.
@@ -718,9 +715,7 @@
  */
 static void
 property_normalize (struct GNUNET_CONTAINER_MultiPeerMap *addresses,
-                   struct Property *p,
-                   struct ATS_Address *address,
-                   uint32_t avg_value)
+    struct Property *p, struct ATS_Address *address, uint32_t avg_value)
 {
   struct FindMinMaxCtx find_ctx;
   int addr_count;
@@ -730,7 +725,7 @@
   find_ctx.max = 0;
   find_ctx.min = UINT32_MAX;
   addr_count = GNUNET_CONTAINER_multipeermap_iterate (addresses,
-                                                     &find_min_max_it, 
&find_ctx);
+      &find_min_max_it, &find_ctx);
   if (0 == addr_count)
   {
     GNUNET_break(0);
@@ -786,10 +781,10 @@
  * @param atsi_count the number of atsi information in the array
  */
 void
-GAS_normalization_normalize_property (struct GNUNET_CONTAINER_MultiPeerMap 
*addresses,
-                                     struct ATS_Address *address,
-                                     const struct GNUNET_ATS_Information *atsi,
-                                     uint32_t atsi_count)
+GAS_normalization_normalize_property (
+    struct GNUNET_CONTAINER_MultiPeerMap *addresses,
+    struct ATS_Address *address, const struct GNUNET_ATS_Information *atsi,
+    uint32_t atsi_count)
 {
   struct Property *cur_prop;
   int c1;
@@ -834,7 +829,6 @@
   }
 }
 
-
 static void
 free_client (struct PreferenceClient *pc)
 {
@@ -850,7 +844,6 @@
   GNUNET_free(pc);
 }
 
-
 /**
  * A performance client disconnected
  *
@@ -871,11 +864,10 @@
   if (NULL == c_cur)
     return;
 
-  GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, c_cur);
+  GNUNET_CONTAINER_DLL_remove(pc_head, pc_tail, c_cur);
   free_client (c_cur);
 }
 
-
 /**
  * Start the normalization component
  *
@@ -917,7 +909,6 @@
   return;
 }
 
-
 /**
  * Free a peer
  *

Modified: gnunet/src/ats/gnunet-service-ats_normalization.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_normalization.h   2013-11-19 16:38:25 UTC 
(rev 30815)
+++ gnunet/src/ats/gnunet-service-ats_normalization.h   2013-11-19 16:42:03 UTC 
(rev 30816)
@@ -71,15 +71,15 @@
 
 
 /**
- * Get the normalized preference values for a specific client
+ * Get the normalized preference values for a specific client and peer
  *
- * @param client the client
- * @param pref desired pref value
- * @return normalized value
+ * @param id the peer
+ * @param the peer
+ * @return the value
  */
 const double
 GAS_normalization_get_preferences_by_client (const void *client,
-    enum GNUNET_ATS_PreferenceKind pref);
+    struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind pref);
 
 /**
  * Normalize an updated preference value

Modified: gnunet/src/ats/test_ats_solver_preferences.c
===================================================================
--- gnunet/src/ats/test_ats_solver_preferences.c        2013-11-19 16:38:25 UTC 
(rev 30815)
+++ gnunet/src/ats/test_ats_solver_preferences.c        2013-11-19 16:42:03 UTC 
(rev 30816)
@@ -83,7 +83,7 @@
 /**
  * Test ats info
  */
-struct GNUNET_ATS_Information test_ats_info[2];
+struct GNUNET_ATS_Information test_ats_info[3];
 
 /**
  * Test ats count
@@ -157,15 +157,13 @@
 {
   int c;
   double pref_val;
-  int prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceType;
-
   if (NULL == perf_ats)
     return;
   for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
   {
     pref_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
     GNUNET_ATS_performance_change_preference (perf_ats,
-        &test_hello_address.peer, prefs[c], pref_val,
+        &test_hello_address.peer, GNUNET_ATS_PREFERENCE_LATENCY, pref_val,
         GNUNET_ATS_PREFERENCE_END);
   }
 }
@@ -235,7 +233,9 @@
   test_ats_info[0].value = htonl (GNUNET_ATS_NET_WAN);
   test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
   test_ats_info[1].value = htonl (1);
-  test_ats_count = 2;
+  test_ats_info[2].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
+  test_ats_info[2].value = htonl (100);
+  test_ats_count = 3;
 
   /* Adding address without session */
   test_session = NULL;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]