gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r26735 - in gnunet/src: ats include


From: gnunet
Subject: [GNUnet-SVN] r26735 - in gnunet/src: ats include
Date: Wed, 3 Apr 2013 14:22:22 +0200

Author: wachs
Date: 2013-04-03 14:22:22 +0200 (Wed, 03 Apr 2013)
New Revision: 26735

Modified:
   gnunet/src/ats/gnunet-service-ats_addresses.c
   gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
   gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c
   gnunet/src/ats/test_ats_mlp_update.c
   gnunet/src/include/gnunet_ats_service.h
Log:
ats change, done


Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c       2013-04-03 12:17:03 UTC 
(rev 26734)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c       2013-04-03 12:22:22 UTC 
(rev 26735)
@@ -419,7 +419,7 @@
                for (c1 = 0; c1 < update_count; c1 ++)
                {
                        (*delta_dest)[c1].type = update[c1].type;
-                       (*delta_dest)[c1].value = htonl(UINT32_MAX);
+                       (*delta_dest)[c1].value = 
htonl(GNUNET_ATS_VALUE_UNDEFINED);
                }
                (*delta_count) = update_count;
                return GNUNET_YES;
@@ -451,7 +451,7 @@
                                add_atsi[add_atsi_count] = update[c1];
                                add_atsi_count ++;
                                delta_atsi[delta_atsi_count].type = 
update[c1].type;
-                               delta_atsi[delta_atsi_count].type = htonl 
(UINT32_MAX);
+                               delta_atsi[delta_atsi_count].value = htonl 
(GNUNET_ATS_VALUE_UNDEFINED);
                                delta_atsi_count ++;
                }
   }
@@ -717,7 +717,7 @@
  *
  * @param address the address
  * @param type the type to extract in HBO
- * @return the value in HBO or UINT32_MAX in HBO if value does not exist
+ * @return the value in HBO or GNUNET_ATS_VALUE_UNDEFINED in HBO if value does 
not exist
  */
 static int
 get_performance_info (struct ATS_Address *address, uint32_t type)
@@ -726,14 +726,14 @@
        GNUNET_assert (NULL != address);
 
        if ((NULL == address->atsi) || (0 == address->atsi_count))
-                       return UINT32_MAX;
+                       return GNUNET_ATS_VALUE_UNDEFINED;
 
        for (c1 = 0; c1 < address->atsi_count; c1++)
        {
                        if (ntohl(address->atsi[c1].type) == type)
                                return ntohl(address->atsi[c1].value);
        }
-       return UINT32_MAX;
+       return GNUNET_ATS_VALUE_UNDEFINED;
 }
 
 
@@ -779,6 +779,10 @@
   atsi_delta = NULL;
   disassemble_ats_information (aa, atsi, atsi_count, &atsi_delta, 
&atsi_delta_count);
   GNUNET_free_non_null (atsi_delta);
+  addr_net = get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE);
+  if (GNUNET_ATS_VALUE_UNDEFINED == addr_net)
+               addr_net = GNUNET_ATS_NET_UNSPECIFIED;
+
   /* Get existing address or address with session == 0 */
   ea = find_equivalent_address (handle, peer, aa);
   if (ea == NULL)
@@ -790,9 +794,6 @@
                                                       
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' 
session id %u, %p\n",
                 GNUNET_i2s (peer), session_id, aa);
-    addr_net = get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE);
-    if (UINT32_MAX == addr_net)
-       addr_net = GNUNET_ATS_NET_UNSPECIFIED;
     /* Tell solver about new address */
     handle->s_add (handle->solver, handle->addresses, aa, addr_net);
     /* Notify performance clients about new address */

Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2013-04-03 12:17:03 UTC 
(rev 26734)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2013-04-03 12:22:22 UTC 
(rev 26735)
@@ -364,7 +364,7 @@
  *
  * @param address the address
  * @param type the type to extract in HBO
- * @return the value in HBO or UINT32_MAX in HBO if value does not exist
+ * @return the value in HBO or GNUNET_ATS_VALUE_UNDEFINED in HBO if value does 
not exist
  */
 static int
 get_performance_info (struct ATS_Address *address, uint32_t type)
@@ -373,14 +373,14 @@
        GNUNET_assert (NULL != address);
 
        if ((NULL == address->atsi) || (0 == address->atsi_count))
-                       return UINT32_MAX;
+                       return GNUNET_ATS_VALUE_UNDEFINED;
 
        for (c1 = 0; c1 < address->atsi_count; c1++)
        {
                        if (ntohl(address->atsi[c1].type) == type)
                                return ntohl(address->atsi[c1].value);
        }
-       return UINT32_MAX;
+       return GNUNET_ATS_VALUE_UNDEFINED;
 }
 
 
