aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-03-23 15:45:57 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-03-23 15:45:57 +0000
commit1f53960ac003ddd8cf164d07de7d01371cec8286 (patch)
tree674314a13969321b830d4fd1155b83c7649b2a09 /src/transport
parentb596c078b0d9d2ef9bae6afd2a343f78a311dd4e (diff)
downloadgnunet-1f53960ac003ddd8cf164d07de7d01371cec8286.tar.gz
gnunet-1f53960ac003ddd8cf164d07de7d01371cec8286.zip
more ATS
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport.c139
1 files changed, 98 insertions, 41 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 116482c60..919192e46 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -48,6 +48,13 @@
48 48
49#define DEBUG_TRANSPORT_HELLO GNUNET_YES 49#define DEBUG_TRANSPORT_HELLO GNUNET_YES
50 50
51#ifndef DEBUG_ATS
52#define DEBUG_ATS GNUNET_YES
53#else
54#undef DEBUG_ATS
55#define DEBUG_ATS GNUNET_YES
56#endif
57
51/** 58/**
52 * Should we do some additional checks (to validate behavior 59 * Should we do some additional checks (to validate behavior
53 * of clients)? 60 * of clients)?
@@ -5548,20 +5555,25 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5548 GNUNET_break (bl_head == NULL); 5555 GNUNET_break (bl_head == NULL);
5549 GNUNET_break (bc_head == NULL); 5556 GNUNET_break (bc_head == NULL);
5550} 5557}
5551#if !HAVE_LIBGLPK
5552 5558
5553void ats_create_problem(int peers, double b_min, double b_max, double r, const struct ATS_peer * list, int max_it, int max_dur) 5559struct ATS_transports
5554{ 5560{
5561 int id;
5562 double c_max;
5563 double c_1;
5564};
5555 5565
5556} 5566#define FUNCTION ats_create_problem (int peers, int transports, double b_min, double b_max, double r, double R, const struct ATS_peer * pl, const struct ATS_transports * tl, int max_it, int max_dur)
5557#else 5567
5558glp_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) 5568#if HAVE_LIBGLPK
5569glp_prob * FUNCTION
5559{ 5570{
5571 int result = GLP_UNDEF;
5560 int c1, c2; 5572 int c1, c2;
5561 glp_prob *lp; 5573 glp_prob *lp;
5562 char * transport; 5574 char * peer_n;
5563 5575
5564 int rows = 1 + peers + peers + peers; 5576 int rows = 1 + (3*peers) + (transports);
5565 int cols = peers; 5577 int cols = peers;
5566 int index = 1; 5578 int index = 1;
5567 int start = 0; 5579 int start = 0;
@@ -5572,18 +5584,16 @@ glp_prob * ats_create_problem (int peers, double b_min, double b_max, double r,
5572 double value; 5584 double value;
5573 5585
5574 /* Setting options */ 5586 /* Setting options */
5575/* glp_smcp * options = GNUNET_malloc( sizeof (glp_smcp)); 5587 glp_smcp * options = GNUNET_malloc( sizeof (glp_smcp));
5588 glp_init_smcp(options);
5589
5576 // max iterations 5590 // max iterations
5577 options->it_lim = max_it; 5591 options->it_lim = max_it;
5578 // max durations 5592 // max durations
5579 options->tm_lim = max_it; 5593 options->tm_lim = max_dur;
5580 options->msg_lev = GLP_MSG_OFF; 5594 options->msg_lev = GLP_MSG_ALL;
5581 options->meth = GLP_PRIMAL;
5582 options->pricing = GLP_PT_PSE;
5583 options->r_test = GLP_RT_HAR;
5584 options->tol_bnd =
5585*/
5586 5595
5596 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating LP problem: %i peers, relativity r %3.2f, b_max %5.2f, b_min %5.2f, \n",peers, r, b_max, b_min);
5587 lp = glp_create_prob(); 5597 lp = glp_create_prob();
5588 glp_set_prob_name(lp, "gnunet ats bandwidth distribution"); 5598 glp_set_prob_name(lp, "gnunet ats bandwidth distribution");
5589 glp_set_obj_dir(lp, GLP_MAX); 5599 glp_set_obj_dir(lp, GLP_MAX);
@@ -5592,15 +5602,17 @@ glp_prob * ats_create_problem (int peers, double b_min, double b_max, double r,
5592 glp_add_cols(lp, cols); 5602 glp_add_cols(lp, cols);
5593 for (c1=1; c1<=cols; c1++) 5603 for (c1=1; c1<=cols; c1++)
5594 { 5604 {
5595 GNUNET_asprintf(&transport,"Peer %s",GNUNET_i2s(&list[c1-1].peer)); 5605 GNUNET_asprintf(&peer_n,"%s",GNUNET_i2s(&pl[c1-1].peer));
5596 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ats_create_problem Peer[%i] : %s \n",c1-1 , transport); 5606 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer[%i] , transport %i, %s: f: %f\n",c1-1 , pl[c1-1].t, peer_n, pl[c1-1].f);
5597 /* add a single transport */ 5607 /* add a single transport */
5598 glp_set_col_name(lp, c1, transport); 5608 glp_set_col_name(lp, c1, peer_n);
5599 /* add a lower bound */ 5609 /* add a lower bound */
5600 glp_set_col_bnds(lp, c1, GLP_LO, 0.0, 0.0); 5610 glp_set_col_bnds(lp, c1, GLP_LO, 0.0, 0.0);
5601 /* set coefficient function */ 5611 /* set coefficient function */
5602 glp_set_obj_coef(lp, c1, 1.0); 5612 value = pl[c1-1].f/b_max;
5603 GNUNET_free(transport); 5613 value = 1.0;
5614 glp_set_obj_coef(lp, c1, value);
5615 GNUNET_free(peer_n);
5604 } 5616 }
5605 5617
5606 5618
@@ -5608,7 +5620,7 @@ glp_prob * ats_create_problem (int peers, double b_min, double b_max, double r,
5608 glp_add_rows(lp, rows); 5620 glp_add_rows(lp, rows);
5609 cur_row = 1; 5621 cur_row = 1;
5610 5622
5611 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "row: %i \n", cur_row); 5623 // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "row: %i \n", cur_row);
5612 glp_set_row_bnds(lp, cur_row, GLP_UP, 0.0, b_max); 5624 glp_set_row_bnds(lp, cur_row, GLP_UP, 0.0, b_max);
5613 for (index=1; index<=cols; index++) 5625 for (index=1; index<=cols; index++)
5614 { 5626 {
@@ -5635,8 +5647,6 @@ glp_prob * ats_create_problem (int peers, double b_min, double b_max, double r,
5635 cur_row++; 5647 cur_row++;
5636 } 5648 }
5637 5649
5638 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CONST 3 \n");
5639
5640 start = index+1; 5650 start = index+1;
5641 for (c1=0; c1<peers; c1++) 5651 for (c1=0; c1<peers; c1++)
5642 { 5652 {
@@ -5655,14 +5665,12 @@ glp_prob * ats_create_problem (int peers, double b_min, double b_max, double r,
5655 cur_row++; 5665 cur_row++;
5656 } 5666 }
5657 5667
5658 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CONST 4 \n");
5659
5660 start = index+1; 5668 start = index+1;
5661 for (c1=0; c1<peers; c1++) 5669 for (c1=0; c1<peers; c1++)
5662 { 5670 {
5663 5671
5664 value = list[c1].f * r; 5672 value = pl[c1].f * r;
5665 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "row: %i %f\n", cur_row, value); 5673 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "row: %i %f\n", cur_row, value);
5666 glp_set_row_bnds(lp, cur_row , GLP_LO, value, 0.0); 5674 glp_set_row_bnds(lp, cur_row , GLP_LO, value, 0.0);
5667 5675
5668 for (c2 = 1; c2 <= cols; c2++) 5676 for (c2 = 1; c2 <= cols; c2++)
@@ -5677,22 +5685,48 @@ glp_prob * ats_create_problem (int peers, double b_min, double b_max, double r,
5677 cur_row++; 5685 cur_row++;
5678 } 5686 }
5679 5687
5680 glp_load_matrix(lp, rows * cols, ia, ja, ar); 5688 /* transport capacity sum of b * c_i < c_max */
5689 start = index+1;
5690 for (c1=0; c1<transports; c1++)
5691 {
5681 5692
5682 glp_simplex(lp, NULL); 5693 value = tl[c1].c_max;
5694 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Transport %i: c_max %5.2f c_1 %5.2f \n", c1, value, tl[c1].c_1);
5695 glp_set_row_bnds(lp, cur_row , GLP_UP, 0.0 , value);
5683 5696
5697 for (c2 = 1; c2 <= cols; c2++)
5698 {
5699 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "c1: %i c2 %i index: %i \n",c1 , c2, index);
5700 ia[index] = cur_row;
5701 ja[index] = c2;
5702 ar[index] = ((pl[c1-1].t == tl[c1].id) ? (tl[c1].c_1) : 0.0);
5703 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ia: %i ja %i ar: %f \n",cur_row , c2, ((c1+1 == c2) ? 1.0 : 0.0));
5704 index++;
5705 }
5706 cur_row++;
5707 }
5708
5709 glp_load_matrix(lp, rows * cols, ia, ja, ar);
5710
5711 result = glp_simplex(lp, options);
5684 5712
5685 printf("z = %g; ", glp_get_obj_val(lp));
5686 for (c1=1; c1<= peers; c1++ ) 5713 for (c1=1; c1<= peers; c1++ )
5687 { 5714 {
5688 printf("x%i = %g; ", c1, glp_get_col_prim(lp, c1)); 5715 printf("x%i = %g; ", c1, glp_get_col_prim(lp, c1));
5689 } 5716 }
5717 printf("z = %g; \n", glp_get_obj_val(lp));
5690 glp_delete_prob(lp); 5718 glp_delete_prob(lp);
5691 //GNUNET_free(options); 5719 GNUNET_free(options);
5692 return lp; 5720 return lp;
5693} 5721}
5722#else
5723void * FUNCTION
5724{
5725
5726}
5694#endif 5727#endif
5695 5728
5729
5696void ats_calculate_bandwidth_distribution (struct ATS_info * ats) 5730void ats_calculate_bandwidth_distribution (struct ATS_info * ats)
5697{ 5731{
5698 struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference(ats->last,GNUNET_TIME_absolute_get()); 5732 struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference(ats->last,GNUNET_TIME_absolute_get());
@@ -5707,33 +5741,56 @@ void ats_calculate_bandwidth_distribution (struct ATS_info * ats)
5707 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CALCULATE DISTRIBUTION\n"); 5741 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CALCULATE DISTRIBUTION\n");
5708#endif 5742#endif
5709 5743
5710 int transports = 9; 5744 int peers = 3;
5745 int transports = 3;
5746
5711 double b_min = 10; 5747 double b_min = 10;
5712 double b_max = 100.0; 5748 double b_max = 100.0;
5713 double r = 0.8; 5749 double r = 0.85;//1.0;
5750 double R = 1.0;
5714 5751
5715 int it = 50; 5752 int it = 50;
5716 int dur = 500; 5753 int dur = 500;
5717 5754
5718 struct ATS_peer * list = GNUNET_malloc(transports * sizeof (struct ATS_peer)); 5755 struct ATS_transports * tl = GNUNET_malloc(transports * sizeof (struct ATS_peer));
5756
5757 struct ATS_peer * pl = GNUNET_malloc(peers * sizeof (struct ATS_peer));
5719 int c = 0; 5758 int c = 0;
5720 while (c < transports) 5759 while (c < peers)
5721 { 5760 {
5722 list[c].peer.hashPubKey.bits[0] = c+1; 5761 pl[c].peer.hashPubKey.bits[0] = c+1;
5723 list[c].f = 1 / (double) transports; 5762 pl[c].f = 1 / (double) peers ;
5763 pl[c].t = 1;
5724 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ats_calculate_bandwidth_distribution Peer[%i] : %s %p \n",c , GNUNET_i2s(&list[c].peer), &list[c].peer); 5764 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ats_calculate_bandwidth_distribution Peer[%i] : %s %p \n",c , GNUNET_i2s(&list[c].peer), &list[c].peer);
5725 c++; 5765 c++;
5726 } 5766 }
5767 c = 0;
5768 while (c < transports)
5769 {
5770 tl[c].id = c;
5771 tl[c].c_max = 100;
5772 tl[c].c_1 = 1;
5773 c++;
5774 }
5775
5776 // test //
5727 5777
5728 ats_create_problem(transports, b_min, b_max, r, list, it, dur); 5778 pl[0].f = 0.33;
5779 pl[2].f = 0.43;
5780 pl[1].f = 0.33;
5781 // test //
5729 5782
5730 GNUNET_free (list); 5783 ats_create_problem(peers, transports, b_min, b_max, r, R, pl, tl, it, dur);
5784
5785 GNUNET_free (pl);
5786 GNUNET_free (tl);
5731 5787
5732 ats->last = GNUNET_TIME_absolute_get(); 5788 ats->last = GNUNET_TIME_absolute_get();
5733 5789
5734} 5790}
5735 5791
5736 5792
5793
5737void 5794void
5738ats_schedule_calculation (void *cls, 5795ats_schedule_calculation (void *cls,
5739 const struct GNUNET_SCHEDULER_TaskContext *tc) 5796 const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -5872,13 +5929,13 @@ struct ForeignAddressList * ats_get_preferred_address (struct ATS_info * ats,
5872 struct NeighbourList *n) 5929 struct NeighbourList *n)
5873{ 5930{
5874#if DEBUG_ATS 5931#if DEBUG_ATS
5875 GNUNET_log (GNUNET_ERROR_TYPE_BULK, "ats_get_prefered_transport for peer: %s\n",GNUNET_i2s(&n->id)); 5932 //GNUNET_log (GNUNET_ERROR_TYPE_BULK, "ats_get_prefered_transport for peer: %s\n",GNUNET_i2s(&n->id));
5876#endif 5933#endif
5877 struct ReadyList *next = n->plugins; 5934 struct ReadyList *next = n->plugins;
5878 while (next != NULL) 5935 while (next != NULL)
5879 { 5936 {
5880#if DEBUG_ATS 5937#if DEBUG_ATS
5881 GNUNET_log (GNUNET_ERROR_TYPE_BULK, "plugin: %s %i\n",next->plugin->short_name,strcmp(next->plugin->short_name,"unix")); 5938 //GNUNET_log (GNUNET_ERROR_TYPE_BULK, "plugin: %s %i\n",next->plugin->short_name,strcmp(next->plugin->short_name,"unix"));
5882#endif 5939#endif
5883 next = next->next; 5940 next = next->next;
5884 } 5941 }