From d74a1b1b52178c35f0f804c34bc63fe2c0203c1a Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 22 Mar 2011 18:36:57 +0000 Subject: [PATCH] ats and changed configure script...does not work correctly...but at least detects when glpk is NOT installed --- configure.ac | 13 ++ src/include/gnunet_transport_service.h | 5 - src/transport/Makefile.am | 8 +- src/transport/gnunet-service-transport.c | 179 +++++++++++++++++++++++ src/transport/test_transport_ats.c | 12 +- src/transport/transport.h | 5 +- 6 files changed, 208 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 3d061c905..699a63d3d 100644 --- a/configure.ac +++ b/configure.ac @@ -247,6 +247,17 @@ LIBCURL_CHECK_CONFIG(,7.20.1,,AC_MSG_ERROR([GNUnet requires libcurl >= 7.20.1])) # restore LIBS LIBS=$SAVE_LIBS +# glpk +glpk=0 +AC_CHECK_HEADERS([glpk.h]) +if test "$ac_cv_header_glpk_h" = yes; then +AM_CONDITIONAL(HAVE_GLPK, 1) +AC_DEFINE_UNQUOTED([HAVE_GLPK], test x$glpk = xtrue, [We have GLPK]) +else +AM_CONDITIONAL(HAVE_GLPK, test x$glpk = xtrue) +AC_MSG_WARN([GLPK not installed.]) +fi + # test for kvm and kstat (for CPU stats under BSD/Solaris) AC_CHECK_LIB([kvm],[kvm_open]) AC_CHECK_LIB([kstat],[kstat_open]) @@ -622,6 +633,8 @@ AC_DEFINE_UNQUOTED([HAVE_ESMTP], $esmtp, [We have libesmtp]) # restore LIBS LIBS=$SAVE_LIBS + + # check for gettext AM_GNU_GETTEXT([external]) AM_GNU_GETTEXT_VERSION([0.16.1]) diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index 04b0f5a33..0fbbf12f0 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h @@ -390,11 +390,6 @@ struct GNUNET_TRANSPORT_ATS_Information uint32_t value; }; -/* Minimum time between to calculations*/ -#define ATS_MIN_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,250) -#define ATS_EXEC_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,1) - -#define DEBUG_ATS GNUNET_NO /** diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 13db3b5c2..43c4692b5 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am @@ -105,6 +105,10 @@ gnunet_transport_LDADD = \ gnunet_transport_DEPENDENCIES = \ libgnunettransport.la +if HAVE_GLPK + GN_GLPK = -lglpk +endif + gnunet_service_transport_SOURCES = \ gnunet-service-transport.c gnunet_service_transport_LDADD = \ @@ -112,10 +116,10 @@ gnunet_service_transport_LDADD = \ $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ $(top_builddir)/src/util/libgnunetutil.la \ + $(GN_GLPK) \ $(GN_LIBINTL) gnunet_service_transport_DEPENDENCIES = \ - libgnunettransport.la - + libgnunettransport.la plugin_LTLIBRARIES = \ libgnunet_plugin_transport_tcp.la \ diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 1a5d0af4b..ba9cdfbc6 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -38,6 +38,9 @@ #include "gnunet_signatures.h" #include "gnunet_transport_plugin.h" #include "transport.h" +#if HAVE_GLPK +#include +#endif #define DEBUG_BLACKLIST GNUNET_YES @@ -5546,6 +5549,153 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_break (bc_head == NULL); } + + +#if HAVE_GLPK + +glp_prob * ats_create_problem(int peers, double b_min, double b_max, double r, const struct ATS_peer * list, int max_it, int max_dur) +{ + int c1, c2; + glp_prob *lp; + char * transport; + + int rows = 1 + peers + peers + peers; + int cols = peers; + int index = 1; + int start = 0; + int cur_row = 0; + + int ia[1+(rows*cols)], ja[1+(rows*cols)]; + double ar[1+(rows*cols)]; + double value; + + /* Setting options */ +/* glp_smcp * options = GNUNET_malloc( sizeof (glp_smcp)); + // max iterations + options->it_lim = max_it; + // max durations + options->tm_lim = max_it; + options->msg_lev = GLP_MSG_OFF; + options->meth = GLP_PRIMAL; + options->pricing = GLP_PT_PSE; + options->r_test = GLP_RT_HAR; + options->tol_bnd = +*/ + + lp = glp_create_prob(); + glp_set_prob_name(lp, "gnunet ats bandwidth distribution"); + glp_set_obj_dir(lp, GLP_MAX); + + /* Adding transports */ + glp_add_cols(lp, cols); + for (c1=1; c1<=cols; c1++) + { + GNUNET_asprintf(&transport,"Peer %s",GNUNET_i2s(&list[c1-1].peer)); + //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ats_create_problem Peer[%i] : %s \n",c1-1 , transport); + /* add a single transport */ + glp_set_col_name(lp, c1, transport); + /* add a lower bound */ + glp_set_col_bnds(lp, c1, GLP_LO, 0.0, 0.0); + /* set coefficient function */ + glp_set_obj_coef(lp, c1, 1.0); + GNUNET_free(transport); + } + + + /* Adding constraints */ + glp_add_rows(lp, rows); + cur_row = 1; + + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "row: %i \n", cur_row); + glp_set_row_bnds(lp, cur_row, GLP_UP, 0.0, b_max); + for (index=1; index<=cols; index++) + { + ia[index] = 1, ja[index] = index, ar[index] = 1.0; + } + + + cur_row = 2; + start = index+1; + for (c1=0; c1last,GNUNET_TIME_absolute_get()); @@ -5559,6 +5709,29 @@ void ats_calculate_bandwidth_distribution (struct ATS_info * ats) #if DEBUG_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CALCULATE DISTRIBUTION\n"); #endif + + int transports = 9; + double b_min = 10; + double b_max = 100.0; + double r = 0.8; + + int it = 50; + int dur = 500; + + struct ATS_peer * list = GNUNET_malloc(transports * sizeof (struct ATS_peer)); + int c = 0; + while (c < transports) + { + list[c].peer.hashPubKey.bits[0] = c+1; + list[c].f = 1 / (double) transports; + //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ats_calculate_bandwidth_distribution Peer[%i] : %s %p \n",c , GNUNET_i2s(&list[c].peer), &list[c].peer); + c++; + } + + ats_create_problem(transports, b_min, b_max, r, list, it, dur); + + GNUNET_free (list); + ats->last = GNUNET_TIME_absolute_get(); } @@ -5780,6 +5953,12 @@ run (void *cls, validation_map = NULL; return; } +#if HAVE_GLPK + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("HAVE\n")); +#else + //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("NOT HAVE\n")); +#endif + ats = ats_init(); max_connect_per_transport = (uint32_t) tneigh; peerinfo = GNUNET_PEERINFO_connect (cfg); diff --git a/src/transport/test_transport_ats.c b/src/transport/test_transport_ats.c index 2d3321a9e..0f80807f6 100644 --- a/src/transport/test_transport_ats.c +++ b/src/transport/test_transport_ats.c @@ -45,7 +45,7 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) /** * How long until we give up on transmitting the message? @@ -138,7 +138,7 @@ end_badly () GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); GNUNET_break (0); GNUNET_TRANSPORT_disconnect (p1.th); - GNUNET_TRANSPORT_disconnect (p2.th); + //GNUNET_TRANSPORT_disconnect (p2.th); ok = 1; } @@ -367,11 +367,11 @@ run (void *cls, &end_badly, NULL); setup_peer (&p1, "test_transport_ats_peer1.conf"); - setup_peer (&p2, "test_transport_ats_peer2.conf"); + //setup_peer (&p2, "test_transport_ats_peer2.conf"); GNUNET_assert(p1.th != NULL); - GNUNET_assert(p2.th != NULL); - + //GNUNET_assert(p2.th != NULL); + return; GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); } @@ -398,7 +398,7 @@ check () argv, "test-transport-api", "nohelp", options, &run, &ok); stop_arm (&p1); - stop_arm (&p2); + // stop_arm (&p2); if (is_https) { diff --git a/src/transport/transport.h b/src/transport/transport.h index dc9e7ce58..7dc96de68 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -34,7 +34,7 @@ #define ATS_MIN_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,250) #define ATS_EXEC_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,1) -#define DEBUG_ATS GNUNET_NO +#define DEBUG_ATS GNUNET_YES struct ATS_info { @@ -49,6 +49,9 @@ struct ATS_info struct ATS_peer { struct GNUNET_PeerIdentity peer; + struct NeighbourList * n; + double f; + int t; }; #define DEBUG_TRANSPORT GNUNET_NO -- 2.25.1