@@ -606,7 +606,7 @@
   for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
   {
        addr_net = get_performance_info (address, GNUNET_ATS_NETWORK_TYPE);
-       if (UINT32_MAX == addr_net)
+       if (GNUNET_ATS_VALUE_UNDEFINED == addr_net)
                addr_net = GNUNET_ATS_NET_UNSPECIFIED;
 
     if (mlp->pv.quota_index[c] == addr_net)
@@ -1092,7 +1092,7 @@
 mlp_update_quality (struct GAS_MLP_Handle *mlp,
                struct GNUNET_CONTAINER_MultiHashMap *addresses,
                struct ATS_Address * address,
-                                                                               
const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
+               const struct GNUNET_ATS_Information *ats_prev, uint32_t 
ats_prev_count)
 {
   struct MLP_information *mlpi = address->solver_information;
   unsigned int c_ats_entry;
@@ -1105,9 +1105,9 @@
   int qual_changed;
   int type_index;
   int avg_index;
-  uint32_t addr_net;
   uint32_t type;
-  uint32_t value;
+  uint32_t prev_value;
+  uint32_t new_value;
   double avg;
   double *queue;
   int rows;
@@ -1116,36 +1116,36 @@
 
 
        LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating %u quality metrics for peer 
`%s'\n",
-      ats_count, GNUNET_i2s (&address->peer));
+      ats_prev_count, GNUNET_i2s (&address->peer));
 
        GNUNET_assert (NULL != mlp);
   GNUNET_assert (NULL != address);
   GNUNET_assert (NULL != address->solver_information);
-  GNUNET_assert (NULL != ats);
+  GNUNET_assert (NULL != ats_prev);
 
   if (NULL == mlp->p.prob)
        return;
 
   qual_changed = GNUNET_NO;
-  for (c_ats_entry = 0; c_ats_entry < ats_count; c_ats_entry++)
+  for (c_ats_entry = 0; c_ats_entry < ats_prev_count; c_ats_entry++)
   {
-               type = ntohl (ats[c_ats_entry].type);
-               value = ntohl (ats[c_ats_entry].value);
+               type = ntohl (ats_prev[c_ats_entry].type);
+               prev_value = ntohl (ats_prev[c_ats_entry].value);
                type_index = -1;
                avg_index = -1;
 
                /* Check for network update */
                if (type == GNUNET_ATS_NETWORK_TYPE)
                {
-                       addr_net = get_performance_info (address, 
GNUNET_ATS_NETWORK_TYPE);
-                       if (UINT32_MAX == addr_net)
-                               addr_net = GNUNET_ATS_NET_UNSPECIFIED;
-                               if (addr_net != value)
+                               new_value = get_performance_info (address, 
GNUNET_ATS_NETWORK_TYPE);
+                       if (GNUNET_ATS_VALUE_UNDEFINED == new_value)
+                               new_value = GNUNET_ATS_NET_UNSPECIFIED;
+                               if (new_value != prev_value)
                                {
                                LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating network 
for peer `%s' from `%s' to `%s'\n",
                              GNUNET_i2s (&address->peer),
-                             GNUNET_ATS_print_network_type(addr_net),
-                             GNUNET_ATS_print_network_type(value));
+                             GNUNET_ATS_print_network_type(prev_value),
+                             GNUNET_ATS_print_network_type(new_value));
                                }
 
                                if (mlpi->c_b == MLP_UNDEFINED)
@@ -1158,13 +1158,13 @@
 
                          for (c_net = 0; c_net <= length + 1; c_net ++)
                          {
-                               if (ind[c_net] == mlp->p.r_quota[addr_net])
+                               if (ind[c_net] == mlp->p.r_quota[prev_value])
                                        break; /* Found index for old network */
                          }
                          val[c_net] = 0.0;
                                glp_set_mat_col (mlp->p.prob, mlpi->c_b, 
length, ind, val);
                                /* Set updated column */
-                               ind[c_net] = mlp->p.r_quota[value];
+                               ind[c_net] = mlp->p.r_quota[new_value];
                                val[c_net] = 1.0;
                                glp_set_mat_col (mlp->p.prob, mlpi->c_b, 
length, ind, val);
                          GNUNET_free (ind);
@@ -1177,9 +1177,9 @@
 
                          for (c_net = 0; c_net <= length + 1; c_net ++)
                          {
-                               if (ind[c_net] == mlp->p.r_quota[value])
+                               if (ind[c_net] == mlp->p.r_quota[prev_value])
                                        LOG (GNUNET_ERROR_TYPE_DEBUG, "Removing 
old network index [%u] == [%f]\n",ind[c_net],val[c_net]);
-                               if (ind[c_net] == mlp->p.r_quota[addr_net])
+                               if (ind[c_net] == mlp->p.r_quota[new_value])
                                {
                                        LOG (GNUNET_ERROR_TYPE_DEBUG, "Setting 
new network index [%u] == [%f]\n",ind[c_net],val[c_net]);
                                        break;
@@ -1208,7 +1208,12 @@
          avg_index = mlpi->q_avg_i[type_index];
 
          /* Update averaging queue */
-         mlpi->q[type_index][avg_index] = value;
+         new_value = get_performance_info (address, type);
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s': `%s' from %u to %u\n",
+        GNUNET_i2s (&address->peer),
+        mlp_ats_to_string(mlp->pv.q[type_index]), prev_value, new_value);
+         GNUNET_assert (GNUNET_ATS_VALUE_UNDEFINED != new_value);
+         mlpi->q[type_index][avg_index] = new_value;
 
          /* Update averaging index */
       if (mlpi->q_avg_i[type_index] + 1 < (MLP_AVERAGING_QUEUE_LENGTH))
@@ -1298,6 +1303,9 @@
  * If the address did not exist before in the problem:
  * The MLP problem has to be recreated and the problem has to be resolved
  *
+ * ATS performance information in address are already updated, delta + previous
+ * values are included in atsi_prev (value GNUNET_ATS_VALUE_UNDEFINED if not 
existing before)
+ *
  * Otherwise the addresses' values can be updated and the existing base can
  * be reused
  *
@@ -1306,8 +1314,8 @@
  * @param address the update address
  * @param session the new session (if changed otherwise current)
  * @param in_use the new address in use state (if changed otherwise current)
- * @param atsi the latest ATS information
- * @param atsi_count the atsi count
+ * @param atsi_prev ATS information updated + previous values, 
GNUNET_ATS_VALUE_UNDEFINED if not existing before
+ * @param atsi_count_prev number of atsi values updated
  */
 void
 GAS_mlp_address_update (void *solver,
@@ -1315,8 +1323,8 @@
                         struct ATS_Address *address,
                         uint32_t session,
                         int in_use,
-                        const struct GNUNET_ATS_Information *atsi,
-                        uint32_t atsi_count)
+                        const struct GNUNET_ATS_Information *atsi_prev,
+                        uint32_t atsi_count_prev)
 {
        struct ATS_Peer *p;
        struct GAS_MLP_Handle *mlp = solver;
@@ -1325,14 +1333,14 @@
        GNUNET_assert (NULL != solver);
        GNUNET_assert (NULL != addresses);
        GNUNET_assert (NULL != address);
-       GNUNET_assert ((NULL != atsi) || (0 == atsi_count));
+       GNUNET_assert ((NULL != atsi_prev) || (0 == atsi_count_prev));
 
   if (NULL == mlpi)
   {
       LOG (GNUNET_ERROR_TYPE_ERROR, _("Updating address for peer `%s' not 
added before\n"), GNUNET_i2s(&address->peer));
       return;
   }
-       mlp_update_quality (mlp, addresses, address, atsi, atsi_count);
+       mlp_update_quality (mlp, addresses, address, atsi_prev, 
atsi_count_prev);
 
   /* Is this peer included in the problem? */
   if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->peers, 
&address->peer.hashPubKey)))

