gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r14692 - in gnunet: . src/include src/transport


From: gnunet
Subject: [GNUnet-SVN] r14692 - in gnunet: . src/include src/transport
Date: Tue, 22 Mar 2011 19:36:57 +0100

Author: wachs
Date: 2011-03-22 19:36:57 +0100 (Tue, 22 Mar 2011)
New Revision: 14692

Modified:
   gnunet/configure.ac
   gnunet/src/include/gnunet_transport_service.h
   gnunet/src/transport/Makefile.am
   gnunet/src/transport/gnunet-service-transport.c
   gnunet/src/transport/test_transport_ats.c
   gnunet/src/transport/transport.h
Log:
ats

and changed configure script...does not work correctly...but at least detects 
when glpk is NOT installed


Modified: gnunet/configure.ac
===================================================================
--- gnunet/configure.ac 2011-03-21 15:08:40 UTC (rev 14691)
+++ gnunet/configure.ac 2011-03-22 18:36:57 UTC (rev 14692)
@@ -247,6 +247,17 @@
 # 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 @@
 # restore LIBS
 LIBS=$SAVE_LIBS
 
+
+
 # check for gettext
 AM_GNU_GETTEXT([external])
 AM_GNU_GETTEXT_VERSION([0.16.1])

Modified: gnunet/src/include/gnunet_transport_service.h
===================================================================
--- gnunet/src/include/gnunet_transport_service.h       2011-03-21 15:08:40 UTC 
(rev 14691)
+++ gnunet/src/include/gnunet_transport_service.h       2011-03-22 18:36:57 UTC 
(rev 14692)
@@ -390,13 +390,8 @@
   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
 
-
 /**
  * Function called by the transport for each received message.
  *

Modified: gnunet/src/transport/Makefile.am
===================================================================
--- gnunet/src/transport/Makefile.am    2011-03-21 15:08:40 UTC (rev 14691)
+++ gnunet/src/transport/Makefile.am    2011-03-22 18:36:57 UTC (rev 14692)
@@ -105,6 +105,10 @@
 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,11 +116,11 @@
   $(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 \
   libgnunet_plugin_transport_udp.la \

Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c     2011-03-21 15:08:40 UTC 
(rev 14691)
+++ gnunet/src/transport/gnunet-service-transport.c     2011-03-22 18:36:57 UTC 
(rev 14692)
@@ -38,6 +38,9 @@
 #include "gnunet_signatures.h"
 #include "gnunet_transport_plugin.h"
 #include "transport.h"
+#if HAVE_GLPK
+#include <glpk.h>
+#endif
 
 #define DEBUG_BLACKLIST GNUNET_YES
 
@@ -5546,6 +5549,153 @@
   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; c1<peers; c1++)
+       {
+               //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 (c2 = 1; c2 <= cols; c2++)
+               {
+                       //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "c1: %i c2 %i  
index: %i \n",c1 , c2, index);
+                       ia[index] = cur_row;
+                       ja[index] = c2;
+                       ar[index] = ((c1+1 == c2) ? 1.0 : 0.0);
+                       //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ia: %i ja %i  
ar: %f \n",cur_row , c2, ((c1+1 == c2) ? 1.0 : 0.0));
+                       index++;
+               }
+               cur_row++;
+       }
+
+       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CONST 3 \n");
+
+       start = index+1;
+       for (c1=0; c1<peers; c1++)
+       {
+               //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "row: %i \n", cur_row);
+               glp_set_row_bnds(lp, cur_row , GLP_LO, b_min, 0.0);
+
+               for (c2 = 1; c2 <= cols; c2++)
+               {
+                       //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "c1: %i c2 %i  
index: %i \n",c1 , c2, index);
+                       ia[index] = cur_row;
+                       ja[index] = c2;
+                       ar[index] = ((c1+1 == c2) ? 1.0 : 0.0);
+                       //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ia: %i ja %i  
ar: %f \n",cur_row , c2, ((c1+1 == c2) ? 1.0 : 0.0));
+                       index++;
+               }
+               cur_row++;
+       }
+
+       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CONST 4 \n");
+
+       start = index+1;
+       for (c1=0; c1<peers; c1++)
+       {
+
+               value = list[c1].f * r;
+               GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "row: %i %f\n", cur_row, 
value);
+               glp_set_row_bnds(lp, cur_row , GLP_LO, value, 0.0);
+
+               for (c2 = 1; c2 <= cols; c2++)
+               {
+                       //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "c1: %i c2 %i  
index: %i \n",c1 , c2, index);
+                       ia[index] = cur_row;
+                       ja[index] = c2;
+                       ar[index] = ((c1+1 == c2) ? (1.0/b_max) : 0.0);
+                       //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ia: %i ja %i  
ar: %f \n",cur_row , c2, ((c1+1 == c2) ? 1.0 : 0.0));
+                       index++;
+               }
+               cur_row++;
+       }
+
+       glp_load_matrix(lp, rows * cols, ia, ja, ar);
+
+       glp_simplex(lp, NULL);
+
+
+       printf("z = %g; ", glp_get_obj_val(lp));
+       for (c1=1; c1<= peers; c1++ )
+       {
+               printf("x%i = %g; ", c1, glp_get_col_prim(lp, c1));
+       }
+       glp_delete_prob(lp);
+       //GNUNET_free(options);
+       return lp;
+}
+#else
+void ats_create_problem(int peers, double b_min, double b_max, double r, const 
struct ATS_peer * list, int max_it, int max_dur)
+{
+
+}
+#endif
+
 void ats_calculate_bandwidth_distribution (struct ATS_info * ats)
 {
        struct GNUNET_TIME_Relative delta = 
GNUNET_TIME_absolute_get_difference(ats->last,GNUNET_TIME_absolute_get());
@@ -5559,6 +5709,29 @@
 #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 @@
       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);

Modified: gnunet/src/transport/test_transport_ats.c
===================================================================
--- gnunet/src/transport/test_transport_ats.c   2011-03-21 15:08:40 UTC (rev 
14691)
+++ gnunet/src/transport/test_transport_ats.c   2011-03-22 18:36:57 UTC (rev 
14692)
@@ -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 @@
   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 @@
                                           &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 @@
                       argv, "test-transport-api", "nohelp",
                       options, &run, &ok);
   stop_arm (&p1);
-  stop_arm (&p2);
+ // stop_arm (&p2);
 
   if (is_https)
   {

Modified: gnunet/src/transport/transport.h
===================================================================
--- gnunet/src/transport/transport.h    2011-03-21 15:08:40 UTC (rev 14691)
+++ gnunet/src/transport/transport.h    2011-03-22 18:36:57 UTC (rev 14692)
@@ -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_peer
 {
        struct GNUNET_PeerIdentity peer;
+       struct NeighbourList * n;
+       double f;
+       int     t;
 };
 
 #define DEBUG_TRANSPORT GNUNET_NO




reply via email to

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