aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorFabian Oehlmann <oehlmann@in.tum.de>2013-11-19 16:37:38 +0000
committerFabian Oehlmann <oehlmann@in.tum.de>2013-11-19 16:37:38 +0000
commit0d16a1d037dc3c4f16c41cde1594ae353833507c (patch)
tree097123faffc89142f712617abf1737c6dd4ef279 /src/ats
parent1b0390ed82cc7378d945f63933d70d06fa0658d7 (diff)
downloadgnunet-0d16a1d037dc3c4f16c41cde1594ae353833507c.tar.gz
gnunet-0d16a1d037dc3c4f16c41cde1594ae353833507c.zip
-integer underflow fix
-bw_changed_cb invocation separate -benchmark info calls
Diffstat (limited to 'src/ats')
-rwxr-xr-xsrc/ats/libgnunet_plugin_ats_ril.c237
1 files changed, 135 insertions, 102 deletions
diff --git a/src/ats/libgnunet_plugin_ats_ril.c b/src/ats/libgnunet_plugin_ats_ril.c
index 045cc91d5..d5621bbd4 100755
--- a/src/ats/libgnunet_plugin_ats_ril.c
+++ b/src/ats/libgnunet_plugin_ats_ril.c
@@ -229,6 +229,16 @@ struct RIL_Peer_Agent
229 * Outbound bandwidth assigned by the agent 229 * Outbound bandwidth assigned by the agent
230 */ 230 */
231 unsigned long long bw_out; 231 unsigned long long bw_out;
232
233 /**
234 * Flag whether a suggestion has to be issued
235 */
236 int suggestion_issue;
237
238 /**
239 * The address which has to be issued ()
240 */
241 struct ATS_Address * suggestion_address;
232}; 242};
233 243
234struct RIL_Network 244struct RIL_Network
@@ -244,19 +254,9 @@ struct RIL_Network
244 unsigned long long bw_in_available; 254 unsigned long long bw_in_available;
245 255
246 /** 256 /**
247 * Total assigned outbound bandwidth
248 */
249 unsigned long long bw_in_assigned;
250
251 /**
252 * Total available outbound bandwidth 257 * Total available outbound bandwidth
253 */ 258 */
254 unsigned long long bw_out_available; 259 unsigned long long bw_out_available;
255
256 /**
257 * Total assigned outbound bandwidth
258 */
259 unsigned long long bw_out_assigned;
260}; 260};
261 261
262/** 262/**
@@ -568,7 +568,7 @@ envi_set_active_suggestion (struct GAS_RIL_Handle *solver,
568{ 568{
569 int notify = GNUNET_NO; 569 int notify = GNUNET_NO;
570 570
571 LOG(GNUNET_ERROR_TYPE_DEBUG, "set_active_suggestion()\n"); 571 LOG(GNUNET_ERROR_TYPE_DEBUG, " set_active_suggestion() for peer '%s'\n", GNUNET_i2s (&agent->peer));
572 572
573 //address change 573 //address change
574 if (agent->address_inuse != new_address) 574 if (agent->address_inuse != new_address)
@@ -581,7 +581,7 @@ envi_set_active_suggestion (struct GAS_RIL_Handle *solver,
581 } 581 }
582 if (NULL != new_address) 582 if (NULL != new_address)
583 { 583 {
584 LOG(GNUNET_ERROR_TYPE_DEBUG, "set address active: %s\n", agent->is_active ? "yes" : "no"); 584 LOG(GNUNET_ERROR_TYPE_DEBUG, " set address active: %s\n", agent->is_active ? "yes" : "no");
585 new_address->active = agent->is_active; 585 new_address->active = agent->is_active;
586 new_address->assigned_bw_in.value__ = htonl (agent->bw_in); 586 new_address->assigned_bw_in.value__ = htonl (agent->bw_in);
587 new_address->assigned_bw_out.value__ = htonl (agent->bw_out); 587 new_address->assigned_bw_out.value__ = htonl (agent->bw_out);
@@ -595,13 +595,14 @@ envi_set_active_suggestion (struct GAS_RIL_Handle *solver,
595 if (new_address->active != agent->is_active) 595 if (new_address->active != agent->is_active)
596 { 596 {
597 new_address->active = agent->is_active; 597 new_address->active = agent->is_active;
598 notify |= GNUNET_YES;
598 } 599 }
599 600
600 //bw change 601 //bw change
601 if (agent->bw_in != new_bw_in) 602 if (agent->bw_in != new_bw_in)
602 { 603 {
603 agent->bw_in = new_bw_in; 604 agent->bw_in = new_bw_in;
604 new_address->assigned_bw_in.value__ = htonl (new_bw_out); 605 new_address->assigned_bw_in.value__ = htonl (new_bw_in);
605 notify |= GNUNET_YES; 606 notify |= GNUNET_YES;
606 } 607 }
607 if (agent->bw_out != new_bw_out) 608 if (agent->bw_out != new_bw_out)
@@ -616,23 +617,50 @@ envi_set_active_suggestion (struct GAS_RIL_Handle *solver,
616 { 617 {
617 if (new_address) 618 if (new_address)
618 { 619 {
619 solver->plugin_envi->bandwidth_changed_cb (solver->plugin_envi->bw_changed_cb_cls, 620 LOG(GNUNET_ERROR_TYPE_DEBUG, " envi_set_active_suggestion() notify\n");
620 new_address); 621 agent->suggestion_issue = GNUNET_YES;
622 agent->suggestion_address = new_address;
621 } 623 }
622 else if (agent->address_inuse) 624 else if (agent->address_inuse)
623 { 625 {
626 //disconnect case, no new address
624 GNUNET_assert(0 == ntohl (agent->address_inuse->assigned_bw_in.value__)); 627 GNUNET_assert(0 == ntohl (agent->address_inuse->assigned_bw_in.value__));
625 GNUNET_assert(0 == ntohl (agent->address_inuse->assigned_bw_out.value__)); 628 GNUNET_assert(0 == ntohl (agent->address_inuse->assigned_bw_out.value__));
626 agent->bw_in = 0; 629 agent->bw_in = 0;
627 agent->bw_out = 0; 630 agent->bw_out = 0;
628 //disconnect 631
629 solver->plugin_envi->bandwidth_changed_cb (solver->plugin_envi->bw_changed_cb_cls, 632 agent->suggestion_issue = GNUNET_YES;
630 agent->address_inuse); 633 agent->suggestion_address = agent->address_inuse;
631 } 634 }
632 } 635 }
633 agent->address_inuse = new_address; 636 agent->address_inuse = new_address;
634} 637}
635 638
639static unsigned long long
640ril_network_get_assigned (struct GAS_RIL_Handle *solver, enum GNUNET_ATS_Network_Type type, int direction_in)
641{
642 struct RIL_Peer_Agent *cur;
643 struct RIL_Network *net;
644 unsigned long long sum = 0;
645
646 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
647 {
648 if (cur->is_active && cur->address_inuse)
649 {
650 net = cur->address_inuse->solver_information;
651 if (net->type == type)
652 {
653 if (direction_in)
654 sum += cur->bw_in;
655 else
656 sum += cur->bw_out;
657 }
658 }
659 }
660
661 return sum;
662}
663
636/** 664/**
637 * Allocates a state vector and fills it with the features present 665 * Allocates a state vector and fills it with the features present
638 * @param solver the solver handle 666 * @param solver the solver handle
@@ -644,18 +672,18 @@ envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
644{ 672{
645 int i; 673 int i;
646 int k; 674 int k;
647 struct RIL_Network *net; 675 struct RIL_Network net;
648 double *state = GNUNET_malloc (sizeof (double) * agent->m); 676 double *state = GNUNET_malloc (sizeof (double) * agent->m);
649 struct RIL_Address_Wrapped *cur_address; 677 struct RIL_Address_Wrapped *cur_address;
650 const double *properties; 678 const double *properties;
651 679
652 for (i = 0; i < solver->networks_count; i++) 680 for (i = 0; i < solver->networks_count; i++)
653 { 681 {
654 net = &solver->network_entries[i]; 682 net = solver->network_entries[i];
655 state[i * RIL_FEATURES_NETWORK_COUNT + 0] = (double) net->bw_in_assigned; 683 state[i * RIL_FEATURES_NETWORK_COUNT + 0] = (double) ril_network_get_assigned(solver, net.type, GNUNET_YES);
656 state[i * RIL_FEATURES_NETWORK_COUNT + 1] = (double) net->bw_in_available; 684 state[i * RIL_FEATURES_NETWORK_COUNT + 1] = (double) net.bw_in_available;
657 state[i * RIL_FEATURES_NETWORK_COUNT + 2] = (double) net->bw_out_assigned; 685 state[i * RIL_FEATURES_NETWORK_COUNT + 2] = (double) ril_network_get_assigned(solver, net.type, GNUNET_NO);
658 state[i * RIL_FEATURES_NETWORK_COUNT + 3] = (double) net->bw_out_available; 686 state[i * RIL_FEATURES_NETWORK_COUNT + 3] = (double) net.bw_out_available;
659 } 687 }
660 688
661 i = i * RIL_FEATURES_NETWORK_COUNT; //first address feature 689 i = i * RIL_FEATURES_NETWORK_COUNT; //first address feature
@@ -753,23 +781,25 @@ static double
753envi_reward_global (struct GAS_RIL_Handle *solver) 781envi_reward_global (struct GAS_RIL_Handle *solver)
754{ 782{
755 int i; 783 int i;
756 unsigned int in_available = 0; 784 struct RIL_Network net;
757 unsigned int out_available = 0; 785 unsigned int sum_in_available = 0;
758 unsigned int in_assigned = 0; 786 unsigned int sum_out_available = 0;
759 unsigned int out_assigned = 0; 787 unsigned int sum_in_assigned = 0;
788 unsigned int sum_out_assigned = 0;
760 double ratio_in; 789 double ratio_in;
761 double ratio_out; 790 double ratio_out;
762 791
763 for (i = 0; i < solver->networks_count; i++) 792 for (i = 0; i < solver->networks_count; i++)
764 { 793 {
765 in_available += solver->network_entries[i].bw_in_available; 794 net = solver->network_entries[i];
766 in_assigned += solver->network_entries[i].bw_in_assigned; 795 sum_in_available += net.bw_in_available;
767 out_available += solver->network_entries[i].bw_out_available; 796 sum_in_assigned += ril_network_get_assigned(solver, net.type, GNUNET_YES);
768 out_assigned += solver->network_entries[i].bw_out_assigned; 797 sum_out_available += net.bw_out_available;
798 sum_out_assigned += ril_network_get_assigned(solver, net.type, GNUNET_NO);
769 } 799 }
770 800
771 ratio_in = ((double) in_assigned) / ((double) in_available); 801 ratio_in = ((double) sum_in_assigned) / ((double) sum_in_available);
772 ratio_out = ((double) out_assigned) / ((double) out_available); 802 ratio_out = ((double) sum_out_assigned) / ((double) sum_out_available);
773 803
774 // global reward in [1,2] 804 // global reward in [1,2]
775 return ((ratio_in + ratio_out) / 2) + 1; 805 return ((ratio_in + ratio_out) / 2) + 1;
@@ -825,8 +855,8 @@ envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
825 855
826 //punish overutilization 856 //punish overutilization
827 net = agent->address_inuse->solver_information; 857 net = agent->address_inuse->solver_information;
828 if ((net->bw_in_assigned > net->bw_in_available) 858 if ((ril_network_get_assigned(solver, net->type, GNUNET_YES) > net->bw_in_available)
829 || (net->bw_out_assigned > net->bw_out_available)) 859 || (ril_network_get_assigned(solver, net->type, GNUNET_NO) > net->bw_out_available))
830 { 860 {
831 return 0; 861 return 0;
832 } 862 }
@@ -848,15 +878,23 @@ envi_action_bw_double (struct GAS_RIL_Handle *solver,
848 struct RIL_Peer_Agent *agent, 878 struct RIL_Peer_Agent *agent,
849 int direction_in) 879 int direction_in)
850{ 880{
881 unsigned long long new_bw;
882
851 if (direction_in) 883 if (direction_in)
852 { 884 {
853 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in * 2, 885 new_bw = agent->bw_in * 2;
886 if (new_bw < agent->bw_in)
887 new_bw = ULLONG_MAX;
888 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw,
854 agent->bw_out, GNUNET_NO); 889 agent->bw_out, GNUNET_NO);
855 } 890 }
856 else 891 else
857 { 892 {
893 new_bw = agent->bw_out * 2;
894 if (new_bw < agent->bw_out)
895 new_bw = ULLONG_MAX;
858 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, 896 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in,
859 agent->bw_out * 2, GNUNET_NO); 897 new_bw, GNUNET_NO);
860 } 898 }
861} 899}
862 900
@@ -880,7 +918,7 @@ envi_action_bw_halven (struct GAS_RIL_Handle *solver,
880 if (direction_in) 918 if (direction_in)
881 { 919 {
882 new_bw = agent->bw_in / 2; 920 new_bw = agent->bw_in / 2;
883 if (new_bw < min_bw) 921 if (new_bw < min_bw || new_bw > agent->bw_in)
884 new_bw = min_bw; 922 new_bw = min_bw;
885 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out, 923 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out,
886 GNUNET_NO); 924 GNUNET_NO);
@@ -888,7 +926,7 @@ envi_action_bw_halven (struct GAS_RIL_Handle *solver,
888 else 926 else
889 { 927 {
890 new_bw = agent->bw_out / 2; 928 new_bw = agent->bw_out / 2;
891 if (new_bw < min_bw) 929 if (new_bw < min_bw || new_bw > agent->bw_out)
892 new_bw = min_bw; 930 new_bw = min_bw;
893 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw, 931 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw,
894 GNUNET_NO); 932 GNUNET_NO);
@@ -906,17 +944,24 @@ envi_action_bw_halven (struct GAS_RIL_Handle *solver,
906static void 944static void
907envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) 945envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in)
908{ 946{
947 unsigned long long new_bw;
909 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 948 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
910 949
911 if (direction_in) 950 if (direction_in)
912 { 951 {
913 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in + (5 * min_bw), 952 new_bw = agent->bw_in + (5 * min_bw);
953 if (new_bw < agent->bw_in)
954 new_bw = ULLONG_MAX;
955 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw,
914 agent->bw_out, GNUNET_NO); 956 agent->bw_out, GNUNET_NO);
915 } 957 }
916 else 958 else
917 { 959 {
960 new_bw = agent->bw_out + (5 * min_bw);
961 if (new_bw < agent->bw_out)
962 new_bw = ULLONG_MAX;
918 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, 963 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in,
919 agent->bw_out + (5 * min_bw), GNUNET_NO); 964 new_bw, GNUNET_NO);
920 } 965 }
921} 966}
922 967
@@ -938,7 +983,7 @@ envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent,
938 if (direction_in) 983 if (direction_in)
939 { 984 {
940 new_bw = agent->bw_in - (5 * min_bw); 985 new_bw = agent->bw_in - (5 * min_bw);
941 if (new_bw < min_bw) 986 if (new_bw < min_bw || new_bw > agent->bw_in)
942 new_bw = min_bw; 987 new_bw = min_bw;
943 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out, 988 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out,
944 GNUNET_NO); 989 GNUNET_NO);
@@ -946,7 +991,7 @@ envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent,
946 else 991 else
947 { 992 {
948 new_bw = agent->bw_out - (5 * min_bw); 993 new_bw = agent->bw_out - (5 * min_bw);
949 if (new_bw < min_bw) 994 if (new_bw < min_bw || new_bw > agent->bw_in)
950 new_bw = min_bw; 995 new_bw = min_bw;
951 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw, 996 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw,
952 GNUNET_NO); 997 GNUNET_NO);
@@ -1056,12 +1101,13 @@ agent_step (struct RIL_Peer_Agent *agent)
1056 double *s_next; 1101 double *s_next;
1057 double reward; 1102 double reward;
1058 1103
1104 LOG(GNUNET_ERROR_TYPE_DEBUG, " agent_step() Peer '%s', algorithm %s\n",
1105 GNUNET_i2s (&agent->peer),
1106 agent->envi->parameters.algorithm ? "Q" : "SARSA");
1107
1059 s_next = envi_get_state (agent->envi, agent); 1108 s_next = envi_get_state (agent->envi, agent);
1060 reward = envi_get_reward (agent->envi, agent); 1109 reward = envi_get_reward (agent->envi, agent);
1061 1110
1062 LOG(GNUNET_ERROR_TYPE_DEBUG, "agent_step() with algorithm %s\n",
1063 agent->envi->parameters.algorithm ? "Q" : "SARSA");
1064
1065 switch (agent->envi->parameters.algorithm) 1111 switch (agent->envi->parameters.algorithm)
1066 { 1112 {
1067 case RIL_ALGO_SARSA: 1113 case RIL_ALGO_SARSA:
@@ -1101,6 +1147,10 @@ agent_step (struct RIL_Peer_Agent *agent)
1101 break; 1147 break;
1102 } 1148 }
1103 1149
1150 //TODO delete this, debug test, faulty actions are 1357
1151 a_next = 1;
1152 LOG(GNUNET_ERROR_TYPE_INFO, " a_next = %d\n", a_next);
1153
1104 GNUNET_assert(RIL_ACTION_INVALID != a_next); 1154 GNUNET_assert(RIL_ACTION_INVALID != a_next);
1105 1155
1106 agent_modify_eligibility (agent, RIL_E_ACCUMULATE); 1156 agent_modify_eligibility (agent, RIL_E_ACCUMULATE);
@@ -1145,10 +1195,10 @@ ril_get_used_resource_ratio (struct GAS_RIL_Handle *solver)
1145 for (i = 0; i < solver->networks_count; i++) 1195 for (i = 0; i < solver->networks_count; i++)
1146 { 1196 {
1147 net = solver->network_entries[i]; 1197 net = solver->network_entries[i];
1148 if (net.bw_in_assigned > 0) //only consider scopes with an active address 1198 if (ril_network_get_assigned(solver, net.type, GNUNET_YES) > 0) //only consider scopes with an active address
1149 { 1199 {
1150 sum_assigned += net.bw_in_assigned; 1200 sum_assigned += ril_network_get_assigned(solver, net.type, GNUNET_YES);
1151 sum_assigned += net.bw_out_assigned; 1201 sum_assigned += ril_network_get_assigned(solver, net.type, GNUNET_NO);
1152 sum_available += net.bw_in_available; 1202 sum_available += net.bw_in_available;
1153 sum_available += net.bw_out_available; 1203 sum_available += net.bw_out_available;
1154 } 1204 }
@@ -1197,9 +1247,6 @@ ril_step_schedule_next (struct GAS_RIL_Handle *solver)
1197 offset = (double) solver->parameters.step_time_min.rel_value_us; 1247 offset = (double) solver->parameters.step_time_min.rel_value_us;
1198 y = factor * pow (used_ratio, RIL_INTERVAL_EXPONENT) + offset; 1248 y = factor * pow (used_ratio, RIL_INTERVAL_EXPONENT) + offset;
1199 1249
1200 //LOG (GNUNET_ERROR_TYPE_INFO, "used = %f, min = %f, max = %f\n", used_ratio, (double)solver->parameters.step_time_min.rel_value_us, (double)solver->parameters.step_time_max.rel_value_us);
1201 //LOG (GNUNET_ERROR_TYPE_INFO, "factor = %f, offset = %f, y = %f\n", factor, offset, y);
1202
1203 GNUNET_assert(y <= (double ) solver->parameters.step_time_max.rel_value_us); 1250 GNUNET_assert(y <= (double ) solver->parameters.step_time_max.rel_value_us);
1204 GNUNET_assert(y >= (double ) solver->parameters.step_time_min.rel_value_us); 1251 GNUNET_assert(y >= (double ) solver->parameters.step_time_min.rel_value_us);
1205 1252
@@ -1230,7 +1277,7 @@ ril_step (struct GAS_RIL_Handle *solver)
1230 1277
1231 ril_inform (solver, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS); 1278 ril_inform (solver, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS);
1232 1279
1233 LOG(GNUNET_ERROR_TYPE_DEBUG, "RIL step number %d\n", solver->step_count); 1280 LOG(GNUNET_ERROR_TYPE_DEBUG, " RIL step number %d\n", solver->step_count);
1234 1281
1235 if (0 == solver->step_count) 1282 if (0 == solver->step_count)
1236 { 1283 {
@@ -1263,6 +1310,18 @@ ril_step (struct GAS_RIL_Handle *solver)
1263 1310
1264 ril_inform (solver, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS); 1311 ril_inform (solver, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS);
1265 1312
1313 ril_inform (solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, GAS_STAT_SUCCESS);
1314 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
1315 {
1316 if (cur->suggestion_issue) {
1317 solver->plugin_envi->bandwidth_changed_cb(solver->plugin_envi->bw_changed_cb_cls, cur->suggestion_address);
1318 LOG(GNUNET_ERROR_TYPE_DEBUG, "\n Suggest address: %s\n\n",
1319 cur->suggestion_address->addr);
1320 cur->suggestion_issue = GNUNET_NO;
1321 }
1322 }
1323 ril_inform (solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, GAS_STAT_SUCCESS);
1324
1266 return GNUNET_YES; 1325 return GNUNET_YES;
1267} 1326}
1268 1327
@@ -1284,6 +1343,9 @@ agent_init (void *s, const struct GNUNET_PeerIdentity *peer)
1284 agent->peer = *peer; 1343 agent->peer = *peer;
1285 agent->step_count = 0; 1344 agent->step_count = 0;
1286 agent->is_active = GNUNET_NO; 1345 agent->is_active = GNUNET_NO;
1346 agent->bw_in = 0;
1347 agent->bw_out = 0;
1348 agent->suggestion_issue = GNUNET_NO;
1287 agent->n = RIL_ACTION_TYPE_NUM; 1349 agent->n = RIL_ACTION_TYPE_NUM;
1288 agent->m = solver->networks_count * RIL_FEATURES_NETWORK_COUNT; 1350 agent->m = solver->networks_count * RIL_FEATURES_NETWORK_COUNT;
1289 agent->W = (double **) GNUNET_malloc (sizeof (double *) * agent->n); 1351 agent->W = (double **) GNUNET_malloc (sizeof (double *) * agent->n);
@@ -1574,9 +1636,7 @@ libgnunet_plugin_ats_ril_init (void *cls)
1574 cur = &solver->network_entries[c]; 1636 cur = &solver->network_entries[c];
1575 cur->type = env->networks[c]; 1637 cur->type = env->networks[c];
1576 cur->bw_in_available = env->in_quota[c]; 1638 cur->bw_in_available = env->in_quota[c];
1577 cur->bw_in_assigned = 0;
1578 cur->bw_out_available = env->out_quota[c]; 1639 cur->bw_out_available = env->out_quota[c];
1579 cur->bw_out_assigned = 0;
1580 } 1640 }
1581 1641
1582 solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed ( 1642 solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed (
@@ -1644,13 +1704,15 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network
1644 unsigned int zero; 1704 unsigned int zero;
1645 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 1705 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1646 1706
1707 LOG (GNUNET_ERROR_TYPE_DEBUG, "API_address_add()\n");
1708
1647 net = ril_get_network (s, network); 1709 net = ril_get_network (s, network);
1648 address->solver_information = net; 1710 address->solver_information = net;
1649 1711
1650 if (!ril_network_is_active (s, network)) 1712 if (!ril_network_is_active (s, network))
1651 { 1713 {
1652 LOG(GNUNET_ERROR_TYPE_DEBUG, 1714 LOG(GNUNET_ERROR_TYPE_DEBUG,
1653 "API_address_add() Did not add %s address %p for peer '%s', network does not have enough bandwidth\n", 1715 "API_address_add() Did not add %s address %s for peer '%s', network does not have enough bandwidth\n",
1654 address->plugin, address->addr, GNUNET_i2s (&address->peer)); 1716 address->plugin, address->addr, GNUNET_i2s (&address->peer));
1655 return; 1717 return;
1656 } 1718 }
@@ -1692,14 +1754,12 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network
1692 1754
1693 if (NULL == agent->address_inuse) 1755 if (NULL == agent->address_inuse)
1694 { 1756 {
1695 net->bw_in_assigned += min_bw;
1696 net->bw_out_assigned += min_bw;
1697 envi_set_active_suggestion (s, agent, address, min_bw, min_bw, GNUNET_NO); 1757 envi_set_active_suggestion (s, agent, address, min_bw, min_bw, GNUNET_NO);
1698 } 1758 }
1699 1759
1700 ril_step (s); 1760 ril_step (s);
1701 1761
1702 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %p for peer '%s'\n", 1762 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %s for peer '%s'\n",
1703 address->active ? "active" : "inactive", address->plugin, address->addr, 1763 address->active ? "active" : "inactive", address->plugin, address->addr,
1704 GNUNET_i2s (&address->peer)); 1764 GNUNET_i2s (&address->peer));
1705} 1765}
@@ -1727,7 +1787,7 @@ GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_o
1727 struct RIL_Network *net; 1787 struct RIL_Network *net;
1728 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 1788 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1729 1789
1730 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_delete() Delete %s%s %s address %p for peer '%s'\n", 1790 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_delete() Delete %s%s %s address %s for peer '%s'\n",
1731 session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin, 1791 session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin,
1732 address->addr, GNUNET_i2s (&address->peer)); 1792 address->addr, GNUNET_i2s (&address->peer));
1733 1793
@@ -1792,20 +1852,13 @@ GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_o
1792 1852
1793 if (address_was_used) 1853 if (address_was_used)
1794 { 1854 {
1795 net = address->solver_information;
1796 net->bw_in_assigned -= agent->bw_in;
1797 net->bw_out_assigned -= agent->bw_out;
1798
1799 if (NULL != agent->addresses_head) //if peer has an address left, use it 1855 if (NULL != agent->addresses_head) //if peer has an address left, use it
1800 { 1856 {
1801 LOG(GNUNET_ERROR_TYPE_DEBUG, "address left: %p\n", 1857 LOG(GNUNET_ERROR_TYPE_DEBUG, "address left: %s\n",
1802 agent->addresses_head->address_naked->addr); 1858 agent->addresses_head->address_naked->addr);
1803 //TODO? check if network/bandwidth update can be done more clever/elegant at different function 1859
1804 envi_set_active_suggestion (s, agent, agent->addresses_head->address_naked, min_bw, min_bw, 1860 envi_set_active_suggestion (s, agent, agent->addresses_head->address_naked, min_bw, min_bw,
1805 GNUNET_NO); 1861 GNUNET_NO);
1806 net = agent->addresses_head->address_naked->solver_information;
1807 net->bw_in_assigned -= min_bw;
1808 net->bw_out_assigned -= min_bw;
1809 } 1862 }
1810 else 1863 else
1811 { 1864 {
@@ -1815,9 +1868,9 @@ GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_o
1815 } 1868 }
1816 } 1869 }
1817 1870
1818 ril_step (solver); 1871 LOG(GNUNET_ERROR_TYPE_DEBUG, "Address deleted: %s\n", address->addr);
1819 1872
1820 LOG(GNUNET_ERROR_TYPE_DEBUG, "Address deleted\n"); 1873 ril_step (solver);
1821} 1874}
1822 1875
1823/** 1876/**
@@ -1837,7 +1890,7 @@ GAS_ril_address_property_changed (void *solver,
1837 double rel_value) 1890 double rel_value)
1838{ 1891{
1839 LOG(GNUNET_ERROR_TYPE_DEBUG, 1892 LOG(GNUNET_ERROR_TYPE_DEBUG,
1840 "API_address_property_changed() Property '%s' for peer '%s' address %p changed " 1893 "API_address_property_changed() Property '%s' for peer '%s' address %s changed "
1841 "to %.2f \n", GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer), 1894 "to %.2f \n", GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
1842 address->addr, rel_value); 1895 address->addr, rel_value);
1843 1896
@@ -1905,8 +1958,6 @@ GAS_ril_address_change_network (void *solver,
1905{ 1958{
1906 struct GAS_RIL_Handle *s = solver; 1959 struct GAS_RIL_Handle *s = solver;
1907 struct RIL_Peer_Agent *agent; 1960 struct RIL_Peer_Agent *agent;
1908 struct RIL_Network *net;
1909 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1910 1961
1911 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_change_network() Network type changed, moving " 1962 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_change_network() Network type changed, moving "
1912 "%s address of peer %s from '%s' to '%s'\n", 1963 "%s address of peer %s from '%s' to '%s'\n",
@@ -1928,14 +1979,7 @@ GAS_ril_address_change_network (void *solver,
1928 return; 1979 return;
1929 } 1980 }
1930 1981
1931 net = ril_get_network (s, current_network); 1982 address->solver_information = ril_get_network(solver, new_network);
1932 net->bw_in_assigned -= agent->bw_in;
1933 net->bw_out_assigned -= agent->bw_out;
1934
1935 net = ril_get_network (s, new_network);
1936 net->bw_in_assigned -= min_bw;
1937 net->bw_out_assigned -= min_bw;
1938 address->solver_information = net;
1939} 1983}
1940 1984
1941/** 1985/**
@@ -1972,7 +2016,7 @@ GAS_ril_bulk_start (void *solver)
1972{ 2016{
1973 struct GAS_RIL_Handle *s = solver; 2017 struct GAS_RIL_Handle *s = solver;
1974 2018
1975 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_start() Locking solver for bulk operation ...\n"); 2019 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_start() lock: %d\n", s->bulk_lock+1);
1976 2020
1977 s->bulk_lock++; 2021 s->bulk_lock++;
1978} 2022}
@@ -1987,7 +2031,7 @@ GAS_ril_bulk_stop (void *solver)
1987{ 2031{
1988 struct GAS_RIL_Handle *s = solver; 2032 struct GAS_RIL_Handle *s = solver;
1989 2033
1990 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_stop() Releasing solver from bulk operation ...\n"); 2034 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_stop() lock: %d\n", s->bulk_lock-1);
1991 2035
1992 if (s->bulk_lock < 1) 2036 if (s->bulk_lock < 1)
1993 { 2037 {
@@ -2021,25 +2065,20 @@ GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *p
2021 */ 2065 */
2022 struct GAS_RIL_Handle *s = solver; 2066 struct GAS_RIL_Handle *s = solver;
2023 struct RIL_Peer_Agent *agent; 2067 struct RIL_Peer_Agent *agent;
2024 struct RIL_Network *net; 2068
2069 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_get_preferred_address()\n");
2025 2070
2026 agent = ril_get_agent (s, peer, GNUNET_YES); 2071 agent = ril_get_agent (s, peer, GNUNET_YES);
2027 2072
2028 agent->is_active = GNUNET_YES; 2073 agent->is_active = GNUNET_YES;
2029 2074
2030 if (agent->address_inuse)
2031 {
2032 net = agent->address_inuse->solver_information;
2033 net->bw_in_assigned += agent->bw_in;
2034 net->bw_out_assigned += agent->bw_out;
2035 }
2036 envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, 2075 envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in, agent->bw_out,
2037 GNUNET_YES); 2076 GNUNET_YES);
2038 2077
2039 if (agent->address_inuse) 2078 if (agent->address_inuse)
2040 { 2079 {
2041 LOG(GNUNET_ERROR_TYPE_DEBUG, 2080 LOG(GNUNET_ERROR_TYPE_DEBUG,
2042 "API_get_preferred_address() Activated agent for peer '%s' with %s address %p\n", 2081 "API_get_preferred_address() Activated agent for peer '%s' with %s address %s\n",
2043 GNUNET_i2s (peer), agent->address_inuse->plugin, agent->address_inuse->addr); 2082 GNUNET_i2s (peer), agent->address_inuse->plugin, agent->address_inuse->addr);
2044 } 2083 }
2045 else 2084 else
@@ -2049,8 +2088,6 @@ GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *p
2049 GNUNET_i2s (peer)); 2088 GNUNET_i2s (peer));
2050 } 2089 }
2051 2090
2052 ril_step (s);
2053
2054 return agent->address_inuse; 2091 return agent->address_inuse;
2055} 2092}
2056 2093
@@ -2068,7 +2105,8 @@ GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdenti
2068{ 2105{
2069 struct GAS_RIL_Handle *s = solver; 2106 struct GAS_RIL_Handle *s = solver;
2070 struct RIL_Peer_Agent *agent; 2107 struct RIL_Peer_Agent *agent;
2071 struct RIL_Network *net; 2108
2109 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_stop_get_preferred_address()");
2072 2110
2073 agent = ril_get_agent (s, peer, GNUNET_NO); 2111 agent = ril_get_agent (s, peer, GNUNET_NO);
2074 2112
@@ -2084,12 +2122,7 @@ GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdenti
2084 } 2122 }
2085 2123
2086 agent->is_active = GNUNET_NO; 2124 agent->is_active = GNUNET_NO;
2087 if (agent->address_inuse) 2125
2088 {
2089 net = agent->address_inuse->solver_information;
2090 net->bw_in_assigned -= agent->bw_in;
2091 net->bw_out_assigned -= agent->bw_out;
2092 }
2093 envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, 2126 envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in, agent->bw_out,
2094 GNUNET_YES); 2127 GNUNET_YES);
2095 2128