diff options
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 113 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.h | 7 |
2 files changed, 71 insertions, 49 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index af30ecd1b..185d24f7d 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -198,34 +198,51 @@ reset_peers (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
198 | static void | 198 | static void |
199 | mlp_delete_problem (struct GAS_MLP_Handle *mlp) | 199 | mlp_delete_problem (struct GAS_MLP_Handle *mlp) |
200 | { | 200 | { |
201 | if (mlp != NULL) | 201 | int c; |
202 | { | 202 | if (mlp == NULL) |
203 | if (mlp->p.prob != NULL) | 203 | return; |
204 | glp_delete_prob(mlp->p.prob); | 204 | if (mlp->p.prob != NULL) |
205 | { | ||
206 | glp_delete_prob(mlp->p.prob); | ||
207 | mlp->p.prob = NULL; | ||
208 | } | ||
205 | 209 | ||
206 | /* delete row index */ | 210 | /* delete row index */ |
207 | if (mlp->p.ia != NULL) | 211 | if (mlp->p.ia != NULL) |
208 | { | 212 | { |
209 | GNUNET_free (mlp->p.ia); | 213 | GNUNET_free (mlp->p.ia); |
210 | mlp->p.ia = NULL; | 214 | mlp->p.ia = NULL; |
211 | } | 215 | } |
216 | |||
217 | /* delete column index */ | ||
218 | if (mlp->p.ja != NULL) | ||
219 | { | ||
220 | GNUNET_free (mlp->p.ja); | ||
221 | mlp->p.ja = NULL; | ||
222 | } | ||
223 | |||
224 | /* delete coefficients */ | ||
225 | if (mlp->p.ar != NULL) | ||
226 | { | ||
227 | GNUNET_free (mlp->p.ar); | ||
228 | mlp->p.ar = NULL; | ||
229 | } | ||
230 | mlp->p.ci = 0; | ||
231 | mlp->p.prob = NULL; | ||
232 | |||
233 | mlp->p.c_d = MLP_UNDEFINED; | ||
234 | mlp->p.c_r = MLP_UNDEFINED; | ||
235 | mlp->p.r_c2 = MLP_UNDEFINED; | ||
236 | mlp->p.r_c4 = MLP_UNDEFINED; | ||
237 | mlp->p.r_c6 = MLP_UNDEFINED; | ||
238 | mlp->p.r_c9 = MLP_UNDEFINED; | ||
239 | for (c = 0; c < mlp->pv.m_q ; c ++) | ||
240 | mlp->p.r_q[c] = MLP_UNDEFINED; | ||
241 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c ++) | ||
242 | mlp->p.r_quota[c] = MLP_UNDEFINED; | ||
243 | mlp->p.ci = MLP_UNDEFINED; | ||
212 | 244 | ||
213 | /* delete column index */ | ||
214 | if (mlp->p.ja != NULL) | ||
215 | { | ||
216 | GNUNET_free (mlp->p.ja); | ||
217 | mlp->p.ja = NULL; | ||
218 | } | ||
219 | 245 | ||
220 | /* delete coefficients */ | ||
221 | if (mlp->p.ar != NULL) | ||
222 | { | ||
223 | GNUNET_free (mlp->p.ar); | ||
224 | mlp->p.ar = NULL; | ||
225 | } | ||
226 | mlp->p.ci = 0; | ||
227 | mlp->p.prob = NULL; | ||
228 | } | ||
229 | GNUNET_CONTAINER_multihashmap_iterate (mlp->peers, &reset_peers, NULL); | 246 | GNUNET_CONTAINER_multihashmap_iterate (mlp->peers, &reset_peers, NULL); |
230 | } | 247 | } |
231 | 248 | ||
@@ -815,9 +832,9 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value | |||
815 | struct GAS_MLP_Handle *mlp = cls; | 832 | struct GAS_MLP_Handle *mlp = cls; |
816 | struct ATS_Address *address; | 833 | struct ATS_Address *address; |
817 | struct MLP_information *mlpi; | 834 | struct MLP_information *mlpi; |
818 | double mlp_bw_in = NaN; | 835 | double mlp_bw_in = MLP_NaN; |
819 | double mlp_bw_out = NaN; | 836 | double mlp_bw_out = MLP_NaN; |
820 | double mlp_use = NaN; | 837 | double mlp_use = MLP_NaN; |
821 | 838 | ||
822 | /* Check if we have to add this peer due to a pending request */ | 839 | /* Check if we have to add this peer due to a pending request */ |
823 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->peers, key)) | 840 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->peers, key)) |
@@ -1020,7 +1037,7 @@ GAS_mlp_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addres | |||
1020 | { | 1037 | { |
1021 | mlpi->q_averaged[c1] = DEFAULT_QUALITY; | 1038 | mlpi->q_averaged[c1] = DEFAULT_QUALITY; |
1022 | for (c2 = 0; c2 < MLP_AVERAGING_QUEUE_LENGTH; c2++) | 1039 | for (c2 = 0; c2 < MLP_AVERAGING_QUEUE_LENGTH; c2++) |
1023 | mlpi->q[c1][c2] = NaN; | 1040 | mlpi->q[c1][c2] = MLP_NaN; |
1024 | } | 1041 | } |
1025 | } | 1042 | } |
1026 | else | 1043 | else |
@@ -1060,18 +1077,25 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, | |||
1060 | int avg_index; | 1077 | int avg_index; |
1061 | uint32_t type; | 1078 | uint32_t type; |
1062 | uint32_t value; | 1079 | uint32_t value; |
1080 | uint32_t old_value; | ||
1063 | double avg; | 1081 | double avg; |
1064 | double *queue; | 1082 | double *queue; |
1065 | int rows; | 1083 | int rows; |
1066 | double *val; | 1084 | double *val; |
1067 | int *ind; | 1085 | int *ind; |
1068 | 1086 | ||
1087 | |||
1069 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating %u quality metrics for peer `%s'\n", | 1088 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating %u quality metrics for peer `%s'\n", |
1070 | ats_count, GNUNET_i2s (&address->peer)); | 1089 | ats_count, GNUNET_i2s (&address->peer)); |
1071 | 1090 | ||
1091 | GNUNET_assert (NULL != mlp); | ||
1072 | GNUNET_assert (NULL != address); | 1092 | GNUNET_assert (NULL != address); |
1073 | GNUNET_assert (NULL != address->solver_information); | 1093 | GNUNET_assert (NULL != address->solver_information); |
1074 | GNUNET_assert (NULL != ats); | 1094 | GNUNET_assert (NULL != ats); |
1095 | |||
1096 | if (NULL == mlp->p.prob) | ||
1097 | return; | ||
1098 | |||
1075 | qual_changed = GNUNET_NO; | 1099 | qual_changed = GNUNET_NO; |
1076 | for (c_ats_entry = 0; c_ats_entry < ats_count; c_ats_entry++) | 1100 | for (c_ats_entry = 0; c_ats_entry < ats_count; c_ats_entry++) |
1077 | { | 1101 | { |
@@ -1085,13 +1109,17 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, | |||
1085 | { | 1109 | { |
1086 | if (address->atsp_network_type != value) | 1110 | if (address->atsp_network_type != value) |
1087 | { | 1111 | { |
1088 | LOG (GNUNET_ERROR_TYPE_ERROR, "Updating network for peer `%s' from `%s' to `%s'\n", | 1112 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating network for peer `%s' from `%s' to `%s'\n", |
1089 | GNUNET_i2s (&address->peer), | 1113 | GNUNET_i2s (&address->peer), |
1090 | GNUNET_ATS_print_network_type(address->atsp_network_type), | 1114 | GNUNET_ATS_print_network_type(address->atsp_network_type), |
1091 | GNUNET_ATS_print_network_type(value)); | 1115 | GNUNET_ATS_print_network_type(value)); |
1092 | |||
1093 | } | 1116 | } |
1094 | 1117 | ||
1118 | old_value = address->atsp_network_type; | ||
1119 | address->atsp_network_type = value; | ||
1120 | if (mlpi->c_b == MLP_UNDEFINED) | ||
1121 | continue; /* This address is not yet in the matrix*/ | ||
1122 | |||
1095 | rows = glp_get_num_rows(mlp->p.prob); | 1123 | rows = glp_get_num_rows(mlp->p.prob); |
1096 | ind = GNUNET_malloc (rows * sizeof (int) + 1); | 1124 | ind = GNUNET_malloc (rows * sizeof (int) + 1); |
1097 | val = GNUNET_malloc (rows * sizeof (double) + 1); | 1125 | val = GNUNET_malloc (rows * sizeof (double) + 1); |
@@ -1101,7 +1129,7 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, | |||
1101 | { | 1129 | { |
1102 | if (ind[c_net] == mlp->p.r_quota[value]) | 1130 | if (ind[c_net] == mlp->p.r_quota[value]) |
1103 | LOG (GNUNET_ERROR_TYPE_ERROR, "New [%u] == [%f]\n",ind[c_net],val[c_net]); | 1131 | LOG (GNUNET_ERROR_TYPE_ERROR, "New [%u] == [%f]\n",ind[c_net],val[c_net]); |
1104 | if (ind[c_net] == mlp->p.r_quota[address->atsp_network_type]) | 1132 | if (ind[c_net] == mlp->p.r_quota[old_value]) |
1105 | { | 1133 | { |
1106 | LOG (GNUNET_ERROR_TYPE_ERROR, "Old [%u] == [%f]\n",ind[c_net],val[c_net]); | 1134 | LOG (GNUNET_ERROR_TYPE_ERROR, "Old [%u] == [%f]\n",ind[c_net],val[c_net]); |
1107 | break; | 1135 | break; |
@@ -1124,19 +1152,16 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, | |||
1124 | for (c_net = 0; c_net <= length + 1; c_net ++) | 1152 | for (c_net = 0; c_net <= length + 1; c_net ++) |
1125 | { | 1153 | { |
1126 | if (ind[c_net] == mlp->p.r_quota[value]) | 1154 | if (ind[c_net] == mlp->p.r_quota[value]) |
1127 | LOG (GNUNET_ERROR_TYPE_ERROR, "New [%u] == [%f]\n",ind[c_net],val[c_net]); | 1155 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Removing old network index [%u] == [%f]\n",ind[c_net],val[c_net]); |
1128 | if (ind[c_net] == mlp->p.r_quota[address->atsp_network_type]) | 1156 | if (ind[c_net] == mlp->p.r_quota[old_value]) |
1129 | { | 1157 | { |
1130 | LOG (GNUNET_ERROR_TYPE_ERROR, "Old [%u] == [%f]\n",ind[c_net],val[c_net]); | 1158 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Setting new network index [%u] == [%f]\n",ind[c_net],val[c_net]); |
1131 | break; | 1159 | break; |
1132 | } | 1160 | } |
1133 | } | 1161 | } |
1134 | |||
1135 | GNUNET_free (ind); | 1162 | GNUNET_free (ind); |
1136 | GNUNET_free (val); | 1163 | GNUNET_free (val); |
1137 | address->atsp_network_type = value; | ||
1138 | mlp->mlp_prob_changed = GNUNET_YES; | 1164 | mlp->mlp_prob_changed = GNUNET_YES; |
1139 | |||
1140 | continue; | 1165 | continue; |
1141 | } | 1166 | } |
1142 | 1167 | ||
@@ -1174,7 +1199,7 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, | |||
1174 | avg = 0; | 1199 | avg = 0; |
1175 | for (c_queue_it = 0; c_queue_it < MLP_AVERAGING_QUEUE_LENGTH; c_queue_it++) | 1200 | for (c_queue_it = 0; c_queue_it < MLP_AVERAGING_QUEUE_LENGTH; c_queue_it++) |
1176 | { | 1201 | { |
1177 | if (mlpi->q[type_index][c_queue_it] != NaN) | 1202 | if (mlpi->q[type_index][c_queue_it] != MLP_NaN) |
1178 | { | 1203 | { |
1179 | queue = mlpi->q[type_index] ; | 1204 | queue = mlpi->q[type_index] ; |
1180 | avg += queue[c_queue_it]; | 1205 | avg += queue[c_queue_it]; |
@@ -1216,7 +1241,7 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, | |||
1216 | return; | 1241 | return; |
1217 | 1242 | ||
1218 | /* Address not yet included in matrix */ | 1243 | /* Address not yet included in matrix */ |
1219 | if (0 == mlpi->c_b) | 1244 | if (MLP_UNDEFINED == mlpi->c_b) |
1220 | return; | 1245 | return; |
1221 | 1246 | ||
1222 | /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] | 1247 | /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] |
@@ -1626,8 +1651,8 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1626 | U = DEFAULT_U; | 1651 | U = DEFAULT_U; |
1627 | 1652 | ||
1628 | /* Get quality metric coefficients from configuration */ | 1653 | /* Get quality metric coefficients from configuration */ |
1629 | int i_delay = NaN; | 1654 | int i_delay = MLP_NaN; |
1630 | int i_distance = NaN; | 1655 | int i_distance = MLP_NaN; |
1631 | int q[GNUNET_ATS_QualityPropertiesCount] = GNUNET_ATS_QualityProperties; | 1656 | int q[GNUNET_ATS_QualityPropertiesCount] = GNUNET_ATS_QualityProperties; |
1632 | for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++) | 1657 | for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++) |
1633 | { | 1658 | { |
@@ -1641,7 +1666,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1641 | i_distance = c; | 1666 | i_distance = c; |
1642 | } | 1667 | } |
1643 | 1668 | ||
1644 | if ((i_delay != NaN) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", | 1669 | if ((i_delay != MLP_NaN) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", |
1645 | "MLP_COEFFICIENT_QUALITY_DELAY", | 1670 | "MLP_COEFFICIENT_QUALITY_DELAY", |
1646 | &tmp))) | 1671 | &tmp))) |
1647 | 1672 | ||
@@ -1649,7 +1674,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1649 | else | 1674 | else |
1650 | mlp->pv.co_Q[i_delay] = DEFAULT_QUALITY; | 1675 | mlp->pv.co_Q[i_delay] = DEFAULT_QUALITY; |
1651 | 1676 | ||
1652 | if ((i_distance != NaN) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", | 1677 | if ((i_distance != MLP_NaN) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats", |
1653 | "MLP_COEFFICIENT_QUALITY_DISTANCE", | 1678 | "MLP_COEFFICIENT_QUALITY_DISTANCE", |
1654 | &tmp))) | 1679 | &tmp))) |
1655 | mlp->pv.co_Q[i_distance] = (double) tmp / 100; | 1680 | mlp->pv.co_Q[i_distance] = (double) tmp / 100; |
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index 9bd18f31f..0c608b1d3 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h | |||
@@ -49,7 +49,8 @@ | |||
49 | #define DEFAULT_MIN_CONNECTIONS 4 | 49 | #define DEFAULT_MIN_CONNECTIONS 4 |
50 | #define DEFAULT_PEER_PREFERENCE 1.0 | 50 | #define DEFAULT_PEER_PREFERENCE 1.0 |
51 | 51 | ||
52 | #define NaN -1 | 52 | #define MLP_NaN -1 |
53 | #define MLP_UNDEFINED 0 | ||
53 | #define GLP_YES 1.0 | 54 | #define GLP_YES 1.0 |
54 | #define GLP_NO 0.0 | 55 | #define GLP_NO 0.0 |
55 | 56 | ||
@@ -139,10 +140,6 @@ struct MLP_Problem | |||
139 | int c_r; | 140 | int c_r; |
140 | /* Column index quality metrics */ | 141 | /* Column index quality metrics */ |
141 | int c_q[GNUNET_ATS_QualityPropertiesCount]; | 142 | int c_q[GNUNET_ATS_QualityPropertiesCount]; |
142 | /* column index ressource costs */ | ||
143 | int c_rc[GNUNET_ATS_QualityPropertiesCount]; | ||
144 | /* Column indices ATS network quotas */ | ||
145 | int c_quota[GNUNET_ATS_NetworkTypeCount]; | ||
146 | 143 | ||
147 | /* Problem matrix */ | 144 | /* Problem matrix */ |
148 | /* Current index */ | 145 | /* Current index */ |