diff options
Diffstat (limited to 'src/transport/test_transport_plugin_cmd_simple_send_performance.c')
-rw-r--r-- | src/transport/test_transport_plugin_cmd_simple_send_performance.c | 508 |
1 files changed, 508 insertions, 0 deletions
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_performance.c b/src/transport/test_transport_plugin_cmd_simple_send_performance.c new file mode 100644 index 000000000..17325e369 --- /dev/null +++ b/src/transport/test_transport_plugin_cmd_simple_send_performance.c | |||
@@ -0,0 +1,508 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
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 | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed/plugin_cmd_simple_send.c | ||
23 | * @brief a plugin to provide the API for running test cases. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_testing_barrier.h" | ||
28 | #include "gnunet_testing_netjail_lib.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_transport_application_service.h" | ||
31 | #include "transport-testing2.h" | ||
32 | #include "transport-testing-cmds.h" | ||
33 | #include "gnunet_testing_barrier.h" | ||
34 | |||
35 | /** | ||
36 | * Generic logging shortcut | ||
37 | */ | ||
38 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
39 | |||
40 | #define BASE_DIR "testdir" | ||
41 | |||
42 | #define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf" | ||
43 | |||
44 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600) | ||
45 | |||
46 | #define MAX_RECEIVED 1000 | ||
47 | |||
48 | #define MESSAGE_SIZE 65000 | ||
49 | |||
50 | static struct GNUNET_TESTING_Command block_send; | ||
51 | |||
52 | static struct GNUNET_TESTING_Command block_receive; | ||
53 | |||
54 | static struct GNUNET_TESTING_Command connect_peers; | ||
55 | |||
56 | static struct GNUNET_TESTING_Command local_prepared; | ||
57 | |||
58 | static struct GNUNET_TESTING_Command start_peer; | ||
59 | |||
60 | static struct GNUNET_TESTING_Interpreter *is; | ||
61 | |||
62 | static struct GNUNET_CONTAINER_MultiPeerMap *senders; | ||
63 | |||
64 | struct Sender | ||
65 | { | ||
66 | /** | ||
67 | * Number of received messages from sender. | ||
68 | */ | ||
69 | unsigned long long num_received; | ||
70 | |||
71 | /** | ||
72 | * Sample mean time the message traveled. | ||
73 | */ | ||
74 | struct GNUNET_TIME_Relative mean_time; | ||
75 | |||
76 | /** | ||
77 | * Time the first message was send. | ||
78 | */ | ||
79 | struct GNUNET_TIME_Absolute time_first; | ||
80 | }; | ||
81 | |||
82 | /** | ||
83 | * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being | ||
84 | * received. | ||
85 | * | ||
86 | */ | ||
87 | static int | ||
88 | check_test (void *cls, | ||
89 | const struct GNUNET_TRANSPORT_TESTING_PerformanceTestMessage *message) | ||
90 | { | ||
91 | return GNUNET_OK; | ||
92 | } | ||
93 | |||
94 | |||
95 | /** | ||
96 | * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE | ||
97 | * being received. | ||
98 | * | ||
99 | */ | ||
100 | static void | ||
101 | handle_test (void *cls, | ||
102 | const struct GNUNET_TRANSPORT_TESTING_PerformanceTestMessage *message) | ||
103 | { | ||
104 | struct GNUNET_PeerIdentity *peer = cls; | ||
105 | const struct GNUNET_TESTING_AsyncContext *ac; | ||
106 | struct Sender *sender; | ||
107 | struct GNUNET_TIME_Absolute time_send; | ||
108 | struct GNUNET_TIME_Absolute now; | ||
109 | struct GNUNET_TIME_Relative time_traveled; | ||
110 | uint32_t num; | ||
111 | struct GNUNET_TRANSPORT_CoreHandle *ch; | ||
112 | const struct StartPeerState *sps; | ||
113 | |||
114 | |||
115 | GNUNET_TRANSPORT_get_trait_state (&start_peer, | ||
116 | &sps); | ||
117 | ch = sps->th; | ||
118 | num = ntohl (message->num); | ||
119 | GNUNET_TESTING_get_trait_async_context (&block_receive, | ||
120 | &ac); | ||
121 | GNUNET_assert (NULL != ac); | ||
122 | |||
123 | sender = GNUNET_CONTAINER_multipeermap_get (senders, peer); | ||
124 | |||
125 | now = GNUNET_TIME_absolute_get (); | ||
126 | time_send = GNUNET_TIME_absolute_ntoh (message->time_send); | ||
127 | |||
128 | time_traveled = GNUNET_TIME_absolute_get_difference (time_send, now); | ||
129 | |||
130 | if (NULL == sender) | ||
131 | { | ||
132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
133 | "time traveled init %s\n", | ||
134 | GNUNET_i2s(peer)); | ||
135 | sender = GNUNET_new (struct Sender); | ||
136 | sender->time_first = time_send; | ||
137 | sender->mean_time = GNUNET_TIME_UNIT_ZERO; | ||
138 | GNUNET_CONTAINER_multipeermap_put (senders, peer, sender, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
139 | } | ||
140 | |||
141 | if (GNUNET_TIME_UNIT_ZERO.rel_value_us == sender->mean_time.rel_value_us) | ||
142 | { | ||
143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
144 | "time traveld mean zero\n"); | ||
145 | sender->mean_time = time_traveled; | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | double factor = sender->num_received/(sender->num_received + 1); | ||
150 | struct GNUNET_TIME_Relative s1; | ||
151 | struct GNUNET_TIME_Relative s2; | ||
152 | |||
153 | s1 = GNUNET_TIME_relative_multiply (sender->mean_time, | ||
154 | factor); | ||
155 | s2 = GNUNET_TIME_relative_divide (time_traveled, | ||
156 | sender->num_received + 1); | ||
157 | sender->mean_time = GNUNET_TIME_relative_add (s1, s2); | ||
158 | } | ||
159 | |||
160 | sender->num_received++; | ||
161 | |||
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
163 | "time traveled: %llu\n", | ||
164 | time_traveled.rel_value_us); | ||
165 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
166 | "mean time traveled: %s %llu messages received with message number %u\n", | ||
167 | GNUNET_STRINGS_relative_time_to_string (sender->mean_time, GNUNET_NO), | ||
168 | sender->num_received, | ||
169 | num); | ||
170 | if (MAX_RECEIVED <= sender->num_received && NULL == ac->cont) | ||
171 | { | ||
172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
173 | "time traveled failed\n"); | ||
174 | GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac); | ||
175 | } | ||
176 | else if (MAX_RECEIVED <= sender->num_received) | ||
177 | { | ||
178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
179 | "time traveled finish\n"); | ||
180 | GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac); | ||
181 | } | ||
182 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
183 | "time traveled end\n"); | ||
184 | GNUNET_TRANSPORT_core_receive_continue (ch, peer); | ||
185 | } | ||
186 | |||
187 | |||
188 | struct GNUNET_TESTING_BarrierList* | ||
189 | get_waiting_for_barriers () | ||
190 | { | ||
191 | struct GNUNET_TESTING_BarrierList* barriers; | ||
192 | struct GNUNET_TESTING_BarrierListEntry *ble; | ||
193 | |||
194 | barriers = GNUNET_new (struct GNUNET_TESTING_BarrierList); | ||
195 | ble = GNUNET_new (struct GNUNET_TESTING_BarrierListEntry); | ||
196 | ble->barrier_name = "ready-to-connect"; | ||
197 | ble->expected_reaches = 1; | ||
198 | GNUNET_CONTAINER_DLL_insert (barriers->head, | ||
199 | barriers->tail, | ||
200 | ble); | ||
201 | |||
202 | ble = GNUNET_new (struct GNUNET_TESTING_BarrierListEntry); | ||
203 | ble->barrier_name = "test-case-finished"; | ||
204 | ble->expected_reaches = 1; | ||
205 | GNUNET_CONTAINER_DLL_insert (barriers->head, | ||
206 | barriers->tail, | ||
207 | ble); | ||
208 | return barriers; | ||
209 | } | ||
210 | |||
211 | |||
212 | /** | ||
213 | * Callback to set the flag indicating all peers started. Will be called via the plugin api. | ||
214 | * | ||
215 | */ | ||
216 | static void | ||
217 | all_peers_started () | ||
218 | { | ||
219 | const struct GNUNET_TESTING_AsyncContext *ac; | ||
220 | |||
221 | GNUNET_TESTING_get_trait_async_context (&block_send, | ||
222 | &ac); | ||
223 | GNUNET_assert (NULL != ac); | ||
224 | if (NULL == ac->cont) | ||
225 | GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac); | ||
226 | else | ||
227 | GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac); | ||
228 | } | ||
229 | |||
230 | |||
231 | /** | ||
232 | * Function called with the final result of the test. | ||
233 | * | ||
234 | * @param cls the `struct MainParams` | ||
235 | * @param rv #GNUNET_OK if the test passed | ||
236 | */ | ||
237 | static void | ||
238 | handle_result (void *cls, | ||
239 | enum GNUNET_GenericReturnValue rv) | ||
240 | { | ||
241 | struct TestState *ts = cls; | ||
242 | |||
243 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
244 | "Local test exits with status %d\n", | ||
245 | rv); | ||
246 | |||
247 | ts->finished_cb (rv); | ||
248 | GNUNET_free (ts->testdir); | ||
249 | GNUNET_free (ts->cfgname); | ||
250 | GNUNET_TESTING_free_topology (ts->topology); | ||
251 | GNUNET_free (ts); | ||
252 | } | ||
253 | |||
254 | |||
255 | /** | ||
256 | * Callback from start peer cmd for signaling a peer got connected. | ||
257 | * | ||
258 | */ | ||
259 | static void * | ||
260 | notify_connect (struct GNUNET_TESTING_Interpreter *is, | ||
261 | const struct GNUNET_PeerIdentity *peer) | ||
262 | { | ||
263 | const struct ConnectPeersState *cps; | ||
264 | const struct GNUNET_TESTING_Command *cmd; | ||
265 | |||
266 | cmd = GNUNET_TESTING_interpreter_lookup_command (is, | ||
267 | "connect-peers"); | ||
268 | GNUNET_TRANSPORT_get_trait_connect_peer_state (cmd, | ||
269 | &cps); | ||
270 | void *ret = NULL; | ||
271 | |||
272 | cps->notify_connect (is, | ||
273 | peer); | ||
274 | return ret; | ||
275 | } | ||
276 | |||
277 | |||
278 | /** | ||
279 | * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api. | ||
280 | */ | ||
281 | static void | ||
282 | all_local_tests_prepared () | ||
283 | { | ||
284 | const struct GNUNET_TESTING_LocalPreparedState *lfs; | ||
285 | |||
286 | GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared, | ||
287 | &lfs); | ||
288 | GNUNET_assert (NULL != &lfs->ac); | ||
289 | if (NULL == lfs->ac.cont) | ||
290 | GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) &lfs->ac); | ||
291 | else | ||
292 | GNUNET_TESTING_async_finish ((struct | ||
293 | GNUNET_TESTING_AsyncContext *) &lfs->ac); | ||
294 | } | ||
295 | |||
296 | |||
297 | /** | ||
298 | * Function to start a local test case. | ||
299 | * | ||
300 | * @param write_message Callback to send a message to the master loop. | ||
301 | * @param router_ip Global address of the network namespace. | ||
302 | * @param node_ip The IP address of the node. | ||
303 | * @param m The number of the node in a network namespace. | ||
304 | * @param n The number of the network namespace. | ||
305 | * @param local_m The number of nodes in a network namespace. | ||
306 | * @param topology_data A file name for the file containing the topology configuration, or a string containing | ||
307 | * the topology configuration. | ||
308 | * @param read_file If read_file is GNUNET_YES this string is the filename for the topology configuration, | ||
309 | * if read_file is GNUNET_NO the string contains the topology configuration. | ||
310 | * @param finish_cb Callback function which writes a message from the helper process running on a netjail | ||
311 | * node to the master process * signaling that the test case running on the netjail node finished. | ||
312 | * @return Returns the struct GNUNET_TESTING_Interpreter of the command loop running on this netjail node. | ||
313 | */ | ||
314 | static struct GNUNET_TESTING_Interpreter * | ||
315 | start_testcase (GNUNET_TESTING_cmd_helper_write_cb write_message, | ||
316 | const char *router_ip, | ||
317 | const char *node_ip, | ||
318 | const char *m, | ||
319 | const char *n, | ||
320 | const char *local_m, | ||
321 | const char *topology_data, | ||
322 | unsigned int *read_file, | ||
323 | GNUNET_TESTING_cmd_helper_finish_cb finished_cb) | ||
324 | { | ||
325 | |||
326 | unsigned int n_int; | ||
327 | unsigned int m_int; | ||
328 | unsigned int local_m_int; | ||
329 | unsigned int num; | ||
330 | struct TestState *ts = GNUNET_new (struct TestState); | ||
331 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
332 | unsigned int sscanf_ret = 0; | ||
333 | |||
334 | senders = GNUNET_CONTAINER_multipeermap_create (1, GNUNET_NO); | ||
335 | ts->finished_cb = finished_cb; | ||
336 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
337 | "n %s m %s\n", | ||
338 | n, | ||
339 | m); | ||
340 | |||
341 | if (GNUNET_YES == *read_file) | ||
342 | { | ||
343 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
344 | "read from file\n"); | ||
345 | topology = GNUNET_TESTING_get_topo_from_file (topology_data); | ||
346 | } | ||
347 | else | ||
348 | topology = GNUNET_TESTING_get_topo_from_string (topology_data); | ||
349 | |||
350 | ts->topology = topology; | ||
351 | |||
352 | errno = 0; | ||
353 | sscanf_ret = sscanf (m, "%u", &m_int); | ||
354 | if (errno != 0) | ||
355 | { | ||
356 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf"); | ||
357 | } | ||
358 | GNUNET_assert (0 < sscanf_ret); | ||
359 | errno = 0; | ||
360 | sscanf_ret = sscanf (n, "%u", &n_int); | ||
361 | if (errno != 0) | ||
362 | { | ||
363 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf"); | ||
364 | } | ||
365 | GNUNET_assert (0 < sscanf_ret); | ||
366 | errno = 0; | ||
367 | sscanf_ret = sscanf (local_m, "%u", &local_m_int); | ||
368 | if (errno != 0) | ||
369 | { | ||
370 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf"); | ||
371 | } | ||
372 | GNUNET_assert (0 < sscanf_ret); | ||
373 | |||
374 | if (0 == n_int) | ||
375 | num = m_int; | ||
376 | else | ||
377 | num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; | ||
378 | |||
379 | block_send = GNUNET_TESTING_cmd_block_until_external_trigger ( | ||
380 | "block"); | ||
381 | block_receive = GNUNET_TESTING_cmd_block_until_external_trigger ( | ||
382 | "block-receive"); | ||
383 | connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers", | ||
384 | "start-peer", | ||
385 | "system-create", | ||
386 | num, | ||
387 | topology, | ||
388 | 0); | ||
389 | local_prepared = GNUNET_TESTING_cmd_local_test_prepared ( | ||
390 | "local-test-prepared", | ||
391 | write_message); | ||
392 | |||
393 | |||
394 | GNUNET_asprintf (&ts->cfgname, | ||
395 | "test_transport_api2_tcp_node1.conf"); | ||
396 | |||
397 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
398 | "plugin cfgname: %s\n", | ||
399 | ts->cfgname); | ||
400 | |||
401 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
402 | "node ip: %s\n", | ||
403 | node_ip); | ||
404 | |||
405 | GNUNET_asprintf (&ts->testdir, | ||
406 | "%s%s%s", | ||
407 | BASE_DIR, | ||
408 | m, | ||
409 | n); | ||
410 | |||
411 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
412 | GNUNET_MQ_hd_var_size (test, | ||
413 | GNUNET_TRANSPORT_TESTING_SIMPLE_PERFORMANCE_MTYPE, | ||
414 | struct GNUNET_TRANSPORT_TESTING_PerformanceTestMessage, | ||
415 | ts), | ||
416 | GNUNET_MQ_handler_end () | ||
417 | }; | ||
418 | |||
419 | start_peer = GNUNET_TRANSPORT_cmd_start_peer ("start-peer", | ||
420 | "system-create", | ||
421 | num, | ||
422 | node_ip, | ||
423 | handlers, | ||
424 | ts->cfgname, | ||
425 | notify_connect, | ||
426 | GNUNET_NO); | ||
427 | |||
428 | struct GNUNET_TESTING_Command commands[] = { | ||
429 | GNUNET_TESTING_cmd_system_create ("system-create", | ||
430 | ts->testdir), | ||
431 | start_peer, | ||
432 | GNUNET_TESTING_cmd_barrier_reached ("ready-to-connect-reached", | ||
433 | "ready-to-connect", | ||
434 | GNUNET_NO, | ||
435 | num, | ||
436 | GNUNET_NO, | ||
437 | write_message), | ||
438 | connect_peers, | ||
439 | GNUNET_TRANSPORT_cmd_send_simple_performance ("send-simple", | ||
440 | "start-peer", | ||
441 | "system-create", | ||
442 | num, | ||
443 | MESSAGE_SIZE, | ||
444 | MAX_RECEIVED, | ||
445 | topology), | ||
446 | block_receive, | ||
447 | GNUNET_TESTING_cmd_barrier_reached ("test-case-finished-reached", | ||
448 | "test-case-finished", | ||
449 | GNUNET_NO, | ||
450 | num, | ||
451 | GNUNET_NO, | ||
452 | write_message), | ||
453 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", | ||
454 | "start-peer"), | ||
455 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", | ||
456 | "system-create"), | ||
457 | GNUNET_TESTING_cmd_end () | ||
458 | }; | ||
459 | |||
460 | ts->write_message = write_message; | ||
461 | |||
462 | is = GNUNET_TESTING_run (commands, | ||
463 | TIMEOUT, | ||
464 | &handle_result, | ||
465 | ts); | ||
466 | return is; | ||
467 | } | ||
468 | |||
469 | |||
470 | /** | ||
471 | * Entry point for the plugin. | ||
472 | * | ||
473 | * @param cls NULL | ||
474 | * @return the exported block API | ||
475 | */ | ||
476 | void * | ||
477 | libgnunet_test_transport_plugin_cmd_simple_send_performance_init (void *cls) | ||
478 | { | ||
479 | struct GNUNET_TESTING_PluginFunctions *api; | ||
480 | |||
481 | GNUNET_log_setup ("simple-send", | ||
482 | "DEBUG", | ||
483 | NULL); | ||
484 | |||
485 | api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); | ||
486 | api->start_testcase = &start_testcase; | ||
487 | api->get_waiting_for_barriers = get_waiting_for_barriers; | ||
488 | return api; | ||
489 | } | ||
490 | |||
491 | |||
492 | /** | ||
493 | * Exit point from the plugin. | ||
494 | * | ||
495 | * @param cls the return value from #libgnunet_test_transport_plugin_simple_send_performance_init | ||
496 | * @return NULL | ||
497 | */ | ||
498 | void * | ||
499 | libgnunet_test_transport_plugin_cmd_simple_send_performance_done (void *cls) | ||
500 | { | ||
501 | struct GNUNET_TESTING_PluginFunctions *api = cls; | ||
502 | |||
503 | GNUNET_free (api); | ||
504 | return NULL; | ||
505 | } | ||
506 | |||
507 | |||
508 | /* end of plugin_cmd_simple_send.c */ | ||