aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-04-13 12:12:12 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-04-13 12:12:12 +0000
commit669c0c17bf9f9bcdd315767f4223c10c0034deff (patch)
tree5f091380308b7dab98c4f87e5535f481b82a3812 /src/transport
parentd47e8be9228c131f93441743c8e90b360d554e9d (diff)
downloadgnunet-669c0c17bf9f9bcdd315767f4223c10c0034deff.tar.gz
gnunet-669c0c17bf9f9bcdd315767f4223c10c0034deff.zip
optimized code
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport.c378
1 files changed, 222 insertions, 156 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 80bdb8edf..3b30b6096 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -995,6 +995,9 @@ struct ATS_info
995#if HAVE_LIBGLPK 995#if HAVE_LIBGLPK
996 glp_prob *prob; 996 glp_prob *prob;
997#endif 997#endif
998
999 struct ATS_mechanism * mechanisms;
1000 struct ATS_peer * peers;
998}; 1001};
999 1002
1000 1003
@@ -1113,9 +1116,6 @@ static void disconnect_neighbour (struct NeighbourList *n, int check);
1113 */ 1116 */
1114static void try_transmission_to_peer (struct NeighbourList *n); 1117static void try_transmission_to_peer (struct NeighbourList *n);
1115 1118
1116
1117static void ats_init ();
1118
1119static void ats_shutdown ( ); 1119static void ats_shutdown ( );
1120 1120
1121static void ats_notify_peer_connect ( 1121static void ats_notify_peer_connect (
@@ -1132,6 +1132,9 @@ static void ats_notify_ats_data (
1132struct ForeignAddressList * ats_get_preferred_address ( 1132struct ForeignAddressList * ats_get_preferred_address (
1133 struct NeighbourList *n); 1133 struct NeighbourList *n);
1134 1134
1135static void
1136ats_calculate_bandwidth_distribution ();
1137
1135/** 1138/**
1136 * Find an entry in the neighbour list for a particular peer. 1139 * Find an entry in the neighbour list for a particular peer.
1137 * 1140 *
@@ -1148,35 +1151,66 @@ find_neighbour (const struct GNUNET_PeerIdentity *key)
1148 return head; 1151 return head;
1149} 1152}
1150 1153
1151static void update_addr_ats (struct ForeignAddressList *fal, const struct GNUNET_TRANSPORT_ATS_Information *ats_data, int ats_count) 1154static int update_addr_ats (struct ForeignAddressList *fal, const struct GNUNET_TRANSPORT_ATS_Information *ats_data, int ats_count)
1152{ 1155{
1153 int c1, c2; 1156 int c1, c2, set;
1157 set = GNUNET_NO;
1154 for (c1=0; c1<ats_count; c1++) 1158 for (c1=0; c1<ats_count; c1++)
1155 { 1159 {
1156 for (c2=0; c2<available_quality_metrics; c2++) 1160 for (c2=0; c2<available_quality_metrics; c2++)
1157 { 1161 {
1158 if (ntohl(ats_data[c1].type) == qm[c2].atis_index) 1162 if (ntohl(ats_data[c1].type) == qm[c2].atis_index)
1159 { 1163 {
1160 fal->quality[c2].values[0] = fal->quality[c2].values[1]; 1164 /* shifting history */
1161 fal->quality[c2].values[1] = fal->quality[c2].values[2]; 1165// fal->quality[c2].values[0] = fal->quality[c2].values[1];
1162 fal->quality[c2].values[2] = ntohl(ats_data[c1].value); 1166// fal->quality[c2].values[1] = fal->quality[c2].values[2];
1167 /* setting latest value */
1168// fal->quality[c2].values[2] = ntohl(ats_data[c1].value);
1169// set = GNUNET_YES;
1170 }
1171 }
1172 if (set == GNUNET_NO)
1173 {
1174 for (c2=0; c2<available_ressources; c2++)
1175 {
1176 if (ntohl(ats_data[c1].type) == ressources[c2].atis_index)
1177 {
1178 //fal->ressources[c2].c = ntohl(ats_data[c1].value);
1179 //set = GNUNET_YES;
1180 }
1163 } 1181 }
1164 } 1182 }
1165 } 1183 }
1184 return set;
1166} 1185}
1167 1186
1168static void update_addr_value (struct ForeignAddressList *fal, uint32_t value , int ats_index) 1187static int update_addr_value (struct ForeignAddressList *fal, uint32_t value , int ats_index)
1169{ 1188{
1170 int c; 1189 int c;
1190 int set = GNUNET_NO;
1171 for (c=0; c<available_quality_metrics; c++) 1191 for (c=0; c<available_quality_metrics; c++)
1172 { 1192 {
1173 if (ats_index == qm[c].atis_index) 1193 if (ats_index == qm[c].atis_index)
1174 { 1194 {
1175 fal->quality[c].values[0] = fal->quality[c].values[1]; 1195// fal->quality[c].values[0] = fal->quality[c].values[1];
1176 fal->quality[c].values[1] = fal->quality[c].values[2]; 1196// fal->quality[c].values[1] = fal->quality[c].values[2];
1177 fal->quality[c].values[2] = value; 1197// fal->quality[c].values[2] = value;
1198 set = GNUNET_YES;
1199 }
1200 }
1201 if (set == GNUNET_NO)
1202 {
1203 for (c=0; c<available_ressources; c++)
1204 {
1205 if (ats_index == ressources[c].atis_index)
1206 {
1207// fal->ressources[c].c = value;
1208// set = GNUNET_YES;
1209 }
1178 } 1210 }
1179 } 1211 }
1212
1213 return set;
1180} 1214}
1181 1215
1182/** 1216/**
@@ -5868,34 +5902,39 @@ static int ats_evaluate_results (int result, int solution, char * problem)
5868 cont=GNUNET_YES; 5902 cont=GNUNET_YES;
5869 break; 5903 break;
5870 case GLP_FEAS: 5904 case GLP_FEAS:
5871 GNUNET_log (error_kind, "%s solution is integer feasible, however, its optimality (or non-optimality) has not been proven, \n", problem); 5905 GNUNET_log (error_kind, "%s solution is %s feasible, however, its optimality (or non-optimality) has not been proven, \n", problem, (0==strcmp(problem,"LP")?"":"integer"));
5872 cont=GNUNET_YES; 5906 cont=GNUNET_YES;
5873 break; 5907 break;
5874 case GLP_NOFEAS: 5908 case GLP_NOFEAS:
5875 GNUNET_log (error_kind, "%s problem has no integer feasible solution\n", problem); 5909 GNUNET_log (error_kind, "%s problem has no %sfeasible solution\n", problem, (0==strcmp(problem,"LP")?"":"integer "));
5876 break; 5910 break;
5911 case GLP_INFEAS:
5912 GNUNET_log (error_kind, "%s problem is infeasible \n", problem);
5877 break; 5913 break;
5914 case GLP_UNBND:
5915 GNUNET_log (error_kind, "%s problem is unbounded \n", problem);
5878 default: 5916 default:
5879 break; 5917 break;
5880 } 5918 }
5881return cont; 5919return cont;
5882} 5920}
5883#endif
5884 5921
5885#if HAVE_LIBGLPK 5922
5886static void ats_solve_problem (unsigned int max_it, unsigned int max_dur, unsigned int c_peers, unsigned int c_mechs, struct ATS_result *res) 5923static void ats_solve_problem (unsigned int max_it, unsigned int max_dur, unsigned int c_peers, unsigned int c_mechs, struct ATS_result *res)
5887{ 5924{
5888 int result; 5925 int result;
5889 int solution; 5926 int solution;
5927 int c;
5890 5928
5891 // Solving simplex 5929 // Solving simplex
5892 glp_prob *prob = ats->prob; 5930 glp_prob *prob = ats->prob;
5893 5931
5894 glp_smcp opt_lp; 5932 glp_smcp opt_lp;
5895 glp_init_smcp(&opt_lp); 5933 glp_init_smcp(&opt_lp);
5896#if VERBOSE_ATS 5934
5897 opt_lp.msg_lev = GLP_MSG_ALL; 5935 opt_lp.msg_lev = GLP_MSG_ALL;
5898#else 5936#if VERBOSE_ATS
5937 #else
5899 opt_lp.msg_lev = GLP_MSG_OFF; 5938 opt_lp.msg_lev = GLP_MSG_OFF;
5900#endif 5939#endif
5901 //opt_lp.presolve = GLP_ON; 5940 //opt_lp.presolve = GLP_ON;
@@ -5911,9 +5950,10 @@ static void ats_solve_problem (unsigned int max_it, unsigned int max_dur, unsig
5911 //opt_mlp.presolve = GLP_ON; 5950 //opt_mlp.presolve = GLP_ON;
5912 opt_mlp.tm_lim = max_dur; 5951 opt_mlp.tm_lim = max_dur;
5913 /* output level */ 5952 /* output level */
5914#if VERBOSE_ATS 5953
5915 opt_mlp.msg_lev = GLP_MSG_ALL; 5954 opt_mlp.msg_lev = GLP_MSG_ALL;
5916#else 5955#if VERBOSE_ATS
5956 #else
5917 opt_mlp.msg_lev = GLP_MSG_OFF; 5957 opt_mlp.msg_lev = GLP_MSG_OFF;
5918#endif 5958#endif
5919 result = glp_intopt (prob, &opt_mlp); 5959 result = glp_intopt (prob, &opt_mlp);
@@ -5928,16 +5968,16 @@ static void ats_solve_problem (unsigned int max_it, unsigned int max_dur, unsig
5928 if ((ats->save_mlp == GNUNET_YES) && (c_peers > 1)) 5968 if ((ats->save_mlp == GNUNET_YES) && (c_peers > 1))
5929 { 5969 {
5930 char * filename; 5970 char * filename;
5931 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%llu.mlp",c_peers, c_mechs, GNUNET_TIME_absolute_get().abs_value); 5971 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_llu.mlp",c_peers, c_mechs, GNUNET_TIME_absolute_get().abs_value);
5932 if (GNUNET_NO == GNUNET_DISK_file_test(filename)) 5972 //if (GNUNET_NO == GNUNET_DISK_file_test(filename))
5933 glp_write_lp (prob, NULL, filename); 5973 glp_write_lp (prob, NULL, filename);
5934 GNUNET_free (filename); 5974 GNUNET_free (filename);
5935 } 5975 }
5936 if ((ats->save_solution == GNUNET_YES) && (c_peers > 1)) 5976 if ((ats->save_solution == GNUNET_YES) && (c_peers > 1))
5937 { 5977 {
5938 char * filename; 5978 char * filename;
5939 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%llu.sol",c_peers, c_mechs, GNUNET_TIME_absolute_get().abs_value); 5979 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_llu.sol",c_peers, c_mechs, GNUNET_TIME_absolute_get().abs_value);
5940 if (GNUNET_NO == GNUNET_DISK_file_test(filename)) 5980 //if (GNUNET_NO == GNUNET_DISK_file_test(filename))
5941 glp_print_sol (prob, filename); 5981 glp_print_sol (prob, filename);
5942 GNUNET_free (filename); 5982 GNUNET_free (filename);
5943 } 5983 }
@@ -5983,10 +6023,47 @@ static void ats_solve_problem (unsigned int max_it, unsigned int max_dur, unsig
5983 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n", glp_get_col_name(prob,2*c_mechs+3), glp_get_col_prim(prob,2*c_mechs+3)); 6023 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n", glp_get_col_name(prob,2*c_mechs+3), glp_get_col_prim(prob,2*c_mechs+3));
5984#endif 6024#endif
5985} 6025}
5986#endif 6026
6027static void ats_delete_problem ()
6028{
6029 int c;
6030
6031 for (c=0; c< (ats->res).c_mechs; c++)
6032 GNUNET_free_non_null (ats->mechanisms[c].rc);
6033
6034 if (ats->mechanisms!=NULL)
6035 {
6036 GNUNET_free(ats->mechanisms);
6037 ats->mechanisms = NULL;
6038 }
6039 if (ats->peers!=NULL)
6040 {
6041 GNUNET_free(ats->peers);
6042 ats->peers = NULL;
6043 }
6044
6045 if (ats->prob != NULL)
6046 {
6047 glp_delete_prob(ats->prob);
6048 ats->prob = NULL;
6049 }
6050
6051 ats->res.begin_cr = GNUNET_SYSERR;
6052 ats->res.begin_qm = GNUNET_SYSERR;
6053 ats->res.c_mechs = 0;
6054 ats->res.c_peers = 0;
6055 ats->res.end_cr = GNUNET_SYSERR;
6056 ats->res.end_qm = GNUNET_SYSERR;
6057 ats->res.solution = GNUNET_SYSERR;
6058 ats->res.valid = GNUNET_SYSERR;
6059}
6060
6061static void ats_update_problem ()
6062{
6063
6064}
5987 6065
5988 6066
5989#if HAVE_LIBGLPK
5990/** solve the bandwidth distribution problem 6067/** solve the bandwidth distribution problem
5991 * @param max_it maximum iterations 6068 * @param max_it maximum iterations
5992 * @param max_dur maximum duration in ms 6069 * @param max_dur maximum duration in ms
@@ -6000,14 +6077,6 @@ static void ats_solve_problem (unsigned int max_it, unsigned int max_dur, unsig
6000 */ 6077 */
6001static int ats_create_problem (double D, double U, double R, int v_b_min, int v_n_min, struct ATS_result *res) 6078static int ats_create_problem (double D, double U, double R, int v_b_min, int v_n_min, struct ATS_result *res)
6002{ 6079{
6003#if !HAVE_LIBGLPK
6004 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "no glpk installed\n");
6005 return GNUNET_SYSERR;
6006#else
6007#if DEBUG_ATS
6008 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "glpk installed\n");
6009#endif
6010
6011 if (ats->prob != NULL) 6080 if (ats->prob != NULL)
6012 glp_delete_prob(ats->prob); 6081 glp_delete_prob(ats->prob);
6013 6082
@@ -6051,11 +6120,16 @@ static int ats_create_problem (double D, double U, double R, int v_b_min, int v_
6051 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No addresses for bw distribution available\n", c_peers); 6120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No addresses for bw distribution available\n", c_peers);
6052#endif 6121#endif
6053 res->valid = GNUNET_NO; 6122 res->valid = GNUNET_NO;
6123 res->c_peers = 0;
6124 res->c_mechs = 0;
6054 return GNUNET_SYSERR; 6125 return GNUNET_SYSERR;
6055 } 6126 }
6056 6127
6057 struct ATS_mechanism * mechanisms = GNUNET_malloc((1+c_mechs) * sizeof (struct ATS_mechanism)); 6128 ats->mechanisms = GNUNET_malloc((1+c_mechs) * sizeof (struct ATS_mechanism));
6058 struct ATS_peer * peers = GNUNET_malloc((1+c_peers) * sizeof (struct ATS_peer)); 6129 ats->peers = GNUNET_malloc((1+c_peers) * sizeof (struct ATS_peer));
6130
6131 struct ATS_mechanism * mechanisms = ats->mechanisms;
6132 struct ATS_peer * peers = ats->peers;
6059 6133
6060 c_mechs = 1; 6134 c_mechs = 1;
6061 c_peers = 1; 6135 c_peers = 1;
@@ -6120,7 +6194,7 @@ static int ats_create_problem (double D, double U, double R, int v_b_min, int v_
6120 glp_set_col_name(ats->prob, c, name); 6194 glp_set_col_name(ats->prob, c, name);
6121 GNUNET_free (name); 6195 GNUNET_free (name);
6122 glp_set_col_bnds(ats->prob, c, GLP_LO, 0.0, 0.0); 6196 glp_set_col_bnds(ats->prob, c, GLP_LO, 0.0, 0.0);
6123 glp_set_obj_coef(ats->prob, c, 1); 6197 glp_set_obj_coef(ats->prob, c, 0);
6124 6198
6125 } 6199 }
6126 /* adding n_t cols */ 6200 /* adding n_t cols */
@@ -6265,31 +6339,16 @@ static int ats_create_problem (double D, double U, double R, int v_b_min, int v_
6265 } 6339 }
6266 row_index ++; 6340 row_index ++;
6267 6341
6268 /* optimisation constraints*/ 6342 // optimisation constraints
6269 6343
6270 /* adding columns */ 6344 // adding columns
6271 glp_add_cols(ats->prob, 3 + c_q_metrics); 6345 //glp_add_cols(ats->prob, 3 + c_q_metrics);
6272 6346
6347 // Constraint 6: optimize for diversity
6348 glp_add_cols(ats->prob, 1);
6273 glp_set_col_name(ats->prob, (2*c_mechs) + 1, "d"); 6349 glp_set_col_name(ats->prob, (2*c_mechs) + 1, "d");
6274 glp_set_obj_coef(ats->prob, (2*c_mechs) + 1, D); 6350 glp_set_obj_coef(ats->prob, (2*c_mechs) + 1, D);
6275 glp_set_col_bnds(ats->prob, (2*c_mechs) + 1, GLP_LO, 0.0, 0.0); 6351 glp_set_col_bnds(ats->prob, (2*c_mechs) + 1, GLP_LO, 0.0, 0.0);
6276 glp_set_col_name(ats->prob, (2*c_mechs) + 2, "u");
6277 glp_set_obj_coef(ats->prob, (2*c_mechs) + 2, U);
6278 glp_set_col_bnds(ats->prob, (2*c_mechs) + 2, GLP_LO, 0.0, 0.0);
6279 glp_set_col_name(ats->prob, (2*c_mechs) + 3, "r");
6280 glp_set_obj_coef(ats->prob, (2*c_mechs) + 3, R);
6281 glp_set_col_bnds(ats->prob, (2*c_mechs) + 3, GLP_LO, 0.0, 0.0);
6282
6283 for (c=1; c<= c_q_metrics; c++)
6284 {
6285 GNUNET_asprintf(&name, "Q_%s",qm[c-1].name);
6286 glp_set_col_name(ats->prob, (2*c_mechs) + 3 + c, name);
6287 glp_set_col_bnds(ats->prob, (2*c_mechs) + 3 + c, GLP_LO, 0.0, 0.0);
6288 GNUNET_free (name);
6289 glp_set_obj_coef(ats->prob, (2*c_mechs) + 3 + c, Q[c]);
6290 }
6291
6292 // Constraint 6: optimize for diversity
6293 glp_add_rows(ats->prob, 1); 6352 glp_add_rows(ats->prob, 1);
6294#if VERBOSE_ATS 6353#if VERBOSE_ATS
6295 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index); 6354 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index);
@@ -6315,8 +6374,79 @@ static int ats_create_problem (double D, double U, double R, int v_b_min, int v_
6315 array_index++; 6374 array_index++;
6316 row_index ++; 6375 row_index ++;
6317 6376
6377 // Constraint 8: optimize bandwidth utility
6378 glp_add_cols(ats->prob, 1);
6379 glp_set_col_name(ats->prob, (2*c_mechs) + 2, "u");
6380 glp_set_obj_coef(ats->prob, (2*c_mechs) + 2, U);
6381 glp_set_col_bnds(ats->prob, (2*c_mechs) + 2, GLP_LO, 0.0, 0.0);
6382 glp_add_rows(ats->prob, 1);
6383#if VERBOSE_ATS
6384 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index);
6385#endif
6386 glp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
6387 for (c=1; c<=c_mechs; c++)
6388 {
6389 ia[array_index] = row_index;
6390 ja[array_index] = c;
6391 ar[array_index] = mechanisms[c].peer->f;
6392#if VERBOSE_ATS
6393 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",array_index, ia[array_index], ja[array_index], ar[array_index]);
6394#endif
6395 array_index++;
6396 }
6397 ia[array_index] = row_index;
6398 ja[array_index] = (2*c_mechs) + 2;
6399 ar[array_index] = -1;
6400#if VERBOSE_ATS
6401 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",array_index, ia[array_index], ja[array_index], ar[array_index]);
6402#endif
6403
6404 array_index++;
6405 row_index ++;
6406
6407 // Constraint 9: optimize relativity
6408 glp_add_cols(ats->prob, 1);
6409 glp_set_col_name(ats->prob, (2*c_mechs) + 3, "r");
6410 glp_set_obj_coef(ats->prob, (2*c_mechs) + 3, R);
6411 glp_set_col_bnds(ats->prob, (2*c_mechs) + 3, GLP_LO, 0.0, 0.0);
6412 glp_add_rows(ats->prob, c_peers);
6413 for (c=1; c<=c_peers; c++)
6414 {
6415 glp_set_row_bnds(ats->prob, row_index, GLP_LO, 0.0, 0.0);
6416
6417 struct ATS_mechanism *m = peers[c].m_head;
6418 while (m!=NULL)
6419 {
6420 ia[array_index] = row_index;
6421 ja[array_index] = m->col_index;
6422 ar[array_index] = 1 / mechanisms[c].peer->f;
6423#if VERBOSE_ATS
6424 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",array_index, ia[array_index], ja[array_index], ar[array_index]);
6425#endif
6426 array_index++;
6427 m = m->next;
6428 }
6429 ia[array_index] = row_index;
6430 ja[array_index] = (2*c_mechs) + 3;
6431 ar[array_index] = -1;
6432#if VERBOSE_ATS
6433 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",array_index, ia[array_index], ja[array_index], ar[array_index]);
6434#endif
6435 array_index++;
6436
6437 row_index++;
6438 }
6318 6439
6319 // Constraint 7: optimize for quality 6440 // Constraint 7: optimize for quality
6441 glp_add_cols(ats->prob, c_q_metrics);
6442 for (c=1; c<= c_q_metrics; c++)
6443 {
6444 GNUNET_asprintf(&name, "Q_%s",qm[c-1].name);
6445 glp_set_col_name(ats->prob, (2*c_mechs) + 3 + c, name);
6446 glp_set_col_bnds(ats->prob, (2*c_mechs) + 3 + c, GLP_LO, 0.0, 0.0);
6447 GNUNET_free (name);
6448 glp_set_obj_coef(ats->prob, (2*c_mechs) + 3 + c, Q[c]);
6449 }
6320 glp_add_rows(ats->prob, available_quality_metrics); 6450 glp_add_rows(ats->prob, available_quality_metrics);
6321 res->begin_qm = array_index; 6451 res->begin_qm = array_index;
6322 for (c=1; c <= c_q_metrics; c++) 6452 for (c=1; c <= c_q_metrics; c++)
@@ -6324,11 +6454,11 @@ static int ats_create_problem (double D, double U, double R, int v_b_min, int v_
6324#if VERBOSE_ATS 6454#if VERBOSE_ATS
6325 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index); 6455 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index);
6326#endif 6456#endif
6457 double value = 1;
6327 glp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0); 6458 glp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
6328
6329 for (c2=1; c2<=c_mechs; c2++) 6459 for (c2=1; c2<=c_mechs; c2++)
6330 { 6460 {
6331 double value = 0; 6461
6332 ia[array_index] = row_index; 6462 ia[array_index] = row_index;
6333 ja[array_index] = c2; 6463 ja[array_index] = c2;
6334 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) 6464 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY)
@@ -6341,6 +6471,7 @@ static int ats_create_problem (double D, double U, double R, int v_b_min, int v_
6341 v2 = mechanisms[c2].addr->quality[c-1].values[2]; 6471 v2 = mechanisms[c2].addr->quality[c-1].values[2];
6342 if (v1 < 1) v0 = 0.1; 6472 if (v1 < 1) v0 = 0.1;
6343 value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0); 6473 value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0);
6474 value = 1;
6344 } 6475 }
6345 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) 6476 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
6346 { 6477 {
@@ -6373,62 +6504,8 @@ static int ats_create_problem (double D, double U, double R, int v_b_min, int v_
6373 array_index++; 6504 array_index++;
6374 row_index++; 6505 row_index++;
6375 } 6506 }
6376 res->end_qm = array_index--; 6507 res->end_qm = array_index-1;
6377
6378 // Constraint 8: optimize bandwidth utility
6379 glp_add_rows(ats->prob, 1);
6380#if VERBOSE_ATS
6381 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index);
6382#endif
6383 glp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
6384 for (c=1; c<=c_mechs; c++)
6385 {
6386 ia[array_index] = row_index;
6387 ja[array_index] = c;
6388 ar[array_index] = mechanisms[c].peer->f;
6389#if VERBOSE_ATS
6390 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",array_index, ia[array_index], ja[array_index], ar[array_index]);
6391#endif
6392 array_index++;
6393 }
6394 ia[array_index] = row_index;
6395 ja[array_index] = (2*c_mechs) + 2;
6396 ar[array_index] = -1;
6397#if VERBOSE_ATS
6398 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",array_index, ia[array_index], ja[array_index], ar[array_index]);
6399#endif
6400
6401 array_index++;
6402 row_index ++;
6403
6404 // Constraint 9: optimize relativity
6405 glp_add_rows(ats->prob, c_peers);
6406 for (c=1; c<=c_peers; c++)
6407 {
6408 glp_set_row_bnds(ats->prob, row_index, GLP_LO, 0.0, 0.0);
6409
6410 struct ATS_mechanism *m = peers[c].m_head;
6411 while (m!=NULL)
6412 {
6413 ia[array_index] = row_index;
6414 ja[array_index] = m->col_index;
6415 ar[array_index] = 1;
6416#if VERBOSE_ATS
6417 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",array_index, ia[array_index], ja[array_index], ar[array_index]);
6418#endif
6419 array_index++;
6420 m = m->next;
6421 }
6422 ia[array_index] = row_index;
6423 ja[array_index] = (2*c_mechs) + 3;
6424 ar[array_index] = -1;
6425#if VERBOSE_ATS
6426 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",array_index, ia[array_index], ja[array_index], ar[array_index]);
6427#endif
6428 array_index++;
6429 6508
6430 row_index++;
6431 }
6432 /* Loading the matrix */ 6509 /* Loading the matrix */
6433 glp_load_matrix(ats->prob, array_index-1, ia, ja, ar); 6510 glp_load_matrix(ats->prob, array_index-1, ia, ja, ar);
6434 6511
@@ -6443,17 +6520,23 @@ static int ats_create_problem (double D, double U, double R, int v_b_min, int v_
6443 GNUNET_free (ia); 6520 GNUNET_free (ia);
6444 GNUNET_free (ar); 6521 GNUNET_free (ar);
6445 6522
6446 for (c=0; c<c_mechs; c++)
6447 GNUNET_free_non_null (mechanisms[c].rc);
6448
6449 GNUNET_free(mechanisms);
6450 GNUNET_free(peers);
6451 return GNUNET_OK; 6523 return GNUNET_OK;
6524
6525}
6526
6527void ats_notify_ats_data (
6528 const struct GNUNET_PeerIdentity *peer,
6529 const struct GNUNET_TRANSPORT_ATS_Information *ats_data)
6530{
6531#if DEBUG_ATS
6532 GNUNET_log (GNUNET_ERROR_TYPE_BULK, "ATS_notify_ats_data: %s\n",GNUNET_i2s(peer));
6452#endif 6533#endif
6534 ats_calculate_bandwidth_distribution(ats);
6453} 6535}
6454#endif 6536#endif
6455 6537
6456void ats_calculate_bandwidth_distribution () 6538static void
6539ats_calculate_bandwidth_distribution ()
6457{ 6540{
6458#if HAVE_LIBGLPK 6541#if HAVE_LIBGLPK
6459 struct GNUNET_TIME_Absolute start; 6542 struct GNUNET_TIME_Absolute start;
@@ -6474,30 +6557,25 @@ void ats_calculate_bandwidth_distribution ()
6474 else 6557 else
6475 dur = (int) ats->max_exec_duration.rel_value; 6558 dur = (int) ats->max_exec_duration.rel_value;
6476 6559
6477
6478
6479 start = GNUNET_TIME_absolute_get(); 6560 start = GNUNET_TIME_absolute_get();
6480 if ((ats->modified_addr == GNUNET_YES) || (ats->prob==NULL)) 6561 if ((ats->modified_addr == GNUNET_YES) || (ats->prob==NULL))
6481 { 6562 {
6482#if DEBUG_ATS
6483 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers/Addresses were modified... have to recreate problem\n");
6484#endif
6485 ats->modified_addr = GNUNET_NO; 6563 ats->modified_addr = GNUNET_NO;
6486 ats->res.c_mechs = 0; 6564 ats_delete_problem ();
6487 ats->res.c_peers = 0;
6488 ats->res.solution = 0;
6489 ats->res.valid = GNUNET_NO;
6490 ats_create_problem (ats->D, ats->U, ats->R, ats->v_b_min, ats->v_n_min, &ats->res); 6565 ats_create_problem (ats->D, ats->U, ats->R, ats->v_b_min, ats->v_n_min, &ats->res);
6566#if DEBUG_ATS
6567 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers/Addresses were modified... new problem: %i peer, %i mechs\n", ats->res.c_peers, ats->res.c_mechs);
6568#endif
6491 } 6569 }
6492 else if (ats->modified_resources) 6570 else if (ats->modified_resources == GNUNET_YES)
6493 { 6571 {
6494 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "RESSOURCE...modified problem\n"); 6572 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "RESSOURCE...modified problem\n");
6495 /* TODO */ 6573 ats_update_problem();
6496 } 6574 }
6497 else if (ats->modified_quality) 6575 else if (ats->modified_quality == GNUNET_YES)
6498 { 6576 {
6499 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "RESSOURCE...quality problem\n"); 6577 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "RESSOURCE...quality problem\n");
6500 /* TODO */ 6578 ats_update_problem();
6501 } 6579 }
6502#if DEBUG_ATS 6580#if DEBUG_ATS
6503 else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem is unmodified\n"); 6581 else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem is unmodified\n");
@@ -6505,15 +6583,18 @@ void ats_calculate_bandwidth_distribution ()
6505 6583
6506 if (ats->res.valid == GNUNET_YES) 6584 if (ats->res.valid == GNUNET_YES)
6507 { 6585 {
6586 ats->res.solution = GNUNET_SYSERR;
6508 ats_solve_problem(ats->max_iterations, ats->max_exec_duration.rel_value, ats->res.c_peers, ats->res.c_mechs, &ats->res); 6587 ats_solve_problem(ats->max_iterations, ats->max_exec_duration.rel_value, ats->res.c_peers, ats->res.c_mechs, &ats->res);
6588 if (ats->res.solution != 5)
6589 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem solution is not optimal: %i\n", ats->res.solution);
6509 } 6590 }
6510 6591
6511 duration = GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get()); 6592 duration = GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get());
6512 6593
6513 if ((ats->res.valid == GNUNET_YES)) 6594 if (ats->res.valid == GNUNET_YES)
6514 { 6595 {
6515#if DEBUG_ATS 6596#if DEBUG_ATS
6516 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP execution time in [ms] for %i mechanisms: %llu %llu \n", res, duration.rel_value, ats->res.solution); 6597 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP execution time in [ms] for %i mechanisms: %llu\n", ats->res.c_mechs, duration.rel_value);
6517#endif 6598#endif
6518 GNUNET_STATISTICS_set (stats, "ATS duration", duration.rel_value, GNUNET_NO); 6599 GNUNET_STATISTICS_set (stats, "ATS duration", duration.rel_value, GNUNET_NO);
6519 GNUNET_STATISTICS_set (stats, "ATS mechanisms", ats->res.c_mechs, GNUNET_NO); 6600 GNUNET_STATISTICS_set (stats, "ATS mechanisms", ats->res.c_mechs, GNUNET_NO);
@@ -6522,7 +6603,7 @@ void ats_calculate_bandwidth_distribution ()
6522 GNUNET_STATISTICS_set (stats, "ATS timestamp", start.abs_value, GNUNET_NO); 6603 GNUNET_STATISTICS_set (stats, "ATS timestamp", start.abs_value, GNUNET_NO);
6523 } 6604 }
6524#if DEBUG_ATS 6605#if DEBUG_ATS
6525 else if (res == 0) 6606 else if (ats->res.valid == GNUNET_NO)
6526 { 6607 {
6527 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP not executed: no addresses\n"); 6608 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP not executed: no addresses\n");
6528 } 6609 }
@@ -6562,6 +6643,10 @@ ats_schedule_calculation (void *cls,
6562 6643
6563void ats_init () 6644void ats_init ()
6564{ 6645{
6646 int c = 0;
6647 unsigned long long value;
6648 char * section;
6649
6565 ats = GNUNET_malloc(sizeof (struct ATS_info)); 6650 ats = GNUNET_malloc(sizeof (struct ATS_info));
6566 6651
6567 ats->min_delta = ATS_MIN_INTERVAL; 6652 ats->min_delta = ATS_MIN_INTERVAL;
@@ -6584,9 +6669,6 @@ void ats_init ()
6584 ats->prob = NULL; 6669 ats->prob = NULL;
6585#endif 6670#endif
6586 6671
6587 int c = 0;
6588 unsigned long long value;
6589 char * section;
6590 /* loading cost ressources */ 6672 /* loading cost ressources */
6591 for (c=0; c<available_ressources; c++) 6673 for (c=0; c<available_ressources; c++)
6592 { 6674 {
@@ -6635,11 +6717,7 @@ static void ats_shutdown ()
6635 GNUNET_SCHEDULER_cancel(ats->ats_task); 6717 GNUNET_SCHEDULER_cancel(ats->ats_task);
6636 ats->ats_task = GNUNET_SCHEDULER_NO_TASK; 6718 ats->ats_task = GNUNET_SCHEDULER_NO_TASK;
6637#if HAVE_LIBGLPK 6719#if HAVE_LIBGLPK
6638 if (ats->prob != NULL) 6720 ats_delete_problem ();
6639 {
6640 glp_delete_prob(ats->prob);
6641 ats->prob = NULL;
6642 }
6643#endif 6721#endif
6644 GNUNET_free (ats); 6722 GNUNET_free (ats);
6645} 6723}
@@ -6678,18 +6756,6 @@ void ats_notify_peer_disconnect (
6678 ats_calculate_bandwidth_distribution (ats); 6756 ats_calculate_bandwidth_distribution (ats);
6679} 6757}
6680 6758
6681#if HAVE_LIBGLPK
6682void ats_notify_ats_data (
6683 const struct GNUNET_PeerIdentity *peer,
6684 const struct GNUNET_TRANSPORT_ATS_Information *ats_data)
6685{
6686#if DEBUG_ATS
6687 GNUNET_log (GNUNET_ERROR_TYPE_BULK, "ATS_notify_ats_data: %s\n",GNUNET_i2s(peer));
6688#endif
6689 ats_calculate_bandwidth_distribution(ats);
6690}
6691#endif
6692
6693struct ForeignAddressList * ats_get_preferred_address ( 6759struct ForeignAddressList * ats_get_preferred_address (
6694 struct NeighbourList *n) 6760 struct NeighbourList *n)
6695{ 6761{