Modified: gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c    2013-04-03 
12:17:03 UTC (rev 26734)
+++ gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c    2013-04-03 
12:22:22 UTC (rev 26735)
@@ -770,7 +770,7 @@
  *
  * @param address the address
  * @param type the type to extract in HBO
- * @return the value in HBO or UINT32_MAX in HBO if value does not exist
+ * @return the value in HBO or GNUNET_ATS_VALUE_UNDEFINED in HBO if value does 
not exist
  */
 static int
 get_performance_info (struct ATS_Address *address, uint32_t type)
@@ -779,14 +779,14 @@
        GNUNET_assert (NULL != address);
 
        if ((NULL == address->atsi) || (0 == address->atsi_count))
-                       return UINT32_MAX;
+                       return GNUNET_ATS_VALUE_UNDEFINED;
 
        for (c1 = 0; c1 < address->atsi_count; c1++)
        {
                        if (ntohl(address->atsi[c1].type) == type)
                                return ntohl(address->atsi[c1].value);
        }
-       return UINT32_MAX;
+       return GNUNET_ATS_VALUE_UNDEFINED;
 }
 
 
@@ -984,7 +984,7 @@
       break;
     case GNUNET_ATS_NETWORK_TYPE:
       addr_net = get_performance_info (address, GNUNET_ATS_NETWORK_TYPE);
