- changes to ats
authorMatthias Wachs <wachs@net.in.tum.de>
Mon, 20 Feb 2012 14:56:24 +0000 (14:56 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Mon, 20 Feb 2012 14:56:24 +0000 (14:56 +0000)
src/ats/gnunet-service-ats_addresses_mlp.c
src/ats/gnunet-service-ats_addresses_mlp.h
src/ats/test_ats_mlp.c
src/include/gnunet_ats_service.h

index 0c9e0b32846dc4c94e82b63200ce85d4ab094b36..57033f07b874b36fbc73c3a086cbe269dcbc59c8 100644 (file)
@@ -347,6 +347,32 @@ create_constraint_it (void *cls, const GNUNET_HashCode * key, void *value)
   mlp->ar[mlp->ci] = 1;
   mlp->ci++;
 
+  /* c 10) obey network specific quotas
+   * (1)*b_1 + ... + (1)*b_m <= quota_n
+   */
+  int cur_row = 0;
+  int c;
+  for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
+    {
+    if (mlp->quota_index[c] == address->atsp_network_type)
+    {
+      cur_row = mlp->r_quota[c];
+      break;
+    }
+  }
+
+  if (cur_row != 0)
+  {
+    mlp->ia[mlp->ci] = cur_row;
+    mlp->ja[mlp->ci] = mlpi->c_b;
+    mlp->ar[mlp->ci] = 1;
+    mlp->ci++;
+  }
+  else
+  {
+    GNUNET_break (0);
+  }
+
   return GNUNET_OK;
 }
 
@@ -421,6 +447,10 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
    * #rows: |ressources|
    * #indices: |n_addresses|
    *
+   * c 10) obey network specific quota
+   * #rows: |network types
+   * #indices: |n_addresses|
+   *
    * Sum for feasibility constraints:
    * #rows: 3 * |n_addresses| +  |ressources| + |peers| + 1
    * #indices: 7 * |n_addresses|
@@ -444,8 +474,8 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
    * #indices: |n_addresses| + |peers|
    * */
 
-  /* last +1 caused by glpk index starting with one */
-  int pi = ((7 * n_addresses) + (4 * n_addresses +  mlp->m_q + mlp->c_p + 2) + 1);
+  /* last +1 caused by glpk index starting with one: [1..pi]*/
+  int pi = ((7 * n_addresses) + (5 * n_addresses +  mlp->m_q + mlp->c_p + 2) + 1);
   mlp->cm_size = pi;
   mlp->ci = 1;
 
@@ -469,6 +499,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
    * c 3) minimum bandwidth
    * c 4) minimum number of connections
    * c 6) maximize diversity
+   * c 10) obey network specific quota
    */
 
   int min = mlp->n_min;
@@ -490,6 +521,14 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
   ar[mlp->ci] = -1;
   mlp->ci++;
 
+  /* Add rows for c 10) */
+  for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
+  {
+    mlp->r_quota[c] = glp_add_rows (mlp->prob, 1);
+    /* Set bounds to 0 <= x <= quota_out */
+    glp_set_row_bnds (mlp->prob, mlp->r_quota[c], GLP_DB, 0.0, mlp->quota_out[c]);
+  }
+
   GNUNET_CONTAINER_multihashmap_iterate (addresses, create_constraint_it, mlp);
 
   /* Adding constraint rows
@@ -549,16 +588,19 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
     {
       mlpi = (struct MLP_information *) addr->mlp_information;
 
+      /* coefficient for c 2) */
       ia[mlp->ci] = peer->r_c2;
       ja[mlp->ci] = mlpi->c_n;
       ar[mlp->ci] = 1;
       mlp->ci++;
 
+      /* coefficient for c 8) */
       ia[mlp->ci] = mlp->r_c8;
       ja[mlp->ci] = mlpi->c_b;
       ar[mlp->ci] = peer->f;
       mlp->ci++;
 
+      /* coefficient for c 9) */
       ia[mlp->ci] = peer->r_c9;
       ja[mlp->ci] = mlpi->c_b;
       ar[mlp->ci] = 1;
@@ -588,7 +630,6 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
       /* Set row bound == 0 */
       glp_set_row_bnds (mlp->prob, mlp->r_q[c], GLP_LO, 0.0, 0.0);
 
-      /* Set -q_m */
       ia[mlp->ci] = mlp->r_q[c];
       ja[mlp->ci] = mlp->c_q[c];
       ar[mlp->ci] = -1;
@@ -605,9 +646,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
           value = (double) addr->ats[index].value;
 
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Quality %i with ATS property `%s' has index %i in addresses ats information has value %f\n", c,  mlp_ats_to_string(mlp->q[c]), index, (double) addr->ats[index].value);
-
         }
-
         else
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Quality %i with ATS property `%s' not existing\n", c,  mlp_ats_to_string(mlp->q[c]), index);
 
@@ -1105,11 +1144,65 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
   else
     U = 1.0;
 
