aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-02-27 14:12:33 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-02-27 14:12:33 +0000
commite9a65d965436f0233a30951e89b01503cf88be35 (patch)
tree0ab10089b708a8472de37617c092cd609242cab7
parent244fd6a8054352cb6b31f7b9eb620769c3c7d7a6 (diff)
downloadgnunet-e9a65d965436f0233a30951e89b01503cf88be35.tar.gz
gnunet-e9a65d965436f0233a30951e89b01503cf88be35.zip
changes
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c81
-rw-r--r--src/ats/test_ats_mlp_update.c19
2 files changed, 85 insertions, 15 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c
index f047ab48f..b15eb61b3 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.c
+++ b/src/ats/gnunet-service-ats_addresses_mlp.c
@@ -1002,13 +1002,23 @@ GAS_mlp_address_add (void *solver, struct GNUNET_CONTAINER_MultiHashMap * addres
1002{ 1002{
1003 struct GAS_MLP_Handle *mlp = solver; 1003 struct GAS_MLP_Handle *mlp = solver;
1004 struct ATS_Peer *p; 1004 struct ATS_Peer *p;
1005 struct MLP_information *mlpi;
1006 int c1;
1007 int c2;
1005 1008
1006 GNUNET_assert (NULL != solver); 1009 GNUNET_assert (NULL != solver);
1007 GNUNET_assert (NULL != addresses); 1010 GNUNET_assert (NULL != addresses);
1008 GNUNET_assert (NULL != address); 1011 GNUNET_assert (NULL != address);
1009 1012
1013
1010 if (NULL == address->solver_information) 1014 if (NULL == address->solver_information)
1011 address->solver_information = GNUNET_malloc (sizeof (struct MLP_information)); 1015 {
1016 address->solver_information = GNUNET_malloc (sizeof (struct MLP_information));
1017 mlpi = address->solver_information;
1018 for (c1 = 0; c1 < mlp->pv.m_q; c1++)
1019 for (c2 = 0; c2 < mlp->pv.m_q; c2++)
1020 mlpi->q[c1][c2] = NaN;
1021 }
1012 else 1022 else
1013 LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding address for peer `%s' multiple times\n"), GNUNET_i2s(&address->peer)); 1023 LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding address for peer `%s' multiple times\n"), GNUNET_i2s(&address->peer));
1014 1024
@@ -1034,13 +1044,15 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1034 struct MLP_information *mlpi = address->solver_information; 1044 struct MLP_information *mlpi = address->solver_information;
1035 unsigned int c; 1045 unsigned int c;
1036 unsigned int c2; 1046 unsigned int c2;
1037 unsigned int type_index; 1047 int type_index;
1038 unsigned int avg_index; 1048 int avg_index;
1039 uint32_t type; 1049 uint32_t type;
1040 uint32_t value; 1050 uint32_t value;
1051 double avg;
1052 double * queue;
1041 1053
1042 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating quality metrics for peer `%s'\n", 1054 LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating %u quality metrics for peer `%s'\n",
1043 GNUNET_i2s (&address->peer)); 1055 ats_count, GNUNET_i2s (&address->peer));
1044 1056
1045 GNUNET_assert (NULL != address); 1057 GNUNET_assert (NULL != address);
1046 GNUNET_assert (NULL != address->solver_information); 1058 GNUNET_assert (NULL != address->solver_information);
@@ -1050,18 +1062,26 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1050 { 1062 {
1051 type = ntohl (ats[c].type); 1063 type = ntohl (ats[c].type);
1052 value = ntohl (ats[c].value); 1064 value = ntohl (ats[c].value);
1065 type_index = -1;
1066 avg_index = -1;
1053 1067
1054 /* Find index for this ATS type */ 1068 /* Find index for this ATS type */
1055 for (c2 = 0; c < ats_count; c++) 1069 for (c2 = 0; c2 < mlp->pv.m_q; c2++)
1056 { 1070 {
1071 LOG (GNUNET_ERROR_TYPE_DEBUG, "Comparing c==%u c2==%u %u and %u \n",
1072 c, c2,
1073 type, mlp->pv.q[c2] );
1057 if (type == mlp->pv.q[c2]) 1074 if (type == mlp->pv.q[c2])
1058 { 1075 {
1059 type_index = c2; 1076 type_index = c2;
1060 break; 1077 break;
1061 } 1078 }
1062 } 1079 }
1063 if (type_index > ats_count) 1080 if (-1 == type_index)
1081 {
1082 LOG (GNUNET_ERROR_TYPE_DEBUG, "Index not found \n");
1064 continue; /* quality index not found */ 1083 continue; /* quality index not found */
1084 }
1065 1085
1066 /* Get average queue index */ 1086 /* Get average queue index */
1067 avg_index = mlpi->q_avg_i[type_index]; 1087 avg_index = mlpi->q_avg_i[type_index];
@@ -1069,13 +1089,52 @@ mlp_update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address,
1069 /* Update averaging queue */ 1089 /* Update averaging queue */
1070 mlpi->q[type_index][avg_index] = value; 1090 mlpi->q[type_index][avg_index] = value;
1071 1091
1092 LOG (GNUNET_ERROR_TYPE_DEBUG, "Update `%s' with value `%u', in q[%u][%u]\n",
1093 mlp_ats_to_string(type), value,
1094 type_index, avg_index);
1095
1096
1072 /* Update averaging index */ 1097 /* Update averaging index */
1073 if (mlpi->q_avg_i[c] + 1 < (MLP_AVERAGING_QUEUE_LENGTH)) 1098 if (mlpi->q_avg_i[type_index] + 1 < (MLP_AVERAGING_QUEUE_LENGTH))
1074 mlpi->q_avg_i[c] ++; 1099 mlpi->q_avg_i[type_index] ++;
1075 else 1100 else
1076 mlpi->q_avg_i[c] = 0; 1101 mlpi->q_avg_i[type_index] = 0;
1102
1103 /* Update average depending on ATS type */
1104 switch (type)
1105 {
1106 case GNUNET_ATS_QUALITY_NET_DISTANCE:
1107 case GNUNET_ATS_QUALITY_NET_DELAY:
1108 c2 = 0;
1109 avg = 0;
1110 for (c = 0; c < MLP_AVERAGING_QUEUE_LENGTH; c++)
1111 {
1112 if (mlpi->q[type_index][c] != NaN)
1113 {
1114 queue = mlpi->q[type_index] ;
1115 avg += queue[c];
1116 c2 ++;
1117 }
1118 }
1119 if ((c2 > 0) && (avg > 0))
1120 /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/
1121 mlpi->q_averaged[type_index] = (double) c2 / avg;
1122 else
1123 mlpi->q_averaged[type_index] = 0.0;
1124
1125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s': `%s' average sum: %f, average: %f, weight: %f\n",
1126 GNUNET_i2s (&address->peer),
1127 mlp_ats_to_string(mlp->pv.q[type_index]),
1128 avg,
1129 avg / (double) c2,
1130 mlpi->q_averaged[type_index]);
1131 break;
1132 default:
1133 GNUNET_break (0);
1134 LOG (GNUNET_ERROR_TYPE_DEBUG, _("Update for ATS type `%s' not implemented!\n"),
1135 mlp_ats_to_string(type));
1136 }
1077 1137
1078 /* Update average */
1079 1138
1080 /* Update problem matrix */ 1139 /* Update problem matrix */
1081 1140
diff --git a/src/ats/test_ats_mlp_update.c b/src/ats/test_ats_mlp_update.c
index 4e1556266..95ff2fffe 100644
--- a/src/ats/test_ats_mlp_update.c
+++ b/src/ats/test_ats_mlp_update.c
@@ -37,6 +37,12 @@
37static int ret; 37static int ret;
38 38
39/** 39/**
40 * ATS Information
41 */
42struct GNUNET_ATS_Information ats[4];
43
44
45/**
40 * MLP solver handle 46 * MLP solver handle
41 */ 47 */
42struct GAS_MLP_Handle *mlp; 48struct GAS_MLP_Handle *mlp;
@@ -155,7 +161,6 @@ check (void *cls, char *const *args, const char *cfgfile,
155 int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; 161 int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
156 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount]; 162 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
157 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount]; 163 unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
158 struct GNUNET_ATS_Information ats;
159 164
160#if !HAVE_LIBGLPK 165#if !HAVE_LIBGLPK
161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!"); 166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
@@ -218,9 +223,15 @@ check (void *cls, char *const *args, const char *cfgfile,
218 GAS_mlp_address_add (mlp, addresses, address[0]); 223 GAS_mlp_address_add (mlp, addresses, address[0]);
219 224
220 /* Updating address 0*/ 225 /* Updating address 0*/
221 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); 226 ats[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
222 ats.value = htonl (GNUNET_ATS_NET_WAN); 227 ats[0].value = htonl (GNUNET_ATS_NET_WAN);
223 GAS_mlp_address_update (mlp, addresses, address[0], 1, GNUNET_NO, &ats, 1); 228 ats[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
229 ats[1].value = htonl (10);
230 ats[2].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
231 ats[2].value = htonl (1);
232 ats[3].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
233 ats[3].value = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
234 GAS_mlp_address_update (mlp, addresses, address[0], 1, GNUNET_NO, ats, 4);
224 235
225 /* Retrieving preferred address for peer and wait for callback */ 236 /* Retrieving preferred address for peer and wait for callback */
226 GAS_mlp_get_preferred_address (mlp, addresses, &p[0]); 237 GAS_mlp_get_preferred_address (mlp, addresses, &p[0]);