aboutsummaryrefslogtreecommitdiff
path: root/src/ats/test_ats_api_performance.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-11-22 12:30:19 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-11-22 12:30:19 +0000
commit9b42dfd0d4fb3c97a389d3352ecf8cb26c564cd7 (patch)
treed9833de05e30eb56fc0d6fb644445e09c5f1a3f4 /src/ats/test_ats_api_performance.c
parent1b82d30656e0415f48bdb358d52f29d28a01e0a3 (diff)
downloadgnunet-9b42dfd0d4fb3c97a389d3352ecf8cb26c564cd7.tar.gz
gnunet-9b42dfd0d4fb3c97a389d3352ecf8cb26c564cd7.zip
- stage 3
Diffstat (limited to 'src/ats/test_ats_api_performance.c')
-rw-r--r--src/ats/test_ats_api_performance.c127
1 files changed, 114 insertions, 13 deletions
diff --git a/src/ats/test_ats_api_performance.c b/src/ats/test_ats_api_performance.c
index 4d736cec5..644121370 100644
--- a/src/ats/test_ats_api_performance.c
+++ b/src/ats/test_ats_api_performance.c
@@ -127,6 +127,100 @@ end ()
127static void 127static void
128test_performance_api (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 128test_performance_api (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
129 129
130void all_active_addresses_peer_cb (void *cls,
131 const struct
132 GNUNET_HELLO_Address *
133 address,
134 struct
135 GNUNET_BANDWIDTH_Value32NBO
136 bandwidth_out,
137 struct
138 GNUNET_BANDWIDTH_Value32NBO
139 bandwidth_in,
140 const struct
141 GNUNET_ATS_Information *
142 ats, uint32_t ats_count)
143{
144
145}
146
147void all_active_addresses_cb (void *cls,
148 const struct
149 GNUNET_HELLO_Address *
150 address,
151 struct
152 GNUNET_BANDWIDTH_Value32NBO
153 bandwidth_out,
154 struct
155 GNUNET_BANDWIDTH_Value32NBO
156 bandwidth_in,
157 const struct
158 GNUNET_ATS_Information *
159 ats, uint32_t ats_count)
160{
161 static int cb = 0;
162 int fail = GNUNET_NO;
163
164 if (address != NULL)
165 {
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s' address `%s'\n",
167 GNUNET_i2s (&address->peer), address->address);
168
169 if (0 == memcmp (&address->peer, &p[0].id,
170 sizeof (struct GNUNET_PeerIdentity)))
171 {
172 if (0 == strcmp(address->address, p0_addresses[0].addr))
173 {
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer 0 address 0\n");
175 cb ++;
176 }
177 else
178 {
179 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected callback for peer 0 address 0!\n");
180 GNUNET_ATS_performance_list_addresses_cancel (phal);
181 fail = GNUNET_YES;
182 }
183 }
184
185 if (0 == memcmp (&address->peer, &p[1].id,
186 sizeof (struct GNUNET_PeerIdentity)))
187 {
188 if (0 == strcmp(address->address, p1_addresses[1].addr))
189 {
190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer 1 address 1\n");
191 cb ++;
192 }
193 else
194 {
195 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected callback for peer 1 address 1!\n");
196 GNUNET_ATS_performance_list_addresses_cancel (phal);
197 fail = GNUNET_YES;
198 }
199 }
200 cb ++;
201 }
202 if ((address == NULL) || (GNUNET_YES == fail))
203 {
204 phal = NULL;
205 if ((2 == cb) && (GNUNET_NO == fail))
206 {
207 /* Received all addresses + terminator cb, next stage */
208 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stage %i: SUCCESS\n", stage);
209 GNUNET_SCHEDULER_add_now (&test_performance_api, NULL);
210 return;
211 }
212 else
213 {
214 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage %i: FAIL\n", stage);
215 GNUNET_SCHEDULER_add_now (&end, NULL);
216 ret = 5;
217 return;
218 }
219 }
220}
221
222
223
130void all_addresses_peer_cb (void *cls, 224void all_addresses_peer_cb (void *cls,
131 const struct 225 const struct
132 GNUNET_HELLO_Address * 226 GNUNET_HELLO_Address *
@@ -142,6 +236,7 @@ void all_addresses_peer_cb (void *cls,
142 ats, uint32_t ats_count) 236 ats, uint32_t ats_count)
143{ 237{
144 static int cb = 0; 238 static int cb = 0;
239 int fail = GNUNET_NO;
145 240
146 if (address != NULL) 241 if (address != NULL)
147 { 242 {
@@ -153,17 +248,16 @@ void all_addresses_peer_cb (void *cls,
153 { 248 {
154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage %i: Received address for wrong peer\n", stage); 249 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage %i: Received address for wrong peer\n", stage);
155 GNUNET_ATS_performance_list_addresses_cancel (phal); 250 GNUNET_ATS_performance_list_addresses_cancel (phal);
156 phal = NULL; 251 fail = GNUNET_YES;
157 GNUNET_SCHEDULER_add_now (&end, NULL);
158 ret = 4; 252 ret = 4;
159 return;
160 } 253 }
161 cb ++; 254 cb ++;
162 } 255 }
163 else 256
257 if ((NULL == address) || (fail))
164 { 258 {
165 phal = NULL; 259 phal = NULL;
166 if (2 == cb) 260 if ((2 == cb) && (GNUNET_NO == fail))
167 { 261 {
168 /* Received all addresses + terminator cb, next stage */ 262 /* Received all addresses + terminator cb, next stage */
169 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stage %i: SUCCESS\n", stage); 263 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stage %i: SUCCESS\n", stage);
@@ -264,22 +358,30 @@ test_performance_api (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
264 } 358 }
265 stage++; 359 stage++;
266 switch (stage) { 360 switch (stage) {
267 case 1: 361 case 1: /* Get all peers, all addresses */
268 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stage 1: \n"); 362 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Run stage 1: \n");
269 phal = GNUNET_ATS_performance_list_addresses (ph, 363 phal = GNUNET_ATS_performance_list_addresses (ph,
270 NULL, 364 NULL,
271 GNUNET_YES, 365 GNUNET_YES,
272 &all_addresses_cb, NULL); 366 &all_addresses_cb, NULL);
273 GNUNET_assert (NULL != phal); 367 GNUNET_assert (NULL != phal);
274 break; 368 break;
275 case 2: 369 case 2: /* Get specific peer, all addresses */
276 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stage 2: \n"); 370 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Run stage 2: \n");
277 phal = GNUNET_ATS_performance_list_addresses (ph, 371 phal = GNUNET_ATS_performance_list_addresses (ph,
278 &p[1].id, 372 &p[1].id,
279 GNUNET_YES, 373 GNUNET_YES,
280 &all_addresses_peer_cb, NULL); 374 &all_addresses_peer_cb, NULL);
281 GNUNET_assert (NULL != phal); 375 GNUNET_assert (NULL != phal);
282 break; 376 break;
377 case 3: /* Get all peers, active addresses */
378 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Run stage 3: \n");
379 phal = GNUNET_ATS_performance_list_addresses (ph,
380 NULL,
381 GNUNET_NO,
382 &all_active_addresses_cb, NULL);
383 GNUNET_assert (NULL != phal);
384 break;
283 default: 385 default:
284 /* done */ 386 /* done */
285 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "All tests successful, shutdown... \n"); 387 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "All tests successful, shutdown... \n");
@@ -391,15 +493,14 @@ run (void *cls,
391 } 493 }
392 494
393 GNUNET_ATS_address_add (ats, &p0_ha[0], NULL, NULL, 0); 495 GNUNET_ATS_address_add (ats, &p0_ha[0], NULL, NULL, 0);
394
395 GNUNET_ATS_address_add (ats, &p0_ha[1], NULL, NULL, 0); 496 GNUNET_ATS_address_add (ats, &p0_ha[1], NULL, NULL, 0);
396 GNUNET_ATS_address_in_use (ats, &p0_ha[1], NULL, GNUNET_YES);
397 497
398 GNUNET_ATS_address_add (ats, &p1_ha[0], NULL, NULL, 0); 498 GNUNET_ATS_address_add (ats, &p1_ha[0], NULL, NULL, 0);
399 GNUNET_ATS_address_in_use (ats, &p1_ha[0], NULL, GNUNET_YES);
400
401 GNUNET_ATS_address_add (ats, &p1_ha[1], NULL, NULL, 0); 499 GNUNET_ATS_address_add (ats, &p1_ha[1], NULL, NULL, 0);
402 500
501 //GNUNET_ATS_address_in_use (ats, &p0_ha[0], NULL, GNUNET_YES);
502 //GNUNET_ATS_address_in_use (ats, &p1_ha[1], NULL, GNUNET_YES);
503
403 GNUNET_ATS_suggest_address (ats, &p[0].id); 504 GNUNET_ATS_suggest_address (ats, &p[0].id);
404 GNUNET_ATS_suggest_address (ats, &p[1].id); 505 GNUNET_ATS_suggest_address (ats, &p[1].id);
405} 506}