gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r26102 - gnunet/src/ats
Date: Thu, 14 Feb 2013 13:42:20 +0100

Author: wachs
Date: 2013-02-14 13:42:20 +0100 (Thu, 14 Feb 2013)
New Revision: 26102

Modified:
   gnunet/src/ats/Makefile.am
   gnunet/src/ats/gnunet-service-ats_addresses.c
   gnunet/src/ats/test_ats_api_common.c
   gnunet/src/ats/test_ats_api_common.h
   gnunet/src/ats/test_ats_mlp.c
   gnunet/src/ats/test_ats_mlp.conf
Log:
modifications


Modified: gnunet/src/ats/Makefile.am
===================================================================
--- gnunet/src/ats/Makefile.am  2013-02-14 12:33:43 UTC (rev 26101)
+++ gnunet/src/ats/Makefile.am  2013-02-14 12:42:20 UTC (rev 26102)
@@ -196,24 +196,21 @@
 
 if HAVE_LIBGLPK
 test_ats_mlp_SOURCES = \
-  $(GN_MLP_SRC) \
-  test_ats_mlp.c
+  $(GN_MLP_SRC) test_ats_mlp.c test_ats_api_common.c
 test_ats_mlp_LDADD = \
   $(GN_LIBGLPK) \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(top_builddir)/src/statistics/libgnunetstatistics.la
 
 #test_ats_mlp_averaging_SOURCES = \
-# $(GN_MLP_SRC) \
-# test_ats_mlp_averaging.c
+# $(GN_MLP_SRC) test_ats_mlp_averaging.c test_ats_api_common.c
 #test_ats_mlp_averaging_LDADD = \
 #  $(GN_LIBGLPK) \
 #  $(top_builddir)/src/util/libgnunetutil.la \
 #  $(top_builddir)/src/statistics/libgnunetstatistics.la
 
 #perf_ats_mlp_SOURCES = \
-# $(GN_MLP_SRC) \
-# perf_ats_mlp.c
+# $(GN_MLP_SRC) perf_ats_mlp.c test_ats_api_common.c
 #perf_ats_mlp_LDADD = \
 #  $(GN_LIBGLPK) \
 #  $(top_builddir)/src/util/libgnunetutil.la \

Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c       2013-02-14 12:33:43 UTC 
(rev 26101)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c       2013-02-14 12:42:20 UTC 
(rev 26102)
@@ -956,6 +956,16 @@
   handle->s_pref (handle->solver, client, peer, kind, score);
 }
 
+
+/**
+ * Load quotas for networks from configuration
+ *
+ * @param cfg configuration handle
+ * @param out_dest where to write outbound quotas
+ * @param in_dest where to write inbound quotas
+ * @param dest_length length of inbound and outbound arrays
+ * @return number of networks loaded
+ */
 static unsigned int
 load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long 
*out_dest, unsigned long long *in_dest, int dest_length)
 {

Modified: gnunet/src/ats/test_ats_api_common.c
===================================================================
--- gnunet/src/ats/test_ats_api_common.c        2013-02-14 12:33:43 UTC (rev 
26101)
+++ gnunet/src/ats/test_ats_api_common.c        2013-02-14 12:42:20 UTC (rev 
26102)
@@ -27,7 +27,9 @@
 #include "test_ats_api_common.h"
 
 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
+#define BIG_M_STRING "unlimited"
 
+
 #define PEERID0 
"2AK99KD8RM9UA9LC3QKA0IQ5UBFC0FBB50EBGCFQT8448DGGACNAC4CJQDD1CPFS494O41U88DJD1FLIG8VA5CQR9IN4L96GP104MVO"
 #define PEERID1 
"5ED7I0AR3MSTAL7FQN04S22E0EQ3CR9RLASCDLVMM1BNFPUPTCT46DLKNJ4DACASJ6U0DR5J8S3R2UJL49682JS7MOVRAB8P8A4PJH0"
 
@@ -136,4 +138,108 @@
 }
 
 
