diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-07-04 15:27:59 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-07-04 15:27:59 +0000 |
commit | 9bde041f15f890cb36d67cc0d085e6bc143112cb (patch) | |
tree | b34c08077c07e1fe6a338263e29084d2b42a871f /src/ats/gnunet-service-ats-solver_proportional.c | |
parent | 0151f4b4c92002f7f3e712d1d0bce3d7b2077312 (diff) | |
download | gnunet-9bde041f15f890cb36d67cc0d085e6bc143112cb.tar.gz gnunet-9bde041f15f890cb36d67cc0d085e6bc143112cb.zip |
major change to solver api: split _update function since it combined 3 different functionalities
proportional almost done, mlp to do
Diffstat (limited to 'src/ats/gnunet-service-ats-solver_proportional.c')
-rw-r--r-- | src/ats/gnunet-service-ats-solver_proportional.c | 286 |
1 files changed, 127 insertions, 159 deletions
diff --git a/src/ats/gnunet-service-ats-solver_proportional.c b/src/ats/gnunet-service-ats-solver_proportional.c index 3aca61156..03cba6eb1 100644 --- a/src/ats/gnunet-service-ats-solver_proportional.c +++ b/src/ats/gnunet-service-ats-solver_proportional.c | |||
@@ -431,7 +431,6 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, | |||
431 | unsigned long long assigned_quota_out = 0; | 431 | unsigned long long assigned_quota_out = 0; |
432 | struct AddressWrapper *cur; | 432 | struct AddressWrapper *cur; |
433 | 433 | ||
434 | |||
435 | if (GNUNET_YES == s->bulk_lock) | 434 | if (GNUNET_YES == s->bulk_lock) |
436 | { | 435 | { |
437 | s->bulk_requests++; | 436 | s->bulk_requests++; |
@@ -556,18 +555,6 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, | |||
556 | } | 555 | } |
557 | 556 | ||
558 | 557 | ||
559 | /** | ||
560 | * Extract an ATS performance info from an address | ||
561 | * | ||
562 | * @param address the address | ||
563 | * @param type the type to extract in HBO | ||
564 | * @return the value in HBO or GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist | ||
565 | */ | ||
566 | static int | ||
567 | get_performance_info (struct ATS_Address *address, uint32_t type); | ||
568 | |||
569 | |||
570 | |||
571 | struct FindBestAddressCtx | 558 | struct FindBestAddressCtx |
572 | { | 559 | { |
573 | struct GAS_PROPORTIONAL_Handle *s; | 560 | struct GAS_PROPORTIONAL_Handle *s; |
@@ -871,31 +858,6 @@ addresse_decrement (struct GAS_PROPORTIONAL_Handle *s, | |||
871 | 858 | ||
872 | 859 | ||
873 | /** | 860 | /** |
874 | * Extract an ATS performance info from an address | ||
875 | * | ||
876 | * @param address the address | ||
877 | * @param type the type to extract in HBO | ||
878 | * @return the value in HBO or GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist | ||
879 | */ | ||
880 | static int | ||
881 | get_performance_info (struct ATS_Address *address, uint32_t type) | ||
882 | { | ||
883 | int c1; | ||
884 | GNUNET_assert (NULL != address); | ||
885 | |||
886 | if ((NULL == address->atsi) || (0 == address->atsi_count)) | ||
887 | return GNUNET_ATS_VALUE_UNDEFINED; | ||
888 | |||
889 | for (c1 = 0; c1 < address->atsi_count; c1++) | ||
890 | { | ||
891 | if (ntohl(address->atsi[c1].type) == type) | ||
892 | return ntohl(address->atsi[c1].value); | ||
893 | } | ||
894 | return GNUNET_ATS_VALUE_UNDEFINED; | ||
895 | } | ||
896 | |||
897 | |||
898 | /** | ||
899 | * Solver API functions | 861 | * Solver API functions |
900 | * --------------------------- | 862 | * --------------------------- |
901 | */ | 863 | */ |
@@ -1146,140 +1108,146 @@ GAS_proportional_address_add (void *solver, | |||
1146 | struct ATS_Address *address, | 1108 | struct ATS_Address *address, |
1147 | uint32_t network); | 1109 | uint32_t network); |
1148 | 1110 | ||
1149 | /** | 1111 | |
1150 | * Updates a single address in the solver and checks previous values | ||
1151 | * | ||
1152 | * @param solver the solver Handle | ||
1153 | * @param addresses the address hashmap containing all addresses | ||
1154 | * @param address the update address | ||
1155 | * @param session the previous session | ||
1156 | * @param in_use the previous address in use state | ||
1157 | * @param prev_ats previous ATS information | ||
1158 | * @param prev_atsi_count the previous atsi count | ||
1159 | */ | ||
1160 | void | 1112 | void |
1161 | GAS_proportional_address_update (void *solver, | 1113 | GAS_proportional_address_property_changed (void *solver, |
1162 | struct ATS_Address *address, | 1114 | struct ATS_Address *address, |
1163 | uint32_t session, | 1115 | uint32_t type, |
1164 | int in_use, | 1116 | uint32_t abs_value, |
1165 | const struct GNUNET_ATS_Information *prev_ats, | 1117 | double rel_value) |
1166 | uint32_t prev_atsi_count) | ||
1167 | { | 1118 | { |
1168 | struct ATS_Address *new; | 1119 | struct GAS_PROPORTIONAL_Handle *s; |
1169 | struct GAS_PROPORTIONAL_Handle *s = (struct GAS_PROPORTIONAL_Handle *) solver; | 1120 | struct Network *n; |
1170 | int i; | ||
1171 | uint32_t prev_value; | ||
1172 | uint32_t prev_type; | ||
1173 | uint32_t addr_net; | ||
1174 | int save_active = GNUNET_NO; | ||
1175 | struct Network *new_net = NULL; | ||
1176 | 1121 | ||
1177 | /* Check updates to performance information */ | 1122 | GNUNET_assert (NULL != solver); |
1178 | for (i = 0; i < prev_atsi_count; i++) | 1123 | GNUNET_assert (NULL != address); |
1179 | { | ||
1180 | prev_type = ntohl (prev_ats[i].type); | ||
1181 | prev_value = ntohl (prev_ats[i].value); | ||
1182 | switch (prev_type) | ||
1183 | { | ||
1184 | case GNUNET_ATS_UTILIZATION_UP: | ||
1185 | case GNUNET_ATS_UTILIZATION_DOWN: | ||
1186 | case GNUNET_ATS_QUALITY_NET_DELAY: | ||
1187 | case GNUNET_ATS_QUALITY_NET_DISTANCE: | ||
1188 | case GNUNET_ATS_COST_WAN: | ||
1189 | case GNUNET_ATS_COST_LAN: | ||
1190 | case GNUNET_ATS_COST_WLAN: | ||
1191 | /* No actions required here*/ | ||
1192 | break; | ||
1193 | case GNUNET_ATS_NETWORK_TYPE: | ||
1194 | |||
1195 | addr_net = get_performance_info (address, GNUNET_ATS_NETWORK_TYPE); | ||
1196 | if (GNUNET_ATS_VALUE_UNDEFINED == addr_net) | ||
1197 | { | ||
1198 | GNUNET_break (0); | ||
1199 | addr_net = GNUNET_ATS_NET_UNSPECIFIED; | ||
1200 | } | ||
1201 | if (addr_net != prev_value) | ||
1202 | { | ||
1203 | /* Network changed */ | ||
1204 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Network type changed, moving %s address from `%s' to `%s'\n", | ||
1205 | (GNUNET_YES == address->active) ? "active" : "inactive", | ||
1206 | GNUNET_ATS_print_network_type(prev_value), | ||
1207 | GNUNET_ATS_print_network_type(addr_net)); | ||
1208 | |||
1209 | save_active = address->active; | ||
1210 | /* remove from old network */ | ||
1211 | GAS_proportional_address_delete (solver, address, GNUNET_NO); | ||
1212 | |||
1213 | /* set new network type */ | ||
1214 | new_net = get_network (solver, addr_net); | ||
1215 | if (NULL == new_net) | ||
1216 | { | ||
1217 | /* Address changed to invalid network... */ | ||
1218 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot find network of type `%u' %s\n"), | ||
1219 | addr_net, GNUNET_ATS_print_network_type (addr_net)); | ||
1220 | address->assigned_bw_in = GNUNET_BANDWIDTH_value_init (0); | ||
1221 | address->assigned_bw_out = GNUNET_BANDWIDTH_value_init (0); | ||
1222 | s->bw_changed (s->bw_changed_cls, address); | ||
1223 | return; | ||
1224 | } | ||
1225 | address->solver_information = new_net; | ||
1226 | |||
1227 | /* Add to new network and update*/ | ||
1228 | GAS_proportional_address_add (solver, address, addr_net); | ||
1229 | if (GNUNET_YES == save_active) | ||
1230 | { | ||
1231 | /* check if bandwidth available in new network */ | ||
1232 | if (GNUNET_YES == (is_bandwidth_available_in_network (new_net))) | ||
1233 | { | ||
1234 | /* Suggest updated address */ | ||
1235 | address->active = GNUNET_YES; | ||
1236 | addresse_increment (s, new_net, GNUNET_NO, GNUNET_YES); | ||
1237 | distribute_bandwidth_in_network (solver, new_net, NULL); | ||
1238 | } | ||
1239 | else | ||
1240 | { | ||
1241 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough bandwidth in new network, suggesting alternative address ..\n"); | ||
1242 | |||
1243 | /* Set old address to zero bw */ | ||
1244 | address->assigned_bw_in = GNUNET_BANDWIDTH_value_init (0); | ||
1245 | address->assigned_bw_out = GNUNET_BANDWIDTH_value_init (0); | ||
1246 | s->bw_changed (s->bw_changed_cls, address); | ||
1247 | |||
1248 | /* Find new address to suggest since no bandwidth in network*/ | ||
1249 | new = (struct ATS_Address *) GAS_proportional_get_preferred_address (s, &address->peer); | ||
1250 | if (NULL != new) | ||
1251 | { | ||
1252 | /* Have an alternative address to suggest */ | ||
1253 | s->bw_changed (s->bw_changed_cls, new); | ||
1254 | } | ||
1255 | } | ||
1256 | } | ||
1257 | } | ||
1258 | break; | ||
1259 | case GNUNET_ATS_ARRAY_TERMINATOR: | ||
1260 | break; | ||
1261 | default: | ||
1262 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1263 | "Received unsupported ATS type %u\n", prev_type); | ||
1264 | GNUNET_break (0); | ||
1265 | break; | ||
1266 | 1124 | ||
1267 | } | 1125 | s = (struct GAS_PROPORTIONAL_Handle *) solver; |
1126 | n = (struct Network *) address->solver_information; | ||
1268 | 1127 | ||
1269 | } | 1128 | if (NULL == n) |
1270 | if (address->session_id != session) | 1129 | { |
1130 | GNUNET_break (0); | ||
1131 | return; | ||
1132 | } | ||
1133 | |||
1134 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1135 | "Property `%s' for peer `%s' address %p changed to %.2f %p %p %p\n", | ||
1136 | GNUNET_ATS_print_property_type (type), | ||
1137 | GNUNET_i2s (&address->peer), | ||
1138 | address, | ||
1139 | rel_value, s, n, &distribute_bandwidth_in_network); | ||
1140 | switch (type) | ||
1271 | { | 1141 | { |
1272 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1142 | case GNUNET_ATS_UTILIZATION_UP: |
1273 | "Session changed from %u to %u\n", session, address->session_id); | 1143 | case GNUNET_ATS_UTILIZATION_DOWN: |
1144 | case GNUNET_ATS_QUALITY_NET_DELAY: | ||
1145 | case GNUNET_ATS_QUALITY_NET_DISTANCE: | ||
1146 | case GNUNET_ATS_COST_WAN: | ||
1147 | case GNUNET_ATS_COST_LAN: | ||
1148 | case GNUNET_ATS_COST_WLAN: | ||
1149 | |||
1150 | //FIXME distribute_bandwidth_in_network (s, n, GNUNET_NO); | ||
1151 | break; | ||
1274 | } | 1152 | } |
1275 | if (address->used != in_use) | 1153 | } |
1154 | |||
1155 | |||
1156 | void | ||
1157 | GAS_proportional_address_session_changed (void *solver, | ||
1158 | struct ATS_Address *address, | ||
1159 | uint32_t cur_session, | ||
1160 | uint32_t new_session) | ||
1161 | { | ||
1162 | if (cur_session!= new_session) | ||
1276 | { | 1163 | { |
1277 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1164 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1278 | "Usage changed from %u to %u\n", in_use, address->used); | 1165 | "Session changed from %u to %u\n", cur_session, new_session); |
1279 | } | 1166 | } |
1167 | } | ||
1280 | 1168 | ||
1169 | void | ||
1170 | GAS_proportional_address_inuse_changed (void *solver, | ||
1171 | struct ATS_Address *address, | ||
1172 | int in_use) | ||
1173 | { | ||
1174 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1175 | "Usage changed to %s\n", | ||
1176 | (GNUNET_YES == in_use) ? "USED" : "UNUSED"); | ||
1281 | } | 1177 | } |
1282 | 1178 | ||
1179 | void | ||
1180 | GAS_proportional_address_change_network (void *solver, | ||
1181 | struct ATS_Address *address, | ||
1182 | uint32_t current_network, | ||
1183 | uint32_t new_network) | ||
1184 | { | ||
1185 | struct ATS_Address *new; | ||
1186 | struct GAS_PROPORTIONAL_Handle *s = (struct GAS_PROPORTIONAL_Handle *) solver; | ||
1187 | int save_active = GNUNET_NO; | ||
1188 | struct Network *new_net = NULL; | ||
1189 | |||
1190 | if (current_network == new_network) | ||
1191 | { | ||
1192 | GNUNET_break (0); | ||
1193 | return; | ||
1194 | } | ||
1195 | |||
1196 | /* Network changed */ | ||
1197 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Network type changed, moving %s address from `%s' to `%s'\n", | ||
1198 | (GNUNET_YES == address->active) ? "active" : "inactive", | ||
1199 | GNUNET_ATS_print_network_type (current_network), | ||
1200 | GNUNET_ATS_print_network_type (new_network)); | ||
1201 | |||
1202 | save_active = address->active; | ||
1203 | /* remove from old network */ | ||
1204 | GAS_proportional_address_delete (solver, address, GNUNET_NO); | ||
1205 | |||
1206 | /* set new network type */ | ||
1207 | new_net = get_network (solver, new_network); | ||
1208 | if (NULL == new_net) | ||
1209 | { | ||
1210 | /* Address changed to invalid network... */ | ||
1211 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot find network of type `%u' %s\n"), | ||
1212 | new_network, GNUNET_ATS_print_network_type (new_network)); | ||
1213 | address->assigned_bw_in = GNUNET_BANDWIDTH_value_init (0); | ||
1214 | address->assigned_bw_out = GNUNET_BANDWIDTH_value_init (0); | ||
1215 | s->bw_changed (s->bw_changed_cls, address); | ||
1216 | return; | ||
1217 | } | ||
1218 | address->solver_information = new_net; | ||
1219 | |||
1220 | /* Add to new network and update*/ | ||
1221 | GAS_proportional_address_add (solver, address, new_network); | ||
1222 | if (GNUNET_YES == save_active) | ||
1223 | { | ||
1224 | /* check if bandwidth available in new network */ | ||
1225 | if (GNUNET_YES == (is_bandwidth_available_in_network (new_net))) | ||
1226 | { | ||
1227 | /* Suggest updated address */ | ||
1228 | address->active = GNUNET_YES; | ||
1229 | addresse_increment (s, new_net, GNUNET_NO, GNUNET_YES); | ||
1230 | distribute_bandwidth_in_network (solver, new_net, NULL); | ||
1231 | } | ||
1232 | else | ||
1233 | { | ||
1234 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough bandwidth in new network, suggesting alternative address ..\n"); | ||
1235 | |||
1236 | /* Set old address to zero bw */ | ||
1237 | address->assigned_bw_in = GNUNET_BANDWIDTH_value_init (0); | ||
1238 | address->assigned_bw_out = GNUNET_BANDWIDTH_value_init (0); | ||
1239 | s->bw_changed (s->bw_changed_cls, address); | ||
1240 | |||
1241 | /* Find new address to suggest since no bandwidth in network*/ | ||
1242 | new = (struct ATS_Address *) GAS_proportional_get_preferred_address (s, &address->peer); | ||
1243 | if (NULL != new) | ||
1244 | { | ||
1245 | /* Have an alternative address to suggest */ | ||
1246 | s->bw_changed (s->bw_changed_cls, new); | ||
1247 | } | ||
1248 | } | ||
1249 | } | ||
1250 | } | ||
1283 | 1251 | ||
1284 | /** | 1252 | /** |
1285 | * Add a new single address to a network | 1253 | * Add a new single address to a network |