diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-08-06 09:00:59 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-08-06 09:00:59 +0000 |
commit | 177f92ec7de0e0b3b294c2ddfb63af57f070b00b (patch) | |
tree | 43eaf3c80743d8270404d2183af3b2d40aedef4c /src/ats/perf_ats.c | |
parent | 0d001a0a8cbda2dc755ed6b3c5e149cf3efe6cc3 (diff) | |
download | gnunet-177f92ec7de0e0b3b294c2ddfb63af57f070b00b.tar.gz gnunet-177f92ec7de0e0b3b294c2ddfb63af57f070b00b.zip |
initialization with ats
Diffstat (limited to 'src/ats/perf_ats.c')
-rw-r--r-- | src/ats/perf_ats.c | 188 |
1 files changed, 162 insertions, 26 deletions
diff --git a/src/ats/perf_ats.c b/src/ats/perf_ats.c index f60a2f345..330b32bd5 100644 --- a/src/ats/perf_ats.c +++ b/src/ats/perf_ats.c | |||
@@ -43,9 +43,14 @@ struct BenchmarkPeer | |||
43 | struct GNUNET_TESTBED_Peer *daemon; | 43 | struct GNUNET_TESTBED_Peer *daemon; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Testbed operation to connect to statistics service | 46 | * Testbed operation to connect to ATS performance service |
47 | */ | 47 | */ |
48 | struct GNUNET_TESTBED_Operation *stat_op; | 48 | struct GNUNET_TESTBED_Operation *ats_perf_op; |
49 | |||
50 | /** | ||
51 | * Testbed operation to connect to ATS scheduling service | ||
52 | */ | ||
53 | struct GNUNET_TESTBED_Operation *ats_sched_op; | ||
49 | 54 | ||
50 | struct GNUNET_ATS_PerformanceHandle *p_handle; | 55 | struct GNUNET_ATS_PerformanceHandle *p_handle; |
51 | struct GNUNET_ATS_SchedulingHandle *s_handle; | 56 | struct GNUNET_ATS_SchedulingHandle *s_handle; |
@@ -76,26 +81,25 @@ static int peers; | |||
76 | static void | 81 | static void |
77 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 82 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
78 | { | 83 | { |
84 | int c_p; | ||
79 | shutdown_task = GNUNET_SCHEDULER_NO_TASK; | 85 | shutdown_task = GNUNET_SCHEDULER_NO_TASK; |
80 | 86 | ||
81 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n")); | 87 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n")); |
82 | 88 | ||
89 | for (c_p = 0; c_p < peers; c_p++) | ||
90 | { | ||
91 | if (NULL != ph[c_p].ats_perf_op) | ||
92 | GNUNET_TESTBED_operation_done (ph[c_p].ats_perf_op); | ||
93 | ph[c_p].ats_perf_op = NULL; | ||
94 | if (NULL != ph[c_p].ats_sched_op) | ||
95 | GNUNET_TESTBED_operation_done (ph[c_p].ats_sched_op); | ||
96 | ph[c_p].ats_sched_op = NULL; | ||
97 | |||
98 | } | ||
83 | 99 | ||
84 | GNUNET_SCHEDULER_shutdown(); | 100 | GNUNET_SCHEDULER_shutdown(); |
85 | } | 101 | } |
86 | 102 | ||
87 | /** | ||
88 | * Controller event callback | ||
89 | * | ||
90 | * @param cls NULL | ||
91 | * @param event the controller event | ||
92 | */ | ||
93 | static void | ||
94 | controller_event_cb (void *cls, | ||
95 | const struct GNUNET_TESTBED_EventInformation *event) | ||
96 | { | ||
97 | |||
98 | } | ||
99 | 103 | ||
100 | static void | 104 | static void |
101 | ats_performance_info_cb (void *cls, | 105 | ats_performance_info_cb (void *cls, |
@@ -110,6 +114,32 @@ ats_performance_info_cb (void *cls, | |||
110 | } | 114 | } |
111 | 115 | ||
112 | /** | 116 | /** |
117 | * Controller event callback | ||
118 | * | ||
119 | * @param cls NULL | ||
120 | * @param event the controller event | ||
121 | */ | ||
122 | static void | ||
123 | controller_event_cb (void *cls, | ||
124 | const struct GNUNET_TESTBED_EventInformation *event) | ||
125 | { | ||
126 | //struct BenchmarkPeer *p = cls; | ||
127 | switch (event->type) | ||
128 | { | ||
129 | case GNUNET_TESTBED_ET_CONNECT: | ||
130 | GNUNET_break (0); | ||
131 | break; | ||
132 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
133 | break; | ||
134 | default: | ||
135 | GNUNET_break (0); | ||
136 | result = GNUNET_SYSERR; | ||
137 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
138 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
139 | } | ||
140 | } | ||
141 | |||
142 | /** | ||
113 | * Called to open a connection to the peer's ATS performance | 143 | * Called to open a connection to the peer's ATS performance |
114 | * | 144 | * |
115 | * @param cls peer context | 145 | * @param cls peer context |
@@ -129,6 +159,7 @@ ats_perf_connect_adapter (void *cls, | |||
129 | return peer->p_handle; | 159 | return peer->p_handle; |
130 | } | 160 | } |
131 | 161 | ||
162 | |||
132 | /** | 163 | /** |
133 | * Called to disconnect from peer's statistics service | 164 | * Called to disconnect from peer's statistics service |
134 | * | 165 | * |
@@ -146,6 +177,100 @@ ats_perf_disconnect_adapter (void *cls, void *op_result) | |||
146 | 177 | ||
147 | 178 | ||
148 | /** | 179 | /** |
180 | * Signature of a function called by ATS with the current bandwidth | ||
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 | */ | ||
191 | static void | ||
192 | ats_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 | { | ||
199 | |||
200 | } | ||
201 | |||
202 | |||
203 | /** | ||
204 | * Callback to be called when a service connect operation is completed | ||
205 | * | ||
206 | * @param cls the callback closure from functions generating an operation | ||
207 | * @param op the operation that has been finished | ||
208 | * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() | ||
209 | * @param emsg error message in case the operation has failed; will be NULL if | ||
210 | * operation has executed successfully. | ||
211 | */ | ||
212 | void ats_connect_completion_cb (void *cls, | ||
213 | struct GNUNET_TESTBED_Operation *op, | ||
214 | void *ca_result, | ||
215 | const char *emsg ) | ||
216 | { | ||
217 | static int op_done = 0 ; | ||
218 | if ((NULL != emsg) || (NULL == ca_result)) | ||
219 | { | ||
220 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
221 | _("Initialization failed, shutdown\n")); | ||
222 | GNUNET_break (0); | ||
223 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
224 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
225 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); | ||
226 | return; | ||
227 | } | ||
228 | op_done ++; | ||
229 | if (op_done == 2 * peers) | ||
230 | { | ||
231 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
232 | _("Initialization done, connecting peers\n")); | ||
233 | |||
234 | } | ||
235 | } | ||
236 | |||
237 | /** | ||
238 | * Called to open a connection to the peer's ATS scheduling API | ||
239 | * | ||
240 | * @param cls peer context | ||
241 | * @param cfg configuration of the peer to connect to; will be available until | ||
242 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
243 | * from GNUNET_TESTBED_service_connect() | ||
244 | * @return service handle to return in 'op_result', NULL on error | ||
245 | */ | ||
246 | static void * | ||
247 | ats_sched_connect_adapter (void *cls, | ||
248 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
249 | { | ||
250 | struct BenchmarkPeer *peer = cls; | ||
251 | peer->s_handle = GNUNET_ATS_scheduling_init(cfg, &ats_scheduling_cb, peer); | ||
252 | if (NULL == peer->s_handle) | ||
253 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create ATS performance handle \n"); | ||
254 | return peer->s_handle; | ||
255 | } | ||
256 | |||
257 | /** | ||
258 | * Called to disconnect from peer's statistics service | ||
259 | * | ||
260 | * @param cls peer context | ||
261 | * @param op_result service handle returned from the connect adapter | ||
262 | */ | ||
263 | static void | ||
264 | ats_sched_disconnect_adapter (void *cls, void *op_result) | ||
265 | { | ||
266 | struct BenchmarkPeer *peer = cls; | ||
267 | |||
268 | GNUNET_ATS_scheduling_done (peer->s_handle); | ||
269 | peer->p_handle = NULL; | ||
270 | } | ||
271 | |||
272 | |||
273 | /** | ||
149 | * Signature of a main function for a testcase. | 274 | * Signature of a main function for a testcase. |
150 | * | 275 | * |
151 | * @param cls closure | 276 | * @param cls closure |
@@ -157,13 +282,15 @@ ats_perf_disconnect_adapter (void *cls, void *op_result) | |||
157 | * failed | 282 | * failed |
158 | */ | 283 | */ |
159 | static void | 284 | static void |
160 | test_master (void *cls, unsigned int num_peers, | 285 | test_main (void *cls, unsigned int num_peers, |
161 | struct GNUNET_TESTBED_Peer **peers_, | 286 | struct GNUNET_TESTBED_Peer **peers_, |
162 | unsigned int links_succeeded, | 287 | unsigned int links_succeeded, |
163 | unsigned int links_failed) | 288 | unsigned int links_failed) |
164 | { | 289 | { |
165 | int c_p; | 290 | int c_p; |
166 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Benchmarking solver `%s' on preference `%s'\n"), solver, preference); | 291 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
292 | _("Benchmarking solver `%s' on preference `%s' with %u peers\n"), | ||
293 | solver, preference, peers); | ||
167 | 294 | ||
168 | shutdown_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &do_shutdown, NULL); | 295 | shutdown_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &do_shutdown, NULL); |
169 | 296 | ||
@@ -171,18 +298,26 @@ test_master (void *cls, unsigned int num_peers, | |||
171 | GNUNET_assert (peers == num_peers); | 298 | GNUNET_assert (peers == num_peers); |
172 | GNUNET_assert (NULL != peers_); | 299 | GNUNET_assert (NULL != peers_); |
173 | 300 | ||
301 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
302 | _("Initializing... \n")); | ||
303 | |||
174 | for (c_p = 0; c_p < num_peers; c_p++) | 304 | for (c_p = 0; c_p < num_peers; c_p++) |
175 | { | 305 | { |
176 | GNUNET_assert (NULL != peers_[c_p]); | 306 | GNUNET_assert (NULL != peers_[c_p]); |
177 | /* Connect to ATS service */ | 307 | /* Connect to ATS performance service */ |
178 | /* | 308 | ph[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, |
179 | ph[c_p].stat_op = GNUNET_TESTBED_service_connect (NULL, | ||
180 | peers_[c_p], "ats", | 309 | peers_[c_p], "ats", |
181 | NULL, &ph[c_p], | 310 | ats_connect_completion_cb, NULL, |
182 | &ats_perf_connect_adapter, | 311 | &ats_perf_connect_adapter, |
183 | &ats_perf_disconnect_adapter, | 312 | &ats_perf_disconnect_adapter, |
184 | &ph[c_p]); | 313 | &ph[c_p]); |
185 | */ | 314 | |
315 | ph[c_p].ats_sched_op = GNUNET_TESTBED_service_connect (NULL, | ||
316 | peers_[c_p], "ats", | ||
317 | ats_connect_completion_cb, NULL, | ||
318 | &ats_sched_connect_adapter, | ||
319 | &ats_sched_disconnect_adapter, | ||
320 | &ph[c_p]); | ||
186 | } | 321 | } |
187 | 322 | ||
188 | 323 | ||
@@ -230,15 +365,15 @@ main (int argc, char *argv[]) | |||
230 | } | 365 | } |
231 | if (c <= argc-1) | 366 | if (c <= argc-1) |
232 | { | 367 | { |
233 | if (0L != (peers = strtol (argv[c + 1], NULL, 10))) | 368 | if ((0L != (peers = strtol (argv[c + 1], NULL, 10))) && (peers >= 3)) |
234 | { | ||
235 | peers = strtol (argv[c + 1], NULL, 10); | ||
236 | fprintf (stderr, "Starting %u peers\n", peers); | 369 | fprintf (stderr, "Starting %u peers\n", peers); |
237 | } | 370 | else |
371 | peers = DEFAULT_NUM; | ||
238 | } | 372 | } |
239 | else | 373 | else |
240 | peers = DEFAULT_NUM; | 374 | peers = DEFAULT_NUM; |
241 | 375 | ||
376 | ph = GNUNET_malloc (peers * sizeof (struct BenchmarkPeer)); | ||
242 | 377 | ||
243 | /* Start topology */ | 378 | /* Start topology */ |
244 | uint64_t event_mask; | 379 | uint64_t event_mask; |
@@ -249,12 +384,13 @@ main (int argc, char *argv[]) | |||
249 | (void) GNUNET_TESTBED_test_run (test_name, | 384 | (void) GNUNET_TESTBED_test_run (test_name, |
250 | conf_name, peers, | 385 | conf_name, peers, |
251 | event_mask, &controller_event_cb, NULL, | 386 | event_mask, &controller_event_cb, NULL, |
252 | &test_master, NULL); | 387 | &test_main, NULL); |
253 | 388 | ||
254 | GNUNET_free (solver); | 389 | GNUNET_free (solver); |
255 | GNUNET_free (preference); | 390 | GNUNET_free (preference); |
256 | GNUNET_free (conf_name); | 391 | GNUNET_free (conf_name); |
257 | GNUNET_free (test_name); | 392 | GNUNET_free (test_name); |
393 | GNUNET_free (ph); | ||
258 | 394 | ||
259 | return result; | 395 | return result; |
260 | } | 396 | } |