+/**
+ * Load quotas for networks from configuration
+ *
+ * @param cfg configuration handle
+ * @param out_dest where to write outbound quotas
+ * @param in_dest where to write inbound quotas
+ * @param dest_length length of inbound and outbound arrays
+ * @return number of networks loaded
+ */
+unsigned int
+load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                                                unsigned long long *out_dest,
+                                                unsigned long long *in_dest,
+                                                int dest_length)
+{
+  char *network_str[GNUNET_ATS_NetworkTypeCount] = 
GNUNET_ATS_NetworkTypeString;
+  char * entry_in = NULL;
+  char * entry_out = NULL;
+  char * quota_out_str;
+  char * quota_in_str;
+  int c;
+  int res;
+
+  for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
+  {
+    in_dest[c] = 0;
+    out_dest[c] = 0;
+    GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
+    GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
+
+    /* quota out */
+    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", 
entry_out, &quota_out_str))
+    {
+      res = GNUNET_NO;
+      if (0 == strcmp(quota_out_str, BIG_M_STRING))
+      {
+        out_dest[c] = GNUNET_ATS_MaxBandwidth;
+        res = GNUNET_YES;
+      }
+      if ((GNUNET_NO == res) && (GNUNET_OK == 
GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
+        res = GNUNET_YES;
+      if ((GNUNET_NO == res) && (GNUNET_OK == 
GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out,  &out_dest[c])))
+         res = GNUNET_YES;
+
+      if (GNUNET_NO == res)
+      {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for 
network `%s':  `%s', assigning default bandwidth %llu\n"),
+              network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
+          out_dest[c] = GNUNET_ATS_DefaultBandwidth;
+      }
+      else
+      {
+          GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Outbound quota configure for 
network `%s' is %llu\n"),
+              network_str[c], out_dest[c]);
+      }
+      GNUNET_free (quota_out_str);
+    }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured 
for network `%s', assigning default bandwidth %llu\n"),
+          network_str[c], GNUNET_ATS_DefaultBandwidth);
+      out_dest[c] = GNUNET_ATS_DefaultBandwidth;
+    }
+
+    /* quota in */
+    if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", 
entry_in, &quota_in_str))
+    {
+      res = GNUNET_NO;
+      if (0 == strcmp(quota_in_str, BIG_M_STRING))
+      {
+        in_dest[c] = GNUNET_ATS_MaxBandwidth;
+        res = GNUNET_YES;
+      }
+      if ((GNUNET_NO == res) && (GNUNET_OK == 
GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
+        res = GNUNET_YES;
+      if ((GNUNET_NO == res) && (GNUNET_OK == 
GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in,  &in_dest[c])))
+         res = GNUNET_YES;
+
+      if (GNUNET_NO == res)
+      {
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for 
network `%s':  `%s', assigning default bandwidth %llu\n"),
+              network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
+          in_dest[c] = GNUNET_ATS_DefaultBandwidth;
+      }
+      else
+      {
+          GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Inbound quota configured for 
network `%s' is %llu\n"),
+              network_str[c], in_dest[c]);
+      }
+      GNUNET_free (quota_in_str);
+    }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure 
for network `%s', assigning default bandwidth %llu\n"),
+          network_str[c], GNUNET_ATS_DefaultBandwidth);
+      out_dest[c] = GNUNET_ATS_DefaultBandwidth;
+    }
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota for network `%s' 
(in/out): %llu %llu\n", network_str[c], in_dest[c], out_dest[c]);
+    GNUNET_free (entry_out);
+    GNUNET_free (entry_in);
+  }
+  return GNUNET_ATS_NetworkTypeCount;
+}
+
 /* end of file test_ats_api_common.c */

Modified: gnunet/src/ats/test_ats_api_common.h
===================================================================
--- gnunet/src/ats/test_ats_api_common.h        2013-02-14 12:33:43 UTC (rev 
26101)
+++ gnunet/src/ats/test_ats_api_common.h        2013-02-14 12:42:20 UTC (rev 
26102)
@@ -72,4 +72,19 @@
 compare_ats (const struct GNUNET_ATS_Information *ats_is, uint32_t 
ats_count_is,
              const struct GNUNET_ATS_Information *ats_should, uint32_t 
ats_count_should);
 
+/**
+ * Load quotas for networks from configuration
+ *
+ * @param cfg configuration handle
+ * @param out_dest where to write outbound quotas
+ * @param in_dest where to write inbound quotas
+ * @param dest_length length of inbound and outbound arrays
+ * @return number of networks loaded
+ */
+unsigned int
+load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                                                unsigned long long *out_dest,
+                                                unsigned long long *in_dest,
+                                                int dest_length);
+
 /* end of file test_ats_api_common.h */

Modified: gnunet/src/ats/test_ats_mlp.c
===================================================================
--- gnunet/src/ats/test_ats_mlp.c       2013-02-14 12:33:43 UTC (rev 26101)
+++ gnunet/src/ats/test_ats_mlp.c       2013-02-14 12:42:20 UTC (rev 26102)
@@ -19,7 +19,7 @@
 */
 /**
  * @file ats/test_ats_mlp.c
- * @brief test for the MLP solver
+ * @brief basic test for the MLP solver
  * @author Christian Grothoff
  * @author Matthias Wachs
 
@@ -29,9 +29,29 @@
 #include "gnunet_statistics_service.h"
 #include "gnunet_ats_service.h"
 #include "gnunet-service-ats_addresses_mlp.h"
+#include "test_ats_api_common.h"
 
+/**
+ * Return value
+ */
 static int ret;
 
+/**
+ * MLP solver handle
+ */
+struct GAS_MLP_Handle *mlp;
+
+
+/**
+ * Statistics handle
+ */
+struct GNUNET_STATISTICS_Handle * stats;
+
+/**
+ * Hashmap containing addresses
+ */
+struct GNUNET_CONTAINER_MultiHashMap * addresses;
+
 #if 0
 
 #define MLP_MAX_EXEC_DURATION   
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
@@ -40,13 +60,13 @@
 
 
 
-struct GNUNET_STATISTICS_Handle * stats;
 
-struct GNUNET_CONTAINER_MultiHashMap * addresses;
 
-struct GAS_MLP_Handle *mlp;
 
 
+
+
+
 static void
 create_address (struct ATS_Address *addr, char * plugin, int ats_count, struct 
GNUNET_ATS_Information *ats)
 {
@@ -148,18 +168,91 @@
 }
 #endif
 
+int addr_it (void *cls,
+             const struct GNUNET_HashCode * key,
+             void *value)
+{
+       GNUNET_CONTAINER_multihashmap_remove (addresses, key, value);
+       return GNUNET_OK;
+}
+
+
 static void
+end_now (int res)
+{
+  if (NULL != stats)
+  {
+         GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
+         stats = NULL;
+  }
+  if (NULL != mlp)
+  {
+               GAS_mlp_done (mlp);
+               mlp = NULL;
+  }
+  if (NULL != addresses)
+  {
+               GNUNET_CONTAINER_multihashmap_iterate (addresses, &addr_it, 
NULL);
+               GNUNET_CONTAINER_multihashmap_destroy (addresses);
+               addresses = NULL ;
+  }
+
+       ret = res;
+}
+
+static void
+bandwidth_changed_cb (void *cls, struct ATS_Address *address)
+{
+
+}
+
+static void
 check (void *cls, char *const *args, const char *cfgfile,
        const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
+  unsigned long long  quotas_in[GNUNET_ATS_NetworkTypeCount];
+  unsigned long long  quotas_out[GNUNET_ATS_NetworkTypeCount];
 
-
 #if !HAVE_LIBGLPK
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
   ret = 1;
   return;
 #endif
 
+  stats = GNUNET_STATISTICS_create("ats", cfg);
+  if (NULL == stats)
+  {
+       GNUNET_break (0);
+    end_now (1);
+    return;
+  }
+
+
+  if (GNUNET_ATS_NetworkTypeCount != load_quotas (cfg, quotas_out, quotas_in,
+                       GNUNET_ATS_NetworkTypeCount))
+  {
+       GNUNET_break (0);
+      end_now (1);
+      return;
+  }
+
+  addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
+
+  mlp  = GAS_mlp_init (cfg, stats, quotas, quotas_out, quotas_in,
+               GNUNET_ATS_NetworkTypeCount, &bandwidth_changed_cb, NULL);
+  if (NULL == mlp)
+  {
+       GNUNET_break (0);
+      end_now (1);
+      return;
+  }
+
+
+
+  end_now (0);
+
+
 #if 0
   struct ATS_Address addr[10];
   struct ATS_Address *res[10];
@@ -169,10 +262,10 @@
   unsigned long long  quotas_out[GNUNET_ATS_NetworkTypeCount];
   int quota_count;
 
-  stats = GNUNET_STATISTICS_create("ats", cfg);
 
-  addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
 
+
+
   quota_count = load_quotas(cfg, quotas_in, quotas_out, 
GNUNET_ATS_NetworkTypeCount);
   mlp = GAS_mlp_init (cfg, NULL, quotas, quotas_in, quotas_out, quota_count);
   mlp->auto_solve = GNUNET_NO;
@@ -253,12 +346,8 @@
 
   GNUNET_assert (mlp->addr_in_problem == 0);
 
-  GAS_mlp_done (mlp);
-
   GNUNET_free (addr[0].plugin);
   GNUNET_free (addr[1].plugin);
-  GNUNET_CONTAINER_multihashmap_destroy (addresses);
-  GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
 #endif
 
   ret = 0;

Modified: gnunet/src/ats/test_ats_mlp.conf
===================================================================
--- gnunet/src/ats/test_ats_mlp.conf    2013-02-14 12:33:43 UTC (rev 26101)
+++ gnunet/src/ats/test_ats_mlp.conf    2013-02-14 12:42:20 UTC (rev 26102)
@@ -35,8 +35,8 @@
 WAN_QUOTA_IN = 64 KiB
 WAN_QUOTA_OUT = 64 KiB
 # WLAN
-WLAN_QUOTA_IN = 512
-WLAN_QUOTA_OUT = 512
+WLAN_QUOTA_IN = 4096
+WLAN_QUOTA_OUT = 4096
 
 # ATS extended options
 DUMP_MLP = NO




reply via email to

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