- mlp
authorMatthias Wachs <wachs@net.in.tum.de>
Thu, 12 Jan 2012 14:49:27 +0000 (14:49 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Thu, 12 Jan 2012 14:49:27 +0000 (14:49 +0000)
src/ats/Makefile.am
src/ats/gnunet-service-ats_addresses.c
src/ats/gnunet-service-ats_addresses.h
src/ats/gnunet-service-ats_addresses_mlp.c
src/ats/gnunet-service-ats_addresses_mlp.h

index 912912a8ae11c5da27c540f26c2b9eb0e56058dc..c8a78bc20bcf43f8ff6e9977bf37485095a070e4 100644 (file)
@@ -16,6 +16,7 @@ endif
 if HAVE_LIBGLPK
   GN_LIBGLPK = -lglpk
   GN_MLP_SRC = gnunet-service-ats_addresses_mlp.c gnunet-service-ats_addresses_mlp.h
+  GN_MLP_TEST = test_ats_mlp
 endif
 
 lib_LTLIBRARIES = libgnunetats.la
@@ -50,7 +51,8 @@ gnunet_service_ats_LDADD = \
 
 
 check_PROGRAMS = \
- test_ats_api_scheduling
+ test_ats_api_scheduling \
+ $(GN_MLP_TEST)
 # test_ats_api_scheduling_get_type
 # test_ats_api_bandwidth_consumption
 
@@ -58,6 +60,15 @@ if ENABLE_TEST_RUN
 TESTS = $(check_PROGRAMS)
 endif
 
+if HAVE_LIBGLPK
+test_ats_mlp_SOURCES = \
+ $(GN_MLP_SRC) \
+ test_ats_mlp.c
+test_ats_mlp_LDADD = \
+  $(GN_LIBGLPK) \
+  $(top_builddir)/src/util/libgnunetutil.la
+endif
+
 test_ats_api_scheduling_SOURCES = \
  test_ats_api_scheduling.c
 test_ats_api_scheduling_LDADD = \
index 73545e35255037884b0b9e20c9623907ba5e8caf..b13de0df1a0c79e45f7a6de29c42adb58329ee24 100644 (file)
 #include "gnunet-service-ats_scheduling.h"
 #include "gnunet-service-ats_reservations.h"
 
-struct ATS_Address
-{
-  struct GNUNET_PeerIdentity peer;
-
-  size_t addr_len;
-
-  uint32_t session_id;
-
-  uint32_t ats_count;
-
-  const void *addr;
-
-  char *plugin;
-
-  struct GNUNET_ATS_Information *ats;
-
-  struct GNUNET_TIME_Relative atsp_latency;
-
-  struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_in;
-
-  struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_out;
-
-  uint32_t atsp_distance;
-
-  uint32_t atsp_cost_wan;
-
-  uint32_t atsp_cost_lan;
-
-  uint32_t atsp_cost_wlan;
-
-  uint32_t atsp_network_type;
-
-  struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_in;
-
-  struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_out;
-
-  /**
-   * Is this the active address for this peer?
-   */
-  int active;
-
-};
-
 enum ATS_Mode
 {
        SIMPLE,
@@ -501,15 +458,16 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
   {
        /* MLP = YES */
        case GNUNET_YES:
-#if !HAVE_LIBGLPK
-               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP mode was configured, but libglpk is not installed, switching to simple mode");
-               ats_mode = SIMPLE;
-               break;
+#if HAVE_LIBGLPK
+          ats_mode = MLP;
+          /* Init the MLP solver with default values */
+          GAS_mlp_init (MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
+          break;
 #else
-               ats_mode = MLP;
-               GAS_mlp_init ();
+          GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP mode was configured, but libglpk is not installed, switching to simple mode");
+          ats_mode = SIMPLE;
+          break;
 #endif
-               break;
        /* MLP = NO */
        case GNUNET_NO:
                ats_mode = SIMPLE;
index 6e5d95f705afc2e77d527d4fab588fd4b5e2938e..3709853a7c3bee63974e6e0d6611e05f12d0455a 100644 (file)
 #include "gnunet_ats_service.h"
 #include "ats.h"
 
+struct ATS_Address
+{
+  struct GNUNET_PeerIdentity peer;
+
+  size_t addr_len;
+
+  uint32_t session_id;
+
+  uint32_t ats_count;
+
+  const void *addr;
+
+  char *plugin;
+
+  struct GNUNET_ATS_Information *ats;
+
+  struct GNUNET_TIME_Relative atsp_latency;
+
+  struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_in;
+
+  struct GNUNET_BANDWIDTH_Value32NBO atsp_utilization_out;
+
+  uint32_t atsp_distance;
+
+  uint32_t atsp_cost_wan;
+
+  uint32_t atsp_cost_lan;
+
+  uint32_t atsp_cost_wlan;
+
+  uint32_t atsp_network_type;
+
+  struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_in;
+
+  struct GNUNET_BANDWIDTH_Value32NBO assigned_bw_out;
+
+  /**
+   * Is this the active address for this peer?
+   */
+  int active;
+
+};
+
 /**
  * Initialize address subsystem.
  * @param cfg configuration to use
index 6352412f40a9ce0fd0126efeb9840d6585810c19..734d07a132afaffa41f2898270ceb6edd845eb0e 100644 (file)
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
+#include "gnunet-service-ats_addresses.h"
 #include "gnunet-service-ats_addresses_mlp.h"
 #if HAVE_LIBGLPK
 #include "glpk.h"
 #endif
 
-struct GAS_MLP_Handle *GAS_mlp;
+/*
+ * The MLP handle
+ */
+static struct GAS_MLP_Handle *GAS_mlp;
+
 
 /**
  * Init the MLP problem solving component
+ *
+ * @param max_duration maximum numbers of iterations for the LP/MLP Solver
+ * @param max_iterations maximum time limit for the LP/MLP Solver
+ * @return GNUNET_OK on success, GNUNET_SYSERR on fail
  */
-void
-GAS_mlp_init ()
+int
+GAS_mlp_init (struct GNUNET_TIME_Relative max_duration, unsigned int max_iterations)
 {
   GAS_mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle));
-  GAS_mlp->prob = NULL;
+
+  /* Init GLPK environment */
+  GNUNET_assert (glp_init_env() == 0);
+
+  /* Create initial MLP problem */
+  GAS_mlp->prob = glp_create_prob();
+  GNUNET_assert (GAS_mlp->prob != NULL);
+
+  GAS_mlp->max_iterations = max_iterations;
+  GAS_mlp->max_exec_duration = max_duration;
+
+  /* Init LP solving parameters */
+  glp_init_smcp(&GAS_mlp->control_param_lp);
+  GAS_mlp->control_param_lp.it_lim = max_iterations;
+  GAS_mlp->control_param_lp.tm_lim = max_duration.rel_value;
+  /* Init MLP solving parameters */
+  glp_init_iocp(&GAS_mlp->control_param_mlp);
+  GAS_mlp->control_param_mlp.tm_lim = max_duration.rel_value;
+
+  return GNUNET_OK;
+}
+
+/**
+ * Updates a single address in the MLP problem
+ *
+ * If the address did not exist before in the problem:
+ * The MLP problem has to be recreated and the problem has to be resolved
+ *
+ * Otherwise the addresses' values can be updated and the existing base can
+ * be reused
+ */
+void
+GAS_mlp_address_update (struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address)
+{
+
+}
+
+/**
+ * Deletes a single address in the MLP problem
+ *
+ * The MLP problem has to be recreated and the problem has to be resolved
+ */
+void
+GAS_mlp_address_delete (struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address)
+{
+
+}
+
+/**
+ * Deletes a single address in the MLP problem
+ */
+void
+GAS_mlp_address_change_preference (struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address)
+{
+
 }
 
 /**
@@ -49,6 +112,12 @@ GAS_mlp_init ()
 void
 GAS_mlp_done ()
 {
+  if (GAS_mlp != NULL)
+    glp_delete_prob(GAS_mlp->prob);
+
+  /* Clean up GLPK environment */
+  glp_free_env();
+
   GNUNET_free (GAS_mlp);
 }
 
index 3351ca54154b548d0124b3443214e855e6f3c1a2..60c8dca05b16485999f1fc702a3f1f94901be18c 100644 (file)
@@ -25,6 +25,7 @@
  * @author Christian Grothoff
  */
 #include "platform.h"
+#include "gnunet-service-ats_addresses.h"
 #if HAVE_LIBGLPK
 #include "glpk.h"
 #endif
 #ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
 #define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
 
+
+#define MLP_MAX_EXEC_DURATION   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
+#define MLP_MAX_ITERATIONS      INT_MAX
+
 struct GAS_MLP_Handle
 {
   /**
@@ -43,13 +48,42 @@ struct GAS_MLP_Handle
   void *prob;
 #endif
 
+  /**
+   * GLPK LP control parameter
+   */
+  glp_smcp control_param_lp;
+
+  /**
+   * GLPK LP control parameter
+   */
+  glp_iocp control_param_mlp;
+
+  /**
+   * Maximum execution time per problem solving
+   */
+  struct GNUNET_TIME_Relative max_exec_duration;
+
+  /**
+   * Maximum number of LP iterations per problem solving
+   */
+  unsigned int max_iterations;
+
 };
 
 /**
  * Init the MLP problem solving component
+ * @param max_duration maximum numbers of iterations for the LP/MLP Solver
+ * @param max_iterations maximum time limit for the LP/MLP Solver
+ * @return GNUNET_OK on success, GNUNET_SYSERR on fail
+ */
+int
+GAS_mlp_init (struct GNUNET_TIME_Relative max_duration, unsigned int max_iterations);
+
+/**
+ * Update address in the MLP problem
  */
 void
-GAS_mlp_init ();
+GAS_mlp_update (struct ATS_Address *address);
 
 /**
  * Shutdown the MLP problem solving component