aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-08-06 13:47:53 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-08-06 13:47:53 +0000
commit7eb2835d8a494c83aedb720a2ac6f6e5ba23f22f (patch)
tree9c4d09a028c0dc13c7468ff2168ecd94b1d9c8af /src
parent628e1b0b13694f982822bfdff868db8753737d05 (diff)
downloadgnunet-7eb2835d8a494c83aedb720a2ac6f6e5ba23f22f.tar.gz
gnunet-7eb2835d8a494c83aedb720a2ac6f6e5ba23f22f.zip
peers are connecting
Diffstat (limited to 'src')
-rw-r--r--src/ats/perf_ats.c111
1 files changed, 21 insertions, 90 deletions
diff --git a/src/ats/perf_ats.c b/src/ats/perf_ats.c
index 76add88a4..b7c7f5ab4 100644
--- a/src/ats/perf_ats.c
+++ b/src/ats/perf_ats.c
@@ -50,24 +50,19 @@ struct BenchmarkPeer
50 struct GNUNET_TESTBED_Operation *ats_perf_op; 50 struct GNUNET_TESTBED_Operation *ats_perf_op;
51 51
52 /** 52 /**
53 * Testbed operation to connect to ATS scheduling service
54 */
55 struct GNUNET_TESTBED_Operation *ats_sched_op;
56
57 /**
58 * Testbed operation to get peer information 53 * Testbed operation to get peer information
59 */ 54 */
60 struct GNUNET_TESTBED_Operation *info_op; 55 struct GNUNET_TESTBED_Operation *info_op;
61 56
62
63 /** 57 /**
64 * Testbed operation to connect peers 58 * Testbed operation to connect peers
65 */ 59 */
66 struct GNUNET_TESTBED_Operation *connect_op; 60 struct GNUNET_TESTBED_Operation *connect_op;
67 61
62 /**
63 * ATS performance handle
64 */
68 struct GNUNET_ATS_PerformanceHandle *p_handle; 65 struct GNUNET_ATS_PerformanceHandle *p_handle;
69 struct GNUNET_ATS_SchedulingHandle *s_handle;
70
71}; 66};
72 67
73struct BenchmarkPeer *ph; 68struct BenchmarkPeer *ph;
@@ -104,27 +99,24 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
104 if (NULL != ph[c_p].ats_perf_op) 99 if (NULL != ph[c_p].ats_perf_op)
105 { 100 {
106 GNUNET_TESTBED_operation_done (ph[c_p].ats_perf_op); 101 GNUNET_TESTBED_operation_done (ph[c_p].ats_perf_op);
102 ph[c_p].ats_perf_op = NULL;
107 } 103 }
108 ph[c_p].ats_perf_op = NULL; 104
109 if (NULL != ph[c_p].ats_sched_op)
110 {
111 GNUNET_TESTBED_operation_done (ph[c_p].ats_sched_op);
112 }
113 ph[c_p].ats_sched_op = NULL;
114 105
115 if (NULL != ph[c_p].info_op) 106 if (NULL != ph[c_p].info_op)
116 { 107 {
117 GNUNET_break (0); 108 GNUNET_break (0);
118 GNUNET_TESTBED_operation_done (ph[c_p].info_op); 109 GNUNET_TESTBED_operation_done (ph[c_p].info_op);
110 ph[c_p].info_op = NULL;
119 } 111 }
120 if (NULL != ph[c_p].connect_op) 112 if (NULL != ph[c_p].connect_op)
121 { 113 {
122 GNUNET_break (0); 114 GNUNET_break (0);
115 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect peer 0 and %u\n"), c_p);
123 GNUNET_TESTBED_operation_done (ph[c_p].connect_op); 116 GNUNET_TESTBED_operation_done (ph[c_p].connect_op);
117 ph[c_p].connect_op = NULL;
118 result = 1;
124 } 119 }
125 ph[c_p].connect_op = NULL;
126
127
128 } 120 }
129 121
130 GNUNET_SCHEDULER_shutdown(); 122 GNUNET_SCHEDULER_shutdown();
@@ -140,31 +132,7 @@ ats_performance_info_cb (void *cls,
140 const struct GNUNET_ATS_Information *ats, 132 const struct GNUNET_ATS_Information *ats,
141 uint32_t ats_count) 133 uint32_t ats_count)
142{ 134{
143 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("[P] %s\n"), GNUNET_i2s (&address->peer)); 135 //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));
167
168} 136}
169 137
170/** 138/**
@@ -232,6 +200,7 @@ void connect_completion_callback (void *cls,
232 struct GNUNET_TESTBED_Operation *op, 200 struct GNUNET_TESTBED_Operation *op,
233 const char *emsg) 201 const char *emsg)
234{ 202{
203 static int connections = 0;
235 struct BenchmarkPeer *p = cls; 204 struct BenchmarkPeer *p = cls;
236 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 205 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
237 _("Connected peer 0 with peer %p\n"), p->peer); 206 _("Connected peer 0 with peer %p\n"), p->peer);
@@ -251,6 +220,12 @@ void connect_completion_callback (void *cls,
251 } 220 }
252 GNUNET_TESTBED_operation_done(op); 221 GNUNET_TESTBED_operation_done(op);
253 p->connect_op = NULL; 222 p->connect_op = NULL;
223 connections++;
224 if (connections == peers -1)
225 {
226 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
227 "All peers connected\n");
228 }
254 229
255} 230}
256static void 231static void
@@ -289,7 +264,6 @@ void ats_connect_completion_cb (void *cls,
289 const char *emsg ) 264 const char *emsg )
290{ 265{
291 static int op_done = 0; 266 static int op_done = 0;
292 int c_p;
293 if ((NULL != emsg) || (NULL == ca_result)) 267 if ((NULL != emsg) || (NULL == ca_result))
294 { 268 {
295 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 269 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -302,7 +276,7 @@ void ats_connect_completion_cb (void *cls,
302 } 276 }
303 277
304 op_done ++; 278 op_done ++;
305 if (op_done == 2 * peers) 279 if (op_done == peers)
306 { 280 {
307 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 281 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
308 _("Initialization done, connecting peers\n")); 282 _("Initialization done, connecting peers\n"));
@@ -312,41 +286,6 @@ void ats_connect_completion_cb (void *cls,
312} 286}
313 287
314/** 288/**
315 * Called to open a connection to the peer's ATS scheduling API
316 *
317 * @param cls peer context
318 * @param cfg configuration of the peer to connect to; will be available until
319 * GNUNET_TESTBED_operation_done() is called on the operation returned
320 * from GNUNET_TESTBED_service_connect()
321 * @return service handle to return in 'op_result', NULL on error
322 */
323static void *
324ats_sched_connect_adapter (void *cls,
325 const struct GNUNET_CONFIGURATION_Handle *cfg)
326{
327 struct BenchmarkPeer *peer = cls;
328 peer->s_handle = GNUNET_ATS_scheduling_init(cfg, &ats_scheduling_cb, peer);
329 if (NULL == peer->s_handle)
330 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create ATS performance handle \n");
331 return peer->s_handle;
332}
333
334/**
335 * Called to disconnect from peer's statistics service
336 *
337 * @param cls peer context
338 * @param op_result service handle returned from the connect adapter
339 */
340static void
341ats_sched_disconnect_adapter (void *cls, void *op_result)
342{
343 struct BenchmarkPeer *peer = cls;
344
345 GNUNET_ATS_scheduling_done (peer->s_handle);
346 peer->p_handle = NULL;
347}
348
349/**
350 * Callback to be called when the requested peer information is available 289 * Callback to be called when the requested peer information is available
351 * 290 *
352 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information() 291 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
@@ -423,13 +362,6 @@ test_main (void *cls, unsigned int num_peers,
423 &ats_perf_connect_adapter, 362 &ats_perf_connect_adapter,
424 &ats_perf_disconnect_adapter, 363 &ats_perf_disconnect_adapter,
425 &ph[c_p]); 364 &ph[c_p]);
426
427 ph[c_p].ats_sched_op = GNUNET_TESTBED_service_connect (NULL,
428 peers_[c_p], "ats",
429 ats_connect_completion_cb, NULL,
430 &ats_sched_connect_adapter,
431 &ats_sched_disconnect_adapter,
432 &ph[c_p]);
433 } 365 }
434} 366}
435 367
@@ -468,14 +400,14 @@ main (int argc, char *argv[])
468 GNUNET_asprintf(&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver, preference); 400 GNUNET_asprintf(&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver, preference);
469 GNUNET_asprintf(&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, preference); 401 GNUNET_asprintf(&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, preference);
470 402
471 for (c = 0; c < argc; c++) 403 for (c = 0; c < (argc -1); c++)
472 { 404 {
473 if (0 == strcmp(argv[c], "-c")) 405 if (0 == strcmp(argv[c], "-c"))
474 break; 406 break;
475 } 407 }
476 if (c <= argc-1) 408 if (c < argc-1)
477 { 409 {
478 if ((0L != (peers = strtol (argv[c + 1], NULL, 10))) && (peers >= 3)) 410 if ((0L != (peers = strtol (argv[c + 1], NULL, 10))) && (peers >= 2))
479 fprintf (stderr, "Starting %u peers\n", peers); 411 fprintf (stderr, "Starting %u peers\n", peers);
480 else 412 else
481 peers = DEFAULT_NUM; 413 peers = DEFAULT_NUM;
@@ -484,7 +416,6 @@ main (int argc, char *argv[])
484 peers = DEFAULT_NUM; 416 peers = DEFAULT_NUM;
485 417
486 ph = GNUNET_malloc (peers * sizeof (struct BenchmarkPeer)); 418 ph = GNUNET_malloc (peers * sizeof (struct BenchmarkPeer));
487
488 /* Start topology */ 419 /* Start topology */
489 uint64_t event_mask; 420 uint64_t event_mask;
490 result = GNUNET_SYSERR; 421 result = GNUNET_SYSERR;