-      if (UINT32_MAX == addr_net)
+      if (GNUNET_ATS_VALUE_UNDEFINED == addr_net)
       {
        GNUNET_break (0);
        addr_net = GNUNET_ATS_NET_UNSPECIFIED;
@@ -1140,7 +1140,7 @@
 
   p_distance_prev = get_performance_info (previous, 
GNUNET_ATS_QUALITY_NET_DISTANCE);
   p_distance_cur = get_performance_info (current, 
GNUNET_ATS_QUALITY_NET_DISTANCE);
-  if ((p_distance_prev != UINT32_MAX) && (p_distance_cur != UINT32_MAX) &&
+  if ((p_distance_prev != GNUNET_ATS_VALUE_UNDEFINED) && (p_distance_cur != 
GNUNET_ATS_VALUE_UNDEFINED) &&
                (p_distance_prev > p_distance_cur))
   {
     /* user shorter distance */
@@ -1150,7 +1150,7 @@
 
   p_delay_prev = get_performance_info (previous, GNUNET_ATS_QUALITY_NET_DELAY);
   p_delay_cur = get_performance_info (current, GNUNET_ATS_QUALITY_NET_DELAY);
-  if ((p_delay_prev != UINT32_MAX) && (p_delay_cur != UINT32_MAX) &&
+  if ((p_delay_prev != GNUNET_ATS_VALUE_UNDEFINED) && (p_delay_cur != 
GNUNET_ATS_VALUE_UNDEFINED) &&
                (p_delay_prev > p_delay_cur))
   {
     /* user lower latency */

Modified: gnunet/src/ats/test_ats_mlp_update.c
===================================================================
--- gnunet/src/ats/test_ats_mlp_update.c        2013-04-03 12:17:03 UTC (rev 
26734)
+++ gnunet/src/ats/test_ats_mlp_update.c        2013-04-03 12:22:22 UTC (rev 
26735)
@@ -41,6 +41,7 @@
  */
 struct GNUNET_ATS_Information ats[4];
 
+struct GNUNET_ATS_Information ats_prev[4];
 
 /**
  * MLP solver handle
@@ -228,6 +229,8 @@
   /* Solve problem to build matrix */
   GAS_mlp_solve_problem (mlp, addresses);
 
+  address[0]->atsi = ats;
+  address[0]->atsi_count = 4;
   /* Updating address 0*/
   ats[0].type =  htonl (GNUNET_ATS_NETWORK_TYPE);
   ats[0].value = htonl (GNUNET_ATS_NET_WAN);
@@ -237,8 +240,18 @@
   ats[2].value = htonl (1);
   ats[3].type =  htonl (GNUNET_ATS_ARRAY_TERMINATOR);
   ats[3].value = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
-  GAS_mlp_address_update (mlp, addresses, address[0], 1, GNUNET_NO, ats, 4);
 
+  ats_prev[0].type =  htonl (GNUNET_ATS_NETWORK_TYPE);
+  ats_prev[0].value = htonl (GNUNET_ATS_NET_UNSPECIFIED);
+  ats_prev[1].type =  htonl (GNUNET_ATS_QUALITY_NET_DELAY);
+  ats_prev[1].value = htonl (GNUNET_ATS_VALUE_UNDEFINED);
+  ats_prev[2].type =  htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
+  ats_prev[2].value = htonl (GNUNET_ATS_VALUE_UNDEFINED);
+  ats_prev[3].type =  htonl (GNUNET_ATS_ARRAY_TERMINATOR);
+  ats_prev[3].value = htonl (GNUNET_ATS_VALUE_UNDEFINED);
+
+  GAS_mlp_address_update (mlp, addresses, address[0], 1, GNUNET_NO, ats_prev, 
4);
+
   /* Solve problem to build matrix */
   GAS_mlp_solve_problem (mlp, addresses);
 }

Modified: gnunet/src/include/gnunet_ats_service.h
===================================================================
--- gnunet/src/include/gnunet_ats_service.h     2013-04-03 12:17:03 UTC (rev 
26734)
+++ gnunet/src/include/gnunet_ats_service.h     2013-04-03 12:22:22 UTC (rev 
26735)
@@ -59,11 +59,15 @@
  */
 #define GNUNET_ATS_DefaultBandwidth 65536
 
+/**
+ * Undefined value for a GNUNET_ATS_Property
+ */
+#define GNUNET_ATS_VALUE_UNDEFINED UINT32_MAX
 
 /**
- * Textual equivalent for GNUNET_ATS_MaxBandwidth
+ * String representation for GNUNET_ATS_VALUE_UNDEFINED
  */
-#define GNUNET_ATS_MaxBandwidthString "unlimited"
+#define GNUNET_ATS_VALUE_UNDEFINED_STR "undefined"
 
 /**
  * Maximum bandwidth assigned to a network : 4095 MB/s
@@ -71,6 +75,11 @@
 #define GNUNET_ATS_MaxBandwidth UINT32_MAX
 
 /**
+ * Textual equivalent for GNUNET_ATS_MaxBandwidth
+ */
+#define GNUNET_ATS_MaxBandwidthString "unlimited"
+
+/**
  * Number of property types supported by ATS
  */
 #define GNUNET_ATS_PropertyCount 9




reply via email to

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