aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-02-20 14:56:24 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-02-20 14:56:24 +0000
commite36402e85e1c81ef2a11a8566564cd4d7d999fc6 (patch)
tree700647131e1b45a7432eb3a6a6ea9e4928e080aa /src/ats
parent99866cb070f9e5f01b324a526a9daaa564a95cc7 (diff)
downloadgnunet-e36402e85e1c81ef2a11a8566564cd4d7d999fc6.tar.gz
gnunet-e36402e85e1c81ef2a11a8566564cd4d7d999fc6.zip
- changes to ats
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c109
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.h7
-rw-r--r--src/ats/test_ats_mlp.c15
3 files changed, 118 insertions, 13 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c
index 0c9e0b328..57033f07b 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.c
+++ b/src/ats/gnunet-service-ats_addresses_mlp.c
@@ -347,6 +347,32 @@ create_constraint_it (void *cls, const GNUNET_HashCode * key, void *value)
347 mlp->ar[mlp->ci] = 1; 347 mlp->ar[mlp->ci] = 1;
348 mlp->ci++; 348 mlp->ci++;
349 349
350 /* c 10) obey network specific quotas
351 * (1)*b_1 + ... + (1)*b_m <= quota_n
352 */
353 int cur_row = 0;
354 int c;
355 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
356 {
357 if (mlp->quota_index[c] == address->atsp_network_type)
358 {
359 cur_row = mlp->r_quota[c];
360 break;
361 }
362 }
363
364 if (cur_row != 0)
365 {
366 mlp->ia[mlp->ci] = cur_row;
367 mlp->ja[mlp->ci] = mlpi->c_b;
368 mlp->ar[mlp->ci] = 1;
369 mlp->ci++;
370 }
371 else
372 {
373 GNUNET_break (0);
374 }
375
350 return GNUNET_OK; 376 return GNUNET_OK;
351} 377}
352 378
@@ -421,6 +447,10 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
421 * #rows: |ressources| 447 * #rows: |ressources|
422 * #indices: |n_addresses| 448 * #indices: |n_addresses|
423 * 449 *
450 * c 10) obey network specific quota
451 * #rows: |network types
452 * #indices: |n_addresses|
453 *
424 * Sum for feasibility constraints: 454 * Sum for feasibility constraints:
425 * #rows: 3 * |n_addresses| + |ressources| + |peers| + 1 455 * #rows: 3 * |n_addresses| + |ressources| + |peers| + 1
426 * #indices: 7 * |n_addresses| 456 * #indices: 7 * |n_addresses|
@@ -444,8 +474,8 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
444 * #indices: |n_addresses| + |peers| 474 * #indices: |n_addresses| + |peers|
445 * */ 475 * */
446 476
447 /* last +1 caused by glpk index starting with one */ 477 /* last +1 caused by glpk index starting with one: [1..pi]*/
448 int pi = ((7 * n_addresses) + (4 * n_addresses + mlp->m_q + mlp->c_p + 2) + 1); 478 int pi = ((7 * n_addresses) + (5 * n_addresses + mlp->m_q + mlp->c_p + 2) + 1);
449 mlp->cm_size = pi; 479 mlp->cm_size = pi;
450 mlp->ci = 1; 480 mlp->ci = 1;
451 481
@@ -469,6 +499,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
469 * c 3) minimum bandwidth 499 * c 3) minimum bandwidth
470 * c 4) minimum number of connections 500 * c 4) minimum number of connections
471 * c 6) maximize diversity 501 * c 6) maximize diversity
502 * c 10) obey network specific quota
472 */ 503 */
473 504
474 int min = mlp->n_min; 505 int min = mlp->n_min;
@@ -490,6 +521,14 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
490 ar[mlp->ci] = -1; 521 ar[mlp->ci] = -1;
491 mlp->ci++; 522 mlp->ci++;
492 523
524 /* Add rows for c 10) */
525 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
526 {
527 mlp->r_quota[c] = glp_add_rows (mlp->prob, 1);
528 /* Set bounds to 0 <= x <= quota_out */
529 glp_set_row_bnds (mlp->prob, mlp->r_quota[c], GLP_DB, 0.0, mlp->quota_out[c]);
530 }
531
493 GNUNET_CONTAINER_multihashmap_iterate (addresses, create_constraint_it, mlp); 532 GNUNET_CONTAINER_multihashmap_iterate (addresses, create_constraint_it, mlp);
494 533
495 /* Adding constraint rows 534 /* Adding constraint rows
@@ -549,16 +588,19 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
549 { 588 {
550 mlpi = (struct MLP_information *) addr->mlp_information; 589 mlpi = (struct MLP_information *) addr->mlp_information;
551 590
591 /* coefficient for c 2) */
552 ia[mlp->ci] = peer->r_c2; 592 ia[mlp->ci] = peer->r_c2;
553 ja[mlp->ci] = mlpi->c_n; 593 ja[mlp->ci] = mlpi->c_n;
554 ar[mlp->ci] = 1; 594 ar[mlp->ci] = 1;
555 mlp->ci++; 595 mlp->ci++;
556 596
597 /* coefficient for c 8) */
557 ia[mlp->ci] = mlp->r_c8; 598 ia[mlp->ci] = mlp->r_c8;
558 ja[mlp->ci] = mlpi->c_b; 599 ja[mlp->ci] = mlpi->c_b;
559 ar[mlp->ci] = peer->f; 600 ar[mlp->ci] = peer->f;
560 mlp->ci++; 601 mlp->ci++;
561 602
603 /* coefficient for c 9) */
562 ia[mlp->ci] = peer->r_c9; 604 ia[mlp->ci] = peer->r_c9;
563 ja[mlp->ci] = mlpi->c_b; 605 ja[mlp->ci] = mlpi->c_b;
564 ar[mlp->ci] = 1; 606 ar[mlp->ci] = 1;
@@ -588,7 +630,6 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
588 /* Set row bound == 0 */ 630 /* Set row bound == 0 */
589 glp_set_row_bnds (mlp->prob, mlp->r_q[c], GLP_LO, 0.0, 0.0); 631 glp_set_row_bnds (mlp->prob, mlp->r_q[c], GLP_LO, 0.0, 0.0);
590 632
591 /* Set -q_m */
592 ia[mlp->ci] = mlp->r_q[c]; 633 ia[mlp->ci] = mlp->r_q[c];
593 ja[mlp->ci] = mlp->c_q[c]; 634 ja[mlp->ci] = mlp->c_q[c];
594 ar[mlp->ci] = -1; 635 ar[mlp->ci] = -1;
@@ -605,9 +646,7 @@ mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CON
605 value = (double) addr->ats[index].value; 646 value = (double) addr->ats[index].value;
606 647
607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Quality %i with ATS property `%s' has index %i in addresses ats information has value %f\n", c, mlp_ats_to_string(mlp->q[c]), index, (double) addr->ats[index].value); 648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Quality %i with ATS property `%s' has index %i in addresses ats information has value %f\n", c, mlp_ats_to_string(mlp->q[c]), index, (double) addr->ats[index].value);
608
609 } 649 }
610
611 else 650 else
612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Quality %i with ATS property `%s' not existing\n", c, mlp_ats_to_string(mlp->q[c]), index); 651 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Quality %i with ATS property `%s' not existing\n", c, mlp_ats_to_string(mlp->q[c]), index);
613 652
@@ -1105,11 +1144,65 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1105 else 1144 else
1106 U = 1.0; 1145 U = 1.0;
1107 1146
1147 /* Init network quotas */
1148 int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
1149 int c;
1150
1151 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
1152 {
1153 mlp->quota_index[c] = quotas[c];
1154 static char * entry_in = NULL;
1155 static char * entry_out = NULL;
1156 unsigned long long quota_in = 0;
1157 unsigned long long quota_out = 0;
1158
1159 switch (quotas[c]) {
1160 case GNUNET_ATS_NET_UNSPECIFIED:
1161 entry_out = "UNSPECIFIED_QUOTA_OUT";
1162 entry_in = "UNSPECIFIED_QUOTA_IN";
1163 break;
1164 case GNUNET_ATS_NET_LOOPBACK:
1165 entry_out = "LOOPBACK_QUOTA_OUT";
1166 entry_in = "LOOPBACK_QUOTA_IN";
1167 break;
1168 case GNUNET_ATS_NET_LAN:
1169 entry_out = "LAN_QUOTA_OUT";
1170 entry_in = "LAN_QUOTA_IN";
1171 break;
1172 case GNUNET_ATS_NET_WAN:
1173 entry_out = "WAN_QUOTA_OUT";
1174 entry_in = "WAN_QUOTA_IN";
1175 break;
1176 case GNUNET_ATS_NET_WLAN:
1177 entry_out = "WLAN_QUOTA_OUT";
1178 entry_in = "WLAN_QUOTA_IN";
1179 break;
1180 default:
1181 break;
1182 }
1183
1184 if ((entry_in == NULL) || (entry_out == NULL))
1185 continue;
1186
1187 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", entry_out, &quota_out))
1188 {
1189 quota_out = UINT32_MAX;
1190 }
1191 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", entry_in, &quota_in))
1192 {
1193 quota_in = UINT32_MAX;
1194 }
1195
1196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found `%s' quota %llu and `%s' quota %llu\n",
1197 entry_out, quota_out, entry_in, quota_in);
1198 mlp->quota_out[c] = quota_out;
1199 mlp->quota_in[c] = quota_in;
1200 }
1201
1108 /* Get quality metric coefficients from configuration */ 1202 /* Get quality metric coefficients from configuration */
1109 int i_delay = -1; 1203 int i_delay = -1;
1110 int i_distance = -1; 1204 int i_distance = -1;
1111 int q[GNUNET_ATS_QualityPropertiesCount] = GNUNET_ATS_QualityProperties; 1205 int q[GNUNET_ATS_QualityPropertiesCount] = GNUNET_ATS_QualityProperties;
1112 int c;
1113 for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++) 1206 for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++)
1114 { 1207 {
1115 /* initialize quality coefficients with default value 1.0 */ 1208 /* initialize quality coefficients with default value 1.0 */
@@ -1143,7 +1236,9 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1143 &tmp)) 1236 &tmp))
1144 b_min = tmp; 1237 b_min = tmp;
1145 else 1238 else
1146 b_min = 64000; 1239 {
1240 b_min = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1241 }
1147 1242
1148 /* Get minimum number of connections from configuration */ 1243 /* Get minimum number of connections from configuration */
1149 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", 1244 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h
index a2e665f4b..9e7ca0533 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.h
+++ b/src/ats/gnunet-service-ats_addresses_mlp.h
@@ -223,6 +223,13 @@ struct GAS_MLP_Handle
223 /* number of quality metrics */ 223 /* number of quality metrics */
224 int m_q; 224 int m_q;
225 225
226 /* ATS network quotas */
227 int c_quota[GNUNET_ATS_NetworkTypeCount];
228 int r_quota[GNUNET_ATS_NetworkTypeCount];
229 int quota_index [GNUNET_ATS_NetworkTypeCount];
230 unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
231 unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
232
226 /* ATS ressource costs 233 /* ATS ressource costs
227 * 234 *
228 * array with GNUNET_ATS_QualityPropertiesCount elements 235 * array with GNUNET_ATS_QualityPropertiesCount elements
diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c
index ddcd41237..9726be38f 100644
--- a/src/ats/test_ats_mlp.c
+++ b/src/ats/test_ats_mlp.c
@@ -97,23 +97,26 @@ check (void *cls, char *const *args, const char *cfgfile,
97 set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 32); 97 set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 32);
98 set_ats (&a1_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0); 98 set_ats (&a1_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0);
99 create_address (&addr[0], "dummy", 3, &a1_ats[0]); 99 create_address (&addr[0], "dummy", 3, &a1_ats[0]);
100 addr[0].atsp_network_type = GNUNET_ATS_NET_WAN;
100 101
101 102
102 /* Creating peer 1 address 2 */ 103 /* Creating peer 1 address 2 */
103 addr[1].peer.hashPubKey = p[0].hashPubKey; 104 addr[1].peer.hashPubKey = p[0].hashPubKey;
104 struct GNUNET_ATS_Information a2_ats[3]; 105 struct GNUNET_ATS_Information a2_ats[3];
105 set_ats (&a2_ats[0], GNUNET_ATS_ARRAY_TERMINATOR, 0); 106 set_ats (&a2_ats[0], GNUNET_ATS_QUALITY_NET_DELAY, 32);
106 set_ats (&a2_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 32); 107 set_ats (&a2_ats[1], GNUNET_ATS_QUALITY_NET_DISTANCE, 1);
107 set_ats (&a2_ats[2], GNUNET_ATS_QUALITY_NET_DISTANCE, 1); 108 set_ats (&a2_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0);
108 create_address (&addr[1], "dummy2", 3, &a2_ats[0]); 109 create_address (&addr[1], "dummy2", 3, &a2_ats[0]);
110 addr[1].atsp_network_type = GNUNET_ATS_NET_WAN;
109 111
110 /* Creating peer 2 address 1 */ 112 /* Creating peer 2 address 1 */
111 addr[2].peer.hashPubKey = p[1].hashPubKey; 113 addr[2].peer.hashPubKey = p[1].hashPubKey;
112 struct GNUNET_ATS_Information a3_ats[3]; 114 struct GNUNET_ATS_Information a3_ats[3];
113 set_ats (&a3_ats[0], GNUNET_ATS_ARRAY_TERMINATOR, 0); 115 set_ats (&a3_ats[0], GNUNET_ATS_QUALITY_NET_DELAY, 32);
114 set_ats (&a3_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 32); 116 set_ats (&a3_ats[1], GNUNET_ATS_QUALITY_NET_DISTANCE, 1);
115 set_ats (&a3_ats[2], GNUNET_ATS_QUALITY_NET_DISTANCE, 1); 117 set_ats (&a3_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0);
116 create_address (&addr[2], "dummy3", 3, &a3_ats[0]); 118 create_address (&addr[2], "dummy3", 3, &a3_ats[0]);
119 addr[2].atsp_network_type = GNUNET_ATS_NET_LAN;
117 120
118 GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 121 GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
119 122