aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-01-18 15:48:14 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-01-18 15:48:14 +0000
commitdd1e1af7b9bcd04014cf4ccc8183fc8022525d04 (patch)
tree7207292171262f3ad224269023f53c96da28df0e /src
parent85c7ef583583c4424f774da10e46f7f1b1063ac7 (diff)
downloadgnunet-dd1e1af7b9bcd04014cf4ccc8183fc8022525d04.tar.gz
gnunet-dd1e1af7b9bcd04014cf4ccc8183fc8022525d04.zip
changes
Diffstat (limited to 'src')
-rw-r--r--src/ats/Makefile.am7
-rw-r--r--src/ats/gnunet-service-ats_addresses_simplistic.c207
-rw-r--r--src/ats/test_ats_simplistic_pref_aging.c296
3 files changed, 426 insertions, 84 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index 0506d3e75..f9a1ec425 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -72,6 +72,7 @@ check_PROGRAMS = \
72 test_ats_simplistic \ 72 test_ats_simplistic \
73 test_ats_simplistic_switch_networks \ 73 test_ats_simplistic_switch_networks \
74 test_ats_simplistic_change_preference \ 74 test_ats_simplistic_change_preference \
75 test_ats_simplistic_pref_aging \
75 test_ats_api_performance 76 test_ats_api_performance
76# $(GN_MLP_TEST) \ 77# $(GN_MLP_TEST) \
77# $(GN_MLP_TEST_AVG) \ 78# $(GN_MLP_TEST_AVG) \
@@ -186,6 +187,12 @@ test_ats_simplistic_change_preference_LDADD = \
186 $(top_builddir)/src/testing/libgnunettesting.la \ 187 $(top_builddir)/src/testing/libgnunettesting.la \
187 $(top_builddir)/src/ats/libgnunetats.la 188 $(top_builddir)/src/ats/libgnunetats.la
188 189
190test_ats_simplistic_pref_aging_SOURCES = \
191 test_ats_simplistic_pref_aging.c test_ats_api_common.c
192test_ats_simplistic_pref_aging_LDADD = \
193 $(top_builddir)/src/util/libgnunetutil.la \
194 $(top_builddir)/src/testing/libgnunettesting.la \
195 $(top_builddir)/src/ats/libgnunetats.la
189 196
190if HAVE_LIBGLPK 197if HAVE_LIBGLPK
191#test_ats_mlp_SOURCES = \ 198#test_ats_mlp_SOURCES = \
diff --git a/src/ats/gnunet-service-ats_addresses_simplistic.c b/src/ats/gnunet-service-ats_addresses_simplistic.c
index cf547bc70..b5df2a1f6 100644
--- a/src/ats/gnunet-service-ats_addresses_simplistic.c
+++ b/src/ats/gnunet-service-ats_addresses_simplistic.c
@@ -55,6 +55,9 @@
55 * 55 *
56 */ 56 */
57 57
58#define PREF_AGING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
59#define PREF_AGING_FACTOR 0.95
60
58#define DEFAULT_PREFERENCE 1.0 61#define DEFAULT_PREFERENCE 1.0
59#define MIN_UPDATE_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 62#define MIN_UPDATE_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
60 63
@@ -171,6 +174,8 @@ struct PreferencePeer
171 double f[GNUNET_ATS_PreferenceCount]; 174 double f[GNUNET_ATS_PreferenceCount];
172 double f_rel[GNUNET_ATS_PreferenceCount]; 175 double f_rel[GNUNET_ATS_PreferenceCount];
173 double f_rel_total; 176 double f_rel_total;
177
178 GNUNET_SCHEDULER_TaskIdentifier aging_task;
174}; 179};
175 180
176struct PreferenceClient 181struct PreferenceClient
@@ -347,6 +352,11 @@ GAS_simplistic_done (void *solver)
347 while (NULL != (p = next_p)) 352 while (NULL != (p = next_p))
348 { 353 {
349 next_p = p->next; 354 next_p = p->next;
355 if (GNUNET_SCHEDULER_NO_TASK != p->aging_task)
356 {
357 GNUNET_SCHEDULER_cancel(p->aging_task);
358 p->aging_task = GNUNET_SCHEDULER_NO_TASK;
359 }
350 GNUNET_CONTAINER_DLL_remove (pc->p_head, pc->p_tail, p); 360 GNUNET_CONTAINER_DLL_remove (pc->p_head, pc->p_tail, p);
351 GNUNET_free (p); 361 GNUNET_free (p);
352 } 362 }
@@ -1065,6 +1075,116 @@ GAS_simplistic_get_preferred_address (void *solver,
1065 return cur; 1075 return cur;
1066} 1076}
1067 1077
1078static void
1079update_preference (struct GAS_SIMPLISTIC_Handle *s,
1080 struct PreferenceClient *cur,
1081 struct PreferencePeer *p,
1082 enum GNUNET_ATS_PreferenceKind kind,
1083 float score_f)
1084{
1085 double p_rel_global;
1086 double *dest;
1087 double score = score_f;
1088 struct PreferencePeer *p_cur;
1089 int i;
1090 int clients;
1091
1092 /* Update preference value according to type */
1093 switch (kind) {
1094 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
1095 case GNUNET_ATS_PREFERENCE_LATENCY:
1096 p->f[kind] = (p->f[kind] + score) / 2;
1097 break;
1098 case GNUNET_ATS_PREFERENCE_END:
1099 break;
1100 default:
1101 break;
1102 }
1103
1104 /* Recalcalculate total preference for this quality kind over all peers*/
1105 cur->f_total[kind] = 0;
1106 for (p_cur = cur->p_head; NULL != p_cur; p_cur = p_cur->next)
1107 cur->f_total[kind] += p_cur->f[kind];
1108
1109 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p has total preference for %s of %.3f\n",
1110 cur->client,
1111 GNUNET_ATS_print_preference_type (kind),
1112 cur->f_total[kind]);
1113
1114 /* Recalcalculate relative preference for all peers */
1115 for (p_cur = cur->p_head; NULL != p_cur; p_cur = p_cur->next)
1116 {
1117 /* Calculate relative preference for specific kind */
1118 p_cur->f_rel[kind] = (cur->f_total[kind] + p_cur->f[kind]) / cur->f_total[kind];
1119 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p: peer `%s' has relative preference for %s of %.3f\n",
1120 cur->client,
1121 GNUNET_i2s (&p_cur->id),
1122 GNUNET_ATS_print_preference_type (kind),
1123 p_cur->f_rel[kind]);
1124
1125 /* Calculate peer relative preference
1126 * Start with i = 1 to exclude terminator */
1127 p_cur->f_rel_total = 0;
1128 for (i = 1; i < GNUNET_ATS_PreferenceCount; i ++)
1129 {
1130 p_cur->f_rel_total += p_cur->f_rel[i];
1131 }
1132 p_cur->f_rel_total /= (GNUNET_ATS_PreferenceCount - 1.0); /* -1 due to terminator */
1133 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p: peer `%s' has total relative preference of %.3f\n",
1134 cur->client,
1135 GNUNET_i2s (&p_cur->id),
1136 p_cur->f_rel_total);
1137 }
1138
1139 /* Calculcate global total relative peer preference over all clients */
1140 p_rel_global = 0.0;
1141 clients = 0;
1142 for (cur = s->pc_head; NULL != cur; cur = cur->next)
1143 {
1144 for (p_cur = cur->p_head; NULL != p_cur; p_cur = p_cur->next)
1145 if (0 == memcmp (&p_cur->id, &p->id, sizeof (p_cur->id)))
1146 break;
1147 if (NULL != p_cur)
1148 {
1149 clients++;
1150 p_rel_global += p_cur->f_rel_total;
1151 }
1152 }
1153 p_rel_global /= clients;
1154 LOG (GNUNET_ERROR_TYPE_DEBUG, "Global preference value for peer `%s': %.3f\n",
1155 GNUNET_i2s (&p->id), p_rel_global);
1156
1157 /* Update global map */
1158 /* FIXME: We should update all peers since they have influence on each other */
1159 if (NULL != (dest = GNUNET_CONTAINER_multihashmap_get(s->prefs, &p->id.hashPubKey)))
1160 (*dest) = p_rel_global;
1161 else
1162 {
1163 dest = GNUNET_malloc (sizeof (float));
1164 (*dest) = p_rel_global;
1165 GNUNET_CONTAINER_multihashmap_put(s->prefs,
1166 &p->id.hashPubKey,
1167 dest,
1168 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1169 }
1170}
1171
1172
1173static void
1174preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1175{
1176 struct PreferencePeer *p = cls;
1177 GNUNET_assert (NULL != p);
1178 p->aging_task = GNUNET_SCHEDULER_NO_TASK;
1179
1180/* LOG (GNUNET_ERROR_TYPE_ERROR, "Aging preferences for peer `%s'\n",
1181 GNUNET_i2s (&p->id));*/
1182
1183 p->aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
1184 &preference_aging, p);
1185}
1186
1187
1068/** 1188/**
1069 * Changes the preferences for a peer in the problem 1189 * Changes the preferences for a peer in the problem
1070 * 1190 *
@@ -1086,10 +1206,6 @@ GAS_simplistic_address_change_preference (void *solver,
1086 struct PreferenceClient *cur; 1206 struct PreferenceClient *cur;
1087 struct PreferencePeer *p; 1207 struct PreferencePeer *p;
1088 int i; 1208 int i;
1089 int clients;
1090 double p_rel_global;
1091 double *dest;
1092 double score = score_f;
1093 1209
1094 GNUNET_assert (NULL != solver); 1210 GNUNET_assert (NULL != solver);
1095 GNUNET_assert (NULL != client); 1211 GNUNET_assert (NULL != client);
@@ -1099,7 +1215,7 @@ GAS_simplistic_address_change_preference (void *solver,
1099 client, 1215 client,
1100 GNUNET_i2s (peer), 1216 GNUNET_i2s (peer),
1101 GNUNET_ATS_print_preference_type (kind), 1217 GNUNET_ATS_print_preference_type (kind),
1102 score); 1218 score_f);
1103 1219
1104 if (kind >= GNUNET_ATS_PreferenceCount) 1220 if (kind >= GNUNET_ATS_PreferenceCount)
1105 { 1221 {
@@ -1168,87 +1284,11 @@ GAS_simplistic_address_change_preference (void *solver,
1168 /* Default value per peer relative preference for a quality: 1.0 */ 1284 /* Default value per peer relative preference for a quality: 1.0 */
1169 p->f_rel[i] = DEFAULT_PREFERENCE; 1285 p->f_rel[i] = DEFAULT_PREFERENCE;
1170 } 1286 }
1287 p->aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, &preference_aging, p);
1171 GNUNET_CONTAINER_DLL_insert (cur->p_head, cur->p_tail, p); 1288 GNUNET_CONTAINER_DLL_insert (cur->p_head, cur->p_tail, p);
1172 } 1289 }
1173 1290
1174 /* Update preference value according to type */ 1291 update_preference (s, cur, p, kind, score_f);
1175 switch (kind) {
1176 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
1177 case GNUNET_ATS_PREFERENCE_LATENCY:
1178 p->f[kind] = (p->f[kind] + score) / 2;
1179 break;
1180 case GNUNET_ATS_PREFERENCE_END:
1181 break;
1182 default:
1183 break;
1184 }
1185
1186 /* Recalcalculate total preference for this quality kind over all peers*/
1187 cur->f_total[kind] = 0;
1188 for (p = cur->p_head; NULL != p; p = p->next)
1189 cur->f_total[kind] += p->f[kind];
1190
1191 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p has total preference for %s of %.3f\n",
1192 cur->client,
1193 GNUNET_ATS_print_preference_type (kind),
1194 cur->f_total[kind]);
1195
1196 /* Recalcalculate relative preference for all peers */
1197 for (p = cur->p_head; NULL != p; p = p->next)
1198 {
1199 /* Calculate relative preference for specific kind */
1200 p->f_rel[kind] = (cur->f_total[kind] + p->f[kind]) / cur->f_total[kind];
1201 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p: peer `%s' has relative preference for %s of %.3f\n",
1202 cur->client,
1203 GNUNET_i2s (&p->id),
1204 GNUNET_ATS_print_preference_type (kind),
1205 p->f_rel[kind]);
1206
1207 /* Calculate peer relative preference
1208 * Start with i = 1 to exclude terminator */
1209 p->f_rel_total = 0;
1210 for (i = 1; i < GNUNET_ATS_PreferenceCount; i ++)
1211 {
1212 p->f_rel_total += p->f_rel[i];
1213 }
1214 p->f_rel_total /= (GNUNET_ATS_PreferenceCount - 1.0); /* -1 due to terminator */
1215 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p: peer `%s' has total relative preference of %.3f\n",
1216 cur->client,
1217 GNUNET_i2s (&p->id),
1218 p->f_rel_total);
1219 }
1220
1221 /* Calculcate global total relative peer preference over all clients */
1222 p_rel_global = 0.0;
1223 clients = 0;
1224 for (cur = s->pc_head; NULL != cur; cur = cur->next)
1225 {
1226 for (p = cur->p_head; NULL != p; p = p->next)
1227 if (0 == memcmp (&p->id, peer, sizeof (p->id)))
1228 break;
1229 if (NULL != p)
1230 {
1231 clients++;
1232 p_rel_global += p->f_rel_total;
1233 }
1234 }
1235 p_rel_global /= clients;
1236 LOG (GNUNET_ERROR_TYPE_DEBUG, "Global preference value for peer `%s': %.3f\n",
1237 GNUNET_i2s (peer), p_rel_global);
1238
1239 /* Update global map */
1240 /* FIXME: We should update all peers since they have influence on each other */
1241 if (NULL != (dest = GNUNET_CONTAINER_multihashmap_get(s->prefs, &peer->hashPubKey)))
1242 (*dest) = p_rel_global;
1243 else
1244 {
1245 dest = GNUNET_malloc (sizeof (float));
1246 (*dest) = p_rel_global;
1247 GNUNET_CONTAINER_multihashmap_put(s->prefs,
1248 &peer->hashPubKey,
1249 dest,
1250 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1251 }
1252 1292
1253 /* FIXME: We should update quotas if UPDATE_INTERVAL is reached */ 1293 /* FIXME: We should update quotas if UPDATE_INTERVAL is reached */
1254 if (GNUNET_TIME_absolute_get().abs_value > next_update.abs_value) 1294 if (GNUNET_TIME_absolute_get().abs_value > next_update.abs_value)
@@ -1257,7 +1297,6 @@ GAS_simplistic_address_change_preference (void *solver,
1257 next_update = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), 1297 next_update = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
1258 MIN_UPDATE_INTERVAL); 1298 MIN_UPDATE_INTERVAL);
1259 } 1299 }
1260
1261} 1300}
1262 1301
1263/* end of gnunet-service-ats_addresses_simplistic.c */ 1302/* end of gnunet-service-ats_addresses_simplistic.c */
diff --git a/src/ats/test_ats_simplistic_pref_aging.c b/src/ats/test_ats_simplistic_pref_aging.c
new file mode 100644
index 000000000..0bd618189
--- /dev/null
+++ b/src/ats/test_ats_simplistic_pref_aging.c
@@ -0,0 +1,296 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file ats/test_ats_mlp.c
22 * @brief test for the MLP solver
23 * @author Christian Grothoff
24 * @author Matthias Wachs
25
26 */
27/**
28 * @file ats/test_ats_api_scheduling_add_address.c
29 * @brief test for ats simplistic solver preference aging:
30 * Add 2 addresses and set high preference for one. Expect higher bw for this
31 * address, wait. Preferences should age and so bw assigned should decrease.
32 * @author Christian Grothoff
33 * @author Matthias Wachs
34 */
35#include "platform.h"
36#include "gnunet_ats_service.h"
37#include "gnunet_testing_lib.h"
38#include "ats.h"
39#include "test_ats_api_common.h"
40
41#define DEBUG_ATS_INFO GNUNET_NO
42
43static GNUNET_SCHEDULER_TaskIdentifier die_task;
44
45/**
46 * Scheduling handle
47 */
48static struct GNUNET_ATS_SchedulingHandle *sched_ats;
49
50/**
51 * Performance handle
52 */
53static struct GNUNET_ATS_PerformanceHandle *perf_ats;
54
55/**
56 * Return value
57 */
58static int ret;
59
60/**
61 * Test address
62 */
63static struct Test_Address test_addr[2];
64
65/**
66 * Test peer
67 */
68static struct PeerContext p[2];
69
70
71/**
72 * HELLO address
73 */
74struct GNUNET_HELLO_Address test_hello_address[2];
75
76/**
77 * Session
78 */
79static void *test_session[2];
80
81/**
82 * Test ats info
83 */
84struct GNUNET_ATS_Information test_ats_info[2];
85
86/**
87 * Test ats count
88 */
89uint32_t test_ats_count;
90
91/**
92 * Configured WAN out quota
93 */
94unsigned long long wan_quota_out;
95
96/**
97 * Configured WAN in quota
98 */
99unsigned long long wan_quota_in;
100
101
102static void
103end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
104{
105 die_task = GNUNET_SCHEDULER_NO_TASK;
106
107 if (sched_ats != NULL)
108 GNUNET_ATS_scheduling_done (sched_ats);
109 if (perf_ats != NULL)
110 GNUNET_ATS_performance_done (perf_ats);
111 free_test_address (&test_addr[0]);
112 ret = GNUNET_SYSERR;
113}
114
115
116static void
117end ()
118{
119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
120 if (die_task != GNUNET_SCHEDULER_NO_TASK)
121 {
122 GNUNET_SCHEDULER_cancel (die_task);
123 die_task = GNUNET_SCHEDULER_NO_TASK;
124 }
125
126 GNUNET_ATS_suggest_address_cancel (sched_ats, &p[0].id);
127 GNUNET_ATS_suggest_address_cancel (sched_ats, &p[1].id);
128
129 GNUNET_ATS_scheduling_done (sched_ats);
130 GNUNET_ATS_performance_done (perf_ats);
131 sched_ats = NULL;
132 perf_ats = NULL;
133 free_test_address (&test_addr[0]);
134 free_test_address (&test_addr[1]);
135}
136
137
138static void
139address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
140 struct Session *session,
141 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
142 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
143 const struct GNUNET_ATS_Information *atsi,
144 uint32_t ats_count)
145{
146 static int stage = 0;
147
148 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Callback for peer `%s': (in/out) %llu/%llu\n",
149 GNUNET_i2s (&address->peer),
150 ntohl (bandwidth_in.value__),
151 ntohl (bandwidth_out.value__));
152
153 stage ++;
154 if (3 == stage)
155 GNUNET_SCHEDULER_add_now (&end, NULL);
156
157}
158
159static void
160run (void *cls,
161 const struct GNUNET_CONFIGURATION_Handle *cfg,
162 struct GNUNET_TESTING_Peer *peer)
163{
164 char *quota_str;
165
166 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "ats", "WAN_QUOTA_OUT", &quota_str))
167 {
168 fprintf (stderr, "Cannot load WAN outbound quota from configuration, exit!\n");
169 ret = 1;
170 return;
171 }
172 if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_str, &wan_quota_out))
173 {
174 fprintf (stderr, "Cannot load WAN outbound quota from configuration, exit!\n");
175 ret = 1;
176 GNUNET_free (quota_str);
177 return;
178 }
179 GNUNET_free (quota_str);
180 quota_str = NULL;
181
182 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "ats", "WAN_QUOTA_IN", &quota_str))
183 {
184 fprintf (stderr, "Cannot load WAN inbound quota from configuration, exit!\n");
185 ret = 1;
186 return;
187 }
188 if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_str, &wan_quota_in))
189 {
190 fprintf (stderr, "Cannot load WAN inbound quota from configuration, exit!\n");
191 GNUNET_free (quota_str);
192 ret = 1;
193 return;
194 }
195 GNUNET_free (quota_str);
196 quota_str = NULL;
197 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Configured WAN inbound quota: %llu\n", wan_quota_in);
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Configured WAN outbound quota: %llu\n", wan_quota_out);
199
200
201 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
202
203 /* Connect to ATS scheduling */
204 sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
205 if (sched_ats == NULL)
206 {
207 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n");
208 ret = 1;
209 end ();
210 return;
211 }
212
213 /* Connect to ATS performance */
214 perf_ats = GNUNET_ATS_performance_init(cfg, NULL, NULL);
215 if (sched_ats == NULL)
216 {
217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n");
218 ret = 1;
219 end ();
220 return;
221 }
222
223
224 /* Set up peer 0 */
225 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p[0].id.hashPubKey))
226 {
227 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
228 ret = GNUNET_SYSERR;
229 end ();
230 return;
231 }
232
233 GNUNET_assert (0 == strcmp (PEERID0, GNUNET_i2s_full (&p[0].id)));
234
235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
236 GNUNET_i2s(&p[0].id));
237
238 /* Set up peer 1*/
239 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID1, &p[1].id.hashPubKey))
240 {
241 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
242 ret = GNUNET_SYSERR;
243 end ();
244 return;
245 }
246
247 GNUNET_assert (0 == strcmp (PEERID1, GNUNET_i2s_full (&p[1].id)));
248
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
250 GNUNET_i2s(&p[1].id));
251
252 /* Prepare ATS Information */
253 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
254 test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
255 test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
256 test_ats_info[1].value = htonl(1);
257 test_ats_count = 2;
258
259 /* Peer 0: Adding address with session */
260 test_session[0] = &test_addr[0];
261 create_test_address (&test_addr[0], "test0", test_session[0], "test0", strlen ("test0") + 1);
262 test_hello_address[0].peer = p[0].id;
263 test_hello_address[0].transport_name = test_addr[0].plugin;
264 test_hello_address[0].address = test_addr[0].addr;
265 test_hello_address[0].address_length = test_addr[0].addr_len;
266 GNUNET_ATS_address_add (sched_ats, &test_hello_address[0], test_session[0], test_ats_info, test_ats_count);
267
268 /* Peer 1: Adding address with session */
269 test_session[1] = &test_addr[1];
270 create_test_address (&test_addr[1], "test1", test_session[1], "test1", strlen ("test1") + 1);
271 test_hello_address[1].peer = p[1].id;
272 test_hello_address[1].transport_name = test_addr[1].plugin;
273 test_hello_address[1].address = test_addr[1].addr;
274 test_hello_address[1].address_length = test_addr[1].addr_len;
275 GNUNET_ATS_address_add (sched_ats, &test_hello_address[1], test_session[1], test_ats_info, test_ats_count);
276
277 GNUNET_ATS_change_preference (perf_ats, &p[1].id, GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END);
278 GNUNET_ATS_change_preference (perf_ats, &p[1].id, GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END);
279
280 GNUNET_ATS_suggest_address (sched_ats, &p[0].id);
281 GNUNET_ATS_suggest_address (sched_ats, &p[1].id);
282}
283
284
285int
286main (int argc, char *argv[])
287{
288 if (0 != GNUNET_TESTING_peer_run ("test_ats_simplistic_pref_aging",
289 "test_ats_api.conf",
290 &run, NULL))
291 return 1;
292 return ret;
293}
294
295
296/* end of file test_ats_simplistic_pref_aging.c */