aboutsummaryrefslogtreecommitdiff
path: root/src/ats/perf_ats.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-08-06 10:12:42 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-08-06 10:12:42 +0000
commit2b1dd62fbcd3f76c7a6f1b095b51d0ff2841ab13 (patch)
tree5534de4418e32591d3b2edccd70a776ef8763e6c /src/ats/perf_ats.c
parent177f92ec7de0e0b3b294c2ddfb63af57f070b00b (diff)
downloadgnunet-2b1dd62fbcd3f76c7a6f1b095b51d0ff2841ab13.tar.gz
gnunet-2b1dd62fbcd3f76c7a6f1b095b51d0ff2841ab13.zip
changes to perf_ats
Diffstat (limited to 'src/ats/perf_ats.c')
-rw-r--r--src/ats/perf_ats.c165
1 files changed, 138 insertions, 27 deletions
diff --git a/src/ats/perf_ats.c b/src/ats/perf_ats.c
index 330b32bd5..2fe71d548 100644
--- a/src/ats/perf_ats.c
+++ b/src/ats/perf_ats.c
@@ -40,7 +40,9 @@ struct BenchmarkPeer
40 /** 40 /**
41 * Handle with testbed. 41 * Handle with testbed.
42 */ 42 */
43 struct GNUNET_TESTBED_Peer *daemon; 43 struct GNUNET_TESTBED_Peer *peer;
44
45 struct GNUNET_PeerIdentity id;
44 46
45 /** 47 /**
46 * Testbed operation to connect to ATS performance service 48 * Testbed operation to connect to ATS performance service
@@ -52,6 +54,17 @@ struct BenchmarkPeer
52 */ 54 */
53 struct GNUNET_TESTBED_Operation *ats_sched_op; 55 struct GNUNET_TESTBED_Operation *ats_sched_op;
54 56
57 /**
58 * Testbed operation to get peer information
59 */
60 struct GNUNET_TESTBED_Operation *info_op;
61
62
63 /**
64 * Testbed operation to connect peers
65 */
66 struct GNUNET_TESTBED_Operation *connect_op;
67
55 struct GNUNET_ATS_PerformanceHandle *p_handle; 68 struct GNUNET_ATS_PerformanceHandle *p_handle;
56 struct GNUNET_ATS_SchedulingHandle *s_handle; 69 struct GNUNET_ATS_SchedulingHandle *s_handle;
57 70
@@ -89,12 +102,29 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
89 for (c_p = 0; c_p < peers; c_p++) 102 for (c_p = 0; c_p < peers; c_p++)
90 { 103 {
91 if (NULL != ph[c_p].ats_perf_op) 104 if (NULL != ph[c_p].ats_perf_op)
105 {
92 GNUNET_TESTBED_operation_done (ph[c_p].ats_perf_op); 106 GNUNET_TESTBED_operation_done (ph[c_p].ats_perf_op);
107 }
93 ph[c_p].ats_perf_op = NULL; 108 ph[c_p].ats_perf_op = NULL;
94 if (NULL != ph[c_p].ats_sched_op) 109 if (NULL != ph[c_p].ats_sched_op)
110 {
95 GNUNET_TESTBED_operation_done (ph[c_p].ats_sched_op); 111 GNUNET_TESTBED_operation_done (ph[c_p].ats_sched_op);
112 }
96 ph[c_p].ats_sched_op = NULL; 113 ph[c_p].ats_sched_op = NULL;
97 114
115 if (NULL != ph[c_p].info_op)
116 {
117 GNUNET_break (0);
118 GNUNET_TESTBED_operation_done (ph[c_p].info_op);
119 }
120 if (NULL != ph[c_p].connect_op)
121 {
122 GNUNET_break (0);
123 GNUNET_TESTBED_operation_done (ph[c_p].connect_op);
124 }
125 ph[c_p].connect_op = NULL;
126
127
98 } 128 }
99 129
100 GNUNET_SCHEDULER_shutdown(); 130 GNUNET_SCHEDULER_shutdown();
@@ -110,6 +140,30 @@ ats_performance_info_cb (void *cls,
110 const struct GNUNET_ATS_Information *ats, 140 const struct GNUNET_ATS_Information *ats,
111 uint32_t ats_count) 141 uint32_t ats_count)
112{ 142{
143 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("[P] %s\n"), GNUNET_i2s (&address->peer));
144}
145
146/**
147 * Signature of a function called by ATS with the current bandwidth
148 * and address preferences as determined by ATS.
149 *
150 * @param cls closure
151 * @param address suggested address (including peer identity of the peer)
152 * @param session session to use
153 * @param bandwidth_out assigned outbound bandwidth for the connection
154 * @param bandwidth_in assigned inbound bandwidth for the connection
155 * @param ats performance data for the address (as far as known)
156 * @param ats_count number of performance records in 'ats'
157 */
158static void
159ats_scheduling_cb (void *cls,
160 const struct GNUNET_HELLO_Address *address,
161 struct Session * session,
162 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
163 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
164 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
165{
166 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("[S] %s\n"), GNUNET_i2s (&address->peer));
113 167
114} 168}
115 169
@@ -127,7 +181,6 @@ controller_event_cb (void *cls,
127 switch (event->type) 181 switch (event->type)
128 { 182 {
129 case GNUNET_TESTBED_ET_CONNECT: 183 case GNUNET_TESTBED_ET_CONNECT:
130 GNUNET_break (0);
131 break; 184 break;
132 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 185 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
133 break; 186 break;
@@ -175,31 +228,32 @@ ats_perf_disconnect_adapter (void *cls, void *op_result)
175 peer->p_handle = NULL; 228 peer->p_handle = NULL;
176} 229}
177 230
178 231void connect_completion_callback (void *cls,
179/** 232 struct GNUNET_TESTBED_Operation *op,
180 * Signature of a function called by ATS with the current bandwidth 233 const char *emsg)
181 * and address preferences as determined by ATS.
182 *
183 * @param cls closure
184 * @param address suggested address (including peer identity of the peer)
185 * @param session session to use
186 * @param bandwidth_out assigned outbound bandwidth for the connection
187 * @param bandwidth_in assigned inbound bandwidth for the connection
188 * @param ats performance data for the address (as far as known)
189 * @param ats_count number of performance records in 'ats'
190 */
191static void
192ats_scheduling_cb (void *cls,
193 const struct GNUNET_HELLO_Address *address,
194 struct Session * session,
195 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
196 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
197 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
198{ 234{
235 struct BenchmarkPeer *p = cls;
236 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
237 _("Connected peer 0 with peer %p\n"), p->peer);
238 if (NULL == emsg)
239 {
240 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
241 _("Connected peer 0 with peer %p\n"), p->peer);
242 }
243 else
244 {
245 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
246 _("Failed to connect peer 0 with peer %p\n"), p->peer);
247 GNUNET_break (0);
248 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
249 GNUNET_SCHEDULER_cancel(shutdown_task);
250 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
251 }
252 GNUNET_TESTBED_operation_done(op);
253 p->connect_op = NULL;
199 254
200} 255}
201 256
202
203/** 257/**
204 * Callback to be called when a service connect operation is completed 258 * Callback to be called when a service connect operation is completed
205 * 259 *
@@ -214,7 +268,8 @@ void ats_connect_completion_cb (void *cls,
214 void *ca_result, 268 void *ca_result,
215 const char *emsg ) 269 const char *emsg )
216{ 270{
217 static int op_done = 0 ; 271 static int op_done = 0;
272 int c_p;
218 if ((NULL != emsg) || (NULL == ca_result)) 273 if ((NULL != emsg) || (NULL == ca_result))
219 { 274 {
220 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 275 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -225,11 +280,33 @@ void ats_connect_completion_cb (void *cls,
225 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); 280 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
226 return; 281 return;
227 } 282 }
283
228 op_done ++; 284 op_done ++;
229 if (op_done == 2 * peers) 285 if (op_done == 2 * peers)
230 { 286 {
231 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 287 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
232 _("Initialization done, connecting peers\n")); 288 _("Initialization done, connecting peers\n"));
289 /*
290 for (c_p = 1; c_p < peers; c_p ++)
291 {
292 ph[c_p].connect_op = GNUNET_TESTBED_overlay_connect( NULL,
293 &connect_completion_callback, &ph[c_p], ph[0].peer, ph[c_p].peer);
294 if (NULL == ph[c_p].connect_op)
295 {
296 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
297 _("Could not connect peer 0 and peer %u\n"), c_p);
298 GNUNET_break (0);
299 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
300 GNUNET_SCHEDULER_cancel(shutdown_task);
301 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
302 return;
303 }
304 else
305 {
306 GNUNET_break (0);
307 }
308 }
309 */
233 310
234 } 311 }
235} 312}
@@ -269,6 +346,36 @@ ats_sched_disconnect_adapter (void *cls, void *op_result)
269 peer->p_handle = NULL; 346 peer->p_handle = NULL;
270} 347}
271 348
349/**
350 * Callback to be called when the requested peer information is available
351 *
352 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
353 * @param op the operation this callback corresponds to
354 * @param pinfo the result; will be NULL if the operation has failed
355 * @param emsg error message if the operation has failed; will be NULL if the
356 * operation is successfull
357 */
358static void
359pid_cb (void *cb_cls,
360 struct GNUNET_TESTBED_Operation *op,
361 const struct GNUNET_TESTBED_PeerInformation*pinfo,
362 const char *emsg)
363{
364 struct BenchmarkPeer *p = cb_cls;
365 if (pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY)
366 {
367 p->id = *pinfo->result.id;
368 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
369 _("Peers %s\n"), GNUNET_i2s (&p->id));
370 }
371 else
372 {
373 GNUNET_assert (0);
374 }
375 GNUNET_TESTBED_operation_done (op);
376 p->info_op = NULL;
377}
378
272 379
273/** 380/**
274 * Signature of a main function for a testcase. 381 * Signature of a main function for a testcase.
@@ -305,22 +412,26 @@ test_main (void *cls, unsigned int num_peers,
305 { 412 {
306 GNUNET_assert (NULL != peers_[c_p]); 413 GNUNET_assert (NULL != peers_[c_p]);
307 /* Connect to ATS performance service */ 414 /* Connect to ATS performance service */
415 ph[c_p].peer = peers_[c_p];
416
417 ph[c_p].info_op = GNUNET_TESTBED_peer_get_information (ph[c_p].peer,
418 GNUNET_TESTBED_PIT_IDENTITY, &pid_cb, &ph[c_p]);
419
308 ph[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, 420 ph[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL,
309 peers_[c_p], "ats", 421 peers_[c_p], "ats",
310 ats_connect_completion_cb, NULL, 422 ats_connect_completion_cb, NULL,
311 &ats_perf_connect_adapter, 423 &ats_perf_connect_adapter,
312 &ats_perf_disconnect_adapter, 424 &ats_perf_disconnect_adapter,
313 &ph[c_p]); 425 &ph[c_p]);
314 426 /*
315 ph[c_p].ats_sched_op = GNUNET_TESTBED_service_connect (NULL, 427 ph[c_p].ats_sched_op = GNUNET_TESTBED_service_connect (NULL,
316 peers_[c_p], "ats", 428 peers_[c_p], "ats",
317 ats_connect_completion_cb, NULL, 429 ats_connect_completion_cb, NULL,
318 &ats_sched_connect_adapter, 430 &ats_sched_connect_adapter,
319 &ats_sched_disconnect_adapter, 431 &ats_sched_disconnect_adapter,
320 &ph[c_p]); 432 &ph[c_p]);
433 */
321 } 434 }
322
323
324} 435}
325 436
326 437