diff options
Diffstat (limited to 'src/ats-tests/ats-testing.c')
-rw-r--r-- | src/ats-tests/ats-testing.c | 1081 |
1 files changed, 542 insertions, 539 deletions
diff --git a/src/ats-tests/ats-testing.c b/src/ats-tests/ats-testing.c index d8b9e5ef5..696deb4bd 100644 --- a/src/ats-tests/ats-testing.c +++ b/src/ats-tests/ats-testing.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010-2013, 2016, 2017 GNUnet e.V. | 3 | Copyright (C) 2010-2013, 2016, 2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -30,8 +30,7 @@ | |||
30 | /** | 30 | /** |
31 | * Connect peers with testbed | 31 | * Connect peers with testbed |
32 | */ | 32 | */ |
33 | struct TestbedConnectOperation | 33 | struct TestbedConnectOperation { |
34 | { | ||
35 | /** | 34 | /** |
36 | * The benchmarking master initiating this connection | 35 | * The benchmarking master initiating this connection |
37 | */ | 36 | */ |
@@ -59,7 +58,7 @@ struct GNUNET_ATS_TEST_Topology *top; | |||
59 | * @param cls NULL | 58 | * @param cls NULL |
60 | */ | 59 | */ |
61 | static void | 60 | static void |
62 | do_shutdown (void *cls) | 61 | do_shutdown(void *cls) |
63 | { | 62 | { |
64 | int c_m; | 63 | int c_m; |
65 | int c_s; | 64 | int c_s; |
@@ -68,119 +67,119 @@ do_shutdown (void *cls) | |||
68 | 67 | ||
69 | top->state.benchmarking = GNUNET_NO; | 68 | top->state.benchmarking = GNUNET_NO; |
70 | 69 | ||
71 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 70 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
72 | "Benchmarking done\n"); | 71 | "Benchmarking done\n"); |
73 | 72 | ||
74 | GNUNET_ATS_TEST_generate_traffic_stop_all (); | 73 | GNUNET_ATS_TEST_generate_traffic_stop_all(); |
75 | 74 | ||
76 | for (c_m = 0; c_m < top->num_masters; c_m++) | 75 | for (c_m = 0; c_m < top->num_masters; c_m++) |
77 | { | ||
78 | p = &top->mps[c_m]; | ||
79 | if (NULL != top->mps[c_m].peer_id_op) | ||
80 | { | ||
81 | GNUNET_TESTBED_operation_done (p->peer_id_op); | ||
82 | p->peer_id_op = NULL; | ||
83 | } | ||
84 | |||
85 | if (NULL != p->ats_task) | ||
86 | GNUNET_SCHEDULER_cancel (p->ats_task); | ||
87 | p->ats_task = NULL; | ||
88 | |||
89 | for (c_op = 0; c_op < p->num_partners; c_op++) | ||
90 | { | ||
91 | if ( (NULL != p->core_connect_ops) && | ||
92 | (NULL != p->core_connect_ops[c_op].connect_op) ) | ||
93 | { | ||
94 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
95 | "Failed to connect peer 0 and %u\n", | ||
96 | c_op); | ||
97 | GNUNET_TESTBED_operation_done (p->core_connect_ops[c_op].connect_op); | ||
98 | p->core_connect_ops[c_op].connect_op = NULL; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | if (NULL != p->ats_perf_op) | ||
103 | { | ||
104 | GNUNET_TESTBED_operation_done (p->ats_perf_op); | ||
105 | p->ats_perf_op = NULL; | ||
106 | } | ||
107 | |||
108 | if (NULL != p->comm_op) | ||
109 | { | 76 | { |
110 | GNUNET_TESTBED_operation_done (p->comm_op); | 77 | p = &top->mps[c_m]; |
111 | p->comm_op = NULL; | 78 | if (NULL != top->mps[c_m].peer_id_op) |
79 | { | ||
80 | GNUNET_TESTBED_operation_done(p->peer_id_op); | ||
81 | p->peer_id_op = NULL; | ||
82 | } | ||
83 | |||
84 | if (NULL != p->ats_task) | ||
85 | GNUNET_SCHEDULER_cancel(p->ats_task); | ||
86 | p->ats_task = NULL; | ||
87 | |||
88 | for (c_op = 0; c_op < p->num_partners; c_op++) | ||
89 | { | ||
90 | if ((NULL != p->core_connect_ops) && | ||
91 | (NULL != p->core_connect_ops[c_op].connect_op)) | ||
92 | { | ||
93 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
94 | "Failed to connect peer 0 and %u\n", | ||
95 | c_op); | ||
96 | GNUNET_TESTBED_operation_done(p->core_connect_ops[c_op].connect_op); | ||
97 | p->core_connect_ops[c_op].connect_op = NULL; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | if (NULL != p->ats_perf_op) | ||
102 | { | ||
103 | GNUNET_TESTBED_operation_done(p->ats_perf_op); | ||
104 | p->ats_perf_op = NULL; | ||
105 | } | ||
106 | |||
107 | if (NULL != p->comm_op) | ||
108 | { | ||
109 | GNUNET_TESTBED_operation_done(p->comm_op); | ||
110 | p->comm_op = NULL; | ||
111 | } | ||
112 | GNUNET_free_non_null(p->core_connect_ops); | ||
113 | GNUNET_free(p->partners); | ||
114 | p->partners = NULL; | ||
112 | } | 115 | } |
113 | GNUNET_free_non_null (p->core_connect_ops); | ||
114 | GNUNET_free(p->partners); | ||
115 | p->partners = NULL; | ||
116 | } | ||
117 | 116 | ||
118 | for (c_s = 0; c_s < top->num_slaves; c_s++) | 117 | for (c_s = 0; c_s < top->num_slaves; c_s++) |
119 | { | ||
120 | p = &top->sps[c_s]; | ||
121 | if (NULL != p->peer_id_op) | ||
122 | { | ||
123 | GNUNET_TESTBED_operation_done (p->peer_id_op); | ||
124 | p->peer_id_op = NULL; | ||
125 | } | ||
126 | if (NULL != p->ats_perf_op) | ||
127 | { | ||
128 | GNUNET_TESTBED_operation_done (p->ats_perf_op); | ||
129 | p->ats_perf_op = NULL; | ||
130 | } | ||
131 | if (NULL != p->comm_op) | ||
132 | { | 118 | { |
133 | GNUNET_TESTBED_operation_done (p->comm_op); | 119 | p = &top->sps[c_s]; |
134 | p->comm_op = NULL; | 120 | if (NULL != p->peer_id_op) |
121 | { | ||
122 | GNUNET_TESTBED_operation_done(p->peer_id_op); | ||
123 | p->peer_id_op = NULL; | ||
124 | } | ||
125 | if (NULL != p->ats_perf_op) | ||
126 | { | ||
127 | GNUNET_TESTBED_operation_done(p->ats_perf_op); | ||
128 | p->ats_perf_op = NULL; | ||
129 | } | ||
130 | if (NULL != p->comm_op) | ||
131 | { | ||
132 | GNUNET_TESTBED_operation_done(p->comm_op); | ||
133 | p->comm_op = NULL; | ||
134 | } | ||
135 | GNUNET_free(p->partners); | ||
136 | p->partners = NULL; | ||
135 | } | 137 | } |
136 | GNUNET_free(p->partners); | 138 | GNUNET_SCHEDULER_shutdown(); |
137 | p->partners = NULL; | 139 | GNUNET_free(top); |
138 | } | ||
139 | GNUNET_SCHEDULER_shutdown (); | ||
140 | GNUNET_free (top); | ||
141 | top = NULL; | 140 | top = NULL; |
142 | } | 141 | } |
143 | 142 | ||
144 | 143 | ||
145 | static struct BenchmarkPartner * | 144 | static struct BenchmarkPartner * |
146 | find_partner (struct BenchmarkPeer *me, | 145 | find_partner(struct BenchmarkPeer *me, |
147 | const struct GNUNET_PeerIdentity *peer) | 146 | const struct GNUNET_PeerIdentity *peer) |
148 | { | 147 | { |
149 | int c_m; | 148 | int c_m; |
150 | 149 | ||
151 | for (c_m = 0; c_m < me->num_partners; c_m++) | 150 | for (c_m = 0; c_m < me->num_partners; c_m++) |
152 | { | ||
153 | /* Find a partner with other as destination */ | ||
154 | if (0 == GNUNET_memcmp (peer, | ||
155 | &me->partners[c_m].dest->id)) | ||
156 | { | 151 | { |
157 | return &me->partners[c_m]; | 152 | /* Find a partner with other as destination */ |
153 | if (0 == GNUNET_memcmp(peer, | ||
154 | &me->partners[c_m].dest->id)) | ||
155 | { | ||
156 | return &me->partners[c_m]; | ||
157 | } | ||
158 | } | 158 | } |
159 | } | ||
160 | 159 | ||
161 | return NULL; | 160 | return NULL; |
162 | } | 161 | } |
163 | 162 | ||
164 | 163 | ||
165 | static struct BenchmarkPeer * | 164 | static struct BenchmarkPeer * |
166 | find_peer (const struct GNUNET_PeerIdentity * peer) | 165 | find_peer(const struct GNUNET_PeerIdentity * peer) |
167 | { | 166 | { |
168 | int c_p; | 167 | int c_p; |
169 | 168 | ||
170 | for (c_p = 0; c_p < top->num_masters; c_p++) | 169 | for (c_p = 0; c_p < top->num_masters; c_p++) |
171 | { | 170 | { |
172 | if (0 == GNUNET_memcmp (&top->mps[c_p].id, | 171 | if (0 == GNUNET_memcmp(&top->mps[c_p].id, |
173 | peer)) | 172 | peer)) |
174 | return &top->mps[c_p]; | 173 | return &top->mps[c_p]; |
175 | } | 174 | } |
176 | 175 | ||
177 | for (c_p = 0; c_p < top->num_slaves; c_p++) | 176 | for (c_p = 0; c_p < top->num_slaves; c_p++) |
178 | { | 177 | { |
179 | if (0 == GNUNET_memcmp (&top->sps[c_p].id, | 178 | if (0 == GNUNET_memcmp(&top->sps[c_p].id, |
180 | peer)) | 179 | peer)) |
181 | return &top->sps[c_p]; | 180 | return &top->sps[c_p]; |
182 | } | 181 | } |
183 | return NULL ; | 182 | return NULL; |
184 | } | 183 | } |
185 | 184 | ||
186 | 185 | ||
@@ -193,9 +192,9 @@ find_peer (const struct GNUNET_PeerIdentity * peer) | |||
193 | * @return the `struct BenchmarkPartner` of @a peer | 192 | * @return the `struct BenchmarkPartner` of @a peer |
194 | */ | 193 | */ |
195 | static void * | 194 | static void * |
196 | comm_connect_cb (void *cls, | 195 | comm_connect_cb(void *cls, |
197 | const struct GNUNET_PeerIdentity *peer, | 196 | const struct GNUNET_PeerIdentity *peer, |
198 | struct GNUNET_MQ_Handle *mq) | 197 | struct GNUNET_MQ_Handle *mq) |
199 | { | 198 | { |
200 | struct BenchmarkPeer *me = cls; | 199 | struct BenchmarkPeer *me = cls; |
201 | struct BenchmarkPeer *remote; | 200 | struct BenchmarkPeer *remote; |
@@ -204,60 +203,60 @@ comm_connect_cb (void *cls, | |||
204 | int c; | 203 | int c; |
205 | int completed; | 204 | int completed; |
206 | 205 | ||
207 | remote = find_peer (peer); | 206 | remote = find_peer(peer); |
208 | if (NULL == remote) | 207 | if (NULL == remote) |
209 | { | 208 | { |
210 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 209 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
211 | "Unknown peer connected: `%s'\n", | 210 | "Unknown peer connected: `%s'\n", |
212 | GNUNET_i2s (peer)); | 211 | GNUNET_i2s(peer)); |
213 | GNUNET_break (0); | 212 | GNUNET_break(0); |
214 | return NULL; | 213 | return NULL; |
215 | } | 214 | } |
216 | 215 | ||
217 | id = GNUNET_strdup (GNUNET_i2s (&me->id)); | 216 | id = GNUNET_strdup(GNUNET_i2s(&me->id)); |
218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 217 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
219 | "%s [%u] `%s' connected to %s [%u] %s\n", | 218 | "%s [%u] `%s' connected to %s [%u] %s\n", |
220 | (me->master == GNUNET_YES) ? "Master": "Slave", | 219 | (me->master == GNUNET_YES) ? "Master" : "Slave", |
221 | me->no, | 220 | me->no, |
222 | id, | 221 | id, |
223 | (remote->master == GNUNET_YES) ? "Master": "Slave", | 222 | (remote->master == GNUNET_YES) ? "Master" : "Slave", |
224 | remote->no, | 223 | remote->no, |
225 | GNUNET_i2s (peer)); | 224 | GNUNET_i2s(peer)); |
226 | 225 | ||
227 | me->core_connections++; | 226 | me->core_connections++; |
228 | if ((GNUNET_YES == me->master) && | 227 | if ((GNUNET_YES == me->master) && |
229 | (GNUNET_NO == remote->master) && | 228 | (GNUNET_NO == remote->master) && |
230 | (GNUNET_NO == top->state.connected_CORE)) | 229 | (GNUNET_NO == top->state.connected_CORE)) |
231 | { | ||
232 | me->core_slave_connections++; | ||
233 | |||
234 | if (me->core_slave_connections == top->num_slaves) | ||
235 | { | ||
236 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
237 | "Master [%u] connected all slaves\n", | ||
238 | me->no); | ||
239 | } | ||
240 | completed = GNUNET_YES; | ||
241 | for (c = 0; c < top->num_masters; c++) | ||
242 | { | ||
243 | if (top->mps[c].core_slave_connections != top->num_slaves) | ||
244 | completed = GNUNET_NO; | ||
245 | } | ||
246 | if (GNUNET_YES == completed) | ||
247 | { | 230 | { |
248 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 231 | me->core_slave_connections++; |
249 | "All master peers connected all slave peers\n"); | 232 | |
250 | top->state.connected_CORE = GNUNET_YES; | 233 | if (me->core_slave_connections == top->num_slaves) |
251 | /* Notify about setup done */ | 234 | { |
252 | if (NULL != top->done_cb) | 235 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
253 | top->done_cb (top->done_cb_cls, | 236 | "Master [%u] connected all slaves\n", |
254 | top->mps, | 237 | me->no); |
255 | top->sps); | 238 | } |
239 | completed = GNUNET_YES; | ||
240 | for (c = 0; c < top->num_masters; c++) | ||
241 | { | ||
242 | if (top->mps[c].core_slave_connections != top->num_slaves) | ||
243 | completed = GNUNET_NO; | ||
244 | } | ||
245 | if (GNUNET_YES == completed) | ||
246 | { | ||
247 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
248 | "All master peers connected all slave peers\n"); | ||
249 | top->state.connected_CORE = GNUNET_YES; | ||
250 | /* Notify about setup done */ | ||
251 | if (NULL != top->done_cb) | ||
252 | top->done_cb(top->done_cb_cls, | ||
253 | top->mps, | ||
254 | top->sps); | ||
255 | } | ||
256 | } | 256 | } |
257 | } | 257 | GNUNET_free(id); |
258 | GNUNET_free (id); | 258 | p = find_partner(me, |
259 | p = find_partner (me, | 259 | peer); |
260 | peer); | ||
261 | if (NULL != p) | 260 | if (NULL != p) |
262 | p->mq = mq; | 261 | p->mq = mq; |
263 | return p; | 262 | return p; |
@@ -270,9 +269,9 @@ comm_connect_cb (void *cls, | |||
270 | * @param internal_cls the `struct BenchmarkPartner` of @a peer | 269 | * @param internal_cls the `struct BenchmarkPartner` of @a peer |
271 | */ | 270 | */ |
272 | static void | 271 | static void |
273 | comm_disconnect_cb (void *cls, | 272 | comm_disconnect_cb(void *cls, |
274 | const struct GNUNET_PeerIdentity *peer, | 273 | const struct GNUNET_PeerIdentity *peer, |
275 | void *internal_cls) | 274 | void *internal_cls) |
276 | { | 275 | { |
277 | struct BenchmarkPeer *me = cls; | 276 | struct BenchmarkPeer *me = cls; |
278 | struct BenchmarkPartner *p = internal_cls; | 277 | struct BenchmarkPartner *p = internal_cls; |
@@ -281,169 +280,170 @@ comm_disconnect_cb (void *cls, | |||
281 | if (NULL == p) | 280 | if (NULL == p) |
282 | return; | 281 | return; |
283 | 282 | ||
284 | id = GNUNET_strdup (GNUNET_i2s (&me->id)); | 283 | id = GNUNET_strdup(GNUNET_i2s(&me->id)); |
285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 284 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
286 | "%s disconnected from %s\n", | 285 | "%s disconnected from %s\n", |
287 | id, | 286 | id, |
288 | GNUNET_i2s (peer)); | 287 | GNUNET_i2s(peer)); |
289 | GNUNET_assert (me->core_connections > 0); | 288 | GNUNET_assert(me->core_connections > 0); |
290 | me->core_connections--; | 289 | me->core_connections--; |
291 | 290 | ||
292 | if ( (GNUNET_YES == top->state.benchmarking) && | 291 | if ((GNUNET_YES == top->state.benchmarking) && |
293 | ( (GNUNET_YES == me->master) || | 292 | ((GNUNET_YES == me->master) || |
294 | (GNUNET_YES == p->dest->master) ) ) | 293 | (GNUNET_YES == p->dest->master))) |
295 | { | 294 | { |
296 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 295 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
297 | "%s disconnected from %s while benchmarking\n", | 296 | "%s disconnected from %s while benchmarking\n", |
298 | id, | 297 | id, |
299 | GNUNET_i2s (peer)); | 298 | GNUNET_i2s(peer)); |
300 | } | 299 | } |
301 | GNUNET_free(id); | 300 | GNUNET_free(id); |
302 | } | 301 | } |
303 | 302 | ||
304 | 303 | ||
305 | static void | 304 | static void |
306 | handle_pong (void *cls, | 305 | handle_pong(void *cls, |
307 | const struct TestMessage *message) | 306 | const struct TestMessage *message) |
308 | { | 307 | { |
309 | struct BenchmarkPartner *p = cls; | 308 | struct BenchmarkPartner *p = cls; |
310 | 309 | ||
311 | GNUNET_ATS_TEST_traffic_handle_pong (p); | 310 | GNUNET_ATS_TEST_traffic_handle_pong(p); |
312 | } | 311 | } |
313 | 312 | ||
314 | 313 | ||
315 | static void | 314 | static void |
316 | handle_ping (void *cls, | 315 | handle_ping(void *cls, |
317 | const struct TestMessage *message) | 316 | const struct TestMessage *message) |
318 | { | 317 | { |
319 | struct BenchmarkPartner *p = cls; | 318 | struct BenchmarkPartner *p = cls; |
320 | 319 | ||
321 | GNUNET_ATS_TEST_traffic_handle_ping (p); | 320 | GNUNET_ATS_TEST_traffic_handle_ping(p); |
322 | } | 321 | } |
323 | 322 | ||
324 | 323 | ||
325 | static void * | 324 | static void * |
326 | transport_connect_adapter (void *cls, | 325 | transport_connect_adapter(void *cls, |
327 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 326 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
328 | { | 327 | { |
329 | struct BenchmarkPeer *me = cls; | 328 | struct BenchmarkPeer *me = cls; |
330 | struct GNUNET_MQ_MessageHandler handlers[] = { | 329 | struct GNUNET_MQ_MessageHandler handlers[] = { |
331 | GNUNET_MQ_hd_fixed_size (ping, | 330 | GNUNET_MQ_hd_fixed_size(ping, |
332 | TEST_MESSAGE_TYPE_PING, | 331 | TEST_MESSAGE_TYPE_PING, |
333 | struct TestMessage, | 332 | struct TestMessage, |
334 | me), | 333 | me), |
335 | GNUNET_MQ_hd_fixed_size (pong, | 334 | GNUNET_MQ_hd_fixed_size(pong, |
336 | TEST_MESSAGE_TYPE_PONG, | 335 | TEST_MESSAGE_TYPE_PONG, |
337 | struct TestMessage, | 336 | struct TestMessage, |
338 | me), | 337 | me), |
339 | GNUNET_MQ_handler_end () | 338 | GNUNET_MQ_handler_end() |
340 | }; | 339 | }; |
341 | 340 | ||
342 | me->th = GNUNET_TRANSPORT_core_connect (cfg, | 341 | me->th = GNUNET_TRANSPORT_core_connect(cfg, |
343 | &me->id, | 342 | &me->id, |
344 | handlers, | 343 | handlers, |
345 | me, | 344 | me, |
346 | &comm_connect_cb, | 345 | &comm_connect_cb, |
347 | &comm_disconnect_cb, | 346 | &comm_disconnect_cb, |
348 | NULL); | 347 | NULL); |
349 | if (NULL == me->th) | 348 | if (NULL == me->th) |
350 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 349 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
351 | "Failed to create transport connection \n"); | 350 | "Failed to create transport connection \n"); |
352 | return me->th; | 351 | return me->th; |
353 | } | 352 | } |
354 | 353 | ||
355 | 354 | ||
356 | static void | 355 | static void |
357 | transport_disconnect_adapter (void *cls, | 356 | transport_disconnect_adapter(void *cls, |
358 | void *op_result) | 357 | void *op_result) |
359 | { | 358 | { |
360 | struct BenchmarkPeer *me = cls; | 359 | struct BenchmarkPeer *me = cls; |
361 | 360 | ||
362 | GNUNET_TRANSPORT_core_disconnect (me->th); | 361 | GNUNET_TRANSPORT_core_disconnect(me->th); |
363 | me->th = NULL; | 362 | me->th = NULL; |
364 | } | 363 | } |
365 | 364 | ||
366 | 365 | ||
367 | static void * | 366 | static void * |
368 | core_connect_adapter (void *cls, | 367 | core_connect_adapter(void *cls, |
369 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 368 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
370 | { | 369 | { |
371 | struct BenchmarkPeer *me = cls; | 370 | struct BenchmarkPeer *me = cls; |
372 | struct GNUNET_MQ_MessageHandler handlers[] = { | 371 | struct GNUNET_MQ_MessageHandler handlers[] = { |
373 | GNUNET_MQ_hd_fixed_size (ping, | 372 | GNUNET_MQ_hd_fixed_size(ping, |
374 | TEST_MESSAGE_TYPE_PING, | 373 | TEST_MESSAGE_TYPE_PING, |
375 | struct TestMessage, | 374 | struct TestMessage, |
376 | me), | 375 | me), |
377 | GNUNET_MQ_hd_fixed_size (pong, | 376 | GNUNET_MQ_hd_fixed_size(pong, |
378 | TEST_MESSAGE_TYPE_PONG, | 377 | TEST_MESSAGE_TYPE_PONG, |
379 | struct TestMessage, | 378 | struct TestMessage, |
380 | me), | 379 | me), |
381 | GNUNET_MQ_handler_end () | 380 | GNUNET_MQ_handler_end() |
382 | }; | 381 | }; |
383 | 382 | ||
384 | me->ch = GNUNET_CORE_connect (cfg, | 383 | me->ch = GNUNET_CORE_connect(cfg, |
385 | me, | 384 | me, |
386 | NULL, | 385 | NULL, |
387 | &comm_connect_cb, | 386 | &comm_connect_cb, |
388 | &comm_disconnect_cb, | 387 | &comm_disconnect_cb, |
389 | handlers); | 388 | handlers); |
390 | if (NULL == me->ch) | 389 | if (NULL == me->ch) |
391 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 390 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
392 | "Failed to create core connection \n"); | 391 | "Failed to create core connection \n"); |
393 | return me->ch; | 392 | return me->ch; |
394 | } | 393 | } |
395 | 394 | ||
396 | 395 | ||
397 | static void | 396 | static void |
398 | core_disconnect_adapter (void *cls, | 397 | core_disconnect_adapter(void *cls, |
399 | void *op_result) | 398 | void *op_result) |
400 | { | 399 | { |
401 | struct BenchmarkPeer *me = cls; | 400 | struct BenchmarkPeer *me = cls; |
402 | 401 | ||
403 | GNUNET_CORE_disconnect (me->ch); | 402 | GNUNET_CORE_disconnect(me->ch); |
404 | me->ch = NULL; | 403 | me->ch = NULL; |
405 | } | 404 | } |
406 | 405 | ||
407 | 406 | ||
408 | static void | 407 | static void |
409 | connect_completion_callback (void *cls, | 408 | connect_completion_callback(void *cls, |
410 | struct GNUNET_TESTBED_Operation *op, | 409 | struct GNUNET_TESTBED_Operation *op, |
411 | const char *emsg) | 410 | const char *emsg) |
412 | { | 411 | { |
413 | struct TestbedConnectOperation *cop = cls; | 412 | struct TestbedConnectOperation *cop = cls; |
414 | static int ops = 0; | 413 | static int ops = 0; |
415 | int c; | 414 | int c; |
415 | |||
416 | if (NULL == emsg) | 416 | if (NULL == emsg) |
417 | { | 417 | { |
418 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 418 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
419 | _("Connected master [%u] with slave [%u]\n"), | 419 | _("Connected master [%u] with slave [%u]\n"), |
420 | cop->master->no, | 420 | cop->master->no, |
421 | cop->slave->no); | 421 | cop->slave->no); |
422 | } | 422 | } |
423 | else | 423 | else |
424 | { | 424 | { |
425 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 425 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
426 | _("Failed to connect master peer [%u] with slave [%u]\n"), | 426 | _("Failed to connect master peer [%u] with slave [%u]\n"), |
427 | cop->master->no, cop->slave->no); | 427 | cop->master->no, cop->slave->no); |
428 | GNUNET_break(0); | 428 | GNUNET_break(0); |
429 | GNUNET_SCHEDULER_shutdown (); | 429 | GNUNET_SCHEDULER_shutdown(); |
430 | } | 430 | } |
431 | GNUNET_TESTBED_operation_done (op); | 431 | GNUNET_TESTBED_operation_done(op); |
432 | ops++; | 432 | ops++; |
433 | for (c = 0; c < top->num_slaves; c++) | 433 | for (c = 0; c < top->num_slaves; c++) |
434 | { | 434 | { |
435 | if (cop == &cop->master->core_connect_ops[c]) | 435 | if (cop == &cop->master->core_connect_ops[c]) |
436 | cop->master->core_connect_ops[c].connect_op = NULL; | 436 | cop->master->core_connect_ops[c].connect_op = NULL; |
437 | } | 437 | } |
438 | if (ops == top->num_masters * top->num_slaves) | 438 | if (ops == top->num_masters * top->num_slaves) |
439 | { | 439 | { |
440 | top->state.connected_PEERS = GNUNET_YES; | 440 | top->state.connected_PEERS = GNUNET_YES; |
441 | } | 441 | } |
442 | } | 442 | } |
443 | 443 | ||
444 | 444 | ||
445 | static void | 445 | static void |
446 | do_connect_peers (void *cls) | 446 | do_connect_peers(void *cls) |
447 | { | 447 | { |
448 | int c_m; | 448 | int c_m; |
449 | int c_s; | 449 | int c_s; |
@@ -453,142 +453,143 @@ do_connect_peers (void *cls) | |||
453 | (top->state.connected_COMM_service == GNUNET_NO)) | 453 | (top->state.connected_COMM_service == GNUNET_NO)) |
454 | return; | 454 | return; |
455 | 455 | ||
456 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 456 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
457 | "Connecting peers on CORE level\n"); | 457 | "Connecting peers on CORE level\n"); |
458 | for (c_m = 0; c_m < top->num_masters; c_m++) | 458 | for (c_m = 0; c_m < top->num_masters; c_m++) |
459 | { | ||
460 | p = &top->mps[c_m]; | ||
461 | p->core_connect_ops = GNUNET_malloc (top->num_slaves * | ||
462 | sizeof (struct TestbedConnectOperation)); | ||
463 | |||
464 | for (c_s = 0; c_s < top->num_slaves; c_s++) | ||
465 | { | 459 | { |
466 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 460 | p = &top->mps[c_m]; |
467 | "Connecting master [%u] with slave [%u]\n", | 461 | p->core_connect_ops = GNUNET_malloc(top->num_slaves * |
468 | p->no, | 462 | sizeof(struct TestbedConnectOperation)); |
469 | top->sps[c_s].no); | 463 | |
470 | p->core_connect_ops[c_s].master = p; | 464 | for (c_s = 0; c_s < top->num_slaves; c_s++) |
471 | p->core_connect_ops[c_s].slave = &top->sps[c_s]; | 465 | { |
472 | p->core_connect_ops[c_s].connect_op | 466 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
473 | = GNUNET_TESTBED_overlay_connect (NULL, | 467 | "Connecting master [%u] with slave [%u]\n", |
474 | &connect_completion_callback, | 468 | p->no, |
475 | &p->core_connect_ops[c_s], | 469 | top->sps[c_s].no); |
476 | top->sps[c_s].peer, | 470 | p->core_connect_ops[c_s].master = p; |
477 | p->peer); | 471 | p->core_connect_ops[c_s].slave = &top->sps[c_s]; |
478 | if (NULL == p->core_connect_ops[c_s].connect_op) | 472 | p->core_connect_ops[c_s].connect_op |
479 | { | 473 | = GNUNET_TESTBED_overlay_connect(NULL, |
480 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 474 | &connect_completion_callback, |
481 | "Could not connect master [%u] and slave [%u]\n", | 475 | &p->core_connect_ops[c_s], |
482 | p->no, | 476 | top->sps[c_s].peer, |
483 | top->sps[c_s].no); | 477 | p->peer); |
484 | GNUNET_break(0); | 478 | if (NULL == p->core_connect_ops[c_s].connect_op) |
485 | GNUNET_SCHEDULER_shutdown (); | 479 | { |
486 | return; | 480 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
487 | } | 481 | "Could not connect master [%u] and slave [%u]\n", |
482 | p->no, | ||
483 | top->sps[c_s].no); | ||
484 | GNUNET_break(0); | ||
485 | GNUNET_SCHEDULER_shutdown(); | ||
486 | return; | ||
487 | } | ||
488 | } | ||
488 | } | 489 | } |
489 | } | ||
490 | } | 490 | } |
491 | 491 | ||
492 | 492 | ||
493 | static void | 493 | static void |
494 | comm_connect_completion_cb (void *cls, | 494 | comm_connect_completion_cb(void *cls, |
495 | struct GNUNET_TESTBED_Operation *op, | 495 | struct GNUNET_TESTBED_Operation *op, |
496 | void *ca_result, | 496 | void *ca_result, |
497 | const char *emsg) | 497 | const char *emsg) |
498 | { | 498 | { |
499 | static int comm_done = 0; | 499 | static int comm_done = 0; |
500 | 500 | ||
501 | if ((NULL != emsg) || (NULL == ca_result)) | 501 | if ((NULL != emsg) || (NULL == ca_result)) |
502 | { | 502 | { |
503 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 503 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
504 | "Initialization failed, shutdown\n"); | 504 | "Initialization failed, shutdown\n"); |
505 | GNUNET_break(0); | 505 | GNUNET_break(0); |
506 | GNUNET_SCHEDULER_shutdown (); | 506 | GNUNET_SCHEDULER_shutdown(); |
507 | return; | 507 | return; |
508 | } | 508 | } |
509 | comm_done++; | 509 | comm_done++; |
510 | 510 | ||
511 | if (comm_done == top->num_slaves + top->num_masters) | 511 | if (comm_done == top->num_slaves + top->num_masters) |
512 | { | 512 | { |
513 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 513 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
514 | "Connected to all %s services\n", | 514 | "Connected to all %s services\n", |
515 | (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT"); | 515 | (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT"); |
516 | top->state.connected_COMM_service = GNUNET_YES; | 516 | top->state.connected_COMM_service = GNUNET_YES; |
517 | GNUNET_SCHEDULER_add_now (&do_connect_peers, | 517 | GNUNET_SCHEDULER_add_now(&do_connect_peers, |
518 | NULL); | 518 | NULL); |
519 | } | 519 | } |
520 | } | 520 | } |
521 | 521 | ||
522 | 522 | ||
523 | static void | 523 | static void |
524 | do_comm_connect (void *cls) | 524 | do_comm_connect(void *cls) |
525 | { | 525 | { |
526 | int c_s; | 526 | int c_s; |
527 | int c_m; | 527 | int c_m; |
528 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 528 | |
529 | "Connecting to all %s services\n", | 529 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
530 | (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT"); | 530 | "Connecting to all %s services\n", |
531 | (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT"); | ||
531 | for (c_m = 0; c_m < top->num_masters; c_m++) | 532 | for (c_m = 0; c_m < top->num_masters; c_m++) |
532 | { | ||
533 | if (GNUNET_YES == top->test_core) | ||
534 | top->mps[c_m].comm_op | ||
535 | = GNUNET_TESTBED_service_connect (NULL, | ||
536 | top->mps[c_m].peer, | ||
537 | "core", | ||
538 | &comm_connect_completion_cb, | ||
539 | NULL, | ||
540 | &core_connect_adapter, | ||
541 | &core_disconnect_adapter, | ||
542 | &top->mps[c_m]); | ||
543 | else | ||
544 | { | 533 | { |
545 | top->mps[c_m].comm_op | 534 | if (GNUNET_YES == top->test_core) |
546 | = GNUNET_TESTBED_service_connect (NULL, | 535 | top->mps[c_m].comm_op |
547 | top->mps[c_m].peer, | 536 | = GNUNET_TESTBED_service_connect(NULL, |
548 | "transport", | 537 | top->mps[c_m].peer, |
549 | &comm_connect_completion_cb, | 538 | "core", |
550 | NULL, | 539 | &comm_connect_completion_cb, |
551 | &transport_connect_adapter, | 540 | NULL, |
552 | &transport_disconnect_adapter, | 541 | &core_connect_adapter, |
553 | &top->mps[c_m]); | 542 | &core_disconnect_adapter, |
543 | &top->mps[c_m]); | ||
544 | else | ||
545 | { | ||
546 | top->mps[c_m].comm_op | ||
547 | = GNUNET_TESTBED_service_connect(NULL, | ||
548 | top->mps[c_m].peer, | ||
549 | "transport", | ||
550 | &comm_connect_completion_cb, | ||
551 | NULL, | ||
552 | &transport_connect_adapter, | ||
553 | &transport_disconnect_adapter, | ||
554 | &top->mps[c_m]); | ||
555 | } | ||
554 | } | 556 | } |
555 | } | ||
556 | 557 | ||
557 | for (c_s = 0; c_s < top->num_slaves; c_s++) | 558 | for (c_s = 0; c_s < top->num_slaves; c_s++) |
558 | { | ||
559 | if (GNUNET_YES == top->test_core) | ||
560 | top->sps[c_s].comm_op | ||
561 | = GNUNET_TESTBED_service_connect (NULL, | ||
562 | top->sps[c_s].peer, | ||
563 | "core", | ||
564 | &comm_connect_completion_cb, | ||
565 | NULL, | ||
566 | &core_connect_adapter, | ||
567 | &core_disconnect_adapter, | ||
568 | &top->sps[c_s]); | ||
569 | else | ||
570 | { | 559 | { |
571 | top->sps[c_s].comm_op | 560 | if (GNUNET_YES == top->test_core) |
572 | = GNUNET_TESTBED_service_connect (NULL, | 561 | top->sps[c_s].comm_op |
573 | top->sps[c_s].peer, | 562 | = GNUNET_TESTBED_service_connect(NULL, |
574 | "transport", | 563 | top->sps[c_s].peer, |
575 | &comm_connect_completion_cb, | 564 | "core", |
576 | NULL, | 565 | &comm_connect_completion_cb, |
577 | &transport_connect_adapter, | 566 | NULL, |
578 | &transport_disconnect_adapter, | 567 | &core_connect_adapter, |
579 | &top->sps[c_s]); | 568 | &core_disconnect_adapter, |
569 | &top->sps[c_s]); | ||
570 | else | ||
571 | { | ||
572 | top->sps[c_s].comm_op | ||
573 | = GNUNET_TESTBED_service_connect(NULL, | ||
574 | top->sps[c_s].peer, | ||
575 | "transport", | ||
576 | &comm_connect_completion_cb, | ||
577 | NULL, | ||
578 | &transport_connect_adapter, | ||
579 | &transport_disconnect_adapter, | ||
580 | &top->sps[c_s]); | ||
581 | } | ||
580 | } | 582 | } |
581 | } | ||
582 | } | 583 | } |
583 | 584 | ||
584 | 585 | ||
585 | static void | 586 | static void |
586 | ats_performance_info_cb (void *cls, | 587 | ats_performance_info_cb(void *cls, |
587 | const struct GNUNET_HELLO_Address *address, | 588 | const struct GNUNET_HELLO_Address *address, |
588 | int address_active, | 589 | int address_active, |
589 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 590 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
590 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 591 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
591 | const struct GNUNET_ATS_Properties *ats_prop) | 592 | const struct GNUNET_ATS_Properties *ats_prop) |
592 | { | 593 | { |
593 | struct BenchmarkPeer *me = cls; | 594 | struct BenchmarkPeer *me = cls; |
594 | struct BenchmarkPartner *p; | 595 | struct BenchmarkPartner *p; |
@@ -596,36 +597,36 @@ ats_performance_info_cb (void *cls, | |||
596 | char *peer_id; | 597 | char *peer_id; |
597 | 598 | ||
598 | if (NULL == address) | 599 | if (NULL == address) |
599 | { | 600 | { |
600 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 601 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
601 | "Peer %u: ATS Service disconnected!\n", | 602 | "Peer %u: ATS Service disconnected!\n", |
602 | me->no); | 603 | me->no); |
603 | return; | 604 | return; |
604 | } | 605 | } |
605 | 606 | ||
606 | p = find_partner (me, | 607 | p = find_partner(me, |
607 | &address->peer); | 608 | &address->peer); |
608 | if (NULL == p) | 609 | if (NULL == p) |
609 | { | 610 | { |
610 | /* This is not one of my partners | 611 | /* This is not one of my partners |
611 | * Will happen since the peers will connect to each other due to gossiping | 612 | * Will happen since the peers will connect to each other due to gossiping |
612 | */ | 613 | */ |
613 | return; | 614 | return; |
614 | } | 615 | } |
615 | peer_id = GNUNET_strdup (GNUNET_i2s (&me->id)); | 616 | peer_id = GNUNET_strdup(GNUNET_i2s(&me->id)); |
616 | 617 | ||
617 | log = GNUNET_NO; | 618 | log = GNUNET_NO; |
618 | if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) || | 619 | if ((p->bandwidth_in != ntohl(bandwidth_in.value__)) || |
619 | (p->bandwidth_out != ntohl (bandwidth_out.value__))) | 620 | (p->bandwidth_out != ntohl(bandwidth_out.value__))) |
620 | log = GNUNET_YES; | 621 | log = GNUNET_YES; |
621 | p->bandwidth_in = ntohl (bandwidth_in.value__); | 622 | p->bandwidth_in = ntohl(bandwidth_in.value__); |
622 | p->bandwidth_out = ntohl (bandwidth_out.value__); | 623 | p->bandwidth_out = ntohl(bandwidth_out.value__); |
623 | 624 | ||
624 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 625 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
625 | "%s [%u] received ATS information: %s\n", | 626 | "%s [%u] received ATS information: %s\n", |
626 | (GNUNET_YES == p->me->master) ? "Master" : "Slave", | 627 | (GNUNET_YES == p->me->master) ? "Master" : "Slave", |
627 | p->me->no, | 628 | p->me->no, |
628 | GNUNET_i2s (&p->dest->id)); | 629 | GNUNET_i2s(&p->dest->id)); |
629 | 630 | ||
630 | p->props.utilization_out = ats_prop->utilization_out; | 631 | p->props.utilization_out = ats_prop->utilization_out; |
631 | p->props.utilization_in = ats_prop->utilization_in; | 632 | p->props.utilization_in = ats_prop->utilization_in; |
@@ -634,113 +635,113 @@ ats_performance_info_cb (void *cls, | |||
634 | p->props.distance = ats_prop->distance; | 635 | p->props.distance = ats_prop->distance; |
635 | 636 | ||
636 | if (GNUNET_YES == log) | 637 | if (GNUNET_YES == log) |
637 | top->ats_perf_cb (cls, address, | 638 | top->ats_perf_cb(cls, address, |
638 | address_active, | 639 | address_active, |
639 | bandwidth_out, | 640 | bandwidth_out, |
640 | bandwidth_in, | 641 | bandwidth_in, |
641 | ats_prop); | 642 | ats_prop); |
642 | GNUNET_free(peer_id); | 643 | GNUNET_free(peer_id); |
643 | } | 644 | } |
644 | 645 | ||
645 | 646 | ||
646 | static void * | 647 | static void * |
647 | ats_perf_connect_adapter (void *cls, | 648 | ats_perf_connect_adapter(void *cls, |
648 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 649 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
649 | { | 650 | { |
650 | struct BenchmarkPeer *me = cls; | 651 | struct BenchmarkPeer *me = cls; |
651 | 652 | ||
652 | me->ats_perf_handle | 653 | me->ats_perf_handle |
653 | = GNUNET_ATS_performance_init (cfg, | 654 | = GNUNET_ATS_performance_init(cfg, |
654 | &ats_performance_info_cb, | 655 | &ats_performance_info_cb, |
655 | me); | 656 | me); |
656 | if (NULL == me->ats_perf_handle) | 657 | if (NULL == me->ats_perf_handle) |
657 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 658 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
658 | "Failed to create ATS performance handle \n"); | 659 | "Failed to create ATS performance handle \n"); |
659 | return me->ats_perf_handle; | 660 | return me->ats_perf_handle; |
660 | } | 661 | } |
661 | 662 | ||
662 | 663 | ||
663 | static void | 664 | static void |
664 | ats_perf_disconnect_adapter (void *cls, | 665 | ats_perf_disconnect_adapter(void *cls, |
665 | void *op_result) | 666 | void *op_result) |
666 | { | 667 | { |
667 | struct BenchmarkPeer *me = cls; | 668 | struct BenchmarkPeer *me = cls; |
668 | 669 | ||
669 | GNUNET_ATS_performance_done (me->ats_perf_handle); | 670 | GNUNET_ATS_performance_done(me->ats_perf_handle); |
670 | me->ats_perf_handle = NULL; | 671 | me->ats_perf_handle = NULL; |
671 | } | 672 | } |
672 | 673 | ||
673 | 674 | ||
674 | static void | 675 | static void |
675 | ats_connect_completion_cb (void *cls, | 676 | ats_connect_completion_cb(void *cls, |
676 | struct GNUNET_TESTBED_Operation *op, | 677 | struct GNUNET_TESTBED_Operation *op, |
677 | void *ca_result, | 678 | void *ca_result, |
678 | const char *emsg) | 679 | const char *emsg) |
679 | { | 680 | { |
680 | static int op_done = 0; | 681 | static int op_done = 0; |
681 | 682 | ||
682 | if ((NULL != emsg) || (NULL == ca_result)) | 683 | if ((NULL != emsg) || (NULL == ca_result)) |
683 | { | 684 | { |
684 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 685 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
685 | "Initialization failed, shutdown\n"); | 686 | "Initialization failed, shutdown\n"); |
686 | GNUNET_break(0); | 687 | GNUNET_break(0); |
687 | GNUNET_SCHEDULER_shutdown (); | 688 | GNUNET_SCHEDULER_shutdown(); |
688 | return; | 689 | return; |
689 | } | 690 | } |
690 | op_done++; | 691 | op_done++; |
691 | if (op_done == (top->num_masters + top->num_slaves)) | 692 | if (op_done == (top->num_masters + top->num_slaves)) |
692 | { | 693 | { |
693 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 694 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
694 | "Connected to all ATS services\n"); | 695 | "Connected to all ATS services\n"); |
695 | top->state.connected_ATS_service = GNUNET_YES; | 696 | top->state.connected_ATS_service = GNUNET_YES; |
696 | GNUNET_SCHEDULER_add_now (&do_comm_connect, | 697 | GNUNET_SCHEDULER_add_now(&do_comm_connect, |
697 | NULL); | 698 | NULL); |
698 | } | 699 | } |
699 | } | 700 | } |
700 | 701 | ||
701 | 702 | ||
702 | static void | 703 | static void |
703 | do_connect_ats (void *cls) | 704 | do_connect_ats(void *cls) |
704 | { | 705 | { |
705 | int c_m; | 706 | int c_m; |
706 | int c_s; | 707 | int c_s; |
707 | 708 | ||
708 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 709 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
709 | "Connecting to all ATS services\n"); | 710 | "Connecting to all ATS services\n"); |
710 | for (c_m = 0; c_m < top->num_masters; c_m++) | 711 | for (c_m = 0; c_m < top->num_masters; c_m++) |
711 | { | 712 | { |
712 | top->mps[c_m].ats_perf_op | 713 | top->mps[c_m].ats_perf_op |
713 | = GNUNET_TESTBED_service_connect (NULL, | 714 | = GNUNET_TESTBED_service_connect(NULL, |
714 | top->mps[c_m].peer, | 715 | top->mps[c_m].peer, |
715 | "ats", | 716 | "ats", |
716 | &ats_connect_completion_cb, | 717 | &ats_connect_completion_cb, |
717 | NULL, | 718 | NULL, |
718 | &ats_perf_connect_adapter, | 719 | &ats_perf_connect_adapter, |
719 | &ats_perf_disconnect_adapter, | 720 | &ats_perf_disconnect_adapter, |
720 | &top->mps[c_m]); | 721 | &top->mps[c_m]); |
721 | } | 722 | } |
722 | 723 | ||
723 | for (c_s = 0; c_s < top->num_slaves; c_s++) | 724 | for (c_s = 0; c_s < top->num_slaves; c_s++) |
724 | { | 725 | { |
725 | top->sps[c_s].ats_perf_op | 726 | top->sps[c_s].ats_perf_op |
726 | = GNUNET_TESTBED_service_connect (NULL, | 727 | = GNUNET_TESTBED_service_connect(NULL, |
727 | top->sps[c_s].peer, | 728 | top->sps[c_s].peer, |
728 | "ats", | 729 | "ats", |
729 | &ats_connect_completion_cb, | 730 | &ats_connect_completion_cb, |
730 | NULL, | 731 | NULL, |
731 | &ats_perf_connect_adapter, | 732 | &ats_perf_connect_adapter, |
732 | &ats_perf_disconnect_adapter, | 733 | &ats_perf_disconnect_adapter, |
733 | &top->sps[c_s]); | 734 | &top->sps[c_s]); |
734 | } | 735 | } |
735 | } | 736 | } |
736 | 737 | ||
737 | 738 | ||
738 | 739 | ||
739 | static void | 740 | static void |
740 | peerinformation_cb (void *cb_cls, | 741 | peerinformation_cb(void *cb_cls, |
741 | struct GNUNET_TESTBED_Operation *op, | 742 | struct GNUNET_TESTBED_Operation *op, |
742 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | 743 | const struct GNUNET_TESTBED_PeerInformation *pinfo, |
743 | const char *emsg) | 744 | const char *emsg) |
744 | { | 745 | { |
745 | struct BenchmarkPeer *p = cb_cls; | 746 | struct BenchmarkPeer *p = cb_cls; |
746 | static int done = 0; | 747 | static int done = 0; |
@@ -748,23 +749,23 @@ peerinformation_cb (void *cb_cls, | |||
748 | GNUNET_assert(pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY); | 749 | GNUNET_assert(pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY); |
749 | 750 | ||
750 | p->id = *pinfo->result.id; | 751 | p->id = *pinfo->result.id; |
751 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 752 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
752 | "%s [%u] has peer id `%s'\n", | 753 | "%s [%u] has peer id `%s'\n", |
753 | (p->master == GNUNET_YES) ? "Master" : "Slave", | 754 | (p->master == GNUNET_YES) ? "Master" : "Slave", |
754 | p->no, | 755 | p->no, |
755 | GNUNET_i2s (&p->id)); | 756 | GNUNET_i2s(&p->id)); |
756 | 757 | ||
757 | GNUNET_TESTBED_operation_done (op); | 758 | GNUNET_TESTBED_operation_done(op); |
758 | p->peer_id_op = NULL; | 759 | p->peer_id_op = NULL; |
759 | done++; | 760 | done++; |
760 | 761 | ||
761 | if (done == top->num_slaves + top->num_masters) | 762 | if (done == top->num_slaves + top->num_masters) |
762 | { | 763 | { |
763 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 764 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
764 | "Retrieved all peer ID, connect to ATS\n"); | 765 | "Retrieved all peer ID, connect to ATS\n"); |
765 | GNUNET_SCHEDULER_add_now (&do_connect_ats, | 766 | GNUNET_SCHEDULER_add_now(&do_connect_ats, |
766 | NULL); | 767 | NULL); |
767 | } | 768 | } |
768 | } | 769 | } |
769 | 770 | ||
770 | 771 | ||
@@ -781,85 +782,85 @@ peerinformation_cb (void *cb_cls, | |||
781 | * failed | 782 | * failed |
782 | */ | 783 | */ |
783 | static void | 784 | static void |
784 | main_run (void *cls, | 785 | main_run(void *cls, |
785 | struct GNUNET_TESTBED_RunHandle *h, | 786 | struct GNUNET_TESTBED_RunHandle *h, |
786 | unsigned int num_peers, | 787 | unsigned int num_peers, |
787 | struct GNUNET_TESTBED_Peer **peers_, | 788 | struct GNUNET_TESTBED_Peer **peers_, |
788 | unsigned int links_succeeded, | 789 | unsigned int links_succeeded, |
789 | unsigned int links_failed) | 790 | unsigned int links_failed) |
790 | { | 791 | { |
791 | int c_m; | 792 | int c_m; |
792 | int c_s; | 793 | int c_s; |
793 | 794 | ||
794 | GNUNET_assert (NULL == cls); | 795 | GNUNET_assert(NULL == cls); |
795 | GNUNET_assert (top->num_masters + top->num_slaves == num_peers); | 796 | GNUNET_assert(top->num_masters + top->num_slaves == num_peers); |
796 | GNUNET_assert (NULL != peers_); | 797 | GNUNET_assert(NULL != peers_); |
797 | 798 | ||
798 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 799 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
799 | top); | 800 | top); |
800 | 801 | ||
801 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 802 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
802 | "Setting up %u masters and %u slaves\n", | 803 | "Setting up %u masters and %u slaves\n", |
803 | top->num_masters, | 804 | top->num_masters, |
804 | top->num_slaves); | 805 | top->num_slaves); |
805 | 806 | ||
806 | /* Setup master peers */ | 807 | /* Setup master peers */ |
807 | for (c_m = 0; c_m < top->num_masters; c_m++) | 808 | for (c_m = 0; c_m < top->num_masters; c_m++) |
808 | { | ||
809 | GNUNET_assert(NULL != peers_[c_m]); | ||
810 | top->mps[c_m].peer = peers_[c_m]; | ||
811 | top->mps[c_m].no = c_m; | ||
812 | top->mps[c_m].master = GNUNET_YES; | ||
813 | top->mps[c_m].pref_partner = &top->sps[c_m]; | ||
814 | top->mps[c_m].pref_value = TEST_ATS_PREFERENCE_DEFAULT; | ||
815 | top->mps[c_m].partners = | ||
816 | GNUNET_malloc (top->num_slaves * sizeof (struct BenchmarkPartner)); | ||
817 | top->mps[c_m].num_partners = top->num_slaves; | ||
818 | /* Initialize partners */ | ||
819 | for (c_s = 0; c_s < top->num_slaves; c_s++) | ||
820 | { | 809 | { |
821 | top->mps[c_m].partners[c_s].me = &top->mps[c_m]; | 810 | GNUNET_assert(NULL != peers_[c_m]); |
822 | top->mps[c_m].partners[c_s].dest = &top->sps[c_s]; | 811 | top->mps[c_m].peer = peers_[c_m]; |
812 | top->mps[c_m].no = c_m; | ||
813 | top->mps[c_m].master = GNUNET_YES; | ||
814 | top->mps[c_m].pref_partner = &top->sps[c_m]; | ||
815 | top->mps[c_m].pref_value = TEST_ATS_PREFERENCE_DEFAULT; | ||
816 | top->mps[c_m].partners = | ||
817 | GNUNET_malloc(top->num_slaves * sizeof(struct BenchmarkPartner)); | ||
818 | top->mps[c_m].num_partners = top->num_slaves; | ||
819 | /* Initialize partners */ | ||
820 | for (c_s = 0; c_s < top->num_slaves; c_s++) | ||
821 | { | ||
822 | top->mps[c_m].partners[c_s].me = &top->mps[c_m]; | ||
823 | top->mps[c_m].partners[c_s].dest = &top->sps[c_s]; | ||
824 | } | ||
825 | /* Get configuration */ | ||
826 | top->mps[c_m].peer_id_op | ||
827 | = GNUNET_TESTBED_peer_get_information(top->mps[c_m].peer, | ||
828 | GNUNET_TESTBED_PIT_IDENTITY, | ||
829 | &peerinformation_cb, | ||
830 | &top->mps[c_m]); | ||
823 | } | 831 | } |
824 | /* Get configuration */ | ||
825 | top->mps[c_m].peer_id_op | ||
826 | = GNUNET_TESTBED_peer_get_information (top->mps[c_m].peer, | ||
827 | GNUNET_TESTBED_PIT_IDENTITY, | ||
828 | &peerinformation_cb, | ||
829 | &top->mps[c_m]); | ||
830 | } | ||
831 | 832 | ||
832 | /* Setup slave peers */ | 833 | /* Setup slave peers */ |
833 | for (c_s = 0; c_s < top->num_slaves; c_s++) | 834 | for (c_s = 0; c_s < top->num_slaves; c_s++) |
834 | { | ||
835 | GNUNET_assert(NULL != peers_[c_s + top->num_masters]); | ||
836 | top->sps[c_s].peer = peers_[c_s + top->num_masters]; | ||
837 | top->sps[c_s].no = c_s + top->num_masters; | ||
838 | top->sps[c_s].master = GNUNET_NO; | ||
839 | top->sps[c_s].partners = | ||
840 | GNUNET_new_array (top->num_masters, | ||
841 | struct BenchmarkPartner); | ||
842 | top->sps[c_s].num_partners = top->num_masters; | ||
843 | /* Initialize partners */ | ||
844 | for (c_m = 0; c_m < top->num_masters; c_m++) | ||
845 | { | 835 | { |
846 | top->sps[c_s].partners[c_m].me = &top->sps[c_s]; | 836 | GNUNET_assert(NULL != peers_[c_s + top->num_masters]); |
847 | top->sps[c_s].partners[c_m].dest = &top->mps[c_m]; | 837 | top->sps[c_s].peer = peers_[c_s + top->num_masters]; |
848 | 838 | top->sps[c_s].no = c_s + top->num_masters; | |
849 | /* Initialize properties */ | 839 | top->sps[c_s].master = GNUNET_NO; |
850 | top->sps[c_s].partners[c_m].props.delay = GNUNET_TIME_UNIT_ZERO; | 840 | top->sps[c_s].partners = |
851 | top->sps[c_s].partners[c_m].props.distance = 0; | 841 | GNUNET_new_array(top->num_masters, |
852 | top->sps[c_s].partners[c_m].props.scope = GNUNET_NT_UNSPECIFIED; | 842 | struct BenchmarkPartner); |
853 | top->sps[c_s].partners[c_m].props.utilization_in = 0; | 843 | top->sps[c_s].num_partners = top->num_masters; |
854 | top->sps[c_s].partners[c_m].props.utilization_out = 0; | 844 | /* Initialize partners */ |
845 | for (c_m = 0; c_m < top->num_masters; c_m++) | ||
846 | { | ||
847 | top->sps[c_s].partners[c_m].me = &top->sps[c_s]; | ||
848 | top->sps[c_s].partners[c_m].dest = &top->mps[c_m]; | ||
849 | |||
850 | /* Initialize properties */ | ||
851 | top->sps[c_s].partners[c_m].props.delay = GNUNET_TIME_UNIT_ZERO; | ||
852 | top->sps[c_s].partners[c_m].props.distance = 0; | ||
853 | top->sps[c_s].partners[c_m].props.scope = GNUNET_NT_UNSPECIFIED; | ||
854 | top->sps[c_s].partners[c_m].props.utilization_in = 0; | ||
855 | top->sps[c_s].partners[c_m].props.utilization_out = 0; | ||
856 | } | ||
857 | /* Get configuration */ | ||
858 | top->sps[c_s].peer_id_op | ||
859 | = GNUNET_TESTBED_peer_get_information(top->sps[c_s].peer, | ||
860 | GNUNET_TESTBED_PIT_IDENTITY, | ||
861 | &peerinformation_cb, | ||
862 | &top->sps[c_s]); | ||
855 | } | 863 | } |
856 | /* Get configuration */ | ||
857 | top->sps[c_s].peer_id_op | ||
858 | = GNUNET_TESTBED_peer_get_information (top->sps[c_s].peer, | ||
859 | GNUNET_TESTBED_PIT_IDENTITY, | ||
860 | &peerinformation_cb, | ||
861 | &top->sps[c_s]); | ||
862 | } | ||
863 | } | 864 | } |
864 | 865 | ||
865 | 866 | ||
@@ -870,24 +871,26 @@ main_run (void *cls, | |||
870 | * @param event the controller event | 871 | * @param event the controller event |
871 | */ | 872 | */ |
872 | static void | 873 | static void |
873 | controller_event_cb (void *cls, | 874 | controller_event_cb(void *cls, |
874 | const struct GNUNET_TESTBED_EventInformation *event) | 875 | const struct GNUNET_TESTBED_EventInformation *event) |
875 | { | 876 | { |
876 | switch (event->type) | 877 | switch (event->type) |
877 | { | 878 | { |
878 | case GNUNET_TESTBED_ET_CONNECT: | 879 | case GNUNET_TESTBED_ET_CONNECT: |
879 | break; | 880 | break; |
880 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | 881 | |
881 | break; | 882 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: |
882 | default: | 883 | break; |
883 | GNUNET_break(0); | 884 | |
884 | GNUNET_SCHEDULER_shutdown (); | 885 | default: |
885 | } | 886 | GNUNET_break(0); |
887 | GNUNET_SCHEDULER_shutdown(); | ||
888 | } | ||
886 | } | 889 | } |
887 | 890 | ||
888 | 891 | ||
889 | struct BenchmarkPeer * | 892 | struct BenchmarkPeer * |
890 | GNUNET_ATS_TEST_get_peer (int src) | 893 | GNUNET_ATS_TEST_get_peer(int src) |
891 | { | 894 | { |
892 | if (src > top->num_masters) | 895 | if (src > top->num_masters) |
893 | return NULL; | 896 | return NULL; |
@@ -896,8 +899,8 @@ GNUNET_ATS_TEST_get_peer (int src) | |||
896 | 899 | ||
897 | 900 | ||
898 | struct BenchmarkPartner * | 901 | struct BenchmarkPartner * |
899 | GNUNET_ATS_TEST_get_partner (int src, | 902 | GNUNET_ATS_TEST_get_partner(int src, |
900 | int dest) | 903 | int dest) |
901 | { | 904 | { |
902 | if (src > top->num_masters) | 905 | if (src > top->num_masters) |
903 | return NULL; | 906 | return NULL; |
@@ -920,37 +923,37 @@ GNUNET_ATS_TEST_get_partner (int src, | |||
920 | * @param log_request_cb callback to call when logging is required | 923 | * @param log_request_cb callback to call when logging is required |
921 | */ | 924 | */ |
922 | void | 925 | void |
923 | GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file, | 926 | GNUNET_ATS_TEST_create_topology(char *name, char *cfg_file, |
924 | unsigned int num_slaves, | 927 | unsigned int num_slaves, |
925 | unsigned int num_masters, | 928 | unsigned int num_masters, |
926 | int test_core, | 929 | int test_core, |
927 | GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb, | 930 | GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb, |
928 | void *done_cb_cls, | 931 | void *done_cb_cls, |
929 | GNUNET_ATS_AddressInformationCallback log_request_cb) | 932 | GNUNET_ATS_AddressInformationCallback log_request_cb) |
930 | { | 933 | { |
931 | top = GNUNET_new (struct GNUNET_ATS_TEST_Topology); | 934 | top = GNUNET_new(struct GNUNET_ATS_TEST_Topology); |
932 | top->num_masters = num_masters; | 935 | top->num_masters = num_masters; |
933 | top->num_slaves = num_slaves; | 936 | top->num_slaves = num_slaves; |
934 | top->done_cb = done_cb; | 937 | top->done_cb = done_cb; |
935 | top->done_cb_cls = done_cb_cls; | 938 | top->done_cb_cls = done_cb_cls; |
936 | top->test_core = test_core; | 939 | top->test_core = test_core; |
937 | top->ats_perf_cb = log_request_cb; | 940 | top->ats_perf_cb = log_request_cb; |
938 | top->mps = GNUNET_new_array (num_masters, | 941 | top->mps = GNUNET_new_array(num_masters, |
939 | struct BenchmarkPeer); | 942 | struct BenchmarkPeer); |
940 | top->sps = GNUNET_new_array (num_slaves, | 943 | top->sps = GNUNET_new_array(num_slaves, |
941 | struct BenchmarkPeer); | 944 | struct BenchmarkPeer); |
942 | 945 | ||
943 | /* Start topology */ | 946 | /* Start topology */ |
944 | uint64_t event_mask; | 947 | uint64_t event_mask; |
945 | event_mask = 0; | 948 | event_mask = 0; |
946 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | 949 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); |
947 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 950 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
948 | (void) GNUNET_TESTBED_test_run (name, | 951 | (void)GNUNET_TESTBED_test_run(name, |
949 | cfg_file, | 952 | cfg_file, |
950 | num_slaves + num_masters, | 953 | num_slaves + num_masters, |
951 | event_mask, | 954 | event_mask, |
952 | &controller_event_cb, NULL, | 955 | &controller_event_cb, NULL, |
953 | &main_run, NULL); | 956 | &main_run, NULL); |
954 | } | 957 | } |
955 | 958 | ||
956 | 959 | ||
@@ -958,7 +961,7 @@ GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file, | |||
958 | * Shutdown topology | 961 | * Shutdown topology |
959 | */ | 962 | */ |
960 | void | 963 | void |
961 | GNUNET_ATS_TEST_shutdown_topology (void) | 964 | GNUNET_ATS_TEST_shutdown_topology(void) |
962 | { | 965 | { |
963 | if (NULL == top) | 966 | if (NULL == top) |
964 | return; | 967 | return; |