+  /* Init network quotas */
+  int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
+  int c;
+
+  for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
+  {
+    mlp->quota_index[c] = quotas[c];
+    static char * entry_in = NULL;
+    static char * entry_out = NULL;
+    unsigned long long quota_in = 0;
+    unsigned long long quota_out = 0;
+
+    switch (quotas[c]) {
+      case GNUNET_ATS_NET_UNSPECIFIED:
+        entry_out = "UNSPECIFIED_QUOTA_OUT";
+        entry_in = "UNSPECIFIED_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_LOOPBACK:
+        entry_out = "LOOPBACK_QUOTA_OUT";
+        entry_in = "LOOPBACK_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_LAN:
+        entry_out = "LAN_QUOTA_OUT";
+        entry_in = "LAN_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_WAN:
+        entry_out = "WAN_QUOTA_OUT";
+        entry_in = "WAN_QUOTA_IN";
+        break;
+      case GNUNET_ATS_NET_WLAN:
+        entry_out = "WLAN_QUOTA_OUT";
+        entry_in = "WLAN_QUOTA_IN";
+        break;
+      default:
+        break;
+    }
+
+    if ((entry_in == NULL) || (entry_out == NULL))
+      continue;
+
+    if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", entry_out, &quota_out))
+    {
+      quota_out = UINT32_MAX;
+    }
+    if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", entry_in, &quota_in))
+    {
+      quota_in = UINT32_MAX;
+    }
+
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found `%s' quota %llu and `%s' quota %llu\n",
+                entry_out, quota_out, entry_in, quota_in);
+    mlp->quota_out[c] = quota_out;
+    mlp->quota_in[c] = quota_in;
+  }
+
   /* Get quality metric coefficients from configuration */
   int i_delay = -1;
   int i_distance = -1;
   int q[GNUNET_ATS_QualityPropertiesCount] = GNUNET_ATS_QualityProperties;
-  int c;
   for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++)
   {
     /* initialize quality coefficients with default value 1.0 */
@@ -1143,7 +1236,9 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
                                                       &tmp))
     b_min = tmp;
   else
-    b_min = 64000;
+  {
+    b_min = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
+  }
 
   /* Get minimum number of connections from configuration */
   if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
index a2e665f4b612827383375b7ce804e09cc66fba03..9e7ca053318fccc1631ead2e02ca5f0ab39eb698 100644 (file)
@@ -223,6 +223,13 @@ struct GAS_MLP_Handle
   /* number of quality metrics */
   int m_q;
 
+  /* ATS network quotas */
+  int c_quota[GNUNET_ATS_NetworkTypeCount];
+  int r_quota[GNUNET_ATS_NetworkTypeCount];
+  int quota_index [GNUNET_ATS_NetworkTypeCount];
+  unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
+  unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
+
   /* ATS ressource costs
    *
    * array with GNUNET_ATS_QualityPropertiesCount elements
index ddcd412375a05f2e1cc32f134c2e5e9a3c658842..9726be38f54f75b177a27894be4e0e07bf214f99 100644 (file)
@@ -97,23 +97,26 @@ check (void *cls, char *const *args, const char *cfgfile,
   set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 32);
   set_ats (&a1_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0);
   create_address (&addr[0], "dummy", 3, &a1_ats[0]);
+  addr[0].atsp_network_type = GNUNET_ATS_NET_WAN;
 
 
   /* Creating peer 1  address 2 */
   addr[1].peer.hashPubKey = p[0].hashPubKey;
   struct GNUNET_ATS_Information a2_ats[3];
-  set_ats (&a2_ats[0], GNUNET_ATS_ARRAY_TERMINATOR, 0);
-  set_ats (&a2_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 32);
-  set_ats (&a2_ats[2], GNUNET_ATS_QUALITY_NET_DISTANCE, 1);
+  set_ats (&a2_ats[0], GNUNET_ATS_QUALITY_NET_DELAY, 32);
+  set_ats (&a2_ats[1], GNUNET_ATS_QUALITY_NET_DISTANCE, 1);
+  set_ats (&a2_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0);
   create_address (&addr[1], "dummy2", 3, &a2_ats[0]);
+  addr[1].atsp_network_type = GNUNET_ATS_NET_WAN;
 
   /* Creating peer 2  address 1 */
   addr[2].peer.hashPubKey = p[1].hashPubKey;
   struct GNUNET_ATS_Information a3_ats[3];
-  set_ats (&a3_ats[0], GNUNET_ATS_ARRAY_TERMINATOR, 0);
-  set_ats (&a3_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 32);
-  set_ats (&a3_ats[2], GNUNET_ATS_QUALITY_NET_DISTANCE, 1);
+  set_ats (&a3_ats[0], GNUNET_ATS_QUALITY_NET_DELAY, 32);
+  set_ats (&a3_ats[1], GNUNET_ATS_QUALITY_NET_DISTANCE, 1);
+  set_ats (&a3_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0);
   create_address (&addr[2], "dummy3", 3, &a3_ats[0]);
+  addr[2].atsp_network_type = GNUNET_ATS_NET_LAN;
 
   GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
 
index 2c1b929fa867b69fffd03c2251aff9b4e597d6f0..858ae1da5336e1f58b31fa3dc12ece092eca9482 100644 (file)
@@ -412,6 +412,15 @@ enum GNUNET_ATS_Property
  */
 #define GNUNET_ATS_QualityProperties {GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE}
 
+/**
+ * Number of ATS quality properties
+ */
+#define GNUNET_ATS_NetworkTypeCount 5
+
+/**
+ * ATS quality properties as array initializer
+ */
+#define GNUNET_ATS_NetworkType {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN}
 
 GNUNET_NETWORK_STRUCT_BEGIN