diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-07-05 09:55:42 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-07-05 09:55:42 +0000 |
commit | 98dce660a7b76c70da2462995729d0445749233b (patch) | |
tree | 18514ec1c034609ba3e8af76bc98c2cb607042c1 /src/ats | |
parent | 9bde041f15f890cb36d67cc0d085e6bc143112cb (diff) | |
download | gnunet-98dce660a7b76c70da2462995729d0445749233b.tar.gz gnunet-98dce660a7b76c70da2462995729d0445749233b.zip |
split up update function and using normalized values
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats-solver_mlp.c | 406 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats-solver_mlp.h | 20 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 17 | ||||
-rw-r--r-- | src/ats/test_ats_mlp_update.c | 5 |
4 files changed, 173 insertions, 275 deletions
diff --git a/src/ats/gnunet-service-ats-solver_mlp.c b/src/ats/gnunet-service-ats-solver_mlp.c index 5a7fbfc78..2a35f574e 100644 --- a/src/ats/gnunet-service-ats-solver_mlp.c +++ b/src/ats/gnunet-service-ats-solver_mlp.c | |||
@@ -421,8 +421,10 @@ static int mlp_create_problem_count_addresses ( | |||
421 | * @param col the column to create the value in | 421 | * @param col the column to create the value in |
422 | * @param val the value to set | 422 | * @param val the value to set |
423 | * @param line calling line for debbuging | 423 | * @param line calling line for debbuging |
424 | * @param GNUNET_YES value changed, GNUNET_NO value did not change, GNUNET_SYSERR | ||
425 | * on error | ||
424 | */ | 426 | */ |
425 | static void | 427 | static int |
426 | mlp_create_problem_update_value (struct MLP_Problem *p, | 428 | mlp_create_problem_update_value (struct MLP_Problem *p, |
427 | int row, int col, double val, | 429 | int row, int col, double val, |
428 | int line) | 430 | int line) |
@@ -430,6 +432,7 @@ mlp_create_problem_update_value (struct MLP_Problem *p, | |||
430 | int c_cols; | 432 | int c_cols; |
431 | int c_elems; | 433 | int c_elems; |
432 | int c1; | 434 | int c1; |
435 | int res; | ||
433 | double *val_array; | 436 | double *val_array; |
434 | int *ind_array; | 437 | int *ind_array; |
435 | 438 | ||
@@ -439,7 +442,7 @@ mlp_create_problem_update_value (struct MLP_Problem *p, | |||
439 | /* Get number of columns and prepare data structure */ | 442 | /* Get number of columns and prepare data structure */ |
440 | c_cols = glp_get_num_cols(p->prob); | 443 | c_cols = glp_get_num_cols(p->prob); |
441 | if (0 >= c_cols) | 444 | if (0 >= c_cols) |
442 | return; | 445 | return GNUNET_SYSERR; |
443 | 446 | ||
444 | val_array = GNUNET_malloc ((c_cols +1)* sizeof (double)); | 447 | val_array = GNUNET_malloc ((c_cols +1)* sizeof (double)); |
445 | GNUNET_assert (NULL != val_array); | 448 | GNUNET_assert (NULL != val_array); |
@@ -451,21 +454,12 @@ mlp_create_problem_update_value (struct MLP_Problem *p, | |||
451 | { | 454 | { |
452 | GNUNET_free (ind_array); | 455 | GNUNET_free (ind_array); |
453 | GNUNET_free (val_array); | 456 | GNUNET_free (val_array); |
454 | return; | 457 | return GNUNET_SYSERR; |
455 | } | 458 | } |
456 | 459 | ||
457 | /* Update the value */ | 460 | /* Update the value */ |
458 | for (c1 = 1; c1 < (c_elems+1); c1++) | 461 | for (c1 = 1; c1 < (c_elems+1); c1++) |
459 | { | 462 | { |
460 | /* Debug | ||
461 | fprintf (stderr, "cur %u of %u: [%u] %s <-> [%u] %s\n", | ||
462 | c1, c_elems, | ||
463 | ind_array[c1], | ||
464 | glp_get_col_name(p->prob, ind_array[c1]), | ||
465 | col, | ||
466 | glp_get_col_name(p->prob, col) | ||
467 | ); | ||
468 | */ | ||
469 | if (ind_array[c1] == col) | 463 | if (ind_array[c1] == col) |
470 | break; | 464 | break; |
471 | } | 465 | } |
@@ -473,17 +467,23 @@ mlp_create_problem_update_value (struct MLP_Problem *p, | |||
473 | { | 467 | { |
474 | GNUNET_free (ind_array); | 468 | GNUNET_free (ind_array); |
475 | GNUNET_free (val_array); | 469 | GNUNET_free (val_array); |
476 | return; /* not found */ | 470 | return GNUNET_SYSERR; /* not found */ |
477 | } | 471 | } |
478 | /* Update value */ | 472 | /* Update value */ |
479 | LOG (GNUNET_ERROR_TYPE_ERROR, "[P] Updating value for peer from `%.2f' to `%.2f'\n", | 473 | LOG (GNUNET_ERROR_TYPE_ERROR, "[P] Updating value in [%s : %s] from `%.2f' to `%.2f'\n", |
474 | glp_get_row_name (p->prob, row), glp_get_col_name (p->prob, col), | ||
480 | val_array[c1], val); | 475 | val_array[c1], val); |
476 | if (val != val_array[c1]) | ||
477 | res = GNUNET_YES; | ||
478 | else | ||
479 | res = GNUNET_NO; | ||
481 | val_array[c1] = val; | 480 | val_array[c1] = val; |
482 | 481 | ||
483 | /* Update the row in the matrix */ | 482 | /* Update the row in the matrix */ |
484 | glp_set_mat_row (p->prob, row, c_elems, ind_array, val_array); | 483 | glp_set_mat_row (p->prob, row, c_elems, ind_array, val_array); |
485 | GNUNET_free (ind_array); | 484 | GNUNET_free (ind_array); |
486 | GNUNET_free (val_array); | 485 | GNUNET_free (val_array); |
486 | return res; | ||
487 | } | 487 | } |
488 | 488 | ||
489 | /** | 489 | /** |
@@ -590,6 +590,7 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC | |||
590 | struct ATS_Peer *peer; | 590 | struct ATS_Peer *peer; |
591 | struct MLP_information *mlpi; | 591 | struct MLP_information *mlpi; |
592 | char *name; | 592 | char *name; |
593 | const double *props; | ||
593 | uint32_t addr_net; | 594 | uint32_t addr_net; |
594 | int c; | 595 | int c; |
595 | 596 | ||
@@ -629,8 +630,6 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC | |||
629 | mlpi->n = 0; | 630 | mlpi->n = 0; |
630 | mlpi->r_c1 = 0; | 631 | mlpi->r_c1 = 0; |
631 | mlpi->r_c3 = 0; | 632 | mlpi->r_c3 = 0; |
632 | for (c = 0; c < mlp->pv.m_q; c++) | ||
633 | mlpi->r_q[0] = 0; | ||
634 | 633 | ||
635 | /* Add bandwidth column */ | 634 | /* Add bandwidth column */ |
636 | GNUNET_asprintf (&name, "b_%s_%s_%p", GNUNET_i2s (&address->peer), address->plugin, address); | 635 | GNUNET_asprintf (&name, "b_%s_%s_%p", GNUNET_i2s (&address->peer), address->plugin, address); |
@@ -703,11 +702,9 @@ mlp_create_problem_add_address_information (void *cls, const struct GNUNET_HashC | |||
703 | 702 | ||
704 | /* c 7) Optimize quality */ | 703 | /* c 7) Optimize quality */ |
705 | /* For all quality metrics, set quality of this address */ | 704 | /* For all quality metrics, set quality of this address */ |
705 | props = mlp->get_properties (mlp->get_properties_cls, address); | ||
706 | for (c = 0; c < mlp->pv.m_q; c++) | 706 | for (c = 0; c < mlp->pv.m_q; c++) |
707 | { | 707 | mlp_create_problem_set_value (p, p->r_q[c], mlpi->c_b, props[c], __LINE__); |
708 | |||
709 | mlp_create_problem_set_value (p, p->r_q[c], mlpi->c_b, mlpi->q_averaged[c], __LINE__); | ||
710 | } | ||
711 | 708 | ||
712 | return GNUNET_OK; | 709 | return GNUNET_OK; |
713 | } | 710 | } |
@@ -1156,9 +1153,6 @@ GAS_mlp_address_add (void *solver, | |||
1156 | { | 1153 | { |
1157 | struct GAS_MLP_Handle *mlp = solver; | 1154 | struct GAS_MLP_Handle *mlp = solver; |
1158 | struct ATS_Peer *p; | 1155 | struct ATS_Peer *p; |
1159 | struct MLP_information *mlpi; | ||
1160 | int c1; | ||
1161 | int c2; | ||
1162 | 1156 | ||
1163 | GNUNET_assert (NULL != solver); | 1157 | GNUNET_assert (NULL != solver); |
1164 | GNUNET_assert (NULL != address); | 1158 | GNUNET_assert (NULL != address); |
@@ -1166,13 +1160,6 @@ GAS_mlp_address_add (void *solver, | |||
1166 | if (NULL == address->solver_information) | 1160 | if (NULL == address->solver_information) |
1167 | { | 1161 | { |
1168 | address->solver_information = GNUNET_malloc (sizeof (struct MLP_information)); | 1162 | address->solver_information = GNUNET_malloc (sizeof (struct MLP_information)); |
1169 | mlpi = address->solver_information; | ||
1170 | for (c1 = 0; c1 < mlp->pv.m_q; c1++) | ||
1171 | { | ||
1172 | mlpi->q_averaged[c1] = DEFAULT_QUALITY; | ||
1173 | for (c2 = 0; c2 < MLP_AVERAGING_QUEUE_LENGTH; c2++) | ||
1174 | mlpi->q[c1][c2] = MLP_NaN; | ||
1175 | } | ||
1176 | } | 1163 | } |
1177 | else | 1164 | else |
1178 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding address for peer `%s' multiple times\n"), GNUNET_i2s(&address->peer)); | 1165 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding address for peer `%s' multiple times\n"), GNUNET_i2s(&address->peer)); |
@@ -1192,52 +1179,7 @@ GAS_mlp_address_add (void *solver, | |||
1192 | } | 1179 | } |
1193 | 1180 | ||
1194 | 1181 | ||
1195 | static void | 1182 | #if 0 |
1196 | mlp_update_quality (struct GAS_MLP_Handle *mlp, | ||
1197 | const struct GNUNET_CONTAINER_MultiHashMap *addresses, | ||
1198 | struct ATS_Address * address, | ||
1199 | const struct GNUNET_ATS_Information *ats_prev, uint32_t ats_prev_count) | ||
1200 | { | ||
1201 | struct MLP_information *mlpi = address->solver_information; | ||
1202 | unsigned int c_ats_entry; | ||
1203 | unsigned int c_queue_entries; | ||
1204 | unsigned int c_cmp; | ||
1205 | unsigned int c_queue_it; | ||
1206 | unsigned int c_row; | ||
1207 | unsigned int c_qual; | ||
1208 | unsigned int c_net; | ||
1209 | int qual_changed; | ||
1210 | int type_index; | ||
1211 | int avg_index; | ||
1212 | uint32_t type; | ||
1213 | uint32_t prev_value; | ||
1214 | uint32_t new_value; | ||
1215 | double avg; | ||
1216 | double *queue; | ||
1217 | int rows; | ||
1218 | double *val; | ||
1219 | int *ind; | ||
1220 | |||
1221 | |||
1222 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating %u quality metrics for peer `%s'\n", | ||
1223 | ats_prev_count, GNUNET_i2s (&address->peer)); | ||
1224 | |||
1225 | GNUNET_assert (NULL != mlp); | ||
1226 | GNUNET_assert (NULL != address); | ||
1227 | GNUNET_assert (NULL != address->solver_information); | ||
1228 | GNUNET_assert (NULL != ats_prev); | ||
1229 | |||
1230 | if (NULL == mlp->p.prob) | ||
1231 | return; | ||
1232 | |||
1233 | qual_changed = GNUNET_NO; | ||
1234 | for (c_ats_entry = 0; c_ats_entry < ats_prev_count; c_ats_entry++) | ||
1235 | { | ||
1236 | type = ntohl (ats_prev[c_ats_entry].type); | ||
1237 | prev_value = ntohl (ats_prev[c_ats_entry].value); | ||
1238 | type_index = -1; | ||
1239 | avg_index = -1; | ||
1240 | |||
1241 | /* Check for network update */ | 1183 | /* Check for network update */ |
1242 | if (type == GNUNET_ATS_NETWORK_TYPE) | 1184 | if (type == GNUNET_ATS_NETWORK_TYPE) |
1243 | { | 1185 | { |
@@ -1294,121 +1236,76 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, | |||
1294 | mlp->mlp_prob_changed = GNUNET_YES; | 1236 | mlp->mlp_prob_changed = GNUNET_YES; |
1295 | continue; | 1237 | continue; |
1296 | } | 1238 | } |
1239 | #endif | ||
1297 | 1240 | ||
1241 | void | ||
1242 | GAS_mlp_address_property_changed (void *solver, | ||
1243 | struct ATS_Address *address, | ||
1244 | uint32_t type, | ||
1245 | uint32_t abs_value, | ||
1246 | double rel_value) | ||
1247 | { | ||
1248 | struct MLP_information *mlpi = address->solver_information; | ||
1249 | struct GAS_MLP_Handle *mlp = solver; | ||
1250 | struct ATS_Peer *p; | ||
1251 | int c1; | ||
1252 | int type_index; | ||
1298 | 1253 | ||
1299 | /* Find index for this ATS type */ | 1254 | GNUNET_assert (NULL != solver); |
1300 | for (c_cmp = 0; c_cmp < mlp->pv.m_q; c_cmp++) | 1255 | GNUNET_assert (NULL != address); |
1301 | { | ||
1302 | if (type == mlp->pv.q[c_cmp]) | ||
1303 | { | ||
1304 | type_index = c_cmp; | ||
1305 | break; | ||
1306 | } | ||
1307 | } | ||
1308 | if (-1 == type_index) | ||
1309 | continue; /* quality index not found */ | ||
1310 | |||
1311 | /* Get average queue index */ | ||
1312 | avg_index = mlpi->q_avg_i[type_index]; | ||
1313 | |||
1314 | /* Update averaging queue */ | ||
1315 | new_value = get_performance_info (address, type); | ||
1316 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s': `%s' from %u to %u\n", | ||
1317 | GNUNET_i2s (&address->peer), | ||
1318 | mlp_ats_to_string(mlp->pv.q[type_index]), prev_value, new_value); | ||
1319 | GNUNET_assert (GNUNET_ATS_VALUE_UNDEFINED != new_value); | ||
1320 | mlpi->q[type_index][avg_index] = new_value; | ||
1321 | |||
1322 | /* Update averaging index */ | ||
1323 | if (mlpi->q_avg_i[type_index] + 1 < (MLP_AVERAGING_QUEUE_LENGTH)) | ||
1324 | mlpi->q_avg_i[type_index] ++; | ||
1325 | else | ||
1326 | mlpi->q_avg_i[type_index] = 0; | ||
1327 | |||
1328 | /* Update average depending on ATS type */ | ||
1329 | switch (type) | ||
1330 | { | ||
1331 | case GNUNET_ATS_QUALITY_NET_DISTANCE: | ||
1332 | case GNUNET_ATS_QUALITY_NET_DELAY: | ||
1333 | c_queue_entries = 0; | ||
1334 | avg = 0; | ||
1335 | for (c_queue_it = 0; c_queue_it < MLP_AVERAGING_QUEUE_LENGTH; c_queue_it++) | ||
1336 | { | ||
1337 | if (mlpi->q[type_index][c_queue_it] != MLP_NaN) | ||
1338 | { | ||
1339 | queue = mlpi->q[type_index] ; | ||
1340 | avg += queue[c_queue_it]; | ||
1341 | c_queue_entries ++; | ||
1342 | } | ||
1343 | } | ||
1344 | if ((c_queue_entries > 0) && (avg > 0)) | ||
1345 | /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/ | ||
1346 | mlpi->q_averaged[type_index] = (double) c_queue_entries / avg; | ||
1347 | else | ||
1348 | mlpi->q_averaged[type_index] = 0.0; | ||
1349 | |||
1350 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating peer `%s': `%s' average sum of %u elements == %f, average == %f, weight == %f\n", | ||
1351 | GNUNET_i2s (&address->peer), | ||
1352 | mlp_ats_to_string(mlp->pv.q[type_index]), | ||
1353 | c_queue_entries, | ||
1354 | avg, | ||
1355 | avg / (double) c_queue_entries, | ||
1356 | mlpi->q_averaged[type_index]); | ||
1357 | qual_changed = GNUNET_YES; | ||
1358 | break; | ||
1359 | default: | ||
1360 | GNUNET_break (0); | ||
1361 | LOG (GNUNET_ERROR_TYPE_DEBUG, _("Update for ATS type `%s' not implemented!\n"), | ||
1362 | mlp_ats_to_string(type)); | ||
1363 | } | ||
1364 | } | ||
1365 | 1256 | ||
1366 | /* Changed, but quality will be automatically set during rebuild */ | 1257 | if (NULL == mlpi) |
1367 | if ((GNUNET_YES == mlp->mlp_prob_changed) && | ||
1368 | (GNUNET_YES == mlp->mlp_auto_solve)) | ||
1369 | { | 1258 | { |
1370 | GAS_mlp_solve_problem (mlp); | 1259 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1371 | return; | 1260 | _("Updating address property `%s' for peer `%s' %p not added before\n"), |
1261 | GNUNET_ATS_print_property_type (type), | ||
1262 | GNUNET_i2s(&address->peer), | ||
1263 | address); | ||
1264 | GNUNET_break (0); | ||
1265 | return; | ||
1372 | } | 1266 | } |
1373 | 1267 | ||
1374 | /* Update problem matrix if required */ | 1268 | if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->requested_peers, |
1375 | if (GNUNET_NO == qual_changed) | 1269 | &address->peer.hashPubKey))) |
1270 | { | ||
1271 | /* Peer is not requested, so no need to update problem */ | ||
1376 | return; | 1272 | return; |
1273 | } | ||
1274 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating property `%s' address for peer `%s'\n", | ||
1275 | GNUNET_ATS_print_property_type (type), | ||
1276 | GNUNET_i2s(&address->peer)); | ||
1377 | 1277 | ||
1378 | /* Address not yet included in matrix */ | 1278 | /* Find row index */ |
1379 | if (MLP_UNDEFINED == mlpi->c_b) | 1279 | type_index = -1; |
1380 | return; | 1280 | for (c1 = 0; c1 < mlp->pv.m_q; c1++) |
1281 | { | ||
1282 | if (type == mlp->pv.q[c1]) | ||
1283 | { | ||
1284 | type_index = c1; | ||
1285 | break; | ||
1286 | } | ||
1287 | } | ||
1288 | if (-1 == type_index) | ||
1289 | { | ||
1290 | GNUNET_break (0); | ||
1291 | return; /* quality index not found */ | ||
1292 | } | ||
1381 | 1293 | ||
1382 | /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] | 1294 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1383 | * Get column mlpi->c_b */ | 1295 | _("Updating address property `%s' for peer `%s' %p\n"), |
1384 | rows = glp_get_num_rows(mlp->p.prob); | 1296 | GNUNET_ATS_print_property_type (type), |
1385 | ind = GNUNET_malloc (rows * sizeof (int) + 1); | 1297 | GNUNET_i2s(&address->peer), |
1386 | val = GNUNET_malloc (rows * sizeof (double) + 1); | 1298 | address, |
1387 | int length = glp_get_mat_col (mlp->p.prob, mlpi->c_b, ind, val); | 1299 | type_index, mlp->p.r_q[type_index]); |
1388 | 1300 | ||
1389 | for (c_qual = 0; c_qual < mlp->pv.m_q; c_qual++) | 1301 | /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */ |
1302 | if (GNUNET_YES == mlp_create_problem_update_value (&mlp->p, | ||
1303 | mlp->p.r_q[type_index], mlpi->c_b, rel_value, __LINE__)) | ||
1390 | { | 1304 | { |
1391 | for (c_row = 0; c_row <= length; c_row ++) | 1305 | mlp->mlp_prob_updated = GNUNET_YES; |
1392 | { | 1306 | if (GNUNET_YES == mlp->mlp_auto_solve) |
1393 | if (ind[c_row] == mlp->p.r_q[c_qual]) | 1307 | GAS_mlp_solve_problem (solver); |
1394 | val[c_row] = mlpi->q_averaged[c_qual]; | ||
1395 | } | ||
1396 | } | 1308 | } |
1397 | /* Set updated column */ | ||
1398 | glp_set_mat_col (mlp->p.prob, mlpi->c_b, length, ind, val); | ||
1399 | GNUNET_free (ind); | ||
1400 | GNUNET_free (val); | ||
1401 | mlp->mlp_prob_updated = GNUNET_YES; | ||
1402 | } | ||
1403 | |||
1404 | void | ||
1405 | GAS_mlp_address_property_changed (void *solver, | ||
1406 | struct ATS_Address *address, | ||
1407 | uint32_t type, | ||
1408 | uint32_t abs_value, | ||
1409 | double rel_value) | ||
1410 | { | ||
1411 | GNUNET_break (0); | ||
1412 | } | 1309 | } |
1413 | 1310 | ||
1414 | 1311 | ||
@@ -1418,7 +1315,8 @@ GAS_mlp_address_session_changed (void *solver, | |||
1418 | uint32_t cur_session, | 1315 | uint32_t cur_session, |
1419 | uint32_t new_session) | 1316 | uint32_t new_session) |
1420 | { | 1317 | { |
1421 | GNUNET_break (0); | 1318 | /* Nothing to do here */ |
1319 | return; | ||
1422 | } | 1320 | } |
1423 | 1321 | ||
1424 | void | 1322 | void |
@@ -1427,94 +1325,102 @@ GAS_mlp_address_inuse_changed (void *solver, | |||
1427 | uint32_t session, | 1325 | uint32_t session, |
1428 | int in_use) | 1326 | int in_use) |
1429 | { | 1327 | { |
1430 | GNUNET_break (0); | 1328 | /* Nothing to do here */ |
1329 | return; | ||
1431 | } | 1330 | } |
1432 | 1331 | ||
1433 | 1332 | ||
1434 | void | 1333 | void |
1435 | GAS_mlp_address_change_network (void *solver, | 1334 | GAS_mlp_address_change_network (void *solver, |
1436 | struct ATS_Address *address, | 1335 | struct ATS_Address *address, |
1437 | uint32_t current_network, | 1336 | uint32_t current_network, |
1438 | uint32_t new_network) | 1337 | uint32_t new_network) |
1439 | { | ||
1440 | GNUNET_break (0); | ||
1441 | } | ||
1442 | |||
1443 | /** | ||
1444 | * Updates a single address in the MLP problem | ||
1445 | * | ||
1446 | * If the address did not exist before in the problem: | ||
1447 | * The MLP problem has to be recreated and the problem has to be resolved | ||
1448 | * | ||
1449 | * ATS performance information in address are already updated, delta + previous | ||
1450 | * values are included in atsi_prev (value GNUNET_ATS_VALUE_UNDEFINED if not existing before) | ||
1451 | * | ||
1452 | * Otherwise the addresses' values can be updated and the existing base can | ||
1453 | * be reused | ||
1454 | * | ||
1455 | * @param solver the solver Handle | ||
1456 | * @param addresses the address hashmap containing all addresses | ||
1457 | * @param address the update address | ||
1458 | * @param prev_session the new session (if changed otherwise current) | ||
1459 | * @param prev_in_use the new address in use state (if changed otherwise current) | ||
1460 | * @param prev_atsi ATS information updated + previous values, GNUNET_ATS_VALUE_UNDEFINED if not existing before | ||
1461 | * @param prev_atsi_count number of atsi values updated | ||
1462 | */ | ||
1463 | void | ||
1464 | GAS_mlp_address_update (void *solver, | ||
1465 | struct ATS_Address *address, | ||
1466 | uint32_t prev_session, | ||
1467 | int prev_in_use, | ||
1468 | const struct GNUNET_ATS_Information *prev_atsi, | ||
1469 | uint32_t prev_atsi_count) | ||
1470 | { | 1338 | { |
1471 | struct ATS_Peer *p; | ||
1472 | struct GAS_MLP_Handle *mlp = solver; | ||
1473 | struct MLP_information *mlpi = address->solver_information; | 1339 | struct MLP_information *mlpi = address->solver_information; |
1340 | struct GAS_MLP_Handle *mlp = solver; | ||
1341 | struct ATS_Peer *p; | ||
1342 | int nets_avail[] = GNUNET_ATS_NetworkType; | ||
1474 | int c1; | 1343 | int c1; |
1344 | // int length; | ||
1345 | // int rows; | ||
1346 | // int *ind; | ||
1347 | // double *val; | ||
1348 | |||
1475 | 1349 | ||
1476 | GNUNET_assert (NULL != solver); | 1350 | GNUNET_assert (NULL != solver); |
1477 | GNUNET_assert (NULL != address); | 1351 | GNUNET_assert (NULL != address); |
1478 | GNUNET_assert ((NULL != prev_atsi) || (0 == prev_atsi_count)); | ||
1479 | 1352 | ||
1480 | if (NULL == mlpi) | 1353 | if (NULL == mlpi) |
1481 | { | 1354 | { |
1482 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Updating address for peer `%s' not added before\n"), GNUNET_i2s(&address->peer)); | 1355 | GNUNET_break (0); |
1483 | return; | 1356 | return; |
1484 | } | 1357 | } |
1485 | 1358 | ||
1486 | if (address->session_id != prev_session) | 1359 | if (mlpi->c_b == MLP_UNDEFINED) |
1487 | { | 1360 | return; /* This address is not yet in the matrix*/ |
1488 | /* Session changed */ | ||
1489 | 1361 | ||
1490 | } | 1362 | if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->requested_peers, |
1491 | if ((NULL != prev_atsi) && (0 != prev_atsi_count)) | 1363 | &address->peer.hashPubKey))) |
1492 | { | 1364 | { |
1493 | /* Properties changed */ | 1365 | /* Peer is not requested, so no need to update problem */ |
1494 | for (c1 = 0; c1 < prev_atsi_count; c1++ ) | 1366 | GNUNET_break (0); |
1495 | { | 1367 | return; |
1496 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating `%s'\n", | 1368 | } |
1497 | GNUNET_ATS_print_property_type (ntohl(prev_atsi[c1].type))); | ||
1498 | //mlp->get_properties (mlp->get_properties_cls ); | ||
1499 | } | ||
1500 | //mlp_update_quality (mlp, mlp->addresses, address, prev_atsi, prev_atsi_count); | ||
1501 | } | ||
1502 | 1369 | ||
1503 | /* Is this peer included in the problem? */ | 1370 | if (current_network == new_network) |
1504 | if (NULL == (p = GNUNET_CONTAINER_multihashmap_get (mlp->requested_peers, &address->peer.hashPubKey))) | 1371 | { |
1505 | { | 1372 | GNUNET_break (0); |
1506 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s' without address request \n", | 1373 | return; |
1507 | GNUNET_i2s(&address->peer)); | 1374 | } |
1508 | return; | ||
1509 | } | ||
1510 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s' with address request \n", | ||
1511 | GNUNET_i2s(&address->peer)); | ||
1512 | mlp->mlp_prob_updated = GNUNET_YES; | ||
1513 | 1375 | ||
1514 | if (GNUNET_YES == mlp->mlp_auto_solve) | 1376 | for (c1 = 0; c1 < GNUNET_ATS_NetworkTypeCount ; c1 ++) |
1515 | GAS_mlp_solve_problem (solver); | 1377 | { |
1378 | if (nets_avail[c1] == new_network) | ||
1379 | break; | ||
1380 | } | ||
1381 | |||
1382 | if (GNUNET_ATS_NetworkTypeCount == c1) | ||
1383 | { | ||
1384 | /* Invalid network */ | ||
1385 | GNUNET_break (0); | ||
1386 | return; | ||
1387 | } | ||
1388 | |||
1389 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating network for peer `%s' from `%s' to `%s'\n", | ||
1390 | GNUNET_i2s (&address->peer), | ||
1391 | GNUNET_ATS_print_network_type(current_network), | ||
1392 | GNUNET_ATS_print_network_type(new_network)); | ||
1393 | #if 0 | ||
1394 | /* Get row for this address */ | ||
1395 | rows = glp_get_num_rows(mlp->p.prob); | ||
1396 | ind = GNUNET_malloc (rows * sizeof (int) + 1); | ||
1397 | val = GNUNET_malloc (rows * sizeof (double) + 1); | ||
1398 | length = glp_get_mat_col (mlp->p.prob, mlpi->c_b, ind, val); | ||
1399 | |||
1400 | /* Remove index from old network */ | ||
1401 | for (c1 = 1; c1 < length +1; c1 ++) | ||
1402 | { | ||
1403 | if (ind[c1] == mlp->p.r_quota[c1]) | ||
1404 | break; /* Found index for old network */ | ||
1405 | } | ||
1406 | val[c1] = 0.0; /* Remove from previous network */ | ||
1407 | glp_set_mat_col (mlp->p.prob, mlpi->c_b, length, ind, val); | ||
1408 | ind[c1] = mlp->p.r_quota[new_network]; /* Add to new network */ | ||
1409 | val[c1] = 1.0; | ||
1410 | glp_set_mat_col (mlp->p.prob, mlpi->c_b, length, ind, val); | ||
1411 | GNUNET_free (ind); | ||
1412 | GNUNET_free (val); | ||
1413 | |||
1414 | length = glp_get_mat_col (mlp->p.prob, mlpi->c_b, ind, val); | ||
1415 | for (c1 = 1; c1 < length + 1; c1 ++) | ||
1416 | { | ||
1417 | fprintf (stderr, "%u: %s\n", ind[c1], glp_get_row_name(mlp->p.prob, ind[c1])); | ||
1418 | } | ||
1419 | #endif | ||
1420 | mlp->mlp_prob_changed = GNUNET_YES; | ||
1516 | } | 1421 | } |
1517 | 1422 | ||
1423 | |||
1518 | /** | 1424 | /** |
1519 | * Deletes a single address in the MLP problem | 1425 | * Deletes a single address in the MLP problem |
1520 | * | 1426 | * |
diff --git a/src/ats/gnunet-service-ats-solver_mlp.h b/src/ats/gnunet-service-ats-solver_mlp.h index 9a8b8efdf..02bfcc945 100644 --- a/src/ats/gnunet-service-ats-solver_mlp.h +++ b/src/ats/gnunet-service-ats-solver_mlp.h | |||
@@ -347,18 +347,6 @@ struct MLP_information | |||
347 | 347 | ||
348 | /* constraint 3: minimum bandwidth */ | 348 | /* constraint 3: minimum bandwidth */ |
349 | unsigned int r_c3; | 349 | unsigned int r_c3; |
350 | |||
351 | /* Quality information row indices */ | ||
352 | unsigned int r_q[GNUNET_ATS_QualityPropertiesCount]; | ||
353 | |||
354 | /* Quality information */ | ||
355 | double q[GNUNET_ATS_QualityPropertiesCount][MLP_AVERAGING_QUEUE_LENGTH]; | ||
356 | |||
357 | /* Quality information averaged */ | ||
358 | double q_averaged[GNUNET_ATS_QualityPropertiesCount]; | ||
359 | |||
360 | /* Averaging index */ | ||
361 | int q_avg_i[GNUNET_ATS_QualityPropertiesCount]; | ||
362 | }; | 350 | }; |
363 | 351 | ||
364 | /** | 352 | /** |
@@ -436,10 +424,10 @@ GAS_mlp_address_inuse_changed (void *solver, | |||
436 | int in_use); | 424 | int in_use); |
437 | 425 | ||
438 | void | 426 | void |
439 | GAS_proportional_address_change_network (void *solver, | 427 | GAS_mlp_address_change_network (void *solver, |
440 | struct ATS_Address *address, | 428 | struct ATS_Address *address, |
441 | uint32_t current_network, | 429 | uint32_t current_network, |
442 | uint32_t new_network); | 430 | uint32_t new_network); |
443 | 431 | ||
444 | /** | 432 | /** |
445 | * Deletes a single address in the MLP problem | 433 | * Deletes a single address in the MLP problem |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index dd12613fd..16f9d3450 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -939,6 +939,7 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
939 | if (GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) | 939 | if (GNUNET_ATS_NETWORK_TYPE == ntohl (atsi_delta[c1].type)) |
940 | { | 940 | { |
941 | /* Network type changed */ | 941 | /* Network type changed */ |
942 | GNUNET_break (0); | ||
942 | handle->s_address_update_network (handle->solver, aa, | 943 | handle->s_address_update_network (handle->solver, aa, |
943 | ntohl (atsi_delta[c1].value), | 944 | ntohl (atsi_delta[c1].value), |
944 | get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE)); | 945 | get_performance_info (aa, GNUNET_ATS_NETWORK_TYPE)); |
@@ -1356,18 +1357,19 @@ normalized_preference_changed_cb (void *cls, | |||
1356 | /** | 1357 | /** |
1357 | * The relative value for a property changed | 1358 | * The relative value for a property changed |
1358 | * | 1359 | * |
1359 | * @param solver the address handle | 1360 | * @param cls the address handle |
1360 | * @param peer the peer | 1361 | * @param peer the peer |
1361 | * @param type the ATS type | 1362 | * @param type the ATS type |
1362 | * @param prop_rel the new relative preference value | 1363 | * @param prop_rel the new relative preference value |
1363 | */ | 1364 | */ |
1364 | static void | 1365 | static void |
1365 | normalized_property_changed_cb (void *solver, | 1366 | normalized_property_changed_cb (void *cls, |
1366 | struct ATS_Address *address, | 1367 | struct ATS_Address *address, |
1367 | uint32_t type, | 1368 | uint32_t type, |
1368 | double prop_rel) | 1369 | double prop_rel) |
1369 | { | 1370 | { |
1370 | GNUNET_assert (NULL != solver); | 1371 | struct GAS_Addresses_Handle *ah = (struct GAS_Addresses_Handle *) cls; |
1372 | GNUNET_assert (NULL != ah); | ||
1371 | 1373 | ||
1372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1374 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1373 | "Normalized property %s for peer `%s' changed to %.3f \n", | 1375 | "Normalized property %s for peer `%s' changed to %.3f \n", |
@@ -1375,7 +1377,7 @@ normalized_property_changed_cb (void *solver, | |||
1375 | GNUNET_i2s (&address->peer), | 1377 | GNUNET_i2s (&address->peer), |
1376 | prop_rel); | 1378 | prop_rel); |
1377 | 1379 | ||
1378 | GAS_proportional_address_property_changed (solver, | 1380 | ah->s_address_update_property (ah->solver, |
1379 | address, | 1381 | address, |
1380 | type, | 1382 | type, |
1381 | 0, | 1383 | 0, |
@@ -1678,6 +1680,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1678 | ah->s_address_update_property = &GAS_mlp_address_property_changed; | 1680 | ah->s_address_update_property = &GAS_mlp_address_property_changed; |
1679 | ah->s_address_update_session = &GAS_mlp_address_session_changed; | 1681 | ah->s_address_update_session = &GAS_mlp_address_session_changed; |
1680 | ah->s_address_update_inuse = &GAS_mlp_address_inuse_changed; | 1682 | ah->s_address_update_inuse = &GAS_mlp_address_inuse_changed; |
1683 | ah->s_address_update_network = &GAS_mlp_address_change_network; | ||
1681 | ah->s_get = &GAS_mlp_get_preferred_address; | 1684 | ah->s_get = &GAS_mlp_get_preferred_address; |
1682 | ah->s_get_stop = &GAS_mlp_stop_get_preferred_address; | 1685 | ah->s_get_stop = &GAS_mlp_stop_get_preferred_address; |
1683 | ah->s_pref = &GAS_mlp_address_change_preference; | 1686 | ah->s_pref = &GAS_mlp_address_change_preference; |
diff --git a/src/ats/test_ats_mlp_update.c b/src/ats/test_ats_mlp_update.c index c13261e9d..8e5a1d6eb 100644 --- a/src/ats/test_ats_mlp_update.c +++ b/src/ats/test_ats_mlp_update.c | |||
@@ -147,7 +147,7 @@ get_property_cb (void *cls, const struct ATS_Address *address) | |||
147 | 147 | ||
148 | static void | 148 | static void |
149 | normalized_property_changed_cb (void *cls, | 149 | normalized_property_changed_cb (void *cls, |
150 | const struct ATS_Address *peer, | 150 | struct ATS_Address *peer, |
151 | uint32_t type, | 151 | uint32_t type, |
152 | double prop_rel) | 152 | double prop_rel) |
153 | { | 153 | { |
@@ -278,7 +278,8 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
278 | ats_prev[3].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR); | 278 | ats_prev[3].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR); |
279 | ats_prev[3].value = htonl (GNUNET_ATS_VALUE_UNDEFINED); | 279 | ats_prev[3].value = htonl (GNUNET_ATS_VALUE_UNDEFINED); |
280 | 280 | ||
281 | GAS_mlp_address_update (mlp, address[0], 1, GNUNET_NO, ats_prev, 4); | 281 | GAS_mlp_address_property_changed(mlp, address[0], GNUNET_ATS_QUALITY_NET_DELAY, 10, 1.1); |
282 | GAS_mlp_address_property_changed(mlp, address[0], GNUNET_ATS_QUALITY_NET_DISTANCE, 1, 1.0); | ||
282 | 283 | ||
283 | /* Solve problem to build matrix */ | 284 | /* Solve problem to build matrix */ |
284 | GAS_mlp_solve_problem (mlp); | 285 | GAS_mlp_solve_problem (mlp); |