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